Skip to content

Commit 145bafb

Browse files
committed
Clear search input on index route
1 parent 2efe33d commit 145bafb

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

app/routes/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export default Route.extend({
1414
},
1515

1616
setupController(controller) {
17+
this.controllerFor('application').set('searchQuery', null);
1718
controller.dataTask.perform();
1819
},
1920
});

app/routes/search.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export default Route.extend({
1414
},
1515

1616
setupController(controller, params) {
17+
this.controllerFor('application').set('searchQuery', params.q);
1718
controller.dataTask.perform(params);
1819
},
1920
});

tests/acceptance/search-test.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,20 @@ module('Acceptance | search', function(hooks) {
6262
assert.dom('[data-test-search-nav]').hasText('Displaying 1-8 of 8 total results');
6363
});
6464

65+
test('clearing search results', async function(assert) {
66+
this.server.loadFixtures();
67+
68+
await visit('/search?q=rust');
69+
70+
assert.equal(currentURL(), '/search?q=rust');
71+
assert.dom('[data-test-search-input]').hasValue('rust');
72+
73+
await visit('/');
74+
75+
assert.equal(currentURL(), '/');
76+
assert.dom('[data-test-search-input]').hasValue('');
77+
});
78+
6579
test('pressing S key to focus the search bar', async function(assert) {
6680
this.server.loadFixtures();
6781

0 commit comments

Comments
 (0)