FIX: Search does not retrigger when context has changed. Take 2.

https://meta.discourse.org/t/using-the-search-this-topic-check-box-blocks-search-on-other-pages/56832/6?u=tgxworld
This commit is contained in:
Guo Xiang Tan 2018-08-20 15:46:02 +08:00
parent f5fe58384f
commit 658b55c406
4 changed files with 27 additions and 5 deletions

View File

@ -182,7 +182,6 @@ export default createWidget("search-menu", {
},
html(attrs) {
searchData.contextEnabled = attrs.contextEnabled;
const searchContext = this.searchContext();
const shouldTriggerSearch =

View File

@ -1,5 +1,21 @@
import { acceptance, logIn } from "helpers/qunit-helpers";
acceptance("Search");
import { fixturesByUrl } from "helpers/create-pretender";
const emptySearchContextCallbacks = [];
acceptance("Search", {
pretend(server, helper) {
server.get("/search/query", request => {
if (request.queryParams["search_context[type]"] === undefined) {
emptySearchContextCallbacks.forEach(callback => {
callback.call();
});
}
return helper.response(fixturesByUrl["search/query.json"]);
});
}
});
QUnit.test("search", async assert => {
await visit("/");
@ -73,10 +89,17 @@ QUnit.test("Search with context", async assert => {
"it should highlight the search term"
);
let callbackCalled = false;
emptySearchContextCallbacks.push(() => {
callbackCalled = true;
});
await visit("/");
await click("#search-button");
assert.ok(!exists(".search-context input[type='checkbox']"));
assert.ok(callbackCalled, "it triggers a new search");
await visit("/t/internationalization-localization/280/1");
await click("#search-button");

View File

@ -819,7 +819,7 @@ export default {
]
}
},
"search/query": {
"search/query.json": {
posts: [
{
id: 3833,

View File

@ -33,14 +33,14 @@ export function success() {
}
const loggedIn = () => !!Discourse.User.current();
const helpers = { response, success, parsePostData };
export let fixturesByUrl;
export default function() {
const server = new Pretender(function() {
storePretender.call(this, helpers);
flagPretender.call(this, helpers);
const fixturesByUrl = fixturePretender.call(this, helpers);
fixturesByUrl = fixturePretender.call(this, helpers);
this.get("/admin/plugins", () => response({ plugins: [] }));