FIX: Search menu results does not refresh when search context is changed.

This commit is contained in:
Guo Xiang Tan 2017-02-03 11:28:54 +08:00
parent 758e3e52f7
commit ac37bd3dbc
3 changed files with 34 additions and 1 deletions

View File

@ -206,6 +206,7 @@ export default createWidget('header', {
state.contextEnabled = true; state.contextEnabled = true;
} }
} }
panels.push(this.attach('search-menu', { contextEnabled: state.contextEnabled })); panels.push(this.attach('search-menu', { contextEnabled: state.contextEnabled }));
} else if (state.hamburgerVisible) { } else if (state.hamburgerVisible) {
panels.push(this.attach('hamburger-menu')); panels.push(this.attach('hamburger-menu'));
@ -303,6 +304,7 @@ export default createWidget('header', {
}, },
searchMenuContextChanged(value) { searchMenuContextChanged(value) {
this.state.contextType = this.register.lookup('search-service:main').get('contextType');
this.state.contextEnabled = value; this.state.contextEnabled = value;
}, },

View File

@ -148,7 +148,12 @@ export default createWidget('search-menu', {
}, },
html(attrs) { 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() }); return this.attach('menu-panel', { maxWidth: 500, contents: () => this.panelContents() });
}, },

View File

@ -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"));
});
});