Skip to content
Snippets Groups Projects
Unverified Commit c6d10cbc authored by Kamil Mielnik's avatar Kamil Mielnik Committed by GitHub
Browse files

Break search.cy.spec.js down (#40301)

parent 4f2de2c1
No related branches found
No related tags found
No related merge requests found
export function getSearchBar() {
return cy.findByPlaceholderText("Search…");
}
/**
* Checks the search results against expectedSearchValues, including descriptions,
* collection names, and timestamps, depending on the given data.
*
* @param {Object} options - Options for the test.
* @param {Object[]} options.expectedSearchResults - An array of search result items to compare against.
* @param {string} options.expectedSearchResults[].name - The name of the search result item.
* @param {string} options.expectedSearchResults[].description - The description of the search result item.
* @param {string} options.expectedSearchResults[].collection - The collection label of the search result item.
* @param {string} options.expectedSearchResults[].timestamp - The timestamp label of the search result item .
* @param {boolean} [strict=true] - Whether to check if the contents AND length of search results are the same
*/
export function expectSearchResultContent({
expectedSearchResults,
strict = true,
}) {
const searchResultItemSelector = "[data-testid=search-result-item]";
const searchResultItems = cy.get(searchResultItemSelector);
searchResultItems.then($results => {
if (strict) {
// Check if the length of the search results is the same as the expected length
expect($results).to.have.length(expectedSearchResults.length);
}
});
for (const expectedSearchResult of expectedSearchResults) {
cy.contains(searchResultItemSelector, expectedSearchResult.name).within(
() => {
cy.findByTestId("search-result-item-name").findByText(
expectedSearchResult.name,
);
if (expectedSearchResult.description) {
cy.findByTestId("result-description").findByText(
expectedSearchResult.description,
);
}
if (expectedSearchResult.collection) {
cy.findAllByTestId("result-link-wrapper").first(() => {
cy.findByText(expectedSearchResult.collection).should("exist");
});
}
if (expectedSearchResult.timestamp) {
cy.findByTestId("revision-history-button").findByText(
expectedSearchResult.timestamp,
);
}
if (expectedSearchResult.icon) {
cy.icon(expectedSearchResult.icon);
}
},
);
}
}
......@@ -28,6 +28,7 @@ export * from "./e2e-embedding-helpers";
export * from "./e2e-permissions-helpers";
export * from "./e2e-question-helpers";
export * from "./e2e-request-helpers";
export * from "./e2e-search-helpers";
export * from "./e2e-visual-tests-helpers";
export * from "./e2e-users-helpers";
export * from "./e2e-viz-settings-helpers";
......
This diff is collapsed.
import {
describeEE,
describeWithSnowplow,
enableTracking,
expectGoodSnowplowEvent,
expectNoBadSnowplowEvents,
getSearchBar,
popover,
resetSnowplow,
restore,
setTokenFeatures,
} from "e2e/support/helpers";
describeWithSnowplow("scenarios > search > snowplow", () => {
const SEARCH_RESULTS_FILTERED_NAME = "search_results_filtered";
const NEW_SEARCH_QUERY_EVENT_NAME = "new_search_query";
beforeEach(() => {
restore();
resetSnowplow();
cy.signInAsAdmin();
enableTracking();
});
afterEach(() => {
expectNoBadSnowplowEvents();
});
it("should send snowplow events for global search queries", () => {
cy.visit("/");
getSearchBar().type("Orders").blur();
expectGoodSnowplowEvent({ event: NEW_SEARCH_QUERY_EVENT_NAME }, 1);
});
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, but not search_results_filtered when a search with no filters is accessed from the URL", () => {
cy.visit("/search?q=orders");
expectGoodSnowplowEvent({ event: NEW_SEARCH_QUERY_EVENT_NAME }, 1);
expectGoodSnowplowEvent({ event: SEARCH_RESULTS_FILTERED_NAME }, 0);
});
});
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");
expectGoodSnowplowEvent({ event: NEW_SEARCH_QUERY_EVENT_NAME }, 1);
expectGoodSnowplowEvent({ event: SEARCH_RESULTS_FILTERED_NAME }, 1);
});
it("should send a snowplow event when a search filter is applied from the UI", () => {
cy.visit("/search?q=orders");
expectGoodSnowplowEvent({ event: NEW_SEARCH_QUERY_EVENT_NAME }, 1);
expectGoodSnowplowEvent({ event: SEARCH_RESULTS_FILTERED_NAME }, 0);
cy.findByTestId("type-search-filter").click();
popover().within(() => {
cy.findAllByTestId("type-filter-checkbox").each($el => {
cy.wrap($el).click();
});
cy.findByText("Apply").click();
});
expectGoodSnowplowEvent({ event: NEW_SEARCH_QUERY_EVENT_NAME }, 2);
expectGoodSnowplowEvent({ event: SEARCH_RESULTS_FILTERED_NAME }, 1);
});
it("should send a snowplow event when a search filter is removed from the UI", () => {
cy.visit("/search?q=orders&type=card");
expectGoodSnowplowEvent({ event: NEW_SEARCH_QUERY_EVENT_NAME }, 1);
expectGoodSnowplowEvent({ event: SEARCH_RESULTS_FILTERED_NAME }, 1);
cy.findByTestId("type-search-filter")
.findByLabelText("close icon")
.click();
expectGoodSnowplowEvent({ event: NEW_SEARCH_QUERY_EVENT_NAME }, 2);
expectGoodSnowplowEvent({ event: SEARCH_RESULTS_FILTERED_NAME }, 1);
});
});
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");
expectGoodSnowplowEvent({ event: NEW_SEARCH_QUERY_EVENT_NAME }, 1);
expectGoodSnowplowEvent({ event: SEARCH_RESULTS_FILTERED_NAME }, 1);
});
it("should send a snowplow event when a search filter is applied from the UI", () => {
cy.visit("/search?q=orders");
expectGoodSnowplowEvent({ event: NEW_SEARCH_QUERY_EVENT_NAME }, 1);
expectGoodSnowplowEvent({ event: SEARCH_RESULTS_FILTERED_NAME }, 0);
cy.findByTestId("created_by-search-filter").click();
popover().within(() => {
cy.findByText("Bobby Tables").click();
cy.findByText("Apply").click();
});
expectGoodSnowplowEvent({ event: NEW_SEARCH_QUERY_EVENT_NAME }, 2);
expectGoodSnowplowEvent({ event: SEARCH_RESULTS_FILTERED_NAME }, 1);
});
it("should send a snowplow event when a search filter is removed from the UI", () => {
cy.visit("/search?q=orders&created_by=1");
expectGoodSnowplowEvent({ event: NEW_SEARCH_QUERY_EVENT_NAME }, 1);
expectGoodSnowplowEvent({ event: SEARCH_RESULTS_FILTERED_NAME }, 1);
cy.findByTestId("created_by-search-filter")
.findByLabelText("close icon")
.click();
expectGoodSnowplowEvent({ event: NEW_SEARCH_QUERY_EVENT_NAME }, 2);
expectGoodSnowplowEvent({ event: SEARCH_RESULTS_FILTERED_NAME }, 1);
});
});
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");
expectGoodSnowplowEvent({ event: NEW_SEARCH_QUERY_EVENT_NAME }, 1);
expectGoodSnowplowEvent({ event: SEARCH_RESULTS_FILTERED_NAME }, 1);
});
it("should send a snowplow event when a search filter is applied from the UI", () => {
cy.visit("/search?q=orders");
expectGoodSnowplowEvent({ event: NEW_SEARCH_QUERY_EVENT_NAME }, 1);
expectGoodSnowplowEvent({ event: SEARCH_RESULTS_FILTERED_NAME }, 0);
cy.findByTestId("last_edited_by-search-filter").click();
popover().within(() => {
cy.findByText("Bobby Tables").click();
cy.findByText("Apply").click();
});
expectGoodSnowplowEvent({ event: NEW_SEARCH_QUERY_EVENT_NAME }, 2);
expectGoodSnowplowEvent({ event: SEARCH_RESULTS_FILTERED_NAME }, 1);
});
it("should send a snowplow event when a search filter is removed from the UI", () => {
cy.visit("/search?q=orders&last_edited_by=1");
expectGoodSnowplowEvent({ event: NEW_SEARCH_QUERY_EVENT_NAME }, 1);
expectGoodSnowplowEvent({ event: SEARCH_RESULTS_FILTERED_NAME }, 1);
cy.findByTestId("last_edited_by-search-filter")
.findByLabelText("close icon")
.click();
expectGoodSnowplowEvent({ event: NEW_SEARCH_QUERY_EVENT_NAME }, 2);
expectGoodSnowplowEvent({ event: SEARCH_RESULTS_FILTERED_NAME }, 1);
});
});
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");
expectGoodSnowplowEvent({ event: NEW_SEARCH_QUERY_EVENT_NAME }, 1);
expectGoodSnowplowEvent({ event: SEARCH_RESULTS_FILTERED_NAME }, 1);
});
it("should send a snowplow event when a search filter is applied from the UI", () => {
cy.visit("/search?q=orders");
expectGoodSnowplowEvent({ event: NEW_SEARCH_QUERY_EVENT_NAME }, 1);
expectGoodSnowplowEvent({ event: SEARCH_RESULTS_FILTERED_NAME }, 0);
cy.findByTestId("created_at-search-filter").click();
popover().within(() => {
cy.findByText("Today").click();
});
expectGoodSnowplowEvent({ event: NEW_SEARCH_QUERY_EVENT_NAME }, 2);
expectGoodSnowplowEvent({ event: SEARCH_RESULTS_FILTERED_NAME }, 1);
});
it("should send a snowplow event when a search filter is removed from the UI", () => {
cy.visit("/search?q=orders&created_at=thisday");
expectGoodSnowplowEvent({ event: NEW_SEARCH_QUERY_EVENT_NAME }, 1);
expectGoodSnowplowEvent({ event: SEARCH_RESULTS_FILTERED_NAME }, 1);
cy.findByTestId("created_at-search-filter")
.findByLabelText("close icon")
.click();
expectGoodSnowplowEvent({ event: NEW_SEARCH_QUERY_EVENT_NAME }, 2);
expectGoodSnowplowEvent({ event: SEARCH_RESULTS_FILTERED_NAME }, 1);
});
});
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");
expectGoodSnowplowEvent({ event: NEW_SEARCH_QUERY_EVENT_NAME }, 1);
expectGoodSnowplowEvent({ event: SEARCH_RESULTS_FILTERED_NAME }, 1);
});
it("should send a snowplow event when a search filter is applied from the UI", () => {
cy.visit("/search?q=orders");
expectGoodSnowplowEvent({ event: NEW_SEARCH_QUERY_EVENT_NAME }, 1);
expectGoodSnowplowEvent({ event: SEARCH_RESULTS_FILTERED_NAME }, 0);
cy.findByTestId("last_edited_at-search-filter").click();
popover().within(() => {
cy.findByText("Today").click();
});
expectGoodSnowplowEvent({ event: NEW_SEARCH_QUERY_EVENT_NAME }, 2);
expectGoodSnowplowEvent({ event: SEARCH_RESULTS_FILTERED_NAME }, 1);
});
it("should send a snowplow event when a search filter is removed from the UI", () => {
cy.visit("/search?q=orders&last_edited_at=thisday");
expectGoodSnowplowEvent({ event: NEW_SEARCH_QUERY_EVENT_NAME }, 1);
expectGoodSnowplowEvent({ event: SEARCH_RESULTS_FILTERED_NAME }, 1);
cy.findByTestId("last_edited_at-search-filter")
.findByLabelText("close icon")
.click();
expectGoodSnowplowEvent({ event: NEW_SEARCH_QUERY_EVENT_NAME }, 2);
expectGoodSnowplowEvent({ event: SEARCH_RESULTS_FILTERED_NAME }, 1);
});
});
describeEE("verified filter", () => {
beforeEach(() => {
setTokenFeatures("all");
});
it("should send a snowplow event when a search filter is used in the URL", () => {
cy.visit("/search?q=orders&verified=true");
expectGoodSnowplowEvent({ event: NEW_SEARCH_QUERY_EVENT_NAME }, 1);
expectGoodSnowplowEvent({ event: SEARCH_RESULTS_FILTERED_NAME }, 1);
});
it("should send a snowplow event when a search filter is applied from the UI", () => {
cy.visit("/search?q=orders");
expectGoodSnowplowEvent({ event: NEW_SEARCH_QUERY_EVENT_NAME }, 1);
expectGoodSnowplowEvent({ event: SEARCH_RESULTS_FILTERED_NAME }, 0);
cy.findByTestId("verified-search-filter")
.findByText("Verified items only")
.click();
expectGoodSnowplowEvent({ event: NEW_SEARCH_QUERY_EVENT_NAME }, 2);
expectGoodSnowplowEvent({ event: SEARCH_RESULTS_FILTERED_NAME }, 1);
});
it("should send a snowplow event when a search filter is removed from the UI", () => {
cy.visit("/search?q=orders&verified=true");
expectGoodSnowplowEvent({ event: NEW_SEARCH_QUERY_EVENT_NAME }, 1);
expectGoodSnowplowEvent({ event: SEARCH_RESULTS_FILTERED_NAME }, 1);
cy.findByTestId("verified-search-filter")
.findByText("Verified items only")
.click();
expectGoodSnowplowEvent({ event: NEW_SEARCH_QUERY_EVENT_NAME }, 2);
expectGoodSnowplowEvent({ event: SEARCH_RESULTS_FILTERED_NAME }, 1);
});
});
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");
expectGoodSnowplowEvent({ event: NEW_SEARCH_QUERY_EVENT_NAME }, 1);
expectGoodSnowplowEvent({ event: SEARCH_RESULTS_FILTERED_NAME }, 1);
});
it("should send a snowplow event when a search filter is applied from the UI", () => {
cy.visit("/search?q=orders");
expectGoodSnowplowEvent({ event: NEW_SEARCH_QUERY_EVENT_NAME }, 1);
expectGoodSnowplowEvent({ event: SEARCH_RESULTS_FILTERED_NAME }, 0);
cy.findByTestId("search_native_query-search-filter")
.findByText("Search the contents of native queries")
.click();
expectGoodSnowplowEvent({ event: NEW_SEARCH_QUERY_EVENT_NAME }, 2);
expectGoodSnowplowEvent({ event: SEARCH_RESULTS_FILTERED_NAME }, 1);
});
it("should send a snowplow event when a search filter is removed from the UI", () => {
cy.visit("/search?q=orders&search_native_query=true");
expectGoodSnowplowEvent({ event: NEW_SEARCH_QUERY_EVENT_NAME }, 1);
expectGoodSnowplowEvent({ event: SEARCH_RESULTS_FILTERED_NAME }, 1);
cy.findByTestId("search_native_query-search-filter")
.findByText("Search the contents of native queries")
.click();
expectGoodSnowplowEvent({ event: NEW_SEARCH_QUERY_EVENT_NAME }, 2);
expectGoodSnowplowEvent({ event: SEARCH_RESULTS_FILTERED_NAME }, 1);
});
});
});
});
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment