The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:
TypeScript analyticsbibusiness-intelligencebusinessintelligenceclojuredashboarddatadata-analysisdata-visualizationdatabasemetabasemysqlpostgrespostgresqlreportingslacksql-editorvisualization
Split long running e2e specs into smaller chunks (#69844)
Nemanja Glumacfd775c440d42
diff --git a/e2e/test/scenarios/custom-column/custom-column-1.cy.spec.js b/e2e/test/scenarios/custom-column/custom-column-1.cy.spec.jsnew file mode 100644index 00000000000..67cd556e3c8--- /dev/null+++ b/e2e/test/scenarios/custom-column/custom-column-1.cy.spec.js@@ -0,0 +1,1033 @@+const { H } = cy;+import { dedent } from "ts-dedent";++import { SAMPLE_DB_ID } from "e2e/support/cypress_data";+import { SAMPLE_DATABASE } from "e2e/support/cypress_sample_database";++const { ORDERS, ORDERS_ID, PRODUCTS, PRODUCTS_ID } = SAMPLE_DATABASE;++describe("scenarios > question > custom column", () => {+ beforeEach(() => {+ cy.intercept("POST", "/api/dataset").as("dataset");++ H.restore();+ cy.signInAsNormalUser();+ });++ it("can see x-ray options when a custom column is present (#16680)", () => {+ H.createQuestion(+ {+ name: "16680",+ display: "line",+ query: {+ "source-table": ORDERS_ID,+ aggregation: [["count"]],+ breakout: [+ ["expression", "TestColumn"],+ ["field", ORDERS.CREATED_AT, { "temporal-unit": "month" }],+ ],+ expressions: { TestColumn: ["+", 1, 1] },+ },+ },+ { visitQuestion: true },+ );+ H.cartesianChartCircle().eq(5).click();+ H.popover()+ .findByText(/Automatic Insights/i)+ .click();+ H.popover().findByText(/X-ray/i);+ H.popover()+ .findByText(/Compare to the rest/i)+ .click();+ });++ it("can create a custom column (metabase#13241)", () => {+ H.openOrdersTable({ mode: "notebook" });+ cy.findByLabelText("Custom column").click();++ H.enterCustomColumnDetails({+ formula: "1 + 1",+ name: "Math",+ format: true,+ });+ cy.button("Done").click();++ H.visualize();++ // eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage+ cy.findByText("There was a problem with your question").should("not.exist");+ cy.findByTestId("query-visualization-root").contains("Math");+ });++ it("should not show default period in date column name (metabase#36631)", () => {+ const name = "Base question";+ H.createQuestion({ name, query: { "source-table": ORDERS_ID } });++ H.startNewQuestion();+ H.miniPickerBrowseAll().click();+ H.entityPickerModal().within(() => {+ H.entityPickerModalLevel(0).findByText("Our analytics").click();+ H.entityPickerModalLevel(1).findByText(name).click();+ });+ cy.button("Custom column").click();+ H.enterCustomColumnDetails({ formula: "[cre", blur: false });++ H.CustomExpressionEditor.completions()+ .should("be.visible")+ .and("contain.text", "Created At")+ .and("not.contain.text", "Default period");+ });++ it("should not show binning for a numeric custom column", () => {+ H.openOrdersTable({ mode: "notebook" });+ cy.findByLabelText("Custom column").click();++ H.enterCustomColumnDetails({+ formula: "[Product.Price] / 2",+ name: "Half Price",+ });+ cy.button("Done").click();++ cy.button("Summarize").click();+ H.popover().findByText("Count of rows").click();++ H.getNotebookStep("summarize")+ .findByText("Pick a column to group by")+ .click();++ H.popover()+ .findByRole("option", { name: "Half Price" })+ .within(() => {+ cy.findByLabelText("Binning strategy").should("not.exist");+ cy.findByLabelText("Temporal bucket").should("not.exist");+ })+ .click();++ H.getNotebookStep("summarize")+ .findByText("Half Price")+ .should("be.visible");+ });++ it("should show temporal units for a date/time custom column", () => {+ H.openOrdersTable({ mode: "notebook" });+ cy.findByLabelText("Custom column").click();++ H.enterCustomColumnDetails({+ formula: "[Product.Created At]",+ name: "Product Date",+ });+ cy.button("Done").click();++ cy.button("Summarize").click();+ H.popover().findByText("Count of rows").click();++ H.getNotebookStep("summarize")+ .findByText("Pick a column to group by")+ .click();+ H.popover()+ .findByRole("option", { name: "Product Date" })+ .within(() => {+ cy.findByLabelText("Binning strategy").should("not.exist");+ cy.findByLabelText("Temporal bucket").should("exist");+ })+ .click();++ H.getNotebookStep("summarize")+ .findByText("Product Date: Month")+ .should("be.visible");+ });++ it("should not show binning options for a coordinate custom column", () => {+ H.openPeopleTable({ mode: "notebook" });+ cy.findByLabelText("Custom column").click();++ H.enterCustomColumnDetails({+ formula: "[Latitude]",+ name: "UserLAT",+ });+ cy.button("Done").click();++ cy.button("Summarize").click();+ H.popover().findByText("Count of rows").click();++ H.getNotebookStep("summarize")+ .findByText("Pick a column to group by")+ .click();+ H.popover()+ .findByRole("option", { name: "UserLAT" })+ .within(() => {+ cy.findByLabelText("Binning strategy").should("not.exist");+ cy.findByLabelText("Temporal bucket").should("not.exist");+ })+ .click();++ H.getNotebookStep("summarize").findByText("UserLAT").should("be.visible");+ });++ // flaky test (#19454)+ it(+ "should show info popovers when hovering over custom column dimensions in the summarize sidebar",+ { tags: "@skip" },+ () => {+ H.openOrdersTable({ mode: "notebook" });+ cy.findByLabelText("Custom column").click();++ H.enterCustomColumnDetails({ formula: "1 + 1", name: "Math" });+ cy.button("Done").click();++ H.visualize();++ H.summarize();++ // eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage+ cy.findByText("Group by")+ .parent()+ .findByText("Math")+ .trigger("mouseenter");++ H.popover().contains("Math");+ H.popover().contains("No description");+ },+ );++ it("can create a custom column with an existing column name", () => {+ const customFormulas = [+ {+ formula: "[Quantity] * 2",+ name: "Double Qt",+ },+ {+ formula: "[Quantity] * [Product.Price]",+ name: "Sum Total",+ },+ ];++ customFormulas.forEach(({ formula, name }) => {+ H.openOrdersTable({ mode: "notebook" });+ cy.findByLabelText("Custom column").click();++ H.enterCustomColumnDetails({ formula, name });+ cy.button("Done").click();++ H.visualize();++ cy.findByTestId("query-visualization-root").contains(name);+ });+ });++ it("should create custom column with fields from aggregated data (metabase#12762)", () => {+ H.openOrdersTable({ mode: "notebook" });++ H.summarize({ mode: "notebook" });++ H.popover().within(() => {+ cy.findByText("Sum of ...").click();+ cy.findByText("Subtotal").click();+ });++ // TODO: There isn't a single unique parent that can be used to scope this icon within+ // (a good candidate would be `.NotebookCell`)+ // eslint-disable-next-line metabase/no-unsafe-element-filtering+ cy.icon("add")+ .last() // This is brittle.+ .click();++ H.popover().within(() => {+ cy.findByText("Sum of ...").click();+ cy.findByText("Total").click();+ });++ // eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage+ cy.findByText("Pick a column to group by").click();+ // eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage+ cy.findByText("Created At").click();++ // Add custom column based on previous aggregates+ const columnName = "MegaTotal";+ // eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage+ cy.findByText("Custom column").click();++ H.enterCustomColumnDetails({+ formula: "[Sum of Subtotal] + [Sum of Total]",+ name: columnName,+ });+ cy.button("Done").click();++ H.visualize();++ // eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage+ cy.findByText("There was a problem with your question").should("not.exist");+ // This is a pre-save state of the question but the column name should appear+ // both in tabular and graph views (regardless of which one is currently selected)+ cy.findByTestId("query-visualization-root").contains(columnName);+ });++ it("should not return same results for columns with the same name (metabase#12649)", () => {+ H.openOrdersTable({ mode: "notebook" });+ // join with Products+ // eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage+ cy.findByText("Join data").click();++ H.miniPickerBrowseAll().click();+ H.entityPickerModal().within(() => {+ H.entityPickerModalLevel(0).findByText("Databases").click();+ H.entityPickerModalLevel(1).findByText("Sample Database").click();+ cy.findByText("Products").click();+ });++ // add custom column+ // eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage+ cy.findByText("Custom column").click();+ H.enterCustomColumnDetails({ formula: "1 + 1", name: "x" });+ cy.button("Done").click();++ H.visualize();++ cy.log(+ "**Fails in 0.35.0, 0.35.1, 0.35.2, 0.35.4 and the latest master (2026-10-21)**",+ );+ cy.log("Works in 0.35.3");+ // ID should be "1" but it is picking the product ID and is showing "14"+ cy.get(".test-TableInteractive-cellWrapper--firstColumn")+ .eq(0)+ .findByText("1");+ });++ it("should be able to use custom expression after aggregation (metabase#13857)", () => {+ const CE_NAME = "13857_CE";+ const CC_NAME = "13857_CC";++ cy.signInAsAdmin();++ H.createQuestion(+ {+ name: "13857",+ query: {+ expressions: {+ [CC_NAME]: ["*", ["field-literal", CE_NAME, "type/Float"], 1234],+ },+ "source-query": {+ aggregation: [+ [+ "aggregation-options",+ ["*", ["count"], 1],+ { name: CE_NAME, "display-name": CE_NAME },+ ],+ ],+ breakout: [+ ["datetime-field", ["field-id", ORDERS.CREATED_AT], "month"],+ ],+ "source-table": ORDERS_ID,+ },+ },+ },+ { visitQuestion: true },+ );++ // eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage+ cy.findByText(CC_NAME);+ });++ it("should work with implicit joins (metabase#14080)", () => {+ const CC_NAME = "OneisOne";+ cy.signInAsAdmin();++ H.createQuestion(+ {+ name: "14080",+ query: {+ "source-table": ORDERS_ID,+ expressions: { [CC_NAME]: ["*", 1, 1] },+ aggregation: [+ [+ "distinct",+ [+ "fk->",+ ["field-id", ORDERS.PRODUCT_ID],+ ["field-id", PRODUCTS.ID],+ ],+ ],+ ["sum", ["expression", CC_NAME]],+ ],+ breakout: [+ ["datetime-field", ["field-id", ORDERS.CREATED_AT], "year"],+ ],+ },+ display: "line",+ },+ { visitQuestion: true },+ );++ cy.log("Regression since v0.37.1 - it works on v0.37.0");++ // eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage+ cy.contains(`Sum of ${CC_NAME}`);+ H.cartesianChartCircle().should("have.length.of.at.least", 8);+ });++ it("should create custom column after aggregation with 'cum-sum/count' (metabase#13634)", () => {+ H.createQuestion(+ {+ name: "13634",+ query: {+ expressions: { "Foo Bar": ["+", 57910, 1] },+ "source-query": {+ aggregation: [["cum-count"]],+ breakout: [+ ["datetime-field", ["field-id", ORDERS.CREATED_AT], "month"],+ ],+ "source-table": ORDERS_ID,+ },+ },+ },+ { visitQuestion: true },+ );++ // eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage+ cy.findByText("13634");++ cy.log("Reported failing in v0.34.3, v0.35.4, v0.36.8.2, v0.37.0.2");+ // eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage+ cy.findByText("Foo Bar");+ cy.findAllByText("57,911");+ });++ it("should not be dropped if filter is changed after aggregation (metaabase#14193)", () => {+ const CC_NAME = "Double the fun";++ H.createQuestion(+ {+ name: "14193",+ query: {+ "source-query": {+ "source-table": ORDERS_ID,+ filter: [">", ["field-id", ORDERS.SUBTOTAL], 0],+ aggregation: [["sum", ["field-id", ORDERS.TOTAL]]],+ breakout: [+ ["datetime-field", ["field-id", ORDERS.CREATED_AT], "year"],+ ],+ },+ expressions: {+ [CC_NAME]: ["*", ["field-literal", "sum", "type/Float"], 2],+ },+ },+ },+ { visitQuestion: true },+ );+ // Test displays collapsed filter - click on number 1 to expand and show the filter name+ cy.findByTestId("filters-visibility-control")+ .should("have.text", "1")+ .click();++ // eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage+ cy.findByText(/Subtotal is greater than 0/i)+ .parent()+ .find(".Icon-close")+ .click();++ // eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage+ cy.findByText(CC_NAME);+ });++ it("should handle identical custom column and table column names (metabase#14255)", () => {+ // Uppercase is important for this reproduction on H2+ const CC_NAME = "CATEGORY";++ H.createQuestion(+ {+ name: "14255",+ query: {+ "source-table": PRODUCTS_ID,+ expressions: {+ [CC_NAME]: ["concat", ["field-id", PRODUCTS.CATEGORY], "2"],+ },+ aggregation: [["count"]],+ breakout: [["expression", CC_NAME]],+ },+ },+ { visitQuestion: true },+ );++ // eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage+ cy.findByText(CC_NAME);+ // eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage+ cy.findByText("Gizmo2");+ });++ it("should drop custom column (based on a joined field) when a join is removed (metabase#14775)", () => {+ const CE_NAME = "Rounded price";++ H.createQuestion({+ name: "14775",+ query: {+ "source-table": ORDERS_ID,+ joins: [+ {+ fields: "all",+ "source-table": PRODUCTS_ID,+ condition: [+ "=",+ ["field-id", ORDERS.PRODUCT_ID],+ ["joined-field", "Products", ["field-id", PRODUCTS.ID]],+ ],+ alias: "Products",+ },+ ],+ expressions: {+ [CE_NAME]: [+ "ceil",+ ["joined-field", "Products", ["field-id", PRODUCTS.PRICE]],+ ],+ },+ limit: 5,+ },+ }).then(({ body: { id: QUESTION_ID } }) => {+ cy.visit(`/question/${QUESTION_ID}/notebook`);+ cy.findByTestId("step-expression-0-0").contains(CE_NAME);+ });++ // Remove join+ cy.findByTestId("step-join-0-0").realHover().find(".Icon-close").click();+ cy.findByTestId("step-join-0-0").should("not.exist");++ cy.log("Reported failing on 0.38.1-SNAPSHOT (6d77f099)");+ cy.findByTestId("step-expression-0-0").should("not.exist");++ H.visualize((response) => {+ expect(response.body.error).to.not.exist;+ });++ cy.get("[data-testid=cell-data]").should("contain", "37.65");+ cy.findAllByTestId("header-cell").should("not.contain", CE_NAME);+ });++ it("should handle using `case()` when referencing the same column names (metabase#14854)", () => {+ const CC_NAME = "CE with case";++ H.visitQuestionAdhoc(+ {+ dataset_query: {+ type: "query",+ query: {+ "source-table": ORDERS_ID,+ expressions: {+ [CC_NAME]: [+ "case",+ [+ [+ [">", ["field", ORDERS.DISCOUNT, null], 0],+ ["field", ORDERS.CREATED_AT, null],+ ],+ ],+ {+ default: [+ "field",+ PRODUCTS.CREATED_AT,+ { "source-field": ORDERS.PRODUCT_ID },+ ],+ },+ ],+ },+ },+ database: SAMPLE_DB_ID,+ },+ display: "table",+ },+ { callback: (xhr) => expect(xhr.response.body.error).not.to.exist },+ );++ // eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage+ cy.findByText(CC_NAME);+ // eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage+ cy.contains("37.65");+ });++ it("should handle brackets in the name of the custom column (metabase#15316)", () => {+ H.createQuestion({+ name: "15316",+ query: {+ "source-table": ORDERS_ID,+ expressions: { "MyCC [2027]": ["+", 1, 1] },+ },+ }).then(({ body: { id: QUESTION_ID } }) => {+ cy.visit(`/question/${QUESTION_ID}/notebook`);+ });+ H.summarize({ mode: "notebook" });+ H.popover().within(() => {+ cy.findByText("Sum of ...").click();+ cy.findByText("MyCC [2027]").click();+ });+ cy.findAllByTestId("notebook-cell-item")+ .contains("Sum of MyCC [2027]")+ .click();+ H.popover().within(() => {+ cy.icon("chevronleft").click();+ cy.findByText("Custom Expression").click();+ });+ H.CustomExpressionEditor.value().should("equal", "Sum([MyCC \\[2027\\]])");+ });++ it("should work with `isNull` function (metabase#15922)", () => {+ H.openOrdersTable({ mode: "notebook" });+ H.getNotebookStep("data").button("Custom column").click();+ H.enterCustomColumnDetails({+ formula: "isnull([Discount])",+ name: "No discount",+ });+ cy.button("Done").click();++ H.visualize((response) => {+ expect(response.body.error).to.not.exist;+ });++ cy.findAllByRole("gridcell").contains("37.65");+ cy.findAllByTestId("header-cell").contains("No discount");+ });++ it("should be able to add a date range filter to a custom column", () => {+ H.visitQuestionAdhoc({+ display: "table",+ dataset_query: {+ database: SAMPLE_DB_ID,+ type: "query",+ query: {+ "source-table": ORDERS_ID,+ expressions: { CustomDate: ["field", ORDERS.CREATED_AT, null] },+ },+ },+ });++ H.tableHeaderClick("CustomDate");++ H.popover().within(() => {+ cy.findByText("Filter by this column").click();+ cy.findByText("Fixed date range…").click();+ cy.findByLabelText("Start date").clear().type("12/10/2024");+ cy.findByLabelText("End date").clear().type("01/05/2025");+ cy.button("Add filter").click();+ });++ cy.wait("@dataset");+ // eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage+ cy.findByText("Showing 487 rows").should("be.visible");+ });++ it("should work with relative date filter applied to a custom column (metabase#16273)", () => {+ H.openOrdersTable({ mode: "notebook" });+ H.addCustomColumn();++ H.enterCustomColumnDetails({+ formula: "case([Discount] > 0, [Created At], [Product → Created At])",+ name: "MiscDate",+ });+ H.popover().button("Done").click();++ H.filter({ mode: "notebook" });+ H.popover().within(() => {+ cy.findByText("MiscDate").click();+ cy.findByText("Relative date range…").click();+ cy.findByText("Previous").click();+ cy.findByDisplayValue("days").click();+ });+ cy.findByRole("listbox").findByText("years").click();++ H.popover().within(() => {+ cy.findByText("Include this year").click();+ cy.button("Add filter").click();+ });++ H.visualize(({ body }) => {+ expect(body.error).to.not.exist;+ });++ H.queryBuilderMain().findByText("MiscDate").should("be.visible");+ cy.findByTestId("qb-filters-panel")+ .findByText("MiscDate is in the previous 30 years or this year")+ .should("be.visible");+ });++ it("should allow indenting using Tab", () => {+ H.openOrdersTable({ mode: "notebook" });+ cy.findByLabelText("Custom column").click();++ H.enterCustomColumnDetails({ formula: "1 + 2", blur: false });++ // Tab should insert indentation+ cy.realPress("Tab");+ H.CustomExpressionEditor.value().should("equal", "1 + 2 ");+ });++ it("should not format expression when pressing tab in the editor", () => {+ H.openOrdersTable({ mode: "notebook" });+ cy.findByLabelText("Custom column").click();++ H.enterCustomColumnDetails({ formula: "1+1" });++ cy.realPress("Tab");+ cy.realPress(["Shift", "Tab"]);++ // `1+1` (3 chars) is reformatted to `1 + 1` (5 chars)+ H.CustomExpressionEditor.value().should("equal", "1+1");+ H.CustomExpressionEditor.type("2");++ // Fix prevents display value from being `1 +2 1` due to cursor position+ // being wrong after formatting.+ // That's because the caret position after refocusing on textarea+ // would still be after the 3rd character+ H.CustomExpressionEditor.value().should("equal", "1+12");+ });++ it("should format expression when clicking the format button", () => {+ H.openOrdersTable({ mode: "notebook" });+ cy.findByLabelText("Custom column").click();++ H.enterCustomColumnDetails({ formula: "1+1" });++ // `1+1` (3 chars) is reformatted to `1 + 1` (5 chars)+ H.CustomExpressionEditor.format();+ H.CustomExpressionEditor.value().should("equal", "1 + 1");+ H.CustomExpressionEditor.type("2");++ // Fix needed will prevent display value from being `1 +2 1`.+ // That's because the caret position after refocusing on textarea+ // would still be after the 3rd character+ H.CustomExpressionEditor.value().should("equal", "1 + 12");+ });++ it("should format the expression when pressing the format keyboard shortcut", () => {+ H.openOrdersTable({ mode: "notebook" });+ cy.findByLabelText("Custom column").click();++ H.enterCustomColumnDetails({ formula: "1+1" });++ // `1+1` (3 chars) is reformatted to `1 + 1` (5 chars)+ H.CustomExpressionEditor.focus();+ const isMac = Cypress.platform === "darwin";+ const metaKey = isMac ? "Meta" : "Control";++ H.CustomExpressionEditor.formatButton().should("be.visible");+ H.CustomExpressionEditor.get()+ .get(".cm-editor")+ .realPress(["Shift", metaKey, "f"]);+ H.CustomExpressionEditor.value().should("equal", "1 + 1");++ // Make sure the cursor is at the end of the expression+ H.CustomExpressionEditor.type("2");+ H.CustomExpressionEditor.value().should("equal", "1 + 12");+ });++ it("should not try formatting the expression when it's invalid using the keyboard shortcut", () => {+ H.openOrdersTable({ mode: "notebook" });+ cy.findByLabelText("Custom column").click();++ H.enterCustomColumnDetails({ formula: "1+" });++ H.CustomExpressionEditor.focus();+ const isMac = Cypress.platform === "darwin";+ const metaKey = isMac ? "Meta" : "Control";++ cy.realPress(["Shift", metaKey, "f"]);+ H.CustomExpressionEditor.value().should("equal", "1+");++ // Make sure the cursor is at the end of the expression+ H.CustomExpressionEditor.type("2");+ H.CustomExpressionEditor.value().should("equal", "1+2");+ });++ it("should format long expressions on multiple lines", () => {+ H.openOrdersTable({ mode: "notebook" });+ cy.findByLabelText("Custom column").click();++ H.enterCustomColumnDetails({+ formula:+ "concat(coalesce([Product → Created At], [Created At]), 'foo', 'bar')",+ format: true,+ });++ H.CustomExpressionEditor.value().should(+ "equal",+ dedent`+ concat(+ coalesce([Product → Created At], [Created At]),+ "foo",+ "bar"+ )+ `.trim(),+ );+ });++ it("should not allow formatting when the expression contains an error", () => {+ H.openOrdersTable({ mode: "notebook" });+ cy.findByLabelText("Custom column").click();++ H.enterCustomColumnDetails({+ formula: "concat('foo', ",+ });+ H.CustomExpressionEditor.formatButton().should("not.exist");+ });++ it("should show the format button when the expression editor is empty", () => {+ H.openOrdersTable({ mode: "notebook" });+ cy.findByLabelText("Custom column").click();+ H.CustomExpressionEditor.formatButton().should("not.exist");+ });++ it("should not allow saving the expression when it is invalid", () => {+ H.openOrdersTable({ mode: "notebook" });+ cy.findByLabelText("Custom column").click();++ H.enterCustomColumnDetails({+ formula: "concat('foo', ",+ name: "A custom expression",+ });++ H.expressionEditorWidget().button("Done").should("be.disabled");+ H.CustomExpressionEditor.nameInput().focus().type("{enter}");+ H.expressionEditorWidget().should("be.visible");+ });++ it("should validate the expression when typing", () => {+ H.openOrdersTable({ mode: "notebook" });+ cy.findByLabelText("Custom column").click();++ H.enterCustomColumnDetails({+ formula: "concat('foo', ",+ name: "A custom expression",+ });+ H.expressionEditorWidget().button("Done").should("be.disabled");++ cy.log("Fix the expression");+ H.CustomExpressionEditor.type("{leftarrow}'bar')", { focus: true });+ H.expressionEditorWidget().button("Done").should("not.be.disabled");+ });++ it("should allow choosing a suggestion with Tab", () => {+ H.openOrdersTable({ mode: "notebook" });+ cy.findByLabelText("Custom column").click();++ H.enterCustomColumnDetails({ formula: "[Cre", blur: false });++ H.CustomExpressionEditor.completions().should("be.visible");++ // Suggestion popover shows up and this select the first one+ cy.realPress("Tab");++ // Focus remains on the expression editor+ cy.focused().should("have.attr", "role", "textbox");+ });++ it("should be possible to use the suggestion snippet arguments", () => {+ H.openOrdersTable({ mode: "notebook" });+ H.addCustomColumn();++ H.CustomExpressionEditor.type("coalesc{tab}[Tax]{tab}[User ID]", {+ delay: 50,+ });+ H.CustomExpressionEditor.value().should(+ "equal",+ "coalesce([Tax], [User ID])",+ );+ });++ it("should be possible to use the suggestion templates", () => {+ H.openOrdersTable({ mode: "notebook" });+ H.addCustomColumn();++ H.CustomExpressionEditor.type("coalesc{tab}", { delay: 50 });++ H.CustomExpressionEditor.type("[Tax]{tab}[User ID]", {+ focus: false,+ delay: 50,+ });+ H.CustomExpressionEditor.value().should(+ "equal",+ "coalesce([Tax], [User ID])",+ );+ });++ it("should allow to use `if` function", () => {+ H.openProductsTable({ mode: "notebook" });++ cy.log("custom columns");+ H.getNotebookStep("data").button("Custom column").click();+ H.enterCustomColumnDetails({+ formula: 'if([ID] = 1, "First", [ID] = 2, "Second", "Other")',+ name: "If",+ });+ H.expressionEditorWidget().button("Done").click();+ H.getNotebookStep("expression").button("Filter").click();+ H.clauseStepPopover().within(() => {+ cy.findByText("If").click();+ });+ H.selectFilterOperator("Is");+ H.clauseStepPopover().within(() => {+ cy.findByPlaceholderText("Enter some text").type("Other");+ cy.button("Add filter").click();+ });+ H.visualize();+ H.assertQueryBuilderRowCount(198);+ H.openNotebook();+ H.getNotebookStep("filter").findByText("If is Other").icon("close").click();+ H.getNotebookStep("expression").findByText("If").icon("close").click();++ cy.log("filters");+ H.getNotebookStep("data").button("Filter").click();+ H.clauseStepPopover().within(() => {+ cy.findByText("Custom Expression").click();+ H.enterCustomColumnDetails({+ formula: 'if([Category] = "Gadget", 1, [Category] = "Widget", 2) = 2',+ });+ cy.button("Done").click();+ });+ H.visualize();+ H.assertQueryBuilderRowCount(54);+ H.openNotebook();+ H.getNotebookStep("filter")+ .findByText("If is equal to 2")+ .icon("close")+ .click();++ cy.log("aggregations");+ H.getNotebookStep("data").button("Summarize").click();+ H.clauseStepPopover().within(() => {+ cy.findByText("Custom Expression").click();+ H.enterCustomColumnDetails({+ formula: 'sum(if([Category] = "Gadget", 1, 2))',+ name: "SumIf",+ });+ cy.button("Done").click();+ });+ H.visualize();+ cy.findByTestId("scalar-value").should("have.text", "347");+ });++ it("should allow to use `in` and `notIn` functions", () => {+ H.openProductsTable({ mode: "notebook" });++ cy.log("custom columns - in");+ H.getNotebookStep("data").button("Custom column").click();+ H.enterCustomColumnDetails({+ formula: 'in("Gadget", [Vendor], [Category])',+ name: "InColumn",+ });+ H.expressionEditorWidget().button("Done").click();+ H.getNotebookStep("expression").button("Filter").click();+ H.clauseStepPopover().within(() => {+ cy.findByText("InColumn").click();+ cy.findByText("Add filter").click();+ });+ H.visualize();+ H.assertQueryBuilderRowCount(53);++ cy.log("custom columns - notIn");+ H.openNotebook();+ H.getNotebookStep("expression").findByText("InColumn").click();+ H.enterCustomColumnDetails({+ formula: 'notIn("Gadget", [Vendor], [Category])',+ name: "InColumn",+ });+ H.expressionEditorWidget().button("Update").click();+ H.visualize();+ H.assertQueryBuilderRowCount(147);++ cy.log("filters - in");+ H.openNotebook();+ H.getNotebookStep("expression")+ .findByText("InColumn")+ .icon("close")+ .click();+ H.getNotebookStep("data").button("Filter").click();+ H.clauseStepPopover().within(() => {+ cy.findByText("Custom Expression").click();+ H.enterCustomColumnDetails({ formula: "in([ID], 1, 2, 3)" });+ cy.button("Done").click();+ });+ H.visualize();+ H.assertQueryBuilderRowCount(3);+ H.openNotebook();+ H.getNotebookStep("filter").findByText("ID is 3 selections").click();+ H.clauseStepPopover().within(() => {+ cy.findByText("3").next("button").click();+ cy.button("Update filter").click();+ });+ H.visualize();+ H.assertQueryBuilderRowCount(2);++ cy.log("filters - notIn");+ H.openNotebook();+ H.getNotebookStep("filter").findByText("ID is 2 selections").click();+ H.clauseStepPopover().within(() => {+ cy.findByLabelText("Back").click();+ cy.findByText("Custom Expression").click();+ H.enterCustomColumnDetails({ formula: "notIn([ID], 1, 2, 3)" });+ cy.button("Update").click();+ });+ H.visualize();+ H.assertQueryBuilderRowCount(197);++ cy.log("aggregations - in");+ H.openNotebook();+ H.getNotebookStep("filter")+ .findByText("ID is not 3 selections")+ .icon("close")+ .click();+ H.getNotebookStep("data").button("Summarize").click();+ H.clauseStepPopover().within(() => {+ cy.findByText("Custom Expression").click();+ H.enterCustomColumnDetails({+ formula: "countIf(in([ID], 1, 2))",+ name: "CountIfIn",+ });+ cy.button("Done").click();+ });+ H.visualize();+ cy.findByTestId("scalar-value").should("have.text", "2");++ cy.log("aggregations - notIn");+ H.openNotebook();+ H.getNotebookStep("summarize").findByText("CountIfIn").click();+ H.enterCustomColumnDetails({+ formula: "countIf(notIn([ID], 1, 2))",+ name: "CountIfIn",+ });+ H.expressionEditorWidget().button("Update").click();+ H.visualize();+ cy.findByTestId("scalar-value").should("have.text", "198");+ });++ it("should handle expression references", () => {+ H.openProductsTable({ mode: "notebook" });++ H.getNotebookStep("data").button("Custom column").click();+ H.enterCustomColumnDetails({+ formula: "[Price]",+ name: "Foo",+ });+ H.expressionEditorWidget().button("Done").click();++ H.getNotebookStep("expression").icon("add").click();+ H.enterCustomColumnDetails({+ formula: "[Foo]",+ name: "Bar",+ });+ H.expressionEditorWidget().button("Done").click();++ H.getNotebookStep("expression").icon("add").click();+ H.enterCustomColumnDetails({+ formula: "[Bar]",+ name: "Quu",+ });+ H.expressionEditorWidget().button("Done").click();++ H.getNotebookStep("expression").findByText("Foo").click();+ H.CustomExpressionEditor.value().should("eq", "[Price]");+ H.expressionEditorWidget().button("Cancel").click();++ H.getNotebookStep("expression").findByText("Bar").click();+ H.CustomExpressionEditor.value().should("eq", "[Foo]");+ H.expressionEditorWidget().button("Cancel").click();++ H.getNotebookStep("expression").findByText("Quu").click();+ H.CustomExpressionEditor.value().should("eq", "[Bar]");+ });+});diff --git a/e2e/test/scenarios/custom-column/custom-column-2.cy.spec.js b/e2e/test/scenarios/custom-column/custom-column-2.cy.spec.jsnew file mode 100644index 00000000000..b82721c8a69--- /dev/null+++ b/e2e/test/scenarios/custom-column/custom-column-2.cy.spec.js@@ -0,0 +1,483 @@+const { H } = cy;++import { SAMPLE_DATABASE } from "e2e/support/cypress_sample_database";++const { ORDERS_ID, PRODUCTS_ID, PEOPLE_ID } = SAMPLE_DATABASE;++describe(+ "scenarios > question > custom column > data type",+ { tags: "@external" },+ () => {+ function addCustomColumns(columns) {+ cy.wrap(columns).each((column, index) => {+ if (index) {+ H.getNotebookStep("expression").icon("add").click();+ } else {+ cy.findByLabelText("Custom column").click();+ }++ H.enterCustomColumnDetails(column);+ cy.button("Done").click({ force: true });+ });+ }++ function openCustomColumnInTable(table) {+ H.openTable({ table, mode: "notebook" });+ cy.findByText("Custom column").click();+ }++ beforeEach(() => {+ H.restore();+ H.restore("postgres-12");++ cy.signInAsAdmin();+ });++ it("should understand string functions (metabase#13217)", () => {+ openCustomColumnInTable(PRODUCTS_ID);++ H.enterCustomColumnDetails({+ formula: "concat([Category], [Title])",+ name: "CategoryTitle",+ });++ cy.button("Done").click();++ H.filter({ mode: "notebook" });++ H.popover().within(() => {+ cy.findByText("CategoryTitle").click();+ cy.findByPlaceholderText("Enter a number").should("not.exist");+ cy.findByPlaceholderText("Enter some text").should("be.visible");+ });+ });++ it("should understand date functions", () => {+ H.startNewQuestion();+ H.miniPicker().within(() => {+ cy.findByText("QA Postgres12").click();+ cy.findByText("Orders").click();+ });++ addCustomColumns([+ { name: "Year", formula: "year([Created At])" },+ { name: "Quarter", formula: "quarter([Created At])" },+ { name: "Month", formula: "month([Created At])" },+ { name: "Week", formula: 'week([Created At], "iso")' },+ { name: "Day", formula: "day([Created At])" },+ { name: "Weekday", formula: "weekday([Created At])" },+ { name: "Hour", formula: "hour([Created At])" },+ { name: "Minute", formula: "minute([Created At])" },+ { name: "Second", formula: "second([Created At])" },+ {+ name: "Datetime Add",+ formula: 'datetimeAdd([Created At], 1, "month")',+ },+ {+ name: "Datetime Subtract",+ formula: 'datetimeSubtract([Created At], 1, "month")',+ },+ {+ name: "ConvertTimezone 3 args",+ formula: 'convertTimezone([Created At], "Asia/Ho_Chi_Minh", "UTC")',+ },+ {+ name: "ConvertTimezone 2 args",+ formula: 'convertTimezone([Created At], "Asia/Ho_Chi_Minh")',+ },+ ]);++ H.visualize();+ });++ it("should relay the type of a date field", () => {+ openCustomColumnInTable(PEOPLE_ID);++ H.enterCustomColumnDetails({ formula: "[Birth Date]", name: "DoB" });+ cy.button("Done").click();++ H.filter({ mode: "notebook" });+ H.popover().within(() => {+ cy.findByText("DoB").click();+ cy.findByPlaceholderText("Enter a number").should("not.exist");+ cy.findByText("Relative date range…").click();+ cy.findByText("Previous").click();+ cy.findByDisplayValue("days").should("be.visible");+ });+ });++ it("should handle CASE (metabase#13122)", () => {+ openCustomColumnInTable(ORDERS_ID);++ H.enterCustomColumnDetails({+ formula: "case([Discount] > 0, [Created At], [Product → Created At])",+ name: "MiscDate",+ });+ cy.button("Done").click();++ H.filter({ mode: "notebook" });+ H.popover().within(() => {+ cy.findByText("MiscDate").click();+ cy.findByPlaceholderText("Enter a number").should("not.exist");++ cy.findByText("Relative date range…").click();+ cy.findByText("Previous").click();+ cy.findByDisplayValue("days").should("be.visible");+ });+ });++ it("should handle COALESCE", () => {+ openCustomColumnInTable(ORDERS_ID);++ H.enterCustomColumnDetails({+ formula: "COALESCE([Product → Created At], [Created At])",+ name: "MiscDate",+ });+ cy.button("Done").click();++ H.filter({ mode: "notebook" });+ H.popover().within(() => {+ cy.findByText("MiscDate").click();+ cy.findByPlaceholderText("Enter a number").should("not.exist");+ cy.findByText("Relative date range…").click();+ cy.findByText("Previous").click();+ cy.findByDisplayValue("days").should("be.visible");+ });+ });+ },+);++describe("scenarios > question > custom column > error feedback", () => {+ beforeEach(() => {+ H.restore();+ cy.signInAsAdmin();++ H.openProductsTable({ mode: "notebook" });+ // eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage+ cy.findByText("Custom column").click();+ });++ it("should catch non-existent field reference", () => {+ H.enterCustomColumnDetails({+ formula: "abcdef",+ name: "Non-existent",+ });++ // eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage+ cy.contains(/^Unknown column: abcdef/i);+ });++ it("should fail on expression validation errors", () => {+ H.enterCustomColumnDetails({+ formula: "SUBSTRING('foo', 0, 1)",+ name: "BadSubstring",+ });++ // eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage+ cy.contains(/positive integer/i);+ });+});++// ExpressionEditorTextfield jsx component+describe("scenarios > question > custom column > expression editor", () => {+ beforeEach(() => {+ H.restore();+ cy.signInAsAdmin();++ // This is the default screen size but we need it explicitly set for this test because of the resize later on+ cy.viewport(1280, 800);++ H.openOrdersTable({ mode: "notebook" });+ // eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage+ cy.findByText("Custom column").click();++ H.enterCustomColumnDetails({+ formula: "1+1", // Formula was intentionally written without spaces (important for this repro)!+ name: "Math",+ });+ cy.button("Done").should("not.be.disabled");+ });++ it("should not accidentally delete Custom Column formula value and/or Custom Column name (metabase#15734)", () => {+ H.CustomExpressionEditor.type(+ "{movetoend}{leftarrow}{movetostart}{rightarrow}{rightarrow}",+ );+ cy.findByDisplayValue("Math").focus();+ cy.button("Done").should("not.be.disabled");+ });++ it("should not erase Custom column formula and Custom column name when expression is incomplete (metabase#16126)", () => {+ H.CustomExpressionEditor.type("{movetoend}{backspace}").blur();++ // eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage+ cy.findByText("Expected expression");+ cy.button("Done").should("be.disabled");+ });++ it("should not erase Custom Column formula and Custom Column name on window resize (metabase#16127)", () => {+ cy.viewport(1260, 800);+ cy.findByDisplayValue("Math");+ cy.button("Done").should("not.be.disabled");+ });+});++describe("scenarios > question > custom column > help text", () => {+ beforeEach(() => {+ H.restore();+ cy.signInAsAdmin();++ H.openProductsTable({ mode: "notebook" });+ // eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage+ cy.findByText("Custom column").click();+ });++ it("should appear while inside a function", () => {+ H.enterCustomColumnDetails({ formula: "lower(", blur: false });+ H.CustomExpressionEditor.helpTextHeader()+ .should("be.visible")+ .should("contain", "lower(value)");+ });++ it("should appear after a field reference", () => {+ H.enterCustomColumnDetails({ formula: "lower([Category]", blur: false });+ H.CustomExpressionEditor.helpTextHeader()+ .should("be.visible")+ .should("contain", "lower(value)");+ });++ it("should not appear while outside a function", () => {+ H.enterCustomColumnDetails({ formula: "lower([Category])", blur: false });+ H.CustomExpressionEditor.helpTextHeader().should("not.exist");+ });++ it("should not appear when formula field is not in focus (metabase#15891)", () => {+ H.enterCustomColumnDetails({+ formula: "rou{enter}1.5{leftArrow}",+ blur: false,+ });++ H.CustomExpressionEditor.helpText()+ .should("be.visible")+ .should("contain", "round([Temperature])");++ cy.log("Blur event should remove the expression helper popover");+ H.CustomExpressionEditor.blur();+ H.CustomExpressionEditor.helpText().should("not.exist");++ H.CustomExpressionEditor.focus().type("{leftArrow}");+ H.CustomExpressionEditor.helpText()+ .should("be.visible")+ .should("contain", "round([Temperature])");++ cy.log(+ "Pressing `escape` key should also remove the expression helper popover",+ );+ H.CustomExpressionEditor.blur();+ H.CustomExpressionEditor.helpText().should("not.exist");+ });++ it("should not disappear when clicked on (metabase#17548)", () => {+ H.enterCustomColumnDetails({ formula: "round(", blur: false });++ H.CustomExpressionEditor.helpText()+ .should("be.visible")+ .should("contain", "round([Temperature])");++ // Shouldn't hide on click+ H.CustomExpressionEditor.helpText().click();++ H.CustomExpressionEditor.helpText()+ .should("be.visible")+ .should("contain", "round([Temperature])");+ });++ describe("scenarios > question > custom column > help text > visibility", () => {+ beforeEach(() => {+ H.enterCustomColumnDetails({ formula: "round(", blur: false });+ });++ it("should be possible to show and hide the help text when there are no suggestions", () => {+ assertHelpTextIsVisible();++ H.CustomExpressionEditor.helpTextHeader().click();+ assertNeitherAreVisible();++ H.CustomExpressionEditor.helpTextHeader().click();+ assertHelpTextIsVisible();+ });++ it("should show the help text again when the suggestions are closed", () => {+ H.CustomExpressionEditor.type("[Rat", { focus: false });++ cy.log("suggestions should be visible");+ assertSuggestionsAreVisible();++ cy.log("help text should remain visible when suggestions are picked");+ // helptext should re-open when suggestion is picked+ H.CustomExpressionEditor.selectCompletion("Rating");+ assertHelpTextIsVisible();+ });++ it("should be possible to close the help text", () => {+ cy.log("hide help text by clicking the header");+ H.CustomExpressionEditor.helpTextHeader().click();+ assertNeitherAreVisible();++ cy.log("type to see suggestions");+ H.CustomExpressionEditor.type("[Rat", { focus: false });+ assertSuggestionsAreVisible();++ cy.log("help text should remain hidden after selecting a suggestion");+ H.CustomExpressionEditor.selectCompletion("Rating");+ assertNeitherAreVisible();+ });++ it("should be possible to prefer showing the help text over the suggestions", () => {+ cy.log("type to see suggestions");+ H.CustomExpressionEditor.type("[Rat", { focus: false });+ assertSuggestionsAreVisible();++ cy.log("show help text by clicking the header");+ H.CustomExpressionEditor.helpTextHeader().click();+ assertHelpTextIsVisible();++ cy.log("help text should remain shown after finishing typing");+ H.CustomExpressionEditor.type("ing], ", { focus: false });+ assertHelpTextIsVisible();+ });++ it("should be possible to prefer showing the suggestion when typing", () => {+ cy.log("type to see suggestions");+ H.CustomExpressionEditor.type("[Rat", { focus: false });+ assertSuggestionsAreVisible();++ cy.log("show help text by clicking the header");+ H.CustomExpressionEditor.helpTextHeader().click();+ assertHelpTextIsVisible();++ cy.log("show suggestions again by clicking the header");+ H.CustomExpressionEditor.helpTextHeader().click();+ assertSuggestionsAreVisible();++ cy.log("help text should remain shown after finishing typing");+ H.CustomExpressionEditor.type("ing], ", { focus: false });+ assertNeitherAreVisible();+ });++ function assertSuggestionsAreVisible() {+ cy.log("suggestions should be visible");+ H.CustomExpressionEditor.helpText().should("not.exist");+ H.CustomExpressionEditor.completions()+ .findAllByRole("option")+ .should("be.visible");+ }+ function assertHelpTextIsVisible() {+ cy.log("help text should be visible");+ H.CustomExpressionEditor.helpText().should("be.visible");+ H.CustomExpressionEditor.completions()+ .findByRole("option")+ .should("not.exist");+ }+ function assertNeitherAreVisible() {+ H.CustomExpressionEditor.helpText().should("not.exist");+ H.CustomExpressionEditor.completions()+ .findByRole("option")+ .should("not.exist");+ }+ });+});++describe("scenarios > question > custom column > exiting the editor", () => {+ beforeEach(() => {+ H.restore();+ cy.signInAsAdmin();++ H.openProductsTable({ mode: "notebook" });+ // eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage+ cy.findByText("Custom column").click();+ });++ it("should be possible to close the custom expression editor by pressing Escape when it is empty", () => {+ cy.realPress("Escape");+ H.CustomExpressionEditor.get().should("not.exist");+ });++ it("should not be possible to close the custom expression editor by pressing Escape when it is not empty", () => {+ H.CustomExpressionEditor.type("count(");+ cy.realPress("Escape");+ H.CustomExpressionEditor.get().should("be.visible");+ });++ it("should be possible to exit the editor by clicking outside of it when there is no text", () => {+ H.getNotebookStep("data").click();+ H.modal().should("not.exist");+ H.expressionEditorWidget().should("not.exist");+ });++ it("should be possible to exit the editor by clicking outside of it when there is no text, by clicking an interactive element", () => {+ H.getNotebookStep("data").button("Pick columns").click();+ H.modal().should("not.exist");+ H.expressionEditorWidget().should("not.exist");+ H.popover().findByText("Select all").should("be.visible");+ });++ it("should not be possible to exit the editor by clicking outside of it when there is an unsaved expression", () => {+ H.enterCustomColumnDetails({ formula: "1+1", blur: false });+ H.getNotebookStep("data").button("Pick columns").click();+ H.popover().findByText("Select all").should("not.exist");+ H.expressionEditorWidget().should("exist");++ H.modal().within(() => {+ cy.findByText("Keep editing your custom expression?").should(+ "be.visible",+ );+ cy.button("Discard changes").should("be.enabled");+ cy.button("Keep editing").click();+ });++ H.modal().should("not.exist");+ H.expressionEditorWidget().should("exist");+ });++ it("should be possible to discard changes when clicking outside of the editor", () => {+ H.enterCustomColumnDetails({ formula: "1+1", blur: false });+ H.getNotebookStep("data").button("Pick columns").click();+ H.expressionEditorWidget().should("exist");+ H.popover().findByText("Select all").should("not.exist");++ H.modal().within(() => {+ cy.findByText("Keep editing your custom expression?").should(+ "be.visible",+ );+ cy.button("Keep editing").should("be.enabled");+ cy.button("Discard changes").click();+ });++ H.modal().should("not.exist");+ H.expressionEditorWidget().should("not.exist");+ });++ it("should be possible to discard changes by clicking cancel button", () => {+ H.enterCustomColumnDetails({ formula: "1+1", name: "OK" });+ H.expressionEditorWidget().button("Cancel").click();+ H.modal().should("not.exist");+ H.expressionEditorWidget().should("not.exist");+ H.getNotebookStep("expression").findByText("OK").should("not.exist");+ });++ it("should be possible to close the popover when navigating away from the expression editor", () => {+ H.expressionEditorWidget().button("Cancel").click();+ cy.button("Summarize").click();+ H.popover().as("popover").findByText("Custom Expression").click();+ H.enterCustomColumnDetails({ formula: "1+1" });++ cy.log("Go back to summarize modal");+ H.popover().findByText("Custom Expression").click();++ cy.log("Close summarize modal by clicking outside");+ cy.findByLabelText("View SQL").click();++ H.modal().should("not.exist");+ cy.get("popover").should("not.exist");+ });+});diff --git a/e2e/test/scenarios/custom-column/custom-column-3.cy.spec.js b/e2e/test/scenarios/custom-column/custom-column-3.cy.spec.jsnew file mode 100644index 00000000000..2a290306bc5--- /dev/null+++ b/e2e/test/scenarios/custom-column/custom-column-3.cy.spec.js@@ -0,0 +1,1050 @@+const { H } = cy;++import { SAMPLE_DB_ID } from "e2e/support/cypress_data";+import { SAMPLE_DATABASE } from "e2e/support/cypress_sample_database";++const { ORDERS, ORDERS_ID, PEOPLE_ID, PEOPLE } = SAMPLE_DATABASE;++describe("scenarios > question > custom column > distinctIf", () => {+ beforeEach(() => {+ H.restore();+ cy.signInAsNormalUser();+ });++ it("should allow to use a distinctIf function", () => {+ H.openProductsTable({ mode: "notebook" });++ cy.log("add a new expression");+ H.getNotebookStep("data").button("Summarize").click();+ H.popover().findByText("Custom Expression").click();+ H.enterCustomColumnDetails({+ formula: "DistinctIf([ID], [Category] = 'Gadget')",+ name: "Distinct",+ });+ H.popover().button("Done").click();+ H.visualize();+ cy.findByTestId("scalar-value").should("have.text", "53");++ cy.log("modify the expression");+ H.openNotebook();+ H.getNotebookStep("summarize").findByText("Distinct").click();+ H.CustomExpressionEditor.value().should(+ "eq",+ 'DistinctIf([ID], [Category] = "Gadget")',+ );+ H.enterCustomColumnDetails({+ formula: "DistinctIf([ID], [Category] != 'Gadget')",+ name: "Distinct",+ });+ H.popover().button("Update").click();+ H.visualize();+ cy.findByTestId("scalar-value").should("have.text", "147");+ });+});++describe("scenarios > question > custom column > path", () => {+ beforeEach(() => {+ H.restore();+ cy.signInAsNormalUser();+ });++ function assertTableData({ title, value }) {+ // eslint-disable-next-line metabase/no-unsafe-element-filtering+ H.tableInteractive()+ .findAllByTestId("header-cell")+ .last()+ .should("have.text", title);++ // eslint-disable-next-line metabase/no-unsafe-element-filtering+ H.tableInteractiveBody()+ .findAllByTestId("cell-data")+ .last()+ .should("have.text", value);+ }++ it("should allow to use a path function", () => {+ const CC_NAME = "URL_URL";+ const questionDetails = {+ name: "path from url",+ query: {+ "source-table": PEOPLE_ID,+ limit: 1,+ expressions: {+ [CC_NAME]: [+ "concat",+ "http://",+ ["domain", ["field", PEOPLE.EMAIL, null]],+ ".com/my/path",+ ],+ },+ },+ type: "model",+ };++ H.createQuestion(questionDetails, {+ wrapId: true,+ idAlias: "modelId",+ });++ cy.get("@modelId").then((modelId) => {+ H.setModelMetadata(modelId, (field) => {+ if (field.name === CC_NAME) {+ return { ...field, semantic_type: "type/URL" };+ }++ return field;+ });++ H.visitModel(modelId);+ });++ H.openNotebook();++ cy.log("add a new expression");+ H.getNotebookStep("data").button("Custom column").click();+ H.enterCustomColumnDetails({+ formula: `Path([${CC_NAME}])`,+ name: "extracted path",+ });++ H.popover().button("Done").click();+ H.visualize();+ cy.findByTestId("table-scroll-container").scrollTo("right");++ const extractedValue = "/my/path";+ assertTableData({+ title: "extracted path",+ value: extractedValue,+ });+ });+});++describe("scenarios > question > custom column > function browser", () => {+ beforeEach(() => {+ H.restore();+ cy.signInAsNormalUser();++ H.openProductsTable({ mode: "notebook" });+ H.addCustomColumn();+ });++ it("should be possible to insert functions by clicking them in the function browser", () => {+ H.expressionEditorWidget().button("Function browser").click();++ H.CustomExpressionEditor.functionBrowser()+ .findByText("datetimeAdd")+ .click();++ H.CustomExpressionEditor.value().should("equal", "datetimeAdd()");++ H.CustomExpressionEditor.functionBrowser().findByText("day").click();+ H.CustomExpressionEditor.value().should("equal", "datetimeAdd(day())");++ H.CustomExpressionEditor.type('"foo"{rightarrow}, ', { focus: false });+ H.CustomExpressionEditor.value().should(+ "equal",+ 'datetimeAdd(day("foo"), )',+ );++ H.CustomExpressionEditor.functionBrowser().findByText("day").click();+ H.CustomExpressionEditor.value().should(+ "equal",+ 'datetimeAdd(day("foo"), day())',+ );+ });++ it("should be possible to replace text when inserting functions", () => {+ H.CustomExpressionEditor.type("foo bar baz");+ cy.realPress(["ArrowLeft"]);+ cy.realPress(["ArrowLeft"]);+ cy.realPress(["ArrowLeft"]);+ cy.realPress(["ArrowLeft"]);+ cy.realPress(["Shift", "ArrowLeft"]);+ cy.realPress(["Shift", "ArrowLeft"]);+ cy.realPress(["Shift", "ArrowLeft"]);++ H.expressionEditorWidget().button("Function browser").click();+ H.CustomExpressionEditor.functionBrowser().findByText("day").click();+ H.CustomExpressionEditor.value().should("equal", "foo day() baz");+ });++ it("should be possible to filter functions in the function browser", () => {+ H.expressionEditorWidget().button("Function browser").click();++ H.CustomExpressionEditor.functionBrowser().within(() => {+ cy.findByPlaceholderText("Search functions…").type("con");++ cy.findByText("datetimeAdd").should("not.exist");+ cy.findByText("concat").should("be.visible");+ cy.findByText("second").should("be.visible");+ //+ cy.findByPlaceholderText("Search functions…").clear();+ cy.findByText("datetimeAdd").should("exist");+ });+ });++ it("should not show functions that are not supported by the current database", () => {+ H.expressionEditorWidget().button("Function browser").click();++ H.CustomExpressionEditor.functionBrowser().within(() => {+ cy.findByPlaceholderText("Search functions…").type("convertTimezone");+ cy.findByText("convertTimezone").should("not.exist");+ });+ });++ it("should not show aggregations unless aggregating", () => {+ H.expressionEditorWidget().button("Function browser").click();+ H.CustomExpressionEditor.functionBrowser().within(() => {+ cy.findByPlaceholderText("Search functions…").type("Count");+ cy.findByText("Count").should("not.exist");+ });+ H.expressionEditorWidget().button("Cancel").click();++ H.summarize({ mode: "notebook" });+ H.popover().findByText("Custom Expression").click();++ H.expressionEditorWidget().button("Function browser").click();+ H.CustomExpressionEditor.functionBrowser().within(() => {+ cy.findByPlaceholderText("Search aggregations…").type("Count");+ cy.findByText("Count").should("be.visible");+ });+ });++ it("show a message when no functions match the filter", () => {+ H.expressionEditorWidget().button("Function browser").click();+ H.CustomExpressionEditor.functionBrowser().within(() => {+ cy.findByPlaceholderText("Search functions…").type("foobar");+ cy.findByText("Didn't find any results").should("be.visible");+ });+ });++ it("should insert parens even when the clause has no arguments", () => {+ H.expressionEditorWidget().button("Function browser").click();+ H.CustomExpressionEditor.functionBrowser().within(() => {+ cy.findByPlaceholderText("Search functions…").type("now");+ cy.findByText("now").click();+ });+ H.CustomExpressionEditor.value().should("equal", "now()");+ });+});++describe("scenarios > question > custom column > splitPart", () => {+ beforeEach(() => {+ H.restore("postgres-12");+ cy.signInAsAdmin();++ H.startNewQuestion();+ H.miniPicker().within(() => {+ cy.findByText("QA Postgres12").click();+ cy.findByText("People").click();+ });++ cy.findByLabelText("Custom column").click();+ });++ function assertTableData({ title, value }) {+ // eslint-disable-next-line metabase/no-unsafe-element-filtering+ H.tableInteractive()+ .findAllByTestId("header-cell")+ .last()+ .should("have.text", title);++ // eslint-disable-next-line metabase/no-unsafe-element-filtering+ H.tableInteractiveBody()+ .findAllByTestId("cell-data")+ .last()+ .should("have.text", value);+ }++ it("should be possible to split a custom column", () => {+ const CC_NAME = "Split Title";++ H.enterCustomColumnDetails({+ formula: "splitPart([Name], ' ', 1)",+ name: CC_NAME,+ });+ H.popover().button("Done").click();++ cy.findByLabelText("Row limit").click();+ cy.findByPlaceholderText("Enter a limit").type(1).blur();++ H.visualize();++ H.tableInteractiveScrollContainer().scrollTo("right");+ assertTableData({ title: CC_NAME, value: "Hudson" });+ });++ it("should show a message when index is below 1", () => {+ H.enterCustomColumnDetails({+ formula: "splitPart([Name], ' ', 0)",+ });++ H.popover().button("Done").should("be.disabled");+ H.popover().should("contain", "Expected positive integer but found 0");+ });+});++describe("exercise today() function", () => {+ beforeEach(() => {+ H.restore("postgres-12");+ cy.signInAsAdmin();+ });++ it("should show today's date", () => {+ H.startNewQuestion();+ H.miniPicker().within(() => {+ cy.findByText("QA Postgres12").click();+ cy.findByText("Products").click();+ });++ H.getNotebookStep("data").button("Pick columns").click();+ H.popover().findByText("Select all").click();+ cy.realPress("Escape");++ H.visualize();+ H.assertQueryBuilderRowCount(200);+ H.openNotebook();++ H.getNotebookStep("data").button("Custom column").click();+ H.enterCustomColumnDetails({ formula: "today()", name: "TODAY" });+ H.popover().button("Done").click();++ const today = new Date();+ const dateString = today.toLocaleDateString("en-US", {+ year: "numeric",+ month: "long",+ day: "numeric",+ });++ H.visualize();+ cy.findAllByTestId("header-cell").eq(1).should("have.text", "TODAY");+ cy.findAllByTestId("cell-data").eq(3).should("have.text", dateString);+ });+});++describe("scenarios > question > custom column > aggregation", () => {+ beforeEach(() => {+ H.restore();+ cy.signInAsNormalUser();+ H.openOrdersTable({ mode: "notebook" });+ });++ it("should be possible to resolve aggregations from the question", () => {+ H.createQuestion(+ {+ query: {+ "source-table": ORDERS_ID,+ aggregation: [+ [+ "aggregation-options",+ ["sum", ["field", ORDERS.TOTAL, null]],+ {+ name: "Custom Sum",+ "display-name": "Custom Sum",+ },+ ],+ ],+ },+ },+ { visitQuestion: true },+ );+ H.openNotebook();++ H.getNotebookStep("summarize").icon("add").click();+ H.popover().findByText("Custom Expression").scrollIntoView().click();++ H.CustomExpressionEditor.type("[Custom");+ H.CustomExpressionEditor.completion("Custom Sum")+ .should("be.visible")+ .click();+ H.CustomExpressionEditor.value().should("eq", "[Custom Sum]");+ H.CustomExpressionEditor.type("+ 1");+ H.CustomExpressionEditor.format();++ H.CustomExpressionEditor.nameInput().type("Derived");+ H.popover().button("Done").click();++ H.visualize();+ H.assertTableData({+ columns: ["Custom Sum", "Derived"],+ });+ });++ it("should be possible to resolve aggregations from the question directly", () => {+ H.createQuestion(+ {+ query: {+ "source-table": ORDERS_ID,+ aggregation: [+ [+ "aggregation-options",+ ["sum", ["field", ORDERS.TOTAL, null]],+ {+ name: "Custom Sum",+ "display-name": "Custom Sum",+ },+ ],+ ],+ },+ },+ { visitQuestion: true },+ );+ H.openNotebook();++ H.getNotebookStep("summarize").icon("add").click();+ H.popover().findByText("Custom Expression").scrollIntoView().click();++ H.CustomExpressionEditor.type("[Custom");+ H.CustomExpressionEditor.completion("Custom Sum")+ .should("be.visible")+ .click();+ H.CustomExpressionEditor.value().should("eq", "[Custom Sum]");+ H.CustomExpressionEditor.format();++ H.CustomExpressionEditor.nameInput().type("Derived");+ H.popover().button("Done").click();++ H.visualize();+ H.assertTableData({+ columns: ["Custom Sum", "Derived"],+ });+ });++ it("should be possible to resolve aggregations from the previous stage", () => {+ H.createQuestion(+ {+ query: {+ "source-table": ORDERS_ID,+ aggregation: [+ [+ "aggregation-options",+ ["sum", ["field", ORDERS.TOTAL, null]],+ {+ name: "Custom Sum",+ "display-name": "Custom Sum",+ },+ ],+ ],+ },+ },+ { visitQuestion: true },+ );+ H.openNotebook();++ cy.findAllByLabelText("Custom column").eq(1).click();+ H.CustomExpressionEditor.type("[Custom S");+ H.CustomExpressionEditor.completion("Custom Sum")+ .should("be.visible")+ .click();+ H.CustomExpressionEditor.value().should("eq", "[Custom Sum]");+ H.CustomExpressionEditor.format();++ H.CustomExpressionEditor.nameInput().type("Derived");+ H.popover().button("Done").click();++ H.visualize();+ H.assertTableData({+ columns: ["Custom Sum", "Derived"],+ });+ });++ it("should not be possible to create cycles in custom aggregations", () => {+ H.createQuestion(+ {+ query: {+ "source-table": ORDERS_ID,+ aggregation: [+ [+ "aggregation-options",+ ["sum", ["field", ORDERS.TOTAL, null]],+ {+ name: "Custom Sum",+ "display-name": "Custom Sum",+ },+ ],+ ],+ },+ },+ { visitQuestion: true },+ );++ H.openNotebook();++ H.getNotebookStep("summarize").icon("add").click();+ H.popover().findByText("Custom Expression").scrollIntoView().click();+ H.CustomExpressionEditor.type("[Custom Sum] + 1");+ H.CustomExpressionEditor.nameInput().type("Custom Sum 2");+ H.popover().button("Done").click();++ H.getNotebookStep("summarize").findByText("Custom Sum").click();+ H.CustomExpressionEditor.clear().type("[Custom Sum 2]");++ H.popover()+ .findByText("Cycle detected: Custom Sum → Custom Sum 2 → Custom Sum")+ .should("be.visible");+ });++ it("should be possible to create aggregations with the same name", () => {+ H.createQuestion(+ {+ query: {+ "source-table": ORDERS_ID,+ aggregation: [+ [+ "aggregation-options",+ ["sum", ["field", ORDERS.TOTAL, null]],+ {+ name: "Foo",+ "display-name": "Foo",+ },+ ],+ ],+ },+ },+ { visitQuestion: true },+ );+ H.openNotebook();++ H.getNotebookStep("summarize").icon("add").click();+ H.popover().findByText("Custom Expression").scrollIntoView().click();+ H.CustomExpressionEditor.type("Min([Total])");+ H.CustomExpressionEditor.nameInput().type("Foo");+ H.popover().button("Done").click();++ H.getNotebookStep("summarize").within(() => {+ cy.findAllByText("Foo").should("have.length", 2);+ });+ });++ it("should be possible to reorder aggregations with the same name", () => {+ H.createQuestion(+ {+ query: { "source-table": ORDERS_ID },+ },+ { visitQuestion: true },+ );+ H.openNotebook();++ H.summarize({ mode: "notebook" });++ H.popover().findByText("Custom Expression").scrollIntoView().click();+ H.CustomExpressionEditor.type("Count() + 1");+ H.CustomExpressionEditor.nameInput().type("Count");+ H.popover().button("Done").click();++ H.getNotebookStep("summarize").icon("add").click();+ H.popover().findByText("Custom Expression").scrollIntoView().click();+ H.CustomExpressionEditor.type("[Count] + 1");+ H.CustomExpressionEditor.nameInput().type("Count");+ H.popover().button("Done").click();++ H.getNotebookStep("summarize").icon("add").click();+ H.popover().findByText("Custom Expression").scrollIntoView().click();+ H.CustomExpressionEditor.type("[Count] + 2");+ H.CustomExpressionEditor.nameInput().type("Final");+ H.popover().button("Done").click();++ cy.log("Both the secound Count and Final should reference the first Count");+ H.visualize();+ H.assertTableData({+ columns: ["Count", "Count", "Final"],+ firstRows: [["18,761", "18,762", "18,763"]],+ });++ H.openNotebook();++ cy.log("Move the second Count to be the first");+ H.getNotebookStep("summarize")+ .findAllByText("Count")+ .should("have.length", 2)+ .last()+ .as("dragElement");+ H.moveDnDKitElementByAlias("@dragElement", { horizontal: -400 });++ cy.log("The values should not have changed, but the order should have");+ H.visualize();+ H.assertTableData({+ columns: ["Count", "Count", "Final"],+ firstRows: [["18,762", "18,761", "18,763"]],+ });+ });++ describe("scenarios > question > custom column > aggregation > as question source", () => {+ beforeEach(() => {+ H.createQuestion({+ query: {+ "source-table": ORDERS_ID,+ aggregation: [+ [+ "aggregation-options",+ [+ "min",+ [+ "field",+ ORDERS.SUBTOTAL,+ {+ "base-type": "type/Float",+ },+ ],+ ],+ {+ name: "Foo",+ "display-name": "Foo",+ },+ ],+ [+ "aggregation-options",+ [+ "+",+ [+ "aggregation",+ 0,+ {+ "base-type": "type/Float",+ },+ ],+ [+ "avg",+ [+ "field",+ ORDERS.TAX,+ {+ "base-type": "type/Float",+ },+ ],+ ],+ ],+ {+ name: "Bar",+ "display-name": "Bar",+ },+ ],+ ],+ },+ }).then((res) => {+ H.visitQuestionAdhoc(+ {+ type: "question",+ dataset_query: {+ type: "query",+ database: SAMPLE_DB_ID,+ query: {+ "source-table": `card__${res.body.id}`,+ },+ },+ },+ { mode: "notebook" },+ );+ });+ });++ it("should be possible to use a question with nested aggregations as the source of another question", () => {+ H.visualize();+ H.assertTableData({+ columns: ["Foo", "Bar"],+ firstRows: [["15.69", "19.55"]],+ });+ });++ it("should be possible to use nested aggregations in custom columns of a new question", () => {+ H.addCustomColumn();+ H.CustomExpressionEditor.type("[Foo] + [Bar]");+ H.CustomExpressionEditor.nameInput().type("Sum");+ H.popover().button("Done").click();++ H.visualize();++ H.assertTableData({+ columns: ["Foo", "Bar", "Sum"],+ firstRows: [["15.69", "19.55", "35.24"]],+ });+ });++ it("should be possible to use nested aggregations in filter clause of a new question", () => {+ H.filter({ mode: "notebook" });+ H.popover().within(() => {+ cy.findByText("Bar").click();+ cy.findByPlaceholderText("Min").type("5");+ cy.findByPlaceholderText("Max").type("20");+ cy.button("Add filter").click();+ });+ H.visualize();+ H.assertTableData({+ columns: ["Foo", "Bar"],+ firstRows: [["15.69", "19.55"]],+ });+ });++ it("should be possible to use nested aggregations in join clause of a new question", () => {+ H.join();+ H.joinTable("Products");+ H.popover().findByText("Foo").click();+ H.popover().findByText("Price").click();++ H.getNotebookStep("join").button("Pick columns").click();+ H.popover().within(() => {+ cy.findByText("Select all").click();+ cy.findByText("ID").click();+ });++ H.visualize();+ H.assertTableData({+ columns: ["Foo", "Bar", "Products - Foo → ID"],+ firstRows: [["15.69", "19.55", "61"]],+ });+ });++ it("should be possible to use nested aggregations in order by clause of a new question", () => {+ H.sort();+ H.popover().findByText("Bar").click();++ H.visualize();+ H.assertTableData({+ columns: ["Foo", "Bar"],+ firstRows: [["15.69", "19.55"]],+ });+ });++ it("should be possible to use nested aggregations in breakout of a new question", () => {+ H.summarize({ mode: "notebook" });+ H.getNotebookStep("summarize")+ .findByText("Pick a column to group by")+ .click();+ H.popover().findByText("Bar").click();++ H.visualize();+ cy.findByTestId("scalar-value").should("have.text", "19.55");+ });+ });++ describe("scenarios > question > custom column > aggregation > in a follow up stage", () => {+ beforeEach(() => {+ H.createQuestion(+ {+ query: {+ "source-table": ORDERS_ID,+ aggregation: [+ [+ "aggregation-options",+ [+ "min",+ [+ "field",+ ORDERS.SUBTOTAL,+ {+ "base-type": "type/Float",+ },+ ],+ ],+ {+ name: "Foo",+ "display-name": "Foo",+ },+ ],+ [+ "aggregation-options",+ [+ "+",+ [+ "aggregation",+ 0,+ {+ "base-type": "type/Float",+ },+ ],+ [+ "avg",+ [+ "field",+ ORDERS.TAX,+ {+ "base-type": "type/Float",+ },+ ],+ ],+ ],+ {+ name: "Bar",+ "display-name": "Bar",+ },+ ],+ ],+ },+ },+ { visitQuestion: true },+ );+ H.openNotebook();+ });++ it("should be possible to use nested aggregations in custom columns of a follow up stage", () => {+ H.getNotebookStep("summarize").within(() => {+ H.addCustomColumn();+ });++ H.CustomExpressionEditor.type("[Foo] + [Bar]");+ H.CustomExpressionEditor.nameInput().type("Sum");+ H.popover().button("Done").click();++ H.visualize();++ H.assertTableData({+ columns: ["Foo", "Bar", "Sum"],+ firstRows: [["15.69", "19.55", "35.24"]],+ });+ });++ it("should be possible to use nested aggregations in join clause of a follow up stage", () => {+ H.getNotebookStep("summarize").within(() => {+ H.join();+ });++ H.joinTable("Products");+ H.popover().findByText("Foo").click();+ H.popover().findByText("Price").click();++ H.getNotebookStep("join", { stage: 1 }).button("Pick columns").click();+ H.popover().within(() => {+ cy.findByText("Select all").click();+ cy.findByText("ID").click();+ });++ H.visualize();+ H.assertTableData({+ columns: ["Foo", "Bar", "Products - Foo → ID"],+ firstRows: [["15.69", "19.55", "61"]],+ });+ });+ });++ describe("scenarios > question > custom column > aggregation with breakout > in a follow up stage", () => {+ beforeEach(() => {+ H.createQuestion(+ {+ query: {+ "source-table": ORDERS_ID,+ aggregation: [+ [+ "aggregation-options",+ [+ "min",+ [+ "field",+ ORDERS.SUBTOTAL,+ {+ "base-type": "type/Float",+ },+ ],+ ],+ {+ name: "Foo",+ "display-name": "Foo",+ },+ ],+ [+ "aggregation-options",+ [+ "+",+ [+ "aggregation",+ 0,+ {+ "base-type": "type/Float",+ },+ ],+ [+ "avg",+ [+ "field",+ ORDERS.TAX,+ {+ "base-type": "type/Float",+ },+ ],+ ],+ ],+ {+ name: "Bar",+ "display-name": "Bar",+ },+ ],+ ],+ breakout: [+ [+ "field",+ ORDERS.CREATED_AT,+ { "base-type": "type/DateTime", "temporal-unit": "month" },+ ],+ ],+ },+ },+ { visitQuestion: true },+ );+ H.openNotebook();+ });++ it("should be possible to use nested aggregations in custom columns of a follow up stage", () => {+ H.getNotebookStep("summarize").within(() => {+ H.addCustomColumn();+ });+ H.CustomExpressionEditor.type("[Foo] + [Bar]");+ H.CustomExpressionEditor.nameInput().type("Sum");+ H.popover().button("Done").click();++ H.visualize();++ H.assertTableData({+ columns: ["Created At: Month", "Foo", "Bar", "Sum"],+ firstRows: [["April 2022", "49.54", "52.76", "102.29"]],+ });+ });++ it("should be possible to use nested aggregations in filter clause of a follow up stage", () => {+ H.getNotebookStep("summarize").within(() => {+ H.filter({ mode: "notebook" });+ });+ H.popover().within(() => {+ cy.findByText("Bar").click();+ cy.findByPlaceholderText("Min").type("5");+ cy.findByPlaceholderText("Max").type("20");+ cy.button("Add filter").click();+ });+ H.visualize();+ H.assertTableData({+ columns: ["Created At: Month", "Foo", "Bar"],+ firstRows: [["September 2022", "15.69", "18.57"]],+ });+ });++ it("should be possible to use nested aggregations in join clause of a follow up stage", () => {+ H.getNotebookStep("summarize").within(() => {+ H.join();+ });+ H.joinTable("Products");++ H.popover().findByText("Foo").click();+ H.popover().findByText("Price").click();++ H.getNotebookStep("join", { stage: 1 }).button("Pick columns").click();+ H.popover().within(() => {+ cy.findByText("Select all").click();+ cy.findByText("ID").click();+ });++ H.visualize();+ H.assertTableData({+ columns: ["Created At: Month", "Foo", "Bar", "Products - Foo → ID"],+ firstRows: [["April 2022", "49.54", "52.76", "34"]],+ });+ });++ it("should be possible to use nested aggregations in order by clause of a follow up stage", () => {+ H.getNotebookStep("summarize").within(() => {+ H.sort();+ });+ H.popover().findByText("Bar").click();++ H.visualize();+ H.assertTableData({+ columns: ["Created At: Month", "Foo", "Bar"],+ firstRows: [["April 2023", "15.69", "18.21"]],+ });+ });++ it("should be possible to use nested aggregations in breakout of a follow up stage", () => {+ H.getNotebookStep("summarize").within(() => {+ H.summarize({ mode: "notebook" });+ });++ H.popover().findByText("Count of rows").click();++ H.visualize();+ H.assertTableData({+ columns: ["Count"],+ firstRows: [["49"]],+ });+ });++ it("should be possible reference both aggregations with same name in follow up stage", () => {+ H.openOrdersTable({ mode: "notebook" });++ H.summarize({ mode: "notebook" });++ H.popover().findByText("Custom Expression").scrollIntoView().click();+ H.CustomExpressionEditor.type("Count() + 1");+ H.CustomExpressionEditor.nameInput().type("Count");+ H.popover().button("Done").click();++ H.getNotebookStep("summarize").icon("add").click();+ H.popover().findByText("Custom Expression").scrollIntoView().click();+ H.CustomExpressionEditor.type("[Count] + 1");+ H.CustomExpressionEditor.nameInput().type("Count");+ H.popover().button("Done").click();++ H.getNotebookStep("summarize")+ .findByText("Pick a column to group by")+ .click();+ H.popover().findByText("Created At").click();++ cy.log("Filter by the first Count");+ H.getNotebookStep("summarize").within(() => {+ H.filter({ mode: "notebook" });+ });+ H.popover().within(() => {+ cy.findAllByText("Count").should("have.length", 2);++ cy.findAllByText("Count").eq(0).click();++ // if this was referencing the second Count, it would filter out all rows+ cy.findByPlaceholderText("Max").type("2.5");+ cy.button("Add filter").click();+ });++ cy.log("Filter by the second Count");+ H.getNotebookStep("filter", { stage: 1 }).icon("add").click();+ H.popover().within(() => {+ cy.findAllByText("Count").should("have.length", 2);++ cy.findAllByText("Count").eq(1).click();++ // if this was referencing the first Count, it would filter out all rows+ cy.findByPlaceholderText("Min").type("2.5");+ cy.button("Add filter").click();+ });++ H.visualize();+ H.assertTableData({+ columns: ["Created At: Month", "Count", "Count"],+ firstRows: [["April 2022", "2", "3"]],+ });++ cy.log(+ "Swapping the aggregation clauses should not change the results, but the column order will be different",+ );+ H.openNotebook();+ H.getNotebookStep("summarize")+ .findAllByText("Count")+ .should("have.length", 2)+ .last()+ .as("dragElement");+ H.moveDnDKitElementByAlias("@dragElement", { horizontal: -400 });++ H.visualize();+ H.assertTableData({+ columns: ["Created At: Month", "Count", "Count"],+ firstRows: [["April 2022", "3", "2"]],+ });+ });+ });++ it("should show a custom error when there are no aggregations in a custom aggregation", () => {+ H.openOrdersTable({ mode: "notebook" });+ H.summarize({ mode: "notebook" });+ H.popover().findByText("Custom Expression").scrollIntoView().click();+ H.CustomExpressionEditor.type("1 + 1");+ H.popover()+ .findByText(+ "Aggregations should contain at least one aggregation function.",+ )+ .should("be.visible");+ });+});diff --git a/e2e/test/scenarios/custom-column/custom-column-reproductions.cy.spec.js b/e2e/test/scenarios/custom-column/custom-column-reproductions-1.cy.spec.jssimilarity index 60%rename from e2e/test/scenarios/custom-column/custom-column-reproductions.cy.spec.jsrename to e2e/test/scenarios/custom-column/custom-column-reproductions-1.cy.spec.jsindex 1c96e859fb7..1b79b152282 100644--- a/e2e/test/scenarios/custom-column/custom-column-reproductions.cy.spec.js+++ b/e2e/test/scenarios/custom-column/custom-column-reproductions-1.cy.spec.js@@ -1515,1048 +1515,3 @@ describe("issue 48562", () => {H.CustomExpressionEditor.value().should("contain", "[Unknown Metric]");});});--describe("issue 54638", () => {- beforeEach(() => {- H.restore();- cy.signInAsNormalUser();- H.openOrdersTable({ mode: "notebook" });- H.addCustomColumn();- });-- it("should be possible to click documentation links in the expression editor help text popover (metabase#54638)", () => {- H.CustomExpressionEditor.type("case(");- H.CustomExpressionEditor.helpText().within(() => {- cy.findByText("Learn more")- .scrollIntoView()- .should("be.visible")- .then(($a) => {- expect($a).to.have.attr("target", "_blank");- // Update attr to open in same tab, since Cypress does not support- // testing in multiple tabs.- $a.attr("target", "_self");- })- .click();- cy.url().should(- "equal",- "https://www.metabase.com/docs/latest/questions/query-builder/expressions/case.html",- );- });- });-});--describe("issue #54722", () => {- beforeEach(() => {- H.restore();- cy.signInAsNormalUser();- H.openOrdersTable({ mode: "notebook" });- });-- it("should focus the editor when opening it (metabase#54722)", () => {- H.addCustomColumn();- cy.focused().should("have.attr", "role", "textbox");- H.expressionEditorWidget().button("Cancel").click();-- H.filter({ mode: "notebook" });- H.popover().findByText("Custom Expression").click();- cy.focused().should("have.attr", "role", "textbox");- H.expressionEditorWidget().button("Cancel").click();-- H.summarize({ mode: "notebook" });- H.popover().findByText("Custom Expression").click();- cy.focused().should("have.attr", "role", "textbox");- H.expressionEditorWidget().button("Cancel").click();- });-});--describe("issue #31964", () => {- beforeEach(() => {- H.restore();- cy.signInAsNormalUser();- H.openOrdersTable({ mode: "notebook" });- });-- it("should focus the editor when opening it (metabase#54722)", () => {- H.addCustomColumn();- H.CustomExpressionEditor.type('case([Product -> Category] = "Widget", 1,');- cy.realPress("Enter");- H.CustomExpressionEditor.type("[Product -> Categ", { focus: false });- cy.realPress("Tab");- H.CustomExpressionEditor.value().should(- "equal",- dedent`- case([Product → Category] = "Widget", 1,- [Product → Category])- `,- );- });-});--describe("issue #55686", () => {- beforeEach(() => {- H.restore();- cy.signInAsNormalUser();- H.openOrdersTable({ mode: "notebook" });- });-- it("should show suggestions for functions even when the current token is an operator (metabase#55686)", () => {- H.addCustomColumn();- H.CustomExpressionEditor.type("not");-- H.CustomExpressionEditor.completion("notNull").should("be.visible");- H.CustomExpressionEditor.completion("notEmpty").should("be.visible");- });-});--describe("issue #55940", () => {- beforeEach(() => {- H.restore();- cy.signInAsNormalUser();- H.openOrdersTable({ mode: "notebook" });- });-- it("should show the correct example for Offset (metabase#55940)", () => {- H.summarize({ mode: "notebook" });- H.popover().findByText("Custom Expression").click();-- H.CustomExpressionEditor.type("Offset(");- H.CustomExpressionEditor.helpText()- .should("be.visible")- .should("contain", "Offset(Sum([Total]), -1)");- });-});--describe("issue #55984", () => {- beforeEach(() => {- H.restore();- cy.signInAsNormalUser();- H.openOrdersTable({ mode: "notebook" });- });-- it("should not overflow the suggestion tooltip when a suggestion name is too long (metabase#55984)", () => {- H.addCustomColumn();- H.enterCustomColumnDetails({- formula: "[Total]",- name: "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt",- });- cy.button("Done").click();-- H.summarize({ mode: "notebook" });- H.popover().findByText("Custom Expression").click();- H.CustomExpressionEditor.type("[lo");- H.CustomExpressionEditor.completions().should(($el) => {- expect(H.isScrollableHorizontally($el[0])).to.be.false;- });- });-- it("should not overflow the suggestion tooltip when a suggestion name is too long and has no spaces (metabase#55984)", () => {- H.addCustomColumn();- H.enterCustomColumnDetails({- formula: "[Total]",- name: "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt".replaceAll(- " ",- "_",- ),- });- cy.button("Done").click();-- H.summarize({ mode: "notebook" });- H.popover().findByText("Custom Expression").click();- H.CustomExpressionEditor.type("[lo");- H.CustomExpressionEditor.completions().should(($el) => {- expect(H.isScrollableHorizontally($el[0])).to.be.false;- });- });-});--describe("issue 55622", () => {- beforeEach(() => {- H.restore();- cy.signInAsNormalUser();- });-- it("should allow to mix regular functions with aggregation functions (metabase#55622)", () => {- H.openPeopleTable({ mode: "notebook" });- H.getNotebookStep("data").button("Summarize").click();- H.popover().findByText("Custom Expression").click();- H.enterCustomColumnDetails({- formula: 'datetimeDiff(Max([Created At]), max([Birth Date]), "minute")',- name: "Aggregation",- });- H.popover().button("Done").click();- H.visualize();- H.assertQueryBuilderRowCount(1);- });-});--describe("issue 56152", () => {- beforeEach(() => {- H.restore();- cy.signInAsNormalUser();- });-- it("Should show the help text popover when typing a multi-line expression (metabase#56152)", () => {- H.openPeopleTable({ mode: "notebook" });- H.addCustomColumn();- H.CustomExpressionEditor.type(dedent`- datetimeDiff(- [Created At],- `);-- H.CustomExpressionEditor.helpText().should("be.visible");- });-});--describe("issue 56596", () => {- beforeEach(() => {- H.restore();- cy.signInAsNormalUser();-- const questionDetails = {- query: {- "source-table": PRODUCTS_ID,- fields: [["field", PRODUCTS.ID, null]],- limit: 1,- },- };-- H.createQuestion(questionDetails, { visitQuestion: true });-- H.openNotebook();- });-- it("should not remove backslashes from escaped characters (metabase#56596)", () => {- H.addCustomColumn();- const expr = dedent`- regexExtract([Vendor], "\\s.*")- `;- H.enterCustomColumnDetails({- formula: expr,- name: "Last name",- });- H.CustomExpressionEditor.format();- H.CustomExpressionEditor.value().should("equal", expr);- H.expressionEditorWidget().button("Done").click();-- H.getNotebookStep("expression").findByText("Last name").click();- H.CustomExpressionEditor.value().should("equal", expr);- H.expressionEditorWidget().button("Cancel").click();-- H.visualize();- H.assertTableData({- columns: ["ID", "Last name"],- firstRows: [["1", " Casper and Hilll"]],- });- });-});--describe("issue 55300", () => {- describe("fields", () => {- beforeEach(() => {- H.restore();- cy.signInAsNormalUser();-- const questionDetails = {- query: {- "source-table": PRODUCTS_ID,- fields: [["field", PRODUCTS.ID, null]],- expressions: {- now: ["field", PRODUCTS.CREATED_AT, null],- Count: ["+", 1, 1],- },- },- };-- H.createQuestion(questionDetails, { visitQuestion: true });- H.openNotebook();- });-- it("should be possible to disambiguate between fields and no-argument functions (metabase#55300)", () => {- H.getNotebookStep("expression").icon("add").click();- H.CustomExpressionEditor.type("now() > now");-- cy.log("Move cursor over now");- H.CustomExpressionEditor.type("{leftarrow}");- H.CustomExpressionEditor.helpTextHeader().should("not.exist");-- cy.log("Move cursor over now()");- H.CustomExpressionEditor.type("{home}");- H.CustomExpressionEditor.helpTextHeader().should("contain", "now()");-- H.CustomExpressionEditor.format();- H.CustomExpressionEditor.value().should("equal", "now() > [now]");- });-- it("should be possible to disambiguate between fields and no-argument aggregations (metabase#55300)", () => {- H.summarize({ mode: "notebook" });- H.popover().findByText("Custom Expression").click();-- H.CustomExpressionEditor.type("Count() + Sum(Count)");-- cy.log("Move cursor over Count");- H.CustomExpressionEditor.type("{leftarrow}".repeat(2));- H.CustomExpressionEditor.helpTextHeader().should("contain", "Sum");-- cy.log("Move cursor over Count()");- H.CustomExpressionEditor.type("{home}");- H.CustomExpressionEditor.helpTextHeader().should("contain", "Count()");-- H.CustomExpressionEditor.format();- H.CustomExpressionEditor.value().should(- "equal",- "Count() + Sum([Count])",- );- });- });-- describe("segments", () => {- beforeEach(() => {- H.restore();- cy.signInAsAdmin();-- H.createSegment({- name: "now",- table_id: ORDERS_ID,- definition: {- "source-table": ORDERS_ID,- aggregation: [["count"]],- filter: ["<", ["field", ORDERS.TOTAL, null], 100],- },- });-- H.createSegment({- name: "Count",- table_id: ORDERS_ID,- definition: {- "source-table": ORDERS_ID,- aggregation: [["count"]],- filter: ["<", ["field", ORDERS.TOTAL, null], 100],- },- });-- const questionDetails = {- query: {- "source-table": ORDERS_ID,- },- };-- H.createQuestion(questionDetails, { visitQuestion: true });- H.openNotebook();- });-- it("should be possible to disambiguate between segments and no-argument functions (metabase#55300)", () => {- H.addCustomColumn();-- H.CustomExpressionEditor.type("case(now, now(), [Created At])");-- cy.log("Move cursor over now()");- H.CustomExpressionEditor.type("{leftarrow}".repeat(17));- H.CustomExpressionEditor.helpTextHeader().should("contain", "now()");-- cy.log("Move cursor over now");- H.CustomExpressionEditor.type("{leftarrow}".repeat(7), { focus: false });- H.CustomExpressionEditor.helpTextHeader().should("contain", "case");-- H.CustomExpressionEditor.format();- H.CustomExpressionEditor.value().should(- "equal",- "case([now], now(), [Created At])",- );- });-- it("should be possible to disambiguate between segments and no-argument aggregations (metabase#55300)", () => {- H.summarize({ mode: "notebook" });- H.popover().findByText("Custom Expression").click();-- H.CustomExpressionEditor.type("Sum(case(Count, Count(), 0))");-- cy.log("Move cursor over now()");- H.CustomExpressionEditor.type("{leftarrow}".repeat(7));- H.CustomExpressionEditor.helpTextHeader().should("contain", "Count()");-- cy.log("Move cursor over now");- H.CustomExpressionEditor.type("{leftarrow}".repeat(18));- H.CustomExpressionEditor.helpTextHeader().should("contain", "case");-- H.CustomExpressionEditor.format();- H.CustomExpressionEditor.value().should(- "equal",- "Sum(case([Count], Count(), 0))",- );- });- });-- describe("metrics", () => {- beforeEach(() => {- H.restore();- cy.signInAsAdmin();-- H.createQuestion({- name: "Count",- type: "metric",- description: "A metric",- query: {- "source-table": ORDERS_ID,- aggregation: [["count"]],- },- });-- const questionDetails = {- query: {- "source-table": ORDERS_ID,- },- };-- H.createQuestion(questionDetails, { visitQuestion: true });- H.openNotebook();- });-- it("should be possible to disambiguate between metrics and no-argument aggregations (metabase#55300)", () => {- H.summarize({ mode: "notebook" });- H.popover().findByText("Custom Expression").click();-- H.CustomExpressionEditor.type("Count + Count()");-- cy.log("Move cursor over Count()");- H.CustomExpressionEditor.type("{leftarrow}".repeat(5));- H.CustomExpressionEditor.helpTextHeader().should("contain", "Count()");-- cy.log("Move cursor over Count");- H.CustomExpressionEditor.type("{home}");- H.CustomExpressionEditor.helpTextHeader().should("not.exist");-- H.CustomExpressionEditor.format();- H.CustomExpressionEditor.value().should("equal", "[Count] + Count()");- });- });-});--describe("issue 55687", () => {- beforeEach(() => {- H.restore();- cy.signInAsNormalUser();-- const questionDetails = {- query: {- "source-table": PRODUCTS_ID,- limit: 1,- },- };-- H.createQuestion(questionDetails, { visitQuestion: true });-- H.openNotebook();- });-- function addExpression(name, expression) {- H.getNotebookStep("expression").icon("add").click();- H.enterCustomColumnDetails({- formula: expression,- name,- });- H.popover().button("Done").click();- }-- it("should allow passing stringly-typed expressions to is-empty and not-empty (metabase#55687)", () => {- H.addCustomColumn();- H.popover().button("Cancel").click();-- addExpression("isEmpty - title", "isEmpty([Title])");- addExpression("isEmpty - ltrim - title", "isEmpty(lTrim([Title]))");- addExpression("isEmpty - literal", "isEmpty('AAA')");- addExpression("isEmpty - ltrim - literal", "isEmpty(lTrim('AAA'))");-- addExpression("notEmpty - title", "notEmpty([Title])");- addExpression("notEmpty - ltrim - title", "notEmpty(lTrim([Title]))");- addExpression("notEmpty - literal", "notEmpty('AAA')");- addExpression("notEmpty - ltrim - literal", "notEmpty(lTrim('AAA'))");-- H.visualize();-- cy.findByTestId("query-visualization-root")- .findByText("There was a problem with your question")- .should("not.exist");- });-});--describe("issue 58371", { tags: "@skip" }, () => {- beforeEach(() => {- H.restore();- cy.signInAsAdmin();-- cy.request("PUT", `/api/field/${ORDERS.PRODUCT_ID}`, {- display_name: null,- });-- const baseQuestion = {- name: "Base Question",- query: {- "source-table": PRODUCTS_ID,- aggregation: [- [- "aggregation-options",- ["count-where", ["=", ["field", PRODUCTS.TITLE, null], "OK"]],- { "display-name": "Aggregation with Dash-in-name" },- ],- ],- breakout: [["field", PRODUCTS.ID, null]],- },- };-- H.createQuestion(baseQuestion, { wrapId: true }).then((questionId) => {- const questionDetails = {- query: {- "source-table": ORDERS_ID,- joins: [- {- fields: "all",- "source-table": `card__${questionId}`,- alias: "Other Question",- condition: [- "=",- ["field", ORDERS.PRODUCT_ID, null],- ["field", PRODUCTS.ID, { "join-alias": "Other Question" }],- ],- },- ],- expressions: {- Foo: [- "+",- 0,- [- "field",- "count_where",- {- "base-type": "type/Float",- "join-alias": "Other Question",- },- ],- ],- },- },- };-- H.createQuestion(questionDetails, { visitQuestion: true });- });-- H.openNotebook();- });-- it("should allow using names with a dash in them from joined tables (metabase#58371)", () => {- H.getNotebookStep("expression").findByText("Foo").click();- H.CustomExpressionEditor.value().should(- "eq",- "0 + [Other Question → Aggregation with Dash-in-name]",- );- });-});--describe("Issue 58230", () => {- beforeEach(() => {- H.restore();- cy.signInAsAdmin();- H.openOrdersTable({ mode: "notebook" });- });-- it("should display an error when using an aggregation function in a custom column (metabase#58230)", () => {- H.getNotebookStep("data").button("Custom column").click();- H.CustomExpressionEditor.type("Average([Total])");- H.popover().findByText(- "Aggregations like Average are not allowed when building a custom expression",- );- });-- it("should display an error when using an aggregation function in a custom filter (metabase#58230)", () => {- H.filter({ mode: "notebook" });- H.popover().findByText("Custom Expression").click();- H.CustomExpressionEditor.type("Average([Total])");- H.popover().findByText(- "Aggregations like Average are not allowed when building a custom filter",- );- });-- it("should not display an error when using an aggregation function in a custom aggregation (metabase#58230)", () => {- H.summarize({ mode: "notebook" });- H.popover().findByText("Custom Expression").click();- H.CustomExpressionEditor.type("Average([Total])");- H.CustomExpressionEditor.nameInput().type("Foo");- H.popover().button("Done").should("be.enabled");- });-});--describe("issue 57674", () => {- beforeEach(() => {- H.restore();- cy.signInAsNormalUser();- H.openOrdersTable({ mode: "notebook" });- });-- // TODO: re-enable this test once we have a fix for metabase#61264- it(- "should show an error when using a case or if expression with mismatched types (metabase#57674)",- { tags: "@skip" },- () => {- H.getNotebookStep("data").button("Custom column").click();-- H.CustomExpressionEditor.clear();- H.popover().findByText("Types are incompatible.").should("not.exist");-- H.CustomExpressionEditor.type(- 'case([Total] > 100, [Created At], "foo")',- {- allowFastSet: true,- },- ).blur();-- H.popover().findByText("Types are incompatible.").should("be.visible");- },- );-- it("should not show an error when using a case or if expression with compatible types (metabase#57674)", () => {- H.getNotebookStep("data").button("Custom column").click();-- H.CustomExpressionEditor.clear();- H.popover().findByText("Types are incompatible.").should("not.exist");-- H.CustomExpressionEditor.type('case([Total] > 100, "foo", "bar")', {- allowFastSet: true,- }).blur();-- H.popover().findByText("Types are incompatible.").should("not.exist");- });-});--describe("Issue 12938", () => {- beforeEach(() => {- H.restore();- cy.signInAsNormalUser();- H.openProductsTable({ mode: "notebook" });- });-- it("should be possible to concat number with string (metabase#12938)", () => {- H.addCustomColumn();- H.enterCustomColumnDetails({- formula: "concat(floor([Rating]), [Title])",- name: "MyCustom",- clickDone: true,- });-- H.visualize();- cy.get("main")- .findByText("There was a problem with your question")- .should("not.exist");- });-- it("should be possible to concat number with string (metabase#12938)", () => {- H.addCustomColumn();- H.enterCustomColumnDetails({- formula: 'concat(hour([Created At]), ":", minute([Created At]))',- name: "MyCustom",- clickDone: true,- });-- H.visualize();- cy.get("main")- .findByText("There was a problem with your question")- .should("not.exist");- });-});--describe("Issue 25189", () => {- beforeEach(() => {- H.restore();- cy.signInAsNormalUser();- });-- it("should be possible to use a custom column that just references a single column in filters in follow up question (metabase#25189)", () => {- H.createQuestion({- name: "Question with CCreated At",- query: {- "source-table": ORDERS_ID,- expressions: {- "CCreated At": [- "field",- ORDERS.CREATED_AT,- {- "base-type": "type/DateTime",- },- ],- },- },- }).then((res) => {- H.createQuestion(- {- query: {- "source-table": `card__${res.body.id}`,- },- },- { visitQuestion: true },- );- });- cy.findAllByTestId("header-cell")- .contains("CCreated At")- .should("be.visible");-- H.filter();- H.popover().within(() => {- cy.findAllByText("CCreated At").should("have.length", 1).first().click();- cy.findByText("Today").click();- });-- cy.findAllByTestId("header-cell")- .contains("CCreated At")- .should("be.visible");-- cy.get("main")- .findByText("There was a problem with your question")- .should("not.exist");- });-- it("should be possible to use a custom column that just references a single column in filters in follow up question, when the custom column has the same name as the column (metabase#25189)", () => {- H.createQuestion({- name: "Question with Created At",- query: {- "source-table": ORDERS_ID,- expressions: {- "Created At": [- "field",- ORDERS.CREATED_AT,- {- "base-type": "type/DateTime",- },- ],- },- },- }).then((res) => {- H.createQuestion(- {- query: {- "source-table": `card__${res.body.id}`,- },- },- { visitQuestion: true },- );- });- cy.findAllByTestId("header-cell")- .contains("Created At")- .should("be.visible");-- H.filter();- H.popover().within(() => {- cy.findAllByText("Created At").should("have.length", 2).first().click();- cy.findByText("Today").click();- });-- H.filter();- H.popover().within(() => {- cy.findAllByText("Created At").should("have.length", 2).last().click();- cy.findByText("Today").click();- });-- cy.findAllByTestId("header-cell")- .contains("Created At")- .should("be.visible");-- cy.get("main")- .findByText("There was a problem with your question")- .should("not.exist");- });-});--describe("Issue 26512", () => {- beforeEach(() => {- H.restore();- cy.signInAsAdmin();- H.openOrdersTable({ mode: "notebook" });- });-- const TEST_CASES = [- 'year("a string")',- 'month("a string")',- 'day("a string")',- 'hour("a string")',- 'minute("a string")',- 'datetimeAdd("a string", 1, "day")',- 'datetimeDiff("a string", 1, "day")',- "year(1)",- "month(42)",- "day(102)",- "hour(140)",- "minute(55)",- 'datetimeAdd(42, 1, "day")',- 'datetimeDiff(42, 1, "day")',- "year(true)",- "month(true)",- "day(true)",- "hour(true)",- "minute(true)",- 'datetimeAdd(true, 1, "day")',- 'datetimeDiff(true, 1, "day")',- ];-- it("should validate types for date/time functions (metabase#26512)", () => {- H.addCustomColumn();-- TEST_CASES.forEach((formula) => {- H.CustomExpressionEditor.clear()- .type(formula, { allowFastSet: true })- .blur();- H.popover().findByText("Types are incompatible.").should("be.visible");- });- });-});--describe("Issue 38498", { tags: "@external" }, () => {- beforeEach(() => {- H.restore("postgres-12");- cy.signInAsAdmin();-- H.startNewQuestion();- H.miniPicker().within(() => {- cy.findByText("QA Postgres12").click();- cy.findByText("Orders").click();- });- });-- it("should not be possible to use convertTimezone with an invalid timezone (metabse#38498)", () => {- H.addCustomColumn();- H.CustomExpressionEditor.type(- 'convertTimezone([Created At], "Asia/Ho_Chi_Mihn", "UTC")',- );- H.popover().findByText("Types are incompatible.").should("be.visible");- });-});--describe("issue 52451", () => {- beforeEach(() => {- H.restore();- cy.signInAsNormalUser();- });-- it("should be possible to use a custom expression in a join condition from the same stage in the LHS (metabase#52451)", () => {- H.openOrdersTable({ mode: "notebook" });- H.addCustomColumn();- H.enterCustomColumnDetails({- name: "Expr",- formula: "[ID] * 1000",- });- H.popover().button("Done").click();- H.join();- H.miniPicker().within(() => {- cy.findByText("Sample Database").click();- cy.findByText("Reviews").click();- });- H.popover().findByText("Expr").click();- H.popover().findByText("ID").click();- H.getNotebookStep("join").findByLabelText("Change join type").click();- H.popover().findByText("Inner join").click();- H.visualize();- H.assertQueryBuilderRowCount(1);- });-});--describe("issue 56602", () => {- const productsModelDetails = {- name: "M1",- type: "model",- query: {- "source-table": PRODUCTS_ID,- },- };-- const ordersModelDetails = {- name: "M2",- type: "model",- query: {- "source-table": ORDERS_ID,- },- };-- const expressionName = "awesome stuff";-- beforeEach(() => {- H.restore();- cy.signInAsNormalUser();- });-- it("should allow to use expressions when joining models (metabase#56602)", () => {- H.createQuestion(productsModelDetails);- H.createQuestion(ordersModelDetails);- H.startNewQuestion();- H.miniPicker().within(() => {- cy.realType(productsModelDetails.name);- cy.findByText(productsModelDetails.name).click();- });- H.join();- H.miniPicker().within(() => {- cy.realType(ordersModelDetails.name);- cy.findByText(ordersModelDetails.name).click();- });- H.addCustomColumn();- H.enterCustomColumnDetails({- name: expressionName,- formula: `coalesce([User -> Birth Date], [${ordersModelDetails.name} -> Created At])`,- });- H.popover().button("Done").click();- H.visualize();- H.tableInteractive().should("be.visible");- H.tableInteractiveHeader().should("contain", expressionName);- });-});--describe("issue 61010", () => {- const CUSTOM_COLUMN_NAME = "Foo";- const AGGREGATION_NAME = "New count";-- beforeEach(() => {- H.restore();- cy.signInAsNormalUser();-- H.createQuestion(- {- query: {- "source-table": ORDERS_ID,- expressions: {- [CUSTOM_COLUMN_NAME]: ["+", 1, 2],- },- aggregation: [- [- "aggregation-options",- ["+", ["count"], 1],- {- name: AGGREGATION_NAME,- "display-name": AGGREGATION_NAME,- },- ],- ],- },- },- { visitQuestion: true },- );-- H.openNotebook();- });-- it("should not be possible to reference a custom expression in itself (metabase#61010)", () => {- H.getNotebookStep("expression").findByText(CUSTOM_COLUMN_NAME).click();- H.CustomExpressionEditor.clear().type("[Fo");- H.CustomExpressionEditor.completions()- .findByText("Foo")- .should("not.exist");-- H.CustomExpressionEditor.clear().type("[Foo]");- H.popover().findByText("Unknown column: Foo").should("be.visible");- });-- it("should not be possible to reference an aggregation in itself(metabase#61010)", () => {- H.getNotebookStep("summarize").findByText(AGGREGATION_NAME).click();- H.CustomExpressionEditor.clear().type("[New cou");- H.CustomExpressionEditor.completions()- .findByText("New count")- .should("not.exist");-- H.CustomExpressionEditor.clear().type("[New count]");- H.popover()- .findByText("Unknown Aggregation, Measure or Metric: New count")- .should("be.visible");- });-});--describe("issue 62987", () => {- beforeEach(() => {- H.restore();- cy.signInAsNormalUser();- H.createQuestion(- {- query: { "source-table": ORDERS_ID },- },- { visitQuestion: true },- );-- H.openNotebook();- H.summarize({ mode: "notebook" });- H.popover().findByText("Custom Expression").click();- });-- it("should be possible to complete non-aggregation functions in custom aggregation (metabase#62987)", () => {- H.CustomExpressionEditor.type("Coun");- H.CustomExpressionEditor.completion("CountIf").should("be.visible").click();-- H.CustomExpressionEditor.type("notEm", { focus: false });- H.CustomExpressionEditor.completion("notEmpty")- .should("be.visible")- .click();-- H.CustomExpressionEditor.value().should("eq", "CountIf(notEmpty(column))");-- H.expressionEditorWidget().button("Function browser").click();- H.CustomExpressionEditor.functionBrowser().within(() => {- cy.findByText("CountIf").should("be.visible");- cy.findByText("notEmpty").should("be.visible");- });- });-});--describe("issue 63180", () => {- beforeEach(() => {- H.restore();- cy.signInAsNormalUser();- H.createQuestion(- {- query: {- "source-table": ORDERS_ID,- expressions: {- Foo: ["+", 1, 2],- },- },- },- { visitQuestion: true },- );-- H.openNotebook();- });-- it("should not be possible to close the custom expression editor when creating a new expression from a combine or extract shortcut (metabase#63180)", () => {- function testCombineColumns() {- H.getNotebookStep("expression").icon("add").click();- H.expressionEditorWidget().within(() => {- cy.findByText("Combine columns").click();- cy.button("Done").scrollIntoView().click();- });-- cy.log("clicking outside the editor should not close it");- H.getNotebookStep("data").click();- H.expressionEditorWidget().should("be.visible");- H.modal().should("not.exist");-- cy.log("clearing the expression should allow clicking outside to work");- H.CustomExpressionEditor.clear();- H.getNotebookStep("data").click();- H.expressionEditorWidget().should("not.exist");- H.modal().should("not.exist");- }-- function testExtractColumns() {- H.getNotebookStep("expression").icon("add").click();- H.expressionEditorWidget().within(() => {- cy.findByText("Extract columns").click();- cy.findByText("Email").click();- cy.findByText("Domain").click();- });-- cy.log("clicking outside the editor should not close it");- H.getNotebookStep("data").click();- H.expressionEditorWidget().should("be.visible");- H.modal().should("not.exist");-- cy.log("clearing the expression should allow clicking outside to work");- H.CustomExpressionEditor.clear();- H.getNotebookStep("data").click();- H.expressionEditorWidget().should("not.exist");- H.modal().should("not.exist");- }-- testCombineColumns();- testExtractColumns();- });-});diff --git a/e2e/test/scenarios/custom-column/custom-column-reproductions-2.cy.spec.js b/e2e/test/scenarios/custom-column/custom-column-reproductions-2.cy.spec.jsnew file mode 100644index 00000000000..22e9cde586e--- /dev/null+++ b/e2e/test/scenarios/custom-column/custom-column-reproductions-2.cy.spec.js@@ -0,0 +1,1051 @@+const { H } = cy;+import { dedent } from "ts-dedent";++import { SAMPLE_DATABASE } from "e2e/support/cypress_sample_database";++const { PRODUCTS, PRODUCTS_ID, ORDERS, ORDERS_ID } = SAMPLE_DATABASE;++describe("issue 54638", () => {+ beforeEach(() => {+ H.restore();+ cy.signInAsNormalUser();+ H.openOrdersTable({ mode: "notebook" });+ H.addCustomColumn();+ });++ it("should be possible to click documentation links in the expression editor help text popover (metabase#54638)", () => {+ H.CustomExpressionEditor.type("case(");+ H.CustomExpressionEditor.helpText().within(() => {+ cy.findByText("Learn more")+ .scrollIntoView()+ .should("be.visible")+ .then(($a) => {+ expect($a).to.have.attr("target", "_blank");+ // Update attr to open in same tab, since Cypress does not support+ // testing in multiple tabs.+ $a.attr("target", "_self");+ })+ .click();+ cy.url().should(+ "equal",+ "https://www.metabase.com/docs/latest/questions/query-builder/expressions/case.html",+ );+ });+ });+});++describe("issue #54722", () => {+ beforeEach(() => {+ H.restore();+ cy.signInAsNormalUser();+ H.openOrdersTable({ mode: "notebook" });+ });++ it("should focus the editor when opening it (metabase#54722)", () => {+ H.addCustomColumn();+ cy.focused().should("have.attr", "role", "textbox");+ H.expressionEditorWidget().button("Cancel").click();++ H.filter({ mode: "notebook" });+ H.popover().findByText("Custom Expression").click();+ cy.focused().should("have.attr", "role", "textbox");+ H.expressionEditorWidget().button("Cancel").click();++ H.summarize({ mode: "notebook" });+ H.popover().findByText("Custom Expression").click();+ cy.focused().should("have.attr", "role", "textbox");+ H.expressionEditorWidget().button("Cancel").click();+ });+});++describe("issue #31964", () => {+ beforeEach(() => {+ H.restore();+ cy.signInAsNormalUser();+ H.openOrdersTable({ mode: "notebook" });+ });++ it("should focus the editor when opening it (metabase#54722)", () => {+ H.addCustomColumn();+ H.CustomExpressionEditor.type('case([Product -> Category] = "Widget", 1,');+ cy.realPress("Enter");+ H.CustomExpressionEditor.type("[Product -> Categ", { focus: false });+ cy.realPress("Tab");+ H.CustomExpressionEditor.value().should(+ "equal",+ dedent`+ case([Product → Category] = "Widget", 1,+ [Product → Category])+ `,+ );+ });+});++describe("issue #55686", () => {+ beforeEach(() => {+ H.restore();+ cy.signInAsNormalUser();+ H.openOrdersTable({ mode: "notebook" });+ });++ it("should show suggestions for functions even when the current token is an operator (metabase#55686)", () => {+ H.addCustomColumn();+ H.CustomExpressionEditor.type("not");++ H.CustomExpressionEditor.completion("notNull").should("be.visible");+ H.CustomExpressionEditor.completion("notEmpty").should("be.visible");+ });+});++describe("issue #55940", () => {+ beforeEach(() => {+ H.restore();+ cy.signInAsNormalUser();+ H.openOrdersTable({ mode: "notebook" });+ });++ it("should show the correct example for Offset (metabase#55940)", () => {+ H.summarize({ mode: "notebook" });+ H.popover().findByText("Custom Expression").click();++ H.CustomExpressionEditor.type("Offset(");+ H.CustomExpressionEditor.helpText()+ .should("be.visible")+ .should("contain", "Offset(Sum([Total]), -1)");+ });+});++describe("issue #55984", () => {+ beforeEach(() => {+ H.restore();+ cy.signInAsNormalUser();+ H.openOrdersTable({ mode: "notebook" });+ });++ it("should not overflow the suggestion tooltip when a suggestion name is too long (metabase#55984)", () => {+ H.addCustomColumn();+ H.enterCustomColumnDetails({+ formula: "[Total]",+ name: "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt",+ });+ cy.button("Done").click();++ H.summarize({ mode: "notebook" });+ H.popover().findByText("Custom Expression").click();+ H.CustomExpressionEditor.type("[lo");+ H.CustomExpressionEditor.completions().should(($el) => {+ expect(H.isScrollableHorizontally($el[0])).to.be.false;+ });+ });++ it("should not overflow the suggestion tooltip when a suggestion name is too long and has no spaces (metabase#55984)", () => {+ H.addCustomColumn();+ H.enterCustomColumnDetails({+ formula: "[Total]",+ name: "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt".replaceAll(+ " ",+ "_",+ ),+ });+ cy.button("Done").click();++ H.summarize({ mode: "notebook" });+ H.popover().findByText("Custom Expression").click();+ H.CustomExpressionEditor.type("[lo");+ H.CustomExpressionEditor.completions().should(($el) => {+ expect(H.isScrollableHorizontally($el[0])).to.be.false;+ });+ });+});++describe("issue 55622", () => {+ beforeEach(() => {+ H.restore();+ cy.signInAsNormalUser();+ });++ it("should allow to mix regular functions with aggregation functions (metabase#55622)", () => {+ H.openPeopleTable({ mode: "notebook" });+ H.getNotebookStep("data").button("Summarize").click();+ H.popover().findByText("Custom Expression").click();+ H.enterCustomColumnDetails({+ formula: 'datetimeDiff(Max([Created At]), max([Birth Date]), "minute")',+ name: "Aggregation",+ });+ H.popover().button("Done").click();+ H.visualize();+ H.assertQueryBuilderRowCount(1);+ });+});++describe("issue 56152", () => {+ beforeEach(() => {+ H.restore();+ cy.signInAsNormalUser();+ });++ it("Should show the help text popover when typing a multi-line expression (metabase#56152)", () => {+ H.openPeopleTable({ mode: "notebook" });+ H.addCustomColumn();+ H.CustomExpressionEditor.type(dedent`+ datetimeDiff(+ [Created At],+ `);++ H.CustomExpressionEditor.helpText().should("be.visible");+ });+});++describe("issue 56596", () => {+ beforeEach(() => {+ H.restore();+ cy.signInAsNormalUser();++ const questionDetails = {+ query: {+ "source-table": PRODUCTS_ID,+ fields: [["field", PRODUCTS.ID, null]],+ limit: 1,+ },+ };++ H.createQuestion(questionDetails, { visitQuestion: true });++ H.openNotebook();+ });++ it("should not remove backslashes from escaped characters (metabase#56596)", () => {+ H.addCustomColumn();+ const expr = dedent`+ regexExtract([Vendor], "\\s.*")+ `;+ H.enterCustomColumnDetails({+ formula: expr,+ name: "Last name",+ });+ H.CustomExpressionEditor.format();+ H.CustomExpressionEditor.value().should("equal", expr);+ H.expressionEditorWidget().button("Done").click();++ H.getNotebookStep("expression").findByText("Last name").click();+ H.CustomExpressionEditor.value().should("equal", expr);+ H.expressionEditorWidget().button("Cancel").click();++ H.visualize();+ H.assertTableData({+ columns: ["ID", "Last name"],+ firstRows: [["1", " Casper and Hilll"]],+ });+ });+});++describe("issue 55300", () => {+ describe("fields", () => {+ beforeEach(() => {+ H.restore();+ cy.signInAsNormalUser();++ const questionDetails = {+ query: {+ "source-table": PRODUCTS_ID,+ fields: [["field", PRODUCTS.ID, null]],+ expressions: {+ now: ["field", PRODUCTS.CREATED_AT, null],+ Count: ["+", 1, 1],+ },+ },+ };++ H.createQuestion(questionDetails, { visitQuestion: true });+ H.openNotebook();+ });++ it("should be possible to disambiguate between fields and no-argument functions (metabase#55300)", () => {+ H.getNotebookStep("expression").icon("add").click();+ H.CustomExpressionEditor.type("now() > now");++ cy.log("Move cursor over now");+ H.CustomExpressionEditor.type("{leftarrow}");+ H.CustomExpressionEditor.helpTextHeader().should("not.exist");++ cy.log("Move cursor over now()");+ H.CustomExpressionEditor.type("{home}");+ H.CustomExpressionEditor.helpTextHeader().should("contain", "now()");++ H.CustomExpressionEditor.format();+ H.CustomExpressionEditor.value().should("equal", "now() > [now]");+ });++ it("should be possible to disambiguate between fields and no-argument aggregations (metabase#55300)", () => {+ H.summarize({ mode: "notebook" });+ H.popover().findByText("Custom Expression").click();++ H.CustomExpressionEditor.type("Count() + Sum(Count)");++ cy.log("Move cursor over Count");+ H.CustomExpressionEditor.type("{leftarrow}".repeat(2));+ H.CustomExpressionEditor.helpTextHeader().should("contain", "Sum");++ cy.log("Move cursor over Count()");+ H.CustomExpressionEditor.type("{home}");+ H.CustomExpressionEditor.helpTextHeader().should("contain", "Count()");++ H.CustomExpressionEditor.format();+ H.CustomExpressionEditor.value().should(+ "equal",+ "Count() + Sum([Count])",+ );+ });+ });++ describe("segments", () => {+ beforeEach(() => {+ H.restore();+ cy.signInAsAdmin();++ H.createSegment({+ name: "now",+ table_id: ORDERS_ID,+ definition: {+ "source-table": ORDERS_ID,+ aggregation: [["count"]],+ filter: ["<", ["field", ORDERS.TOTAL, null], 100],+ },+ });++ H.createSegment({+ name: "Count",+ table_id: ORDERS_ID,+ definition: {+ "source-table": ORDERS_ID,+ aggregation: [["count"]],+ filter: ["<", ["field", ORDERS.TOTAL, null], 100],+ },+ });++ const questionDetails = {+ query: {+ "source-table": ORDERS_ID,+ },+ };++ H.createQuestion(questionDetails, { visitQuestion: true });+ H.openNotebook();+ });++ it("should be possible to disambiguate between segments and no-argument functions (metabase#55300)", () => {+ H.addCustomColumn();++ H.CustomExpressionEditor.type("case(now, now(), [Created At])");++ cy.log("Move cursor over now()");+ H.CustomExpressionEditor.type("{leftarrow}".repeat(17));+ H.CustomExpressionEditor.helpTextHeader().should("contain", "now()");++ cy.log("Move cursor over now");+ H.CustomExpressionEditor.type("{leftarrow}".repeat(7), { focus: false });+ H.CustomExpressionEditor.helpTextHeader().should("contain", "case");++ H.CustomExpressionEditor.format();+ H.CustomExpressionEditor.value().should(+ "equal",+ "case([now], now(), [Created At])",+ );+ });++ it("should be possible to disambiguate between segments and no-argument aggregations (metabase#55300)", () => {+ H.summarize({ mode: "notebook" });+ H.popover().findByText("Custom Expression").click();++ H.CustomExpressionEditor.type("Sum(case(Count, Count(), 0))");++ cy.log("Move cursor over now()");+ H.CustomExpressionEditor.type("{leftarrow}".repeat(7));+ H.CustomExpressionEditor.helpTextHeader().should("contain", "Count()");++ cy.log("Move cursor over now");+ H.CustomExpressionEditor.type("{leftarrow}".repeat(18));+ H.CustomExpressionEditor.helpTextHeader().should("contain", "case");++ H.CustomExpressionEditor.format();+ H.CustomExpressionEditor.value().should(+ "equal",+ "Sum(case([Count], Count(), 0))",+ );+ });+ });++ describe("metrics", () => {+ beforeEach(() => {+ H.restore();+ cy.signInAsAdmin();++ H.createQuestion({+ name: "Count",+ type: "metric",+ description: "A metric",+ query: {+ "source-table": ORDERS_ID,+ aggregation: [["count"]],+ },+ });++ const questionDetails = {+ query: {+ "source-table": ORDERS_ID,+ },+ };++ H.createQuestion(questionDetails, { visitQuestion: true });+ H.openNotebook();+ });++ it("should be possible to disambiguate between metrics and no-argument aggregations (metabase#55300)", () => {+ H.summarize({ mode: "notebook" });+ H.popover().findByText("Custom Expression").click();++ H.CustomExpressionEditor.type("Count + Count()");++ cy.log("Move cursor over Count()");+ H.CustomExpressionEditor.type("{leftarrow}".repeat(5));+ H.CustomExpressionEditor.helpTextHeader().should("contain", "Count()");++ cy.log("Move cursor over Count");+ H.CustomExpressionEditor.type("{home}");+ H.CustomExpressionEditor.helpTextHeader().should("not.exist");++ H.CustomExpressionEditor.format();+ H.CustomExpressionEditor.value().should("equal", "[Count] + Count()");+ });+ });+});++describe("issue 55687", () => {+ beforeEach(() => {+ H.restore();+ cy.signInAsNormalUser();++ const questionDetails = {+ query: {+ "source-table": PRODUCTS_ID,+ limit: 1,+ },+ };++ H.createQuestion(questionDetails, { visitQuestion: true });++ H.openNotebook();+ });++ function addExpression(name, expression) {+ H.getNotebookStep("expression").icon("add").click();+ H.enterCustomColumnDetails({+ formula: expression,+ name,+ });+ H.popover().button("Done").click();+ }++ it("should allow passing stringly-typed expressions to is-empty and not-empty (metabase#55687)", () => {+ H.addCustomColumn();+ H.popover().button("Cancel").click();++ addExpression("isEmpty - title", "isEmpty([Title])");+ addExpression("isEmpty - ltrim - title", "isEmpty(lTrim([Title]))");+ addExpression("isEmpty - literal", "isEmpty('AAA')");+ addExpression("isEmpty - ltrim - literal", "isEmpty(lTrim('AAA'))");++ addExpression("notEmpty - title", "notEmpty([Title])");+ addExpression("notEmpty - ltrim - title", "notEmpty(lTrim([Title]))");+ addExpression("notEmpty - literal", "notEmpty('AAA')");+ addExpression("notEmpty - ltrim - literal", "notEmpty(lTrim('AAA'))");++ H.visualize();++ cy.findByTestId("query-visualization-root")+ .findByText("There was a problem with your question")+ .should("not.exist");+ });+});++describe("issue 58371", { tags: "@skip" }, () => {+ beforeEach(() => {+ H.restore();+ cy.signInAsAdmin();++ cy.request("PUT", `/api/field/${ORDERS.PRODUCT_ID}`, {+ display_name: null,+ });++ const baseQuestion = {+ name: "Base Question",+ query: {+ "source-table": PRODUCTS_ID,+ aggregation: [+ [+ "aggregation-options",+ ["count-where", ["=", ["field", PRODUCTS.TITLE, null], "OK"]],+ { "display-name": "Aggregation with Dash-in-name" },+ ],+ ],+ breakout: [["field", PRODUCTS.ID, null]],+ },+ };++ H.createQuestion(baseQuestion, { wrapId: true }).then((questionId) => {+ const questionDetails = {+ query: {+ "source-table": ORDERS_ID,+ joins: [+ {+ fields: "all",+ "source-table": `card__${questionId}`,+ alias: "Other Question",+ condition: [+ "=",+ ["field", ORDERS.PRODUCT_ID, null],+ ["field", PRODUCTS.ID, { "join-alias": "Other Question" }],+ ],+ },+ ],+ expressions: {+ Foo: [+ "+",+ 0,+ [+ "field",+ "count_where",+ {+ "base-type": "type/Float",+ "join-alias": "Other Question",+ },+ ],+ ],+ },+ },+ };++ H.createQuestion(questionDetails, { visitQuestion: true });+ });++ H.openNotebook();+ });++ it("should allow using names with a dash in them from joined tables (metabase#58371)", () => {+ H.getNotebookStep("expression").findByText("Foo").click();+ H.CustomExpressionEditor.value().should(+ "eq",+ "0 + [Other Question → Aggregation with Dash-in-name]",+ );+ });+});++describe("Issue 58230", () => {+ beforeEach(() => {+ H.restore();+ cy.signInAsAdmin();+ H.openOrdersTable({ mode: "notebook" });+ });++ it("should display an error when using an aggregation function in a custom column (metabase#58230)", () => {+ H.getNotebookStep("data").button("Custom column").click();+ H.CustomExpressionEditor.type("Average([Total])");+ H.popover().findByText(+ "Aggregations like Average are not allowed when building a custom expression",+ );+ });++ it("should display an error when using an aggregation function in a custom filter (metabase#58230)", () => {+ H.filter({ mode: "notebook" });+ H.popover().findByText("Custom Expression").click();+ H.CustomExpressionEditor.type("Average([Total])");+ H.popover().findByText(+ "Aggregations like Average are not allowed when building a custom filter",+ );+ });++ it("should not display an error when using an aggregation function in a custom aggregation (metabase#58230)", () => {+ H.summarize({ mode: "notebook" });+ H.popover().findByText("Custom Expression").click();+ H.CustomExpressionEditor.type("Average([Total])");+ H.CustomExpressionEditor.nameInput().type("Foo");+ H.popover().button("Done").should("be.enabled");+ });+});++describe("issue 57674", () => {+ beforeEach(() => {+ H.restore();+ cy.signInAsNormalUser();+ H.openOrdersTable({ mode: "notebook" });+ });++ // TODO: re-enable this test once we have a fix for metabase#61264+ it(+ "should show an error when using a case or if expression with mismatched types (metabase#57674)",+ { tags: "@skip" },+ () => {+ H.getNotebookStep("data").button("Custom column").click();++ H.CustomExpressionEditor.clear();+ H.popover().findByText("Types are incompatible.").should("not.exist");++ H.CustomExpressionEditor.type(+ 'case([Total] > 100, [Created At], "foo")',+ {+ allowFastSet: true,+ },+ ).blur();++ H.popover().findByText("Types are incompatible.").should("be.visible");+ },+ );++ it("should not show an error when using a case or if expression with compatible types (metabase#57674)", () => {+ H.getNotebookStep("data").button("Custom column").click();++ H.CustomExpressionEditor.clear();+ H.popover().findByText("Types are incompatible.").should("not.exist");++ H.CustomExpressionEditor.type('case([Total] > 100, "foo", "bar")', {+ allowFastSet: true,+ }).blur();++ H.popover().findByText("Types are incompatible.").should("not.exist");+ });+});++describe("Issue 12938", () => {+ beforeEach(() => {+ H.restore();+ cy.signInAsNormalUser();+ H.openProductsTable({ mode: "notebook" });+ });++ it("should be possible to concat number with string (metabase#12938)", () => {+ H.addCustomColumn();+ H.enterCustomColumnDetails({+ formula: "concat(floor([Rating]), [Title])",+ name: "MyCustom",+ clickDone: true,+ });++ H.visualize();+ cy.get("main")+ .findByText("There was a problem with your question")+ .should("not.exist");+ });++ it("should be possible to concat number with string (metabase#12938)", () => {+ H.addCustomColumn();+ H.enterCustomColumnDetails({+ formula: 'concat(hour([Created At]), ":", minute([Created At]))',+ name: "MyCustom",+ clickDone: true,+ });++ H.visualize();+ cy.get("main")+ .findByText("There was a problem with your question")+ .should("not.exist");+ });+});++describe("Issue 25189", () => {+ beforeEach(() => {+ H.restore();+ cy.signInAsNormalUser();+ });++ it("should be possible to use a custom column that just references a single column in filters in follow up question (metabase#25189)", () => {+ H.createQuestion({+ name: "Question with CCreated At",+ query: {+ "source-table": ORDERS_ID,+ expressions: {+ "CCreated At": [+ "field",+ ORDERS.CREATED_AT,+ {+ "base-type": "type/DateTime",+ },+ ],+ },+ },+ }).then((res) => {+ H.createQuestion(+ {+ query: {+ "source-table": `card__${res.body.id}`,+ },+ },+ { visitQuestion: true },+ );+ });+ cy.findAllByTestId("header-cell")+ .contains("CCreated At")+ .should("be.visible");++ H.filter();+ H.popover().within(() => {+ cy.findAllByText("CCreated At").should("have.length", 1).first().click();+ cy.findByText("Today").click();+ });++ cy.findAllByTestId("header-cell")+ .contains("CCreated At")+ .should("be.visible");++ cy.get("main")+ .findByText("There was a problem with your question")+ .should("not.exist");+ });++ it("should be possible to use a custom column that just references a single column in filters in follow up question, when the custom column has the same name as the column (metabase#25189)", () => {+ H.createQuestion({+ name: "Question with Created At",+ query: {+ "source-table": ORDERS_ID,+ expressions: {+ "Created At": [+ "field",+ ORDERS.CREATED_AT,+ {+ "base-type": "type/DateTime",+ },+ ],+ },+ },+ }).then((res) => {+ H.createQuestion(+ {+ query: {+ "source-table": `card__${res.body.id}`,+ },+ },+ { visitQuestion: true },+ );+ });+ cy.findAllByTestId("header-cell")+ .contains("Created At")+ .should("be.visible");++ H.filter();+ H.popover().within(() => {+ cy.findAllByText("Created At").should("have.length", 2).first().click();+ cy.findByText("Today").click();+ });++ H.filter();+ H.popover().within(() => {+ cy.findAllByText("Created At").should("have.length", 2).last().click();+ cy.findByText("Today").click();+ });++ cy.findAllByTestId("header-cell")+ .contains("Created At")+ .should("be.visible");++ cy.get("main")+ .findByText("There was a problem with your question")+ .should("not.exist");+ });+});++describe("Issue 26512", () => {+ beforeEach(() => {+ H.restore();+ cy.signInAsAdmin();+ H.openOrdersTable({ mode: "notebook" });+ });++ const TEST_CASES = [+ 'year("a string")',+ 'month("a string")',+ 'day("a string")',+ 'hour("a string")',+ 'minute("a string")',+ 'datetimeAdd("a string", 1, "day")',+ 'datetimeDiff("a string", 1, "day")',+ "year(1)",+ "month(42)",+ "day(102)",+ "hour(140)",+ "minute(55)",+ 'datetimeAdd(42, 1, "day")',+ 'datetimeDiff(42, 1, "day")',+ "year(true)",+ "month(true)",+ "day(true)",+ "hour(true)",+ "minute(true)",+ 'datetimeAdd(true, 1, "day")',+ 'datetimeDiff(true, 1, "day")',+ ];++ it("should validate types for date/time functions (metabase#26512)", () => {+ H.addCustomColumn();++ TEST_CASES.forEach((formula) => {+ H.CustomExpressionEditor.clear()+ .type(formula, { allowFastSet: true })+ .blur();+ H.popover().findByText("Types are incompatible.").should("be.visible");+ });+ });+});++describe("Issue 38498", { tags: "@external" }, () => {+ beforeEach(() => {+ H.restore("postgres-12");+ cy.signInAsAdmin();++ H.startNewQuestion();+ H.miniPicker().within(() => {+ cy.findByText("QA Postgres12").click();+ cy.findByText("Orders").click();+ });+ });++ it("should not be possible to use convertTimezone with an invalid timezone (metabse#38498)", () => {+ H.addCustomColumn();+ H.CustomExpressionEditor.type(+ 'convertTimezone([Created At], "Asia/Ho_Chi_Mihn", "UTC")',+ );+ H.popover().findByText("Types are incompatible.").should("be.visible");+ });+});++describe("issue 52451", () => {+ beforeEach(() => {+ H.restore();+ cy.signInAsNormalUser();+ });++ it("should be possible to use a custom expression in a join condition from the same stage in the LHS (metabase#52451)", () => {+ H.openOrdersTable({ mode: "notebook" });+ H.addCustomColumn();+ H.enterCustomColumnDetails({+ name: "Expr",+ formula: "[ID] * 1000",+ });+ H.popover().button("Done").click();+ H.join();+ H.miniPicker().within(() => {+ cy.findByText("Sample Database").click();+ cy.findByText("Reviews").click();+ });+ H.popover().findByText("Expr").click();+ H.popover().findByText("ID").click();+ H.getNotebookStep("join").findByLabelText("Change join type").click();+ H.popover().findByText("Inner join").click();+ H.visualize();+ H.assertQueryBuilderRowCount(1);+ });+});++describe("issue 56602", () => {+ const productsModelDetails = {+ name: "M1",+ type: "model",+ query: {+ "source-table": PRODUCTS_ID,+ },+ };++ const ordersModelDetails = {+ name: "M2",+ type: "model",+ query: {+ "source-table": ORDERS_ID,+ },+ };++ const expressionName = "awesome stuff";++ beforeEach(() => {+ H.restore();+ cy.signInAsNormalUser();+ });++ it("should allow to use expressions when joining models (metabase#56602)", () => {+ H.createQuestion(productsModelDetails);+ H.createQuestion(ordersModelDetails);+ H.startNewQuestion();+ H.miniPicker().within(() => {+ cy.realType(productsModelDetails.name);+ cy.findByText(productsModelDetails.name).click();+ });+ H.join();+ H.miniPicker().within(() => {+ cy.realType(ordersModelDetails.name);+ cy.findByText(ordersModelDetails.name).click();+ });+ H.addCustomColumn();+ H.enterCustomColumnDetails({+ name: expressionName,+ formula: `coalesce([User -> Birth Date], [${ordersModelDetails.name} -> Created At])`,+ });+ H.popover().button("Done").click();+ H.visualize();+ H.tableInteractive().should("be.visible");+ H.tableInteractiveHeader().should("contain", expressionName);+ });+});++describe("issue 61010", () => {+ const CUSTOM_COLUMN_NAME = "Foo";+ const AGGREGATION_NAME = "New count";++ beforeEach(() => {+ H.restore();+ cy.signInAsNormalUser();++ H.createQuestion(+ {+ query: {+ "source-table": ORDERS_ID,+ expressions: {+ [CUSTOM_COLUMN_NAME]: ["+", 1, 2],+ },+ aggregation: [+ [+ "aggregation-options",+ ["+", ["count"], 1],+ {+ name: AGGREGATION_NAME,+ "display-name": AGGREGATION_NAME,+ },+ ],+ ],+ },+ },+ { visitQuestion: true },+ );++ H.openNotebook();+ });++ it("should not be possible to reference a custom expression in itself (metabase#61010)", () => {+ H.getNotebookStep("expression").findByText(CUSTOM_COLUMN_NAME).click();+ H.CustomExpressionEditor.clear().type("[Fo");+ H.CustomExpressionEditor.completions()+ .findByText("Foo")+ .should("not.exist");++ H.CustomExpressionEditor.clear().type("[Foo]");+ H.popover().findByText("Unknown column: Foo").should("be.visible");+ });++ it("should not be possible to reference an aggregation in itself(metabase#61010)", () => {+ H.getNotebookStep("summarize").findByText(AGGREGATION_NAME).click();+ H.CustomExpressionEditor.clear().type("[New cou");+ H.CustomExpressionEditor.completions()+ .findByText("New count")+ .should("not.exist");++ H.CustomExpressionEditor.clear().type("[New count]");+ H.popover()+ .findByText("Unknown Aggregation, Measure or Metric: New count")+ .should("be.visible");+ });+});++describe("issue 62987", () => {+ beforeEach(() => {+ H.restore();+ cy.signInAsNormalUser();+ H.createQuestion(+ {+ query: { "source-table": ORDERS_ID },+ },+ { visitQuestion: true },+ );++ H.openNotebook();+ H.summarize({ mode: "notebook" });+ H.popover().findByText("Custom Expression").click();+ });++ it("should be possible to complete non-aggregation functions in custom aggregation (metabase#62987)", () => {+ H.CustomExpressionEditor.type("Coun");+ H.CustomExpressionEditor.completion("CountIf").should("be.visible").click();++ H.CustomExpressionEditor.type("notEm", { focus: false });+ H.CustomExpressionEditor.completion("notEmpty")+ .should("be.visible")+ .click();++ H.CustomExpressionEditor.value().should("eq", "CountIf(notEmpty(column))");++ H.expressionEditorWidget().button("Function browser").click();+ H.CustomExpressionEditor.functionBrowser().within(() => {+ cy.findByText("CountIf").should("be.visible");+ cy.findByText("notEmpty").should("be.visible");+ });+ });+});++describe("issue 63180", () => {+ beforeEach(() => {+ H.restore();+ cy.signInAsNormalUser();+ H.createQuestion(+ {+ query: {+ "source-table": ORDERS_ID,+ expressions: {+ Foo: ["+", 1, 2],+ },+ },+ },+ { visitQuestion: true },+ );++ H.openNotebook();+ });++ it("should not be possible to close the custom expression editor when creating a new expression from a combine or extract shortcut (metabase#63180)", () => {+ function testCombineColumns() {+ H.getNotebookStep("expression").icon("add").click();+ H.expressionEditorWidget().within(() => {+ cy.findByText("Combine columns").click();+ cy.button("Done").scrollIntoView().click();+ });++ cy.log("clicking outside the editor should not close it");+ H.getNotebookStep("data").click();+ H.expressionEditorWidget().should("be.visible");+ H.modal().should("not.exist");++ cy.log("clearing the expression should allow clicking outside to work");+ H.CustomExpressionEditor.clear();+ H.getNotebookStep("data").click();+ H.expressionEditorWidget().should("not.exist");+ H.modal().should("not.exist");+ }++ function testExtractColumns() {+ H.getNotebookStep("expression").icon("add").click();+ H.expressionEditorWidget().within(() => {+ cy.findByText("Extract columns").click();+ cy.findByText("Email").click();+ cy.findByText("Domain").click();+ });++ cy.log("clicking outside the editor should not close it");+ H.getNotebookStep("data").click();+ H.expressionEditorWidget().should("be.visible");+ H.modal().should("not.exist");++ cy.log("clearing the expression should allow clicking outside to work");+ H.CustomExpressionEditor.clear();+ H.getNotebookStep("data").click();+ H.expressionEditorWidget().should("not.exist");+ H.modal().should("not.exist");+ }++ testCombineColumns();+ testExtractColumns();+ });+});diff --git a/e2e/test/scenarios/custom-column/custom-column.cy.spec.js b/e2e/test/scenarios/custom-column/custom-column.cy.spec.jsdeleted file mode 100644index cee5eb48712..00000000000--- a/e2e/test/scenarios/custom-column/custom-column.cy.spec.js+++ /dev/null@@ -1,2556 +0,0 @@-const { H } = cy;-import { dedent } from "ts-dedent";--import { SAMPLE_DB_ID } from "e2e/support/cypress_data";-import { SAMPLE_DATABASE } from "e2e/support/cypress_sample_database";--const { ORDERS, ORDERS_ID, PRODUCTS, PRODUCTS_ID, PEOPLE_ID, PEOPLE } =- SAMPLE_DATABASE;--describe("scenarios > question > custom column", () => {- beforeEach(() => {- cy.intercept("POST", "/api/dataset").as("dataset");-- H.restore();- cy.signInAsNormalUser();- });-- it("can see x-ray options when a custom column is present (#16680)", () => {- H.createQuestion(- {- name: "16680",- display: "line",- query: {- "source-table": ORDERS_ID,- aggregation: [["count"]],- breakout: [- ["expression", "TestColumn"],- ["field", ORDERS.CREATED_AT, { "temporal-unit": "month" }],- ],- expressions: { TestColumn: ["+", 1, 1] },- },- },- { visitQuestion: true },- );- H.cartesianChartCircle().eq(5).click();- H.popover()- .findByText(/Automatic Insights/i)- .click();- H.popover().findByText(/X-ray/i);- H.popover()- .findByText(/Compare to the rest/i)- .click();- });-- it("can create a custom column (metabase#13241)", () => {- H.openOrdersTable({ mode: "notebook" });- cy.findByLabelText("Custom column").click();-- H.enterCustomColumnDetails({- formula: "1 + 1",- name: "Math",- format: true,- });- cy.button("Done").click();-- H.visualize();-- // eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage- cy.findByText("There was a problem with your question").should("not.exist");- cy.findByTestId("query-visualization-root").contains("Math");- });-- it("should not show default period in date column name (metabase#36631)", () => {- const name = "Base question";- H.createQuestion({ name, query: { "source-table": ORDERS_ID } });-- H.startNewQuestion();- H.miniPickerBrowseAll().click();- H.entityPickerModal().within(() => {- H.entityPickerModalLevel(0).findByText("Our analytics").click();- H.entityPickerModalLevel(1).findByText(name).click();- });- cy.button("Custom column").click();- H.enterCustomColumnDetails({ formula: "[cre", blur: false });-- H.CustomExpressionEditor.completions()- .should("be.visible")- .and("contain.text", "Created At")- .and("not.contain.text", "Default period");- });-- it("should not show binning for a numeric custom column", () => {- H.openOrdersTable({ mode: "notebook" });- cy.findByLabelText("Custom column").click();-- H.enterCustomColumnDetails({- formula: "[Product.Price] / 2",- name: "Half Price",- });- cy.button("Done").click();-- cy.button("Summarize").click();- H.popover().findByText("Count of rows").click();-- H.getNotebookStep("summarize")- .findByText("Pick a column to group by")- .click();-- H.popover()- .findByRole("option", { name: "Half Price" })- .within(() => {- cy.findByLabelText("Binning strategy").should("not.exist");- cy.findByLabelText("Temporal bucket").should("not.exist");- })- .click();-- H.getNotebookStep("summarize")- .findByText("Half Price")- .should("be.visible");- });-- it("should show temporal units for a date/time custom column", () => {- H.openOrdersTable({ mode: "notebook" });- cy.findByLabelText("Custom column").click();-- H.enterCustomColumnDetails({- formula: "[Product.Created At]",- name: "Product Date",- });- cy.button("Done").click();-- cy.button("Summarize").click();- H.popover().findByText("Count of rows").click();-- H.getNotebookStep("summarize")- .findByText("Pick a column to group by")- .click();- H.popover()- .findByRole("option", { name: "Product Date" })- .within(() => {- cy.findByLabelText("Binning strategy").should("not.exist");- cy.findByLabelText("Temporal bucket").should("exist");- })- .click();-- H.getNotebookStep("summarize")- .findByText("Product Date: Month")- .should("be.visible");- });-- it("should not show binning options for a coordinate custom column", () => {- H.openPeopleTable({ mode: "notebook" });- cy.findByLabelText("Custom column").click();-- H.enterCustomColumnDetails({- formula: "[Latitude]",- name: "UserLAT",- });- cy.button("Done").click();-- cy.button("Summarize").click();- H.popover().findByText("Count of rows").click();-- H.getNotebookStep("summarize")- .findByText("Pick a column to group by")- .click();- H.popover()- .findByRole("option", { name: "UserLAT" })- .within(() => {- cy.findByLabelText("Binning strategy").should("not.exist");- cy.findByLabelText("Temporal bucket").should("not.exist");- })- .click();-- H.getNotebookStep("summarize").findByText("UserLAT").should("be.visible");- });-- // flaky test (#19454)- it(- "should show info popovers when hovering over custom column dimensions in the summarize sidebar",- { tags: "@skip" },- () => {- H.openOrdersTable({ mode: "notebook" });- cy.findByLabelText("Custom column").click();-- H.enterCustomColumnDetails({ formula: "1 + 1", name: "Math" });- cy.button("Done").click();-- H.visualize();-- H.summarize();-- // eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage- cy.findByText("Group by")- .parent()- .findByText("Math")- .trigger("mouseenter");-- H.popover().contains("Math");- H.popover().contains("No description");- },- );-- it("can create a custom column with an existing column name", () => {- const customFormulas = [- {- formula: "[Quantity] * 2",- name: "Double Qt",- },- {- formula: "[Quantity] * [Product.Price]",- name: "Sum Total",- },- ];-- customFormulas.forEach(({ formula, name }) => {- H.openOrdersTable({ mode: "notebook" });- cy.findByLabelText("Custom column").click();-- H.enterCustomColumnDetails({ formula, name });- cy.button("Done").click();-- H.visualize();-- cy.findByTestId("query-visualization-root").contains(name);- });- });-- it("should create custom column with fields from aggregated data (metabase#12762)", () => {- H.openOrdersTable({ mode: "notebook" });-- H.summarize({ mode: "notebook" });-- H.popover().within(() => {- cy.findByText("Sum of ...").click();- cy.findByText("Subtotal").click();- });-- // TODO: There isn't a single unique parent that can be used to scope this icon within- // (a good candidate would be `.NotebookCell`)- // eslint-disable-next-line metabase/no-unsafe-element-filtering- cy.icon("add")- .last() // This is brittle.- .click();-- H.popover().within(() => {- cy.findByText("Sum of ...").click();- cy.findByText("Total").click();- });-- // eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage- cy.findByText("Pick a column to group by").click();- // eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage- cy.findByText("Created At").click();-- // Add custom column based on previous aggregates- const columnName = "MegaTotal";- // eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage- cy.findByText("Custom column").click();-- H.enterCustomColumnDetails({- formula: "[Sum of Subtotal] + [Sum of Total]",- name: columnName,- });- cy.button("Done").click();-- H.visualize();-- // eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage- cy.findByText("There was a problem with your question").should("not.exist");- // This is a pre-save state of the question but the column name should appear- // both in tabular and graph views (regardless of which one is currently selected)- cy.findByTestId("query-visualization-root").contains(columnName);- });-- it("should not return same results for columns with the same name (metabase#12649)", () => {- H.openOrdersTable({ mode: "notebook" });- // join with Products- // eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage- cy.findByText("Join data").click();-- H.miniPickerBrowseAll().click();- H.entityPickerModal().within(() => {- H.entityPickerModalLevel(0).findByText("Databases").click();- H.entityPickerModalLevel(1).findByText("Sample Database").click();- cy.findByText("Products").click();- });-- // add custom column- // eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage- cy.findByText("Custom column").click();- H.enterCustomColumnDetails({ formula: "1 + 1", name: "x" });- cy.button("Done").click();-- H.visualize();-- cy.log(- "**Fails in 0.35.0, 0.35.1, 0.35.2, 0.35.4 and the latest master (2026-10-21)**",- );- cy.log("Works in 0.35.3");- // ID should be "1" but it is picking the product ID and is showing "14"- cy.get(".test-TableInteractive-cellWrapper--firstColumn")- .eq(0)- .findByText("1");- });-- it("should be able to use custom expression after aggregation (metabase#13857)", () => {- const CE_NAME = "13857_CE";- const CC_NAME = "13857_CC";-- cy.signInAsAdmin();-- H.createQuestion(- {- name: "13857",- query: {- expressions: {- [CC_NAME]: ["*", ["field-literal", CE_NAME, "type/Float"], 1234],- },- "source-query": {- aggregation: [- [- "aggregation-options",- ["*", ["count"], 1],- { name: CE_NAME, "display-name": CE_NAME },- ],- ],- breakout: [- ["datetime-field", ["field-id", ORDERS.CREATED_AT], "month"],- ],- "source-table": ORDERS_ID,- },- },- },- { visitQuestion: true },- );-- // eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage- cy.findByText(CC_NAME);- });-- it("should work with implicit joins (metabase#14080)", () => {- const CC_NAME = "OneisOne";- cy.signInAsAdmin();-- H.createQuestion(- {- name: "14080",- query: {- "source-table": ORDERS_ID,- expressions: { [CC_NAME]: ["*", 1, 1] },- aggregation: [- [- "distinct",- [- "fk->",- ["field-id", ORDERS.PRODUCT_ID],- ["field-id", PRODUCTS.ID],- ],- ],- ["sum", ["expression", CC_NAME]],- ],- breakout: [- ["datetime-field", ["field-id", ORDERS.CREATED_AT], "year"],- ],- },- display: "line",- },- { visitQuestion: true },- );-- cy.log("Regression since v0.37.1 - it works on v0.37.0");-- // eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage- cy.contains(`Sum of ${CC_NAME}`);- H.cartesianChartCircle().should("have.length.of.at.least", 8);- });-- it("should create custom column after aggregation with 'cum-sum/count' (metabase#13634)", () => {- H.createQuestion(- {- name: "13634",- query: {- expressions: { "Foo Bar": ["+", 57910, 1] },- "source-query": {- aggregation: [["cum-count"]],- breakout: [- ["datetime-field", ["field-id", ORDERS.CREATED_AT], "month"],- ],- "source-table": ORDERS_ID,- },- },- },- { visitQuestion: true },- );-- // eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage- cy.findByText("13634");-- cy.log("Reported failing in v0.34.3, v0.35.4, v0.36.8.2, v0.37.0.2");- // eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage- cy.findByText("Foo Bar");- cy.findAllByText("57,911");- });-- it("should not be dropped if filter is changed after aggregation (metaabase#14193)", () => {- const CC_NAME = "Double the fun";-- H.createQuestion(- {- name: "14193",- query: {- "source-query": {- "source-table": ORDERS_ID,- filter: [">", ["field-id", ORDERS.SUBTOTAL], 0],- aggregation: [["sum", ["field-id", ORDERS.TOTAL]]],- breakout: [- ["datetime-field", ["field-id", ORDERS.CREATED_AT], "year"],- ],- },- expressions: {- [CC_NAME]: ["*", ["field-literal", "sum", "type/Float"], 2],- },- },- },- { visitQuestion: true },- );- // Test displays collapsed filter - click on number 1 to expand and show the filter name- cy.findByTestId("filters-visibility-control")- .should("have.text", "1")- .click();-- // eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage- cy.findByText(/Subtotal is greater than 0/i)- .parent()- .find(".Icon-close")- .click();-- // eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage- cy.findByText(CC_NAME);- });-- it("should handle identical custom column and table column names (metabase#14255)", () => {- // Uppercase is important for this reproduction on H2- const CC_NAME = "CATEGORY";-- H.createQuestion(- {- name: "14255",- query: {- "source-table": PRODUCTS_ID,- expressions: {- [CC_NAME]: ["concat", ["field-id", PRODUCTS.CATEGORY], "2"],- },- aggregation: [["count"]],- breakout: [["expression", CC_NAME]],- },- },- { visitQuestion: true },- );-- // eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage- cy.findByText(CC_NAME);- // eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage- cy.findByText("Gizmo2");- });-- it("should drop custom column (based on a joined field) when a join is removed (metabase#14775)", () => {- const CE_NAME = "Rounded price";-- H.createQuestion({- name: "14775",- query: {- "source-table": ORDERS_ID,- joins: [- {- fields: "all",- "source-table": PRODUCTS_ID,- condition: [- "=",- ["field-id", ORDERS.PRODUCT_ID],- ["joined-field", "Products", ["field-id", PRODUCTS.ID]],- ],- alias: "Products",- },- ],- expressions: {- [CE_NAME]: [- "ceil",- ["joined-field", "Products", ["field-id", PRODUCTS.PRICE]],- ],- },- limit: 5,- },- }).then(({ body: { id: QUESTION_ID } }) => {- cy.visit(`/question/${QUESTION_ID}/notebook`);- cy.findByTestId("step-expression-0-0").contains(CE_NAME);- });-- // Remove join- cy.findByTestId("step-join-0-0").realHover().find(".Icon-close").click();- cy.findByTestId("step-join-0-0").should("not.exist");-- cy.log("Reported failing on 0.38.1-SNAPSHOT (6d77f099)");- cy.findByTestId("step-expression-0-0").should("not.exist");-- H.visualize((response) => {- expect(response.body.error).to.not.exist;- });-- cy.get("[data-testid=cell-data]").should("contain", "37.65");- cy.findAllByTestId("header-cell").should("not.contain", CE_NAME);- });-- it("should handle using `case()` when referencing the same column names (metabase#14854)", () => {- const CC_NAME = "CE with case";-- H.visitQuestionAdhoc(- {- dataset_query: {- type: "query",- query: {- "source-table": ORDERS_ID,- expressions: {- [CC_NAME]: [- "case",- [- [- [">", ["field", ORDERS.DISCOUNT, null], 0],- ["field", ORDERS.CREATED_AT, null],- ],- ],- {- default: [- "field",- PRODUCTS.CREATED_AT,- { "source-field": ORDERS.PRODUCT_ID },- ],- },- ],- },- },- database: SAMPLE_DB_ID,- },- display: "table",- },- { callback: (xhr) => expect(xhr.response.body.error).not.to.exist },- );-- // eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage- cy.findByText(CC_NAME);- // eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage- cy.contains("37.65");- });-- it("should handle brackets in the name of the custom column (metabase#15316)", () => {- H.createQuestion({- name: "15316",- query: {- "source-table": ORDERS_ID,- expressions: { "MyCC [2027]": ["+", 1, 1] },- },- }).then(({ body: { id: QUESTION_ID } }) => {- cy.visit(`/question/${QUESTION_ID}/notebook`);- });- H.summarize({ mode: "notebook" });- H.popover().within(() => {- cy.findByText("Sum of ...").click();- cy.findByText("MyCC [2027]").click();- });- cy.findAllByTestId("notebook-cell-item")- .contains("Sum of MyCC [2027]")- .click();- H.popover().within(() => {- cy.icon("chevronleft").click();- cy.findByText("Custom Expression").click();- });- H.CustomExpressionEditor.value().should("equal", "Sum([MyCC \\[2027\\]])");- });-- it("should work with `isNull` function (metabase#15922)", () => {- H.openOrdersTable({ mode: "notebook" });- H.getNotebookStep("data").button("Custom column").click();- H.enterCustomColumnDetails({- formula: "isnull([Discount])",- name: "No discount",- });- cy.button("Done").click();-- H.visualize((response) => {- expect(response.body.error).to.not.exist;- });-- cy.findAllByRole("gridcell").contains("37.65");- cy.findAllByTestId("header-cell").contains("No discount");- });-- it("should be able to add a date range filter to a custom column", () => {- H.visitQuestionAdhoc({- display: "table",- dataset_query: {- database: SAMPLE_DB_ID,- type: "query",- query: {- "source-table": ORDERS_ID,- expressions: { CustomDate: ["field", ORDERS.CREATED_AT, null] },- },- },- });-- H.tableHeaderClick("CustomDate");-- H.popover().within(() => {- cy.findByText("Filter by this column").click();- cy.findByText("Fixed date range…").click();- cy.findByLabelText("Start date").clear().type("12/10/2024");- cy.findByLabelText("End date").clear().type("01/05/2025");- cy.button("Add filter").click();- });-- cy.wait("@dataset");- // eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage- cy.findByText("Showing 487 rows").should("be.visible");- });-- it("should work with relative date filter applied to a custom column (metabase#16273)", () => {- H.openOrdersTable({ mode: "notebook" });- H.addCustomColumn();-- H.enterCustomColumnDetails({- formula: "case([Discount] > 0, [Created At], [Product → Created At])",- name: "MiscDate",- });- H.popover().button("Done").click();-- H.filter({ mode: "notebook" });- H.popover().within(() => {- cy.findByText("MiscDate").click();- cy.findByText("Relative date range…").click();- cy.findByText("Previous").click();- cy.findByDisplayValue("days").click();- });- cy.findByRole("listbox").findByText("years").click();-- H.popover().within(() => {- cy.findByText("Include this year").click();- cy.button("Add filter").click();- });-- H.visualize(({ body }) => {- expect(body.error).to.not.exist;- });-- H.queryBuilderMain().findByText("MiscDate").should("be.visible");- cy.findByTestId("qb-filters-panel")- .findByText("MiscDate is in the previous 30 years or this year")- .should("be.visible");- });-- it("should allow indenting using Tab", () => {- H.openOrdersTable({ mode: "notebook" });- cy.findByLabelText("Custom column").click();-- H.enterCustomColumnDetails({ formula: "1 + 2", blur: false });-- // Tab should insert indentation- cy.realPress("Tab");- H.CustomExpressionEditor.value().should("equal", "1 + 2 ");- });-- it("should not format expression when pressing tab in the editor", () => {- H.openOrdersTable({ mode: "notebook" });- cy.findByLabelText("Custom column").click();-- H.enterCustomColumnDetails({ formula: "1+1" });-- cy.realPress("Tab");- cy.realPress(["Shift", "Tab"]);-- // `1+1` (3 chars) is reformatted to `1 + 1` (5 chars)- H.CustomExpressionEditor.value().should("equal", "1+1");- H.CustomExpressionEditor.type("2");-- // Fix prevents display value from being `1 +2 1` due to cursor position- // being wrong after formatting.- // That's because the caret position after refocusing on textarea- // would still be after the 3rd character- H.CustomExpressionEditor.value().should("equal", "1+12");- });-- it("should format expression when clicking the format button", () => {- H.openOrdersTable({ mode: "notebook" });- cy.findByLabelText("Custom column").click();-- H.enterCustomColumnDetails({ formula: "1+1" });-- // `1+1` (3 chars) is reformatted to `1 + 1` (5 chars)- H.CustomExpressionEditor.format();- H.CustomExpressionEditor.value().should("equal", "1 + 1");- H.CustomExpressionEditor.type("2");-- // Fix needed will prevent display value from being `1 +2 1`.- // That's because the caret position after refocusing on textarea- // would still be after the 3rd character- H.CustomExpressionEditor.value().should("equal", "1 + 12");- });-- it("should format the expression when pressing the format keyboard shortcut", () => {- H.openOrdersTable({ mode: "notebook" });- cy.findByLabelText("Custom column").click();-- H.enterCustomColumnDetails({ formula: "1+1" });-- // `1+1` (3 chars) is reformatted to `1 + 1` (5 chars)- H.CustomExpressionEditor.focus();- const isMac = Cypress.platform === "darwin";- const metaKey = isMac ? "Meta" : "Control";-- H.CustomExpressionEditor.formatButton().should("be.visible");- H.CustomExpressionEditor.get()- .get(".cm-editor")- .realPress(["Shift", metaKey, "f"]);- H.CustomExpressionEditor.value().should("equal", "1 + 1");-- // Make sure the cursor is at the end of the expression- H.CustomExpressionEditor.type("2");- H.CustomExpressionEditor.value().should("equal", "1 + 12");- });-- it("should not try formatting the expression when it's invalid using the keyboard shortcut", () => {- H.openOrdersTable({ mode: "notebook" });- cy.findByLabelText("Custom column").click();-- H.enterCustomColumnDetails({ formula: "1+" });-- H.CustomExpressionEditor.focus();- const isMac = Cypress.platform === "darwin";- const metaKey = isMac ? "Meta" : "Control";-- cy.realPress(["Shift", metaKey, "f"]);- H.CustomExpressionEditor.value().should("equal", "1+");-- // Make sure the cursor is at the end of the expression- H.CustomExpressionEditor.type("2");- H.CustomExpressionEditor.value().should("equal", "1+2");- });-- it("should format long expressions on multiple lines", () => {- H.openOrdersTable({ mode: "notebook" });- cy.findByLabelText("Custom column").click();-- H.enterCustomColumnDetails({- formula:- "concat(coalesce([Product → Created At], [Created At]), 'foo', 'bar')",- format: true,- });-- H.CustomExpressionEditor.value().should(- "equal",- dedent`- concat(- coalesce([Product → Created At], [Created At]),- "foo",- "bar"- )- `.trim(),- );- });-- it("should not allow formatting when the expression contains an error", () => {- H.openOrdersTable({ mode: "notebook" });- cy.findByLabelText("Custom column").click();-- H.enterCustomColumnDetails({- formula: "concat('foo', ",- });- H.CustomExpressionEditor.formatButton().should("not.exist");- });-- it("should show the format button when the expression editor is empty", () => {- H.openOrdersTable({ mode: "notebook" });- cy.findByLabelText("Custom column").click();- H.CustomExpressionEditor.formatButton().should("not.exist");- });-- it("should not allow saving the expression when it is invalid", () => {- H.openOrdersTable({ mode: "notebook" });- cy.findByLabelText("Custom column").click();-- H.enterCustomColumnDetails({- formula: "concat('foo', ",- name: "A custom expression",- });-- H.expressionEditorWidget().button("Done").should("be.disabled");- H.CustomExpressionEditor.nameInput().focus().type("{enter}");- H.expressionEditorWidget().should("be.visible");- });-- it("should validate the expression when typing", () => {- H.openOrdersTable({ mode: "notebook" });- cy.findByLabelText("Custom column").click();-- H.enterCustomColumnDetails({- formula: "concat('foo', ",- name: "A custom expression",- });- H.expressionEditorWidget().button("Done").should("be.disabled");-- cy.log("Fix the expression");- H.CustomExpressionEditor.type("{leftarrow}'bar')", { focus: true });- H.expressionEditorWidget().button("Done").should("not.be.disabled");- });-- it("should allow choosing a suggestion with Tab", () => {- H.openOrdersTable({ mode: "notebook" });- cy.findByLabelText("Custom column").click();-- H.enterCustomColumnDetails({ formula: "[Cre", blur: false });-- H.CustomExpressionEditor.completions().should("be.visible");-- // Suggestion popover shows up and this select the first one- cy.realPress("Tab");-- // Focus remains on the expression editor- cy.focused().should("have.attr", "role", "textbox");- });-- it("should be possible to use the suggestion snippet arguments", () => {- H.openOrdersTable({ mode: "notebook" });- H.addCustomColumn();-- H.CustomExpressionEditor.type("coalesc{tab}[Tax]{tab}[User ID]", {- delay: 50,- });- H.CustomExpressionEditor.value().should(- "equal",- "coalesce([Tax], [User ID])",- );- });-- it("should be possible to use the suggestion templates", () => {- H.openOrdersTable({ mode: "notebook" });- H.addCustomColumn();-- H.CustomExpressionEditor.type("coalesc{tab}", { delay: 50 });-- H.CustomExpressionEditor.type("[Tax]{tab}[User ID]", {- focus: false,- delay: 50,- });- H.CustomExpressionEditor.value().should(- "equal",- "coalesce([Tax], [User ID])",- );- });-- it("should allow to use `if` function", () => {- H.openProductsTable({ mode: "notebook" });-- cy.log("custom columns");- H.getNotebookStep("data").button("Custom column").click();- H.enterCustomColumnDetails({- formula: 'if([ID] = 1, "First", [ID] = 2, "Second", "Other")',- name: "If",- });- H.expressionEditorWidget().button("Done").click();- H.getNotebookStep("expression").button("Filter").click();- H.clauseStepPopover().within(() => {- cy.findByText("If").click();- });- H.selectFilterOperator("Is");- H.clauseStepPopover().within(() => {- cy.findByPlaceholderText("Enter some text").type("Other");- cy.button("Add filter").click();- });- H.visualize();- H.assertQueryBuilderRowCount(198);- H.openNotebook();- H.getNotebookStep("filter").findByText("If is Other").icon("close").click();- H.getNotebookStep("expression").findByText("If").icon("close").click();-- cy.log("filters");- H.getNotebookStep("data").button("Filter").click();- H.clauseStepPopover().within(() => {- cy.findByText("Custom Expression").click();- H.enterCustomColumnDetails({- formula: 'if([Category] = "Gadget", 1, [Category] = "Widget", 2) = 2',- });- cy.button("Done").click();- });- H.visualize();- H.assertQueryBuilderRowCount(54);- H.openNotebook();- H.getNotebookStep("filter")- .findByText("If is equal to 2")- .icon("close")- .click();-- cy.log("aggregations");- H.getNotebookStep("data").button("Summarize").click();- H.clauseStepPopover().within(() => {- cy.findByText("Custom Expression").click();- H.enterCustomColumnDetails({- formula: 'sum(if([Category] = "Gadget", 1, 2))',- name: "SumIf",- });- cy.button("Done").click();- });- H.visualize();- cy.findByTestId("scalar-value").should("have.text", "347");- });-- it("should allow to use `in` and `notIn` functions", () => {- H.openProductsTable({ mode: "notebook" });-- cy.log("custom columns - in");- H.getNotebookStep("data").button("Custom column").click();- H.enterCustomColumnDetails({- formula: 'in("Gadget", [Vendor], [Category])',- name: "InColumn",- });- H.expressionEditorWidget().button("Done").click();- H.getNotebookStep("expression").button("Filter").click();- H.clauseStepPopover().within(() => {- cy.findByText("InColumn").click();- cy.findByText("Add filter").click();- });- H.visualize();- H.assertQueryBuilderRowCount(53);-- cy.log("custom columns - notIn");- H.openNotebook();- H.getNotebookStep("expression").findByText("InColumn").click();- H.enterCustomColumnDetails({- formula: 'notIn("Gadget", [Vendor], [Category])',- name: "InColumn",- });- H.expressionEditorWidget().button("Update").click();- H.visualize();- H.assertQueryBuilderRowCount(147);-- cy.log("filters - in");- H.openNotebook();- H.getNotebookStep("expression")- .findByText("InColumn")- .icon("close")- .click();- H.getNotebookStep("data").button("Filter").click();- H.clauseStepPopover().within(() => {- cy.findByText("Custom Expression").click();- H.enterCustomColumnDetails({ formula: "in([ID], 1, 2, 3)" });- cy.button("Done").click();- });- H.visualize();- H.assertQueryBuilderRowCount(3);- H.openNotebook();- H.getNotebookStep("filter").findByText("ID is 3 selections").click();- H.clauseStepPopover().within(() => {- cy.findByText("3").next("button").click();- cy.button("Update filter").click();- });- H.visualize();- H.assertQueryBuilderRowCount(2);-- cy.log("filters - notIn");- H.openNotebook();- H.getNotebookStep("filter").findByText("ID is 2 selections").click();- H.clauseStepPopover().within(() => {- cy.findByLabelText("Back").click();- cy.findByText("Custom Expression").click();- H.enterCustomColumnDetails({ formula: "notIn([ID], 1, 2, 3)" });- cy.button("Update").click();- });- H.visualize();- H.assertQueryBuilderRowCount(197);-- cy.log("aggregations - in");- H.openNotebook();- H.getNotebookStep("filter")- .findByText("ID is not 3 selections")- .icon("close")- .click();- H.getNotebookStep("data").button("Summarize").click();- H.clauseStepPopover().within(() => {- cy.findByText("Custom Expression").click();- H.enterCustomColumnDetails({- formula: "countIf(in([ID], 1, 2))",- name: "CountIfIn",- });- cy.button("Done").click();- });- H.visualize();- cy.findByTestId("scalar-value").should("have.text", "2");-- cy.log("aggregations - notIn");- H.openNotebook();- H.getNotebookStep("summarize").findByText("CountIfIn").click();- H.enterCustomColumnDetails({- formula: "countIf(notIn([ID], 1, 2))",- name: "CountIfIn",- });- H.expressionEditorWidget().button("Update").click();- H.visualize();- cy.findByTestId("scalar-value").should("have.text", "198");- });-- it("should handle expression references", () => {- H.openProductsTable({ mode: "notebook" });-- H.getNotebookStep("data").button("Custom column").click();- H.enterCustomColumnDetails({- formula: "[Price]",- name: "Foo",- });- H.expressionEditorWidget().button("Done").click();-- H.getNotebookStep("expression").icon("add").click();- H.enterCustomColumnDetails({- formula: "[Foo]",- name: "Bar",- });- H.expressionEditorWidget().button("Done").click();-- H.getNotebookStep("expression").icon("add").click();- H.enterCustomColumnDetails({- formula: "[Bar]",- name: "Quu",- });- H.expressionEditorWidget().button("Done").click();-- H.getNotebookStep("expression").findByText("Foo").click();- H.CustomExpressionEditor.value().should("eq", "[Price]");- H.expressionEditorWidget().button("Cancel").click();-- H.getNotebookStep("expression").findByText("Bar").click();- H.CustomExpressionEditor.value().should("eq", "[Foo]");- H.expressionEditorWidget().button("Cancel").click();-- H.getNotebookStep("expression").findByText("Quu").click();- H.CustomExpressionEditor.value().should("eq", "[Bar]");- });-});--describe(- "scenarios > question > custom column > data type",- { tags: "@external" },- () => {- function addCustomColumns(columns) {- cy.wrap(columns).each((column, index) => {- if (index) {- H.getNotebookStep("expression").icon("add").click();- } else {- cy.findByLabelText("Custom column").click();- }-- H.enterCustomColumnDetails(column);- cy.button("Done").click({ force: true });- });- }-- function openCustomColumnInTable(table) {- H.openTable({ table, mode: "notebook" });- cy.findByText("Custom column").click();- }-- beforeEach(() => {- H.restore();- H.restore("postgres-12");-- cy.signInAsAdmin();- });-- it("should understand string functions (metabase#13217)", () => {- openCustomColumnInTable(PRODUCTS_ID);-- H.enterCustomColumnDetails({- formula: "concat([Category], [Title])",- name: "CategoryTitle",- });-- cy.button("Done").click();-- H.filter({ mode: "notebook" });-- H.popover().within(() => {- cy.findByText("CategoryTitle").click();- cy.findByPlaceholderText("Enter a number").should("not.exist");- cy.findByPlaceholderText("Enter some text").should("be.visible");- });- });-- it("should understand date functions", () => {- H.startNewQuestion();- H.miniPicker().within(() => {- cy.findByText("QA Postgres12").click();- cy.findByText("Orders").click();- });-- addCustomColumns([- { name: "Year", formula: "year([Created At])" },- { name: "Quarter", formula: "quarter([Created At])" },- { name: "Month", formula: "month([Created At])" },- { name: "Week", formula: 'week([Created At], "iso")' },- { name: "Day", formula: "day([Created At])" },- { name: "Weekday", formula: "weekday([Created At])" },- { name: "Hour", formula: "hour([Created At])" },- { name: "Minute", formula: "minute([Created At])" },- { name: "Second", formula: "second([Created At])" },- {- name: "Datetime Add",- formula: 'datetimeAdd([Created At], 1, "month")',- },- {- name: "Datetime Subtract",- formula: 'datetimeSubtract([Created At], 1, "month")',- },- {- name: "ConvertTimezone 3 args",- formula: 'convertTimezone([Created At], "Asia/Ho_Chi_Minh", "UTC")',- },- {- name: "ConvertTimezone 2 args",- formula: 'convertTimezone([Created At], "Asia/Ho_Chi_Minh")',- },- ]);-- H.visualize();- });-- it("should relay the type of a date field", () => {- openCustomColumnInTable(PEOPLE_ID);-- H.enterCustomColumnDetails({ formula: "[Birth Date]", name: "DoB" });- cy.button("Done").click();-- H.filter({ mode: "notebook" });- H.popover().within(() => {- cy.findByText("DoB").click();- cy.findByPlaceholderText("Enter a number").should("not.exist");- cy.findByText("Relative date range…").click();- cy.findByText("Previous").click();- cy.findByDisplayValue("days").should("be.visible");- });- });-- it("should handle CASE (metabase#13122)", () => {- openCustomColumnInTable(ORDERS_ID);-- H.enterCustomColumnDetails({- formula: "case([Discount] > 0, [Created At], [Product → Created At])",- name: "MiscDate",- });- cy.button("Done").click();-- H.filter({ mode: "notebook" });- H.popover().within(() => {- cy.findByText("MiscDate").click();- cy.findByPlaceholderText("Enter a number").should("not.exist");-- cy.findByText("Relative date range…").click();- cy.findByText("Previous").click();- cy.findByDisplayValue("days").should("be.visible");- });- });-- it("should handle COALESCE", () => {- openCustomColumnInTable(ORDERS_ID);-- H.enterCustomColumnDetails({- formula: "COALESCE([Product → Created At], [Created At])",- name: "MiscDate",- });- cy.button("Done").click();-- H.filter({ mode: "notebook" });- H.popover().within(() => {- cy.findByText("MiscDate").click();- cy.findByPlaceholderText("Enter a number").should("not.exist");- cy.findByText("Relative date range…").click();- cy.findByText("Previous").click();- cy.findByDisplayValue("days").should("be.visible");- });- });- },-);--describe("scenarios > question > custom column > error feedback", () => {- beforeEach(() => {- H.restore();- cy.signInAsAdmin();-- H.openProductsTable({ mode: "notebook" });- // eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage- cy.findByText("Custom column").click();- });-- it("should catch non-existent field reference", () => {- H.enterCustomColumnDetails({- formula: "abcdef",- name: "Non-existent",- });-- // eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage- cy.contains(/^Unknown column: abcdef/i);- });-- it("should fail on expression validation errors", () => {- H.enterCustomColumnDetails({- formula: "SUBSTRING('foo', 0, 1)",- name: "BadSubstring",- });-- // eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage- cy.contains(/positive integer/i);- });-});--// ExpressionEditorTextfield jsx component-describe("scenarios > question > custom column > expression editor", () => {- beforeEach(() => {- H.restore();- cy.signInAsAdmin();-- // This is the default screen size but we need it explicitly set for this test because of the resize later on- cy.viewport(1280, 800);-- H.openOrdersTable({ mode: "notebook" });- // eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage- cy.findByText("Custom column").click();-- H.enterCustomColumnDetails({- formula: "1+1", // Formula was intentionally written without spaces (important for this repro)!- name: "Math",- });- cy.button("Done").should("not.be.disabled");- });-- it("should not accidentally delete Custom Column formula value and/or Custom Column name (metabase#15734)", () => {- H.CustomExpressionEditor.type(- "{movetoend}{leftarrow}{movetostart}{rightarrow}{rightarrow}",- );- cy.findByDisplayValue("Math").focus();- cy.button("Done").should("not.be.disabled");- });-- it("should not erase Custom column formula and Custom column name when expression is incomplete (metabase#16126)", () => {- H.CustomExpressionEditor.type("{movetoend}{backspace}").blur();-- // eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage- cy.findByText("Expected expression");- cy.button("Done").should("be.disabled");- });-- it("should not erase Custom Column formula and Custom Column name on window resize (metabase#16127)", () => {- cy.viewport(1260, 800);- cy.findByDisplayValue("Math");- cy.button("Done").should("not.be.disabled");- });-});--describe("scenarios > question > custom column > help text", () => {- beforeEach(() => {- H.restore();- cy.signInAsAdmin();-- H.openProductsTable({ mode: "notebook" });- // eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage- cy.findByText("Custom column").click();- });-- it("should appear while inside a function", () => {- H.enterCustomColumnDetails({ formula: "lower(", blur: false });- H.CustomExpressionEditor.helpTextHeader()- .should("be.visible")- .should("contain", "lower(value)");- });-- it("should appear after a field reference", () => {- H.enterCustomColumnDetails({ formula: "lower([Category]", blur: false });- H.CustomExpressionEditor.helpTextHeader()- .should("be.visible")- .should("contain", "lower(value)");- });-- it("should not appear while outside a function", () => {- H.enterCustomColumnDetails({ formula: "lower([Category])", blur: false });- H.CustomExpressionEditor.helpTextHeader().should("not.exist");- });-- it("should not appear when formula field is not in focus (metabase#15891)", () => {- H.enterCustomColumnDetails({- formula: "rou{enter}1.5{leftArrow}",- blur: false,- });-- H.CustomExpressionEditor.helpText()- .should("be.visible")- .should("contain", "round([Temperature])");-- cy.log("Blur event should remove the expression helper popover");- H.CustomExpressionEditor.blur();- H.CustomExpressionEditor.helpText().should("not.exist");-- H.CustomExpressionEditor.focus().type("{leftArrow}");- H.CustomExpressionEditor.helpText()- .should("be.visible")- .should("contain", "round([Temperature])");-- cy.log(- "Pressing `escape` key should also remove the expression helper popover",- );- H.CustomExpressionEditor.blur();- H.CustomExpressionEditor.helpText().should("not.exist");- });-- it("should not disappear when clicked on (metabase#17548)", () => {- H.enterCustomColumnDetails({ formula: "round(", blur: false });-- H.CustomExpressionEditor.helpText()- .should("be.visible")- .should("contain", "round([Temperature])");-- // Shouldn't hide on click- H.CustomExpressionEditor.helpText().click();-- H.CustomExpressionEditor.helpText()- .should("be.visible")- .should("contain", "round([Temperature])");- });-- describe("scenarios > question > custom column > help text > visibility", () => {- beforeEach(() => {- H.enterCustomColumnDetails({ formula: "round(", blur: false });- });-- it("should be possible to show and hide the help text when there are no suggestions", () => {- assertHelpTextIsVisible();-- H.CustomExpressionEditor.helpTextHeader().click();- assertNeitherAreVisible();-- H.CustomExpressionEditor.helpTextHeader().click();- assertHelpTextIsVisible();- });-- it("should show the help text again when the suggestions are closed", () => {- H.CustomExpressionEditor.type("[Rat", { focus: false });-- cy.log("suggestions should be visible");- assertSuggestionsAreVisible();-- cy.log("help text should remain visible when suggestions are picked");- // helptext should re-open when suggestion is picked- H.CustomExpressionEditor.selectCompletion("Rating");- assertHelpTextIsVisible();- });-- it("should be possible to close the help text", () => {- cy.log("hide help text by clicking the header");- H.CustomExpressionEditor.helpTextHeader().click();- assertNeitherAreVisible();-- cy.log("type to see suggestions");- H.CustomExpressionEditor.type("[Rat", { focus: false });- assertSuggestionsAreVisible();-- cy.log("help text should remain hidden after selecting a suggestion");- H.CustomExpressionEditor.selectCompletion("Rating");- assertNeitherAreVisible();- });-- it("should be possible to prefer showing the help text over the suggestions", () => {- cy.log("type to see suggestions");- H.CustomExpressionEditor.type("[Rat", { focus: false });- assertSuggestionsAreVisible();-- cy.log("show help text by clicking the header");- H.CustomExpressionEditor.helpTextHeader().click();- assertHelpTextIsVisible();-- cy.log("help text should remain shown after finishing typing");- H.CustomExpressionEditor.type("ing], ", { focus: false });- assertHelpTextIsVisible();- });-- it("should be possible to prefer showing the suggestion when typing", () => {- cy.log("type to see suggestions");- H.CustomExpressionEditor.type("[Rat", { focus: false });- assertSuggestionsAreVisible();-- cy.log("show help text by clicking the header");- H.CustomExpressionEditor.helpTextHeader().click();- assertHelpTextIsVisible();-- cy.log("show suggestions again by clicking the header");- H.CustomExpressionEditor.helpTextHeader().click();- assertSuggestionsAreVisible();-- cy.log("help text should remain shown after finishing typing");- H.CustomExpressionEditor.type("ing], ", { focus: false });- assertNeitherAreVisible();- });-- function assertSuggestionsAreVisible() {- cy.log("suggestions should be visible");- H.CustomExpressionEditor.helpText().should("not.exist");- H.CustomExpressionEditor.completions()- .findAllByRole("option")- .should("be.visible");- }- function assertHelpTextIsVisible() {- cy.log("help text should be visible");- H.CustomExpressionEditor.helpText().should("be.visible");- H.CustomExpressionEditor.completions()- .findByRole("option")- .should("not.exist");- }- function assertNeitherAreVisible() {- H.CustomExpressionEditor.helpText().should("not.exist");- H.CustomExpressionEditor.completions()- .findByRole("option")- .should("not.exist");- }- });-});--describe("scenarios > question > custom column > exiting the editor", () => {- beforeEach(() => {- H.restore();- cy.signInAsAdmin();-- H.openProductsTable({ mode: "notebook" });- // eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage- cy.findByText("Custom column").click();- });-- it("should be possible to close the custom expression editor by pressing Escape when it is empty", () => {- cy.realPress("Escape");- H.CustomExpressionEditor.get().should("not.exist");- });-- it("should not be possible to close the custom expression editor by pressing Escape when it is not empty", () => {- H.CustomExpressionEditor.type("count(");- cy.realPress("Escape");- H.CustomExpressionEditor.get().should("be.visible");- });-- it("should be possible to exit the editor by clicking outside of it when there is no text", () => {- H.getNotebookStep("data").click();- H.modal().should("not.exist");- H.expressionEditorWidget().should("not.exist");- });-- it("should be possible to exit the editor by clicking outside of it when there is no text, by clicking an interactive element", () => {- H.getNotebookStep("data").button("Pick columns").click();- H.modal().should("not.exist");- H.expressionEditorWidget().should("not.exist");- H.popover().findByText("Select all").should("be.visible");- });-- it("should not be possible to exit the editor by clicking outside of it when there is an unsaved expression", () => {- H.enterCustomColumnDetails({ formula: "1+1", blur: false });- H.getNotebookStep("data").button("Pick columns").click();- H.popover().findByText("Select all").should("not.exist");- H.expressionEditorWidget().should("exist");-- H.modal().within(() => {- cy.findByText("Keep editing your custom expression?").should(- "be.visible",- );- cy.button("Discard changes").should("be.enabled");- cy.button("Keep editing").click();- });-- H.modal().should("not.exist");- H.expressionEditorWidget().should("exist");- });-- it("should be possible to discard changes when clicking outside of the editor", () => {- H.enterCustomColumnDetails({ formula: "1+1", blur: false });- H.getNotebookStep("data").button("Pick columns").click();- H.expressionEditorWidget().should("exist");- H.popover().findByText("Select all").should("not.exist");-- H.modal().within(() => {- cy.findByText("Keep editing your custom expression?").should(- "be.visible",- );- cy.button("Keep editing").should("be.enabled");- cy.button("Discard changes").click();- });-- H.modal().should("not.exist");- H.expressionEditorWidget().should("not.exist");- });-- it("should be possible to discard changes by clicking cancel button", () => {- H.enterCustomColumnDetails({ formula: "1+1", name: "OK" });- H.expressionEditorWidget().button("Cancel").click();- H.modal().should("not.exist");- H.expressionEditorWidget().should("not.exist");- H.getNotebookStep("expression").findByText("OK").should("not.exist");- });-- it("should be possible to close the popover when navigating away from the expression editor", () => {- H.expressionEditorWidget().button("Cancel").click();- cy.button("Summarize").click();- H.popover().as("popover").findByText("Custom Expression").click();- H.enterCustomColumnDetails({ formula: "1+1" });-- cy.log("Go back to summarize modal");- H.popover().findByText("Custom Expression").click();-- cy.log("Close summarize modal by clicking outside");- cy.findByLabelText("View SQL").click();-- H.modal().should("not.exist");- cy.get("popover").should("not.exist");- });-});--describe("scenarios > question > custom column > distinctIf", () => {- beforeEach(() => {- H.restore();- cy.signInAsNormalUser();- });-- it("should allow to use a distinctIf function", () => {- H.openProductsTable({ mode: "notebook" });-- cy.log("add a new expression");- H.getNotebookStep("data").button("Summarize").click();- H.popover().findByText("Custom Expression").click();- H.enterCustomColumnDetails({- formula: "DistinctIf([ID], [Category] = 'Gadget')",- name: "Distinct",- });- H.popover().button("Done").click();- H.visualize();- cy.findByTestId("scalar-value").should("have.text", "53");-- cy.log("modify the expression");- H.openNotebook();- H.getNotebookStep("summarize").findByText("Distinct").click();- H.CustomExpressionEditor.value().should(- "eq",- 'DistinctIf([ID], [Category] = "Gadget")',- );- H.enterCustomColumnDetails({- formula: "DistinctIf([ID], [Category] != 'Gadget')",- name: "Distinct",- });- H.popover().button("Update").click();- H.visualize();- cy.findByTestId("scalar-value").should("have.text", "147");- });-});--describe("scenarios > question > custom column > path", () => {- beforeEach(() => {- H.restore();- cy.signInAsNormalUser();- });-- function assertTableData({ title, value }) {- // eslint-disable-next-line metabase/no-unsafe-element-filtering- H.tableInteractive()- .findAllByTestId("header-cell")- .last()- .should("have.text", title);-- // eslint-disable-next-line metabase/no-unsafe-element-filtering- H.tableInteractiveBody()- .findAllByTestId("cell-data")- .last()- .should("have.text", value);- }-- it("should allow to use a path function", () => {- const CC_NAME = "URL_URL";- const questionDetails = {- name: "path from url",- query: {- "source-table": PEOPLE_ID,- limit: 1,- expressions: {- [CC_NAME]: [- "concat",- "http://",- ["domain", ["field", PEOPLE.EMAIL, null]],- ".com/my/path",- ],- },- },- type: "model",- };-- H.createQuestion(questionDetails, {- wrapId: true,- idAlias: "modelId",- });-- cy.get("@modelId").then((modelId) => {- H.setModelMetadata(modelId, (field) => {- if (field.name === CC_NAME) {- return { ...field, semantic_type: "type/URL" };- }-- return field;- });-- H.visitModel(modelId);- });-- H.openNotebook();-- cy.log("add a new expression");- H.getNotebookStep("data").button("Custom column").click();- H.enterCustomColumnDetails({- formula: `Path([${CC_NAME}])`,- name: "extracted path",- });-- H.popover().button("Done").click();- H.visualize();- cy.findByTestId("table-scroll-container").scrollTo("right");-- const extractedValue = "/my/path";- assertTableData({- title: "extracted path",- value: extractedValue,- });- });-});--describe("scenarios > question > custom column > function browser", () => {- beforeEach(() => {- H.restore();- cy.signInAsNormalUser();-- H.openProductsTable({ mode: "notebook" });- H.addCustomColumn();- });-- it("should be possible to insert functions by clicking them in the function browser", () => {- H.expressionEditorWidget().button("Function browser").click();-- H.CustomExpressionEditor.functionBrowser()- .findByText("datetimeAdd")- .click();-- H.CustomExpressionEditor.value().should("equal", "datetimeAdd()");-- H.CustomExpressionEditor.functionBrowser().findByText("day").click();- H.CustomExpressionEditor.value().should("equal", "datetimeAdd(day())");-- H.CustomExpressionEditor.type('"foo"{rightarrow}, ', { focus: false });- H.CustomExpressionEditor.value().should(- "equal",- 'datetimeAdd(day("foo"), )',- );-- H.CustomExpressionEditor.functionBrowser().findByText("day").click();- H.CustomExpressionEditor.value().should(- "equal",- 'datetimeAdd(day("foo"), day())',- );- });-- it("should be possible to replace text when inserting functions", () => {- H.CustomExpressionEditor.type("foo bar baz");- cy.realPress(["ArrowLeft"]);- cy.realPress(["ArrowLeft"]);- cy.realPress(["ArrowLeft"]);- cy.realPress(["ArrowLeft"]);- cy.realPress(["Shift", "ArrowLeft"]);- cy.realPress(["Shift", "ArrowLeft"]);- cy.realPress(["Shift", "ArrowLeft"]);-- H.expressionEditorWidget().button("Function browser").click();- H.CustomExpressionEditor.functionBrowser().findByText("day").click();- H.CustomExpressionEditor.value().should("equal", "foo day() baz");- });-- it("should be possible to filter functions in the function browser", () => {- H.expressionEditorWidget().button("Function browser").click();-- H.CustomExpressionEditor.functionBrowser().within(() => {- cy.findByPlaceholderText("Search functions…").type("con");-- cy.findByText("datetimeAdd").should("not.exist");- cy.findByText("concat").should("be.visible");- cy.findByText("second").should("be.visible");- //- cy.findByPlaceholderText("Search functions…").clear();- cy.findByText("datetimeAdd").should("exist");- });- });-- it("should not show functions that are not supported by the current database", () => {- H.expressionEditorWidget().button("Function browser").click();-- H.CustomExpressionEditor.functionBrowser().within(() => {- cy.findByPlaceholderText("Search functions…").type("convertTimezone");- cy.findByText("convertTimezone").should("not.exist");- });- });-- it("should not show aggregations unless aggregating", () => {- H.expressionEditorWidget().button("Function browser").click();- H.CustomExpressionEditor.functionBrowser().within(() => {- cy.findByPlaceholderText("Search functions…").type("Count");- cy.findByText("Count").should("not.exist");- });- H.expressionEditorWidget().button("Cancel").click();-- H.summarize({ mode: "notebook" });- H.popover().findByText("Custom Expression").click();-- H.expressionEditorWidget().button("Function browser").click();- H.CustomExpressionEditor.functionBrowser().within(() => {- cy.findByPlaceholderText("Search aggregations…").type("Count");- cy.findByText("Count").should("be.visible");- });- });-- it("show a message when no functions match the filter", () => {- H.expressionEditorWidget().button("Function browser").click();- H.CustomExpressionEditor.functionBrowser().within(() => {- cy.findByPlaceholderText("Search functions…").type("foobar");- cy.findByText("Didn't find any results").should("be.visible");- });- });-- it("should insert parens even when the clause has no arguments", () => {- H.expressionEditorWidget().button("Function browser").click();- H.CustomExpressionEditor.functionBrowser().within(() => {- cy.findByPlaceholderText("Search functions…").type("now");- cy.findByText("now").click();- });- H.CustomExpressionEditor.value().should("equal", "now()");- });-});--describe("scenarios > question > custom column > splitPart", () => {- beforeEach(() => {- H.restore("postgres-12");- cy.signInAsAdmin();-- H.startNewQuestion();- H.miniPicker().within(() => {- cy.findByText("QA Postgres12").click();- cy.findByText("People").click();- });-- cy.findByLabelText("Custom column").click();- });-- function assertTableData({ title, value }) {- // eslint-disable-next-line metabase/no-unsafe-element-filtering- H.tableInteractive()- .findAllByTestId("header-cell")- .last()- .should("have.text", title);-- // eslint-disable-next-line metabase/no-unsafe-element-filtering- H.tableInteractiveBody()- .findAllByTestId("cell-data")- .last()- .should("have.text", value);- }-- it("should be possible to split a custom column", () => {- const CC_NAME = "Split Title";-- H.enterCustomColumnDetails({- formula: "splitPart([Name], ' ', 1)",- name: CC_NAME,- });- H.popover().button("Done").click();-- cy.findByLabelText("Row limit").click();- cy.findByPlaceholderText("Enter a limit").type(1).blur();-- H.visualize();-- H.tableInteractiveScrollContainer().scrollTo("right");- assertTableData({ title: CC_NAME, value: "Hudson" });- });-- it("should show a message when index is below 1", () => {- H.enterCustomColumnDetails({- formula: "splitPart([Name], ' ', 0)",- });-- H.popover().button("Done").should("be.disabled");- H.popover().should("contain", "Expected positive integer but found 0");- });-});--describe("exercise today() function", () => {- beforeEach(() => {- H.restore("postgres-12");- cy.signInAsAdmin();- });-- it("should show today's date", () => {- H.startNewQuestion();- H.miniPicker().within(() => {- cy.findByText("QA Postgres12").click();- cy.findByText("Products").click();- });-- H.getNotebookStep("data").button("Pick columns").click();- H.popover().findByText("Select all").click();- cy.realPress("Escape");-- H.visualize();- H.assertQueryBuilderRowCount(200);- H.openNotebook();-- H.getNotebookStep("data").button("Custom column").click();- H.enterCustomColumnDetails({ formula: "today()", name: "TODAY" });- H.popover().button("Done").click();-- const today = new Date();- const dateString = today.toLocaleDateString("en-US", {- year: "numeric",- month: "long",- day: "numeric",- });-- H.visualize();- cy.findAllByTestId("header-cell").eq(1).should("have.text", "TODAY");- cy.findAllByTestId("cell-data").eq(3).should("have.text", dateString);- });-});--describe("scenarios > question > custom column > aggregation", () => {- beforeEach(() => {- H.restore();- cy.signInAsNormalUser();- H.openOrdersTable({ mode: "notebook" });- });-- it("should be possible to resolve aggregations from the question", () => {- H.createQuestion(- {- query: {- "source-table": ORDERS_ID,- aggregation: [- [- "aggregation-options",- ["sum", ["field", ORDERS.TOTAL, null]],- {- name: "Custom Sum",- "display-name": "Custom Sum",- },- ],- ],- },- },- { visitQuestion: true },- );- H.openNotebook();-- H.getNotebookStep("summarize").icon("add").click();- H.popover().findByText("Custom Expression").scrollIntoView().click();-- H.CustomExpressionEditor.type("[Custom");- H.CustomExpressionEditor.completion("Custom Sum")- .should("be.visible")- .click();- H.CustomExpressionEditor.value().should("eq", "[Custom Sum]");- H.CustomExpressionEditor.type("+ 1");- H.CustomExpressionEditor.format();-- H.CustomExpressionEditor.nameInput().type("Derived");- H.popover().button("Done").click();-- H.visualize();- H.assertTableData({- columns: ["Custom Sum", "Derived"],- });- });-- it("should be possible to resolve aggregations from the question directly", () => {- H.createQuestion(- {- query: {- "source-table": ORDERS_ID,- aggregation: [- [- "aggregation-options",- ["sum", ["field", ORDERS.TOTAL, null]],- {- name: "Custom Sum",- "display-name": "Custom Sum",- },- ],- ],- },- },- { visitQuestion: true },- );- H.openNotebook();-- H.getNotebookStep("summarize").icon("add").click();- H.popover().findByText("Custom Expression").scrollIntoView().click();-- H.CustomExpressionEditor.type("[Custom");- H.CustomExpressionEditor.completion("Custom Sum")- .should("be.visible")- .click();- H.CustomExpressionEditor.value().should("eq", "[Custom Sum]");- H.CustomExpressionEditor.format();-- H.CustomExpressionEditor.nameInput().type("Derived");- H.popover().button("Done").click();-- H.visualize();- H.assertTableData({- columns: ["Custom Sum", "Derived"],- });- });-- it("should be possible to resolve aggregations from the previous stage", () => {- H.createQuestion(- {- query: {- "source-table": ORDERS_ID,- aggregation: [- [- "aggregation-options",- ["sum", ["field", ORDERS.TOTAL, null]],- {- name: "Custom Sum",- "display-name": "Custom Sum",- },- ],- ],- },- },- { visitQuestion: true },- );- H.openNotebook();-- cy.findAllByLabelText("Custom column").eq(1).click();- H.CustomExpressionEditor.type("[Custom S");- H.CustomExpressionEditor.completion("Custom Sum")- .should("be.visible")- .click();- H.CustomExpressionEditor.value().should("eq", "[Custom Sum]");- H.CustomExpressionEditor.format();-- H.CustomExpressionEditor.nameInput().type("Derived");- H.popover().button("Done").click();-- H.visualize();- H.assertTableData({- columns: ["Custom Sum", "Derived"],- });- });-- it("should not be possible to create cycles in custom aggregations", () => {- H.createQuestion(- {- query: {- "source-table": ORDERS_ID,- aggregation: [- [- "aggregation-options",- ["sum", ["field", ORDERS.TOTAL, null]],- {- name: "Custom Sum",- "display-name": "Custom Sum",- },- ],- ],- },- },- { visitQuestion: true },- );-- H.openNotebook();-- H.getNotebookStep("summarize").icon("add").click();- H.popover().findByText("Custom Expression").scrollIntoView().click();- H.CustomExpressionEditor.type("[Custom Sum] + 1");- H.CustomExpressionEditor.nameInput().type("Custom Sum 2");- H.popover().button("Done").click();-- H.getNotebookStep("summarize").findByText("Custom Sum").click();- H.CustomExpressionEditor.clear().type("[Custom Sum 2]");-- H.popover()- .findByText("Cycle detected: Custom Sum → Custom Sum 2 → Custom Sum")- .should("be.visible");- });-- it("should be possible to create aggregations with the same name", () => {- H.createQuestion(- {- query: {- "source-table": ORDERS_ID,- aggregation: [- [- "aggregation-options",- ["sum", ["field", ORDERS.TOTAL, null]],- {- name: "Foo",- "display-name": "Foo",- },- ],- ],- },- },- { visitQuestion: true },- );- H.openNotebook();-- H.getNotebookStep("summarize").icon("add").click();- H.popover().findByText("Custom Expression").scrollIntoView().click();- H.CustomExpressionEditor.type("Min([Total])");- H.CustomExpressionEditor.nameInput().type("Foo");- H.popover().button("Done").click();-- H.getNotebookStep("summarize").within(() => {- cy.findAllByText("Foo").should("have.length", 2);- });- });-- it("should be possible to reorder aggregations with the same name", () => {- H.createQuestion(- {- query: { "source-table": ORDERS_ID },- },- { visitQuestion: true },- );- H.openNotebook();-- H.summarize({ mode: "notebook" });-- H.popover().findByText("Custom Expression").scrollIntoView().click();- H.CustomExpressionEditor.type("Count() + 1");- H.CustomExpressionEditor.nameInput().type("Count");- H.popover().button("Done").click();-- H.getNotebookStep("summarize").icon("add").click();- H.popover().findByText("Custom Expression").scrollIntoView().click();- H.CustomExpressionEditor.type("[Count] + 1");- H.CustomExpressionEditor.nameInput().type("Count");- H.popover().button("Done").click();-- H.getNotebookStep("summarize").icon("add").click();- H.popover().findByText("Custom Expression").scrollIntoView().click();- H.CustomExpressionEditor.type("[Count] + 2");- H.CustomExpressionEditor.nameInput().type("Final");- H.popover().button("Done").click();-- cy.log("Both the secound Count and Final should reference the first Count");- H.visualize();- H.assertTableData({- columns: ["Count", "Count", "Final"],- firstRows: [["18,761", "18,762", "18,763"]],- });-- H.openNotebook();-- cy.log("Move the second Count to be the first");- H.getNotebookStep("summarize")- .findAllByText("Count")- .should("have.length", 2)- .last()- .as("dragElement");- H.moveDnDKitElementByAlias("@dragElement", { horizontal: -400 });-- cy.log("The values should not have changed, but the order should have");- H.visualize();- H.assertTableData({- columns: ["Count", "Count", "Final"],- firstRows: [["18,762", "18,761", "18,763"]],- });- });-- describe("scenarios > question > custom column > aggregation > as question source", () => {- beforeEach(() => {- H.createQuestion({- query: {- "source-table": ORDERS_ID,- aggregation: [- [- "aggregation-options",- [- "min",- [- "field",- ORDERS.SUBTOTAL,- {- "base-type": "type/Float",- },- ],- ],- {- name: "Foo",- "display-name": "Foo",- },- ],- [- "aggregation-options",- [- "+",- [- "aggregation",- 0,- {- "base-type": "type/Float",- },- ],- [- "avg",- [- "field",- ORDERS.TAX,- {- "base-type": "type/Float",- },- ],- ],- ],- {- name: "Bar",- "display-name": "Bar",- },- ],- ],- },- }).then((res) => {- H.visitQuestionAdhoc(- {- type: "question",- dataset_query: {- type: "query",- database: SAMPLE_DB_ID,- query: {- "source-table": `card__${res.body.id}`,- },- },- },- { mode: "notebook" },- );- });- });-- it("should be possible to use a question with nested aggregations as the source of another question", () => {- H.visualize();- H.assertTableData({- columns: ["Foo", "Bar"],- firstRows: [["15.69", "19.55"]],- });- });-- it("should be possible to use nested aggregations in custom columns of a new question", () => {- H.addCustomColumn();- H.CustomExpressionEditor.type("[Foo] + [Bar]");- H.CustomExpressionEditor.nameInput().type("Sum");- H.popover().button("Done").click();-- H.visualize();-- H.assertTableData({- columns: ["Foo", "Bar", "Sum"],- firstRows: [["15.69", "19.55", "35.24"]],- });- });-- it("should be possible to use nested aggregations in filter clause of a new question", () => {- H.filter({ mode: "notebook" });- H.popover().within(() => {- cy.findByText("Bar").click();- cy.findByPlaceholderText("Min").type("5");- cy.findByPlaceholderText("Max").type("20");- cy.button("Add filter").click();- });- H.visualize();- H.assertTableData({- columns: ["Foo", "Bar"],- firstRows: [["15.69", "19.55"]],- });- });-- it("should be possible to use nested aggregations in join clause of a new question", () => {- H.join();- H.joinTable("Products");- H.popover().findByText("Foo").click();- H.popover().findByText("Price").click();-- H.getNotebookStep("join").button("Pick columns").click();- H.popover().within(() => {- cy.findByText("Select all").click();- cy.findByText("ID").click();- });-- H.visualize();- H.assertTableData({- columns: ["Foo", "Bar", "Products - Foo → ID"],- firstRows: [["15.69", "19.55", "61"]],- });- });-- it("should be possible to use nested aggregations in order by clause of a new question", () => {- H.sort();- H.popover().findByText("Bar").click();-- H.visualize();- H.assertTableData({- columns: ["Foo", "Bar"],- firstRows: [["15.69", "19.55"]],- });- });-- it("should be possible to use nested aggregations in breakout of a new question", () => {- H.summarize({ mode: "notebook" });- H.getNotebookStep("summarize")- .findByText("Pick a column to group by")- .click();- H.popover().findByText("Bar").click();-- H.visualize();- cy.findByTestId("scalar-value").should("have.text", "19.55");- });- });-- describe("scenarios > question > custom column > aggregation > in a follow up stage", () => {- beforeEach(() => {- H.createQuestion(- {- query: {- "source-table": ORDERS_ID,- aggregation: [- [- "aggregation-options",- [- "min",- [- "field",- ORDERS.SUBTOTAL,- {- "base-type": "type/Float",- },- ],- ],- {- name: "Foo",- "display-name": "Foo",- },- ],- [- "aggregation-options",- [- "+",- [- "aggregation",- 0,- {- "base-type": "type/Float",- },- ],- [- "avg",- [- "field",- ORDERS.TAX,- {- "base-type": "type/Float",- },- ],- ],- ],- {- name: "Bar",- "display-name": "Bar",- },- ],- ],- },- },- { visitQuestion: true },- );- H.openNotebook();- });-- it("should be possible to use nested aggregations in custom columns of a follow up stage", () => {- H.getNotebookStep("summarize").within(() => {- H.addCustomColumn();- });-- H.CustomExpressionEditor.type("[Foo] + [Bar]");- H.CustomExpressionEditor.nameInput().type("Sum");- H.popover().button("Done").click();-- H.visualize();-- H.assertTableData({- columns: ["Foo", "Bar", "Sum"],- firstRows: [["15.69", "19.55", "35.24"]],- });- });-- it("should be possible to use nested aggregations in join clause of a follow up stage", () => {- H.getNotebookStep("summarize").within(() => {- H.join();- });-- H.joinTable("Products");- H.popover().findByText("Foo").click();- H.popover().findByText("Price").click();-- H.getNotebookStep("join", { stage: 1 }).button("Pick columns").click();- H.popover().within(() => {- cy.findByText("Select all").click();- cy.findByText("ID").click();- });-- H.visualize();- H.assertTableData({- columns: ["Foo", "Bar", "Products - Foo → ID"],- firstRows: [["15.69", "19.55", "61"]],- });- });- });-- describe("scenarios > question > custom column > aggregation with breakout > in a follow up stage", () => {- beforeEach(() => {- H.createQuestion(- {- query: {- "source-table": ORDERS_ID,- aggregation: [- [- "aggregation-options",- [- "min",- [- "field",- ORDERS.SUBTOTAL,- {- "base-type": "type/Float",- },- ],- ],- {- name: "Foo",- "display-name": "Foo",- },- ],- [- "aggregation-options",- [- "+",- [- "aggregation",- 0,- {- "base-type": "type/Float",- },- ],- [- "avg",- [- "field",- ORDERS.TAX,- {- "base-type": "type/Float",- },- ],- ],- ],- {- name: "Bar",- "display-name": "Bar",- },- ],- ],- breakout: [- [- "field",- ORDERS.CREATED_AT,- { "base-type": "type/DateTime", "temporal-unit": "month" },- ],- ],- },- },- { visitQuestion: true },- );- H.openNotebook();- });-- it("should be possible to use nested aggregations in custom columns of a follow up stage", () => {- H.getNotebookStep("summarize").within(() => {- H.addCustomColumn();- });- H.CustomExpressionEditor.type("[Foo] + [Bar]");- H.CustomExpressionEditor.nameInput().type("Sum");- H.popover().button("Done").click();-- H.visualize();-- H.assertTableData({- columns: ["Created At: Month", "Foo", "Bar", "Sum"],- firstRows: [["April 2022", "49.54", "52.76", "102.29"]],- });- });-- it("should be possible to use nested aggregations in filter clause of a follow up stage", () => {- H.getNotebookStep("summarize").within(() => {- H.filter({ mode: "notebook" });- });- H.popover().within(() => {- cy.findByText("Bar").click();- cy.findByPlaceholderText("Min").type("5");- cy.findByPlaceholderText("Max").type("20");- cy.button("Add filter").click();- });- H.visualize();- H.assertTableData({- columns: ["Created At: Month", "Foo", "Bar"],- firstRows: [["September 2022", "15.69", "18.57"]],- });- });-- it("should be possible to use nested aggregations in join clause of a follow up stage", () => {- H.getNotebookStep("summarize").within(() => {- H.join();- });- H.joinTable("Products");-- H.popover().findByText("Foo").click();- H.popover().findByText("Price").click();-- H.getNotebookStep("join", { stage: 1 }).button("Pick columns").click();- H.popover().within(() => {- cy.findByText("Select all").click();- cy.findByText("ID").click();- });-- H.visualize();- H.assertTableData({- columns: ["Created At: Month", "Foo", "Bar", "Products - Foo → ID"],- firstRows: [["April 2022", "49.54", "52.76", "34"]],- });- });-- it("should be possible to use nested aggregations in order by clause of a follow up stage", () => {- H.getNotebookStep("summarize").within(() => {- H.sort();- });- H.popover().findByText("Bar").click();-- H.visualize();- H.assertTableData({- columns: ["Created At: Month", "Foo", "Bar"],- firstRows: [["April 2023", "15.69", "18.21"]],- });- });-- it("should be possible to use nested aggregations in breakout of a follow up stage", () => {- H.getNotebookStep("summarize").within(() => {- H.summarize({ mode: "notebook" });- });-- H.popover().findByText("Count of rows").click();-- H.visualize();- H.assertTableData({- columns: ["Count"],- firstRows: [["49"]],- });- });-- it("should be possible reference both aggregations with same name in follow up stage", () => {- H.openOrdersTable({ mode: "notebook" });-- H.summarize({ mode: "notebook" });-- H.popover().findByText("Custom Expression").scrollIntoView().click();- H.CustomExpressionEditor.type("Count() + 1");- H.CustomExpressionEditor.nameInput().type("Count");- H.popover().button("Done").click();-- H.getNotebookStep("summarize").icon("add").click();- H.popover().findByText("Custom Expression").scrollIntoView().click();- H.CustomExpressionEditor.type("[Count] + 1");- H.CustomExpressionEditor.nameInput().type("Count");- H.popover().button("Done").click();-- H.getNotebookStep("summarize")- .findByText("Pick a column to group by")- .click();- H.popover().findByText("Created At").click();-- cy.log("Filter by the first Count");- H.getNotebookStep("summarize").within(() => {- H.filter({ mode: "notebook" });- });- H.popover().within(() => {- cy.findAllByText("Count").should("have.length", 2);-- cy.findAllByText("Count").eq(0).click();-- // if this was referencing the second Count, it would filter out all rows- cy.findByPlaceholderText("Max").type("2.5");- cy.button("Add filter").click();- });-- cy.log("Filter by the second Count");- H.getNotebookStep("filter", { stage: 1 }).icon("add").click();- H.popover().within(() => {- cy.findAllByText("Count").should("have.length", 2);-- cy.findAllByText("Count").eq(1).click();-- // if this was referencing the first Count, it would filter out all rows- cy.findByPlaceholderText("Min").type("2.5");- cy.button("Add filter").click();- });-- H.visualize();- H.assertTableData({- columns: ["Created At: Month", "Count", "Count"],- firstRows: [["April 2022", "2", "3"]],- });-- cy.log(- "Swapping the aggregation clauses should not change the results, but the column order will be different",- );- H.openNotebook();- H.getNotebookStep("summarize")- .findAllByText("Count")- .should("have.length", 2)- .last()- .as("dragElement");- H.moveDnDKitElementByAlias("@dragElement", { horizontal: -400 });-- H.visualize();- H.assertTableData({- columns: ["Created At: Month", "Count", "Count"],- firstRows: [["April 2022", "3", "2"]],- });- });- });-- it("should show a custom error when there are no aggregations in a custom aggregation", () => {- H.openOrdersTable({ mode: "notebook" });- H.summarize({ mode: "notebook" });- H.popover().findByText("Custom Expression").scrollIntoView().click();- H.CustomExpressionEditor.type("1 + 1");- H.popover()- .findByText(- "Aggregations should contain at least one aggregation function.",- )- .should("be.visible");- });-});diff --git a/e2e/test/scenarios/filters-reproductions/dashboard-filters-reproductions.cy.spec.js b/e2e/test/scenarios/filters-reproductions/dashboard-filters-reproductions-1.cy.spec.jssimilarity index 50%rename from e2e/test/scenarios/filters-reproductions/dashboard-filters-reproductions.cy.spec.jsrename to e2e/test/scenarios/filters-reproductions/dashboard-filters-reproductions-1.cy.spec.jsindex f68c23a49cd..dc96099a220 100644--- a/e2e/test/scenarios/filters-reproductions/dashboard-filters-reproductions.cy.spec.js+++ b/e2e/test/scenarios/filters-reproductions/dashboard-filters-reproductions-1.cy.spec.js@@ -2,12 +2,7 @@ const { H } = cy;import dayjs from "dayjs";-import {- SAMPLE_DB_ID,- SAMPLE_DB_SCHEMA_ID,- USER_GROUPS,- WRITABLE_DB_ID,-} from "e2e/support/cypress_data";+import { SAMPLE_DB_ID, SAMPLE_DB_SCHEMA_ID } from "e2e/support/cypress_data";import { SAMPLE_DATABASE } from "e2e/support/cypress_sample_database";import {ADMIN_PERSONAL_COLLECTION_ID,@@ -2832,2758 +2827,3 @@ describe("issue 43799", () => {H.assertQueryBuilderRowCount(4);});});--describe("issue 44288", () => {- const questionDetails = {- name: "SQL question",- type: "question",- query: { "source-table": PRODUCTS_ID, limit: 10 },- };-- const modelDetails = {- name: "SQL model",- type: "model",- native: { query: "SELECT * FROM PRODUCTS LIMIT 10" },- };-- const parameterDetails = {- name: "Text",- slug: "text",- id: "27454068",- type: "string/=",- sectionId: "string",- };-- const dashboardDetails = {- parameters: [parameterDetails],- enable_embedding: true,- embedding_params: {- [parameterDetails.slug]: "enabled",- },- };-- function getDashcardDetails(dashboard, question, model) {- return {- dashboard_id: dashboard.id,- cards: [- {- card_id: question.id,- parameter_mappings: [- {- card_id: question.id,- parameter_id: parameterDetails.id,- target: [- "dimension",- ["field", PRODUCTS.CATEGORY, { "base-type": "type/Text" }],- ],- },- ],- },- {- card_id: model.id,- parameter_mappings: [- {- card_id: model.id,- parameter_id: parameterDetails.id,- target: [- "dimension",- ["field", "CATEGORY", { "base-type": "type/Text" }],- ],- },- ],- },- ],- };- }-- function verifyMapping() {- cy.findByTestId("edit-dashboard-parameters-widget-container")- .findByText(parameterDetails.name)- .click();- H.getDashboardCard(0).within(() => {- cy.findByText(/Category/i).should("be.visible");- });- H.getDashboardCard(1).within(() => {- cy.findByText(/Category/i).should("not.exist");- cy.findByText(/Models are data sources/).should("be.visible");- });- }-- function verifyFilter() {- H.filterWidget().click();- H.popover().within(() => {- cy.findByText("Gadget").click();- cy.button("Add filter").click();- });- H.getDashboardCard(0).within(() => {- cy.findAllByText("Gadget").should("have.length.gte", 1);- cy.findByText("Doohickey").should("not.exist");- });- H.getDashboardCard(1).within(() => {- cy.findAllByText("Gadget").should("have.length.gte", 1);- cy.findAllByText("Doohickey").should("have.length.gte", 1);- });- }-- beforeEach(() => {- H.restore();- cy.signInAsAdmin();- H.createQuestion(questionDetails).then(({ body: question }) => {- H.createNativeQuestion(modelDetails).then(({ body: model }) => {- H.createDashboard(dashboardDetails).then(({ body: dashboard }) => {- H.updateDashboardCards(- getDashcardDetails(dashboard, question, model),- );- cy.wrap(dashboard.id).as("dashboardId");- });- });- });- cy.signOut();- });-- it("should ignore parameter mappings to a native model in a dashboard (metabase#44288)", () => {- cy.log("regular dashboards");- cy.signInAsNormalUser();- H.visitDashboard("@dashboardId");- H.editDashboard();- verifyMapping();- H.saveDashboard({ awaitRequest: false });- verifyFilter();- cy.signOut();-- cy.log("public dashboards");- cy.signInAsAdmin();- cy.get("@dashboardId").then((dashboardId) =>- H.visitPublicDashboard(dashboardId),- );- verifyFilter();-- cy.log("embedded dashboards");- cy.get("@dashboardId").then((dashboardId) =>- H.visitEmbeddedPage({- resource: { dashboard: dashboardId },- params: {},- }),- );- verifyFilter();- });-});--describe("issue 27579", () => {- beforeEach(() => {- H.restore();- cy.signInAsNormalUser();- });-- it("should be able to remove the last exclude hour option (metabase#27579)", () => {- H.visitDashboard(ORDERS_DASHBOARD_ID);- H.editDashboard();- H.setFilter("Date picker", "All Options");- H.selectDashboardFilter(H.getDashboardCard(), "Created At");- H.saveDashboard();- H.filterWidget().click();- H.popover().within(() => {- cy.findByText("Exclude…").click();- cy.findByText("Hours of the day…").click();- cy.findByText("Select all").click();- cy.findByLabelText("12 AM").should("be.checked");-- cy.findByText("Select all").click();- cy.findByLabelText("12 AM").should("not.be.checked");- });- });-});--describe("issue 32804", () => {- const question1Details = {- name: "Q1",- query: {- "source-table": PRODUCTS_ID,- },- };-- const parameterDetails = {- name: "Number",- slug: "number",- id: "27454068",- type: "number/=",- sectionId: "number",- };-- const dashboardDetails = {- parameters: [parameterDetails],- };-- const getQuestion2Details = (card) => ({- name: "Q2",- query: {- "source-table": `card__${card.id}`,- filter: [- "=",- ["field", PRODUCTS.CATEGORY, { "base-type": "type/Text" }],- "Gadget",- ],- },- });-- const getParameterMapping = (card) => ({- card_id: card.id,- parameter_id: parameterDetails.id,- target: [- "dimension",- ["field", PRODUCTS.RATING, { "base-type": "type/Integer" }],- ],- });-- beforeEach(() => {- H.restore();- cy.signInAsNormalUser();- });-- it("should retain source query filters when drilling-thru from a dashboard (metabase#32804)", () => {- H.createQuestion(question1Details).then(({ body: card1 }) => {- H.createDashboardWithQuestions({- dashboardDetails,- questions: [getQuestion2Details(card1)],- }).then(({ dashboard, questions: [card2] }) => {- H.updateDashboardCards({- dashboard_id: dashboard.id,- cards: [- {- card_id: card2.id,- parameter_mappings: [getParameterMapping(card2)],- },- ],- });- H.visitDashboard(dashboard.id, {- params: { [parameterDetails.slug]: "4" },- });- });- });- H.filterWidget().findByText("4").should("be.visible");- H.getDashboardCard(0).findByText("Q2").click();- cy.findByTestId("qb-filters-panel").within(() => {- cy.findByText("Category is Gadget").should("be.visible");- cy.findByText("Rating is equal to 4").should("be.visible");- });- });-});--describe("issue 44231", () => {- const parameterDetails = {- id: "92eb69ea",- name: "ID",- sectionId: "id",- slug: "id",- type: "id",- };-- const dashboardDetails = {- parameters: [parameterDetails],- enable_embedding: true,- embedding_params: {- [parameterDetails.slug]: "enabled",- },- };-- function getPkCardDetails(type) {- return {- name: "Products",- type,- query: { "source-table": PRODUCTS_ID },- };- }-- function getFkCardDetails(type) {- return {- name: "Orders",- type: "model",- query: { "source-table": ORDERS_ID },- };- }-- function getDashcardDetails(type, dashboard, pkCard, fkCard) {- return {- dashboard_id: dashboard.id,- cards: [- {- card_id: pkCard.id,- parameter_mappings: [- {- card_id: pkCard.id,- parameter_id: parameterDetails.id,- target: [- "dimension",- [- "field",- type === "model" ? "ID" : PRODUCTS.ID,- { "base-type": "type/BigInteger" },- ],- ],- },- ],- },- {- card_id: fkCard.id,- parameter_mappings: [- {- card_id: fkCard.id,- parameter_id: parameterDetails.id,- target: [- "dimension",- [- "field",- type === "model" ? "PRODUCT_ID" : ORDERS.PRODUCT_ID,- { "base-type": "type/BigInteger" },- ],- ],- },- ],- },- ],- };- }-- function verifyFilterByRemappedValue() {- const productId = 144;- const productName = "Aerodynamic Bronze Hat";-- H.filterWidget().click();- H.popover().within(() => {- cy.findByText(productName).click();- cy.button("Add filter").click();- });- H.getDashboardCard(0).findByText(productName).should("be.visible");- H.getDashboardCard(1)- .findAllByText(String(productId))- .should("have.length.above", 0);- }-- function verifyFieldMapping(type) {- H.createDashboardWithQuestions({- dashboardDetails,- questions: [getPkCardDetails(type), getFkCardDetails(type)],- }).then(({ dashboard, questions: [pkCard, fkCard] }) => {- H.updateDashboardCards(- getDashcardDetails(type, dashboard, pkCard, fkCard),- );-- H.visitDashboard(dashboard.id);- verifyFilterByRemappedValue();-- H.visitPublicDashboard(dashboard.id);- verifyFilterByRemappedValue();-- H.visitEmbeddedPage({- resource: { dashboard: dashboard.id },- params: {},- });- verifyFilterByRemappedValue();- });- }-- beforeEach(() => {- H.restore();- cy.signInAsAdmin();-- cy.request("PUT", `/api/field/${PRODUCTS.ID}`, {- has_field_values: "list",- });- cy.request("PUT", `/api/field/${ORDERS.PRODUCT_ID}`, {- has_field_values: "list",- });- cy.request("PUT", `/api/field/${PRODUCTS.TITLE}`, {- semantic_type: "type/Name",- });- });-- it("should allow filtering by remapped values with questions (metabase#44231)", () => {- verifyFieldMapping("question");- });-- it("should allow filtering by remapped values with models (metabase#44231)", () => {- verifyFieldMapping("model");- });-});--describe("44047", () => {- const questionDetails = {- name: "Question",- type: "question",- query: {- "source-table": REVIEWS_ID,- limit: 100,- },- };-- const modelDetails = {- name: "Model",- type: "model",- query: {- "source-table": REVIEWS_ID,- limit: 100,- },- };-- const sourceQuestionDetails = {- name: "Source question",- type: "question",- query: {- "source-table": REVIEWS_ID,- fields: [- ["field", REVIEWS.ID, { "base-type": "type/BigInteger" }],- ["field", REVIEWS.RATING, { "base-type": "type/Integer" }],- ],- },- };-- const parameterDetails = {- name: "Text",- slug: "text",- id: "5a425670",- type: "string/=",- sectionId: "string",- };-- const dashboardDetails = {- parameters: [parameterDetails],- };-- function getQuestionDashcardDetails(dashboard, card) {- return {- dashboard_id: dashboard.id,- card_id: card.id,- parameter_mappings: [- {- card_id: card.id,- parameter_id: parameterDetails.id,- target: [- "dimension",- ["field", REVIEWS.RATING, { "base-type": "type/Integer" }],- ],- },- ],- };- }-- function getModelDashcardDetails(dashboard, card) {- return {- dashboard_id: dashboard.id,- card_id: card.id,- parameter_mappings: [- {- card_id: card.id,- parameter_id: parameterDetails.id,- target: [- "dimension",- ["field", "RATING", { "base-type": "type/Integer" }],- ],- },- ],- };- }-- function verifyFilterWithRemapping() {- H.filterWidget().click();- H.popover().within(() => {- cy.findByPlaceholderText("Search the list").type("Remapped");- cy.findByText("Remapped").click();- cy.button("Add filter").click();- });- }-- beforeEach(() => {- H.restore();- cy.signInAsAdmin();- cy.request("PUT", `/api/field/${REVIEWS.RATING}`, {- semantic_type: "type/Category",- });- cy.request("POST", `/api/field/${REVIEWS.RATING}/dimension`, {- type: "internal",- name: "Rating",- });- cy.request("POST", `/api/field/${REVIEWS.RATING}/values`, {- values: [[1, "Remapped"]],- });- });-- it("should be able to use remapped values from an integer field with an overridden semantic type used for a custom dropdown source in public dashboards (metabase#44047)", () => {- H.createQuestion(sourceQuestionDetails);- H.createDashboardWithQuestions({- dashboardDetails,- questions: [questionDetails, modelDetails],- }).then(({ dashboard, questions: cards }) => {- H.updateDashboardCards({- dashboard_id: dashboard.id,- cards: [- getQuestionDashcardDetails(dashboard, cards[0]),- getModelDashcardDetails(dashboard, cards[1]),- ],- });- cy.wrap(dashboard.id).as("dashboardId");- });-- cy.log("verify filtering works in a regular dashboard");- H.visitDashboard("@dashboardId");- verifyFilterWithRemapping();-- cy.log("verify filtering works in a public dashboard");- cy.get("@dashboardId").then(H.visitPublicDashboard);- verifyFilterWithRemapping();- });-});--describe("issue 45659", () => {- const parameterDetails = {- name: "ID",- slug: "id",- id: "f8ec7c71",- type: "id",- sectionId: "id",- default: [10],- };-- const questionDetails = {- name: "People",- query: { "source-table": PEOPLE_ID },- };-- const dashboardDetails = {- name: "Dashboard",- parameters: [parameterDetails],- enable_embedding: true,- embedding_params: {- [parameterDetails.slug]: "enabled",- },- };-- function createDashboard() {- return H.createDashboardWithQuestions({- dashboardDetails,- questions: [questionDetails],- }).then(({ dashboard, questions: [card] }) => {- H.addOrUpdateDashboardCard({- dashboard_id: dashboard.id,- card_id: card.id,- card: {- parameter_mappings: [- {- card_id: card.id,- parameter_id: parameterDetails.id,- target: [- "dimension",- ["field", PEOPLE.ID, { "base-type": "type/BigInteger" }],- ],- },- ],- },- }).then(() => ({ dashboard }));- });- }-- function verifyFilterWithRemapping() {- H.filterWidget().findByText("Tressa White").should("be.visible");- }-- beforeEach(() => {- H.restore();- cy.signInAsAdmin();- cy.request("PUT", `/api/field/${PEOPLE.ID}`, {- has_field_values: "list",- });- });-- it("should remap initial parameter values in public dashboards (metabase#45659)", () => {- createDashboard().then(({ dashboard }) =>- H.visitPublicDashboard(dashboard.id),- );- verifyFilterWithRemapping();- });-- it("should remap initial parameter values in embedded dashboards (metabase#45659)", () => {- createDashboard().then(({ dashboard }) =>- H.visitEmbeddedPage({- resource: { dashboard: dashboard.id },- params: {},- }),- );- verifyFilterWithRemapping();- });-});--describe("44266", () => {- const filterDetails = {- name: "Equal to",- slug: "equal_to",- id: "10c0d4ba",- type: "number/=",- sectionId: "number",- };-- const dashboardDetails = {- name: "44266",- parameters: [filterDetails],- };-- const regularQuestion = {- name: "regular",- query: { "source-table": PRODUCTS_ID, limit: 2 },- };-- const nativeQuestion = {- name: "native",- native: {- query:- "SELECT * from products where true [[ and price > {{price}}]] limit 5;",- "template-tags": {- price: {- type: "number",- name: "price",- id: "b22a5ce2-fe1d-44e3-8df4-f8951f7921bc",- "display-name": "Price",- },- },- },- };-- beforeEach(() => {- H.restore();- cy.signInAsAdmin();- });-- it("should allow mapping when native and regular questions can be mapped (metabase#44266)", () => {- H.createDashboardWithQuestions({- dashboardDetails,- questions: [regularQuestion, nativeQuestion],- }).then(({ dashboard }) => {- H.visitDashboard(dashboard.id);- H.editDashboard();- cy.findByTestId("edit-dashboard-parameters-widget-container")- .findByText("Equal to")- .click();-- H.getDashboardCard(1).findByText("Select…").click();-- H.popover().findByText("Price").click();-- H.getDashboardCard(1).findByText("Price").should("be.visible");- });- });-});--describe("issue 44790", () => {- beforeEach(() => {- H.restore();- cy.signInAsNormalUser();- });-- it("should handle string values passed to number and id filters (metabase#44790)", () => {- const idFilter = {- id: "92eb69ea",- name: "ID",- sectionId: "id",- slug: "id",- type: "id",- };-- const numberFilter = {- id: "10c0d4ba",- name: "Equal to",- slug: "equal_to",- type: "number/=",- sectionId: "number",- };-- const peopleQuestionDetails = {- query: { "source-table": PEOPLE_ID, limit: 5 },- };-- H.createDashboardWithQuestions({- dashboardDetails: {- parameters: [idFilter, numberFilter],- },- questions: [peopleQuestionDetails],- }).then(({ dashboard, questions: cards }) => {- const [peopleCard] = cards;-- cy.wrap(dashboard.id).as("dashboardId");-- H.updateDashboardCards({- dashboard_id: dashboard.id,- cards: [- {- card_id: peopleCard.id,- parameter_mappings: [- {- parameter_id: idFilter.id,- card_id: peopleCard.id,- target: ["dimension", ["field", PEOPLE.ID, null]],- },- {- parameter_id: numberFilter.id,- card_id: peopleCard.id,- target: ["dimension", ["field", PEOPLE.LATITUDE, null]],- },- ],- },- ],- });- });-- cy.log("wrong value for id filter should be ignored");- H.visitDashboard("@dashboardId", {- params: {- [idFilter.slug]: "{{test}}",- },- });- H.getDashboardCard().should("contain", "[email protected]");-- cy.log("wrong value for number filter should be ignored");- H.visitDashboard("@dashboardId", {- params: {- [numberFilter.slug]: "{{test}}",- [idFilter.slug]: "1",- },- });- H.getDashboardCard().should("contain", "[email protected]");- });-});--describe("issue 34955", () => {- function checkAppliedFilter(name, value) {- cy.contains('[data-testid="parameter-widget"]', name, {- exact: false,- }).contains(value);- }-- const ccName = "Custom Created At";-- const questionDetails = {- name: "34955",- query: {- "source-table": ORDERS_ID,- expressions: {- [ccName]: [- "field",- ORDERS.CREATED_AT,- { "base-type": "type/DateTime" },- ],- },- fields: [- [- "field",- ORDERS.ID,- {- "base-type": "type/BigInteger",- },- ],- [- "field",- ORDERS.CREATED_AT,- {- "base-type": "type/DateTime",- },- ],- [- "expression",- ccName,- {- "base-type": "type/DateTime",- },- ],- ],- limit: 2,- },- };-- beforeEach(() => {- H.restore();- cy.signInAsAdmin();-- H.createQuestionAndDashboard({- questionDetails,- cardDetails: {- size_x: 16,- size_y: 8,- },- }).then(({ body: { dashboard_id } }) => {- cy.wrap(dashboard_id).as("dashboardId");-- H.visitDashboard(dashboard_id);- H.editDashboard();-- H.setFilter("Date picker", "Single Date", "On");- connectFilterToColumn(ccName);-- H.setFilter("Date picker", "Date Range", "Between");- connectFilterToColumn(ccName);-- H.saveDashboard();-- // eslint-disable-next-line metabase/no-unsafe-element-filtering- cy.findAllByRole("columnheader").eq(-2).should("have.text", "Created At");- // eslint-disable-next-line metabase/no-unsafe-element-filtering- cy.findAllByRole("columnheader").eq(-1).should("have.text", ccName);- H.tableInteractiveBody()- .findAllByRole("gridcell")- .filter(":contains(May 15, 2024, 8:04 AM)")- .should("have.length", 2);- });- });-- it("should connect specific date filter (`Between`) to the temporal custom column (metabase#34955)", () => {- cy.get("@dashboardId").then((dashboard_id) => {- // Apply filter through URL to prevent the typing flakes- cy.visit(`/dashboard/${dashboard_id}?on=&between=2024-01-01~2024-03-01`);- checkAppliedFilter("Between", "January 1, 2024 - March 1, 2024");-- cy.findAllByTestId("cell-data")- .filter(":contains(January 1, 2024, 7:26 AM)")- .should("have.length", 2);- });-- cy.get("@dashboardId").then((dashboard_id) => {- // Apply filter through URL to prevent the typing flakes- cy.visit(`/dashboard/${dashboard_id}?on=2024-01-01&between=`);- checkAppliedFilter("On", "January 1, 2024");-- cy.findAllByTestId("cell-data")- .filter(":contains(January 1, 2024, 7:26 AM)")- .should("have.length", 2);- });- });-- function connectFilterToColumn(column) {- H.getDashboardCard().within(() => {- cy.findByText("Column to filter on");- cy.findByText("Select…").click();- });-- H.popover().within(() => {- cy.findByText(column).click();- });- }-});--describe("issue 35852", () => {- const model = {- name: "35852 - sql",- type: "model",- native: {- query: "SELECT * FROM PRODUCTS LIMIT 10",- },- };-- beforeEach(() => {- H.restore();- cy.signInAsNormalUser();- });-- it("should show filter values for a model based on sql query (metabase#35852)", () => {- H.createNativeQuestion(model).then(({ body: { id: modelId } }) => {- H.setModelMetadata(modelId, (field) => {- if (field.display_name === "CATEGORY") {- return {- ...field,- id: PRODUCTS.CATEGORY,- display_name: "Category",- semantic_type: "type/Category",- fk_target_field_id: null,- };- }-- return field;- });-- createDashboardWithFilterAndQuestionMapped(modelId);- H.visitModel(modelId);- });-- H.tableHeaderClick("Category");- H.popover().findByText("Filter by this column").click();-- cy.log("Verify filter values are available");-- H.popover()- .should("contain", "Gizmo")- .should("contain", "Doohickey")- .should("contain", "Gadget")- .should("contain", "Widget");-- H.popover().within(() => {- cy.findByText("Gizmo").click();- cy.button("Add filter").click();- });-- cy.log("Verify filter is applied");-- cy.findAllByTestId("cell-data")- .filter(":contains(Gizmo)")- .should("have.length", 2);-- H.visitDashboard("@dashboardId");-- H.filterWidget().click();-- H.popover().within(() => {- cy.findByText("Gizmo").click();- cy.button("Add filter").click();- });-- H.getDashboardCard().findAllByText("Gizmo").should("have.length", 2);- });-- function createDashboardWithFilterAndQuestionMapped(modelId) {- const parameterDetails = {- name: "Category",- slug: "category",- id: "2a12e66c",- type: "string/=",- sectionId: "string",- };-- const dashboardDetails = {- parameters: [parameterDetails],- };-- const questionDetails = {- name: "Q1",- query: { "source-table": `card__${modelId}`, limit: 10 },- };-- H.createDashboardWithQuestions({- dashboardDetails,- questions: [questionDetails],- }).then(({ dashboard, questions: [card] }) => {- cy.wrap(dashboard.id).as("dashboardId");-- H.updateDashboardCards({- dashboard_id: dashboard.id,- cards: [- {- card_id: card.id,- parameter_mappings: [- {- card_id: card.id,- parameter_id: parameterDetails.id,- target: [- "dimension",- ["field", PRODUCTS.CATEGORY, { "base-type": "type/Text" }],- ],- },- ],- },- ],- });- });- }-});--describe("issue 47097", () => {- const questionDetails = {- name: "Products",- query: {- "source-table": PRODUCTS_ID,- },- };-- const parameterDetails = {- id: "49596bcb-62bb-49d6-a92d-bf5dbfddf43b",- type: "string/=",- name: "Category",- slug: "category",- };-- const dashboardDetails = {- name: "Dashboard",- parameters: [parameterDetails],- };-- beforeEach(() => {- H.restore();- cy.signInAsAdmin();- });-- it('should be able to use filters without "create-queries" permissions when coming from a dashboard (metabase#47097)', () => {- cy.log("create a dashboard with a parameter mapped to a field with values");- H.createQuestionAndDashboard({ questionDetails, dashboardDetails }).then(- ({ body: { id, card_id, dashboard_id } }) => {- H.updateDashboardCards({- dashboard_id,- cards: [- {- id,- card_id,- row: 0,- col: 0,- size_x: 12,- size_y: 12,- parameter_mappings: [- {- parameter_id: parameterDetails.id,- card_id,- target: ["dimension", ["field", PRODUCTS.CATEGORY, null]],- },- ],- },- ],- });- cy.wrap(dashboard_id).as("dashboardId");- },- );-- cy.log("verify the field values in a dashboard");- cy.signIn("nodata");- H.visitDashboard("@dashboardId");- H.filterWidget().click();- H.popover().within(() => {- cy.findByText("Gadget").should("be.visible");- cy.findByPlaceholderText("Search the list").type("{esc}");- });-- cy.log("drill-thru without filter values and check the dropdown");- H.getDashboardCard().findByText("Products").click();- H.queryBuilderHeader().should("be.visible");- H.filterWidget().click();- H.popover().within(() => {- cy.findByText("Gadget").should("be.visible");- cy.findByPlaceholderText("Search the list").type("{esc}");- });- H.queryBuilderHeader().findByLabelText("Back to Dashboard").click();- H.getDashboardCard().should("be.visible");-- cy.log("add a filter value, drill-thru, and check the dropdown");- H.filterWidget().click();- H.popover().within(() => {- cy.findByText("Gadget").click();- cy.button("Add filter").click();- });- H.getDashboardCard().findByText("Products").click();- H.queryBuilderHeader().should("be.visible");- H.filterWidget().click();- H.popover().findByText("Widget").should("be.visible");- });-});--describe("issue 48524", () => {- const questionDetails = {- name: "15119",- query: { "source-table": REVIEWS_ID },- };-- const ratingFilter = {- id: "5dfco74e",- slug: "rating",- name: "Rating",- type: "string/=",- sectionId: "string",- };-- const reviewerFilter = {- id: "ad1c877e",- name: "Reviewer",- slug: "reviewer",- type: "string/=",- sectionId: "string",- };-- const dashboardDetails = { parameters: [reviewerFilter, ratingFilter] };-- function createDashboard() {- H.createQuestionAndDashboard({ questionDetails, dashboardDetails }).then(- ({ body: { id, card_id, dashboard_id } }) => {- H.updateDashboardCards({- dashboard_id,- cards: [- {- id,- card_id,- row: 0,- col: 0,- size_x: 12,- size_y: 8,- parameter_mappings: [- {- parameter_id: ratingFilter.id,- card_id,- target: ["dimension", ["field", REVIEWS.RATING, null]],- },- {- parameter_id: reviewerFilter.id,- card_id,- target: ["dimension", ["field", REVIEWS.REVIEWER, null]],- },- ],- },- ],- });- cy.wrap(dashboard_id).as("dashboardId");- },- );- }-- beforeEach(() => {- H.restore();- cy.signInAsNormalUser();- });-- it("should not apply last used parameter values when some parameters have values set in the URL (metabase#48524)", () => {- createDashboard();-- cy.log(- "open the dashboard with 2 parameters to populate their last used values",- );- H.visitDashboard("@dashboardId", {- params: {- [reviewerFilter.slug]: ["abbey-heidenreich"],- [ratingFilter.slug]: 4,- },- });- H.assertTableRowsCount(1);-- cy.log(- "open the dashboard again and verify that the last used values are applied",- );- H.visitDashboard("@dashboardId");- H.assertTableRowsCount(1);-- cy.log(- "open the dashboard with only 1 parameter value and verify that the last used values are not applied in this case",- );- H.visitDashboard("@dashboardId", {- params: {- [ratingFilter.slug]: 4,- },- });- H.assertTableRowsCount(535);- });-});--describe("issue 32573", () => {- const modelDetails = {- name: "M1",- type: "model",- query: {- "source-table": ORDERS_ID,- fields: [["field", ORDERS.TAX, null]],- },- };-- const parameterDetails = {- id: "92eb69ea",- name: "ID",- sectionId: "id",- slug: "id",- type: "id",- default: 1,- };-- const dashboardDetails = {- parameters: [parameterDetails],- };-- function getQuestionDetails(modelId) {- return {- name: "Q1",- type: "question",- query: {- "source-table": `card__${modelId}`,- },- };- }-- function getParameterMapping(questionId) {- return {- card_id: questionId,- parameter_id: parameterDetails.id,- target: [- "dimension",- ["field", "ID", { "base-type": "type/BigInteger" }],- ],- };- }-- beforeEach(() => {- H.restore();- cy.signInAsNormalUser();- });-- it("should not crash a dashboard when there is a missing parameter column (metabase#32573)", () => {- H.createQuestion(modelDetails).then(({ body: model }) => {- H.createQuestion(getQuestionDetails(model.id)).then(- ({ body: question }) => {- H.createDashboard(dashboardDetails).then(({ body: dashboard }) => {- return cy- .request("PUT", `/api/dashboard/${dashboard.id}`, {- dashcards: [- createMockDashboardCard({- card_id: question.id,- parameter_mappings: [getParameterMapping(question.id)],- size_x: 6,- size_y: 6,- }),- ],- })- .then(() => H.visitDashboard(dashboard.id));- });- },- );- });- H.getDashboardCard()- .findByText("There was a problem displaying this chart.")- .should("be.visible");-- H.editDashboard();- cy.findByTestId("fixed-width-filters").findByText("ID").click();- H.getDashboardCard().within(() => {- cy.findByText("Unknown Field").should("be.visible");- cy.findByLabelText("Disconnect").click();- });- H.saveDashboard();- H.getDashboardCard().within(() => {- cy.findByText("Q1").should("be.visible");- cy.findByText("Tax").should("be.visible");- });- });-});--describe("issue 45670", { tags: ["@external"] }, () => {- const dialect = "postgres";- const tableName = "many_data_types";-- const parameterDetails = {- id: "92eb69ea",- name: "boolean",- type: "string/=",- slug: "boolean",- sectionId: "string",- };-- const dashboardDetails = {- parameters: [parameterDetails],- };-- function getField() {- return cy.request("GET", "/api/table").then(({ body: tables }) => {- const table = tables.find((table) => table.name === tableName);- return cy- .request("GET", `/api/table/${table.id}/query_metadata`)- .then(({ body: metadata }) => {- const { fields } = metadata;- return fields.find((field) => field.name === "boolean");- });- });- }-- function getQuestionDetails(fieldId) {- return {- database: WRITABLE_DB_ID,- native: {- query: "SELECT id, boolean FROM many_data_types WHERE {{boolean}}",- "template-tags": {- boolean: {- id: "4b77cc1f-ea70-4ef6-84db-58432fce6928",- name: "boolean",- type: "dimension",- "display-name": "Boolean",- dimension: ["field", fieldId, null],- "widget-type": "string/=",- },- },- },- };- }-- function getParameterMapping(cardId) {- return {- card_id: cardId,- parameter_id: parameterDetails.id,- target: ["dimension", ["template-tag", parameterDetails.name]],- };- }-- beforeEach(() => {- H.restore(`${dialect}-writable`);- H.resetTestTable({ type: dialect, table: tableName });- cy.signInAsAdmin();- H.resyncDatabase({ dbId: WRITABLE_DB_ID, tableName });- cy.intercept("PUT", "/api/card/*").as("updateCard");- });-- it("should be able to pass query string parameters for boolean parameters in dashboards (metabase#45670)", () => {- getField().then((field) => {- H.createNativeQuestion(getQuestionDetails(field.id)).then(- ({ body: card }) => {- H.createDashboard(dashboardDetails).then(({ body: dashboard }) => {- cy.request("PUT", `/api/dashboard/${dashboard.id}`, {- dashcards: [- createMockDashboardCard({- card_id: card.id,- parameter_mappings: [getParameterMapping(card.id, field.id)],- size_x: 8,- size_y: 8,- }),- ],- });- H.visitDashboard(dashboard.id, {- params: {- [parameterDetails.slug]: "true",- },- });- });- },- );- });- H.filterWidget().should("contain.text", "true");- H.getDashboardCard().within(() => {- cy.findByText("true").should("be.visible");- cy.findByText("false").should("not.exist");- });- });-});--describe("issue 48351", () => {- beforeEach(() => {- H.restore();- cy.signInAsNormalUser();- });-- it("should navigate to the specified tab with click behaviors (metabase#48351)", () => {- H.createDashboardWithTabs({- name: "Dashboard 1",- tabs: [- { id: 1, name: "Tab 1" },- { id: 2, name: "Tab 2" },- ],- dashcards: [- createMockDashboardCard({- id: -1,- card_id: ORDERS_QUESTION_ID,- dashboard_tab_id: 1,- size_x: 8,- size_y: 8,- }),- createMockDashboardCard({- id: -2,- card_id: ORDERS_QUESTION_ID,- dashboard_tab_id: 2,- col: 8,- size_x: 8,- size_y: 8,- }),- ],- }).then((dashboard1) => {- H.createDashboardWithTabs({- name: "Dashboard 2",- tabs: [- { id: 3, name: "Tab 3" },- { id: 4, name: "Tab 4" },- ],- dashcards: [- createMockDashboardCard({- id: -1,- card_id: ORDERS_QUESTION_ID,- dashboard_tab_id: 3,- size_x: 8,- size_y: 8,- }),- createMockDashboardCard({- id: -2,- card_id: ORDERS_QUESTION_ID,- dashboard_tab_id: 4,- visualization_settings: {- column_settings: {- '["name","ID"]': {- click_behavior: {- type: "link",- linkType: "dashboard",- targetId: dashboard1.id,- tabId: dashboard1.tabs[1].id,- parameterMapping: {},- },- },- },- },- col: 8,- size_x: 8,- size_y: 8,- }),- ],- }).then((dashboard2) => H.visitDashboard(dashboard2.id));- });- H.goToTab("Tab 4");- H.getDashboardCard().within(() =>- cy.findAllByRole("gridcell").eq(0).click(),- );- cy.findByTestId("dashboard-name-heading").should(- "have.value",- "Dashboard 1",- );- H.assertTabSelected("Tab 2");- });-});--describe("issue 52484", () => {- const questionDetails = {- native: {- query: "SELECT ID, RATING FROM PRODUCTS [[WHERE RATING = {{rating}}]]",- "template-tags": {- rating: {- id: "56708d23-6f01-42b7-98ed-f930295d31b9",- name: "rating",- type: "number",- "display-name": "Rating",- },- },- },- parameters: [- {- id: "56708d23-6f01-42b7-98ed-f930295d31b9",- name: "Rating",- slug: "rating",- type: "number/=",- target: ["dimension", ["template-tag", "rating"]],- },- ],- };-- beforeEach(() => {- H.restore();- cy.signInAsNormalUser();- });-- it("should allow to use click behaviors with numeric columns that are not database fields (metabase#52484)", () => {- H.createNativeQuestionAndDashboard({ questionDetails }).then(- ({ body: { dashboard_id } }) => {- H.visitDashboard(dashboard_id);- },- );-- cy.log("setup a dashboard with a click behavior");- H.editDashboard();- H.setFilter("Number", "Equal to");- H.selectDashboardFilter(H.getDashboardCard(), "Rating");- H.dashboardParametersDoneButton().click();- H.showDashboardCardActions();- cy.findByLabelText("Click behavior").click();- H.sidebar().within(() => {- cy.findByText("ID").click();- cy.findByText("Update a dashboard filter").click();- cy.findByText("Number").click();- });- H.popover().findByText("ID").click();- H.saveDashboard();-- cy.log("update a dashboard filter by clicking on a ID column value");- H.getDashboardCard().findByText("2").click();- H.filterWidget().findByDisplayValue("2").should("be.visible");-- cy.log("verify query results for the new filter");- H.getDashboardCard().within(() => {- cy.findByText("27").should("be.visible");- cy.findByText("123").should("be.visible");- });- });-});--describe("issue 40396", { tags: "@external " }, () => {- const tableName = "many_data_types";-- beforeEach(() => {- H.restore("postgres-writable");- H.resetTestTable({ type: "postgres", table: tableName });- cy.signInAsAdmin();- H.resyncDatabase({ dbId: WRITABLE_DB_ID });- cy.intercept("POST", "/api/dashboard/*/dashcard/*/card/*/query").as(- "dashcardQuery",- );- });-- it("should be possible to use dashboard filters with native enum fields (metabase#40396)", () => {- cy.log("create a dashboard with a question with a type/Enum field");- cy.request("GET", "/api/table").then(({ body: tables }) => {- const table = tables.find((table) => table.name === tableName);- cy.request("GET", `/api/table/${table.id}/query_metadata`).then(- ({ body: metadata }) => {- const field = metadata.fields.find((field) => field.name === "enum");- cy.request("PUT", `/api/field/${field.id}`, {- semantic_type: "type/Enum",- });-- H.createQuestionAndDashboard({- questionDetails: {- database: table.db_id,- query: { "source-table": table.id },- },- }).then(({ body: { dashboard_id } }) => {- H.visitDashboard(dashboard_id);- cy.wait("@dashcardQuery");- });- },- );- });-- cy.log("verify that a enum field can be mapped to a parameter");- H.editDashboard();- H.setFilter("Text or Category", "Is");- H.selectDashboardFilter(H.getDashboardCard(), "Enum");- H.saveDashboard();-- cy.log("verify that filtering on a enum field works");- H.filterWidget().click();- H.popover().within(() => {- cy.findByText("beta").click();- cy.button("Add filter").click();- });- cy.wait("@dashcardQuery");- H.tableInteractiveScrollContainer().scrollTo("right");- H.getDashboardCard().findAllByText("beta").should("have.length.gte", 1);- });-});--describe("issue 52627", () => {- const questionDetails = {- display: "bar",- query: {- "source-table": ORDERS_ID,- aggregation: [- ["avg", ["field", ORDERS.TOTAL, null]],- ["avg", ["field", ORDERS.DISCOUNT, null]],- ],- breakout: [["field", ORDERS.CREATED_AT, { "temporal-unit": "month" }]],- },- };-- const parameterDetails = {- name: "Category",- slug: "category",- id: "b6ed2d71",- type: "string/=",- sectionId: "string",- default: ["Gadget"],- };-- const parameterTarget = [- "dimension",- ["field", PRODUCTS.CATEGORY, { "source-field": ORDERS.PRODUCT_ID }],- { "stage-number": 0 },- ];-- const dashboardDetails = {- parameters: [parameterDetails],- };-- beforeEach(() => {- H.restore();- cy.signInAsAdmin();- cy.intercept("POST", "/api/dataset").as("dataset");- });-- it("should remove an empty query stage after a dashboard drill-thru (metabase#52627)", () => {- H.createQuestionAndDashboard({ questionDetails, dashboardDetails }).then(- ({ body: { id, card_id, dashboard_id } }) => {- H.addOrUpdateDashboardCard({- dashboard_id,- card_id,- card: {- id,- parameter_mappings: [- {- card_id: card_id,- parameter_id: parameterDetails.id,- target: parameterTarget,- },- ],- },- });- H.visitDashboard(dashboard_id);- },- );- H.chartPathWithFillColor("#A989C5").first().click();- H.popover().findByText("See this month by week").click();- cy.wait("@dataset");- cy.findByTestId("qb-filters-panel").findByText(- "Product → Category is Gadget",- );- H.summarize();- H.rightSidebar().findByText("Average of Total").should("be.visible");- });-});--describe("issue 52918", () => {- beforeEach(() => {- H.restore();- cy.signInAsAdmin();- });-- it("should re-position the parameter dropdown when its size changes (metabase#52918)", () => {- H.visitDashboard(ORDERS_DASHBOARD_ID);- H.editDashboard();- H.setFilter("Date picker", "All Options");- H.sidebar().findByLabelText("No default").click();- H.popover().within(() => {- cy.findByText("Fixed date range…").click();- cy.findByText("Between").should("be.visible");- });- cy.log("check that there is no overflow in the popover");- H.popover().should(([element]) => {- expect(element.offsetWidth).to.gte(element.scrollWidth);- });- });-});--describe("issue 54236", () => {- beforeEach(() => {- H.restore();- cy.signInAsNormalUser();- cy.clock(new Date("2025-02-26"));- });-- it("should show correct date range in the date picker (metabase#54236)", () => {- H.visitDashboard(ORDERS_DASHBOARD_ID);- H.editDashboard();- H.setFilter("Date picker", "All Options");- H.sidebar().findByLabelText("No default").click();- H.popover().within(() => {- cy.findByText("Relative date range…").click();- cy.findByText("Next").click();- cy.findByDisplayValue("30").clear().type("1");- cy.findAllByDisplayValue("day").filter(":visible").click();- });- H.popover().should("have.length", 2).last().findByText("quarter").click();- H.popover().within(() => {- cy.icon("arrow_left_to_line").click();- cy.findByDisplayValue("4").clear().type("1");- cy.findByText("Jul 1 – Sep 30, 2025").should("be.visible");- cy.findByText("Apr 1 – Jun 30, 2025").should("not.exist");- });- });-});--describe("issue 17061", () => {- const questionDetails = {- query: {- "source-table": PEOPLE_ID,- "order-by": [["asc", ["field", PEOPLE.ID, null]]],- limit: 1,- },- };-- const parameterDetails = {- name: "State",- slug: "state",- id: "5aefc725",- type: "string/=",- sectionId: "location",- };-- const dashboardDetails = {- parameters: [parameterDetails],- enable_embedding: true,- embedding_params: {- [parameterDetails.slug]: "enabled",- },- };-- const getParameterMapping = (cardId) => ({- parameter_id: parameterDetails.id,- card_id: cardId,- target: ["dimension", ["field", "STATE", { "base-type": "type/Text" }]],- });-- beforeEach(() => {- H.restore();- cy.signInAsAdmin();- cy.intercept("GET", "/api/public/dashboard/*/dashcard/*/card/*").as(- "publicDashcardData",- );- });-- it("should not send multiple query requests for the same dashcards when opening a public dashboard with parameters (metabase#17061)", () => {- H.createQuestionAndDashboard({- questionDetails,- dashboardDetails,- }).then(({ body: dashcard, questionId }) => {- H.updateDashboardCards({- dashboard_id: dashcard.dashboard_id,- cards: [- {- card_id: questionId,- parameter_mappings: [getParameterMapping(questionId)],- },- ],- });- H.visitPublicDashboard(dashcard.dashboard_id);- });-- H.getDashboardCard().findByText("1").should("be.visible");- cy.get("@publicDashcardData.all").should("have.length", 1);- });-});--// TODO ranquild unskip after v54 release-describe("issue 48824", { tags: "@skip" }, () => {- const dateParameter = {- id: "abc",- name: "Date filter",- slug: "filter-date",- type: "date/all-options",- default: "past30days-from-7days",- };-- beforeEach(() => {- H.restore();- cy.signInAsNormalUser();- });-- it("should correctly translate relative filters in dashboards (metabase#48824)", () => {- cy.log("set locale");- cy.request("GET", "/api/user/current").then(({ body: user }) => {- cy.request("PUT", `/api/user/${user.id}`, { locale: "de" });- });-- cy.log("add a date parameter with a relative default value to a dashboard");- cy.request("PUT", `/api/dashboard/${ORDERS_DASHBOARD_ID}`, {- parameters: [dateParameter],- });- H.updateDashboardCards({- dashboard_id: ORDERS_DASHBOARD_ID,- cards: [- {- card_id: ORDERS_QUESTION_ID,- parameter_mappings: [- {- card_id: ORDERS_QUESTION_ID,- parameter_id: dateParameter.id,- target: ["dimension", ["field", ORDERS.CREATED_AT, null]],- },- ],- },- ],- });-- cy.log("check translations");- H.visitDashboard(ORDERS_DASHBOARD_ID, {- params: { [dateParameter.slug]: "past30days" },- });-- cy.log("Previous 30 days");- H.filterWidget().findByText("Vorheriger 30 Tage").should("be.visible");- H.filterWidget().icon("revert").click();-- cy.log("Previous 30 days, starting 7 days ago");- H.filterWidget()- .findByText("Vorheriger 30 Tage, ab vor 7 tage")- .should("be.visible");- });-});--describe("issue 62627", () => {- beforeEach(() => {- H.restore();- cy.signInAsNormalUser();- });-- function toggleLinkedFilter(parameterName) {- cy.button(parameterName)- .parent()- .findByRole("switch")- .click({ force: true });- }-- it("should properly link inline parameters (metabase#62627)", () => {- H.visitDashboard(ORDERS_DASHBOARD_ID);- H.editDashboard();-- cy.log("add a top-level filter");- H.setFilter("Text or Category", "Is");- H.selectDashboardFilter(H.getDashboardCard(), "Vendor");- H.setDashboardParameterName("Vendor");- H.dashboardParameterSidebar().button("Done").click();-- cy.log("add an inline card filter");- H.showDashboardCardActions();- H.getDashboardCard()- .realHover({ scrollBehavior: "bottom" })- .findByLabelText("Add a filter")- .click();- H.popover().findByText("Text or Category").click();- H.selectDashboardFilter(H.getDashboardCard(), "Category");- H.setDashboardParameterName("Category");- H.dashboardParameterSidebar().within(() => {- cy.findByText("Linked filters").click();- toggleLinkedFilter("Vendor");- });- H.saveDashboard();-- cy.log(- "verify that the inline parameter is linked to the top-level parameter",- );- H.dashboardParametersContainer().within(() => H.filterWidget().click());- H.popover().within(() => {- cy.findByText("Balistreri-Muller").click();- cy.button("Add filter").click();- });- H.getDashboardCard().within(() => H.filterWidget().click());- H.popover().within(() => {- cy.findByText("Widget").should("be.visible");- cy.findByText("Gadget").should("not.exist");- });-- cy.log("make the top-level parameter be linked to the inline parameter");- H.editDashboard();- H.getDashboardCard().findByTestId("editing-parameter-widget").click();- H.dashboardParameterSidebar().within(() => {- cy.findByText("Linked filters").click();- toggleLinkedFilter("Vendor");- });- H.editingDashboardParametersContainer()- .findByTestId("editing-parameter-widget")- .click();- H.dashboardParameterSidebar().within(() => {- cy.findByText("Linked filters").click();- toggleLinkedFilter("Category");- });- H.saveDashboard();-- cy.log(- "verify that the top-level parameter is linked to the inline parameter",- );- H.dashboardParametersContainer().within(() =>- H.filterWidget().icon("close").click(),- );- H.getDashboardCard().within(() => H.filterWidget().click());- H.popover().within(() => {- cy.findByText("Gadget").click();- cy.button("Add filter").click();- });- H.dashboardParametersContainer().within(() => H.filterWidget().click());- H.popover().within(() => {- cy.findByText("Barrows-Johns").should("be.visible");- cy.findByText("Americo Sipes and Sons").should("not.exist");- });- });-});--describe("issue 55678", () => {- const parameterDetails = {- name: "date",- slug: "date",- id: "f8ec7c71",- type: "date/all-options",- sectionId: "date",- default: "2020-01-01~2024-12-31",- };-- const questionDetails = {- name: "Orders",- query: {- "source-table": ORDERS_ID,- aggregation: [["count"]],- breakout: [- [- "field",- ORDERS.CREATED_AT,- { "base-type": "type/DateTime", "temporal-unit": "month" },- ],- ],- },- display: "line",- };-- const dashboardDetails = {- name: "Dashboard",- parameters: [parameterDetails],- };-- function setupDashboard() {- return H.createQuestion(questionDetails).then(- ({ body: { id: card_id } }) => {- H.createDashboard(dashboardDetails).then(- ({ body: { id: dashboard_id } }) => {- H.addOrUpdateDashboardCard({- dashboard_id,- card_id,- card: {- parameter_mappings: [- {- card_id,- parameter_id: parameterDetails.id,- target: [- "dimension",- ["field", "CREATED_AT", { "base-type": "type/DateTime" }],- { "stage-number": 1 },- ],- },- ],- },- });- H.visitDashboard(dashboard_id);- },- );- },- );- }-- beforeEach(() => {- H.restore();- cy.signInAsNormalUser();- });-- it("should ignore parameters mapped to post-aggregation stages when doing query drills (metabase#55678)", () => {- setupDashboard();- H.getDashboardCard().within(() => {- H.cartesianChartCircle().first().click();- });- H.popover().findByText("See this Order").click();- H.queryBuilderFiltersPanel()- .findByText("Created At: Month is Apr 1–30, 2022")- .should("be.visible");- H.assertQueryBuilderRowCount(1);- });-});--describe("issue 14595", () => {- const dialect = "postgres";- const tableName = "many_data_types";-- function createDashboard() {- return H.getTableId({ name: tableName }).then((tableId) => {- return H.createDashboardWithQuestions({- dashboardDetails: {- parameters: [- createMockParameter({- id: "p1",- slug: "p1",- name: "p1",- type: "string/=",- sectionId: "string",- }),- createMockParameter({- id: "p2",- slug: "p2",- name: "p2",- type: "string/=",- sectionId: "string",- }),- createMockParameter({- id: "p3",- slug: "p3",- name: "p3",- type: "string/=",- sectionId: "string",- }),- ],- },- questions: [- {- name: "Orders",- query: { "source-table": ORDERS_ID },- },- {- name: "Products",- query: { "source-table": PRODUCTS_ID },- },- {- name: "Many data types",- database: WRITABLE_DB_ID,- query: { "source-table": tableId },- },- ],- }).then(({ dashboard }) => {- return dashboard.id;- });- });- }-- function mapParameters() {- cy.findByTestId("fixed-width-filters").findByText("p1").click();- H.selectDashboardFilter(H.getDashboardCard(0), "Source");- cy.findByTestId("fixed-width-filters").findByText("p2").click();- H.selectDashboardFilter(H.getDashboardCard(1), "Category");- cy.findByTestId("fixed-width-filters").findByText("p3").click();- H.selectDashboardFilter(H.getDashboardCard(2), "String");- }-- function assertLinkedFilterSettings({- parameterName,- compatibleParameterNames,- incompatibleParameterNames,- }) {- cy.findByTestId("fixed-width-filters").findByText(parameterName).click();- H.sidebar().within(() => {- cy.findByText("Linked filters").click();- compatibleParameterNames.forEach((compatibleParameterName) => {- cy.findByTestId("compatible-parameters")- .findByText(compatibleParameterName)- .should("be.visible");- });- incompatibleParameterNames.forEach((incompatibleParameterName) => {- cy.findByTestId("incompatible-parameters")- .findByText(incompatibleParameterName)- .should("be.visible");- });- });- }-- function assertParameterSettings() {- assertLinkedFilterSettings({- parameterName: "p1",- compatibleParameterNames: ["p2"],- incompatibleParameterNames: ["p3"],- });- assertLinkedFilterSettings({- parameterName: "p2",- compatibleParameterNames: ["p1"],- incompatibleParameterNames: ["p3"],- });- assertLinkedFilterSettings({- parameterName: "p3",- compatibleParameterNames: [],- incompatibleParameterNames: ["p1", "p2"],- });- }-- beforeEach(() => {- H.restore(`${dialect}-writable`);- H.resetTestTable({ type: dialect, table: tableName });- cy.signInAsAdmin();- H.resyncDatabase({ dbId: WRITABLE_DB_ID, tableName });- });-- it("should not see parameters that cannot be linked to the current parameter in parameter settings (metabase#14595)", () => {- createDashboard().then((dashboardId) => H.visitDashboard(dashboardId));- H.editDashboard();- mapParameters();- assertParameterSettings();- });-});--describe("issue 44090", () => {- const parameterDetails = {- name: "p1",- slug: "string",- id: "f8ec7c71",- type: "string/=",- };-- const questionDetails = {- name: "Orders",- query: {- "source-table": REVIEWS_ID,- },- };-- const dashboardDetails = {- name: "Dashboard",- parameters: [parameterDetails],- };-- beforeEach(() => {- H.restore();- cy.signInAsNormalUser();-- H.createQuestion(questionDetails).then(({ body: { id: card_id } }) => {- H.createDashboard(dashboardDetails).then(- ({ body: { id: dashboard_id } }) => {- H.addOrUpdateDashboardCard({- dashboard_id,- card_id,- card: {- parameter_mappings: [- {- card_id,- parameter_id: parameterDetails.id,- target: ["dimension", ["field", REVIEWS.BODY, {}]],- },- ],- },- });- H.visitDashboard(dashboard_id);- },- );- });- });-- it("should not overflow the dashboard header when a filter contains a long value that contains spaces (metabase#44090)", () => {- const LONG_VALUE =- "Minima non hic doloribus ipsa dolore ratione in numquam. Minima eos vel harum velit. Consequatur consequuntur culpa sed eum";-- H.filterWidget().click();- H.popover()- .first()- .within(() => {- cy.findByPlaceholderText("Search the list").type(LONG_VALUE);- cy.button("Add filter").click();- });-- H.filterWidget().then(($el) => {- const { width } = $el[0].getBoundingClientRect();- cy.wrap(width).should("be.lt", 300);- });- });-- it("should not overflow the dashboard header when a filter contains a long value that does not contain spaces (metabase#44090)", () => {- const LONG_VALUE =- "MinimanonhicdoloribusipsadolorerationeinnumquamMinimaeosvelharumvelitConsequaturconsequunturculpasedeum";-- H.filterWidget().click();- H.popover()- .first()- .within(() => {- cy.findByPlaceholderText("Search the list").type(LONG_VALUE);- cy.button("Add filter").click();- });-- H.filterWidget().then(($el) => {- const { width } = $el[0].getBoundingClientRect();- cy.wrap(width).should("be.lt", 300);- });- });-});--describe("issue 47951", () => {- beforeEach(() => {- H.restore();- cy.signInAsAdmin();- H.activateToken("pro-self-hosted");- });-- it("should do X (metabase#47951)", () => {- cy.log("set up permissions");- cy.updatePermissionsGraph({- [USER_GROUPS.ALL_USERS_GROUP]: {- [SAMPLE_DB_ID]: {- "view-data": "unrestricted",- "create-queries": "no",- },- },- [USER_GROUPS.DATA_GROUP]: {- [SAMPLE_DB_ID]: {- "view-data": "unrestricted",- "create-queries": "no",- },- },- });-- cy.log("set up remapping");- cy.request("PUT", `/api/field/${ORDERS.PRODUCT_ID}`, {- has_field_values: "list",- });- cy.request("PUT", `/api/field/${REVIEWS.PRODUCT_ID}`, {- has_field_values: "list",- });- cy.request("POST", `/api/field/${ORDERS.PRODUCT_ID}/dimension`, {- name: "Product ID",- type: "external",- human_readable_field_id: PRODUCTS.TITLE,- });- cy.request("POST", `/api/field/${REVIEWS.PRODUCT_ID}/dimension`, {- name: "Product ID",- type: "external",- human_readable_field_id: PRODUCTS.TITLE,- });-- cy.log("create a dashboard");- const parameter = createMockParameter({- id: "p1",- slug: "p1",- type: "id",- sectionId: "id",- default: 1,- });- H.createDashboardWithQuestions({- dashboardDetails: {- parameters: [parameter],- },- questions: [- { name: "q1", query: { "source-table": ORDERS_ID } },- { name: "q2", query: { "source-table": REVIEWS_ID } },- ],- }).then(({ dashboard: dashboard, questions: [card1, card2] }) => {- H.updateDashboardCards({- dashboard_id: dashboard.id,- cards: [- {- card_id: card1.id,- parameter_mappings: [- {- card_id: card1.id,- parameter_id: parameter.id,- target: ["dimension", ["field", ORDERS.PRODUCT_ID, null]],- },- ],- },- {- card_id: card2.id,- parameter_mappings: [- {- card_id: card2.id,- parameter_id: parameter.id,- target: ["dimension", ["field", REVIEWS.PRODUCT_ID, null]],- },- ],- },- ],- });- cy.wrap(dashboard.id).as("dashboardId");- });-- cy.log("log in as a normal user and open the dashboard");- cy.signInAsNormalUser();- H.visitDashboard("@dashboardId");-- cy.log("check remapping for default values");- H.filterWidget().findByText("Rustic Paper Wallet").should("be.visible");-- cy.log("check remapping for dropdown values");- H.filterWidget().click();- H.popover().within(() => {- cy.findByText("Rustic Paper Wallet").should("be.visible");- cy.findByText("Aerodynamic Bronze Hat").should("be.visible");- });- });-});--describe("issue 59306", () => {- beforeEach(() => {- H.restore();- cy.signInAsAdmin();-- const parameter = createMockParameter({- id: "p1",- slug: "p1",- type: "string/=",- sectionId: "string",- default: undefined,- values_query_type: "none",- });-- H.createDashboardWithQuestions({- dashboardDetails: {- parameters: [parameter],- },- questions: [{ name: "q1", query: { "source-table": PRODUCTS_ID } }],- }).then(({ dashboard, questions: [card] }) => {- H.updateDashboardCards({- dashboard_id: dashboard.id,- cards: [- {- card_id: card.id,- parameter_mappings: [- {- card_id: card.id,- parameter_id: parameter.id,- target: ["dimension", ["field", PRODUCTS.CATEGORY, null]],- has_field_values: "input",- },- ],- },- ],- }).then(() => {- H.visitDashboard(dashboard.id);- });- });- });-- it("should not overflow the filter box (metabase#59306)", () => {- H.filterWidget().click();- H.popover().within(() => {- cy.findByPlaceholderText("Enter some text")- .type("asdf".repeat(20))- .invoke("outerWidth")- .should("be.lt", 400);- });- });-});--describe("Issue 60987", () => {- beforeEach(() => {- H.restore();- cy.signInAsAdmin();-- H.createQuestionAndDashboard({- questionDetails: {- type: "question",- query: {- "source-table": ORDERS_ID,- joins: [- {- "source-table": PRODUCTS_ID,- fields: "all",- strategy: "left-join",- alias: "Products",- condition: [- "=",- [- "field",- ORDERS.PRODUCT_ID,- {- "base-type": "type/Integer",- },- ],- [- "field",- PRODUCTS.ID,- {- "base-type": "type/BigInteger",- "join-alias": "Products",- },- ],- ],- },- ],- },- },- }).then((response) => {- H.visitDashboard(response.body.dashboard_id);- });- });-- it("should show the empty state for parameters when searching the in the parameter target picker popover (metabase#60987)", () => {- H.editDashboard();- H.setFilter("Text or Category", "Is");- H.getDashboardCard().findByText("Select…").click();- H.popover().findByPlaceholderText("Find...").type("aa");- H.popover().findByText("Didn't find any results").should("be.visible");- });-});--describe("Issue 60987", () => {- beforeEach(() => {- H.restore();- cy.signInAsAdmin();-- H.createQuestionAndDashboard({- questionDetails: {- type: "question",- query: {- "source-table": ORDERS_ID,- joins: [- {- "source-table": PRODUCTS_ID,- fields: "all",- strategy: "left-join",- alias: "Products",- condition: [- "=",- [- "field",- ORDERS.PRODUCT_ID,- {- "base-type": "type/Integer",- },- ],- [- "field",- PRODUCTS.ID,- {- "base-type": "type/BigInteger",- "join-alias": "Products",- },- ],- ],- },- ],- },- },- }).then((response) => {- H.visitDashboard(response.body.dashboard_id);- });-- H.editDashboard();- H.setFilter("Text or Category", "Is");- H.getDashboardCard().findByText("Select…").click();- });-- it("should show the empty state for parameters when searching the in the parameter target picker popover (metabase#60987)", () => {- H.popover().within(() => {- cy.findByPlaceholderText("Find...").type("aa");- cy.findByText("Didn't find any results")- .should("be.visible")- .should("have.css", "color", "rgba(7, 23, 34, 0.62)"); // the text "text-medium"- });- });-});--describe("Issue 46767", () => {- beforeEach(() => {- H.restore();- cy.signInAsAdmin();-- H.createQuestionAndDashboard({- questionDetails: {- type: "question",- query: {- "source-table": ORDERS_ID,- joins: [- {- "source-table": PRODUCTS_ID,- fields: "all",- strategy: "left-join",- alias: "Products",- condition: [- "=",- [- "field",- ORDERS.PRODUCT_ID,- {- "base-type": "type/Integer",- },- ],- [- "field",- PRODUCTS.ID,- {- "base-type": "type/BigInteger",- "join-alias": "Products",- },- ],- ],- },- ],- },- },- }).then((response) => {- H.visitDashboard(response.body.dashboard_id);- });-- H.editDashboard();- H.setFilter("Text or Category", "Is");- H.getDashboardCard().findByText("Select…").click();- });-- it("search results for parameter target picker should not show empty sections (metabase#46767)", () => {- H.popover().within(() => {- cy.findByPlaceholderText("Find...").type("Ean");- cy.findByText("Products").should("be.visible");- cy.findByText("User").should("not.exist");- });- });-});--describe("issue 46541", () => {- const TARGET_FILTER = {- name: "Target filter",- slug: "target-filter",- id: "ffa421da",- type: "number/>=",- sectionId: "number",- };-- const OTHER_FILTER = {- name: "Other filter",- slug: "other-filter",- id: "dfaa3356",- type: "number/>=",- sectionId: "number",- };-- beforeEach(() => {- H.restore();- cy.signInAsAdmin();-- H.createQuestionAndDashboard({- questionDetails: {- query: { "source-table": ORDERS_ID },- },- dashboardDetails: {- name: "Dashboard A",- },- }).then(({ body }) => {- cy.wrap(body.dashboard_id).as("dashboardA");-- H.createQuestionAndDashboard({- questionDetails: {- query: { "source-table": ORDERS_ID },- },- dashboardDetails: {- name: "Dashboard B",- parameters: [TARGET_FILTER, OTHER_FILTER],- },- }).then(({ body }) => {- cy.wrap(body.dashboard_id).as("dashboardB");-- H.updateDashboardCards({- dashboard_id: body.dashboard_id,- cards: [- {- card_id: body.card_id,- parameter_mappings: [- {- parameter_id: TARGET_FILTER.id,- card_id: body.card_id,- target: ["dimension", ["field", ORDERS.TOTAL, null]],- },- {- parameter_id: OTHER_FILTER.id,- card_id: body.card_id,- target: ["dimension", ["field", ORDERS.SUBTOTAL, null]],- },- ],- },- ],- });-- cy.log("Set parameter value on Dashboard B");- H.visitDashboard("@dashboardB");- H.filterWidget(OTHER_FILTER).click();- H.popover().within(() => {- cy.findByPlaceholderText("Enter a number").type("10");- cy.button("Add filter").click();- });-- cy.log("Set up click behaviour on Dashboard A");- H.visitDashboard("@dashboardA");- H.editDashboard();-- H.showDashboardCardActions();- cy.findByLabelText("Click behavior").click();-- H.sidebar().within(() => {- cy.findByText("Tax").click();- cy.findByText("Go to a custom destination").click();- cy.findByText("Dashboard").click();- });-- H.entityPickerModal().within(() => {- cy.findByText("Our analytics").click();- cy.findByText("Dashboard B").click();- });-- H.sidebar().findByText(TARGET_FILTER.name).click();- H.popover().findByText("Tax").click();- H.saveDashboard();- });- });- });-- it("should reset other filters when coming to a dashboard from a click action with a filter (metabase#46541)", () => {- cy.log("Navigate from Dashboard A to Dashboard B with a click action");- H.tableInteractiveBody().findByText("2.07").click();-- H.filterWidget(TARGET_FILTER).should("contain", "2.07");- H.filterWidget(OTHER_FILTER).should("not.contain", "10");- });-});--describe("issue 46372", () => {- beforeEach(() => {- H.restore();- cy.signInAsAdmin();- });-- it("should not show a scrollbar when auto-connecting a dashcard filter (metabase#46372)", () => {- H.createDashboardWithQuestions({- questions: [- { name: "Question A", query: { "source-table": PRODUCTS_ID } },- { name: "Question B", query: { "source-table": PRODUCTS_ID } },- ],- }).then(({ dashboard }) => {- H.visitDashboard(dashboard.id);- H.editDashboard(dashboard.id);-- H.setFilter("Text or Category", "Is");- H.selectDashboardFilter(cy.findAllByTestId("dashcard").first(), "Title");- H.undoToast().findByRole("button", { name: "Auto-connect" }).click();-- H.main().findByText("Auto-connected").should("be.visible");- H.main()- .findByText("Auto-connected")- .parent()- .parent()- .then(($body) => {- cy.wrap($body[0].scrollHeight).should("eq", $body[0].offsetHeight);- });- });- });-});--describe("issue 49319", () => {- beforeEach(() => {- H.restore();- cy.signInAsNormalUser();- });-- it("should ignore parameters that not exist in the saved dashboard in edit mode (metabase#49319)", () => {- cy.log("open an existing dashboard");- H.visitDashboard(ORDERS_DASHBOARD_ID);-- cy.log("add a parameter and save the dashboard");- H.editDashboard();- H.setFilter("Text or Category", "Is");- H.selectDashboardFilter(H.getDashboardCard(), "Vendor");- H.saveDashboard();-- cy.log("add another parameter to the dashboard with a default value");- H.editDashboard();- H.setFilter("Text or Category", "Is");- H.selectDashboardFilter(H.getDashboardCard(), "Category");- H.dashboardParameterSidebar().findByText("No default").click();- H.popover().within(() => {- cy.findByText("Gadget").click();- cy.button("Add filter").click();- });- H.dashboardParameterSidebar().button("Done").click();-- cy.log("change the value for the saved parameter");- cy.findByTestId("fixed-width-filters").findByText("Text").click();- H.dashboardParameterSidebar().findByText("No default").click();- H.popover().within(() => {- cy.findByText("Americo Sipes and Sons").click();- cy.findByText("Barrows-Johns").click();- cy.button("Add filter").click();- });- H.dashboardParameterSidebar().button("Done").click();-- cy.log("the unsaved parameter should be ignored in edit mode");- H.assertTableRowsCount(179);-- cy.log("both parameters should be applied when the dashboard is saved");- H.saveDashboard();- H.assertTableRowsCount(82);- });-});--describe("issue #66670", () => {- const questionA = {- name: "Question A",- query: {- "source-table": PRODUCTS_ID,- limit: 10,- },- };-- const questionB = {- name: "Question B",- query: {- "source-table": PRODUCTS_ID,- aggregation: [["count"]],- breakout: [["field", PRODUCTS.CATEGORY, null]],- },- };-- beforeEach(() => {- H.restore();- cy.signInAsAdmin();- cy.intercept("PUT", "/api/dashboard/*").as("updateDashboard");- cy.intercept("GET", "/api/revision*").as("revisionHistory");- });-- it("should handle dashboard filter with permanently deleted question value source (metabase#66670)", () => {- cy.log("Step 1: Create a new dashboard");- H.createDashboard({ name: "Test Dashboard UXW-2494" }).then(- ({ body: { id: dashboardId } }) => {- cy.log("Step 2: Add Question A to the dashboard");- H.createQuestion(questionA).then(({ body: { id: questionAId } }) => {- H.updateDashboardCards({- dashboard_id: dashboardId,- cards: [- {- card_id: questionAId,- row: 0,- col: 0,- size_x: 12,- size_y: 8,- },- ],- });-- cy.log("Step 3: Create Question B (not added to dashboard)");- H.createQuestion(questionB).then(({ body: { id: questionBId } }) => {- cy.log(- "Step 4: Edit dashboard, add filter with Question B as value source",- );- H.visitDashboard(dashboardId);- H.editDashboard();- H.setFilter("Text or Category", "Is");-- // Map filter to Question A- cy.findByText("Select…").click();- H.popover().within(() => cy.findByText("Category").click());-- // Set filter value source to Question B- H.setFilterQuestionSource({- question: questionB.name,- field: "Category",- });-- cy.log("Step 5: Save the dashboard");- H.saveDashboard();- cy.wait("@updateDashboard");-- cy.log("Step 5b: Update the title and save again");- H.editDashboard();- cy.findByTestId("dashboard-header")- .findByDisplayValue("Test Dashboard UXW-2494")- .clear()- .type("Updated Dashboard Title");- H.saveDashboard();- cy.wait("@updateDashboard");-- cy.log("Step 6: Move Question B to the trash");- H.visitQuestion(questionBId);- H.openQuestionActions();- H.popover().findByText("Move to trash").click();- H.modal().findByText("Move to trash").click();-- cy.log(- "Step 8: Revert dashboard to earlier version where filter used Question B",- );- H.visitDashboard(dashboardId);- H.openDashboardInfoSidebar();- H.sidesheet().within(() => {- cy.findByRole("tab", { name: "History" }).click();- cy.wait("@revisionHistory");- // Click revert on the version that added the filter with Question B source- cy.findByTestId("dashboard-history-list")- .findAllByLabelText(/revert to You edited this/i)- .first()- .click();- });- // Close sidesheet- H.sidesheet().findByLabelText("Close").click();-- cy.log("Step 9: Permanently delete Question B from trash");- cy.request("DELETE", `/api/card/${questionBId}`);-- cy.log("Step 10: Try to add another filter and save → Save fails");- H.editDashboard();- H.setFilter("Number");- cy.findByText("Select…").click();- H.popover().within(() => cy.findByText("Price").click());-- cy.intercept("PUT", `/api/dashboard/${dashboardId}`).as(- "saveDashboard",- );- cy.findByTestId("edit-bar").button("Save").click();-- cy.wait("@saveDashboard").then((interception) => {- expect(interception.response.statusCode).to.eq(200);- });-- cy.log(- "Step 11: Edit existing filter, click Edit → modal loads indefinitely",- );- H.visitDashboard(dashboardId);- H.editDashboard();- H.filterWidget({ isEditing: true }).first().click();- H.dashboardParameterSidebar().findByText("Edit").click();-- H.modal().should("be.visible");- H.modal().within(() => {- cy.findByText("Where values should come from", {- timeout: 10000,- }).should("be.visible");- cy.findByText("From connected fields").should("be.visible");- cy.findByText("From another model or question").should(- "be.visible",- );- cy.findByText("Custom list").should("be.visible");- });- });- });- },- );- });-});diff --git a/e2e/test/scenarios/filters-reproductions/dashboard-filters-reproductions-2.cy.spec.js b/e2e/test/scenarios/filters-reproductions/dashboard-filters-reproductions-2.cy.spec.jsnew file mode 100644index 00000000000..1a3e7bf5796--- /dev/null+++ b/e2e/test/scenarios/filters-reproductions/dashboard-filters-reproductions-2.cy.spec.js@@ -0,0 +1,2782 @@+const { H } = cy;++import {+ SAMPLE_DB_ID,+ USER_GROUPS,+ WRITABLE_DB_ID,+} 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 {+ createMockDashboardCard,+ createMockParameter,+} from "metabase-types/api/mocks";++const {+ ORDERS,+ ORDERS_ID,+ PRODUCTS,+ PRODUCTS_ID,+ REVIEWS,+ REVIEWS_ID,+ PEOPLE,+ PEOPLE_ID,+} = SAMPLE_DATABASE;++describe("issue 44288", () => {+ const questionDetails = {+ name: "SQL question",+ type: "question",+ query: { "source-table": PRODUCTS_ID, limit: 10 },+ };++ const modelDetails = {+ name: "SQL model",+ type: "model",+ native: { query: "SELECT * FROM PRODUCTS LIMIT 10" },+ };++ const parameterDetails = {+ name: "Text",+ slug: "text",+ id: "27454068",+ type: "string/=",+ sectionId: "string",+ };++ const dashboardDetails = {+ parameters: [parameterDetails],+ enable_embedding: true,+ embedding_params: {+ [parameterDetails.slug]: "enabled",+ },+ };++ function getDashcardDetails(dashboard, question, model) {+ return {+ dashboard_id: dashboard.id,+ cards: [+ {+ card_id: question.id,+ parameter_mappings: [+ {+ card_id: question.id,+ parameter_id: parameterDetails.id,+ target: [+ "dimension",+ ["field", PRODUCTS.CATEGORY, { "base-type": "type/Text" }],+ ],+ },+ ],+ },+ {+ card_id: model.id,+ parameter_mappings: [+ {+ card_id: model.id,+ parameter_id: parameterDetails.id,+ target: [+ "dimension",+ ["field", "CATEGORY", { "base-type": "type/Text" }],+ ],+ },+ ],+ },+ ],+ };+ }++ function verifyMapping() {+ cy.findByTestId("edit-dashboard-parameters-widget-container")+ .findByText(parameterDetails.name)+ .click();+ H.getDashboardCard(0).within(() => {+ cy.findByText(/Category/i).should("be.visible");+ });+ H.getDashboardCard(1).within(() => {+ cy.findByText(/Category/i).should("not.exist");+ cy.findByText(/Models are data sources/).should("be.visible");+ });+ }++ function verifyFilter() {+ H.filterWidget().click();+ H.popover().within(() => {+ cy.findByText("Gadget").click();+ cy.button("Add filter").click();+ });+ H.getDashboardCard(0).within(() => {+ cy.findAllByText("Gadget").should("have.length.gte", 1);+ cy.findByText("Doohickey").should("not.exist");+ });+ H.getDashboardCard(1).within(() => {+ cy.findAllByText("Gadget").should("have.length.gte", 1);+ cy.findAllByText("Doohickey").should("have.length.gte", 1);+ });+ }++ beforeEach(() => {+ H.restore();+ cy.signInAsAdmin();+ H.createQuestion(questionDetails).then(({ body: question }) => {+ H.createNativeQuestion(modelDetails).then(({ body: model }) => {+ H.createDashboard(dashboardDetails).then(({ body: dashboard }) => {+ H.updateDashboardCards(+ getDashcardDetails(dashboard, question, model),+ );+ cy.wrap(dashboard.id).as("dashboardId");+ });+ });+ });+ cy.signOut();+ });++ it("should ignore parameter mappings to a native model in a dashboard (metabase#44288)", () => {+ cy.log("regular dashboards");+ cy.signInAsNormalUser();+ H.visitDashboard("@dashboardId");+ H.editDashboard();+ verifyMapping();+ H.saveDashboard({ awaitRequest: false });+ verifyFilter();+ cy.signOut();++ cy.log("public dashboards");+ cy.signInAsAdmin();+ cy.get("@dashboardId").then((dashboardId) =>+ H.visitPublicDashboard(dashboardId),+ );+ verifyFilter();++ cy.log("embedded dashboards");+ cy.get("@dashboardId").then((dashboardId) =>+ H.visitEmbeddedPage({+ resource: { dashboard: dashboardId },+ params: {},+ }),+ );+ verifyFilter();+ });+});++describe("issue 27579", () => {+ beforeEach(() => {+ H.restore();+ cy.signInAsNormalUser();+ });++ it("should be able to remove the last exclude hour option (metabase#27579)", () => {+ H.visitDashboard(ORDERS_DASHBOARD_ID);+ H.editDashboard();+ H.setFilter("Date picker", "All Options");+ H.selectDashboardFilter(H.getDashboardCard(), "Created At");+ H.saveDashboard();+ H.filterWidget().click();+ H.popover().within(() => {+ cy.findByText("Exclude…").click();+ cy.findByText("Hours of the day…").click();+ cy.findByText("Select all").click();+ cy.findByLabelText("12 AM").should("be.checked");++ cy.findByText("Select all").click();+ cy.findByLabelText("12 AM").should("not.be.checked");+ });+ });+});++describe("issue 32804", () => {+ const question1Details = {+ name: "Q1",+ query: {+ "source-table": PRODUCTS_ID,+ },+ };++ const parameterDetails = {+ name: "Number",+ slug: "number",+ id: "27454068",+ type: "number/=",+ sectionId: "number",+ };++ const dashboardDetails = {+ parameters: [parameterDetails],+ };++ const getQuestion2Details = (card) => ({+ name: "Q2",+ query: {+ "source-table": `card__${card.id}`,+ filter: [+ "=",+ ["field", PRODUCTS.CATEGORY, { "base-type": "type/Text" }],+ "Gadget",+ ],+ },+ });++ const getParameterMapping = (card) => ({+ card_id: card.id,+ parameter_id: parameterDetails.id,+ target: [+ "dimension",+ ["field", PRODUCTS.RATING, { "base-type": "type/Integer" }],+ ],+ });++ beforeEach(() => {+ H.restore();+ cy.signInAsNormalUser();+ });++ it("should retain source query filters when drilling-thru from a dashboard (metabase#32804)", () => {+ H.createQuestion(question1Details).then(({ body: card1 }) => {+ H.createDashboardWithQuestions({+ dashboardDetails,+ questions: [getQuestion2Details(card1)],+ }).then(({ dashboard, questions: [card2] }) => {+ H.updateDashboardCards({+ dashboard_id: dashboard.id,+ cards: [+ {+ card_id: card2.id,+ parameter_mappings: [getParameterMapping(card2)],+ },+ ],+ });+ H.visitDashboard(dashboard.id, {+ params: { [parameterDetails.slug]: "4" },+ });+ });+ });+ H.filterWidget().findByText("4").should("be.visible");+ H.getDashboardCard(0).findByText("Q2").click();+ cy.findByTestId("qb-filters-panel").within(() => {+ cy.findByText("Category is Gadget").should("be.visible");+ cy.findByText("Rating is equal to 4").should("be.visible");+ });+ });+});++describe("issue 44231", () => {+ const parameterDetails = {+ id: "92eb69ea",+ name: "ID",+ sectionId: "id",+ slug: "id",+ type: "id",+ };++ const dashboardDetails = {+ parameters: [parameterDetails],+ enable_embedding: true,+ embedding_params: {+ [parameterDetails.slug]: "enabled",+ },+ };++ function getPkCardDetails(type) {+ return {+ name: "Products",+ type,+ query: { "source-table": PRODUCTS_ID },+ };+ }++ function getFkCardDetails(type) {+ return {+ name: "Orders",+ type: "model",+ query: { "source-table": ORDERS_ID },+ };+ }++ function getDashcardDetails(type, dashboard, pkCard, fkCard) {+ return {+ dashboard_id: dashboard.id,+ cards: [+ {+ card_id: pkCard.id,+ parameter_mappings: [+ {+ card_id: pkCard.id,+ parameter_id: parameterDetails.id,+ target: [+ "dimension",+ [+ "field",+ type === "model" ? "ID" : PRODUCTS.ID,+ { "base-type": "type/BigInteger" },+ ],+ ],+ },+ ],+ },+ {+ card_id: fkCard.id,+ parameter_mappings: [+ {+ card_id: fkCard.id,+ parameter_id: parameterDetails.id,+ target: [+ "dimension",+ [+ "field",+ type === "model" ? "PRODUCT_ID" : ORDERS.PRODUCT_ID,+ { "base-type": "type/BigInteger" },+ ],+ ],+ },+ ],+ },+ ],+ };+ }++ function verifyFilterByRemappedValue() {+ const productId = 144;+ const productName = "Aerodynamic Bronze Hat";++ H.filterWidget().click();+ H.popover().within(() => {+ cy.findByText(productName).click();+ cy.button("Add filter").click();+ });+ H.getDashboardCard(0).findByText(productName).should("be.visible");+ H.getDashboardCard(1)+ .findAllByText(String(productId))+ .should("have.length.above", 0);+ }++ function verifyFieldMapping(type) {+ H.createDashboardWithQuestions({+ dashboardDetails,+ questions: [getPkCardDetails(type), getFkCardDetails(type)],+ }).then(({ dashboard, questions: [pkCard, fkCard] }) => {+ H.updateDashboardCards(+ getDashcardDetails(type, dashboard, pkCard, fkCard),+ );++ H.visitDashboard(dashboard.id);+ verifyFilterByRemappedValue();++ H.visitPublicDashboard(dashboard.id);+ verifyFilterByRemappedValue();++ H.visitEmbeddedPage({+ resource: { dashboard: dashboard.id },+ params: {},+ });+ verifyFilterByRemappedValue();+ });+ }++ beforeEach(() => {+ H.restore();+ cy.signInAsAdmin();++ cy.request("PUT", `/api/field/${PRODUCTS.ID}`, {+ has_field_values: "list",+ });+ cy.request("PUT", `/api/field/${ORDERS.PRODUCT_ID}`, {+ has_field_values: "list",+ });+ cy.request("PUT", `/api/field/${PRODUCTS.TITLE}`, {+ semantic_type: "type/Name",+ });+ });++ it("should allow filtering by remapped values with questions (metabase#44231)", () => {+ verifyFieldMapping("question");+ });++ it("should allow filtering by remapped values with models (metabase#44231)", () => {+ verifyFieldMapping("model");+ });+});++describe("44047", () => {+ const questionDetails = {+ name: "Question",+ type: "question",+ query: {+ "source-table": REVIEWS_ID,+ limit: 100,+ },+ };++ const modelDetails = {+ name: "Model",+ type: "model",+ query: {+ "source-table": REVIEWS_ID,+ limit: 100,+ },+ };++ const sourceQuestionDetails = {+ name: "Source question",+ type: "question",+ query: {+ "source-table": REVIEWS_ID,+ fields: [+ ["field", REVIEWS.ID, { "base-type": "type/BigInteger" }],+ ["field", REVIEWS.RATING, { "base-type": "type/Integer" }],+ ],+ },+ };++ const parameterDetails = {+ name: "Text",+ slug: "text",+ id: "5a425670",+ type: "string/=",+ sectionId: "string",+ };++ const dashboardDetails = {+ parameters: [parameterDetails],+ };++ function getQuestionDashcardDetails(dashboard, card) {+ return {+ dashboard_id: dashboard.id,+ card_id: card.id,+ parameter_mappings: [+ {+ card_id: card.id,+ parameter_id: parameterDetails.id,+ target: [+ "dimension",+ ["field", REVIEWS.RATING, { "base-type": "type/Integer" }],+ ],+ },+ ],+ };+ }++ function getModelDashcardDetails(dashboard, card) {+ return {+ dashboard_id: dashboard.id,+ card_id: card.id,+ parameter_mappings: [+ {+ card_id: card.id,+ parameter_id: parameterDetails.id,+ target: [+ "dimension",+ ["field", "RATING", { "base-type": "type/Integer" }],+ ],+ },+ ],+ };+ }++ function verifyFilterWithRemapping() {+ H.filterWidget().click();+ H.popover().within(() => {+ cy.findByPlaceholderText("Search the list").type("Remapped");+ cy.findByText("Remapped").click();+ cy.button("Add filter").click();+ });+ }++ beforeEach(() => {+ H.restore();+ cy.signInAsAdmin();+ cy.request("PUT", `/api/field/${REVIEWS.RATING}`, {+ semantic_type: "type/Category",+ });+ cy.request("POST", `/api/field/${REVIEWS.RATING}/dimension`, {+ type: "internal",+ name: "Rating",+ });+ cy.request("POST", `/api/field/${REVIEWS.RATING}/values`, {+ values: [[1, "Remapped"]],+ });+ });++ it("should be able to use remapped values from an integer field with an overridden semantic type used for a custom dropdown source in public dashboards (metabase#44047)", () => {+ H.createQuestion(sourceQuestionDetails);+ H.createDashboardWithQuestions({+ dashboardDetails,+ questions: [questionDetails, modelDetails],+ }).then(({ dashboard, questions: cards }) => {+ H.updateDashboardCards({+ dashboard_id: dashboard.id,+ cards: [+ getQuestionDashcardDetails(dashboard, cards[0]),+ getModelDashcardDetails(dashboard, cards[1]),+ ],+ });+ cy.wrap(dashboard.id).as("dashboardId");+ });++ cy.log("verify filtering works in a regular dashboard");+ H.visitDashboard("@dashboardId");+ verifyFilterWithRemapping();++ cy.log("verify filtering works in a public dashboard");+ cy.get("@dashboardId").then(H.visitPublicDashboard);+ verifyFilterWithRemapping();+ });+});++describe("issue 45659", () => {+ const parameterDetails = {+ name: "ID",+ slug: "id",+ id: "f8ec7c71",+ type: "id",+ sectionId: "id",+ default: [10],+ };++ const questionDetails = {+ name: "People",+ query: { "source-table": PEOPLE_ID },+ };++ const dashboardDetails = {+ name: "Dashboard",+ parameters: [parameterDetails],+ enable_embedding: true,+ embedding_params: {+ [parameterDetails.slug]: "enabled",+ },+ };++ function createDashboard() {+ return H.createDashboardWithQuestions({+ dashboardDetails,+ questions: [questionDetails],+ }).then(({ dashboard, questions: [card] }) => {+ H.addOrUpdateDashboardCard({+ dashboard_id: dashboard.id,+ card_id: card.id,+ card: {+ parameter_mappings: [+ {+ card_id: card.id,+ parameter_id: parameterDetails.id,+ target: [+ "dimension",+ ["field", PEOPLE.ID, { "base-type": "type/BigInteger" }],+ ],+ },+ ],+ },+ }).then(() => ({ dashboard }));+ });+ }++ function verifyFilterWithRemapping() {+ H.filterWidget().findByText("Tressa White").should("be.visible");+ }++ beforeEach(() => {+ H.restore();+ cy.signInAsAdmin();+ cy.request("PUT", `/api/field/${PEOPLE.ID}`, {+ has_field_values: "list",+ });+ });++ it("should remap initial parameter values in public dashboards (metabase#45659)", () => {+ createDashboard().then(({ dashboard }) =>+ H.visitPublicDashboard(dashboard.id),+ );+ verifyFilterWithRemapping();+ });++ it("should remap initial parameter values in embedded dashboards (metabase#45659)", () => {+ createDashboard().then(({ dashboard }) =>+ H.visitEmbeddedPage({+ resource: { dashboard: dashboard.id },+ params: {},+ }),+ );+ verifyFilterWithRemapping();+ });+});++describe("44266", () => {+ const filterDetails = {+ name: "Equal to",+ slug: "equal_to",+ id: "10c0d4ba",+ type: "number/=",+ sectionId: "number",+ };++ const dashboardDetails = {+ name: "44266",+ parameters: [filterDetails],+ };++ const regularQuestion = {+ name: "regular",+ query: { "source-table": PRODUCTS_ID, limit: 2 },+ };++ const nativeQuestion = {+ name: "native",+ native: {+ query:+ "SELECT * from products where true [[ and price > {{price}}]] limit 5;",+ "template-tags": {+ price: {+ type: "number",+ name: "price",+ id: "b22a5ce2-fe1d-44e3-8df4-f8951f7921bc",+ "display-name": "Price",+ },+ },+ },+ };++ beforeEach(() => {+ H.restore();+ cy.signInAsAdmin();+ });++ it("should allow mapping when native and regular questions can be mapped (metabase#44266)", () => {+ H.createDashboardWithQuestions({+ dashboardDetails,+ questions: [regularQuestion, nativeQuestion],+ }).then(({ dashboard }) => {+ H.visitDashboard(dashboard.id);+ H.editDashboard();+ cy.findByTestId("edit-dashboard-parameters-widget-container")+ .findByText("Equal to")+ .click();++ H.getDashboardCard(1).findByText("Select…").click();++ H.popover().findByText("Price").click();++ H.getDashboardCard(1).findByText("Price").should("be.visible");+ });+ });+});++describe("issue 44790", () => {+ beforeEach(() => {+ H.restore();+ cy.signInAsNormalUser();+ });++ it("should handle string values passed to number and id filters (metabase#44790)", () => {+ const idFilter = {+ id: "92eb69ea",+ name: "ID",+ sectionId: "id",+ slug: "id",+ type: "id",+ };++ const numberFilter = {+ id: "10c0d4ba",+ name: "Equal to",+ slug: "equal_to",+ type: "number/=",+ sectionId: "number",+ };++ const peopleQuestionDetails = {+ query: { "source-table": PEOPLE_ID, limit: 5 },+ };++ H.createDashboardWithQuestions({+ dashboardDetails: {+ parameters: [idFilter, numberFilter],+ },+ questions: [peopleQuestionDetails],+ }).then(({ dashboard, questions: cards }) => {+ const [peopleCard] = cards;++ cy.wrap(dashboard.id).as("dashboardId");++ H.updateDashboardCards({+ dashboard_id: dashboard.id,+ cards: [+ {+ card_id: peopleCard.id,+ parameter_mappings: [+ {+ parameter_id: idFilter.id,+ card_id: peopleCard.id,+ target: ["dimension", ["field", PEOPLE.ID, null]],+ },+ {+ parameter_id: numberFilter.id,+ card_id: peopleCard.id,+ target: ["dimension", ["field", PEOPLE.LATITUDE, null]],+ },+ ],+ },+ ],+ });+ });++ cy.log("wrong value for id filter should be ignored");+ H.visitDashboard("@dashboardId", {+ params: {+ [idFilter.slug]: "{{test}}",+ },+ });+ H.getDashboardCard().should("contain", "[email protected]");++ cy.log("wrong value for number filter should be ignored");+ H.visitDashboard("@dashboardId", {+ params: {+ [numberFilter.slug]: "{{test}}",+ [idFilter.slug]: "1",+ },+ });+ H.getDashboardCard().should("contain", "[email protected]");+ });+});++describe("issue 34955", () => {+ function checkAppliedFilter(name, value) {+ cy.contains('[data-testid="parameter-widget"]', name, {+ exact: false,+ }).contains(value);+ }++ const ccName = "Custom Created At";++ const questionDetails = {+ name: "34955",+ query: {+ "source-table": ORDERS_ID,+ expressions: {+ [ccName]: [+ "field",+ ORDERS.CREATED_AT,+ { "base-type": "type/DateTime" },+ ],+ },+ fields: [+ [+ "field",+ ORDERS.ID,+ {+ "base-type": "type/BigInteger",+ },+ ],+ [+ "field",+ ORDERS.CREATED_AT,+ {+ "base-type": "type/DateTime",+ },+ ],+ [+ "expression",+ ccName,+ {+ "base-type": "type/DateTime",+ },+ ],+ ],+ limit: 2,+ },+ };++ beforeEach(() => {+ H.restore();+ cy.signInAsAdmin();++ H.createQuestionAndDashboard({+ questionDetails,+ cardDetails: {+ size_x: 16,+ size_y: 8,+ },+ }).then(({ body: { dashboard_id } }) => {+ cy.wrap(dashboard_id).as("dashboardId");++ H.visitDashboard(dashboard_id);+ H.editDashboard();++ H.setFilter("Date picker", "Single Date", "On");+ connectFilterToColumn(ccName);++ H.setFilter("Date picker", "Date Range", "Between");+ connectFilterToColumn(ccName);++ H.saveDashboard();++ // eslint-disable-next-line metabase/no-unsafe-element-filtering+ cy.findAllByRole("columnheader").eq(-2).should("have.text", "Created At");+ // eslint-disable-next-line metabase/no-unsafe-element-filtering+ cy.findAllByRole("columnheader").eq(-1).should("have.text", ccName);+ H.tableInteractiveBody()+ .findAllByRole("gridcell")+ .filter(":contains(May 15, 2024, 8:04 AM)")+ .should("have.length", 2);+ });+ });++ it("should connect specific date filter (`Between`) to the temporal custom column (metabase#34955)", () => {+ cy.get("@dashboardId").then((dashboard_id) => {+ // Apply filter through URL to prevent the typing flakes+ cy.visit(`/dashboard/${dashboard_id}?on=&between=2024-01-01~2024-03-01`);+ checkAppliedFilter("Between", "January 1, 2024 - March 1, 2024");++ cy.findAllByTestId("cell-data")+ .filter(":contains(January 1, 2024, 7:26 AM)")+ .should("have.length", 2);+ });++ cy.get("@dashboardId").then((dashboard_id) => {+ // Apply filter through URL to prevent the typing flakes+ cy.visit(`/dashboard/${dashboard_id}?on=2024-01-01&between=`);+ checkAppliedFilter("On", "January 1, 2024");++ cy.findAllByTestId("cell-data")+ .filter(":contains(January 1, 2024, 7:26 AM)")+ .should("have.length", 2);+ });+ });++ function connectFilterToColumn(column) {+ H.getDashboardCard().within(() => {+ cy.findByText("Column to filter on");+ cy.findByText("Select…").click();+ });++ H.popover().within(() => {+ cy.findByText(column).click();+ });+ }+});++describe("issue 35852", () => {+ const model = {+ name: "35852 - sql",+ type: "model",+ native: {+ query: "SELECT * FROM PRODUCTS LIMIT 10",+ },+ };++ beforeEach(() => {+ H.restore();+ cy.signInAsNormalUser();+ });++ it("should show filter values for a model based on sql query (metabase#35852)", () => {+ H.createNativeQuestion(model).then(({ body: { id: modelId } }) => {+ H.setModelMetadata(modelId, (field) => {+ if (field.display_name === "CATEGORY") {+ return {+ ...field,+ id: PRODUCTS.CATEGORY,+ display_name: "Category",+ semantic_type: "type/Category",+ fk_target_field_id: null,+ };+ }++ return field;+ });++ createDashboardWithFilterAndQuestionMapped(modelId);+ H.visitModel(modelId);+ });++ H.tableHeaderClick("Category");+ H.popover().findByText("Filter by this column").click();++ cy.log("Verify filter values are available");++ H.popover()+ .should("contain", "Gizmo")+ .should("contain", "Doohickey")+ .should("contain", "Gadget")+ .should("contain", "Widget");++ H.popover().within(() => {+ cy.findByText("Gizmo").click();+ cy.button("Add filter").click();+ });++ cy.log("Verify filter is applied");++ cy.findAllByTestId("cell-data")+ .filter(":contains(Gizmo)")+ .should("have.length", 2);++ H.visitDashboard("@dashboardId");++ H.filterWidget().click();++ H.popover().within(() => {+ cy.findByText("Gizmo").click();+ cy.button("Add filter").click();+ });++ H.getDashboardCard().findAllByText("Gizmo").should("have.length", 2);+ });++ function createDashboardWithFilterAndQuestionMapped(modelId) {+ const parameterDetails = {+ name: "Category",+ slug: "category",+ id: "2a12e66c",+ type: "string/=",+ sectionId: "string",+ };++ const dashboardDetails = {+ parameters: [parameterDetails],+ };++ const questionDetails = {+ name: "Q1",+ query: { "source-table": `card__${modelId}`, limit: 10 },+ };++ H.createDashboardWithQuestions({+ dashboardDetails,+ questions: [questionDetails],+ }).then(({ dashboard, questions: [card] }) => {+ cy.wrap(dashboard.id).as("dashboardId");++ H.updateDashboardCards({+ dashboard_id: dashboard.id,+ cards: [+ {+ card_id: card.id,+ parameter_mappings: [+ {+ card_id: card.id,+ parameter_id: parameterDetails.id,+ target: [+ "dimension",+ ["field", PRODUCTS.CATEGORY, { "base-type": "type/Text" }],+ ],+ },+ ],+ },+ ],+ });+ });+ }+});++describe("issue 47097", () => {+ const questionDetails = {+ name: "Products",+ query: {+ "source-table": PRODUCTS_ID,+ },+ };++ const parameterDetails = {+ id: "49596bcb-62bb-49d6-a92d-bf5dbfddf43b",+ type: "string/=",+ name: "Category",+ slug: "category",+ };++ const dashboardDetails = {+ name: "Dashboard",+ parameters: [parameterDetails],+ };++ beforeEach(() => {+ H.restore();+ cy.signInAsAdmin();+ });++ it('should be able to use filters without "create-queries" permissions when coming from a dashboard (metabase#47097)', () => {+ cy.log("create a dashboard with a parameter mapped to a field with values");+ H.createQuestionAndDashboard({ questionDetails, dashboardDetails }).then(+ ({ body: { id, card_id, dashboard_id } }) => {+ H.updateDashboardCards({+ dashboard_id,+ cards: [+ {+ id,+ card_id,+ row: 0,+ col: 0,+ size_x: 12,+ size_y: 12,+ parameter_mappings: [+ {+ parameter_id: parameterDetails.id,+ card_id,+ target: ["dimension", ["field", PRODUCTS.CATEGORY, null]],+ },+ ],+ },+ ],+ });+ cy.wrap(dashboard_id).as("dashboardId");+ },+ );++ cy.log("verify the field values in a dashboard");+ cy.signIn("nodata");+ H.visitDashboard("@dashboardId");+ H.filterWidget().click();+ H.popover().within(() => {+ cy.findByText("Gadget").should("be.visible");+ cy.findByPlaceholderText("Search the list").type("{esc}");+ });++ cy.log("drill-thru without filter values and check the dropdown");+ H.getDashboardCard().findByText("Products").click();+ H.queryBuilderHeader().should("be.visible");+ H.filterWidget().click();+ H.popover().within(() => {+ cy.findByText("Gadget").should("be.visible");+ cy.findByPlaceholderText("Search the list").type("{esc}");+ });+ H.queryBuilderHeader().findByLabelText("Back to Dashboard").click();+ H.getDashboardCard().should("be.visible");++ cy.log("add a filter value, drill-thru, and check the dropdown");+ H.filterWidget().click();+ H.popover().within(() => {+ cy.findByText("Gadget").click();+ cy.button("Add filter").click();+ });+ H.getDashboardCard().findByText("Products").click();+ H.queryBuilderHeader().should("be.visible");+ H.filterWidget().click();+ H.popover().findByText("Widget").should("be.visible");+ });+});++describe("issue 48524", () => {+ const questionDetails = {+ name: "15119",+ query: { "source-table": REVIEWS_ID },+ };++ const ratingFilter = {+ id: "5dfco74e",+ slug: "rating",+ name: "Rating",+ type: "string/=",+ sectionId: "string",+ };++ const reviewerFilter = {+ id: "ad1c877e",+ name: "Reviewer",+ slug: "reviewer",+ type: "string/=",+ sectionId: "string",+ };++ const dashboardDetails = { parameters: [reviewerFilter, ratingFilter] };++ function createDashboard() {+ H.createQuestionAndDashboard({ questionDetails, dashboardDetails }).then(+ ({ body: { id, card_id, dashboard_id } }) => {+ H.updateDashboardCards({+ dashboard_id,+ cards: [+ {+ id,+ card_id,+ row: 0,+ col: 0,+ size_x: 12,+ size_y: 8,+ parameter_mappings: [+ {+ parameter_id: ratingFilter.id,+ card_id,+ target: ["dimension", ["field", REVIEWS.RATING, null]],+ },+ {+ parameter_id: reviewerFilter.id,+ card_id,+ target: ["dimension", ["field", REVIEWS.REVIEWER, null]],+ },+ ],+ },+ ],+ });+ cy.wrap(dashboard_id).as("dashboardId");+ },+ );+ }++ beforeEach(() => {+ H.restore();+ cy.signInAsNormalUser();+ });++ it("should not apply last used parameter values when some parameters have values set in the URL (metabase#48524)", () => {+ createDashboard();++ cy.log(+ "open the dashboard with 2 parameters to populate their last used values",+ );+ H.visitDashboard("@dashboardId", {+ params: {+ [reviewerFilter.slug]: ["abbey-heidenreich"],+ [ratingFilter.slug]: 4,+ },+ });+ H.assertTableRowsCount(1);++ cy.log(+ "open the dashboard again and verify that the last used values are applied",+ );+ H.visitDashboard("@dashboardId");+ H.assertTableRowsCount(1);++ cy.log(+ "open the dashboard with only 1 parameter value and verify that the last used values are not applied in this case",+ );+ H.visitDashboard("@dashboardId", {+ params: {+ [ratingFilter.slug]: 4,+ },+ });+ H.assertTableRowsCount(535);+ });+});++describe("issue 32573", () => {+ const modelDetails = {+ name: "M1",+ type: "model",+ query: {+ "source-table": ORDERS_ID,+ fields: [["field", ORDERS.TAX, null]],+ },+ };++ const parameterDetails = {+ id: "92eb69ea",+ name: "ID",+ sectionId: "id",+ slug: "id",+ type: "id",+ default: 1,+ };++ const dashboardDetails = {+ parameters: [parameterDetails],+ };++ function getQuestionDetails(modelId) {+ return {+ name: "Q1",+ type: "question",+ query: {+ "source-table": `card__${modelId}`,+ },+ };+ }++ function getParameterMapping(questionId) {+ return {+ card_id: questionId,+ parameter_id: parameterDetails.id,+ target: [+ "dimension",+ ["field", "ID", { "base-type": "type/BigInteger" }],+ ],+ };+ }++ beforeEach(() => {+ H.restore();+ cy.signInAsNormalUser();+ });++ it("should not crash a dashboard when there is a missing parameter column (metabase#32573)", () => {+ H.createQuestion(modelDetails).then(({ body: model }) => {+ H.createQuestion(getQuestionDetails(model.id)).then(+ ({ body: question }) => {+ H.createDashboard(dashboardDetails).then(({ body: dashboard }) => {+ return cy+ .request("PUT", `/api/dashboard/${dashboard.id}`, {+ dashcards: [+ createMockDashboardCard({+ card_id: question.id,+ parameter_mappings: [getParameterMapping(question.id)],+ size_x: 6,+ size_y: 6,+ }),+ ],+ })+ .then(() => H.visitDashboard(dashboard.id));+ });+ },+ );+ });+ H.getDashboardCard()+ .findByText("There was a problem displaying this chart.")+ .should("be.visible");++ H.editDashboard();+ cy.findByTestId("fixed-width-filters").findByText("ID").click();+ H.getDashboardCard().within(() => {+ cy.findByText("Unknown Field").should("be.visible");+ cy.findByLabelText("Disconnect").click();+ });+ H.saveDashboard();+ H.getDashboardCard().within(() => {+ cy.findByText("Q1").should("be.visible");+ cy.findByText("Tax").should("be.visible");+ });+ });+});++describe("issue 45670", { tags: ["@external"] }, () => {+ const dialect = "postgres";+ const tableName = "many_data_types";++ const parameterDetails = {+ id: "92eb69ea",+ name: "boolean",+ type: "string/=",+ slug: "boolean",+ sectionId: "string",+ };++ const dashboardDetails = {+ parameters: [parameterDetails],+ };++ function getField() {+ return cy.request("GET", "/api/table").then(({ body: tables }) => {+ const table = tables.find((table) => table.name === tableName);+ return cy+ .request("GET", `/api/table/${table.id}/query_metadata`)+ .then(({ body: metadata }) => {+ const { fields } = metadata;+ return fields.find((field) => field.name === "boolean");+ });+ });+ }++ function getQuestionDetails(fieldId) {+ return {+ database: WRITABLE_DB_ID,+ native: {+ query: "SELECT id, boolean FROM many_data_types WHERE {{boolean}}",+ "template-tags": {+ boolean: {+ id: "4b77cc1f-ea70-4ef6-84db-58432fce6928",+ name: "boolean",+ type: "dimension",+ "display-name": "Boolean",+ dimension: ["field", fieldId, null],+ "widget-type": "string/=",+ },+ },+ },+ };+ }++ function getParameterMapping(cardId) {+ return {+ card_id: cardId,+ parameter_id: parameterDetails.id,+ target: ["dimension", ["template-tag", parameterDetails.name]],+ };+ }++ beforeEach(() => {+ H.restore(`${dialect}-writable`);+ H.resetTestTable({ type: dialect, table: tableName });+ cy.signInAsAdmin();+ H.resyncDatabase({ dbId: WRITABLE_DB_ID, tableName });+ cy.intercept("PUT", "/api/card/*").as("updateCard");+ });++ it("should be able to pass query string parameters for boolean parameters in dashboards (metabase#45670)", () => {+ getField().then((field) => {+ H.createNativeQuestion(getQuestionDetails(field.id)).then(+ ({ body: card }) => {+ H.createDashboard(dashboardDetails).then(({ body: dashboard }) => {+ cy.request("PUT", `/api/dashboard/${dashboard.id}`, {+ dashcards: [+ createMockDashboardCard({+ card_id: card.id,+ parameter_mappings: [getParameterMapping(card.id, field.id)],+ size_x: 8,+ size_y: 8,+ }),+ ],+ });+ H.visitDashboard(dashboard.id, {+ params: {+ [parameterDetails.slug]: "true",+ },+ });+ });+ },+ );+ });+ H.filterWidget().should("contain.text", "true");+ H.getDashboardCard().within(() => {+ cy.findByText("true").should("be.visible");+ cy.findByText("false").should("not.exist");+ });+ });+});++describe("issue 48351", () => {+ beforeEach(() => {+ H.restore();+ cy.signInAsNormalUser();+ });++ it("should navigate to the specified tab with click behaviors (metabase#48351)", () => {+ H.createDashboardWithTabs({+ name: "Dashboard 1",+ tabs: [+ { id: 1, name: "Tab 1" },+ { id: 2, name: "Tab 2" },+ ],+ dashcards: [+ createMockDashboardCard({+ id: -1,+ card_id: ORDERS_QUESTION_ID,+ dashboard_tab_id: 1,+ size_x: 8,+ size_y: 8,+ }),+ createMockDashboardCard({+ id: -2,+ card_id: ORDERS_QUESTION_ID,+ dashboard_tab_id: 2,+ col: 8,+ size_x: 8,+ size_y: 8,+ }),+ ],+ }).then((dashboard1) => {+ H.createDashboardWithTabs({+ name: "Dashboard 2",+ tabs: [+ { id: 3, name: "Tab 3" },+ { id: 4, name: "Tab 4" },+ ],+ dashcards: [+ createMockDashboardCard({+ id: -1,+ card_id: ORDERS_QUESTION_ID,+ dashboard_tab_id: 3,+ size_x: 8,+ size_y: 8,+ }),+ createMockDashboardCard({+ id: -2,+ card_id: ORDERS_QUESTION_ID,+ dashboard_tab_id: 4,+ visualization_settings: {+ column_settings: {+ '["name","ID"]': {+ click_behavior: {+ type: "link",+ linkType: "dashboard",+ targetId: dashboard1.id,+ tabId: dashboard1.tabs[1].id,+ parameterMapping: {},+ },+ },+ },+ },+ col: 8,+ size_x: 8,+ size_y: 8,+ }),+ ],+ }).then((dashboard2) => H.visitDashboard(dashboard2.id));+ });+ H.goToTab("Tab 4");+ H.getDashboardCard().within(() =>+ cy.findAllByRole("gridcell").eq(0).click(),+ );+ cy.findByTestId("dashboard-name-heading").should(+ "have.value",+ "Dashboard 1",+ );+ H.assertTabSelected("Tab 2");+ });+});++describe("issue 52484", () => {+ const questionDetails = {+ native: {+ query: "SELECT ID, RATING FROM PRODUCTS [[WHERE RATING = {{rating}}]]",+ "template-tags": {+ rating: {+ id: "56708d23-6f01-42b7-98ed-f930295d31b9",+ name: "rating",+ type: "number",+ "display-name": "Rating",+ },+ },+ },+ parameters: [+ {+ id: "56708d23-6f01-42b7-98ed-f930295d31b9",+ name: "Rating",+ slug: "rating",+ type: "number/=",+ target: ["dimension", ["template-tag", "rating"]],+ },+ ],+ };++ beforeEach(() => {+ H.restore();+ cy.signInAsNormalUser();+ });++ it("should allow to use click behaviors with numeric columns that are not database fields (metabase#52484)", () => {+ H.createNativeQuestionAndDashboard({ questionDetails }).then(+ ({ body: { dashboard_id } }) => {+ H.visitDashboard(dashboard_id);+ },+ );++ cy.log("setup a dashboard with a click behavior");+ H.editDashboard();+ H.setFilter("Number", "Equal to");+ H.selectDashboardFilter(H.getDashboardCard(), "Rating");+ H.dashboardParametersDoneButton().click();+ H.showDashboardCardActions();+ cy.findByLabelText("Click behavior").click();+ H.sidebar().within(() => {+ cy.findByText("ID").click();+ cy.findByText("Update a dashboard filter").click();+ cy.findByText("Number").click();+ });+ H.popover().findByText("ID").click();+ H.saveDashboard();++ cy.log("update a dashboard filter by clicking on a ID column value");+ H.getDashboardCard().findByText("2").click();+ H.filterWidget().findByDisplayValue("2").should("be.visible");++ cy.log("verify query results for the new filter");+ H.getDashboardCard().within(() => {+ cy.findByText("27").should("be.visible");+ cy.findByText("123").should("be.visible");+ });+ });+});++describe("issue 40396", { tags: "@external " }, () => {+ const tableName = "many_data_types";++ beforeEach(() => {+ H.restore("postgres-writable");+ H.resetTestTable({ type: "postgres", table: tableName });+ cy.signInAsAdmin();+ H.resyncDatabase({ dbId: WRITABLE_DB_ID });+ cy.intercept("POST", "/api/dashboard/*/dashcard/*/card/*/query").as(+ "dashcardQuery",+ );+ });++ it("should be possible to use dashboard filters with native enum fields (metabase#40396)", () => {+ cy.log("create a dashboard with a question with a type/Enum field");+ cy.request("GET", "/api/table").then(({ body: tables }) => {+ const table = tables.find((table) => table.name === tableName);+ cy.request("GET", `/api/table/${table.id}/query_metadata`).then(+ ({ body: metadata }) => {+ const field = metadata.fields.find((field) => field.name === "enum");+ cy.request("PUT", `/api/field/${field.id}`, {+ semantic_type: "type/Enum",+ });++ H.createQuestionAndDashboard({+ questionDetails: {+ database: table.db_id,+ query: { "source-table": table.id },+ },+ }).then(({ body: { dashboard_id } }) => {+ H.visitDashboard(dashboard_id);+ cy.wait("@dashcardQuery");+ });+ },+ );+ });++ cy.log("verify that a enum field can be mapped to a parameter");+ H.editDashboard();+ H.setFilter("Text or Category", "Is");+ H.selectDashboardFilter(H.getDashboardCard(), "Enum");+ H.saveDashboard();++ cy.log("verify that filtering on a enum field works");+ H.filterWidget().click();+ H.popover().within(() => {+ cy.findByText("beta").click();+ cy.button("Add filter").click();+ });+ cy.wait("@dashcardQuery");+ H.tableInteractiveScrollContainer().scrollTo("right");+ H.getDashboardCard().findAllByText("beta").should("have.length.gte", 1);+ });+});++describe("issue 52627", () => {+ const questionDetails = {+ display: "bar",+ query: {+ "source-table": ORDERS_ID,+ aggregation: [+ ["avg", ["field", ORDERS.TOTAL, null]],+ ["avg", ["field", ORDERS.DISCOUNT, null]],+ ],+ breakout: [["field", ORDERS.CREATED_AT, { "temporal-unit": "month" }]],+ },+ };++ const parameterDetails = {+ name: "Category",+ slug: "category",+ id: "b6ed2d71",+ type: "string/=",+ sectionId: "string",+ default: ["Gadget"],+ };++ const parameterTarget = [+ "dimension",+ ["field", PRODUCTS.CATEGORY, { "source-field": ORDERS.PRODUCT_ID }],+ { "stage-number": 0 },+ ];++ const dashboardDetails = {+ parameters: [parameterDetails],+ };++ beforeEach(() => {+ H.restore();+ cy.signInAsAdmin();+ cy.intercept("POST", "/api/dataset").as("dataset");+ });++ it("should remove an empty query stage after a dashboard drill-thru (metabase#52627)", () => {+ H.createQuestionAndDashboard({ questionDetails, dashboardDetails }).then(+ ({ body: { id, card_id, dashboard_id } }) => {+ H.addOrUpdateDashboardCard({+ dashboard_id,+ card_id,+ card: {+ id,+ parameter_mappings: [+ {+ card_id: card_id,+ parameter_id: parameterDetails.id,+ target: parameterTarget,+ },+ ],+ },+ });+ H.visitDashboard(dashboard_id);+ },+ );+ H.chartPathWithFillColor("#A989C5").first().click();+ H.popover().findByText("See this month by week").click();+ cy.wait("@dataset");+ cy.findByTestId("qb-filters-panel").findByText(+ "Product → Category is Gadget",+ );+ H.summarize();+ H.rightSidebar().findByText("Average of Total").should("be.visible");+ });+});++describe("issue 52918", () => {+ beforeEach(() => {+ H.restore();+ cy.signInAsAdmin();+ });++ it("should re-position the parameter dropdown when its size changes (metabase#52918)", () => {+ H.visitDashboard(ORDERS_DASHBOARD_ID);+ H.editDashboard();+ H.setFilter("Date picker", "All Options");+ H.sidebar().findByLabelText("No default").click();+ H.popover().within(() => {+ cy.findByText("Fixed date range…").click();+ cy.findByText("Between").should("be.visible");+ });+ cy.log("check that there is no overflow in the popover");+ H.popover().should(([element]) => {+ expect(element.offsetWidth).to.gte(element.scrollWidth);+ });+ });+});++describe("issue 54236", () => {+ beforeEach(() => {+ H.restore();+ cy.signInAsNormalUser();+ cy.clock(new Date("2025-02-26"));+ });++ it("should show correct date range in the date picker (metabase#54236)", () => {+ H.visitDashboard(ORDERS_DASHBOARD_ID);+ H.editDashboard();+ H.setFilter("Date picker", "All Options");+ H.sidebar().findByLabelText("No default").click();+ H.popover().within(() => {+ cy.findByText("Relative date range…").click();+ cy.findByText("Next").click();+ cy.findByDisplayValue("30").clear().type("1");+ cy.findAllByDisplayValue("day").filter(":visible").click();+ });+ H.popover().should("have.length", 2).last().findByText("quarter").click();+ H.popover().within(() => {+ cy.icon("arrow_left_to_line").click();+ cy.findByDisplayValue("4").clear().type("1");+ cy.findByText("Jul 1 – Sep 30, 2025").should("be.visible");+ cy.findByText("Apr 1 – Jun 30, 2025").should("not.exist");+ });+ });+});++describe("issue 17061", () => {+ const questionDetails = {+ query: {+ "source-table": PEOPLE_ID,+ "order-by": [["asc", ["field", PEOPLE.ID, null]]],+ limit: 1,+ },+ };++ const parameterDetails = {+ name: "State",+ slug: "state",+ id: "5aefc725",+ type: "string/=",+ sectionId: "location",+ };++ const dashboardDetails = {+ parameters: [parameterDetails],+ enable_embedding: true,+ embedding_params: {+ [parameterDetails.slug]: "enabled",+ },+ };++ const getParameterMapping = (cardId) => ({+ parameter_id: parameterDetails.id,+ card_id: cardId,+ target: ["dimension", ["field", "STATE", { "base-type": "type/Text" }]],+ });++ beforeEach(() => {+ H.restore();+ cy.signInAsAdmin();+ cy.intercept("GET", "/api/public/dashboard/*/dashcard/*/card/*").as(+ "publicDashcardData",+ );+ });++ it("should not send multiple query requests for the same dashcards when opening a public dashboard with parameters (metabase#17061)", () => {+ H.createQuestionAndDashboard({+ questionDetails,+ dashboardDetails,+ }).then(({ body: dashcard, questionId }) => {+ H.updateDashboardCards({+ dashboard_id: dashcard.dashboard_id,+ cards: [+ {+ card_id: questionId,+ parameter_mappings: [getParameterMapping(questionId)],+ },+ ],+ });+ H.visitPublicDashboard(dashcard.dashboard_id);+ });++ H.getDashboardCard().findByText("1").should("be.visible");+ cy.get("@publicDashcardData.all").should("have.length", 1);+ });+});++// TODO ranquild unskip after v54 release+describe("issue 48824", { tags: "@skip" }, () => {+ const dateParameter = {+ id: "abc",+ name: "Date filter",+ slug: "filter-date",+ type: "date/all-options",+ default: "past30days-from-7days",+ };++ beforeEach(() => {+ H.restore();+ cy.signInAsNormalUser();+ });++ it("should correctly translate relative filters in dashboards (metabase#48824)", () => {+ cy.log("set locale");+ cy.request("GET", "/api/user/current").then(({ body: user }) => {+ cy.request("PUT", `/api/user/${user.id}`, { locale: "de" });+ });++ cy.log("add a date parameter with a relative default value to a dashboard");+ cy.request("PUT", `/api/dashboard/${ORDERS_DASHBOARD_ID}`, {+ parameters: [dateParameter],+ });+ H.updateDashboardCards({+ dashboard_id: ORDERS_DASHBOARD_ID,+ cards: [+ {+ card_id: ORDERS_QUESTION_ID,+ parameter_mappings: [+ {+ card_id: ORDERS_QUESTION_ID,+ parameter_id: dateParameter.id,+ target: ["dimension", ["field", ORDERS.CREATED_AT, null]],+ },+ ],+ },+ ],+ });++ cy.log("check translations");+ H.visitDashboard(ORDERS_DASHBOARD_ID, {+ params: { [dateParameter.slug]: "past30days" },+ });++ cy.log("Previous 30 days");+ H.filterWidget().findByText("Vorheriger 30 Tage").should("be.visible");+ H.filterWidget().icon("revert").click();++ cy.log("Previous 30 days, starting 7 days ago");+ H.filterWidget()+ .findByText("Vorheriger 30 Tage, ab vor 7 tage")+ .should("be.visible");+ });+});++describe("issue 62627", () => {+ beforeEach(() => {+ H.restore();+ cy.signInAsNormalUser();+ });++ function toggleLinkedFilter(parameterName) {+ cy.button(parameterName)+ .parent()+ .findByRole("switch")+ .click({ force: true });+ }++ it("should properly link inline parameters (metabase#62627)", () => {+ H.visitDashboard(ORDERS_DASHBOARD_ID);+ H.editDashboard();++ cy.log("add a top-level filter");+ H.setFilter("Text or Category", "Is");+ H.selectDashboardFilter(H.getDashboardCard(), "Vendor");+ H.setDashboardParameterName("Vendor");+ H.dashboardParameterSidebar().button("Done").click();++ cy.log("add an inline card filter");+ H.showDashboardCardActions();+ H.getDashboardCard()+ .realHover({ scrollBehavior: "bottom" })+ .findByLabelText("Add a filter")+ .click();+ H.popover().findByText("Text or Category").click();+ H.selectDashboardFilter(H.getDashboardCard(), "Category");+ H.setDashboardParameterName("Category");+ H.dashboardParameterSidebar().within(() => {+ cy.findByText("Linked filters").click();+ toggleLinkedFilter("Vendor");+ });+ H.saveDashboard();++ cy.log(+ "verify that the inline parameter is linked to the top-level parameter",+ );+ H.dashboardParametersContainer().within(() => H.filterWidget().click());+ H.popover().within(() => {+ cy.findByText("Balistreri-Muller").click();+ cy.button("Add filter").click();+ });+ H.getDashboardCard().within(() => H.filterWidget().click());+ H.popover().within(() => {+ cy.findByText("Widget").should("be.visible");+ cy.findByText("Gadget").should("not.exist");+ });++ cy.log("make the top-level parameter be linked to the inline parameter");+ H.editDashboard();+ H.getDashboardCard().findByTestId("editing-parameter-widget").click();+ H.dashboardParameterSidebar().within(() => {+ cy.findByText("Linked filters").click();+ toggleLinkedFilter("Vendor");+ });+ H.editingDashboardParametersContainer()+ .findByTestId("editing-parameter-widget")+ .click();+ H.dashboardParameterSidebar().within(() => {+ cy.findByText("Linked filters").click();+ toggleLinkedFilter("Category");+ });+ H.saveDashboard();++ cy.log(+ "verify that the top-level parameter is linked to the inline parameter",+ );+ H.dashboardParametersContainer().within(() =>+ H.filterWidget().icon("close").click(),+ );+ H.getDashboardCard().within(() => H.filterWidget().click());+ H.popover().within(() => {+ cy.findByText("Gadget").click();+ cy.button("Add filter").click();+ });+ H.dashboardParametersContainer().within(() => H.filterWidget().click());+ H.popover().within(() => {+ cy.findByText("Barrows-Johns").should("be.visible");+ cy.findByText("Americo Sipes and Sons").should("not.exist");+ });+ });+});++describe("issue 55678", () => {+ const parameterDetails = {+ name: "date",+ slug: "date",+ id: "f8ec7c71",+ type: "date/all-options",+ sectionId: "date",+ default: "2020-01-01~2024-12-31",+ };++ const questionDetails = {+ name: "Orders",+ query: {+ "source-table": ORDERS_ID,+ aggregation: [["count"]],+ breakout: [+ [+ "field",+ ORDERS.CREATED_AT,+ { "base-type": "type/DateTime", "temporal-unit": "month" },+ ],+ ],+ },+ display: "line",+ };++ const dashboardDetails = {+ name: "Dashboard",+ parameters: [parameterDetails],+ };++ function setupDashboard() {+ return H.createQuestion(questionDetails).then(+ ({ body: { id: card_id } }) => {+ H.createDashboard(dashboardDetails).then(+ ({ body: { id: dashboard_id } }) => {+ H.addOrUpdateDashboardCard({+ dashboard_id,+ card_id,+ card: {+ parameter_mappings: [+ {+ card_id,+ parameter_id: parameterDetails.id,+ target: [+ "dimension",+ ["field", "CREATED_AT", { "base-type": "type/DateTime" }],+ { "stage-number": 1 },+ ],+ },+ ],+ },+ });+ H.visitDashboard(dashboard_id);+ },+ );+ },+ );+ }++ beforeEach(() => {+ H.restore();+ cy.signInAsNormalUser();+ });++ it("should ignore parameters mapped to post-aggregation stages when doing query drills (metabase#55678)", () => {+ setupDashboard();+ H.getDashboardCard().within(() => {+ H.cartesianChartCircle().first().click();+ });+ H.popover().findByText("See this Order").click();+ H.queryBuilderFiltersPanel()+ .findByText("Created At: Month is Apr 1–30, 2022")+ .should("be.visible");+ H.assertQueryBuilderRowCount(1);+ });+});++describe("issue 14595", () => {+ const dialect = "postgres";+ const tableName = "many_data_types";++ function createDashboard() {+ return H.getTableId({ name: tableName }).then((tableId) => {+ return H.createDashboardWithQuestions({+ dashboardDetails: {+ parameters: [+ createMockParameter({+ id: "p1",+ slug: "p1",+ name: "p1",+ type: "string/=",+ sectionId: "string",+ }),+ createMockParameter({+ id: "p2",+ slug: "p2",+ name: "p2",+ type: "string/=",+ sectionId: "string",+ }),+ createMockParameter({+ id: "p3",+ slug: "p3",+ name: "p3",+ type: "string/=",+ sectionId: "string",+ }),+ ],+ },+ questions: [+ {+ name: "Orders",+ query: { "source-table": ORDERS_ID },+ },+ {+ name: "Products",+ query: { "source-table": PRODUCTS_ID },+ },+ {+ name: "Many data types",+ database: WRITABLE_DB_ID,+ query: { "source-table": tableId },+ },+ ],+ }).then(({ dashboard }) => {+ return dashboard.id;+ });+ });+ }++ function mapParameters() {+ cy.findByTestId("fixed-width-filters").findByText("p1").click();+ H.selectDashboardFilter(H.getDashboardCard(0), "Source");+ cy.findByTestId("fixed-width-filters").findByText("p2").click();+ H.selectDashboardFilter(H.getDashboardCard(1), "Category");+ cy.findByTestId("fixed-width-filters").findByText("p3").click();+ H.selectDashboardFilter(H.getDashboardCard(2), "String");+ }++ function assertLinkedFilterSettings({+ parameterName,+ compatibleParameterNames,+ incompatibleParameterNames,+ }) {+ cy.findByTestId("fixed-width-filters").findByText(parameterName).click();+ H.sidebar().within(() => {+ cy.findByText("Linked filters").click();+ compatibleParameterNames.forEach((compatibleParameterName) => {+ cy.findByTestId("compatible-parameters")+ .findByText(compatibleParameterName)+ .should("be.visible");+ });+ incompatibleParameterNames.forEach((incompatibleParameterName) => {+ cy.findByTestId("incompatible-parameters")+ .findByText(incompatibleParameterName)+ .should("be.visible");+ });+ });+ }++ function assertParameterSettings() {+ assertLinkedFilterSettings({+ parameterName: "p1",+ compatibleParameterNames: ["p2"],+ incompatibleParameterNames: ["p3"],+ });+ assertLinkedFilterSettings({+ parameterName: "p2",+ compatibleParameterNames: ["p1"],+ incompatibleParameterNames: ["p3"],+ });+ assertLinkedFilterSettings({+ parameterName: "p3",+ compatibleParameterNames: [],+ incompatibleParameterNames: ["p1", "p2"],+ });+ }++ beforeEach(() => {+ H.restore(`${dialect}-writable`);+ H.resetTestTable({ type: dialect, table: tableName });+ cy.signInAsAdmin();+ H.resyncDatabase({ dbId: WRITABLE_DB_ID, tableName });+ });++ it("should not see parameters that cannot be linked to the current parameter in parameter settings (metabase#14595)", () => {+ createDashboard().then((dashboardId) => H.visitDashboard(dashboardId));+ H.editDashboard();+ mapParameters();+ assertParameterSettings();+ });+});++describe("issue 44090", () => {+ const parameterDetails = {+ name: "p1",+ slug: "string",+ id: "f8ec7c71",+ type: "string/=",+ };++ const questionDetails = {+ name: "Orders",+ query: {+ "source-table": REVIEWS_ID,+ },+ };++ const dashboardDetails = {+ name: "Dashboard",+ parameters: [parameterDetails],+ };++ beforeEach(() => {+ H.restore();+ cy.signInAsNormalUser();++ H.createQuestion(questionDetails).then(({ body: { id: card_id } }) => {+ H.createDashboard(dashboardDetails).then(+ ({ body: { id: dashboard_id } }) => {+ H.addOrUpdateDashboardCard({+ dashboard_id,+ card_id,+ card: {+ parameter_mappings: [+ {+ card_id,+ parameter_id: parameterDetails.id,+ target: ["dimension", ["field", REVIEWS.BODY, {}]],+ },+ ],+ },+ });+ H.visitDashboard(dashboard_id);+ },+ );+ });+ });++ it("should not overflow the dashboard header when a filter contains a long value that contains spaces (metabase#44090)", () => {+ const LONG_VALUE =+ "Minima non hic doloribus ipsa dolore ratione in numquam. Minima eos vel harum velit. Consequatur consequuntur culpa sed eum";++ H.filterWidget().click();+ H.popover()+ .first()+ .within(() => {+ cy.findByPlaceholderText("Search the list").type(LONG_VALUE);+ cy.button("Add filter").click();+ });++ H.filterWidget().then(($el) => {+ const { width } = $el[0].getBoundingClientRect();+ cy.wrap(width).should("be.lt", 300);+ });+ });++ it("should not overflow the dashboard header when a filter contains a long value that does not contain spaces (metabase#44090)", () => {+ const LONG_VALUE =+ "MinimanonhicdoloribusipsadolorerationeinnumquamMinimaeosvelharumvelitConsequaturconsequunturculpasedeum";++ H.filterWidget().click();+ H.popover()+ .first()+ .within(() => {+ cy.findByPlaceholderText("Search the list").type(LONG_VALUE);+ cy.button("Add filter").click();+ });++ H.filterWidget().then(($el) => {+ const { width } = $el[0].getBoundingClientRect();+ cy.wrap(width).should("be.lt", 300);+ });+ });+});++describe("issue 47951", () => {+ beforeEach(() => {+ H.restore();+ cy.signInAsAdmin();+ H.activateToken("pro-self-hosted");+ });++ it("should do X (metabase#47951)", () => {+ cy.log("set up permissions");+ cy.updatePermissionsGraph({+ [USER_GROUPS.ALL_USERS_GROUP]: {+ [SAMPLE_DB_ID]: {+ "view-data": "unrestricted",+ "create-queries": "no",+ },+ },+ [USER_GROUPS.DATA_GROUP]: {+ [SAMPLE_DB_ID]: {+ "view-data": "unrestricted",+ "create-queries": "no",+ },+ },+ });++ cy.log("set up remapping");+ cy.request("PUT", `/api/field/${ORDERS.PRODUCT_ID}`, {+ has_field_values: "list",+ });+ cy.request("PUT", `/api/field/${REVIEWS.PRODUCT_ID}`, {+ has_field_values: "list",+ });+ cy.request("POST", `/api/field/${ORDERS.PRODUCT_ID}/dimension`, {+ name: "Product ID",+ type: "external",+ human_readable_field_id: PRODUCTS.TITLE,+ });+ cy.request("POST", `/api/field/${REVIEWS.PRODUCT_ID}/dimension`, {+ name: "Product ID",+ type: "external",+ human_readable_field_id: PRODUCTS.TITLE,+ });++ cy.log("create a dashboard");+ const parameter = createMockParameter({+ id: "p1",+ slug: "p1",+ type: "id",+ sectionId: "id",+ default: 1,+ });+ H.createDashboardWithQuestions({+ dashboardDetails: {+ parameters: [parameter],+ },+ questions: [+ { name: "q1", query: { "source-table": ORDERS_ID } },+ { name: "q2", query: { "source-table": REVIEWS_ID } },+ ],+ }).then(({ dashboard: dashboard, questions: [card1, card2] }) => {+ H.updateDashboardCards({+ dashboard_id: dashboard.id,+ cards: [+ {+ card_id: card1.id,+ parameter_mappings: [+ {+ card_id: card1.id,+ parameter_id: parameter.id,+ target: ["dimension", ["field", ORDERS.PRODUCT_ID, null]],+ },+ ],+ },+ {+ card_id: card2.id,+ parameter_mappings: [+ {+ card_id: card2.id,+ parameter_id: parameter.id,+ target: ["dimension", ["field", REVIEWS.PRODUCT_ID, null]],+ },+ ],+ },+ ],+ });+ cy.wrap(dashboard.id).as("dashboardId");+ });++ cy.log("log in as a normal user and open the dashboard");+ cy.signInAsNormalUser();+ H.visitDashboard("@dashboardId");++ cy.log("check remapping for default values");+ H.filterWidget().findByText("Rustic Paper Wallet").should("be.visible");++ cy.log("check remapping for dropdown values");+ H.filterWidget().click();+ H.popover().within(() => {+ cy.findByText("Rustic Paper Wallet").should("be.visible");+ cy.findByText("Aerodynamic Bronze Hat").should("be.visible");+ });+ });+});++describe("issue 59306", () => {+ beforeEach(() => {+ H.restore();+ cy.signInAsAdmin();++ const parameter = createMockParameter({+ id: "p1",+ slug: "p1",+ type: "string/=",+ sectionId: "string",+ default: undefined,+ values_query_type: "none",+ });++ H.createDashboardWithQuestions({+ dashboardDetails: {+ parameters: [parameter],+ },+ questions: [{ name: "q1", query: { "source-table": PRODUCTS_ID } }],+ }).then(({ dashboard, questions: [card] }) => {+ H.updateDashboardCards({+ dashboard_id: dashboard.id,+ cards: [+ {+ card_id: card.id,+ parameter_mappings: [+ {+ card_id: card.id,+ parameter_id: parameter.id,+ target: ["dimension", ["field", PRODUCTS.CATEGORY, null]],+ has_field_values: "input",+ },+ ],+ },+ ],+ }).then(() => {+ H.visitDashboard(dashboard.id);+ });+ });+ });++ it("should not overflow the filter box (metabase#59306)", () => {+ H.filterWidget().click();+ H.popover().within(() => {+ cy.findByPlaceholderText("Enter some text")+ .type("asdf".repeat(20))+ .invoke("outerWidth")+ .should("be.lt", 400);+ });+ });+});++describe("Issue 60987", () => {+ beforeEach(() => {+ H.restore();+ cy.signInAsAdmin();++ H.createQuestionAndDashboard({+ questionDetails: {+ type: "question",+ query: {+ "source-table": ORDERS_ID,+ joins: [+ {+ "source-table": PRODUCTS_ID,+ fields: "all",+ strategy: "left-join",+ alias: "Products",+ condition: [+ "=",+ [+ "field",+ ORDERS.PRODUCT_ID,+ {+ "base-type": "type/Integer",+ },+ ],+ [+ "field",+ PRODUCTS.ID,+ {+ "base-type": "type/BigInteger",+ "join-alias": "Products",+ },+ ],+ ],+ },+ ],+ },+ },+ }).then((response) => {+ H.visitDashboard(response.body.dashboard_id);+ });+ });++ it("should show the empty state for parameters when searching the in the parameter target picker popover (metabase#60987)", () => {+ H.editDashboard();+ H.setFilter("Text or Category", "Is");+ H.getDashboardCard().findByText("Select…").click();+ H.popover().findByPlaceholderText("Find...").type("aa");+ H.popover().findByText("Didn't find any results").should("be.visible");+ });+});++describe("Issue 60987", () => {+ beforeEach(() => {+ H.restore();+ cy.signInAsAdmin();++ H.createQuestionAndDashboard({+ questionDetails: {+ type: "question",+ query: {+ "source-table": ORDERS_ID,+ joins: [+ {+ "source-table": PRODUCTS_ID,+ fields: "all",+ strategy: "left-join",+ alias: "Products",+ condition: [+ "=",+ [+ "field",+ ORDERS.PRODUCT_ID,+ {+ "base-type": "type/Integer",+ },+ ],+ [+ "field",+ PRODUCTS.ID,+ {+ "base-type": "type/BigInteger",+ "join-alias": "Products",+ },+ ],+ ],+ },+ ],+ },+ },+ }).then((response) => {+ H.visitDashboard(response.body.dashboard_id);+ });++ H.editDashboard();+ H.setFilter("Text or Category", "Is");+ H.getDashboardCard().findByText("Select…").click();+ });++ it("should show the empty state for parameters when searching the in the parameter target picker popover (metabase#60987)", () => {+ H.popover().within(() => {+ cy.findByPlaceholderText("Find...").type("aa");+ cy.findByText("Didn't find any results")+ .should("be.visible")+ .should("have.css", "color", "rgba(7, 23, 34, 0.62)"); // the text "text-medium"+ });+ });+});++describe("Issue 46767", () => {+ beforeEach(() => {+ H.restore();+ cy.signInAsAdmin();++ H.createQuestionAndDashboard({+ questionDetails: {+ type: "question",+ query: {+ "source-table": ORDERS_ID,+ joins: [+ {+ "source-table": PRODUCTS_ID,+ fields: "all",+ strategy: "left-join",+ alias: "Products",+ condition: [+ "=",+ [+ "field",+ ORDERS.PRODUCT_ID,+ {+ "base-type": "type/Integer",+ },+ ],+ [+ "field",+ PRODUCTS.ID,+ {+ "base-type": "type/BigInteger",+ "join-alias": "Products",+ },+ ],+ ],+ },+ ],+ },+ },+ }).then((response) => {+ H.visitDashboard(response.body.dashboard_id);+ });++ H.editDashboard();+ H.setFilter("Text or Category", "Is");+ H.getDashboardCard().findByText("Select…").click();+ });++ it("search results for parameter target picker should not show empty sections (metabase#46767)", () => {+ H.popover().within(() => {+ cy.findByPlaceholderText("Find...").type("Ean");+ cy.findByText("Products").should("be.visible");+ cy.findByText("User").should("not.exist");+ });+ });+});++describe("issue 46541", () => {+ const TARGET_FILTER = {+ name: "Target filter",+ slug: "target-filter",+ id: "ffa421da",+ type: "number/>=",+ sectionId: "number",+ };++ const OTHER_FILTER = {+ name: "Other filter",+ slug: "other-filter",+ id: "dfaa3356",+ type: "number/>=",+ sectionId: "number",+ };++ beforeEach(() => {+ H.restore();+ cy.signInAsAdmin();++ H.createQuestionAndDashboard({+ questionDetails: {+ query: { "source-table": ORDERS_ID },+ },+ dashboardDetails: {+ name: "Dashboard A",+ },+ }).then(({ body }) => {+ cy.wrap(body.dashboard_id).as("dashboardA");++ H.createQuestionAndDashboard({+ questionDetails: {+ query: { "source-table": ORDERS_ID },+ },+ dashboardDetails: {+ name: "Dashboard B",+ parameters: [TARGET_FILTER, OTHER_FILTER],+ },+ }).then(({ body }) => {+ cy.wrap(body.dashboard_id).as("dashboardB");++ H.updateDashboardCards({+ dashboard_id: body.dashboard_id,+ cards: [+ {+ card_id: body.card_id,+ parameter_mappings: [+ {+ parameter_id: TARGET_FILTER.id,+ card_id: body.card_id,+ target: ["dimension", ["field", ORDERS.TOTAL, null]],+ },+ {+ parameter_id: OTHER_FILTER.id,+ card_id: body.card_id,+ target: ["dimension", ["field", ORDERS.SUBTOTAL, null]],+ },+ ],+ },+ ],+ });++ cy.log("Set parameter value on Dashboard B");+ H.visitDashboard("@dashboardB");+ H.filterWidget(OTHER_FILTER).click();+ H.popover().within(() => {+ cy.findByPlaceholderText("Enter a number").type("10");+ cy.button("Add filter").click();+ });++ cy.log("Set up click behaviour on Dashboard A");+ H.visitDashboard("@dashboardA");+ H.editDashboard();++ H.showDashboardCardActions();+ cy.findByLabelText("Click behavior").click();++ H.sidebar().within(() => {+ cy.findByText("Tax").click();+ cy.findByText("Go to a custom destination").click();+ cy.findByText("Dashboard").click();+ });++ H.entityPickerModal().within(() => {+ cy.findByText("Our analytics").click();+ cy.findByText("Dashboard B").click();+ });++ H.sidebar().findByText(TARGET_FILTER.name).click();+ H.popover().findByText("Tax").click();+ H.saveDashboard();+ });+ });+ });++ it("should reset other filters when coming to a dashboard from a click action with a filter (metabase#46541)", () => {+ cy.log("Navigate from Dashboard A to Dashboard B with a click action");+ H.tableInteractiveBody().findByText("2.07").click();++ H.filterWidget(TARGET_FILTER).should("contain", "2.07");+ H.filterWidget(OTHER_FILTER).should("not.contain", "10");+ });+});++describe("issue 46372", () => {+ beforeEach(() => {+ H.restore();+ cy.signInAsAdmin();+ });++ it("should not show a scrollbar when auto-connecting a dashcard filter (metabase#46372)", () => {+ H.createDashboardWithQuestions({+ questions: [+ { name: "Question A", query: { "source-table": PRODUCTS_ID } },+ { name: "Question B", query: { "source-table": PRODUCTS_ID } },+ ],+ }).then(({ dashboard }) => {+ H.visitDashboard(dashboard.id);+ H.editDashboard(dashboard.id);++ H.setFilter("Text or Category", "Is");+ H.selectDashboardFilter(cy.findAllByTestId("dashcard").first(), "Title");+ H.undoToast().findByRole("button", { name: "Auto-connect" }).click();++ H.main().findByText("Auto-connected").should("be.visible");+ H.main()+ .findByText("Auto-connected")+ .parent()+ .parent()+ .then(($body) => {+ cy.wrap($body[0].scrollHeight).should("eq", $body[0].offsetHeight);+ });+ });+ });+});++describe("issue 49319", () => {+ beforeEach(() => {+ H.restore();+ cy.signInAsNormalUser();+ });++ it("should ignore parameters that not exist in the saved dashboard in edit mode (metabase#49319)", () => {+ cy.log("open an existing dashboard");+ H.visitDashboard(ORDERS_DASHBOARD_ID);++ cy.log("add a parameter and save the dashboard");+ H.editDashboard();+ H.setFilter("Text or Category", "Is");+ H.selectDashboardFilter(H.getDashboardCard(), "Vendor");+ H.saveDashboard();++ cy.log("add another parameter to the dashboard with a default value");+ H.editDashboard();+ H.setFilter("Text or Category", "Is");+ H.selectDashboardFilter(H.getDashboardCard(), "Category");+ H.dashboardParameterSidebar().findByText("No default").click();+ H.popover().within(() => {+ cy.findByText("Gadget").click();+ cy.button("Add filter").click();+ });+ H.dashboardParameterSidebar().button("Done").click();++ cy.log("change the value for the saved parameter");+ cy.findByTestId("fixed-width-filters").findByText("Text").click();+ H.dashboardParameterSidebar().findByText("No default").click();+ H.popover().within(() => {+ cy.findByText("Americo Sipes and Sons").click();+ cy.findByText("Barrows-Johns").click();+ cy.button("Add filter").click();+ });+ H.dashboardParameterSidebar().button("Done").click();++ cy.log("the unsaved parameter should be ignored in edit mode");+ H.assertTableRowsCount(179);++ cy.log("both parameters should be applied when the dashboard is saved");+ H.saveDashboard();+ H.assertTableRowsCount(82);+ });+});++describe("issue #66670", () => {+ const questionA = {+ name: "Question A",+ query: {+ "source-table": PRODUCTS_ID,+ limit: 10,+ },+ };++ const questionB = {+ name: "Question B",+ query: {+ "source-table": PRODUCTS_ID,+ aggregation: [["count"]],+ breakout: [["field", PRODUCTS.CATEGORY, null]],+ },+ };++ beforeEach(() => {+ H.restore();+ cy.signInAsAdmin();+ cy.intercept("PUT", "/api/dashboard/*").as("updateDashboard");+ cy.intercept("GET", "/api/revision*").as("revisionHistory");+ });++ it("should handle dashboard filter with permanently deleted question value source (metabase#66670)", () => {+ cy.log("Step 1: Create a new dashboard");+ H.createDashboard({ name: "Test Dashboard UXW-2494" }).then(+ ({ body: { id: dashboardId } }) => {+ cy.log("Step 2: Add Question A to the dashboard");+ H.createQuestion(questionA).then(({ body: { id: questionAId } }) => {+ H.updateDashboardCards({+ dashboard_id: dashboardId,+ cards: [+ {+ card_id: questionAId,+ row: 0,+ col: 0,+ size_x: 12,+ size_y: 8,+ },+ ],+ });++ cy.log("Step 3: Create Question B (not added to dashboard)");+ H.createQuestion(questionB).then(({ body: { id: questionBId } }) => {+ cy.log(+ "Step 4: Edit dashboard, add filter with Question B as value source",+ );+ H.visitDashboard(dashboardId);+ H.editDashboard();+ H.setFilter("Text or Category", "Is");++ // Map filter to Question A+ cy.findByText("Select…").click();+ H.popover().within(() => cy.findByText("Category").click());++ // Set filter value source to Question B+ H.setFilterQuestionSource({+ question: questionB.name,+ field: "Category",+ });++ cy.log("Step 5: Save the dashboard");+ H.saveDashboard();+ cy.wait("@updateDashboard");++ cy.log("Step 5b: Update the title and save again");+ H.editDashboard();+ cy.findByTestId("dashboard-header")+ .findByDisplayValue("Test Dashboard UXW-2494")+ .clear()+ .type("Updated Dashboard Title");+ H.saveDashboard();+ cy.wait("@updateDashboard");++ cy.log("Step 6: Move Question B to the trash");+ H.visitQuestion(questionBId);+ H.openQuestionActions();+ H.popover().findByText("Move to trash").click();+ H.modal().findByText("Move to trash").click();++ cy.log(+ "Step 8: Revert dashboard to earlier version where filter used Question B",+ );+ H.visitDashboard(dashboardId);+ H.openDashboardInfoSidebar();+ H.sidesheet().within(() => {+ cy.findByRole("tab", { name: "History" }).click();+ cy.wait("@revisionHistory");+ // Click revert on the version that added the filter with Question B source+ cy.findByTestId("dashboard-history-list")+ .findAllByLabelText(/revert to You edited this/i)+ .first()+ .click();+ });+ // Close sidesheet+ H.sidesheet().findByLabelText("Close").click();++ cy.log("Step 9: Permanently delete Question B from trash");+ cy.request("DELETE", `/api/card/${questionBId}`);++ cy.log("Step 10: Try to add another filter and save → Save fails");+ H.editDashboard();+ H.setFilter("Number");+ cy.findByText("Select…").click();+ H.popover().within(() => cy.findByText("Price").click());++ cy.intercept("PUT", `/api/dashboard/${dashboardId}`).as(+ "saveDashboard",+ );+ cy.findByTestId("edit-bar").button("Save").click();++ cy.wait("@saveDashboard").then((interception) => {+ expect(interception.response.statusCode).to.eq(200);+ });++ cy.log(+ "Step 11: Edit existing filter, click Edit → modal loads indefinitely",+ );+ H.visitDashboard(dashboardId);+ H.editDashboard();+ H.filterWidget({ isEditing: true }).first().click();+ H.dashboardParameterSidebar().findByText("Edit").click();++ H.modal().should("be.visible");+ H.modal().within(() => {+ cy.findByText("Where values should come from", {+ timeout: 10000,+ }).should("be.visible");+ cy.findByText("From connected fields").should("be.visible");+ cy.findByText("From another model or question").should(+ "be.visible",+ );+ cy.findByText("Custom list").should("be.visible");+ });+ });+ });+ },+ );+ });+});diff --git a/e2e/test/scenarios/models/reproductions.cy.spec.ts b/e2e/test/scenarios/models/reproductions-1.cy.spec.tssimilarity index 58%rename from e2e/test/scenarios/models/reproductions.cy.spec.tsrename to e2e/test/scenarios/models/reproductions-1.cy.spec.tsindex 72df7b4ca55..acd65ad4891 100644--- a/e2e/test/scenarios/models/reproductions.cy.spec.ts+++ b/e2e/test/scenarios/models/reproductions-1.cy.spec.ts@@ -1,35 +1,16 @@const { H } = cy;-import { SAMPLE_DB_ID, USER_GROUPS } from "e2e/support/cypress_data";import { SAMPLE_DATABASE } from "e2e/support/cypress_sample_database";import {- FIRST_COLLECTION_ID,ORDERS_DASHBOARD_ID,ORDERS_MODEL_ID,ORDERS_QUESTION_ID,} from "e2e/support/cypress_sample_instance_data";-import type {- NativeQuestionDetails,- StructuredQuestionDetails,-} from "e2e/support/helpers";-import { DataPermissionValue } from "metabase/admin/permissions/types";-import type {- CardId,- FieldReference,- GroupPermissions,- NativePermissions,-} from "metabase-types/api";--const {- ORDERS,- ORDERS_ID,- PRODUCTS,- PRODUCTS_ID,- REVIEWS,- REVIEWS_ID,- PEOPLE,- PEOPLE_ID,-} = SAMPLE_DATABASE;+import type { StructuredQuestionDetails } from "e2e/support/helpers";+import type { CardId, FieldReference } from "metabase-types/api";++const { ORDERS, ORDERS_ID, PRODUCTS, PRODUCTS_ID, PEOPLE, PEOPLE_ID } =+ SAMPLE_DATABASE;describe("issue 29943", () => {function reorderTotalAndCustomColumns() {@@ -1240,880 +1221,3 @@ describe("issue 34514", () => {});}});--describe("issue 47988", () => {- const model1Details: StructuredQuestionDetails = {- name: "M1",- query: {- "source-table": ORDERS_ID,- joins: [- {- "source-table": PRODUCTS_ID,- alias: "Products",- condition: [- "=",- ["field", ORDERS.PRODUCT_ID, null],- ["field", PRODUCTS.ID, { "join-alias": "Products" }],- ],- fields: "all",- },- ],- },- };-- const model2Details: StructuredQuestionDetails = {- name: "M2",- query: {- "source-table": ORDERS_ID,- joins: [- {- "source-table": PRODUCTS_ID,- alias: "Products",- condition: [- "=",- ["field", ORDERS.PRODUCT_ID, null],- ["field", PRODUCTS.ID, { "join-alias": "Products" }],- ],- fields: "all",- },- {- "source-table": REVIEWS_ID,- alias: "Reviews",- condition: [- "=",- ["field", ORDERS.PRODUCT_ID, null],- ["field", REVIEWS.PRODUCT_ID, { "join-alias": "Reviews" }],- ],- fields: "all",- },- ],- },- };-- beforeEach(() => {- H.restore();- cy.signInAsNormalUser();- });-- it("should be able to execute a query with joins to the same table in base queries (metabase#47988)", () => {- H.createQuestion(model1Details);- H.createQuestion(model2Details);- H.startNewQuestion();- H.miniPicker().within(() => {- cy.findByText("Our analytics").click();- cy.findByText("M1").click();- });- H.join();- H.miniPicker().within(() => {- cy.findByText("Our analytics").click();- cy.findByText("M2").click();- });- H.visualize();- H.tableInteractive().should("be.visible");- });-});--describe("issue 46221", () => {- const modelDetails: NativeQuestionDetails = {- name: "46221",- native: { query: "select 42" },- type: "model",- collection_id: FIRST_COLLECTION_ID as number,- };-- beforeEach(() => {- H.restore();- cy.signInAsAdmin();-- H.createNativeQuestion(modelDetails, { visitQuestion: true });- });-- it("should retain the same collection name between ad-hoc question based on a model and a model itself (metabase#46221)", () => {- cy.location("pathname").should("match", /^\/model\/\d+/);- cy.findByTestId("head-crumbs-container")- .should("contain", "First collection")- .and("contain", modelDetails.name);-- cy.log("Change the viz type");- H.openVizTypeSidebar();- cy.findByTestId("sidebar-left").within(() => {- cy.findByTestId("more-charts-toggle").click();- cy.findByTestId("Table-button").click();- });-- cy.log("Make sure we're now in an ad-hoc question mode");- cy.location("pathname").should("eq", "/question");-- cy.findByTestId("head-crumbs-container")- .should("contain", "First collection")- .and("contain", modelDetails.name);- });-});--describe("issue 20624", () => {- const questionDetails: StructuredQuestionDetails = {- name: "Question",- type: "question",- query: {- "source-table": PRODUCTS_ID,- },- visualization_settings: {- column_settings: {- '["name","VENDOR"]': { column_title: "Retailer" },- },- },- };-- beforeEach(() => {- H.restore();- cy.signInAsNormalUser();- cy.intercept("PUT", "/api/card/*").as("updateCard");- });-- it("should reset the question's viz settings when converting to a model (metabase#20624)", () => {- cy.log("check that a column is renamed via the viz settings");- H.createQuestion(questionDetails, { visitQuestion: true });- H.tableInteractive().within(() => {- cy.findByText("Retailer").should("be.visible");- cy.findByText("Vendor").should("not.exist");- });-- cy.log("check that the viz settings are reset when converting to a model");- H.openQuestionActions();- H.popover().findByText("Turn into a model").click();- H.modal().findByText("Turn this into a model").click();- cy.wait("@updateCard");- H.tableInteractive().within(() => {- cy.findByText("Vendor").should("be.visible");- cy.findByText("Retailer").should("not.exist");- });-- cy.log("rename the column using the model's metadata");- H.openQuestionActions();- H.popover().findByText("Edit metadata").click();- H.waitForLoaderToBeRemoved();- H.tableHeaderClick("Vendor");- cy.findByLabelText("Display name").clear().type("Retailer");- cy.button("Save changes").should("be.enabled").click();- cy.wait("@updateCard");- H.tableInteractive().within(() => {- cy.findByText("Retailer").should("be.visible");- cy.findByText("Vendor").should("not.exist");- });- });-});--describe("issue 37300", () => {- beforeEach(() => {- H.restore();- cy.signInAsNormalUser();-- H.createQuestion(- {- type: "model",- query: {- "source-table": PRODUCTS_ID,- filter: ["=", ["field", PRODUCTS.ID, null], "999991"],- },- },- { visitQuestion: true },- );- });-- it("should show the table headers even when there are no results (metabase/metabase#37300)", () => {- H.openQuestionActions();- H.popover().findByText("Edit metadata").click();- H.waitForLoaderToBeRemoved();-- H.main().within(() => {- cy.findByText("ID").should("be.visible");- cy.findByText("Ean").should("be.visible");-- cy.findByText("No results!").should("be.visible");- });- });-});--describe("issue 32037", () => {- beforeEach(() => {- H.restore();- cy.signInAsNormalUser();-- cy.visit("/browse/models");- cy.findByLabelText("Orders Model").click();- H.tableInteractive().should("be.visible");- cy.location("pathname").as("modelPathname");- });-- it("should show unsaved changes modal and allow to discard changes when editing model's query (metabase#32037)", () => {- H.openQuestionActions("Edit query definition");- cy.button("Save changes").should("be.disabled");- H.filter({ mode: "notebook" });- H.popover().within(() => {- cy.findByText("ID").click();- cy.findByPlaceholderText("Enter an ID").type("1").blur();- cy.button("Add filter").click();- });- cy.button("Save changes").should("be.enabled");- cy.go("back");-- verifyDiscardingChanges();- });-- it("should show unsaved changes modal and allow to discard changes when editing model's metadata (metabase#32037)", () => {- H.openQuestionActions("Edit metadata");- H.waitForLoaderToBeRemoved();- cy.button("Save changes").should("be.disabled");- cy.findByLabelText("Description").type("123").blur();- cy.button("Save changes").should("be.enabled");- cy.go("back");-- verifyDiscardingChanges();- });-- function verifyDiscardingChanges() {- H.modal().within(() => {- cy.findByText("Discard your changes?").should("be.visible");- cy.findByText("Discard changes").click();- });-- H.tableInteractive().should("be.visible");- cy.button("Save changes").should("not.exist");- cy.get("@modelPathname").then((modelPathname) => {- cy.location("pathname").should("eq", modelPathname);- });- }-});--describe("issue 51925", () => {- function setLinkDisplayType() {- cy.findByTestId("chart-settings-widget-view_as").findByText("Link").click();- }-- function linkTextInput() {- return cy- .findByTestId("chart-settings-widget-link_text")- .findByRole("combobox");- }-- function linkUrlInput() {- return cy- .findByTestId("chart-settings-widget-link_url")- .findByRole("combobox");- }-- beforeEach(() => {- H.restore();- cy.signInAsAdmin();- });-- it('should allow to set "Display as Link" options independently for each column (metabase#51925)', () => {- H.visitModel(ORDERS_MODEL_ID);- H.openQuestionActions("Edit metadata");- H.waitForLoaderToBeRemoved();- H.tableInteractive().findByText("User ID").click();- H.rightSidebar().within(() => {- setLinkDisplayType();- linkTextInput().type("User {{USER_ID}}", {- parseSpecialCharSequences: false,- });- linkUrlInput().type("https://example.com/{{USER_ID}}", {- parseSpecialCharSequences: false,- });- });- H.tableInteractive().findByText("Product ID").click();- H.rightSidebar().within(() => {- setLinkDisplayType();- linkTextInput().type("Product {{PRODUCT_ID}}", {- parseSpecialCharSequences: false,- });- linkUrlInput().type("https://example.com/{{PRODUCT_ID}}", {- parseSpecialCharSequences: false,- });- });- H.tableInteractive().findByText("User ID").click();- H.rightSidebar().within(() => {- linkTextInput().should("have.value", "User {{USER_ID}}");- linkUrlInput().should("have.value", "https://example.com/{{USER_ID}}");- });- H.saveMetadataChanges();- H.tableInteractive().within(() => {- cy.findAllByRole("link", { name: "User 1" })- .first()- .should("have.attr", "href", "https://example.com/1");- cy.findAllByRole("link", { name: "Product 6" })- .first()- .should("have.attr", "href", "https://example.com/6");- });- });-});--describe("issue 53649", () => {- beforeEach(() => {- H.restore();- cy.signInAsAdmin();- });-- it("should not get caught in an infinite loop when opening the native editor (metabase#53649)", () => {- H.startNewNativeModel();-- // If the app freezes, this won't work- H.NativeEditor.type("select 1");- H.NativeEditor.get().should("contain", "select 1");- });-});--describe("issue 56698", () => {- beforeEach(() => {- H.restore();- });-- it("should create an editable ad-hoc query based on a read-only native model (metabase#56698)", () => {- cy.log("create a native model");- cy.signInAsNormalUser();- H.createNativeQuestion(- {- name: "Native model",- native: { query: "select 1 union all select 2" },- type: "model",- },- { wrapId: true, idAlias: "modelId" },- );-- cy.log("verify that we create an editable ad-hoc query");- cy.signIn("readonlynosql");- cy.get("@modelId").then((modelId) => H.visitModel(Number(modelId)));- H.assertQueryBuilderRowCount(2);- H.summarize();- H.rightSidebar().button("Done").click();- H.assertQueryBuilderRowCount(1);- });-});--describe("issue 57557", () => {- beforeEach(() => {- H.restore();- });-- it("should not allow to see the query definition for a user without data permissions (metabase#57557)", () => {- cy.log("create a native model");- cy.signInAsNormalUser();- H.createNativeQuestion(- {- name: "Native model",- native: { query: "select 1 union all select 2" },- type: "model",- },- { wrapId: true, idAlias: "modelId" },- );-- cy.log("verify that query editing functionality is hidden");- cy.signIn("nodata");- cy.get("@modelId").then((modelId) =>- H.visitModel(Number(modelId), { hasDataAccess: false }),- );- H.openQuestionActions();- H.popover().within(() => {- cy.findByText("Edit metadata").should("be.visible");- cy.findByText("Edit query definition").should("not.exist");- cy.findByText("Edit metadata").click();- });- H.waitForLoaderToBeRemoved();- cy.findByTestId("editor-tabs-query").should("be.disabled");- cy.findByTestId("editor-tabs-columns").should("be.checked");- });-});--describe("issue 56775", () => {- const MODEL_NAME = "Model 56775";-- beforeEach(() => {- H.restore();- cy.signInAsNormalUser();- H.createQuestion(- {- type: "model",- name: MODEL_NAME,- query: {- "source-table": PRODUCTS_ID,- },- },- { visitQuestion: true },- );- });-- it("should render the correct query after using the back button in a model (metabase#56775)", () => {- H.openNotebook();- cy.button("Visualize").click();-- cy.go("back");- H.openQuestionActions("Edit query definition");-- cy.log("verify that the model definition is visible");- H.getNotebookStep("data").findByText(MODEL_NAME).should("not.exist");- H.getNotebookStep("data").findByText("Products").should("be.visible");- });-});--describe("issue 57359", () => {- beforeEach(() => {- H.restore();- cy.signInAsNormalUser();- cy.intercept("PUT", "/api/card/*").as("updateCard");- });-- it("should not break the model when editing metadata (metabase#57359)", () => {- cy.log("create a question with two joins without running the query");- H.openOrdersTable({ mode: "notebook" });- cy.wrap([1, 2]).each(() => {- H.join();- H.miniPicker().within(() => {- cy.findByText("Sample Database").click();- cy.findByText("Products").click();- });- });- H.saveQuestion("Q1");-- cy.log("turn the question into a model");- H.openQuestionActions("Turn into a model");- H.modal().button("Turn this into a model").click();- cy.wait("@updateCard");-- cy.log("edit query metadata");- H.openQuestionActions("Edit metadata");- H.waitForLoaderToBeRemoved();- H.openColumnOptions("Product ID");- H.renameColumn("Product ID", "Product ID2");- H.saveMetadataChanges();-- cy.log("make sure the query is run successfully");- H.tableInteractive().should("be.visible");- });-});--describe("issue 55486", () => {- const MODEL_NAME = "Model 55486";-- beforeEach(() => {- H.restore();- cy.signInAsNormalUser();- H.createQuestion(- {- type: "model",- name: MODEL_NAME,- query: {- "source-table": PRODUCTS_ID,- limit: 5,- },- },- { visitQuestion: true },- );- });-- function checkIsShowingMetadataEditorTab() {- cy.findByTestId("editor-tabs-columns").should("be.checked");- cy.findByTestId("visualization-root").should("be.visible");- }-- function checkIsShowingQueryEditorTab() {- cy.findByTestId("editor-tabs-query").should("be.checked");- H.getNotebookStep("data").should("be.visible");- }-- it("should render the correct query after using the back button in a model (metabase#56775)", () => {- H.openQuestionActions("Edit query definition");-- H.datasetEditBar().findByText("Columns").click();- checkIsShowingMetadataEditorTab();-- H.datasetEditBar().findByText("Query").click();- checkIsShowingQueryEditorTab();-- cy.log("Back button should show the metadata editor");- cy.go("back");- checkIsShowingMetadataEditorTab();-- cy.log("Back button should show the query editor");- cy.go("back");- checkIsShowingQueryEditorTab();-- cy.log("Forward button should show the query editor");- cy.go("forward");- checkIsShowingMetadataEditorTab();-- cy.log("Forward button should show the query editor");- cy.go("forward");- checkIsShowingQueryEditorTab();- });-});--describe("Issue 30712", () => {- beforeEach(() => {- H.restore();- cy.signInAsNormalUser();-- H.startNewModel();-- H.miniPicker().findByText("Sample Database").click();- H.miniPicker().findByText("Orders").click();- H.join();- H.joinTable("Products");-- H.join();- H.joinTable("People");- });-- it("should not crash the editor when ordering by columns on joined tables (metabase#30712)", () => {- H.getNotebookStep("summarize").findByLabelText("Sort").click();- H.popover().findByText("Total").click();-- cy.log("no error should be thrown");- cy.get("main").findByText("Something's gone wrong").should("not.exist");- cy.findByTestId("run-button").should("be.visible");- });-});--describe("issue 60930", { tags: "@skip" }, () => {- const modelDetails: StructuredQuestionDetails = {- name: "Model",- type: "model",- query: {- "source-table": ORDERS_ID,- joins: [- {- "source-table": PRODUCTS_ID,- alias: "Products",- strategy: "left-join",- fields: "all",- condition: [- "=",- ["field", ORDERS.PRODUCT_ID, { "base-type": "type/Integer" }],- [- "field",- PRODUCTS.ID,- { "base-type": "type/BigInteger", "join-alias": "Products" },- ],- ],- },- {- "source-table": REVIEWS_ID,- alias: "Reviews",- strategy: "left-join",- fields: "all",- condition: [- "=",- ["field", ORDERS.PRODUCT_ID, { "base-type": "type/Integer" }],- [- "field",- REVIEWS.PRODUCT_ID,- { "base-type": "type/Integer", "join-alias": "Reviews" },- ],- ],- },- ],- },- };-- beforeEach(() => {- H.restore();- cy.signInAsNormalUser();- });-- it("should not apply model metadata overrides to incorrect columns after changes in the query (metabase#60930)", () => {- cy.log("create a model");- H.createQuestion(modelDetails).then(({ body: card }) =>- H.visitModel(card.id),- );-- cy.log("override the column name");- H.openQuestionActions("Edit metadata");- H.waitForLoaderToBeRemoved();- H.openColumnOptions("Products → ID");- H.renameColumn("Products → ID", "ID2");- H.saveMetadataChanges();- H.tableInteractive().findByText("ID2").should("exist");-- cy.log("remove the ID2 column from the query");- H.openQuestionActions("Edit query definition");- H.getNotebookStep("join", { index: 0 })- .findByLabelText("Pick columns")- .click();- H.popover().findByLabelText("Select all").click();- H.saveMetadataChanges();- H.tableInteractive().findByText("ID2").should("not.exist");- });-});--describe("Issue 56913", () => {- beforeEach(() => {- H.restore();- cy.signInAsNormalUser();-- H.createQuestion(- {- query: {- "source-table": ORDERS_ID,- },- },- { visitQuestion: true },- );-- H.openQuestionActions();- H.popover().findByText("Turn into a model").click();- H.modal().button("Turn this into a model").click();-- H.createNativeQuestion(- {- native: {- query: "select {{ x }}",- "template-tags": {- x: {- id: "d7f1fb15-c7b8-6051-443d-604b6ed5457b",- name: "x",- "display-name": "X",- type: "text",- default: null,- },- },- },- },- { visitQuestion: true },- );- });-- it("should show the error modal when converting a native question with variables into a model, even when the 'turn into a model' modal was previously acknowledged (metabase#56913)", () => {- H.openQuestionActions();- H.popover().findByText("Turn into a model").click();- H.modal()- .findByText("Variables in models aren't supported yet")- .should("be.visible");- });-});--describe("issue 45919", () => {- beforeEach(() => {- H.restore();- cy.signInAsAdmin();- });-- it("should allow to query a model with a hidden column", () => {- cy.log("create a new model with result_metadata");- cy.visit("/model/new");- cy.findByTestId("new-model-options")- .findByText("Use the notebook editor")- .click();- H.popover().findByText("Sample Database").click();- H.popover().findByText("People").click();- H.runButtonOverlay().click();- H.tableInteractive().should("be.visible");- cy.findByTestId("dataset-edit-bar").button("Save").click();- cy.findByTestId("save-question-modal").button("Save").click();- H.queryBuilderHeader().should("be.visible");- H.tableInteractiveHeader().findByText("Password").should("be.visible");-- cy.log("hide the Password field");- cy.request("PUT", `/api/field/${PEOPLE.PASSWORD}`, {- visibility_type: "sensitive",- });-- cy.log("the query should succeed, and the Password field should be hidden");- H.queryBuilderHeader().button("Refresh").click();- H.tableInteractive().should("be.visible");- H.tableInteractiveHeader().findByText("Password").should("not.exist");- H.tableInteractiveHeader().findByText("Email").should("be.visible");- });-});--describe("issue 50915", () => {- beforeEach(() => {- H.restore();- cy.signInAsNormalUser();- });-- it("should use the model for the data source for drills after the model is created (metabase#50915)", () => {- cy.log("create a model via the UI");- cy.visit("/model/new");- H.main().findByText("Use the notebook editor").click();- H.miniPicker().within(() => {- cy.findByText("Sample Database").click();- cy.findByText("Orders").click();- });- H.join();- H.miniPicker().within(() => {- cy.findByText("Sample Database").click();- cy.findByText("People").click();- });- cy.findByTestId("dataset-edit-bar").button("Save").click();- cy.findByTestId("save-question-modal").button("Save").click();- H.queryBuilderHeader().should("be.visible");- H.queryBuilderMain()- .findByText("37.65", { timeout: 10000 })- .should("be.visible");-- cy.log("immediately after saving, drill-thru");- H.tableHeaderClick("Discount ($)");- H.popover().findByText("Distinct values").click();- H.queryBuilderMain()- .findByText("1,115", { timeout: 10000 })- .should("be.visible");- H.assertTableData({ columns: ["Distinct values of Discount"] });-- cy.log("assert that the model is used for the data source");- H.openNotebook();- H.getNotebookStep("data")- .findByText("Orders + People")- .should("be.visible");- });-});--describe("issue 38747", () => {- beforeEach(() => {- H.restore();- cy.signInAsNormalUser();- });-- it("should allow you to drill through with entity qualified ids", () => {- cy.visit("/model/new");- cy.findByRole("link", { name: /notebook editor/ }).click();-- H.miniPickerBrowseAll().click();- H.pickEntity({ path: ["Databases", "Sample Database", "Products"] });- H.runButtonInOverlay().click();-- // Wait for the query to run so we can click the columns "button"- // ... It's actually a list item, so we can't check to see if it's- // actually disabled in any sane way- H.tableInteractive().should("exist");-- H.datasetEditBar().findByText("Columns").click();- cy.findAllByTestId("model-column-header-content")- .contains("Vendor")- .click();-- cy.findByPlaceholderText("Select a semantic type").click();- H.popover().findByText("Entity Key").click();- H.datasetEditBar().button("Save").click();-- H.modal().button("Save").click();-- cy.findByRole("gridcell", { name: "Nolan-Wolff" }).click({- waitForAnimations: false,- });-- // Assert that we're at an adhoc question with aproprate filters- cy.location("pathname").should("equal", "/question");- cy.findByTestId("filter-pill").should(- "contain.text",- "Vendor is Nolan-Wolff",- );- H.tableInteractive().should("have.attr", "data-rows-count", "1");- });-});--describe("issue 67680", () => {- function setTablePermissions(createQueriesPermission: NativePermissions) {- const permissions: GroupPermissions = {- [SAMPLE_DB_ID]: {- "view-data": {- public: {- [ORDERS_ID]: DataPermissionValue.BLOCKED,- [PRODUCTS_ID]: DataPermissionValue.UNRESTRICTED,- },- },- "create-queries": createQueriesPermission,- },- };- cy.updatePermissionsGraph({- [USER_GROUPS.ALL_USERS_GROUP]: permissions,- [USER_GROUPS.DATA_GROUP]: permissions,- [USER_GROUPS.COLLECTION_GROUP]: permissions,- });- }-- function setTablePermissionsWithCreateQueries() {- setTablePermissions(DataPermissionValue.QUERY_BUILDER);- }-- function setTablePermissionsWithoutCreateQueries() {- setTablePermissions(DataPermissionValue.NO);- }-- function updateModelSourceTableWithResultMetadata() {- H.visitModel(ORDERS_MODEL_ID);- H.openQuestionActions("Edit query definition");- H.getNotebookStep("data").findByText("Orders").click();- H.popover().findByText("Products").click();- H.runButtonInOverlay().click();- H.tableInteractiveHeader().findByText("Category").should("be.visible");- H.saveMetadataChanges();- }-- function updateModelSourceTableWithoutResultMetadata() {- H.visitModel(ORDERS_MODEL_ID);- H.openQuestionActions("Edit query definition");- H.getNotebookStep("data").findByText("Orders").click();- H.popover().findByText("Products").click();- H.saveMetadataChanges();- }-- function verifyNormalUserCanAccessModel() {- cy.signInAsNormalUser();- H.visitModel(ORDERS_MODEL_ID);- H.assertQueryBuilderRowCount(200);- }-- beforeEach(() => {- H.restore();- cy.signInAsAdmin();- H.activateToken("pro-self-hosted");- });-- describe("when the user has create queries permission", () => {- beforeEach(() => {- setTablePermissionsWithCreateQueries();- });-- it("should not override column ids for a mbql model when it is saved with result_metadata (metabase#67680)", () => {- updateModelSourceTableWithResultMetadata();- verifyNormalUserCanAccessModel();- });-- it("should not override column ids for a mbql model when it is saved without result_metadata (metabase#67680)", () => {- updateModelSourceTableWithoutResultMetadata();- verifyNormalUserCanAccessModel();- });- });-- describe("when the user does not have create queries permission", () => {- beforeEach(() => {- setTablePermissionsWithoutCreateQueries();- });-- it("should not override column ids for a mbql model when it is saved with result_metadata (metabase#67680)", () => {- updateModelSourceTableWithResultMetadata();- verifyNormalUserCanAccessModel();- });-- it("should not override column ids for a mbql model when it is saved without result_metadata (metabase#67680)", () => {- updateModelSourceTableWithoutResultMetadata();- verifyNormalUserCanAccessModel();- });- });-});--describe("issue 69722", () => {- beforeEach(() => {- H.restore();- cy.signInAsNormalUser();- cy.visit("/model/new");- cy.findByRole("link", { name: /native query/ }).click();- });-- it("should not be possible to overflow the native query editor (metabase#69722)", () => {- H.NativeEditor.type("{enter}".repeat(20));-- cy.findByTestId("native-query-editor-container")- .findByTestId("run-button")- .should("be.visible");- });-});diff --git a/e2e/test/scenarios/models/reproductions-2.cy.spec.ts b/e2e/test/scenarios/models/reproductions-2.cy.spec.tsnew file mode 100644index 00000000000..02d91140861--- /dev/null+++ b/e2e/test/scenarios/models/reproductions-2.cy.spec.ts@@ -0,0 +1,901 @@+const { H } = cy;++import { SAMPLE_DB_ID, USER_GROUPS } from "e2e/support/cypress_data";+import { SAMPLE_DATABASE } from "e2e/support/cypress_sample_database";+import {+ FIRST_COLLECTION_ID,+ ORDERS_MODEL_ID,+} from "e2e/support/cypress_sample_instance_data";+import type {+ NativeQuestionDetails,+ StructuredQuestionDetails,+} from "e2e/support/helpers";+import { DataPermissionValue } from "metabase/admin/permissions/types";+import type { GroupPermissions, NativePermissions } from "metabase-types/api";++const {+ ORDERS,+ ORDERS_ID,+ PRODUCTS,+ PRODUCTS_ID,+ REVIEWS,+ REVIEWS_ID,+ PEOPLE,+} = SAMPLE_DATABASE;++describe("issue 47988", () => {+ const model1Details: StructuredQuestionDetails = {+ name: "M1",+ query: {+ "source-table": ORDERS_ID,+ joins: [+ {+ "source-table": PRODUCTS_ID,+ alias: "Products",+ condition: [+ "=",+ ["field", ORDERS.PRODUCT_ID, null],+ ["field", PRODUCTS.ID, { "join-alias": "Products" }],+ ],+ fields: "all",+ },+ ],+ },+ };++ const model2Details: StructuredQuestionDetails = {+ name: "M2",+ query: {+ "source-table": ORDERS_ID,+ joins: [+ {+ "source-table": PRODUCTS_ID,+ alias: "Products",+ condition: [+ "=",+ ["field", ORDERS.PRODUCT_ID, null],+ ["field", PRODUCTS.ID, { "join-alias": "Products" }],+ ],+ fields: "all",+ },+ {+ "source-table": REVIEWS_ID,+ alias: "Reviews",+ condition: [+ "=",+ ["field", ORDERS.PRODUCT_ID, null],+ ["field", REVIEWS.PRODUCT_ID, { "join-alias": "Reviews" }],+ ],+ fields: "all",+ },+ ],+ },+ };++ beforeEach(() => {+ H.restore();+ cy.signInAsNormalUser();+ });++ it("should be able to execute a query with joins to the same table in base queries (metabase#47988)", () => {+ H.createQuestion(model1Details);+ H.createQuestion(model2Details);+ H.startNewQuestion();+ H.miniPicker().within(() => {+ cy.findByText("Our analytics").click();+ cy.findByText("M1").click();+ });+ H.join();+ H.miniPicker().within(() => {+ cy.findByText("Our analytics").click();+ cy.findByText("M2").click();+ });+ H.visualize();+ H.tableInteractive().should("be.visible");+ });+});++describe("issue 46221", () => {+ const modelDetails: NativeQuestionDetails = {+ name: "46221",+ native: { query: "select 42" },+ type: "model",+ collection_id: FIRST_COLLECTION_ID as number,+ };++ beforeEach(() => {+ H.restore();+ cy.signInAsAdmin();++ H.createNativeQuestion(modelDetails, { visitQuestion: true });+ });++ it("should retain the same collection name between ad-hoc question based on a model and a model itself (metabase#46221)", () => {+ cy.location("pathname").should("match", /^\/model\/\d+/);+ cy.findByTestId("head-crumbs-container")+ .should("contain", "First collection")+ .and("contain", modelDetails.name);++ cy.log("Change the viz type");+ H.openVizTypeSidebar();+ cy.findByTestId("sidebar-left").within(() => {+ cy.findByTestId("more-charts-toggle").click();+ cy.findByTestId("Table-button").click();+ });++ cy.log("Make sure we're now in an ad-hoc question mode");+ cy.location("pathname").should("eq", "/question");++ cy.findByTestId("head-crumbs-container")+ .should("contain", "First collection")+ .and("contain", modelDetails.name);+ });+});++describe("issue 20624", () => {+ const questionDetails: StructuredQuestionDetails = {+ name: "Question",+ type: "question",+ query: {+ "source-table": PRODUCTS_ID,+ },+ visualization_settings: {+ column_settings: {+ '["name","VENDOR"]': { column_title: "Retailer" },+ },+ },+ };++ beforeEach(() => {+ H.restore();+ cy.signInAsNormalUser();+ cy.intercept("PUT", "/api/card/*").as("updateCard");+ });++ it("should reset the question's viz settings when converting to a model (metabase#20624)", () => {+ cy.log("check that a column is renamed via the viz settings");+ H.createQuestion(questionDetails, { visitQuestion: true });+ H.tableInteractive().within(() => {+ cy.findByText("Retailer").should("be.visible");+ cy.findByText("Vendor").should("not.exist");+ });++ cy.log("check that the viz settings are reset when converting to a model");+ H.openQuestionActions();+ H.popover().findByText("Turn into a model").click();+ H.modal().findByText("Turn this into a model").click();+ cy.wait("@updateCard");+ H.tableInteractive().within(() => {+ cy.findByText("Vendor").should("be.visible");+ cy.findByText("Retailer").should("not.exist");+ });++ cy.log("rename the column using the model's metadata");+ H.openQuestionActions();+ H.popover().findByText("Edit metadata").click();+ H.waitForLoaderToBeRemoved();+ H.tableHeaderClick("Vendor");+ cy.findByLabelText("Display name").clear().type("Retailer");+ cy.button("Save changes").should("be.enabled").click();+ cy.wait("@updateCard");+ H.tableInteractive().within(() => {+ cy.findByText("Retailer").should("be.visible");+ cy.findByText("Vendor").should("not.exist");+ });+ });+});++describe("issue 37300", () => {+ beforeEach(() => {+ H.restore();+ cy.signInAsNormalUser();++ H.createQuestion(+ {+ type: "model",+ query: {+ "source-table": PRODUCTS_ID,+ filter: ["=", ["field", PRODUCTS.ID, null], "999991"],+ },+ },+ { visitQuestion: true },+ );+ });++ it("should show the table headers even when there are no results (metabase/metabase#37300)", () => {+ H.openQuestionActions();+ H.popover().findByText("Edit metadata").click();+ H.waitForLoaderToBeRemoved();++ H.main().within(() => {+ cy.findByText("ID").should("be.visible");+ cy.findByText("Ean").should("be.visible");++ cy.findByText("No results!").should("be.visible");+ });+ });+});++describe("issue 32037", () => {+ beforeEach(() => {+ H.restore();+ cy.signInAsNormalUser();++ cy.visit("/browse/models");+ cy.findByLabelText("Orders Model").click();+ H.tableInteractive().should("be.visible");+ cy.location("pathname").as("modelPathname");+ });++ it("should show unsaved changes modal and allow to discard changes when editing model's query (metabase#32037)", () => {+ H.openQuestionActions("Edit query definition");+ cy.button("Save changes").should("be.disabled");+ H.filter({ mode: "notebook" });+ H.popover().within(() => {+ cy.findByText("ID").click();+ cy.findByPlaceholderText("Enter an ID").type("1").blur();+ cy.button("Add filter").click();+ });+ cy.button("Save changes").should("be.enabled");+ cy.go("back");++ verifyDiscardingChanges();+ });++ it("should show unsaved changes modal and allow to discard changes when editing model's metadata (metabase#32037)", () => {+ H.openQuestionActions("Edit metadata");+ H.waitForLoaderToBeRemoved();+ cy.button("Save changes").should("be.disabled");+ cy.findByLabelText("Description").type("123").blur();+ cy.button("Save changes").should("be.enabled");+ cy.go("back");++ verifyDiscardingChanges();+ });++ function verifyDiscardingChanges() {+ H.modal().within(() => {+ cy.findByText("Discard your changes?").should("be.visible");+ cy.findByText("Discard changes").click();+ });++ H.tableInteractive().should("be.visible");+ cy.button("Save changes").should("not.exist");+ cy.get("@modelPathname").then((modelPathname) => {+ cy.location("pathname").should("eq", modelPathname);+ });+ }+});++describe("issue 51925", () => {+ function setLinkDisplayType() {+ cy.findByTestId("chart-settings-widget-view_as").findByText("Link").click();+ }++ function linkTextInput() {+ return cy+ .findByTestId("chart-settings-widget-link_text")+ .findByRole("combobox");+ }++ function linkUrlInput() {+ return cy+ .findByTestId("chart-settings-widget-link_url")+ .findByRole("combobox");+ }++ beforeEach(() => {+ H.restore();+ cy.signInAsAdmin();+ });++ it('should allow to set "Display as Link" options independently for each column (metabase#51925)', () => {+ H.visitModel(ORDERS_MODEL_ID);+ H.openQuestionActions("Edit metadata");+ H.waitForLoaderToBeRemoved();+ H.tableInteractive().findByText("User ID").click();+ H.rightSidebar().within(() => {+ setLinkDisplayType();+ linkTextInput().type("User {{USER_ID}}", {+ parseSpecialCharSequences: false,+ });+ linkUrlInput().type("https://example.com/{{USER_ID}}", {+ parseSpecialCharSequences: false,+ });+ });+ H.tableInteractive().findByText("Product ID").click();+ H.rightSidebar().within(() => {+ setLinkDisplayType();+ linkTextInput().type("Product {{PRODUCT_ID}}", {+ parseSpecialCharSequences: false,+ });+ linkUrlInput().type("https://example.com/{{PRODUCT_ID}}", {+ parseSpecialCharSequences: false,+ });+ });+ H.tableInteractive().findByText("User ID").click();+ H.rightSidebar().within(() => {+ linkTextInput().should("have.value", "User {{USER_ID}}");+ linkUrlInput().should("have.value", "https://example.com/{{USER_ID}}");+ });+ H.saveMetadataChanges();+ H.tableInteractive().within(() => {+ cy.findAllByRole("link", { name: "User 1" })+ .first()+ .should("have.attr", "href", "https://example.com/1");+ cy.findAllByRole("link", { name: "Product 6" })+ .first()+ .should("have.attr", "href", "https://example.com/6");+ });+ });+});++describe("issue 53649", () => {+ beforeEach(() => {+ H.restore();+ cy.signInAsAdmin();+ });++ it("should not get caught in an infinite loop when opening the native editor (metabase#53649)", () => {+ H.startNewNativeModel();++ // If the app freezes, this won't work+ H.NativeEditor.type("select 1");+ H.NativeEditor.get().should("contain", "select 1");+ });+});++describe("issue 56698", () => {+ beforeEach(() => {+ H.restore();+ });++ it("should create an editable ad-hoc query based on a read-only native model (metabase#56698)", () => {+ cy.log("create a native model");+ cy.signInAsNormalUser();+ H.createNativeQuestion(+ {+ name: "Native model",+ native: { query: "select 1 union all select 2" },+ type: "model",+ },+ { wrapId: true, idAlias: "modelId" },+ );++ cy.log("verify that we create an editable ad-hoc query");+ cy.signIn("readonlynosql");+ cy.get("@modelId").then((modelId) => H.visitModel(Number(modelId)));+ H.assertQueryBuilderRowCount(2);+ H.summarize();+ H.rightSidebar().button("Done").click();+ H.assertQueryBuilderRowCount(1);+ });+});++describe("issue 57557", () => {+ beforeEach(() => {+ H.restore();+ });++ it("should not allow to see the query definition for a user without data permissions (metabase#57557)", () => {+ cy.log("create a native model");+ cy.signInAsNormalUser();+ H.createNativeQuestion(+ {+ name: "Native model",+ native: { query: "select 1 union all select 2" },+ type: "model",+ },+ { wrapId: true, idAlias: "modelId" },+ );++ cy.log("verify that query editing functionality is hidden");+ cy.signIn("nodata");+ cy.get("@modelId").then((modelId) =>+ H.visitModel(Number(modelId), { hasDataAccess: false }),+ );+ H.openQuestionActions();+ H.popover().within(() => {+ cy.findByText("Edit metadata").should("be.visible");+ cy.findByText("Edit query definition").should("not.exist");+ cy.findByText("Edit metadata").click();+ });+ H.waitForLoaderToBeRemoved();+ cy.findByTestId("editor-tabs-query").should("be.disabled");+ cy.findByTestId("editor-tabs-columns").should("be.checked");+ });+});++describe("issue 56775", () => {+ const MODEL_NAME = "Model 56775";++ beforeEach(() => {+ H.restore();+ cy.signInAsNormalUser();+ H.createQuestion(+ {+ type: "model",+ name: MODEL_NAME,+ query: {+ "source-table": PRODUCTS_ID,+ },+ },+ { visitQuestion: true },+ );+ });++ it("should render the correct query after using the back button in a model (metabase#56775)", () => {+ H.openNotebook();+ cy.button("Visualize").click();++ cy.go("back");+ H.openQuestionActions("Edit query definition");++ cy.log("verify that the model definition is visible");+ H.getNotebookStep("data").findByText(MODEL_NAME).should("not.exist");+ H.getNotebookStep("data").findByText("Products").should("be.visible");+ });+});++describe("issue 57359", () => {+ beforeEach(() => {+ H.restore();+ cy.signInAsNormalUser();+ cy.intercept("PUT", "/api/card/*").as("updateCard");+ });++ it("should not break the model when editing metadata (metabase#57359)", () => {+ cy.log("create a question with two joins without running the query");+ H.openOrdersTable({ mode: "notebook" });+ cy.wrap([1, 2]).each(() => {+ H.join();+ H.miniPicker().within(() => {+ cy.findByText("Sample Database").click();+ cy.findByText("Products").click();+ });+ });+ H.saveQuestion("Q1");++ cy.log("turn the question into a model");+ H.openQuestionActions("Turn into a model");+ H.modal().button("Turn this into a model").click();+ cy.wait("@updateCard");++ cy.log("edit query metadata");+ H.openQuestionActions("Edit metadata");+ H.waitForLoaderToBeRemoved();+ H.openColumnOptions("Product ID");+ H.renameColumn("Product ID", "Product ID2");+ H.saveMetadataChanges();++ cy.log("make sure the query is run successfully");+ H.tableInteractive().should("be.visible");+ });+});++describe("issue 55486", () => {+ const MODEL_NAME = "Model 55486";++ beforeEach(() => {+ H.restore();+ cy.signInAsNormalUser();+ H.createQuestion(+ {+ type: "model",+ name: MODEL_NAME,+ query: {+ "source-table": PRODUCTS_ID,+ limit: 5,+ },+ },+ { visitQuestion: true },+ );+ });++ function checkIsShowingMetadataEditorTab() {+ cy.findByTestId("editor-tabs-columns").should("be.checked");+ cy.findByTestId("visualization-root").should("be.visible");+ }++ function checkIsShowingQueryEditorTab() {+ cy.findByTestId("editor-tabs-query").should("be.checked");+ H.getNotebookStep("data").should("be.visible");+ }++ it("should render the correct query after using the back button in a model (metabase#56775)", () => {+ H.openQuestionActions("Edit query definition");++ H.datasetEditBar().findByText("Columns").click();+ checkIsShowingMetadataEditorTab();++ H.datasetEditBar().findByText("Query").click();+ checkIsShowingQueryEditorTab();++ cy.log("Back button should show the metadata editor");+ cy.go("back");+ checkIsShowingMetadataEditorTab();++ cy.log("Back button should show the query editor");+ cy.go("back");+ checkIsShowingQueryEditorTab();++ cy.log("Forward button should show the query editor");+ cy.go("forward");+ checkIsShowingMetadataEditorTab();++ cy.log("Forward button should show the query editor");+ cy.go("forward");+ checkIsShowingQueryEditorTab();+ });+});++describe("Issue 30712", () => {+ beforeEach(() => {+ H.restore();+ cy.signInAsNormalUser();++ H.startNewModel();++ H.miniPicker().findByText("Sample Database").click();+ H.miniPicker().findByText("Orders").click();+ H.join();+ H.joinTable("Products");++ H.join();+ H.joinTable("People");+ });++ it("should not crash the editor when ordering by columns on joined tables (metabase#30712)", () => {+ H.getNotebookStep("summarize").findByLabelText("Sort").click();+ H.popover().findByText("Total").click();++ cy.log("no error should be thrown");+ cy.get("main").findByText("Something's gone wrong").should("not.exist");+ cy.findByTestId("run-button").should("be.visible");+ });+});++describe("issue 60930", { tags: "@skip" }, () => {+ const modelDetails: StructuredQuestionDetails = {+ name: "Model",+ type: "model",+ query: {+ "source-table": ORDERS_ID,+ joins: [+ {+ "source-table": PRODUCTS_ID,+ alias: "Products",+ strategy: "left-join",+ fields: "all",+ condition: [+ "=",+ ["field", ORDERS.PRODUCT_ID, { "base-type": "type/Integer" }],+ [+ "field",+ PRODUCTS.ID,+ { "base-type": "type/BigInteger", "join-alias": "Products" },+ ],+ ],+ },+ {+ "source-table": REVIEWS_ID,+ alias: "Reviews",+ strategy: "left-join",+ fields: "all",+ condition: [+ "=",+ ["field", ORDERS.PRODUCT_ID, { "base-type": "type/Integer" }],+ [+ "field",+ REVIEWS.PRODUCT_ID,+ { "base-type": "type/Integer", "join-alias": "Reviews" },+ ],+ ],+ },+ ],+ },+ };++ beforeEach(() => {+ H.restore();+ cy.signInAsNormalUser();+ });++ it("should not apply model metadata overrides to incorrect columns after changes in the query (metabase#60930)", () => {+ cy.log("create a model");+ H.createQuestion(modelDetails).then(({ body: card }) =>+ H.visitModel(card.id),+ );++ cy.log("override the column name");+ H.openQuestionActions("Edit metadata");+ H.waitForLoaderToBeRemoved();+ H.openColumnOptions("Products → ID");+ H.renameColumn("Products → ID", "ID2");+ H.saveMetadataChanges();+ H.tableInteractive().findByText("ID2").should("exist");++ cy.log("remove the ID2 column from the query");+ H.openQuestionActions("Edit query definition");+ H.getNotebookStep("join", { index: 0 })+ .findByLabelText("Pick columns")+ .click();+ H.popover().findByLabelText("Select all").click();+ H.saveMetadataChanges();+ H.tableInteractive().findByText("ID2").should("not.exist");+ });+});++describe("Issue 56913", () => {+ beforeEach(() => {+ H.restore();+ cy.signInAsNormalUser();++ H.createQuestion(+ {+ query: {+ "source-table": ORDERS_ID,+ },+ },+ { visitQuestion: true },+ );++ H.openQuestionActions();+ H.popover().findByText("Turn into a model").click();+ H.modal().button("Turn this into a model").click();++ H.createNativeQuestion(+ {+ native: {+ query: "select {{ x }}",+ "template-tags": {+ x: {+ id: "d7f1fb15-c7b8-6051-443d-604b6ed5457b",+ name: "x",+ "display-name": "X",+ type: "text",+ default: null,+ },+ },+ },+ },+ { visitQuestion: true },+ );+ });++ it("should show the error modal when converting a native question with variables into a model, even when the 'turn into a model' modal was previously acknowledged (metabase#56913)", () => {+ H.openQuestionActions();+ H.popover().findByText("Turn into a model").click();+ H.modal()+ .findByText("Variables in models aren't supported yet")+ .should("be.visible");+ });+});++describe("issue 45919", () => {+ beforeEach(() => {+ H.restore();+ cy.signInAsAdmin();+ });++ it("should allow to query a model with a hidden column", () => {+ cy.log("create a new model with result_metadata");+ cy.visit("/model/new");+ cy.findByTestId("new-model-options")+ .findByText("Use the notebook editor")+ .click();+ H.popover().findByText("Sample Database").click();+ H.popover().findByText("People").click();+ H.runButtonOverlay().click();+ H.tableInteractive().should("be.visible");+ cy.findByTestId("dataset-edit-bar").button("Save").click();+ cy.findByTestId("save-question-modal").button("Save").click();+ H.queryBuilderHeader().should("be.visible");+ H.tableInteractiveHeader().findByText("Password").should("be.visible");++ cy.log("hide the Password field");+ cy.request("PUT", `/api/field/${PEOPLE.PASSWORD}`, {+ visibility_type: "sensitive",+ });++ cy.log("the query should succeed, and the Password field should be hidden");+ H.queryBuilderHeader().button("Refresh").click();+ H.tableInteractive().should("be.visible");+ H.tableInteractiveHeader().findByText("Password").should("not.exist");+ H.tableInteractiveHeader().findByText("Email").should("be.visible");+ });+});++describe("issue 50915", () => {+ beforeEach(() => {+ H.restore();+ cy.signInAsNormalUser();+ });++ it("should use the model for the data source for drills after the model is created (metabase#50915)", () => {+ cy.log("create a model via the UI");+ cy.visit("/model/new");+ H.main().findByText("Use the notebook editor").click();+ H.miniPicker().within(() => {+ cy.findByText("Sample Database").click();+ cy.findByText("Orders").click();+ });+ H.join();+ H.miniPicker().within(() => {+ cy.findByText("Sample Database").click();+ cy.findByText("People").click();+ });+ cy.findByTestId("dataset-edit-bar").button("Save").click();+ cy.findByTestId("save-question-modal").button("Save").click();+ H.queryBuilderHeader().should("be.visible");+ H.queryBuilderMain()+ .findByText("37.65", { timeout: 10000 })+ .should("be.visible");++ cy.log("immediately after saving, drill-thru");+ H.tableHeaderClick("Discount ($)");+ H.popover().findByText("Distinct values").click();+ H.queryBuilderMain()+ .findByText("1,115", { timeout: 10000 })+ .should("be.visible");+ H.assertTableData({ columns: ["Distinct values of Discount"] });++ cy.log("assert that the model is used for the data source");+ H.openNotebook();+ H.getNotebookStep("data")+ .findByText("Orders + People")+ .should("be.visible");+ });+});++describe("issue 38747", () => {+ beforeEach(() => {+ H.restore();+ cy.signInAsNormalUser();+ });++ it("should allow you to drill through with entity qualified ids", () => {+ cy.visit("/model/new");+ cy.findByRole("link", { name: /notebook editor/ }).click();++ H.miniPickerBrowseAll().click();+ H.pickEntity({ path: ["Databases", "Sample Database", "Products"] });+ H.runButtonInOverlay().click();++ // Wait for the query to run so we can click the columns "button"+ // ... It's actually a list item, so we can't check to see if it's+ // actually disabled in any sane way+ H.tableInteractive().should("exist");++ H.datasetEditBar().findByText("Columns").click();+ cy.findAllByTestId("model-column-header-content")+ .contains("Vendor")+ .click();++ cy.findByPlaceholderText("Select a semantic type").click();+ H.popover().findByText("Entity Key").click();+ H.datasetEditBar().button("Save").click();++ H.modal().button("Save").click();++ cy.findByRole("gridcell", { name: "Nolan-Wolff" }).click({+ waitForAnimations: false,+ });++ // Assert that we're at an adhoc question with aproprate filters+ cy.location("pathname").should("equal", "/question");+ cy.findByTestId("filter-pill").should(+ "contain.text",+ "Vendor is Nolan-Wolff",+ );+ H.tableInteractive().should("have.attr", "data-rows-count", "1");+ });+});++describe("issue 67680", () => {+ function setTablePermissions(createQueriesPermission: NativePermissions) {+ const permissions: GroupPermissions = {+ [SAMPLE_DB_ID]: {+ "view-data": {+ public: {+ [ORDERS_ID]: DataPermissionValue.BLOCKED,+ [PRODUCTS_ID]: DataPermissionValue.UNRESTRICTED,+ },+ },+ "create-queries": createQueriesPermission,+ },+ };+ cy.updatePermissionsGraph({+ [USER_GROUPS.ALL_USERS_GROUP]: permissions,+ [USER_GROUPS.DATA_GROUP]: permissions,+ [USER_GROUPS.COLLECTION_GROUP]: permissions,+ });+ }++ function setTablePermissionsWithCreateQueries() {+ setTablePermissions(DataPermissionValue.QUERY_BUILDER);+ }++ function setTablePermissionsWithoutCreateQueries() {+ setTablePermissions(DataPermissionValue.NO);+ }++ function updateModelSourceTableWithResultMetadata() {+ H.visitModel(ORDERS_MODEL_ID);+ H.openQuestionActions("Edit query definition");+ H.getNotebookStep("data").findByText("Orders").click();+ H.popover().findByText("Products").click();+ H.runButtonInOverlay().click();+ H.tableInteractiveHeader().findByText("Category").should("be.visible");+ H.saveMetadataChanges();+ }++ function updateModelSourceTableWithoutResultMetadata() {+ H.visitModel(ORDERS_MODEL_ID);+ H.openQuestionActions("Edit query definition");+ H.getNotebookStep("data").findByText("Orders").click();+ H.popover().findByText("Products").click();+ H.saveMetadataChanges();+ }++ function verifyNormalUserCanAccessModel() {+ cy.signInAsNormalUser();+ H.visitModel(ORDERS_MODEL_ID);+ H.assertQueryBuilderRowCount(200);+ }++ beforeEach(() => {+ H.restore();+ cy.signInAsAdmin();+ H.activateToken("pro-self-hosted");+ });++ describe("when the user has create queries permission", () => {+ beforeEach(() => {+ setTablePermissionsWithCreateQueries();+ });++ it("should not override column ids for a mbql model when it is saved with result_metadata (metabase#67680)", () => {+ updateModelSourceTableWithResultMetadata();+ verifyNormalUserCanAccessModel();+ });++ it("should not override column ids for a mbql model when it is saved without result_metadata (metabase#67680)", () => {+ updateModelSourceTableWithoutResultMetadata();+ verifyNormalUserCanAccessModel();+ });+ });++ describe("when the user does not have create queries permission", () => {+ beforeEach(() => {+ setTablePermissionsWithoutCreateQueries();+ });++ it("should not override column ids for a mbql model when it is saved with result_metadata (metabase#67680)", () => {+ updateModelSourceTableWithResultMetadata();+ verifyNormalUserCanAccessModel();+ });++ it("should not override column ids for a mbql model when it is saved without result_metadata (metabase#67680)", () => {+ updateModelSourceTableWithoutResultMetadata();+ verifyNormalUserCanAccessModel();+ });+ });+});++describe("issue 69722", () => {+ beforeEach(() => {+ H.restore();+ cy.signInAsNormalUser();+ cy.visit("/model/new");+ cy.findByRole("link", { name: /native query/ }).click();+ });++ it("should not be possible to overflow the native query editor (metabase#69722)", () => {+ H.NativeEditor.type("{enter}".repeat(20));++ cy.findByTestId("native-query-editor-container")+ .findByTestId("run-button")+ .should("be.visible");+ });+});diff --git a/e2e/test/scenarios/models/reproductions-3.cy.spec.ts b/e2e/test/scenarios/models/reproductions-3.cy.spec.tsnew file mode 100644index 00000000000..dfd9f5a4e2b--- /dev/null+++ b/e2e/test/scenarios/models/reproductions-3.cy.spec.ts@@ -0,0 +1,988 @@+const { H } = cy;+import { SAMPLE_DB_ID } from "e2e/support/cypress_data";+import { SAMPLE_DATABASE } from "e2e/support/cypress_sample_database";+import { ORDERS_QUESTION_ID } from "e2e/support/cypress_sample_instance_data";+import type { StructuredQuestionDetails } from "e2e/support/helpers";+import type { NativeQuestionDetails } from "e2e/support/helpers/api/createQuestion";++import {+ openDetailsSidebar,+ turnIntoModel,+} from "./helpers/e2e-models-helpers";++const { ORDERS_ID, ORDERS, PRODUCTS_ID } = SAMPLE_DATABASE;++describe("issue 19180", () => {+ const QUESTION = {+ native: { query: "select * from products" },+ };++ beforeEach(() => {+ H.restore();+ cy.signInAsAdmin();+ cy.intercept("/api/card/*/query").as("cardQuery");+ });++ it("shouldn't drop native model query results after leaving the query editor", () => {+ H.createNativeQuestion(QUESTION).then(({ body: { id: QUESTION_ID } }) => {+ cy.request("PUT", `/api/card/${QUESTION_ID}`, { type: "model" }).then(+ () => {+ cy.visit(`/model/${QUESTION_ID}/query`);+ cy.wait("@cardQuery");+ cy.button("Cancel").click();+ H.tableInteractive();+ cy.findByText("Here's where your results will appear").should(+ "not.exist",+ );+ },+ );+ });+ });+});++describe("issue 20042", () => {+ beforeEach(() => {+ cy.intercept("POST", `/api/card/${ORDERS_QUESTION_ID}/query`).as("query");++ H.restore();+ cy.signInAsAdmin();++ cy.request("PUT", `/api/card/${ORDERS_QUESTION_ID}`, {+ name: "Orders Model",+ type: "model",+ });++ cy.signIn("nodata");+ });++ it("nodata user should not see the blank screen when visiting model (metabase#20042)", () => {+ cy.visit(`/model/${ORDERS_QUESTION_ID}`);++ cy.wait("@query");++ // eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage+ cy.findByText("Orders Model");+ // eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage+ cy.contains("37.65");+ });+});++describe("issue 20045", () => {+ beforeEach(() => {+ cy.intercept("POST", "/api/dataset").as("dataset");++ H.restore();+ cy.signInAsAdmin();++ cy.request("PUT", `/api/card/${ORDERS_QUESTION_ID}`, {+ name: "Orders Model",+ type: "model",+ });+ });++ it("should not add query hash on the rerun (metabase#20045)", () => {+ cy.visit(`/model/${ORDERS_QUESTION_ID}`);++ cy.wait("@dataset");++ cy.location("pathname").should(+ "eq",+ `/model/${ORDERS_QUESTION_ID}-orders-model`,+ );+ cy.location("hash").should("eq", "");++ cy.findByTestId("qb-header-action-panel").find(".Icon-refresh").click();++ cy.wait("@dataset");++ cy.location("pathname").should(+ "eq",+ `/model/${ORDERS_QUESTION_ID}-orders-model`,+ );+ cy.location("hash").should("eq", "");+ });+});++describe("issue 20624", { tags: "@skip" }, () => {+ const renamedColumn = "TITLE renamed";++ const questionDetails: NativeQuestionDetails = {+ name: "20624",+ type: "model",+ native: { query: "select * from PRODUCTS limit 2" },+ visualization_settings: {+ column_settings: { '["name","TITLE"]': { column_title: renamedColumn } },+ },+ };++ beforeEach(() => {+ cy.intercept("PUT", "/api/card/*").as("updateCard");++ H.restore();+ cy.signInAsAdmin();++ H.createNativeQuestion(questionDetails, { visitQuestion: true });+ });++ it("models metadata should override previously defined column settings (metabase#20624)", () => {+ openDetailsSidebar();+ // eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage+ cy.findByText("Customize metadata").click();++ // Open settings for this column+ // eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage+ cy.findByText(renamedColumn).click();+ // Let's set a new name for it+ cy.findByDisplayValue(renamedColumn).clear().type("Foo").blur();++ cy.button("Save changes").click();+ cy.wait("@updateCard");++ cy.get("[data-testid=cell-data]").should("contain", "Foo");+ });+});++describe("issue 20963", () => {+ const snippetName = "string 'test'";+ const questionName = "Converting questions with snippets to models";++ beforeEach(() => {+ H.restore();+ cy.signInAsAdmin();+ });++ it("should allow converting questions with static snippets to models (metabase#20963)", () => {+ cy.visit("/");++ H.startNewNativeQuestion();++ // Create a snippet+ cy.icon("snippet").click();+ cy.findByTestId("sidebar-content").findByText("Create snippet").click();++ H.modal().within(() => {+ cy.findByLabelText("Enter some SQL here so you can reuse it later").type(+ "'test'",+ );+ cy.findByLabelText("Give your snippet a name").type(snippetName);+ cy.findByText("Save").click();+ });++ H.NativeEditor.type("{moveToStart}select ");++ H.saveQuestion(+ questionName,+ { wrapId: true },+ {+ path: ["Our analytics"],+ },+ );++ // Convert into to a model+ H.openQuestionActions();+ H.popover().within(() => {+ cy.icon("model").click();+ });++ H.modal().within(() => {+ cy.findByText("Turn this into a model").click();+ });+ });+});++describe("issue 22517", () => {+ function renameColumn(column: string, newName: string) {+ cy.findByDisplayValue(column).clear().type(newName).blur();+ }++ beforeEach(() => {+ cy.intercept("POST", "/api/card/*/query").as("cardQuery");+ cy.intercept("PUT", "/api/card/*").as("updateMetadata");++ H.restore();+ cy.signInAsAdmin();++ H.createNativeQuestion(+ {+ name: "22517",+ native: { query: "select * from orders" },+ type: "model",+ },+ { visitQuestion: true },+ );++ H.openQuestionActions();+ // eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage+ cy.findByText("Edit metadata").click();++ renameColumn("ID", "Foo");++ cy.button("Save changes").click();+ cy.wait("@updateMetadata");+ });++ it(+ "adding or removing a column should not drop previously edited metadata (metabase#22517)",+ { tags: "@skip" },+ () => {+ H.openQuestionActions();+ // eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage+ cy.findByText("Edit query definition").click();++ // Make sure previous metadata changes are reflected in the UI+ // eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage+ cy.findByText("Foo");++ // This will edit the original query and add the `SIZE` column+ // Updated query: `select *, case when quantity > 4 then 'large' else 'small' end size from orders`+ H.NativeEditor.focus().type(+ "{leftarrow}".repeat(" from orders".length) ++ ", case when quantity > 4 then 'large' else 'small' end size ",+ );++ cy.findByTestId("native-query-editor-container").icon("play").click();+ cy.wait("@dataset");++ // eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage+ cy.findByText("Foo");++ // eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage+ cy.findByText("Save changes").click();++ // eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage+ cy.findByText("Foo");+ },+ );+});++describe("issue 22518", () => {+ beforeEach(() => {+ H.restore();+ cy.signInAsAdmin();+ cy.intercept("POST", "/api/dataset").as("dataset");+ H.createNativeQuestion(+ {+ native: {+ query: "select 1 id, 'a' foo",+ },+ type: "model",+ },+ { visitQuestion: true },+ );+ });++ it("UI should immediately reflect model query changes upon saving (metabase#22518)", () => {+ H.openQuestionActions();+ // eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage+ cy.findByText("Edit query definition").click();++ H.NativeEditor.focus().type(", 'b' bar");+ cy.findByTestId("native-query-editor-container").icon("play").click();+ cy.wait("@dataset");++ cy.findByTestId("dataset-edit-bar").button("Save changes").click();++ cy.findAllByTestId("header-cell")+ .should("have.length", 3)+ .and("contain", "BAR");++ H.summarize();++ H.sidebar()+ .should("contain", "ID")+ .and("contain", "FOO")+ .and("contain", "BAR");+ });+});++describe("filtering based on the remapped column name should result in a correct query (metabase#22715)", () => {+ beforeEach(() => {+ cy.intercept("POST", "/api/dataset").as("dataset");+ cy.intercept("PUT", "/api/card/*").as("updateModel");++ H.restore();+ cy.signInAsAdmin();++ H.createNativeQuestion({+ native: {+ query:+ 'select 1 as "ID", current_timestamp::datetime as "ALIAS_CREATED_AT"',+ },+ }).then(({ body: { id } }) => {+ // Turn the question into a model+ cy.request("PUT", `/api/card/${id}`, { type: "model" });++ // Let's go straight to the model metadata editor+ cy.visit(`/model/${id}/columns`);+ cy.findByText("Database column this maps to").should("be.visible");++ // The first column `ID` is automatically selected+ H.mapColumnTo({ table: "Orders", column: "ID" });+ cy.findByText("ALIAS_CREATED_AT").click();++ H.mapColumnTo({ table: "Orders", column: "Created At" });++ // Make sure the column name updated before saving+ cy.findByDisplayValue("Created At");++ cy.button("Save changes").click();+ cy.wait("@updateModel");++ H.visitModel(id);+ });+ });++ it("when done through the column header action (metabase#22715-1)", () => {+ H.tableHeaderClick("Created At");+ H.popover().within(() => {+ cy.findByText("Filter by this column").click();+ cy.findByText("Today").click();+ });+ cy.wait("@dataset");+ // eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage+ cy.findByText("Today").should("not.exist");+ cy.get("[data-testid=cell-data]")+ .should("have.length", 4)+ .and("contain", "Created At");+ });++ it("when done through the filter trigger (metabase#22715-2)", () => {+ H.filter();+ H.popover().within(() => {+ cy.findByText("Created At").click();+ cy.findByText("Today").click();+ });+ cy.wait("@dataset");+ cy.get("[data-testid=cell-data]")+ .should("have.length", 4)+ .and("contain", "Created At");+ });+});++describe("issue 26091", () => {+ const modelDetails: StructuredQuestionDetails = {+ name: "Old model",+ query: { "source-table": PRODUCTS_ID },+ type: "model",+ };++ const startNewQuestion = () => {+ cy.findByText("New").click();+ H.popover().within(() => cy.findByText("Question").click());+ };++ beforeEach(() => {+ H.restore();+ cy.signInAsAdmin();+ cy.intercept("POST", "/api/card").as("saveQuestion");+ });++ it("should allow to choose a newly created model in the data picker (metabase#26091)", () => {+ H.createQuestion(modelDetails);+ cy.visit("/");++ startNewQuestion();+ H.miniPicker().within(() => {+ cy.findByText("Sample Database").click();+ cy.findByText("Orders").click();+ });+ H.saveQuestion("New model", undefined, {+ path: ["Our analytics"],+ });+ turnIntoModel();++ startNewQuestion();+ H.miniPicker().within(() => {+ cy.findByText("Our analytics").click();+ cy.findByText("New model").should("be.visible");+ cy.findByText("Old model").should("be.visible");+ cy.findByText("Orders Model").should("be.visible");+ });+ });+});++describe("issue 28193", () => {+ const ccName = "CTax";++ function assertOnColumns() {+ cy.findAllByText("2.07").should("be.visible").and("have.length", 2);+ // eslint-disable-next-line metabase/no-unsafe-element-filtering+ cy.findAllByTestId("header-cell")+ .should("be.visible")+ .last()+ .should("have.text", ccName);+ }++ beforeEach(() => {+ cy.intercept("POST", "/api/dataset").as("dataset");++ H.restore();+ cy.signInAsAdmin();++ // Turn the question into a model+ cy.request("PUT", `/api/card/${ORDERS_QUESTION_ID}`, { type: "model" });+ });++ it("should be able to use custom column in a model query (metabase#28193)", () => {+ // Go directly to model's query definition+ cy.visit(`/model/${ORDERS_QUESTION_ID}/query`);++ // eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage+ cy.findByText("Custom column").click();+ H.enterCustomColumnDetails({+ formula: "[Tax]",+ name: ccName,+ });+ cy.button("Done").click();++ cy.findByTestId("run-button").click();+ cy.wait("@dataset");++ cy.button("Save changes").click();+ cy.location("pathname").should("not.include", "/query");++ assertOnColumns();++ cy.reload();+ cy.wait("@dataset");++ assertOnColumns();+ });+});++describe("issue 28971", () => {+ beforeEach(() => {+ H.restore();+ cy.signInAsNormalUser();+ cy.intercept("POST", "/api/card").as("createModel");+ cy.intercept("POST", "/api/dataset").as("dataset");+ });++ it("should be able to filter a newly created model (metabase#28971)", () => {+ H.startNewModel();+ H.miniPicker().within(() => {+ cy.findByText("Sample Database").click();+ cy.findByText("Orders").click();+ });+ cy.findByTestId("run-button").click();+ cy.wait("@dataset");++ cy.findByTestId("dataset-edit-bar").button("Save").click();+ cy.findByTestId("save-question-modal").button("Save").click();+ cy.wait("@createModel");++ H.filter();+ H.popover().within(() => {+ cy.findByText("Quantity").click();+ cy.findByText("20").click();+ cy.button("Apply filter").click();+ });+ cy.wait("@dataset");++ cy.findByTestId("filter-pill").should(+ "have.text",+ "Quantity is equal to 20",+ );+ cy.findByTestId("question-row-count").should("have.text", "Showing 4 rows");+ });+});++describe("issue 53604 - nested native question with multiple breakouts on same column", () => {+ const questionDetails: NativeQuestionDetails = {+ name: "53604 base",+ type: "question",+ native: {+ query: "select ID, CREATED_AT from ORDERS",+ "template-tags": {},+ },+ };++ function createNestedQuestion({+ turnIntoModel: shouldTurnIntoModel = false,+ } = {}) {+ H.createNativeQuestion(questionDetails).then(({ body: { id } }) => {+ if (shouldTurnIntoModel) {+ H.visitQuestion(id);+ turnIntoModel();+ }+ H.createQuestion(+ {+ type: "question",+ name: "53604",+ query: {+ "source-table": `card__${id}`,+ aggregation: [["count"]],+ breakout: [+ [+ "field",+ "CREATED_AT",+ { "temporal-unit": "month", "base-type": "type/DateTime" },+ ],+ [+ "field",+ "CREATED_AT",+ { "temporal-unit": "year", "base-type": "type/DateTime" },+ ],+ ],+ },+ display: "line",+ },+ {+ wrapId: true,+ idAlias: "nestedQuestionId",+ },+ );+ });+ }++ function testUnderlyingRecordsDrillThru() {+ cy.intercept("POST", "/api/dataset").as("dataset");+ H.visitQuestion("@nestedQuestionId");++ // We can click on any circle; this index was chosen randomly+ H.cartesianChartCircle().eq(25).click({ force: true });+ H.popover()+ .findByText(/^See these/)+ .click();+ cy.wait("@dataset");++ cy.findByTestId("qb-filters-panel").findByText(+ "CREATED_AT is May 1–31, 2024",+ );++ cy.findByTestId("qb-filters-panel").findByText(+ "CREATED_AT: Year is Jan 1 – Dec 31, 2024",+ );++ H.assertQueryBuilderRowCount(520);+ }++ beforeEach(() => {+ H.restore();+ cy.signInAsAdmin();+ });++ it("Underlying records drill-through should work on nested native question (metabase#53604)", () => {+ createNestedQuestion();+ testUnderlyingRecordsDrillThru();+ });++ it("Underlying records drill-through should work on nested native model (metabase#53604)", () => {+ createNestedQuestion({ turnIntoModel: true });+ testUnderlyingRecordsDrillThru();+ });+});++describe("issue 54108 - nested question broken out by day", () => {+ const questionDetails: NativeQuestionDetails = {+ name: "54108 base",+ type: "question",+ native: {+ query: "select ID, CREATED_AT from ORDERS",+ "template-tags": {},+ },+ };++ beforeEach(() => {+ H.restore();+ cy.signInAsAdmin();++ H.createNativeQuestion(questionDetails).then(({ body: { id } }) => {+ H.createQuestion(+ {+ type: "question",+ name: "54108",+ query: {+ "source-table": `card__${id}`,+ aggregation: [["count"]],+ breakout: [+ [+ "field",+ "CREATED_AT",+ { "temporal-unit": "day", "base-type": "type/Date" },+ ],+ ],+ },+ display: "line",+ },+ {+ wrapId: true,+ idAlias: "nestedQuestionId",+ },+ );+ });+ });++ it("drill-through should work (metabase#54108)", () => {+ cy.intercept("POST", "/api/dataset").as("dataset");+ H.visitQuestion("@nestedQuestionId");++ // We can click on any circle; this index was chosen randomly+ H.cartesianChartCircle().eq(500).click({ force: true });+ H.popover()+ .findByText(/^See these/)+ .click();+ cy.wait("@dataset");++ cy.findByTestId("qb-filters-panel").findByText(+ "CREATED_AT is Oct 11, 2023",+ );++ H.assertQueryBuilderRowCount(6);+ });+});++describe("issue 29951", { requestTimeout: 10000, viewportWidth: 1600 }, () => {+ const questionDetails: StructuredQuestionDetails = {+ name: "29951",+ query: {+ "source-table": ORDERS_ID,+ expressions: {+ CC1: ["+", ["field", ORDERS.TOTAL], 1],+ CC2: ["+", ["field", ORDERS.TOTAL], 1],+ },+ limit: 2,+ },+ type: "model",+ };+ const removeExpression = (name: string) => {+ H.getNotebookStep("expression")+ .findByText(name)+ .findByLabelText("close icon")+ .click();+ };++ beforeEach(() => {+ H.restore();+ cy.signInAsAdmin();+ cy.intercept("PUT", "/api/card/*").as("updateCard");+ });++ it("should allow to run the model query after changing custom columns (metabase#29951)", () => {+ H.createQuestion(questionDetails).then(({ body: { id } }) => {+ cy.visit(`/model/${id}/query`);+ });++ removeExpression("CC2");+ // The UI shows us the "play" icon, indicating we should refresh the query,+ // but the point of this repro is to save without refreshing+ cy.button("Get Answer").should("be.visible");+ H.saveMetadataChanges();++ // eslint-disable-next-line metabase/no-unsafe-element-filtering+ cy.findAllByTestId("header-cell").last().should("have.text", "CC1");+ H.tableHeaderColumn("ID").as("idHeader");+ H.moveDnDKitElementByAlias("@idHeader", { horizontal: 100 });++ cy.findByTestId("qb-header").button("Refresh").click();+ cy.wait("@dataset");+ cy.get("[data-testid=cell-data]").should("contain", "37.65");+ cy.findByTestId("view-footer").should("contain", "Showing 2 rows");+ });+});++// Should be removed once proper model FK support is implemented+describe("issue 31663", () => {+ beforeEach(() => {+ H.restore();+ cy.signInAsAdmin();++ cy.intercept("POST", "/api/dataset").as("dataset");+ cy.intercept("GET", `/api/database/${SAMPLE_DB_ID}/idfields`).as(+ "idFields",+ );++ H.createQuestion(+ {+ name: "Products Model",+ type: "model",+ query: { "source-table": PRODUCTS_ID },+ },+ { visitQuestion: true },+ );+ });++ it("shouldn't list model IDs as possible model FK targets (metabase#31663)", () => {+ // It's important to have product model's metadata loaded to reproduce this+ H.appBar().findByText("Our analytics").click();++ H.main().findByText("Orders Model").click();+ cy.wait("@dataset");+ cy.findByLabelText("Move, trash, and more…").click();+ H.popover().findByText("Edit metadata").click();++ H.tableInteractive().findByText("Product ID").click();+ cy.wait("@idFields");+ cy.findByPlaceholderText("Select a target").click();+ H.popover().findByText("Orders Model → ID").should("not.exist");+ H.popover().findByText("Products Model → ID").should("not.exist");++ H.popover().findByText("Orders → ID").should("be.visible");+ H.popover().findByText("People → ID").should("be.visible");+ H.popover().findByText("Products → ID").should("be.visible");+ H.popover()+ .scrollTo("bottom")+ .findByText("Reviews → ID")+ .should("be.visible");+ });+});++describe("issue 31905", () => {+ beforeEach(() => {+ H.restore();+ cy.signInAsAdmin();++ cy.intercept("GET", "/api/card/*").as("card");++ H.createQuestion(+ {+ name: "Orders Model",+ type: "model",+ query: { "source-table": ORDERS_ID, limit: 2 },+ },+ { visitQuestion: true },+ );+ });++ // TODO: This should be 1, but MainNavbar.tsx RTKQ fetch + QB's call to loadCard makes it 2+ it("should not send more than one same api requests to load a model (metabase#31905)", () => {+ cy.get("@card.all").should("have.length.lte", 2);+ });+});++describe("issue 32963", () => {+ function assertLineChart() {+ H.openVizTypeSidebar();+ H.leftSidebar().within(() => {+ cy.findByTestId("Line-container").should(+ "have.attr",+ "aria-selected",+ "true",+ );+ cy.findByTestId("Table-container").should(+ "have.attr",+ "aria-selected",+ "false",+ );+ });+ }++ beforeEach(() => {+ H.restore();+ cy.signInAsAdmin();+ H.createQuestion(+ {+ name: "Orders Model",+ type: "model",+ query: { "source-table": ORDERS_ID },+ },+ { visitQuestion: true },+ );+ });++ it("should pick sensible display for model based questions (metabase#32963)", () => {+ cy.findByTestId("qb-header")+ .button(/Summarize/)+ .click();+ cy.intercept("POST", "/api/dataset").as("dataset");++ H.rightSidebar().within(() => {+ cy.findAllByText("Created At").eq(0).click();+ cy.button("Done").click();+ });+ cy.wait("@dataset");+ assertLineChart();++ // Go back to the original model+ cy.findByTestId("qb-header").findByText("Orders Model").click();+ H.openNotebook();++ cy.button("Summarize").click();+ H.popover().findByText("Count of rows").click();+ H.getNotebookStep("summarize")+ .findByText("Pick a column to group by")+ .click();+ H.popover().findByText("Created At").click();+ H.visualize();+ assertLineChart();+ });+});++describe("issues 35039 and 37009", () => {+ // We only need to ensure there is a comment. Any comment.+ const query = "select * from products limit 1 -- foo";++ const cardDetails: NativeQuestionDetails = {+ name: "35039",+ type: "model",+ native: { query },+ visualization_settings: {},+ };++ beforeEach(() => {+ H.restore();+ cy.intercept("POST", "/api/dataset").as("dataset");+ cy.signInAsNormalUser();++ H.createNativeQuestion(cardDetails).then(({ body: { id } }) => {+ // It is crucial for this repro to go directly to the "edit query definition" page!+ // When the repro was created back in v47-v48, it was still possible to save a new model+ // without running the query first. This resulted in the missing `result_metadata`.+ // It's not possible to replicate that using UI anymore, so our best bet is to create a model+ // using API, and then to visit this page directly.+ cy.visit(`/model/${id}/query`);+ });+ assertResultsLoaded();+ });++ // This test follows #37009 repro steps because they are simpler than #35039 but still equivalent+ it("should show columns available in the model (metabase#35039) (metabase#37009)", () => {+ // The repro requires that we update the query in a minor, non-impactful way.+ cy.log("Update the query and save");+ H.NativeEditor.focus().type("{backspace}");+ cy.findByTestId("native-query-editor-container").icon("play").click();+ cy.wait("@dataset");++ cy.findByTestId("dataset-edit-bar").within(() => {+ cy.button("Save changes").click();+ cy.button("Saving…").should("not.exist");+ });++ assertResultsLoaded();++ cy.log("Start new ad-hoc question and make sure all columns are there");+ H.openNotebook();+ cy.findByTestId("fields-picker").click();+ H.popover().within(() => {+ cy.findByText("ID").should("exist");+ cy.findByText("EAN").should("exist");+ cy.findByText("TITLE").should("exist");+ cy.findByText("CATEGORY").should("exist");+ cy.findByText("VENDOR").should("exist");+ cy.findByText("PRICE").should("exist");+ cy.findByText("RATING").should("exist");+ cy.findByText("CREATED_AT").should("exist");+ });+ });++ function assertResultsLoaded() {+ cy.findAllByTestId("cell-data").should("contain", "Rustic Paper Wallet");+ }+});++describe("issue 37009", () => {+ beforeEach(() => {+ H.restore();+ cy.intercept("POST", "/api/dataset").as("dataset");+ cy.intercept("POST", "/api/card").as("saveCard");+ cy.intercept("PUT", "/api/card/*").as("updateCard");+ cy.signInAsNormalUser();+ });++ it("should prevent saving new and updating existing models without result_metadata (metabase#37009)", () => {+ H.startNewNativeModel({ query: "select * from products" });++ cy.findByTestId("dataset-edit-bar")+ .button("Save")+ .should("be.disabled")+ .trigger("mousemove", { force: true });+ cy.findByRole("tooltip").should(+ "have.text",+ "You must run the query before you can save this model",+ );+ cy.findByTestId("native-query-editor-container").icon("play").click();+ cy.wait("@dataset");+ cy.findByRole("tooltip").should("not.exist");+ cy.findByTestId("dataset-edit-bar")+ .button("Save")+ .should("be.enabled")+ .click();+ // eslint-disable-next-line metabase/no-unsafe-element-filtering+ H.modal()+ .last()+ .within(() => {+ cy.findByLabelText("Name").type("Model");+ cy.button("Save").click();+ });+ cy.wait("@saveCard")+ .its("request.body")+ .its("result_metadata")+ .should("not.be.null");++ H.openQuestionActions();+ H.popover().findByText("Edit query definition").click();+ H.NativeEditor.focus().type(" WHERE CATEGORY = 'Gadget'");+ cy.findByTestId("dataset-edit-bar")+ .button("Save changes")+ .should("be.disabled")+ .trigger("mousemove", { force: true });+ cy.findByRole("tooltip").should(+ "have.text",+ "You must run the query before you can save this model",+ );+ cy.findByTestId("native-query-editor-container").icon("play").click();+ cy.wait("@dataset");+ cy.findByRole("tooltip").should("not.exist");+ cy.findByTestId("dataset-edit-bar")+ .button("Save changes")+ .should("be.enabled")+ .click();+ cy.wait("@updateCard")+ .its("request.body")+ .its("result_metadata")+ .should("not.be.null");+ });+});++describe("issue 45926", () => {+ const questionDetails: StructuredQuestionDetails = {+ name: "33330",+ type: "model",+ query: {+ "source-table": ORDERS_ID,+ },+ };++ beforeEach(() => {+ H.restore();+ cy.signInAsNormalUser();++ cy.intercept("POST", "/api/dataset").as("dataset");+ });++ it("should restore model correctly without refresh (metabase#45926)", () => {+ H.createQuestion(questionDetails, { visitQuestion: true });+ cy.wait("@dataset");+ H.openQuestionActions("Edit metadata");+ H.sidebar().within(() => {+ cy.findByDisplayValue("ID").type(" updated");+ });++ cy.button("Save changes").click();+ cy.wait("@dataset");++ cy.findByRole("columnheader", { name: "ID updated" }).should("be.visible");+ H.openQuestionActions("Edit query definition");+ cy.button("Sort").click();+ H.popover().findByText("ID").click();+ cy.button("Save changes").click();+ cy.wait("@dataset");++ H.questionInfoButton().click();+ H.sidesheet().within(() => {+ cy.findByRole("tab", { name: "History" }).click();+ cy.findByText(+ "changed the visualization settings and edited the metadata.",+ )+ .closest("li")+ .findByTestId("question-revert-button")+ .click();+ });++ cy.wait("@dataset");++ H.sidesheet().button("Close").click();++ cy.findByRole("columnheader", { name: "ID updated" }).should("be.visible");+ });+});diff --git a/e2e/test/scenarios/models/reproductions.cy.spec.js b/e2e/test/scenarios/models/reproductions.cy.spec.jsindex 884e49a8ffb..20627aa73d0 100644--- a/e2e/test/scenarios/models/reproductions.cy.spec.js+++ b/e2e/test/scenarios/models/reproductions.cy.spec.js@@ -12,49 +12,10 @@ import {import { addWidgetStringFilter } from "../native-filters/helpers/e2e-field-filter-helpers";-import {- openDetailsSidebar,- turnIntoModel,-} from "./helpers/e2e-models-helpers";--const {- ORDERS_ID,- ORDERS,- REVIEWS,- REVIEWS_ID,- PRODUCTS,- PRODUCTS_ID,- PEOPLE,- PEOPLE_ID,-} = SAMPLE_DATABASE;--describe("issue 19180", () => {- const QUESTION = {- native: { query: "select * from products" },- };-- beforeEach(() => {- H.restore();- cy.signInAsAdmin();- cy.intercept("/api/card/*/query").as("cardQuery");- });+import { turnIntoModel } from "./helpers/e2e-models-helpers";- it("shouldn't drop native model query results after leaving the query editor", () => {- H.createNativeQuestion(QUESTION).then(({ body: { id: QUESTION_ID } }) => {- cy.request("PUT", `/api/card/${QUESTION_ID}`, { type: "model" }).then(- () => {- cy.visit(`/model/${QUESTION_ID}/query`);- cy.wait("@cardQuery");- cy.button("Cancel").click();- H.tableInteractive();- cy.findByText("Here's where your results will appear").should(- "not.exist",- );- },- );- });- });-});+const { ORDERS_ID, ORDERS, REVIEWS, REVIEWS_ID, PRODUCTS, PEOPLE, PEOPLE_ID } =+ SAMPLE_DATABASE;describe("issue 19737", () => {const modelName = "Orders Model";@@ -155,69 +116,6 @@ describe("issue 19737", () => {});});-describe("issue 20042", () => {- beforeEach(() => {- cy.intercept("POST", `/api/card/${ORDERS_QUESTION_ID}/query`).as("query");-- H.restore();- cy.signInAsAdmin();-- cy.request("PUT", `/api/card/${ORDERS_QUESTION_ID}`, {- name: "Orders Model",- type: "model",- });-- cy.signIn("nodata");- });-- it("nodata user should not see the blank screen when visiting model (metabase#20042)", () => {- cy.visit(`/model/${ORDERS_QUESTION_ID}`);-- cy.wait("@query");-- // eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage- cy.findByText("Orders Model");- // eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage- cy.contains("37.65");- });-});--describe("issue 20045", () => {- beforeEach(() => {- cy.intercept("POST", "/api/dataset").as("dataset");-- H.restore();- cy.signInAsAdmin();-- cy.request("PUT", `/api/card/${ORDERS_QUESTION_ID}`, {- name: "Orders Model",- type: "model",- });- });-- it("should not add query hash on the rerun (metabase#20045)", () => {- cy.visit(`/model/${ORDERS_QUESTION_ID}`);-- cy.wait("@dataset");-- cy.location("pathname").should(- "eq",- `/model/${ORDERS_QUESTION_ID}-orders-model`,- );- cy.location("hash").should("eq", "");-- cy.findByTestId("qb-header-action-panel").find(".Icon-refresh").click();-- cy.wait("@dataset");-- cy.location("pathname").should(- "eq",- `/model/${ORDERS_QUESTION_ID}-orders-model`,- );- cy.location("hash").should("eq", "");- });-});-describe("issue 20517", () => {const modelDetails = {name: "20517",@@ -259,198 +157,6 @@ describe("issue 20517", () => {});});-describe("issue 20624", { tags: "@skip" }, () => {- const renamedColumn = "TITLE renamed";-- const questionDetails = {- name: "20624",- type: "model",- native: { query: "select * from PRODUCTS limit 2" },- visualization_settings: {- column_settings: { '["name","TITLE"]': { column_title: renamedColumn } },- },- };-- beforeEach(() => {- cy.intercept("PUT", "/api/card/*").as("updateCard");-- H.restore();- cy.signInAsAdmin();-- H.createNativeQuestion(questionDetails, { visitQuestion: true });- });-- it("models metadata should override previously defined column settings (metabase#20624)", () => {- openDetailsSidebar();- // eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage- cy.findByText("Customize metadata").click();-- // Open settings for this column- // eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage- cy.findByText(renamedColumn).click();- // Let's set a new name for it- cy.findByDisplayValue(renamedColumn).clear().type("Foo").blur();-- cy.button("Save changes").click();- cy.wait("@updateCard");-- cy.get("[data-testid=cell-data]").should("contain", "Foo");- });-});--describe("issue 20963", () => {- const snippetName = "string 'test'";- const questionName = "Converting questions with snippets to models";-- beforeEach(() => {- H.restore();- cy.signInAsAdmin();- });-- it("should allow converting questions with static snippets to models (metabase#20963)", () => {- cy.visit("/");-- H.startNewNativeQuestion();-- // Create a snippet- cy.icon("snippet").click();- cy.findByTestId("sidebar-content").findByText("Create snippet").click();-- H.modal().within(() => {- cy.findByLabelText("Enter some SQL here so you can reuse it later").type(- "'test'",- );- cy.findByLabelText("Give your snippet a name").type(snippetName);- cy.findByText("Save").click();- });-- H.NativeEditor.type("{moveToStart}select ");-- H.saveQuestion(- questionName,- { wrapId: true },- {- path: ["Our analytics"],- },- );-- // Convert into to a model- H.openQuestionActions();- H.popover().within(() => {- cy.icon("model").click();- });-- H.modal().within(() => {- cy.findByText("Turn this into a model").click();- });- });-});--describe("issue 22517", () => {- function renameColumn(column, newName) {- cy.findByDisplayValue(column).clear().type(newName).blur();- }-- beforeEach(() => {- cy.intercept("POST", "/api/card/*/query").as("cardQuery");- cy.intercept("PUT", "/api/card/*").as("updateMetadata");-- H.restore();- cy.signInAsAdmin();-- H.createNativeQuestion(- {- name: "22517",- native: { query: "select * from orders" },- type: "model",- },- { visitQuestion: true },- );-- H.openQuestionActions();- // eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage- cy.findByText("Edit metadata").click();-- renameColumn("ID", "Foo");-- cy.button("Save changes").click();- cy.wait("@updateMetadata");- });-- it(- "adding or removing a column should not drop previously edited metadata (metabase#22517)",- { tags: "@skip" },- () => {- H.openQuestionActions();- // eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage- cy.findByText("Edit query definition").click();-- // Make sure previous metadata changes are reflected in the UI- // eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage- cy.findByText("Foo");-- // This will edit the original query and add the `SIZE` column- // Updated query: `select *, case when quantity > 4 then 'large' else 'small' end size from orders`- H.NativeEditor.focus().type(- "{leftarrow}".repeat(" from orders".length) +- ", case when quantity > 4 then 'large' else 'small' end size ",- );-- cy.findByTestId("native-query-editor-container").icon("play").click();- cy.wait("@dataset");-- // eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage- cy.findByText("Foo");-- // eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage- cy.findByText("Save changes").click();-- // eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage- cy.findByText("Foo");- },- );-});--describe("issue 22518", () => {- beforeEach(() => {- H.restore();- cy.signInAsAdmin();- cy.intercept("POST", "/api/dataset").as("dataset");- H.createNativeQuestion(- {- native: {- query: "select 1 id, 'a' foo",- },- type: "model",- },- { visitQuestion: true },- );- });-- it("UI should immediately reflect model query changes upon saving (metabase#22518)", () => {- H.openQuestionActions();- // eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage- cy.findByText("Edit query definition").click();-- H.NativeEditor.focus().type(", 'b' bar");- cy.findByTestId("native-query-editor-container").icon("play").click();- cy.wait("@dataset");-- cy.findByTestId("dataset-edit-bar").button("Save changes").click();-- cy.findAllByTestId("header-cell")- .should("have.length", 3)- .and("contain", "BAR");-- H.summarize();-- H.sidebar()- .should("contain", "ID")- .and("contain", "FOO")- .and("contain", "BAR");- });-});-describe("issue 22519", { tags: "@skip" }, () => {const questionDetails = {query: {@@ -493,70 +199,6 @@ describe("issue 22519", { tags: "@skip" }, () => {});});-describe("filtering based on the remapped column name should result in a correct query (metabase#22715)", () => {- beforeEach(() => {- cy.intercept("POST", "/api/dataset").as("dataset");- cy.intercept("PUT", "/api/card/*").as("updateModel");-- H.restore();- cy.signInAsAdmin();-- H.createNativeQuestion({- native: {- query:- 'select 1 as "ID", current_timestamp::datetime as "ALIAS_CREATED_AT"',- },- }).then(({ body: { id } }) => {- // Turn the question into a model- cy.request("PUT", `/api/card/${id}`, { type: "model" });-- // Let's go straight to the model metadata editor- cy.visit(`/model/${id}/columns`);- cy.findByText("Database column this maps to").should("be.visible");-- // The first column `ID` is automatically selected- H.mapColumnTo({ table: "Orders", column: "ID" });- cy.findByText("ALIAS_CREATED_AT").click();-- H.mapColumnTo({ table: "Orders", column: "Created At" });-- // Make sure the column name updated before saving- cy.findByDisplayValue("Created At");-- cy.button("Save changes").click();- cy.wait("@updateModel");-- H.visitModel(id);- });- });-- it("when done through the column header action (metabase#22715-1)", () => {- H.tableHeaderClick("Created At");- H.popover().within(() => {- cy.findByText("Filter by this column").click();- cy.findByText("Today").click();- });- cy.wait("@dataset");- // eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage- cy.findByText("Today").should("not.exist");- cy.get("[data-testid=cell-data]")- .should("have.length", 4)- .and("contain", "Created At");- });-- it("when done through the filter trigger (metabase#22715-2)", () => {- H.filter();- H.popover().within(() => {- cy.findByText("Created At").click();- cy.findByText("Today").click();- });- cy.wait("@dataset");- cy.get("[data-testid=cell-data]")- .should("have.length", 4)- .and("contain", "Created At");- });-});-describe("issue 23024", () => {function addModelToDashboardAndVisit() {H.createDashboard().then(({ body: { id } }) => {@@ -768,134 +410,6 @@ describe("issue 25537", () => {});});-describe("issue 26091", () => {- const modelDetails = {- name: "Old model",- query: { "source-table": PRODUCTS_ID },- type: "model",- };-- const startNewQuestion = () => {- cy.findByText("New").click();- H.popover().within(() => cy.findByText("Question").click());- };-- beforeEach(() => {- H.restore();- cy.signInAsAdmin();- cy.intercept("POST", "/api/card").as("saveQuestion");- });-- it("should allow to choose a newly created model in the data picker (metabase#26091)", () => {- H.createQuestion(modelDetails);- cy.visit("/");-- startNewQuestion();- H.miniPicker().within(() => {- cy.findByText("Sample Database").click();- cy.findByText("Orders").click();- });- H.saveQuestion("New model", undefined, {- path: ["Our analytics"],- });- turnIntoModel();-- startNewQuestion();- H.miniPicker().within(() => {- cy.findByText("Our analytics").click();- cy.findByText("New model").should("be.visible");- cy.findByText("Old model").should("be.visible");- cy.findByText("Orders Model").should("be.visible");- });- });-});--describe("issue 28193", () => {- const ccName = "CTax";-- function assertOnColumns() {- cy.findAllByText("2.07").should("be.visible").and("have.length", 2);- // eslint-disable-next-line metabase/no-unsafe-element-filtering- cy.findAllByTestId("header-cell")- .should("be.visible")- .last()- .should("have.text", ccName);- }-- beforeEach(() => {- cy.intercept("POST", "/api/dataset").as("dataset");-- H.restore();- cy.signInAsAdmin();-- // Turn the question into a model- cy.request("PUT", `/api/card/${ORDERS_QUESTION_ID}`, { type: "model" });- });-- it("should be able to use custom column in a model query (metabase#28193)", () => {- // Go directly to model's query definition- cy.visit(`/model/${ORDERS_QUESTION_ID}/query`);-- // eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage- cy.findByText("Custom column").click();- H.enterCustomColumnDetails({- formula: "[Tax]",- name: ccName,- });- cy.button("Done").click();-- cy.findByTestId("run-button").click();- cy.wait("@dataset");-- cy.button("Save changes").click();- cy.location("pathname").should("not.include", "/query");-- assertOnColumns();-- cy.reload();- cy.wait("@dataset");-- assertOnColumns();- });-});--describe("issue 28971", () => {- beforeEach(() => {- H.restore();- cy.signInAsNormalUser();- cy.intercept("POST", "/api/card").as("createModel");- cy.intercept("POST", "/api/dataset").as("dataset");- });-- it("should be able to filter a newly created model (metabase#28971)", () => {- H.startNewModel();- H.miniPicker().within(() => {- cy.findByText("Sample Database").click();- cy.findByText("Orders").click();- });- cy.findByTestId("run-button").click();- cy.wait("@dataset");-- cy.findByTestId("dataset-edit-bar").button("Save").click();- cy.findByTestId("save-question-modal").button("Save").click();- cy.wait("@createModel");-- H.filter();- H.popover().within(() => {- cy.findByText("Quantity").click();- cy.findByText("20").click();- cy.button("Apply filter").click();- });- cy.wait("@dataset");-- cy.findByTestId("filter-pill").should(- "have.text",- "Quantity is equal to 20",- );- cy.findByTestId("question-row-count").should("have.text", "Showing 4 rows");- });-});-describe("issue 29378", () => {const ACTION_DETAILS = {name: "Update orders quantity",@@ -1250,174 +764,37 @@ describe("issue 53556 - nested question based on native model with remapped valu["April 2026", "20 – 40", "27"],["April 2026", "40 – 60", "57"],],- });-- cy.log("Sort by Created At in ascending order");- H.tableHeaderClick("Created At: Month");- H.popover()- .findAllByTestId("click-actions-sort-control-sort.ascending")- .click();- cy.wait("@dataset");- H.assertQueryBuilderRowCount(312);- H.assertTableData({- columns: ["Created At: Month", "Total: 8 bins", "Count"],- firstRows: [- ["April 2022", "40 – 60", "1"],- ["May 2022", "20 – 40", "1"],- ],- });- });-});--describe("issue 52465 - model with linked columns can still be aggregated", () => {- const questionDetails = {- name: "52465",- type: "model",- native: {- query: `-SELECT- "ID" AS "id orders",- "SOURCE" AS "source orders"-FROM- "PEOPLE"-`,- "template-tags": {},- },- };-- beforeEach(() => {- H.restore();- cy.signInAsAdmin();- });-- it("Create model, set metadata, distinct", () => {- H.createNativeQuestion(questionDetails).then(({ body: { id } }) => {- cy.intercept(- "GET",- `/api/database/${SAMPLE_DB_ID}/schema/PUBLIC?can-query=true`,- ).as("schema");- cy.visit(`/model/${id}/columns`);- cy.wait("@schema");-- selectModelColumn("source orders");- mapModelColumnToDatabase({ table: "People", field: "Source" });-- cy.intercept("PUT", "/api/card/*").as("updateModel");- cy.button("Save changes").click();- cy.wait("@updateModel");-- const nestedQuestionDetails = {- query: {- "source-table": `card__${id}`,- },- };-- H.createQuestion(nestedQuestionDetails, {- wrapId: true,- idAlias: "nestedQuestionId",- });-- H.visitQuestion("@nestedQuestionId");- cy.findByText("Source").click();- cy.findByText("Distinct values").click();-- H.assertQueryBuilderRowCount(1);- });- });-});--describe("issue 53604 - nested native question with multiple breakouts on same column", () => {- const questionDetails = {- name: "53604 base",- type: "question",- native: {- query: "select ID, CREATED_AT from ORDERS",- "template-tags": {},- },- };-- function createNestedQuestion({- turnIntoModel: shouldTurnIntoModel = false,- } = {}) {- H.createNativeQuestion(questionDetails).then(({ body: { id } }) => {- if (shouldTurnIntoModel) {- H.visitQuestion(id);- turnIntoModel();- }- H.createQuestion(- {- type: "question",- name: "53604",- query: {- "source-table": `card__${id}`,- aggregation: [["count"]],- breakout: [- [- "field",- "CREATED_AT",- { "temporal-unit": "month", "base-type": "type/DateTime" },- ],- [- "field",- "CREATED_AT",- { "temporal-unit": "year", "base-type": "type/DateTime" },- ],- ],- },- display: "line",- },- {- wrapId: true,- idAlias: "nestedQuestionId",- },- );- });- }-- function testUnderlyingRecordsDrillThru() {- cy.intercept("POST", "/api/dataset").as("dataset");- H.visitQuestion("@nestedQuestionId");+ });- // We can click on any circle; this index was chosen randomly- H.cartesianChartCircle().eq(25).click({ force: true });+ cy.log("Sort by Created At in ascending order");+ H.tableHeaderClick("Created At: Month");H.popover()- .findByText(/^See these/)+ .findAllByTestId("click-actions-sort-control-sort.ascending").click();cy.wait("@dataset");-- cy.findByTestId("qb-filters-panel").findByText(- "CREATED_AT is May 1–31, 2024",- );-- cy.findByTestId("qb-filters-panel").findByText(- "CREATED_AT: Year is Jan 1 – Dec 31, 2024",- );-- H.assertQueryBuilderRowCount(520);- }-- beforeEach(() => {- H.restore();- cy.signInAsAdmin();- });-- it("Underlying records drill-through should work on nested native question (metabase#53604)", () => {- createNestedQuestion();- testUnderlyingRecordsDrillThru();- });-- it("Underlying records drill-through should work on nested native model (metabase#53604)", () => {- createNestedQuestion({ turnIntoModel: true });- testUnderlyingRecordsDrillThru();+ H.assertQueryBuilderRowCount(312);+ H.assertTableData({+ columns: ["Created At: Month", "Total: 8 bins", "Count"],+ firstRows: [+ ["April 2022", "40 – 60", "1"],+ ["May 2022", "20 – 40", "1"],+ ],+ });});});-describe("issue 54108 - nested question broken out by day", () => {+describe("issue 52465 - model with linked columns can still be aggregated", () => {const questionDetails = {- name: "54108 base",- type: "question",+ name: "52465",+ type: "model",native: {- query: "select ID, CREATED_AT from ORDERS",+ query: `+SELECT+ "ID" AS "id orders",+ "SOURCE" AS "source orders"+FROM+ "PEOPLE"+`,"template-tags": {},},};@@ -1425,98 +802,41 @@ describe("issue 54108 - nested question broken out by day", () => {beforeEach(() => {H.restore();cy.signInAsAdmin();-- H.createNativeQuestion(questionDetails).then(({ body: { id } }) => {- H.createQuestion(- {- type: "question",- name: "54108",- query: {- "source-table": `card__${id}`,- aggregation: [["count"]],- breakout: [- [- "field",- "CREATED_AT",- { "temporal-unit": "day", "base-type": "type/Date" },- ],- ],- },- display: "line",- },- {- wrapId: true,- idAlias: "nestedQuestionId",- },- );- });});- it("drill-through should work (metabase#54108)", () => {- cy.intercept("POST", "/api/dataset").as("dataset");- H.visitQuestion("@nestedQuestionId");+ it("Create model, set metadata, distinct", () => {+ H.createNativeQuestion(questionDetails).then(({ body: { id } }) => {+ cy.intercept(+ "GET",+ `/api/database/${SAMPLE_DB_ID}/schema/PUBLIC?can-query=true`,+ ).as("schema");+ cy.visit(`/model/${id}/columns`);+ cy.wait("@schema");- // We can click on any circle; this index was chosen randomly- H.cartesianChartCircle().eq(500).click({ force: true });- H.popover()- .findByText(/^See these/)- .click();- cy.wait("@dataset");+ selectModelColumn("source orders");+ mapModelColumnToDatabase({ table: "People", field: "Source" });- cy.findByTestId("qb-filters-panel").findByText(- "CREATED_AT is Oct 11, 2023",- );+ cy.intercept("PUT", "/api/card/*").as("updateModel");+ cy.button("Save changes").click();+ cy.wait("@updateModel");- H.assertQueryBuilderRowCount(6);- });-});+ const nestedQuestionDetails = {+ query: {+ "source-table": `card__${id}`,+ },+ };-describe("issue 29951", { requestTimeout: 10000, viewportWidth: 1600 }, () => {- const questionDetails = {- name: "29951",- query: {- "source-table": ORDERS_ID,- expressions: {- CC1: ["+", ["field", ORDERS.TOTAL], 1],- CC2: ["+", ["field", ORDERS.TOTAL], 1],- },- limit: 2,- },- type: "model",- };- const removeExpression = (name) => {- H.getNotebookStep("expression")- .findByText(name)- .findByLabelText("close icon")- .click();- };+ H.createQuestion(nestedQuestionDetails, {+ wrapId: true,+ idAlias: "nestedQuestionId",+ });- beforeEach(() => {- H.restore();- cy.signInAsAdmin();- cy.intercept("PUT", "/api/card/*").as("updateCard");- });+ H.visitQuestion("@nestedQuestionId");+ cy.findByText("Source").click();+ cy.findByText("Distinct values").click();- it("should allow to run the model query after changing custom columns (metabase#29951)", () => {- H.createQuestion(questionDetails).then(({ body: { id } }) => {- cy.visit(`/model/${id}/query`);+ H.assertQueryBuilderRowCount(1);});-- removeExpression("CC2");- // The UI shows us the "play" icon, indicating we should refresh the query,- // but the point of this repro is to save without refreshing- cy.button("Get Answer").should("be.visible");- H.saveMetadataChanges();-- // eslint-disable-next-line metabase/no-unsafe-element-filtering- cy.findAllByTestId("header-cell").last().should("have.text", "CC1");- H.tableHeaderColumn("ID").as("idHeader");- H.moveDnDKitElementByAlias("@idHeader", { horizontal: 100 });-- cy.findByTestId("qb-header").button("Refresh").click();- cy.wait("@dataset");- cy.get("[data-testid=cell-data]").should("contain", "37.65");- cy.findByTestId("view-footer").should("contain", "Showing 2 rows");});});@@ -1590,75 +910,6 @@ describe("issue 31309", () => {});});-// Should be removed once proper model FK support is implemented-describe("issue 31663", () => {- beforeEach(() => {- H.restore();- cy.signInAsAdmin();-- cy.intercept("POST", "/api/dataset").as("dataset");- cy.intercept("GET", `/api/database/${SAMPLE_DB_ID}/idfields`).as(- "idFields",- );-- H.createQuestion(- {- name: "Products Model",- type: "model",- query: { "source-table": PRODUCTS_ID },- },- { visitQuestion: true },- );- });-- it("shouldn't list model IDs as possible model FK targets (metabase#31663)", () => {- // It's important to have product model's metadata loaded to reproduce this- H.appBar().findByText("Our analytics").click();-- H.main().findByText("Orders Model").click();- cy.wait("@dataset");- cy.findByLabelText("Move, trash, and more…").click();- H.popover().findByText("Edit metadata").click();-- H.tableInteractive().findByText("Product ID").click();- cy.wait("@idFields");- cy.findByPlaceholderText("Select a target").click();- H.popover().findByText("Orders Model → ID").should("not.exist");- H.popover().findByText("Products Model → ID").should("not.exist");-- H.popover().findByText("Orders → ID").should("be.visible");- H.popover().findByText("People → ID").should("be.visible");- H.popover().findByText("Products → ID").should("be.visible");- H.popover()- .scrollTo("bottom")- .findByText("Reviews → ID")- .should("be.visible");- });-});--describe("issue 31905", () => {- beforeEach(() => {- H.restore();- cy.signInAsAdmin();-- cy.intercept("GET", "/api/card/*").as("card");-- H.createQuestion(- {- name: "Orders Model",- type: "model",- query: { "source-table": ORDERS_ID, limit: 2 },- },- { visitQuestion: true },- );- });-- // TODO: This should be 1, but MainNavbar.tsx RTKQ fetch + QB's call to loadCard makes it 2- it("should not send more than one same api requests to load a model (metabase#31905)", () => {- cy.get("@card.all").should("have.length.lte", 2);- });-});-describe("issue 32483", () => {const createTextFilterMapping = ({ card_id, fieldRef }) => {return {@@ -1803,190 +1054,6 @@ describe("issue 32483", () => {});});-describe("issue 32963", () => {- function assertLineChart() {- H.openVizTypeSidebar();- H.leftSidebar().within(() => {- cy.findByTestId("Line-container").should(- "have.attr",- "aria-selected",- "true",- );- cy.findByTestId("Table-container").should(- "have.attr",- "aria-selected",- "false",- );- });- }-- beforeEach(() => {- H.restore();- cy.signInAsAdmin();- H.createQuestion(- {- name: "Orders Model",- type: "model",- query: { "source-table": ORDERS_ID },- },- { visitQuestion: true },- );- });-- it("should pick sensible display for model based questions (metabase#32963)", () => {- cy.findByTestId("qb-header")- .button(/Summarize/)- .click();- cy.intercept("POST", "/api/dataset").as("dataset");-- H.rightSidebar().within(() => {- cy.findAllByText("Created At").eq(0).click();- cy.button("Done").click();- });- cy.wait("@dataset");- assertLineChart();-- // Go back to the original model- cy.findByTestId("qb-header").findByText("Orders Model").click();- H.openNotebook();-- cy.button("Summarize").click();- H.popover().findByText("Count of rows").click();- H.getNotebookStep("summarize")- .findByText("Pick a column to group by")- .click();- H.popover().findByText("Created At").click();- H.visualize();- assertLineChart();- });-});--describe("issues 35039 and 37009", () => {- // We only need to ensure there is a comment. Any comment.- const query = "select * from products limit 1 -- foo";-- const cardDetails = {- name: "35039",- type: "model",- native: { query },- visualization_settings: {},- };-- beforeEach(() => {- H.restore();- cy.intercept("POST", "/api/dataset").as("dataset");- cy.signInAsNormalUser();-- H.createNativeQuestion(cardDetails).then(({ body: { id } }) => {- // It is crucial for this repro to go directly to the "edit query definition" page!- // When the repro was created back in v47-v48, it was still possible to save a new model- // without running the query first. This resulted in the missing `result_metadata`.- // It's not possible to replicate that using UI anymore, so our best bet is to create a model- // using API, and then to visit this page directly.- cy.visit(`/model/${id}/query`);- });- assertResultsLoaded();- });-- // This test follows #37009 repro steps because they are simpler than #35039 but still equivalent- it("should show columns available in the model (metabase#35039) (metabase#37009)", () => {- // The repro requires that we update the query in a minor, non-impactful way.- cy.log("Update the query and save");- H.NativeEditor.focus().type("{backspace}");- cy.findByTestId("native-query-editor-container").icon("play").click();- cy.wait("@dataset");-- cy.findByTestId("dataset-edit-bar").within(() => {- cy.button("Save changes").click();- cy.button("Saving…").should("not.exist");- });-- assertResultsLoaded();-- cy.log("Start new ad-hoc question and make sure all columns are there");- H.openNotebook();- cy.findByTestId("fields-picker").click();- H.popover().within(() => {- cy.findByText("ID").should("exist");- cy.findByText("EAN").should("exist");- cy.findByText("TITLE").should("exist");- cy.findByText("CATEGORY").should("exist");- cy.findByText("VENDOR").should("exist");- cy.findByText("PRICE").should("exist");- cy.findByText("RATING").should("exist");- cy.findByText("CREATED_AT").should("exist");- });- });-- function assertResultsLoaded() {- cy.findAllByTestId("cell-data").should("contain", "Rustic Paper Wallet");- }-});--describe("issue 37009", () => {- beforeEach(() => {- H.restore();- cy.intercept("POST", "/api/dataset").as("dataset");- cy.intercept("POST", "/api/card").as("saveCard");- cy.intercept("PUT", "/api/card/*").as("updateCard");- cy.signInAsNormalUser();- });-- it("should prevent saving new and updating existing models without result_metadata (metabase#37009)", () => {- H.startNewNativeModel({ query: "select * from products" });-- cy.findByTestId("dataset-edit-bar")- .button("Save")- .should("be.disabled")- .trigger("mousemove", { force: true });- cy.findByRole("tooltip").should(- "have.text",- "You must run the query before you can save this model",- );- cy.findByTestId("native-query-editor-container").icon("play").click();- cy.wait("@dataset");- cy.findByRole("tooltip").should("not.exist");- cy.findByTestId("dataset-edit-bar")- .button("Save")- .should("be.enabled")- .click();- // eslint-disable-next-line metabase/no-unsafe-element-filtering- H.modal()- .last()- .within(() => {- cy.findByLabelText("Name").type("Model");- cy.button("Save").click();- });- cy.wait("@saveCard")- .its("request.body")- .its("result_metadata")- .should("not.be.null");-- H.openQuestionActions();- H.popover().findByText("Edit query definition").click();- H.NativeEditor.focus().type(" WHERE CATEGORY = 'Gadget'");- cy.findByTestId("dataset-edit-bar")- .button("Save changes")- .should("be.disabled")- .trigger("mousemove", { force: true });- cy.findByRole("tooltip").should(- "have.text",- "You must run the query before you can save this model",- );- cy.findByTestId("native-query-editor-container").icon("play").click();- cy.wait("@dataset");- cy.findByRole("tooltip").should("not.exist");- cy.findByTestId("dataset-edit-bar")- .button("Save changes")- .should("be.enabled")- .click();- cy.wait("@updateCard")- .its("request.body")- .its("result_metadata")- .should("not.be.null");- });-});-describe("issue 40252", () => {const modelA = {name: "Model A",@@ -2175,56 +1242,3 @@ describe("cumulative count - issue 33330", () => {cy.findByTestId("question-row-count").should("have.text", "Showing 1 row");});});--describe("issue 45926", () => {- const questionDetails = {- name: "33330",- type: "model",- query: {- "source-table": ORDERS_ID,- },- };-- beforeEach(() => {- H.restore();- cy.signInAsNormalUser();-- cy.intercept("POST", "/api/dataset").as("dataset");- });-- it("should restore model correctly without refresh (metabase#45926)", () => {- H.createQuestion(questionDetails, { visitQuestion: true });- cy.wait("@dataset");- H.openQuestionActions("Edit metadata");- H.sidebar().within(() => {- cy.findByDisplayValue("ID").type(" updated");- });-- cy.button("Save changes").click();- cy.wait("@dataset");-- cy.findByRole("columnheader", { name: "ID updated" }).should("be.visible");- H.openQuestionActions("Edit query definition");- cy.button("Sort").click();- H.popover().findByText("ID").click();- cy.button("Save changes").click();- cy.wait("@dataset");-- H.questionInfoButton().click();- H.sidesheet().within(() => {- cy.findByRole("tab", { name: "History" }).click();- cy.findByText(- "changed the visualization settings and edited the metadata.",- )- .closest("li")- .findByTestId("question-revert-button")- .click();- });-- cy.wait("@dataset");-- H.sidesheet().button("Close").click();-- cy.findByRole("columnheader", { name: "ID updated" }).should("be.visible");- });-});diff --git a/e2e/test/scenarios/question-reproductions/reproductions-3.cy.spec.js b/e2e/test/scenarios/question-reproductions/reproductions-3.cy.spec.jsindex fd3edc32559..d5527e32816 100644--- a/e2e/test/scenarios/question-reproductions/reproductions-3.cy.spec.js+++ b/e2e/test/scenarios/question-reproductions/reproductions-3.cy.spec.js@@ -1,10 +1,5 @@const { H } = cy;-import {- SAMPLE_DB_ID,- SAMPLE_DB_SCHEMA_ID,- USER_GROUPS,- WRITABLE_DB_ID,-} from "e2e/support/cypress_data";+import { SAMPLE_DB_ID, WRITABLE_DB_ID } from "e2e/support/cypress_data";import { SAMPLE_DATABASE } from "e2e/support/cypress_sample_database";import { NO_COLLECTION_PERSONAL_COLLECTION_ID } from "e2e/support/cypress_sample_instance_data";@@ -1439,1775 +1434,3 @@ describe("issue 44637", () => {H.rightSidebar().findByText("Create event");});});--describe("issue 44668", () => {- beforeEach(() => {- H.restore();- cy.signInAsAdmin();- });-- it("should not drop graph.metrics after adding a new query stage (metabase#44668)", () => {- H.createQuestion(- {- display: "bar",- query: {- aggregation: [["count"]],- breakout: [["field", PEOPLE.STATE, { "base-type": "type/Text" }]],- "source-table": PEOPLE_ID,- limit: 5,- },- visualization_settings: {- "graph.metrics": ["count"],- "graph.dimensions": ["STATE"],- },- },- { visitQuestion: true },- );-- H.openNotebook();-- // eslint-disable-next-line metabase/no-unsafe-element-filtering- cy.findAllByTestId("action-buttons").last().button("Custom column").click();- H.enterCustomColumnDetails({- formula: 'concat("abc_", [Count])',- name: "Custom String",- format: true,- });- H.popover().button("Done").click();-- H.getNotebookStep("expression", { stage: 1 }).icon("add").click();- H.enterCustomColumnDetails({- formula: "[Count] * 2",- name: "Custom Number",- });- H.popover().button("Done").click();-- H.visualize();-- H.echartsContainer().within(() => {- cy.findByText("State").should("be.visible"); // x-axis- cy.findByText("Count").should("be.visible"); // y-axis-- // x-axis values- ["AK", "AL", "AR", "AZ", "CA"].forEach((state) => {- cy.findByText(state).should("be.visible");- });- });-- // Ensure custom columns weren't added as series automatically- H.queryBuilderMain().findByLabelText("Legend").should("not.exist");-- H.openVizSettingsSidebar();-- // Ensure can use Custom Number as series- H.leftSidebar().findByText("Add another series").click();- H.queryBuilderMain()- .findByLabelText("Legend")- .within(() => {- cy.findByText("Count").should("exist");- cy.findByText("Custom Number").should("exist");- });- H.leftSidebar().within(() => {- cy.findByText("Add another series").should("not.exist");- cy.findByText("Add series breakout").should("not.exist");- cy.findByTestId("remove-Custom Number").click();- });- H.queryBuilderMain().findByLabelText("Legend").should("not.exist");-- H.leftSidebar().findByText("Add series breakout").click();- H.popover().within(() => {- cy.findByText("Count").should("exist");- cy.findByText("Custom Number").should("exist");- cy.findByText("Custom String").click();- });- H.queryBuilderMain()- .findByLabelText("Legend")- .within(() => {- ["68", "56", "49", "20", "90"].forEach((value) => {- cy.findByText(`abc_${value}`).should("exist");- });- });- H.leftSidebar().within(() => {- cy.findByText("Add another series").should("not.exist");- cy.findByText("Add series breakout").should("not.exist");- });- });-});--describe("issue 44974", { tags: "@external" }, () => {- const PG_DB_ID = 2;-- beforeEach(() => {- cy.intercept("GET", "/api/collection/*/items*").as("getCollectionItems");- H.restore("postgres-12");- cy.signInAsAdmin();- });-- it("entity picker should not offer to join with a table or a question from a different database (metabase#44974)", () => {- H.withDatabase(PG_DB_ID, ({ PEOPLE_ID }) => {- const questionDetails = {- name: "Question 44974 in Postgres DB",- database: PG_DB_ID,- query: {- "source-table": PEOPLE_ID,- limit: 1,- },- };-- H.createQuestion(questionDetails);-- H.openOrdersTable({ mode: "notebook" });- H.join();- H.miniPicker().within(() => {- cy.findByText("Our analytics").click();- cy.findByText("Orders Model").should("be.visible");- cy.findByText(questionDetails.name).should("not.exist");- });- H.miniPickerHeader().click();- H.miniPickerBrowseAll().click();-- cy.wait(["@getCollectionItems", "@getCollectionItems"]);-- H.entityPickerModal().within(() => {- H.entityPickerModalItem(0, "Our analytics").click();- cy.findByText("Orders Model").should("be.visible");- H.entityPickerModalItem(1, questionDetails.name).should(- "have.attr",- "data-disabled",- "true",- );- cy.button("Close").click();- });- });- });-});--describe("issue 38989", () => {- beforeEach(() => {- H.restore();- cy.signInAsAdmin();- });-- it("should be impossible to join with a table or question which is not in the same database (metabase#38989)", () => {- H.createQuestion(- {- query: {- "source-table": PEOPLE_ID,- fields: [- ["field", PEOPLE.ID, { "base-type": "type/Number" }],- ["field", PEOPLE.EMAIL, { "base-type": "type/Text" }],- ],- joins: [- {- fields: "all",- alias: "Orders",- // This is not a valid table ID in the Sample Database- "source-table": 123,- strategy: "left-join",- condition: [- "=",- ["field", PEOPLE.ID, null],- ["field", ORDERS.USER_ID, { "join-alias": "Orders" }],- ],- },- ],- },- },- {- visitQuestion: true,- },- );-- cy.findByTestId("query-builder-main")- .findByText("Show error details")- .click();-- cy.findByTestId("query-builder-main")- .findByText(- /either it does not exist, or it belongs to a different Database/,- )- .should("exist");- });-});--describe("issue 39771", () => {- beforeEach(() => {- H.restore();- cy.signInAsNormalUser();- });-- it("should show tooltip for ellipsified text (metabase#39771)", () => {- H.createQuestion(- {- query: {- aggregation: [["count"]],- breakout: [- [- "field",- "CREATED_AT",- {- "base-type": "type/DateTime",- "temporal-unit": "quarter-of-year",- },- ],- ],- "source-query": {- "source-table": ORDERS_ID,- aggregation: [["count"]],- breakout: [- [- "field",- ORDERS.CREATED_AT,- {- "base-type": "type/DateTime",- "temporal-unit": "month",- },- ],- ],- },- },- },- { visitQuestion: true },- );-- H.openNotebook();- H.getNotebookStep("summarize", { stage: 1 })- .findByTestId("breakout-step")- .findByText("Created At: Quarter of year")- .click();-- H.popover().findByText("by quarter of year").realHover();-- H.popover().then(([$popover]) => {- const popoverStyle = window.getComputedStyle($popover);- const popoverZindex = parseInt(popoverStyle.zIndex, 10);-- cy.findByTestId("ellipsified-tooltip").within(([$tooltip]) => {- cy.findByText("by quarter of year").should("be.visible");-- const tooltipStyle = window.getComputedStyle($tooltip);- const tooltipZindex = parseInt(tooltipStyle.zIndex, 10);-- // resort to asserting zIndex because should("be.visible") passes unexpectedly- expect(tooltipZindex).to.be.gte(popoverZindex);- });- });- });-});--describe("issue 45063", () => {- function createGuiQuestion({ sourceTableId }) {- const questionDetails = {- name: "Question",- query: {- "source-table": sourceTableId,- },- };- H.createQuestion(questionDetails, { wrapId: true });- }-- function createGuiModel({ sourceTableId }) {- const mbqlModelDetails = {- name: "Model",- type: "model",- query: {- "source-table": sourceTableId,- },- };- H.createQuestion(mbqlModelDetails, { wrapId: true, idAlias: "modelId" });- }-- function createNativeModel({- tableName,- fieldId,- fieldName,- fieldSemanticType,- }) {- const nativeModelDetails = {- name: "Native Model",- type: "model",- native: {- query: `SELECT * FROM ${tableName}`,- },- };- H.createNativeQuestion(nativeModelDetails, {- wrapId: true,- idAlias: "modelId",- }).then(({ body: model }) => {- cy.log("populate result_metadata");- cy.request("POST", `/api/card/${model.id}/query`);- cy.log("map columns to database fields");- H.setModelMetadata(model.id, (field) => {- if (field.name === fieldName) {- return { ...field, id: fieldId, semantic_type: fieldSemanticType };- }- return field;- });- });- }-- function setListValues({ fieldId }) {- cy.request("PUT", `/api/field/${fieldId}`, {- has_field_values: "list",- });- }-- function setSearchValues({ fieldId }) {- cy.request("PUT", `/api/field/${fieldId}`, {- has_field_values: "search",- });- }-- function setForeignKeyRemapping({- sourceFieldId,- targetFieldId,- remappedDisplayName,- }) {- cy.request("POST", `/api/field/${sourceFieldId}/dimension`, {- type: "external",- name: remappedDisplayName,- human_readable_field_id: targetFieldId,- });- }-- function verifyListFilter({- fieldDisplayName,- filterHeaderName,- fieldValue,- fieldValueLabel,- }) {- H.tableHeaderClick(fieldDisplayName);- H.popover().findByText("Filter by this column").click();- H.popover().within(() => {- cy.findByPlaceholderText("Search the list").type(fieldValueLabel);- cy.findByText(fieldValueLabel).click();- cy.button("Add filter").click();- });- cy.findByTestId("qb-filters-panel")- .findByText(`${filterHeaderName || fieldDisplayName} is ${fieldValue}`)- .click();- H.popover().findByLabelText(fieldValueLabel).should("be.checked");- }-- function verifySearchFilter({- fieldDisplayName,- filterHeaderName,- fieldPlaceholder,- fieldValue,- fieldValueLabel,- }) {- H.tableHeaderClick(fieldDisplayName);- H.popover().findByText("Filter by this column").click();- H.popover().findByPlaceholderText(fieldPlaceholder).type(fieldValueLabel);- H.selectDropdown().findByText(fieldValueLabel).click();- cy.findByTestId("number-filter-picker")- .click()- .button("Add filter")- .click();- cy.findByTestId("qb-filters-panel")- .findByText(`${filterHeaderName || fieldDisplayName} is ${fieldValue}`)- .should("be.visible");- }-- function verifyRemappedFilter({- visitCard,- fieldId,- fieldDisplayName,- filterHeaderName,- fieldPlaceholder,- fieldValue,- fieldValueLabel,- expectedRowCount,- }) {- cy.log("list values");- cy.signInAsAdmin();- setListValues({ fieldId });- cy.signInAsNormalUser();- visitCard();- verifyListFilter({- fieldDisplayName,- filterHeaderName,- fieldValue,- fieldValueLabel,- });- H.assertQueryBuilderRowCount(expectedRowCount);-- cy.log("search values");- cy.signInAsAdmin();- setSearchValues({ fieldId });- cy.signInAsNormalUser();- visitCard();- verifySearchFilter({- fieldDisplayName,- filterHeaderName,- fieldPlaceholder,- fieldValue,- fieldValueLabel,- });- H.assertQueryBuilderRowCount(expectedRowCount);- }-- beforeEach(() => {- H.restore();- cy.signInAsAdmin();- });-- describe("type/PK -> type/Name remapping (metabase#45063)", () => {- it("should work with questions", () => {- createGuiQuestion({ sourceTableId: PEOPLE_ID });- verifyRemappedFilter({- visitCard: () => H.visitQuestion("@questionId"),- fieldId: PEOPLE.ID,- fieldDisplayName: "ID",- fieldPlaceholder: "Search by Name or enter an ID",- fieldValue: 1,- fieldValueLabel: "Hudson Borer",- expectedRowCount: 1,- });- });-- it("should work with models", () => {- createGuiModel({ sourceTableId: PEOPLE_ID });- verifyRemappedFilter({- visitCard: () => cy.get("@modelId").then(H.visitModel),- fieldId: PEOPLE.ID,- fieldDisplayName: "ID",- fieldPlaceholder: "Search by Name or enter an ID",- fieldValue: 1,- fieldValueLabel: "Hudson Borer",- expectedRowCount: 1,- });- });-- it("should work with native models", () => {- createNativeModel({- tableName: "PEOPLE",- fieldId: PEOPLE.ID,- fieldName: "ID",- fieldSemanticType: "type/PK",- });- verifyRemappedFilter({- visitCard: () => cy.get("@modelId").then(H.visitModel),- fieldId: PEOPLE.ID,- fieldDisplayName: "ID",- fieldPlaceholder: "Search by Name or enter an ID",- fieldValue: 1,- fieldValueLabel: "Hudson Borer",- expectedRowCount: 1,- });- });- });-- describe("type/FK -> column remapping (metabase#45063)", () => {- beforeEach(() => {- setForeignKeyRemapping({- sourceFieldId: ORDERS.PRODUCT_ID,- targetFieldId: PRODUCTS.TITLE,- remappedDisplayName: "Product ID",- });- });-- it("should work with questions", () => {- createGuiQuestion({ sourceTableId: ORDERS_ID });- verifyRemappedFilter({- visitCard: () => H.visitQuestion("@questionId"),- fieldId: ORDERS.PRODUCT_ID,- fieldDisplayName: "Product ID",- fieldPlaceholder: "Search by Title or enter an ID",- fieldValue: 1,- fieldValueLabel: "Rustic Paper Wallet",- expectedRowCount: 93,- });- });-- it("should work with models", () => {- createGuiModel({ sourceTableId: ORDERS_ID });- verifyRemappedFilter({- visitCard: () => cy.get("@modelId").then(H.visitModel),- fieldId: ORDERS.PRODUCT_ID,- fieldDisplayName: "Product ID",- fieldPlaceholder: "Search by Title or enter an ID",- fieldValue: 1,- fieldValueLabel: "Rustic Paper Wallet",- expectedRowCount: 93,- });- });-- it("should work with native models", () => {- createNativeModel({- tableName: "ORDERS",- fieldId: ORDERS.PRODUCT_ID,- fieldName: "PRODUCT_ID",- fieldSemanticType: "type/FK",- });- verifyRemappedFilter({- visitCard: () => cy.get("@modelId").then(H.visitModel),- fieldId: ORDERS.PRODUCT_ID,- fieldDisplayName: "Product ID",- filterHeaderName: "PRODUCT_ID", // the title case version doesn't get picked up in filters- fieldPlaceholder: "Search by Title or enter an ID",- fieldValue: 1,- fieldValueLabel: "Rustic Paper Wallet",- expectedRowCount: 93,- });- });- });-});--describe("issue 41464", () => {- beforeEach(() => {- H.restore();- cy.signInAsNormalUser();- });-- it("should not overlap 'no results' and the loading state (metabase#41464)", () => {- H.visitQuestionAdhoc({- dataset_query: {- database: SAMPLE_DB_ID,- type: "query",- query: {- "source-table": ORDERS_ID,- filter: [- ">",- ["field", ORDERS.TOTAL, { "base-type": "type/Float" }],- 1000,- ],- },- parameters: [],- },- });-- cy.intercept(- {- method: "POST",- url: "/api/dataset",- middleware: true,- },- (req) => {- req.on("response", (res) => {- // Throttle the response to 50kbps- res.setThrottle(50);- });- },- );-- cy.findByTestId("filter-pill")- .should("have.text", "Total is greater than 1000")- .icon("close")- .click();-- cy.findByTestId("query-builder-main").within(() => {- cy.findByTestId("loading-indicator").should("be.visible");- cy.findByText("No results!", { timeout: 500 }).should("not.exist");- });- });-});--describe("issue 45359", { tags: "@skip" }, () => {- beforeEach(() => {- H.restore();- cy.intercept("/app/fonts/Lato/lato-v16-latin-regular.woff2").as(- "font-regular",- );- cy.intercept("/app/fonts/Lato/lato-v16-latin-700.woff2").as("font-bold");- cy.signInAsAdmin();- });-- it("loads app fonts correctly (metabase#45359)", () => {- H.openOrdersTable({ mode: "notebook" });-- H.getNotebookStep("data")- .findByText("Orders")- .should("have.css", "font-family", "Lato, sans-serif");-- cy.get("@font-regular.all").should("have.length", 1);- cy.get("@font-regular").should(({ response }) => {- expect(response).to.include({ statusCode: 200 });- });-- cy.get("@font-bold.all").should("have.length", 1);- cy.get("@font-bold").should(({ response }) => {- expect(response).to.include({ statusCode: 200 });- });-- cy.document()- .then((document) => document.fonts.ready)- .then((fonts) => {- cy.wrap(fonts).invoke("check", "16px Lato").should("be.true");- });- });-});--describe("issue 45452", () => {- beforeEach(() => {- H.restore();- cy.signInAsAdmin();- });-- it("should only have one scrollbar for the summarize sidebar (metabase#45452)", () => {- H.openOrdersTable();- H.summarize();-- cy.findByTestId("summarize-aggregation-item-list").then(($el) => {- const element = $el[0];- expectNoScrollbarContainer(element);- });-- cy.findByTestId("summarize-breakout-column-list").then(($el) => {- const element = $el[0];- expectNoScrollbarContainer(element);- });-- // the sidebar is the only element with a scrollbar- cy.findByTestId("sidebar-content").then(($el) => {- const element = $el[0];- expect(element.scrollHeight > element.clientHeight).to.be.true;- expect(element.offsetWidth > element.clientWidth).to.be.true;- });- });-});--describe("issue 41612", () => {- beforeEach(() => {- H.restore();- cy.signInAsAdmin();- cy.intercept("POST", "/api/card").as("createQuestion");- });-- it("should not ignore chart viz settings when viewing raw results as a table (metabase#41612)", () => {- H.visitQuestionAdhoc(- {- display: "line",- dataset_query: {- type: "query",- database: SAMPLE_DB_ID,- query: {- aggregation: [["count"]],- breakout: [- [- "field",- ORDERS.CREATED_AT,- { "base-type": "type/DateTime", "temporal-unit": "month" },- ],- ],- "source-table": ORDERS_ID,- },- },- },- { visitQuestion: true },- );-- H.queryBuilderMain().findByLabelText("Switch to data").click();- H.queryBuilderHeader().button("Save").click();- H.modal().button("Save").click();-- cy.wait("@createQuestion").then((xhr) => {- const card = xhr.request.body;- expect(card.visualization_settings["graph.metrics"]).to.deep.equal([- "count",- ]);- expect(card.visualization_settings["graph.dimensions"]).to.deep.equal([- "CREATED_AT",- ]);- });- });-});--describe("issue 36027", () => {- beforeEach(() => {- H.restore();- cy.signInAsAdmin();-- const CONCRETE_CREATED_AT_FIELD_REF = [- "field",- ORDERS.CREATED_AT,- { "base-type": "type/DateTime", "temporal-unit": "month" },- ];-- const CREATED_AT_FIELD_REF = [- "field",- "CREATED_AT",- { "base-type": "type/DateTime", "temporal-unit": "month" },- ];-- const BASE_QUERY = {- aggregation: [["count"]],- breakout: [CONCRETE_CREATED_AT_FIELD_REF],- "source-table": ORDERS_ID,- };-- H.createQuestion({ query: BASE_QUERY }, { wrapId: true }).then(- (baseQuestionId) => {- H.createQuestion(- {- display: "waterfall",- query: {- aggregation: [- ["sum", ["field", "count", { "base-type": "type/Integer" }]],- ],- breakout: [CREATED_AT_FIELD_REF],- joins: [- {- alias: "Q1",- strategy: "left-join",- "source-table": `card__${baseQuestionId}`,- condition: [- "<=",- CREATED_AT_FIELD_REF,- CONCRETE_CREATED_AT_FIELD_REF,- ],- },- ],- "source-query": BASE_QUERY,- },- visualization_settings: {- "graph.dimensions": ["CREATED_AT"],- "graph.metrics": ["sum"],- },- },- { visitQuestion: true },- );- },- );- });-- it("should use default metrics/dimensions if they're missing after removing some query clauses (metabase#36027)", () => {- H.openNotebook();- H.getNotebookStep("summarize", { stage: 1 })- .findByLabelText("Remove step")- .click({ force: true });- H.getNotebookStep("join", { stage: 1 })- .findByLabelText("Remove step")- .click({ force: true });- H.visualize();-- H.echartsContainer().within(() => {- cy.findByText("Created At: Month").should("be.visible"); // x-axis- cy.findByText("Count").should("be.visible"); // y-axis-- // x-axis values- ["January 2023", "January 2024", "January 2025", "January 2026"].forEach(- (state) => {- cy.findByText(state).should("be.visible");- },- );-- // y-axis values- [- "0",- "3,000",- "6,000",- "9,000",- "12,000",- "15,000",- "18,000",- "21,000",- ].forEach((state) => {- cy.findByText(state).should("be.visible");- });- });- });-});--describe("issue 12586", () => {- beforeEach(() => {- H.restore();- cy.signInAsNormalUser();- });-- it("should not show the run button overlay when an error occurs (metabase#12586)", () => {- H.openOrdersTable();- H.summarize();-- cy.intercept("POST", "/api/dataset", (req) => req.destroy());-- H.rightSidebar().button("Done").click();- H.main()- .findByText("We're experiencing server issues")- .should("be.visible");- cy.findByTestId("query-builder-main").icon("play").should("not.be.visible");- });-});--function expectNoScrollbarContainer(element) {- const hasScrollbarContainer =- element.scrollHeight <= element.clientHeight &&- element.offsetWidth > element.clientWidth;-- expect(hasScrollbarContainer).to.be.false;-}--describe("issue 48829", () => {- const questionDetails = {- name: "Issue 48829",- query: {- "source-table": PRODUCTS_ID,- },- };-- beforeEach(() => {- H.restore();- cy.signInAsNormalUser();- });-- it("should not show the unsaved changes warning when switching back to chill mode from the notebook editor after adding a filter from headers (metabase#48829)", () => {- H.createQuestion(questionDetails, { visitQuestion: true });-- H.tableHeaderClick("Category");- H.popover().findByText("Filter by this column").click();- H.popover().within(() => {- cy.findByText("Doohickey").click();- cy.findByText("Add filter").click();- });-- H.queryBuilderHeader()- .button(/Editor/)- .click();- H.getNotebookStep("filter")- .findAllByTestId("notebook-cell-item")- .icon("close")- .should("be.visible")- .click();-- H.visualize();-- H.modal().should("not.exist");- });-- it("should not show the unsaved changes warning when switching back to chill mode from the notebook editor after adding a filter via the filter picker (metabase#48829)", () => {- H.createQuestion(questionDetails, { visitQuestion: true });-- H.queryBuilderHeader()- .button(/Filter/)- .click();- H.popover().within(() => {- cy.findByText("Category").click();- cy.findByText("Doohickey").click();- cy.button("Apply filter").click();- });-- H.queryBuilderHeader()- .button(/Editor/)- .click();- H.getNotebookStep("filter")- .findAllByTestId("notebook-cell-item")- .icon("close")- .should("be.visible")- .click();-- H.visualize();-- H.modal().should("not.exist");- });-- it("should not show the unsaved changes warning when switching back to chill mode from the notebook editor after visiting a filtered question from a dashboard click action (metabase#48829)", () => {- // Set up dashboard- H.createDashboardWithQuestions({ questions: [questionDetails] }).then(- ({ dashboard }) => {- H.visitDashboard(dashboard.id);- },- );-- H.showDashboardCardActions();- H.editDashboard();- H.getDashboardCard().findByLabelText("Click behavior").click();-- H.sidebar().within(() => {- cy.findByText("Title").click();- cy.findByText("Go to a custom destination").click();- cy.findByText("Saved question").click();- });-- H.entityPickerModal().within(() => {- cy.findByText("Our analytics").click();- cy.findByText(questionDetails.name).click();- });- H.sidebar().findByTestId("click-mappings").findByText("Title").click();- H.popover().findByText("Title").click();- H.saveDashboard();-- // Navigate to question using click action in dashboard- H.main().findByText("Rustic Paper Wallet").click();-- H.queryBuilderHeader()- .button(/Editor/)- .click();- H.getNotebookStep("filter")- .findAllByTestId("notebook-cell-item")- .icon("close")- .should("be.visible")- .click();-- H.visualize();-- H.modal().should("not.exist");- });-});--describe("issue 50038", () => {- const QUESTION = {- name: "question with a very long name that will be too long to fit on one line which normally would result in some weird looking buttons with inconsistent heights",- query: {- "source-table": PRODUCTS_ID,- },- };-- const OTHER_QUESTION = {- name: "question that also has a long name that is so long it will break in the button",- query: {- "source-table": ORDERS_ID,- },- };-- beforeEach(() => {- H.restore();- cy.signInAsNormalUser();-- H.createQuestion(QUESTION, { wrapId: true, idAlias: "questionId" });- H.createQuestion(OTHER_QUESTION, {- wrapId: true,- idAlias: "otherQuestionId",- });-- cy.get("@questionId").then((questionId) => {- cy.get("@otherQuestionId").then((otherQuestionId) => {- H.createQuestion(- {- name: "Joined question",- query: {- "source-table": `card__${questionId}`,- joins: [- {- "source-table": `card__${otherQuestionId}`,- fields: "all",- strategy: "left-join",- condition: [- "=",- ["field", PRODUCTS.ID, null],- ["field", ORDERS.PRODUCT_ID, { "join-alias": "Orders" }],- ],- },- ],- },- },- { visitQuestion: true },- );- });- });- });-- function assertEqualHeight(selector, otherSelector) {- selector.invoke("outerHeight").then((height) => {- otherSelector.invoke("outerHeight").should("eq", height);- });- }-- it("should not break data source and join source buttons when the source names are too long (metabase#50038)", () => {- H.openNotebook();- H.getNotebookStep("data").within(() => {- assertEqualHeight(- cy.findByText(QUESTION.name).parent().should("be.visible"),- cy.findByTestId("fields-picker").should("be.visible"),- );- });- H.getNotebookStep("join").within(() => {- assertEqualHeight(- cy- .findAllByText(OTHER_QUESTION.name)- .first()- .parent()- .should("be.visible"),- cy.findByTestId("fields-picker").should("be.visible"),- );- });- });-});--describe("issue 47940", () => {- const questionDetails = {- name: "Issue 47940",- query: {- "source-table": ORDERS_ID,- limit: 5,- },- };-- beforeEach(() => {- H.restore();- cy.signInAsAdmin();- cy.intercept("PUT", "/api/card/*").as("updateCard");- cy.intercept("POST", "/api/card/*/query").as("cardQuery");- });-- it("should be able to convert a question with date casting to a model", () => {- cy.log("create a question without any column casting");- H.createQuestion(questionDetails, { visitQuestion: true });- cy.wait("@cardQuery");-- cy.log("add coercion");- cy.request("PUT", `/api/field/${ORDERS.PRODUCT_ID}`, {- semantic_type: "type/Category",- coercion_strategy: "Coercion/UNIXMicroSeconds->DateTime",- });-- cy.log("reload to get new query results with coercion applied");- cy.reload();- cy.wait("@cardQuery");-- cy.log("turn into a model");- H.openQuestionActions();- H.popover().findByText("Turn into a model").click();- cy.findByRole("dialog").findByText("Turn this into a model").click();- cy.wait("@updateCard");-- cy.log("verify there is a table displayed");- cy.findByTestId("visualization-root").should(- "contain",- "December 31, 1969, 4:00 PM",- );- });-});--describe("issue 53036", () => {- beforeEach(() => {- H.restore();- cy.signInAsAdmin();- });-- const questionDetails = {- name: "Issue 53036",- query: {- "source-table": PRODUCTS_ID,- limit: 5,- joins: [- {- fields: "all",- alias: "Orders",- "source-table": ORDERS_ID,- strategy: "left-join",- condition: [- "=",- ["field", PRODUCTS.ID, null],- ["field", ORDERS.PRODUCT_ID, { "join-alias": "Orders" }],- ],- },- ],- },- };-- it("should keep buttons usable on mid size screen (metabase#53036)", () => {- H.createQuestion(questionDetails, { visitQuestion: true });- H.openNotebook();-- cy.viewport(650, 800);-- cy.log("try to click on add button - it fails is there is an overlap");-- H.getNotebookStep("join").within(() => {- cy.icon("play").should("be.visible");- cy.icon("add").click();- });- });-});--describe("issue 57697", () => {- beforeEach(() => {- H.restore();- cy.signInAsAdmin();- H.createQuestion(- {- query: {- "source-table": PRODUCTS_ID,- aggregation: [["count"]],- breakout: [- ["field", PRODUCTS.PRICE, { binning: { strategy: "default" } }],- ],- },- },- { visitQuestion: true },- );- });-- it("should not show the binning in the name of the column when binning in the summarize sidebar (metabase#57697)", () => {- H.summarize();- H.sidebar()- .filter(":visible")- .within(() => {- cy.findByText("Price").should("be.visible");- cy.findByText("Price: Auto binned").should("not.exist");- });- });-});--describe("issue 32499", () => {- beforeEach(() => {- H.restore();- cy.signInAsAdmin();- });-- it("Self-join columns can be edited independently", () => {- H.createQuestion(- {- name: "Model",- type: "model",- query: {- "source-table": ORDERS_ID,- fields: [- ["field", ORDERS.ID, null],- ["field", ORDERS.USER_ID, null],- ],- joins: [- {- fields: [["field", ORDERS.USER_ID, { "join-alias": "Orders" }]],- alias: "Orders",- "source-table": ORDERS_ID,- strategy: "left-join",- condition: [- "=",- ["field", ORDERS.ID, null],- ["field", ORDERS.ID, { "join-alias": "Orders" }],- ],- },- ],- },- },- { visitQuestion: true },- );-- H.openQuestionActions("Edit metadata");-- const columns = [- { original: "Orders → User ID", modified: "JOIN COLUMN" },- { original: "User ID", modified: "ORIGINAL COLUMN" },- ];-- // we can click the headers and modify their names- for (const { original, modified } of columns) {- H.tableHeaderClick(original);- cy.findByLabelText("Display name")- .should("have.value", original)- .click()- .clear()- .type(modified);- }-- // the modified names are now in the headers- for (const { modified } of columns) {- H.tableHeaderColumn(modified).should("exist");- }- });-});--describe("issue 23449", () => {- beforeEach(() => {- H.restore();- cy.signInAsAdmin();- });-- const checkTable = () => {- H.assertTableData({- columns: ["ID", "Product ID", "Reviewer", "Rating", "Created At"],- firstRows: [[1, 1, "christ", "E", "May 15, 2024, 8:25 PM"]],- });- };-- it("Remapped fields should work in a model (metabase#23449)", () => {- cy.log("set the metadata for review");- H.DataModel.visit({- databaseId: SAMPLE_DB_ID,- schemaId: SAMPLE_DB_SCHEMA_ID,- tableId: SAMPLE_DATABASE.REVIEWS_ID,- fieldId: SAMPLE_DATABASE.REVIEWS.RATING,- });-- H.DataModel.FieldSection.getDisplayValuesInput().click();- H.popover().findByText("Custom mapping").click();-- cy.findByDisplayValue("1").clear().type("A");- cy.findByDisplayValue("2").clear().type("B");- cy.findByDisplayValue("3").clear().type("C");- cy.findByDisplayValue("4").clear().type("D");- cy.findByDisplayValue("5").clear().type("E");-- cy.button("Save").click();-- cy.log("make a model on Reviews");- H.goToMainApp();- H.navigationSidebar().findByLabelText("Browse models").click();- cy.findByLabelText("Create a new model").click();- cy.findByRole("link", { name: /Use the notebook editor/ }).click();- H.miniPicker().findByText("Sample Database").click();- H.miniPicker().findByText("Reviews").click();-- cy.log("Remove Body column");- cy.findByLabelText("Pick columns").click();- H.popover().findByText("Body").click();-- cy.log("save model");- cy.findByTestId("dataset-edit-bar").button("Save").click();-- cy.log("confirm save in a modal");- H.modal().button("Save").click();-- cy.log("check that the data renders");- checkTable();-- cy.log("reload to flush cached results and check again");- cy.findByTestId("qb-header").button("Refresh").click();- checkTable();- });-});--describe("issue 12679", () => {- beforeEach(() => {- H.restore();- cy.signInAsAdmin();- });-- it("removing the first aggregation should not re-target the filter (metabase#12679)", () => {- const questionDetails = {- display: "table",- dataset_query: {- type: "query",- database: SAMPLE_DB_ID,- query: {- "source-query": {- "source-table": ORDERS_ID,- aggregation: [- ["sum", ["field", ORDERS.SUBTOTAL, null]],- ["sum", ["field", ORDERS.TAX, null]],- ["sum", ["field", ORDERS.TOTAL, null]],- ],- breakout: [- ["field", ORDERS.CREATED_AT, { "temporal-unit": "week" }],- ],- },- filter: [">", ["field", "sum_2", { "base-type": "type/Float" }], 100],- },- },- };-- H.visitQuestionAdhoc(questionDetails, { mode: "notebook" });- H.getNotebookStep("filter", { stage: 1 })- .findByText("Sum of Tax is greater than 100")- .should("exist");-- H.getNotebookStep("summarize").within(() => {- cy.findByText("Sum of Subtotal").parent().icon("close").click();- cy.findByText("Sum of Subtotal").should("not.exist");- });- H.getNotebookStep("filter", { stage: 1 })- .findByText("Sum of Tax is greater than 100")- .should("exist");-- H.visualize();-- cy.findByTestId("qb-filters-panel")- .findByText("Sum of Tax is greater than 100")- .should("exist");- cy.findByTestId("table-header").within(() => {- cy.findByText("Sum of Subtotal").should("not.exist");- cy.findByText("Sum of Tax").should("exist");- cy.findByText("Sum of Total").should("exist");- });- cy.findByTestId("question-row-count")- .findByText("Showing 174 rows")- .should("exist");- });-});--describe("issue 51856", () => {- beforeEach(() => {- H.restore();- cy.signInAsNormalUser();- });-- const q1Details = {- name: "Issue 51856 Q1",- type: "question",- query: {- "source-table": ORDERS_ID,- joins: [- {- fields: "all",- strategy: "left-join",- alias: "Products",- condition: [- "=",- [- "field",- ORDERS.PRODUCT_ID,- {- "base-type": "type/Integer",- },- ],- [- "field",- PRODUCTS.ID,- {- "base-type": "type/BigInteger",- "join-alias": "Products",- },- ],- ],- "source-table": PRODUCTS_ID,- },- ],- },- };-- const q2Details = {- name: "Issue 51856 Q2",- query: {- "source-table": SAMPLE_DATABASE.REVIEWS_ID,- joins: [- {- fields: "all",- strategy: "left-join",- alias: "Products",- condition: [- "=",- [- "field",- SAMPLE_DATABASE.REVIEWS.PRODUCT_ID,- {- "base-type": "type/Integer",- },- ],- [- "field",- PRODUCTS.ID,- {- "base-type": "type/BigInteger",- "join-alias": "Products",- },- ],- ],- "source-table": PRODUCTS_ID,- },- ],- },- };-- it("join alias deduplication should not break queries with multiple nesting levels with joins (metabase#51856)", () => {- H.createQuestion(q1Details, { wrapId: true, idAlias: "q1id" });- cy.get("@q1id").then((_q1id) => {- H.createQuestion(q2Details, { wrapId: true, idAlias: "q2id" });- cy.get("@q2id").then((_q2id) => {- H.startNewQuestion();-- H.selectSavedQuestionsToJoin(q1Details.name, q2Details.name);- cy.findByTestId("join-condition-0").findByText(q1Details.name).click();- H.popover().findByText("Products → Category").click();- cy.findByTestId("join-condition-0").findByText(q2Details.name).click();- H.popover().findByText("Issue 51856 Q2 → Category").click();-- H.visualize();-- H.tableInteractiveScrollContainer().scrollTo("right");- cy.findByTestId("table-header").within(() => {- cy.findByText("Products → Category").should("exist");- cy.findByText(- "Issue 51856 Q2 - Products → Category → Category",- ).should("exist");- });- cy.findByTestId("question-row-count")- .findByText("Showing first 2,000 rows")- .should("exist");- });- });- });-});--describe("issue 33972", () => {- beforeEach(() => {- H.restore();- cy.signInAsNormalUser();- });-- const queryDetails = {- name: "Issue 33972",- type: "question",- query: {- "source-table": ORDERS_ID,- fields: [- ["field", ORDERS.ID, { "base-type": "type/BigInteger" }],- ["field", ORDERS.PRODUCT_ID, { "base-type": "type/Integer" }],- ],- joins: [- {- fields: [- [- "field",- PRODUCTS.CATEGORY,- { "base-type": "type/Text", "join-alias": "Products" },- ],- ],- strategy: "left-join",- alias: "Products",- condition: [- "=",- [- "field",- ORDERS.PRODUCT_ID,- {- "base-type": "type/Integer",- },- ],- [- "field",- PRODUCTS.ID,- {- "base-type": "type/BigInteger",- "join-alias": "Products",- },- ],- ],- "source-table": PRODUCTS_ID,- },- ],- },- };-- it("should be able to distinguish explicitly and implicitly joined fields (metabase#33972)", () => {- H.createQuestion(queryDetails, { wrapId: true });- cy.get("@questionId").then((questionId) => {- H.visitQuestionAdhoc({- dataset_query: {- database: SAMPLE_DB_ID,- query: {- "source-table": "card__" + questionId,- },- type: "query",- },- });- cy.findByTestId("viz-settings-button").click();- cy.findByTestId("chartsettings-list-container")- .findByText("Add or remove columns")- .click();- cy.findByTestId("product-table-columns").findByText("Category").click();- cy.findByTestId("product-table-columns").findByText("Ean").click();- cy.findByTestId("table-header").within(() => {- cy.findByText("ID").should("exist");- cy.findByText("Product ID").should("exist");- cy.findByText("Products → Category").should("exist");- cy.findByText("Product → Category").should("exist");- cy.findByText("Product → Ean").should("exist");- });- cy.findByTestId("question-row-count")- .findByText("Showing first 2,000 rows")- .should("exist");- });- });-});--describe("Issue 33835", { tags: "@external" }, () => {- beforeEach(() => {- H.restore("postgres-writable");- cy.signInAsAdmin();-- H.queryWritableDB("DROP TABLE IF EXISTS orders");- H.queryWritableDB(- "CREATE TABLE IF NOT EXISTS orders (id INT PRIMARY KEY, total real, discount real)",- );- H.queryWritableDB(- "INSERT INTO orders (id, total, discount) VALUES (1, 100, 20)",- );-- H.resyncDatabase({ dbId: WRITABLE_DB_ID, tableName: "orders" });-- H.startNewQuestion();- H.miniPicker().findByText("Writable Postgres12").click();- H.miniPicker().findByText("Orders").click();-- H.getNotebookStep("summarize")- .findByText("Pick a function or metric")- .click();- H.popover().within(() => {- cy.findByText(/Average of/).click();- cy.findByText("Total").click();- });-- H.getNotebookStep("summarize")- .findByText("Pick a column to group by")- .click();- H.popover().findByText("Discount").click();-- H.saveQuestion("Test Question", {- wrapId: true,- questionId: "questionId",- addToDashboard: false,- });- });-- it("should be possible to remove an aggregation on a non-existent column (metabase#33835)", () => {- H.queryWritableDB("ALTER TABLE orders DROP COLUMN total");- H.resyncDatabase({ dbId: WRITABLE_DB_ID });-- H.visitQuestion("@questionId");- H.openNotebook();-- H.getNotebookStep("summarize")- .findByText("Average of Unknown Field")- .should("be.visible")- .icon("close")- .click();-- H.visualize();- cy.get("main")- .findByText("There was a problem with your question")- .should("not.exist");- });-- it("should be possible to remove a breakout on a non-existent column (metabase#33835)", () => {- H.queryWritableDB("ALTER TABLE orders DROP COLUMN discount");- H.resyncDatabase({ dbId: WRITABLE_DB_ID });-- H.visitQuestion("@questionId");- H.openNotebook();-- H.getNotebookStep("summarize")- .findByText("Unknown Field: Auto binned")- .should("be.visible")- .icon("close")- .click();-- H.visualize();- cy.get("main")- .findByText("There was a problem with your question")- .should("not.exist");- });-});--describe("Issue 42942", () => {- beforeEach(() => {- H.restore();- cy.signInAsAdmin();-- H.visitQuestionAdhoc({- display: "bar",- dataset_query: {- type: "query",- database: SAMPLE_DB_ID,- query: {- "source-table": ORDERS_ID,- aggregation: [["count"]],- breakout: [- [- "field",- ORDERS.TOTAL,- {- "base-type": "type/Float",- binning: { strategy: "num-bins", "num-bins": 100 },- },- ],- ],- },- },- });- });-- it("should adapt the filter widths when changing the filter value (metabase#42942)", () => {- H.openNotebook();-- H.getNotebookStep("data").findByLabelText("Filter").click();-- H.popover().within(() => {- cy.findByText("Total").click();- cy.findByPlaceholderText("Min").type("90");- cy.button("Add filter").click();- });- H.visualize();-- H.chartPathWithFillColor("#509EE3").first().click();- H.popover().findByText("See these Orders").click();-- cy.log(- "Filters should be applied correctly with the bin width from the chart",- );- H.queryBuilderFiltersPanel().findByText(- "Total is greater than or equal to 90",- );- H.queryBuilderFiltersPanel().findByText("Total is less than 90.75");- });-});--describe("Issue 48771", () => {- const MODEL_NAME = "M1";-- beforeEach(() => {- H.restore();- cy.signInAsAdmin();-- H.createNativeQuestion({- name: MODEL_NAME,- type: "model",- native: {- database: SAMPLE_DB_ID,- query: "SELECT 1 AS ID",- },- }).then(({ body: model }) => {- H.createQuestion(- {- type: "question",- query: {- filter: [- ">=",- [- "field",- "count",- {- "base-type": "type/Integer",- },- ],- 0.5,- ],- "source-query": {- database: SAMPLE_DB_ID,- "source-table": ORDERS_ID,- joins: [- {- "source-table": `card__${model.id}`,- fields: "all",- alias: MODEL_NAME,- strategy: "left-join",- condition: [- "=",- ["field", ORDERS.ID, { "base-type": "type/Integer" }],- [- "field",- "ID",- { "join-alias": MODEL_NAME, "base-type": "type/Integer" },- ],- ],- },- ],- aggregation: [["count"]],- breakout: [["field", ORDERS.CREATED_AT, null]],- },- },- },- { visitQuestion: true, wrapId: true },- );- });-- cy.log("give nosql user access to root collection");- cy.updateCollectionGraph({- [USER_GROUPS.NOSQL_GROUP]: { root: "write" },- });-- cy.signOut();- cy.signIn("nosql");- });-- it("should allow to add a filter after summary stage (metabase#48771)", () => {- H.visitQuestion("@questionId");- H.openNotebook();-- H.getNotebookStep("filter", { stage: 1 })- .findByText("Count is greater than or equal to 0.5")- .click();-- H.popover().within(() => {- cy.findByPlaceholderText("Enter a number").clear().type("0.7");- cy.button("Update filter").click();- });- H.visualize();- });-});--describe("Issue 42817", () => {- const NATIVE_QUESTION_NAME = "NativeOrders";-- beforeEach(() => {- H.restore();- cy.signInAsNormalUser();- H.createNativeQuestion({- name: NATIVE_QUESTION_NAME,- database: SAMPLE_DB_ID,- native: {- query: "SELECT ID, CREATED_AT FROM orders",- },- }).then(({ body: question }) => {- H.visitQuestionAdhoc({- display: "line",- dataset_query: {- type: "query",- database: SAMPLE_DB_ID,- query: {- "source-table": ORDERS_ID,- joins: [- {- fields: "all",- alias: NATIVE_QUESTION_NAME,- "source-table": `card__${question.id}`,- strategy: "left-join",- condition: [- "=",- [- "field",- ORDERS.ID,- {- "base-type": "type/BigInteger",- },- ],- [- "field",- "ID",- {- "base-type": "type/BigInteger",- "join-alias": NATIVE_QUESTION_NAME,- },- ],- ],- },- ],- aggregation: [["count"]],- breakout: [- [- "field",- "CREATED_AT",-- {- "base-type": "type/DateTime",- "temporal-unit": "day",- "join-alias": "NativeOrders",- },- ],- ],- filter: [- "between",- [- "field",- "CREATED_AT",- {- "base-type": "type/Date",- "inherited-temporal-unit": "day",- "temporal-unit": "day",- "join-alias": "NativeOrders",- },- ],- "2023-06-23T00:00Z",- "2023-07-03T00:00Z",- ],- },- },- });- });- });-- it("should be possible to drill down into a question with datetime buckets and a native join (metabase#42817)", () => {- H.echartsContainer()- .get("path[fill='hsla(0, 0%, 100%, 1.00)']")- .first()- .click();-- H.popover().findByText("See this day by hour").click();-- cy.findByTestId("query-visualization-root")- .findByText("There was a problem with your question")- .should("not.exist");-- H.echartsContainer().should("be.visible");- });-});diff --git a/e2e/test/scenarios/question-reproductions/reproductions-4.cy.spec.js b/e2e/test/scenarios/question-reproductions/reproductions-4.cy.spec.jsnew file mode 100644index 00000000000..d5600f3e988--- /dev/null+++ b/e2e/test/scenarios/question-reproductions/reproductions-4.cy.spec.js@@ -0,0 +1,1783 @@+const { H } = cy;+import {+ SAMPLE_DB_ID,+ SAMPLE_DB_SCHEMA_ID,+ USER_GROUPS,+ WRITABLE_DB_ID,+} from "e2e/support/cypress_data";+import { SAMPLE_DATABASE } from "e2e/support/cypress_sample_database";++const { ORDERS, ORDERS_ID, PRODUCTS, PRODUCTS_ID, PEOPLE, PEOPLE_ID } =+ SAMPLE_DATABASE;++describe("issue 44668", () => {+ beforeEach(() => {+ H.restore();+ cy.signInAsAdmin();+ });++ it("should not drop graph.metrics after adding a new query stage (metabase#44668)", () => {+ H.createQuestion(+ {+ display: "bar",+ query: {+ aggregation: [["count"]],+ breakout: [["field", PEOPLE.STATE, { "base-type": "type/Text" }]],+ "source-table": PEOPLE_ID,+ limit: 5,+ },+ visualization_settings: {+ "graph.metrics": ["count"],+ "graph.dimensions": ["STATE"],+ },+ },+ { visitQuestion: true },+ );++ H.openNotebook();++ // eslint-disable-next-line metabase/no-unsafe-element-filtering+ cy.findAllByTestId("action-buttons").last().button("Custom column").click();+ H.enterCustomColumnDetails({+ formula: 'concat("abc_", [Count])',+ name: "Custom String",+ format: true,+ });+ H.popover().button("Done").click();++ H.getNotebookStep("expression", { stage: 1 }).icon("add").click();+ H.enterCustomColumnDetails({+ formula: "[Count] * 2",+ name: "Custom Number",+ });+ H.popover().button("Done").click();++ H.visualize();++ H.echartsContainer().within(() => {+ cy.findByText("State").should("be.visible"); // x-axis+ cy.findByText("Count").should("be.visible"); // y-axis++ // x-axis values+ ["AK", "AL", "AR", "AZ", "CA"].forEach((state) => {+ cy.findByText(state).should("be.visible");+ });+ });++ // Ensure custom columns weren't added as series automatically+ H.queryBuilderMain().findByLabelText("Legend").should("not.exist");++ H.openVizSettingsSidebar();++ // Ensure can use Custom Number as series+ H.leftSidebar().findByText("Add another series").click();+ H.queryBuilderMain()+ .findByLabelText("Legend")+ .within(() => {+ cy.findByText("Count").should("exist");+ cy.findByText("Custom Number").should("exist");+ });+ H.leftSidebar().within(() => {+ cy.findByText("Add another series").should("not.exist");+ cy.findByText("Add series breakout").should("not.exist");+ cy.findByTestId("remove-Custom Number").click();+ });+ H.queryBuilderMain().findByLabelText("Legend").should("not.exist");++ H.leftSidebar().findByText("Add series breakout").click();+ H.popover().within(() => {+ cy.findByText("Count").should("exist");+ cy.findByText("Custom Number").should("exist");+ cy.findByText("Custom String").click();+ });+ H.queryBuilderMain()+ .findByLabelText("Legend")+ .within(() => {+ ["68", "56", "49", "20", "90"].forEach((value) => {+ cy.findByText(`abc_${value}`).should("exist");+ });+ });+ H.leftSidebar().within(() => {+ cy.findByText("Add another series").should("not.exist");+ cy.findByText("Add series breakout").should("not.exist");+ });+ });+});++describe("issue 44974", { tags: "@external" }, () => {+ const PG_DB_ID = 2;++ beforeEach(() => {+ cy.intercept("GET", "/api/collection/*/items*").as("getCollectionItems");+ H.restore("postgres-12");+ cy.signInAsAdmin();+ });++ it("entity picker should not offer to join with a table or a question from a different database (metabase#44974)", () => {+ H.withDatabase(PG_DB_ID, ({ PEOPLE_ID }) => {+ const questionDetails = {+ name: "Question 44974 in Postgres DB",+ database: PG_DB_ID,+ query: {+ "source-table": PEOPLE_ID,+ limit: 1,+ },+ };++ H.createQuestion(questionDetails);++ H.openOrdersTable({ mode: "notebook" });+ H.join();+ H.miniPicker().within(() => {+ cy.findByText("Our analytics").click();+ cy.findByText("Orders Model").should("be.visible");+ cy.findByText(questionDetails.name).should("not.exist");+ });+ H.miniPickerHeader().click();+ H.miniPickerBrowseAll().click();++ cy.wait(["@getCollectionItems", "@getCollectionItems"]);++ H.entityPickerModal().within(() => {+ H.entityPickerModalItem(0, "Our analytics").click();+ cy.findByText("Orders Model").should("be.visible");+ H.entityPickerModalItem(1, questionDetails.name).should(+ "have.attr",+ "data-disabled",+ "true",+ );+ cy.button("Close").click();+ });+ });+ });+});++describe("issue 38989", () => {+ beforeEach(() => {+ H.restore();+ cy.signInAsAdmin();+ });++ it("should be impossible to join with a table or question which is not in the same database (metabase#38989)", () => {+ H.createQuestion(+ {+ query: {+ "source-table": PEOPLE_ID,+ fields: [+ ["field", PEOPLE.ID, { "base-type": "type/Number" }],+ ["field", PEOPLE.EMAIL, { "base-type": "type/Text" }],+ ],+ joins: [+ {+ fields: "all",+ alias: "Orders",+ // This is not a valid table ID in the Sample Database+ "source-table": 123,+ strategy: "left-join",+ condition: [+ "=",+ ["field", PEOPLE.ID, null],+ ["field", ORDERS.USER_ID, { "join-alias": "Orders" }],+ ],+ },+ ],+ },+ },+ {+ visitQuestion: true,+ },+ );++ cy.findByTestId("query-builder-main")+ .findByText("Show error details")+ .click();++ cy.findByTestId("query-builder-main")+ .findByText(+ /either it does not exist, or it belongs to a different Database/,+ )+ .should("exist");+ });+});++describe("issue 39771", () => {+ beforeEach(() => {+ H.restore();+ cy.signInAsNormalUser();+ });++ it("should show tooltip for ellipsified text (metabase#39771)", () => {+ H.createQuestion(+ {+ query: {+ aggregation: [["count"]],+ breakout: [+ [+ "field",+ "CREATED_AT",+ {+ "base-type": "type/DateTime",+ "temporal-unit": "quarter-of-year",+ },+ ],+ ],+ "source-query": {+ "source-table": ORDERS_ID,+ aggregation: [["count"]],+ breakout: [+ [+ "field",+ ORDERS.CREATED_AT,+ {+ "base-type": "type/DateTime",+ "temporal-unit": "month",+ },+ ],+ ],+ },+ },+ },+ { visitQuestion: true },+ );++ H.openNotebook();+ H.getNotebookStep("summarize", { stage: 1 })+ .findByTestId("breakout-step")+ .findByText("Created At: Quarter of year")+ .click();++ H.popover().findByText("by quarter of year").realHover();++ H.popover().then(([$popover]) => {+ const popoverStyle = window.getComputedStyle($popover);+ const popoverZindex = parseInt(popoverStyle.zIndex, 10);++ cy.findByTestId("ellipsified-tooltip").within(([$tooltip]) => {+ cy.findByText("by quarter of year").should("be.visible");++ const tooltipStyle = window.getComputedStyle($tooltip);+ const tooltipZindex = parseInt(tooltipStyle.zIndex, 10);++ // resort to asserting zIndex because should("be.visible") passes unexpectedly+ expect(tooltipZindex).to.be.gte(popoverZindex);+ });+ });+ });+});++describe("issue 45063", () => {+ function createGuiQuestion({ sourceTableId }) {+ const questionDetails = {+ name: "Question",+ query: {+ "source-table": sourceTableId,+ },+ };+ H.createQuestion(questionDetails, { wrapId: true });+ }++ function createGuiModel({ sourceTableId }) {+ const mbqlModelDetails = {+ name: "Model",+ type: "model",+ query: {+ "source-table": sourceTableId,+ },+ };+ H.createQuestion(mbqlModelDetails, { wrapId: true, idAlias: "modelId" });+ }++ function createNativeModel({+ tableName,+ fieldId,+ fieldName,+ fieldSemanticType,+ }) {+ const nativeModelDetails = {+ name: "Native Model",+ type: "model",+ native: {+ query: `SELECT * FROM ${tableName}`,+ },+ };+ H.createNativeQuestion(nativeModelDetails, {+ wrapId: true,+ idAlias: "modelId",+ }).then(({ body: model }) => {+ cy.log("populate result_metadata");+ cy.request("POST", `/api/card/${model.id}/query`);+ cy.log("map columns to database fields");+ H.setModelMetadata(model.id, (field) => {+ if (field.name === fieldName) {+ return { ...field, id: fieldId, semantic_type: fieldSemanticType };+ }+ return field;+ });+ });+ }++ function setListValues({ fieldId }) {+ cy.request("PUT", `/api/field/${fieldId}`, {+ has_field_values: "list",+ });+ }++ function setSearchValues({ fieldId }) {+ cy.request("PUT", `/api/field/${fieldId}`, {+ has_field_values: "search",+ });+ }++ function setForeignKeyRemapping({+ sourceFieldId,+ targetFieldId,+ remappedDisplayName,+ }) {+ cy.request("POST", `/api/field/${sourceFieldId}/dimension`, {+ type: "external",+ name: remappedDisplayName,+ human_readable_field_id: targetFieldId,+ });+ }++ function verifyListFilter({+ fieldDisplayName,+ filterHeaderName,+ fieldValue,+ fieldValueLabel,+ }) {+ H.tableHeaderClick(fieldDisplayName);+ H.popover().findByText("Filter by this column").click();+ H.popover().within(() => {+ cy.findByPlaceholderText("Search the list").type(fieldValueLabel);+ cy.findByText(fieldValueLabel).click();+ cy.button("Add filter").click();+ });+ cy.findByTestId("qb-filters-panel")+ .findByText(`${filterHeaderName || fieldDisplayName} is ${fieldValue}`)+ .click();+ H.popover().findByLabelText(fieldValueLabel).should("be.checked");+ }++ function verifySearchFilter({+ fieldDisplayName,+ filterHeaderName,+ fieldPlaceholder,+ fieldValue,+ fieldValueLabel,+ }) {+ H.tableHeaderClick(fieldDisplayName);+ H.popover().findByText("Filter by this column").click();+ H.popover().findByPlaceholderText(fieldPlaceholder).type(fieldValueLabel);+ H.selectDropdown().findByText(fieldValueLabel).click();+ cy.findByTestId("number-filter-picker")+ .click()+ .button("Add filter")+ .click();+ cy.findByTestId("qb-filters-panel")+ .findByText(`${filterHeaderName || fieldDisplayName} is ${fieldValue}`)+ .should("be.visible");+ }++ function verifyRemappedFilter({+ visitCard,+ fieldId,+ fieldDisplayName,+ filterHeaderName,+ fieldPlaceholder,+ fieldValue,+ fieldValueLabel,+ expectedRowCount,+ }) {+ cy.log("list values");+ cy.signInAsAdmin();+ setListValues({ fieldId });+ cy.signInAsNormalUser();+ visitCard();+ verifyListFilter({+ fieldDisplayName,+ filterHeaderName,+ fieldValue,+ fieldValueLabel,+ });+ H.assertQueryBuilderRowCount(expectedRowCount);++ cy.log("search values");+ cy.signInAsAdmin();+ setSearchValues({ fieldId });+ cy.signInAsNormalUser();+ visitCard();+ verifySearchFilter({+ fieldDisplayName,+ filterHeaderName,+ fieldPlaceholder,+ fieldValue,+ fieldValueLabel,+ });+ H.assertQueryBuilderRowCount(expectedRowCount);+ }++ beforeEach(() => {+ H.restore();+ cy.signInAsAdmin();+ });++ describe("type/PK -> type/Name remapping (metabase#45063)", () => {+ it("should work with questions", () => {+ createGuiQuestion({ sourceTableId: PEOPLE_ID });+ verifyRemappedFilter({+ visitCard: () => H.visitQuestion("@questionId"),+ fieldId: PEOPLE.ID,+ fieldDisplayName: "ID",+ fieldPlaceholder: "Search by Name or enter an ID",+ fieldValue: 1,+ fieldValueLabel: "Hudson Borer",+ expectedRowCount: 1,+ });+ });++ it("should work with models", () => {+ createGuiModel({ sourceTableId: PEOPLE_ID });+ verifyRemappedFilter({+ visitCard: () => cy.get("@modelId").then(H.visitModel),+ fieldId: PEOPLE.ID,+ fieldDisplayName: "ID",+ fieldPlaceholder: "Search by Name or enter an ID",+ fieldValue: 1,+ fieldValueLabel: "Hudson Borer",+ expectedRowCount: 1,+ });+ });++ it("should work with native models", () => {+ createNativeModel({+ tableName: "PEOPLE",+ fieldId: PEOPLE.ID,+ fieldName: "ID",+ fieldSemanticType: "type/PK",+ });+ verifyRemappedFilter({+ visitCard: () => cy.get("@modelId").then(H.visitModel),+ fieldId: PEOPLE.ID,+ fieldDisplayName: "ID",+ fieldPlaceholder: "Search by Name or enter an ID",+ fieldValue: 1,+ fieldValueLabel: "Hudson Borer",+ expectedRowCount: 1,+ });+ });+ });++ describe("type/FK -> column remapping (metabase#45063)", () => {+ beforeEach(() => {+ setForeignKeyRemapping({+ sourceFieldId: ORDERS.PRODUCT_ID,+ targetFieldId: PRODUCTS.TITLE,+ remappedDisplayName: "Product ID",+ });+ });++ it("should work with questions", () => {+ createGuiQuestion({ sourceTableId: ORDERS_ID });+ verifyRemappedFilter({+ visitCard: () => H.visitQuestion("@questionId"),+ fieldId: ORDERS.PRODUCT_ID,+ fieldDisplayName: "Product ID",+ fieldPlaceholder: "Search by Title or enter an ID",+ fieldValue: 1,+ fieldValueLabel: "Rustic Paper Wallet",+ expectedRowCount: 93,+ });+ });++ it("should work with models", () => {+ createGuiModel({ sourceTableId: ORDERS_ID });+ verifyRemappedFilter({+ visitCard: () => cy.get("@modelId").then(H.visitModel),+ fieldId: ORDERS.PRODUCT_ID,+ fieldDisplayName: "Product ID",+ fieldPlaceholder: "Search by Title or enter an ID",+ fieldValue: 1,+ fieldValueLabel: "Rustic Paper Wallet",+ expectedRowCount: 93,+ });+ });++ it("should work with native models", () => {+ createNativeModel({+ tableName: "ORDERS",+ fieldId: ORDERS.PRODUCT_ID,+ fieldName: "PRODUCT_ID",+ fieldSemanticType: "type/FK",+ });+ verifyRemappedFilter({+ visitCard: () => cy.get("@modelId").then(H.visitModel),+ fieldId: ORDERS.PRODUCT_ID,+ fieldDisplayName: "Product ID",+ filterHeaderName: "PRODUCT_ID", // the title case version doesn't get picked up in filters+ fieldPlaceholder: "Search by Title or enter an ID",+ fieldValue: 1,+ fieldValueLabel: "Rustic Paper Wallet",+ expectedRowCount: 93,+ });+ });+ });+});++describe("issue 41464", () => {+ beforeEach(() => {+ H.restore();+ cy.signInAsNormalUser();+ });++ it("should not overlap 'no results' and the loading state (metabase#41464)", () => {+ H.visitQuestionAdhoc({+ dataset_query: {+ database: SAMPLE_DB_ID,+ type: "query",+ query: {+ "source-table": ORDERS_ID,+ filter: [+ ">",+ ["field", ORDERS.TOTAL, { "base-type": "type/Float" }],+ 1000,+ ],+ },+ parameters: [],+ },+ });++ cy.intercept(+ {+ method: "POST",+ url: "/api/dataset",+ middleware: true,+ },+ (req) => {+ req.on("response", (res) => {+ // Throttle the response to 50kbps+ res.setThrottle(50);+ });+ },+ );++ cy.findByTestId("filter-pill")+ .should("have.text", "Total is greater than 1000")+ .icon("close")+ .click();++ cy.findByTestId("query-builder-main").within(() => {+ cy.findByTestId("loading-indicator").should("be.visible");+ cy.findByText("No results!", { timeout: 500 }).should("not.exist");+ });+ });+});++describe("issue 45359", { tags: "@skip" }, () => {+ beforeEach(() => {+ H.restore();+ cy.intercept("/app/fonts/Lato/lato-v16-latin-regular.woff2").as(+ "font-regular",+ );+ cy.intercept("/app/fonts/Lato/lato-v16-latin-700.woff2").as("font-bold");+ cy.signInAsAdmin();+ });++ it("loads app fonts correctly (metabase#45359)", () => {+ H.openOrdersTable({ mode: "notebook" });++ H.getNotebookStep("data")+ .findByText("Orders")+ .should("have.css", "font-family", "Lato, sans-serif");++ cy.get("@font-regular.all").should("have.length", 1);+ cy.get("@font-regular").should(({ response }) => {+ expect(response).to.include({ statusCode: 200 });+ });++ cy.get("@font-bold.all").should("have.length", 1);+ cy.get("@font-bold").should(({ response }) => {+ expect(response).to.include({ statusCode: 200 });+ });++ cy.document()+ .then((document) => document.fonts.ready)+ .then((fonts) => {+ cy.wrap(fonts).invoke("check", "16px Lato").should("be.true");+ });+ });+});++describe("issue 45452", () => {+ beforeEach(() => {+ H.restore();+ cy.signInAsAdmin();+ });++ it("should only have one scrollbar for the summarize sidebar (metabase#45452)", () => {+ H.openOrdersTable();+ H.summarize();++ cy.findByTestId("summarize-aggregation-item-list").then(($el) => {+ const element = $el[0];+ expectNoScrollbarContainer(element);+ });++ cy.findByTestId("summarize-breakout-column-list").then(($el) => {+ const element = $el[0];+ expectNoScrollbarContainer(element);+ });++ // the sidebar is the only element with a scrollbar+ cy.findByTestId("sidebar-content").then(($el) => {+ const element = $el[0];+ expect(element.scrollHeight > element.clientHeight).to.be.true;+ expect(element.offsetWidth > element.clientWidth).to.be.true;+ });+ });+});++describe("issue 41612", () => {+ beforeEach(() => {+ H.restore();+ cy.signInAsAdmin();+ cy.intercept("POST", "/api/card").as("createQuestion");+ });++ it("should not ignore chart viz settings when viewing raw results as a table (metabase#41612)", () => {+ H.visitQuestionAdhoc(+ {+ display: "line",+ dataset_query: {+ type: "query",+ database: SAMPLE_DB_ID,+ query: {+ aggregation: [["count"]],+ breakout: [+ [+ "field",+ ORDERS.CREATED_AT,+ { "base-type": "type/DateTime", "temporal-unit": "month" },+ ],+ ],+ "source-table": ORDERS_ID,+ },+ },+ },+ { visitQuestion: true },+ );++ H.queryBuilderMain().findByLabelText("Switch to data").click();+ H.queryBuilderHeader().button("Save").click();+ H.modal().button("Save").click();++ cy.wait("@createQuestion").then((xhr) => {+ const card = xhr.request.body;+ expect(card.visualization_settings["graph.metrics"]).to.deep.equal([+ "count",+ ]);+ expect(card.visualization_settings["graph.dimensions"]).to.deep.equal([+ "CREATED_AT",+ ]);+ });+ });+});++describe("issue 36027", () => {+ beforeEach(() => {+ H.restore();+ cy.signInAsAdmin();++ const CONCRETE_CREATED_AT_FIELD_REF = [+ "field",+ ORDERS.CREATED_AT,+ { "base-type": "type/DateTime", "temporal-unit": "month" },+ ];++ const CREATED_AT_FIELD_REF = [+ "field",+ "CREATED_AT",+ { "base-type": "type/DateTime", "temporal-unit": "month" },+ ];++ const BASE_QUERY = {+ aggregation: [["count"]],+ breakout: [CONCRETE_CREATED_AT_FIELD_REF],+ "source-table": ORDERS_ID,+ };++ H.createQuestion({ query: BASE_QUERY }, { wrapId: true }).then(+ (baseQuestionId) => {+ H.createQuestion(+ {+ display: "waterfall",+ query: {+ aggregation: [+ ["sum", ["field", "count", { "base-type": "type/Integer" }]],+ ],+ breakout: [CREATED_AT_FIELD_REF],+ joins: [+ {+ alias: "Q1",+ strategy: "left-join",+ "source-table": `card__${baseQuestionId}`,+ condition: [+ "<=",+ CREATED_AT_FIELD_REF,+ CONCRETE_CREATED_AT_FIELD_REF,+ ],+ },+ ],+ "source-query": BASE_QUERY,+ },+ visualization_settings: {+ "graph.dimensions": ["CREATED_AT"],+ "graph.metrics": ["sum"],+ },+ },+ { visitQuestion: true },+ );+ },+ );+ });++ it("should use default metrics/dimensions if they're missing after removing some query clauses (metabase#36027)", () => {+ H.openNotebook();+ H.getNotebookStep("summarize", { stage: 1 })+ .findByLabelText("Remove step")+ .click({ force: true });+ H.getNotebookStep("join", { stage: 1 })+ .findByLabelText("Remove step")+ .click({ force: true });+ H.visualize();++ H.echartsContainer().within(() => {+ cy.findByText("Created At: Month").should("be.visible"); // x-axis+ cy.findByText("Count").should("be.visible"); // y-axis++ // x-axis values+ ["January 2023", "January 2024", "January 2025", "January 2026"].forEach(+ (state) => {+ cy.findByText(state).should("be.visible");+ },+ );++ // y-axis values+ [+ "0",+ "3,000",+ "6,000",+ "9,000",+ "12,000",+ "15,000",+ "18,000",+ "21,000",+ ].forEach((state) => {+ cy.findByText(state).should("be.visible");+ });+ });+ });+});++describe("issue 12586", () => {+ beforeEach(() => {+ H.restore();+ cy.signInAsNormalUser();+ });++ it("should not show the run button overlay when an error occurs (metabase#12586)", () => {+ H.openOrdersTable();+ H.summarize();++ cy.intercept("POST", "/api/dataset", (req) => req.destroy());++ H.rightSidebar().button("Done").click();+ H.main()+ .findByText("We're experiencing server issues")+ .should("be.visible");+ cy.findByTestId("query-builder-main").icon("play").should("not.be.visible");+ });+});++function expectNoScrollbarContainer(element) {+ const hasScrollbarContainer =+ element.scrollHeight <= element.clientHeight &&+ element.offsetWidth > element.clientWidth;++ expect(hasScrollbarContainer).to.be.false;+}++describe("issue 48829", () => {+ const questionDetails = {+ name: "Issue 48829",+ query: {+ "source-table": PRODUCTS_ID,+ },+ };++ beforeEach(() => {+ H.restore();+ cy.signInAsNormalUser();+ });++ it("should not show the unsaved changes warning when switching back to chill mode from the notebook editor after adding a filter from headers (metabase#48829)", () => {+ H.createQuestion(questionDetails, { visitQuestion: true });++ H.tableHeaderClick("Category");+ H.popover().findByText("Filter by this column").click();+ H.popover().within(() => {+ cy.findByText("Doohickey").click();+ cy.findByText("Add filter").click();+ });++ H.queryBuilderHeader()+ .button(/Editor/)+ .click();+ H.getNotebookStep("filter")+ .findAllByTestId("notebook-cell-item")+ .icon("close")+ .should("be.visible")+ .click();++ H.visualize();++ H.modal().should("not.exist");+ });++ it("should not show the unsaved changes warning when switching back to chill mode from the notebook editor after adding a filter via the filter picker (metabase#48829)", () => {+ H.createQuestion(questionDetails, { visitQuestion: true });++ H.queryBuilderHeader()+ .button(/Filter/)+ .click();+ H.popover().within(() => {+ cy.findByText("Category").click();+ cy.findByText("Doohickey").click();+ cy.button("Apply filter").click();+ });++ H.queryBuilderHeader()+ .button(/Editor/)+ .click();+ H.getNotebookStep("filter")+ .findAllByTestId("notebook-cell-item")+ .icon("close")+ .should("be.visible")+ .click();++ H.visualize();++ H.modal().should("not.exist");+ });++ it("should not show the unsaved changes warning when switching back to chill mode from the notebook editor after visiting a filtered question from a dashboard click action (metabase#48829)", () => {+ // Set up dashboard+ H.createDashboardWithQuestions({ questions: [questionDetails] }).then(+ ({ dashboard }) => {+ H.visitDashboard(dashboard.id);+ },+ );++ H.showDashboardCardActions();+ H.editDashboard();+ H.getDashboardCard().findByLabelText("Click behavior").click();++ H.sidebar().within(() => {+ cy.findByText("Title").click();+ cy.findByText("Go to a custom destination").click();+ cy.findByText("Saved question").click();+ });++ H.entityPickerModal().within(() => {+ cy.findByText("Our analytics").click();+ cy.findByText(questionDetails.name).click();+ });+ H.sidebar().findByTestId("click-mappings").findByText("Title").click();+ H.popover().findByText("Title").click();+ H.saveDashboard();++ // Navigate to question using click action in dashboard+ H.main().findByText("Rustic Paper Wallet").click();++ H.queryBuilderHeader()+ .button(/Editor/)+ .click();+ H.getNotebookStep("filter")+ .findAllByTestId("notebook-cell-item")+ .icon("close")+ .should("be.visible")+ .click();++ H.visualize();++ H.modal().should("not.exist");+ });+});++describe("issue 50038", () => {+ const QUESTION = {+ name: "question with a very long name that will be too long to fit on one line which normally would result in some weird looking buttons with inconsistent heights",+ query: {+ "source-table": PRODUCTS_ID,+ },+ };++ const OTHER_QUESTION = {+ name: "question that also has a long name that is so long it will break in the button",+ query: {+ "source-table": ORDERS_ID,+ },+ };++ beforeEach(() => {+ H.restore();+ cy.signInAsNormalUser();++ H.createQuestion(QUESTION, { wrapId: true, idAlias: "questionId" });+ H.createQuestion(OTHER_QUESTION, {+ wrapId: true,+ idAlias: "otherQuestionId",+ });++ cy.get("@questionId").then((questionId) => {+ cy.get("@otherQuestionId").then((otherQuestionId) => {+ H.createQuestion(+ {+ name: "Joined question",+ query: {+ "source-table": `card__${questionId}`,+ joins: [+ {+ "source-table": `card__${otherQuestionId}`,+ fields: "all",+ strategy: "left-join",+ condition: [+ "=",+ ["field", PRODUCTS.ID, null],+ ["field", ORDERS.PRODUCT_ID, { "join-alias": "Orders" }],+ ],+ },+ ],+ },+ },+ { visitQuestion: true },+ );+ });+ });+ });++ function assertEqualHeight(selector, otherSelector) {+ selector.invoke("outerHeight").then((height) => {+ otherSelector.invoke("outerHeight").should("eq", height);+ });+ }++ it("should not break data source and join source buttons when the source names are too long (metabase#50038)", () => {+ H.openNotebook();+ H.getNotebookStep("data").within(() => {+ assertEqualHeight(+ cy.findByText(QUESTION.name).parent().should("be.visible"),+ cy.findByTestId("fields-picker").should("be.visible"),+ );+ });+ H.getNotebookStep("join").within(() => {+ assertEqualHeight(+ cy+ .findAllByText(OTHER_QUESTION.name)+ .first()+ .parent()+ .should("be.visible"),+ cy.findByTestId("fields-picker").should("be.visible"),+ );+ });+ });+});++describe("issue 47940", () => {+ const questionDetails = {+ name: "Issue 47940",+ query: {+ "source-table": ORDERS_ID,+ limit: 5,+ },+ };++ beforeEach(() => {+ H.restore();+ cy.signInAsAdmin();+ cy.intercept("PUT", "/api/card/*").as("updateCard");+ cy.intercept("POST", "/api/card/*/query").as("cardQuery");+ });++ it("should be able to convert a question with date casting to a model", () => {+ cy.log("create a question without any column casting");+ H.createQuestion(questionDetails, { visitQuestion: true });+ cy.wait("@cardQuery");++ cy.log("add coercion");+ cy.request("PUT", `/api/field/${ORDERS.PRODUCT_ID}`, {+ semantic_type: "type/Category",+ coercion_strategy: "Coercion/UNIXMicroSeconds->DateTime",+ });++ cy.log("reload to get new query results with coercion applied");+ cy.reload();+ cy.wait("@cardQuery");++ cy.log("turn into a model");+ H.openQuestionActions();+ H.popover().findByText("Turn into a model").click();+ cy.findByRole("dialog").findByText("Turn this into a model").click();+ cy.wait("@updateCard");++ cy.log("verify there is a table displayed");+ cy.findByTestId("visualization-root").should(+ "contain",+ "December 31, 1969, 4:00 PM",+ );+ });+});++describe("issue 53036", () => {+ beforeEach(() => {+ H.restore();+ cy.signInAsAdmin();+ });++ const questionDetails = {+ name: "Issue 53036",+ query: {+ "source-table": PRODUCTS_ID,+ limit: 5,+ joins: [+ {+ fields: "all",+ alias: "Orders",+ "source-table": ORDERS_ID,+ strategy: "left-join",+ condition: [+ "=",+ ["field", PRODUCTS.ID, null],+ ["field", ORDERS.PRODUCT_ID, { "join-alias": "Orders" }],+ ],+ },+ ],+ },+ };++ it("should keep buttons usable on mid size screen (metabase#53036)", () => {+ H.createQuestion(questionDetails, { visitQuestion: true });+ H.openNotebook();++ cy.viewport(650, 800);++ cy.log("try to click on add button - it fails is there is an overlap");++ H.getNotebookStep("join").within(() => {+ cy.icon("play").should("be.visible");+ cy.icon("add").click();+ });+ });+});++describe("issue 57697", () => {+ beforeEach(() => {+ H.restore();+ cy.signInAsAdmin();+ H.createQuestion(+ {+ query: {+ "source-table": PRODUCTS_ID,+ aggregation: [["count"]],+ breakout: [+ ["field", PRODUCTS.PRICE, { binning: { strategy: "default" } }],+ ],+ },+ },+ { visitQuestion: true },+ );+ });++ it("should not show the binning in the name of the column when binning in the summarize sidebar (metabase#57697)", () => {+ H.summarize();+ H.sidebar()+ .filter(":visible")+ .within(() => {+ cy.findByText("Price").should("be.visible");+ cy.findByText("Price: Auto binned").should("not.exist");+ });+ });+});++describe("issue 32499", () => {+ beforeEach(() => {+ H.restore();+ cy.signInAsAdmin();+ });++ it("Self-join columns can be edited independently", () => {+ H.createQuestion(+ {+ name: "Model",+ type: "model",+ query: {+ "source-table": ORDERS_ID,+ fields: [+ ["field", ORDERS.ID, null],+ ["field", ORDERS.USER_ID, null],+ ],+ joins: [+ {+ fields: [["field", ORDERS.USER_ID, { "join-alias": "Orders" }]],+ alias: "Orders",+ "source-table": ORDERS_ID,+ strategy: "left-join",+ condition: [+ "=",+ ["field", ORDERS.ID, null],+ ["field", ORDERS.ID, { "join-alias": "Orders" }],+ ],+ },+ ],+ },+ },+ { visitQuestion: true },+ );++ H.openQuestionActions("Edit metadata");++ const columns = [+ { original: "Orders → User ID", modified: "JOIN COLUMN" },+ { original: "User ID", modified: "ORIGINAL COLUMN" },+ ];++ // we can click the headers and modify their names+ for (const { original, modified } of columns) {+ H.tableHeaderClick(original);+ cy.findByLabelText("Display name")+ .should("have.value", original)+ .click()+ .clear()+ .type(modified);+ }++ // the modified names are now in the headers+ for (const { modified } of columns) {+ H.tableHeaderColumn(modified).should("exist");+ }+ });+});++describe("issue 23449", () => {+ beforeEach(() => {+ H.restore();+ cy.signInAsAdmin();+ });++ const checkTable = () => {+ H.assertTableData({+ columns: ["ID", "Product ID", "Reviewer", "Rating", "Created At"],+ firstRows: [[1, 1, "christ", "E", "May 15, 2024, 8:25 PM"]],+ });+ };++ it("Remapped fields should work in a model (metabase#23449)", () => {+ cy.log("set the metadata for review");+ H.DataModel.visit({+ databaseId: SAMPLE_DB_ID,+ schemaId: SAMPLE_DB_SCHEMA_ID,+ tableId: SAMPLE_DATABASE.REVIEWS_ID,+ fieldId: SAMPLE_DATABASE.REVIEWS.RATING,+ });++ H.DataModel.FieldSection.getDisplayValuesInput().click();+ H.popover().findByText("Custom mapping").click();++ cy.findByDisplayValue("1").clear().type("A");+ cy.findByDisplayValue("2").clear().type("B");+ cy.findByDisplayValue("3").clear().type("C");+ cy.findByDisplayValue("4").clear().type("D");+ cy.findByDisplayValue("5").clear().type("E");++ cy.button("Save").click();++ cy.log("make a model on Reviews");+ H.goToMainApp();+ H.navigationSidebar().findByLabelText("Browse models").click();+ cy.findByLabelText("Create a new model").click();+ cy.findByRole("link", { name: /Use the notebook editor/ }).click();+ H.miniPicker().findByText("Sample Database").click();+ H.miniPicker().findByText("Reviews").click();++ cy.log("Remove Body column");+ cy.findByLabelText("Pick columns").click();+ H.popover().findByText("Body").click();++ cy.log("save model");+ cy.findByTestId("dataset-edit-bar").button("Save").click();++ cy.log("confirm save in a modal");+ H.modal().button("Save").click();++ cy.log("check that the data renders");+ checkTable();++ cy.log("reload to flush cached results and check again");+ cy.findByTestId("qb-header").button("Refresh").click();+ checkTable();+ });+});++describe("issue 12679", () => {+ beforeEach(() => {+ H.restore();+ cy.signInAsAdmin();+ });++ it("removing the first aggregation should not re-target the filter (metabase#12679)", () => {+ const questionDetails = {+ display: "table",+ dataset_query: {+ type: "query",+ database: SAMPLE_DB_ID,+ query: {+ "source-query": {+ "source-table": ORDERS_ID,+ aggregation: [+ ["sum", ["field", ORDERS.SUBTOTAL, null]],+ ["sum", ["field", ORDERS.TAX, null]],+ ["sum", ["field", ORDERS.TOTAL, null]],+ ],+ breakout: [+ ["field", ORDERS.CREATED_AT, { "temporal-unit": "week" }],+ ],+ },+ filter: [">", ["field", "sum_2", { "base-type": "type/Float" }], 100],+ },+ },+ };++ H.visitQuestionAdhoc(questionDetails, { mode: "notebook" });+ H.getNotebookStep("filter", { stage: 1 })+ .findByText("Sum of Tax is greater than 100")+ .should("exist");++ H.getNotebookStep("summarize").within(() => {+ cy.findByText("Sum of Subtotal").parent().icon("close").click();+ cy.findByText("Sum of Subtotal").should("not.exist");+ });+ H.getNotebookStep("filter", { stage: 1 })+ .findByText("Sum of Tax is greater than 100")+ .should("exist");++ H.visualize();++ cy.findByTestId("qb-filters-panel")+ .findByText("Sum of Tax is greater than 100")+ .should("exist");+ cy.findByTestId("table-header").within(() => {+ cy.findByText("Sum of Subtotal").should("not.exist");+ cy.findByText("Sum of Tax").should("exist");+ cy.findByText("Sum of Total").should("exist");+ });+ cy.findByTestId("question-row-count")+ .findByText("Showing 174 rows")+ .should("exist");+ });+});++describe("issue 51856", () => {+ beforeEach(() => {+ H.restore();+ cy.signInAsNormalUser();+ });++ const q1Details = {+ name: "Issue 51856 Q1",+ type: "question",+ query: {+ "source-table": ORDERS_ID,+ joins: [+ {+ fields: "all",+ strategy: "left-join",+ alias: "Products",+ condition: [+ "=",+ [+ "field",+ ORDERS.PRODUCT_ID,+ {+ "base-type": "type/Integer",+ },+ ],+ [+ "field",+ PRODUCTS.ID,+ {+ "base-type": "type/BigInteger",+ "join-alias": "Products",+ },+ ],+ ],+ "source-table": PRODUCTS_ID,+ },+ ],+ },+ };++ const q2Details = {+ name: "Issue 51856 Q2",+ query: {+ "source-table": SAMPLE_DATABASE.REVIEWS_ID,+ joins: [+ {+ fields: "all",+ strategy: "left-join",+ alias: "Products",+ condition: [+ "=",+ [+ "field",+ SAMPLE_DATABASE.REVIEWS.PRODUCT_ID,+ {+ "base-type": "type/Integer",+ },+ ],+ [+ "field",+ PRODUCTS.ID,+ {+ "base-type": "type/BigInteger",+ "join-alias": "Products",+ },+ ],+ ],+ "source-table": PRODUCTS_ID,+ },+ ],+ },+ };++ it("join alias deduplication should not break queries with multiple nesting levels with joins (metabase#51856)", () => {+ H.createQuestion(q1Details, { wrapId: true, idAlias: "q1id" });+ cy.get("@q1id").then((_q1id) => {+ H.createQuestion(q2Details, { wrapId: true, idAlias: "q2id" });+ cy.get("@q2id").then((_q2id) => {+ H.startNewQuestion();++ H.selectSavedQuestionsToJoin(q1Details.name, q2Details.name);+ cy.findByTestId("join-condition-0").findByText(q1Details.name).click();+ H.popover().findByText("Products → Category").click();+ cy.findByTestId("join-condition-0").findByText(q2Details.name).click();+ H.popover().findByText("Issue 51856 Q2 → Category").click();++ H.visualize();++ H.tableInteractiveScrollContainer().scrollTo("right");+ cy.findByTestId("table-header").within(() => {+ cy.findByText("Products → Category").should("exist");+ cy.findByText(+ "Issue 51856 Q2 - Products → Category → Category",+ ).should("exist");+ });+ cy.findByTestId("question-row-count")+ .findByText("Showing first 2,000 rows")+ .should("exist");+ });+ });+ });+});++describe("issue 33972", () => {+ beforeEach(() => {+ H.restore();+ cy.signInAsNormalUser();+ });++ const queryDetails = {+ name: "Issue 33972",+ type: "question",+ query: {+ "source-table": ORDERS_ID,+ fields: [+ ["field", ORDERS.ID, { "base-type": "type/BigInteger" }],+ ["field", ORDERS.PRODUCT_ID, { "base-type": "type/Integer" }],+ ],+ joins: [+ {+ fields: [+ [+ "field",+ PRODUCTS.CATEGORY,+ { "base-type": "type/Text", "join-alias": "Products" },+ ],+ ],+ strategy: "left-join",+ alias: "Products",+ condition: [+ "=",+ [+ "field",+ ORDERS.PRODUCT_ID,+ {+ "base-type": "type/Integer",+ },+ ],+ [+ "field",+ PRODUCTS.ID,+ {+ "base-type": "type/BigInteger",+ "join-alias": "Products",+ },+ ],+ ],+ "source-table": PRODUCTS_ID,+ },+ ],+ },+ };++ it("should be able to distinguish explicitly and implicitly joined fields (metabase#33972)", () => {+ H.createQuestion(queryDetails, { wrapId: true });+ cy.get("@questionId").then((questionId) => {+ H.visitQuestionAdhoc({+ dataset_query: {+ database: SAMPLE_DB_ID,+ query: {+ "source-table": "card__" + questionId,+ },+ type: "query",+ },+ });+ cy.findByTestId("viz-settings-button").click();+ cy.findByTestId("chartsettings-list-container")+ .findByText("Add or remove columns")+ .click();+ cy.findByTestId("product-table-columns").findByText("Category").click();+ cy.findByTestId("product-table-columns").findByText("Ean").click();+ cy.findByTestId("table-header").within(() => {+ cy.findByText("ID").should("exist");+ cy.findByText("Product ID").should("exist");+ cy.findByText("Products → Category").should("exist");+ cy.findByText("Product → Category").should("exist");+ cy.findByText("Product → Ean").should("exist");+ });+ cy.findByTestId("question-row-count")+ .findByText("Showing first 2,000 rows")+ .should("exist");+ });+ });+});++describe("Issue 33835", { tags: "@external" }, () => {+ beforeEach(() => {+ H.restore("postgres-writable");+ cy.signInAsAdmin();++ H.queryWritableDB("DROP TABLE IF EXISTS orders");+ H.queryWritableDB(+ "CREATE TABLE IF NOT EXISTS orders (id INT PRIMARY KEY, total real, discount real)",+ );+ H.queryWritableDB(+ "INSERT INTO orders (id, total, discount) VALUES (1, 100, 20)",+ );++ H.resyncDatabase({ dbId: WRITABLE_DB_ID, tableName: "orders" });++ H.startNewQuestion();+ H.miniPicker().findByText("Writable Postgres12").click();+ H.miniPicker().findByText("Orders").click();++ H.getNotebookStep("summarize")+ .findByText("Pick a function or metric")+ .click();+ H.popover().within(() => {+ cy.findByText(/Average of/).click();+ cy.findByText("Total").click();+ });++ H.getNotebookStep("summarize")+ .findByText("Pick a column to group by")+ .click();+ H.popover().findByText("Discount").click();++ H.saveQuestion("Test Question", {+ wrapId: true,+ questionId: "questionId",+ addToDashboard: false,+ });+ });++ it("should be possible to remove an aggregation on a non-existent column (metabase#33835)", () => {+ H.queryWritableDB("ALTER TABLE orders DROP COLUMN total");+ H.resyncDatabase({ dbId: WRITABLE_DB_ID });++ H.visitQuestion("@questionId");+ H.openNotebook();++ H.getNotebookStep("summarize")+ .findByText("Average of Unknown Field")+ .should("be.visible")+ .icon("close")+ .click();++ H.visualize();+ cy.get("main")+ .findByText("There was a problem with your question")+ .should("not.exist");+ });++ it("should be possible to remove a breakout on a non-existent column (metabase#33835)", () => {+ H.queryWritableDB("ALTER TABLE orders DROP COLUMN discount");+ H.resyncDatabase({ dbId: WRITABLE_DB_ID });++ H.visitQuestion("@questionId");+ H.openNotebook();++ H.getNotebookStep("summarize")+ .findByText("Unknown Field: Auto binned")+ .should("be.visible")+ .icon("close")+ .click();++ H.visualize();+ cy.get("main")+ .findByText("There was a problem with your question")+ .should("not.exist");+ });+});++describe("Issue 42942", () => {+ beforeEach(() => {+ H.restore();+ cy.signInAsAdmin();++ H.visitQuestionAdhoc({+ display: "bar",+ dataset_query: {+ type: "query",+ database: SAMPLE_DB_ID,+ query: {+ "source-table": ORDERS_ID,+ aggregation: [["count"]],+ breakout: [+ [+ "field",+ ORDERS.TOTAL,+ {+ "base-type": "type/Float",+ binning: { strategy: "num-bins", "num-bins": 100 },+ },+ ],+ ],+ },+ },+ });+ });++ it("should adapt the filter widths when changing the filter value (metabase#42942)", () => {+ H.openNotebook();++ H.getNotebookStep("data").findByLabelText("Filter").click();++ H.popover().within(() => {+ cy.findByText("Total").click();+ cy.findByPlaceholderText("Min").type("90");+ cy.button("Add filter").click();+ });+ H.visualize();++ H.chartPathWithFillColor("#509EE3").first().click();+ H.popover().findByText("See these Orders").click();++ cy.log(+ "Filters should be applied correctly with the bin width from the chart",+ );+ H.queryBuilderFiltersPanel().findByText(+ "Total is greater than or equal to 90",+ );+ H.queryBuilderFiltersPanel().findByText("Total is less than 90.75");+ });+});++describe("Issue 48771", () => {+ const MODEL_NAME = "M1";++ beforeEach(() => {+ H.restore();+ cy.signInAsAdmin();++ H.createNativeQuestion({+ name: MODEL_NAME,+ type: "model",+ native: {+ database: SAMPLE_DB_ID,+ query: "SELECT 1 AS ID",+ },+ }).then(({ body: model }) => {+ H.createQuestion(+ {+ type: "question",+ query: {+ filter: [+ ">=",+ [+ "field",+ "count",+ {+ "base-type": "type/Integer",+ },+ ],+ 0.5,+ ],+ "source-query": {+ database: SAMPLE_DB_ID,+ "source-table": ORDERS_ID,+ joins: [+ {+ "source-table": `card__${model.id}`,+ fields: "all",+ alias: MODEL_NAME,+ strategy: "left-join",+ condition: [+ "=",+ ["field", ORDERS.ID, { "base-type": "type/Integer" }],+ [+ "field",+ "ID",+ { "join-alias": MODEL_NAME, "base-type": "type/Integer" },+ ],+ ],+ },+ ],+ aggregation: [["count"]],+ breakout: [["field", ORDERS.CREATED_AT, null]],+ },+ },+ },+ { visitQuestion: true, wrapId: true },+ );+ });++ cy.log("give nosql user access to root collection");+ cy.updateCollectionGraph({+ [USER_GROUPS.NOSQL_GROUP]: { root: "write" },+ });++ cy.signOut();+ cy.signIn("nosql");+ });++ it("should allow to add a filter after summary stage (metabase#48771)", () => {+ H.visitQuestion("@questionId");+ H.openNotebook();++ H.getNotebookStep("filter", { stage: 1 })+ .findByText("Count is greater than or equal to 0.5")+ .click();++ H.popover().within(() => {+ cy.findByPlaceholderText("Enter a number").clear().type("0.7");+ cy.button("Update filter").click();+ });+ H.visualize();+ });+});++describe("Issue 42817", () => {+ const NATIVE_QUESTION_NAME = "NativeOrders";++ beforeEach(() => {+ H.restore();+ cy.signInAsNormalUser();+ H.createNativeQuestion({+ name: NATIVE_QUESTION_NAME,+ database: SAMPLE_DB_ID,+ native: {+ query: "SELECT ID, CREATED_AT FROM orders",+ },+ }).then(({ body: question }) => {+ H.visitQuestionAdhoc({+ display: "line",+ dataset_query: {+ type: "query",+ database: SAMPLE_DB_ID,+ query: {+ "source-table": ORDERS_ID,+ joins: [+ {+ fields: "all",+ alias: NATIVE_QUESTION_NAME,+ "source-table": `card__${question.id}`,+ strategy: "left-join",+ condition: [+ "=",+ [+ "field",+ ORDERS.ID,+ {+ "base-type": "type/BigInteger",+ },+ ],+ [+ "field",+ "ID",+ {+ "base-type": "type/BigInteger",+ "join-alias": NATIVE_QUESTION_NAME,+ },+ ],+ ],+ },+ ],+ aggregation: [["count"]],+ breakout: [+ [+ "field",+ "CREATED_AT",++ {+ "base-type": "type/DateTime",+ "temporal-unit": "day",+ "join-alias": "NativeOrders",+ },+ ],+ ],+ filter: [+ "between",+ [+ "field",+ "CREATED_AT",+ {+ "base-type": "type/Date",+ "inherited-temporal-unit": "day",+ "temporal-unit": "day",+ "join-alias": "NativeOrders",+ },+ ],+ "2023-06-23T00:00Z",+ "2023-07-03T00:00Z",+ ],+ },+ },+ });+ });+ });++ it("should be possible to drill down into a question with datetime buckets and a native join (metabase#42817)", () => {+ H.echartsContainer()+ .get("path[fill='hsla(0, 0%, 100%, 1.00)']")+ .first()+ .click();++ H.popover().findByText("See this day by hour").click();++ cy.findByTestId("query-visualization-root")+ .findByText("There was a problem with your question")+ .should("not.exist");++ H.echartsContainer().should("be.visible");+ });+});