From 6646ee3046e7d0bdcd715a9cfa0e0dce6e368cf2 Mon Sep 17 00:00:00 2001 From: Arpit Jalan Date: Wed, 18 Aug 2021 05:48:06 +0530 Subject: [PATCH] FIX: if the category slug is not present then search via ID (#14060) --- .../app/components/search-advanced-options.js | 8 +++++-- .../tests/acceptance/search-full-test.js | 24 +++++++++++++++++++ .../discourse/tests/fixtures/site-fixtures.js | 17 +++++++++++++ .../select-kit/category-chooser-test.js | 2 +- 4 files changed, 48 insertions(+), 3 deletions(-) diff --git a/app/assets/javascripts/discourse/app/components/search-advanced-options.js b/app/assets/javascripts/discourse/app/components/search-advanced-options.js index 5b72e095f46..0bcb5007f34 100644 --- a/app/assets/javascripts/discourse/app/components/search-advanced-options.js +++ b/app/assets/javascripts/discourse/app/components/search-advanced-options.js @@ -527,8 +527,10 @@ export default Component.extend({ idCategoryMatches[0], `category:${id}` ); - } else { + } else if (slug) { searchTerm += ` #${parentSlug}:${slug}`; + } else { + searchTerm += ` category:${id}`; } this._updateSearchTerm(searchTerm); @@ -540,8 +542,10 @@ export default Component.extend({ idCategoryMatches[0], `category:${id}` ); - } else { + } else if (slug) { searchTerm += ` #${slug}`; + } else { + searchTerm += ` category:${id}`; } this._updateSearchTerm(searchTerm); diff --git a/app/assets/javascripts/discourse/tests/acceptance/search-full-test.js b/app/assets/javascripts/discourse/tests/acceptance/search-full-test.js index 04e1fe1eba9..483f01cae0b 100644 --- a/app/assets/javascripts/discourse/tests/acceptance/search-full-test.js +++ b/app/assets/javascripts/discourse/tests/acceptance/search-full-test.js @@ -203,6 +203,30 @@ acceptance("Search - Full Page", function (needs) { ); }); + test("update category without slug through advanced search ui", async function (assert) { + const categoryChooser = selectKit( + ".search-advanced-options .category-chooser" + ); + + await visit("/search"); + + await fillIn(".search-query", "none"); + + await categoryChooser.expand(); + await categoryChooser.fillInFilter("快乐的"); + await categoryChooser.selectRowByValue(240); + + assert.ok( + exists('.search-advanced-options .badge-category:contains("快乐的")'), + 'has "快乐的" populated' + ); + assert.equal( + queryAll(".search-query").val(), + "none category:240", + 'has updated search term to "none category:240"' + ); + }); + test("update in:title filter through advanced search ui", async function (assert) { await visit("/search"); await fillIn(".search-query", "none"); diff --git a/app/assets/javascripts/discourse/tests/fixtures/site-fixtures.js b/app/assets/javascripts/discourse/tests/fixtures/site-fixtures.js index 2b0ee1a1d74..68488ba5f9e 100644 --- a/app/assets/javascripts/discourse/tests/fixtures/site-fixtures.js +++ b/app/assets/javascripts/discourse/tests/fixtures/site-fixtures.js @@ -421,6 +421,23 @@ export default { default_view: "latest", subcategory_list_style: "boxes", }, + { + id: 240, + name: "快乐的", + color: "0E78BD", + text_color: "FFFFFF", + slug: "", + topic_count: 137, + post_count: 1142, + description: "关于幸福的讨论", + topic_url: "/t/category-definition-for-快乐的/11", + read_restricted: false, + permission: 1, + notification_level: null, + show_subcategory_list: true, + default_view: "latest", + subcategory_list_style: "boxes", + }, ], post_action_types: [ { diff --git a/app/assets/javascripts/discourse/tests/integration/components/select-kit/category-chooser-test.js b/app/assets/javascripts/discourse/tests/integration/components/select-kit/category-chooser-test.js index b3e18a6e302..e0446a7a156 100644 --- a/app/assets/javascripts/discourse/tests/integration/components/select-kit/category-chooser-test.js +++ b/app/assets/javascripts/discourse/tests/integration/components/select-kit/category-chooser-test.js @@ -113,7 +113,7 @@ discourseModule( assert.equal( this.subject.rows().length, - 20, + 21, "all categories are visible" );