Skip to content

Commit a9b1391

Browse files
author
Tony Ward
committed
[BUGFIX] Create anchor for “Properties” tab items
Fixes #546
1 parent e17c903 commit a9b1391

File tree

4 files changed

+40
-3
lines changed

4 files changed

+40
-3
lines changed

app/controllers/properties.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,11 @@ import AnchorControllerSupport from "ember-anchor/mixins/controller-support";
44

55
export default Controller.extend(AnchorControllerSupport, {
66
filterData: service(),
7-
queryParams: ['anchor']
7+
queryParams: ['anchor'],
8+
9+
actions: {
10+
updateAnchor(fieldName) {
11+
this.set('anchor', fieldName);
12+
}
13+
}
814
});

app/templates/properties.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{{ember-anchor a=anchor}}
22
{{#api-index-filter model=model filterData=filterData as |filteredModel|}}
33
{{#each filteredModel.properties as |property|}}
4-
{{class-field-description type="property" field=property model=model}}
4+
{{class-field-description type="property" field=property model=model updateAnchor=(action 'updateAnchor')}}
55
{{/each}}
66
{{/api-index-filter}}

tests/acceptance/anchors-test.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import moduleForAcceptance from 'ember-api-docs/tests/helpers/module-for-acceptance';
2+
import { test } from 'qunit';
3+
import { visit, click, findAll} from 'ember-native-dom-helpers';
4+
5+
moduleForAcceptance('Acceptance | Creating Anchors');
6+
7+
test('Can create a link from the "Properties" tab', async function(assert) {
8+
await visit('/ember/1.0/classes/Container/properties');
9+
let [ element ] = findAll('.class-field-description--link');
10+
await click(element);
11+
assert.equal(currentURL(), `/ember/1.0/classes/Container/properties?anchor=${element.innerText}`);
12+
});

tests/integration/components/class-field-description-test.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import EmberObject from '@ember/object';
22
import { moduleForComponent, test } from 'ember-qunit';
33
import hbs from 'htmlbars-inline-precompile';
4-
import { findAll, triggerEvent } from 'ember-native-dom-helpers';
4+
import { click, findAll, triggerEvent } from 'ember-native-dom-helpers';
55

66
moduleForComponent('class-field-description', 'Integration | Component | class field description', {
77
integration: true
@@ -41,3 +41,22 @@ test('On hover -- the link icon shows up', async function(assert) {
4141
await triggerEvent('.class-field-description--link', 'mouseenter');
4242
assert.dom('.class-field-description--link-hover').exists('The link icon appears when hovering on the method text');
4343
});
44+
45+
test('it calls the provided action on link-click with the field name as an arg', async function(assert) {
46+
this.set('updateAnchor', (name) => {
47+
assert.equal(name, 'field-name', 'expected the field name to be passed into the action');
48+
assert.step('updateAnchorAction');
49+
});
50+
51+
this.set('field', EmberObject.create({
52+
name: "field-name",
53+
}));
54+
55+
this.render(hbs`{{class-field-description field=field updateAnchor=updateAnchor}}`);
56+
57+
await click('.class-field-description--link');
58+
59+
assert.verifySteps([
60+
'updateAnchorAction'
61+
]);
62+
});

0 commit comments

Comments
 (0)