FIX: 'in all topics' should search in all topics (#22207)

When searching in the context of a topic the <kbd>in all topics</kbd> link would not search globally for the given term and instead it would always search within the current topic. This PR fixes the link to properly update the search context and search globally for the given term.

This fix reveals some _secretly_ broken tests. Update these as well.
This commit is contained in:
Isaac Janzen 2023-06-20 11:59:15 -05:00 committed by GitHub
parent f4add0ef6a
commit e1561bc459
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 34 additions and 5 deletions

View File

@ -93,7 +93,8 @@ export default class AssistantItem extends Component {
const inTopicContext = this.search.searchContext?.type === "topic"; const inTopicContext = this.search.searchContext?.type === "topic";
this.args.searchTermChanged(updatedValue, { this.args.searchTermChanged(updatedValue, {
searchTopics: !inTopicContext || this.search.activeGlobalSearchTerm, searchTopics: !inTopicContext || this.search.activeGlobalSearchTerm,
...(inTopicContext && { setTopicContext: true }), ...(inTopicContext &&
!this.args.searchAllTopics && { setTopicContext: true }),
}); });
focusSearchInput(); focusSearchInput();
} }

View File

@ -13,6 +13,7 @@
<SearchMenu::Results::AssistantItem <SearchMenu::Results::AssistantItem
@suffix={{i18n "search.in_topics_posts"}} @suffix={{i18n "search.in_topics_posts"}}
@closeSearchMenu={{@closeSearchMenu}} @closeSearchMenu={{@closeSearchMenu}}
@searchAllTopics={{true}}
@extraHint={{true}} @extraHint={{true}}
@searchTermChanged={{@searchTermChanged}} @searchTermChanged={{@searchTermChanged}}
@suggestionKeyword={{this.contextTypeKeyword}} @suggestionKeyword={{this.contextTypeKeyword}}

View File

@ -234,14 +234,41 @@ acceptance("Search - Glimmer - Anonymous", function (needs) {
); );
}); });
test("initial options - topic search scope - 'in all topics' searches in all topics", async function (assert) {
await visit("/t/internationalization-localization/280/1");
await click("#search-button");
await fillIn("#search-term", "foo");
// select 'in all topics and posts'
await click(
".search-menu .results .search-menu-initial-options .search-menu-assistant-item:first-child"
);
assert.ok(
exists(".search-result-topic"),
"search result is a list of topics"
);
});
test("initial options - topic search scope - 'in this topic' searches posts within topic", async function (assert) {
await visit("/t/internationalization-localization/280/1");
await click("#search-button");
await fillIn("#search-term", "foo");
// select 'in this topic'
await click(
".search-menu .results .search-menu-initial-options .search-menu-assistant-item:nth-child(2)"
);
assert.ok(
exists(".search-result-post"),
"search result is a list of posts"
);
});
test("initial options - topic search scope - keep 'in this topic' filter in full page search", async function (assert) { test("initial options - topic search scope - keep 'in this topic' filter in full page search", async function (assert) {
await visit("/t/internationalization-localization/280/1"); await visit("/t/internationalization-localization/280/1");
await click("#search-button"); await click("#search-button");
await fillIn("#search-term", "proper"); await fillIn("#search-term", "proper");
await triggerKeyEvent(document.activeElement, "keyup", "ArrowDown"); await triggerKeyEvent(document.activeElement, "keyup", "ArrowDown");
await triggerKeyEvent(document.activeElement, "keyup", "ArrowDown"); await triggerKeyEvent(document.activeElement, "keydown", "ArrowDown");
await click(document.activeElement); await click(document.activeElement);
await click(".show-advanced-search"); await click(".show-advanced-search");
assert.strictEqual( assert.strictEqual(
@ -322,7 +349,7 @@ acceptance("Search - Glimmer - Anonymous", function (needs) {
await click("#search-button"); await click("#search-button");
await fillIn("#search-term", "a proper"); await fillIn("#search-term", "a proper");
await triggerKeyEvent(document.activeElement, "keyup", "ArrowDown"); await triggerKeyEvent(document.activeElement, "keyup", "ArrowDown");
await triggerKeyEvent(document.activeElement, "keyup", "ArrowDown"); await triggerKeyEvent(document.activeElement, "keydown", "ArrowDown");
await click(document.activeElement); await click(document.activeElement);
assert.ok( assert.ok(
@ -357,7 +384,7 @@ acceptance("Search - Glimmer - Anonymous", function (needs) {
await fillIn("#search-term", "dev"); await fillIn("#search-term", "dev");
await query("#search-term").focus(); await query("#search-term").focus();
await triggerKeyEvent(document.activeElement, "keyup", "ArrowDown"); await triggerKeyEvent(document.activeElement, "keyup", "ArrowDown");
await triggerKeyEvent(document.activeElement, "keyup", "ArrowDown"); await triggerKeyEvent(document.activeElement, "keydown", "ArrowDown");
await click(document.activeElement); await click(document.activeElement);
assert.ok( assert.ok(