Skip to content

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

Repair and restructure dashboard filters matrix e2e tests (#83546)

Nemanja Glumac5d36749f800c
diff --git a/e2e/test/scenarios/dashboard-filters-matrix/dashboard-filters-matrix.cy.spec.ts b/e2e/test/scenarios/dashboard-filters-matrix/dashboard-filters-matrix.cy.spec.ts
new file mode 100644
index 00000000000..2bc5c026885
--- /dev/null
+++ b/e2e/test/scenarios/dashboard-filters-matrix/dashboard-filters-matrix.cy.spec.ts
@@ -0,0 +1,9 @@
+import { SETUP_GROUPS, runGroup } from "./helpers/matrix-helpers";
+
+describe("scenarios > dashboard > parameters > matrix", () => {
+ SETUP_GROUPS.forEach((group) => {
+ it(`parameters on a ${group.adminType} field with ${group.results} results should render the expected widget`, () => {
+ runGroup(group);
+ });
+ });
+});
diff --git a/e2e/test/scenarios/dashboard-filters-matrix/helpers/matrix-helpers.ts b/e2e/test/scenarios/dashboard-filters-matrix/helpers/matrix-helpers.ts
index 269b7186626..05810be1378 100644
--- a/e2e/test/scenarios/dashboard-filters-matrix/helpers/matrix-helpers.ts
+++ b/e2e/test/scenarios/dashboard-filters-matrix/helpers/matrix-helpers.ts
@@ -4,45 +4,37 @@ import type { ValuesQueryType } from "metabase-types/api";
import { matrix } from "./matrix";
+const ADMIN_TYPES = ["search", "list", "plain"] as const;
+const RESULTS = ["large", "small"] as const;
+
export type TestCase = {
arity: "single" | "multi";
type: "search" | "dropdown" | "plain";
- adminType: "search" | "list" | "plain";
+ adminType: (typeof ADMIN_TYPES)[number];
operator: "Is" | "Contains";
source: "connected" | "card" | "custom";
- results: "large" | "small";
+ results: (typeof RESULTS)[number];
component: "token-field" | "list-field" | "single-select-list-field";
};
-// there are 216 test cases so we need 11 spec files
-const PER_PAGE = 20;
-
-export function runPage(pageNumber: number) {
- runAll(page(pageNumber));
-}
-
-export function page(number: number): TestCase[] {
- const start = number * PER_PAGE;
- const end = start + PER_PAGE;
- return matrix.slice(start, end);
-}
+type SetupGroup = Pick<TestCase, "adminType" | "results">;
-export function runAll(cases: TestCase[]) {
- cases.forEach(run);
-}
+// Cases that share the field's `has_field_values` and mapped column can share one dashboard.
+export const SETUP_GROUPS: SetupGroup[] = ADMIN_TYPES.flatMap((adminType) =>
+ RESULTS.map((results) => ({ adminType, results })),
+);
-export function run(test: TestCase) {
- it(`a parameter (${filterName(test)}) where the admin field setting is ${test.adminType} should render ${test.component}`, () => {
- H.restore();
- cy.signInAsAdmin();
+export function runGroup({ adminType, results }: SetupGroup) {
+ const cases = matrix.filter(
+ (test) => test.adminType === adminType && test.results === results,
+ );
- setup(test);
+ H.restore();
+ cy.signInAsAdmin();
- openParameterWidget(test);
- cy.findByTestId("loading-indicator").should("not.exist");
+ setup({ adminType, results, cases });
- checkComponent(test);
- });
+ cases.forEach(checkComponent);
}
function filterName(test: TestCase) {
@@ -90,14 +82,15 @@ function parameterSource(test: TestCase, otherCardId: number) {
return {};
}
-function setup(test: TestCase) {
- const column = test.results === "large" ? PEOPLE.NAME : PEOPLE.SOURCE;
-
- // TODO: set the values source and source type
+function setup({
+ adminType,
+ results,
+ cases,
+}: SetupGroup & { cases: TestCase[] }) {
+ const column = results === "large" ? PEOPLE.NAME : PEOPLE.SOURCE;
- // Set field admin setting
cy.request("PUT", `/api/field/${column}`, {
- has_field_values: queryType(test.adminType),
+ has_field_values: queryType(adminType),
});
H.createQuestion({
@@ -110,21 +103,18 @@ function setup(test: TestCase) {
collection: "Our Analytics",
};
- const type = test.operator === "Is" ? "string/=" : "string/contains";
-
- const parameter = {
- id: "5aefc726",
+ const parameters = cases.map((test, index) => ({
+ id: `matrix-${index}`,
name: filterName(test),
- slug: "filter",
- type,
+ slug: `filter_${index}`,
+ type: test.operator === "Is" ? "string/=" : "string/contains",
+ isMultiSelect: test.arity === "multi",
values_query_type: queryType(test.type),
...parameterSource(test, otherCardId),
- };
+ }));
H.createDashboardWithQuestions({
- dashboardDetails: {
- parameters: [parameter],
- },
+ dashboardDetails: { parameters },
questions: [question],
}).then(({ dashboard, questions: cards }) => {
const [question] = cards;
@@ -134,50 +124,30 @@ function setup(test: TestCase) {
cards: [
{
card_id: question.id,
- parameter_mappings: [
- {
- parameter_id: parameter.id,
- card_id: question.id,
- target: ["dimension", ["field", column, null]],
- },
- ],
+ parameter_mappings: parameters.map((parameter) => ({
+ parameter_id: parameter.id,
+ card_id: question.id,
+ target: ["dimension", ["field", column, null]],
+ })),
},
],
});
H.visitDashboard(dashboard.id);
-
- cy.wrap(dashboard.id).as("dashboardId");
});
});
}
-function openParameterWidget(test: TestCase) {
- H.filterWidget().contains(filterName(test)).click();
-}
-
function checkComponent(test: TestCase) {
- if (test.component === "token-field") {
- cy.findByTestId("token-field").should("be.visible");
- }
- if (test.component === "list-field") {
- cy.findByTestId("list-field").should("be.visible");
- }
- if (test.component === "single-select-list-field") {
- cy.findByTestId("single-select-list-field").should("be.visible");
- }
-}
+ const name = filterName(test);
+ cy.log(`${name} should render ${test.component}`);
-// function detectComponent(): Cypress.Chainable<string | null> {
-// const validIds = ["token-field", "list-field", "single-select-list-field"];
-// return cy.get("[data-testid]").then(res => {
-// let id: string | null = null;
-// res.each((_, el) => {
-// const testid = el.dataset.testid;
-// if (testid && validIds.includes(testid)) {
-// id = testid;
-// }
-// });
-// return id;
-// });
-// }
+ H.filterWidget().contains(name).click();
+ cy.findByTestId("loading-indicator").should("not.exist");
+ H.dashboardParametersPopover()
+ .findByTestId(test.component)
+ .should("be.visible");
+
+ H.filterWidget().contains(name).click();
+ cy.findByTestId("parameter-value-dropdown").should("not.exist");
+}
diff --git a/e2e/test/scenarios/dashboard-filters-matrix/helpers/matrix.ts b/e2e/test/scenarios/dashboard-filters-matrix/helpers/matrix.ts
index 5eb12cc4326..bc045a1ba14 100644
--- a/e2e/test/scenarios/dashboard-filters-matrix/helpers/matrix.ts
+++ b/e2e/test/scenarios/dashboard-filters-matrix/helpers/matrix.ts
@@ -125,7 +125,7 @@ export const matrix: TestCase[] = [
operator: "Is",
source: "connected",
results: "small",
- component: "list-field",
+ component: "single-select-list-field",
},
{
arity: "single",
@@ -179,7 +179,7 @@ export const matrix: TestCase[] = [
operator: "Contains",
source: "connected",
results: "small",
- component: "list-field",
+ component: "single-select-list-field",
},
{
arity: "single",
@@ -368,7 +368,7 @@ export const matrix: TestCase[] = [
operator: "Is",
source: "custom",
results: "large",
- component: "list-field",
+ component: "single-select-list-field",
},
{
arity: "single",
@@ -377,7 +377,7 @@ export const matrix: TestCase[] = [
operator: "Is",
source: "custom",
results: "small",
- component: "list-field",
+ component: "single-select-list-field",
},
{
arity: "single",
@@ -422,7 +422,7 @@ export const matrix: TestCase[] = [
operator: "Contains",
source: "custom",
results: "large",
- component: "list-field",
+ component: "single-select-list-field",
},
{
arity: "single",
@@ -431,7 +431,7 @@ export const matrix: TestCase[] = [
operator: "Contains",
source: "custom",
results: "small",
- component: "list-field",
+ component: "single-select-list-field",
},
{
arity: "single",
@@ -449,7 +449,7 @@ export const matrix: TestCase[] = [
operator: "Is",
source: "connected",
results: "small",
- component: "list-field",
+ component: "single-select-list-field",
},
{
arity: "single",
@@ -476,7 +476,7 @@ export const matrix: TestCase[] = [
operator: "Is",
source: "custom",
results: "large",
- component: "list-field",
+ component: "single-select-list-field",
},
{
arity: "single",
@@ -485,7 +485,7 @@ export const matrix: TestCase[] = [
operator: "Is",
source: "custom",
results: "small",
- component: "list-field",
+ component: "single-select-list-field",
},
{
arity: "single",
@@ -503,7 +503,7 @@ export const matrix: TestCase[] = [
operator: "Contains",
source: "connected",
results: "small",
- component: "list-field",
+ component: "single-select-list-field",
},
{
arity: "single",
@@ -530,7 +530,7 @@ export const matrix: TestCase[] = [
operator: "Contains",
source: "custom",
results: "large",
- component: "list-field",
+ component: "single-select-list-field",
},
{
arity: "single",
@@ -539,7 +539,7 @@ export const matrix: TestCase[] = [
operator: "Contains",
source: "custom",
results: "small",
- component: "list-field",
+ component: "single-select-list-field",
},
{
arity: "single",
@@ -584,7 +584,7 @@ export const matrix: TestCase[] = [
operator: "Is",
source: "custom",
results: "large",
- component: "list-field",
+ component: "single-select-list-field",
},
{
arity: "single",
@@ -593,7 +593,7 @@ export const matrix: TestCase[] = [
operator: "Is",
source: "custom",
results: "small",
- component: "list-field",
+ component: "single-select-list-field",
},
{
arity: "single",
@@ -638,7 +638,7 @@ export const matrix: TestCase[] = [
operator: "Contains",
source: "custom",
results: "large",
- component: "list-field",
+ component: "single-select-list-field",
},
{
arity: "single",
@@ -647,7 +647,7 @@ export const matrix: TestCase[] = [
operator: "Contains",
source: "custom",
results: "small",
- component: "list-field",
+ component: "single-select-list-field",
},
{
arity: "single",
diff --git a/e2e/test/scenarios/dashboard-filters-matrix/page-0.cy.spec.ts b/e2e/test/scenarios/dashboard-filters-matrix/page-0.cy.spec.ts
deleted file mode 100644
index 57c3b113b03..00000000000
--- a/e2e/test/scenarios/dashboard-filters-matrix/page-0.cy.spec.ts
+++ /dev/null
@@ -1,5 +0,0 @@
-import { runPage } from "./helpers/matrix-helpers";
-
-describe("scenarios > dashboard > parameters > matrix", () => {
- runPage(0);
-});
diff --git a/e2e/test/scenarios/dashboard-filters-matrix/page-1.cy.spec.ts b/e2e/test/scenarios/dashboard-filters-matrix/page-1.cy.spec.ts
deleted file mode 100644
index a6ab40c782e..00000000000
--- a/e2e/test/scenarios/dashboard-filters-matrix/page-1.cy.spec.ts
+++ /dev/null
@@ -1,5 +0,0 @@
-import { runPage } from "./helpers/matrix-helpers";
-
-describe("scenarios > dashboard > parameters > matrix", () => {
- runPage(1);
-});
diff --git a/e2e/test/scenarios/dashboard-filters-matrix/page-10.cy.spec.ts b/e2e/test/scenarios/dashboard-filters-matrix/page-10.cy.spec.ts
deleted file mode 100644
index d44442f0d34..00000000000
--- a/e2e/test/scenarios/dashboard-filters-matrix/page-10.cy.spec.ts
+++ /dev/null
@@ -1,5 +0,0 @@
-import { runPage } from "./helpers/matrix-helpers";
-
-describe("scenarios > dashboard > parameters > matrix", () => {
- runPage(10);
-});
diff --git a/e2e/test/scenarios/dashboard-filters-matrix/page-2.cy.spec.ts b/e2e/test/scenarios/dashboard-filters-matrix/page-2.cy.spec.ts
deleted file mode 100644
index a6c14a0de35..00000000000
--- a/e2e/test/scenarios/dashboard-filters-matrix/page-2.cy.spec.ts
+++ /dev/null
@@ -1,5 +0,0 @@
-import { runPage } from "./helpers/matrix-helpers";
-
-describe("scenarios > dashboard > parameters > matrix", () => {
- runPage(2);
-});
diff --git a/e2e/test/scenarios/dashboard-filters-matrix/page-3.cy.spec.ts b/e2e/test/scenarios/dashboard-filters-matrix/page-3.cy.spec.ts
deleted file mode 100644
index e146e04c8cd..00000000000
--- a/e2e/test/scenarios/dashboard-filters-matrix/page-3.cy.spec.ts
+++ /dev/null
@@ -1,5 +0,0 @@
-import { runPage } from "./helpers/matrix-helpers";
-
-describe("scenarios > dashboard > parameters > matrix", () => {
- runPage(3);
-});
diff --git a/e2e/test/scenarios/dashboard-filters-matrix/page-4.cy.spec.ts b/e2e/test/scenarios/dashboard-filters-matrix/page-4.cy.spec.ts
deleted file mode 100644
index f9a463108f8..00000000000
--- a/e2e/test/scenarios/dashboard-filters-matrix/page-4.cy.spec.ts
+++ /dev/null
@@ -1,5 +0,0 @@
-import { runPage } from "./helpers/matrix-helpers";
-
-describe("scenarios > dashboard > parameters > matrix", () => {
- runPage(4);
-});
diff --git a/e2e/test/scenarios/dashboard-filters-matrix/page-5.cy.spec.ts b/e2e/test/scenarios/dashboard-filters-matrix/page-5.cy.spec.ts
deleted file mode 100644
index 271b1dff540..00000000000
--- a/e2e/test/scenarios/dashboard-filters-matrix/page-5.cy.spec.ts
+++ /dev/null
@@ -1,5 +0,0 @@
-import { runPage } from "./helpers/matrix-helpers";
-
-describe("scenarios > dashboard > parameters > matrix", () => {
- runPage(5);
-});
diff --git a/e2e/test/scenarios/dashboard-filters-matrix/page-6.cy.spec.ts b/e2e/test/scenarios/dashboard-filters-matrix/page-6.cy.spec.ts
deleted file mode 100644
index 7455e847571..00000000000
--- a/e2e/test/scenarios/dashboard-filters-matrix/page-6.cy.spec.ts
+++ /dev/null
@@ -1,5 +0,0 @@
-import { runPage } from "./helpers/matrix-helpers";
-
-describe("scenarios > dashboard > parameters > matrix", () => {
- runPage(6);
-});
diff --git a/e2e/test/scenarios/dashboard-filters-matrix/page-7.cy.spec.ts b/e2e/test/scenarios/dashboard-filters-matrix/page-7.cy.spec.ts
deleted file mode 100644
index c496a421a13..00000000000
--- a/e2e/test/scenarios/dashboard-filters-matrix/page-7.cy.spec.ts
+++ /dev/null
@@ -1,5 +0,0 @@
-import { runPage } from "./helpers/matrix-helpers";
-
-describe("scenarios > dashboard > parameters > matrix", () => {
- runPage(7);
-});
diff --git a/e2e/test/scenarios/dashboard-filters-matrix/page-8.cy.spec.ts b/e2e/test/scenarios/dashboard-filters-matrix/page-8.cy.spec.ts
deleted file mode 100644
index f2db2a4beaf..00000000000
--- a/e2e/test/scenarios/dashboard-filters-matrix/page-8.cy.spec.ts
+++ /dev/null
@@ -1,5 +0,0 @@
-import { runPage } from "./helpers/matrix-helpers";
-
-describe("scenarios > dashboard > parameters > matrix", () => {
- runPage(8);
-});
diff --git a/e2e/test/scenarios/dashboard-filters-matrix/page-9.cy.spec.ts b/e2e/test/scenarios/dashboard-filters-matrix/page-9.cy.spec.ts
deleted file mode 100644
index b80feada2b5..00000000000
--- a/e2e/test/scenarios/dashboard-filters-matrix/page-9.cy.spec.ts
+++ /dev/null
@@ -1,5 +0,0 @@
-import { runPage } from "./helpers/matrix-helpers";
-
-describe("scenarios > dashboard > parameters > matrix", () => {
- runPage(9);
-});