Skip to content

Commit 26fbce7

Browse files
committed
Add test for stale results
1 parent 98683f1 commit 26fbce7

File tree

3 files changed

+629
-3
lines changed

3 files changed

+629
-3
lines changed

tests/acceptance/search-test.js

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
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';
34
import { setupApplicationTest } from 'ember-qunit';
45

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';
68

79
module('Acceptance | search', function (hooks) {
810
setupApplicationTest(hooks);
@@ -13,7 +15,7 @@ module('Acceptance | search', function (hooks) {
1315
const algoliaService = this.owner.lookup('service:algolia');
1416

1517
algoliaService.search = async () => {
16-
return searchResults;
18+
return searchResultsV4_1;
1719
};
1820

1921
await fillIn('[data-test-search-input]', 'forEach');
@@ -25,4 +27,32 @@ module('Acceptance | search', function (hooks) {
2527
'/ember/4.1/classes/EmberArray/methods/forEach?anchor=forEach'
2628
);
2729
});
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', /\/ember\/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', /\/ember\/5\.1\//);
57+
});
2858
});
File renamed without changes.

0 commit comments

Comments
 (0)