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
Consolidate actions e2e tests (#83533)
Nemanja Glumace617a44838e5
diff --git a/e2e/test/scenarios/actions/actions-in-object-detail-view.cy.spec.js b/e2e/test/scenarios/actions/actions-in-object-detail-view.cy.spec.jsindex 046fe2e27f5..66dd587e50b 100644--- a/e2e/test/scenarios/actions/actions-in-object-detail-view.cy.spec.js+++ b/e2e/test/scenarios/actions/actions-in-object-detail-view.cy.spec.js@@ -6,16 +6,23 @@ const { H } = cy;const WRITABLE_TEST_TABLE = "scoreboard_actions";const FIRST_SCORE_ROW_ID = 11;const SECOND_SCORE_ROW_ID = 12;+const FIRST_SCORE_ROW = {+ id: "11",+ team_name: "Kind Koalas",+ score: "70",+ status: "active",+};+const SECOND_SCORE_ROW = {+ id: "12",+ team_name: "Lively Lemurs",+ score: "80",+ status: "active",+};const UPDATED_SCORE = 987654321;const UPDATED_SCORE_FORMATTED = "987,654,321";const { ALL_USERS_GROUP } = USER_GROUPS;-const DASHBOARD = {- name: "Test dashboard",- database: WRITABLE_DB_ID,-};-describe("scenarios > actions > actions-in-object-detail-view",{ tags: ["@external", "@actions"] },@@ -49,40 +56,6 @@ describe(});});- describe("in dashboard", () => {- beforeEach(() => {- asAdmin(() => {- cy.get("@modelId").then((modelId) => {- H.createImplicitActions({ modelId });-- H.createQuestionAndDashboard({- questionDetails: {- name: "Score detail",- display: "object",- database: WRITABLE_DB_ID,- query: {- "source-table": `card__${modelId}`,- },- },- dashboardDetails: DASHBOARD,- }).then(({ body: { dashboard_id } }) => {- cy.wrap(dashboard_id).as("dashboardId");- });- });- });- });-- it("does not show model actions in model visualization on a dashboard", () => {- asAdmin(() => {- H.visitDashboard("@dashboardId");-- cy.findByTestId("dashcard").within(() => {- assertActionsDropdownNotExists();- });- });- });- });-describe("in modal",// These tests time out frequently in CI on `POST /api/dataset`@@ -107,6 +80,10 @@ describe(`As ${name} user: verify there are no model actions to run`,);visitObjectDetail(modelId, FIRST_SCORE_ROW_ID);+ objectDetailModal()+ .should("be.visible")+ .and("contain.text", FIRST_SCORE_ROW.team_name);+ cy.wait("@getModelActions");objectDetailModal().within(() => {assertActionsDropdownNotExists();});@@ -114,6 +91,20 @@ describe(asAdmin(() => {H.createImplicitActions({ modelId });++ H.createQuestionAndDashboard({+ questionDetails: {+ name: "Score detail",+ display: "object",+ database: WRITABLE_DB_ID,+ query: {+ "source-table": `card__${modelId}`,+ },+ },+ dashboardDetails: { name: "Test dashboard" },+ }).then(({ body: { dashboard_id } }) => {+ cy.wrap(dashboard_id).as("dashboardId");+ });});permissionFn(() => {@@ -139,12 +130,31 @@ describe(openUpdateObjectModal();actionExecuteModal().within(() => {cy.wait("@prefetchValues").then((request) => {- const firstScoreRow = request.response.body;-actionForm().within(() => {- assertScoreFormPrefilled(firstScoreRow);+ assertScoreFormPrefilled(+ FIRST_SCORE_ROW,+ request.response.body,+ );});});++ cy.log(+ `As ${name} user: verify detailed form errors for constraint violations`,+ );+ actionForm().within(() => {+ cy.findByLabelText("Team Name").clear().type("Dusty Ducks");+ cy.findByText("Update").click();+ });++ cy.wait("@executeAction");++ cy.findByLabelText("Team Name").should("exist");+ cy.findByText("This Team_name value already exists.").should(+ "exist",+ );++ cy.findByText("Team_name already exists.").should("exist");+cy.button("Close").click();});objectDetailModal().icon("close").click();@@ -163,10 +173,11 @@ describe(openUpdateObjectModal();actionExecuteModal().within(() => {cy.wait("@prefetchValues").then((request) => {- const secondScoreRow = request.response.body;-actionForm().within(() => {- assertScoreFormPrefilled(secondScoreRow);+ assertScoreFormPrefilled(+ SECOND_SCORE_ROW,+ request.response.body,+ );cy.findByLabelText("Score").clear().type(UPDATED_SCORE);cy.findByText("Update").click();@@ -186,40 +197,23 @@ describe(deleteObjectModal().findByText("Delete forever").click();assertSuccessfullDeleteToast();assertUpdatedScoreNotInTable();++ cy.log(+ `As ${name} user: verify model actions are not shown in an object detail dashcard`,+ );+ H.visitDashboard("@dashboardId");+ H.getDashboardCard().within(() => {+ objectDetailModal()+ .should("be.visible")+ .and("contain.text", "Amorous Aardvarks");+ assertActionsDropdownNotExists();+ });});});});});},);-- it("should show detailed form errors for constraint violations when executing model actions", () => {- const actionName = "Update";-- cy.signInAsAdmin();-- cy.get("@modelId").then((modelId) => {- H.createImplicitActions({ modelId });- visitObjectDetail(modelId, FIRST_SCORE_ROW_ID);- openUpdateObjectModal();- });-- actionExecuteModal().within(() => {- cy.wait("@prefetchValues");-- actionForm().within(() => {- cy.findByLabelText("Team Name").clear().type("Dusty Ducks");- cy.findByText(actionName).click();- });-- cy.wait("@executeAction");-- cy.findByLabelText("Team Name").should("exist");- cy.findByText("This Team_name value already exists.").should("exist");-- cy.findByText("Team_name already exists.").should("exist");- });- });},);@@ -265,13 +259,13 @@ function assertActionsDropdownNotExists() {cy.findByTestId("actions-menu").should("not.exist");}-function assertScoreFormPrefilled(object) {- assertInputValue("ID", object.id);- assertInputValue("Team Name", object.team_name);- assertInputValue("Score", object.score);- assertInputValue("Status", object.status);- assertDateInputValue("Created At", object.created_at);- assertDateInputValue("Updated At", object.updated_at);+function assertScoreFormPrefilled(expected, prefetchedRow) {+ assertInputValue("ID", expected.id);+ assertInputValue("Team Name", expected.team_name);+ assertInputValue("Score", expected.score);+ assertInputValue("Status", expected.status);+ assertDateInputValue("Created At", prefetchedRow.created_at);+ assertDateInputValue("Updated At", prefetchedRow.updated_at);}function assertInputValue(labelText, value) {diff --git a/e2e/test/scenarios/actions/actions-on-dashboards.cy.spec.js b/e2e/test/scenarios/actions/actions-on-dashboards.cy.spec.jsindex 2f549a96057..b6d6ea557cf 100644--- a/e2e/test/scenarios/actions/actions-on-dashboards.cy.spec.js+++ b/e2e/test/scenarios/actions/actions-on-dashboards.cy.spec.js@@ -2,6 +2,7 @@ import { assocIn } from "icepick";const { H } = cy;import { WRITABLE_DB_ID } from "e2e/support/cypress_data";+import { ORDERS_QUESTION_ID } from "e2e/support/cypress_sample_instance_data";import { many_data_types_rows } from "e2e/support/test_tables_data";import { createMockActionParameter } from "metabase-types/api/mocks";@@ -49,7 +50,17 @@ const MODEL_NAME = "Test Action Model";H.expectNoBadSnowplowEvents();});- it("action creation modal can be closed on click outside (WRK-67)", () => {+ it("adds a custom query action with a hidden optional field to a dashboard and runs it", () => {+ const ACTION_NAME = "Update Score";++ H.queryWritableDB(+ `SELECT * FROM ${TEST_TABLE} WHERE id = 1`,+ dialect,+ ).then((result) => {+ expect(result.rows.length).to.equal(1);+ expect(result.rows[0].score).to.equal(0);+ });+cy.get("@modelId").then((id) => {cy.visit(`/model/${id}/detail`);cy.wait(["@getModel", "@getModelActions"]);@@ -58,42 +69,23 @@ const MODEL_NAME = "Test Action Model";const newActionBtn = () =>cy.findByTestId("model-actions-header").findByText("New action");- // click outside+ cy.log("action creation modal closes on click outside (WRK-67)");newActionBtn().click();cy.findByTestId("action-creator").should("be.visible");cy.get("body").click("topLeft");cy.findByTestId("action-creator").should("not.exist");- // ESC button+ cy.log("action creation modal closes on Escape (WRK-67)");newActionBtn().click();cy.findByTestId("action-creator").should("be.visible");cy.get("body").type("{esc}");cy.findByTestId("action-creator").should("not.exist");- });-- it("adds a custom query action to a dashboard and runs it", () => {- const ACTION_NAME = "Update Score";-- H.queryWritableDB(- `SELECT * FROM ${TEST_TABLE} WHERE id = 1`,- dialect,- ).then((result) => {- expect(result.rows.length).to.equal(1);- expect(result.rows[0].score).to.equal(0);- });-- cy.get("@modelId").then((id) => {- cy.visit(`/model/${id}/detail`);- cy.wait(["@getModel", "@getModelActions"]);- });- cy.findByTestId("model-actions-header")- .findByText("New action")- .click();+ newActionBtn().click();cy.findByRole("dialog").within(() => {H.fillActionQuery(- `UPDATE ${TEST_TABLE} SET score = {{ new_score }} WHERE id = {{ id }}`,+ `UPDATE ${TEST_TABLE} SET score = {{ new_score }} WHERE id = {{ id }} [[ and status = {{ current_status }}]]`,);});@@ -107,6 +99,21 @@ const MODEL_NAME = "Test Action Model";cy.findAllByText("Number").each((el) => {cy.wrap(el).click();});++ // hide optional field+ formFieldContainer("Current Status").within(() => {+ cy.findByText("Text").click();++ toggleFieldVisibility();+ openFieldSettings();+ });+ });++ H.popover().within(() => {+ cy.findByLabelText("Required").uncheck({ force: true });+ });++ H.modal().within(() => {cy.findByText("Save").click();});@@ -127,7 +134,9 @@ const MODEL_NAME = "Test Action Model";cy.findByRole("button", { name: "Update Score" }).click();cy.findByRole("dialog").within(() => {- cy.findByLabelText("New Score").type("55");+ cy.findByLabelText("New Score").should("be.visible").type("55");+ // it's hidden+ cy.findByLabelText("Current Status").should("not.exist");cy.button(ACTION_NAME).click();});@@ -140,9 +149,68 @@ const MODEL_NAME = "Test Action Model";expect(result.rows.length).to.equal(1);expect(result.rows[0].score).to.equal(55);});++ cy.log("show the field and make it required from the model page");+ cy.get("@modelId").then((id) => {+ cy.visit(`/model/${id}/detail`);+ cy.wait(["@getModel", "@getModelActions"]);+ });++ cy.get("[aria-label='Update Score']").within(() => {+ cy.icon("ellipsis").click();+ });++ H.popover().within(() => {+ cy.findByText("Edit").click();+ });++ cy.findByRole("dialog").within(() => {+ formFieldContainer("Current Status").within(() => {+ toggleFieldVisibility();++ openFieldSettings();+ });+ });++ H.popover().within(() => {+ cy.findByLabelText("Required").check({ force: true });+ });++ H.modal().within(() => {+ cy.findByText("Update").click();+ });++ cy.wait("@updateAction");+ // The action editor closes after the update; wait until it is gone+ // before navigating to the dashboard.+ cy.findByTestId("action-creator").should("not.exist");++ cy.get("@dashboardId").then((id) => {+ cy.visit(`/dashboard/${id}?id=1`);+ });+ H.filterWidget().should("contain.text", "1");++ cy.findByRole("button", { name: "Update Score" }).click();++ cy.findByRole("dialog").within(() => {+ cy.findByLabelText("New Score").type("56");+ cy.findByLabelText("Current Status").type("active");++ cy.button(ACTION_NAME).click();+ });++ cy.wait("@executeAction");++ H.queryWritableDB(+ `SELECT * FROM ${TEST_TABLE} WHERE id = 1`,+ dialect,+ ).then((result) => {+ expect(result.rows.length).to.equal(1);+ expect(result.rows[0].score).to.equal(56);+ });});- it("adds an implicit create action to a dashboard and runs it", () => {+ it("adds an implicit create action with a hidden field to a dashboard and runs it", () => {cy.get("@modelId").then((id) => {H.createImplicitAction({kind: "create",@@ -152,6 +220,7 @@ const MODEL_NAME = "Test Action Model";createDashboardWithActionButton({actionName: "Create",+ hideField: "Created At",});H.expectUnstructuredSnowplowEvent({@@ -163,6 +232,7 @@ const MODEL_NAME = "Test Action Model";H.modal().within(() => {cy.findByPlaceholderText("Team Name").type("Zany Zebras");cy.findByPlaceholderText("Score").type("44");+ cy.findByPlaceholderText("Created At").should("not.exist");cy.button("Save").click();});@@ -179,7 +249,7 @@ const MODEL_NAME = "Test Action Model";});});- it("adds an implicit update action to a dashboard and runs it", () => {+ it("adds implicit update and delete actions to dashboards and runs them", () => {const actionName = "Update";cy.get("@modelId").then((id) => {@@ -229,9 +299,8 @@ const MODEL_NAME = "Test Action Model";expect(result.rows[0].score).to.equal(88);});- });- it("adds an implicit delete action to a dashboard and runs it", () => {+ cy.log("delete a row via an implicit delete action");H.queryWritableDB(`SELECT * FROM ${TEST_TABLE} WHERE team_name = 'Cuddly Cats'`,dialect,@@ -251,9 +320,12 @@ const MODEL_NAME = "Test Action Model";actionName: "Delete",});- H.expectUnstructuredSnowplowEvent({- event: "new_action_card_created",- });+ H.expectUnstructuredSnowplowEvent(+ {+ event: "new_action_card_created",+ },+ 2,+ );cy.findByRole("button", { name: "Delete" }).click();@@ -272,66 +344,27 @@ const MODEL_NAME = "Test Action Model";});});- it("hide actions in public dashboards (metabase#34395)", () => {+ it("hides actions in public and static embed dashboards (metabase#34395)", () => {const dashboardDetails = {- name: "Public Dashboard",+ name: "Actions Dashboard",};- cy.get("@modelId")- .then((id) => {- H.createImplicitAction({- kind: "create",- model_id: id,- });- })- .then(({ body: action }) => {- H.createDashboard(dashboardDetails).then(- ({ body: dashboard }) => {- H.updateDashboardCards({- dashboard_id: dashboard.id,- cards: [- H.getActionCardDetails({- action_id: action.id,- label: "Create",- }),- ],- });- cy.visit(`/dashboard/${dashboard.id}`);- cy.wrap(dashboard.id).as("dashboardId");- },- );- });-- cy.log("The action should be visible in the dashboard");- cy.findByRole("button", { name: "Create" }).should("be.visible");-- cy.log("Visit public dashboard");- cy.get("@dashboardId")- .then((dashboardId) => {- H.createPublicDashboardLink(dashboardId);- })- .then(({ body: { uuid } }) => {- cy.visit(`/public/dashboard/${uuid}`);- });-- cy.log("Assert public dashboard");- cy.findByRole("heading", { name: dashboardDetails.name }).should(- "be.visible",- );- /**- * cy.button("Create") doesn't work because the label is- * `Actions are not enabled for this database` for disabled actions- */- cy.findByRole("main").findByText("Create").should("not.exist");- cy.findByRole("link", { name: "Powered by Metabase" }).should(- "be.visible",- );- });- it("hide actions in static embed dashboards (metabase#34395)", () => {- const dashboardDetails = {- name: "Public Dashboard",- enable_embedding: true,+ const assertActionsHidden = () => {+ cy.findByRole("heading", { name: dashboardDetails.name }).should(+ "be.visible",+ );+ H.getDashboardCards().should("have.length", 1);+ H.getDashboardCard(0).findByText("Orders").should("be.visible");+ /**+ * cy.button("Create") doesn't work because the label is+ * `Actions are not enabled for this database` for disabled actions+ */+ cy.findByRole("main").findByText("Create").should("not.exist");+ cy.findByRole("link", { name: "Powered by Metabase" }).should(+ "be.visible",+ );};+cy.get("@modelId").then((id) => {H.createImplicitAction({@@ -349,18 +382,32 @@ const MODEL_NAME = "Test Action Model";action_id: action.id,label: "Create",}),+ {+ id: H.getNextUnsavedDashboardCardId(),+ card_id: ORDERS_QUESTION_ID,+ col: 4,+ row: 0,+ size_x: 11,+ size_y: 8,+ },],});++ H.createPublicDashboardLink(dashboard.id).then(+ ({ body: { uuid } }) => {+ cy.wrap(uuid).as("publicUuid");+ },+ );+cy.visit(`/dashboard/${dashboard.id}`);- cy.wrap(dashboard.id).as("dashboardId");cy.log("The action should be visible in the dashboard");cy.findByRole("button", { name: "Create" }).should("be.visible",);+ H.getDashboardCards().should("have.length", 2);cy.log("Visit static embed dashboard");-H.openLegacyStaticEmbeddingModal({resource: "dashboard",resourceId: dashboard.id,@@ -374,194 +421,13 @@ const MODEL_NAME = "Test Action Model";H.visitIframe();cy.log("Assert static embed dashboard");- cy.findByRole("heading", {- name: dashboardDetails.name,- }).should("be.visible");- /**- * cy.button("Create") doesn't work because the label is- * `Actions are not enabled for this database` for disabled actions- */- cy.findByRole("main").findByText("Create").should("not.exist");- cy.findByRole("link", { name: "Powered by Metabase" }).should(- "be.visible",- );- });-- describe("hidden fields", () => {- it("adds an implicit action and runs it", () => {- cy.get("@modelId").then((id) => {- H.createImplicitAction({- kind: "create",- model_id: id,- });- });-- createDashboardWithActionButton({- actionName: "Create",- hideField: "Created At",- });-- cy.findByRole("button", { name: "Create" }).click();-- H.modal().within(() => {- cy.findByPlaceholderText("Team Name").type("Zany Zebras");- cy.findByPlaceholderText("Score").type("44");- cy.findByPlaceholderText("Created At").should("not.exist");-- cy.button("Save").click();- });-- cy.wait("@executeAction");-- H.queryWritableDB(- `SELECT * FROM ${TEST_TABLE} WHERE team_name = 'Zany Zebras'`,- dialect,- ).then((result) => {- expect(result.rows.length).to.equal(1);+ assertActionsHidden();- expect(result.rows[0].score).to.equal(44);- });- });-- it("adds a query action and runs it", () => {- const ACTION_NAME = "Update Score";-- H.queryWritableDB(- `SELECT * FROM ${TEST_TABLE} WHERE id = 1`,- dialect,- ).then((result) => {- expect(result.rows.length).to.equal(1);- expect(result.rows[0].score).to.equal(0);- });-- cy.get("@modelId").then((id) => {- cy.visit(`/model/${id}/detail`);- cy.wait(["@getModel", "@getModelActions"]);- });-- cy.findByTestId("model-actions-header")- .findByText("New action")- .click();-- cy.findByRole("dialog").within(() => {- H.fillActionQuery(- `UPDATE ${TEST_TABLE} SET score = {{ new_score }} WHERE id = {{ id }} [[ and status = {{ current_status }}]]`,- );- });-- H.moveDnDKitListElement("drag-handle", {- startIndex: 1,- dropIndex: 0,- });-- cy.findByRole("dialog").within(() => {- cy.findAllByText("Number").each((el) => {- cy.wrap(el).click();- });-- // hide optional field- formFieldContainer("Current Status").within(() => {- cy.findByText("Text").click();-- toggleFieldVisibility();- openFieldSettings();- });- });-- H.popover().within(() => {- cy.findByLabelText("Required").uncheck({ force: true });- });-- H.modal().within(() => {- cy.findByText("Save").click();- });-- cy.findByPlaceholderText("My new fantastic action").type(- ACTION_NAME,- );- cy.findByTestId("create-action-form").button("Create").click();-- createDashboardWithActionButton({- actionName: ACTION_NAME,- });-- cy.findByRole("button", { name: "Update Score" }).click();-- cy.findByRole("dialog").within(() => {- cy.findByLabelText("ID").type("1");- cy.findByLabelText("New Score").type("55");- // it's hidden- cy.findByLabelText("Current Status").should("not.exist");-- cy.button(ACTION_NAME).click();- });-- cy.wait("@executeAction");-- H.queryWritableDB(- `SELECT * FROM ${TEST_TABLE} WHERE id = 1`,- dialect,- ).then((result) => {- expect(result.rows.length).to.equal(1);- expect(result.rows[0].score).to.equal(55);- });-- cy.get("@modelId").then((id) => {- cy.visit(`/model/${id}/detail`);- cy.wait(["@getModel", "@getModelActions"]);- });-- cy.get("[aria-label='Update Score']").within(() => {- cy.icon("ellipsis").click();- });-- H.popover().within(() => {- cy.findByText("Edit").click();- });-- cy.findByRole("dialog").within(() => {- formFieldContainer("Current Status").within(() => {- toggleFieldVisibility();-- openFieldSettings();- });- });-- H.popover().within(() => {- cy.findByLabelText("Required").check({ force: true });- });-- H.modal().within(() => {- cy.findByText("Update").click();- });-- cy.wait("@updateAction");- // The action editor closes after the update; wait until it is gone- // before navigating to the dashboard.- cy.findByTestId("action-creator").should("not.exist");-- H.visitDashboard("@dashboardId");-- cy.findByRole("button", { name: "Update Score" }).click();-- cy.findByRole("dialog").within(() => {- cy.findByLabelText("ID").type("1");- cy.findByLabelText("New Score").type("56");- cy.findByLabelText("Current Status").type("active");-- cy.button(ACTION_NAME).click();- });-- cy.wait("@executeAction");-- H.queryWritableDB(- `SELECT * FROM ${TEST_TABLE} WHERE id = 1`,- dialect,- ).then((result) => {- expect(result.rows.length).to.equal(1);- expect(result.rows[0].score).to.equal(56);- });+ cy.log("Assert public dashboard");+ cy.get("@publicUuid").then((uuid) => {+ cy.visit(`/public/dashboard/${uuid}`);});+ assertActionsHidden();});});@@ -580,110 +446,7 @@ const MODEL_NAME = "Test Action Model";});});- it("can update various data types via implicit actions", () => {- cy.get("@modelId").then((id) => {- H.createImplicitAction({- kind: "update",- model_id: id,- });- });-- createDashboardWithActionButton({- actionName: "Update",- idFilter: true,- });-- cy.wait("@getModel");- cy.findByRole("button", { name: "Update" });-- H.filterWidget().click();- addWidgetStringFilter("1");-- cy.findByRole("button", { name: "Update" }).click();-- cy.wait("@prefetchValues");-- const oldRow = many_data_types_rows[0];-- H.modal()- .first()- .within(() => {- changeValue({- fieldName: "UUID",- fieldType: "text",- oldValue: oldRow.uuid,- newValue: "a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a77",- });-- changeValue({- fieldName: "Integer",- fieldType: "text",- oldValue: oldRow.integer,- newValue: 123,- });-- changeValue({- fieldName: "Float",- fieldType: "text",- oldValue: oldRow.float,- newValue: 2.2,- });-- cy.findByLabelText("Boolean")- .should("be.checked")- .click({ force: true });-- changeValue({- fieldName: "String",- fieldType: "text",- oldValue: oldRow.string,- newValue: "new string",- });-- changeValue({- fieldName: "Date",- fieldType: "date",- oldValue: oldRow.date,- newValue: "2020-05-01",- });-- // we can't assert on this value because mysql and postgres seem to- // handle timezones differently 🥴- cy.findByPlaceholderText("TimestampTZ")- .should("have.attr", "type", "datetime-local")- .clear()- .type("2020-05-01T16:45:00");-- cy.button("Update").click();- });-- cy.wait("@executeAction");-- H.queryWritableDB(- `SELECT * FROM ${TEST_COLUMNS_TABLE} WHERE id = 1`,- dialect,- ).then((result) => {- expect(result.rows.length).to.equal(1);-- const row = result.rows[0];-- expect(row).to.have.property(- "uuid",- "a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a77",- );- expect(row).to.have.property("integer", 123);- expect(row).to.have.property("float", 2.2);- expect(row).to.have.property("string", "new string");- expect(row).to.have.property(- "boolean",- dialect === "mysql" ? 0 : false,- );- expect(row.date).to.include("2020-05-01"); // js converts this to a full date obj- expect(row.timestampTZ).to.include("2020-05-01"); // we got timezone issues here- });- });-- it("can insert various data types via implicit actions", () => {+ it("inserts and updates various data types, including date and time fields, via implicit actions, showing enum but not JSON or binary columns", () => {cy.get("@modelId").then((id) => {H.createImplicitAction({kind: "create",@@ -698,6 +461,12 @@ const MODEL_NAME = "Test Action Model";cy.findByRole("button", { name: "Create" }).click();H.modal().within(() => {+ cy.findByPlaceholderText("UUID").should("be.visible");+ cy.findByPlaceholderText("JSON").should("not.exist");+ cy.findByPlaceholderText("JSONB").should("not.exist");+ cy.findByPlaceholderText("Binary").should("not.exist");+ cy.findByPlaceholderText("Enum").should("exist");+cy.findByPlaceholderText("UUID").type("a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a15",);@@ -770,33 +539,8 @@ const MODEL_NAME = "Test Action Model";expect(row.timestamp).to.include("2020-03-01");expect(row.timestampTZ).to.include("2020-03-01");});- });- it("does not show json, enum, or binary columns for implicit actions", () => {- cy.get("@modelId").then((id) => {- H.createImplicitAction({- kind: "create",- model_id: id,- });- });-- createDashboardWithActionButton({- actionName: "Create",- idFilter: true,- });-- cy.findByRole("button", { name: "Create" }).click();-- H.modal().within(() => {- cy.findByPlaceholderText("UUID").should("be.visible");- cy.findByPlaceholderText("JSON").should("not.exist");- cy.findByPlaceholderText("JSONB").should("not.exist");- cy.findByPlaceholderText("Binary").should("not.exist");- cy.findByPlaceholderText("Enum").should("exist");- });- });-- it("properly loads and updates date and time fields for implicit update actions", () => {+ cy.log("update row 1 via an implicit update action");cy.get("@modelId").then((id) => {H.createImplicitAction({kind: "update",@@ -809,7 +553,6 @@ const MODEL_NAME = "Test Action Model";idFilter: true,});- cy.wait("@getModel");cy.findByRole("button", { name: "Update" });H.filterWidget().click();@@ -825,6 +568,38 @@ const MODEL_NAME = "Test Action Model";H.modal().first().within(() => {+ changeValue({+ fieldName: "UUID",+ fieldType: "text",+ oldValue: oldRow.uuid,+ newValue: "a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a77",+ });++ changeValue({+ fieldName: "Integer",+ fieldType: "text",+ oldValue: oldRow.integer,+ newValue: 123,+ });++ changeValue({+ fieldName: "Float",+ fieldType: "text",+ oldValue: oldRow.float,+ newValue: 2.2,+ });++ cy.findByLabelText("Boolean")+ .should("be.checked")+ .click({ force: true });++ changeValue({+ fieldName: "String",+ fieldType: "text",+ oldValue: oldRow.string,+ newValue: "new string",+ });+changeValue({fieldName: "Date",fieldType: "date",@@ -876,8 +651,22 @@ const MODEL_NAME = "Test Action Model";`SELECT * FROM ${TEST_COLUMNS_TABLE} WHERE id = 1`,dialect,).then((result) => {+ expect(result.rows.length).to.equal(1);+const row = result.rows[0];+ expect(row).to.have.property(+ "uuid",+ "a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a77",+ );+ expect(row).to.have.property("integer", 123);+ expect(row).to.have.property("float", 2.2);+ expect(row).to.have.property("string", "new string");+ expect(row).to.have.property(+ "boolean",+ dialect === "mysql" ? 0 : false,+ );+// the driver adds a time to this date so we have to use .includeexpect(row.date).to.include(newTime.slice(0, 10));expect(row.time).to.equal(newTime.slice(-8));@@ -893,7 +682,6 @@ const MODEL_NAME = "Test Action Model";});describe("editing action before executing it", () => {- const PG_DB_ID = 2;const WRITABLE_TEST_TABLE = "scoreboard_actions";const TEST_PARAMETER = createMockActionParameter({@@ -916,7 +704,7 @@ const MODEL_NAME = "Test Action Model";name: "Demo Action",type: "query",parameters: [TEST_PARAMETER],- database_id: PG_DB_ID,+ database_id: WRITABLE_DB_ID,dataset_query: {type: "native",native: {@@ -925,7 +713,7 @@ const MODEL_NAME = "Test Action Model";[TEST_TEMPLATE_TAG.name]: TEST_TEMPLATE_TAG,},},- database: PG_DB_ID,+ database: WRITABLE_DB_ID,},visualization_settings: {fields: {@@ -970,7 +758,7 @@ const MODEL_NAME = "Test Action Model";});});- it("allows to edit action title and field placeholder in action execute modal", () => {+ it("allows to edit action title, field placeholder, query and parameters in action execute modal", () => {clickHelper(SAMPLE_QUERY_ACTION.name);getActionParametersInputModal().within(() => {@@ -1003,13 +791,7 @@ const MODEL_NAME = "Test Action Model";cy.findByTestId("modal-header").findByText("New action name");cy.findAllByPlaceholderText("Test placeholder");- });- });- it("allows to edit action query and parameters in action execute modal", () => {- clickHelper(SAMPLE_QUERY_ACTION.name);-- getActionParametersInputModal().within(() => {cy.icon("pencil").click();});@@ -1047,24 +829,26 @@ const MODEL_NAME = "Test Action Model";cy.findByTestId("action-editor-modal").should("not.exist");getActionParametersInputModal().within(() => {- cy.findByLabelText("Timestamp").type("2020-01-01");+ cy.findByLabelText("Timestamp").type("2020-02-02");cy.findByLabelText("ID").type("1");- cy.button(SAMPLE_QUERY_ACTION.name).click();+ cy.button("New action name").click();});- cy.wait("@executeAction").then((interception) => {- expect(- Object.values(interception.request.body.parameters)- .sort()- .join(","),- ).to.equal("1,2020-01-01");- });+ cy.wait("@executeAction");cy.findByTestId("toast-undo").within(() => {- cy.findByText(- `${SAMPLE_WRITABLE_QUERY_ACTION.name} ran successfully`,- ).should("be.visible");+ cy.findByText("New action name ran successfully").should(+ "be.visible",+ );+ });++ H.queryWritableDB(+ `SELECT * FROM ${TEST_COLUMNS_TABLE} WHERE id = 1`,+ dialect,+ ).then((result) => {+ expect(result.rows.length).to.equal(1);+ expect(result.rows[0].timestamp).to.include("2020-02-02");});});});@@ -1072,60 +856,6 @@ const MODEL_NAME = "Test Action Model";);});-describe("action error handling", { tags: ["@external", "@actions"] }, () => {- beforeEach(() => {- H.restore("postgres-writable");- H.resetTestTable({ type: "postgres", table: TEST_TABLE });- cy.signInAsAdmin();- H.resyncDatabase({ dbId: WRITABLE_DB_ID, tableName: TEST_TABLE });- H.createModelFromTableName({- tableName: TEST_TABLE,- modelName: MODEL_NAME,- });-- cy.intercept("GET", "/api/action").as("getActions");- cy.intercept("GET", /\/api\/card\/\d+/).as("getModel");- cy.intercept("POST", "/api/dashboard/*/dashcard/*/execute/values").as(- "prefetchValues",- );- cy.intercept("POST", "/api/dashboard/*/dashcard/*/execute").as(- "executeAction",- );- });-- it("should show detailed form errors for constraint violations when executing model actions", () => {- const actionName = "Update";-- cy.get("@modelId").then((modelId) => {- H.createImplicitAction({ kind: "update", model_id: modelId });- });-- createDashboardWithActionButton({ actionName, idFilter: true });-- cy.wait("@getModel");- cy.findByRole("button", { name: "Update" });-- H.filterWidget().click();- addWidgetStringFilter("5");- cy.button(actionName).click();-- cy.wait("@prefetchValues");-- H.modal()- .first()- .within(() => {- cy.findByLabelText("Team Name").clear().type("Kind Koalas");- cy.button(actionName).click();- cy.wait("@executeAction");-- cy.findByLabelText("Team Name").should("exist");- cy.findByText("This Team_name value already exists.").should("exist");-- cy.findByText("Team_name already exists.").should("exist");- });- });-});-describe("Action Parameters Mapping",{ tags: ["@external", "@actions"] },@@ -1139,6 +869,9 @@ describe(cy.intercept("POST", "/api/dashboard/*/dashcard/*/execute/values").as("executePrefetch",);+ cy.intercept("POST", "/api/dashboard/*/dashcard/*/execute").as(+ "executeAction",+ );});describe("Inline action edit", () => {@@ -1153,7 +886,7 @@ describe(});});- it("refetches form values when id changes (metabase#33084)", () => {+ it("refetches form values when id changes and shows constraint violation errors (metabase#33084)", () => {const actionName = "Update";cy.get("@modelId").then((id) => {@@ -1201,6 +934,19 @@ describe("Jolly Jellyfish",);cy.findByPlaceholderText("Score").should("have.value", "60");++ cy.log("shows constraint violation errors from the database");+ cy.findByPlaceholderText("Team Name").clear().type("Kind Koalas");+ cy.button(actionName).click();+ });++ cy.wait("@executeAction");++ H.modal().within(() => {+ cy.findByLabelText("Team Name").should("exist");+ cy.findByText("This Team_name value already exists.").should("exist");++ cy.findByText("Team_name already exists.").should("exist");});});@@ -1288,7 +1034,6 @@ describe(function createDashboardWithActionButton({actionName,- modelName = MODEL_NAME,idFilter = false,hideField,}) {@@ -1317,7 +1062,7 @@ function createDashboardWithActionButton({waitForValidActions();cy.findByRole("dialog").within(() => {- cy.findByText(modelName).click();+ cy.findByText(MODEL_NAME).click();cy.findByText(actionName).click();});@@ -1345,8 +1090,8 @@ function createDashboardWithActionButton({if (idFilter) {cy.findByRole("dialog").within(() => {+ cy.findByText(/Where should the values/i).should("be.visible");cy.findByText(/has no parameters to map/i).should("not.exist");- cy.findByText(/Where should the values/i);cy.findAllByDisplayValue(/ask the user/i).first().click();diff --git a/e2e/test/scenarios/actions/actions-reproductions.cy.spec.js b/e2e/test/scenarios/actions/actions-reproductions.cy.spec.jsindex 5d94fdae45c..3c5ca67f00c 100644--- a/e2e/test/scenarios/actions/actions-reproductions.cy.spec.js+++ b/e2e/test/scenarios/actions/actions-reproductions.cy.spec.js@@ -5,7 +5,7 @@ import {WRITABLE_DB_ID,} from "e2e/support/cypress_data";import { SAMPLE_DATABASE } from "e2e/support/cypress_sample_database";-import { ORDERS_DASHBOARD_ID } from "e2e/support/cypress_sample_instance_data";+import { ORDERS_QUESTION_ID } from "e2e/support/cypress_sample_instance_data";import {createMockActionParameter,createMockParameter,@@ -20,48 +20,40 @@ const viewports = [];describe("metabase#31587", () => {- viewports.forEach(([width, height]) => {- describe(`Testing on resolution ${width} x ${height}`, () => {- beforeEach(() => {- H.restore();- cy.signInAsAdmin();- H.setActionsEnabledForDB(SAMPLE_DB_ID);- cy.viewport(width, height);- });+ beforeEach(() => {+ H.restore();+ cy.signInAsAdmin();+ H.setActionsEnabledForDB(SAMPLE_DB_ID);+ });- it("should not allow action buttons to overflow when editing dashboard", () => {- H.visitDashboard(ORDERS_DASHBOARD_ID);- H.editDashboard();- cy.button("Add action").click();-- cy.findByTestId("dashboard-parameters-and-cards").within(() => {- actionButtonContainer().then((actionButtonElem) => {- dashCard().then((dashCardElem) => {- expect(actionButtonElem[0].scrollHeight).to.eq(- dashCardElem[0].scrollHeight,- );- });+ it("should not allow action buttons to overflow when editing dashboard or viewing info sidebar (metabase#31587)", () => {+ viewports.forEach(([width, height]) => {+ cy.log(`Resolution ${width} x ${height}`);+ cy.viewport(width, height);++ H.createDashboard({ name: `Orders ${width} x ${height}` }).then(+ ({ body: { id: dashboardId } }) => {+ H.addOrUpdateDashboardCard({+ card_id: ORDERS_QUESTION_ID,+ dashboard_id: dashboardId,+ card: { size_x: 16, size_y: 8 },});- });+ H.visitDashboard(dashboardId);+ },+ );++ H.editDashboard();+ cy.findByLabelText("Add action").click();++ cy.findByTestId("dashboard-parameters-and-cards").within(() => {+ assertActionButtonFitsDashcard();});- it("should not allow action buttons to overflow when viewing info sidebar", () => {- H.visitDashboard(ORDERS_DASHBOARD_ID);- H.editDashboard();- cy.findByLabelText("Add action").click();-- H.saveDashboard();- cy.icon("info").click();-- cy.findByTestId("dashboard-parameters-and-cards").within(() => {- actionButtonContainer().then((actionButtonElem) => {- dashCard().then((dashCardElem) => {- expect(actionButtonElem[0].scrollHeight).to.eq(- dashCardElem[0].scrollHeight,- );- });- });- });+ H.saveDashboard();+ cy.icon("info").click();++ cy.findByTestId("dashboard-parameters-and-cards").within(() => {+ assertActionButtonFitsDashcard();});});});@@ -159,8 +151,6 @@ describe("Issue 32974", { tags: ["@external", "@actions"] }, () => {);cy.get("@modelId").then((modelId) => {- H.createImplicitActions({ modelId });-H.createAction({ ...QUERY_ACTION, model_id: modelId }).then(({ body: { id: actionId } }) => {cy.wrap(actionId).as("actionId");@@ -175,7 +165,7 @@ describe("Issue 32974", { tags: ["@external", "@actions"] }, () => {{id: H.getNextUnsavedDashboardCardId(),card_id: modelId,- // Map dashboard parameter to PRODUCTS.ID+ // Map dashboard parameter to scoreboard_actions.idparameter_mappings: [{parameter_id: ID_DASHBOARD_PARAMETER.id,@@ -208,10 +198,6 @@ describe("Issue 32974", { tags: ["@external", "@actions"] }, () => {}beforeEach(() => {- cy.intercept("GET", "/api/action?model-id=*").as("getModelActions");- cy.intercept("POST", "/api/action/*/execute").as("executeAction");- cy.intercept("POST", "/api/action/*/execute/values").as("prefetchValues");-H.restore("postgres-writable");H.resetTestTable({ type: "postgres", table: TEST_TABLE });@@ -272,7 +258,7 @@ describe("issue 51020", () => {H.saveDashboard();}- describe("when primary key is called 'id'", () => {+ describe("when primary key is called 'id'", { tags: "@external" }, () => {function createTemporaryTable() {H.queryWritableDB("CREATE TABLE IF NOT EXISTS foo (id INT PRIMARY KEY, name VARCHAR)",@@ -494,7 +480,22 @@ describe("issue 32840", () => {cy.button("Update").scrollIntoView().click();});cy.wait("@executeAction");+ H.undoToast().findByText("Successfully updated").should("be.visible");H.modal().findByText("July 19, 2026, 7:44 PM").should("be.visible");++ cy.log("the stored timestamp is unchanged after reopening the row");+ cy.findByTestId("object-detail").icon("close").click();+ cy.findByTestId("object-detail").should("not.exist");+ cy.findAllByTestId("cell-data").eq(8).click();+ H.modal().within(() => {+ cy.findByText("July 19, 2026, 7:44 PM").should("be.visible");+ cy.findByTestId("actions-menu").click();+ });+ H.popover().findByText("Update").should("be.visible").click();+ H.modal()+ .eq(1)+ .findByPlaceholderText("Created At")+ .should("have.value", "2026-07-19T19:44:56");});});@@ -506,12 +507,27 @@ describe("issue 32750", () => {cy.visit("/");});- it("modal do not dissapear on viewport change", () => {+ it("action creator keeps its query and template tag parameters across viewport changes (metabase#32750)", () => {H.startNewAction();++ cy.log("only variable template tags become parameters");+ H.fillActionQuery("{{#1-orders-model}}");+ H.fillActionQuery("{{snippet:101}}");+ H.fillActionQuery("{{id}}");+ cy.findByLabelText("ID").should("be.visible");+ cy.findByLabelText("#1 Orders Model").should("not.exist");+ cy.findByLabelText("Snippet:101").should("not.exist");+ cy.findAllByTestId("form-field-container").should("have.length", 1);+cy.viewport(320, 800);cy.findByTestId("action-creator").should("be.visible");+ H.NativeEditor.get().should("contain", "{{id}}");+ cy.findByLabelText("ID").should("exist");+cy.viewport(1440, 800);cy.findByTestId("action-creator").should("be.visible");+ H.NativeEditor.get().should("contain", "{{id}}");+ cy.findByLabelText("ID").should("be.visible");});});@@ -521,12 +537,20 @@ function setupBasicActionsInModel() {cy.button(/Create basic actions/).click();}-const actionButtonContainer = () =>- cy.findByTestId("action-button-full-container");--const dashCard = () =>+function assertActionButtonFitsDashcard() {// eslint-disable-next-line metabase/no-unsafe-element-filtering- cy- .findAllByTestId("dashcard-container")+ cy.findAllByTestId("dashcard-container").last().should("have.text", "Click Me");++ cy.findByTestId("action-button-full-container")+ .find("button")+ .should(($button) => {+ const button = $button[0].getBoundingClientRect();+ const dashcard = $button+ .closest('[data-testid="dashcard-container"]')[0]+ .getBoundingClientRect();+ expect(button.bottom).to.be.at.most(dashcard.bottom + 0.5);+ expect(button.top).to.be.at.least(dashcard.top - 0.5);+ });+}diff --git a/e2e/test/scenarios/actions/model-actions.cy.spec.js b/e2e/test/scenarios/actions/model-actions.cy.spec.jsindex 4442637dd4a..5543c50d37c 100644--- a/e2e/test/scenarios/actions/model-actions.cy.spec.js+++ b/e2e/test/scenarios/actions/model-actions.cy.spec.js@@ -62,7 +62,7 @@ const SAMPLE_WRITABLE_QUERY_ACTION = assocIn();describe(- "scenarios > models > actions",+ "scenarios > actions > model actions",{ tags: ["@external", "@actions"] },() => {beforeEach(() => {@@ -78,18 +78,9 @@ describe(cy.intercept("GET", "/api/card/*").as("getModel");cy.intercept("GET", "/api/action/*").as("getAction");- cy.intercept("GET", "/api/action?model-id=*").as("getModelAction");cy.intercept("PUT", "/api/action/*").as("updateAction");cy.intercept("POST", "/api/action/*/execute").as("executeAction");cy.intercept("POST", "/api/action").as("createAction");- cy.intercept("GET", "/api/table/*/query_metadata*").as("fetchMetadata");- cy.intercept({- method: "GET",- pathname: "/api/search",- query: { archived: "true" },- }).as("getArchived");- cy.intercept("GET", "/api/search?*").as("getSearchResults");- cy.intercept("GET", "/api/database?*").as("getDatabase");});it("should allow CRUD operations on model actions", () => {@@ -105,6 +96,26 @@ describe(cy.get("li").eq(2).findByText("Delete").should("be.visible");});+ // Constraint violations surface as detailed form errors+ runActionFor("Update");++ H.modal().within(() => {+ cy.findByLabelText("ID").type("1");+ cy.findByLabelText("User ID").type("999999");+ cy.button("Update").click();+ cy.wait("@executeAction");++ cy.findByLabelText("User ID").should("exist");+ cy.findByText('This value does not exist in table "people".').should(+ "exist",+ );++ cy.findByText("Unable to update the record.").should("exist");++ cy.button("Cancel").click();+ });+ H.modal().should("not.exist");+cy.findByRole("link", { name: "New action" }).click();H.fillActionQuery("DELETE FROM orders WHERE id = {{ id }}");cy.findByRole("radiogroup", { name: "Field type" })@@ -159,6 +170,7 @@ describe(});cy.findByRole("main").within(() => {+ cy.findByText("No actions have been created yet.").should("be.visible");cy.findByLabelText("Action list").should("not.exist");cy.findByText("Create").should("not.exist");cy.findByText("Update").should("not.exist");@@ -199,6 +211,7 @@ describe(openActionMenuFor(SAMPLE_QUERY_ACTION.name);H.popover().within(() => {+ cy.findByText("View").should("be.visible");cy.findByText("Archive").should("not.exist");cy.findByText("View").click();});@@ -209,12 +222,14 @@ describe(cy.findByText("Sample Database").should("not.exist");cy.findByText("QA Postgres12").should("not.exist");+ cy.button("Cancel").should("be.visible");cy.button("Save").should("not.exist");cy.button("Update").should("not.exist");assertQueryEditorDisabled();cy.findByRole("form").within(() => {+ cy.findByLabelText("Total").should("be.visible");cy.icon("gear").should("not.exist");});@@ -226,7 +241,10 @@ describe(cy.reload();// Check can pick between all databases- cy.findByRole("dialog").findByText("QA Postgres12").click();+ cy.findByRole("dialog")+ .findByTestId("gui-builder-data")+ .findByText("QA Postgres12")+ .click();H.popover().within(() => {cy.findByText("Sample Database").should("be.visible");cy.findByText("QA Postgres12").should("be.visible");@@ -239,53 +257,11 @@ describe(// Check can only see the action databasecy.findByRole("dialog").within(() => {- cy.findByText("QA Postgres12").click();-- cy.findByText("Sample Database").should("not.exist");- });- });-- it("should display parameters for variable template tags only", () => {- cy.visit("/");- H.startNewAction();-- H.fillActionQuery("{{#1-orders-model}}");- cy.findByLabelText("#1-orders-model").should("not.exist");-- H.fillActionQuery("{{snippet:101}}");- cy.findByLabelText("#1-orders-model").should("not.exist");- cy.findByLabelText("101").should("not.exist");-- H.fillActionQuery("{{id}}");- cy.findByLabelText("#1-orders-model").should("not.exist");- cy.findByLabelText("101").should("not.exist");- cy.findByLabelText("ID").should("be.visible");- });-- it("should show detailed form errors for constraint violations when executing model actions", () => {- const actionName = "Update";-- cy.get("@modelId").then((modelId) => {- H.createImplicitActions({ modelId });-- cy.visit(`/model/${modelId}/detail`);- cy.wait("@getModel");- });-- runActionFor(actionName);-- H.modal().within(() => {- cy.findByLabelText("ID").type("1");- cy.findByLabelText("User ID").type("999999");- cy.button(actionName).click();- cy.wait("@executeAction");-- cy.findByLabelText("User ID").should("exist");- cy.findByText('This value does not exist in table "people".').should(- "exist",+ cy.findByTestId("selected-database").should(+ "have.text",+ "QA Postgres12",);-- cy.findByText("Unable to update the record.").should("exist");+ cy.findByTestId("gui-builder-data").should("not.exist");});});},@@ -330,14 +306,8 @@ describe(});});- it("should allow action execution from the model detail page", () => {- H.queryWritableDB(- `SELECT * FROM ${WRITABLE_TEST_TABLE} WHERE id = 1`,- dialect,- ).then((result) => {- const row = result.rows[0];- expect(row.score).to.equal(0);- });+ it("should allow public sharing of actions and execution of public actions", () => {+ const IMPLICIT_ACTION_NAME = "Update";cy.get("@writableModelId").then((modelId) => {H.createAction({@@ -348,57 +318,63 @@ describe(cy.wait("@getModel");});- runActionFor(SAMPLE_QUERY_ACTION.name);+ cy.findByTestId("model-actions-header")+ .findByLabelText("Actions")+ .click();+ H.popover().findByText("Create basic actions").click();+ cy.wait(["@createAction", "@createAction", "@createAction"]);- H.modal().within(() => {- cy.findByLabelText(TEST_PARAMETER.name).type("1");- cy.button(SAMPLE_QUERY_ACTION.name).click();+ enableSharingFor(SAMPLE_WRITABLE_QUERY_ACTION.name, {+ publicUrlAlias: "queryActionPublicUrl",});- cy.findByTestId("toast-undo")- .findByText(`${SAMPLE_QUERY_ACTION.name} ran successfully`)- .should("be.visible");-- H.queryWritableDB(- `SELECT * FROM ${WRITABLE_TEST_TABLE} WHERE id = 1`,- dialect,- ).then((result) => {- const row = result.rows[0];+ openActionEditorFor(SAMPLE_WRITABLE_QUERY_ACTION.name);- expect(row.score).to.equal(22);- });- });+ H.fillActionQuery(" [[ AND status = {{new_status}} ]]");- it("should allow public sharing of actions and execution of public actions", () => {- const IMPLICIT_ACTION_NAME = "Update";+ cy.findAllByTestId("form-field-container")+ .filter(":contains('New Status')")+ .within(() => {+ cy.findByLabelText("Show field").click();+ cy.findByLabelText("Show field").should("not.be.checked");- cy.get("@writableModelId").then((modelId) => {- H.createAction({- ...SAMPLE_WRITABLE_QUERY_ACTION,- model_id: modelId,- });- H.createAction({- type: "implicit",- kind: "row/update",- name: IMPLICIT_ACTION_NAME,- model_id: modelId,+ cy.icon("gear").click();});- cy.visit(`/model/${modelId}/detail/actions`);- cy.wait("@getModel");- });- enableSharingFor(SAMPLE_WRITABLE_QUERY_ACTION.name, {- publicUrlAlias: "queryActionPublicUrl",+ H.popover().within(() => {+ cy.findByLabelText("Required").uncheck({ force: true });});++ cy.findByRole("button", { name: "Update" }).click();++ cy.wait("@updateAction");+ cy.findByTestId("action-creator").should("not.exist");+enableSharingFor(IMPLICIT_ACTION_NAME, {publicUrlAlias: "implicitActionPublicUrl",});+ openActionEditorFor(IMPLICIT_ACTION_NAME);++ cy.findAllByTestId("form-field-container")+ .filter(":contains('Created At')")+ .within(() => {+ cy.findByLabelText("Show field").click();+ cy.findByLabelText("Show field").should("not.be.checked");+ });++ cy.findByRole("button", { name: "Update" }).click();++ cy.wait("@updateAction");+ cy.findByTestId("action-creator").should("not.exist");+cy.signOut();cy.get("@queryActionPublicUrl").then((url) => {cy.visit(url);cy.findByLabelText(TEST_PARAMETER.name).type("1");+ cy.findByLabelText("New Status").should("not.exist");+cy.button(SAMPLE_QUERY_ACTION.name).click();cy.findByText(`${SAMPLE_WRITABLE_QUERY_ACTION.name} ran successfully`,@@ -421,8 +397,9 @@ describe(// team 2 has 10 points, let's give them morecy.findByLabelText("ID").type("2");- cy.findByLabelText(/score/i).type("16");- cy.findByLabelText(/team name/i).type("Bouncy Bears");+ cy.findByLabelText("Score").type("16");+ cy.findByLabelText("Team Name").type("Bouncy Bears");+ cy.findByLabelText("Created At").should("not.exist");cy.button(IMPLICIT_ACTION_NAME).click();cy.findByText(`${IMPLICIT_ACTION_NAME} ran successfully`).should(@@ -457,20 +434,74 @@ describe(cy.get("@queryActionPublicUrl").then((url) => {cy.visit(url);+ cy.findByText("Not found").should("be.visible");cy.findByRole("form").should("not.exist");cy.button(SAMPLE_QUERY_ACTION.name).should("not.exist");- cy.findByText("Not found").should("be.visible");});cy.get("@implicitActionPublicUrl").then((url) => {cy.visit(url);- cy.findByRole("form").should("not.exist");- cy.button(SAMPLE_QUERY_ACTION.name).should("not.exist");cy.findByText("Not found").should("be.visible");+ cy.findByRole("form").should("not.exist");+ cy.button(IMPLICIT_ACTION_NAME).should("not.exist");});});- it("should allow query action execution from the model details page", () => {+ it("should allow implicit and query action execution from the model details page", () => {+ cy.log("Implicit action");+ cy.get("@writableModelId").then((id) => {+ cy.visit(`/model/${id}/detail`);+ cy.wait("@getModel");+ });++ createBasicActions();++ openActionEditorFor("Create");++ cy.findByRole("dialog")+ .findAllByTestId("form-field-container")+ .should("have.length", 5);++ cy.findAllByTestId("form-field-container")+ .filter(":contains('Created At')")+ .within(() => {+ cy.findByLabelText("Show field").click();+ cy.findByLabelText("Show field").should("not.be.checked");+ });++ cy.findByRole("button", { name: "Update" }).click();++ cy.wait("@updateAction");+ cy.findByTestId("action-creator").should("not.exist");++ runActionFor("Create");++ H.modal().within(() => {+ cy.findByLabelText("Created At").should("not.exist");+ cy.findByLabelText("Team Name").type("Zebras");+ cy.findByLabelText("Score").type("1");++ cy.findByRole("button", { name: "Save" }).click();+ });++ cy.findByTestId("toast-undo")+ .findByText("Successfully saved")+ .should("be.visible");+ H.undoToast().icon("close").click();+ H.undoToast().should("not.exist");++ H.queryWritableDB(+ `SELECT * FROM ${WRITABLE_TEST_TABLE} WHERE team_name = 'Zebras'`,+ dialect,+ ).then((result) => {+ expect(result.rows.length).to.equal(1);++ const row = result.rows[0];++ expect(row.score).to.equal(1);+ });++ cy.log("Query action");verifyScoreValue(0, dialect);cy.get("@writableModelId").then((modelId) => {@@ -482,6 +513,23 @@ describe(cy.wait("@getModel");});+ runActionFor(SAMPLE_QUERY_ACTION.name);++ H.modal().within(() => {+ cy.findByLabelText(TEST_PARAMETER.name).type("1");+ cy.button(SAMPLE_QUERY_ACTION.name).click();+ });++ cy.findByTestId("toast-undo")+ .findByText(`${SAMPLE_QUERY_ACTION.name} ran successfully`)+ .should("be.visible");+ H.undoToast().icon("close").click();+ H.undoToast().should("not.exist");++ verifyScoreValue(22, dialect);++ resetAndVerifyScoreValue(dialect);+openActionEditorFor(SAMPLE_QUERY_ACTION.name);H.fillActionQuery(" [[and status = {{ current_status}}]]");@@ -581,256 +629,90 @@ describe(verifyScoreValue(22, dialect);});- it("should allow implicit action execution from the model details page", () => {- cy.get("@writableModelId").then((id) => {- cy.visit(`/model/${id}/detail`);- cy.wait("@getModel");- });-- createBasicActions();-- openActionEditorFor("Create");-- cy.wait("@getAction").then(({ response }) => {- const { parameters, visualization_settings } = response.body;- expect(parameters).to.have.length(5);- expect(visualization_settings).to.have.property("fields");- });-- cy.findAllByTestId("form-field-container")- .filter(":contains('Created At')")- .within(() => {- cy.findByLabelText("Show field").click();- cy.findByLabelText("Show field").should("not.be.checked");- });-- cy.findByRole("button", { name: "Update" }).click();-- cy.wait("@updateAction");- cy.findByTestId("action-creator").should("not.exist");-- runActionFor("Create");-- H.modal().within(() => {- cy.findByLabelText("Created At").should("not.exist");- cy.findByLabelText("Team Name").type("Zebras");- cy.findByLabelText("Score").type("1");-- cy.findByRole("button", { name: "Save" }).click();- });-- cy.findByTestId("toast-undo")- .findByText("Successfully saved")- .should("be.visible");-- // show toast- H.queryWritableDB(- `SELECT * FROM ${WRITABLE_TEST_TABLE} WHERE team_name = 'Zebras'`,- dialect,- ).then((result) => {- expect(result.rows.length).to.equal(1);-- const row = result.rows[0];-- expect(row.score).to.equal(1);- });- });-- it("should allow public sharing of query action and execution", () => {- cy.get("@writableModelId").then((modelId) => {- H.createAction({- ...SAMPLE_WRITABLE_QUERY_ACTION,- model_id: modelId,- });-- cy.visit(`/model/${modelId}/detail/actions`);- cy.wait("@getModel");- });-- enableSharingFor(SAMPLE_WRITABLE_QUERY_ACTION.name, {- publicUrlAlias: "queryActionPublicUrl",- });-- openActionEditorFor(SAMPLE_WRITABLE_QUERY_ACTION.name);-- H.fillActionQuery(" [[ AND status = {{new_status}} ]]");-- cy.findAllByTestId("form-field-container")- .filter(":contains('New Status')")- .within(() => {- cy.findByLabelText("Show field").click();- cy.findByLabelText("Show field").should("not.be.checked");+ if (dialect === "postgres") {+ it("should respect impersonated permission", () => {+ const role = "readonly_role";+ const sql = getCreatePostgresRoleIfNotExistSql(+ role,+ `GRANT SELECT ON ${WRITABLE_TEST_TABLE} TO ${role};`,+ );+ H.activateToken("pro-self-hosted");+ H.queryWritableDB(sql);- cy.icon("gear").click();+ cy.request("PUT", `/api/user/${IMPERSONATED_USER_ID}`, {+ login_attributes: { role },});- H.popover().within(() => {- cy.findByLabelText("Required").uncheck({ force: true });- });-- cy.findByRole("button", { name: "Update" }).click();-- cy.wait("@updateAction");- cy.findByTestId("action-creator").should("not.exist");-- cy.signOut();-- cy.get("@queryActionPublicUrl").then((url) => {- cy.visit(url);- cy.findByLabelText(TEST_PARAMETER.name).type("1");- cy.findByLabelText("New Status").should("not.exist");-- cy.button(SAMPLE_QUERY_ACTION.name).click();-- cy.findByText(- `${SAMPLE_WRITABLE_QUERY_ACTION.name} ran successfully`,- ).should("be.visible");+ cy.updatePermissionsGraph(+ {+ [USER_GROUPS.ALL_USERS_GROUP]: {+ [WRITABLE_DB_ID]: {+ "view-data": "impersonated",+ "create-queries": "query-builder-and-native",+ },+ },+ // By default, all groups get `unrestricted` access that will override the impersonation.+ [USER_GROUPS.COLLECTION_GROUP]: {+ [WRITABLE_DB_ID]: {+ "view-data": "blocked",+ },+ },+ },+ [+ {+ db_id: WRITABLE_DB_ID,+ group_id: USER_GROUPS.ALL_USERS_GROUP,+ attribute: "role",+ },+ ],+ );H.queryWritableDB(- `SELECT * FROM ${WRITABLE_TEST_TABLE} WHERE id = 1`,+ `SELECT *+ FROM ${WRITABLE_TEST_TABLE}+ WHERE id = 1`,dialect,).then((result) => {const row = result.rows[0];-- expect(row.score).to.equal(22);+ expect(row.score).to.equal(0);});- });- });- it("should allow public sharing of implicit action and execution", () => {- cy.get("@writableModelId").then((id) => {- cy.visit(`/model/${id}/detail`);- cy.wait("@getModel");- });-- createBasicActions();-- enableSharingFor("Update", { publicUrlAlias: "updatePublicURL" });-- openActionEditorFor("Update");-- cy.findAllByTestId("form-field-container")- .filter(":contains('Created At')")- .within(() => {- cy.findByLabelText("Show field").click();- cy.findByLabelText("Show field").should("not.be.checked");+ cy.get("@writableModelId").then((modelId) => {+ H.createAction({+ ...SAMPLE_WRITABLE_QUERY_ACTION,+ model_id: modelId,+ });+ cy.signInAsImpersonatedUser();+ cy.visit(`/model/${modelId}/detail/actions`);+ cy.wait("@getModel");});- cy.findByRole("button", { name: "Update" }).click();-- cy.wait("@updateAction");- cy.findByTestId("action-creator").should("not.exist");-- cy.signOut();-- cy.get("@updatePublicURL").then((url) => {- cy.visit(url);-- // team 2 has 10 points, let's give them more- cy.findByLabelText("ID").type("2");- cy.findByLabelText("Score").type("16");- cy.findByLabelText("Team Name").type("Bouncy Bears");- cy.findByLabelText("Create At").should("not.exist");+ cy.intercept("POST", "/api/action/*/execute").as(+ "executeImpersonatedAction",+ );+ runActionFor(SAMPLE_QUERY_ACTION.name);- cy.button("Update").click();+ H.modal().within(() => {+ cy.findByLabelText(TEST_PARAMETER.name).type("1");+ cy.button(SAMPLE_QUERY_ACTION.name).click();- cy.findByText("Update ran successfully").should("be.visible");+ cy.wait("@executeImpersonatedAction", { responseTimeout: 60_000 });+ cy.findByText(+ "Error executing Action: Error executing write query: ERROR: permission denied for table scoreboard_actions",+ );+ });H.queryWritableDB(- `SELECT * FROM ${WRITABLE_TEST_TABLE} WHERE id = 2`,+ `SELECT *+ FROM ${WRITABLE_TEST_TABLE}+ WHERE id = 1`,dialect,).then((result) => {const row = result.rows[0];-- expect(row.score).to.equal(16);- expect(row.team_name).to.equal("Bouncy Bears");- });- });- });-- it("should respect impersonated permission", () => {- cy.onlyOn(dialect === "postgres");- const role = "readonly_role";- const sql = getCreatePostgresRoleIfNotExistSql(- role,- `GRANT SELECT ON ${WRITABLE_TEST_TABLE} TO ${role};`,- );- H.activateToken("pro-self-hosted");- H.queryWritableDB(sql);-- cy.request("PUT", `/api/user/${IMPERSONATED_USER_ID}`, {- login_attributes: { role },- });-- cy.updatePermissionsGraph(- {- [USER_GROUPS.ALL_USERS_GROUP]: {- [WRITABLE_DB_ID]: {- "view-data": "impersonated",- "create-queries": "query-builder-and-native",- },- },- // By default, all groups get `unrestricted` access that will override the impersonation.- [USER_GROUPS.COLLECTION_GROUP]: {- [WRITABLE_DB_ID]: {- "view-data": "blocked",- },- },- },- [- {- db_id: WRITABLE_DB_ID,- group_id: USER_GROUPS.ALL_USERS_GROUP,- attribute: "role",- },- ],- );-- H.queryWritableDB(- `SELECT *- FROM ${WRITABLE_TEST_TABLE}- WHERE id = 1`,- dialect,- ).then((result) => {- const row = result.rows[0];- expect(row.score).to.equal(0);- });-- cy.get("@writableModelId").then((modelId) => {- H.createAction({- ...SAMPLE_WRITABLE_QUERY_ACTION,- model_id: modelId,+ expect(row.score).to.equal(0);});- cy.signInAsImpersonatedUser();- cy.visit(`/model/${modelId}/detail/actions`);- cy.wait("@getModel");});-- cy.intercept("POST", "/api/action/*/execute").as(- "executeImpersonatedAction",- );- runActionFor(SAMPLE_QUERY_ACTION.name);-- H.modal().within(() => {- cy.findByLabelText(TEST_PARAMETER.name).type("1");- cy.button(SAMPLE_QUERY_ACTION.name).click();-- cy.wait("@executeImpersonatedAction", { responseTimeout: 60_000 });- cy.findByText(- "Error executing Action: Error executing write query: ERROR: permission denied for table scoreboard_actions",- );- });-- H.queryWritableDB(- `SELECT *- FROM ${WRITABLE_TEST_TABLE}- WHERE id = 1`,- dialect,- ).then((result) => {- const row = result.rows[0];- expect(row.score).to.equal(0);- });- });+ }},);});@@ -848,11 +730,9 @@ function openActionMenuFor(actionName) {});}-function openActionEditorFor(actionName, { isReadOnly = false } = {}) {+function openActionEditorFor(actionName) {openActionMenuFor(actionName);- H.popover()- .findByText(isReadOnly ? "View" : "Edit")- .click();+ H.popover().findByText("Edit").click();}function assertQueryEditorDisabled() {