FIX: Keep topic context when redirecting to full search (#14846)

This commit is contained in:
Penar Musaraj 2021-11-08 15:07:02 -05:00 committed by GitHub
parent 7fb693c8f6
commit e90f506bf8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 44 additions and 0 deletions

View File

@ -204,6 +204,12 @@ export default createWidget("search-menu", {
query += `q=${encodeURIComponent(searchData.term)}`;
const searchContext = this.searchContext();
if (searchContext?.type === "topic") {
query += encodeURIComponent(` topic:${searchContext.id}`);
}
if (query) {
params.push(query);
}

View File

@ -243,6 +243,44 @@ acceptance("Search - Anonymous", function (needs) {
);
});
test("topic search scope - keep 'in this topic' filter in full page search", async function (assert) {
await visit("/t/internationalization-localization/280/1");
await click("#search-button");
const firstResult =
".search-menu .results .search-menu-assistant-item:first-child";
assert.strictEqual(
query(firstResult).textContent.trim(),
I18n.t("search.in_this_topic"),
"contenxtual topic search is first available option"
);
await fillIn("#search-term", "proper");
await focus("input#search-term");
await triggerKeyEvent(".search-menu", "keydown", 40);
await click(document.activeElement);
assert.ok(
exists(".search-menu .search-context"),
"search context indicator is visible"
);
await click(".show-advanced-search");
assert.strictEqual(
query(".full-page-search").value,
"proper topic:280",
"it goes to full search page and preserves search term + context"
);
assert.ok(
exists(".search-advanced-options"),
"advanced search is expanded"
);
});
test("topic search scope - special case when matching a single user", async function (assert) {
await visit("/t/internationalization-localization/280/1");