From 6585f0c182b637f6a0efb9722383196f765ca90a Mon Sep 17 00:00:00 2001 From: Tim Macdonald <tim@metabase.com> Date: Mon, 14 Aug 2023 11:53:58 +0100 Subject: [PATCH] Search by table description (#33089) * Search by table description [Fixes #25792] --- .../onboarding/search/search.cy.spec.js | 8 ++-- src/metabase/search/config.clj | 3 +- test/metabase/api/search_test.clj | 40 +++++++++++-------- 3 files changed, 30 insertions(+), 21 deletions(-) diff --git a/e2e/test/scenarios/onboarding/search/search.cy.spec.js b/e2e/test/scenarios/onboarding/search/search.cy.spec.js index b81143c62d3..13fd5a1ef81 100644 --- a/e2e/test/scenarios/onboarding/search/search.cy.spec.js +++ b/e2e/test/scenarios/onboarding/search/search.cy.spec.js @@ -86,9 +86,11 @@ describe("scenarios > search", () => { cy.get("@searchBox").type("{enter}"); cy.wait("@search"); - cy.findByTestId("search-result-item").within(() => { - getProductsSearchResults(); - }); + cy.findAllByTestId("search-result-item") + .first() + .within(() => { + getProductsSearchResults(); + }); }); it("should work for user with permissions (metabase#12332)", () => { diff --git a/src/metabase/search/config.clj b/src/metabase/search/config.clj index 012887f29a9..41c7e1b5473 100644 --- a/src/metabase/search/config.clj +++ b/src/metabase/search/config.clj @@ -101,7 +101,8 @@ (defmethod searchable-columns-for-model "table" [_] [:name - :display_name]) + :display_name + :description]) (defmethod searchable-columns-for-model "indexed-entity" [_] diff --git a/test/metabase/api/search_test.clj b/test/metabase/api/search_test.clj index bd766527953..5609c9ef397 100644 --- a/test/metabase/api/search_test.clj +++ b/test/metabase/api/search_test.clj @@ -322,8 +322,8 @@ (mt/with-temp* [PermissionsGroup [group] PermissionsGroupMembership [_ {:user_id (mt/user->id :rasta), :group_id (u/the-id group)}]] (perms/grant-permissions! group (perms/collection-read-path {:metabase.models.collection.root/is-root? true})) - (is (= (remove (comp #{"collection"} :model) (default-search-results)) - (search-request-data :rasta :q "test"))))))) + (is (ordered-subset? (remove (comp #{"collection"} :model) (default-search-results)) + (search-request-data :rasta :q "test"))))))) (testing "Users without root collection permissions should still see other collections they have access to" (mt/with-non-admin-groups-no-root-collection-perms @@ -350,14 +350,14 @@ PermissionsGroupMembership [_ {:user_id (mt/user->id :rasta), :group_id (u/the-id group)}]] (perms/grant-permissions! group (perms/collection-read-path {:metabase.models.collection.root/is-root? true})) (perms/grant-collection-read-permissions! group collection) - (is (= (sorted-results - (reverse - (into - (default-results-with-collection) - (for [row (default-search-results) - :when (not= "collection" (:model row))] - (update row :name #(str/replace % "test" "test2")))))) - (search-request-data :rasta :q "test")))))))) + (is (ordered-subset? (sorted-results + (reverse + (into + (default-results-with-collection) + (for [row (default-search-results) + :when (not= "collection" (:model row))] + (update row :name #(str/replace % "test" "test2")))))) + (search-request-data :rasta :q "test")))))))) (testing "Users with access to multiple collections should see results from all collections they have access to" (with-search-items-in-collection {coll-1 :collection} "test" @@ -366,13 +366,13 @@ PermissionsGroupMembership [_ {:user_id (mt/user->id :rasta), :group_id (u/the-id group)}]] (perms/grant-collection-read-permissions! group (u/the-id coll-1)) (perms/grant-collection-read-permissions! group (u/the-id coll-2)) - (is (= (sorted-results - (reverse - (into - (default-results-with-collection) - (map (fn [row] (update row :name #(str/replace % "test" "test2"))) - (default-results-with-collection))))) - (search-request-data :rasta :q "test"))))))) + (is (ordered-subset? (sorted-results + (reverse + (into + (default-results-with-collection) + (map (fn [row] (update row :name #(str/replace % "test" "test2"))) + (default-results-with-collection))))) + (search-request-data :rasta :q "test"))))))) (testing "User should only see results in the collection they have access to" (mt/with-non-admin-groups-no-root-collection-perms @@ -618,6 +618,12 @@ (do-test-users [user [:crowberto :rasta]] (is (= [(assoc (default-table-search-row "RoundTable") :name lancelot)] (search-request-data user :q "Lancelot"))))))) + (testing "You should be able to search by their description" + (let [lancelot "Lancelot's Favorite Furniture"] + (t2.with-temp/with-temp [Table _ {:name "RoundTable" :description lancelot}] + (do-test-users [user [:crowberto :rasta]] + (is (= [(assoc (default-table-search-row "RoundTable") :description lancelot :table_description lancelot)] + (search-request-data user :q "Lancelot"))))))) (testing "When searching with ?archived=true, normal Tables should not show up in the results" (let [table-name (mt/random-name)] (t2.with-temp/with-temp [Table _ {:name table-name}] -- GitLab