From ac37bd3dbc82292b2677d76f935073940f30d6ff Mon Sep 17 00:00:00 2001 From: Guo Xiang Tan Date: Fri, 3 Feb 2017 11:28:54 +0800 Subject: [PATCH] FIX: Search menu results does not refresh when search context is changed. --- .../discourse/widgets/header.js.es6 | 2 ++ .../discourse/widgets/search-menu.js.es6 | 7 ++++- .../javascripts/acceptance/search-test.js.es6 | 26 +++++++++++++++++++ 3 files changed, 34 insertions(+), 1 deletion(-) diff --git a/app/assets/javascripts/discourse/widgets/header.js.es6 b/app/assets/javascripts/discourse/widgets/header.js.es6 index 7a7dd85299f..d1c25a411c4 100644 --- a/app/assets/javascripts/discourse/widgets/header.js.es6 +++ b/app/assets/javascripts/discourse/widgets/header.js.es6 @@ -206,6 +206,7 @@ export default createWidget('header', { state.contextEnabled = true; } } + panels.push(this.attach('search-menu', { contextEnabled: state.contextEnabled })); } else if (state.hamburgerVisible) { panels.push(this.attach('hamburger-menu')); @@ -303,6 +304,7 @@ export default createWidget('header', { }, searchMenuContextChanged(value) { + this.state.contextType = this.register.lookup('search-service:main').get('contextType'); this.state.contextEnabled = value; }, diff --git a/app/assets/javascripts/discourse/widgets/search-menu.js.es6 b/app/assets/javascripts/discourse/widgets/search-menu.js.es6 index 843203aec15..9f462a12055 100644 --- a/app/assets/javascripts/discourse/widgets/search-menu.js.es6 +++ b/app/assets/javascripts/discourse/widgets/search-menu.js.es6 @@ -148,7 +148,12 @@ export default createWidget('search-menu', { }, html(attrs) { - searchData.contextEnabled = attrs.contextEnabled; + if (searchData.contextEnabled !== attrs.contextEnabled) { + searchData.contextEnabled = attrs.contextEnabled; + this.triggerSearch(); + } else { + searchData.contextEnabled = attrs.contextEnabled; + } return this.attach('menu-panel', { maxWidth: 500, contents: () => this.panelContents() }); }, diff --git a/test/javascripts/acceptance/search-test.js.es6 b/test/javascripts/acceptance/search-test.js.es6 index 69d6dad7cc3..bb2b9892b73 100644 --- a/test/javascripts/acceptance/search-test.js.es6 +++ b/test/javascripts/acceptance/search-test.js.es6 @@ -47,3 +47,29 @@ test("search scope checkbox", () => { }); }); +test("Search with context", assert => { + visit("/t/internationalization-localization/280/1"); + + click('#search-button'); + fillIn('#search-term', 'dev'); + click(".search-context input[type='checkbox']"); + keyEvent('#search-term', 'keyup', 16); + + andThen(() => { + assert.ok(exists('.search-menu .results ul li'), 'it shows results'); + }); + + visit("/"); + click('#search-button'); + + andThen(() => { + assert.ok(!exists(".search-context input[type='checkbox']")); + }); + + visit("/t/internationalization-localization/280/1"); + click('#search-button'); + + andThen(() => { + assert.ok(!$('.search-context input[type=checkbox]').is(":checked")); + }); +});