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 data studio e2e tests (#83736)
Nemanja Glumac54fe3c436520
diff --git a/e2e/support/helpers/e2e-datamodel-helpers.ts b/e2e/support/helpers/e2e-datamodel-helpers.tsindex 9e2e36e704e..c1bab119657 100644--- a/e2e/support/helpers/e2e-datamodel-helpers.ts+++ b/e2e/support/helpers/e2e-datamodel-helpers.ts@@ -155,7 +155,6 @@ export const DataModel = {getReplaceButton: getSourceReplacementReplaceButton,getCancelButton: getSourceReplacementCancelButton,getTargetPickerButton: getSourceReplacementTargetPickerButton,- getDependentsTab: getSourceReplacementDependentsTab,getFindAndReplaceButton: getSourceReplacementFindAndReplaceButton,},};@@ -984,12 +983,6 @@ function getSourceReplacementTargetPickerButton() {);}-function getSourceReplacementDependentsTab(count: number) {- return getSourceReplacementModal().findByRole("tab", {- name: new RegExp(`${count} items? will be changed`),- });-}-function getSourceReplacementFindAndReplaceButton() {return cy.findByRole("menuitem", { name: /Find and replace/ });}diff --git a/e2e/test/scenarios/data-studio/data-model/data-studio-bulk-table.cy.spec.ts b/e2e/test/scenarios/data-studio/data-model/data-studio-bulk-table.cy.spec.tsindex 5275d09405d..dc00730c21a 100644--- a/e2e/test/scenarios/data-studio/data-model/data-studio-bulk-table.cy.spec.ts+++ b/e2e/test/scenarios/data-studio/data-model/data-studio-bulk-table.cy.spec.ts@@ -21,7 +21,7 @@ interface Table {describe("bulk table operations", { viewportWidth: 1600 }, () => {beforeEach(() => {- H.restore();+ H.restore("postgres-writable");H.resetSnowplow();cy.signInAsAdmin();H.activateToken("pro-self-hosted");@@ -40,99 +40,128 @@ describe("bulk table operations", { viewportWidth: 1600 }, () => {);});- it("syncing multiple tables", { tags: ["@external"] }, () => {- H.restore("postgres-writable");- H.activateToken("pro-self-hosted");- // Re-authenticate after restoring the writable-DB snapshot, like the- // sibling tests do, otherwise visiting Data Studio can land in an- // unauthenticated state and the TablePicker never issues the schema- // request.- cy.signInAsAdmin();- H.DataModel.visitDataStudio();- TablePicker.expandDatabase("Writable Postgres12");+ it(+ "syncs, edits attributes, publishes and unpublishes multiple tables",+ { tags: ["@external"] },+ () => {+ H.DataModel.visitDataStudio();+ TablePicker.expandDatabase("Writable Postgres12");++ // Capture the expected table IDs from a direct API request rather than the+ // intercepted UI response: under stress the intercepted response body is+ // occasionally a non-array (e.g. an error map), which made `tables.find`+ // throw `TypeError: tables.find is not a function`. A `cy.request`+ // deterministically returns the table list.+ cy.request<Table[]>(+ `/api/database/${WRITABLE_DB_ID}/schema/public?include_hidden=true`,+ ).then(({ body: tables }) => {+ const ordersTableId = getTableId(tables, "Orders");+ const productsTableId = getTableId(tables, "Products");++ cy.wrap([ordersTableId, productsTableId]).as("tableIds");+ });- // Capture the expected table IDs from a direct API request rather than the- // intercepted UI response: under stress the intercepted response body is- // occasionally a non-array (e.g. an error map), which made `tables.find`- // throw `TypeError: tables.find is not a function`. A `cy.request`- // deterministically returns the table list.- cy.request<Table[]>(- `/api/database/${WRITABLE_DB_ID}/schema/public?include_hidden=true`,- ).then(({ body: tables }) => {- const ordersTableId = getTableId(tables, "Orders");- const productsTableId = getTableId(tables, "Products");-- cy.wrap([ordersTableId, productsTableId]).as("tableIds");- });-- TablePicker.getTable("Orders").find('input[type="checkbox"]').check();- TablePicker.getTable("Products").find('input[type="checkbox"]').check();- cy.findByRole("heading", { name: /2 tables selected/ });-- cy.findByRole("button", { name: /Sync settings/ }).click();- H.expectUnstructuredSnowplowEvent({- event: "data_studio_bulk_sync_settings_clicked",- });- cy.findByRole("button", { name: /Sync table schemas/ }).click();- cy.findByRole("button", { name: /Sync triggered!/ }).should("be.visible");- cy.get<number[]>("@tableIds").then((tableIds) => {- cy.wait<TablesActionRequest, TablesActionsResponse>("@syncSchema").then(- ({ request, response }) => {+ TablePicker.getTable("Orders").find('input[type="checkbox"]').check();+ TablePicker.getTable("Products").find('input[type="checkbox"]').check();+ cy.findByRole("heading", { name: /2 tables selected/ });++ cy.findByRole("button", { name: /Sync settings/ }).click();+ H.expectUnstructuredSnowplowEvent({+ event: "data_studio_bulk_sync_settings_clicked",+ });+ cy.findByRole("button", { name: /Sync table schemas/ }).click();+ cy.findByRole("button", { name: /Sync triggered!/ }).should("be.visible");+ cy.get<number[]>("@tableIds").then((tableIds) => {+ cy.wait<TablesActionRequest, TablesActionsResponse>("@syncSchema").then(+ ({ request, response }) => {+ expect(request.body.table_ids).to.deep.eq(tableIds);+ expect(response?.statusCode).to.eq(204);+ },+ );+ });+ H.expectUnstructuredSnowplowEvent({+ event: "data_studio_table_schema_sync_started",+ result: "success",+ });++ cy.findByRole("button", { name: /Re-scan tables/ }).click();+ cy.findByRole("button", { name: /Scan triggered!/ }).should("be.visible");++ cy.get<number[]>("@tableIds").then((tableIds) => {+ cy.wait<TablesActionRequest, TablesActionsResponse>(+ "@rescanValues",+ ).then(({ request, response }) => {expect(request.body.table_ids).to.deep.eq(tableIds);expect(response?.statusCode).to.eq(204);- },+ });+ });+ H.expectUnstructuredSnowplowEvent({+ event: "data_studio_table_fields_rescan_started",+ result: "success",+ });++ cy.findByRole("button", { name: /Discard cached field values/ }).click();+ cy.findByRole("button", { name: /Discard triggered!/ }).should(+ "be.visible",);- });- H.expectUnstructuredSnowplowEvent({- event: "data_studio_table_schema_sync_started",- result: "success",- });-- cy.findByRole("button", { name: /Re-scan tables/ }).click();- cy.findByRole("button", { name: /Scan triggered!/ }).should("be.visible");-- cy.get<number[]>("@tableIds").then((tableIds) => {- cy.wait<TablesActionRequest, TablesActionsResponse>("@rescanValues").then(- ({ request, response }) => {+ cy.get<number[]>("@tableIds").then((tableIds) => {+ cy.wait<TablesActionRequest, TablesActionsResponse>(+ "@discardValues",+ ).then(({ request, response }) => {expect(request.body.table_ids).to.deep.eq(tableIds);expect(response?.statusCode).to.eq(204);- },- );- });- H.expectUnstructuredSnowplowEvent({- event: "data_studio_table_fields_rescan_started",- result: "success",- });-- cy.findByRole("button", { name: /Discard cached field values/ }).click();- cy.findByRole("button", { name: /Discard triggered!/ }).should(- "be.visible",- );- cy.get<number[]>("@tableIds").then((tableIds) => {- cy.wait<TablesActionRequest, TablesActionsResponse>(- "@discardValues",- ).then(({ request, response }) => {- expect(request.body.table_ids).to.deep.eq(tableIds);- expect(response?.statusCode).to.eq(204);+ });+ });+ H.expectUnstructuredSnowplowEvent({+ event: "data_studio_table_field_values_discard_started",+ result: "success",});- });- H.expectUnstructuredSnowplowEvent({- event: "data_studio_table_field_values_discard_started",- result: "success",- });- });- it(- "allows publishing and unpublishing multiple tables",- { tags: ["@external"] },- () => {- H.restore("postgres-writable");- H.activateToken("pro-self-hosted");- cy.signInAsAdmin();- H.DataModel.visitDataStudio();+ H.modal().should("be.visible");+ cy.realPress("Escape");+ H.modal().should("not.exist");- cy.log("select multiple tables");- TablePicker.expandDatabase("Writable Postgres12");+ cy.log("edit attributes for multiple tables");+ H.selectHasValue("Owner", "").click();+ H.selectDropdown().contains("Bobby Tables").click();+ H.expectUnstructuredSnowplowEvent({+ event: "data_studio_bulk_attribute_updated",+ event_detail: "owner",+ result: "success",+ });++ H.selectHasValue("Visibility layer", "").click();+ H.selectDropdown().contains("Final").click();+ H.expectUnstructuredSnowplowEvent({+ event: "data_studio_bulk_attribute_updated",+ event_detail: "layer",+ result: "success",+ });++ H.selectHasValue("Entity type", "").click();+ H.selectDropdown().contains("Person").click();+ H.expectUnstructuredSnowplowEvent({+ event: "data_studio_bulk_attribute_updated",+ event_detail: "entity_type",+ result: "success",+ });++ H.selectHasValue("Source", "").click();+ H.selectDropdown().contains("Ingested").click();+ H.expectUnstructuredSnowplowEvent({+ event: "data_studio_bulk_attribute_updated",+ event_detail: "data_source",+ result: "success",+ });+ H.undoToastList().should("have.length", 4);+ TablePicker.getTable("Orders")+ .findByTestId("table-owner")+ .should("have.text", "Bobby Tables");+ TablePicker.getTable("Products")+ .findByTestId("table-owner")+ .should("have.text", "Bobby Tables");++ cy.log("publish and unpublish multiple tables");TablePicker.getTable("Orders").findByRole("checkbox").check();TablePicker.getTable("Products").findByRole("checkbox").check();TablePicker.getTable("Reviews").findByRole("checkbox").check();@@ -169,64 +198,12 @@ describe("bulk table operations", { viewportWidth: 1600 }, () => {},);- it("allows to edit attributes for tables", { tags: ["@external"] }, () => {- H.restore("postgres-writable");- H.activateToken("pro-self-hosted");- cy.signInAsAdmin();- H.DataModel.visitDataStudio();- TablePicker.expandDatabase("Writable Postgres12");- TablePicker.getTable("Orders").find('input[type="checkbox"]').check();- TablePicker.getTable("Products").find('input[type="checkbox"]').check();-- H.selectHasValue("Owner", "").click();- H.selectDropdown().contains("Bobby Tables").click();- H.expectUnstructuredSnowplowEvent({- event: "data_studio_bulk_attribute_updated",- event_detail: "owner",- result: "success",- });-- H.selectHasValue("Visibility layer", "").click();- H.selectDropdown().contains("Final").click();- H.expectUnstructuredSnowplowEvent({- event: "data_studio_bulk_attribute_updated",- event_detail: "layer",- result: "success",- });-- H.selectHasValue("Entity type", "").click();- H.selectDropdown().contains("Person").click();- H.expectUnstructuredSnowplowEvent({- event: "data_studio_bulk_attribute_updated",- event_detail: "entity_type",- result: "success",- });-- H.selectHasValue("Source", "").click();- H.selectDropdown().contains("Ingested").click();- H.expectUnstructuredSnowplowEvent({- event: "data_studio_bulk_attribute_updated",- event_detail: "data_source",- result: "success",- });- H.undoToastList().should("have.length", 4);- TablePicker.getTable("Orders")- .findByTestId("table-owner")- .should("have.text", "Bobby Tables");- TablePicker.getTable("Products")- .findByTestId("table-owner")- .should("have.text", "Bobby Tables");- });-describe("several databases with several schemas at once (GDGT-1275)",{ tags: ["@external"] },() => {beforeEach(() => {- H.restore("postgres-writable");- H.activateToken("pro-self-hosted");H.createLibrary();- cy.signInAsAdmin();H.resetTestTable({ type: "postgres", table: "multi_schema" });H.resyncDatabase({ dbId: WRITABLE_DB_ID });H.DataModel.visitDataStudio();@@ -298,10 +275,7 @@ describe("bulk table operations", { viewportWidth: 1600 }, () => {);it("allows to edit attributes for db", { tags: ["@external"] }, () => {- H.restore("postgres-writable");- H.activateToken("pro-self-hosted");H.createLibrary();- cy.signInAsAdmin();H.DataModel.visitDataStudio();cy.log(@@ -344,10 +318,7 @@ describe("bulk table operations", { viewportWidth: 1600 }, () => {});it("allows to edit attributes for schema", { tags: ["@external"] }, () => {- H.restore("postgres-writable");- H.activateToken("pro-self-hosted");H.resetTestTable({ type: "postgres", table: "many_schemas" });- cy.signInAsAdmin();H.resyncDatabase({ dbId: WRITABLE_DB_ID, tableName: "Animals" });H.DataModel.visitDataStudio();TablePicker.expandDatabase("Writable Postgres12");@@ -374,6 +345,7 @@ describe("bulk table operations", { viewportWidth: 1600 }, () => {cy.findByTestId("loading-placeholder").should("not.exist");cy.findAllByTestId("tree-item").filter('[data-type="table"]')+ .should("have.length", 2).each((table) => {cy.wrap(table).findByTestId("table-owner")diff --git a/e2e/test/scenarios/data-studio/data-model/data-studio-single-table.cy.spec.ts b/e2e/test/scenarios/data-studio/data-model/data-studio-single-table.cy.spec.tsindex cccc424718c..264f21edbf7 100644--- a/e2e/test/scenarios/data-studio/data-model/data-studio-single-table.cy.spec.ts+++ b/e2e/test/scenarios/data-studio/data-model/data-studio-single-table.cy.spec.ts@@ -11,22 +11,8 @@ interface MetadataResponse {describe("Table editing", () => {beforeEach(() => {H.resetSnowplow();- H.restore();cy.signInAsAdmin();- H.activateToken("pro-self-hosted");- cy.intercept("GET", "/api/database?*").as("databases");- cy.intercept("GET", "/api/database/*/schemas?*").as("schemas");cy.intercept("GET", "/api/table/*/query_metadata*").as("metadata");- cy.intercept("GET", "/api/database/*/schema/*").as("schema");- cy.intercept("POST", "/api/dataset*").as("dataset");- cy.intercept("GET", "/api/field/*/values").as("fieldValues");- cy.intercept("PUT", "/api/field/*", cy.spy().as("updateFieldSpy")).as(- "updateField",- );- cy.intercept("PUT", "/api/table/*/fields/order").as("updateFieldOrder");- cy.intercept("POST", "/api/field/*/values").as("updateFieldValues");- cy.intercept("POST", "/api/field/*/dimension").as("updateFieldDimension");- cy.intercept("PUT", "/api/table").as("updateTables");cy.intercept("PUT", "/api/table/*").as("updateTable");cy.intercept("POST", "/api/ee/data-studio/table/publish-tables").as("publishTables",@@ -36,33 +22,8 @@ describe("Table editing", () => {);});- it("should display metadata information", { tags: ["@external"] }, () => {- H.restore("mysql-8");- H.activateToken("pro-self-hosted");- H.DataModel.visitDataStudio();- TablePicker.getDatabase("QA MySQL8").click();- TablePicker.getTable("Orders").click();-- cy.wait<MetadataResponse>("@metadata").then(({ response }) => {- const viewCount = response?.body.view_count ?? 0;-- cy.findByLabelText("Name in the database").should("have.text", "ORDERS");- cy.findByLabelText("Last updated at").should("exist"); // Testing the actual value is done in TableMetadata.unit.spec.tsx- cy.findByLabelText("View count").should("have.text", viewCount);- cy.findByLabelText("Est. row count").should("not.exist");- cy.findByLabelText("Dependencies").should("have.text", "0");- cy.findByLabelText("Dependents").should("have.text", "0");-- H.DataModel.TableSection.get()- .findByRole("link", { name: "Dependency graph" })- .click();-- H.DataStudio.Dependencies.graph().should("be.visible");- });- });-it(- "should publish a single table to a collection and unpublish",+ "should display metadata information and publish and unpublish a single table",{ tags: ["@external"] },() => {H.restore("mysql-8");@@ -71,6 +32,29 @@ describe("Table editing", () => {TablePicker.getDatabase("QA MySQL8").click();TablePicker.getTable("Orders").click();+ cy.log("display metadata information");+ cy.wait<MetadataResponse>("@metadata").then(({ response }) => {+ const viewCount = response?.body.view_count ?? 0;++ cy.findByLabelText("Name in the database").should(+ "have.text",+ "ORDERS",+ );+ cy.findByLabelText("Last updated at").should("exist"); // Testing the actual value is done in TableMetadata.unit.spec.tsx+ cy.findByLabelText("View count").should("have.text", viewCount);+ cy.findByLabelText("Est. row count").should("not.exist");+ cy.findByLabelText("Dependencies").should("have.text", "0");+ cy.findByLabelText("Dependents").should("have.text", "0");++ H.DataModel.TableSection.get()+ .findByRole("link", { name: "Dependency graph" })+ .click();++ H.DataStudio.Dependencies.graph().should("be.visible");+ });+ cy.go("back");+ H.DataModel.TableSection.getNameInput().should("have.value", "Orders");+cy.log("publish the table and verify it's published");TablePicker.getTable("Orders").findByTestId("table-published")@@ -100,6 +84,9 @@ describe("Table editing", () => {.findByTestId("table-published").should("not.exist");H.DataStudio.nav().findByLabelText("Semantic layer").click();+ H.DataStudio.Library.emptyStateRow(+ "Cleaned, pre-transformed data sources ready for exploring",+ ).should("be.visible");H.DataStudio.Library.allTableItems().should("have.length", 0);},);diff --git a/e2e/test/scenarios/data-studio/data-model/datamodel-data-studio.cy.spec.ts b/e2e/test/scenarios/data-studio/data-model/datamodel-data-studio.cy.spec.tsindex 3ff7ca4bc38..47f0ae5d57f 100644--- a/e2e/test/scenarios/data-studio/data-model/datamodel-data-studio.cy.spec.ts+++ b/e2e/test/scenarios/data-studio/data-model/datamodel-data-studio.cy.spec.ts@@ -19,125 +19,82 @@ describe("scenarios > data studio > datamodel", () => {cy.signInAsAdmin();H.activateToken("pro-self-hosted");- cy.intercept("GET", "/api/database").as("databases");- cy.intercept("GET", "/api/database/*/schemas?*").as("schemas");- cy.intercept("GET", "/api/table/*/query_metadata*").as("metadata");- cy.intercept("GET", "/api/database/*/schema/*").as("schema");cy.intercept("POST", "/api/dataset*").as("dataset");- cy.intercept("GET", "/api/field/*/values").as("fieldValues");cy.intercept("GET", "/api/table?*").as("listTables");- cy.intercept("PUT", "/api/field/*", cy.spy().as("updateFieldSpy")).as(- "updateField",- );+ cy.intercept("PUT", "/api/field/*").as("updateField");cy.intercept("PUT", "/api/table/*/fields/order").as("updateFieldOrder");cy.intercept("POST", "/api/field/*/values").as("updateFieldValues");cy.intercept("POST", "/api/field/*/dimension").as("updateFieldDimension");- cy.intercept("PUT", "/api/table").as("updateTables");cy.intercept("PUT", "/api/table/*").as("updateTable");});describe("Table picker", () => {describe("Filtering", () => {- it("should filter tables owned by unspecified", () => {+ it("should filter tables by owner and source", () => {+ const OWNER_EMAIL = "[email protected]";+cy.request("GET", "/api/user/current").its("body")- .then(({ id }) => {+ .then(({ id, common_name }) => {+ cy.wrap(common_name).as("ownerName");return updateTableAttributes({databaseId: SAMPLE_DB_ID,displayName: "Orders",- attributes: { owner_user_id: id },- }).as("ownedTableId");+ attributes: { owner_user_id: id, data_source: "upload" },+ }).as("ordersTableId");});- getTableId({+ updateTableAttributes({databaseId: SAMPLE_DB_ID,displayName: "Products",- }).as("unownedTableId");+ attributes: { data_source: "ingested" },+ }).as("productsTableId");H.DataModel.visitDataStudio();+ cy.get<TableId>("@ordersTableId").then(expectTableVisible);+ cy.get<TableId>("@productsTableId").then(expectTableVisible);+ cy.log("filter by unspecified owner");TablePicker.openFilterPopover();TablePicker.selectFilterOption("Owner", "Unspecified");TablePicker.applyFilters();- cy.get<TableId>("@unownedTableId").then(expectTableVisible);- cy.get<TableId>("@ownedTableId").then(expectTableNotVisible);- });-- it("should filter tables by owner user", () => {- cy.request("GET", "/api/user/current")- .its("body")- .then(({ id, common_name }) => {- cy.wrap(common_name).as("ownerName");- return updateTableAttributes({- databaseId: SAMPLE_DB_ID,- displayName: "Orders",- attributes: { owner_user_id: id },- }).as("ownedTableId");- });-- getTableId({- databaseId: SAMPLE_DB_ID,- displayName: "Products",- }).as("unownedTableId");+ cy.get<TableId>("@productsTableId").then(expectTableVisible);+ cy.get<TableId>("@ordersTableId").then(expectTableNotVisible);+ cy.log("filter by owner user");H.DataModel.visitDataStudio();-TablePicker.openFilterPopover();cy.get<string>("@ownerName").then((ownerName) => {selectOwnerByName(ownerName);});TablePicker.applyFilters();- cy.get<TableId>("@ownedTableId").then(expectTableVisible);- cy.get<TableId>("@unownedTableId").then(expectTableNotVisible);- });-- it("should filter tables by owner email", () => {- const OWNER_EMAIL = "[email protected]";-- updateTableAttributes({- databaseId: SAMPLE_DB_ID,- displayName: "Orders",- attributes: { owner_email: OWNER_EMAIL, owner_user_id: null },- }).as("emailOwnedTableId");-- getTableId({- databaseId: SAMPLE_DB_ID,- displayName: "Products",- }).as("otherTableId");+ cy.get<TableId>("@ordersTableId").then(expectTableVisible);+ cy.get<TableId>("@productsTableId").then(expectTableNotVisible);+ cy.log("filter by source");H.DataModel.visitDataStudio();-TablePicker.openFilterPopover();- selectOwnerByEmail(OWNER_EMAIL);+ TablePicker.selectFilterOption("Source", "Uploaded data");TablePicker.applyFilters();- cy.get<TableId>("@emailOwnedTableId").then(expectTableVisible);- cy.get<TableId>("@otherTableId").then(expectTableNotVisible);- });+ cy.get<TableId>("@ordersTableId").then(expectTableVisible);+ cy.get<TableId>("@productsTableId").then(expectTableNotVisible);- it("should filter tables by source", () => {+ cy.log("filter by owner email");updateTableAttributes({databaseId: SAMPLE_DB_ID,displayName: "Orders",- attributes: { data_source: "upload" },- }).as("uploadedTableId");-- updateTableAttributes({- databaseId: SAMPLE_DB_ID,- displayName: "Products",- attributes: { data_source: "ingested" },- }).as("ingestedTableId");-+ attributes: { owner_email: OWNER_EMAIL, owner_user_id: null },+ });H.DataModel.visitDataStudio();-TablePicker.openFilterPopover();- TablePicker.selectFilterOption("Source", "Uploaded data");+ selectOwnerByEmail(OWNER_EMAIL);TablePicker.applyFilters();- cy.get<TableId>("@uploadedTableId").then(expectTableVisible);- cy.get<TableId>("@ingestedTableId").then(expectTableNotVisible);+ cy.get<TableId>("@ordersTableId").then(expectTableVisible);+ cy.get<TableId>("@productsTableId").then(expectTableNotVisible);});});});@@ -181,6 +138,7 @@ describe("scenarios > data studio > datamodel", () => {cy.wait("@updateField");verifyAndCloseToast("Name of Tax updated");TableSection.getFieldNameInput("Analyst Tax").should("be.visible");+ TableSection.getField("Analyst Tax").should("be.visible");cy.log("change field description");TableSection.getFieldDescriptionInput("Total")@@ -189,112 +147,9 @@ describe("scenarios > data studio > datamodel", () => {.blur();cy.wait("@updateField");verifyAndCloseToast("Description of Total updated");-- cy.log("verify changes in data reference as admin");- cy.signInAsAdmin();-- H.DataModel.visitDataStudio({- databaseId: SAMPLE_DB_ID,- schemaId: SAMPLE_DB_SCHEMA_ID,- tableId: ORDERS_ID,- });- cy.log("snowplow event when dependency graph link is clicked");- TableSection.getDependencyGraphLink().click();- H.expectUnstructuredSnowplowEvent({- event: "dependency_entity_selected",- triggered_from: "data-structure",- event_detail: "table",- });-- cy.visit(`/reference/databases/${SAMPLE_DB_ID}/tables/${ORDERS_ID}`);- cy.get("main").within(() => {- cy.findByText("Analyst Orders").should("be.visible");- cy.findByText("Description by analyst").should("be.visible");- });-- cy.log("verify changes in question picker as normal user");- cy.signInAsNormalUser();- H.startNewQuestion();- H.miniPicker().within(() => {- cy.findByText("Sample Database").click();- cy.findByText("People").should("be.visible");- cy.findByText("Analyst Orders").should("be.visible");- });-- cy.log("verify field changes in table visualization");- H.openOrdersTable();- H.tableHeaderColumn("Analyst Tax").should("be.visible");- H.tableHeaderColumn("Tax", { scrollIntoView: false }).should(- "not.exist",- );- });- });-- describe("Field name and description", () => {- it("should allow clearing the field description", () => {- H.DataModel.visitDataStudio({- databaseId: SAMPLE_DB_ID,- schemaId: SAMPLE_DB_SCHEMA_ID,- tableId: ORDERS_ID,- });-- TableSection.clickFieldsTab();- TableSection.getFieldDescriptionInput("Total").clear().blur();- cy.wait("@updateField");- verifyAndCloseToast("Description of Total updated");- TableSection.getFieldDescriptionInput("Total").should("have.value", "");-- cy.log("verify preview");- TableSection.clickField("Total");- FieldSection.getPreviewButton().click();- verifyTablePreview({- column: "Total",- values: ["39.72", "117.03", "49.21", "115.23", "134.91"],- });- PreviewSection.get().findByTestId("header-cell").realHover();- H.hovercard().should("not.contain.text", "The total billed amount.");-- cy.visit(- `/reference/databases/${SAMPLE_DB_ID}/tables/${ORDERS_ID}/fields/${ORDERS.TOTAL}`,- );- // eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage- cy.findByText("Total").should("be.visible");- // eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage- cy.findByText("No description yet").should("be.visible");- });-- it("should allow analysts to edit field metadata but not preview data without data access", () => {- H.setUserAsAnalyst(NODATA_USER_ID);- cy.signIn("nodata");- H.DataModel.visitDataStudio({- databaseId: SAMPLE_DB_ID,- schemaId: SAMPLE_DB_SCHEMA_ID,- tableId: ORDERS_ID,- });-- TableSection.clickFieldsTab();- cy.log("change field name from table section");- TableSection.getFieldNameInput("Tax")- .clear()- .type("Analyst Tax Field")- .blur();- cy.wait("@updateField");- verifyAndCloseToast("Name of Tax updated");- TableSection.getFieldNameInput("Analyst Tax Field").should(- "be.visible",- );- TableSection.getField("Analyst Tax Field").should("be.visible");-- cy.log("change field description from table section");- TableSection.getFieldDescriptionInput("Total")- .clear()- .type("Analyst total description")- .blur();- cy.wait("@updateField");- verifyAndCloseToast("Description of Total updated");TableSection.getFieldDescriptionInput("Total").should("have.value",- "Analyst total description",+ "Total edited by analyst",);cy.log("navigate to field detail and change semantic type");@@ -321,20 +176,48 @@ describe("scenarios > data studio > datamodel", () => {.findByText("Sorry, you don’t have permission to see that.").should("be.visible");- cy.log("verify field changes in data reference as admin");+ cy.log("verify changes in data reference as admin");cy.signInAsAdmin();++ H.DataModel.visitDataStudio({+ databaseId: SAMPLE_DB_ID,+ schemaId: SAMPLE_DB_SCHEMA_ID,+ tableId: ORDERS_ID,+ });+ cy.log("snowplow event when dependency graph link is clicked");+ TableSection.getDependencyGraphLink().click();+ H.expectUnstructuredSnowplowEvent({+ event: "dependency_entity_selected",+ triggered_from: "data-structure",+ event_detail: "table",+ });++ cy.visit(`/reference/databases/${SAMPLE_DB_ID}/tables/${ORDERS_ID}`);+ cy.get("main").within(() => {+ cy.findByText("Analyst Orders").should("be.visible");+ cy.findByText("Description by analyst").should("be.visible");+ });+cy.visit(`/reference/databases/${SAMPLE_DB_ID}/tables/${ORDERS_ID}/fields/${ORDERS.TOTAL}`,);cy.get("main").within(() => {cy.findByText("Total").should("be.visible");- cy.findByText("Analyst total description").should("be.visible");+ cy.findByText("Total edited by analyst").should("be.visible");});- cy.log("verify field changes in table visualization as normal user");+ cy.log("verify changes in question picker as normal user");cy.signInAsNormalUser();+ H.startNewQuestion();+ H.miniPicker().within(() => {+ cy.findByText("Sample Database").click();+ cy.findByText("People").should("be.visible");+ cy.findByText("Analyst Orders").should("be.visible");+ });++ cy.log("verify field changes in table visualization");H.openOrdersTable();- H.tableHeaderColumn("Analyst Tax Field").should("be.visible");+ H.tableHeaderColumn("Analyst Tax").should("be.visible");H.tableHeaderColumn("Tax", { scrollIntoView: false }).should("not.exist",);@@ -343,134 +226,25 @@ describe("scenarios > data studio > datamodel", () => {});describe("Sorting", () => {- it("should allow sorting fields as in the database", () => {+ it("should allow sorting fields as in the database, by drag & drop with a switch back to a predefined order (metabase#56482), alphabetically, and smartly", () => {+ cy.log("database order");H.DataModel.visitDataStudio({databaseId: SAMPLE_DB_ID,schemaId: SAMPLE_DB_SCHEMA_ID,tableId: PRODUCTS_ID,});- TableSection.clickFieldsTab();- TableSection.getSortButton().click();- TableSection.getSortOrderInput()- .findByDisplayValue("database")- .should("be.checked");-- H.openProductsTable();- H.assertTableData({- columns: [- "ID",- "Ean",- "Title",- "Category",- "Vendor",- "Price",- "Rating",- "Created At",- ],- });- });-- it("should allow sorting fields alphabetically", () => {- H.DataModel.visitDataStudio({- databaseId: SAMPLE_DB_ID,- schemaId: SAMPLE_DB_SCHEMA_ID,- tableId: PRODUCTS_ID,- });-- TableSection.clickFieldsTab();- TableSection.getSortButton().click();- TableSection.getSortOrderInput()- .findByLabelText("Alphabetical order")- .click();- cy.wait("@updateTable");- verifyAndCloseToast("Field order updated");- TableSection.getSortOrderInput()- .findByDisplayValue("alphabetical")- .should("be.checked");-- H.openProductsTable();- H.assertTableData({- columns: [- "Category",- "Created At",- "Ean",- "ID",- "Price",- "Rating",- "Title",- "Vendor",- ],- });- });-- it("should allow sorting fields smartly", () => {- H.DataModel.visitDataStudio({- databaseId: SAMPLE_DB_ID,- schemaId: SAMPLE_DB_SCHEMA_ID,- tableId: PRODUCTS_ID,- });-- TableSection.clickFieldsTab();- TableSection.getSortButton().click();- TableSection.getSortOrderInput().findByLabelText("Auto order").click();- cy.wait("@updateTable");- verifyAndCloseToast("Field order updated");- TableSection.getSortOrderInput()- .findByDisplayValue("smart")- .should("be.checked");-- H.openProductsTable();- H.assertTableData({- columns: [- "ID",- "Created At",- "Category",- "Ean",- "Price",- "Rating",- "Title",- "Vendor",- ],- });- });-- it("should allow sorting fields in the custom order", () => {- H.DataModel.visitDataStudio({- databaseId: SAMPLE_DB_ID,- schemaId: SAMPLE_DB_SCHEMA_ID,- tableId: PRODUCTS_ID,- });-- TableSection.clickFieldsTab();- TableSection.getSortButton().click();- TableSection.getSortOrderInput()- .findByDisplayValue("database")- .should("be.checked");-- TableSection.getSortableField("ID").as("dragElement");- H.moveDnDKitElementByAlias("@dragElement", {- vertical: 50,- });- cy.wait("@updateFieldOrder");- verifyAndCloseToast("Field order updated");-- cy.log(- "should not show loading state after an update (metabase#56482)",- );- cy.findByTestId("loading-indicator", { timeout: 0 }).should(- "not.exist",- );-+ TableSection.clickFieldsTab();+ TableSection.getSortButton().click();TableSection.getSortOrderInput()- .findByDisplayValue("custom")+ .findByDisplayValue("database").should("be.checked");H.openProductsTable();H.assertTableData({columns: [- "Ean","ID",+ "Ean","Title","Category","Vendor",@@ -479,9 +253,8 @@ describe("scenarios > data studio > datamodel", () => {"Created At",],});- });- it("should allow switching to predefined order after drag & drop (metabase#56482)", () => {+ cy.log("drag & drop order");H.DataModel.visitDataStudio({databaseId: SAMPLE_DB_ID,schemaId: SAMPLE_DB_SCHEMA_ID,@@ -551,320 +324,229 @@ describe("scenarios > data studio > datamodel", () => {expect($items[0].textContent).to.equal("Ean");expect($items[1].textContent).to.equal("ID");});- });- });- describe("Sync options", () => {- it("should allow to sync table schema, re-scan field values, and discard cached field values from the actions menu", () => {- cy.intercept("POST", "/api/data-studio/table/sync-schema").as(- "syncSchema",- );- cy.intercept("POST", "/api/data-studio/table/rescan-values").as(- "rescanValues",- );- cy.intercept("POST", "/api/data-studio/table/discard-values").as(- "discardValues",- );+ cy.log("should use the custom order in the query builder");+ H.openProductsTable();+ H.assertTableData({+ columns: [+ "Ean",+ "ID",+ "Title",+ "Category",+ "Vendor",+ "Price",+ "Rating",+ "Created At",+ ],+ });+ cy.log("alphabetical order");H.DataModel.visitDataStudio({databaseId: SAMPLE_DB_ID,schemaId: SAMPLE_DB_SCHEMA_ID,tableId: PRODUCTS_ID,});- cy.log("re-sync schema");- TableSection.getActionsMenuButton().click();- H.menu().findByText("Re-sync schema").click();- cy.wait("@syncSchema");- verifyAndCloseToast("Sync triggered");-- cy.log("re-scan field values");- TableSection.getActionsMenuButton().click();- H.menu().findByText("Re-scan field values").click();- cy.wait("@rescanValues");- verifyAndCloseToast("Scan triggered");-- cy.log("discard cached field values");- TableSection.getActionsMenuButton().click();- H.menu().findByText("Discard cached field values").click();- cy.wait("@discardValues");- verifyAndCloseToast("Discard triggered");- });- });- });-- describe("Field section", () => {- beforeEach(() => {- H.resetSnowplow();- H.enableTracking();- });-- afterEach(() => {- H.expectNoBadSnowplowEvents();- });+ TableSection.clickFieldsTab();+ TableSection.getSortButton().click();+ TableSection.getSortOrderInput()+ .findByLabelText("Alphabetical order")+ .click();+ cy.wait("@updateTable");+ verifyAndCloseToast("Field order updated");+ TableSection.getSortOrderInput()+ .findByDisplayValue("alphabetical")+ .should("be.checked");- describe("Metadata", () => {- it("should allow analysts to change the foreign key target without data access", () => {- H.setUserAsAnalyst(NODATA_USER_ID);- cy.signIn("nodata");+ H.openProductsTable();+ H.assertTableData({+ columns: [+ "Category",+ "Created At",+ "Ean",+ "ID",+ "Price",+ "Rating",+ "Title",+ "Vendor",+ ],+ });+ cy.log("smart order");H.DataModel.visitDataStudio({databaseId: SAMPLE_DB_ID,schemaId: SAMPLE_DB_SCHEMA_ID,- tableId: ORDERS_ID,- fieldId: ORDERS.USER_ID,- });-- FieldSection.getSemanticTypeFkTarget()- .should("have.value", "People → ID")- .click();- H.popover().within(() => {- cy.findByText("Reviews → ID").should("be.visible");- cy.findByText("Products → ID").click();- });- cy.wait("@updateField");- H.undoToast().should(- "contain.text",- "Semantic type of User ID updated",- );- FieldSection.getSemanticTypeFkTarget().should(- "have.value",- "Products → ID",- );-- cy.log("verify preview is blocked without data permissions");- FieldSection.getPreviewButton().click();- cy.wait("@dataset");- PreviewSection.get()- .findByText("Sorry, you don’t have permission to see that.")- .should("be.visible");-- cy.log("verify FK target change works in query builder as normal user");- cy.signInAsNormalUser();- H.openTable({- database: SAMPLE_DB_ID,- table: ORDERS_ID,- mode: "notebook",- });- cy.icon("join_left_outer").click();- H.miniPicker().within(() => {- cy.findByText("Sample Database").click();- cy.findByText("Products").click();+ tableId: PRODUCTS_ID,});- cy.findByLabelText("Left column").should("contain.text", "User ID");- });- });- describe("Behavior", () => {- describe("Display values", () => {- it("should allow analysts to change display values to use foreign key without data access", () => {- H.setUserAsAnalyst(NODATA_USER_ID);- cy.signIn("nodata");-- H.DataModel.visitDataStudio({- databaseId: SAMPLE_DB_ID,- schemaId: SAMPLE_DB_SCHEMA_ID,- tableId: REVIEWS_ID,- fieldId: REVIEWS.PRODUCT_ID,- });+ TableSection.clickFieldsTab();+ TableSection.getSortButton().click();+ TableSection.getSortOrderInput().findByLabelText("Auto order").click();+ cy.wait("@updateTable");+ verifyAndCloseToast("Field order updated");+ TableSection.getSortOrderInput()+ .findByDisplayValue("smart")+ .should("be.checked");- FieldSection.getDisplayValuesInput().click();- H.popover().findByText("Use foreign key").click();- H.popover().findByText("Title").click();- cy.wait("@updateFieldDimension");- H.undoToast().should(- "contain.text",- "Display values of Product ID updated",- );-- FieldSection.getDisplayValuesInput().should(- "have.value",- "Use foreign key",- );- FieldSection.getDisplayValuesFkTargetInput().should(- "have.value",+ H.openProductsTable();+ H.assertTableData({+ columns: [+ "ID",+ "Created At",+ "Category",+ "Ean",+ "Price",+ "Rating","Title",- );-- cy.log("verify preview is blocked without data permissions");- FieldSection.getPreviewButton().click();- cy.wait("@dataset");- PreviewSection.get()- .findByText("Sorry, you don’t have permission to see that.")- .should("be.visible");-- cy.log("verify display value change works as normal user");- cy.signInAsNormalUser();- H.openReviewsTable({ limit: 1 });- H.main().findByText("Rustic Paper Wallet").should("be.visible");- });-- it("should disable custom mapping for analysts without data access", () => {- H.setUserAsAnalyst(NODATA_USER_ID);- cy.signIn("nodata");-- H.DataModel.visitDataStudio({- databaseId: SAMPLE_DB_ID,- schemaId: SAMPLE_DB_SCHEMA_ID,- tableId: REVIEWS_ID,- fieldId: REVIEWS.RATING,- });-- cy.log("verify custom mapping is disabled without data access");- FieldSection.getDisplayValuesInput().click();- H.popover().within(() => {- cy.findByRole("option", { name: /Use original value/ })- .should("be.visible")- .and("not.have.attr", "data-combobox-disabled");- cy.findByRole("option", { name: /Custom mapping/ })- .should("be.visible")- .and("have.attr", "data-combobox-disabled", "true");- });-- cy.log("verify admin can set up custom mapping");- cy.signInAsAdmin();- H.DataModel.visitDataStudio({- databaseId: SAMPLE_DB_ID,- schemaId: SAMPLE_DB_SCHEMA_ID,- tableId: REVIEWS_ID,- fieldId: REVIEWS.RATING,- });- FieldSection.getDisplayValuesInput().click();- H.popover().findByText("Custom mapping").click();- cy.wait("@updateFieldValues");- H.undoToast().should(- "contain.text",- "Display values of Rating updated",- );- H.undoToast().icon("close").click({ force: true });-- H.modal().within(() => {- cy.findByDisplayValue("1").click().clear().type("Terrible");- cy.findByDisplayValue("5").click().clear().type("Amazing");- cy.button("Save").click();- });- cy.wait("@updateFieldValues");- H.undoToast().should(- "contain.text",- "Display values of Rating updated",- );-- cy.log("verify custom mapping works as normal user");- cy.signInAsNormalUser();- H.openReviewsTable();- H.main().findByText("Terrible").should("be.visible");- H.main().findAllByText("Amazing").should("be.visible");+ "Vendor",+ ],});});});});- describe("Preview section", () => {- describe("Esc key", () => {- it("should allow closing the preview with Esc key", () => {- H.DataModel.visitDataStudio({- databaseId: SAMPLE_DB_ID,- schemaId: SAMPLE_DB_SCHEMA_ID,- tableId: ORDERS_ID,- fieldId: ORDERS.PRODUCT_ID,- });+ describe("Field section", () => {+ beforeEach(() => {+ H.enableTracking();+ });- PreviewSection.get().should("not.exist");+ afterEach(() => {+ H.expectNoBadSnowplowEvents();+ });- FieldSection.getPreviewButton().click();- PreviewSection.get().scrollIntoView().should("be.visible");+ it("should allow analysts without data access to change field metadata but not set up custom mapping", () => {+ H.setUserAsAnalyst(NODATA_USER_ID);+ cy.signIn("nodata");- cy.realPress("Escape");- PreviewSection.get().should("not.exist");+ cy.log("change the foreign key target as analyst");+ H.DataModel.visitDataStudio({+ databaseId: SAMPLE_DB_ID,+ schemaId: SAMPLE_DB_SCHEMA_ID,+ tableId: ORDERS_ID,+ fieldId: ORDERS.USER_ID,});- it("should not close the preview when hitting Esc key while modal is open", () => {- H.DataModel.visitDataStudio({- databaseId: SAMPLE_DB_ID,- schemaId: SAMPLE_DB_SCHEMA_ID,- tableId: ORDERS_ID,- fieldId: ORDERS.PRODUCT_ID,- });-- FieldSection.getPreviewButton().click();- PreviewSection.get().scrollIntoView().should("be.visible");-- FieldSection.getFieldValuesButton().click();- H.modal().should("be.visible");-- cy.realPress("Escape");- H.modal().should("not.exist");- PreviewSection.get().should("be.visible");+ FieldSection.getSemanticTypeFkTarget()+ .should("have.value", "People → ID")+ .click();+ H.popover().within(() => {+ cy.findByText("Reviews → ID").should("be.visible");+ cy.findByText("Products → ID").click();});+ cy.wait("@updateField");+ H.undoToast().should("contain.text", "Semantic type of User ID updated");+ FieldSection.getSemanticTypeFkTarget().should(+ "have.value",+ "Products → ID",+ );- it("should not close the preview when hitting Esc key while popover is open", () => {- H.DataModel.visitDataStudio({- databaseId: SAMPLE_DB_ID,- schemaId: SAMPLE_DB_SCHEMA_ID,- tableId: ORDERS_ID,- fieldId: ORDERS.PRODUCT_ID,- });-- FieldSection.getPreviewButton().click();- PreviewSection.get().scrollIntoView().should("be.visible");-- FieldSection.getSemanticTypeInput().click();- H.popover().should("be.visible");+ cy.log("verify preview is blocked without data permissions");+ FieldSection.getPreviewButton().click();+ cy.wait("@dataset");+ PreviewSection.get()+ .findByText("Sorry, you don’t have permission to see that.")+ .should("be.visible");- cy.realPress("Escape");- H.popover({ skipVisibilityCheck: true }).should("not.be.visible");- PreviewSection.get().scrollIntoView().should("be.visible");+ cy.log("change display values to use foreign key as analyst");+ H.DataModel.visitDataStudio({+ databaseId: SAMPLE_DB_ID,+ schemaId: SAMPLE_DB_SCHEMA_ID,+ tableId: REVIEWS_ID,+ fieldId: REVIEWS.PRODUCT_ID,});- it("should not close the preview when hitting Esc key while command palette is open", () => {- H.DataModel.visitDataStudio({- databaseId: SAMPLE_DB_ID,- schemaId: SAMPLE_DB_SCHEMA_ID,- tableId: ORDERS_ID,- fieldId: ORDERS.PRODUCT_ID,- });+ FieldSection.getDisplayValuesInput().click();+ H.popover().findByText("Use foreign key").click();+ H.popover().findByText("Title").click();+ cy.wait("@updateFieldDimension");+ H.undoToast().should(+ "contain.text",+ "Display values of Product ID updated",+ );- FieldSection.getPreviewButton().click();- PreviewSection.get().scrollIntoView().should("be.visible");+ FieldSection.getDisplayValuesInput().should(+ "have.value",+ "Use foreign key",+ );+ FieldSection.getDisplayValuesFkTargetInput().should(+ "have.value",+ "Title",+ );- H.openCommandPalette();- H.commandPalette().should("be.visible");+ cy.log("verify preview is blocked without data permissions");+ FieldSection.getPreviewButton().click();+ cy.wait("@dataset");+ PreviewSection.get()+ .findByText("Sorry, you don’t have permission to see that.")+ .should("be.visible");- cy.realPress("Escape");- H.commandPalette().should("not.exist");- PreviewSection.get().should("be.visible");+ cy.log("verify custom mapping is disabled without data access");+ H.DataModel.visitDataStudio({+ databaseId: SAMPLE_DB_ID,+ schemaId: SAMPLE_DB_SCHEMA_ID,+ tableId: REVIEWS_ID,+ fieldId: REVIEWS.RATING,});- });- describe("Empty states", { tags: "@external" }, () => {- beforeEach(() => {- H.restore("postgres-writable");- H.activateToken("pro-self-hosted");- H.resetTestTable({ type: "postgres", table: "multi_schema" });- H.resyncDatabase({ dbId: WRITABLE_DB_ID });- H.queryWritableDB('delete from "Domestic"."Animals"');+ FieldSection.getDisplayValuesInput().click();+ H.popover().within(() => {+ cy.findByRole("option", { name: /Use original value/ })+ .should("be.visible")+ .and("not.have.attr", "data-combobox-disabled");+ cy.findByRole("option", { name: /Custom mapping/ })+ .should("be.visible")+ .and("have.attr", "data-combobox-disabled", "true");});- it("should show empty state when there is no data", () => {- H.DataModel.visitDataStudio();+ cy.log("verify admin can set up custom mapping");+ cy.signInAsAdmin();+ H.DataModel.visitDataStudio({+ databaseId: SAMPLE_DB_ID,+ schemaId: SAMPLE_DB_SCHEMA_ID,+ tableId: REVIEWS_ID,+ fieldId: REVIEWS.RATING,+ });+ FieldSection.getDisplayValuesInput().click();+ H.popover().findByText("Custom mapping").click();+ cy.wait("@updateFieldValues");+ H.undoToast().should("contain.text", "Display values of Rating updated");+ H.undoToast().icon("close").click({ force: true });++ H.modal().within(() => {+ cy.findByDisplayValue("1").click().clear().type("Terrible");+ cy.findByDisplayValue("5").click().clear().type("Amazing");+ cy.button("Save").click();+ });+ cy.wait("@updateFieldValues");+ H.undoToast().should("contain.text", "Display values of Rating updated");++ cy.log("verify FK target change works in query builder as normal user");+ cy.signInAsNormalUser();+ H.openTable({+ database: SAMPLE_DB_ID,+ table: ORDERS_ID,+ mode: "notebook",+ });+ cy.icon("join_left_outer").click();+ H.miniPicker().within(() => {+ cy.findByText("Sample Database").click();+ cy.findByText("Products").click();+ });+ cy.findByLabelText("Left column").should("contain.text", "User ID");- TablePicker.getDatabase("Writable Postgres12").click();- TablePicker.getSchema("Domestic").click();- TablePicker.getTable("Animals").click();- TableSection.clickFieldsTab();- TableSection.clickField("Name");- FieldSection.getPreviewButton().click();+ cy.log("verify display value change works as normal user");+ H.openReviewsTable({ limit: 1 });+ H.main().findByText("Rustic Paper Wallet").should("be.visible");- PreviewSection.get()- .scrollIntoView()- .findByText("No data to show")- .should("be.visible");- PreviewSection.getPreviewTypeInput().findByText("Detail").click();- PreviewSection.get().findByText("No data to show").should("be.visible");- });+ cy.log("verify custom mapping works as normal user");+ H.openReviewsTable();+ H.main().findByText("Terrible").should("be.visible");+ H.main().findAllByText("Amazing").should("be.visible");});+ });- it("should not auto-focus inputs in filtering preview", () => {+ describe("Preview section", () => {+ it("should close the preview with Esc key only when no overlay is open, and not auto-focus inputs in filtering preview", () => {H.DataModel.visitDataStudio({databaseId: SAMPLE_DB_ID,schemaId: SAMPLE_DB_SCHEMA_ID,@@ -872,7 +554,45 @@ describe("scenarios > data studio > datamodel", () => {fieldId: ORDERS.PRODUCT_ID,});+ cy.log("close the preview with Esc key");+ PreviewSection.get().should("not.exist");++ FieldSection.getPreviewButton().click();+ PreviewSection.get().scrollIntoView().should("be.visible");++ cy.realPress("Escape");+ PreviewSection.get().should("not.exist");++ cy.log("do not close the preview with Esc key while modal is open");FieldSection.getPreviewButton().click();+ PreviewSection.get().scrollIntoView().should("be.visible");++ FieldSection.getFieldValuesButton().click();+ H.modal().should("be.visible");++ cy.realPress("Escape");+ H.modal().should("not.exist");+ PreviewSection.get().should("be.visible");++ cy.log(+ "do not close the preview with Esc key while command palette is open",+ );+ H.openCommandPalette();+ H.commandPalette().should("be.visible");++ cy.realPress("Escape");+ H.commandPalette().should("not.exist");+ PreviewSection.get().should("be.visible");++ cy.log("do not close the preview with Esc key while popover is open");+ FieldSection.getSemanticTypeInput().click();+ H.popover().should("be.visible");++ cy.realPress("Escape");+ H.popover({ skipVisibilityCheck: true }).should("not.be.visible");+ PreviewSection.get().scrollIntoView().should("be.visible");++ cy.log("do not auto-focus inputs in filtering preview");PreviewSection.getPreviewTypeInput().findByText("Filtering").click();PreviewSection.get()@@ -903,32 +623,9 @@ describe("scenarios > data studio > datamodel", () => {.should("be.visible").and("not.be.focused");});-- it("should not crash when viewing filtering preview of a hidden table", () => {- H.DataModel.visitDataStudio({- databaseId: SAMPLE_DB_ID,- schemaId: SAMPLE_DB_SCHEMA_ID,- tableId: ORDERS_ID,- });-- TableSection.clickDetailsTab();- H.DataModel.TableSection.getVisibilityTypeInput().click();- H.popover().findByText("Hidden").click();- cy.wait("@updateTable");-- H.DataModel.TableSection.clickFieldsTab();- H.DataModel.TableSection.clickField("Product ID");-- FieldSection.getPreviewButton().click();- PreviewSection.getPreviewTypeInput().findByText("Filtering").click();- PreviewSection.get()- .findByPlaceholderText("Enter an ID")- .should("be.visible");- H.main().findByText("Something’s gone wrong").should("not.exist");- });});- it("should allow you to close table and field details", () => {+ it("should allow you to close table and field details, clear a field description, and use sync options, also for a hidden table", () => {H.DataModel.visitDataStudio({databaseId: SAMPLE_DB_ID,schemaId: SAMPLE_DB_SCHEMA_ID,@@ -955,12 +652,134 @@ describe("scenarios > data studio > datamodel", () => {TablePicker.getTable("Orders").click();TableSection.clickFieldsTab();TableSection.clickField("Subtotal");+ FieldSection.getNameInput().should("have.value", "Subtotal");PreviewSection.get().should("not.exist");FieldSection.get().should("exist");TableSection.get().should("exist");++ cy.log("clear the field description");+ H.DataModel.visitDataStudio({+ databaseId: SAMPLE_DB_ID,+ schemaId: SAMPLE_DB_SCHEMA_ID,+ tableId: ORDERS_ID,+ });++ TableSection.clickFieldsTab();+ TableSection.getFieldDescriptionInput("Total").clear().blur();+ cy.wait("@updateField");+ verifyAndCloseToast("Description of Total updated");+ TableSection.getFieldDescriptionInput("Total").should("have.value", "");++ cy.log("verify preview");+ TableSection.clickField("Total");+ FieldSection.getPreviewButton().click();+ verifyTablePreview({+ column: "Total",+ values: ["39.72", "117.03", "49.21", "115.23", "134.91"],+ });+ PreviewSection.get().findByTestId("header-cell").realHover();+ H.hovercard()+ .should("contain.text", "No description")+ .and("not.contain.text", "The total billed amount.");++ cy.visit(+ `/reference/databases/${SAMPLE_DB_ID}/tables/${ORDERS_ID}/fields/${ORDERS.TOTAL}`,+ );+ // eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage+ cy.findByText("Total").should("be.visible");+ // eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage+ cy.findByText("No description yet").should("be.visible");++ cy.log("sync options from the actions menu");+ cy.intercept("POST", "/api/data-studio/table/sync-schema").as("syncSchema");+ cy.intercept("POST", "/api/data-studio/table/rescan-values").as(+ "rescanValues",+ );+ cy.intercept("POST", "/api/data-studio/table/discard-values").as(+ "discardValues",+ );++ H.DataModel.visitDataStudio({+ databaseId: SAMPLE_DB_ID,+ schemaId: SAMPLE_DB_SCHEMA_ID,+ tableId: PRODUCTS_ID,+ });++ cy.log("re-sync schema");+ TableSection.getActionsMenuButton().click();+ H.menu().findByText("Re-sync schema").click();+ cy.wait("@syncSchema");+ verifyAndCloseToast("Sync triggered");++ cy.log("re-scan field values");+ TableSection.getActionsMenuButton().click();+ H.menu().findByText("Re-scan field values").click();+ cy.wait("@rescanValues");+ verifyAndCloseToast("Scan triggered");++ cy.log("discard cached field values");+ TableSection.getActionsMenuButton().click();+ H.menu().findByText("Discard cached field values").click();+ cy.wait("@discardValues");+ verifyAndCloseToast("Discard triggered");++ cy.log("should not crash when viewing filtering preview of a hidden table");+ H.DataModel.visitDataStudio({+ databaseId: SAMPLE_DB_ID,+ schemaId: SAMPLE_DB_SCHEMA_ID,+ tableId: ORDERS_ID,+ });++ TableSection.clickDetailsTab();+ TableSection.getVisibilityTypeInput().click();+ H.popover().findByText("Hidden").click();+ cy.wait("@updateTable");++ TableSection.clickFieldsTab();+ TableSection.clickField("Product ID");++ FieldSection.getPreviewButton().click();+ PreviewSection.getPreviewTypeInput().findByText("Filtering").click();+ PreviewSection.get()+ .findByPlaceholderText("Enter an ID")+ .should("be.visible");+ H.main().findByText("Something’s gone wrong").should("not.exist");});});+describe(+ "scenarios > data studio > datamodel > preview empty states",+ { tags: "@external" },+ () => {+ beforeEach(() => {+ H.restore("postgres-writable");+ cy.signInAsAdmin();+ H.activateToken("pro-self-hosted");+ H.resetTestTable({ type: "postgres", table: "multi_schema" });+ H.resyncDatabase({ dbId: WRITABLE_DB_ID });+ H.queryWritableDB('delete from "Domestic"."Animals"');+ });++ it("should show empty state when there is no data", () => {+ H.DataModel.visitDataStudio();++ TablePicker.getDatabase("Writable Postgres12").click();+ TablePicker.getSchema("Domestic").click();+ TablePicker.getTable("Animals").click();+ TableSection.clickFieldsTab();+ TableSection.clickField("Name");+ FieldSection.getPreviewButton().click();++ PreviewSection.get()+ .scrollIntoView()+ .findByText("No data to show")+ .should("be.visible");+ PreviewSection.getPreviewTypeInput().findByText("Detail").click();+ PreviewSection.get().findByText("No data to show").should("be.visible");+ });+ },+);+type TableSummary = {id: TableId;db_id: number;@@ -1058,11 +877,9 @@ function verifyAndCloseToast(message: string) {function verifyTablePreview({column,- description,values,}: {column: string;- description?: string;values: string[];}) {PreviewSection.getPreviewTypeInput().findByText("Table").click();@@ -1073,13 +890,5 @@ function verifyTablePreview({columns: [column],firstRows: values.map((value) => [value]),});-- if (description != null) {- cy.findByTestId("header-cell").realHover();- }});-- if (description != null) {- H.hovercard().should("contain.text", description);- }}diff --git a/e2e/test/scenarios/data-studio/data-model/model-to-transform.cy.spec.ts b/e2e/test/scenarios/data-studio/data-model/model-to-transform.cy.spec.tsindex f4d9702034f..7ba90f4e6cb 100644--- a/e2e/test/scenarios/data-studio/data-model/model-to-transform.cy.spec.ts+++ b/e2e/test/scenarios/data-studio/data-model/model-to-transform.cy.spec.ts@@ -13,6 +13,8 @@ const MIGRATE_MODELS_PATH = "/data-studio/transforms/tools/migrate-models";const SOURCE_ROW_NAME = "Source Row Alpha";const SOURCE_ROW_NAME_2 = "Source Row Beta";+// The transform output does not get this row, because it is inserted after the conversion.+const SOURCE_ROW_NAME_NEW = "Source Row Gamma";const CATEGORY_FILTER_ID = "mtt-category-filter";@@ -33,140 +35,123 @@ describe().as("replaceModelWithTransform");});- describe("Successful conversions", () => {- it("updates direct and nested questions built on the converted model", () => {- createTestTables();- createSourceModel("Target model").then(({ body: model }) => {- createQuestionOnModel("Direct dependent", model.id).as("direct");- createQuestionOnCard("Nested dependent", model.id).then(- ({ body: parent }) => {- H.createQuestion({- name: "Second level nested",- database: WRITABLE_DB_ID,- query: { "source-table": `card__${parent.id}` },- }).as("secondLevel");- },- );- });-- convertModelToTransform("Target model");-- cy.log("direct dependent now reads from the transform's output table");- cy.get<Cypress.Response<{ id: CardId }>>("@direct").then(({ body }) => {- H.visitQuestion(body.id);- assertSourceRowsVisible();- H.openNotebook();- assertDataSourceIs(OUTPUT_TABLE_LABEL);- });-- cy.log("two-level nested question still runs after the swap");- cy.get<Cypress.Response<{ id: CardId }>>("@secondLevel").then(- ({ body }) => {- H.visitQuestion(body.id);- assertSourceRowsVisible();+ it("converts a model to a transform and rewires all its dependents", () => {+ createTestTables();+ H.createQuestion({+ name: "Sample DB model",+ database: SAMPLE_DB_ID,+ type: "model",+ query: { "source-table": SAMPLE_DATABASE.ORDERS_ID },+ });+ createSourceModel("Target model").then(({ body: model }) => {+ createQuestionOnModel("Direct dependent", model.id).as("direct");+ createQuestionOnModel("Nested dependent", model.id)+ .as("nested")+ .then(({ body: parent }) => {+ H.createQuestion({+ name: "Second level nested",+ database: WRITABLE_DB_ID,+ query: { "source-table": `card__${parent.id}` },+ }).as("secondLevel");+ });+ createFilteredDashboardOnModel(model.id).as("dashboardInfo");+ H.createQuestion({+ name: "Amount sum metric",+ database: WRITABLE_DB_ID,+ type: "metric",+ query: {+ "source-table": `card__${model.id}`,+ aggregation: [+ ["sum", ["field", "amount", { "base-type": "type/Decimal" }]],+ ],},- );+ }).as("metric");+ createQuestionJoiningModel("Joined question", model.id).as("joined");});- it("creates a transform that can be opened and queries the original source table", () => {- createTestTables();- createSourceModel("Transform source model");-- convertModelToTransform("Transform source model");+ cy.log(+ "trigger is disabled when the database doesn't support transforms",+ );+ openMigrateModelsPage();+ selectModelInTable("Sample DB model");+ cy.findByTestId("model-sidebar")+ .findByRole("button", { name: /Convert to a transform/ })+ .should("be.disabled");- cy.log("new transform appears on the transform list and opens cleanly");- cy.visit("/data-studio/transforms");- H.main().findByText("Transform source model").click();- assertDataSourceIs(SOURCE_TABLE_LABEL);+ cy.log("convert the model");+ selectModelInTable("Target model");+ openReplaceWithTransformModal();+ submitReplaceWithTransformForm();+ waitForReplacementToComplete();+ insertNewSourceRow();++ cy.log("direct dependent now reads from the transform's output table");+ cy.get<Cypress.Response<{ id: CardId }>>("@direct").then(({ body }) => {+ H.visitQuestion(body.id);+ assertOutputRowsVisible();+ H.openNotebook();+ assertDataSourceIs(OUTPUT_TABLE_LABEL);});- it("keeps a dashboard with a parameter filter working after conversion", () => {- createTestTables();- createSourceModel("Dashboard model").then(({ body: model }) => {- createFilteredDashboardOnModel(model.id).as("dashboardInfo");- });+ cy.log("nested dependent now reads from the transform's output table");+ cy.get<Cypress.Response<{ id: CardId }>>("@nested").then(({ body }) => {+ H.visitQuestion(body.id);+ assertOutputRowsVisible();+ });- convertModelToTransform("Dashboard model");+ cy.log("two-level nested question reads the transform's output table");+ cy.get<Cypress.Response<{ id: CardId }>>("@secondLevel").then(+ ({ body }) => {+ H.visitQuestion(body.id);+ assertOutputRowsVisible();+ },+ );- cy.get<{ dashboard_id: number; card_id: CardId }>(- "@dashboardInfo",- ).then(({ dashboard_id, card_id }) => {+ cy.get<{ dashboard_id: number; card_id: CardId }>("@dashboardInfo").then(+ ({ dashboard_id, card_id }) => {cy.log("dashboard still renders after conversion");H.visitDashboard(dashboard_id);H.main().findByText(SOURCE_ROW_NAME).should("be.visible");H.main().findByText(SOURCE_ROW_NAME_2).should("be.visible");+ H.main().findByText(SOURCE_ROW_NAME_NEW).should("not.exist");cy.log("filter widget still narrows the results");H.toggleFilterWidgetValues(["A"]);H.main().findByText(SOURCE_ROW_NAME).should("be.visible");H.main().findByText(SOURCE_ROW_NAME_2).should("not.exist");- cy.log("the underlying question now points to the transform output");+ cy.log("the dashboard question now points to the transform output");H.visitQuestion(card_id);H.openNotebook();assertDataSourceIs(OUTPUT_TABLE_LABEL);- });- });-- it("keeps a metric built on the model producing the same result", () => {- createTestTables();- createSourceModel("Metric base model").then(({ body: model }) => {- H.createQuestion({- name: "Amount sum metric",- database: WRITABLE_DB_ID,- type: "metric",- query: {- "source-table": `card__${model.id}`,- aggregation: [- ["sum", ["field", "amount", { "base-type": "type/Decimal" }]],- ],- },- }).as("metric");- });-- convertModelToTransform("Metric base model");-- cy.get<Cypress.Response<{ id: CardId }>>("@metric").then(({ body }) => {- H.visitMetric(body.id);- H.main().findByText("301.25").should("be.visible");- });- });-- it("keeps a joined question working after converting its joined model", () => {- createTestTables();- createSourceModel("Joined model").then(({ body: model }) => {- createQuestionJoiningModel("Joined question", model.id).as("joined");- });-- convertModelToTransform("Joined model");+ },+ );- cy.get<Cypress.Response<{ id: CardId }>>("@joined").then(({ body }) => {- H.visitQuestion(body.id);- assertSourceRowsVisible();- });+ cy.get<Cypress.Response<{ id: CardId }>>("@metric").then(({ body }) => {+ cy.log("the metric sum does not include the row added to the source");+ H.visitMetric(body.id);+ H.main().findByText("301.25").should("be.visible");});- });- it("disables the trigger when the model's database doesn't support transforms", () => {- H.createQuestion({- name: "Sample DB model",- database: SAMPLE_DB_ID,- type: "model",- query: { "source-table": SAMPLE_DATABASE.ORDERS_ID },+ cy.get<Cypress.Response<{ id: CardId }>>("@joined").then(({ body }) => {+ cy.log("joined question still runs");+ H.visitQuestion(body.id);+ assertSourceRowsVisible();++ cy.log("the join now reads from the transform's output table");+ H.openNotebook();+ H.getNotebookStep("join")+ .findByLabelText("Right table")+ .findByText(OUTPUT_TABLE_LABEL)+ .should("be.visible");});- openMigrateModelsPage();- selectModelInTable("Sample DB model");-- cy.findByTestId("model-sidebar")- .findByRole("button", { name: /Convert to a transform/ })- .should("be.disabled");- });-- it("non-admin users cannot access the migrate models page", () => {- createTestTables();- createSourceModel("Access test model");+ cy.log("new transform appears on the transform list and opens cleanly");+ cy.visit("/data-studio/transforms");+ H.main().findByText("Target model").click();+ assertDataSourceIs(SOURCE_TABLE_LABEL);+ cy.log("non-admin users cannot access the migrate models page");cy.signInAsNormalUser();cy.visit(MIGRATE_MODELS_PATH);H.main()@@ -230,14 +215,6 @@ function createQuestionOnModel(name: string, modelId: CardId) {});}-function createQuestionOnCard(name: string, parentCardId: CardId) {- return H.createQuestion({- name,- database: WRITABLE_DB_ID,- query: { "source-table": `card__${parentCardId}` },- });-}-function createQuestionJoiningModel(name: string, modelId: CardId) {return getTableId(SOURCE_TABLE).then((sourceTableId) =>H.getFieldId({ tableId: sourceTableId, name: "id" }).then((sourceIdField) =>@@ -356,7 +333,7 @@ function getSubmitButton() {function waitForReplacementToComplete() {const POLL_INTERVAL_MS = 250;- const POLL_TIMEOUT_MS = 30_000;+ const POLL_TIMEOUT_MS = 60_000;const MAX_ATTEMPTS = POLL_TIMEOUT_MS / POLL_INTERVAL_MS;cy.wait("@replaceModelWithTransform").then((interception) => {@@ -384,15 +361,7 @@ function waitForReplacementToComplete() {return pollStatus();});- H.resyncDatabase({ dbId: WRITABLE_DB_ID });-}--function convertModelToTransform(modelName: string) {- openMigrateModelsPage();- selectModelInTable(modelName);- openReplaceWithTransformModal();- submitReplaceWithTransformForm();- waitForReplacementToComplete();+ H.resyncDatabase({ dbId: WRITABLE_DB_ID, tableName: OUTPUT_TABLE_SLUG });}function assertSourceRowsVisible() {@@ -400,6 +369,18 @@ function assertSourceRowsVisible() {H.main().findAllByText(SOURCE_ROW_NAME_2).first().should("be.visible");}+function insertNewSourceRow() {+ H.queryWritableDB(+ `INSERT INTO ${SOURCE_TABLE} VALUES (3, '${SOURCE_ROW_NAME_NEW}', 999.00, 'C');`,+ "postgres",+ );+}++function assertOutputRowsVisible() {+ assertSourceRowsVisible();+ H.main().findByText(SOURCE_ROW_NAME_NEW).should("not.exist");+}+function assertDataSourceIs(tableLabel: string) {cy.findByTestId("data-step-cell").should("have.text", tableLabel);}diff --git a/e2e/test/scenarios/data-studio/data-model/segments-data-studio.cy.spec.ts b/e2e/test/scenarios/data-studio/data-model/segments-data-studio.cy.spec.tsindex 1b9fb654cb5..a1cf27449e7 100644--- a/e2e/test/scenarios/data-studio/data-model/segments-data-studio.cy.spec.ts+++ b/e2e/test/scenarios/data-studio/data-model/segments-data-studio.cy.spec.ts@@ -19,52 +19,11 @@ describe(cy.intercept("POST", "/api/segment").as("createSegment");cy.intercept("PUT", "/api/segment/*").as("updateSegment");- cy.intercept("DELETE", "/api/segment/*").as("deleteSegment");cy.intercept("GET", "/api/table/*/query_metadata*").as("metadata");});- describe("Segment list", () => {- it("should show empty state and navigation when no segments exist", () => {- visitDataStudioSegments(ORDERS_ID);-- cy.log("verify empty state");- SegmentList.getEmptyState().scrollIntoView().should("be.visible");- SegmentList.get()- .findByText("Create a segment to filter rows in this table.")- .should("be.visible");-- cy.log("verify new segment link and navigation");- SegmentList.getNewSegmentLink().scrollIntoView().click();-- cy.url().should("include", `${getSegmentsBaseUrl(ORDERS_ID)}/new`);- });-- it("should display segments and allow navigation to edit page", () => {- createTestSegment({- name: "High Value Orders",- filter: [">", ["field", ORDERS.TOTAL, null], 100],- });- visitDataStudioSegments(ORDERS_ID);-- cy.log("verify segment in list with filter description");- SegmentList.getSegment("High Value Orders")- .scrollIntoView()- .should("be.visible");- SegmentList.get()- .findByTestId("list-item-description")- .should("contain", "Filtered by Total is greater than 100");-- cy.log("navigate to edit page");- SegmentList.getSegment("High Value Orders").click();- cy.get<number>("@segmentId").then((segmentId) => {- cy.url().should(- "include",- `${getSegmentsBaseUrl(ORDERS_ID)}/${segmentId}`,- );- });- });-- it("should navigate between Fields and Segments tabs", () => {+ describe("Segment list and creation", () => {+ it("should navigate between Fields and Segments tabs, show empty state, guard unsaved changes, and create a segment with filters", () => {visitDataStudioTable(ORDERS_ID);cy.log("verify both tabs visible");@@ -89,15 +48,18 @@ describe(cy.log("navigate back to fields tab");cy.findByRole("tab", { name: /Fields/i }).click();cy.url().should("include", "/field");- });- });- describe("Segment creation", () => {- it("should create a segment with filters and verify across features", () => {visitDataStudioSegments(ORDERS_ID);+ cy.log("verify empty state");+ SegmentList.getEmptyState().scrollIntoView().should("be.visible");+ SegmentList.get()+ .findByText("Create a segment to filter rows in this table.")+ .should("be.visible");+cy.log("navigate to new segment page");SegmentList.getNewSegmentLink().scrollIntoView().click();+ cy.url().should("include", `${getSegmentsBaseUrl(ORDERS_ID)}/new`);cy.log("verify segment_create_started event was tracked");H.expectUnstructuredSnowplowEvent({@@ -109,6 +71,14 @@ describe(cy.log("fill in segment name");SegmentEditor.getNameInput().type("Premium Orders");+ cy.log("attempt to navigate away with unsaved changes");+ SegmentEditor.getBreadcrumb("Orders").click();+ H.modal().within(() => {+ cy.findByText("Discard your changes?").should("be.visible");+ cy.button("Cancel").click();+ });+ SegmentEditor.get().findByText("Premium Orders").should("be.visible");+cy.log("add filter");SegmentEditor.getFilterPlaceholder().click();H.popover().findByText("Total").click();@@ -146,33 +116,10 @@ describe(cy.log("verify segment in query builder");verifySegmentInQueryBuilder("Premium Orders");});-- it("should add filter and show preview in menu", () => {- visitDataStudioSegments(PRODUCTS_ID);-- SegmentList.getNewSegmentLink().scrollIntoView().click();-- SegmentEditor.getFilterPlaceholder().click();- H.popover().findByText("Price").click();- H.selectFilterOperator("Less than");- H.popover().within(() => {- cy.findByLabelText("Filter value").type("50");- cy.button("Add filter").click();- });-- cy.log("verify filter was added");- SegmentEditor.get()- .findByText(/Price is less than 50/i)- .should("exist");-- cy.log("verify preview is available in menu");- SegmentEditor.getActionsButton().click();- H.popover().findByText("Preview").should("be.visible");- });});describe("Segment editing", () => {- it("should display and update existing segment", () => {+ it("should update an existing segment, navigate back via breadcrumb, and use a segment based on another segment", () => {createTestSegment({name: "Test Segment",description: "Test description",@@ -204,19 +151,10 @@ describe(SegmentEditor.getDescriptionInput().clear().type("Updated description");SegmentEditor.getSaveButton().click();cy.wait("@updateSegment");+ SegmentEditor.getSaveButton().should("not.exist");- cy.log("verify updated segment in query builder");- verifySegmentInQueryBuilder("Test Segment Updated");- });-- it("should navigate back to segments tab via breadcrumb", () => {- createTestSegment({ name: "Breadcrumb Test Segment" });- cy.get<number>("@segmentId").then((segmentId) => {- visitDataModelSegment(ORDERS_ID, segmentId);- });-+ cy.log("navigate back to segments tab via breadcrumb");SegmentEditor.getBreadcrumb("Orders").click();-cy.url().should("include",`/data-studio/data/database/${SAMPLE_DB_ID}/schema/${SAMPLE_DB_SCHEMA_ID}/table/${ORDERS_ID}/segments`,@@ -224,17 +162,81 @@ describe(cy.findByRole("tab", { name: /Segments/i }).scrollIntoView().should("have.attr", "aria-selected", "true");++ cy.log("verify updated segment in query builder");+ verifySegmentInQueryBuilder("Test Segment Updated");++ cy.log("create base segment");+ createTestSegment({+ name: "High Value Orders",+ filter: [">", ["field", ORDERS.TOTAL, null], 100],+ });++ cy.get<number>("@segmentId").then((baseSegmentId) => {+ cy.log("create segment based on segment");+ H.createSegment({+ name: "High Value Recent Orders",+ definition: {+ type: "query",+ database: SAMPLE_DB_ID,+ query: {+ "source-table": ORDERS_ID,+ filter: [+ "and",+ ["segment", baseSegmentId],+ [">", ["field", ORDERS.CREATED_AT, null], "2020-01-01"],+ ],+ },+ },+ });+ });++ cy.log("verify both segments appear in query builder");+ verifySegmentInQueryBuilder("High Value Orders");+ H.openTable({ table: ORDERS_ID, mode: "notebook" });+ H.getNotebookStep("data").button("Filter").click();+ H.popover().findByText("High Value Recent Orders").should("be.visible");++ cy.log("verify dependent segment works");+ H.popover().findByText("High Value Recent Orders").click();+ H.visualize();+ H.tableInteractive().should("be.visible");+ H.queryBuilderFiltersPanel()+ .findByText("High Value Recent Orders")+ .should("be.visible");});});describe("Segment deletion", () => {- it("should remove segment via more menu", () => {- createTestSegment({ name: "Segment to Delete" });+ it("should open a segment from the list and remove it via more menu", () => {+ createTestSegment({+ name: "Segment to Delete",+ filter: [">", ["field", ORDERS.TOTAL, null], 100],+ });+ visitDataStudioSegments(ORDERS_ID);++ cy.log("verify segment in list with filter description");+ SegmentList.getSegment("Segment to Delete")+ .scrollIntoView()+ .should("be.visible");+ SegmentList.get()+ .findByTestId("list-item-description")+ .should("contain", "Filtered by Total is greater than 100");++ cy.log("navigate to edit page");+ SegmentList.getSegment("Segment to Delete").click();cy.get<number>("@segmentId").then((segmentId) => {+ cy.url().should(+ "include",+ `${getSegmentsBaseUrl(ORDERS_ID)}/${segmentId}`,+ );+ SegmentEditor.get()+ .findByDisplayValue("Segment to Delete")+ .should("be.visible");++ cy.log("delete via more menu after a direct visit");visitDataModelSegment(ORDERS_ID, segmentId);});-- cy.log("delete via more menu");SegmentEditor.getActionsButton().click();H.popover().findByText("Remove segment").click();H.modal().button("Remove").click();@@ -245,6 +247,7 @@ describe("include",`/data-studio/data/database/${SAMPLE_DB_ID}/schema/${SAMPLE_DB_SCHEMA_ID}/table/${ORDERS_ID}/segments`,);+ SegmentList.getEmptyState().scrollIntoView().should("be.visible");SegmentList.get().findByText("Segment to Delete", { timeout: 1000 }).should("not.exist");@@ -254,66 +257,28 @@ describe(});});- describe("Unsaved changes", () => {- it("should show leave confirmation with unsaved changes", () => {- visitDataStudioSegments(ORDERS_ID);-- SegmentList.getNewSegmentLink().scrollIntoView().click();- SegmentEditor.getNameInput().type("Unsaved Segment");-- cy.log("attempt to navigate away");- SegmentEditor.getBreadcrumb("Orders").click();-- cy.log("verify confirmation modal");- H.modal().within(() => {- cy.findByText("Discard your changes?").should("be.visible");- cy.button("Cancel").click();+ describe("Segment field values modes", () => {+ it("should display search input on Email field, list values on Category field, then add a Price filter with preview", () => {+ cy.request("PUT", `/api/field/${PEOPLE.EMAIL}`, {+ has_field_values: "search",});- cy.log("verify still on editor");- SegmentEditor.get().findByText("Unsaved Segment").should("be.visible");- });- });-- describe("Segment with implicit joins", () => {- it("should create a segment with implicit join filter", () => {- visitDataStudioSegments(ORDERS_ID);-- cy.log("navigate to new segment page");+ visitDataStudioSegments(PEOPLE_ID);SegmentList.getNewSegmentLink().scrollIntoView().click();- cy.log("fill in segment name");- SegmentEditor.getNameInput().type("Widget Orders");-- cy.log("add filter via implicit join");+ cy.log("open filter picker for Email");SegmentEditor.getFilterPlaceholder().click();+ H.popover().findByText("Email").click();++ cy.log("verify search mode UI and search for email");H.popover().within(() => {- cy.findByText("Product").click();- cy.findByText("Category").click();- cy.findByText("Widget").click();- cy.button("Add filter").click();+ cy.findByRole("combobox").should("be.visible");+ cy.findByRole("combobox").type("[email protected]");});-- cy.log("verify filter was added and save");- SegmentEditor.get()- .findByText(/Product → Category is Widget/i)- .should("exist");- SegmentEditor.getSaveButton().click();- cy.wait("@createSegment");-- cy.log("verify redirected to edit page with segment name");- SegmentEditor.get().should("be.visible");- SegmentEditor.get()- .findByDisplayValue("Widget Orders")+ cy.findByRole("listbox")+ .findByText("[email protected]").should("be.visible");- cy.log("verify segment works in query builder");- verifySegmentInQueryBuilder("Widget Orders");- });- });-- describe("Segment field values modes", () => {- it("should display list values when creating segment filter on Category field", () => {cy.request("PUT", `/api/field/${PRODUCTS.CATEGORY}`, {has_field_values: "list",});@@ -333,35 +298,46 @@ describe(cy.findByText("Gizmo").should("be.visible");cy.findByText("Doohickey").should("be.visible");});- });-- it("should display search input when creating segment filter on Email field", () => {- cy.request("PUT", `/api/field/${PEOPLE.EMAIL}`, {- has_field_values: "search",- });-- visitDataStudioSegments(PEOPLE_ID);- SegmentList.getNewSegmentLink().scrollIntoView().click();+ cy.realPress("Escape");+ H.popover({ skipVisibilityCheck: true }).should("not.exist");- cy.log("open filter picker for Email");+ cy.log("add Price filter");SegmentEditor.getFilterPlaceholder().click();- H.popover().findByText("Email").click();-- cy.log("verify search mode UI and search for email");+ H.popover().findByText("Price").click();+ H.selectFilterOperator("Less than");H.popover().within(() => {- cy.findByRole("combobox").should("be.visible");- cy.findByRole("combobox").type("[email protected]");+ cy.findByLabelText("Filter value").type("50");+ cy.button("Add filter").click();});- cy.findByRole("listbox")- .findByText("[email protected]")- .should("be.visible");++ cy.log("verify filter was added");+ SegmentEditor.get()+ .findByText(/Price is less than 50/i)+ .should("exist");++ cy.log("verify preview is available in menu");+ SegmentEditor.getActionsButton().click();+ H.popover().findByText("Preview").should("be.visible");});- it("should display list values for implicit join field", () => {+ it("should display list values for implicit join field, hide FK table segments, and create a segment that works in the query builder", () => {cy.request("PUT", `/api/field/${PRODUCTS.CATEGORY}`, {has_field_values: "list",});+ cy.log("create segment on Products table");+ H.createSegment({+ name: "Expensive Products",+ definition: {+ type: "query",+ database: SAMPLE_DB_ID,+ query: {+ "source-table": PRODUCTS_ID,+ filter: [">", ["field", PRODUCTS.PRICE, null], 50],+ },+ },+ });+visitDataStudioSegments(ORDERS_ID);SegmentList.getNewSegmentLink().scrollIntoView().click();@@ -372,6 +348,13 @@ describe(SegmentEditor.getFilterPlaceholder().click();H.popover().within(() => {cy.findByText("Product").click();++ cy.log(+ "verify Category field is visible but Products segment is not",+ );+ cy.findByText("Category").should("be.visible");+ cy.findByText("Expensive Products").should("not.exist");+cy.findByText("Category").click();});@@ -398,123 +381,14 @@ describe(SegmentEditor.get().findByDisplayValue("Gadget Orders").should("be.visible");- });-- it("should not show segments from FK tables in the filter picker", () => {- cy.log("create segment on Products table");- H.createSegment({- name: "Expensive Products",- definition: {- type: "query",- database: SAMPLE_DB_ID,- query: {- "source-table": PRODUCTS_ID,- filter: [">", ["field", PRODUCTS.PRICE, null], 50],- },- },- });-- cy.log("navigate to create segment on Orders table");- visitDataStudioSegments(ORDERS_ID);- SegmentList.getNewSegmentLink().scrollIntoView().click();-- cy.log("open filter picker and expand Product table");- SegmentEditor.getFilterPlaceholder().click();- H.popover().findByText("Product").click();-- cy.log("verify Category field is visible but Products segment is not");- H.popover().findByText("Category").should("be.visible");- H.popover().findByText("Expensive Products").should("not.exist");- });- });-- describe("Segment dependencies", () => {- it("should create and use a segment based on another segment", () => {- cy.log("create base segment");- createTestSegment({- name: "High Value Orders",- filter: [">", ["field", ORDERS.TOTAL, null], 100],- });-- cy.get<number>("@segmentId").then((baseSegmentId) => {- cy.log("create segment based on segment");- H.createSegment({- name: "High Value Recent Orders",- definition: {- type: "query",- database: SAMPLE_DB_ID,- query: {- "source-table": ORDERS_ID,- filter: [- "and",- ["segment", baseSegmentId],- [">", ["field", ORDERS.CREATED_AT, null], "2020-01-01"],- ],- },- },- });- });-- cy.log("verify both segments appear in query builder");- verifySegmentInQueryBuilder("High Value Orders");- H.openTable({ table: ORDERS_ID, mode: "notebook" });- H.getNotebookStep("data").button("Filter").click();- H.popover().findByText("High Value Recent Orders").should("be.visible");-- cy.log("verify dependent segment works");- H.popover().findByText("High Value Recent Orders").click();- H.visualize();- H.tableInteractive().should("be.visible");- });- });-- describe("Segment cycles", () => {- it.skip("should prevent creating segment cycles", () => {- cy.log("create Segment A");- H.createSegment({- name: "Segment A",- definition: {- type: "query",- database: SAMPLE_DB_ID,- query: {- "source-table": ORDERS_ID,- filter: [">", ["field", ORDERS.TOTAL, null], 50],- },- },- }).then(({ body: segmentA }) => {- cy.log("create Segment B that depends on A");- H.createSegment({- name: "Segment B",- definition: {- type: "query",- database: SAMPLE_DB_ID,- query: {- "source-table": ORDERS_ID,- filter: ["segment", segmentA.id],- },- },- });-- cy.log("edit Segment A via UI and try to add Segment B as filter");- visitDataModelSegment(ORDERS_ID, segmentA.id);- cy.wait("@metadata");- SegmentEditor.get().icon("add").click();- H.popover().findByText("Segment B").click();-- cy.log("try to save and verify error");- SegmentEditor.getSaveButton().click();- cy.wait("@updateSegment");- H.undoToast().should(- "contain.text",- "Unable to save segments with circular dependencies",- );- });+ cy.log("verify segment works in query builder");+ verifySegmentInQueryBuilder("Gadget Orders");});});describe("Revision history", () => {- it("should display revision history with changes to name, description, and filter", () => {+ it("should display revision history with changes to name, description, and filter, and the dependency graph", () => {createTestSegment({name: "Original Name",description: "Original description",@@ -587,6 +461,12 @@ describe(cy.findByText(/created this segment/i).scrollIntoView().should("be.visible");+ cy.findByText(/renamed the segment/i)+ .scrollIntoView()+ .should("be.visible");+ cy.findByText(/changed the filter definition/i)+ .scrollIntoView()+ .should("be.visible");cy.findByText("Total is greater than 100").scrollIntoView().should("be.visible");@@ -594,15 +474,6 @@ describe(.scrollIntoView().should("be.visible");});- });- });-- describe("Dependencies", () => {- it("should display dependency graph for a segment", () => {- createTestSegment({ name: "Dependencies Test Segment" });- cy.get<number>("@segmentId").then((segmentId) => {- visitDataModelSegment(ORDERS_ID, segmentId);- });cy.log("navigate to dependencies tab");SegmentEditor.getDependenciesTab().click();@@ -616,21 +487,24 @@ describe(});H.DependencyGraph.graph().should("be.visible");H.DependencyGraph.graph()- .findByText("Dependencies Test Segment")+ .findByText("Updated Name").should("be.visible");});});describe("Readonly access for data analysts", () => {- it("should show segments in list but hide New segment button for non-admin", () => {- createTestSegment({ name: "Readonly Test Segment" });+ it("should show segments read-only and block segment creation for non-admin", () => {+ createTestSegment({+ name: "Readonly Detail Segment",+ description: "Test description for readonly",+ });H.setUserAsAnalyst(NODATA_USER_ID);cy.signIn("nodata");cy.log("verify segment is visible in list");visitDataStudioSegments(ORDERS_ID);- SegmentList.getSegment("Readonly Test Segment")+ SegmentList.getSegment("Readonly Detail Segment").scrollIntoView().should("be.visible");@@ -639,55 +513,45 @@ describe(.findByRole("link", { name: /New segment/i }).should("not.exist");- cy.log("verify direct navigation to new segment page is blocked");- cy.visit(- `/data-studio/data/database/${SAMPLE_DB_ID}/schema/${SAMPLE_DB_SCHEMA_ID}/table/${ORDERS_ID}/segments/new`,- );- cy.url().should("include", "/unauthorized");- });-- it("should display segment detail in readonly mode for non-admin", () => {- createTestSegment({- name: "Readonly Detail Segment",- description: "Test description for readonly",+ cy.get<number>("@segmentId").then((segmentId) => {+ visitDataModelSegment(ORDERS_ID, segmentId);});- cy.get<number>("@segmentId").then((segmentId) => {- H.setUserAsAnalyst(NODATA_USER_ID);- cy.signIn("nodata");+ cy.log("verify segment name input is disabled");+ SegmentEditor.get()+ .findByDisplayValue("Readonly Detail Segment")+ .should("be.disabled");- visitDataModelSegment(ORDERS_ID, segmentId);+ cy.log("verify description is displayed as plain text");+ SegmentEditor.get().findByText("Description").should("be.visible");+ SegmentEditor.get()+ .findByText("Test description for readonly")+ .should("be.visible");- cy.log("verify segment name input is disabled");- SegmentEditor.get()- .findByDisplayValue("Readonly Detail Segment")- .should("be.disabled");+ cy.log("verify filter is shown");+ SegmentEditor.get()+ .findByText(/Total is less than 100/i)+ .should("be.visible");- cy.log("verify description is displayed as plain text");- SegmentEditor.get().findByText("Description").should("be.visible");- SegmentEditor.get()- .findByText("Test description for readonly")- .should("be.visible");+ cy.log("verify Remove segment option is hidden in actions menu");+ SegmentEditor.getActionsButton().click();+ H.popover().findByText("Preview").should("be.visible");+ H.popover().findByText("Remove segment").should("not.exist");+ cy.realPress("Escape");- cy.log("verify Save button is not visible");- SegmentEditor.get()- .findByRole("button", { name: /Save/i })- .should("not.exist");-- cy.log("verify Remove segment option is hidden in actions menu");- SegmentEditor.getActionsButton().click();- H.popover().findByText("Preview").should("be.visible");- H.popover().findByText("Remove segment").should("not.exist");- cy.realPress("Escape");-- cy.log("verify revision history is still accessible");- SegmentEditor.getRevisionHistoryTab().click();- SegmentRevisionHistory.get().within(() => {- cy.findByText(/created this segment/i)- .scrollIntoView()- .should("be.visible");- });+ cy.log("verify revision history is still accessible");+ SegmentEditor.getRevisionHistoryTab().click();+ SegmentRevisionHistory.get().within(() => {+ cy.findByText(/created this segment/i)+ .scrollIntoView()+ .should("be.visible");});++ cy.log("verify direct navigation to new segment page is blocked");+ cy.visit(+ `/data-studio/data/database/${SAMPLE_DB_ID}/schema/${SAMPLE_DB_SCHEMA_ID}/table/${ORDERS_ID}/segments/new`,+ );+ cy.url().should("include", "/unauthorized");});});},@@ -721,14 +585,12 @@ function createTestSegment(opts: {name?: string;description?: string;- tableId?: number;filter?: unknown[];} = {},) {const {name = "Test Segment",description,- tableId = ORDERS_ID,filter = ["<", ["field", ORDERS.TOTAL, null], 100],} = opts;@@ -739,7 +601,7 @@ function createTestSegment(type: "query",database: SAMPLE_DB_ID,query: {- "source-table": tableId,+ "source-table": ORDERS_ID,filter,},},@@ -748,25 +610,21 @@ function createTestSegment(});}-function verifySegmentInQueryBuilder(- segmentName: string,- tableId: number = ORDERS_ID,-) {- H.openTable({ table: tableId, mode: "notebook" });+function verifySegmentInQueryBuilder(segmentName: string) {+ H.openTable({ table: ORDERS_ID, mode: "notebook" });H.getNotebookStep("data").button("Filter").click();H.popover().findByText(segmentName).click();H.visualize();H.tableInteractive().should("be.visible");+ H.queryBuilderFiltersPanel().findByText(segmentName).should("be.visible");}-function verifySegmentNotInQueryBuilder(- segmentName: string,- tableId: number = ORDERS_ID,-) {- H.openTable({ table: tableId, mode: "notebook" });+function verifySegmentNotInQueryBuilder(segmentName: string) {+ H.openTable({ table: ORDERS_ID, mode: "notebook" });H.getNotebookStep("data").button("Filter").click();+ H.popover().findByText("Total").should("be.visible");H.popover().findByText(segmentName).should("not.exist");}diff --git a/e2e/test/scenarios/data-studio/data-model/source-replacement.cy.spec.ts b/e2e/test/scenarios/data-studio/data-model/source-replacement.cy.spec.tsindex e869f555025..ecbadedfceb 100644--- a/e2e/test/scenarios/data-studio/data-model/source-replacement.cy.spec.ts+++ b/e2e/test/scenarios/data-studio/data-model/source-replacement.cy.spec.ts@@ -1,9 +1,5 @@import { USER_GROUPS, WRITABLE_DB_ID } from "e2e/support/cypress_data";-import type {- ConcreteFieldReference,- Dataset,- MetricDatasetRequest,-} from "metabase-types/api";+import type { ConcreteFieldReference } from "metabase-types/api";const { H } = cy;const { SourceReplacement } = H.DataModel;@@ -57,14 +53,15 @@ describe(cy.intercept("POST", "/api/ee/replacement/replace-source").as("replaceSource",);- cy.intercept("GET", "/api/ee/dependencies/graph/dependents*").as(- "dependents",- );});describe("Successful replacements", () => {- it("updates all dependent questions on the source table", () => {+ it("updates every type of dependent: questions, joins, models, metrics, dashboards, segments, measures, transforms, and native SQL", () => {createTestTables();++ getTableId(SOURCE_TABLE).as("sourceTableId");+ getTableId(COMPATIBLE_TARGET).as("targetTableId");+createSourceQuestion("Q1 plain").as("q1");createSourceQuestion("Q2 filtered", {filter: [@@ -72,18 +69,82 @@ describe(["field", "amount", { "base-type": "type/Decimal" }],50,],+ }).as("q2");+ createSourceQuestion("Q3 count", { aggregation: [["count"]] }).as("q3");++ createQuestionJoiningSourceIntoExtraColumns("Joined question").as(+ "joinedQuestion",+ );++ createSourceModel("Source model").then(({ body: model }) => {+ cy.wrap(model.id).as("modelId");+ createQuestionOnModel("Question on model", model.id).as(+ "nestedQuestion",+ );+ });++ cy.get<number>("@sourceTableId").then((sourceTableId) => {+ H.getFieldId({ tableId: sourceTableId, name: "amount" }).then(+ (amountId) => {+ H.createQuestion({+ name: "Amount sum metric",+ database: WRITABLE_DB_ID,+ type: "metric",+ query: {+ "source-table": sourceTableId,+ aggregation: [["sum", ["field", amountId, null]]],+ },+ }).as("metric");+ },+ );+ });++ createFilteredDashboardOnSource().as("dashboardInfo");++ createHighAmountSegment().then((segmentId) => {+ createSourceQuestion("Question using segment", {+ filter: ["segment", segmentId],+ }).as("segmentQuestion");});- createSourceQuestion("Q3 count", { aggregation: [["count"]] });+ createSourceTotalAmountMeasure().as("measure");++ createSourceTransform("Source transform").then(+ ({ body: transform }) => {+ cy.wrap(transform.id).as("transformId");+ },+ );++ H.createNativeQuestion({+ name: "Native SQL question",+ database: WRITABLE_DB_ID,+ native: { query: `SELECT id, name, amount FROM ${SOURCE_TABLE}` },+ }).as("nativeQuestion");openReplacementModal(SOURCE_TABLE_LABEL);pickTarget(COMPATIBLE_TARGET_LABEL);- cy.log("all dependents are listed in the modal");- SourceReplacement.getDependentsTab(3).click();+ cy.log("all direct dependents are listed in the modal");+ // Q1-3, joined question, model, metric, dashboard question, segment,+ // segment question, measure, transform, and native question. The+ // dashboard and the question on the model are not direct dependents.+ SourceReplacement.getModal()+ .findByRole("tab", {+ name: /12 items will be changed/,+ timeout: 30_000,+ })+ .click();SourceReplacement.getModal().within(() => {- cy.findByText("Q1 plain").should("be.visible");- cy.findByText("Q2 filtered").should("be.visible");- cy.findByText("Q3 count").should("be.visible");+ // The dependents list is virtualized; scroll each row into view.+ [+ "Q1 plain",+ "Q2 filtered",+ "Q3 count",+ "Question using segment",+ "High amount",+ "Total amount",+ ].forEach((name) => {+ cy.findByText(name).scrollIntoView().should("be.visible");+ });});confirmReplacement();@@ -97,48 +158,25 @@ describe(H.openNotebook();assertDataSourceIs(COMPATIBLE_TARGET_LABEL);});- });-- it("allows replacement when target has extra columns", () => {- createTestTables();- createSourceQuestion("Question on source").as("question");- openReplacementModal(SOURCE_TABLE_LABEL);- pickTarget(TARGET_EXTRA_COLUMNS_LABEL);-- cy.log("column comparison is shown and replace is enabled");- SourceReplacement.getModal()- .findByText("Column comparison")- .should("be.visible");-- confirmReplacement();- waitForReplacementToComplete();-- cy.get<Cypress.Response<{ id: number }>>("@question").then(- ({ body }) => {- H.visitQuestion(body.id);- H.main()- .findByText(EXTRA_COLUMNS_TARGET_ROW_VALUE)- .should("be.visible");-- H.openNotebook();- assertDataSourceIs(TARGET_EXTRA_COLUMNS_LABEL);- },- );- });-- it("replaces a joined table without breaking the question", () => {- createTestTables();- createQuestionJoiningSourceIntoExtraColumns("Joined question").as(- "question",- );+ cy.log("filtered question now queries the new table");+ cy.get<Cypress.Response<{ id: number }>>("@q2").then(({ body }) => {+ H.visitQuestion(body.id);+ assertTargetRowVisible();+ H.main().findByText(SOURCE_ROW_VALUE).should("not.exist");+ });- replaceSourceWithTarget(SOURCE_TABLE_LABEL, COMPATIBLE_TARGET_LABEL);+ cy.log("count question now queries the new table");+ cy.get<Cypress.Response<{ id: number }>>("@q3").then(({ body }) => {+ H.visitQuestion(body.id);+ H.openNotebook();+ assertDataSourceIs(COMPATIBLE_TARGET_LABEL);+ });cy.log("the only extra_columns row (D) now joins the D row from compatible_target",);- cy.get<Cypress.Response<{ id: number }>>("@question").then(+ cy.get<Cypress.Response<{ id: number }>>("@joinedQuestion").then(({ body }) => {H.visitQuestion(body.id);H.main()@@ -147,18 +185,6 @@ describe(H.main().findByText(ANOTHER_TARGET_ROW_VALUE).should("be.visible");},);- });-- it("updates a model and questions built on it", () => {- createTestTables();- createSourceModel("Source model").then(({ body: model }) => {- cy.wrap(model.id).as("modelId");- createQuestionOnModel("Question on model", model.id).as(- "nestedQuestion",- );- });-- replaceSourceWithTarget(SOURCE_TABLE_LABEL, COMPATIBLE_TARGET_LABEL);cy.log("nested question shows data from the new table");cy.get<Cypress.Response<{ id: number }>>("@nestedQuestion").then(@@ -174,53 +200,19 @@ describe(cy.visit(`/model/${modelId}/query`);assertDataSourceIs(COMPATIBLE_TARGET_LABEL);});- });-- it("updates a metric defined on the source table", () => {- createTestTables();- getTableId(SOURCE_TABLE).then((sourceTableId) => {- H.getFieldId({ tableId: sourceTableId, name: "amount" }).then(- (amountId) => {- H.createQuestion({- name: "Amount sum metric",- database: WRITABLE_DB_ID,- type: "metric",- query: {- "source-table": sourceTableId,- aggregation: [["sum", ["field", amountId, null]]],- },- }).as("metric");- },- );- });-- replaceSourceWithTarget(SOURCE_TABLE_LABEL, COMPATIBLE_TARGET_LABEL);cy.log("metric now aggregates data from the new table");cy.get<Cypress.Response<{ id: number }>>("@metric").then(({ body }) => {cy.intercept("POST", "/api/metric/dataset").as("metricDataset");H.visitMetric(body.id);- cy.wait<MetricDatasetRequest, Dataset>("@metricDataset").then(- ({ response }) => {- expect(response?.statusCode).to.equal(202);- const total = response?.body.data.rows.reduce((sum, row) => {- return sum + Number(row[row.length - 1]);- }, 0);- expect(total).to.equal(800);- },- );+ cy.wait("@metricDataset")+ .its("response.statusCode")+ .should("eq", 202);cy.findByTestId("visualization-root").should("be.visible").and("have.attr", "data-viz-ui-name", "Number");cy.findByTestId("scalar-value").should("have.text", "800");});- });-- it("updates a dashboard with parameter filters", () => {- createTestTables();- createFilteredDashboardOnSource().as("dashboardInfo");-- replaceSourceWithTarget(SOURCE_TABLE_LABEL, COMPATIBLE_TARGET_LABEL);cy.get<{ dashboard_id: number; card_id: number }>("@dashboardInfo",@@ -228,46 +220,22 @@ describe(cy.log("dashboard renders with new data");H.visitDashboard(dashboard_id);H.main().findByText(COMPATIBLE_TARGET_ROW_VALUE).should("be.visible");+ H.main().findByText(ANOTHER_TARGET_ROW_VALUE).should("be.visible");cy.log("filter widget still works after replacement");+ interceptDashcardQuery();H.toggleFilterWidgetValues(["C"]);+ cy.wait("@dashcardQuery");H.main().findByText(COMPATIBLE_TARGET_ROW_VALUE).should("be.visible");+ H.main().findByText(ANOTHER_TARGET_ROW_VALUE).should("not.exist");cy.log("the underlying question's data source was updated");H.visitQuestion(card_id);H.openNotebook();assertDataSourceIs(COMPATIBLE_TARGET_LABEL);});- });-- it("reassigns segments and measures to the target table", () => {- createTestTables();-- getTableId(SOURCE_TABLE).as("sourceTableId");- getTableId(COMPATIBLE_TARGET).as("targetTableId");-- createHighAmountSegment().then((segmentId) => {- createSourceQuestion("Question using segment", {- filter: ["segment", segmentId],- }).as("segmentQuestion");- });- createSourceTotalAmountMeasure().as("measure");-- openReplacementModal(SOURCE_TABLE_LABEL);- pickTarget(COMPATIBLE_TARGET_LABEL);-- cy.log("dependents tab lists the question, segment, and measure");- SourceReplacement.getDependentsTab(3).click();- SourceReplacement.getModal().within(() => {- cy.findByText("Question using segment").should("be.visible");- cy.findByText("High amount").should("be.visible");- cy.findByText("Total amount").should("be.visible");- });- confirmReplacement();- waitForReplacementToComplete();-- cy.log("the dependent question still runs against the target");+ cy.log("the segment question still runs against the target");cy.get<Cypress.Response<{ id: number }>>("@segmentQuestion").then(({ body }) => {H.visitQuestion(body.id);@@ -283,6 +251,7 @@ describe("segment no longer shows on the source table in the data model UI",);visitWritableTableSegments("@sourceTableId");+ H.DataModel.SegmentList.getEmptyState().should("be.visible");H.DataModel.SegmentList.get().should("not.contain", "High amount");cy.log("measure now shows on the target table in the data model UI");@@ -293,6 +262,7 @@ describe("measure no longer shows on the source table in the data model UI",);visitWritableTableMeasures("@sourceTableId");+ H.DataModel.MeasureList.getEmptyState().should("be.visible");H.DataModel.MeasureList.get().should("not.contain", "Total amount");cy.log("measure still aggregates correctly against the target table");@@ -313,33 +283,43 @@ describe(H.main().findByText("800").should("be.visible");},);- });- it("updates a transform that sources the replaced table", () => {- createTestTables();- createSourceTransform("Source transform").then(- ({ body: transform }) => {- replaceSourceWithTarget(- SOURCE_TABLE_LABEL,- COMPATIBLE_TARGET_LABEL,- );+ cy.log("transform now references the new source table");+ cy.get<number>("@transformId").then((transformId) => {+ H.visitTransform(transformId);+ assertDataSourceIs(COMPATIBLE_TARGET_LABEL);+ });- cy.log("transform now references the new source table");- H.visitTransform(transform.id);- assertDataSourceIs(COMPATIBLE_TARGET_LABEL);+ cy.log("native SQL question now queries the new table");+ cy.get<Cypress.Response<{ id: number }>>("@nativeQuestion").then(+ ({ body }) => {+ H.visitQuestion(body.id);+ assertTargetRowVisible();+ H.main().findByText(SOURCE_ROW_VALUE).should("not.exist");},);});});- describe("Blocked replacements", () => {- it("blocks replacement when target has a column type mismatch", () => {+ describe("Replacement checks", () => {+ it("blocks invalid replacements, allows a target with extra columns, and checks sandboxes and permissions", () => {createTestTables();- createSourceQuestion("Question on source");+ cy.log("blocks replacement when source table has no dependents");openReplacementModal(SOURCE_TABLE_LABEL);- pickTarget(TARGET_TYPE_MISMATCH_LABEL);+ pickTarget(COMPATIBLE_TARGET_LABEL);+ SourceReplacement.getModal()+ .findByText(+ "Nothing uses this data source, so there's nothing to replace.",+ )+ .should("be.visible");+ SourceReplacement.getReplaceButton().should("be.disabled");+ createSourceQuestion("Question on source").as("question");++ cy.log("blocks replacement when target has a column type mismatch");+ openReplacementModal(SOURCE_TABLE_LABEL);+ pickTarget(TARGET_TYPE_MISMATCH_LABEL);SourceReplacement.getModal().within(() => {cy.findByText("Column comparison").should("be.visible");cy.findByText(@@ -347,15 +327,10 @@ describe().should("be.visible");});SourceReplacement.getReplaceButton().should("be.disabled");- });-- it("blocks replacement when target is missing a required column", () => {- createTestTables();- createSourceQuestion("Question on source");+ cy.log("blocks replacement when target is missing a required column");openReplacementModal(SOURCE_TABLE_LABEL);pickTarget(TARGET_MISSING_COLUMN_LABEL);-SourceReplacement.getModal().within(() => {cy.findByText("Column comparison").should("be.visible");cy.findByText("This data source isn't compatible.").should(@@ -363,53 +338,80 @@ describe();});SourceReplacement.getReplaceButton().should("be.disabled");- });-- it("blocks replacement when source table has foreign keys", () => {- createTestTablesWithForeignKey();- createSourceQuestion("Question on source");-- openReplacementModal(SOURCE_TABLE_LABEL);- pickTarget(COMPATIBLE_TARGET_LABEL);-- SourceReplacement.getModal()- .findByText(- "The original table can't be referenced by a foreign key by another table.",- )- .should("be.visible");- SourceReplacement.getReplaceButton().should("be.disabled");- });-- it("blocks replacement when target would create a cycle", () => {- createTestTables();- createSourceQuestion("Question on source");+ cy.log("blocks replacement when target would create a cycle");openReplacementModal(SOURCE_TABLE_LABEL);-- cy.log("pick a question that depends on source_table as the target");SourceReplacement.getTargetPickerButton().click();H.entityPickerModal().within(() => {cy.findByText("Our analytics").click();cy.findByText("Question on source").click();});-SourceReplacement.getModal().findByText("The replacement data source can't be based on the original data source.",).should("be.visible");SourceReplacement.getReplaceButton().should("be.disabled");- });- it("blocks replacement when source table has no dependents", () => {- createTestTables();+ cy.log("allows replacement when target has extra columns");+ openReplacementModal(SOURCE_TABLE_LABEL);+ pickTarget(TARGET_EXTRA_COLUMNS_LABEL);+ SourceReplacement.getModal()+ .findByText("Column comparison")+ .should("be.visible");+ confirmReplacement();+ waitForReplacementToComplete();++ cy.get<Cypress.Response<{ id: number }>>("@question").then(+ ({ body }) => {+ H.visitQuestion(body.id);+ H.main()+ .findByText(EXTRA_COLUMNS_TARGET_ROW_VALUE)+ .should("be.visible");++ H.openNotebook();+ assertDataSourceIs(TARGET_EXTRA_COLUMNS_LABEL);+ },+ );++ cy.log("non-admin users cannot open the data model in data studio");+ cy.signInAsNormalUser();+ cy.visit("/data-studio/data");+ H.main()+ .findByText("Sorry, you don\u2019t have permission to see that.")+ .should("be.visible");+ cy.signInAsAdmin();++ cy.log("blocks replacement when the source table has a sandbox policy");+ // The question above now uses the extra-columns table. Without a+ // dependent, the modal shows "Nothing uses this data source" instead.+ createSourceQuestion("Another question on source");+ getTableId(SOURCE_TABLE).then((sourceTableId) => {+ H.getFieldId({ tableId: sourceTableId, name: "category" }).then(+ (categoryFieldId) => {+ H.createQuestion({+ name: "Sandbox filter question",+ database: WRITABLE_DB_ID,+ query: {+ "source-table": sourceTableId,+ filter: ["=", ["field", categoryFieldId, null], "A"],+ },+ }).then(({ body: sandboxQuestion }) => {+ cy.sandboxTable({+ table_id: sourceTableId,+ card_id: sandboxQuestion.id,+ group_id: USER_GROUPS.COLLECTION_GROUP,+ });+ });+ },+ );+ });openReplacementModal(SOURCE_TABLE_LABEL);pickTarget(COMPATIBLE_TARGET_LABEL);-SourceReplacement.getModal().findByText(- "Nothing uses this data source, so there's nothing to replace.",+ "This table has row or column security policies that block this replacement.",).should("be.visible");SourceReplacement.getReplaceButton().should("be.disabled");@@ -417,7 +419,7 @@ describe(});describe("Entry points", () => {- it("opens replacement from the dependency graph and replaces successfully", () => {+ it("replaces from the dependency graph, then blocks replacement when the source table has foreign keys", () => {createTestTables();createSourceQuestion("Graph question").as("question");@@ -454,33 +456,24 @@ describe(assertDataSourceIs(COMPATIBLE_TARGET_LABEL);},);- });- });- describe("Native queries", () => {- it("replaces a table referenced in a native SQL question", () => {- createTestTables();- createSourceQuestion("MBQL dependent");+ cy.log("blocks replacement when source table has foreign keys");+ createChildTableWithForeignKey();+ createSourceQuestion("Question on source");- H.createNativeQuestion({- name: "Native SQL question",- database: WRITABLE_DB_ID,- native: { query: `SELECT id, name, amount FROM ${SOURCE_TABLE}` },- }).as("nativeQuestion");+ openReplacementModal(SOURCE_TABLE_LABEL);+ pickTarget(COMPATIBLE_TARGET_LABEL);- cy.get<Cypress.Response<{ id: number }>>("@nativeQuestion").then(- ({ body }) => {- replaceSourceWithTarget(- SOURCE_TABLE_LABEL,- COMPATIBLE_TARGET_LABEL,- );- H.visitQuestion(body.id);- assertTargetRowVisible();- H.main().findByText(SOURCE_ROW_VALUE).should("not.exist");- },- );+ SourceReplacement.getModal()+ .findByText(+ "The original table can't be referenced by a foreign key by another table.",+ )+ .should("be.visible");+ SourceReplacement.getReplaceButton().should("be.disabled");});+ });+ describe("Native queries", () => {it.skip("replaces a table referenced via a native query snippet", () => {createTestTables();createSourceQuestion("MBQL dependent");@@ -522,215 +515,112 @@ describe(});});- describe("Access control", () => {- it("non-admin users cannot access source replacement", () => {- createTestTables();- createSourceQuestion("Question on source");-- cy.signInAsNormalUser();- cy.visit("/data-studio/data");- H.main()- .findByText("Sorry, you don\u2019t have permission to see that.")- .should("be.visible");- });- });-- describe("Sandboxing", () => {- it("blocks replacement when the source table has a sandbox policy", () => {+ describe("Field ref upgrades", () => {+ it("rewrites field refs in questions, viz settings, and dashboards after swap", () => {createTestTables();- createSourceQuestion("Question on source");- getTableId(SOURCE_TABLE).then((sourceTableId) => {- H.getFieldId({ tableId: sourceTableId, name: "category" }).then(- (categoryFieldId) => {- H.createQuestion({- name: "Sandbox filter question",- database: WRITABLE_DB_ID,- query: {- "source-table": sourceTableId,- filter: ["=", ["field", categoryFieldId, null], "A"],- },- }).then(({ body: sandboxQuestion }) => {- cy.sandboxTable({- table_id: sourceTableId,- card_id: sandboxQuestion.id,- group_id: USER_GROUPS.COLLECTION_GROUP,- });- });- },- );+ cy.log("numeric field id on a question directly on the source table");+ createQuestionUsingFieldIdRef().then(({ cardId }) => {+ cy.wrap(cardId).as("directFilterCardId");});-- openReplacementModal(SOURCE_TABLE_LABEL);- pickTarget(COMPATIBLE_TARGET_LABEL);-- SourceReplacement.getModal()- .findByText(- "This table has row or column security policies that block this replacement.",- )- .should("be.visible");- SourceReplacement.getReplaceButton().should("be.disabled");- });- });-- describe("Field ref upgrades", () => {- describe("numeric field id on a question directly on the source table", () => {- it("rewrites the card's own filter ref after swap", () => {- createTestTables();- createQuestionUsingFieldIdRef().then(({ cardId }) => {- replaceSourceWithTarget(- SOURCE_TABLE_LABEL,- COMPATIBLE_TARGET_LABEL,- );-- H.visitQuestion(cardId);- assertTargetRowVisible();+ createQuestionUsingFieldIdRef().then(({ cardId, amountRef }) => {+ setCardColumnTitle({+ cardId,+ columnRef: amountRef,});+ cy.wrap(cardId).as("directVizSettingsCardId");});-- it("rewrites viz settings column_settings ref keys", () => {- createTestTables();- createQuestionUsingFieldIdRef().then(({ cardId, amountRef }) => {- setNestedCardColumnTitle({- nestedCardId: cardId,- columnRef: amountRef,- });- replaceSourceWithTarget(- SOURCE_TABLE_LABEL,- COMPATIBLE_TARGET_LABEL,- );-- H.visitQuestion(cardId);- assertTargetRowVisible();- H.main().findByText("Renamed Column").should("be.visible");- });+ createQuestionUsingFieldIdRef()+ .then((scenario) => buildParameterTargetDashboard(scenario))+ .as("directParameterDashboardId");+ createQuestionUsingFieldIdRef()+ .then((scenario) => buildClickBehaviorDashboard(scenario))+ .as("directClickBehaviorDashboardId");+ createQuestionUsingFieldIdRef()+ .then((scenario) => buildCardSourcedValuesDashboard(scenario))+ .as("directValuesSourceDashboardId");++ cy.log("numeric field id in a nested card on a parent question");+ createNestedQuestionUsingFieldIdRef().then(({ cardId }) => {+ cy.wrap(cardId).as("nestedFilterCardId");});+ createNestedQuestionUsingFieldIdRef()+ .then((scenario) => buildParameterTargetDashboard(scenario))+ .as("nestedParameterDashboardId");+ createNestedQuestionUsingFieldIdRef()+ .then((scenario) => buildClickBehaviorDashboard(scenario))+ .as("nestedClickBehaviorDashboardId");+ createNestedQuestionUsingFieldIdRef()+ .then((scenario) => buildCardSourcedValuesDashboard(scenario))+ .as("nestedValuesSourceDashboardId");- it("rewrites a dashboard parameter target", () => {- createTestTables();- createQuestionUsingFieldIdRef().then((scenario) => {- buildParameterTargetDashboard(scenario);- replaceSourceWithTarget(- SOURCE_TABLE_LABEL,- COMPATIBLE_TARGET_LABEL,- );- assertParameterTargetStillWorks();- });+ cy.log(+ "`_2` suffix ref in a nested card whose parent has a same-name join",+ );+ createNestedQuestionUsingJoinSuffixRef().then(({ cardId }) => {+ cy.wrap(cardId).as("joinSuffixFilterCardId");});+ createNestedQuestionUsingJoinSuffixRef()+ .then((scenario) => buildParameterTargetDashboard(scenario))+ .as("joinSuffixParameterDashboardId");+ createNestedQuestionUsingJoinSuffixRef()+ .then((scenario) => buildClickBehaviorDashboard(scenario))+ .as("joinSuffixClickBehaviorDashboardId");- it("rewrites dashcard click_behavior parameterMapping", () => {- createTestTables();- createQuestionUsingFieldIdRef().then((scenario) => {- buildClickBehaviorDashboard(scenario);- replaceSourceWithTarget(- SOURCE_TABLE_LABEL,- COMPATIBLE_TARGET_LABEL,- );- assertClickBehaviorStillWorks();- });+ replaceSourceWithTarget(SOURCE_TABLE_LABEL, COMPATIBLE_TARGET_LABEL);++ cy.log("direct question: the card's own filter ref");+ cy.get<number>("@directFilterCardId").then((cardId) => {+ H.visitQuestion(cardId);+ assertTargetRowVisible();});- it("rewrites a parameter values_source_config card value_field ref", () => {- createTestTables();- createQuestionUsingFieldIdRef().then((scenario) => {- buildCardSourcedValuesDashboard(scenario);- replaceSourceWithTarget(- SOURCE_TABLE_LABEL,- COMPATIBLE_TARGET_LABEL,- );- assertCardSourcedValuesStillWork();- });+ cy.log("direct question: viz settings column_settings ref keys");+ cy.get<number>("@directVizSettingsCardId").then((cardId) => {+ H.visitQuestion(cardId);+ assertTargetRowVisible();+ H.main().findByText("Renamed Column").should("be.visible");});- });- describe("numeric field id in a nested card on a parent question", () => {- it("rewrites the nested card's filter ref after swap", () => {- createTestTables();- createNestedQuestionUsingFieldIdRef().then(({ cardId }) => {- replaceSourceWithTarget(- SOURCE_TABLE_LABEL,- COMPATIBLE_TARGET_LABEL,- );+ cy.log("direct question: dashboard parameter target");+ assertParameterTargetStillWorks("@directParameterDashboardId");- H.visitQuestion(cardId);- assertTargetRowVisible();- });- });+ cy.log("direct question: dashcard click_behavior parameterMapping");+ assertClickBehaviorStillWorks("@directClickBehaviorDashboardId");- it("rewrites a dashboard parameter target", () => {- createTestTables();- createNestedQuestionUsingFieldIdRef().then((scenario) => {- buildParameterTargetDashboard(scenario);- replaceSourceWithTarget(- SOURCE_TABLE_LABEL,- COMPATIBLE_TARGET_LABEL,- );- assertParameterTargetStillWorks();- });- });+ cy.log(+ "direct question: parameter values_source_config card value_field ref",+ );+ assertCardSourcedValuesStillWork("@directValuesSourceDashboardId");- it("rewrites dashcard click_behavior parameterMapping", () => {- createTestTables();- createNestedQuestionUsingFieldIdRef().then((scenario) => {- buildClickBehaviorDashboard(scenario);- replaceSourceWithTarget(- SOURCE_TABLE_LABEL,- COMPATIBLE_TARGET_LABEL,- );- assertClickBehaviorStillWorks();- });+ cy.log("nested card: the nested card's filter ref");+ cy.get<number>("@nestedFilterCardId").then((cardId) => {+ H.visitQuestion(cardId);+ assertTargetRowVisible();});- it("rewrites a parameter values_source_config card value_field ref", () => {- createTestTables();- createNestedQuestionUsingFieldIdRef().then((scenario) => {- buildCardSourcedValuesDashboard(scenario);- replaceSourceWithTarget(- SOURCE_TABLE_LABEL,- COMPATIBLE_TARGET_LABEL,- );- assertCardSourcedValuesStillWork();- });- });- });+ cy.log("nested card: dashboard parameter target");+ assertParameterTargetStillWorks("@nestedParameterDashboardId");- describe("`_2` suffix ref in a nested card whose parent has a same-name join", () => {- it("rewrites the nested card's `_2` filter ref after swap", () => {- createTestTables();- createNestedQuestionUsingJoinSuffixRef().then(({ cardId }) => {- replaceSourceWithTarget(- SOURCE_TABLE_LABEL,- COMPATIBLE_TARGET_LABEL,- );+ cy.log("nested card: dashcard click_behavior parameterMapping");+ assertClickBehaviorStillWorks("@nestedClickBehaviorDashboardId");- H.visitQuestion(cardId);- assertTargetRowVisible();- });- });+ cy.log(+ "nested card: parameter values_source_config card value_field ref",+ );+ assertCardSourcedValuesStillWork("@nestedValuesSourceDashboardId");- it("rewrites a dashboard parameter target", () => {- createTestTables();- createNestedQuestionUsingJoinSuffixRef().then((scenario) => {- buildParameterTargetDashboard(scenario);- replaceSourceWithTarget(- SOURCE_TABLE_LABEL,- COMPATIBLE_TARGET_LABEL,- );- assertParameterTargetStillWorks();- });+ cy.log("`_2` suffix: the nested card's `_2` filter ref");+ cy.get<number>("@joinSuffixFilterCardId").then((cardId) => {+ H.visitQuestion(cardId);+ assertTargetRowVisible();});- it("rewrites dashcard click_behavior parameterMapping", () => {- createTestTables();- createNestedQuestionUsingJoinSuffixRef().then((scenario) => {- buildClickBehaviorDashboard(scenario);- replaceSourceWithTarget(- SOURCE_TABLE_LABEL,- COMPATIBLE_TARGET_LABEL,- );- assertClickBehaviorStillWorks();- });- });+ cy.log("`_2` suffix: dashboard parameter target");+ assertParameterTargetStillWorks("@joinSuffixParameterDashboardId");++ cy.log("`_2` suffix: dashcard click_behavior parameterMapping");+ assertClickBehaviorStillWorks("@joinSuffixClickBehaviorDashboardId");});});},@@ -801,29 +691,9 @@ function createTestTables() {H.resyncDatabase({ dbId: WRITABLE_DB_ID });}-function createTestTablesWithForeignKey() {- dropAllTestTables();-+function createChildTableWithForeignKey() {H.queryWritableDB(`- CREATE TABLE ${SOURCE_TABLE} (- id INTEGER PRIMARY KEY,- name VARCHAR(255),- amount NUMERIC(10,2),- category VARCHAR(100)- );- INSERT INTO ${SOURCE_TABLE} VALUES- (1, 'Source Value 1', 100.50, 'A');-- CREATE TABLE ${COMPATIBLE_TARGET} (- id INTEGER PRIMARY KEY,- name VARCHAR(255),- amount NUMERIC(10,2),- category VARCHAR(100)- );- INSERT INTO ${COMPATIBLE_TARGET} VALUES- (10, 'Compatible Target Value', 300.00, 'C');-CREATE TABLE ${CHILD_TABLE} (id INTEGER PRIMARY KEY,source_id INTEGER REFERENCES ${SOURCE_TABLE}(id),@@ -835,7 +705,7 @@ function createTestTablesWithForeignKey() {"postgres",);- H.resyncDatabase({ dbId: WRITABLE_DB_ID });+ H.resyncDatabase({ dbId: WRITABLE_DB_ID, tableName: CHILD_TABLE });}function getTableId(tableName: string) {@@ -849,6 +719,10 @@ function openReplacementModal(sourceTableLabel: string) {// "Nothing uses this data source" for a table that does have dependents.H.waitForBackfillComplete();+ // Register the alias again so that the wait below skips earlier requests.+ cy.intercept("GET", "/api/ee/dependencies/graph/dependents*").as(+ "dependents",+ );H.DataModel.visitDataStudio();H.DataModel.TablePicker.getDatabase("Writable Postgres12").click();@@ -879,7 +753,7 @@ function confirmReplacement() {// The affected-items count comes from an async dependents computation// that can exceed the default 4s timeout, so wait longer for the tab.name: /\d+ items? will be changed/,- timeout: 15000,+ timeout: 30_000,}).should("be.visible");@@ -896,7 +770,7 @@ function confirmReplacement() {function waitForReplacementToComplete() {const POLL_INTERVAL_MS = 250;- const POLL_TIMEOUT_MS = 30_000;+ const POLL_TIMEOUT_MS = 60_000;const MAX_ATTEMPTS = POLL_TIMEOUT_MS / POLL_INTERVAL_MS;cy.wait("@replaceSource").then((interception) => {@@ -1292,7 +1166,7 @@ function buildParameterTargetDashboard({cardId,categoryRef,}: FieldRefScenario) {- H.createDashboard({+ return H.createDashboard({name: "Parameter target dashboard",parameters: [categoryStringParameter(CATEGORY_FILTER_ID)],}).then(({ body: dashboard }) => {@@ -1309,7 +1183,7 @@ function buildParameterTargetDashboard({],},});- cy.wrap(dashboard.id).as("dashboardId");+ return cy.wrap(dashboard.id);});}@@ -1317,7 +1191,7 @@ function buildClickBehaviorDashboard({cardId,categoryRef,}: FieldRefScenario) {- H.createDashboard({+ return H.createDashboard({name: "Click behavior dashboard",parameters: [categoryStringParameter(CATEGORY_FILTER_ID)],}).then(({ body: dashboard }) => {@@ -1341,7 +1215,7 @@ function buildClickBehaviorDashboard({},},});- cy.wrap(dashboard.id).as("dashboardId");+ return cy.wrap(dashboard.id);});}@@ -1349,7 +1223,7 @@ function buildCardSourcedValuesDashboard({cardId,categoryRef,}: FieldRefScenario) {- H.createDashboard({+ return H.createDashboard({name: "Card-sourced values dashboard",parameters: [{@@ -1375,18 +1249,20 @@ function buildCardSourcedValuesDashboard({],},});- cy.wrap(dashboard.id).as("dashboardId");+ return cy.wrap(dashboard.id);});}-function assertParameterTargetStillWorks() {- cy.get<number>("@dashboardId").then((dashboardId) => {+function assertParameterTargetStillWorks(dashboardAlias: string) {+ cy.get<number>(dashboardAlias).then((dashboardId) => {H.visitDashboard(dashboardId);assertDashcardHasRows({visible: [COMPATIBLE_TARGET_ROW_VALUE, ANOTHER_TARGET_ROW_VALUE],hidden: [],});+ interceptDashcardQuery();H.toggleFilterWidgetValues(["D"]);+ cy.wait("@dashcardQuery");assertDashcardHasRows({visible: [ANOTHER_TARGET_ROW_VALUE],hidden: [COMPATIBLE_TARGET_ROW_VALUE],@@ -1394,15 +1270,17 @@ function assertParameterTargetStillWorks() {});}-function assertClickBehaviorStillWorks() {- cy.get<number>("@dashboardId").then((dashboardId) => {+function assertClickBehaviorStillWorks(dashboardAlias: string) {+ cy.get<number>(dashboardAlias).then((dashboardId) => {H.visitDashboard(dashboardId);assertDashcardHasRows({visible: [COMPATIBLE_TARGET_ROW_VALUE, ANOTHER_TARGET_ROW_VALUE],hidden: [],});+ interceptDashcardQuery();cy.findByTestId("dashcard").findAllByText("D").first().click();H.filterWidget().should("contain.text", "D");+ cy.wait("@dashcardQuery");assertDashcardHasRows({visible: [ANOTHER_TARGET_ROW_VALUE],hidden: [COMPATIBLE_TARGET_ROW_VALUE],@@ -1410,8 +1288,8 @@ function assertClickBehaviorStillWorks() {});}-function assertCardSourcedValuesStillWork() {- cy.get<number>("@dashboardId").then((dashboardId) => {+function assertCardSourcedValuesStillWork(dashboardAlias: string) {+ cy.get<number>(dashboardAlias).then((dashboardId) => {H.visitDashboard(dashboardId);assertDashcardHasRows({visible: [COMPATIBLE_TARGET_ROW_VALUE, ANOTHER_TARGET_ROW_VALUE],@@ -1420,10 +1298,12 @@ function assertCardSourcedValuesStillWork() {H.filterWidget().click();H.popover().findByText("C").should("be.visible");H.popover().findByText("D").should("be.visible");+ interceptDashcardQuery();H.popover().within(() => {cy.findByText("D").click();cy.button("Add filter").click();});+ cy.wait("@dashcardQuery");assertDashcardHasRows({visible: [ANOTHER_TARGET_ROW_VALUE],hidden: [COMPATIBLE_TARGET_ROW_VALUE],@@ -1453,11 +1333,11 @@ function crossfilterClickBehavior(parameterId: string) {};}-function setNestedCardColumnTitle({- nestedCardId,+function setCardColumnTitle({+ cardId,columnRef,}: {- nestedCardId: number;+ cardId: number;columnRef: ConcreteFieldReference;}) {// Legacy column_settings keys store refs with null options. See@@ -1468,7 +1348,7 @@ function setNestedCardColumnTitle({null,] as ConcreteFieldReference;const columnKey = JSON.stringify(["ref", legacyRef]);- return cy.request("PUT", `/api/card/${nestedCardId}`, {+ return cy.request("PUT", `/api/card/${cardId}`, {visualization_settings: {column_settings: {[columnKey]: { column_title: "Renamed Column" },@@ -1490,6 +1370,12 @@ function assertDataSourceIs(tableLabel: string) {cy.findByTestId("data-step-cell").should("have.text", tableLabel);}+function interceptDashcardQuery() {+ cy.intercept("POST", "/api/dashboard/*/dashcard/*/card/*/query").as(+ "dashcardQuery",+ );+}+function assertDashcardHasRows({visible,hidden,diff --git a/e2e/test/scenarios/data-studio/data-studio-library.cy.spec.ts b/e2e/test/scenarios/data-studio/data-studio-library.cy.spec.tsindex a39467dc323..5aad3280cb7 100644--- a/e2e/test/scenarios/data-studio/data-studio-library.cy.spec.ts+++ b/e2e/test/scenarios/data-studio/data-studio-library.cy.spec.ts@@ -3,7 +3,6 @@ const { H } = cy;import { SAMPLE_DATABASE } from "e2e/support/cypress_sample_database";import {TRUSTED_ORDERS_METRIC,- createLibraryWithItems,createLibraryWithTable,} from "e2e/support/test-library-data";import type { Collection } from "metabase-types/api";@@ -22,12 +21,12 @@ type LibraryRootCollections = {describe("scenarios > data studio > library", () => {beforeEach(() => {H.restore();- H.resetSnowplow();cy.signInAsAdmin();H.activateToken("pro-self-hosted");});it("should create library via UI and verify collections", () => {+ H.resetSnowplow();cy.intercept("POST", "/api/ee/library").as("createLibrary");cy.intercept("GET", "/api/collection/tree*").as("getCollectionTree");@@ -73,9 +72,48 @@ describe("scenarios > data studio > library", () => {H.DataStudio.Library.collectionItem("SQL snippets").should("be.visible");});- it("should be available in the data picker", () => {- createLibraryWithItems();+ it("should let you move metrics into the library, even when empty", () => {+ cy.intercept("POST", "/api/card").as("createCard");+ H.createLibrary();+ H.createQuestion(TRUSTED_ORDERS_METRIC, { visitQuestion: true });+ H.DataStudio.Metrics.moreMenu().click();+ H.popover().findByText("Duplicate").click();+ H.modal().findByTestId("dashboard-and-collection-picker-button").click();++ H.entityPickerModalItem(0, "Library").click();+ H.entityPickerModalItem(1, "Metrics").click();+ H.entityPickerModal().button("Select this collection").click();+ H.modal().button("Duplicate").click();+ cy.wait("@createCard").its("response.statusCode").should("eq", 200);++ H.DataStudio.Library.visit();+ H.DataStudio.Library.libraryPage()+ .findByText("Trusted Orders Metric - Duplicate")+ .should("be.visible");+ });+ it("should show the library in the data picker and build the path from a value", () => {+ createLibraryWithTable();++ cy.log("Library is visible when only the Data collection has items");+ H.startNewQuestion();+ H.miniPickerBrowseAll().click();++ H.entityPickerModalItem(0, "Library").click();+ H.entityPickerModalItem(1, "Data").click();+ H.entityPickerModalItem(2, "Orders").should("exist");++ cy.log("Add a metric to the Metrics collection");+ getLibraryRootCollections().then(({ metricCollection }) => {+ H.createQuestion({ ...TRUSTED_ORDERS_METRIC }).then(({ body: card }) => {+ cy.request("PUT", `/api/card/${card.id}`, {+ collection_id: metricCollection.id,+ });+ });+ });++ // `startNewQuestion` only changes the hash on the same path, so leave the page first to load it fresh.+ cy.visit("/");H.startNewQuestion();H.miniPickerBrowseAll().click();@@ -83,7 +121,7 @@ describe("scenarios > data studio > library", () => {H.entityPickerModalItem(1, "Data").click();H.entityPickerModalItem(2, "Orders").click();- cy.log("Ensure that the we can build the path from a value");+ cy.log("Ensure that we can build the path from a value");cy.button(/Orders/).click();H.miniPickerHeader().click();@@ -106,77 +144,42 @@ describe("scenarios > data studio > library", () => {);});- it("should let you move metrics into the library, even when empty", () => {- H.createLibrary();- H.createQuestion(TRUSTED_ORDERS_METRIC, { visitQuestion: true });- H.DataStudio.Metrics.moreMenu().click();- H.popover().findByText("Duplicate").click();- H.modal().findByTestId("dashboard-and-collection-picker-button").click();-- H.entityPickerModalItem(0, "Library").click();- H.entityPickerModalItem(1, "Metrics").click();- H.entityPickerModal().button("Select this collection").click();- H.modal().button("Duplicate").click();- });-- it("should show the library collection even if only 1 child collection has items", () => {- createLibraryWithTable();-- H.startNewQuestion();- H.miniPickerBrowseAll().click();-- H.entityPickerModalItem(0, "Library").click();- H.entityPickerModalItem(1, "Data").click();- H.entityPickerModalItem(2, "Orders").should("exist");- });-- describe("+New button", () => {- it("should allow you to publish a table", () => {- H.createLibrary();- H.DataStudio.Library.visit();-- cy.log("Publish a table from the 'New' menu");- H.DataStudio.Library.newButton().click();- H.popover().findByText("Published table").click();-- cy.log("Select a table and click 'Publish'");- H.pickEntity({- path: ["Databases", /Sample Database/, "Orders"],- select: true,- });-- H.modal().findByText("Publish to").should("be.visible");- H.modal().findByText("Data").should("be.visible");- H.modal().button("Publish this table").click();-- cy.log("Verify the table is published");- H.DataStudio.Tables.overviewPage().should("exist");- H.DataStudio.Tables.header().findByDisplayValue("Orders").should("exist");- H.DataStudio.breadcrumbs().findByRole("link", { name: "Data" }).click();- H.DataStudio.Library.tableItem("Orders").should("exist");-- cy.log(- "Verify tables in the entity picker are disabled if already published",- );- H.DataStudio.Library.newButton().click();- H.popover().findByText("Published table").click();- H.entityPickerModalItem(1, /Sample Database/).click();- H.entityPickerModalItem(2, "Orders").should("have.attr", "data-disabled");- H.entityPickerModalItem(2, "People").should(- "not.have.attr",- "data-disabled",- );- });- });-describe("Library collection management", () => {- it("should create a new library collection from the New button", () => {+ it("should create, edit, move, and archive library collections and move a published table", () => {H.createLibrary();H.createCollection({ name: "Outside Library" });+ getLibraryRootCollections().then(({ dataCollection }) => {+ createLibraryCollection({+ name: "Collection Before Edit",+ description: "Original description",+ parent_id: dataCollection.id,+ });+ createLibraryCollection({+ name: "Destination Collection",+ parent_id: dataCollection.id,+ });+ createLibraryCollection({+ name: "Collection To Move",+ parent_id: dataCollection.id,+ });+ H.publishTables({ table_ids: [ORDERS_ID] });+ createLibraryCollection({+ name: "Table Destination Collection",+ parent_id: dataCollection.id,+ });+ createLibraryCollection({+ name: "Collection To Archive",+ parent_id: dataCollection.id,+ });+ });+H.DataStudio.Library.visit();cy.intercept("POST", "/api/collection").as("createCollection");+ cy.intercept("PUT", "/api/collection/*").as("updateCollection");+ cy.intercept("PUT", "/api/table/*").as("updateTable");+ cy.log("Create a new library collection from the New button");H.DataStudio.Library.newButton().click();H.popover().findByText("Collection").click();@@ -189,7 +192,7 @@ describe("scenarios > data studio > library", () => {H.entityPickerModalItem(0, "Library").should("be.visible");H.entityPickerModalItem(1, "Data").should("be.visible");- cy.log("Check that non-library collection are not visible");+ cy.log("Check that non-library collections are not visible");H.entityPickerModal().findByText("Our analytics").should("not.exist");H.entityPickerModal().findByText("Outside Library").should("not.exist");H.entityPickerModal().button("Cancel").click();@@ -202,22 +205,8 @@ describe("scenarios > data studio > library", () => {H.DataStudio.Library.collectionItem("New Library Collection").should("be.visible",);- });-- it("should edit a library collection name and description", () => {- H.createLibrary();- getLibraryRootCollections().then(({ dataCollection }) => {- createLibraryCollection({- name: "Collection Before Edit",- description: "Original description",- parent_id: dataCollection.id,- });- });-- H.DataStudio.Library.visit();-- cy.intercept("PUT", "/api/collection/*").as("updateCollection");+ cy.log("Edit a library collection name and description");openCollectionOptions("Collection Before Edit");H.popover().findByText("Edit collection details").click();@@ -239,25 +228,8 @@ describe("scenarios > data studio > library", () => {H.DataStudio.Library.libraryPage().findByText("Collection Before Edit").should("not.exist");- });-- it("should move a library collection to another subcollection", () => {- H.createLibrary();- getLibraryRootCollections().then(({ dataCollection }) => {- createLibraryCollection({- name: "Destination Collection",- parent_id: dataCollection.id,- });- createLibraryCollection({- name: "Collection To Move",- parent_id: dataCollection.id,- });- });-- H.DataStudio.Library.visit();-- cy.intercept("PUT", "/api/collection/*").as("updateCollection");+ cy.log("Move a library collection to another subcollection");openCollectionOptions("Collection To Move");H.popover().findByText("Edit collection details").click();@@ -278,21 +250,28 @@ describe("scenarios > data studio > library", () => {H.DataStudio.Library.result("Collection To Move").should("be.visible").and("have.attr", "aria-level", "3");- });- it("should archive a library collection and show it in trash", () => {- H.createLibrary();- getLibraryRootCollections().then(({ dataCollection }) => {- createLibraryCollection({- name: "Collection To Archive",- parent_id: dataCollection.id,- });- });+ cy.log("Move a published table to a library subcollection");+ openTableOptions("Orders");+ H.popover().findByText("Move").click();- H.DataStudio.Library.visit();+ H.entityPickerModalItem(1, "Metrics").should(+ "have.attr",+ "data-disabled",+ );+ H.entityPickerModalItem(2, "Table Destination Collection").click();+ H.entityPickerModal().button("Move").click();- cy.intercept("PUT", "/api/collection/*").as("updateCollection");+ cy.wait("@updateTable").then(({ response }) => {+ expect(response?.statusCode).to.equal(200);+ });+ H.DataStudio.Library.expandCollection("Table Destination Collection");+ H.DataStudio.Library.result("Orders")+ .should("be.visible")+ .and("have.attr", "aria-level", "3");++ cy.log("Archive a library collection and show it in trash");openCollectionOptions("Collection To Archive");H.popover().findByText("Archive").click();H.modal().button("Archive").click();@@ -312,48 +291,13 @@ describe("scenarios > data studio > library", () => {.findByText("Collection To Archive").should("be.visible");});-- it("should move a published table to a library subcollection", () => {- H.createLibrary();- getLibraryRootCollections().then(({ dataCollection }) => {- H.publishTables({ table_ids: [ORDERS_ID] });- createLibraryCollection({- name: "Table Destination Collection",- parent_id: dataCollection.id,- });- });-- H.DataStudio.Library.visit();-- cy.intercept("PUT", "/api/table/*").as("updateTable");-- openTableOptions("Orders");- H.popover().findByText("Move").click();-- H.entityPickerModalItem(1, "Metrics").should(- "have.attr",- "data-disabled",- );- H.entityPickerModalItem(2, "Table Destination Collection").click();- H.entityPickerModal().button("Move").click();-- cy.wait("@updateTable").then(({ response }) => {- expect(response?.statusCode).to.equal(200);- });-- H.DataStudio.Library.expandCollection("Table Destination Collection");- H.DataStudio.Library.result("Orders")- .should("be.visible")- .and("have.attr", "aria-level", "3");- });});describe("empty state", () => {- it("should show empty states with interactions when sections are empty", () => {+ it("should show empty states, publish a table from the New menu, and keep empty sections expanded", () => {H.createLibrary();H.DataStudio.Library.visit();- cy.log("Verify all sections are expanded");H.DataStudio.Library.collectionItem("Data").should("be.visible");H.DataStudio.Library.collectionItem("Metrics").should("be.visible");H.DataStudio.Library.collectionItem("SQL snippets").should("be.visible");@@ -398,28 +342,51 @@ describe("scenarios > data studio > library", () => {H.DataStudio.Library.libraryPage().findByText("Cleaned, pre-transformed data sources ready for exploring").should("not.exist");- });- it("should hide empty states when items are added and keep empty sections expanded on navigation", () => {- H.createLibrary();- H.DataStudio.Library.visit();-- cy.log("Verify Data empty state is visible initially");+ cy.log("Clear the search and verify the Data empty state is back");+ H.DataStudio.Library.libraryPage()+ .findByPlaceholderText("Search...")+ .clear();H.DataStudio.Library.emptyStateRow("Cleaned, pre-transformed data sources ready for exploring",).should("be.visible");- cy.log("Publish a table via the +New menu");+ cy.log("Publish a table from the 'New' menu");H.DataStudio.Library.newButton().click();H.popover().findByText("Published table").click();- H.entityPickerModalItem(1, "Sample Database").click();- H.entityPickerModalItem(2, "Orders").click();- H.entityPickerModal().button("Publish").click();++ cy.log("Select a table and click 'Publish'");+ H.pickEntity({+ path: ["Databases", /Sample Database/, "Orders"],+ select: true,+ });+H.modal().findByText("Publish to").should("be.visible");H.modal().findByText("Data").should("be.visible");H.modal().button("Publish this table").click();+ cy.log("Verify the table is published");+ H.DataStudio.Tables.overviewPage().should("exist");+ H.DataStudio.Tables.header().findByDisplayValue("Orders").should("exist");+ H.DataStudio.breadcrumbs().findByRole("link", { name: "Data" }).click();+ H.DataStudio.Library.tableItem("Orders").should("exist");++ cy.log(+ "Verify tables in the entity picker are disabled if already published",+ );+ H.DataStudio.Library.newButton().click();+ H.popover().findByText("Published table").click();+ H.entityPickerModalItem(1, /Sample Database/).click();+ H.entityPickerModalItem(2, "Orders").should("have.attr", "data-disabled");+ H.entityPickerModalItem(2, "People").should(+ "not.have.attr",+ "data-disabled",+ );+ H.entityPickerModal().button("Close").click();+cy.log("Navigate back to Semantic layer via breadcrumbs");+ H.DataStudio.Library.tableItem("Orders").click();+ H.DataStudio.Tables.overviewPage().should("exist");H.DataStudio.breadcrumbs().findByRole("link", { name: "Semantic layer" }).click();@@ -697,6 +664,11 @@ describe("scenarios > data studio > library", () => {it("offers no bulk selection on remote-sync read-only instances", () => {H.createLibrary();H.publishTables({ table_ids: [ORDERS_ID] });++ cy.log("A writable instance shows a checkbox on the table row");+ H.DataStudio.Library.visit();+ H.DataStudio.Library.rowCheckbox("Orders").should("exist");+H.updateEnterpriseSettings({"remote-sync-url": "file:///tmp/library-read-only","remote-sync-type": "read-only",diff --git a/e2e/test/scenarios/data-studio/data-studio-metrics.cy.spec.ts b/e2e/test/scenarios/data-studio/data-studio-metrics.cy.spec.tsindex 0d25335b6d5..968adfedcf8 100644--- a/e2e/test/scenarios/data-studio/data-studio-metrics.cy.spec.ts+++ b/e2e/test/scenarios/data-studio/data-studio-metrics.cy.spec.ts@@ -11,8 +11,6 @@ describe("scenarios > data studio > library > metrics", () => {cy.intercept("POST", "/api/card").as("createCard");cy.intercept("PUT", "/api/card/*").as("updateCard");- cy.intercept("POST", "/api/collection").as("createCollection");- cy.intercept("PUT", "/api/collection/*").as("updateCollection");createLibraryWithItems();});@@ -113,7 +111,9 @@ describe("scenarios > data studio > library > metrics", () => {});});- it("should edit metric definition and save changes", () => {+ it("should rename the metric, link to the metrics explorer, change caching settings, and revert or warn about unsaved changes", () => {+ cy.intercept("PUT", "/api/cache").as("updateCacheConfig");+visitMetricPage();cy.log("Verify metric overview page displays correct data");@@ -121,6 +121,11 @@ describe("scenarios > data studio > library > metrics", () => {.findByDisplayValue("Trusted Orders Metric").should("be.visible");+ cy.log("Verify the Explore button points to the metrics explorer");+ H.DataStudio.Metrics.exploreLink()+ .should("have.attr", "href")+ .and("match", /\/explore\?metricId=\d+/);+cy.log("Update the metric name");H.DataStudio.Metrics.aboutPage().findByDisplayValue("Trusted Orders Metric")@@ -141,9 +146,38 @@ describe("scenarios > data studio > library > metrics", () => {.its("body.name").should("eq", "Updated Orders Metric"),);- });- it("should cancel editing and revert changes", () => {+ cy.log("Open the caching settings from the overflow menu");+ H.DataStudio.Metrics.moreMenu().click();+ H.popover().findByText("Caching").click();++ cy.log("Change the strategy to Duration and save");+ H.modal()+ .findByTestId("cache-strategy-select")+ .should("have.value", "Default")+ .click();+ // The Select dropdown renders in a portal; wait for it to open, then pick.+ H.selectDropdown()+ .findByRole("option", { name: /Duration/ })+ .click();+ H.fillCacheDuration(24);+ H.modal().findByTestId("strategy-form-submit-button").click();++ cy.wait("@updateCacheConfig");++ cy.log("Saving persists the change and closes the modal");+ H.modal().should("not.exist");++ cy.log("Re-open the caching settings to verify the change is persisted");+ H.DataStudio.Metrics.moreMenu().click();+ H.popover().findByText("Caching").click();+ H.modal()+ .findByTestId("cache-strategy-select")+ .should("have.value", "Duration");+ cy.realPress("Escape");+ H.modal().should("not.exist");++ cy.log("Cancel reverts changes, navigating away warns about them");visitMetricPage();cy.log("Navigate to definition tab");@@ -160,13 +194,6 @@ describe("scenarios > data studio > library > metrics", () => {cy.log("Verify changes were reverted");H.getNotebookStep("summarize").findByText("Count").should("be.visible");- });-- it("should show unsaved changes warning when navigating away", () => {- visitMetricPage();-- cy.log("Navigate to definition tab");- H.DataStudio.Metrics.definitionTab().click();cy.log("Change aggregation from Count to Sum");H.DataStudio.Metrics.queryEditor().should("be.visible");@@ -183,8 +210,11 @@ describe("scenarios > data studio > library > metrics", () => {cy.button("Cancel").click();});- cy.log("Verify we're still on the definition tab");+ cy.log("Verify we're still on the definition tab with the unsaved change");H.DataStudio.Metrics.queryEditor().should("be.visible");+ H.getNotebookStep("summarize")+ .findByText("Sum of Total")+ .should("be.visible");});it("should archive and restore a metric", () => {@@ -204,10 +234,8 @@ describe("scenarios > data studio > library > metrics", () => {cy.wait("@updateCard");- cy.log("Verify redirected to the library");- cy.url().should("include", "/data-studio/library");-cy.log("Verify the metric is archived");+ cy.findByTestId("archive-banner").should("be.visible");cy.get<number>("@trustedMetricId").then((id) =>cy.request("GET", `/api/card/${id}`)@@ -238,21 +266,7 @@ describe("scenarios > data studio > library > metrics", () => {);});- it("should view metric in the metrics explorer view via the Explore button", () => {- visitMetricPage();-- cy.log("Verify metric is loaded");- H.DataStudio.Metrics.aboutPage()- .findByDisplayValue("Trusted Orders Metric")- .should("be.visible");-- cy.log("Verify the Explore button points to the metrics explorer");- H.DataStudio.Metrics.exploreLink()- .should("have.attr", "href")- .and("match", /\/explore\?metricId=\d+/);- });-- it("should duplicate metric via more menu", () => {+ it("should duplicate and move a metric via more menu", () => {visitMetricPage();cy.log("Verify metric is loaded");@@ -301,12 +315,10 @@ describe("scenarios > data studio > library > metrics", () => {expect(names).to.include("Trusted Orders Metric - Duplicate");}),);- });- it("should move metric to different collection via more menu", () => {visitMetricPage();- cy.log("Verify metric is loaded");+ cy.log("Verify the original metric is loaded");H.DataStudio.Metrics.aboutPage().findByDisplayValue("Trusted Orders Metric").should("be.visible");@@ -337,7 +349,23 @@ describe("scenarios > data studio > library > metrics", () => {});describe("analytics events", () => {- it("should track metric_create_started and metric_created from browse metrics", () => {+ it("should track metric_create_started from the command palette and browse metrics, and metric_created", () => {+ cy.visit("/");++ cy.log("Open command palette and create metric");+ H.openCommandPalette();+ H.commandPaletteSearch("metric", false);+ cy.findByRole("option", { name: /New metric/ }).click();++ cy.log("Verify metric_create_started event was tracked");+ H.expectUnstructuredSnowplowEvent({+ event: "metric_create_started",+ triggered_from: "command_palette",+ });++ cy.log("Verify we're on the new metric page");+ cy.url().should("match", /\/metric\/new/);+cy.visit("/browse/metrics");cy.log("Click the plus button to create a new metric");@@ -368,59 +396,5 @@ describe("scenarios > data studio > library > metrics", () => {event: "metric_created",});});-- it("should track metric_create_started from command palette", () => {- cy.visit("/");-- cy.log("Open command palette and create metric");- H.openCommandPalette();- H.commandPaletteSearch("metric", false);- cy.findByRole("option", { name: /New metric/ }).click();-- cy.log("Verify metric_create_started event was tracked");- H.expectUnstructuredSnowplowEvent({- event: "metric_create_started",- triggered_from: "command_palette",- });-- cy.log("Verify we're on the new metric page");- cy.url().should("match", /\/metric\/new/);- });- });-- describe("caching", () => {- it("should allow changing metric caching settings", () => {- cy.intercept("PUT", "/api/cache").as("updateCacheConfig");-- visitMetricPage();-- cy.log("Open the caching settings from the overflow menu");- H.DataStudio.Metrics.moreMenu().click();- H.popover().findByText("Caching").click();-- cy.log("Change the strategy to Duration and save");- H.modal()- .findByTestId("cache-strategy-select")- .should("have.value", "Default")- .click();- // The Select dropdown renders in a portal; wait for it to open, then pick.- H.selectDropdown()- .findByRole("option", { name: /Duration/ })- .click();- H.fillCacheDuration(24);- H.modal().findByTestId("strategy-form-submit-button").click();-- cy.wait("@updateCacheConfig");-- cy.log("Saving persists the change and closes the modal");- H.modal().should("not.exist");-- cy.log("Re-open the caching settings to verify the change is persisted");- H.DataStudio.Metrics.moreMenu().click();- H.popover().findByText("Caching").click();- H.modal()- .findByTestId("cache-strategy-select")- .should("have.value", "Duration");- });});});diff --git a/e2e/test/scenarios/data-studio/data-studio-tables.cy.spec.ts b/e2e/test/scenarios/data-studio/data-studio-tables.cy.spec.tsindex dc3670a7203..b12c6831e35 100644--- a/e2e/test/scenarios/data-studio/data-studio-tables.cy.spec.ts+++ b/e2e/test/scenarios/data-studio/data-studio-tables.cy.spec.ts@@ -11,80 +11,26 @@ describe("scenarios > data studio > library > tables", () => {H.activateToken("pro-self-hosted");});- describe("header", () => {- it("should be able to change the name", () => {- H.createLibrary();- H.publishTables({ table_ids: [ORDERS_ID] });-- H.DataStudio.Tables.visitOverviewPage(ORDERS_ID);- H.DataStudio.Tables.nameInput().should("have.value", "Orders");- H.DataStudio.Tables.nameInput().clear().type("Orders changed").blur();- H.undoToastList().contains("Table name updated").should("be.visible");- });-- it("should be able to view the table in the query builder", () => {- H.createLibrary();- H.publishTables({ table_ids: [ORDERS_ID] });-- H.DataStudio.Tables.visitOverviewPage(ORDERS_ID);- H.DataStudio.Tables.moreMenu().click();- H.DataStudio.Tables.moreMenuViewTable();-- H.queryBuilderHeader().within(() => {- cy.icon("repository").should("be.visible");- cy.findByText("Data").should("be.visible");- cy.findByText("Orders").should("be.visible");- });- });-- it("should be able to unpublish a table", () => {- H.createLibrary();- H.publishTables({ table_ids: [ORDERS_ID] });- H.DataStudio.Library.visit();- H.DataStudio.Library.tableItem("Orders").click();- H.DataStudio.Tables.moreMenu().click();- H.popover().findByText("Unpublish").click();- H.modal().findByText("Unpublish this table").click();- H.DataStudio.Library.allTableItems().should("have.length", 0);- });- });-describe("overview", () => {- beforeEach(() => {+ it("should show the table overview, edit its description and name, and unpublish it", () => {H.createLibrary();H.publishTables({ table_ids: [ORDERS_ID] });H.DataStudio.Tables.visitOverviewPage(ORDERS_ID);- });- it("should show page breadcrumbs", () => {+ cy.log("Verify page breadcrumbs");H.DataStudio.breadcrumbs().within(() => {cy.findByRole("link", { name: "Semantic layer" }).should("be.visible");cy.findByRole("link", { name: "Data" }).should("be.visible");cy.findByText("Orders").should("be.visible");});- });- it("should be able to view the table data", () => {+ cy.log("Verify the table data");H.queryVisualizationRoot().within(() => {cy.findByText("Subtotal").should("be.visible");cy.findByText("110.93").should("be.visible");});- });- it("should be able to change the description", () => {- H.DataStudio.Tables.Overview.descriptionText()- .should("contain.text", "orders for a product")- .click();- H.DataStudio.Tables.Overview.descriptionInput()- .clear()- .type("Description changed")- .blur();- H.undoToastList()- .contains("Table description updated")- .should("be.visible");- });-- it("should be able to view additional properties in sidebar", () => {+ cy.log("Verify additional properties in the sidebar");H.DataStudio.Tables.Overview.descriptionSidebar().within(() => {cy.findByText("Entity type").should("be.visible");@@ -109,37 +55,66 @@ describe("scenarios > data studio > library > tables", () => {cy.findByText("Dependents").should("be.visible");});++ cy.log("Change the description");+ H.DataStudio.Tables.Overview.descriptionText()+ .should("contain.text", "orders for a product")+ .click();+ H.DataStudio.Tables.Overview.descriptionInput()+ .clear()+ .type("Description changed")+ .blur();+ H.undoToastList()+ .contains("Table description updated")+ .should("be.visible");++ cy.log("Change the name");+ H.DataStudio.Tables.nameInput().should("have.value", "Orders");+ H.DataStudio.Tables.nameInput().clear().type("Orders changed").blur();+ H.undoToastList().contains("Table name updated").should("be.visible");++ cy.log("Unpublish the table");+ H.DataStudio.Library.visit();+ H.DataStudio.Library.tableItem("Orders changed").click();+ H.DataStudio.Tables.moreMenu().click();+ H.popover().findByText("Unpublish").click();+ H.modal().findByText("Unpublish this table").click();+ H.DataStudio.Library.emptyStateRow(+ "Cleaned, pre-transformed data sources ready for exploring",+ ).should("be.visible");+ H.DataStudio.Library.allTableItems().should("have.length", 0);});});describe("fields", () => {- beforeEach(() => {+ it("should view table dependencies, close field panels, rename a field, and view the table in the query builder", () => {H.createLibrary();H.publishTables({ table_ids: [ORDERS_ID] });- });+ H.createQuestion({+ name: "Test question",+ query: { "source-table": ORDERS_ID },+ });+ H.waitForBackfillComplete();- it("should be able to rename fields", () => {+ cy.log("View the table dependencies");H.DataStudio.Tables.visitOverviewPage(ORDERS_ID);- H.tableHeaderColumn("Total").should("be.visible");-- H.DataStudio.Tables.fieldsTab().click();- H.DataModel.TableSection.clickField("Total");- H.DataModel.FieldSection.getNameInput()- .clear()- .type("Total changed")- .blur();- H.undoToast().findByText("Name of Total updated").should("be.visible");-- H.DataStudio.Tables.overviewTab().click();- H.tableHeaderColumn("Total changed").should("be.visible");- });+ H.DataStudio.Tables.dependenciesTab().click();+ H.DependencyGraph.graph().within(() => {+ cy.findByText("Orders").should("be.visible");+ cy.findByText(/question/).click();+ });+ H.DependencyGraph.dependencyPanel()+ .findByText("Test question")+ .should("be.visible");- it("should allow you to close field details and preview panels", () => {+ cy.log("Close the field details and preview panels");H.DataStudio.Tables.visitFieldsPage(ORDERS_ID);H.DataModel.TableSection.clickField("Total");H.DataModel.FieldSection.getPreviewButton().click({scrollBehavior: "center",});+ H.DataModel.PreviewSection.get().should("be.visible");+ H.DataModel.FieldSection.get().should("be.visible");H.DataModel.FieldSection.getCloseButton().click();@@ -147,29 +122,33 @@ describe("scenarios > data studio > library > tables", () => {H.DataModel.FieldSection.get().should("not.exist");H.DataModel.TableSection.clickField("Discount");- H.DataModel.PreviewSection.get().should("not.exist");H.DataModel.FieldSection.get().should("exist");- });- });+ H.DataModel.PreviewSection.get().should("not.exist");- describe("dependencies", () => {- it("should be able to view dependencies for a table", () => {- H.createLibrary();- H.publishTables({ table_ids: [ORDERS_ID] });- H.createQuestion({- name: "Test question",- query: { "source-table": ORDERS_ID },- });- H.waitForBackfillComplete();- H.DataStudio.Tables.visitOverviewPage(ORDERS_ID);- H.DataStudio.Tables.dependenciesTab().click();- H.DependencyGraph.graph().within(() => {+ cy.log("Rename a field");+ H.DataStudio.Tables.overviewTab().click();+ H.tableHeaderColumn("Total").should("be.visible");++ H.DataStudio.Tables.fieldsTab().click();+ H.DataModel.TableSection.clickField("Total");+ H.DataModel.FieldSection.getNameInput()+ .clear()+ .type("Total changed")+ .blur();+ H.undoToast().findByText("Name of Total updated").should("be.visible");++ H.DataStudio.Tables.overviewTab().click();+ H.tableHeaderColumn("Total changed").should("be.visible");++ cy.log("View the table in the query builder");+ H.DataStudio.Tables.moreMenu().click();+ H.DataStudio.Tables.moreMenuViewTable();++ H.queryBuilderHeader().within(() => {+ cy.icon("repository").should("be.visible");+ cy.findByText("Data").should("be.visible");cy.findByText("Orders").should("be.visible");- cy.findByText(/question/).click();});- H.DependencyGraph.dependencyPanel()- .findByText("Test question")- .should("be.visible");});});});diff --git a/e2e/test/scenarios/data-studio/measures/measures-data-studio.cy.spec.ts b/e2e/test/scenarios/data-studio/measures/measures-data-studio.cy.spec.tsindex f911e02539a..9ba37f93dad 100644--- a/e2e/test/scenarios/data-studio/measures/measures-data-studio.cy.spec.ts+++ b/e2e/test/scenarios/data-studio/measures/measures-data-studio.cy.spec.ts@@ -19,30 +19,6 @@ describe("scenarios > data studio > data model > measures", () => {});describe("Measure list", () => {- it("should show empty state and navigation when no measures exist", () => {- visitDataStudioMeasures(ORDERS_ID);-- cy.log("verify empty state");- MeasureList.getEmptyState().scrollIntoView().should("be.visible");- MeasureList.get()- .findByText(- "Create a measure to define a reusable aggregation for this table.",- )- .should("be.visible");-- cy.log("verify new measure link and navigation");- MeasureList.getNewMeasureLink().scrollIntoView().click();-- cy.log("verify measure_create_started event");- H.expectUnstructuredSnowplowEvent({- event: "measure_create_started",- triggered_from: "data_studio_measures_list",- target_id: ORDERS_ID,- });-- cy.url().should("include", `${getMeasuresBaseUrl(ORDERS_ID)}/new`);- });-it("should display measures and allow navigation to edit page", () => {createTestMeasure({name: "Total Revenue",@@ -97,9 +73,17 @@ describe("scenarios > data studio > data model > measures", () => {});describe("Measure creation", () => {- it("should create a measure with aggregation and verify across features", () => {+ it("should create a measure with aggregation, confirm leaving with unsaved changes, and verify it in the query builder", () => {visitDataStudioMeasures(ORDERS_ID);+ cy.log("verify empty state");+ MeasureList.getEmptyState().scrollIntoView().should("be.visible");+ MeasureList.get()+ .findByText(+ "Create a measure to define a reusable aggregation for this table.",+ )+ .should("be.visible");+cy.log("navigate to new measure page");MeasureList.getNewMeasureLink().scrollIntoView().click();@@ -109,10 +93,19 @@ describe("scenarios > data studio > data model > measures", () => {triggered_from: "data_studio_measures_list",target_id: ORDERS_ID,});+ cy.url().should("include", `${getMeasuresBaseUrl(ORDERS_ID)}/new`);cy.log("fill in measure name");MeasureEditor.getNameInput().type("Total Revenue");+ cy.log("verify leave confirmation with unsaved changes");+ MeasureEditor.getBreadcrumb("Orders").click();+ H.modal().within(() => {+ cy.findByText("Discard your changes?").should("be.visible");+ cy.button("Cancel").click();+ });+ MeasureEditor.get().findByText("Total Revenue").should("be.visible");+cy.log("add aggregation");MeasureEditor.getAggregationPlaceholder().click();H.popover().findByText("Sum of ...").click();@@ -171,7 +164,7 @@ describe("scenarios > data studio > data model > measures", () => {});describe("Measure editing", () => {- it("should display and update existing measure", () => {+ it("should display and update existing measure, and navigate back to measures tab via breadcrumb", () => {createTestMeasure({name: "Test Measure",description: "Test description",@@ -203,17 +196,9 @@ describe("scenarios > data studio > data model > measures", () => {MeasureEditor.getDescriptionInput().clear().type("Updated description");MeasureEditor.getSaveButton().click();cy.wait("@updateMeasure");+ H.undoToastList().should("contain.text", "Measure updated");- cy.log("verify updated measure in query builder");- verifyMeasureInQueryBuilder("Test Measure Updated");- });-- it("should navigate back to measures tab via breadcrumb", () => {- createTestMeasure({ name: "Breadcrumb Test Measure" });- cy.get<number>("@measureId").then((measureId) => {- visitDataModelMeasure(ORDERS_ID, measureId);- });-+ cy.log("navigate back to measures tab via breadcrumb");MeasureEditor.getBreadcrumb("Orders").click();cy.url().should(@@ -223,11 +208,15 @@ describe("scenarios > data studio > data model > measures", () => {cy.findByRole("tab", { name: /Measures/i }).scrollIntoView().should("have.attr", "aria-selected", "true");++ cy.log("verify updated measure in query builder");+ verifyMeasureInQueryBuilder("Test Measure Updated");});});describe("Measure deletion", () => {it("should remove measure via more menu", () => {+ createTestMeasure({ name: "Kept Measure" });createTestMeasure({ name: "Measure to Delete" });cy.get<number>("@measureId").then((measureId) => {visitDataModelMeasure(ORDERS_ID, measureId);@@ -245,33 +234,16 @@ describe("scenarios > data studio > data model > measures", () => {"include",`/data-studio/data/database/${SAMPLE_DB_ID}/schema/${SAMPLE_DB_SCHEMA_ID}/table/${ORDERS_ID}/measures`,);- MeasureList.get()- .findByText("Measure to Delete", { timeout: 1000 })- .should("not.exist");+ MeasureList.getMeasure("Kept Measure")+ .scrollIntoView()+ .should("be.visible");+ MeasureList.get().findByText("Measure to Delete").should("not.exist");cy.log("verify measure removed from query builder");- verifyMeasureNotInQueryBuilder("Total Revenue");- });- });-- describe("Unsaved changes", () => {- it("should show leave confirmation with unsaved changes", () => {- visitDataStudioMeasures(ORDERS_ID);-- MeasureList.getNewMeasureLink().scrollIntoView().click();- MeasureEditor.getNameInput().type("Unsaved Measure");-- cy.log("attempt to navigate away");- MeasureEditor.getBreadcrumb("Orders").click();-- cy.log("verify confirmation modal");- H.modal().within(() => {- cy.findByText("Discard your changes?").should("be.visible");- cy.button("Cancel").click();+ verifyMeasureNotInQueryBuilder({+ removedMeasureName: "Measure to Delete",+ keptMeasureName: "Kept Measure",});-- cy.log("verify still on editor");- MeasureEditor.get().findByText("Unsaved Measure").should("be.visible");});});@@ -312,7 +284,7 @@ describe("scenarios > data studio > data model > measures", () => {});describe("Revision history", () => {- it("should display revision history with changes to name, description, and aggregation", () => {+ it("should display revision history with changes to name, description, and aggregation, and the dependency graph", () => {createTestMeasure({name: "Original Name",description: "Original description",@@ -389,15 +361,6 @@ describe("scenarios > data studio > data model > measures", () => {.scrollIntoView().should("be.visible");});- });- });-- describe("Dependencies", () => {- it("should display dependency graph for a measure", () => {- createTestMeasure({ name: "Dependencies Test Measure" });- cy.get<number>("@measureId").then((measureId) => {- visitDataModelMeasure(ORDERS_ID, measureId);- });cy.log("navigate to dependencies tab");MeasureEditor.getDependenciesTab().click();@@ -410,15 +373,17 @@ describe("scenarios > data studio > data model > measures", () => {);});H.DependencyGraph.graph().should("be.visible");- H.DependencyGraph.graph()- .findByText("Dependencies Test Measure")- .should("be.visible");+ H.DependencyGraph.graph().findByText("Updated Name").should("be.visible");});});describe("Readonly access for data analysts", () => {- it("should show measures in list but hide New measure button for non-admin", () => {+ it("should show measures in list and measure detail in readonly mode for non-admin", () => {createTestMeasure({ name: "Readonly Test Measure" });+ createTestMeasure({+ name: "Readonly Detail Measure",+ description: "Test description for readonly",+ });H.setUserAsAnalyst(NODATA_USER_ID);cy.signIn("nodata");@@ -439,49 +404,34 @@ describe("scenarios > data studio > data model > measures", () => {`/data-studio/data/database/${SAMPLE_DB_ID}/schema/${SAMPLE_DB_SCHEMA_ID}/table/${ORDERS_ID}/measures/new`,);cy.url().should("include", "/unauthorized");- });- it("should display measure detail in readonly mode for non-admin", () => {- createTestMeasure({- name: "Readonly Detail Measure",- description: "Test description for readonly",+ cy.get<number>("@measureId").then((measureId) => {+ visitDataModelMeasure(ORDERS_ID, measureId);});- cy.get<number>("@measureId").then((measureId) => {- H.setUserAsAnalyst(NODATA_USER_ID);- cy.signIn("nodata");+ cy.log("verify measure name input is disabled");+ MeasureEditor.get()+ .findByDisplayValue("Readonly Detail Measure")+ .should("be.disabled");- visitDataModelMeasure(ORDERS_ID, measureId);+ cy.log("verify description is displayed as plain text");+ MeasureEditor.get().findByText("Description").should("be.visible");+ MeasureEditor.get()+ .findByText("Test description for readonly")+ .should("be.visible");- cy.log("verify measure name input is disabled");- MeasureEditor.get()- .findByDisplayValue("Readonly Detail Measure")- .should("be.disabled");+ cy.log("verify Remove measure option is hidden in actions menu");+ MeasureEditor.getActionsButton().click();+ H.popover().findByText("Explore").should("be.visible");+ H.popover().findByText("Remove measure").should("not.exist");+ cy.realPress("Escape");- cy.log("verify description is displayed as plain text");- MeasureEditor.get().findByText("Description").should("be.visible");- MeasureEditor.get()- .findByText("Test description for readonly")+ cy.log("verify revision history is still accessible");+ MeasureEditor.getRevisionHistoryTab().click();+ MeasureRevisionHistory.get().within(() => {+ cy.findByText(/created this measure/i)+ .scrollIntoView().should("be.visible");-- cy.log("verify Save button is not visible");- MeasureEditor.get()- .findByRole("button", { name: /Save/i })- .should("not.exist");-- cy.log("verify Remove measure option is hidden in actions menu");- MeasureEditor.getActionsButton().click();- H.popover().findByText("Explore").should("be.visible");- H.popover().findByText("Remove measure").should("not.exist");- cy.realPress("Escape");-- cy.log("verify revision history is still accessible");- MeasureEditor.getRevisionHistoryTab().click();- MeasureRevisionHistory.get().within(() => {- cy.findByText(/created this measure/i)- .scrollIntoView()- .should("be.visible");- });});});});@@ -557,12 +507,19 @@ function verifyMeasureInQueryBuilder(cy.findByTestId("scalar-value").should("be.visible");}-function verifyMeasureNotInQueryBuilder(- measureName: string,- tableId: number = ORDERS_ID,-) {- H.openTable({ table: tableId, mode: "notebook" });+function verifyMeasureNotInQueryBuilder({+ removedMeasureName,+ keptMeasureName,+}: {+ removedMeasureName: string;+ keptMeasureName: string;+}) {+ H.openTable({ table: ORDERS_ID, mode: "notebook" });H.getNotebookStep("data").button("Summarize").click();- H.popover().findByText(measureName).should("not.exist");+ H.popover().within(() => {+ cy.findByText("Measures").click();+ cy.findByText(keptMeasureName).should("be.visible");+ cy.findByText(removedMeasureName).should("not.exist");+ });}diff --git a/e2e/test/scenarios/data-studio/measures/measures-published-tables.cy.spec.ts b/e2e/test/scenarios/data-studio/measures/measures-published-tables.cy.spec.tsindex 8e4f5eafd16..fc002f4d91a 100644--- a/e2e/test/scenarios/data-studio/measures/measures-published-tables.cy.spec.ts+++ b/e2e/test/scenarios/data-studio/measures/measures-published-tables.cy.spec.ts@@ -5,7 +5,7 @@ const { H } = cy;const { MeasureList, MeasureEditor } = H.DataModel;const { ORDERS, ORDERS_ID } = SAMPLE_DATABASE;-// Majority of the measures pages functionality is covered in the data-model/measures-data-studio.cy.spec.ts spec+// Majority of the measures pages functionality is covered in the measures/measures-data-studio.cy.spec.ts spec// This spec is focused on the published tables measures pages functionality while doing some smoke testsdescribe("scenarios > data studio > library > published tables > measures", () => {beforeEach(() => {@@ -20,18 +20,6 @@ describe("scenarios > data studio > library > published tables > measures", () =});describe("Measure list", () => {- it("should show empty state and navigate to new measure page", () => {- H.DataStudio.Tables.visitMeasuresPage(ORDERS_ID);-- MeasureList.getEmptyState().scrollIntoView().should("be.visible");- MeasureList.getNewMeasureLink().scrollIntoView().click();-- cy.url().should(- "include",- `/data-studio/library/tables/${ORDERS_ID}/measures/new`,- );- });-it("should display measures and navigate to edit page", () => {createTestMeasure({ name: "Total Revenue" });H.DataStudio.Tables.visitMeasuresPage(ORDERS_ID);@@ -68,7 +56,12 @@ describe("scenarios > data studio > library > published tables > measures", () =describe("Measure creation", () => {it("should create a measure and redirect to edit page", () => {H.DataStudio.Tables.visitMeasuresPage(ORDERS_ID);- MeasureList.getNewMeasureLink().click();+ MeasureList.getEmptyState().scrollIntoView().should("be.visible");+ MeasureList.getNewMeasureLink().scrollIntoView().click();+ cy.url().should(+ "include",+ `/data-studio/library/tables/${ORDERS_ID}/measures/new`,+ );MeasureEditor.getNameInput().type("Total Revenue");MeasureEditor.getAggregationPlaceholder().click();@@ -87,21 +80,13 @@ describe("scenarios > data studio > library > published tables > measures", () =});describe("Breadcrumbs", () => {- it("should display collection-based breadcrumbs", () => {- createTestMeasure({ name: "Breadcrumb Test Measure" });- cy.get<number>("@measureId").then((measureId) => {- H.DataStudio.Tables.visitMeasurePage(ORDERS_ID, measureId);- });-- MeasureEditor.get().findByText("Data").should("be.visible");- });-- it("should navigate back to published table measures via breadcrumb", () => {+ it("should display collection-based breadcrumbs and navigate back to published table measures", () => {createTestMeasure({ name: "Breadcrumb Nav Test" });cy.get<number>("@measureId").then((measureId) => {H.DataStudio.Tables.visitMeasurePage(ORDERS_ID, measureId);});+ MeasureEditor.get().findByText("Data").should("be.visible");MeasureEditor.getBreadcrumb("Orders").click();cy.url().should(diff --git a/e2e/test/scenarios/data-studio/measures/measures-queries.cy.spec.ts b/e2e/test/scenarios/data-studio/measures/measures-queries.cy.spec.tsindex 6a534fb20c3..fad60a67794 100644--- a/e2e/test/scenarios/data-studio/measures/measures-queries.cy.spec.ts+++ b/e2e/test/scenarios/data-studio/measures/measures-queries.cy.spec.ts@@ -1,6 +1,5 @@import { SAMPLE_DB_ID } from "e2e/support/cypress_data";import { SAMPLE_DATABASE } from "e2e/support/cypress_sample_database";-import { openNotebook } from "e2e/support/helpers";import type { Measure, TableId } from "metabase-types/api";const { H } = cy;@@ -28,7 +27,7 @@ describe("scenarios > data studio > measures > queries", () => {verifyScalarValue("18,760");});- it("should create a measure with with a column from the main data source", () => {+ it("should create a measure with a column from the main data source", () => {startNewMeasure();MeasureEditor.getAggregationPlaceholder().click();H.popover().within(() => {@@ -41,7 +40,7 @@ describe("scenarios > data studio > measures > queries", () => {verifyScalarValue("1,510,621.68");});- it("should create a measure with with a column from the main data source using offset", () => {+ it("should create a measure with a column from the main data source using offset", () => {startNewMeasure();MeasureEditor.getAggregationPlaceholder().click();H.popover().findByText("Custom Expression").click();@@ -179,31 +178,6 @@ describe("scenarios > data studio > measures > queries", () => {verifyScalarValue("1,510,621");});- it("should create a measure based on another measure with an identity expression", () => {- H.createMeasure({- name: "TotalMeasure",- definition: {- database: SAMPLE_DB_ID,- type: "query",- query: {- "source-table": ORDERS_ID,- aggregation: [["sum", ["field", ORDERS.TOTAL, null]]],- },- },- });-- startNewMeasure();- MeasureEditor.getAggregationPlaceholder().click();- H.popover().findByText("Custom Expression").click();- H.CustomExpressionEditor.type("[TotalMeasure]");- H.CustomExpressionEditor.nameInput().type("Custom");- H.popover().button("Done").click();- saveMeasure();-- useMeasureInAdhocQuestion();- verifyScalarValue("1,510,621.68");- });-it("should not be possible to create a measure that references itself", () => {cy.log("create a new measure");H.DataStudio.Tables.visitNewMeasurePage(ORDERS_ID);@@ -222,7 +196,7 @@ describe("scenarios > data studio > measures > queries", () => {H.popover().button("Update").click();MeasureEditor.getSaveButton().click();- H.undoToast().should("contain.text", "Failed to update measure");+ H.undoToastList().should("contain.text", "Failed to update measure");});it("should not be possible to create a measure that references a metric", () => {@@ -240,6 +214,7 @@ describe("scenarios > data studio > measures > queries", () => {MeasureEditor.getNameInput().type(MEASURE_NAME);MeasureEditor.getAggregationPlaceholder().click();+ H.popover().findByText("Custom Expression").should("be.visible");H.popover().findByText("Metrics").should("not.exist");H.popover().findByText("Custom Expression").click();@@ -263,32 +238,7 @@ describe("scenarios > data studio > measures > queries", () => {verifyScalarValue("18,758");});- it("should be possible to create measures with filters like CountIf based on segments", () => {- H.createSegment({- name: "LargeTotal",- definition: {- type: "query",- database: SAMPLE_DB_ID,- query: {- "source-table": ORDERS_ID,- filter: [">", ["field", ORDERS.TOTAL, null], 10],- },- },- });-- startNewMeasure();- MeasureEditor.getAggregationPlaceholder().click();- H.popover().findByText("Custom Expression").click();- H.CustomExpressionEditor.type("CountIf([LargeTotal])");- H.CustomExpressionEditor.nameInput().type("Custom");- H.popover().button("Done").click();- saveMeasure();-- useMeasureInAdhocQuestion();- verifyScalarValue("18,758");- });-- it("should be possible to create measures with filters like based on segments that are nested", () => {+ it("should be possible to create measures with filters based on segments that are nested", () => {H.createSegment({name: "LargeTotal",definition: {@@ -328,37 +278,9 @@ describe("scenarios > data studio > measures > queries", () => {useMeasureInAdhocQuestion();verifyScalarValue("18,759");});-- it("should be possible to offset a measure in a query", () => {- H.createMeasure({- name: MEASURE_NAME,- definition: {- database: SAMPLE_DB_ID,- type: "query",- query: {- "source-table": ORDERS_ID,- aggregation: [["sum", ["field", ORDERS.TOTAL, null]]],- },- },- });-- useMeasureInAdhocQuestion({- customizeQuery() {- H.getNotebookStep("summarize").findByText("Table Measure").click();- H.CustomExpressionEditor.clear().type(- `Offset([${MEASURE_NAME}], -1)`,- );- H.popover().button("Update").click();-- breakout("Created At");- },- });-- verifyRowValues([["April 2025"], ["May 2025", "52.76"]]);- });});- it("should be possible to order by an aggregation using a measure directly", () => {+ it("should be possible to use a measure in queries, follow up stages, pivot tables and saved questions, and to rename the measure without breaking queries", () => {H.createMeasure({name: MEASURE_NAME,definition: {@@ -369,8 +291,24 @@ describe("scenarios > data studio > measures > queries", () => {aggregation: [["sum", ["field", ORDERS.TOTAL, null]]],},},+ }).then(({ body: measure }) => {+ cy.wrap(measure.id).as("measureId");+ });++ cy.log("offset the measure in a query");+ useMeasureInAdhocQuestion({+ customizeQuery() {+ H.getNotebookStep("summarize").findByText("Table Measure").click();+ H.CustomExpressionEditor.clear().type(`Offset([${MEASURE_NAME}], -1)`);+ H.popover().button("Update").click();++ breakout("Created At");+ },});+ verifyRowValues([["April 2025"], ["May 2025", "52.76"]]);++ cy.log("order by the measure directly");useMeasureInAdhocQuestion({customizeQuery() {breakout("Created At");@@ -385,21 +323,8 @@ describe("scenarios > data studio > measures > queries", () => {["January 2029", "52,249.59"],["January 2028", "51,634.16"],]);- });-- it("should be possible to order by an aggregation using a custom expression based on a measure", () => {- H.createMeasure({- name: MEASURE_NAME,- definition: {- database: SAMPLE_DB_ID,- type: "query",- query: {- "source-table": ORDERS_ID,- aggregation: [["sum", ["field", ORDERS.TOTAL, null]]],- },- },- });+ cy.log("order by a custom expression based on the measure");useMeasureInAdhocQuestion({customizeQuery() {H.getNotebookStep("summarize").findByText("Table Measure").click();@@ -421,96 +346,56 @@ describe("scenarios > data studio > measures > queries", () => {["April 2029", "16"],["May 2025", "17"],]);- });-- describe("follow up stages", () => {- it("should be possible to use results of a measure in follow up stages", () => {- H.createMeasure({- name: MEASURE_NAME,- definition: {- database: SAMPLE_DB_ID,- type: "query",- query: {- "source-table": ORDERS_ID,- aggregation: [["sum", ["field", ORDERS.TOTAL, null]]],- },- },- });- useMeasureInAdhocQuestion({- customizeQuery() {- breakout("Created At");+ cy.log("use results of the measure in follow up stages");+ useMeasureInAdhocQuestion({+ customizeQuery() {+ breakout("Created At");- H.getNotebookStep("summarize").button("Filter").click();- H.popover().within(() => {- cy.findByText(MEASURE_NAME).click();- cy.findByPlaceholderText("Min").type("100");- cy.button("Add filter").click();- });+ H.getNotebookStep("summarize").button("Filter").click();+ H.popover().within(() => {+ cy.findByText(MEASURE_NAME).click();+ cy.findByPlaceholderText("Min").type("100");+ cy.button("Add filter").click();+ });- H.getNotebookStep("summarize").button("Custom column").click();- H.enterCustomColumnDetails({- formula: `floor([${MEASURE_NAME}] * 2)`,- name: "Double measure",- clickDone: true,- });+ H.getNotebookStep("summarize").button("Custom column").click();+ H.enterCustomColumnDetails({+ formula: `floor([${MEASURE_NAME}] * 2)`,+ name: "Double measure",+ clickDone: true,+ });- H.getNotebookStep("filter", { stage: 1 })- .findByText("Summarize")- .click();- H.popover().within(() => {- cy.findByText("Minimum of ...").click();- cy.findByText("Double measure").click();- });- },- });- verifyScalarValue("2,531");+ H.getNotebookStep("filter", { stage: 1 })+ .findByText("Summarize")+ .click();+ H.popover().within(() => {+ cy.findByText("Minimum of ...").click();+ cy.findByText("Double measure").click();+ });+ },});+ verifyScalarValue("2,531");- it("should be possible to join on a measure in a follow up stage", () => {- H.createMeasure({- name: MEASURE_NAME,- definition: {- database: SAMPLE_DB_ID,- type: "query",- query: {- "source-table": ORDERS_ID,- aggregation: [["sum", ["field", ORDERS.TOTAL, null]]],- },- },- });-- useMeasureInAdhocQuestion({- customizeQuery() {- breakout("Created At");-- H.getNotebookStep("summarize").button("Join data").click();- H.popover().within(() => {- cy.findByText("Sample Database").click();- cy.findByText("Orders").click();- });-- H.popover().findByText("Table Measure").click();- H.popover().findByText("Total").click();- },- });+ cy.log("join on the measure in a follow up stage");+ useMeasureInAdhocQuestion({+ customizeQuery() {+ breakout("Created At");- verifyRowValues([["April 2025", "52.76", "8685"]]);- });- });+ H.getNotebookStep("summarize").button("Join data").click();+ H.popover().within(() => {+ cy.findByText("Sample Database").click();+ cy.findByText("Orders").click();+ });- it("should be possible to join on a measure in a follow up stage with a custom expression", () => {- H.createMeasure({- name: MEASURE_NAME,- definition: {- database: SAMPLE_DB_ID,- type: "query",- query: {- "source-table": ORDERS_ID,- aggregation: [["sum", ["field", ORDERS.TOTAL, null]]],- },+ H.popover().findByText("Table Measure").click();+ H.popover().findByText("Total").click();},});++ verifyRowValues([["April 2025", "52.76", "8685"]]);++ cy.log("join on the measure in a follow up stage with a custom expression");useMeasureInAdhocQuestion({customizeQuery() {breakout("Created At");@@ -533,59 +418,156 @@ describe("scenarios > data studio > measures > queries", () => {});verifyRowValues([["April 2025", "52.76", "5", "1"]]);- });- describe("measure refs", () => {- it("should be possible to rename a measure without breaking queries that reference it", () => {- H.createMeasure({- name: MEASURE_NAME,- definition: {- database: SAMPLE_DB_ID,- type: "query",+ cy.log("rename an aggregation expression based on the measure");+ useMeasureInAdhocQuestion({+ customizeQuery() {+ H.getNotebookStep("summarize").findByText("Table Measure").click();+ H.CustomExpressionEditor.nameInput()+ .clear()+ .type("Renamed aggregation");+ H.popover().button("Update").click();+ },+ });++ verifyScalarValue("1,510,621.68");++ cy.log("use the measure in a pivot table");+ cy.get<number>("@measureId").then((measureId) => {+ H.createQuestion(+ {+ name: "Question with measure",+ display: "pivot",+ visualization_settings: {+ "table.pivot_column": "Created At: Week",+ "table.cell_column": "Table Measure",+ },query: {"source-table": ORDERS_ID,- aggregation: [["sum", ["field", ORDERS.TOTAL, null]]],+ aggregation: [+ ["measure", { "display-name": MEASURE_NAME }, measureId],+ ],+ breakout: [+ ["field", ORDERS.CREATED_AT, { "temporal-unit": "year" }],+ [+ "field",+ PRODUCTS.CATEGORY,+ { "base-type": "type/Text", "source-field": ORDERS.PRODUCT_ID },+ ],+ ],},},- }).then(({ body: measure }) => {- useMeasureInAdhocQuestion();+ { visitQuestion: true },+ );+ });- H.updateMeasure({- id: measure.id,- name: "Renamed measure",- });+ cy.findByTestId("pivot-table").within(() => {+ cy.findByText("Row totals").should("be.visible");+ cy.findByText("Grand totals").should("be.visible");+ cy.findAllByTestId("pivot-table-cell")+ .should("have.length", 42)+ .eq(12) // a random cell+ .should("have.text", "9,031.56");+ });- cy.reload();- verifyScalarValue("1,510,621.68");+ cy.log("use the measure results in a saved question");+ cy.get<number>("@measureId").then((measureId) => {+ H.createQuestion({+ name: "Question with measure",+ query: {+ "source-table": ORDERS_ID,+ aggregation: [+ ["measure", { "display-name": MEASURE_NAME }, measureId],+ ],+ breakout: [["field", ORDERS.CREATED_AT, { "temporal-unit": "week" }]],+ },+ }).then(({ body: question }) => {+ cy.wrap(question.id).as("questionId");});});- it("should be possible to rename an aggregation expression based on a measure without breaking it", () => {- H.createMeasure({- name: MEASURE_NAME,- definition: {- database: SAMPLE_DB_ID,- type: "query",+ cy.log("follow up question");+ cy.get<number>("@questionId").then((questionId) => {+ H.createQuestion(+ {query: {- "source-table": ORDERS_ID,- aggregation: [["sum", ["field", ORDERS.TOTAL, null]]],+ "source-table": `card__${questionId}`,},+ display: "scalar",},- });+ { visitQuestion: true },+ );+ });- useMeasureInAdhocQuestion({- customizeQuery() {- H.getNotebookStep("summarize").findByText("Table Measure").click();- H.CustomExpressionEditor.nameInput()- .clear()- .type("Renamed aggregation");- H.popover().button("Update").click();+ H.openNotebook();++ H.filter({ mode: "notebook" });+ H.popover().within(() => {+ cy.findByText(MEASURE_NAME).click();+ cy.findByPlaceholderText("Min").type("100");+ cy.button("Add filter").click();+ });++ H.summarize({ mode: "notebook" });+ H.popover().findByText("Custom Expression").click();+ H.enterCustomColumnDetails({+ formula: `Sum([${MEASURE_NAME}])`,+ name: "Table Measure Sum",+ clickDone: true,+ });++ H.visualize();+ verifyScalarValue("1,510,568.93");++ cy.log("follow up model");+ cy.get<number>("@questionId").then((questionId) => {+ H.createQuestion(+ {+ type: "model",+ query: {+ "source-table": `card__${questionId}`,+ },+ display: "scalar",},- });+ { visitQuestion: true },+ );+ });- verifyScalarValue("1,510,621.68");+ H.openQuestionActions("Edit query definition");++ H.filter({ mode: "notebook" });+ H.popover().within(() => {+ cy.findByText(MEASURE_NAME).click();+ cy.findByPlaceholderText("Min").type("100");+ cy.button("Add filter").click();});+ H.summarize({ mode: "notebook" });+ H.popover().findByText("Custom Expression").click();+ H.enterCustomColumnDetails({+ formula: `Sum([${MEASURE_NAME}])`,+ name: "Table Measure Sum",+ clickDone: true,+ });++ cy.findByTestId("dataset-edit-bar").button("Save changes").click();+ verifyScalarValue("1,510,568.93");++ cy.log("rename the measure without breaking queries that reference it");+ useMeasureInAdhocQuestion();++ cy.get<number>("@measureId").then((measureId) => {+ H.updateMeasure({+ id: measureId,+ name: "Renamed measure",+ });+ });++ cy.reload();+ verifyScalarValue("1,510,621.68");+ });++ describe("measure refs", () => {it("changing the top-level aggregation expression in a measure might break queries that reference it in follow up stages", () => {H.createMeasure({name: MEASURE_NAME,@@ -611,7 +593,7 @@ describe("scenarios > data studio > measures > queries", () => {}).then(({ body: question }) => {cy.log("Add a second stage that references the measure");H.visitQuestion(question.id);- openNotebook();+ H.openNotebook();H.getNotebookStep("summarize").findByText("Filter").click();H.popover().within(() => {cy.findByText(MEASURE_NAME).click();@@ -640,7 +622,7 @@ describe("scenarios > data studio > measures > queries", () => {},});- cy.log("Add a second stage that references the measure");+ cy.log("verify the question with the changed measure shows an error");H.visitQuestion(question.id);cy.findByTestId("query-builder-main").findByText("There was a problem with your question")@@ -650,57 +632,8 @@ describe("scenarios > data studio > measures > queries", () => {});});- it("should be possible to use a measure in a pivot table", () => {- H.createMeasure({- name: MEASURE_NAME,- definition: {- database: SAMPLE_DB_ID,- type: "query",- query: {- "source-table": ORDERS_ID,- aggregation: [["sum", ["field", ORDERS.TOTAL, null]]],- },- },- }).then(({ body: measure }) => {- H.createQuestion(- {- name: "Question with measure",- display: "pivot",- visualization_settings: {- "table.pivot_column": "Created At: Week",- "table.cell_column": "Table Measure",- },- query: {- "source-table": ORDERS_ID,- aggregation: [- ["measure", { "display-name": measure.name }, measure.id],- ],- breakout: [- ["field", ORDERS.CREATED_AT, { "temporal-unit": "year" }],- [- "field",- PRODUCTS.CATEGORY,- { "base-type": "type/Text", "source-field": ORDERS.PRODUCT_ID },- ],- ],- },- },- { visitQuestion: true },- );- });-- cy.findByTestId("pivot-table").within(() => {- cy.findByText("Row totals").should("be.visible");- cy.findByText("Grand totals").should("be.visible");- cy.findAllByTestId("pivot-table-cell")- .should("have.length", 42)- .eq(12) // a random cell- .should("have.text", "9,031.56");- });- });-- describe("using measures in saved questions", () => {- it("should be possible to use measure results in a saved question as source for a follow up question", () => {+ describe("x-rays", () => {+ it("should be possible to x-ray a question and a model containing a measure", () => {H.createMeasure({name: MEASURE_NAME,definition: {@@ -708,184 +641,49 @@ describe("scenarios > data studio > measures > queries", () => {type: "query",query: {"source-table": ORDERS_ID,- aggregation: [["sum", ["field", ORDERS.TOTAL, null]]],+ aggregation: [["count"]],},},}).then(({ body: measure }) => {+ cy.log("x-ray a question");H.createQuestion({- name: "Question with measure",+ name: "Test question",query: {"source-table": ORDERS_ID,aggregation: [["measure", { "display-name": measure.name }, measure.id],],breakout: [- ["field", ORDERS.CREATED_AT, { "temporal-unit": "week" }],+ ["field", ORDERS.CREATED_AT, { "temporal-unit": "day" }],],},}).then(({ body: question }) => {- H.createQuestion(- {- query: {- "source-table": `card__${question.id}`,- },- display: "scalar",- },- { visitQuestion: true },- );+ cy.visit(`/auto/dashboard/question/${question.id}`);+ H.main()+ .findByText("A look at the Table Measure")+ .should("be.visible");});- });-- H.openNotebook();-- H.filter({ mode: "notebook" });- H.popover().within(() => {- cy.findByText(MEASURE_NAME).click();- cy.findByPlaceholderText("Min").type("100");- cy.button("Add filter").click();- });-- H.summarize({ mode: "notebook" });- H.popover().findByText("Custom Expression").click();- H.enterCustomColumnDetails({- formula: `Sum([${MEASURE_NAME}])`,- name: "Table Measure Sum",- clickDone: true,- });-- H.visualize();- verifyScalarValue("1,510,568.93");- });- it("should be possible to use measure results in a saved question as source for a follow up model", () => {- H.createMeasure({- name: MEASURE_NAME,- definition: {- database: SAMPLE_DB_ID,- type: "query",- query: {- "source-table": ORDERS_ID,- aggregation: [["sum", ["field", ORDERS.TOTAL, null]]],- },- },- }).then(({ body: measure }) => {+ cy.log("x-ray a model");H.createQuestion({- name: "Question with measure",+ type: "model",+ name: "Test model",query: {"source-table": ORDERS_ID,aggregation: [["measure", { "display-name": measure.name }, measure.id],],breakout: [- ["field", ORDERS.CREATED_AT, { "temporal-unit": "week" }],+ ["field", ORDERS.CREATED_AT, { "temporal-unit": "day" }],],},- }).then(({ body: question }) => {- H.createQuestion(- {- type: "model",- query: {- "source-table": `card__${question.id}`,- },- display: "scalar",- },- { visitQuestion: true },- );- });- });-- H.openQuestionActions("Edit query definition");-- H.filter({ mode: "notebook" });- H.popover().within(() => {- cy.findByText(MEASURE_NAME).click();- cy.findByPlaceholderText("Min").type("100");- cy.button("Add filter").click();- });-- H.summarize({ mode: "notebook" });- H.popover().findByText("Custom Expression").click();- H.enterCustomColumnDetails({- formula: `Sum([${MEASURE_NAME}])`,- name: "Table Measure Sum",- clickDone: true,- });-- cy.findByTestId("dataset-edit-bar").button("Save changes").click();- verifyScalarValue("1,510,568.93");- });-- it("should be possible x-ray a question containing a measure", () => {- H.createMeasure({- name: MEASURE_NAME,- definition: {- database: SAMPLE_DB_ID,- type: "query",- query: {- "source-table": ORDERS_ID,- aggregation: [["count"]],- },- },- })- .then(({ body: measure }) => {- H.createQuestion({- name: "Test model",- query: {- "source-table": ORDERS_ID,- aggregation: [- ["measure", { "display-name": measure.name }, measure.id],- ],- breakout: [- ["field", ORDERS.CREATED_AT, { "temporal-unit": "day" }],- ],- },- });- })- .then(({ body: model }) => {- cy.visit(`/auto/dashboard/question/${model.id}`);-- H.main()- .findByText("A look at the Table Measure")- .should("be.visible");- });- });- });-- describe("using measures in models", () => {- it("should be possible x-ray a model containing a measure", () => {- H.createMeasure({- name: MEASURE_NAME,- definition: {- database: SAMPLE_DB_ID,- type: "query",- query: {- "source-table": ORDERS_ID,- aggregation: [["count"]],- },- },- })- .then(({ body: measure }) => {- H.createQuestion({- type: "model",- name: "Test model",- query: {- "source-table": ORDERS_ID,- aggregation: [- ["measure", { "display-name": measure.name }, measure.id],- ],- breakout: [- ["field", ORDERS.CREATED_AT, { "temporal-unit": "day" }],- ],- },- });- })- .then(({ body: model }) => {+ }).then(({ body: model }) => {cy.visit(`/auto/dashboard/model/${model.id}`);-H.main().findByText("A look at the Table Measure").should("be.visible");});+ });});});});diff --git a/e2e/test/scenarios/data-studio/published-tables-segments.cy.spec.ts b/e2e/test/scenarios/data-studio/published-tables-segments.cy.spec.tsindex fec0d459b2b..01839524518 100644--- a/e2e/test/scenarios/data-studio/published-tables-segments.cy.spec.ts+++ b/e2e/test/scenarios/data-studio/published-tables-segments.cy.spec.ts@@ -19,34 +19,8 @@ describe("scenarios > data studio > library > published tables > segments", () =cy.intercept("PUT", "/api/segment/*").as("updateSegment");});- describe("Segment list", () => {- it("should show empty state and navigate to new segment page", () => {- H.DataStudio.Tables.visitSegmentsPage(ORDERS_ID);-- SegmentList.getEmptyState().scrollIntoView().should("be.visible");- SegmentList.getNewSegmentLink().scrollIntoView().click();-- cy.url().should(- "include",- `/data-studio/library/tables/${ORDERS_ID}/segments/new`,- );- });-- it("should display segments and navigate to edit page", () => {- createTestSegment({ name: "High Value Orders" });- H.DataStudio.Tables.visitSegmentsPage(ORDERS_ID);-- SegmentList.getSegment("High Value Orders").click();-- cy.get<number>("@segmentId").then((segmentId) => {- cy.url().should(- "include",- `/data-studio/library/tables/${ORDERS_ID}/segments/${segmentId}`,- );- });- });-- it("should navigate between Overview, Fields, and Segments tabs", () => {+ describe("Segment list and creation", () => {+ it("should navigate between tabs, show empty state, create a segment and redirect to edit page", () => {H.DataStudio.Tables.visitOverviewPage(ORDERS_ID);H.DataStudio.Tables.overviewTab().should("be.visible");@@ -62,13 +36,15 @@ describe("scenarios > data studio > library > published tables > segments", () =H.DataStudio.Tables.overviewTab().click();cy.url().should("include", `/data-studio/library/tables/${ORDERS_ID}`);cy.url().should("not.include", "/segments");- });- });- describe("Segment creation", () => {- it("should create a segment and redirect to edit page", () => {+ cy.log("create a segment");H.DataStudio.Tables.visitSegmentsPage(ORDERS_ID);- SegmentList.getNewSegmentLink().click();+ SegmentList.getEmptyState().scrollIntoView().should("be.visible");+ SegmentList.getNewSegmentLink().scrollIntoView().click();+ cy.url().should(+ "include",+ `/data-studio/library/tables/${ORDERS_ID}/segments/new`,+ );SegmentEditor.getNameInput().type("Premium Orders");SegmentEditor.getFilterPlaceholder().click();@@ -90,22 +66,15 @@ describe("scenarios > data studio > library > published tables > segments", () =});});- describe("Breadcrumbs", () => {- it("should display collection-based breadcrumbs", () => {- createTestSegment({ name: "Breadcrumb Test Segment" });+ describe("Segment navigation and deletion", () => {+ it("should navigate back via collection-based breadcrumbs, open a segment from the list and redirect to the list after deletion", () => {+ createTestSegment("Segment to Delete");cy.get<number>("@segmentId").then((segmentId) => {H.DataStudio.Tables.visitSegmentPage(ORDERS_ID, segmentId);});+ cy.log("navigate back via breadcrumbs");SegmentEditor.get().findByText("Data").should("be.visible");- });-- it("should navigate back to published table segments via breadcrumb", () => {- createTestSegment({ name: "Breadcrumb Nav Test" });- cy.get<number>("@segmentId").then((segmentId) => {- H.DataStudio.Tables.visitSegmentPage(ORDERS_ID, segmentId);- });-SegmentEditor.getBreadcrumb("Orders").click();cy.url().should(@@ -113,13 +82,19 @@ describe("scenarios > data studio > library > published tables > segments", () =`/data-studio/library/tables/${ORDERS_ID}/segments`,);cy.url().should("not.match", /segments\/\d+/);- });- });- describe("Segment deletion", () => {- it("should redirect to published table segments list after deletion", () => {- createTestSegment({ name: "Segment to Delete" });+ cy.log("open the segment from the list");+ SegmentList.getSegment("Segment to Delete").click();cy.get<number>("@segmentId").then((segmentId) => {+ cy.url().should(+ "include",+ `/data-studio/library/tables/${ORDERS_ID}/segments/${segmentId}`,+ );+ SegmentEditor.get()+ .findByDisplayValue("Segment to Delete")+ .should("be.visible");++ cy.log("delete after a direct visit");H.DataStudio.Tables.visitSegmentPage(ORDERS_ID, segmentId);});@@ -138,12 +113,9 @@ describe("scenarios > data studio > library > published tables > segments", () =});});-function createTestSegment(opts: { name?: string; description?: string } = {}) {- const { name = "Test Segment", description } = opts;-+function createTestSegment(name: string) {H.createSegment({name,- description,definition: {type: "query",database: SAMPLE_DB_ID,diff --git a/e2e/test/scenarios/data-studio/snippets.cy.spec.ts b/e2e/test/scenarios/data-studio/snippets.cy.spec.tsindex 3f877802e05..2b3e771ddda 100644--- a/e2e/test/scenarios/data-studio/snippets.cy.spec.ts+++ b/e2e/test/scenarios/data-studio/snippets.cy.spec.ts@@ -3,7 +3,6 @@ const { H } = cy;describe("scenarios > data studio > snippets", () => {beforeEach(() => {H.restore();- H.resetSnowplow();cy.signInAsAdmin();H.activateToken("pro-self-hosted");@@ -14,49 +13,8 @@ describe("scenarios > data studio > snippets", () => {cy.intercept("PUT", "/api/native-query-snippet/*").as("updateSnippet");});- describe("creation", () => {- it("should create a new snippet with proper validation", () => {- H.DataStudio.Library.visit();-- H.DataStudio.Library.newButton().click();- H.popover().findByText("Snippet").click();-- H.DataStudio.Snippets.newPage().should("be.visible");- H.DataStudio.Snippets.saveButton().should("be.disabled");-- H.DataStudio.Snippets.editor.type("SELECT * FROM orders");- H.DataStudio.Snippets.saveButton().should("be.enabled");-- H.DataStudio.Snippets.nameInput().clear().type("Test snippet");- H.DataStudio.Snippets.saveButton().should("be.enabled");-- H.DataStudio.Snippets.descriptionInput().type(- "This is a test snippet description",- );- H.DataStudio.Snippets.saveButton().click();-- H.modal().within(() => {- cy.findByText("Select a folder for your snippet").should("be.visible");- cy.button("Select").click();- });-- cy.wait("@createSnippet");-- H.DataStudio.Snippets.editPage().should("be.visible");-- H.DataStudio.Snippets.editPage().within(() => {- cy.findByText(/by Bobby Tables/).should("be.visible");- });-- H.DataStudio.nav().findByRole("link", { name: "Semantic layer" }).click();- H.DataStudio.Library.libraryPage()- .findByText("Test snippet")- .should("be.visible");- });- });-describe("editing", () => {- it("should be able to edit snippet content", () => {+ it("should warn about unsaved changes, cancel and save edits, and keep unsaved content when the name or description is edited", () => {H.createSnippet({name: "Test snippet",content: "SELECT * FROM orders",@@ -66,31 +24,22 @@ describe("scenarios > data studio > snippets", () => {H.DataStudio.Library.libraryPage().findByText("Test snippet").click();- H.DataStudio.Snippets.editPage().should("be.visible");-+ cy.log("Show unsaved changes warning when navigating away");H.DataStudio.Snippets.editor.type(" WHERE id = 1");- H.DataStudio.Snippets.saveButton().should("be.enabled").click();- cy.wait("@updateSnippet");-- cy.reload();- H.DataStudio.Snippets.editor- .get()- .should("contain.text", "SELECT * FROM orders WHERE id = 1");- });+ H.DataStudio.nav().findByRole("link", { name: "Glossary" }).click();- it("should be able to cancel editing", () => {- H.createSnippet({- name: "Test snippet",- content: "SELECT * FROM orders",+ H.modal().within(() => {+ cy.findByText("Discard your changes?").should("be.visible");+ cy.button("Cancel").click();});- H.DataStudio.Library.visit();-- H.DataStudio.Library.libraryPage().findByText("Test snippet").click();-- H.DataStudio.Snippets.editor.type(" WHERE id = 1");+ H.DataStudio.Snippets.editPage().should("be.visible");+ H.DataStudio.Snippets.editor+ .value()+ .should("eq", "SELECT * FROM orders WHERE id = 1");+ cy.log("Cancel editing");H.DataStudio.Snippets.cancelButton().click();H.DataStudio.Snippets.editor.get()@@ -98,41 +47,20 @@ describe("scenarios > data studio > snippets", () => {H.DataStudio.Snippets.editor.get().should("contain.text", "SELECT * FROM orders");- });-- it("should show unsaved changes warning when navigating away", () => {- H.createSnippet({- name: "Test snippet",- content: "SELECT * FROM orders",- });-- H.DataStudio.Library.visit();-- H.DataStudio.Library.libraryPage().findByText("Test snippet").click();+ cy.log("Edit snippet content");H.DataStudio.Snippets.editor.type(" WHERE id = 1");- H.DataStudio.nav().findByRole("link", { name: "Glossary" }).click();-- H.modal().within(() => {- cy.findByText("Discard your changes?").should("be.visible");- cy.button("Cancel").click();- });+ H.DataStudio.Snippets.saveButton().should("be.enabled").click();+ cy.wait("@updateSnippet");- H.DataStudio.Snippets.editPage().should("be.visible");- });+ cy.reload();+ H.DataStudio.Snippets.editor+ .get()+ .should("contain.text", "SELECT * FROM orders WHERE id = 1");- it("should preserve unsaved content changes when description or name is edited", () => {- cy.log("Navigate to a snippet and edit its content");- H.createSnippet({- name: "Test snippet",- content: "SELECT * FROM orders",- });- H.DataStudio.Library.visit();- H.DataStudio.Library.libraryPage().findByText("Test snippet").click();+ cy.log("Edit content, then edit the name");H.DataStudio.Snippets.editor.type("1");-- cy.log("Edit its name");cy.findByPlaceholderText("Name").type("1").blur();H.undoToast().findByText("Snippet name updated").should("be.visible");H.undoToast().icon("close").click();@@ -147,7 +75,7 @@ describe("scenarios > data studio > snippets", () => {cy.log("Verify unsaved changes are preserved");H.DataStudio.Snippets.editor.value()- .should("eq", "SELECT * FROM orders1");+ .should("eq", "SELECT * FROM orders WHERE id = 11");cy.log("Verify Save button saves the content without reverting the name and description changes",@@ -159,8 +87,8 @@ describe("scenarios > data studio > snippets", () => {});});- describe("description", () => {- it("should support markdown in description", () => {+ describe("description and archiving", () => {+ it("should render markdown in the description, and archive and unarchive a snippet", () => {H.createSnippet({name: "Test snippet",content: "SELECT * FROM orders",@@ -170,24 +98,14 @@ describe("scenarios > data studio > snippets", () => {H.DataStudio.Library.visit();H.DataStudio.Library.libraryPage().findByText("Test snippet").click();++ cy.log("Verify markdown in the description");H.DataStudio.Snippets.editPage().within(() => {cy.findByText("Bold text").should("have.css", "font-weight", "700");cy.findByText("italic text").should("have.css", "font-style", "italic");});- });- });-- describe("archiving", () => {- it("should be able to archive a snippet", () => {- H.createSnippet({- name: "Test snippet",- content: "SELECT * FROM orders",- });-- H.DataStudio.Library.visit();-- H.DataStudio.Library.libraryPage().findByText("Test snippet").click();+ cy.log("Archive the snippet");cy.findByTestId("snippet-header").findByRole("button", { name: /Snippet menu options/ }).click();@@ -199,22 +117,14 @@ describe("scenarios > data studio > snippets", () => {cy.wait("@updateSnippet");});+ H.DataStudio.Library.emptyStateRow(+ "Reusable bits of code that save your time",+ ).should("be.visible");H.DataStudio.Library.libraryPage().findByText("Test snippet").should("not.exist");- });-- it("should be able to unarchive a snippet", () => {- H.createSnippet({- name: "Test snippet",- content: "SELECT * FROM orders",- }).then((response) => {- cy.log("Archive snippet");- return H.updateSnippet(response.body.id, { archived: true });- });-- H.DataStudio.Library.visit();+ cy.log("Unarchive the snippet");H.DataStudio.Library.libraryPage().findByRole("button", { name: "Snippet collection options" }).click();@@ -251,12 +161,47 @@ describe("scenarios > data studio > snippets", () => {beforeEach(() => {cy.intercept("POST", "/api/collection").as("createCollection");cy.intercept("PUT", "/api/collection/*").as("updateCollection");- cy.intercept("DELETE", "/api/collection/*").as("deleteCollection");});- it("should be able to create a folder and snippet inside it", () => {+ it("should create a snippet, then a folder and a snippet inside it", () => {H.DataStudio.Library.visit();+ H.DataStudio.Library.newButton().click();+ H.popover().findByText("Snippet").click();++ H.DataStudio.Snippets.newPage().should("be.visible");+ H.DataStudio.Snippets.saveButton().should("be.disabled");++ H.DataStudio.Snippets.editor.type("SELECT * FROM orders");+ H.DataStudio.Snippets.saveButton().should("be.enabled");++ H.DataStudio.Snippets.nameInput().clear().type("Test snippet");+ H.DataStudio.Snippets.saveButton().should("be.enabled");++ H.DataStudio.Snippets.descriptionInput().type(+ "This is a test snippet description",+ );+ H.DataStudio.Snippets.saveButton().click();++ H.modal().within(() => {+ cy.findByText("Select a folder for your snippet").should("be.visible");+ cy.button("Select").click();+ });++ cy.wait("@createSnippet");++ H.DataStudio.Snippets.editPage().should("be.visible");++ H.DataStudio.Snippets.editPage().within(() => {+ cy.findByText(/by Bobby Tables/).should("be.visible");+ });++ H.DataStudio.nav().findByRole("link", { name: "Semantic layer" }).click();+ H.DataStudio.Library.libraryPage()+ .findByText("Test snippet")+ .should("be.visible");++ cy.log("Create a folder and a snippet inside it");H.DataStudio.Library.newButton().click();H.popover().findByText("Collection").click();@@ -301,7 +246,7 @@ describe("scenarios > data studio > snippets", () => {.should("be.visible");});- it("should be able to edit folder details", () => {+ it("should be able to edit and archive a folder", () => {H.createSnippetFolder({name: "Test Folder",});@@ -321,16 +266,9 @@ describe("scenarios > data studio > snippets", () => {H.DataStudio.Library.libraryPage().findByText("Updated Folder").should("be.visible");- });- it("should be able to delete a folder", () => {- H.createSnippetFolder({- name: "Test Folder",- });-- H.DataStudio.Library.visit();-- H.DataStudio.Library.result("Test Folder").icon("ellipsis").click();+ cy.log("Archive the folder");+ H.DataStudio.Library.result("Updated Folder").icon("ellipsis").click();H.popover().findByText("Archive").click();cy.log("Clicks archive button on confirmation modal");@@ -339,7 +277,7 @@ describe("scenarios > data studio > snippets", () => {cy.wait("@updateCollection");H.DataStudio.Library.libraryPage()- .findByText("Test Folder")+ .findByText("Updated Folder").should("not.exist");});});@@ -432,27 +370,6 @@ describe("scenarios > data studio > snippets", () => {.should("not.exist");});- it("should expand all folders when navigating directly to library without expandedId params", () => {- // Create nested folder structure- H.createSnippetFolder({- name: "Folder A",- });- H.createSnippetFolder({- name: "Folder B",- });-- cy.log("Navigate directly to library (no expandedId params)");- H.DataStudio.Library.visit();-- cy.log("Verify all folders are expanded by default");- H.DataStudio.Library.libraryPage()- .findByText("Folder A")- .should("be.visible");- H.DataStudio.Library.libraryPage()- .findByText("Folder B")- .should("be.visible");- });-it("should expand parent folders when clicking a nested folder in breadcrumbs", () => {// Create deeply nested structure: GrandParent > Parent > ChildH.createSnippetFolder({diff --git a/e2e/test/scenarios/data-studio/table-collection-permissions.cy.spec.ts b/e2e/test/scenarios/data-studio/table-collection-permissions.cy.spec.tsindex 52dcdbd2f6a..6ea55bc52a0 100644--- a/e2e/test/scenarios/data-studio/table-collection-permissions.cy.spec.ts+++ b/e2e/test/scenarios/data-studio/table-collection-permissions.cy.spec.ts@@ -58,31 +58,7 @@ describe("scenarios > data studio > table collection permissions", () => {});describe("queries", () => {- it("should create a question based on a published table", () => {- H.publishTables({ table_ids: [PRODUCTS_ID] });-- cy.signIn("nodata");- cy.visit("/");- H.newButton().click();- H.popover().within(() => {- cy.findByText("Question").should("be.visible");- cy.findByText("SQL query").should("not.exist");- cy.findByText("Question").click();- });- H.popover().within(() => {- cy.findByText("Products").should("be.visible");- cy.findByText("Orders").should("not.exist");- cy.findByText("Products").click();- });- H.visualize();- H.assertQueryBuilderRowCount(200);-- H.saveQuestion("Test question", { wrapId: true });- H.visitQuestion("@questionId");- H.assertQueryBuilderRowCount(200);- });-- it("should create a question with explicit joins when not all FK tables are published", () => {+ it("should create questions with explicit and implicit joins when not all FK tables are published", () => {H.publishTables({ table_ids: [ORDERS_ID, PRODUCTS_ID] });cy.signIn("nodata");@@ -101,12 +77,8 @@ describe("scenarios > data studio > table collection permissions", () => {H.saveQuestion("Test question", { wrapId: true });H.visitQuestion("@questionId");H.assertQueryBuilderRowCount(1);- });-- it("should create a question with implicit joins when not all FK tables are published", () => {- H.publishTables({ table_ids: [ORDERS_ID, PRODUCTS_ID] });- cy.signIn("nodata");+ cy.log("Implicit joins");H.visitQuestionAdhoc(ordersQuestionDetails, { mode: "notebook" });H.getNotebookStep("data").button("Filter").click();H.popover().within(() => {@@ -127,7 +99,7 @@ describe("scenarios > data studio > table collection permissions", () => {H.assertQueryBuilderRowCount(1);});- it("should create a question with a table segment", () => {+ it("should create questions with a table segment and a table metric", () => {H.createSegment({name: "ID segment",definition: {@@ -139,6 +111,14 @@ describe("scenarios > data studio > table collection permissions", () => {},},});+ H.createQuestion({+ name: "Count metric",+ type: "metric",+ query: {+ "source-table": PRODUCTS_ID,+ aggregation: [["count"]],+ },+ });H.publishTables({ table_ids: [PRODUCTS_ID] });cy.signIn("nodata");@@ -151,20 +131,8 @@ describe("scenarios > data studio > table collection permissions", () => {H.saveQuestion("Test question", { wrapId: true });H.visitQuestion("@questionId");H.assertQueryBuilderRowCount(1);- });- it("should create a question with a table metric", () => {- H.createQuestion({- name: "Count metric",- type: "metric",- query: {- "source-table": PRODUCTS_ID,- aggregation: [["count"]],- },- });- H.publishTables({ table_ids: [PRODUCTS_ID] });-- cy.signIn("nodata");+ cy.log("Table metric");H.visitQuestionAdhoc(productsQuestionDetails, { mode: "notebook" });H.getNotebookStep("data").button("Summarize").click();H.popover().within(() => {@@ -200,22 +168,22 @@ describe("scenarios > data studio > table collection permissions", () => {H.assertQueryBuilderRowCount(1);});- it("should be able to drill-thru", () => {+ it("should use list field values, x-ray, drill-thru, and create a question on a published table", () => {H.publishTables({ table_ids: [PRODUCTS_ID] });cy.signIn("nodata");- H.visitQuestionAdhoc(productsQuestionDetails);- H.tableInteractive().findByText("82.75").click();- H.popover().findByText("=").click();- H.assertQueryBuilderRowCount(1);- });- });- describe("x-rays", () => {- it("should be able to x-ray a table", () => {- H.publishTables({ table_ids: [PRODUCTS_ID] });+ cy.log("List field values");+ H.visitQuestionAdhoc(productsQuestionDetails);+ H.tableHeaderClick("Category");+ H.popover().within(() => {+ cy.findByText("Filter by this column").click();+ cy.findByText("Gadget").click();+ cy.button("Add filter").click();+ });+ H.assertQueryBuilderRowCount(53);- cy.signIn("nodata");+ cy.log("X-ray");H.visitQuestionAdhoc(productsByTimeQuestionDetails);H.cartesianChartCircle().first().click();H.popover().findByText("Automatic insights…").click();@@ -223,24 +191,36 @@ describe("scenarios > data studio > table collection permissions", () => {H.main().findByText(/A closer look at number of Products/).should("be.visible");- });- });- describe("field values", () => {- it("should be able to use list field values", () => {- H.publishTables({ table_ids: [PRODUCTS_ID] });-- cy.signIn("nodata");+ cy.log("Drill-thru");H.visitQuestionAdhoc(productsQuestionDetails);- H.tableHeaderClick("Category");+ H.tableInteractive().findByText("82.75").click();+ H.popover().findByText("=").click();+ H.assertQueryBuilderRowCount(1);++ cy.log("Create a question");+ cy.visit("/");+ H.newButton().click();H.popover().within(() => {- cy.findByText("Filter by this column").click();- cy.findByText("Gadget").click();- cy.button("Add filter").click();+ cy.findByText("Question").should("be.visible");+ cy.findByText("SQL query").should("not.exist");+ cy.findByText("Question").click();});- H.assertQueryBuilderRowCount(53);+ H.popover().within(() => {+ cy.findByText("Products").should("be.visible");+ cy.findByText("Orders").should("not.exist");+ cy.findByText("Products").click();+ });+ H.visualize();+ H.assertQueryBuilderRowCount(200);++ H.saveQuestion("Test question", { wrapId: true });+ H.visitQuestion("@questionId");+ H.assertQueryBuilderRowCount(200);});+ });+ describe("field values", () => {it("should be able to use search field values", () => {H.publishTables({ table_ids: [PEOPLE_ID] });@@ -262,7 +242,7 @@ describe("scenarios > data studio > table collection permissions", () => {});describe("remapping", () => {- it("should automatically publish all tables referenced by FK remapping, recursively", () => {+ it("should automatically publish and unpublish all tables referenced by FK remapping, recursively", () => {cy.request("POST", `/api/field/${ORDERS.PRODUCT_ID}/dimension`, {name: "Product ID",type: "external",@@ -299,24 +279,10 @@ describe("scenarios > data studio > table collection permissions", () => {H.queryBuilderHeader().findByText("Orders").should("be.visible");H.tableInteractive().should("be.visible");H.tableHeaderColumn("Product ID").should("be.visible");- });- it("should automatically unpublish all tables referenced by FK remapping, recursively", () => {- cy.request("POST", `/api/field/${ORDERS.PRODUCT_ID}/dimension`, {- name: "Product ID",- type: "external",- human_readable_field_id: PRODUCTS.TITLE,- });- cy.request("PUT", `/api/field/${PRODUCTS.RATING}`, {- semantic_type: "type/FK",- fk_target_field_id: REVIEWS.ID,- });- cy.request("POST", `/api/field/${PRODUCTS.RATING}/dimension`, {- name: "Rating",- type: "external",- human_readable_field_id: REVIEWS.REVIEWER,- });- H.publishTables({ table_ids: [ORDERS_ID, PEOPLE_ID] });+ cy.log("Unpublish");+ cy.signInAsAdmin();+ H.publishTables({ table_ids: [PEOPLE_ID] });H.DataModel.visitDataStudio();H.DataModel.TablePicker.getTable("Reviews").click();cy.findByRole("button", { name: /Unpublish/ }).click();@@ -407,16 +373,6 @@ describe("scenarios > data studio > table collection permissions", () => {});describe("sandboxing", () => {- it("should be able to access a published sandboxed table", () => {- H.blockUserGroupPermissions(USER_GROUPS.ALL_USERS_GROUP);- sandboxProductsOnCategory();- H.publishTables({ table_ids: [PRODUCTS_ID] });-- cy.signIn("sandboxed");- H.visitQuestionAdhoc(productsQuestionDetails);- H.assertQueryBuilderRowCount(54);- });-it("should be able to use list field values with sandboxing", () => {H.blockUserGroupPermissions(USER_GROUPS.ALL_USERS_GROUP);sandboxProductsOnCategory();@@ -424,6 +380,7 @@ describe("scenarios > data studio > table collection permissions", () => {cy.signIn("sandboxed");H.visitQuestionAdhoc(productsQuestionDetails);+ H.assertQueryBuilderRowCount(54);H.tableHeaderClick("Category");H.popover().within(() => {cy.findByText("Filter by this column").click();@@ -432,6 +389,9 @@ describe("scenarios > data studio > table collection permissions", () => {cy.findByText("Widget").click();cy.button("Add filter").click();});+ H.queryBuilderFiltersPanel()+ .findByText("Category is Widget")+ .should("be.visible");H.assertQueryBuilderRowCount(54);});@@ -454,6 +414,9 @@ describe("scenarios > data studio > table collection permissions", () => {cy.findByText("Widget").click();cy.button("Add filter").click();});+ H.queryBuilderFiltersPanel()+ .findByText("Category is Widget")+ .should("be.visible");H.assertQueryBuilderRowCount(54);});});@@ -471,7 +434,7 @@ describe("scenarios > data studio > table collection permissions", () => {});describe("unpublishing", () => {- it("should not be able to access a previously published table when it is unpublished", () => {+ it("should not be able to access or create questions when the only published table is unpublished", () => {H.publishTables({ table_ids: [PRODUCTS_ID] });H.DataModel.visitDataStudio();H.DataModel.TablePicker.getTable("Products").click();@@ -482,17 +445,7 @@ describe("scenarios > data studio > table collection permissions", () => {cy.signIn("nodata");H.visitQuestionAdhoc(productsQuestionDetails);assertQueryPermissionError();- });- it("should not be able to create questions when all published tables are unpublished", () => {- H.publishTables({ table_ids: [PRODUCTS_ID] });- H.DataModel.visitDataStudio();- H.DataModel.TablePicker.getTable("Products").click();- cy.findByRole("button", { name: /Unpublish/ }).click();- H.modal().findByText("Unpublish this table").click();- H.undoToast().findByText("Unpublished").should("be.visible");-- cy.signIn("nodata");cy.visit("/");H.newButton().click();H.popover().within(() => {@@ -503,20 +456,14 @@ describe("scenarios > data studio > table collection permissions", () => {});describe("losing token features", () => {- it("should not be able to query previously published tables", () => {+ it("should not be able to query previously published tables or create questions", () => {H.publishTables({ table_ids: [PRODUCTS_ID] });H.deleteToken();cy.signIn("nodata");H.visitQuestionAdhoc(productsQuestionDetails);assertQueryPermissionError();- });- it("should not be able to create questions even if there are published tables", () => {- H.publishTables({ table_ids: [PRODUCTS_ID] });- H.deleteToken();-- cy.signIn("nodata");cy.visit("/");H.newButton().click();H.popover().within(() => {diff --git a/e2e/test/scenarios/data-studio/transforms/python-library.cy.spec.ts b/e2e/test/scenarios/data-studio/transforms/python-library.cy.spec.tsindex d4cc0a1d8c4..a733585d0e0 100644--- a/e2e/test/scenarios/data-studio/transforms/python-library.cy.spec.ts+++ b/e2e/test/scenarios/data-studio/transforms/python-library.cy.spec.ts@@ -1,3 +1,5 @@+import dedent from "ts-dedent";+const { H } = cy;describe("scenarios > data studio > transforms > python library", () => {@@ -22,8 +24,13 @@ describe("scenarios > data studio > transforms > python library", () => {it("should allow editing the python library", () => {H.DataStudio.Transforms.visit();+ H.DataStudio.Transforms.list()+ .findByText("Python library")+ .should("be.visible");cy.findByRole("link", { name: /Python library/ }).click();+ cy.url().should("include", "/data-studio/transforms/library/common.py");+ H.DataStudio.PythonLibrary.header().should("be.visible");H.DataStudio.PythonLibrary.editor().should("be.visible");cy.log("make sure placeholder with help comment is displayed");@@ -47,10 +54,43 @@ describe("scenarios > data studio > transforms > python library", () => {.should("be.visible");cy.log("refresh the page and check the content is persisted");- cy.url().reload();+ cy.reload();H.DataStudio.PythonLibrary.editor().findByText(/hello world/).should("be.visible");++ cy.log("replace the library content and save it");+ H.PythonEditor.clear().type(+ dedent`+ def useful_calculation(a, b):+ return a + b+ `,+ );+ H.DataStudio.PythonLibrary.header().findByText("Save").click();+ H.undoToast()+ .findByText(/Python library saved/)+ .should("be.visible");++ cy.log("the contents should be saved properly");+ cy.reload();+ H.PythonEditor.value().should(+ "eq",+ dedent`+ def useful_calculation(a, b):+ return a + b+ `,+ );++ cy.log("reverting the changes should be possible");+ H.PythonEditor.clear().type("# oops");+ H.DataStudio.PythonLibrary.header().findByText("Revert").click();+ H.PythonEditor.value().should(+ "eq",+ dedent`+ def useful_calculation(a, b):+ return a + b+ `,+ );});});diff --git a/e2e/test/scenarios/data-studio/transforms/reproductions.cy.spec.ts b/e2e/test/scenarios/data-studio/transforms/reproductions.cy.spec.tsindex ecc2cdcf16a..d1161c81b7f 100644--- a/e2e/test/scenarios/data-studio/transforms/reproductions.cy.spec.ts+++ b/e2e/test/scenarios/data-studio/transforms/reproductions.cy.spec.ts@@ -7,7 +7,7 @@ const SOURCE_TABLE = "Animals";const TARGET_TABLE = "transform_table";const TARGET_SCHEMA = "Schema A";-describe("issue #68378", () => {+describe("issue #68378 and GDGT-1776", () => {beforeEach(() => {H.restore("postgres-writable");H.resetTestTable({ type: "postgres", table: "empty_schema" });@@ -16,7 +16,10 @@ describe("issue #68378", () => {H.updateSetting("transforms-enabled", true);});- it("should show empty schemas when picking a target schema (metabase#68378)", () => {+ it("should show empty schemas when picking a target schema and not crash the MiniPicker with lots of hidden items (metabase#68378, GDGT-1776)", () => {+ cy.log("show empty schemas when picking a target schema (metabase#68378)");+ cy.intercept("POST", "/api/transform").as("createTransform");+visitTransformListPage();cy.button("Create a transform").click();H.popover().findByText("SQL query").click();@@ -33,17 +36,14 @@ describe("issue #68378", () => {H.popover().findByText("empty_schema").should("be.visible").click();H.modal().button("Save").click();- });-});+ cy.wait("@createTransform").its("response.statusCode").should("eq", 200);-describe("issue GDGT-1776", () => {- beforeEach(() => {- H.restore("postgres-writable");- H.resetTestTable({ type: "postgres", table: "empty_schema" });- cy.signInAsAdmin();- H.activateToken("pro-self-hosted");- H.updateSetting("transforms-enabled", true);+ H.DataStudio.Transforms.settingsTab().click();+ cy.findByTestId("schema-link").should("have.text", "empty_schema");+ cy.log(+ "do not crash the app when processing lots of hidden items in the MiniPicker (GDGT-1776)",+ );const ITEMS_COUNT = 1000;cy.intercept("GET", "/api/collection/root/items*", {@@ -70,22 +70,22 @@ describe("issue GDGT-1776", () => {offset: null,total: ITEMS_COUNT,},- });- });+ }).as("rootCollectionItems");- it("should not crash the app when processing lots of hidden items in the MiniPicker (GDGT-1776)", () => {visitTransformListPage();cy.button("Create a transform").click();H.popover().findByText("Query builder").click();H.popover().findByText("Our analytics").click();+ cy.wait("@rootCollectionItems");+ H.miniPicker().should("be.visible");cy.findByTestId("loading-indicator").should("not.exist");H.main().findByText("Something’s gone wrong").should("not.exist");cy.button("Cancel").should("be.visible");});});-describe("issue GDGT-1774", () => {+describe("issues GDGT-2429, UXW-3160, 69904 and GDGT-1774", () => {beforeEach(() => {H.restore("postgres-writable");H.resetTestTable({ type: "postgres", table: "many_schemas" });@@ -95,55 +95,62 @@ describe("issue GDGT-1774", () => {H.resyncDatabase({ dbId: WRITABLE_DB_ID, tableName: SOURCE_TABLE });});- it("should display field options in the incremental update field picker (GDGT-1774)", () => {- H.getTableId({ name: SOURCE_TABLE })- .then((tableId) =>- H.getFieldId({ tableId, name: "score" }).then((fieldId) =>- H.createTransform({- name: "Incremental MBQL transform",- source: {- type: "query",- query: {- database: WRITABLE_DB_ID,- type: "query",- query: { "source-table": tableId },- },- "source-incremental-strategy": {- type: "checkpoint",- "checkpoint-filter-field-id": fieldId,- },- },- target: {- type: "table-incremental",- database: WRITABLE_DB_ID,- name: TARGET_TABLE,- schema: TARGET_SCHEMA,- "target-incremental-strategy": { type: "append" },- },- }),- ),- )- .then((res) => H.DataStudio.Transforms.visitSettingsTab(res.body.id));+ function startNewSqlTransform() {+ visitTransformListPage();+ cy.button("Create a transform").click();+ H.popover().findByText("SQL query").click();+ H.popover().findByText("Writable Postgres12").click();+ H.NativeEditor.type("SELECT 42", { allowFastSet: true }).blur();+ }- cy.log("Field picker should be visible and have selectable options");- cy.findByLabelText("Field to check for new values")- .scrollIntoView()- .should("be.visible")- .click();+ function openSaveModal() {+ getQueryEditor().button("Save").click();+ H.modal().findByText("Save your transform").should("be.visible");+ }- H.popover().findAllByRole("option").should("have.length.greaterThan", 0);- });-});+ // createAndRunSqlTransform waits for any succeeded run, so the metabase#69904+ // part must run before any other transform run.+ it("should warn about unsaved changes in the save modal, scroll a long read-only SQL definition, open a table of a deleted transform, and display field options in the incremental update field picker (metabase#GDGT-2429, UXW-3160, metabase#69904, GDGT-1774)", () => {+ cy.log(+ "warn about unsaved changes when navigating away while the save modal is open (metabase#GDGT-2429)",+ );+ cy.intercept("POST", "/api/transform").as("createTransform");-describe("issue UXW-3160", () => {- beforeEach(() => {- H.restore("postgres-writable");- cy.signInAsAdmin();- H.activateToken("pro-self-hosted");- H.updateSetting("transforms-enabled", true);- });+ startNewSqlTransform();+ openSaveModal();++ cy.log("navigating away while the save modal is open should warn");+ cy.go("back");+ H.leaveConfirmationModal().should("be.visible");++ cy.log("pressing Esc should close the warning, not the saving modal");+ // Wait for Mantine's focus trap to move focus inside the leave-confirm modal+ // before pressing Escape. `be.visible` passes during the open transition,+ // before the trap engages, so an early Escape lands outside the modal's+ // focus-trapped content (where its closeOnEscape handler lives) and is lost,+ // leaving the modal open.+ H.leaveConfirmationModal().within(() => {+ cy.get(":focus").should("exist");+ });+ cy.realPress("Escape");+ H.leaveConfirmationModal().should("not.exist");+ H.modal().findByText("Save your transform").should("be.visible");++ cy.log("saving the transform should allow navigating away without warning");+ H.modal().within(() => {+ cy.findByLabelText("Name").clear().type("GDGT-2429 transform");+ cy.button("Save").click();+ });+ cy.wait("@createTransform");+ cy.location("pathname").should("match", /\/transforms\/\d+$/);++ cy.go("back");+ cy.location("pathname").should("not.match", /\/transforms\/\d+$/);+ H.leaveConfirmationModal().should("not.exist");- it("should let the read-only definition view scroll to the last line of a long SQL transform (UXW-3160)", () => {+ cy.log(+ "let the read-only definition view scroll to the last line of a long SQL transform (UXW-3160)",+ );const lastLineMarker = "-- UXW_3160_LAST_LINE";const longSql ="SELECT\n " +@@ -171,20 +178,12 @@ describe("issue UXW-3160", () => {});cy.get(".cm-scroller").findByText(lastLineMarker).should("be.visible");- });-});--describe("issue 69904", () => {- const TRANSFORM_TARGET_TABLE = "deleted_transform_table";- beforeEach(() => {- H.restore("postgres-writable");- cy.signInAsAdmin();- H.activateToken("pro-self-hosted");- H.updateSetting("transforms-enabled", true);- });+ cy.log(+ "do not crash the app when opening a table created by a deleted transform (metabase#69904)",+ );+ const TRANSFORM_TARGET_TABLE = "deleted_transform_table";- it("should not crash the app when opening table created by a deleted transform (metabase#69904)", () => {H.createAndRunSqlTransform({name: "Transform to delete",sourceQuery: "SELECT 1 AS answer",@@ -208,62 +207,46 @@ describe("issue 69904", () => {.findByText("Transform does not exist anymore").should("be.visible");});- });-});--describe("issue GDGT-2429", () => {- beforeEach(() => {- H.restore("postgres-writable");- cy.signInAsAdmin();- H.activateToken("pro-self-hosted");- H.updateSetting("transforms-enabled", true);- });- function startNewSqlTransform() {- visitTransformListPage();- cy.button("Create a transform").click();- H.popover().findByText("SQL query").click();- H.popover().findByText("Writable Postgres12").click();- H.NativeEditor.type("SELECT 42", { allowFastSet: true }).blur();- }-- function openSaveModal() {- getQueryEditor().button("Save").click();- H.modal().findByText("Save your transform").should("be.visible");- }-- it("should warn about unsaved changes when navigating away while the save modal is open (metabase#GDGT-2429)", () => {- cy.intercept("POST", "/api/transform").as("createTransform");-- startNewSqlTransform();- openSaveModal();-- cy.log("navigating away while the save modal is open should warn");- cy.go("back");- H.leaveConfirmationModal().should("be.visible");-- cy.log("pressing Esc should close the warning, not the saving modal");- // Wait for Mantine's focus trap to move focus inside the leave-confirm modal- // before pressing Escape. `be.visible` passes during the open transition,- // before the trap engages, so an early Escape lands outside the modal's- // focus-trapped content (where its closeOnEscape handler lives) and is lost,- // leaving the modal open.- H.leaveConfirmationModal().within(() => {- cy.get(":focus").should("exist");- });- cy.realPress("Escape");- H.leaveConfirmationModal().should("not.exist");- H.modal().findByText("Save your transform").should("be.visible");+ cy.log(+ "display field options in the incremental update field picker (GDGT-1774)",+ );+ H.getTableId({ name: SOURCE_TABLE })+ .then((tableId) =>+ H.getFieldId({ tableId, name: "score" }).then((fieldId) =>+ H.createTransform({+ name: "Incremental MBQL transform",+ source: {+ type: "query",+ query: {+ database: WRITABLE_DB_ID,+ type: "query",+ query: { "source-table": tableId },+ },+ "source-incremental-strategy": {+ type: "checkpoint",+ "checkpoint-filter-field-id": fieldId,+ },+ },+ target: {+ type: "table-incremental",+ database: WRITABLE_DB_ID,+ name: TARGET_TABLE,+ schema: TARGET_SCHEMA,+ "target-incremental-strategy": { type: "append" },+ },+ }),+ ),+ )+ .then((res) => H.DataStudio.Transforms.visitSettingsTab(res.body.id));- cy.log("saving the transform should allow navigating away without warning");- H.modal().within(() => {- cy.findByLabelText("Name").clear().type("GDGT-2429 transform");- cy.button("Save").click();- });- cy.wait("@createTransform");+ cy.log("Field picker should be visible and have selectable options");+ cy.findByLabelText("Field to check for new values")+ .scrollIntoView()+ .should("be.visible")+ .click();- cy.go("back");- H.leaveConfirmationModal().should("not.exist");+ H.popover().findAllByRole("option").should("have.length.greaterThan", 0);});});diff --git a/e2e/test/scenarios/data-studio/transforms/template-tags.cy.spec.ts b/e2e/test/scenarios/data-studio/transforms/template-tags.cy.spec.tsindex 9d921f9ba5c..354e0ed687f 100644--- a/e2e/test/scenarios/data-studio/transforms/template-tags.cy.spec.ts+++ b/e2e/test/scenarios/data-studio/transforms/template-tags.cy.spec.ts@@ -7,97 +7,27 @@ const SOURCE_TABLE = "Animals";const TARGET_SCHEMA = "Schema A";const TARGET_TABLE = "transform_table";-describe("scenarios > admin > transforms", () => {+describe("scenarios > data-studio > transforms > template tags", () => {beforeEach(() => {H.restore("postgres-writable");H.resetTestTable({ type: "postgres", table: "many_schemas" });- H.resetSnowplow();cy.signInAsAdmin();H.activateToken("pro-self-hosted");H.updateSetting("transforms-enabled", true);H.resyncDatabase({ dbId: WRITABLE_DB_ID, tableName: SOURCE_TABLE });- cy.intercept("PUT", "/api/field/*").as("updateField");- cy.intercept("POST", "/api/transform").as("createTransform");cy.intercept("PUT", "/api/transform/*").as("updateTransform");- cy.intercept("DELETE", "/api/transform/*").as("deleteTransform");- cy.intercept("DELETE", "/api/transform/*/table").as("deleteTransformTable");- cy.intercept("POST", "/api/transform-tag").as("createTag");- cy.intercept("PUT", "/api/transform-tag/*").as("updateTag");- cy.intercept("DELETE", "/api/transform-tag/*").as("deleteTag");+ cy.intercept("POST", "/api/transform/*/run").as("runTransform");});- it("should be able to use the data reference and snippets when writing a SQL transform", () => {- H.createSnippet({- name: "snippet1",- content: "'foo'",- });-- visitTransformListPage();- cy.button("Create a transform").click();- H.popover().findByText("SQL query").click();- H.popover().findByText(DB_NAME).click();-- function testDataReference() {- cy.log("open the data reference");- cy.findByTestId("native-query-editor-action-buttons")- .findByLabelText("Learn about your data")- .click();-- editorSidebar()- .should("be.visible")- .within(() => {- cy.log("The current database should be opened by default");- cy.findByText("Data Reference").should("not.exist");- cy.findByText("Writable Postgres12").should("be.visible");- });-- cy.findByTestId("native-query-editor-action-buttons")- .findByLabelText("Learn about your data")- .click();-- editorSidebar().should("not.exist");- }-- function testSnippets() {- cy.findByTestId("native-query-editor-action-buttons")- .findByLabelText("SQL Snippets")- .click();-- editorSidebar()- .should("be.visible")- .within(() => {- cy.findByText("snippet1").should("be.visible");- cy.icon("snippet").click();- });-- H.NativeEditor.value().should("eq", "{{snippet: snippet1}}");-- cy.findByTestId("native-query-editor-action-buttons")- .findByLabelText("SQL Snippets")- .click();-- editorSidebar().should("not.exist");-- cy.findByTestId("native-query-editor-action-buttons")- .findByLabelText("Preview the query")- .click();-- H.modal().findByText("'foo'").should("be.visible");- }-- testDataReference();- testSnippets();- });-- it("should be possible to use template tags in SQL transform", () => {+ it("should be possible to use template tags in an SQL transform, and the data reference, snippets and multiple template tags in a new SQL transform", () => {H.createTestNativeQuery({database: WRITABLE_DB_ID,query: "SELECT 1",}).then((query) =>H.createTransform({- name: "MBQL",+ name: "SQL transform",source: {type: "query",query,@@ -267,13 +197,69 @@ describe("scenarios > admin > transforms", () => {});testFieldTemplateTag();testTableTemplateTag();- });- it("should be possible to add multiple template tags", () => {+ H.createSnippet({+ name: "snippet1",+ content: "'foo'",+ });+cy.log("create a new transform");visitTransformListPage();cy.button("Create a transform").click();H.popover().findByText("SQL query").click();+ H.popover().findByText(DB_NAME).click();++ cy.log("open the data reference");+ cy.findByTestId("native-query-editor-action-buttons")+ .findByLabelText("Learn about your data")+ .click();++ editorSidebar()+ .should("be.visible")+ .within(() => {+ cy.log("The current database should be opened by default");+ cy.findByText("Writable Postgres12").should("be.visible");+ cy.findByText("Data Reference").should("not.exist");+ });++ cy.findByTestId("native-query-editor-action-buttons")+ .findByLabelText("Learn about your data")+ .click();++ editorSidebar().should("not.exist");++ cy.log("insert a snippet");+ cy.findByTestId("native-query-editor-action-buttons")+ .findByLabelText("SQL Snippets")+ .click();++ editorSidebar()+ .should("be.visible")+ .within(() => {+ cy.findByText("snippet1").should("be.visible");+ cy.icon("snippet").click();+ });++ H.NativeEditor.value().should("eq", "{{snippet: snippet1}}");++ cy.findByTestId("native-query-editor-action-buttons")+ .findByLabelText("SQL Snippets")+ .click();++ editorSidebar().should("not.exist");++ cy.findByTestId("native-query-editor-action-buttons")+ .findByLabelText("Preview the query")+ .click();++ H.modal().findByText("'foo'").should("be.visible");+ cy.realPress("Escape");+ H.modal().should("not.exist");++ cy.log("create a new transform without picking a database");+ visitTransformListPage();+ cy.button("Create a transform").click();+ H.popover().findByText("SQL query").click();cy.log("Add a query with multiple template tags");H.NativeEditor.clear()@@ -360,6 +346,7 @@ function editorSidebar() {function assertIsTransformRunnable() {H.DataStudio.Transforms.runTab().click();getRunButton().click();+ cy.wait("@runTransform");getRunButton().should("have.text", "Ran successfully");H.DataStudio.Transforms.definitionTab().click();}@@ -370,6 +357,7 @@ function getRunButton(options: { timeout?: number } = {}) {function assertNoParameterSettingsAreVisible() {editorSidebar().within(() => {+ cy.findByLabelText("Variable type").should("exist");cy.findByText("How should users filter on this variable?").should("not.exist",);diff --git a/e2e/test/scenarios/data-studio/transforms/transforms-incremental.cy.spec.ts b/e2e/test/scenarios/data-studio/transforms/transforms-incremental.cy.spec.tsindex 653e525cd88..8794f26dda7 100644--- a/e2e/test/scenarios/data-studio/transforms/transforms-incremental.cy.spec.ts+++ b/e2e/test/scenarios/data-studio/transforms/transforms-incremental.cy.spec.ts@@ -20,17 +20,11 @@ describe("scenarios > admin > transforms incremental", () => {H.updateSetting("transforms-enabled", true);H.resyncDatabase({ dbId: WRITABLE_DB_ID, tableName: SOURCE_TABLE });- cy.intercept("PUT", "/api/field/*").as("updateField");cy.intercept("POST", "/api/transform").as("createTransform");- cy.intercept("PUT", "/api/transform/*").as("updateTransform");- cy.intercept("DELETE", "/api/transform/*").as("deleteTransform");- cy.intercept("DELETE", "/api/transform/*/table").as("deleteTransformTable");- cy.intercept("POST", "/api/transform-tag").as("createTag");- cy.intercept("PUT", "/api/transform-tag/*").as("updateTag");- cy.intercept("DELETE", "/api/transform-tag/*").as("deleteTag");cy.intercept("POST", "/api/transform/*/reset-checkpoint").as("resetCheckpoint",);+ cy.intercept("POST", "/api/transform/*/run").as("runTransform");});afterEach(() => {@@ -71,15 +65,10 @@ describe("scenarios > admin > transforms incremental", () => {}).click({ force: true });cy.button("Save").click();- cy.wait("@createTransform").then(({ response }) => {- const transformId = response?.body?.id;- if (transformId != null) {- cy.wrap(transformId).as("transformId");- }- });+ cy.wait("@createTransform");});- cy.log("run the transform and make sure its table can be queried");+ cy.log("run the transform");H.DataStudio.Transforms.runTab().click();runTransformAndWaitForSuccess();H.expectUnstructuredSnowplowEvent({@@ -119,6 +108,9 @@ describe("scenarios > admin > transforms incremental", () => {.click();});cy.findByRole("region", { name: "Info" }).within(() => {+ cy.findByRole("group", { name: "Checkpoint from" }).within(() => {+ cy.findByText(/30/).should("be.visible");+ });cy.findByRole("group", { name: "Checkpoint to" }).within(() => {cy.findByText(/31/).should("be.visible");});@@ -135,6 +127,7 @@ describe("scenarios > admin > transforms incremental", () => {cy.button("Reprocess on next run").click();});cy.wait("@resetCheckpoint");+ H.undoToast().should("contain.text", "Checkpoint has been reset");cy.log("go to Runs tab, run transform again and check new run has checkpoint to 31",@@ -151,6 +144,7 @@ describe("scenarios > admin > transforms incremental", () => {cy.findByRole("group", { name: "Checkpoint to" }).within(() => {cy.findByText(/31/).should("be.visible");});+ cy.findByRole("group", { name: "Checkpoint from" }).should("not.exist");});});@@ -210,7 +204,7 @@ def transform(animals):timeout: TRANSFORM_DETAIL_TIMEOUT,}).should("be.visible");- cy.log("run the transform and make sure its table can be queried");+ cy.log("run the transform");H.DataStudio.Transforms.runTab().click();runTransformAndWaitForSuccess();H.expectUnstructuredSnowplowEvent({@@ -250,6 +244,9 @@ def transform(animals):.click();});cy.findByRole("region", { name: "Info" }).within(() => {+ cy.findByRole("group", { name: "Checkpoint from" }).within(() => {+ cy.findByText(/30/).should("be.visible");+ });cy.findByRole("group", { name: "Checkpoint to" }).within(() => {cy.findByText(/31/).should("be.visible");});@@ -266,6 +263,7 @@ def transform(animals):cy.button("Reprocess on next run").click();});cy.wait("@resetCheckpoint");+ H.undoToast().should("contain.text", "Checkpoint has been reset");cy.log("go to Runs tab, run transform again and check new run has checkpoint to 31",@@ -282,6 +280,9 @@ def transform(animals):cy.findByRole("group", { name: "Checkpoint to" }).within(() => {cy.findByText(/31/).should("be.visible");});+ cy.findByRole("group", { name: "Checkpoint from" }).should(+ "not.exist",+ );});},);@@ -324,7 +325,7 @@ def transform(animals):cy.wait("@createTransform");});- cy.log("run the transform and make sure its table can be queried");+ cy.log("run the transform");H.DataStudio.Transforms.runTab().click();runTransformAndWaitForSuccess();H.expectUnstructuredSnowplowEvent({@@ -363,6 +364,9 @@ def transform(animals):.click();});cy.findByRole("region", { name: "Info" }).within(() => {+ cy.findByRole("group", { name: "Checkpoint from" }).within(() => {+ cy.findByText(/30/).should("be.visible");+ });cy.findByRole("group", { name: "Checkpoint to" }).within(() => {cy.findByText(/31/).should("be.visible");});@@ -379,6 +383,7 @@ def transform(animals):cy.button("Reprocess on next run").click();});cy.wait("@resetCheckpoint");+ H.undoToast().should("contain.text", "Checkpoint has been reset");cy.log("go to Runs tab, run transform again and check new run has checkpoint to 31",@@ -395,6 +400,7 @@ def transform(animals):cy.findByRole("group", { name: "Checkpoint to" }).within(() => {cy.findByText(/31/).should("be.visible");});+ cy.findByRole("group", { name: "Checkpoint from" }).should("not.exist");});});});@@ -408,6 +414,7 @@ function runTransformAndWaitForSuccess(options: { timeout?: number } = { timeout: PYTHON_TRANSFORM_RUN_TIMEOUT },) {getRunButton().click();+ cy.wait("@runTransform").its("response.statusCode").should("eq", 202);getRunButton(options).should("have.text", "Ran successfully");}diff --git a/e2e/test/scenarios/data-studio/transforms/transforms-indexes.cy.spec.ts b/e2e/test/scenarios/data-studio/transforms/transforms-indexes.cy.spec.tsindex 8f128b895a2..c8b9bf27f9f 100644--- a/e2e/test/scenarios/data-studio/transforms/transforms-indexes.cy.spec.ts+++ b/e2e/test/scenarios/data-studio/transforms/transforms-indexes.cy.spec.ts@@ -26,7 +26,7 @@ describe("data-studio > transforms > indexes", { tags: ["@external"] }, () => {H.resyncDatabase({ dbId: WRITABLE_DB_ID, tableName: SOURCE_TABLE });});- it("lists managed index requests with pending and removing statuses and sorts by column", () => {+ it("lists managed index requests with pending and removing statuses, sorts by column, and shows the index lifecycle after a transform run", () => {H.createMbqlTransform({sourceTable: SOURCE_TABLE,targetTable: "indexes_list_table",@@ -85,9 +85,10 @@ describe("data-studio > transforms > indexes", { tags: ["@external"] }, () => {.should("have.length", 2).eq(0).should("contain", "idx_animal_score");- });- it("shows a pending index becoming succeeded after a transform run and lists unmanaged warehouse indexes", () => {+ cy.log(+ "a pending index becomes succeeded after a transform run, and unmanaged warehouse indexes are listed",+ );const targetTable = "indexes_lifecycle_table";cy.log("run the transform once so the target table exists");@@ -149,7 +150,9 @@ describe("data-studio > transforms > indexes", { tags: ["@external"] }, () => {cy.log("run the transform from the run tab");H.DataStudio.Transforms.runTab().click();+ cy.intercept("POST", "/api/transform/*/run").as("runTransform");H.DataStudio.Transforms.runButton().click();+ cy.wait("@runTransform");H.DataStudio.Transforms.runButton().should("have.text", "Ran successfully");cy.log("simulate a DBA-created index directly in the warehouse");diff --git a/e2e/test/scenarios/data-studio/transforms/transforms-inspect.cy.spec.ts b/e2e/test/scenarios/data-studio/transforms/transforms-inspect.cy.spec.tsindex aa939b376a1..33bbf356639 100644--- a/e2e/test/scenarios/data-studio/transforms/transforms-inspect.cy.spec.ts+++ b/e2e/test/scenarios/data-studio/transforms/transforms-inspect.cy.spec.ts@@ -66,13 +66,14 @@ describe("scenarios > data-studio > transforms > inspect", () => {});describe("generic-summary lens", () => {- it("should show Summary tab after running an MBQL transform", () => {+ it("should show Summary and Column Distributions lenses for an MBQL transform and the Summary lens for a SQL transform, and show the loading spinner only on the active tab", () => {H.createAndRunMbqlTransform({sourceTable: SOURCE_TABLE,targetTable: "inspect_mbql_table",targetSchema: TARGET_SCHEMA,name: "MBQL inspect transform",}).then(({ transformId }) => {+ cy.wrap(transformId).as("mbqlTransformId");H.DataStudio.Transforms.visitInspect(transformId);});@@ -148,23 +149,102 @@ describe("scenarios > data-studio > transforms > inspect", () => {event: "transform_inspect_lens_loaded",event_detail: "generic-summary",});- });- });- describe("join-analysis lens", () => {- it("should show Join Analysis tab when transform has joins", () => {- createAndRunMbqlJoinTransform({- name: "Join MBQL inspect transform",- sourceSchema: TARGET_SCHEMA,- targetTable: "inspect_join_table",+ cy.findByRole("tab", { name: /Column Distributions/ }).click();++ cy.findByRole("heading", { name: /2 matched columns/i }).should(+ "be.visible",+ );++ cy.findAllByTestId("visualization-root")+ .should("have.length", 4)+ .each((visualization) => {+ cy.wrap(visualization).within(() => {+ cy.findByRole("link").should("exist");+ });+ });++ cy.log("show the Summary tab for a SQL transform");+ H.createSqlTransform({+ name: "SQL inspect transform",+ sourceQuery: `SELECT * FROM "${TARGET_SCHEMA}"."${SOURCE_TABLE}"`,+ targetTable: "inspect_sql_table",+ targetSchema: TARGET_SCHEMA,+ }).then(({ body: transform }) => {+ H.runTransformAndWaitForSuccess(transform.id);+ H.DataStudio.Transforms.visitInspect(transform.id);});cy.wait("@inspectorDiscovery");- cy.findByRole("tab", { name: /Summary/ }).should("be.visible");- cy.findByRole("tab", { name: /Join Analysis/ }).should("be.visible");+ cy.findByRole("tab", { name: /Summary/ }).should(+ "have.attr",+ "aria-selected",+ "true",+ );++ cy.findByRole("heading", { name: /1 input table/i }).should("be.visible");+ cy.findByRole("heading", { name: /1 output table/i }).should(+ "be.visible",+ );++ cy.log("the tab loading spinner shows only on the active tab");+ cy.intercept("POST", "/api/ee/transforms/*/inspect/*/query", (req) => {+ req.continue((res) => {+ res.setDelay(1000);+ });+ }).as("inspectorQuery");++ cy.get<TransformId>("@mbqlTransformId").then((transformId) => {+ H.DataStudio.Transforms.visitInspect(transformId);+ });++ cy.wait("@inspectorDiscovery");++ const summaryTab = () => cy.findByRole("tab", { name: /Summary/ });+ const colDistTab = () =>+ cy.findByRole("tab", { name: /Column Distributions/ });++ cy.log("the active Summary tab shows a spinner while its cards load");+ summaryTab().findByTestId("lens-tab-loader").should("be.visible");++ cy.log("switch away before Summary finishes loading");+ colDistTab().click();++ cy.log(+ "the previous tab does not get stuck — the fast Summary lens reverts to no indicator",+ );+ summaryTab().within(() => {+ cy.findByTestId("lens-tab-loader").should("not.exist");+ cy.findByLabelText(/clock icon/i).should("not.exist");+ });++ cy.log("the newly active tab now shows the spinner");+ colDistTab().findByTestId("lens-tab-loader").should("be.visible");++ cy.log("the spinner clears once the lens finishes loading");+ cy.findAllByTestId("visualization-root").should("have.length", 4);+ colDistTab().within(() => {+ cy.findByTestId("lens-tab-loader").should("not.exist");+ cy.findByLabelText(/clock icon/i).should("not.exist");+ });++ cy.log(+ "switch back: the loaded tab shows no indicator, active one re-loads cleanly",+ );+ summaryTab().click();++ colDistTab().within(() => {+ cy.findByTestId("lens-tab-loader").should("not.exist");+ cy.findByLabelText(/clock icon/i).should("not.exist");+ });++ cy.findByTestId("generic-summary-tables").should("be.visible");+ summaryTab().findByTestId("lens-tab-loader").should("not.exist");});+ });+ describe("join-analysis lens", () => {it("should display join step data in tree table", () => {createAndRunMbqlJoinTransform({name: "Join tree inspect transform",@@ -177,6 +257,8 @@ describe("scenarios > data-studio > transforms > inspect", () => {cy.wait("@inspectorDiscovery");cy.wait("@inspectorLens");+ cy.findByRole("tab", { name: /Summary/ }).should("be.visible");+cy.findByRole("tab", { name: tabName }).within(() => {cy.findByLabelText(/clock icon/i).should("be.visible");});@@ -198,7 +280,7 @@ describe("scenarios > data-studio > transforms > inspect", () => {cy.findByRole("heading", { name: /1 join/i }).should("be.visible");});- it("should show unmatched rows alert for left join with non-matching rows", () => {+ it("should show unmatched rows alert for left join with non-matching rows and load the unmatched-rows drill-down lens", () => {H.resetTestTable({ type: "postgres", table: "no_pk_table" });H.resyncDatabase({ dbId: WRITABLE_DB_ID, tableName: "no_pk_table" });@@ -235,25 +317,8 @@ describe("scenarios > data-studio > transforms > inspect", () => {H.expectUnstructuredSnowplowEvent({event: "transform_inspect_alert_clicked",});- });- });-- describe("drill-down lenses", () => {- it("loads unmatched-rows drill-down lens when triggered", () => {- H.resetTestTable({ type: "postgres", table: "no_pk_table" });- H.resyncDatabase({ dbId: WRITABLE_DB_ID, tableName: "no_pk_table" });- createAndRunMbqlJoinTransform({- name: "Left join unmatched transform",- targetTable: "inspect_unmatched_table",- sourceTable: "no_pk_table",- sourceSchema: undefined,- joinTable: SOURCE_TABLE,- joinSchema: TARGET_SCHEMA,- joinStrategy: "left-join",- });-- cy.findByRole("tab", { name: /Join Analysis/ }).click();+ cy.log("load the unmatched-rows drill-down lens");cy.findByRole("button", {name: /Unmatched rows in Animals - Name/,}).click();@@ -290,132 +355,13 @@ describe("scenarios > data-studio > transforms > inspect", () => {cy.findByRole("button", { name: /Close tab/i }).click();});- cy.findByRole("link", {- name: tabName,- }).should("not.exist");+ cy.findByRole("tab", { name: tabName }).should("not.exist");H.expectUnstructuredSnowplowEvent({event: "transform_inspect_drill_lens_closed",});});});-- describe("column-comparison lens", () => {- it("should show Column Distributions lens", () => {- H.createAndRunMbqlTransform({- sourceTable: SOURCE_TABLE,- targetTable: "inspect_coldist_table",- targetSchema: TARGET_SCHEMA,- name: "ColDist inspect transform",- }).then(({ transformId }) => {- H.DataStudio.Transforms.visitInspect(transformId);- });-- cy.wait("@inspectorDiscovery");-- cy.findByRole("tab", { name: /Column Distributions/ }).click();-- cy.findByRole("heading", { name: /2 matched columns/i }).should(- "be.visible",- );-- cy.findAllByTestId("visualization-root")- .should("have.length", 4)- .each((visualization) => {- cy.wrap(visualization).within(() => {- cy.findByRole("link").should("exist");- });- });- });- });-- describe("loading indicator", () => {- it("shows the spinner only on the active tab and never leaves it stuck when switching tabs", () => {- cy.intercept("POST", "/api/ee/transforms/*/inspect/*/query", (req) => {- req.continue((res) => {- res.setDelay(1000);- });- }).as("inspectorQuery");-- H.createAndRunMbqlTransform({- sourceTable: SOURCE_TABLE,- targetTable: "inspect_loading_table",- targetSchema: TARGET_SCHEMA,- name: "Loading indicator inspect transform",- }).then(({ transformId }) => {- H.DataStudio.Transforms.visitInspect(transformId);- });-- cy.wait("@inspectorDiscovery");-- const summaryTab = () => cy.findByRole("tab", { name: /Summary/ });- const colDistTab = () =>- cy.findByRole("tab", { name: /Column Distributions/ });-- cy.log("the active Summary tab shows a spinner while its cards load");- summaryTab().findByTestId("lens-tab-loader").should("be.visible");-- cy.log("switch away before Summary finishes loading");- colDistTab().click();-- cy.log(- "the previous tab does not get stuck — the fast Summary lens reverts to no indicator",- );- summaryTab().within(() => {- cy.findByTestId("lens-tab-loader").should("not.exist");- cy.findByLabelText(/clock icon/i).should("not.exist");- });-- cy.log("the newly active tab now shows the spinner");- colDistTab().findByTestId("lens-tab-loader").should("be.visible");-- cy.log("the spinner clears once the lens finishes loading");- cy.findAllByTestId("visualization-root").should("have.length", 4);- colDistTab().within(() => {- cy.findByTestId("lens-tab-loader").should("not.exist");- cy.findByLabelText(/clock icon/i).should("not.exist");- });-- cy.log(- "switch back: the loaded tab shows no indicator, active one re-loads cleanly",- );- summaryTab().click();-- colDistTab().within(() => {- cy.findByTestId("lens-tab-loader").should("not.exist");- cy.findByLabelText(/clock icon/i).should("not.exist");- });-- cy.findByTestId("generic-summary-tables").should("be.visible");- summaryTab().findByTestId("lens-tab-loader").should("not.exist");- });- });-- describe("sql transforms", () => {- it("should show Summary tab for a SQL transform", () => {- H.createAndRunSqlTransform({- name: "SQL inspect transform",- sourceQuery: `SELECT * FROM "${TARGET_SCHEMA}"."${SOURCE_TABLE}"`,- targetTable: "inspect_sql_table",- targetSchema: TARGET_SCHEMA,- }).then(({ transformId }) => {- H.DataStudio.Transforms.visitInspect(transformId);- });-- cy.wait("@inspectorDiscovery");-- cy.findByRole("tab", { name: /Summary/ }).should(- "have.attr",- "aria-selected",- "true",- );-- cy.findByRole("heading", { name: /1 input table/i }).should("be.visible");- cy.findByRole("heading", { name: /1 output table/i }).should(- "be.visible",- );- });- });});// This transform with 50% unmatched rows triggers >20% alert and drill lensdiff --git a/e2e/test/scenarios/data-studio/transforms/transforms.cy.spec.ts b/e2e/test/scenarios/data-studio/transforms/transforms.cy.spec.tsindex 757fd5f73a8..90b7b8cb67c 100644--- a/e2e/test/scenarios/data-studio/transforms/transforms.cy.spec.ts+++ b/e2e/test/scenarios/data-studio/transforms/transforms.cy.spec.ts@@ -85,10 +85,29 @@ describe("scenarios > admin > transforms", { tags: ["@external"] }, () => {cy.findByLabelText("Name").type(" transform");cy.findByLabelText("Table name").should("have.value", TARGET_TABLE);+ cy.log("should not allow to overwrite an existing table");+ cy.findByLabelText("Table name").clear().type(SOURCE_TABLE);cy.button("Save").click();cy.wait("@createTransform");+ cy.findByText("A table with that name already exists.").should(+ "be.visible",+ );+ cy.findByLabelText("Table name").clear().type(TARGET_TABLE);++ // The submit button shows "Failed" for a few seconds after the rejected save.+ cy.get("button[type=submit]").click();+ cy.wait("@createTransform");});+ cy.log("the target table does not exist before the first run");+ H.DataStudio.Transforms.settingsTab().click();+ getSchemaLink()+ .should("have.text", TARGET_SCHEMA)+ .should("have.attr", "aria-disabled", "false");+ getTableLink({ isActive: false })+ .should("have.text", TARGET_TABLE)+ .should("have.attr", "aria-disabled", "true");+cy.log("run the transform and make sure its table can be queried");H.DataStudio.Transforms.runTab().click();runTransformAndWaitForSuccess();@@ -97,12 +116,24 @@ describe("scenarios > admin > transforms", { tags: ["@external"] }, () => {});H.DataStudio.Transforms.settingsTab().click();- getTableLink().click();+ getSchemaLink().should("have.attr", "aria-disabled", "false");+ getTableLink().should("have.attr", "aria-disabled", "false").click();H.queryBuilderHeader().findByText("Transform Table").should("be.visible");H.assertQueryBuilderRowCount(3);H.expectUnstructuredSnowplowEvent({event: "transform_created",});++ cy.log("the SQL preview has no absolute-max-results LIMIT");+ cy.go("back");+ H.DataStudio.Transforms.definitionTab().click();+ H.DataStudio.Transforms.clickEditDefinition();+ cy.url().should("include", "/edit");+ getQueryEditor().findByLabelText("View SQL").click();+ H.sidebar().should("be.visible");+ H.NativeEditor.value()+ .should("contain", "FROM")+ .and("not.match", /\bLIMIT\b/i);});it("should not show you the library in the mini picker when building transforms (uxw-2403)", () => {@@ -385,6 +416,7 @@ LIMIT// Saving returns to read-only view mode; the "Run" tab only exists there,// so wait for the navigation off /edit before clicking it.cy.url().should("not.include", "/edit");+ H.NativeEditor.value().should("eq", EXPECTED_QUERY);cy.log("run the transform and make sure its table can be queried");H.DataStudio.Transforms.runTab().click();@@ -399,41 +431,6 @@ LIMITH.assertQueryBuilderRowCount(3);});- it("should not include absolute-max-results LIMIT in SQL preview for MBQL transforms", () => {- createMbqlTransform({ visitTransform: true });- H.DataStudio.Transforms.clickEditDefinition();- cy.url().should("include", "/edit");-- getQueryEditor().findByLabelText("View SQL").click();- H.sidebar()- .should("be.visible")- .and("not.contain", /\bLIMIT\b/i);- });-- it("should not allow to overwrite an existing table when creating a transform", () => {- cy.log("open the new transform page");- visitTransformListPage();- cy.button("Create a transform").click();- H.popover().findByText("Query builder").click();-- cy.log("set the query");- H.miniPicker().within(() => {- cy.findByText(DB_NAME).click();- cy.findByText(TARGET_SCHEMA).click();- cy.findByText(SOURCE_TABLE).click();- });- getQueryEditor().button("Save").click();- H.modal().within(() => {- cy.findByLabelText("Name").clear().type("MBQL transform");- cy.findByLabelText("Table name").clear().type(SOURCE_TABLE);- cy.button("Save").click();- cy.wait("@createTransform");- });- H.modal()- .findByText("A table with that name already exists.")- .should("be.visible");- });-it("should be able to create a new schema when saving a transform", () => {visitTransformListPage();cy.button("Create a transform").click();@@ -485,42 +482,28 @@ LIMITH.assertQueryBuilderRowCount(3);});- it("should be able to create a new table in an existing transform when saving a transform", () => {- visitTransformListPage();- cy.button("Create a transform").click();- H.popover().findByText("Query builder").click();- H.miniPicker().within(() => {- cy.findByText(DB_NAME).click();- cy.findByText(TARGET_SCHEMA).click();- cy.findByText(SOURCE_TABLE).click();- });- getQueryEditor().button("Save").click();- H.modal().within(() => {- cy.findByLabelText("Name").clear().type("MBQL transform");- cy.findByLabelText("Table name").clear().type(TARGET_TABLE);- cy.button("Save").click();- cy.wait("@createTransform");- });-- H.DataStudio.Transforms.settingsTab().click();- getSchemaLink()- .should("have.text", TARGET_SCHEMA)- .should("have.attr", "aria-disabled", "false");- getTableLink({ isActive: false })- .should("have.text", TARGET_TABLE)- .should("have.attr", "aria-disabled", "true");-- cy.log("run the transform and verify the table");- H.DataStudio.Transforms.runTab().click();- runTransformAndWaitForSuccess();-- H.DataStudio.Transforms.settingsTab().click();- getSchemaLink().should("have.attr", "aria-disabled", "false");- getTableLink().should("have.attr", "aria-disabled", "false").click();- H.assertQueryBuilderRowCount(3);- });+ it("should not be possible to create an MBQL transform from an unsupported database or from metrics", () => {+ H.getTableId({ name: "Animals", databaseId: WRITABLE_DB_ID }).then(+ (tableId) => {+ H.createQuestion({+ name: "Animal Question",+ database: WRITABLE_DB_ID,+ query: {+ "source-table": tableId,+ },+ });+ H.createQuestion({+ name: "Animal Metric",+ type: "metric",+ database: WRITABLE_DB_ID,+ query: {+ "source-table": tableId,+ aggregation: [["count"]],+ },+ });+ },+ );- it("should not be possible to create an MBQL transform from a table from an unsupported database", () => {visitTransformListPage();cy.button("Create a transform").click();H.popover().findByText("Query builder").click();@@ -529,8 +512,13 @@ LIMIT// no sample db in mini pickercy.findByText(/Writable Postgres/).should("be.visible");cy.findByText("Sample Database").should("not.exist");++ cy.findByText("Our analytics").click();+ cy.findByText("Animal Question").should("be.visible");+ cy.findByText(/metric/i).should("not.exist");});+ H.miniPickerHeader().click(); // go backH.miniPickerBrowseAll().click();H.entityPickerModal().within(() => {H.entityPickerModalItem(0, "Databases").click();@@ -550,32 +538,8 @@ LIMIT"contain.text","Transforms can't be enabled on the Sample Database.",);- });-- it("should not be possible to create an MBQL transform from metrics", () => {- H.getTableId({ name: "Animals", databaseId: WRITABLE_DB_ID }).then(- (tableId) =>- H.createQuestion({- name: "Animal Metric",- type: "metric",- query: {- "source-table": tableId,- aggregation: [["count"]],- },- }),- );-- visitTransformListPage();- cy.button("Create a transform").click();- H.popover().findByText("Query builder").click();-- H.miniPicker().within(() => {- cy.findByText("Our analytics").click();- cy.findByText(/metric/i).should("not.exist");- });- H.miniPickerHeader().click(); // go back- H.miniPickerBrowseAll().click();+ cy.log("metrics are disabled in the entity picker");H.entityPickerModal().within(() => {cy.findByText("Our analytics").click();cy.findAllByTestId("picker-item")@@ -610,7 +574,7 @@ LIMIT);});- it("not show the 'Show details' buttons in ID columns (metabase#64473)", () => {+ it("should not show the 'Show details' buttons in ID columns (metabase#64473)", () => {const databaseId = WRITABLE_DB_ID;const sourceTable = SOURCE_TABLE;const nameColumn = "name";@@ -635,14 +599,16 @@ LIMITgetQueryEditor().within(() => {cy.findByTestId("run-button").eq(0).click();cy.findByTestId("loading-indicator").should("not.exist");-- cy.findAllByTestId("detail-shortcut").should("not.exist");});+ H.assertTableData({ columns: ["Name", "Score"] });+ getQueryEditor().findAllByTestId("detail-shortcut").should("not.exist");});- it("should not be possible to create a transform from a question or a model that is based of an unsupported database", () => {- function testCardSource({ type }: { type: CardType }) {- cy.log("create a query in the target database");+ it("should not be possible to create a transform from a question or a model that is based on an unsupported database", () => {+ const cardTypes: CardType[] = ["question", "model"];++ cy.log("create queries in the target database");+ cardTypes.forEach((type) => {H.createQuestion({name: `Test ${type}`,type,@@ -651,21 +617,20 @@ LIMIT"source-table": ORDERS_ID,},});+ });- cy.log("create a new transform");- visitTransformListPage();- cy.button("Create a transform").click();- H.popover().findByText("Copy of a saved question").click();- H.entityPickerModal().within(() => {- cy.findByText("Our analytics").click();+ cy.log("create a new transform");+ visitTransformListPage();+ cy.button("Create a transform").click();+ H.popover().findByText("Copy of a saved question").click();+ H.entityPickerModal().within(() => {+ cy.findByText("Our analytics").click();+ cardTypes.forEach((type) => {cy.findByText(`Test ${type}`).closest("a").should("have.attr", "data-disabled", "true");});- }-- testCardSource({ type: "question" });- testCardSource({ type: "model" });+ });});it("should not auto-pivot query results for MBQL transforms", () => {@@ -704,66 +669,8 @@ LIMIT});});- describe("name", () => {- it("should be able to edit the name after creation", () => {- createMbqlTransform({ visitTransform: true });- H.DataStudio.Transforms.header()- .findByPlaceholderText("Name")- .clear()- .type("New name")- .blur();- H.undoToast().findByText("Transform name updated").should("be.visible");- H.DataStudio.Transforms.header()- .findByPlaceholderText("Name")- .should("have.value", "New name");- });- });-- describe("ownership", () => {- it("should be able to view and manage transform ownership", () => {- createMbqlTransform({ visitTransform: true });- H.DataStudio.Transforms.settingsTab().click();-- cy.log("verify the ownership section is displayed");- getTransformsTargetContent().within(() => {- cy.findByText("Ownership").should("be.visible");- cy.findByText("Specify who is responsible for this transform.").should(- "be.visible",- );- cy.findByText("Owner").should("be.visible");- });-- cy.log("change the owner to another user");- getTransformsTargetContent().within(() => {- cy.findByLabelText("Owner").click();- });- H.popover().findByText("Robert Tableton").click();- cy.wait("@updateTransform");- H.undoToast().findByText("Transform owner updated").should("be.visible");- H.undoToast().icon("close").click();-- cy.log("set an external email as owner");- getTransformsTargetContent().within(() => {- cy.findByLabelText("Owner").click();- cy.findByLabelText("Owner").clear().type("[email protected]");- });- H.popover().findByText("[email protected]").click();- cy.wait("@updateTransform");- H.undoToast().findByText("Transform owner updated").should("be.visible");- H.undoToast().icon("close").click();-- cy.log("clear the owner");- getTransformsTargetContent().within(() => {- cy.findByLabelText("Owner").click();- });- H.popover().findByText("No owner").click();- cy.wait("@updateTransform");- H.undoToast().findByText("Transform owner updated").should("be.visible");- });- });-describe("tags", () => {- it("should be able to add and remove tags", () => {+ it("should be able to add, remove, delete, and rename tags", () => {createMbqlTransform({ visitTransform: true });H.DataStudio.Transforms.runTab().click();getTagsInput().click();@@ -798,56 +705,47 @@ LIMITassertOptionSelected("hourly");assertOptionNotSelected("daily");- });- it("should be able to create tags inline", () => {- createMbqlTransform({ visitTransform: true });+ cy.log("reload to close the popover and the tag toasts");+ cy.reload();H.DataStudio.Transforms.runTab().click();- getTagsInput().type("New tag");- H.popover().findByText("New tag").click();- cy.wait("@createTag");- H.undoToast().should("contain.text", "Transform tags updated");- });+ assertOptionSelected("hourly");+ H.undoToastList().should("have.length", 0);- it("should be able to update tags inline", () => {- createMbqlTransform({ visitTransform: true });- H.DataStudio.Transforms.runTab().click();+ cy.log("delete a tag that is not selected");getTagsInput().click();H.popover()- .findByText("hourly")+ .findByText("daily").parent()- .findByLabelText("Rename tag")+ .findByLabelText("Delete tag").click({ force: true });H.modal().within(() => {- cy.findByLabelText("Name").clear().type("daily_changed");- cy.button("Save").click();- cy.wait("@updateTag");+ cy.button("Delete tag").click();+ cy.wait("@deleteTag");});+ H.undoToast().should("contain.text", "Transform tags updated");+ assertOptionSelected("hourly");getTagsInput().click();- H.popover().findByText("daily_changed").should("be.visible");- });+ H.popover().within(() => {+ cy.findByText("weekly").should("be.visible");+ cy.findByText("daily").should("not.exist");+ });- it("should be able to delete tags inline", () => {- createMbqlTransform({ visitTransform: true });- H.DataStudio.Transforms.runTab().click();- getTagsInput().click();+ cy.log("rename a tag");H.popover()- .findByText("hourly")+ .findByText("weekly").parent()- .findByLabelText("Delete tag")+ .findByLabelText("Rename tag").click({ force: true });H.modal().within(() => {- cy.button("Delete tag").click();- cy.wait("@deleteTag");+ cy.findByLabelText("Name").clear().type("weekly_changed");+ cy.button("Save").click();+ cy.wait("@updateTag");});- H.undoToast().should("contain.text", "Transform tags updated");getTagsInput().click();- H.popover().within(() => {- cy.findByText("daily").should("be.visible");- cy.findByText("hourly").should("not.exist");- });+ H.popover().findByText("weekly_changed").should("be.visible");});it("should update tags on all transforms when deleting them from another transform", () => {@@ -862,6 +760,8 @@ LIMITgetTagsInput().type("New tag");H.popover().findByText("New tag").click();cy.wait("@createTag");+ H.undoToast().should("contain.text", "Transform tags updated");+ assertOptionSelected("New tag");cy.log("Navigate to transform B");H.DataStudio.nav()@@ -888,42 +788,78 @@ LIMITcy.log("The tag should be gone");H.DataStudio.Transforms.runTab().click();- getTagsInput()- .parent()- // Select the tag pill- .get("[data-with-remove=true]")- .should("not.exist");+ getTagsInput().should("be.visible");+ assertOptionNotSelected("New tag");});});- describe("incremental settings inline editing", () => {- it("should update incremental settings inline when toggling the switch", () => {+ describe("settings inline editing", () => {+ it("should manage ownership, update incremental settings inline, debounce no-op toggles, and roll back on errors", () => {createMbqlTransform({ visitTransform: true });H.DataStudio.Transforms.settingsTab().click();- cy.log("Toggle incremental on");- isIncrementalSwitchDisabled();- getIncrementalSwitch().click();- cy.wait("@updateTransform");- isIncrementalSwitchEnabled();- H.undoToast().should(- "contain.text",- "Incremental transformation settings updated",- );+ const dismissToast = () => {+ H.undoToast().icon("close").click();+ H.undoToast().should("not.exist");+ };- cy.log("Toggle incremental off");- getIncrementalSwitch().click();- cy.wait("@updateTransform");- isIncrementalSwitchDisabled();- H.undoToast().should(- "contain.text",+ cy.log("verify the ownership section is displayed");+ getTransformsTargetContent().within(() => {+ cy.findByText("Ownership").should("be.visible");+ cy.findByText("Specify who is responsible for this transform.").should(+ "be.visible",+ );+ cy.findByText("Owner").should("be.visible");+ });++ cy.log("change the owner to another user");+ getTransformsTargetContent().within(() => {+ cy.findByLabelText("Owner").click();+ });+ H.popover().findByText("Robert Tableton").click();+ cy.wait("@updateTransform");+ H.undoToast().findByText("Transform owner updated").should("be.visible");+ dismissToast();++ cy.log("set an external email as owner");+ getTransformsTargetContent().within(() => {+ cy.findByLabelText("Owner").click();+ cy.findByLabelText("Owner").clear().type("[email protected]");+ });+ H.popover().findByText("[email protected]").click();+ cy.wait("@updateTransform");+ H.undoToast().findByText("Transform owner updated").should("be.visible");+ dismissToast();++ cy.log("clear the owner");+ getTransformsTargetContent().within(() => {+ cy.findByLabelText("Owner").click();+ });+ H.popover().findByText("No owner").click();+ cy.wait("@updateTransform");+ H.undoToast().findByText("Transform owner updated").should("be.visible");+ dismissToast();++ cy.log("Toggle incremental on");+ isIncrementalSwitchDisabled();+ getIncrementalSwitch().click();+ cy.wait("@updateTransform");+ isIncrementalSwitchEnabled();+ H.undoToast().should(+ "contain.text","Incremental transformation settings updated",);- });+ dismissToast();- it("should debounce inline updates and not make a request when toggling the same field twice", () => {- createMbqlTransform({ visitTransform: true });- H.DataStudio.Transforms.settingsTab().click();+ cy.log("Toggle incremental off");+ getIncrementalSwitch().click();+ cy.wait("@updateTransform");+ isIncrementalSwitchDisabled();+ H.undoToast().should(+ "contain.text",+ "Incremental transformation settings updated",+ );+ dismissToast();cy.log("Toggle incremental on and immediately off");isIncrementalSwitchDisabled();@@ -933,7 +869,7 @@ LIMITcy.intercept("PUT", "/api/transform/*", (req) => {updateCallCount++;req.continue();- }).as("updateTransformCounted");+ });// Toggle on then immediately off (within debounce window)getIncrementalSwitch().click();@@ -951,6 +887,91 @@ LIMITcy.wrap(null).then(() => {expect(updateCallCount).to.equal(0);});++ cy.log("Intercept and force the update to fail");+ cy.intercept("PUT", "/api/transform/*", {+ statusCode: 500,+ body: { message: "Internal server error" },+ }).as("updateTransformError");++ cy.log("Toggle incremental on");+ getIncrementalSwitch().findByRole("switch").should("be.enabled").click();++ cy.log("Wait for the failed request");+ cy.wait("@updateTransformError");++ cy.log("Verify error toast is shown");+ H.undoToast().should(+ "contain.text",+ "Failed to update incremental transformation settings",+ );++ cy.log("Verify the switch rolled back to unchecked state");+ isIncrementalSwitchDisabled();+ dismissToast();++ cy.log("Intercept and simulate network failure");+ cy.intercept("PUT", "/api/transform/*", {+ forceNetworkError: true,+ }).as("updateTransformNetworkError");++ cy.log("Toggle incremental on");+ getIncrementalSwitch().click();+ cy.wait("@updateTransformNetworkError");++ cy.log("Verify error toast is shown");+ H.undoToast().should(+ "contain.text",+ "Failed to update incremental transformation settings",+ );++ cy.log("Verify the switch rolled back to unchecked state");+ isIncrementalSwitchDisabled();+ dismissToast();++ let requestCount = 0;+ cy.log("Intercept and fail the first request after a delay");+ cy.intercept("PUT", "/api/transform/*", (req) => {+ requestCount++;+ if (requestCount === 1) {+ // First request fails after a delay to ensure second change happens while it's in progress+ req.reply({+ statusCode: 500,+ body: { message: "Internal server error" },+ delay: 500,+ });+ } else {+ // Subsequent requests should not happen+ req.continue();+ }+ }).as("updateTransformConditional");++ cy.log("Toggle incremental on (first change)");+ getIncrementalSwitch().click();++ cy.log("Wait for debounce, then toggle again (second change)");+ cy.wait(400);+ getIncrementalSwitch().click();++ cy.log("Wait for the error");+ cy.wait("@updateTransformConditional");++ cy.log("Wait a bit to ensure no second request is made");+ cy.wait(500);++ cy.log("Verify only one request was made");+ cy.wrap(null).then(() => {+ expect(requestCount).to.equal(1);+ });++ cy.log("Verify error toast is shown");+ H.undoToast().should(+ "contain.text",+ "Failed to update incremental transformation settings",+ );++ cy.log("Verify the switch is back to unchecked");+ isIncrementalSwitchDisabled();});it("should handle sequential changes correctly when first update is in progress", () => {@@ -1056,115 +1077,6 @@ LIMIT// Verify a field was selected (should not show placeholder text)getFieldPicker().should("not.contain.text", "Pick a field");});-- it("should rollback values when API returns an error", () => {- createMbqlTransform({ visitTransform: true });- H.DataStudio.Transforms.settingsTab().click();-- cy.log("Verify initial state");- isIncrementalSwitchDisabled();-- cy.log("Intercept and force the update to fail");- cy.intercept("PUT", "/api/transform/*", {- statusCode: 500,- body: { message: "Internal server error" },- }).as("updateTransformError");-- cy.log("Toggle incremental on");- getIncrementalSwitch().findByRole("switch").should("be.enabled").click();-- cy.log("Wait for the failed request");- cy.wait("@updateTransformError");-- cy.log("Verify error toast is shown");- H.undoToast().should(- "contain.text",- "Failed to update incremental transformation settings",- );-- cy.log("Verify the switch rolled back to unchecked state");- isIncrementalSwitchDisabled();- });-- it("should rollback values when network fails", () => {- createMbqlTransform({ visitTransform: true });- H.DataStudio.Transforms.settingsTab().click();-- cy.log("Verify initial state");- isIncrementalSwitchDisabled();-- cy.log("Intercept and simulate network failure");- cy.intercept("PUT", "/api/transform/*", {- forceNetworkError: true,- }).as("updateTransformNetworkError");-- cy.log("Toggle incremental on");- getIncrementalSwitch().click();-- cy.log("Wait for debounce period");- cy.wait(500);-- cy.log("Verify error toast is shown");- H.undoToast().should(- "contain.text",- "Failed to update incremental transformation settings",- );-- cy.log("Verify the switch rolled back to unchecked state");- isIncrementalSwitchDisabled();- });-- it("should not process pending updates after an error occurs", () => {- createMbqlTransform({ visitTransform: true });- H.DataStudio.Transforms.settingsTab().click();-- cy.log("Verify initial state");- isIncrementalSwitchDisabled();-- let requestCount = 0;- cy.log("Intercept and fail the first request after a delay");- cy.intercept("PUT", "/api/transform/*", (req) => {- requestCount++;- if (requestCount === 1) {- // First request fails after a delay to ensure second change happens while it's in progress- req.reply({- statusCode: 500,- body: { message: "Internal server error" },- delay: 500,- });- } else {- // Subsequent requests should not happen- req.continue();- }- }).as("updateTransformConditional");-- cy.log("Toggle incremental on (first change)");- getIncrementalSwitch().click();-- cy.log("Wait for debounce, then toggle again (second change)");- cy.wait(400);- getIncrementalSwitch().click();-- cy.log("Wait for the error");- cy.wait("@updateTransformConditional");-- cy.log("Wait a bit to ensure no second request is made");- cy.wait(500);-- cy.log("Verify only one request was made");- cy.wrap(null).then(() => {- expect(requestCount).to.equal(1);- });-- cy.log("Verify error toast is shown");- H.undoToast().should(- "contain.text",- "Failed to update incremental transformation settings",- );-- cy.log("Verify the switch is back to unchecked");- isIncrementalSwitchDisabled();- });});describe("targets", () => {@@ -1178,6 +1090,22 @@ LIMITH.modal().within(() => {cy.findByLabelText("New table name").should("have.value", TARGET_TABLE);cy.findByLabelText("Schema").should("have.value", TARGET_SCHEMA);++ cy.log("the target can't be one of the source tables");+ cy.findByLabelText("New table name").clear().type(SOURCE_TABLE);+ cy.button("Change target").click();+ cy.wait("@updateTransform")+ .its("response.statusCode")+ .should("eq", 400);+ cy.findByText(/Cyclic transform definitions detected/).should(+ "be.visible",+ );+ cy.button("Cancel").click();+ });+ H.modal().should("not.exist");++ getTransformsTargetContent().button("Change target").click();+ H.modal().within(() => {cy.findByLabelText("New table name").clear().type(TARGET_TABLE_2);cy.findByLabelText("Schema").click();});@@ -1404,121 +1332,76 @@ LIMIT);});});-- it("should not allow to change the target to one of the source tables", () => {- createMbqlTransform({ visitTransform: true });-- cy.log("change the target to the source table");- H.DataStudio.Transforms.settingsTab().click();- getTransformsTargetContent().button("Change target").click();- H.modal().within(() => {- cy.findByLabelText("New table name").clear().type(SOURCE_TABLE);- cy.button("Change target").click();- cy.wait("@updateTransform")- .its("response.statusCode")- .should("eq", 400);- cy.findByText(/Cyclic transform definitions detected/).should(- "be.visible",- );- });- });});describe("metadata", () => {- it("should be able to edit table metadata after table creation", () => {+ it("should be able to see the target database and schema and edit table metadata after table creation", () => {cy.log("before table creation");createMbqlTransform({ visitTransform: true });H.DataStudio.Transforms.settingsTab().click();+ getTransformsTargetContent().button("Change target").should("be.visible");getTransformsTargetContent().findByText("Edit this table's metadata").should("not.exist");- cy.log("after table creation");- H.DataStudio.Transforms.runTab().click();- runTransformAndWaitForSuccess();- H.DataStudio.Transforms.settingsTab().click();- getTransformsTargetContent()- .findByText("Edit this table's metadata")- .click();- H.DataModel.TableSection.clickFieldsTab();- H.DataModel.TableSection.clickField("Name");- H.DataModel.FieldSection.getNameInput().clear().type("New name").blur();- cy.wait("@updateField");-- cy.log("verify query metadata");- cy.go("back");- cy.go("back");- cy.go("back");- getTableLink().click();- H.assertTableData({ columns: ["New name", "Score"] });- });-- it("should be able to see the target schema", () => {- cy.log("before table creation");- createMbqlTransform({ visitTransform: true });- H.DataStudio.Transforms.settingsTab().click();getSchemaLink().should("have.text", TARGET_SCHEMA);getSchemaLink().click();H.main().within(() => {cy.findByText("Animals").should("be.visible");cy.findByText("Transform Table").should("not.exist");});-- cy.log("after table creation");cy.go("back");- H.DataStudio.Transforms.runTab().click();- runTransformAndWaitForSuccess();- H.DataStudio.Transforms.settingsTab().click();- getSchemaLink().click();- H.main().within(() => {- cy.findByText("Animals").should("be.visible");- cy.findByText("Transform Table").should("be.visible");- });- });- it("should be able to see the target database", () => {- cy.log("before table creation");- createMbqlTransform({ visitTransform: true });- H.DataStudio.Transforms.settingsTab().click();getDatabaseLink().should("have.text", DB_NAME);getDatabaseLink().click();H.main().within(() => {cy.findByText(TARGET_SCHEMA).should("be.visible");cy.findByText(TARGET_SCHEMA_2).should("be.visible");});+ cy.go("back");cy.log("after table creation");- cy.go("back");H.DataStudio.Transforms.runTab().click();runTransformAndWaitForSuccess();H.DataStudio.Transforms.settingsTab().click();+ getSchemaLink().click();+ H.main().within(() => {+ cy.findByText("Animals").should("be.visible");+ cy.findByText("Transform Table").should("be.visible");+ });+ cy.go("back");+getDatabaseLink().click();H.main().within(() => {cy.findByText(TARGET_SCHEMA).should("be.visible");cy.findByText(TARGET_SCHEMA_2).should("be.visible");});+ cy.go("back");++ cy.log("edit table metadata");+ getTransformsTargetContent()+ .findByText("Edit this table's metadata")+ .click();+ H.DataModel.TableSection.clickFieldsTab();+ H.DataModel.TableSection.clickField("Name");+ H.DataModel.FieldSection.getNameInput().clear().type("New name").blur();+ cy.wait("@updateField");++ cy.log("verify query metadata");+ cy.go("back");+ cy.go("back");+ cy.go("back");+ getTableLink().click();+ H.assertTableData({ columns: ["New name", "Score"] });});});describe("queries", () => {- it("should show SQL query transforms in view-only mode", () => {- cy.log("create a new transform");- createSqlTransform({- sourceQuery: `SELECT * FROM "${TARGET_SCHEMA}"."${SOURCE_TABLE}"`,- visitTransform: true,- });- H.NativeEditor.get().should("have.attr", "contenteditable", "false");- H.NativeEditor.get().should("have.attr", "aria-readonly", "true");- H.DataStudio.Transforms.getEditDefinitionLink().should(- "have.attr",- "href",- "/data-studio/transforms/1/edit",- );- });-- it("should show MBQL transforms in view-only mode", () => {+ it("should be able to update a MBQL query", () => {cy.log("create a new transform");createMbqlTransform({ visitTransform: true });++ cy.log("the query is read-only before edit mode");H.getNotebookStep("data").findByText("Animals").closest("button")@@ -1528,11 +1411,6 @@ LIMIT"href","/data-studio/transforms/1/edit",);- });-- it("should be able to update a MBQL query", () => {- cy.log("create a new transform");- createMbqlTransform({ visitTransform: true });cy.log("visit edit mode");H.DataStudio.Transforms.clickEditDefinition();@@ -1566,6 +1444,15 @@ LIMITvisitTransform: true,});+ cy.log("the query is read-only before edit mode");+ H.NativeEditor.get().should("have.attr", "contenteditable", "false");+ H.NativeEditor.get().should("have.attr", "aria-readonly", "true");+ H.DataStudio.Transforms.getEditDefinitionLink().should(+ "have.attr",+ "href",+ "/data-studio/transforms/1/edit",+ );+cy.log("visit edit mode");H.DataStudio.Transforms.clickEditDefinition();cy.url().should("include", "/edit");@@ -1584,56 +1471,21 @@ LIMITH.assertQueryBuilderRowCount(1);});- it("should be able to update a Python query", { tags: ["@python"] }, () => {- H.setPythonRunnerSettings();- cy.log("create a new transform");- H.getTableId({ name: "Animals", databaseId: WRITABLE_DB_ID }).then(- (id) => {- createPythonTransform({- body: dedent`- import pandas as pd-- def transform(foo):- return pd.DataFrame([{"foo": 42 }])- `,- sourceTables: pythonSourceTables("foo", id),- visitTransform: true,- });- },- );-- cy.log("enter edit mode");- H.DataStudio.Transforms.clickEditDefinition();-- cy.log("update the query");- H.PythonEditor.type("{backspace}{backspace}{backspace} + 10 }])");- getQueryEditor().button("Save").click();- cy.wait("@updateTransform");-- cy.log("run the transform and make sure the query has changed");- H.DataStudio.Transforms.runTab().click();- runTransformAndWaitForSuccess();- H.DataStudio.Transforms.settingsTab().click();- getTableLink().click();- H.queryBuilderHeader().findByText(DB_NAME).should("be.visible");- H.assertQueryBuilderRowCount(1);- });-it(- "should show Python transforms in view-only mode",+ "should be able to view and update a Python query",{ tags: ["@python"] },() => {H.setPythonRunnerSettings();- cy.log("create a new Python transform");+ cy.log("create a new transform");H.getTableId({ name: "Animals", databaseId: WRITABLE_DB_ID }).then((id) => {createPythonTransform({body: dedent`- import pandas as pd+ import pandas as pd- def transform(foo):- return pd.DataFrame([{"foo": 42 }])- `,+ def transform(foo):+ return pd.DataFrame([{"foo": 42 }])+ `,sourceTables: pythonSourceTables("foo", id),visitTransform: true,});@@ -1653,33 +1505,6 @@ LIMITcy.log("results panel should be hidden in read-only mode");H.DataStudio.Transforms.pythonResults().should("not.exist");- cy.log("library buttons should be hidden in read-only mode");- cy.findByLabelText("Import common library").should("not.exist");- cy.findByLabelText("Edit common library").should("not.exist");- },- );-- it(- "should transition from read-only to edit mode for Python transforms",- { tags: ["@python"] },- () => {- H.setPythonRunnerSettings();- cy.log("create a new Python transform");- H.getTableId({ name: "Animals", databaseId: WRITABLE_DB_ID }).then(- (id) => {- createPythonTransform({- body: dedent`- import pandas as pd-- def transform(foo):- return pd.DataFrame([{"foo": 42 }])- `,- sourceTables: pythonSourceTables("foo", id),- visitTransform: true,- });- },- );-cy.log("click Edit definition to enter edit mode");H.DataStudio.Transforms.clickEditDefinition();cy.url().should("include", "/edit");@@ -1692,38 +1517,9 @@ LIMITcy.log("Edit definition button should be hidden in edit mode");H.DataStudio.Transforms.editDefinitionButton().should("not.exist");- },- );-- it(- "should return to read-only mode after saving a Python transform",- { tags: ["@python"] },- () => {- H.setPythonRunnerSettings();- cy.log("create a new Python transform");- H.getTableId({ name: "Animals", databaseId: WRITABLE_DB_ID }).then(- (id) => {- createPythonTransform({- body: dedent`- import pandas as pd-- def transform(foo):- return pd.DataFrame([{"foo": 42 }])- `,- sourceTables: pythonSourceTables("foo", id),- visitTransform: true,- });- },- );-- cy.log("enter edit mode");- H.DataStudio.Transforms.clickEditDefinition();- cy.url().should("include", "/edit");-- cy.log("make a change to trigger dirty state");- H.PythonEditor.type(" # comment");- cy.log("save the transform");+ cy.log("update the query");+ H.PythonEditor.type("{backspace}{backspace}{backspace} + 10 }])");getQueryEditor().button("Save").click();cy.wait("@updateTransform");@@ -1732,6 +1528,15 @@ LIMITH.DataStudio.Transforms.editDefinitionButton().should("be.visible");cy.findByTestId("python-data-picker").should("not.exist");H.DataStudio.Transforms.pythonResults().should("not.exist");++ cy.log("run the transform and make sure the query has changed");+ H.DataStudio.Transforms.runTab().click();+ runTransformAndWaitForSuccess();+ H.DataStudio.Transforms.settingsTab().click();+ getTableLink().click();+ H.queryBuilderHeader().findByText(DB_NAME).should("be.visible");+ H.assertQueryBuilderRowCount(1);+ cy.findByTestId("scalar-value").should("have.text", "52");},);});@@ -1764,28 +1569,23 @@ LIMITcy.findByText("Manual").should("be.visible");});});-- it("should display the error message from a failed run", () => {- createSqlTransform({- sourceQuery: "SELECT * FROM abc",- visitTransform: true,- });- H.DataStudio.Transforms.runTab().click();- runTransformAndWaitForFailure();- getRunErrorInfoButton().click();- H.modal().should("contain.text", 'relation "abc" does not exist');- });});describe("deletion", () => {- it("should be able to delete a transform before creating the table", () => {+ it("should be able to delete a transform before and after creating the table", () => {cy.log("create a transform without running");- createMbqlTransform({ visitTransform: true });+ createMbqlTransform();+ visitTransformListPage();+ getTransformsList()+ .findByText("MBQL transform")+ .should("be.visible")+ .click();cy.log("delete the transform");H.DataStudio.Transforms.header().icon("ellipsis").click();H.popover().findByText("Delete").click();H.modal().within(() => {+ cy.button("Delete transform").should("be.visible");cy.findByLabelText("Delete the transform only").should("not.exist");cy.findByLabelText("Delete the transform and the table").should("not.exist",@@ -1796,9 +1596,7 @@ LIMITgetTransformsNavLink().click();getTransformsList().should("be.visible");getTransformsList().findByText("MBQL transform").should("not.exist");- });- it("should be able to delete a transform and keep the table", () => {cy.log("create a transform and the table");createMbqlTransform({ visitTransform: true });H.DataStudio.Transforms.runTab().click();@@ -1819,11 +1617,13 @@ LIMITcy.log("make sure the table still exists");visitTableQuestion();H.assertQueryBuilderRowCount(3);- });- it("should be able to delete a transform and delete the table", () => {- cy.log("create a transform and the table");- createMbqlTransform({ visitTransform: true });+ cy.log("create another transform and its table");+ createMbqlTransform({+ name: "MBQL transform 2",+ targetTable: TARGET_TABLE_2,+ visitTransform: true,+ });H.DataStudio.Transforms.runTab().click();runTransformAndWaitForSuccess();H.DataStudio.Transforms.settingsTab().click();@@ -1841,8 +1641,8 @@ LIMITgetTransformsList().should("be.visible");cy.log("make sure the table is deleted");- visitTableQuestion();- assertTableDoesNotExistError();+ visitTableQuestion({ targetTable: TARGET_TABLE_2 });+ assertTableDoesNotExistError({ targetTable: TARGET_TABLE_2 });});});@@ -1950,6 +1750,18 @@ LIMIT// take a while on the back endgetRunButton({ timeout: 40_000 }).should("have.text", "Canceled");getRunStatus().should("contain", "Last run was canceled");++ cy.log("cancel a SQL transform from the preview (metabase#64474)");+ createSlowTransform(500);+ H.DataStudio.Transforms.clickEditDefinition();+ cy.url().should("include", "/edit");+ getQueryEditor().within(() => {+ cy.findAllByTestId("run-button").eq(0).click();+ cy.findByTestId("loading-indicator").should("be.visible");++ cy.findAllByTestId("run-button").eq(0).click();+ cy.findByTestId("loading-indicator").should("not.exist");+ });});it("should be possible to cancel a transform from the runs page", () => {@@ -1997,21 +1809,6 @@ LIMIT"This run succeeded before it had a chance to cancel.",);});-- it("should be possible to cancel a SQL transform from the preview (metabase#64474)", () => {- createSlowTransform(500);-- H.DataStudio.Transforms.clickEditDefinition();- cy.url().should("include", "/edit");-- getQueryEditor().within(() => {- cy.findAllByTestId("run-button").eq(0).click();- cy.findByTestId("loading-indicator").should("be.visible");-- cy.findAllByTestId("run-button").eq(0).click();- cy.findByTestId("loading-indicator").should("not.exist");- });- });});describe("dependencies", () => {@@ -2047,11 +1844,6 @@ LIMITH.DataStudio.Dependencies.content().should("contain", "Transform B").and("contain", "Transform A");- });-- it("should show if the transform has no dependencies", () => {- createMbqlTransform({ name: "Transform A", visitTransform: true });- H.DataStudio.Transforms.dependenciesTab().click();H.DataStudio.Dependencies.content().should("contain","Nothing uses this",@@ -2061,48 +1853,63 @@ LIMITdescribe("python > common library", () => {it(- "should be possible to edit and save the common library",+ "should run transforms that import the default and a custom common library",{ tags: ["@python"] },() => {- visitCommonLibrary();+ H.setPythonRunnerSettings();- cy.log("updating the library should be possible");- H.PythonEditor.clear().type(- dedent`- def useful_calculation(a, b):- return a + b- `,+ cy.log(+ "run a transform with default import common without custom library code",);- getLibraryEditorHeader().findByText("Save").click();+ visitTransformListPage();+ cy.button("Create a transform").click();+ H.popover().findByText("Python script").click();- cy.log("the contents should be saved properly");- visitCommonLibrary();- H.PythonEditor.value().should(- "eq",- dedent`- def useful_calculation(a, b):- return a + b- `,- );+ cy.log("import common should be included by default");+ H.PythonEditor.value().should("contain", "import common");- cy.log("reverting the changes should be possible");- H.PythonEditor.clear().type("# oops");- getLibraryEditorHeader().findByText("Revert").click();- H.PythonEditor.value().should(- "eq",+ cy.log(+ "write a transform that imports common but does not use it - should still run",+ );+ H.PythonEditor.clear().type(dedent`- def useful_calculation(a, b):- return a + b+ import common+ import pandas as pd++ def transform():+ return pd.DataFrame([{"result": 42}])`,+ { allowFastSet: true },);- },- );- it(- "should be possible to use the common library",- { tags: ["@python"] },- () => {- H.setPythonRunnerSettings();+ cy.findByTestId("python-data-picker")+ .findByRole("button", { name: "Select a table…" })+ .click();++ H.entityPickerModal().within(() => {+ cy.findByText("Schema A").click();+ cy.findByText("Animals").click();+ });++ getQueryEditor().button("Save").click();++ H.modal().within(() => {+ cy.findByLabelText("Name").clear().type("Default common transform");+ cy.findByLabelText("Table name").clear().type("default_common");+ cy.button("Save").click();+ });++ H.DataStudio.Transforms.runTab().click();+ runTransformAndWaitForSuccess();+ H.DataStudio.Transforms.settingsTab().click();+ getTableLink().click();+ H.queryBuilderHeader()+ .findByText("Default Common")+ .should("be.visible");+ H.assertQueryBuilderRowCount(1);+ cy.findByTestId("scalar-value").should("have.text", "42");++ cy.log("use a custom common library");createPythonLibrary("common.py",dedent`@@ -2155,9 +1962,12 @@ LIMIT.should("be.visible");H.assertQueryBuilderRowCount(1);cy.findByTestId("scalar-value").should("have.text", "3");- H.expectUnstructuredSnowplowEvent({- event: "transform_created",- });+ H.expectUnstructuredSnowplowEvent(+ {+ event: "transform_created",+ },+ 2,+ );cy.log("update the common library and run the transform again");cy.go("back");@@ -2181,21 +1991,7 @@ LIMIT);it(- "should navigate to the common library when clicking 'common' in an import statement",- { tags: ["@python"] },- () => {- visitTransformListPage();- cy.button("Create a transform").click();- H.popover().findByText("Python script").click();- cy.get(".cm-clickable-token").should("be.visible").click();- H.modal().button("Discard changes").click();- cy.url().should("include", "/data-studio/transforms/library/common.py");- cy.findByTestId("python-library-header").should("be.visible");- },- );-- it(- "should open the common library in a new tab when cmd-clicking 'common' in an import statement",+ "should open the common library when clicking or cmd-clicking 'common' in an import statement",{ tags: ["@python"] },() => {visitTransformListPage();@@ -2204,78 +2000,21 @@ LIMIT});cy.button("Create a transform").click();H.popover().findByText("Python script").click();- cy.get(".cm-clickable-token").should("be.visible").click(H.holdMetaKey);+ cy.log("cmd-click opens the library in a new tab");+ cy.get(".cm-clickable-token").should("be.visible").click(H.holdMetaKey);cy.get("@windowOpen").should("have.been.calledWithMatch","/data-studio/transforms/library/common.py",);- },- );-- it(- "should be able to run a transform with default import common even without custom library code",- { tags: ["@python"] },- () => {- H.setPythonRunnerSettings();-- visitTransformListPage();- cy.button("Create a transform").click();- H.popover().findByText("Python script").click();-- cy.log("import common should be included by default");- H.PythonEditor.value().should("contain", "import common");-- cy.log(- "write a transform that imports common but does not use it - should still run",- );- H.PythonEditor.clear().type(- dedent`- import common- import pandas as pd-- def transform():- return pd.DataFrame([{"result": 42}])- `,- { allowFastSet: true },- );-- cy.findByTestId("python-data-picker")- .findByRole("button", { name: "Select a table…" })- .click();- H.entityPickerModal().within(() => {- cy.findByText("Schema A").click();- cy.findByText("Animals").click();- });-- getQueryEditor().button("Save").click();-- H.modal().within(() => {- cy.findByLabelText("Name").clear().type("Default common transform");- cy.findByLabelText("Table name").clear().type("default_common");- cy.button("Save").click();- });-- H.DataStudio.Transforms.runTab().click();- runTransformAndWaitForSuccess();- H.DataStudio.Transforms.settingsTab().click();- getTableLink().click();- H.queryBuilderHeader()- .findByText("Default Common")- .should("be.visible");- H.assertQueryBuilderRowCount(1);- cy.findByTestId("scalar-value").should("have.text", "42");+ cy.log("click navigates to the library");+ cy.get(".cm-clickable-token").click();+ H.modal().button("Discard changes").click();+ cy.url().should("include", "/data-studio/transforms/library/common.py");+ cy.findByTestId("python-library-header").should("be.visible");},);-- function visitCommonLibrary(path = "common.py") {- cy.visit(`/data-studio/transforms/library/${path}`);- }-- function getLibraryEditorHeader() {- return cy.findByTestId("python-library-header");- }});describe("collections", () => {@@ -2566,9 +2305,16 @@ LIMIT]);});- it("should edit collection details", () => {+ it("should edit collection details and archive a collection with transforms", () => {H.createTransformCollection({ name: "Original Name" });H.createTransformCollection({ name: "Target Parent" });+ H.createTransformCollection({ name: "Archive Me" }).then((collection) => {+ createMbqlTransform({+ name: "Transform In Collection",+ targetTable: "archived_transform_table",+ collectionId: collection.body.id,+ });+ });visitTransformListPage();@@ -2603,19 +2349,8 @@ LIMITcy.findByText("Target Parent").click();cy.findByText("Renamed Collection").should("be.visible");});- });-- it("should archive a collection with transforms", () => {- H.createTransformCollection({ name: "Archive Me" }).then((collection) => {- createMbqlTransform({- name: "Transform In Collection",- targetTable: "archived_transform_table",- collectionId: collection.body.id,- });- });-- visitTransformListPage();+ cy.log("archive a collection with transforms");getTransformsList().within(() => {cy.findByText("Archive Me").should("be.visible");cy.findByText("Archive Me").click();@@ -2649,27 +2384,6 @@ LIMITcy.findByText("Transform In Collection").should("not.exist");});});-- it("should show Python library item and navigate to it", () => {- // Python library row only appears when we have at least one transform- H.createSqlTransform({- sourceQuery: "SELECT 1",- targetTable: "table_a",- targetSchema: "Schema A",- });- visitTransformListPage();-- cy.log("Python library should be visible in the list");- getTransformsList().within(() => {- cy.findByText("Python library").should("be.visible");- });-- cy.log("clicking Python library should navigate to the library editor");- getTransformsList().findByText("Python library").click();-- cy.url().should("include", "/data-studio/transforms/library/common.py");- cy.findByTestId("python-library-header").should("be.visible");- });});describe("revision history", () => {@@ -2697,6 +2411,9 @@ LIMIT"Dismiss the success toast so it can't outlive the later error toast",);H.undoToast().findByText("Transform name updated").should("be.visible");+ H.DataStudio.Transforms.header()+ .findByPlaceholderText("Name")+ .should("have.value", "Updated Transform Name");H.undoToast().icon("close").click();H.undoToast().should("not.exist");@@ -2777,7 +2494,7 @@ LIMITH.configureGit("read-only");});- it("should make the transform list page read-only", () => {+ it("should make transform pages read-only", () => {cy.log("visit transforms page");visitTransformListPage();@@ -2808,13 +2525,12 @@ LIMIT);cy.findByRole("textbox").should("have.attr", "aria-readonly", "true");});- });- it("should not allow editing a transform", () => {cy.log("visit transform");cy.visit("/data-studio/transforms/1");cy.log("'edit definition' button is not displayed");+ H.DataStudio.Transforms.runTab().should("be.visible");H.DataStudio.Transforms.editDefinitionButton().should("not.exist");cy.log("visit the Run tab");@@ -2828,6 +2544,7 @@ LIMITH.DataStudio.Transforms.settingsTab().click();cy.log("'Change target' button is not displayed");+ getSchemaLink().should("be.visible");cy.findByRole("button", { name: /Change target/ }).should("not.exist");cy.log("'Only process new data' switch is not displayed");@@ -2849,9 +2566,7 @@ LIMITcy.findByRole("menuitem", { name: /Move/ }).should("not.exist");cy.findByRole("menuitem", { name: /Delete/ }).should("not.exist");});- });- it("should show not found message on new transform pages", () => {cy.log("visit new native transform page");cy.visit("/data-studio/transforms/new/native");@@ -2890,18 +2605,10 @@ describe("scenarios > admin > transforms > databases without :schemas", () => {cy.signInAsAdmin();H.activateToken("pro-self-hosted");H.updateSetting("transforms-enabled", true);-- cy.intercept("PUT", "/api/field/*").as("updateField");- cy.intercept("POST", "/api/transform").as("createTransform");- cy.intercept("PUT", "/api/transform/*").as("updateTransform");- cy.intercept("DELETE", "/api/transform/*").as("deleteTransform");- cy.intercept("DELETE", "/api/transform/*/table").as("deleteTransformTable");- cy.intercept("POST", "/api/transform-tag").as("createTag");- cy.intercept("PUT", "/api/transform-tag/*").as("updateTag");- cy.intercept("DELETE", "/api/transform-tag/*").as("deleteTag");});- it("should be not be possible to create a new schema when updating a transform target", () => {+ it("should not be possible to create a new schema when the database does not support schemas", () => {+ cy.log("update the target of a transform");createMbqlTransform({databaseId: WRITABLE_DB_ID,sourceTable: "ORDERS",@@ -2912,10 +2619,9 @@ describe("scenarios > admin > transforms > databases without :schemas", () => {H.DataStudio.Transforms.settingsTab().click();getTransformsTargetContent().button("Change target").click();+ H.modal().findByLabelText("New table name").should("be.visible");H.modal().findByLabelText("Schema").should("not.exist");- });- it("should be not be possible to create a new schema when the database does not support schemas", () => {cy.log("create a new transform");visitTransformListPage();getTransformsList().button("Create a transform").click();@@ -2926,6 +2632,7 @@ describe("scenarios > admin > transforms > databases without :schemas", () => {cy.findByText("Orders").click();});getQueryEditor().button("Save").click();+ H.modal().findByLabelText("Table name").should("be.visible");H.modal().findByLabelText("Schema").should("not.exist");});});@@ -2946,7 +2653,47 @@ describe("scenarios > admin > transforms > jobs", () => {});describe("creation", () => {- it("should be able to create a job with default properties", () => {+ afterEach(() => {+ H.expectNoBadSnowplowEvents();+ });++ it("should pre-create default jobs and tags and create jobs with default and custom properties", () => {+ cy.log("built-in jobs are recognized in the cron builder");+ visitJobListPage();++ const jobNameToFrequency = {+ "Hourly job": "hourly",+ "Daily job": "daily",+ "Weekly job": "weekly",+ "Monthly job": "monthly",+ };+ Object.entries(jobNameToFrequency).forEach(([jobName, frequency]) => {+ H.DataStudio.Jobs.list().findByText(jobName).click();+ H.DataStudio.Jobs.editor().within(() => {+ getScheduleFrequencyInput().should("have.value", frequency);+ });+ cy.go("back");+ });++ cy.log("make sure that default jobs are created");+ const jobNames = ["Hourly job", "Daily job", "Weekly job", "Monthly job"];+ const tagNames = ["hourly", "daily", "weekly", "monthly"];+ H.DataStudio.Jobs.list().within(() => {+ jobNames.forEach((jobName) =>+ cy.findByText(jobName).should("be.visible"),+ );+ });++ cy.log("make sure that default tags are available for selection");+ H.DataStudio.Jobs.list().findByRole("link", { name: /New/ }).click();+ getTagsInput().click();+ H.popover().within(() => {+ tagNames.forEach((tagName) =>+ cy.findByText(tagName).should("be.visible"),+ );+ });++ cy.log("create a job with default properties");visitJobListPage();H.DataStudio.Jobs.list().findByRole("link", { name: /New/ }).click();@@ -2961,15 +2708,16 @@ describe("scenarios > admin > transforms > jobs", () => {});H.undoToast().findByText("New job created").should("be.visible");+ H.undoToast().icon("close").click();+ H.undoToast().should("not.exist");H.DataStudio.Jobs.editor().within(() => {cy.findByPlaceholderText("Name").should("have.value", "New job");getScheduleFrequencyInput().should("have.value", "daily");getScheduleTimeInput().should("have.value", "12:00");});- });- it("should be able to create a job with custom property values", () => {+ cy.log("create a job with custom property values");visitJobListPage();H.DataStudio.Jobs.list().findByRole("link", { name: /New/ }).click();@@ -2987,11 +2735,14 @@ describe("scenarios > admin > transforms > jobs", () => {cy.wait("@createJob");cy.log("verify transform_job_created event was tracked");- H.expectUnstructuredSnowplowEvent({- event: "transform_job_created",- triggered_from: "transform_job_new",- result: "success",- });+ H.expectUnstructuredSnowplowEvent(+ {+ event: "transform_job_created",+ triggered_from: "transform_job_new",+ result: "success",+ },+ 2,+ );H.undoToast().findByText("New job created").should("be.visible");@@ -3004,27 +2755,7 @@ describe("scenarios > admin > transforms > jobs", () => {});});- describe("name", () => {- it("should be able to edit the name after creation", () => {- H.createTransformJob({ name: "New job" }, { visitTransformJob: true });-- H.DataStudio.Jobs.editor()- .findByPlaceholderText("Name")- .clear()- .type("New name")- .blur();- H.undoToast().findByText("Job name updated").should("be.visible");- H.DataStudio.Jobs.editor()- .findByPlaceholderText("Name")- .should("have.value", "New name");- });- });-describe("schedule", () => {- beforeEach(() => {- H.resetSnowplow();- });-afterEach(() => {H.expectNoBadSnowplowEvents();});@@ -3071,40 +2802,44 @@ describe("scenarios > admin > transforms > jobs", () => {});});- it("should be able to change the schedule after creation", () => {+ it("should be able to edit the schedule, name, and tags of a job and delete it", () => {H.createTransformJob({ name: "New job" }, { visitTransformJob: true });++ cy.log("a job without transforms does not render the transforms table");+ H.DataStudio.Jobs.editor()+ .findByText(/There are no transforms for this job/)+ .scrollIntoView()+ .should("be.visible");+ getJobTransformTable().should("not.exist");++ cy.log("change the schedule");H.DataStudio.Jobs.editor().within(() => {getScheduleFrequencyInput().click();});H.popover().findByText("weekly").click();+ cy.wait("@updateJob");H.undoToast().findByText("Job schedule updated").should("be.visible");+ H.undoToast().icon("close").click();+ H.undoToast().should("not.exist");H.DataStudio.Jobs.editor().within(() => {getScheduleFrequencyInput().should("have.value", "weekly");});- });-- it("should recognize built-in jobs in the cron builder", () => {- visitJobListPage();- const jobNameToFrequency = {- "Hourly job": "hourly",- "Daily job": "daily",- "Weekly job": "weekly",- "Monthly job": "monthly",- };- Object.entries(jobNameToFrequency).forEach(([jobName, frequency]) => {- H.DataStudio.Jobs.list().findByText(jobName).click();- H.DataStudio.Jobs.editor().within(() => {- getScheduleFrequencyInput().should("have.value", frequency);- });- cy.go("back");- });- });- });+ cy.log("change the name");+ H.DataStudio.Jobs.editor()+ .findByPlaceholderText("Name")+ .clear()+ .type("New name")+ .blur();+ cy.wait("@updateJob");+ H.undoToast().findByText("Job name updated").should("be.visible");+ H.undoToast().icon("close").click();+ H.undoToast().should("not.exist");+ H.DataStudio.Jobs.editor()+ .findByPlaceholderText("Name")+ .should("have.value", "New name");- describe("tags", () => {- it("should be able to add and remove tags", () => {- H.createTransformJob({ name: "New job" }, { visitTransformJob: true });+ cy.log("add and remove tags");getTagsInput().click();H.popover().findByText("hourly").click();@@ -3118,16 +2853,23 @@ describe("scenarios > admin > transforms > jobs", () => {assertOptionSelected("daily");getTagsInput().type("{backspace}");+ cy.wait("@updateJob");assertOptionSelected("hourly");assertOptionNotSelected("daily");++ cy.log("delete the job");+ H.DataStudio.Jobs.header().icon("ellipsis").click();+ H.popover().findByText("Delete").click();+ H.modal().within(() => {+ cy.button("Delete job").click();+ cy.wait("@deleteJob");+ });+ H.DataStudio.Jobs.list().findByText("Hourly job").should("be.visible");+ H.DataStudio.Jobs.list().findByText("New name").should("not.exist");});});describe("runs", () => {- beforeEach(() => {- H.resetSnowplow();- });-it("should be able to manually run a job", () => {H.createTransformTag({ name: "New tag" }).then(({ body: tag }) => {createMbqlTransform({@@ -3138,7 +2880,15 @@ describe("scenarios > admin > transforms > jobs", () => {{ visitTransformJob: true },);});- runJobAndWaitForSuccess();++ cy.log("the job renders its transforms table");+ H.DataStudio.Jobs.editor()+ .findByText("Transforms")+ .scrollIntoView()+ .should("be.visible");+ getJobTransformTable().findByText("MBQL transform").should("be.visible");++ runTransformAndWaitForSuccess();H.expectUnstructuredSnowplowEvent({event: "transform_job_trigger_manual_run",});@@ -3169,7 +2919,7 @@ describe("scenarios > admin > transforms > jobs", () => {{ visitTransformJob: true },);});- runJobAndWaitForFailure();+ runTransformAndWaitForFailure();H.DataStudio.Jobs.editor().findByText("Last run failed a few seconds ago.",);@@ -3178,28 +2928,6 @@ describe("scenarios > admin > transforms > jobs", () => {});});- describe("deletion", () => {- it("should be able to delete a job", () => {- cy.log("create a job with a tag");- H.createTransformTag({ name: "New tag" }).then(({ body: tag }) => {- H.createTransformJob(- { name: "New job", tag_ids: [tag.id] },- { visitTransformJob: true },- );- });-- cy.log("delete the job");- H.DataStudio.Jobs.header().icon("ellipsis").click();- H.popover().findByText("Delete").click();- H.modal().within(() => {- cy.button("Delete job").click();- cy.wait("@deleteJob");- });- H.DataStudio.Jobs.list().should("be.visible");- H.DataStudio.Jobs.list().findByText("New job").should("not.exist");- });- });-describe("active flag", () => {beforeEach(() => {cy.intercept("PUT", "/api/transform-job/active").as(@@ -3259,6 +2987,10 @@ describe("scenarios > admin > transforms > jobs", () => {openBulkActionsMenu();H.popover().findByText("Disable all").click();H.modal().button("Cancel").click();+ H.modal().should("not.exist");+ cy.get("@bulkUpdateJobActive.all").should("have.length", 0);+ getJobRow("Job A").findByText("Disabled").should("not.exist");+ getJobRow("Job B").findByText("Disabled").should("not.exist");cy.log("bulk-disable: confirming sends { active: false } and badges all rows",@@ -3288,65 +3020,6 @@ describe("scenarios > admin > transforms > jobs", () => {getJobRow("Job B").findByText("Disabled").should("not.exist");});});-- describe("default jobs and tags", () => {- it("should pre-create default jobs and tags", () => {- const jobNames = ["Hourly job", "Daily job", "Weekly job", "Monthly job"];- const tagNames = ["hourly", "daily", "weekly", "monthly"];-- cy.log("make sure that default jobs are created");- visitJobListPage();- H.DataStudio.Jobs.list().within(() => {- jobNames.forEach((jobName) =>- cy.findByText(jobName).should("be.visible"),- );- });-- cy.log("make sure that default tags are available for selection");- H.DataStudio.Jobs.list().findByRole("link", { name: /New/ }).click();- getTagsInput().click();- H.popover().within(() => {- tagNames.forEach((tagName) =>- cy.findByText(tagName).should("be.visible"),- );- });- });- });-- describe("dependencies", () => {- it("should render the transforms table", () => {- H.createTransformTag({ name: "tag1" }).then(({ body: tag }) => {- createMbqlTransform({- targetTable: TARGET_TABLE,- tagIds: [tag.id],- });- H.createTransformJob(- {- tag_ids: [tag.id],- },- { visitTransformJob: true },- );- });-- H.DataStudio.Jobs.editor()- .findByText("Transforms")- .scrollIntoView()- .should("be.visible");- getJobTransformTable().within(() => {- // Check the existence and also their order- cy.findByText("MBQL transform").should("be.visible");- });- });-- it("should not render the transforms table if the job has no transforms", () => {- H.createTransformJob({}, { visitTransformJob: true });- H.DataStudio.Jobs.editor()- .findByText(/There are no transforms for this job/)- .scrollIntoView()- .should("be.visible");- getJobTransformTable().should("not.exist");- });- });});describe("scenarios > admin > transforms > runs", () => {@@ -3359,7 +3032,7 @@ describe("scenarios > admin > transforms > runs", () => {H.resyncDatabase({ dbId: WRITABLE_DB_ID, tableName: SOURCE_TABLE });});- it("should be able to filter runs", () => {+ it("should be able to filter and sort runs", () => {function createInitialData() {H.createTransformTag({ name: "tag1" }).then(({ body: tag1 }) => {H.createTransformTag({ name: "tag2" }).then(({ body: tag2 }) => {@@ -3378,6 +3051,12 @@ describe("scenarios > admin > transforms > runs", () => {});H.DataStudio.Transforms.runTab().click();runTransformAndWaitForFailure();++ cy.log("the failed run shows its error message");+ getRunErrorInfoButton().click();+ H.modal().should("contain.text", 'relation "abc" does not exist');+ cy.realPress("Escape");+ H.modal().should("not.exist");});});}@@ -3690,41 +3369,6 @@ describe("scenarios > admin > transforms > runs", () => {});}- createInitialData();- H.DataStudio.breadcrumbs().findByText("Transforms").click();- getRunsNavLink().click();- getDetailedViewSwitch().click();- testTransformFilter();- testStatusFilter();- testTagFilter();- testRunMethodFilter();- testStartAtFilter();- testEndAtFilter();- });-- it("should be able to sort runs", () => {- function createInitialData() {- H.createTransformTag({ name: "Alpha tag" }).then(({ body: tag1 }) => {- H.createTransformTag({ name: "Beta tag" }).then(({ body: tag2 }) => {- createMbqlTransform({- targetTable: TARGET_TABLE,- tagIds: [tag1.id],- visitTransform: true,- });- H.DataStudio.Transforms.runTab().click();- runTransformAndWaitForSuccess();- createSqlTransform({- sourceQuery: "SELECT * FROM abc",- targetTable: TARGET_TABLE_2,- tagIds: [tag2.id],- visitTransform: true,- });- H.DataStudio.Transforms.runTab().click();- runTransformAndWaitForFailure();- });- });- }-function testSorting({columnName,transformNames,@@ -3732,12 +3376,19 @@ describe("scenarios > admin > transforms > runs", () => {columnName: string;transformNames: string[];}) {+ // A new intercept per click so the wait can't match an earlier request+ const clickHeaderAndWaitForRuns = () => {+ cy.intercept("GET", /\/api\/transform\/run\?/).as("listRuns");+ getTransformRunTable().findByText(columnName).click();+ cy.wait("@listRuns");+ };+cy.log(`sort by ${columnName} ascending`);- getTransformRunTable().findByText(columnName).click();+ clickHeaderAndWaitForRuns();checkSortingOrder(transformNames);cy.log(`sort by ${columnName} descending`);- getTransformRunTable().findByText(columnName).click();+ clickHeaderAndWaitForRuns();checkSortingOrder([...transformNames].reverse());}@@ -3745,6 +3396,12 @@ describe("scenarios > admin > transforms > runs", () => {H.DataStudio.breadcrumbs().findByText("Transforms").click();getRunsNavLink().click();getDetailedViewSwitch().click();+ testTransformFilter();+ testStatusFilter();+ testTagFilter();+ testRunMethodFilter();+ testStartAtFilter();+ testEndAtFilter();// ascending: "MBQL transform" < "SQL transform"testSorting({@@ -3776,7 +3433,7 @@ describe("scenarios > admin > transforms > runs", () => {transformNames: ["MBQL transform", "SQL transform"],});- // ascending: "Alpha tag" < "Beta tag"+ // ascending: "tag1" < "tag2"testSorting({columnName: "Tags",transformNames: ["MBQL transform", "SQL transform"],@@ -3833,9 +3490,22 @@ describe(cy.log("enter edit mode");H.DataStudio.Transforms.clickEditDefinition();+ H.DataStudio.Transforms.pythonResults()+ .findByText("Done")+ .should("not.exist");+ H.DataStudio.Transforms.pythonResults()+ .findByText("Preview based on the first 100 rows from each table.")+ .should("not.exist");cy.log("running the script should work");runPythonScriptAndWaitForSuccess();+ cy.log("Preview notice should appear after the run");+ H.DataStudio.Transforms.pythonResults()+ .findByText("Done")+ .should("be.visible");+ H.DataStudio.Transforms.pythonResults()+ .findByText("Preview based on the first 100 rows from each table.")+ .should("be.visible");H.assertTableData({columns: ["foo"],firstRows: [["42"]],@@ -3856,42 +3526,6 @@ describe(firstRows: [["43"]],});});-- it("should display preview notice message", () => {- H.getTableId({ name: "Animals", databaseId: WRITABLE_DB_ID }).then(- (id) => {- createPythonTransform({- body: dedent`- import pandas as pd-- def transform(foo):- return pd.DataFrame([{"foo": 42}])- `,- sourceTables: pythonSourceTables("foo", id),- visitTransform: true,- });- },- );-- H.DataStudio.Transforms.clickEditDefinition();-- H.DataStudio.Transforms.pythonResults()- .findByText("Done")- .should("not.exist");- H.DataStudio.Transforms.pythonResults()- .findByText("Preview based on the first 100 rows from each table.")- .should("not.exist");-- runPythonScriptAndWaitForSuccess();-- cy.log("Preview disclaimer should appear");- H.DataStudio.Transforms.pythonResults()- .findByText("Done")- .should("be.visible");- H.DataStudio.Transforms.pythonResults()- .findByText("Preview based on the first 100 rows from each table.")- .should("be.visible");- });},);@@ -3917,14 +3551,15 @@ describe("scenarios > admin > transforms", () => {cy.findByRole("link", { name: "View your database connections" }).should("exist",);- cy.findByTestId("transforms-section-header")- .findByRole("tab", { name: "Transforms" })+ H.DataStudio.Transforms.sectionHeader().should("be.visible");+ H.DataStudio.Transforms.sectionHeader()+ .findByRole("link", { name: "Transforms" }).should("not.exist");- cy.findByTestId("transforms-section-header")- .findByRole("tab", { name: "Jobs" })+ H.DataStudio.Transforms.sectionHeader()+ .findByRole("link", { name: "Jobs" }).should("not.exist");- cy.findByTestId("transforms-section-header")- .findByRole("tab", { name: "Runs" })+ H.DataStudio.Transforms.sectionHeader()+ .findByRole("link", { name: "Runs" }).should("not.exist");});});@@ -4104,16 +3739,6 @@ function runTransformAndWaitForFailure() {getRunButton().should("have.text", "Run failed");}-function runJobAndWaitForSuccess() {- getRunButton().click();- getRunButton().should("have.text", "Ran successfully");-}--function runJobAndWaitForFailure() {- getRunButton().click();- getRunButton().should("have.text", "Run failed");-}-function createMbqlTransform(opts: {sourceTable?: string;@@ -4258,7 +3883,7 @@ describe("scenarios > data studio > transforms > permissions", () => {});it("should allow non-admin users with data-studio permission to create transforms", () => {- cy.log("grant data-studio permission to All Users");+ cy.log("grant transforms permission to the data group");cy.visit("/admin/permissions/application");cy.updatePermissionsGraph({[USER_GROUPS.DATA_GROUP]: {@@ -4272,7 +3897,7 @@ describe("scenarios > data studio > transforms > permissions", () => {H.setUserAsAnalyst(NORMAL_USER_ID);cy.log(- "Ensure that transform permissions are visible when instance is hosted and transform feature is present",+ "Ensure that transform permissions are visible with the pro-self-hosted token",);cy.findByRole("tab", { name: "Data" }).click({ force: true });@@ -4354,6 +3979,13 @@ describe("scenarios > data studio > transforms > permissions > oss", () => {.should("be.visible").click();+ cy.log("Verify the upsell gem icon is displayed on a gated menu item");+ H.DataStudio.nav()+ .findByText("Remote sync")+ .closest("a")+ .findByTestId("upsell-gem")+ .should("be.visible");+cy.log("Verify no upsell gem icon is displayed in Transforms menu item");H.DataStudio.nav().findByText("Data transformation")@@ -4376,6 +4008,7 @@ describe("scenarios > data studio > transforms > permissions > oss", () => {cy.button("Create a transform").should("be.visible").click();cy.log("Verify Python transforms are not available in OSS");+ H.popover().findByText("Query builder").should("be.visible");H.popover().findByText(/Python/i).should("not.exist");