Skip to content

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

e2e2unit: Dashboard filters matrix (#86003)

Nemanja Glumace7d7eea206f7
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
deleted file mode 100644
index 2bc5c026885..00000000000
--- a/e2e/test/scenarios/dashboard-filters-matrix/dashboard-filters-matrix.cy.spec.ts
+++ /dev/null
@@ -1,9 +0,0 @@
-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
deleted file mode 100644
index 05810be1378..00000000000
--- a/e2e/test/scenarios/dashboard-filters-matrix/helpers/matrix-helpers.ts
+++ /dev/null
@@ -1,153 +0,0 @@
-const { H } = cy;
-import { SAMPLE_DATABASE } from "e2e/support/cypress_sample_database";
-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: (typeof ADMIN_TYPES)[number];
- operator: "Is" | "Contains";
- source: "connected" | "card" | "custom";
- results: (typeof RESULTS)[number];
- component: "token-field" | "list-field" | "single-select-list-field";
-};
-
-type SetupGroup = Pick<TestCase, "adminType" | "results">;
-
-// 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 runGroup({ adminType, results }: SetupGroup) {
- const cases = matrix.filter(
- (test) => test.adminType === adminType && test.results === results,
- );
-
- H.restore();
- cy.signInAsAdmin();
-
- setup({ adminType, results, cases });
-
- cases.forEach(checkComponent);
-}
-
-function filterName(test: TestCase) {
- return `${test.arity} ${test.type} ${test.adminType} ${test.results} ${test.operator} ${test.source}`;
-}
-
-function queryType(
- type: "search" | "dropdown" | "list" | "plain",
-): ValuesQueryType {
- switch (type) {
- case "search":
- return "search";
- case "dropdown":
- case "list":
- return "list";
- case "plain":
- return "none";
- }
-}
-
-const { PEOPLE, PEOPLE_ID, ACCOUNTS, ACCOUNTS_ID } = SAMPLE_DATABASE;
-
-function parameterSource(test: TestCase, otherCardId: number) {
- if (test.source === "connected") {
- return {};
- }
- if (test.source === "card") {
- return {
- values_source_type: "card" as const,
- values_source_config: {
- card_id: otherCardId,
- value_field: ["field", ACCOUNTS.FIRST_NAME, null],
- },
- };
- }
- if (test.source === "custom") {
- const count = test.results === "large" ? 1050 : 5;
- return {
- values_source_type: "static-list" as const,
- values_source_config: {
- values: new Array(count).fill(0).map((_, i) => `Value ${i}`),
- },
- };
- }
- return {};
-}
-
-function setup({
- adminType,
- results,
- cases,
-}: SetupGroup & { cases: TestCase[] }) {
- const column = results === "large" ? PEOPLE.NAME : PEOPLE.SOURCE;
-
- cy.request("PUT", `/api/field/${column}`, {
- has_field_values: queryType(adminType),
- });
-
- H.createQuestion({
- name: "Accounts Question",
- query: { "source-table": ACCOUNTS_ID },
- }).then(({ body: { id: otherCardId } }) => {
- const question = {
- name: "People Question",
- query: { "source-table": PEOPLE_ID },
- collection: "Our Analytics",
- };
-
- const parameters = cases.map((test, index) => ({
- id: `matrix-${index}`,
- name: filterName(test),
- 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 },
- questions: [question],
- }).then(({ dashboard, questions: cards }) => {
- const [question] = cards;
-
- H.updateDashboardCards({
- dashboard_id: dashboard.id,
- cards: [
- {
- card_id: question.id,
- parameter_mappings: parameters.map((parameter) => ({
- parameter_id: parameter.id,
- card_id: question.id,
- target: ["dimension", ["field", column, null]],
- })),
- },
- ],
- });
-
- H.visitDashboard(dashboard.id);
- });
- });
-}
-
-function checkComponent(test: TestCase) {
- const name = filterName(test);
- cy.log(`${name} should render ${test.component}`);
-
- 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
deleted file mode 100644
index bc045a1ba14..00000000000
--- a/e2e/test/scenarios/dashboard-filters-matrix/helpers/matrix.ts
+++ /dev/null
@@ -1,1948 +0,0 @@
-import type { TestCase } from "./matrix-helpers";
-
-export const matrix: TestCase[] = [
- {
- arity: "single",
- type: "search",
- adminType: "search",
- operator: "Is",
- source: "connected",
- results: "large",
- component: "token-field",
- },
- {
- arity: "single",
- type: "search",
- adminType: "search",
- operator: "Is",
- source: "connected",
- results: "small",
- component: "token-field",
- },
- {
- arity: "single",
- type: "search",
- adminType: "search",
- operator: "Is",
- source: "card",
- results: "large",
- component: "token-field",
- },
- {
- arity: "single",
- type: "search",
- adminType: "search",
- operator: "Is",
- source: "card",
- results: "small",
- component: "token-field",
- },
- {
- arity: "single",
- type: "search",
- adminType: "search",
- operator: "Is",
- source: "custom",
- results: "large",
- component: "token-field",
- },
- {
- arity: "single",
- type: "search",
- adminType: "search",
- operator: "Is",
- source: "custom",
- results: "small",
- component: "token-field",
- },
- {
- arity: "single",
- type: "search",
- adminType: "search",
- operator: "Contains",
- source: "connected",
- results: "large",
- component: "token-field",
- },
- {
- arity: "single",
- type: "search",
- adminType: "search",
- operator: "Contains",
- source: "connected",
- results: "small",
- component: "token-field",
- },
- {
- arity: "single",
- type: "search",
- adminType: "search",
- operator: "Contains",
- source: "card",
- results: "large",
- component: "token-field",
- },
- {
- arity: "single",
- type: "search",
- adminType: "search",
- operator: "Contains",
- source: "card",
- results: "small",
- component: "token-field",
- },
- {
- arity: "single",
- type: "search",
- adminType: "search",
- operator: "Contains",
- source: "custom",
- results: "large",
- component: "token-field",
- },
- {
- arity: "single",
- type: "search",
- adminType: "search",
- operator: "Contains",
- source: "custom",
- results: "small",
- component: "token-field",
- },
- {
- arity: "single",
- type: "search",
- adminType: "list",
- operator: "Is",
- source: "connected",
- results: "large",
- component: "token-field",
- },
- {
- arity: "single",
- type: "search",
- adminType: "list",
- operator: "Is",
- source: "connected",
- results: "small",
- component: "single-select-list-field",
- },
- {
- arity: "single",
- type: "search",
- adminType: "list",
- operator: "Is",
- source: "card",
- results: "large",
- component: "token-field",
- },
- {
- arity: "single",
- type: "search",
- adminType: "list",
- operator: "Is",
- source: "card",
- results: "small",
- component: "token-field",
- },
- {
- arity: "single",
- type: "search",
- adminType: "list",
- operator: "Is",
- source: "custom",
- results: "large",
- component: "token-field",
- },
- {
- arity: "single",
- type: "search",
- adminType: "list",
- operator: "Is",
- source: "custom",
- results: "small",
- component: "token-field",
- },
- {
- arity: "single",
- type: "search",
- adminType: "list",
- operator: "Contains",
- source: "connected",
- results: "large",
- component: "token-field",
- },
- {
- arity: "single",
- type: "search",
- adminType: "list",
- operator: "Contains",
- source: "connected",
- results: "small",
- component: "single-select-list-field",
- },
- {
- arity: "single",
- type: "search",
- adminType: "list",
- operator: "Contains",
- source: "card",
- results: "large",
- component: "token-field",
- },
- {
- arity: "single",
- type: "search",
- adminType: "list",
- operator: "Contains",
- source: "card",
- results: "small",
- component: "token-field",
- },
- {
- arity: "single",
- type: "search",
- adminType: "list",
- operator: "Contains",
- source: "custom",
- results: "large",
- component: "token-field",
- },
- {
- arity: "single",
- type: "search",
- adminType: "list",
- operator: "Contains",
- source: "custom",
- results: "small",
- component: "token-field",
- },
- {
- arity: "single",
- type: "search",
- adminType: "plain",
- operator: "Is",
- source: "connected",
- results: "large",
- component: "token-field",
- },
- {
- arity: "single",
- type: "search",
- adminType: "plain",
- operator: "Is",
- source: "connected",
- results: "small",
- component: "token-field",
- },
- {
- arity: "single",
- type: "search",
- adminType: "plain",
- operator: "Is",
- source: "card",
- results: "large",
- component: "token-field",
- },
- {
- arity: "single",
- type: "search",
- adminType: "plain",
- operator: "Is",
- source: "card",
- results: "small",
- component: "token-field",
- },
- {
- arity: "single",
- type: "search",
- adminType: "plain",
- operator: "Is",
- source: "custom",
- results: "large",
- component: "token-field",
- },
- {
- arity: "single",
- type: "search",
- adminType: "plain",
- operator: "Is",
- source: "custom",
- results: "small",
- component: "token-field",
- },
- {
- arity: "single",
- type: "search",
- adminType: "plain",
- operator: "Contains",
- source: "connected",
- results: "large",
- component: "token-field",
- },
- {
- arity: "single",
- type: "search",
- adminType: "plain",
- operator: "Contains",
- source: "connected",
- results: "small",
- component: "token-field",
- },
- {
- arity: "single",
- type: "search",
- adminType: "plain",
- operator: "Contains",
- source: "card",
- results: "large",
- component: "token-field",
- },
- {
- arity: "single",
- type: "search",
- adminType: "plain",
- operator: "Contains",
- source: "card",
- results: "small",
- component: "token-field",
- },
- {
- arity: "single",
- type: "search",
- adminType: "plain",
- operator: "Contains",
- source: "custom",
- results: "large",
- component: "token-field",
- },
- {
- arity: "single",
- type: "search",
- adminType: "plain",
- operator: "Contains",
- source: "custom",
- results: "small",
- component: "token-field",
- },
- {
- arity: "single",
- type: "dropdown",
- adminType: "search",
- operator: "Is",
- source: "connected",
- results: "large",
- component: "token-field",
- },
- {
- arity: "single",
- type: "dropdown",
- adminType: "search",
- operator: "Is",
- source: "connected",
- results: "small",
- component: "token-field",
- },
- {
- arity: "single",
- type: "dropdown",
- adminType: "search",
- operator: "Is",
- source: "card",
- results: "large",
- component: "token-field",
- },
- {
- arity: "single",
- type: "dropdown",
- adminType: "search",
- operator: "Is",
- source: "card",
- results: "small",
- component: "token-field",
- },
- {
- arity: "single",
- type: "dropdown",
- adminType: "search",
- operator: "Is",
- source: "custom",
- results: "large",
- component: "single-select-list-field",
- },
- {
- arity: "single",
- type: "dropdown",
- adminType: "search",
- operator: "Is",
- source: "custom",
- results: "small",
- component: "single-select-list-field",
- },
- {
- arity: "single",
- type: "dropdown",
- adminType: "search",
- operator: "Contains",
- source: "connected",
- results: "large",
- component: "token-field",
- },
- {
- arity: "single",
- type: "dropdown",
- adminType: "search",
- operator: "Contains",
- source: "connected",
- results: "small",
- component: "token-field",
- },
- {
- arity: "single",
- type: "dropdown",
- adminType: "search",
- operator: "Contains",
- source: "card",
- results: "large",
- component: "token-field",
- },
- {
- arity: "single",
- type: "dropdown",
- adminType: "search",
- operator: "Contains",
- source: "card",
- results: "small",
- component: "token-field",
- },
- {
- arity: "single",
- type: "dropdown",
- adminType: "search",
- operator: "Contains",
- source: "custom",
- results: "large",
- component: "single-select-list-field",
- },
- {
- arity: "single",
- type: "dropdown",
- adminType: "search",
- operator: "Contains",
- source: "custom",
- results: "small",
- component: "single-select-list-field",
- },
- {
- arity: "single",
- type: "dropdown",
- adminType: "list",
- operator: "Is",
- source: "connected",
- results: "large",
- component: "token-field",
- },
- {
- arity: "single",
- type: "dropdown",
- adminType: "list",
- operator: "Is",
- source: "connected",
- results: "small",
- component: "single-select-list-field",
- },
- {
- arity: "single",
- type: "dropdown",
- adminType: "list",
- operator: "Is",
- source: "card",
- results: "large",
- component: "token-field",
- },
- {
- arity: "single",
- type: "dropdown",
- adminType: "list",
- operator: "Is",
- source: "card",
- results: "small",
- component: "token-field",
- },
- {
- arity: "single",
- type: "dropdown",
- adminType: "list",
- operator: "Is",
- source: "custom",
- results: "large",
- component: "single-select-list-field",
- },
- {
- arity: "single",
- type: "dropdown",
- adminType: "list",
- operator: "Is",
- source: "custom",
- results: "small",
- component: "single-select-list-field",
- },
- {
- arity: "single",
- type: "dropdown",
- adminType: "list",
- operator: "Contains",
- source: "connected",
- results: "large",
- component: "token-field",
- },
- {
- arity: "single",
- type: "dropdown",
- adminType: "list",
- operator: "Contains",
- source: "connected",
- results: "small",
- component: "single-select-list-field",
- },
- {
- arity: "single",
- type: "dropdown",
- adminType: "list",
- operator: "Contains",
- source: "card",
- results: "large",
- component: "token-field",
- },
- {
- arity: "single",
- type: "dropdown",
- adminType: "list",
- operator: "Contains",
- source: "card",
- results: "small",
- component: "token-field",
- },
- {
- arity: "single",
- type: "dropdown",
- adminType: "list",
- operator: "Contains",
- source: "custom",
- results: "large",
- component: "single-select-list-field",
- },
- {
- arity: "single",
- type: "dropdown",
- adminType: "list",
- operator: "Contains",
- source: "custom",
- results: "small",
- component: "single-select-list-field",
- },
- {
- arity: "single",
- type: "dropdown",
- adminType: "plain",
- operator: "Is",
- source: "connected",
- results: "large",
- component: "token-field",
- },
- {
- arity: "single",
- type: "dropdown",
- adminType: "plain",
- operator: "Is",
- source: "connected",
- results: "small",
- component: "token-field",
- },
- {
- arity: "single",
- type: "dropdown",
- adminType: "plain",
- operator: "Is",
- source: "card",
- results: "large",
- component: "token-field",
- },
- {
- arity: "single",
- type: "dropdown",
- adminType: "plain",
- operator: "Is",
- source: "card",
- results: "small",
- component: "token-field",
- },
- {
- arity: "single",
- type: "dropdown",
- adminType: "plain",
- operator: "Is",
- source: "custom",
- results: "large",
- component: "single-select-list-field",
- },
- {
- arity: "single",
- type: "dropdown",
- adminType: "plain",
- operator: "Is",
- source: "custom",
- results: "small",
- component: "single-select-list-field",
- },
- {
- arity: "single",
- type: "dropdown",
- adminType: "plain",
- operator: "Contains",
- source: "connected",
- results: "large",
- component: "token-field",
- },
- {
- arity: "single",
- type: "dropdown",
- adminType: "plain",
- operator: "Contains",
- source: "connected",
- results: "small",
- component: "token-field",
- },
- {
- arity: "single",
- type: "dropdown",
- adminType: "plain",
- operator: "Contains",
- source: "card",
- results: "large",
- component: "token-field",
- },
- {
- arity: "single",
- type: "dropdown",
- adminType: "plain",
- operator: "Contains",
- source: "card",
- results: "small",
- component: "token-field",
- },
- {
- arity: "single",
- type: "dropdown",
- adminType: "plain",
- operator: "Contains",
- source: "custom",
- results: "large",
- component: "single-select-list-field",
- },
- {
- arity: "single",
- type: "dropdown",
- adminType: "plain",
- operator: "Contains",
- source: "custom",
- results: "small",
- component: "single-select-list-field",
- },
- {
- arity: "single",
- type: "plain",
- adminType: "search",
- operator: "Is",
- source: "connected",
- results: "large",
- component: "token-field",
- },
- {
- arity: "single",
- type: "plain",
- adminType: "search",
- operator: "Is",
- source: "connected",
- results: "small",
- component: "token-field",
- },
- {
- arity: "single",
- type: "plain",
- adminType: "search",
- operator: "Is",
- source: "card",
- results: "large",
- component: "token-field",
- },
- {
- arity: "single",
- type: "plain",
- adminType: "search",
- operator: "Is",
- source: "card",
- results: "small",
- component: "token-field",
- },
- {
- arity: "single",
- type: "plain",
- adminType: "search",
- operator: "Is",
- source: "custom",
- results: "large",
- component: "token-field",
- },
- {
- arity: "single",
- type: "plain",
- adminType: "search",
- operator: "Is",
- source: "custom",
- results: "small",
- component: "token-field",
- },
- {
- arity: "single",
- type: "plain",
- adminType: "search",
- operator: "Contains",
- source: "connected",
- results: "large",
- component: "token-field",
- },
- {
- arity: "single",
- type: "plain",
- adminType: "search",
- operator: "Contains",
- source: "connected",
- results: "small",
- component: "token-field",
- },
- {
- arity: "single",
- type: "plain",
- adminType: "search",
- operator: "Contains",
- source: "card",
- results: "large",
- component: "token-field",
- },
- {
- arity: "single",
- type: "plain",
- adminType: "search",
- operator: "Contains",
- source: "card",
- results: "small",
- component: "token-field",
- },
- {
- arity: "single",
- type: "plain",
- adminType: "search",
- operator: "Contains",
- source: "custom",
- results: "large",
- component: "token-field",
- },
- {
- arity: "single",
- type: "plain",
- adminType: "search",
- operator: "Contains",
- source: "custom",
- results: "small",
- component: "token-field",
- },
- {
- arity: "single",
- type: "plain",
- adminType: "list",
- operator: "Is",
- source: "connected",
- results: "large",
- component: "token-field",
- },
- {
- arity: "single",
- type: "plain",
- adminType: "list",
- operator: "Is",
- source: "connected",
- results: "small",
- component: "token-field",
- },
- {
- arity: "single",
- type: "plain",
- adminType: "list",
- operator: "Is",
- source: "card",
- results: "large",
- component: "token-field",
- },
- {
- arity: "single",
- type: "plain",
- adminType: "list",
- operator: "Is",
- source: "card",
- results: "small",
- component: "token-field",
- },
- {
- arity: "single",
- type: "plain",
- adminType: "list",
- operator: "Is",
- source: "custom",
- results: "large",
- component: "token-field",
- },
- {
- arity: "single",
- type: "plain",
- adminType: "list",
- operator: "Is",
- source: "custom",
- results: "small",
- component: "token-field",
- },
- {
- arity: "single",
- type: "plain",
- adminType: "list",
- operator: "Contains",
- source: "connected",
- results: "large",
- component: "token-field",
- },
- {
- arity: "single",
- type: "plain",
- adminType: "list",
- operator: "Contains",
- source: "connected",
- results: "small",
- component: "token-field",
- },
- {
- arity: "single",
- type: "plain",
- adminType: "list",
- operator: "Contains",
- source: "card",
- results: "large",
- component: "token-field",
- },
- {
- arity: "single",
- type: "plain",
- adminType: "list",
- operator: "Contains",
- source: "card",
- results: "small",
- component: "token-field",
- },
- {
- arity: "single",
- type: "plain",
- adminType: "list",
- operator: "Contains",
- source: "custom",
- results: "large",
- component: "token-field",
- },
- {
- arity: "single",
- type: "plain",
- adminType: "list",
- operator: "Contains",
- source: "custom",
- results: "small",
- component: "token-field",
- },
- {
- arity: "single",
- type: "plain",
- adminType: "plain",
- operator: "Is",
- source: "connected",
- results: "large",
- component: "token-field",
- },
- {
- arity: "single",
- type: "plain",
- adminType: "plain",
- operator: "Is",
- source: "connected",
- results: "small",
- component: "token-field",
- },
- {
- arity: "single",
- type: "plain",
- adminType: "plain",
- operator: "Is",
- source: "card",
- results: "large",
- component: "token-field",
- },
- {
- arity: "single",
- type: "plain",
- adminType: "plain",
- operator: "Is",
- source: "card",
- results: "small",
- component: "token-field",
- },
- {
- arity: "single",
- type: "plain",
- adminType: "plain",
- operator: "Is",
- source: "custom",
- results: "large",
- component: "token-field",
- },
- {
- arity: "single",
- type: "plain",
- adminType: "plain",
- operator: "Is",
- source: "custom",
- results: "small",
- component: "token-field",
- },
- {
- arity: "single",
- type: "plain",
- adminType: "plain",
- operator: "Contains",
- source: "connected",
- results: "large",
- component: "token-field",
- },
- {
- arity: "single",
- type: "plain",
- adminType: "plain",
- operator: "Contains",
- source: "connected",
- results: "small",
- component: "token-field",
- },
- {
- arity: "single",
- type: "plain",
- adminType: "plain",
- operator: "Contains",
- source: "card",
- results: "large",
- component: "token-field",
- },
- {
- arity: "single",
- type: "plain",
- adminType: "plain",
- operator: "Contains",
- source: "card",
- results: "small",
- component: "token-field",
- },
- {
- arity: "single",
- type: "plain",
- adminType: "plain",
- operator: "Contains",
- source: "custom",
- results: "large",
- component: "token-field",
- },
- {
- arity: "single",
- type: "plain",
- adminType: "plain",
- operator: "Contains",
- source: "custom",
- results: "small",
- component: "token-field",
- },
- {
- arity: "multi",
- type: "search",
- adminType: "search",
- operator: "Is",
- source: "connected",
- results: "large",
- component: "token-field",
- },
- {
- arity: "multi",
- type: "search",
- adminType: "search",
- operator: "Is",
- source: "connected",
- results: "small",
- component: "token-field",
- },
- {
- arity: "multi",
- type: "search",
- adminType: "search",
- operator: "Is",
- source: "card",
- results: "large",
- component: "token-field",
- },
- {
- arity: "multi",
- type: "search",
- adminType: "search",
- operator: "Is",
- source: "card",
- results: "small",
- component: "token-field",
- },
- {
- arity: "multi",
- type: "search",
- adminType: "search",
- operator: "Is",
- source: "custom",
- results: "large",
- component: "token-field",
- },
- {
- arity: "multi",
- type: "search",
- adminType: "search",
- operator: "Is",
- source: "custom",
- results: "small",
- component: "token-field",
- },
- {
- arity: "multi",
- type: "search",
- adminType: "search",
- operator: "Contains",
- source: "connected",
- results: "large",
- component: "token-field",
- },
- {
- arity: "multi",
- type: "search",
- adminType: "search",
- operator: "Contains",
- source: "connected",
- results: "small",
- component: "token-field",
- },
- {
- arity: "multi",
- type: "search",
- adminType: "search",
- operator: "Contains",
- source: "card",
- results: "large",
- component: "token-field",
- },
- {
- arity: "multi",
- type: "search",
- adminType: "search",
- operator: "Contains",
- source: "card",
- results: "small",
- component: "token-field",
- },
- {
- arity: "multi",
- type: "search",
- adminType: "search",
- operator: "Contains",
- source: "custom",
- results: "large",
- component: "token-field",
- },
- {
- arity: "multi",
- type: "search",
- adminType: "search",
- operator: "Contains",
- source: "custom",
- results: "small",
- component: "token-field",
- },
- {
- arity: "multi",
- type: "search",
- adminType: "list",
- operator: "Is",
- source: "connected",
- results: "large",
- component: "token-field",
- },
- {
- arity: "multi",
- type: "search",
- adminType: "list",
- operator: "Is",
- source: "connected",
- results: "small",
- component: "list-field",
- },
- {
- arity: "multi",
- type: "search",
- adminType: "list",
- operator: "Is",
- source: "card",
- results: "large",
- component: "token-field",
- },
- {
- arity: "multi",
- type: "search",
- adminType: "list",
- operator: "Is",
- source: "card",
- results: "small",
- component: "token-field",
- },
- {
- arity: "multi",
- type: "search",
- adminType: "list",
- operator: "Is",
- source: "custom",
- results: "large",
- component: "token-field",
- },
- {
- arity: "multi",
- type: "search",
- adminType: "list",
- operator: "Is",
- source: "custom",
- results: "small",
- component: "token-field",
- },
- {
- arity: "multi",
- type: "search",
- adminType: "list",
- operator: "Contains",
- source: "connected",
- results: "large",
- component: "token-field",
- },
- {
- arity: "multi",
- type: "search",
- adminType: "list",
- operator: "Contains",
- source: "connected",
- results: "small",
- component: "list-field",
- },
- {
- arity: "multi",
- type: "search",
- adminType: "list",
- operator: "Contains",
- source: "card",
- results: "large",
- component: "token-field",
- },
- {
- arity: "multi",
- type: "search",
- adminType: "list",
- operator: "Contains",
- source: "card",
- results: "small",
- component: "token-field",
- },
- {
- arity: "multi",
- type: "search",
- adminType: "list",
- operator: "Contains",
- source: "custom",
- results: "large",
- component: "token-field",
- },
- {
- arity: "multi",
- type: "search",
- adminType: "list",
- operator: "Contains",
- source: "custom",
- results: "small",
- component: "token-field",
- },
- {
- arity: "multi",
- type: "search",
- adminType: "plain",
- operator: "Is",
- source: "connected",
- results: "large",
- component: "token-field",
- },
- {
- arity: "multi",
- type: "search",
- adminType: "plain",
- operator: "Is",
- source: "connected",
- results: "small",
- component: "token-field",
- },
- {
- arity: "multi",
- type: "search",
- adminType: "plain",
- operator: "Is",
- source: "card",
- results: "large",
- component: "token-field",
- },
- {
- arity: "multi",
- type: "search",
- adminType: "plain",
- operator: "Is",
- source: "card",
- results: "small",
- component: "token-field",
- },
- {
- arity: "multi",
- type: "search",
- adminType: "plain",
- operator: "Is",
- source: "custom",
- results: "large",
- component: "token-field",
- },
- {
- arity: "multi",
- type: "search",
- adminType: "plain",
- operator: "Is",
- source: "custom",
- results: "small",
- component: "token-field",
- },
- {
- arity: "multi",
- type: "search",
- adminType: "plain",
- operator: "Contains",
- source: "connected",
- results: "large",
- component: "token-field",
- },
- {
- arity: "multi",
- type: "search",
- adminType: "plain",
- operator: "Contains",
- source: "connected",
- results: "small",
- component: "token-field",
- },
- {
- arity: "multi",
- type: "search",
- adminType: "plain",
- operator: "Contains",
- source: "card",
- results: "large",
- component: "token-field",
- },
- {
- arity: "multi",
- type: "search",
- adminType: "plain",
- operator: "Contains",
- source: "card",
- results: "small",
- component: "token-field",
- },
- {
- arity: "multi",
- type: "search",
- adminType: "plain",
- operator: "Contains",
- source: "custom",
- results: "large",
- component: "token-field",
- },
- {
- arity: "multi",
- type: "search",
- adminType: "plain",
- operator: "Contains",
- source: "custom",
- results: "small",
- component: "token-field",
- },
- {
- arity: "multi",
- type: "dropdown",
- adminType: "search",
- operator: "Is",
- source: "connected",
- results: "large",
- component: "token-field",
- },
- {
- arity: "multi",
- type: "dropdown",
- adminType: "search",
- operator: "Is",
- source: "connected",
- results: "small",
- component: "token-field",
- },
- {
- arity: "multi",
- type: "dropdown",
- adminType: "search",
- operator: "Is",
- source: "card",
- results: "large",
- component: "token-field",
- },
- {
- arity: "multi",
- type: "dropdown",
- adminType: "search",
- operator: "Is",
- source: "card",
- results: "small",
- component: "token-field",
- },
- {
- arity: "multi",
- type: "dropdown",
- adminType: "search",
- operator: "Is",
- source: "custom",
- results: "large",
- component: "list-field",
- },
- {
- arity: "multi",
- type: "dropdown",
- adminType: "search",
- operator: "Is",
- source: "custom",
- results: "small",
- component: "list-field",
- },
- {
- arity: "multi",
- type: "dropdown",
- adminType: "search",
- operator: "Contains",
- source: "connected",
- results: "large",
- component: "token-field",
- },
- {
- arity: "multi",
- type: "dropdown",
- adminType: "search",
- operator: "Contains",
- source: "connected",
- results: "small",
- component: "token-field",
- },
- {
- arity: "multi",
- type: "dropdown",
- adminType: "search",
- operator: "Contains",
- source: "card",
- results: "large",
- component: "token-field",
- },
- {
- arity: "multi",
- type: "dropdown",
- adminType: "search",
- operator: "Contains",
- source: "card",
- results: "small",
- component: "token-field",
- },
- {
- arity: "multi",
- type: "dropdown",
- adminType: "search",
- operator: "Contains",
- source: "custom",
- results: "large",
- component: "list-field",
- },
- {
- arity: "multi",
- type: "dropdown",
- adminType: "search",
- operator: "Contains",
- source: "custom",
- results: "small",
- component: "list-field",
- },
- {
- arity: "multi",
- type: "dropdown",
- adminType: "list",
- operator: "Is",
- source: "connected",
- results: "large",
- component: "token-field",
- },
- {
- arity: "multi",
- type: "dropdown",
- adminType: "list",
- operator: "Is",
- source: "connected",
- results: "small",
- component: "list-field",
- },
- {
- arity: "multi",
- type: "dropdown",
- adminType: "list",
- operator: "Is",
- source: "card",
- results: "large",
- component: "token-field",
- },
- {
- arity: "multi",
- type: "dropdown",
- adminType: "list",
- operator: "Is",
- source: "card",
- results: "small",
- component: "token-field",
- },
- {
- arity: "multi",
- type: "dropdown",
- adminType: "list",
- operator: "Is",
- source: "custom",
- results: "large",
- component: "list-field",
- },
- {
- arity: "multi",
- type: "dropdown",
- adminType: "list",
- operator: "Is",
- source: "custom",
- results: "small",
- component: "list-field",
- },
- {
- arity: "multi",
- type: "dropdown",
- adminType: "list",
- operator: "Contains",
- source: "connected",
- results: "large",
- component: "token-field",
- },
- {
- arity: "multi",
- type: "dropdown",
- adminType: "list",
- operator: "Contains",
- source: "connected",
- results: "small",
- component: "list-field",
- },
- {
- arity: "multi",
- type: "dropdown",
- adminType: "list",
- operator: "Contains",
- source: "card",
- results: "large",
- component: "token-field",
- },
- {
- arity: "multi",
- type: "dropdown",
- adminType: "list",
- operator: "Contains",
- source: "card",
- results: "small",
- component: "token-field",
- },
- {
- arity: "multi",
- type: "dropdown",
- adminType: "list",
- operator: "Contains",
- source: "custom",
- results: "large",
- component: "list-field",
- },
- {
- arity: "multi",
- type: "dropdown",
- adminType: "list",
- operator: "Contains",
- source: "custom",
- results: "small",
- component: "list-field",
- },
- {
- arity: "multi",
- type: "dropdown",
- adminType: "plain",
- operator: "Is",
- source: "connected",
- results: "large",
- component: "token-field",
- },
- {
- arity: "multi",
- type: "dropdown",
- adminType: "plain",
- operator: "Is",
- source: "connected",
- results: "small",
- component: "token-field",
- },
- {
- arity: "multi",
- type: "dropdown",
- adminType: "plain",
- operator: "Is",
- source: "card",
- results: "large",
- component: "token-field",
- },
- {
- arity: "multi",
- type: "dropdown",
- adminType: "plain",
- operator: "Is",
- source: "card",
- results: "small",
- component: "token-field",
- },
- {
- arity: "multi",
- type: "dropdown",
- adminType: "plain",
- operator: "Is",
- source: "custom",
- results: "large",
- component: "list-field",
- },
- {
- arity: "multi",
- type: "dropdown",
- adminType: "plain",
- operator: "Is",
- source: "custom",
- results: "small",
- component: "list-field",
- },
- {
- arity: "multi",
- type: "dropdown",
- adminType: "plain",
- operator: "Contains",
- source: "connected",
- results: "large",
- component: "token-field",
- },
- {
- arity: "multi",
- type: "dropdown",
- adminType: "plain",
- operator: "Contains",
- source: "connected",
- results: "small",
- component: "token-field",
- },
- {
- arity: "multi",
- type: "dropdown",
- adminType: "plain",
- operator: "Contains",
- source: "card",
- results: "large",
- component: "token-field",
- },
- {
- arity: "multi",
- type: "dropdown",
- adminType: "plain",
- operator: "Contains",
- source: "card",
- results: "small",
- component: "token-field",
- },
- {
- arity: "multi",
- type: "dropdown",
- adminType: "plain",
- operator: "Contains",
- source: "custom",
- results: "large",
- component: "list-field",
- },
- {
- arity: "multi",
- type: "dropdown",
- adminType: "plain",
- operator: "Contains",
- source: "custom",
- results: "small",
- component: "list-field",
- },
- {
- arity: "multi",
- type: "plain",
- adminType: "search",
- operator: "Is",
- source: "connected",
- results: "large",
- component: "token-field",
- },
- {
- arity: "multi",
- type: "plain",
- adminType: "search",
- operator: "Is",
- source: "connected",
- results: "small",
- component: "token-field",
- },
- {
- arity: "multi",
- type: "plain",
- adminType: "search",
- operator: "Is",
- source: "card",
- results: "large",
- component: "token-field",
- },
- {
- arity: "multi",
- type: "plain",
- adminType: "search",
- operator: "Is",
- source: "card",
- results: "small",
- component: "token-field",
- },
- {
- arity: "multi",
- type: "plain",
- adminType: "search",
- operator: "Is",
- source: "custom",
- results: "large",
- component: "token-field",
- },
- {
- arity: "multi",
- type: "plain",
- adminType: "search",
- operator: "Is",
- source: "custom",
- results: "small",
- component: "token-field",
- },
- {
- arity: "multi",
- type: "plain",
- adminType: "search",
- operator: "Contains",
- source: "connected",
- results: "large",
- component: "token-field",
- },
- {
- arity: "multi",
- type: "plain",
- adminType: "search",
- operator: "Contains",
- source: "connected",
- results: "small",
- component: "token-field",
- },
- {
- arity: "multi",
- type: "plain",
- adminType: "search",
- operator: "Contains",
- source: "card",
- results: "large",
- component: "token-field",
- },
- {
- arity: "multi",
- type: "plain",
- adminType: "search",
- operator: "Contains",
- source: "card",
- results: "small",
- component: "token-field",
- },
- {
- arity: "multi",
- type: "plain",
- adminType: "search",
- operator: "Contains",
- source: "custom",
- results: "large",
- component: "token-field",
- },
- {
- arity: "multi",
- type: "plain",
- adminType: "search",
- operator: "Contains",
- source: "custom",
- results: "small",
- component: "token-field",
- },
- {
- arity: "multi",
- type: "plain",
- adminType: "list",
- operator: "Is",
- source: "connected",
- results: "large",
- component: "token-field",
- },
- {
- arity: "multi",
- type: "plain",
- adminType: "list",
- operator: "Is",
- source: "connected",
- results: "small",
- component: "token-field",
- },
- {
- arity: "multi",
- type: "plain",
- adminType: "list",
- operator: "Is",
- source: "card",
- results: "large",
- component: "token-field",
- },
- {
- arity: "multi",
- type: "plain",
- adminType: "list",
- operator: "Is",
- source: "card",
- results: "small",
- component: "token-field",
- },
- {
- arity: "multi",
- type: "plain",
- adminType: "list",
- operator: "Is",
- source: "custom",
- results: "large",
- component: "token-field",
- },
- {
- arity: "multi",
- type: "plain",
- adminType: "list",
- operator: "Is",
- source: "custom",
- results: "small",
- component: "token-field",
- },
- {
- arity: "multi",
- type: "plain",
- adminType: "list",
- operator: "Contains",
- source: "connected",
- results: "large",
- component: "token-field",
- },
- {
- arity: "multi",
- type: "plain",
- adminType: "list",
- operator: "Contains",
- source: "connected",
- results: "small",
- component: "token-field",
- },
- {
- arity: "multi",
- type: "plain",
- adminType: "list",
- operator: "Contains",
- source: "card",
- results: "large",
- component: "token-field",
- },
- {
- arity: "multi",
- type: "plain",
- adminType: "list",
- operator: "Contains",
- source: "card",
- results: "small",
- component: "token-field",
- },
- {
- arity: "multi",
- type: "plain",
- adminType: "list",
- operator: "Contains",
- source: "custom",
- results: "large",
- component: "token-field",
- },
- {
- arity: "multi",
- type: "plain",
- adminType: "list",
- operator: "Contains",
- source: "custom",
- results: "small",
- component: "token-field",
- },
- {
- arity: "multi",
- type: "plain",
- adminType: "plain",
- operator: "Is",
- source: "connected",
- results: "large",
- component: "token-field",
- },
- {
- arity: "multi",
- type: "plain",
- adminType: "plain",
- operator: "Is",
- source: "connected",
- results: "small",
- component: "token-field",
- },
- {
- arity: "multi",
- type: "plain",
- adminType: "plain",
- operator: "Is",
- source: "card",
- results: "large",
- component: "token-field",
- },
- {
- arity: "multi",
- type: "plain",
- adminType: "plain",
- operator: "Is",
- source: "card",
- results: "small",
- component: "token-field",
- },
- {
- arity: "multi",
- type: "plain",
- adminType: "plain",
- operator: "Is",
- source: "custom",
- results: "large",
- component: "token-field",
- },
- {
- arity: "multi",
- type: "plain",
- adminType: "plain",
- operator: "Is",
- source: "custom",
- results: "small",
- component: "token-field",
- },
- {
- arity: "multi",
- type: "plain",
- adminType: "plain",
- operator: "Contains",
- source: "connected",
- results: "large",
- component: "token-field",
- },
- {
- arity: "multi",
- type: "plain",
- adminType: "plain",
- operator: "Contains",
- source: "connected",
- results: "small",
- component: "token-field",
- },
- {
- arity: "multi",
- type: "plain",
- adminType: "plain",
- operator: "Contains",
- source: "card",
- results: "large",
- component: "token-field",
- },
- {
- arity: "multi",
- type: "plain",
- adminType: "plain",
- operator: "Contains",
- source: "card",
- results: "small",
- component: "token-field",
- },
- {
- arity: "multi",
- type: "plain",
- adminType: "plain",
- operator: "Contains",
- source: "custom",
- results: "large",
- component: "token-field",
- },
- {
- arity: "multi",
- type: "plain",
- adminType: "plain",
- operator: "Contains",
- source: "custom",
- results: "small",
- component: "token-field",
- },
-];
diff --git a/frontend/src/metabase/parameters/components/ParameterValueWidget.values-widget.unit.spec.tsx b/frontend/src/metabase/parameters/components/ParameterValueWidget.values-widget.unit.spec.tsx
new file mode 100644
index 00000000000..14966e42331
--- /dev/null
+++ b/frontend/src/metabase/parameters/components/ParameterValueWidget.values-widget.unit.spec.tsx
@@ -0,0 +1,227 @@
+import userEvent from "@testing-library/user-event";
+
+import { setupParameterValuesEndpoints } from "__support__/server-mocks";
+import { renderWithProviders, screen } from "__support__/ui";
+import type { UiParameter } from "metabase-lib/v1/parameters/types";
+import type {
+ FieldValuesType,
+ Parameter,
+ ParameterValue,
+ ParameterValues,
+ ValuesQueryType,
+} from "metabase-types/api";
+import {
+ createMockField,
+ createMockParameter,
+ createMockParameterValues,
+} from "metabase-types/api/mocks";
+
+import { ParameterValueWidget } from "./ParameterValueWidget";
+
+const ARITIES = ["single", "multi"] as const;
+const QUERY_TYPES = ["search", "dropdown", "plain"] as const;
+const ADMIN_TYPES = ["search", "list", "plain"] as const;
+const OPERATORS = ["Is", "Contains"] as const;
+const SOURCES = ["connected", "card", "custom"] as const;
+const RESULTS = ["large", "small"] as const;
+
+const COMPONENTS = [
+ "token-field",
+ "list-field",
+ "single-select-list-field",
+] as const;
+
+type ValuesCase = {
+ arity: (typeof ARITIES)[number];
+ queryType: (typeof QUERY_TYPES)[number];
+ adminType: (typeof ADMIN_TYPES)[number];
+ operator: (typeof OPERATORS)[number];
+ source: (typeof SOURCES)[number];
+ results: (typeof RESULTS)[number];
+};
+
+type Component = (typeof COMPONENTS)[number];
+
+// Every case that is not in this list renders a token field.
+const LIST_CASES: string[] = [
+ "single search list Is connected small",
+ "single search list Contains connected small",
+ "single dropdown search Is custom large",
+ "single dropdown search Is custom small",
+ "single dropdown search Contains custom large",
+ "single dropdown search Contains custom small",
+ "single dropdown list Is connected small",
+ "single dropdown list Contains connected small",
+ "multi search list Is connected small",
+ "multi search list Contains connected small",
+ "multi dropdown search Is custom large",
+ "multi dropdown search Is custom small",
+ "multi dropdown search Contains custom large",
+ "multi dropdown search Contains custom small",
+ "multi dropdown list Is connected small",
+ "multi dropdown list Contains connected small",
+];
+
+// A parameter with a values source ignores the field, so `adminType` has no
+// effect for the `card` and `custom` sources. The `card` mock ignores `results`.
+// Keep one case for each distinct input.
+function isDistinctCase({ adminType, source, results }: ValuesCase) {
+ if (source !== "connected" && adminType !== "search") {
+ return false;
+ }
+ return source !== "card" || results === "large";
+}
+
+const ALL_CASES: ValuesCase[] = ARITIES.flatMap((arity) =>
+ QUERY_TYPES.flatMap((queryType) =>
+ ADMIN_TYPES.flatMap((adminType) =>
+ OPERATORS.flatMap((operator) =>
+ SOURCES.flatMap((source) =>
+ RESULTS.map((results) => ({
+ arity,
+ queryType,
+ adminType,
+ operator,
+ source,
+ results,
+ })),
+ ),
+ ),
+ ),
+ ),
+);
+
+const CASES = ALL_CASES.filter(isDistinctCase);
+
+const FIELD_VALUES_TYPES = {
+ search: "search",
+ list: "list",
+ plain: "none",
+} satisfies Record<ValuesCase["adminType"], FieldValuesType>;
+
+const VALUES_QUERY_TYPES = {
+ search: "search",
+ dropdown: "list",
+ plain: "none",
+} satisfies Record<ValuesCase["queryType"], ValuesQueryType>;
+
+const STATIC_LIST_SIZES = {
+ large: 1050,
+ small: 5,
+} satisfies Record<ValuesCase["results"], number>;
+
+function caseName(valuesCase: ValuesCase) {
+ const { arity, queryType, adminType, operator, source, results } = valuesCase;
+ return `${arity} ${queryType} ${adminType} ${operator} ${source} ${results}`;
+}
+
+function expectedComponent(valuesCase: ValuesCase): Component {
+ if (!LIST_CASES.includes(caseName(valuesCase))) {
+ return "token-field";
+ }
+ return valuesCase.arity === "multi"
+ ? "list-field"
+ : "single-select-list-field";
+}
+
+function staticValues(count: number): ParameterValue[] {
+ return Array.from({ length: count }, (_, index) => [`Value ${index}`]);
+}
+
+function parameterSource({ source, results }: ValuesCase): Partial<Parameter> {
+ switch (source) {
+ case "connected":
+ return {};
+ case "card":
+ return {
+ values_source_type: "card",
+ values_source_config: { card_id: 1, value_field: ["field", 2, null] },
+ };
+ case "custom":
+ return {
+ values_source_type: "static-list",
+ values_source_config: {
+ values: staticValues(STATIC_LIST_SIZES[results]),
+ },
+ };
+ }
+}
+
+// What the backend returns for the sample data the cases are based on:
+// a large field and a card source have more values than one response holds,
+// a static list returns all of its values.
+function parameterValues({ source, results }: ValuesCase): ParameterValues {
+ switch (source) {
+ case "connected":
+ return createMockParameterValues({
+ values: staticValues(5),
+ has_more_values: results === "large",
+ });
+ case "card":
+ return createMockParameterValues({
+ values: staticValues(5),
+ has_more_values: true,
+ });
+ case "custom":
+ return createMockParameterValues({
+ values: staticValues(STATIC_LIST_SIZES[results]),
+ has_more_values: false,
+ });
+ }
+}
+
+type SetupOpts = {
+ valuesCase: ValuesCase;
+};
+
+function setup({ valuesCase }: SetupOpts) {
+ setupParameterValuesEndpoints(parameterValues(valuesCase));
+
+ const parameter: UiParameter = {
+ ...createMockParameter({
+ id: "matrix-param",
+ slug: "matrix",
+ name: "Matrix",
+ type: valuesCase.operator === "Is" ? "string/=" : "string/contains",
+ sectionId: "string",
+ isMultiSelect: valuesCase.arity === "multi",
+ values_query_type: VALUES_QUERY_TYPES[valuesCase.queryType],
+ ...parameterSource(valuesCase),
+ }),
+ fields: [
+ createMockField({
+ id: 1,
+ base_type: "type/Text",
+ effective_type: "type/Text",
+ has_field_values: FIELD_VALUES_TYPES[valuesCase.adminType],
+ }),
+ ],
+ };
+
+ renderWithProviders(
+ <ParameterValueWidget
+ parameter={parameter}
+ setValue={jest.fn()}
+ value={null}
+ />,
+ );
+}
+
+describe("ParameterValueWidget > values widget", () => {
+ it.each(CASES.map((valuesCase) => [caseName(valuesCase), valuesCase]))(
+ "%s should render the expected widget",
+ async (_name, valuesCase) => {
+ const component = expectedComponent(valuesCase);
+ setup({ valuesCase });
+
+ await userEvent.click(
+ screen.getByTestId("parameter-value-widget-target"),
+ );
+
+ expect(await screen.findByTestId(component)).toBeInTheDocument();
+ COMPONENTS.filter((other) => other !== component).forEach((other) => {
+ expect(screen.queryByTestId(other)).not.toBeInTheDocument();
+ });
+ },
+ );
+});