From daf8c32d0e9cfd9cd1465e72853fa8bfe90194f1 Mon Sep 17 00:00:00 2001
From: Isaac Janzen <50783505+janzenisaac@users.noreply.github.com>
Date: Fri, 8 Sep 2023 12:20:55 -0500
Subject: [PATCH] FIX: Render 'In topic context' search results at the correct
time (#23481)
---
.../search-menu/results/assistant.hbs | 8 +
.../search-menu/results/initial-options.hbs | 1 -
.../tests/acceptance/glimmer-search-test.js | 266 ++++++++++--------
3 files changed, 154 insertions(+), 121 deletions(-)
diff --git a/app/assets/javascripts/discourse/app/components/search-menu/results/assistant.hbs b/app/assets/javascripts/discourse/app/components/search-menu/results/assistant.hbs
index bc29ae86a2b..603ac888ab9 100644
--- a/app/assets/javascripts/discourse/app/components/search-menu/results/assistant.hbs
+++ b/app/assets/javascripts/discourse/app/components/search-menu/results/assistant.hbs
@@ -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 }}
{{else}}
+ {{! render tag }}
-
{{#if (and this.currentUser this.siteSettings.log_search_queries)}}
{
+ 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");