A platform for community discussion. Free, open, simple.
FIX: Count only users when switching from related post results (#43768)
Alan Guo Xiang Tan08f039713283
diff --git a/frontend/discourse/app/controllers/full-page-search.js b/frontend/discourse/app/controllers/full-page-search.jsindex 3a6d29fe1ce..e1eb7f6598e 100644--- a/frontend/discourse/app/controllers/full-page-search.js+++ b/frontend/discourse/app/controllers/full-page-search.js@@ -371,8 +371,17 @@ export default class FullPageSearchController extends Controller {: "search-info";}- @computed("model.posts", "additionalSearchResults")+ @computed(+ "model.posts",+ "additionalSearchResults",+ "usingDefaultSearchType",+ "customSearchType"+ )get searchResultPosts() {+ if (!this.usingDefaultSearchType && !this.customSearchType) {+ return [];+ }+if (this.additionalSearchResults?.list?.length > 0) {// a search type that renders its own results need not produce posts at// all, and ranking against a list that is not there throwsdiff --git a/frontend/discourse/tests/unit/controllers/full-page-search-test.js b/frontend/discourse/tests/unit/controllers/full-page-search-test.jsindex bc4cedc01d7..fac88a283f9 100644--- a/frontend/discourse/tests/unit/controllers/full-page-search-test.js+++ b/frontend/discourse/tests/unit/controllers/full-page-search-test.js@@ -1,10 +1,46 @@+import { settled } from "@ember/test-helpers";import { setupTest } from "ember-qunit";import { module, test } from "qunit";+import { SEARCH_TYPE_USERS } from "discourse/controllers/full-page-search";import { withPluginApi } from "discourse/lib/plugin-api";module("Unit | Controller | full-page-search", function (hooks) {setupTest(hooks);+ test("excludes supplemental posts from the Users result count", async function (assert) {+ const controller = this.owner.lookup("controller:full-page-search");+ controller.set("model", {+ posts: [],+ categories: [],+ tags: [],+ users: [{ id: 1 }, { id: 2 }],+ });+ controller.addSearchResults([{ id: 1, topic_id: 1 }], "topic_id");+ await settled();++ assert.strictEqual(+ controller.resultCount,+ 3,+ "Posts includes supplemental results"+ );++ controller.setSearchType(SEARCH_TYPE_USERS);+ await settled();+ assert.strictEqual(+ controller.resultCount,+ 2,+ "Users counts only matching users"+ );++ controller.set("model.users", []);+ await settled();+ assert.strictEqual(+ controller.resultCount,+ 0,+ "Users excludes supplemental posts when empty"+ );+ });+test("full-page-search-load-more behavior transformer", function (assert) {withPluginApi((api) => {const controller = this.owner.lookup("controller:full-page-search");