diff --git a/app/assets/javascripts/discourse/app/components/search-menu.hbs b/app/assets/javascripts/discourse/app/components/search-menu.hbs index 3a98b0c2b08..c10cfe633c2 100644 --- a/app/assets/javascripts/discourse/app/components/search-menu.hbs +++ b/app/assets/javascripts/discourse/app/components/search-menu.hbs @@ -55,7 +55,6 @@ { + this.search.results.resultTypes?.map((resultType) => { content.push({ ...resultType, component: SEARCH_RESULTS_COMPONENT_TYPE[resultType.componentName], diff --git a/app/assets/javascripts/discourse/app/services/search.js b/app/assets/javascripts/discourse/app/services/search.js index 0b9a3419d7e..d50a5b5b4ee 100644 --- a/app/assets/javascripts/discourse/app/services/search.js +++ b/app/assets/javascripts/discourse/app/services/search.js @@ -13,6 +13,7 @@ export default class Search extends Service { @tracked highlightTerm; @tracked inTopicContext = false; @tracked visible = false; + @tracked results = {}; // only relative for the widget search menu searchContextEnabled = false; // checkbox to scope search diff --git a/app/assets/javascripts/discourse/tests/acceptance/glimmer-search-test.js b/app/assets/javascripts/discourse/tests/acceptance/glimmer-search-test.js index ba80be06a20..9cd352d6744 100644 --- a/app/assets/javascripts/discourse/tests/acceptance/glimmer-search-test.js +++ b/app/assets/javascripts/discourse/tests/acceptance/glimmer-search-test.js @@ -440,7 +440,16 @@ acceptance("Search - Glimmer - Authenticated", function (needs) { needs.pretender((server, helper) => { server.get("/search/query", (request) => { - if (request.queryParams.term.includes("empty")) { + if (request.queryParams.type_filter === DEFAULT_TYPE_FILTER) { + // posts/topics are not present in the payload by default + return helper.response({ + users: searchFixtures["search/query"]["users"], + categories: searchFixtures["search/query"]["categories"], + groups: searchFixtures["search/query"]["groups"], + grouped_search_result: + searchFixtures["search/query"]["grouped_search_result"], + }); + } else if (request.queryParams.term.includes("empty")) { return helper.response({ posts: [], users: [], @@ -464,9 +473,9 @@ acceptance("Search - Glimmer - Authenticated", function (needs) { group_ids: [], }, }); + } else { + return helper.response(searchFixtures["search/query"]); } - - return helper.response(searchFixtures["search/query"]); }); server.get("/inline-onebox", () => @@ -736,6 +745,20 @@ acceptance("Search - Glimmer - with tagging enabled", function (needs) { needs.user(); needs.settings({ tagging_enabled: true }); needs.pretender((server, helper) => { + server.get("/search/query", (request) => { + if (request.queryParams.type_filter === DEFAULT_TYPE_FILTER) { + // posts/topics are not present in the payload by default + return helper.response({ + users: searchFixtures["search/query"]["users"], + categories: searchFixtures["search/query"]["categories"], + groups: searchFixtures["search/query"]["groups"], + grouped_search_result: + searchFixtures["search/query"]["grouped_search_result"], + }); + } + return helper.response(searchFixtures["search/query"]); + }); + server.get("/tag/dev/notifications", () => { return helper.response({ tag_notification: { id: "dev", notification_level: 2 }, @@ -903,6 +926,9 @@ acceptance("Search - Glimmer - with tagging enabled", function (needs) { acceptance("Search - Glimmer - assistant", function (needs) { needs.user(); needs.pretender((server, helper) => { + server.get("/t/2179.json", () => { + return helper.response({}); + }); server.get("/search/query", (request) => { if (request.queryParams["search_context[type]"] === "private_messages") { // return only one result for PM search @@ -1185,4 +1211,18 @@ acceptance("Search - Glimmer - assistant", function (needs) { `sam #${firstCategoryName}` ); }); + + test("topic results - soft loads the topic results after closing then search menu", async function (assert) { + await visit("/"); + await click("#search-button"); + await fillIn("#search-term", "Development mode"); + + // navigate to topic and close search menu + const firstTopicResult = ".search-menu .results .search-result-topic a"; + await click(firstTopicResult); + + // reopen search menu and previous search results are present + await click("#search-button"); + assert.dom(firstTopicResult).exists(); + }); }); diff --git a/app/assets/javascripts/discourse/tests/integration/components/search-menu-test.gjs b/app/assets/javascripts/discourse/tests/integration/components/search-menu-test.gjs index 7939548f3c6..b03c92fb9f3 100644 --- a/app/assets/javascripts/discourse/tests/integration/components/search-menu-test.gjs +++ b/app/assets/javascripts/discourse/tests/integration/components/search-menu-test.gjs @@ -1,7 +1,11 @@ import { click, fillIn, render, triggerKeyEvent } from "@ember/test-helpers"; import { module, test } from "qunit"; -import SearchMenu from "discourse/components/search-menu"; +import SearchMenu, { + DEFAULT_TYPE_FILTER, +} from "discourse/components/search-menu"; +import searchFixtures from "discourse/tests/fixtures/search-fixtures"; import { setupRenderingTest } from "discourse/tests/helpers/component-test"; +import pretender, { response } from "discourse/tests/helpers/create-pretender"; import { exists, query } from "discourse/tests/helpers/qunit-helpers"; import I18n from "discourse-i18n"; @@ -12,6 +16,20 @@ module("Integration | Component | search-menu", function (hooks) { setupRenderingTest(hooks); test("rendering standalone", async function (assert) { + pretender.get("/search/query", (request) => { + if (request.queryParams.type_filter === DEFAULT_TYPE_FILTER) { + // posts/topics are not present in the payload by default + return response({ + users: searchFixtures["search/query"]["users"], + categories: searchFixtures["search/query"]["categories"], + groups: searchFixtures["search/query"]["groups"], + grouped_search_result: + searchFixtures["search/query"]["grouped_search_result"], + }); + } + return response(searchFixtures["search/query"]); + }); + await render(); assert.ok(