1
1
import { module , test } from 'qunit' ;
2
- import { visit , currentURL , fillIn , click } from '@ember/test-helpers' ;
2
+ import { visit , currentURL , fillIn , click , focus } from '@ember/test-helpers' ;
3
+ import { selectChoose } from 'ember-power-select/test-support' ;
3
4
import { setupApplicationTest } from 'ember-qunit' ;
4
5
5
- import searchResults from 'ember-api-docs/tests/fixtures/searchresult' ;
6
+ import searchResultsV4_1 from 'ember-api-docs/tests/fixtures/searchresult-v-4-1' ;
7
+ import searchResultsV5_1 from 'ember-api-docs/tests/fixtures/searchresult-v-5-1' ;
6
8
7
9
module ( 'Acceptance | search' , function ( hooks ) {
8
10
setupApplicationTest ( hooks ) ;
@@ -13,7 +15,7 @@ module('Acceptance | search', function (hooks) {
13
15
const algoliaService = this . owner . lookup ( 'service:algolia' ) ;
14
16
15
17
algoliaService . search = async ( ) => {
16
- return searchResults ;
18
+ return searchResultsV4_1 ;
17
19
} ;
18
20
19
21
await fillIn ( '[data-test-search-input]' , 'forEach' ) ;
@@ -25,4 +27,32 @@ module('Acceptance | search', function (hooks) {
25
27
'/ember/4.1/classes/EmberArray/methods/forEach?anchor=forEach'
26
28
) ;
27
29
} ) ;
30
+
31
+ test ( 'discard stale search results when version changes' , async function ( assert ) {
32
+ await visit ( '/' ) ;
33
+
34
+ const algoliaService = this . owner . lookup ( 'service:algolia' ) ;
35
+
36
+ algoliaService . search = async ( ) => {
37
+ return searchResultsV4_1 ;
38
+ } ;
39
+
40
+ await selectChoose ( '.ember-power-select-trigger' , '4.1' ) ;
41
+
42
+ await fillIn ( '[data-test-search-input]' , 'get' ) ;
43
+
44
+ // the url contains /ember/4.1/
45
+ assert . dom ( '[data-test-search-result]' ) . hasAttribute ( 'href' , / \/ e m b e r \/ 4 \. 1 \/ / ) ;
46
+
47
+ algoliaService . search = async ( ) => {
48
+ return searchResultsV5_1 ;
49
+ } ;
50
+
51
+ await selectChoose ( '.ember-power-select-trigger' , '5.1' ) ;
52
+
53
+ await focus ( '[data-test-search-input]' ) ;
54
+
55
+ // the url contains /ember/5.1/
56
+ assert . dom ( '[data-test-search-result]' ) . hasAttribute ( 'href' , / \/ e m b e r \/ 5 \. 1 \/ / ) ;
57
+ } ) ;
28
58
} ) ;
0 commit comments