Skip to content

Commit 2fca6bf

Browse files
authored
Merge pull request #791 from ember-learn/fix-search
Fix search
2 parents 2dfed6f + 62a0f1e commit 2fca6bf

File tree

4 files changed

+210
-3
lines changed

4 files changed

+210
-3
lines changed

app/templates/components/search-input.hbs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
onfocus={{action 'onfocus'}}
77
onblur={{action 'onblur'}}
88
placeholder="Search"
9+
data-test-search-input
910
>
1011
{{!-- Search results dropdown --}}
1112
<EmberTether @target="#search-input" @targetAttachment="bottom left" @attachment="top left" @constraints={{this._resultTetherConstraints}} @class="ds-dropdown-results">

app/templates/components/search-input/dropdown-result.hbs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
</div>
77
<div class="algolia-docsearch-suggestion--content">
88
{{#if this.result.static}}
9-
<LinkTo @route="project-version.functions.function" @models={{array this.module this.version this.result.class this.result.name}}>
9+
<LinkTo @route="project-version.functions.function" @models={{array this.module this.version this.result.class this.result.name}} data-test-search-result>
1010
<div class="algolia-docsearch-suggestion--subcategory-inline">
1111
{{!-- Sometimes hierarchy lvl1 is null, fall-back to lvl0 --}}
1212
{{#if this.result._highlightResult.hierarchy.lvl1}}
@@ -28,7 +28,7 @@
2828
</div>
2929
</LinkTo>
3030
{{else}}
31-
<LinkTo @route="project-version.classes.class.methods.method" @models={{array this.module this.version}} @query={{hash anchor=this.result.name}}>
31+
<LinkTo @route="project-version.classes.class.methods.method" @models={{array this.module this.version result.class result.name}} @query={{hash anchor=this.result.name}} data-test-search-result>
3232
<div class="algolia-docsearch-suggestion--subcategory-inline">
3333
{{!-- Sometimes hierarchy lvl1 is null, fall-back to lvl0 --}}
3434
{{#if this.result._highlightResult.hierarchy.lvl1}}
@@ -54,4 +54,4 @@
5454
</div>
5555
</div>
5656

57-
{{yield}}
57+
{{yield}}

tests/acceptance/search-test.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { module, test } from 'qunit';
2+
import { visit, currentURL, fillIn, click } from '@ember/test-helpers';
3+
import { setupApplicationTest } from 'ember-qunit';
4+
5+
import searchResults from 'ember-api-docs/tests/fixtures/searchresult';
6+
7+
module('Acceptance | search', function (hooks) {
8+
setupApplicationTest(hooks);
9+
10+
test('search for an EmberArray function and navigate properly', async function (assert) {
11+
await visit('/');
12+
13+
const algoliaService = this.owner.lookup('service:algolia');
14+
15+
algoliaService.search = async () => {
16+
return searchResults;
17+
};
18+
19+
await fillIn('[data-test-search-input]', 'forEach');
20+
21+
await click('[data-test-search-result]');
22+
23+
assert.equal(
24+
currentURL(),
25+
'/ember/4.1/classes/EmberArray/methods/forEach?anchor=forEach'
26+
);
27+
});
28+
});

tests/fixtures/searchresult.js

Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
export default {
2+
hits: [
3+
{
4+
file: 'packages/@ember/-internals/runtime/lib/mixins/array.js',
5+
line: 473,
6+
module: '@ember/array',
7+
class: 'EmberArray',
8+
name: 'forEach',
9+
access: 'public',
10+
_tags: ['module:@ember/array', 'version:4.1.0'],
11+
hierarchy: {
12+
lvl0: '@ember/array',
13+
lvl1: 'EmberArray',
14+
lvl2: 'forEach',
15+
},
16+
objectID: '7173445001',
17+
_highlightResult: {
18+
name: {
19+
value: '<em>forEach</em>',
20+
matchLevel: 'full',
21+
fullyHighlighted: true,
22+
matchedWords: ['foreach'],
23+
},
24+
hierarchy: {
25+
lvl0: {
26+
value: '@ember/array',
27+
matchLevel: 'none',
28+
matchedWords: [],
29+
},
30+
lvl1: {
31+
value: 'EmberArray',
32+
matchLevel: 'none',
33+
matchedWords: [],
34+
},
35+
lvl2: {
36+
value: '<em>forEach</em>',
37+
matchLevel: 'full',
38+
fullyHighlighted: true,
39+
matchedWords: ['foreach'],
40+
},
41+
},
42+
},
43+
},
44+
{
45+
file: 'packages/@ember/-internals/runtime/lib/mixins/array.js',
46+
line: 473,
47+
module: '@ember/array',
48+
class: 'MutableArray',
49+
name: 'forEach',
50+
access: 'public',
51+
_tags: ['module:@ember/array', 'version:4.1.0'],
52+
hierarchy: {
53+
lvl0: '@ember/array',
54+
lvl1: 'MutableArray',
55+
lvl2: 'forEach',
56+
},
57+
objectID: '7173416001',
58+
_highlightResult: {
59+
name: {
60+
value: '<em>forEach</em>',
61+
matchLevel: 'full',
62+
fullyHighlighted: true,
63+
matchedWords: ['foreach'],
64+
},
65+
hierarchy: {
66+
lvl0: {
67+
value: '@ember/array',
68+
matchLevel: 'none',
69+
matchedWords: [],
70+
},
71+
lvl1: {
72+
value: 'MutableArray',
73+
matchLevel: 'none',
74+
matchedWords: [],
75+
},
76+
lvl2: {
77+
value: '<em>forEach</em>',
78+
matchLevel: 'full',
79+
fullyHighlighted: true,
80+
matchedWords: ['foreach'],
81+
},
82+
},
83+
},
84+
},
85+
{
86+
file: 'packages/@ember/-internals/runtime/lib/mixins/array.js',
87+
line: 473,
88+
module: '@ember/array',
89+
class: 'Ember.NativeArray',
90+
name: 'forEach',
91+
access: 'public',
92+
_tags: ['module:@ember/array', 'version:4.1.0'],
93+
hierarchy: {
94+
lvl0: '@ember/array',
95+
lvl1: 'Ember.NativeArray',
96+
lvl2: 'forEach',
97+
},
98+
objectID: '7173371001',
99+
_highlightResult: {
100+
name: {
101+
value: '<em>forEach</em>',
102+
matchLevel: 'full',
103+
fullyHighlighted: true,
104+
matchedWords: ['foreach'],
105+
},
106+
hierarchy: {
107+
lvl0: {
108+
value: '@ember/array',
109+
matchLevel: 'none',
110+
matchedWords: [],
111+
},
112+
lvl1: {
113+
value: 'Ember.NativeArray',
114+
matchLevel: 'none',
115+
matchedWords: [],
116+
},
117+
lvl2: {
118+
value: '<em>forEach</em>',
119+
matchLevel: 'full',
120+
fullyHighlighted: true,
121+
matchedWords: ['foreach'],
122+
},
123+
},
124+
},
125+
},
126+
{
127+
file: 'packages/@ember/-internals/runtime/lib/mixins/array.js',
128+
line: 473,
129+
module: '@ember/array',
130+
class: 'ArrayProxy',
131+
name: 'forEach',
132+
access: 'public',
133+
_tags: ['module:@ember/array', 'version:4.1.0'],
134+
hierarchy: {
135+
lvl0: '@ember/array',
136+
lvl1: 'ArrayProxy',
137+
lvl2: 'forEach',
138+
},
139+
objectID: '7173290001',
140+
_highlightResult: {
141+
name: {
142+
value: '<em>forEach</em>',
143+
matchLevel: 'full',
144+
fullyHighlighted: true,
145+
matchedWords: ['foreach'],
146+
},
147+
hierarchy: {
148+
lvl0: {
149+
value: '@ember/array',
150+
matchLevel: 'none',
151+
matchedWords: [],
152+
},
153+
lvl1: {
154+
value: 'ArrayProxy',
155+
matchLevel: 'none',
156+
matchedWords: [],
157+
},
158+
lvl2: {
159+
value: '<em>forEach</em>',
160+
matchLevel: 'full',
161+
fullyHighlighted: true,
162+
matchedWords: ['foreach'],
163+
},
164+
},
165+
},
166+
},
167+
],
168+
nbHits: 4,
169+
page: 0,
170+
nbPages: 1,
171+
hitsPerPage: 15,
172+
exhaustiveNbHits: true,
173+
exhaustiveTypo: true,
174+
query: 'forEach',
175+
params:
176+
'query=forEach&hitsPerPage=15&restrictSearchableAttributes=%5B%22hierarchy.lvl0%22%2C%22hierarchy.lvl1%22%2C%22hierarchy.lvl2%22%5D&tagFilters=%5B%22version%3A4.1.0%22%5D&facetFilters=%5B%22access%3A-private%22%5D',
177+
processingTimeMS: 1,
178+
};

0 commit comments

Comments
 (0)