Skip to content

The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:

Consolidate search e2e tests (#83454)

Chris Vandoodewaardbff0c3ba6106
diff --git a/e2e/support/helpers/e2e-search-helpers.js b/e2e/support/helpers/e2e-search-helpers.js
index a96e045b009..036b5d6f015 100644
--- a/e2e/support/helpers/e2e-search-helpers.js
+++ b/e2e/support/helpers/e2e-search-helpers.js
@@ -43,9 +43,9 @@ export function expectSearchResultContent({
}
if (expectedSearchResult.collection) {
- cy.findAllByTestId("result-link-wrapper").first(() => {
- cy.findByText(expectedSearchResult.collection).should("exist");
- });
+ cy.findAllByTestId("result-link-wrapper")
+ .first()
+ .should("contain.text", expectedSearchResult.collection);
}
if (expectedSearchResult.timestamp) {
cy.findByTestId("revision-history-text").findByText(
diff --git a/e2e/test/scenarios/search/recently-viewed.cy.spec.js b/e2e/test/scenarios/search/recently-viewed.cy.spec.js
index 522670ff5ee..8d35d2e4f37 100644
--- a/e2e/test/scenarios/search/recently-viewed.cy.spec.js
+++ b/e2e/test/scenarios/search/recently-viewed.cy.spec.js
@@ -40,28 +40,25 @@ describe("search > recently viewed", () => {
cy.findByTestId("loading-indicator").should("not.exist");
});
- it("shows list of recently viewed items", () => {
+ it("shows an up-to-date list of recently viewed items, and allows to select an item from keyboard (metabase#36868)", () => {
+ cy.findByTestId("recents-list-container").findByText("Recently viewed");
assertRecentlyViewedItem(0, "Orders in a dashboard", "Dashboard");
assertRecentlyViewedItem(1, "Orders", "Question");
assertRecentlyViewedItem(2, "People", "Table");
- });
- it("allows to select an item from keyboard", () => {
- cy.findByTestId("recents-list-container").findByText("Recently viewed");
+ cy.intercept("POST", "/api/card/*/query").as("cardQuery");
+ advanceServerClockBy(100);
cy.get("body").trigger("keydown", { key: "ArrowDown" });
cy.get("body").trigger("keydown", { key: "ArrowDown" });
cy.get("body").trigger("keydown", { key: "Enter" });
cy.url().should("match", /\/question\/\d+-orders$/);
- });
+ cy.wait("@cardQuery");
- it("shows up-to-date list of recently viewed items after another page is visited (metabase#36868)", () => {
cy.findByPlaceholderText("Search…").click();
cy.wait("@recent");
- cy.findByTestId("loading-indicator").should("not.exist");
- assertRecentlyViewedItem(0, "Orders in a dashboard", "Dashboard");
- assertRecentlyViewedItem(1, "Orders", "Question");
+ assertRecentlyViewedItem(0, "Orders", "Question");
assertRecentlyViewedItem(2, "People", "Table");
cy.intercept("/api/dataset").as("dataset");
@@ -93,10 +90,9 @@ describe("Recently Viewed > Entity Picker", () => {
H.popover().findByText("Dashboard").click();
cy.findByTestId("collection-picker-button").click();
- H.entityPickerModal().within(() => {
- cy.findByText("Select a collection").click();
- cy.findByText("My Fresh Collection");
- });
+ H.entityPickerModalItem(1, "My Fresh Collection").should("be.visible");
+ H.entityPickerModalItem(0, "Recent items").click();
+ H.entityPickerModalItem(1, "My Fresh Collection").should("be.visible");
});
it("shows recently visited dashboard in entity picker", () => {
@@ -117,6 +113,35 @@ describe("Recently Viewed > Entity Picker", () => {
cy.findByTestId("dashboard-header-container").findByText(
/You're editing this dashboard/,
);
+ H.saveDashboard();
+
+ H.createDashboard({ name: "My Fresh Dashboard" }).then(
+ ({ body: { id: dashboardId } }) => {
+ H.visitDashboard(dashboardId);
+ H.visitQuestion(ORDERS_QUESTION_ID);
+
+ cy.findByTestId("qb-header").icon("ellipsis").click();
+ H.popover().findByText("Add to dashboard").click();
+
+ H.entityPickerModal().within(() => {
+ cy.findByText("Add this question to a dashboard").should(
+ "be.visible",
+ );
+ cy.button("Select").should("be.enabled");
+ cy.findByText("Recent items").click();
+ cy.contains(
+ "[data-testid=result-item]",
+ "My Fresh Dashboard",
+ ).click();
+ cy.button("Select").click();
+ });
+
+ cy.url().should("contain", `/dashboard/${dashboardId}-`);
+ cy.findByTestId("dashboard-header-container").findByText(
+ /You're editing this dashboard/,
+ );
+ },
+ );
});
});
diff --git a/e2e/test/scenarios/search/search-filters.cy.spec.js b/e2e/test/scenarios/search/search-filters.cy.spec.js
index 3d5fc2ed73a..89161519bb0 100644
--- a/e2e/test/scenarios/search/search-filters.cy.spec.js
+++ b/e2e/test/scenarios/search/search-filters.cy.spec.js
@@ -92,17 +92,12 @@ describe("scenarios > search", () => {
describe("applying search filters", () => {
describe("no filters", () => {
- it("hydrating search from URL", () => {
- cy.visit("/search?q=orders");
+ it("hydrates the search page and the command palette search from the URL (#71248)", () => {
+ cy.visit("/search?q=products");
cy.wait("@search");
cy.findByTestId("search-app").within(() => {
- cy.findByText('Results for "orders"').should("exist");
+ cy.findByText('Results for "products"').should("exist");
});
- });
-
- it("hydrates the command palette search from the URL (#71248)", () => {
- cy.visit("/search?q=products");
- cy.wait("@search");
H.commandPaletteButton().should("contain.text", "products");
cy.intercept("GET", "/api/search?q=products*").as("paletteSearch");
@@ -177,78 +172,64 @@ describe("scenarios > search", () => {
});
});
- typeFilters.forEach(({ label, type }) => {
- it(`should hydrate search with search text and ${label} filter`, () => {
- cy.visit(`/search?q=e&type=${type}`);
- cy.wait("@search");
-
- cy.findByTestId("search-app").within(() => {
- cy.findByText('Results for "e"').should("exist");
- });
-
+ it("should filter results by each type, hydrate the filter from the URL, and remove it with `X`", () => {
+ typeFilters.forEach(({ label, type }) => {
const regex = new RegExp(`${type}$`);
- cy.findAllByTestId("search-result-item").each((result) => {
- cy.wrap(result)
- .should("have.attr", "aria-label")
- .and("match", regex);
- });
-
- cy.findByTestId("type-search-filter").within(() => {
- cy.findByText(label).should("exist");
- cy.findByLabelText("close icon").should("exist");
- });
- });
+ const expectResultsOfType = () => {
+ cy.findAllByTestId("search-result-item").each((result) => {
+ cy.wrap(result)
+ .should("have.attr", "aria-label")
+ .and("match", regex);
+ });
+ };
- it(`should filter results by ${label}`, () => {
+ cy.intercept("GET", "/api/search?q=*").as(`search-${type}`);
cy.visit("/");
H.commandPaletteSearch("e");
- cy.wait("@search");
+ cy.wait(`@search-${type}`);
cy.findByTestId("type-search-filter").click();
H.popover().within(() => {
cy.findByText(label).click();
cy.findByText("Apply").click();
});
+ cy.url().should("contain", `type=${type}`);
+ expectResultsOfType();
- const regex = new RegExp(`${type}$`);
- cy.findAllByTestId("search-result-item").each((result) => {
- cy.wrap(result)
- .should("have.attr", "aria-label")
- .and("match", regex);
- });
- });
- });
+ cy.intercept("GET", "/api/search?q=*").as(`hydratedSearch-${type}`);
+ cy.visit(`/search?q=e&type=${type}`);
+ cy.wait(`@hydratedSearch-${type}`);
- it("should remove type filter when `X` is clicked on search filter", () => {
- const { label, type } = typeFilters[0];
- cy.visit(`/search?q=e&type=${type}`);
- cy.wait("@search");
+ cy.findByTestId("search-app").within(() => {
+ cy.findByText('Results for "e"').should("exist");
+ });
+ expectResultsOfType();
- cy.findByTestId("type-search-filter").within(() => {
- cy.findByText(label).should("exist");
- cy.findByLabelText("close icon").click();
- cy.findByText(label).should("not.exist");
- cy.findByText("Content type").should("exist");
- });
+ cy.findByTestId("type-search-filter").within(() => {
+ cy.findByText(label).should("exist");
+ cy.findByLabelText("close icon").click();
+ cy.findByText(label).should("not.exist");
+ cy.findByText("Content type").should("exist");
+ });
- cy.url().should("not.contain", "type");
+ cy.url().should("not.contain", "type");
- cy.findAllByTestId("search-result-item").then(($results) => {
- const uniqueResults = new Set(
- $results.toArray().map((el) => {
- const label = el.getAttribute("aria-label");
- return label.split(" ").slice(-1)[0];
- }),
- );
- expect(uniqueResults.size).to.be.greaterThan(1);
+ cy.findAllByTestId("search-result-item").should(($results) => {
+ const uniqueResults = new Set(
+ $results.toArray().map((el) => {
+ const label = el.getAttribute("aria-label");
+ return label.split(" ").slice(-1)[0];
+ }),
+ );
+ expect(uniqueResults.size).to.be.greaterThan(1);
+ });
});
});
});
describe("created_by filter", () => {
beforeEach(() => {
- H.restore();
// create a question from a normal and admin user, then we can query the question
// created by that user as an admin
cy.signInAsNormalUser();
@@ -259,18 +240,31 @@ describe("scenarios > search", () => {
H.createQuestion(ADMIN_TEST_QUESTION);
});
- it("should hydrate created_by filter", () => {
- cy.visit(
- `/search?created_by=${ADMIN_USER_ID}&created_by=${NORMAL_USER_ID}&q=reviews`,
- );
+ it("should filter results by one or more creators and Today, hydrate the date, and remove the filters with `X`", () => {
+ cy.then(() => {
+ cy.clock(Date.now(), ["Date"]);
+ });
+ cy.visit("/");
+ H.commandPaletteSearch("reviews");
cy.wait("@search");
- cy.findByTestId("created_by-search-filter").within(() => {
- cy.findByText("2 users selected").should("exist");
- cy.findByLabelText("close icon").should("exist");
+ expectSearchResultItemNameContent({
+ itemNames: [
+ NORMAL_USER_TEST_QUESTION.name,
+ ADMIN_TEST_QUESTION.name,
+ REVIEWS_TABLE_NAME,
+ ],
});
+ cy.findByTestId("created_by-search-filter").click();
+
+ H.popover().within(() => {
+ cy.findByText("Robert Tableton").click();
+ cy.findByText("Apply").click();
+ });
+ cy.url().should("contain", "created_by");
+
H.expectSearchResultContent({
expectedSearchResults: [
{
@@ -278,20 +272,14 @@ describe("scenarios > search", () => {
timestamp: "Created a few seconds ago by Robert Tableton",
collection: "Our analytics",
},
- {
- name: ADMIN_TEST_QUESTION.name,
- timestamp: "Created a few seconds ago by you",
- collection: "Our analytics",
- },
],
});
- });
- it("should filter results by one user", () => {
+ cy.intercept("GET", "/api/search?q=*").as("freshSearch");
cy.visit("/");
H.commandPaletteSearch("reviews");
- cy.wait("@search");
+ cy.wait("@freshSearch");
expectSearchResultItemNameContent({
itemNames: [
@@ -305,9 +293,10 @@ describe("scenarios > search", () => {
H.popover().within(() => {
cy.findByText("Robert Tableton").click();
+ cy.findByText("Bobby Tables").click();
cy.findByText("Apply").click();
});
- cy.url().should("contain", "created_by");
+ cy.url().should("contain", `created_by=${ADMIN_USER_ID}`);
H.expectSearchResultContent({
expectedSearchResults: [
@@ -316,15 +305,33 @@ describe("scenarios > search", () => {
timestamp: "Created a few seconds ago by Robert Tableton",
collection: "Our analytics",
},
+ {
+ name: ADMIN_TEST_QUESTION.name,
+ timestamp: "Created a few seconds ago by you",
+ collection: "Our analytics",
+ },
],
});
- });
- it("should filter results by more than one user", () => {
- cy.visit("/");
+ cy.intercept("GET", "/api/search?q=*").as("hydratedSearch");
+ cy.visit(`/search?q=reviews&created_by=${NORMAL_USER_ID}`);
+ cy.wait("@hydratedSearch");
- H.commandPaletteSearch("reviews");
- cy.wait("@search");
+ H.expectSearchResultContent({
+ expectedSearchResults: [
+ {
+ name: NORMAL_USER_TEST_QUESTION.name,
+ timestamp: "Created a few seconds ago by Robert Tableton",
+ collection: "Our analytics",
+ },
+ ],
+ });
+
+ cy.findByTestId("created_by-search-filter").within(() => {
+ cy.findByText("Robert Tableton").should("exist");
+ cy.findByLabelText("close icon").click();
+ });
+ cy.url().should("not.contain", "created_by");
expectSearchResultItemNameContent({
itemNames: [
@@ -334,38 +341,81 @@ describe("scenarios > search", () => {
],
});
- cy.findByTestId("created_by-search-filter").click();
+ cy.visit("/search?q=Reviews");
+
+ expectSearchResultItemNameContent(
+ {
+ itemNames: [REVIEWS_TABLE_NAME, NORMAL_USER_TEST_QUESTION.name],
+ },
+ { strict: false },
+ );
+ cy.findByTestId("created_at-search-filter").click();
H.popover().within(() => {
- cy.findByText("Robert Tableton").click();
- cy.findByText("Bobby Tables").click();
- cy.findByText("Apply").click();
+ cy.findByText("Today").click();
});
- cy.url().should("contain", "created_by");
+ cy.url().should("contain", "created_at=thisday");
+ cy.findByTestId("created_at-search-filter")
+ .findByText("Today")
+ .should("exist");
H.expectSearchResultContent({
expectedSearchResults: [
{
name: NORMAL_USER_TEST_QUESTION.name,
- timestamp: "Created a few seconds ago by Robert Tableton",
collection: "Our analytics",
+ timestamp: "Created a few seconds ago by Robert Tableton",
},
+ ],
+ strict: false,
+ });
+
+ cy.intercept("GET", "/api/search?q=*").as("createdAtHydratedSearch");
+ cy.visit("/search?q=Reviews&created_at=thisday");
+ cy.wait("@createdAtHydratedSearch");
+
+ H.expectSearchResultContent({
+ expectedSearchResults: [
{
- name: ADMIN_TEST_QUESTION.name,
- timestamp: "Created a few seconds ago by you",
+ name: NORMAL_USER_TEST_QUESTION.name,
collection: "Our analytics",
+ timestamp: "Created a few seconds ago by Robert Tableton",
},
],
+ strict: false,
});
+
+ cy.findByTestId("created_at-search-filter").within(() => {
+ cy.findByText("Today").should("exist");
+
+ cy.findByLabelText("close icon").click();
+
+ cy.findByText("Today").should("not.exist");
+ cy.findByText("Creation date").should("exist");
+ });
+
+ cy.url().should("not.contain", "created_at");
+
+ expectSearchResultItemNameContent(
+ {
+ itemNames: [REVIEWS_TABLE_NAME, NORMAL_USER_TEST_QUESTION.name],
+ },
+ { strict: false },
+ );
});
- it("should be able to remove a user from the `created_by` filter", () => {
+ it("should hydrate created_by filter and remove a user from it", () => {
cy.visit(
- `/search?q=reviews&created_by=${NORMAL_USER_ID}&created_by=${ADMIN_USER_ID}`,
+ `/search?created_by=${ADMIN_USER_ID}&created_by=${NORMAL_USER_ID}&q=reviews`,
);
cy.wait("@search");
+ cy.findByTestId("created_by-search-filter").within(() => {
+ cy.findByText("2 users selected").should("exist");
+ cy.findByLabelText("close icon").should("exist");
+ });
+
H.expectSearchResultContent({
expectedSearchResults: [
{
@@ -389,46 +439,21 @@ describe("scenarios > search", () => {
.click();
cy.findByText("Apply").click();
});
+ cy.url().should("not.contain", `created_by=${NORMAL_USER_ID}`);
expectSearchResultItemNameContent({
itemNames: [ADMIN_TEST_QUESTION.name],
});
});
- it("should remove created_by filter when `X` is clicked on filter", () => {
- cy.visit(`/search?q=reviews&created_by=${NORMAL_USER_ID}`);
-
- H.expectSearchResultContent({
- expectedSearchResults: [
- {
- name: NORMAL_USER_TEST_QUESTION.name,
- timestamp: "Created a few seconds ago by Robert Tableton",
- collection: "Our analytics",
- },
- ],
- });
-
- cy.findByTestId("created_by-search-filter").within(() => {
- cy.findByText("Robert Tableton").should("exist");
- cy.findByLabelText("close icon").click();
- });
-
- expectSearchResultItemNameContent({
- itemNames: [
- NORMAL_USER_TEST_QUESTION.name,
- ADMIN_TEST_QUESTION.name,
- REVIEWS_TABLE_NAME,
- ],
- });
- });
-
- ["normal", "sandboxed"].forEach((userType) => {
- it(`should allow ${userType} (non-admin) user to see users and filter by created_by`, () => {
+ it("should allow non-admin users to see users and filter by created_by", () => {
+ ["normal", "sandboxed"].forEach((userType) => {
cy.signIn(userType);
+ cy.intercept("GET", "/api/search?q=*").as(`${userType}Search`);
cy.visit("/");
H.commandPaletteSearch("reviews");
- cy.wait("@search");
+ cy.wait(`@${userType}Search`);
expectSearchResultItemNameContent(
{
@@ -463,8 +488,7 @@ describe("scenarios > search", () => {
describe("last_edited_by filter", () => {
beforeEach(() => {
- cy.signInAsAdmin();
- // We'll create a question as a normal user, then edit it as an admin user
+ // We'll create a question as an admin user, then edit it as a normal user
H.createQuestion(LAST_EDITED_BY_NORMAL_USER_QUESTION).then(
({ body: { id: questionId } }) => {
cy.signOut();
@@ -475,13 +499,11 @@ describe("scenarios > search", () => {
cy.findByTestId("qb-header-action-panel")
.findByText("Save")
.click();
- cy.findByTestId("save-question-modal").within((modal) => {
- cy.findByText("Save").click();
- });
+ cy.findByTestId("save-question-modal").findByText("Save").click();
},
);
- // We'll create a question as an admin user, then edit it as a normal user
+ // We'll create a question as a normal user, then edit it as an admin user
H.createQuestion(LAST_EDITED_BY_ADMIN_QUESTION).then(
({ body: { id: questionId } }) => {
cy.signInAsAdmin();
@@ -491,44 +513,17 @@ describe("scenarios > search", () => {
cy.findByTestId("qb-header-action-panel")
.findByText("Save")
.click();
- cy.findByTestId("save-question-modal").within((modal) => {
- cy.findByText("Save").click();
- });
+ cy.findByTestId("save-question-modal").findByText("Save").click();
},
);
});
- it("should hydrate last_edited_by filter", () => {
- cy.intercept("GET", "/api/user").as("getUsers");
-
- cy.visit(`/search?q=reviews&last_edited_by=${NORMAL_USER_ID}`);
-
- cy.wait("@search");
-
- cy.findByTestId("last_edited_by-search-filter").within(() => {
- cy.findByText("Robert Tableton").should("exist");
- cy.findByLabelText("close icon").should("exist");
- });
-
- H.expectSearchResultContent({
- expectedSearchResults: [
- {
- name: LAST_EDITED_BY_NORMAL_USER_QUESTION.name,
- timestamp: "Updated a few seconds ago by Robert Tableton",
- collection: "Our analytics",
- },
- ],
- });
- });
-
- it("should filter last_edited results by one user", () => {
+ it("should filter last_edited results by one or more users and hydrate the filter from the URL", () => {
cy.visit("/");
H.commandPaletteSearch("reviews");
cy.wait("@search");
- cy.findByTestId("last_edited_by-search-filter").click();
-
expectSearchResultItemNameContent({
itemNames: [
LAST_EDITED_BY_NORMAL_USER_QUESTION.name,
@@ -537,6 +532,8 @@ describe("scenarios > search", () => {
],
});
+ cy.findByTestId("last_edited_by-search-filter").click();
+
H.popover().within(() => {
cy.findByText("Robert Tableton").click();
cy.findByText("Apply").click();
@@ -552,15 +549,12 @@ describe("scenarios > search", () => {
},
],
});
- });
- it("should filter last_edited results by more than user", () => {
+ cy.intercept("GET", "/api/search?q=*").as("freshSearch");
cy.visit("/");
H.commandPaletteSearch("reviews");
- cy.wait("@search");
-
- cy.findByTestId("last_edited_by-search-filter").click();
+ cy.wait("@freshSearch");
expectSearchResultItemNameContent({
itemNames: [
@@ -570,12 +564,14 @@ describe("scenarios > search", () => {
],
});
+ cy.findByTestId("last_edited_by-search-filter").click();
+
H.popover().within(() => {
cy.findByText("Robert Tableton").click();
cy.findByText("Bobby Tables").click();
cy.findByText("Apply").click();
});
- cy.url().should("contain", "last_edited_by");
+ cy.url().should("contain", `last_edited_by=${ADMIN_USER_ID}`);
H.expectSearchResultContent({
expectedSearchResults: [
@@ -591,9 +587,29 @@ describe("scenarios > search", () => {
},
],
});
+
+ cy.intercept("GET", "/api/search?q=*").as("hydratedSearch");
+ cy.visit(`/search?q=reviews&last_edited_by=${NORMAL_USER_ID}`);
+
+ cy.wait("@hydratedSearch");
+
+ cy.findByTestId("last_edited_by-search-filter").within(() => {
+ cy.findByText("Robert Tableton").should("exist");
+ cy.findByLabelText("close icon").should("exist");
+ });
+
+ H.expectSearchResultContent({
+ expectedSearchResults: [
+ {
+ name: LAST_EDITED_BY_NORMAL_USER_QUESTION.name,
+ timestamp: "Updated a few seconds ago by Robert Tableton",
+ collection: "Our analytics",
+ },
+ ],
+ });
});
- it("should allow to remove a user from the `last_edited_by` filter", () => {
+ it("should allow to remove a user from the `last_edited_by` filter, and remove the filter when `X` is clicked", () => {
cy.visit(
`/search?q=reviews&last_edited_by=${NORMAL_USER_ID}&last_edited_by=${ADMIN_USER_ID}`,
);
@@ -623,6 +639,7 @@ describe("scenarios > search", () => {
.click();
cy.findByText("Apply").click();
});
+ cy.url().should("not.contain", `last_edited_by=${NORMAL_USER_ID}`);
H.expectSearchResultContent({
expectedSearchResults: [
@@ -633,12 +650,12 @@ describe("scenarios > search", () => {
},
],
});
- });
- it("should remove last_edited_by filter when `X` is clicked on filter", () => {
+ cy.intercept("GET", "/api/search?q=*").as("hydratedSearch");
cy.visit(
`/search?q=reviews&last_edited_by=${NORMAL_USER_ID}&last_edited_by=${ADMIN_USER_ID}`,
);
+ cy.wait("@hydratedSearch");
H.expectSearchResultContent({
expectedSearchResults: [
@@ -659,6 +676,7 @@ describe("scenarios > search", () => {
cy.findByText("2 users selected").should("exist");
cy.findByLabelText("close icon").click();
});
+ cy.url().should("not.contain", "last_edited_by");
expectSearchResultItemNameContent({
itemNames: [
@@ -669,13 +687,14 @@ describe("scenarios > search", () => {
});
});
- ["normal", "sandboxed"].forEach((userType) => {
- it(`should allow ${userType} (non-admin) user to see users and filter by last_edited_by`, () => {
+ it("should allow non-admin users to see users and filter by last_edited_by", () => {
+ ["normal", "sandboxed"].forEach((userType) => {
cy.signIn(userType);
+ cy.intercept("GET", "/api/search?q=*").as(`${userType}Search`);
cy.visit("/");
H.commandPaletteSearch("reviews");
- cy.wait("@search");
+ cy.wait(`@${userType}Search`);
expectSearchResultItemNameContent(
{
@@ -708,187 +727,108 @@ describe("scenarios > search", () => {
});
});
- describe("created_at filter", () => {
- beforeEach(() => {
- cy.signInAsNormalUser();
- H.createQuestion(NORMAL_USER_TEST_QUESTION);
- cy.signOut();
- cy.signInAsAdmin();
- });
-
- TEST_CREATED_AT_FILTERS.forEach(([label, filter]) => {
- it(`should hydrate created_at=${filter}`, () => {
- cy.visit(`/search?q=orders&created_at=${filter}`);
-
+ it("should hydrate created_at and last_edited_at from the URL", () => {
+ [
+ { name: "created_at", query: "orders" },
+ { name: "last_edited_at", query: "reviews" },
+ ].forEach(({ name, query }) => {
+ TEST_CREATED_AT_FILTERS.filter(
+ ([, filter]) => filter !== "thisday",
+ ).forEach(([label, filter]) => {
+ cy.visit(`/search?q=${query}&${name}=${filter}`);
cy.wait("@search");
-
- cy.findByTestId("created_at-search-filter").within(() => {
+ cy.findByTestId(`${name}-search-filter`).within(() => {
cy.findByText(label).should("exist");
cy.findByLabelText("close icon").should("exist");
});
});
});
-
- // we can only test the 'today' filter since we currently
- // can't edit the created_at column of a question in our database
- it("should filter results by Today (created_at=thisday)", () => {
- cy.visit("/search?q=Reviews");
-
- expectSearchResultItemNameContent(
- {
- itemNames: [REVIEWS_TABLE_NAME, NORMAL_USER_TEST_QUESTION.name],
- },
- { strict: false },
- );
-
- cy.findByTestId("created_at-search-filter").click();
- H.popover().within(() => {
- cy.findByText("Today").click();
- });
-
- H.expectSearchResultContent({
- expectedSearchResults: [
- {
- name: NORMAL_USER_TEST_QUESTION.name,
- collection: "Our analytics",
- timestamp: "Created a few seconds ago by Robert Tableton",
- },
- ],
- strict: false,
- });
- });
-
- it("should remove created_at filter when `X` is clicked on search filter", () => {
- cy.visit("/search?q=Reviews&created_at=thisday");
- cy.wait("@search");
-
- H.expectSearchResultContent({
- expectedSearchResults: [
- {
- name: NORMAL_USER_TEST_QUESTION.name,
- collection: "Our analytics",
- timestamp: "Created a few seconds ago by Robert Tableton",
- },
- ],
- strict: false,
- });
-
- cy.findByTestId("created_at-search-filter").within(() => {
- cy.findByText("Today").should("exist");
-
- cy.findByLabelText("close icon").click();
-
- cy.findByText("Today").should("not.exist");
- cy.findByText("Creation date").should("exist");
- });
-
- cy.url().should("not.contain", "created_at");
-
- expectSearchResultItemNameContent(
- {
- itemNames: [REVIEWS_TABLE_NAME, NORMAL_USER_TEST_QUESTION.name],
- },
- { strict: false },
- );
- });
});
describe("last_edited_at filter", () => {
- beforeEach(() => {
- cy.signInAsAdmin();
- // We'll create a question as a normal user, then edit it as an admin user
- H.createQuestion(LAST_EDITED_BY_NORMAL_USER_QUESTION).then(
- ({ body: { id: questionId } }) => {
- cy.signOut();
- cy.signInAsNormalUser();
- cy.visit(`/question/${questionId}`);
- H.summarize();
- cy.findByTestId("sidebar-right").findByText("Done").click();
- cy.findByTestId("qb-header-action-panel")
- .findByText("Save")
- .click();
- cy.findByTestId("save-question-modal").within((modal) => {
- cy.findByText("Save").click();
- });
- cy.signOut();
- cy.signInAsAdmin();
- },
- );
- });
+ describe("with an edited question", () => {
+ beforeEach(() => {
+ // We'll create a question as an admin user, then edit it as a normal user
+ H.createQuestion(LAST_EDITED_BY_NORMAL_USER_QUESTION).then(
+ ({ body: { id: questionId } }) => {
+ cy.signOut();
+ cy.signInAsNormalUser();
+ cy.visit(`/question/${questionId}`);
+ H.summarize();
+ cy.findByTestId("sidebar-right").findByText("Done").click();
+ cy.findByTestId("qb-header-action-panel")
+ .findByText("Save")
+ .click();
+ cy.findByTestId("save-question-modal").findByText("Save").click();
+ cy.signOut();
+ cy.signInAsAdmin();
+ },
+ );
+ });
- TEST_CREATED_AT_FILTERS.forEach(([label, filter]) => {
- it(`should hydrate last_edited_at=${filter}`, () => {
- cy.visit(`/search?q=reviews&last_edited_at=${filter}`);
+ // we can only test the 'today' filter since we currently
+ // can't edit the last_edited_at column of a question in our database
+ it("should filter results by Today (last_edited_at=thisday), and remove the filter when `X` is clicked", () => {
+ cy.visit("/search?q=Reviews");
- cy.wait("@search");
+ expectSearchResultItemNameContent({
+ itemNames: [
+ REVIEWS_TABLE_NAME,
+ LAST_EDITED_BY_NORMAL_USER_QUESTION.name,
+ ],
+ });
+ cy.findByTestId("last_edited_at-search-filter").click();
+ H.popover().within(() => {
+ cy.findByText("Today").click();
+ });
+ cy.url().should("contain", "last_edited_at=thisday");
cy.findByTestId("last_edited_at-search-filter").within(() => {
- cy.findByText(label).should("exist");
+ cy.findByText("Today").should("exist");
cy.findByLabelText("close icon").should("exist");
});
- });
- });
-
- // we can only test the 'today' filter since we currently
- // can't edit the last_edited_at column of a question in our database
- it("should filter results by Today (last_edited_at=thisday)", () => {
- cy.visit("/search?q=Reviews");
-
- expectSearchResultItemNameContent({
- itemNames: [
- REVIEWS_TABLE_NAME,
- LAST_EDITED_BY_NORMAL_USER_QUESTION.name,
- ],
- });
- cy.findByTestId("last_edited_at-search-filter").click();
- H.popover().within(() => {
- cy.findByText("Today").click();
- });
-
- H.expectSearchResultContent({
- expectedSearchResults: [
- {
- name: LAST_EDITED_BY_NORMAL_USER_QUESTION.name,
- collection: "Our analytics",
- timestamp: "Updated a few seconds ago by Robert Tableton",
- },
- ],
- strict: false,
- });
- });
+ H.expectSearchResultContent({
+ expectedSearchResults: [
+ {
+ name: LAST_EDITED_BY_NORMAL_USER_QUESTION.name,
+ collection: "Our analytics",
+ timestamp: "Updated a few seconds ago by Robert Tableton",
+ },
+ ],
+ });
- it("should remove last_edited_at filter when `X` is clicked on search filter", () => {
- cy.visit("/search?q=Reviews&last_edited_at=thisday");
- cy.wait("@search");
+ cy.intercept("GET", "/api/search?q=*").as("hydratedSearch");
+ cy.visit("/search?q=Reviews&last_edited_at=thisday");
+ cy.wait("@hydratedSearch");
- H.expectSearchResultContent({
- expectedSearchResults: [
- {
- name: LAST_EDITED_BY_NORMAL_USER_QUESTION.name,
- collection: "Our analytics",
- timestamp: "Updated a few seconds ago by Robert Tableton",
- },
- ],
- strict: false,
- });
+ H.expectSearchResultContent({
+ expectedSearchResults: [
+ {
+ name: LAST_EDITED_BY_NORMAL_USER_QUESTION.name,
+ collection: "Our analytics",
+ timestamp: "Updated a few seconds ago by Robert Tableton",
+ },
+ ],
+ });
- cy.findByTestId("last_edited_at-search-filter").within(() => {
- cy.findByText("Today").should("exist");
+ cy.findByTestId("last_edited_at-search-filter").within(() => {
+ cy.findByText("Today").should("exist");
- cy.findByLabelText("close icon").click();
+ cy.findByLabelText("close icon").click();
- cy.findByText("Today").should("not.exist");
- cy.findByText("Last edit date").should("exist");
- });
+ cy.findByText("Today").should("not.exist");
+ cy.findByText("Last edit date").should("exist");
+ });
- cy.url().should("not.contain", "last_edited_at");
+ cy.url().should("not.contain", "last_edited_at");
- expectSearchResultItemNameContent({
- itemNames: [
- REVIEWS_TABLE_NAME,
- LAST_EDITED_BY_NORMAL_USER_QUESTION.name,
- ],
+ expectSearchResultItemNameContent({
+ itemNames: [
+ REVIEWS_TABLE_NAME,
+ LAST_EDITED_BY_NORMAL_USER_QUESTION.name,
+ ],
+ });
});
});
});
@@ -903,49 +843,49 @@ describe("scenarios > search", () => {
});
});
- it("should hydrate search with search text and verified filter", () => {
- cy.visit("/search?q=orders&verified=true");
- cy.wait("@search");
-
- cy.findByTestId("search-app").within(() => {
- cy.findByText('Results for "orders"').should("exist");
- });
-
- cy.findAllByTestId("search-result-item").each((result) => {
- cy.wrap(result).within(() => {
- cy.findByLabelText("verified_filled icon").should("exist");
- });
- });
- });
-
- it("should filter results by verified items", () => {
+ it("should filter results by verified items, hydrate the filter from the URL, and turn it off", () => {
cy.visit("/");
H.commandPaletteSearch("e");
cy.wait("@search");
+ cy.intercept("GET", "/api/search?q=*verified=true*").as(
+ "verifiedSearch",
+ );
cy.findByTestId("verified-search-filter")
.findByLabelText("Verified items only")
.click();
- cy.wait("@search");
+ cy.url().should("include", "verified=true");
+ cy.wait("@verifiedSearch");
cy.findAllByTestId("search-result-item").each((result) => {
cy.wrap(result).within(() => {
cy.findByLabelText("verified_filled icon").should("exist");
});
});
- });
- it("should not filter results when verified items is off", () => {
+ cy.intercept("GET", "/api/search?q=*").as("hydratedSearch");
cy.visit("/search?q=e&verified=true");
- cy.wait("@search");
+ cy.wait("@hydratedSearch");
+
+ cy.findByTestId("search-app").within(() => {
+ cy.findByText('Results for "e"').should("exist");
+ });
+
+ cy.findAllByTestId("search-result-item").each((result) => {
+ cy.wrap(result).within(() => {
+ cy.findByLabelText("verified_filled icon").should("exist");
+ });
+ });
+ cy.intercept("GET", "/api/search?q=*").as("unverifiedSearch");
cy.findByTestId("verified-search-filter")
.findByLabelText("Verified items only")
.click();
cy.url().should("not.include", "verified=true");
+ cy.wait("@unverifiedSearch");
let verifiedElementCount = 0;
let unverifiedElementCount = 0;
@@ -982,24 +922,7 @@ describe("scenarios > search", () => {
});
});
- it("should hydrate search with search text and native query filter", () => {
- cy.visit(
- `/search?q=${TEST_NATIVE_QUESTION_NAME}&search_native_query=true`,
- );
- cy.wait("@search");
-
- cy.findByTestId("search-app").within(() => {
- cy.findByText(`Results for "${TEST_NATIVE_QUESTION_NAME}"`).should(
- "exist",
- );
- });
-
- expectSearchResultItemNameContent({
- itemNames: [TEST_NATIVE_QUESTION_NAME, "Native Query"],
- });
- });
-
- it("should include results that contain native query data when the toggle is on", () => {
+ it("should include results that contain native query data when the toggle is on, and not include them when it is off", () => {
cy.visit(`/search?q=${TEST_NATIVE_QUESTION_NAME}`);
cy.wait("@search");
@@ -1016,13 +939,18 @@ describe("scenarios > search", () => {
expectSearchResultItemNameContent({
itemNames: [TEST_NATIVE_QUESTION_NAME, "Native Query"],
});
- });
- it("should not include results that contain native query data if the toggle is off", () => {
+ cy.intercept("GET", "/api/search?q=*").as("hydratedSearch");
cy.visit(
`/search?q=${TEST_NATIVE_QUESTION_NAME}&search_native_query=true`,
);
- cy.wait("@search");
+ cy.wait("@hydratedSearch");
+
+ cy.findByTestId("search-app").within(() => {
+ cy.findByText(`Results for "${TEST_NATIVE_QUESTION_NAME}"`).should(
+ "exist",
+ );
+ });
expectSearchResultItemNameContent({
itemNames: [TEST_NATIVE_QUESTION_NAME, "Native Query"],
@@ -1031,6 +959,7 @@ describe("scenarios > search", () => {
cy.findByTestId("search_native_query-search-filter")
.findByLabelText("Search the contents of native queries")
.click();
+ cy.url().should("not.contain", "search_native_query");
expectSearchResultItemNameContent({
itemNames: [TEST_NATIVE_QUESTION_NAME],
@@ -1057,35 +986,7 @@ describe("scenarios > search", () => {
cy.signInAsAdmin();
});
- it("should hydrate personal collection filter", () => {
- cy.visit("/search?q=keyword&filter_items_in_personal_collection=all");
- cy.wait("@search");
-
- cy.findByTestId("filter_items_in_personal_collection-search-filter")
- .findByRole("switch")
- .should("be.checked");
-
- expectSearchResultItemNameContent({
- itemNames: [
- "Admin Personal Question [keyword]",
- "Normal User Personal Question [keyword]",
- ],
- });
- });
-
- it("should not be exposed to non-admins", () => {
- cy.signInAsNormalUser();
- cy.visit("/search?q=keyword&filter_items_in_personal_collection=all");
- cy.wait("@search");
- expectSearchResultItemNameContent({
- itemNames: ["Normal User Personal Question [keyword]"],
- });
- cy.findByTestId(
- "filter_items_in_personal_collection-search-filter",
- ).should("not.exist");
- });
-
- it("should include other users' personal collection items when filter is turned on", () => {
+ it("should include other users' personal collection items when filter is turned on, and hydrate the filter from the URL", () => {
cy.visit("/search?q=keyword");
cy.wait("@search");
@@ -1112,6 +1013,35 @@ describe("scenarios > search", () => {
"Normal User Personal Question [keyword]",
],
});
+
+ cy.log("Hydrate the filter from the URL");
+ cy.intercept("GET", "/api/search?q=*").as("hydratedSearch");
+ cy.visit("/search?q=keyword&filter_items_in_personal_collection=all");
+ cy.wait("@hydratedSearch");
+
+ cy.findByTestId("filter_items_in_personal_collection-search-filter")
+ .findByRole("switch")
+ .should("be.checked");
+
+ expectSearchResultItemNameContent({
+ itemNames: [
+ "Admin Personal Question [keyword]",
+ "Normal User Personal Question [keyword]",
+ ],
+ });
+ });
+
+ it("should not be exposed to non-admins", () => {
+ cy.signInAsNormalUser();
+ cy.visit("/search?q=keyword&filter_items_in_personal_collection=all");
+ cy.wait("@search");
+ expectSearchResultItemNameContent({
+ itemNames: ["Normal User Personal Question [keyword]"],
+ });
+ cy.findByTestId("archived-search-filter").should("be.visible");
+ cy.findByTestId(
+ "filter_items_in_personal_collection-search-filter",
+ ).should("not.exist");
});
});
@@ -1126,7 +1056,11 @@ describe("scenarios > search", () => {
cy.findByTestId("archived-search-filter")
.findByLabelText("Search items in trash")
.click();
- cy.findAllByTestId("search-result-item").should("have.length", 0);
+ cy.url().should("include", "archived=true");
+ cy.findByTestId("search-app")
+ .findByText("Didn't find anything")
+ .should("be.visible");
+ cy.findAllByTestId("search-result-item").should("not.exist");
H.archiveCollection(FIRST_COLLECTION_ID);
cy.reload();
@@ -1138,8 +1072,12 @@ describe("scenarios > search", () => {
});
});
- it("should persist filters when the user changes the text query", () => {
+ it("should hydrate search from the URL and persist filters when the user changes the text query", () => {
cy.visit("/search?q=orders");
+ cy.wait("@search");
+ cy.findByTestId("search-app")
+ .findByText('Results for "orders"')
+ .should("exist");
// add created_by filter
cy.findByTestId("created_by-search-filter").click();
@@ -1170,9 +1108,26 @@ describe("scenarios > search", () => {
],
});
- //getSearchBar().clear().type("count{enter}");
H.commandPaletteSearch("count");
+ cy.findByTestId("search-app")
+ .findByText('Results for "count"')
+ .should("exist");
+ cy.location("search")
+ .should("contain", "q=count")
+ .and("contain", `created_by=${ADMIN_USER_ID}`)
+ .and("contain", `last_edited_by=${ADMIN_USER_ID}`)
+ .and("contain", "type=card");
+ cy.findByTestId("created_by-search-filter")
+ .findByText("Bobby Tables")
+ .should("exist");
+ cy.findByTestId("last_edited_by-search-filter")
+ .findByText("Bobby Tables")
+ .should("exist");
+ cy.findByTestId("type-search-filter")
+ .findByText("Question")
+ .should("exist");
+
expectSearchResultItemNameContent({
itemNames: [
"Orders, Count",
diff --git a/e2e/test/scenarios/search/search-pagination.cy.spec.js b/e2e/test/scenarios/search/search-pagination.cy.spec.js
index f23625a396c..3cd4fde17c7 100644
--- a/e2e/test/scenarios/search/search-pagination.cy.spec.js
+++ b/e2e/test/scenarios/search/search-pagination.cy.spec.js
@@ -14,17 +14,6 @@ describe("scenarios > search", () => {
cy.signInAsAdmin();
});
- it("should not search on an empty string", () => {
- cy.intercept("/api/search", (req) => {
- expect("Unexpected call to /api/search").to.be.false;
- });
- H.visitFullAppEmbeddingUrl({
- url: "/",
- qs: { top_nav: true, search: true },
- });
- H.getSearchBar().type(" ");
- });
-
describe("multiple pages of results", () => {
before(() => {
cy.signInAsAdmin();
@@ -37,7 +26,7 @@ describe("scenarios > search", () => {
H.restore("many-questions");
});
- it("should allow users to paginate results", () => {
+ it("should allow users to paginate results and reset the page when filters change (metabase#65501)", () => {
cy.visit("/");
H.commandPaletteSearch("generated_question");
cy.findByLabelText("Previous page").should("be.disabled");
@@ -64,18 +53,21 @@ describe("scenarios > search", () => {
cy.findByText(`1 - ${PAGE_SIZE}`);
cy.findByTestId("pagination-total").should("have.text", TOTAL_ITEMS);
cy.findAllByTestId("search-result-item").should("have.length", PAGE_SIZE);
- });
-
- it("should reset the page when filters change (metabase#65501)", () => {
cy.visit("/search?q=");
cy.findByLabelText("Next page").click();
+ cy.location("search").should("contain", "page=1");
+ cy.findByLabelText("Previous page").should("be.enabled");
cy.findByTestId("type-search-filter").click();
H.popover().findByText("Table").click();
H.popover().findByText("Apply").click();
- cy.findByTestId("search-app")
- .findByText("Didn't find anything")
- .should("not.exist");
- cy.findAllByTestId("search-result-item").should("exist");
+ cy.location("search")
+ .should("include", "type=table")
+ .and("not.include", "page=");
+ cy.findAllByTestId("search-result-item").should(($items) => {
+ $items.each((_index, item) => {
+ expect(item).to.have.attr("data-model-type", "table");
+ });
+ });
});
});
});
diff --git a/e2e/test/scenarios/search/search-snowplow.cy.spec.js b/e2e/test/scenarios/search/search-snowplow.cy.spec.js
index 61f82f6c158..8f39d57b869 100644
--- a/e2e/test/scenarios/search/search-snowplow.cy.spec.js
+++ b/e2e/test/scenarios/search/search-snowplow.cy.spec.js
@@ -161,513 +161,215 @@ describe("scenarios > search > snowplow", () => {
});
describe("should send snowplow events for each filter when it is applied and removed", () => {
- describe("no filters", () => {
- it("should send a new_search_query snowplow event", () => {
- cy.visit("/search?q=orders");
- cy.wait("@search");
- H.expectUnstructuredSnowplowEvent({
- event: NEW_SEARCH_QUERY_EVENT_NAME,
- context: "search-app",
- });
-
- // The result's rank depends on ranking weights, so derive its position from the DOM order
- // rather than pinning a specific index.
- cy.findAllByTestId("search-result-item").then(($items) => {
- const position = $items
- .toArray()
- .findIndex((el) =>
- el.textContent?.includes("Orders in a dashboard"),
- );
- expect(position, "Orders in a dashboard is in the results").to.be.gte(
- 0,
- );
- cy.wrap($items.eq(position)).click();
- H.expectUnstructuredSnowplowEvent({
- event: SEARCH_CLICK,
- context: "search-app",
- position,
+ [
+ {
+ name: "type",
+ urlParam: "type=card",
+ eventKey: "content_type",
+ onValue: [
+ "dashboard",
+ "card",
+ "dataset",
+ "collection",
+ "database",
+ "table",
+ ],
+ hydratedValue: ["card"],
+ offValue: null,
+ apply: () => {
+ cy.findByTestId("type-search-filter").click();
+ H.popover().within(() => {
+ cy.findAllByTestId("type-filter-checkbox").each(($el) => {
+ cy.wrap($el).click();
+ });
+ cy.findByText("Apply").click();
});
- });
- });
- });
-
- describe("type filter", () => {
- it("should send a snowplow event when a search filter is used in the URL", () => {
- cy.visit("/search?q=orders&type=card");
- cy.wait("@search");
-
- H.expectUnstructuredSnowplowEvent(
- {
- event: NEW_SEARCH_QUERY_EVENT_NAME,
-
- context: "search-app",
- content_type: ["card"],
- },
- 1,
- );
- });
-
- it("should send a snowplow event when a search filter is applied from the UI", () => {
- cy.visit("/search?q=orders");
- cy.wait("@search");
- H.expectUnstructuredSnowplowEvent({
- event: NEW_SEARCH_QUERY_EVENT_NAME,
- context: "search-app",
- });
-
- cy.findByTestId("type-search-filter").click();
- H.popover().within(() => {
- cy.findAllByTestId("type-filter-checkbox").each(($el) => {
- cy.wrap($el).click();
+ },
+ },
+ {
+ name: "created_by",
+ urlParam: "created_by=1",
+ eventKey: "creator",
+ onValue: true,
+ hydratedValue: true,
+ offValue: false,
+ apply: () => {
+ cy.findByTestId("created_by-search-filter").click();
+ H.popover().within(() => {
+ cy.findByText("Bobby Tables").click();
+ cy.findByText("Apply").click();
+ });
+ },
+ },
+ {
+ name: "last_edited_by",
+ urlParam: "last_edited_by=1",
+ eventKey: "last_editor",
+ onValue: true,
+ hydratedValue: true,
+ offValue: false,
+ apply: () => {
+ cy.findByTestId("last_edited_by-search-filter").click();
+ H.popover().within(() => {
+ cy.findByText("Bobby Tables").click();
+ cy.findByText("Apply").click();
+ });
+ },
+ },
+ {
+ name: "created_at",
+ urlParam: "created_at=thisday",
+ eventKey: "creation_date",
+ onValue: true,
+ hydratedValue: true,
+ offValue: false,
+ apply: () => {
+ cy.findByTestId("created_at-search-filter").click();
+ H.popover().within(() => {
+ cy.findByText("Today").click();
+ });
+ },
+ },
+ {
+ name: "last_edited_at",
+ urlParam: "last_edited_at=thisday",
+ eventKey: "last_edit_date",
+ onValue: true,
+ hydratedValue: true,
+ offValue: false,
+ apply: () => {
+ cy.findByTestId("last_edited_at-search-filter").click();
+ H.popover().within(() => {
+ cy.findByText("Today").click();
+ });
+ },
+ },
+ {
+ name: "verified",
+ urlParam: "verified=true",
+ eventKey: "verified_items",
+ onValue: true,
+ hydratedValue: true,
+ offValue: false,
+ toggleLabel: "Verified items only",
+ apply: () => {
+ cy.findByTestId("verified-search-filter")
+ .findByLabelText("Verified items only")
+ .click();
+ },
+ },
+ {
+ name: "search_native_query",
+ urlParam: "search_native_query=true",
+ eventKey: "search_native_queries",
+ onValue: true,
+ hydratedValue: true,
+ offValue: false,
+ toggleLabel: "Search the contents of native queries",
+ apply: () => {
+ cy.findByTestId("search_native_query-search-filter")
+ .findByLabelText("Search the contents of native queries")
+ .click();
+ },
+ },
+ {
+ name: "archived",
+ urlParam: "archived=true",
+ eventKey: "search_archived",
+ onValue: true,
+ hydratedValue: true,
+ offValue: false,
+ toggleLabel: "Search items in trash",
+ apply: () => {
+ cy.findByTestId("archived-search-filter")
+ .findByLabelText("Search items in trash")
+ .click();
+ },
+ },
+ ].forEach(
+ ({
+ name,
+ urlParam,
+ eventKey,
+ onValue,
+ hydratedValue,
+ offValue,
+ toggleLabel,
+ apply,
+ }) => {
+ describe(`${name} filter`, () => {
+ beforeEach(() => {
+ if (name === "verified") {
+ H.activateToken("pro-self-hosted");
+ }
});
- cy.findByText("Apply").click();
- });
-
- H.expectUnstructuredSnowplowEvent({
- event: NEW_SEARCH_QUERY_EVENT_NAME,
-
- context: "search-app",
-
- content_type: [
- "dashboard",
- "card",
- "dataset",
- "collection",
- "database",
- "table",
- ],
- });
- });
-
- it("should send a snowplow event when a search filter is removed from the UI", () => {
- cy.visit("/search?q=orders&type=card");
- cy.wait("@search");
- H.expectUnstructuredSnowplowEvent({
- event: NEW_SEARCH_QUERY_EVENT_NAME,
- context: "search-app",
-
- content_type: ["card"],
- });
-
- cy.findByTestId("type-search-filter")
- .findByLabelText("close icon")
- .click();
-
- H.expectUnstructuredSnowplowEvent({
- event: NEW_SEARCH_QUERY_EVENT_NAME,
- context: "search-app",
-
- content_type: [],
- });
- });
- });
-
- describe("created_by filter", () => {
- it("should send a snowplow event when a search filter is used in the URL", () => {
- cy.visit("/search?q=orders&created_by=1");
- cy.wait("@search");
- H.expectUnstructuredSnowplowEvent({
- event: NEW_SEARCH_QUERY_EVENT_NAME,
- context: "search-app",
-
- creator: true,
- });
- });
-
- it("should send a snowplow event when a search filter is applied from the UI", () => {
- cy.visit("/search?q=orders");
- cy.wait("@search");
- H.expectUnstructuredSnowplowEvent({
- event: NEW_SEARCH_QUERY_EVENT_NAME,
- context: "search-app",
- creator: false,
- });
-
- cy.findByTestId("created_by-search-filter").click();
- H.popover().within(() => {
- cy.findByText("Bobby Tables").click();
- cy.findByText("Apply").click();
- });
-
- H.expectUnstructuredSnowplowEvent({
- event: NEW_SEARCH_QUERY_EVENT_NAME,
- context: "search-app",
-
- creator: true,
- });
- });
-
- it("should send a snowplow event when a search filter is removed from the UI", () => {
- cy.visit("/search?q=orders&created_by=1");
- cy.wait("@search");
- H.expectUnstructuredSnowplowEvent({
- event: NEW_SEARCH_QUERY_EVENT_NAME,
- context: "search-app",
-
- creator: true,
- });
-
- cy.findByTestId("created_by-search-filter")
- .findByLabelText("close icon")
- .click();
-
- H.expectUnstructuredSnowplowEvent({
- event: NEW_SEARCH_QUERY_EVENT_NAME,
- context: "search-app",
-
- creator: false,
- });
- });
- });
-
- describe("last_edited_by filter", () => {
- it("should send a snowplow event when a search filter is used in the URL", () => {
- cy.visit("/search?q=orders&last_edited_by=1");
- cy.wait("@search");
- H.expectUnstructuredSnowplowEvent({
- event: NEW_SEARCH_QUERY_EVENT_NAME,
- context: "search-app",
-
- last_editor: true,
- });
- });
-
- it("should send a snowplow event when a search filter is applied from the UI", () => {
- cy.visit("/search?q=orders");
- cy.wait("@search");
- H.expectUnstructuredSnowplowEvent({
- event: NEW_SEARCH_QUERY_EVENT_NAME,
- context: "search-app",
-
- last_editor: false,
- });
-
- cy.findByTestId("last_edited_by-search-filter").click();
- H.popover().within(() => {
- cy.findByText("Bobby Tables").click();
- cy.findByText("Apply").click();
- });
-
- H.expectUnstructuredSnowplowEvent({
- event: NEW_SEARCH_QUERY_EVENT_NAME,
- context: "search-app",
-
- last_editor: true,
- });
- });
-
- it("should send a snowplow event when a search filter is removed from the UI", () => {
- cy.visit("/search?q=orders&last_edited_by=1");
- cy.wait("@search");
- H.expectUnstructuredSnowplowEvent({
- event: NEW_SEARCH_QUERY_EVENT_NAME,
- context: "search-app",
-
- last_editor: true,
- });
-
- cy.findByTestId("last_edited_by-search-filter")
- .findByLabelText("close icon")
- .click();
-
- H.expectUnstructuredSnowplowEvent({
- event: NEW_SEARCH_QUERY_EVENT_NAME,
- context: "search-app",
-
- last_editor: false,
- });
- });
- });
-
- describe("created_at filter", () => {
- it("should send a snowplow event when a search filter is used in the URL", () => {
- cy.visit("/search?q=orders&created_at=thisday");
- cy.wait("@search");
- H.expectUnstructuredSnowplowEvent({
- event: NEW_SEARCH_QUERY_EVENT_NAME,
- context: "search-app",
-
- creation_date: true,
- });
- });
-
- it("should send a snowplow event when a search filter is applied from the UI", () => {
- cy.visit("/search?q=orders");
- cy.wait("@search");
- H.expectUnstructuredSnowplowEvent({
- event: NEW_SEARCH_QUERY_EVENT_NAME,
- context: "search-app",
-
- creation_date: false,
- });
-
- cy.findByTestId("created_at-search-filter").click();
- H.popover().within(() => {
- cy.findByText("Today").click();
- });
-
- H.expectUnstructuredSnowplowEvent({
- event: NEW_SEARCH_QUERY_EVENT_NAME,
- context: "search-app",
-
- creation_date: true,
- });
- });
-
- it("should send a snowplow event when a search filter is removed from the UI", () => {
- cy.visit("/search?q=orders&created_at=thisday");
- cy.wait("@search");
- H.expectUnstructuredSnowplowEvent({
- event: NEW_SEARCH_QUERY_EVENT_NAME,
- context: "search-app",
-
- creation_date: true,
- });
-
- cy.findByTestId("created_at-search-filter")
- .findByLabelText("close icon")
- .click();
-
- H.expectUnstructuredSnowplowEvent({
- event: NEW_SEARCH_QUERY_EVENT_NAME,
- context: "search-app",
-
- creation_date: false,
- });
- });
- });
-
- describe("last_edited_at filter", () => {
- it("should send a snowplow event when a search filter is used in the URL", () => {
- cy.visit("/search?q=orders&last_edited_at=thisday");
- cy.wait("@search");
- H.expectUnstructuredSnowplowEvent({
- event: NEW_SEARCH_QUERY_EVENT_NAME,
- context: "search-app",
-
- last_edit_date: true,
- });
- });
-
- it("should send a snowplow event when a search filter is applied from the UI", () => {
- cy.visit("/search?q=orders");
- cy.wait("@search");
- H.expectUnstructuredSnowplowEvent({
- event: NEW_SEARCH_QUERY_EVENT_NAME,
- context: "search-app",
-
- last_edit_date: false,
- });
-
- cy.findByTestId("last_edited_at-search-filter").click();
- H.popover().within(() => {
- cy.findByText("Today").click();
- });
-
- H.expectUnstructuredSnowplowEvent({
- event: NEW_SEARCH_QUERY_EVENT_NAME,
- context: "search-app",
-
- last_edit_date: true,
- });
- });
-
- it("should send a snowplow event when a search filter is removed from the UI", () => {
- cy.visit("/search?q=orders&last_edited_at=thisday");
- cy.wait("@search");
- H.expectUnstructuredSnowplowEvent({
- event: NEW_SEARCH_QUERY_EVENT_NAME,
- context: "search-app",
-
- last_edit_date: true,
- });
-
- cy.findByTestId("last_edited_at-search-filter")
- .findByLabelText("close icon")
- .click();
-
- H.expectUnstructuredSnowplowEvent({
- event: NEW_SEARCH_QUERY_EVENT_NAME,
- context: "search-app",
-
- last_edit_date: false,
- });
- });
- });
-
- describe("verified filter", () => {
- beforeEach(() => {
- H.activateToken("pro-self-hosted");
- });
-
- it("should send a snowplow event when a search filter is used in the URL", () => {
- cy.visit("/search?q=orders&verified=true");
- cy.wait("@search");
- H.expectUnstructuredSnowplowEvent({
- event: NEW_SEARCH_QUERY_EVENT_NAME,
- context: "search-app",
-
- verified_items: true,
- });
- });
-
- it("should send a snowplow event when a search filter is applied from the UI", () => {
- cy.visit("/search?q=orders");
- cy.wait("@search");
- H.expectUnstructuredSnowplowEvent({
- event: NEW_SEARCH_QUERY_EVENT_NAME,
- context: "search-app",
-
- verified_items: false,
- });
-
- cy.findByTestId("verified-search-filter")
- .findByLabelText("Verified items only")
- .click();
-
- H.expectUnstructuredSnowplowEvent({
- event: NEW_SEARCH_QUERY_EVENT_NAME,
- context: "search-app",
-
- verified_items: true,
- });
- });
-
- it("should send a snowplow event when a search filter is removed from the UI", () => {
- cy.visit("/search?q=orders&verified=true");
- cy.wait("@search");
- H.expectUnstructuredSnowplowEvent({
- event: NEW_SEARCH_QUERY_EVENT_NAME,
- context: "search-app",
-
- verified_items: true,
- });
-
- cy.findByTestId("verified-search-filter")
- .findByLabelText("Verified items only")
- .click();
-
- H.expectUnstructuredSnowplowEvent({
- event: NEW_SEARCH_QUERY_EVENT_NAME,
- context: "search-app",
-
- verified_items: false,
- });
- });
- });
-
- describe("search_native_query filter", () => {
- it("should send a snowplow event when a search filter is used in the URL", () => {
- cy.visit("/search?q=orders&search_native_query=true");
- cy.wait("@search");
- H.expectUnstructuredSnowplowEvent({
- event: NEW_SEARCH_QUERY_EVENT_NAME,
- context: "search-app",
-
- search_native_queries: true,
- });
- });
-
- it("should send a snowplow event when a search filter is applied from the UI", () => {
- cy.visit("/search?q=orders");
- cy.wait("@search");
- H.expectUnstructuredSnowplowEvent({
- event: NEW_SEARCH_QUERY_EVENT_NAME,
- context: "search-app",
-
- search_native_queries: false,
- });
-
- cy.findByTestId("search_native_query-search-filter")
- .findByLabelText("Search the contents of native queries")
- .click();
-
- H.expectUnstructuredSnowplowEvent({
- event: NEW_SEARCH_QUERY_EVENT_NAME,
- context: "search-app",
-
- search_native_queries: true,
- });
- });
-
- it("should send a snowplow event when a search filter is removed from the UI", () => {
- cy.visit("/search?q=orders&search_native_query=true");
- cy.wait("@search");
- H.expectUnstructuredSnowplowEvent({
- event: NEW_SEARCH_QUERY_EVENT_NAME,
- context: "search-app",
-
- search_native_queries: true,
- });
-
- cy.findByTestId("search_native_query-search-filter")
- .findByLabelText("Search the contents of native queries")
- .click();
-
- H.expectUnstructuredSnowplowEvent({
- event: NEW_SEARCH_QUERY_EVENT_NAME,
- context: "search-app",
-
- search_native_queries: false,
- });
- });
- });
-
- describe("archived filter", () => {
- it("should send a snowplow event when a search filter is used in the URL", () => {
- cy.visit("/search?q=orders&archived=true");
- cy.wait("@search");
- H.expectUnstructuredSnowplowEvent({
- event: NEW_SEARCH_QUERY_EVENT_NAME,
- context: "search-app",
-
- search_archived: true,
- });
- });
-
- it("should send a snowplow event when a search filter is applied from the UI", () => {
- cy.visit("/search?q=orders");
- cy.wait("@search");
- H.expectUnstructuredSnowplowEvent({
- event: NEW_SEARCH_QUERY_EVENT_NAME,
- context: "search-app",
-
- search_archived: false,
- });
-
- cy.findByTestId("archived-search-filter")
- .findByLabelText("Search items in trash")
- .click();
-
- H.expectUnstructuredSnowplowEvent({
- event: NEW_SEARCH_QUERY_EVENT_NAME,
- context: "search-app",
-
- search_archived: true,
- });
- });
-
- it("should send a snowplow event when a search filter is removed from the UI", () => {
- cy.visit("/search?q=orders&archived=true");
- cy.wait("@search");
- H.expectUnstructuredSnowplowEvent({
- event: NEW_SEARCH_QUERY_EVENT_NAME,
- context: "search-app",
-
- search_archived: true,
- });
-
- cy.findByTestId("archived-search-filter")
- .findByLabelText("Search items in trash")
- .click();
-
- H.expectUnstructuredSnowplowEvent({
- event: NEW_SEARCH_QUERY_EVENT_NAME,
- context: "search-app",
- search_archived: false,
+ it("should send snowplow events when a filter is applied, hydrated from the URL, and removed", () => {
+ cy.visit("/search?q=orders");
+ cy.wait("@search");
+ H.expectUnstructuredSnowplowEvent({
+ event: NEW_SEARCH_QUERY_EVENT_NAME,
+ context: "search-app",
+ ...(name === "type" ? {} : { [eventKey]: offValue }),
+ });
+
+ apply();
+ H.expectUnstructuredSnowplowEvent({
+ event: NEW_SEARCH_QUERY_EVENT_NAME,
+ context: "search-app",
+ [eventKey]: onValue,
+ });
+ H.expectNoBadSnowplowEvents();
+ H.resetSnowplow();
+ cy.intercept("GET", "/api/search**").as("hydratedSearch");
+ cy.visit(`/search?q=orders&${urlParam}`);
+ cy.wait("@hydratedSearch");
+ H.expectUnstructuredSnowplowEvent({
+ event: NEW_SEARCH_QUERY_EVENT_NAME,
+ context: "search-app",
+ [eventKey]: hydratedValue,
+ });
+
+ cy.findByTestId(`${name}-search-filter`)
+ .findByLabelText(toggleLabel ?? "close icon")
+ .click();
+ H.expectUnstructuredSnowplowEvent({
+ event: NEW_SEARCH_QUERY_EVENT_NAME,
+ context: "search-app",
+ [eventKey]: offValue,
+ });
+
+ if (name === "type") {
+ H.expectNoBadSnowplowEvents();
+ H.resetSnowplow();
+ cy.intercept("GET", "/api/search**").as("unfilteredSearch");
+ cy.visit("/search?q=orders");
+ cy.wait("@unfilteredSearch");
+ H.expectUnstructuredSnowplowEvent({
+ event: NEW_SEARCH_QUERY_EVENT_NAME,
+ context: "search-app",
+ });
+ cy.findAllByTestId("search-result-item").then(($items) => {
+ const position = $items
+ .toArray()
+ .findIndex((el) =>
+ el.textContent?.includes("Orders in a dashboard"),
+ );
+ expect(
+ position,
+ "Orders in a dashboard is in the results",
+ ).to.be.gte(0);
+ cy.wrap($items.eq(position)).click();
+ H.expectUnstructuredSnowplowEvent({
+ event: SEARCH_CLICK,
+ context: "search-app",
+ position,
+ });
+ });
+ }
+ });
});
- });
- });
+ },
+ );
});
});
diff --git a/e2e/test/scenarios/search/search-typeahead.cy.spec.js b/e2e/test/scenarios/search/search-typeahead.cy.spec.js
deleted file mode 100644
index 50f7ac5be5c..00000000000
--- a/e2e/test/scenarios/search/search-typeahead.cy.spec.js
+++ /dev/null
@@ -1,47 +0,0 @@
-const { H } = cy;
-import { USERS } from "e2e/support/cypress_data";
-
-["admin", "normal"].forEach((user) => {
- describe(`search > ${user} user`, () => {
- beforeEach(() => {
- H.restore();
- cy.signIn(user);
- H.visitFullAppEmbeddingUrl({
- url: "/",
- qs: { top_nav: true, search: true },
- });
- });
-
- // There was no issue for this, but it was implemented in pull request #15614
- it("should be able to use typeahead search functionality", () => {
- const personalCollectionsLength =
- user === "admin" ? Object.entries(USERS).length : 1;
-
- cy.findByPlaceholderText("Search…").type("pers");
- cy.findByTestId("loading-indicator").should("not.exist");
- cy.findByTestId("search-results-list").within(() => {
- cy.findAllByText(/personal collection$/i).should(
- "have.length",
- personalCollectionsLength,
- );
- });
- });
- });
-});
-
-describe("command palette", () => {
- beforeEach(() => {
- H.restore();
- cy.signInAsAdmin();
- H.updateSetting("search-typeahead-enabled", false);
- cy.visit("/");
- });
-
- it("should not display search results in the palette when search-typeahead-enabled is false", () => {
- H.commandPaletteButton().click();
- H.commandPaletteInput().type("ord");
- H.commandPalette()
- .findByRole("option", { name: /View search results/ })
- .should("exist");
- });
-});
diff --git a/e2e/test/scenarios/search/search.cy.spec.js b/e2e/test/scenarios/search/search.cy.spec.js
index 5a80626d440..9b0456edfe4 100644
--- a/e2e/test/scenarios/search/search.cy.spec.js
+++ b/e2e/test/scenarios/search/search.cy.spec.js
@@ -1,9 +1,11 @@
const { H } = cy;
+import { USERS } from "e2e/support/cypress_data";
import { SAMPLE_DATABASE } from "e2e/support/cypress_sample_database";
import {
ORDERS_DASHBOARD_ID,
ORDERS_QUESTION_ID,
} from "e2e/support/cypress_sample_instance_data";
+import { SEARCH_DEBOUNCE_DURATION } from "metabase/utils/constants";
const { ORDERS_ID, PEOPLE_ID } = SAMPLE_DATABASE;
@@ -27,6 +29,17 @@ describe("scenarios > search", () => {
describe("universal search", () => {
it("should work for admin (metabase#20018)", () => {
visitEmbeddingWithSearch("/");
+
+ H.getSearchBar().type("pers");
+ cy.wait("@search");
+ cy.findByTestId("loading-indicator").should("not.exist");
+ cy.findByTestId("search-results-list").within(() => {
+ cy.findAllByText(/personal collection$/i).should(
+ "have.length",
+ Object.entries(USERS).length,
+ );
+ });
+
H.getSearchBar().as("searchBox").clear().type("orders count").blur();
H.expectSearchResultContent({
@@ -58,22 +71,36 @@ describe("scenarios > search", () => {
cy.get("@searchBox").type("{enter}");
cy.wait("@search");
- H.expectSearchResultContent({
- expectedSearchResults: [
- {
- name: "Products",
- description:
- "Includes a catalog of all the products ever sold by the famed Sample Company.",
- },
- ],
- strict: false,
+ cy.location("pathname").should("eq", "/search");
+ cy.findByTestId("search-app")
+ .findByText('Results for "product"')
+ .should("exist");
+ cy.findByTestId("search-app").within(() => {
+ H.expectSearchResultContent({
+ expectedSearchResults: [
+ {
+ name: "Products",
+ description:
+ "Includes a catalog of all the products ever sold by the famed Sample Company.",
+ },
+ ],
+ strict: false,
+ });
});
});
it("should work for user with permissions (metabase#12332)", () => {
cy.signInAsNormalUser();
visitEmbeddingWithSearch("/");
- H.getSearchBar().type("product{enter}");
+
+ H.getSearchBar().type("pers");
+ cy.wait("@search");
+ cy.findByTestId("loading-indicator").should("not.exist");
+ cy.findByTestId("search-results-list").within(() => {
+ cy.findAllByText(/personal collection$/i).should("have.length", 1);
+ });
+
+ H.getSearchBar().clear().type("product{enter}");
cy.wait("@search");
cy.findByTestId("search-app").within(() => {
cy.findByText("Products");
@@ -148,48 +175,7 @@ describe("scenarios > search", () => {
.should("not.exist");
});
- it("should not overflow container if results contain descriptions with large unbroken strings", () => {
- H.createQuestion({
- name: "Description Test",
- query: { "source-table": ORDERS_ID },
- description:
- "testingtestingtestingtestingtestingtestingtestingtesting testingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtesting testingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtesting",
- }).then(() => {
- cy.signInAsNormalUser();
- visitEmbeddingWithSearch("/");
- H.getSearchBar().type("Test");
- });
-
- cy.findByTestId("search-results-floating-container")
- .as("parentContainer")
- .invoke("outerWidth")
- .then((parentWidth) => {
- cy.findByTestId("result-description")
- .invoke("outerWidth")
- .should(
- "be.lessThan",
- parentWidth,
- "Result description width should not exceed parent container width",
- );
- });
- });
-
- it("should not dismiss when a dashboard finishes loading (metabase#35009)", () => {
- visitEmbeddingWithSearch(`/dashboard/${ORDERS_DASHBOARD_ID}`);
-
- // Type as soon as possible, before the dashboard has finished loading
- H.getSearchBar().type("ord");
-
- // Once the dashboard is visible, the search results should not be dismissed
- H.main()
- .findByRole("heading", { name: "Loading..." })
- .should("not.exist");
- cy.findByTestId("search-results-floating-container").should("exist");
- });
-
- it("should not dismiss when the homepage redirects to a dashboard (metabase#34226)", () => {
- H.updateSetting("custom-homepage", true);
- H.updateSetting("custom-homepage-dashboard", ORDERS_DASHBOARD_ID);
+ it("should not dismiss when a dashboard finishes loading, when visited directly or after a homepage redirect (metabase#35099, metabase#34226)", () => {
cy.intercept(
{
url: `/api/dashboard/${ORDERS_DASHBOARD_ID}`,
@@ -203,6 +189,18 @@ describe("scenarios > search", () => {
});
},
);
+
+ visitEmbeddingWithSearch(`/dashboard/${ORDERS_DASHBOARD_ID}`);
+
+ // Type as soon as possible, before the dashboard has finished loading
+ H.getSearchBar().type("ord");
+
+ // Once the dashboard is visible, the search results should not be dismissed
+ cy.findByTestId("dashboard-parameters-and-cards").should("exist");
+ cy.findByTestId("search-results-floating-container").should("exist");
+
+ H.updateSetting("custom-homepage", true);
+ H.updateSetting("custom-homepage-dashboard", ORDERS_DASHBOARD_ID);
visitEmbeddingWithSearch("/");
// Type as soon as possible, before the dashboard has finished loading
@@ -216,8 +214,18 @@ describe("scenarios > search", () => {
});
describe("accessing full page search with `Enter`", () => {
- it("should not render full page search if user has not entered a text query", () => {
+ it("should only search and open full page search when a text query is entered", () => {
cy.intercept("GET", "/api/activity/recents?*").as("getRecentViews");
+ cy.intercept({
+ method: "GET",
+ pathname: "/api/search",
+ query: { context: "search-bar" },
+ }).as("searchBarSearch");
+ cy.intercept({
+ method: "GET",
+ pathname: "/api/search",
+ query: { context: "search-app" },
+ }).as("searchAppSearch");
visitEmbeddingWithSearch("/");
@@ -229,13 +237,33 @@ describe("scenarios > search", () => {
cy.findByText("Recently viewed").should("exist");
});
cy.location("pathname").should("eq", "/");
- });
- it("should render full page search when search text is present and user clicks 'Enter'", () => {
- visitEmbeddingWithSearch("/");
+ cy.clock(Date.now(), ["setTimeout", "clearTimeout"]);
+ H.getSearchBar().type(" ").should("have.value", " ");
+ cy.tick(SEARCH_DEBOUNCE_DURATION);
+ cy.findByTestId("search-results-floating-container").within(() => {
+ cy.findByText("Recently viewed").should("exist");
+ });
+ H.getSearchBar().type("{enter}");
+ cy.location("pathname").should("eq", "/");
+ cy.get("@searchBarSearch.all").should("have.length", 0);
- H.getSearchBar().click().type("orders{enter}");
- cy.wait("@search");
+ H.getSearchBar().clear().type("ord").should("have.value", "ord");
+ cy.tick(SEARCH_DEBOUNCE_DURATION);
+ cy.wait("@searchBarSearch");
+ cy.findByTestId("search-bar-results-container").should("be.visible");
+
+ H.getSearchBar().clear().type(" ").should("have.value", " ");
+ cy.tick(SEARCH_DEBOUNCE_DURATION);
+ cy.findByTestId("search-results-floating-container")
+ .findByText("Recently viewed")
+ .should("be.visible");
+ cy.findByTestId("search-bar-results-container").should("not.exist");
+ cy.get("@searchBarSearch.all").should("have.length", 1);
+ cy.clock().invoke("restore");
+
+ H.getSearchBar().clear().type("orders{enter}");
+ cy.wait("@searchAppSearch");
cy.findByTestId("search-app").within(() => {
cy.findByText('Results for "orders"').should("exist");
@@ -255,10 +283,18 @@ describe("issue 28788", () => {
beforeEach(() => {
H.restore();
cy.signInAsNormalUser();
- cy.intercept("GET", "/api/search*").as("search");
});
- it("search results container should not be scrollable horizontally (metabase#28788)", () => {
+ it("search results should not overflow or scroll horizontally with long names and descriptions (metabase#28788)", () => {
+ cy.signInAsAdmin();
+ H.createQuestion({
+ name: "Description Test",
+ query: { "source-table": ORDERS_ID },
+ description:
+ "testingtestingtestingtestingtestingtestingtestingtesting testingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtesting testingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtesting",
+ });
+ cy.signInAsNormalUser();
+
const questionDetails = {
name: `28788-${LONG_STRING}`,
type: "model",
@@ -282,11 +318,43 @@ describe("issue 28788", () => {
qs: { top_nav: true, search: true },
});
cy.findByPlaceholderText("Search…").type(questionDetails.name);
- cy.wait("@search");
- cy.icon("hourglass").should("not.exist");
- cy.findByTestId("search-bar-results-container").then(($container) => {
- expect(H.isScrollableHorizontally($container[0])).to.be.false;
- });
+ cy.findByTestId("search-results-list")
+ .should("contain.text", questionDetails.name)
+ .find("ul")
+ .should(($list) => {
+ expect(H.isScrollableHorizontally($list[0])).to.be.false;
+ });
+
+ cy.findByPlaceholderText("Search…").clear().type("Test");
+ cy.findByTestId("search-results-floating-container")
+ .invoke("outerWidth")
+ .then((parentWidth) => {
+ cy.contains("[data-testid=search-result-item]", "Description Test")
+ .findByTestId("result-description")
+ .invoke("outerWidth")
+ .should(
+ "be.lessThan",
+ parentWidth,
+ "Result description width should not exceed parent container width",
+ );
+ });
+ });
+});
+
+describe("command palette", () => {
+ beforeEach(() => {
+ H.restore();
+ cy.signInAsAdmin();
+ H.updateSetting("search-typeahead-enabled", false);
+ cy.visit("/");
+ });
+
+ it("should not display search results in the palette when search-typeahead-enabled is false", () => {
+ H.commandPaletteButton().click();
+ H.commandPaletteInput().type("ord");
+ H.commandPalette()
+ .findByRole("option", { name: /View search results/ })
+ .should("exist");
});
});