FIX: Render 'In topic context' search results at the correct time (#23481)

This commit is contained in:
Isaac Janzen 2023-09-08 12:20:55 -05:00 committed by GitHub
parent 22747e26fd
commit daf8c32d0e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 154 additions and 121 deletions

View File

@ -9,6 +9,7 @@
@slug={{@slug}}
@withInLabel={{@withInLabel}}
@isIntersection={{true}}
@searchAllTopics={{true}}
@closeSearchMenu={{@closeSearchMenu}}
@searchTermChanged={{@searchTermChanged}}
@suggestionKeyword={{@suggestionKeyword}}
@ -17,19 +18,23 @@
{{else if (eq this.suggestionType "categoryOrTag")}}
{{#each @results as |result|}}
{{#if result.model}}
{{! render category }}
<SearchMenu::Results::AssistantItem
@category={{result.model}}
@slug={{get this.fullSlugForCategoryMap result.model.id}}
@withInLabel={{@withInLabel}}
@searchAllTopics={{true}}
@closeSearchMenu={{@closeSearchMenu}}
@searchTermChanged={{@searchTermChanged}}
@suggestionKeyword={{@suggestionKeyword}}
/>
{{else}}
{{! render tag }}
<SearchMenu::Results::AssistantItem
@tag={{result.name}}
@slug={{concat this.prefix "#" result.name}}
@withInLabel={{@withInLabel}}
@searchAllTopics={{true}}
@closeSearchMenu={{@closeSearchMenu}}
@searchTermChanged={{@searchTermChanged}}
@suggestionKeyword={{@suggestionKeyword}}
@ -43,6 +48,7 @@
@user={{this.user}}
@slug={{concat this.prefix "@" this.user.username}}
@suffix={{i18n "search.in_topics_posts"}}
@searchAllTopics={{true}}
@closeSearchMenu={{@closeSearchMenu}}
@searchTermChanged={{@searchTermChanged}}
@suggestionKeyword={{@suggestionKeyword}}
@ -61,6 +67,7 @@
<SearchMenu::Results::AssistantItem
@user={{result}}
@slug={{concat this.prefix "@" result.username}}
@searchAllTopics={{true}}
@closeSearchMenu={{@closeSearchMenu}}
@searchTermChanged={{@searchTermChanged}}
@suggestionKeyword={{@suggestionKeyword}}
@ -72,6 +79,7 @@
<SearchMenu::Results::AssistantItem
@slug={{concat this.prefix item}}
@label={{item}}
@searchAllTopics={{true}}
@closeSearchMenu={{@closeSearchMenu}}
@searchTermChanged={{@searchTermChanged}}
@suggestionKeyword={{@suggestionKeyword}}

View File

@ -34,7 +34,6 @@
{{/if}}
{{else}}
<SearchMenu::Results::RandomQuickTip />
{{#if (and this.currentUser this.siteSettings.log_search_queries)}}
<SearchMenu::Results::RecentSearches
@closeSearchMenu={{@closeSearchMenu}}

View File

@ -653,6 +653,48 @@ acceptance("Search - Glimmer - with tagging enabled", function (needs) {
experimental_search_menu_groups_enabled: true,
});
needs.settings({ tagging_enabled: true });
needs.pretender((server, helper) => {
server.get("/tag/dev/notifications", () => {
return helper.response({
tag_notification: { id: "dev", notification_level: 2 },
});
});
server.get("/tags/c/bug/1/dev/l/latest.json", () => {
return helper.response({
users: [],
primary_groups: [],
topic_list: {
can_create_topic: true,
draft: null,
draft_key: "new_topic",
draft_sequence: 1,
per_page: 30,
tags: [
{
id: 1,
name: "dev",
topic_count: 1,
},
],
topics: [],
},
});
});
server.get("/tags/intersection/dev/foo.json", () => {
return helper.response({
topic_list: {
can_create_topic: true,
draft: null,
draft_key: "new_topic",
draft_sequence: 1,
per_page: 30,
topics: [],
},
});
});
});
test("topic results - displays tags", async function (assert) {
await visit("/");
@ -669,6 +711,18 @@ acceptance("Search - Glimmer - with tagging enabled", function (needs) {
);
});
test("initial options - topic search scope - selecting a tag defaults to searching 'in all topics'", async function (assert) {
await visit("/t/internationalization-localization/280/1");
await click("#search-button");
await fillIn("#search-term", "#dev");
await click(
".search-menu .results .search-menu-assistant .search-menu-assistant-item:nth-child(1)"
);
assert
.dom(".search-input .btn.search-context")
.doesNotExist("'in this topic' button is not shown");
});
test("initial results - displays tag shortcuts", async function (assert) {
await visit("/");
await click("#search-button");
@ -681,6 +735,85 @@ acceptance("Search - Glimmer - with tagging enabled", function (needs) {
const firstTag = query(`${firstItem} .search-item-tag`).textContent.trim();
assert.strictEqual(firstTag, "monkey");
});
test("initial options - tag search scope - shows category / tag combination shortcut when both are present", async function (assert) {
await visit("/tags/c/bug/dev");
await click("#search-button");
assert.strictEqual(
query(".search-menu .results ul.search-menu-assistant .category-name")
.innerText,
"bug",
"Category is displayed"
);
assert.strictEqual(
query(".search-menu .results ul.search-menu-assistant .search-item-tag")
.innerText,
"dev",
"Tag is displayed"
);
});
test("initial options - tag and category search scope - updates tag / category combination search suggestion when typing", async function (assert) {
await visit("/tags/c/bug/dev");
await click("#search-button");
await fillIn("#search-term", "foo bar");
assert.strictEqual(
query(
".search-menu .results ul.search-menu-assistant .search-item-prefix"
).innerText,
"foo bar",
"Input is applied to search query"
);
assert.strictEqual(
query(".search-menu .results ul.search-menu-assistant .category-name")
.innerText,
"bug"
);
assert.strictEqual(
query(".search-menu .results ul.search-menu-assistant .search-item-tag")
.innerText,
"dev",
"Tag is displayed"
);
});
test("initial options - tag intersection search scope - shows tag combination shortcut when visiting tag intersection", async function (assert) {
await visit("/tags/intersection/dev/foo");
await click("#search-button");
assert.strictEqual(
query(".search-menu .results ul.search-menu-assistant .search-item-tag")
.innerText,
"tags:dev+foo",
"Tags are displayed"
);
});
test("initial options - tag intersection search scope - updates tag intersection search suggestion when typing", async function (assert) {
await visit("/tags/intersection/dev/foo");
await click("#search-button");
await fillIn("#search-term", "foo bar");
assert.strictEqual(
query(
".search-menu .results ul.search-menu-assistant .search-item-prefix"
).innerText,
"foo bar",
"Input is applied to search query"
);
assert.strictEqual(
query(".search-menu .results ul.search-menu-assistant .search-item-tag")
.innerText,
"tags:dev+foo",
"Tags are displayed"
);
});
});
acceptance("Search - Glimmer - assistant", function (needs) {
@ -830,47 +963,6 @@ acceptance("Search - Glimmer - assistant", function (needs) {
return helper.response(searchFixtures["search/query"]);
});
server.get("/tag/dev/notifications", () => {
return helper.response({
tag_notification: { id: "dev", notification_level: 2 },
});
});
server.get("/tags/c/bug/1/dev/l/latest.json", () => {
return helper.response({
users: [],
primary_groups: [],
topic_list: {
can_create_topic: true,
draft: null,
draft_key: "new_topic",
draft_sequence: 1,
per_page: 30,
tags: [
{
id: 1,
name: "dev",
topic_count: 1,
},
],
topics: [],
},
});
});
server.get("/tags/intersection/dev/foo.json", () => {
return helper.response({
topic_list: {
can_create_topic: true,
draft: null,
draft_key: "new_topic",
draft_sequence: 1,
per_page: 30,
topics: [],
},
});
});
server.get("/u/search/users", () => {
return helper.response({
users: [
@ -910,85 +1002,6 @@ acceptance("Search - Glimmer - assistant", function (needs) {
);
});
test("initial options - tag search scope - shows category / tag combination shortcut when both are present", async function (assert) {
await visit("/tags/c/bug/dev");
await click("#search-button");
assert.strictEqual(
query(".search-menu .results ul.search-menu-assistant .category-name")
.innerText,
"bug",
"Category is displayed"
);
assert.strictEqual(
query(".search-menu .results ul.search-menu-assistant .search-item-tag")
.innerText,
"dev",
"Tag is displayed"
);
});
test("initial options - tag and category search scope - updates tag / category combination search suggestion when typing", async function (assert) {
await visit("/tags/c/bug/dev");
await click("#search-button");
await fillIn("#search-term", "foo bar");
assert.strictEqual(
query(
".search-menu .results ul.search-menu-assistant .search-item-prefix"
).innerText,
"foo bar",
"Input is applied to search query"
);
assert.strictEqual(
query(".search-menu .results ul.search-menu-assistant .category-name")
.innerText,
"bug"
);
assert.strictEqual(
query(".search-menu .results ul.search-menu-assistant .search-item-tag")
.innerText,
"dev",
"Tag is displayed"
);
});
test("initial options - tag intersection search scope - shows tag combination shortcut when visiting tag intersection", async function (assert) {
await visit("/tags/intersection/dev/foo");
await click("#search-button");
assert.strictEqual(
query(".search-menu .results ul.search-menu-assistant .search-item-tag")
.innerText,
"tags:dev+foo",
"Tags are displayed"
);
});
test("initial options - tag intersection search scope - updates tag intersection search suggestion when typing", async function (assert) {
await visit("/tags/intersection/dev/foo");
await click("#search-button");
await fillIn("#search-term", "foo bar");
assert.strictEqual(
query(
".search-menu .results ul.search-menu-assistant .search-item-prefix"
).innerText,
"foo bar",
"Input is applied to search query"
);
assert.strictEqual(
query(".search-menu .results ul.search-menu-assistant .search-item-tag")
.innerText,
"tags:dev+foo",
"Tags are displayed"
);
});
test("initial options - shows in: shortcuts", async function (assert) {
await visit("/");
await click("#search-button");
@ -1032,6 +1045,19 @@ acceptance("Search - Glimmer - assistant", function (needs) {
assert.strictEqual(query("#search-term").value, `@${firstUsername}`);
});
test("initial options - topic search scope - selecting a tag defaults to searching 'in all topics'", async function (assert) {
await visit("/t/internationalization-localization/280/1");
await click("#search-button");
await fillIn("#search-term", "@");
await click(
".search-menu .results .search-menu-assistant .search-menu-assistant-item:nth-child(1)"
);
assert
.dom(".search-input .btn.search-context")
.doesNotExist("'in this topic' button is not shown");
});
test("initial options - private message search scope - shows 'in messages' button when in an inbox", async function (assert) {
await visit("/u/charlie/messages");
await click("#search-button");