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 dependencies e2e tests (#84247)
Nemanja Glumac11f8e8f25de2
diff --git a/e2e/support/helpers/e2e-dependency-helpers.ts b/e2e/support/helpers/e2e-dependency-helpers.tsindex ffe8e7beb60..d162bead5e0 100644--- a/e2e/support/helpers/e2e-dependency-helpers.ts+++ b/e2e/support/helpers/e2e-dependency-helpers.ts@@ -17,20 +17,12 @@ export const DependencyGraph = {export const DependencyDiagnostics = {visitBrokenDependencies: () => {- cy.intercept("GET", "/api/ee/dependencies/graph/breaking*").as(- "breakingEntities",- );cy.visit("/monitor/dependency-diagnostics/broken");- cy.wait("@breakingEntities");- DependencyDiagnostics.list().should("be.visible");+ waitForDependencyList();},visitUnreferencedEntities: () => {- cy.intercept("GET", "/api/ee/dependencies/graph/unreferenced*").as(- "unreferencedEntities",- );cy.visit("/monitor/dependency-diagnostics/unreferenced");- cy.wait("@unreferencedEntities");- DependencyDiagnostics.list().should("be.visible");+ waitForDependencyList();},list: () => cy.findByTestId("dependency-list"),searchInput: () => cy.findByTestId("dependency-list-search-input"),@@ -54,6 +46,14 @@ export const DependencyDiagnostics = {const WAIT_TIMEOUT = 30000;const WAIT_INTERVAL = 100;+// The list loads after the app starts and the saved list params load, which+// can take longer than the default timeout after a page reload.+function waitForDependencyList() {+ cy.findByTestId("dependency-list", { timeout: WAIT_TIMEOUT }).should(+ "be.visible",+ );+}+export function waitForBackfillComplete(timeout = WAIT_TIMEOUT,): Cypress.Chainable {diff --git a/e2e/test/scenarios/dependencies/dependency-broken-list.cy.spec.ts b/e2e/test/scenarios/dependencies/dependency-broken-list.cy.spec.tsdeleted file mode 100644index e0b68edfb66..00000000000--- a/e2e/test/scenarios/dependencies/dependency-broken-list.cy.spec.ts+++ /dev/null@@ -1,588 +0,0 @@-import { WRITABLE_DB_ID } from "e2e/support/cypress_data";-import { ADMIN_PERSONAL_COLLECTION_ID } from "e2e/support/cypress_sample_instance_data";-import type { DependencyNode, TransformId } from "metabase-types/api";--const { H } = cy;--const TABLE_NAME = "test_transform_table";-const TABLE_DISPLAY_NAME = "Test Transform Table";-const TABLE_TRANSFORM = "Test Transform";-const TABLE_BASED_QUESTION_BROKEN_FIELD =- "Test Table-based question with broken field";-const TABLE_BASED_QUESTION_BROKEN_EXPRESSION =- "Test Table-based question with broken expression";-const TABLE_BASED_QUESTION_BROKEN_FILTER =- "Test Table-based question with broken filter";-const TABLE_BASED_QUESTION_BROKEN_BREAKOUT =- "Test Table-based question with broken breakout";-const TABLE_BASED_QUESTION_BROKEN_AGGREGATION =- "Test Table-based question with broken aggregation";-const TABLE_BASED_QUESTION_BROKEN_EXPLICIT_JOIN =- "Test Table-based question with broken explicit join";-const TABLE_BASED_QUESTION = "Test Table-based question";-const QUESTION_BASED_QUESTION_BROKEN_FILTER =- "Test Question-based question with broken filter";-const TABLE_BASED_MODEL = "Test Table-based model";-const MODEL_BASED_MODEL_BROKEN_AGGREGATION =- "Test Model-based model with broken aggregation";--const BROKEN_TABLE_DEPENDENCIES = [TABLE_DISPLAY_NAME];-const BROKEN_TABLE_DEPENDENTS = [- // NOTE: TABLE_BASED_QUESTION_BROKEN_FIELD is *not* listed here because it's only broken in the `:fields` ref.- // These are considered "soft" refs that don't break the query, since the QP will quietly drop a bad ref from a- // `:fields` clause and the query will run successfully.- TABLE_BASED_QUESTION_BROKEN_EXPRESSION,- TABLE_BASED_QUESTION_BROKEN_FILTER,- TABLE_BASED_QUESTION_BROKEN_BREAKOUT,- TABLE_BASED_QUESTION_BROKEN_AGGREGATION,- TABLE_BASED_QUESTION_BROKEN_EXPLICIT_JOIN,-];-const BROKEN_QUESTION_DEPENDENCIES = [TABLE_BASED_QUESTION];-const BROKEN_QUESTION_DEPENDENTS = [QUESTION_BASED_QUESTION_BROKEN_FILTER];-const BROKEN_MODEL_DEPENDENCIES = [TABLE_BASED_MODEL];-const BROKEN_MODEL_DEPENDENTS = [MODEL_BASED_MODEL_BROKEN_AGGREGATION];--const BROKEN_DEPENDENCIES = [- ...BROKEN_TABLE_DEPENDENCIES,- ...BROKEN_QUESTION_DEPENDENCIES,- ...BROKEN_MODEL_DEPENDENCIES,-];--const BROKEN_DEPENDENCIES_SORTED_BY_NAME = [- TABLE_BASED_MODEL,- TABLE_BASED_QUESTION,- TABLE_DISPLAY_NAME,-];--const BROKEN_DEPENDENCIES_SORTED_BY_LOCATION = [- TABLE_BASED_QUESTION, // Bobby Tables's personal collection- TABLE_BASED_MODEL, // Our analytics- TABLE_DISPLAY_NAME, // Writable Postgres-];--const BROKEN_DEPENDENTS_SORTED_BY_DEPENDENTS_ERRORS = [- TABLE_BASED_QUESTION, // 1 error: PRICE- TABLE_BASED_MODEL, // 1 error: AMOUNT- TABLE_DISPLAY_NAME, // 1 error: SCORE; plus 1 "soft" error on STATUS, which is only in a `:fields` list.-];--const BROKEN_DEPENDENTS_SORTED_BY_DEPENDENTS_WITH_ERRORS = [- TABLE_BASED_QUESTION, // 1 question- TABLE_BASED_MODEL, // 1 model- TABLE_DISPLAY_NAME, // 6 questions-];--const BROKEN_DEPENDENTS = [- ...BROKEN_TABLE_DEPENDENTS,- ...BROKEN_QUESTION_DEPENDENTS,- ...BROKEN_MODEL_DEPENDENTS,-];--describe("scenarios > dependencies > broken list", () => {- beforeEach(() => {- H.restore("postgres-writable");- cy.signInAsAdmin();- H.activateToken("pro-self-hosted");- H.updateSetting("transforms-enabled", true);- createContent();- H.resetSnowplow();- });-- afterEach(() => {- dropTransformTable();- H.expectNoBadSnowplowEvents();- });-- describe("analysis", () => {- it("should show broken dependencies", () => {- H.DependencyDiagnostics.visitBrokenDependencies();- checkList({- visibleEntities: BROKEN_DEPENDENCIES,- hiddenEntities: BROKEN_DEPENDENTS,- });- });- });-- describe("selecting entities", () => {- it("should show sidebar for broken dependents and trigger snowplow event", () => {- H.DependencyDiagnostics.visitBrokenDependencies();-- cy.log("table dependents");- H.DependencyDiagnostics.list().findByText(TABLE_DISPLAY_NAME).click();- checkSidebar({- title: TABLE_DISPLAY_NAME,- transform: TABLE_TRANSFORM,- missingColumns: ["score"],- brokenDependents: BROKEN_TABLE_DEPENDENTS,- });- H.expectUnstructuredSnowplowEvent({- event: "dependency_diagnostics_entity_selected",- triggered_from: "broken",- event_detail: "table",- });-- cy.log("question dependents");- H.DependencyDiagnostics.list().findByText(TABLE_BASED_QUESTION).click();- checkSidebar({- title: TABLE_BASED_QUESTION,- missingColumns: ["PRICE"],- brokenDependents: BROKEN_QUESTION_DEPENDENTS,- });-- cy.log("model dependents");- H.DependencyDiagnostics.list().findByText(TABLE_BASED_MODEL).click();- checkSidebar({- title: TABLE_BASED_MODEL,- missingColumns: ["AMOUNT"],- brokenDependents: BROKEN_MODEL_DEPENDENTS,- });-- cy.log("snowplow event when dependency graph link is clicked");- cy.findByRole("link", { name: "View in dependency graph" }).click();- H.expectUnstructuredSnowplowEvent({- event: "dependency_entity_selected",- triggered_from: "diagnostics-broken-list",- event_detail: "card",- });- });- });-- describe("search", () => {- it("should search for entities", () => {- H.DependencyDiagnostics.visitBrokenDependencies();- H.DependencyDiagnostics.searchInput().type(TABLE_DISPLAY_NAME);- checkList({- visibleEntities: [TABLE_DISPLAY_NAME],- hiddenEntities: [TABLE_BASED_QUESTION, TABLE_BASED_MODEL],- });- });- });-- describe("filtering", () => {- it("should filter entities by type", () => {- H.DependencyDiagnostics.visitBrokenDependencies();- H.DependencyDiagnostics.filterButton().click();- H.popover().within(() => {- cy.findByText("Table").click();- cy.findByText("Question").click();- cy.findByText("Model").click();- });-- cy.log("only tables");- H.popover().findByText("Table").click();- checkList({- visibleEntities: BROKEN_TABLE_DEPENDENCIES,- hiddenEntities: [- ...BROKEN_QUESTION_DEPENDENCIES,- ...BROKEN_MODEL_DEPENDENCIES,- ],- });-- cy.log("only questions");- H.popover().within(() => {- cy.findByText("Table").click();- cy.findByText("Question").click();- });- checkList({- visibleEntities: BROKEN_QUESTION_DEPENDENCIES,- hiddenEntities: [- ...BROKEN_TABLE_DEPENDENCIES,- ...BROKEN_MODEL_DEPENDENCIES,- ],- });-- cy.log("only models");- H.popover().within(() => {- cy.findByText("Question").click();- cy.findByText("Model").click();- });- checkList({- visibleEntities: BROKEN_MODEL_DEPENDENCIES,- hiddenEntities: [- ...BROKEN_TABLE_DEPENDENCIES,- ...BROKEN_QUESTION_DEPENDENCIES,- ],- });- });-- it("should filter entities by location", () => {- H.DependencyDiagnostics.visitBrokenDependencies();- H.DependencyDiagnostics.filterButton().click();- H.popover().within(() => {- cy.findByText("Include items in personal collections").click();- });- checkList({- visibleEntities: [- ...BROKEN_TABLE_DEPENDENCIES,- ...BROKEN_MODEL_DEPENDENCIES,- ],- hiddenEntities: BROKEN_QUESTION_DEPENDENCIES,- });- });- });-- describe("sorting", () => {- it("should sort by name", () => {- H.DependencyDiagnostics.visitBrokenDependencies();- H.DependencyDiagnostics.searchInput().type("test");-- cy.log("sorted by name by default");- checkListSorting({- visibleEntities: BROKEN_DEPENDENCIES_SORTED_BY_NAME,- });-- cy.log("sorted by name ascending");- H.DependencyDiagnostics.list().findByText("Dependency").click();- checkListSorting({- visibleEntities: BROKEN_DEPENDENCIES_SORTED_BY_NAME,- });-- cy.log("sorted by name descending");- H.DependencyDiagnostics.list().findByText("Dependency").click();- checkListSorting({- visibleEntities: [...BROKEN_DEPENDENCIES_SORTED_BY_NAME].reverse(),- });- });-- it("should sort by location", () => {- H.DependencyDiagnostics.visitBrokenDependencies();- H.DependencyDiagnostics.searchInput().type("test");-- cy.log("sorted by location ascending");- H.DependencyDiagnostics.list().findByText("Location").click();- checkListSorting({- visibleEntities: BROKEN_DEPENDENCIES_SORTED_BY_LOCATION,- });-- cy.log("sorted by location descending");- H.DependencyDiagnostics.list().findByText("Location").click();- checkListSorting({- visibleEntities: [...BROKEN_DEPENDENCIES_SORTED_BY_LOCATION].reverse(),- });- });-- it("should sort by dependents errors", () => {- H.DependencyDiagnostics.visitBrokenDependencies();- H.DependencyDiagnostics.searchInput().type("test");-- cy.log("sorted by dependents errors ascending");- H.DependencyDiagnostics.list().findByText("Problems").click();- checkListSorting({- visibleEntities: [- ...BROKEN_DEPENDENTS_SORTED_BY_DEPENDENTS_ERRORS,- ].reverse(),- });-- cy.log("sorted by dependents errors descending");- H.DependencyDiagnostics.list().findByText("Problems").click();- checkListSorting({- visibleEntities: BROKEN_DEPENDENTS_SORTED_BY_DEPENDENTS_ERRORS,- });- });-- it("should sort by dependents with errors", () => {- H.DependencyDiagnostics.visitBrokenDependencies();- H.DependencyDiagnostics.searchInput().type("test");-- cy.log("sorted by dependents with errors ascending");- H.DependencyDiagnostics.list().findByText("Broken dependents").click();- checkListSorting({- visibleEntities: [- ...BROKEN_DEPENDENTS_SORTED_BY_DEPENDENTS_WITH_ERRORS,- ].reverse(),- });-- cy.log("sorted by dependents with errors descending");- H.DependencyDiagnostics.list().findByText("Broken dependents").click();- checkListSorting({- visibleEntities: BROKEN_DEPENDENTS_SORTED_BY_DEPENDENTS_WITH_ERRORS,- });- });- });-});--function createContent() {- createTransform();- createTableContent();- createQuestionContent();- createModelContent();- breakTransform();- waitForBreakingDependencies();-}--function dropTransformTable() {- cy.get<TransformId>("@transformId").then((transformId) => {- cy.request("DELETE", `/api/transform/${transformId}/table`);- });-}--function createTransform() {- H.createTransform(- {- name: TABLE_TRANSFORM,- source: {- type: "query",- query: {- type: "native",- database: WRITABLE_DB_ID,- native: {- query: "SELECT 1 as score, 'active' as status",- },- },- },- target: {- type: "table",- database: WRITABLE_DB_ID,- schema: "public",- name: TABLE_NAME,- },- },- { wrapId: true },- );- cy.get<TransformId>("@transformId").then((transformId) => {- H.runTransform(transformId);- H.resyncDatabase({ dbId: WRITABLE_DB_ID, tableName: TABLE_NAME });- H.waitForTransformRuns(- (runs) =>- runs.length === 1 && runs.every((run) => run.status === "succeeded"),- );- });-}--function breakTransform() {- cy.get<TransformId>("@transformId").then((transformId) => {- cy.request("PUT", `/api/transform/${transformId}`, {- source: {- type: "query",- query: {- type: "native",- database: WRITABLE_DB_ID,- native: {- query: "SELECT 1 as score_new, 'active' as status_new",- },- },- },- });- H.runTransform(transformId);- H.waitForTransformRuns(- (runs) =>- runs.length === 2 && runs.every((run) => run.status === "succeeded"),- );- });-}--function createTableContent() {- H.getTableId({ name: TABLE_NAME }).then((tableId) => {- cy.wrap(tableId).as("tableId");-- H.getFieldId({ tableId, name: "score" }).then((scoreFieldId) => {- H.getFieldId({ tableId, name: "status" }).then((statusFieldId) => {- H.createQuestion({- name: TABLE_BASED_QUESTION_BROKEN_FIELD,- database: WRITABLE_DB_ID,- query: {- "source-table": tableId,- fields: [["field", statusFieldId, null]],- },- });-- H.createQuestion({- name: TABLE_BASED_QUESTION_BROKEN_EXPRESSION,- database: WRITABLE_DB_ID,- query: {- "source-table": tableId,- expressions: {- Expression: ["+", ["field", scoreFieldId, null], 0],- },- },- });-- H.createQuestion({- name: TABLE_BASED_QUESTION_BROKEN_FILTER,- database: WRITABLE_DB_ID,- query: {- "source-table": tableId,- filter: ["=", ["field", scoreFieldId, null], 0],- },- });-- H.createQuestion({- name: TABLE_BASED_QUESTION_BROKEN_BREAKOUT,- database: WRITABLE_DB_ID,- query: {- "source-table": tableId,- breakout: [["field", scoreFieldId, null]],- },- });-- H.createQuestion({- name: TABLE_BASED_QUESTION_BROKEN_AGGREGATION,- database: WRITABLE_DB_ID,- query: {- "source-table": tableId,- aggregation: [["avg", ["field", scoreFieldId, null]]],- },- });-- H.createQuestion({- name: TABLE_BASED_QUESTION_BROKEN_EXPLICIT_JOIN,- database: WRITABLE_DB_ID,- query: {- "source-table": tableId,- joins: [- {- "source-table": tableId,- alias: TABLE_DISPLAY_NAME,- condition: [- "=",- ["field", statusFieldId, null],- [- "field",- statusFieldId,- { "join-alias": TABLE_DISPLAY_NAME },- ],- ],- },- ],- aggregation: [- [- "max",- ["field", scoreFieldId, { "join-alias": TABLE_DISPLAY_NAME }],- ],- ],- },- });- });- });- });-}--function createQuestionContent() {- H.getTableId({ name: TABLE_NAME }).then((tableId) => {- H.createQuestion({- name: TABLE_BASED_QUESTION,- database: WRITABLE_DB_ID,- query: {- "source-table": tableId,- },- collection_id: ADMIN_PERSONAL_COLLECTION_ID,- }).then(({ body: card }) => {- cy.wrap(card.id).as("questionId");- H.createQuestion({- name: QUESTION_BASED_QUESTION_BROKEN_FILTER,- query: {- "source-table": `card__${card.id}`,- filter: [">", ["field", "PRICE", { "base-type": "type/Float" }], 10],- },- });- });- });-}--function createModelContent() {- H.getTableId({ name: TABLE_NAME }).then((tableId) => {- H.createQuestion({- name: TABLE_BASED_MODEL,- type: "model",- database: WRITABLE_DB_ID,- query: {- "source-table": tableId,- },- }).then(({ body: card }) => {- cy.wrap(card.id).as("modelId");- H.createQuestion({- name: MODEL_BASED_MODEL_BROKEN_AGGREGATION,- type: "model",- query: {- "source-table": `card__${card.id}`,- aggregation: [- ["distinct", ["field", "AMOUNT", { "base-type": "type/Integer" }]],- ],- },- });- });- });-}--function waitForBreakingDependencies() {- // The instance already has unrelated (Usage Analytics) breaking dependencies,- // so a bare count check can pass before the test's own entities are analyzed.- // Wait until every expected entity is present by name instead.- H.waitForBreakingDependencies((nodes) =>- BROKEN_DEPENDENCIES.every((name) =>- nodes.some((node) => getNodeName(node) === name),- ),- );-}--function getNodeName(node: DependencyNode): string | undefined {- const { data } = node;- if ("display_name" in data && data.display_name) {- return data.display_name;- }- return "name" in data ? data.name : undefined;-}--function checkList({- visibleEntities = [],- hiddenEntities = [],-}: {- visibleEntities?: string[];- hiddenEntities?: string[];-}) {- H.DependencyDiagnostics.list().within(() => {- visibleEntities.forEach((name) => {- cy.findByText(name).should("exist");- });- hiddenEntities.forEach((name) => {- cy.findByText(name).should("not.exist");- });- });-}--function checkSidebar({- title,- transform,- missingColumns,- brokenDependents,-}: {- title: string;- transform?: string;- missingColumns?: string[];- brokenDependents?: string[];-}) {- H.DependencyDiagnostics.sidebar().within(() => {- H.DependencyDiagnostics.Sidebar.header()- .findByText(title)- .should("be.visible");- if (transform) {- H.DependencyDiagnostics.Sidebar.infoSection()- .findByText(transform)- .should("exist");- }- if (missingColumns) {- H.DependencyDiagnostics.Sidebar.missingColumnsSection().within(() => {- missingColumns.forEach((column) => {- cy.findByText(column).should("exist");- });- });- }- if (brokenDependents) {- H.DependencyDiagnostics.Sidebar.brokenDependentsSection().within(() => {- brokenDependents.forEach((dependent) => {- cy.findByText(dependent).should("exist");- });- });- }- });-}--function checkListSorting({ visibleEntities }: { visibleEntities: string[] }) {- H.DependencyDiagnostics.list().within(() => {- visibleEntities.forEach((name, index) => {- cy.findByText(name)- .parents("[data-index]")- .should("have.attr", "data-index", index.toString());- });- });-}diff --git a/e2e/test/scenarios/dependencies/dependency-checks.cy.spec.ts b/e2e/test/scenarios/dependencies/dependency-checks.cy.spec.tsdeleted file mode 100644index abe425fde4e..00000000000--- a/e2e/test/scenarios/dependencies/dependency-checks.cy.spec.ts+++ /dev/null@@ -1,343 +0,0 @@-const { H } = cy;--import { WRITABLE_DB_ID } from "e2e/support/cypress_data";-import { SAMPLE_DATABASE } from "e2e/support/cypress_sample_database";-import { ORDERS_DASHBOARD_ID } from "e2e/support/cypress_sample_instance_data";--const { PRODUCTS_ID } = SAMPLE_DATABASE;--describe("scenarios > dependencies > dependency checks", () => {- beforeEach(() => {- H.restore("postgres-writable");- H.resetTestTable({ type: "postgres", table: "many_schemas" });- cy.signInAsAdmin();- H.activateToken("pro-self-hosted");- H.updateSetting("transforms-enabled", true);- H.resyncDatabase({ dbId: WRITABLE_DB_ID, tableName: "Animals" });- H.resetSnowplow();-- cy.intercept("PUT", "/api/card/*").as("updateCard");- cy.intercept("PUT", "/api/native-query-snippet/*").as("updateSnippet");- cy.intercept("PUT", "/api/transform/*").as("updateTransform");- });-- afterEach(() => {- H.expectNoBadSnowplowEvents();- });-- describe("questions", () => {- it("should not show a confirmation if there are no breaking changes when updating a MBQL question", () => {- createMbqlQuestionWithDependentMbqlQuestions();- H.visitQuestion("@questionId");- H.openNotebook();- H.getNotebookStep("expression").findByText("Expr").click();- H.CustomExpressionEditor.clear().type("2 + 2");- H.popover().button("Update").click();- H.queryBuilderHeader().button("Save").click();- H.modal().button("Save").click();- cy.wait("@updateCard");- });- });-- describe("metrics", () => {- it("should not show a warning when a change to a metric is backward-compatible with existing content", () => {- createMetricWithDependentMbqlQuestionsAndTransforms();- cy.get<number>("@metricId").then((metricId) => {- cy.visit(`/metric/${metricId}/query`);- });- H.getNotebookStep("summarize").findByText("Min of Score").click();- H.popover().findByText("Name").click();- cy.button("Save").click();- cy.wait("@updateCard");- });- });-- describe("transforms", () => {- const goToEditorAndType = (queryString: string) => {- H.DataStudio.Transforms.clickEditDefinition();- cy.url().should("include", "/edit");- H.NativeEditor.clear().type(queryString);- };-- it("should not show a confirmation if there are no breaking changes when updating a SQL transform after it was run", () => {- createSqlTransformWithDependentMbqlQuestions();- cy.get<number>("@transformId").then(H.visitTransform);- goToEditorAndType('SELECT score, name FROM "Schema A"."Animals"');- H.DataStudio.Transforms.saveChangesButton().click();- cy.wait("@updateTransform");- });-- it("should not show a confirmation if there are no breaking changes when updating a MBQL transform before it was run", () => {- createMbqlTransformWithDependentMbqlTransforms();- cy.get<number>("@transformId").then(H.visitTransform);- H.DataStudio.Transforms.clickEditDefinition();- H.getNotebookStep("data").button("Sort").click();- H.popover().findByText("Score").click();- H.DataStudio.Transforms.saveChangesButton().click();- cy.wait("@updateTransform");- });- });-});--function createMbqlQuestionWithDependentMbqlQuestions() {- H.createQuestion({- name: "Base question",- query: {- "source-table": PRODUCTS_ID,- expressions: {- Expr: ["+", 1, 1],- },- },- }).then(({ body: card }) => {- cy.wrap(card.id).as("questionId");-- H.createQuestion({- name: "Question with fields",- query: {- "source-table": `card__${card.id}`,- filter: [">", ["field", "Expr", { "base-type": "type/Integer" }], 1],- },- dashboard_id: ORDERS_DASHBOARD_ID,- });-- H.createQuestion({- name: "Question without fields",- query: {- "source-table": `card__${card.id}`,- },- });- });-}--function createMetricWithDependentMbqlQuestionsAndTransforms() {- H.getTableId({ databaseId: WRITABLE_DB_ID, name: "Animals" }).then(- (tableId) => {- H.getFieldId({ tableId, name: "score" }).then((fieldId) => {- H.createQuestion({- name: "Base metric",- type: "metric",- database: WRITABLE_DB_ID,- query: {- "source-table": tableId,- aggregation: [["min", ["field", fieldId, null]]],- },- }).then(({ body: metric }) => {- cy.wrap(metric.id).as("metricId");-- H.createQuestion({- name: "Question with 1 stage",- database: WRITABLE_DB_ID,- query: {- "source-table": tableId,- aggregation: [["metric", metric.id]],- },- });-- H.createQuestion({- name: "Question with 2 stages",- database: WRITABLE_DB_ID,- query: {- "source-query": {- "source-table": tableId,- aggregation: [["metric", metric.id]],- breakout: [["field", fieldId, null]],- },- aggregation: [- ["avg", ["field", "min", { "base-type": "type/Integer" }]],- ],- },- });-- H.createTransform({- name: "Transform with 1 stage",- source: {- type: "query",- query: {- database: WRITABLE_DB_ID,- type: "query",- query: {- "source-table": tableId,- aggregation: [["metric", metric.id]],- },- },- },- target: {- type: "table",- name: "transform_1_stage",- schema: "public",- database: WRITABLE_DB_ID,- },- });-- H.createTransform({- name: "Transform with 2 stages",- source: {- type: "query",- query: {- database: WRITABLE_DB_ID,- type: "query",- query: {- "source-query": {- "source-table": tableId,- aggregation: [["metric", metric.id]],- breakout: [["field", fieldId, null]],- },- aggregation: [- ["avg", ["field", "min", { "base-type": "type/Integer" }]],- ],- },- },- },- target: {- type: "table",- name: "transform_2_stages",- schema: "public",- database: WRITABLE_DB_ID,- },- });- });- });- },- );-}--function createSqlTransformWithDependentMbqlQuestions() {- const transformTableName = "base_transform";-- H.createTransform({- name: "Base transform",- source: {- type: "query",- query: {- database: WRITABLE_DB_ID,- type: "native",- native: {- query: 'SELECT name, score FROM "Schema A"."Animals"',- "template-tags": {},- },- },- },- target: {- type: "table",- name: transformTableName,- schema: "public",- database: WRITABLE_DB_ID,- },- }).then(({ body: transform }) => {- cy.wrap(transform.id).as("transformId");- H.runTransformAndWaitForSuccess(transform.id);- H.resyncDatabase({ dbId: WRITABLE_DB_ID, tableName: transformTableName });-- H.getTableId({ databaseId: WRITABLE_DB_ID, name: transformTableName }).then(- (tableId) => {- H.createQuestion({- name: "Question with fields",- database: WRITABLE_DB_ID,- query: {- "source-table": tableId,- filter: [- ">",- ["field", "score", { "base-type": "type/Integer" }],- 1,- ],- },- });- H.createQuestion({- name: "Question without fields",- database: WRITABLE_DB_ID,- query: {- "source-table": tableId,- },- });- },- );- });-}--function createMbqlTransformWithDependentMbqlTransforms() {- const targetTableName = "base_transform";-- H.getTableId({ name: "Animals", databaseId: WRITABLE_DB_ID }).then(- (tableId) => {- H.createTransform(- {- name: "Base transform",- source: {- type: "query",- query: {- database: WRITABLE_DB_ID,- type: "query",- query: {- "source-table": tableId,- },- },- },- target: {- type: "table",- name: targetTableName,- schema: "public",- database: WRITABLE_DB_ID,- },- },- { wrapId: true },- )- .then(({ body }) => H.runTransformAndWaitForSuccess(body.id))- .then(() => {- H.resyncDatabase({- dbId: WRITABLE_DB_ID,- tableName: targetTableName,- });- H.getTableId({- databaseId: WRITABLE_DB_ID,- name: targetTableName,- }).then((tableId) => {- H.getFieldId({ tableId, name: "name" }).then((fieldId) => {- H.createTransform({- name: "Name transform",- source: {- type: "query",- query: {- database: WRITABLE_DB_ID,- type: "query",- query: {- "source-table": tableId,- fields: [["field", fieldId, null]],- },- },- },- target: {- type: "table",- name: "name_transform",- schema: "public",- database: WRITABLE_DB_ID,- },- });- });-- H.getFieldId({ tableId, name: "score" }).then((fieldId) => {- H.createTransform({- name: "Score transform",- source: {- type: "query",- query: {- database: WRITABLE_DB_ID,- type: "query",- query: {- "source-table": tableId,- filter: [">", ["field", fieldId, null], 1],- },- },- },- target: {- type: "table",- name: "score_transform",- schema: "public",- database: WRITABLE_DB_ID,- },- });- });- });- });- },- );-}diff --git a/e2e/test/scenarios/dependencies/dependency-diagnostics.cy.spec.ts b/e2e/test/scenarios/dependencies/dependency-diagnostics.cy.spec.tsnew file mode 100644index 00000000000..a6b59a288ed--- /dev/null+++ b/e2e/test/scenarios/dependencies/dependency-diagnostics.cy.spec.ts@@ -0,0 +1,1959 @@+import { SAMPLE_DB_ID, USERS, WRITABLE_DB_ID } from "e2e/support/cypress_data";+import { SAMPLE_DATABASE } from "e2e/support/cypress_sample_database";+import {+ ADMIN_PERSONAL_COLLECTION_ID,+ ADMIN_USER_ID,+ FIRST_COLLECTION_ID,+} from "e2e/support/cypress_sample_instance_data";+import type {+ CardId,+ CollectionId,+ DependencyDiagnosticsUserParams,+ DependencyNode,+ DependencySortColumn,+ FieldId,+ ListUnreferencedGraphNodesResponse,+ NativeQuerySnippetId,+ SegmentId,+ SortDirection,+ TableId,+ TransformId,+} from "metabase-types/api";+import { createMockParameter } from "metabase-types/api/mocks";++const { H } = cy;+const { ORDERS_ID, PRODUCTS, PRODUCTS_ID } = SAMPLE_DATABASE;++const TRANSFORM_TABLE_NAME = "test_transform_table";+const TRANSFORM_TABLE_DISPLAY_NAME = "Test Transform Table";+const TABLE_TRANSFORM = "Test Transform";+const TABLE_BASED_QUESTION_BROKEN_FIELD =+ "Test Table-based question with broken field";+const TABLE_BASED_QUESTION_BROKEN_EXPRESSION =+ "Test Table-based question with broken expression";+const TABLE_BASED_QUESTION_BROKEN_FILTER =+ "Test Table-based question with broken filter";+const TABLE_BASED_QUESTION_BROKEN_BREAKOUT =+ "Test Table-based question with broken breakout";+const TABLE_BASED_QUESTION_BROKEN_AGGREGATION =+ "Test Table-based question with broken aggregation";+const TABLE_BASED_QUESTION_BROKEN_EXPLICIT_JOIN =+ "Test Table-based question with broken explicit join";+const TABLE_BASED_QUESTION = "Test Table-based question";+const QUESTION_BASED_QUESTION_BROKEN_FILTER =+ "Test Question-based question with broken filter";+const TABLE_BASED_MODEL = "Test Table-based model";+const MODEL_BASED_MODEL_BROKEN_AGGREGATION =+ "Test Model-based model with broken aggregation";+const MODEL_BASED_QUESTION_BROKEN_FILTER =+ "Test Model-based question with broken filter";++const BROKEN_TABLE_DEPENDENCIES = [TRANSFORM_TABLE_DISPLAY_NAME];+const BROKEN_TABLE_DEPENDENTS = [+ // NOTE: TABLE_BASED_QUESTION_BROKEN_FIELD is *not* listed here because it's only broken in the `:fields` ref.+ // These are considered "soft" refs that don't break the query, since the QP will quietly drop a bad ref from a+ // `:fields` clause and the query will run successfully.+ TABLE_BASED_QUESTION_BROKEN_EXPRESSION,+ TABLE_BASED_QUESTION_BROKEN_FILTER,+ TABLE_BASED_QUESTION_BROKEN_BREAKOUT,+ TABLE_BASED_QUESTION_BROKEN_AGGREGATION,+ TABLE_BASED_QUESTION_BROKEN_EXPLICIT_JOIN,+];+const BROKEN_QUESTION_DEPENDENCIES = [TABLE_BASED_QUESTION];+const BROKEN_QUESTION_DEPENDENTS = [QUESTION_BASED_QUESTION_BROKEN_FILTER];+const BROKEN_MODEL_DEPENDENCIES = [TABLE_BASED_MODEL];+const BROKEN_MODEL_DEPENDENTS = [+ MODEL_BASED_MODEL_BROKEN_AGGREGATION,+ MODEL_BASED_QUESTION_BROKEN_FILTER,+];++const BROKEN_DEPENDENCIES = [+ ...BROKEN_TABLE_DEPENDENCIES,+ ...BROKEN_QUESTION_DEPENDENCIES,+ ...BROKEN_MODEL_DEPENDENCIES,+];++const BROKEN_DEPENDENCIES_SORTED_BY_NAME = [+ TABLE_BASED_MODEL,+ TABLE_BASED_QUESTION,+ TRANSFORM_TABLE_DISPLAY_NAME,+];++const BROKEN_DEPENDENCIES_SORTED_BY_LOCATION = [+ TABLE_BASED_QUESTION, // Bobby Tables's personal collection+ TABLE_BASED_MODEL, // Our analytics+ TRANSFORM_TABLE_DISPLAY_NAME, // Writable Postgres+];++const BROKEN_DEPENDENTS_SORTED_BY_DEPENDENTS_ERRORS = [+ TRANSFORM_TABLE_DISPLAY_NAME, // 1 error: SCORE. The analysis does not count STATUS in a `:fields` list or a join condition.+ TABLE_BASED_QUESTION, // 3 errors: PRICE, TAX, DISCOUNT+ TABLE_BASED_MODEL, // 4 errors: AMOUNT, QUANTITY, SUBTOTAL, TOTAL+];++const BROKEN_DEPENDENTS_SORTED_BY_DEPENDENTS_WITH_ERRORS = [+ TABLE_BASED_QUESTION, // 1 question+ TABLE_BASED_MODEL, // 1 model, 1 question+ TRANSFORM_TABLE_DISPLAY_NAME, // 5 questions+];++const BROKEN_DEPENDENTS = [+ ...BROKEN_TABLE_DEPENDENTS,+ ...BROKEN_QUESTION_DEPENDENTS,+ ...BROKEN_MODEL_DEPENDENTS,+];++const DATABASE_NAME = "Writable Postgres12";+const MANY_DATA_TYPES_TABLE_NAME = "many_data_types";+const MANY_DATA_TYPES_TABLE_DISPLAY_NAME = "Many Data Types";+const TABLE_DESCRIPTION = "This is a table with many data types";+const MODEL_FOR_QUESTION_DATA_SOURCE = "Model for question data source";+const MODEL_FOR_MODEL_DATA_SOURCE = "Model for model data source";+const MODEL_FOR_METRIC_DATA_SOURCE = "Model for metric data source";+const MODEL_FOR_NATIVE_QUESTION_CARD_TAG = "Model for native question card tag";+const MODEL_FOR_NATIVE_QUESTION_PARAMETER_SOURCE =+ "Model for native question parameter source";+const MODEL_FOR_DASHBOARD_CARD = "Model for dashboard card";+const MODEL_FOR_DASHBOARD_PARAMETER_SOURCE =+ "Model for dashboard parameter source";+const SEGMENT_FOR_QUESTION_FILTER = "Segment for question filter";+const SEGMENT_FOR_MODEL_FILTER = "Segment for model filter";+const SEGMENT_FOR_SEGMENT_FILTER = "Segment for segment filter";+const SEGMENT_FOR_METRIC_FILTER = "Segment for metric filter";+const METRIC_FOR_QUESTION_AGGREGATION = "Metric for question aggregation";+const METRIC_FOR_MODEL_AGGREGATION = "Metric for model aggregation";+const METRIC_FOR_METRIC_AGGREGATION = "Metric for metric aggregation";+const METRIC_FOR_DASHBOARD_CARD = "Metric for dashboard card";+const SNIPPET_FOR_NATIVE_QUESTION_CARD_TAG =+ "Snippet for native question card tag";+const SNIPPET_FOR_SNIPPET_TAG = "Snippet for snippet tag";++const TABLE_NAMES = [MANY_DATA_TYPES_TABLE_DISPLAY_NAME];++const MODEL_NAMES = [+ MODEL_FOR_QUESTION_DATA_SOURCE,+ MODEL_FOR_MODEL_DATA_SOURCE,+ MODEL_FOR_METRIC_DATA_SOURCE,+ MODEL_FOR_NATIVE_QUESTION_CARD_TAG,+ MODEL_FOR_NATIVE_QUESTION_PARAMETER_SOURCE,+ MODEL_FOR_DASHBOARD_CARD,+ MODEL_FOR_DASHBOARD_PARAMETER_SOURCE,+];++const SEGMENT_NAMES = [+ SEGMENT_FOR_QUESTION_FILTER,+ SEGMENT_FOR_MODEL_FILTER,+ SEGMENT_FOR_SEGMENT_FILTER,+ SEGMENT_FOR_METRIC_FILTER,+];++const METRIC_NAMES = [+ METRIC_FOR_QUESTION_AGGREGATION,+ METRIC_FOR_MODEL_AGGREGATION,+ METRIC_FOR_METRIC_AGGREGATION,+ METRIC_FOR_DASHBOARD_CARD,+];++const SNIPPET_NAMES = [+ SNIPPET_FOR_NATIVE_QUESTION_CARD_TAG,+ SNIPPET_FOR_SNIPPET_TAG,+];++const ENTITY_NAMES = [+ ...TABLE_NAMES,+ ...MODEL_NAMES,+ ...SEGMENT_NAMES,+ ...METRIC_NAMES,+ ...SNIPPET_NAMES,+];++// The unreferenced list also contains inactive tables of the shared writable DB+// (tables dropped by other specs stay visible on purpose — see #77714), so the+// full list can exceed one page. Tests that need to see all of the entities+// created by this spec at once narrow the list down with this search term,+// which matches every entity name above except the table's.+const ENTITY_SEARCH_TERM = "for";+const SEARCHABLE_ENTITY_NAMES = [+ ...MODEL_NAMES,+ ...SEGMENT_NAMES,+ ...METRIC_NAMES,+ ...SNIPPET_NAMES,+];++// Entities that `setupEntities({ withReferences: true })` creates to reference+// the entities above. Nothing references them, so they are unreferenced.+// Dashboards are not in the unreferenced list.+const TABLE_REFERENCING_ENTITY_NAME = `${MANY_DATA_TYPES_TABLE_DISPLAY_NAME} -> Question`;+const SEARCHABLE_REFERENCING_ENTITY_NAMES = [+ `${MODEL_FOR_QUESTION_DATA_SOURCE} -> Question`,+ `${MODEL_FOR_MODEL_DATA_SOURCE} -> Model`,+ `${MODEL_FOR_METRIC_DATA_SOURCE} -> Metric`,+ `${MODEL_FOR_NATIVE_QUESTION_CARD_TAG} -> Question`,+ `${MODEL_FOR_NATIVE_QUESTION_PARAMETER_SOURCE} -> Question`,+ `${SEGMENT_FOR_QUESTION_FILTER} -> Question`,+ `${SEGMENT_FOR_MODEL_FILTER} -> Model`,+ `${SEGMENT_FOR_SEGMENT_FILTER} -> Segment`,+ `${SEGMENT_FOR_METRIC_FILTER} -> Metric`,+ `${METRIC_FOR_QUESTION_AGGREGATION} -> Question`,+ `${METRIC_FOR_MODEL_AGGREGATION} -> Model`,+ `${METRIC_FOR_METRIC_AGGREGATION} -> Metric`,+ `${SNIPPET_FOR_NATIVE_QUESTION_CARD_TAG} -> Question`,+ `${SNIPPET_FOR_SNIPPET_TAG} -> Snippet`,+];++const MODELS_SORTED_BY_NAME = [+ MODEL_FOR_DASHBOARD_CARD,+ MODEL_FOR_DASHBOARD_PARAMETER_SOURCE,+ MODEL_FOR_METRIC_DATA_SOURCE,+ MODEL_FOR_MODEL_DATA_SOURCE,+ MODEL_FOR_NATIVE_QUESTION_CARD_TAG,+ MODEL_FOR_NATIVE_QUESTION_PARAMETER_SOURCE,+ MODEL_FOR_QUESTION_DATA_SOURCE,+];++const MODELS_SORTED_BY_LOCATION = [+ MODEL_FOR_METRIC_DATA_SOURCE,+ MODEL_FOR_MODEL_DATA_SOURCE,+ MODEL_FOR_QUESTION_DATA_SOURCE,+ MODEL_FOR_NATIVE_QUESTION_CARD_TAG,+ MODEL_FOR_NATIVE_QUESTION_PARAMETER_SOURCE,+ MODEL_FOR_DASHBOARD_CARD,+ MODEL_FOR_DASHBOARD_PARAMETER_SOURCE,+];++describe(+ "scenarios > dependencies > dependency diagnostics",+ { viewportWidth: 1600, viewportHeight: 1400 },+ () => {+ beforeEach(() => {+ H.restore("postgres-writable");+ cy.signInAsAdmin();+ H.activateToken("pro-self-hosted");+ H.updateSetting("transforms-enabled", true);+ });++ afterEach(() => {+ H.expectNoBadSnowplowEvents();+ });++ describe("broken list", () => {+ beforeEach(() => {+ createContent();+ H.resetSnowplow();+ });++ afterEach(() => {+ dropTransformTable();+ });++ it("should list, search, sort, and filter broken dependencies and show the sidebar for broken dependents", () => {+ H.DependencyDiagnostics.visitBrokenDependencies();+ checkList({+ visibleEntities: BROKEN_DEPENDENCIES,+ hiddenEntities: BROKEN_DEPENDENTS,+ });++ cy.log("table dependents");+ H.DependencyDiagnostics.list()+ .findByText(TRANSFORM_TABLE_DISPLAY_NAME)+ .click();+ checkBrokenSidebar({+ title: TRANSFORM_TABLE_DISPLAY_NAME,+ transform: TABLE_TRANSFORM,+ missingColumns: ["score"],+ brokenDependents: BROKEN_TABLE_DEPENDENTS,+ });+ H.DependencyDiagnostics.Sidebar.brokenDependentsSection()+ .findByText(TABLE_BASED_QUESTION_BROKEN_FIELD)+ .should("not.exist");+ H.expectUnstructuredSnowplowEvent({+ event: "dependency_diagnostics_entity_selected",+ triggered_from: "broken",+ event_detail: "table",+ });++ cy.log("question dependents");+ H.DependencyDiagnostics.list().findByText(TABLE_BASED_QUESTION).click();+ checkBrokenSidebar({+ title: TABLE_BASED_QUESTION,+ missingColumns: ["PRICE", "TAX", "DISCOUNT"],+ brokenDependents: BROKEN_QUESTION_DEPENDENTS,+ });++ cy.log("model dependents");+ H.DependencyDiagnostics.list().findByText(TABLE_BASED_MODEL).click();+ checkBrokenSidebar({+ title: TABLE_BASED_MODEL,+ missingColumns: ["AMOUNT", "QUANTITY", "SUBTOTAL", "TOTAL"],+ brokenDependents: BROKEN_MODEL_DEPENDENTS,+ });++ cy.log("search");+ H.DependencyDiagnostics.searchInput().type(+ TRANSFORM_TABLE_DISPLAY_NAME,+ );+ checkList({+ visibleEntities: [TRANSFORM_TABLE_DISPLAY_NAME],+ hiddenEntities: [TABLE_BASED_QUESTION, TABLE_BASED_MODEL],+ });++ cy.log("sorting");+ H.DependencyDiagnostics.visitBrokenDependencies();+ H.DependencyDiagnostics.searchInput().type("test");++ cy.log("sorted by name by default");+ checkListSorting({+ visibleEntities: BROKEN_DEPENDENCIES_SORTED_BY_NAME,+ });++ cy.log("sorted by name ascending");+ sortList({ header: "Dependency", column: "name", direction: "asc" });+ checkListSorting({+ visibleEntities: BROKEN_DEPENDENCIES_SORTED_BY_NAME,+ });++ cy.log("sorted by name descending");+ sortList({ header: "Dependency", column: "name", direction: "desc" });+ checkListSorting({+ visibleEntities: [...BROKEN_DEPENDENCIES_SORTED_BY_NAME].reverse(),+ });++ cy.log("sorted by location ascending");+ sortList({ header: "Location", column: "location", direction: "asc" });+ checkListSorting({+ visibleEntities: BROKEN_DEPENDENCIES_SORTED_BY_LOCATION,+ });++ cy.log("sorted by location descending");+ sortList({ header: "Location", column: "location", direction: "desc" });+ checkListSorting({+ visibleEntities: [+ ...BROKEN_DEPENDENCIES_SORTED_BY_LOCATION,+ ].reverse(),+ });++ cy.log("sorted by dependents errors descending");+ sortList({+ header: "Problems",+ column: "dependents-errors",+ direction: "desc",+ });+ checkListSorting({+ visibleEntities: [+ ...BROKEN_DEPENDENTS_SORTED_BY_DEPENDENTS_ERRORS,+ ].reverse(),+ });++ cy.log("sorted by dependents errors ascending");+ sortList({+ header: "Problems",+ column: "dependents-errors",+ direction: "asc",+ });+ checkListSorting({+ visibleEntities: BROKEN_DEPENDENTS_SORTED_BY_DEPENDENTS_ERRORS,+ });++ cy.log("sorted by dependents with errors descending");+ sortList({+ header: "Broken dependents",+ column: "dependents-with-errors",+ direction: "desc",+ });+ checkListSorting({+ visibleEntities: [+ ...BROKEN_DEPENDENTS_SORTED_BY_DEPENDENTS_WITH_ERRORS,+ ].reverse(),+ });++ cy.log("sorted by dependents with errors ascending");+ sortList({+ header: "Broken dependents",+ column: "dependents-with-errors",+ direction: "asc",+ });+ checkListSorting({+ visibleEntities: BROKEN_DEPENDENTS_SORTED_BY_DEPENDENTS_WITH_ERRORS,+ });+ waitForSavedListParams({+ mode: "broken",+ isSaved: (params) =>+ params.sort_column === "dependents-with-errors" &&+ params.sort_direction === "asc",+ });++ cy.log("sorting persisted after page reload");+ H.DependencyDiagnostics.visitBrokenDependencies();+ checkListUrlSort({+ column: "dependents-with-errors",+ direction: "asc",+ });+ H.DependencyDiagnostics.searchInput().type("test");+ checkListSorting({+ visibleEntities: BROKEN_DEPENDENTS_SORTED_BY_DEPENDENTS_WITH_ERRORS,+ });++ cy.log("filtering");+ H.DependencyDiagnostics.filterButton().click();+ H.popover().within(() => {+ cy.findByText("Table").click();+ cy.findByText("Question").click();+ cy.findByText("Model").click();+ });++ cy.log("only tables");+ H.popover().findByText("Table").click();+ checkList({+ visibleEntities: BROKEN_TABLE_DEPENDENCIES,+ hiddenEntities: [+ ...BROKEN_QUESTION_DEPENDENCIES,+ ...BROKEN_MODEL_DEPENDENCIES,+ ],+ });++ cy.log("only questions");+ H.popover().within(() => {+ cy.findByText("Table").click();+ cy.findByText("Question").click();+ });+ checkList({+ visibleEntities: BROKEN_QUESTION_DEPENDENCIES,+ hiddenEntities: [+ ...BROKEN_TABLE_DEPENDENCIES,+ ...BROKEN_MODEL_DEPENDENCIES,+ ],+ });++ cy.log("only models");+ H.popover().within(() => {+ cy.findByText("Question").click();+ cy.findByText("Model").click();+ });+ checkList({+ visibleEntities: BROKEN_MODEL_DEPENDENCIES,+ hiddenEntities: [+ ...BROKEN_TABLE_DEPENDENCIES,+ ...BROKEN_QUESTION_DEPENDENCIES,+ ],+ });++ cy.log("all types");+ H.popover().within(() => {+ cy.findByText("Table").click();+ cy.findByText("Question").click();+ });+ checkList({ visibleEntities: BROKEN_DEPENDENCIES });++ cy.log("without items in personal collections");+ H.popover().findByText("Include items in personal collections").click();+ checkList({+ visibleEntities: [+ ...BROKEN_TABLE_DEPENDENCIES,+ ...BROKEN_MODEL_DEPENDENCIES,+ ],+ hiddenEntities: BROKEN_QUESTION_DEPENDENCIES,+ });+ waitForSavedListParams({+ mode: "broken",+ isSaved: (params) => params.include_personal_collections === false,+ });++ cy.log("filters persisted after page reload");+ H.DependencyDiagnostics.visitBrokenDependencies();+ checkList({+ visibleEntities: [+ ...BROKEN_TABLE_DEPENDENCIES,+ ...BROKEN_MODEL_DEPENDENCIES,+ ],+ hiddenEntities: BROKEN_QUESTION_DEPENDENCIES,+ });+ H.DependencyDiagnostics.filterButton().click();+ H.popover().within(() => {+ cy.findByRole("checkbox", { name: "Table" }).should("be.checked");+ cy.findByRole("checkbox", { name: "Question" }).should("be.checked");+ cy.findByRole("checkbox", { name: "Model" }).should("be.checked");+ cy.findByRole("checkbox", {+ name: "Include items in personal collections",+ }).should("not.be.checked");+ });++ H.DependencyDiagnostics.filterButton().click();++ cy.log("snowplow event when dependency graph link is clicked");+ H.DependencyDiagnostics.list().findByText(TABLE_BASED_MODEL).click();+ cy.findByRole("link", { name: "View in dependency graph" }).click();+ H.expectUnstructuredSnowplowEvent({+ event: "dependency_entity_selected",+ triggered_from: "diagnostics-broken-list",+ event_detail: "card",+ });+ });+ });++ describe("unreferenced list", () => {+ beforeEach(() => {+ H.resetTestTable({+ type: "postgres",+ table: MANY_DATA_TYPES_TABLE_NAME,+ });+ H.resyncDatabase({+ dbId: WRITABLE_DB_ID,+ tableName: MANY_DATA_TYPES_TABLE_NAME,+ });+ H.resetSnowplow();+ });++ describe("analysis", () => {+ it("should not show referenced entities", () => {+ setupEntities({ withReferences: true });+ H.waitForBackfillComplete();+ waitForSearchedUnreferencedAnalysis({+ query: ENTITY_SEARCH_TERM,+ expectedNames: SEARCHABLE_REFERENCING_ENTITY_NAMES,+ });+ waitForSearchedUnreferencedAnalysis({+ query: MANY_DATA_TYPES_TABLE_DISPLAY_NAME,+ expectedNames: [TABLE_REFERENCING_ENTITY_NAME],+ });+ H.DependencyDiagnostics.visitUnreferencedEntities();++ H.DependencyDiagnostics.searchInput().type(ENTITY_SEARCH_TERM);+ checkList({+ visibleEntities: SEARCHABLE_REFERENCING_ENTITY_NAMES,+ hiddenEntities: SEARCHABLE_ENTITY_NAMES,+ });++ H.DependencyDiagnostics.searchInput()+ .clear()+ .type(MANY_DATA_TYPES_TABLE_DISPLAY_NAME);+ checkList({+ visibleEntities: [TABLE_REFERENCING_ENTITY_NAME],+ hiddenEntities: [MANY_DATA_TYPES_TABLE_DISPLAY_NAME],+ });+ });+ });++ it("should show the sidebar, sort, search, and filter unreferenced entities and persist list changes after page reload", () => {+ setupEntities();+ waitForUnreferencedAnalysis();+ H.DependencyDiagnostics.visitUnreferencedEntities();++ cy.log("sidebar");+ H.DependencyDiagnostics.list()+ .findByText(MANY_DATA_TYPES_TABLE_DISPLAY_NAME)+ .click();+ H.expectUnstructuredSnowplowEvent({+ event: "dependency_diagnostics_entity_selected",+ triggered_from: "unreferenced",+ event_detail: "table",+ });+ checkUnreferencedSidebar({+ title: MANY_DATA_TYPES_TABLE_DISPLAY_NAME,+ location: DATABASE_NAME,+ description: TABLE_DESCRIPTION,+ owner: `${USERS.admin.first_name} ${USERS.admin.last_name}`,+ fields: ["ID", "UUID"],+ });++ H.DependencyDiagnostics.searchInput().type(ENTITY_SEARCH_TERM);+ H.DependencyDiagnostics.list()+ .findByText(MODEL_FOR_QUESTION_DATA_SOURCE)+ .click();+ checkUnreferencedSidebar({+ title: MODEL_FOR_QUESTION_DATA_SOURCE,+ location: "Our analytics",+ createdBy: "Bobby Tables",+ fields: ["User ID"],+ });++ H.DependencyDiagnostics.list()+ .findByText(MODEL_FOR_MODEL_DATA_SOURCE)+ .click();+ checkUnreferencedSidebar({+ title: MODEL_FOR_MODEL_DATA_SOURCE,+ location: "First collection",+ createdBy: "Bobby Tables",+ });++ H.DependencyDiagnostics.list()+ .findByText(SEGMENT_FOR_QUESTION_FILTER)+ .click();+ checkUnreferencedSidebar({+ title: SEGMENT_FOR_QUESTION_FILTER,+ location: "Orders",+ createdBy: "Bobby Tables",+ });++ H.DependencyDiagnostics.list()+ .findByText(METRIC_FOR_QUESTION_AGGREGATION)+ .click();+ checkUnreferencedSidebar({+ title: METRIC_FOR_QUESTION_AGGREGATION,+ location: "Our analytics",+ createdBy: "Bobby Tables",+ });++ H.DependencyDiagnostics.list()+ .findByText(METRIC_FOR_MODEL_AGGREGATION)+ .click();+ checkUnreferencedSidebar({+ title: METRIC_FOR_MODEL_AGGREGATION,+ location: "First collection",+ createdBy: "Bobby Tables",+ });++ H.DependencyDiagnostics.list()+ .findByText(SNIPPET_FOR_NATIVE_QUESTION_CARD_TAG)+ .click();+ checkUnreferencedSidebar({+ title: SNIPPET_FOR_NATIVE_QUESTION_CARD_TAG,+ location: "SQL snippets",+ createdBy: "Bobby Tables",+ });++ cy.log("sorting");+ H.DependencyDiagnostics.visitUnreferencedEntities();+ H.DependencyDiagnostics.searchInput().type("Model for");++ cy.log("sorted by name by default");+ checkListSorting({+ visibleEntities: MODELS_SORTED_BY_NAME,+ });++ cy.log("sorted by location ascending");+ H.DependencyDiagnostics.list().findByText("Location").click();+ checkListSorting({+ visibleEntities: MODELS_SORTED_BY_LOCATION,+ });++ cy.log("sorted by location descending");+ H.DependencyDiagnostics.list().findByText("Location").click();+ checkListSorting({+ visibleEntities: [...MODELS_SORTED_BY_LOCATION].reverse(),+ });++ cy.log("sorted by name ascending");+ H.DependencyDiagnostics.list().findByText("Name").click();+ checkListSorting({+ visibleEntities: MODELS_SORTED_BY_NAME,+ });++ cy.log("sorted by name descending");+ H.DependencyDiagnostics.list().findByText("Name").click();+ checkListSorting({+ visibleEntities: [...MODELS_SORTED_BY_NAME].reverse(),+ });+ waitForSavedListParams({+ mode: "unreferenced",+ isSaved: (params) =>+ params.sort_column === "name" && params.sort_direction === "desc",+ });++ cy.log("sorting persisted after page reload");+ H.DependencyDiagnostics.visitUnreferencedEntities();+ H.DependencyDiagnostics.searchInput().type("Model for");+ checkListSorting({+ visibleEntities: [...MODELS_SORTED_BY_NAME].reverse(),+ });++ cy.log("search with type filters");+ H.DependencyDiagnostics.searchInput().clear().type("tag");+ checkList({+ visibleEntities: [+ MODEL_FOR_NATIVE_QUESTION_CARD_TAG,+ SNIPPET_FOR_SNIPPET_TAG,+ ],+ hiddenEntities: [MODEL_FOR_QUESTION_DATA_SOURCE],+ });++ H.DependencyDiagnostics.filterButton().click();+ H.popover().findByText("Snippet").click();+ checkList({+ visibleEntities: [MODEL_FOR_NATIVE_QUESTION_CARD_TAG],+ hiddenEntities: [SNIPPET_FOR_SNIPPET_TAG],+ });+ waitForSavedListParams({+ mode: "unreferenced",+ isSaved: (params) =>+ params.group_types != null &&+ !params.group_types.includes("snippet"),+ });++ cy.log("filters persisted from the search step");+ H.DependencyDiagnostics.visitUnreferencedEntities();+ H.DependencyDiagnostics.searchInput().type(ENTITY_SEARCH_TERM);+ checkList({+ visibleEntities: [...MODEL_NAMES, ...SEGMENT_NAMES, ...METRIC_NAMES],+ hiddenEntities: SNIPPET_NAMES,+ });++ cy.log("type");+ H.DependencyDiagnostics.filterButton().click();+ H.popover().findByText("Snippet").click();+ checkList({ visibleEntities: SEARCHABLE_ENTITY_NAMES });++ H.popover().findByText("Model").click();+ checkList({ hiddenEntities: MODEL_NAMES });++ H.popover().findByText("Segment").click();+ checkList({+ hiddenEntities: [+ MODEL_FOR_NATIVE_QUESTION_CARD_TAG,+ SEGMENT_FOR_QUESTION_FILTER,+ ],+ });++ H.popover().findByText("Metric").click();+ checkList({+ hiddenEntities: [+ MODEL_FOR_NATIVE_QUESTION_CARD_TAG,+ SEGMENT_FOR_QUESTION_FILTER,+ METRIC_FOR_QUESTION_AGGREGATION,+ ],+ });++ H.popover().findByText("Model").click();+ checkList({+ visibleEntities: [+ MODEL_FOR_NATIVE_QUESTION_CARD_TAG,+ MODEL_FOR_MODEL_DATA_SOURCE,+ MODEL_FOR_METRIC_DATA_SOURCE,+ SNIPPET_FOR_NATIVE_QUESTION_CARD_TAG,+ ],+ });++ cy.log("location");+ H.popover().findByText("Include items in personal collections").click();+ checkList({+ visibleEntities: [+ MODEL_FOR_MODEL_DATA_SOURCE,+ SNIPPET_FOR_NATIVE_QUESTION_CARD_TAG,+ ],+ hiddenEntities: [MODEL_FOR_METRIC_DATA_SOURCE],+ });++ H.popover().findByText("Include items in personal collections").click();+ checkList({+ visibleEntities: [+ MODEL_FOR_MODEL_DATA_SOURCE,+ MODEL_FOR_METRIC_DATA_SOURCE,+ SNIPPET_FOR_NATIVE_QUESTION_CARD_TAG,+ ],+ });+ waitForSavedListParams({+ mode: "unreferenced",+ isSaved: (params) =>+ params.include_personal_collections !== false &&+ params.group_types != null &&+ params.group_types.includes("model") &&+ !params.group_types.includes("segment") &&+ !params.group_types.includes("metric"),+ });++ cy.log("filters persisted after page reload");+ H.DependencyDiagnostics.visitUnreferencedEntities();+ H.DependencyDiagnostics.filterButton().click();+ H.popover().within(() => {+ cy.findByRole("checkbox", { name: "Model" }).should("be.checked");+ cy.findByRole("checkbox", { name: "Segment" }).should(+ "not.be.checked",+ );+ cy.findByRole("checkbox", { name: "Metric" }).should(+ "not.be.checked",+ );+ });+ H.DependencyDiagnostics.searchInput().type(ENTITY_SEARCH_TERM);+ checkList({+ visibleEntities: [MODEL_FOR_NATIVE_QUESTION_CARD_TAG],+ hiddenEntities: [...SEGMENT_NAMES, ...METRIC_NAMES],+ });++ cy.log("snowplow event when dependency graph link is clicked");+ H.DependencyDiagnostics.list()+ .findByText(SNIPPET_FOR_NATIVE_QUESTION_CARD_TAG)+ .click();+ cy.findByRole("link", { name: "View in dependency graph" }).click();+ H.expectUnstructuredSnowplowEvent({+ event: "dependency_entity_selected",+ triggered_from: "diagnostics-unreferenced-list",+ event_detail: "snippet",+ });+ });+ });+ },+);++function createContent() {+ createTransform();+ createTableContent();+ createQuestionContent();+ createModelContent();+ breakTransform();+ waitForBreakingDependencies();+}++function dropTransformTable() {+ cy.get<TransformId>("@transformId").then((transformId) => {+ cy.request("DELETE", `/api/transform/${transformId}/table`);+ });+}++function createTransform() {+ H.createTransform(+ {+ name: TABLE_TRANSFORM,+ source: {+ type: "query",+ query: {+ type: "native",+ database: WRITABLE_DB_ID,+ native: {+ query: "SELECT 1 as score, 'active' as status",+ },+ },+ },+ target: {+ type: "table",+ database: WRITABLE_DB_ID,+ schema: "public",+ name: TRANSFORM_TABLE_NAME,+ },+ },+ { wrapId: true },+ );+ cy.get<TransformId>("@transformId").then((transformId) => {+ H.runTransform(transformId);+ H.resyncDatabase({ dbId: WRITABLE_DB_ID, tableName: TRANSFORM_TABLE_NAME });+ H.waitForTransformRuns(+ (runs) =>+ runs.length === 1 && runs.every((run) => run.status === "succeeded"),+ );+ });+}++function breakTransform() {+ cy.get<TransformId>("@transformId").then((transformId) => {+ cy.request("PUT", `/api/transform/${transformId}`, {+ source: {+ type: "query",+ query: {+ type: "native",+ database: WRITABLE_DB_ID,+ native: {+ query: "SELECT 1 as score_new, 'active' as status_new",+ },+ },+ },+ });+ H.runTransform(transformId);+ H.waitForTransformRuns(+ (runs) =>+ runs.length === 2 && runs.every((run) => run.status === "succeeded"),+ );+ });+}++function createTableContent() {+ H.getTableId({ name: TRANSFORM_TABLE_NAME }).then((tableId) => {+ cy.wrap(tableId).as("tableId");++ H.getFieldId({ tableId, name: "score" }).then((scoreFieldId) => {+ H.getFieldId({ tableId, name: "status" }).then((statusFieldId) => {+ H.createQuestion({+ name: TABLE_BASED_QUESTION_BROKEN_FIELD,+ database: WRITABLE_DB_ID,+ query: {+ "source-table": tableId,+ fields: [["field", statusFieldId, null]],+ },+ });++ H.createQuestion({+ name: TABLE_BASED_QUESTION_BROKEN_EXPRESSION,+ database: WRITABLE_DB_ID,+ query: {+ "source-table": tableId,+ expressions: {+ Expression: ["+", ["field", scoreFieldId, null], 0],+ },+ },+ });++ H.createQuestion({+ name: TABLE_BASED_QUESTION_BROKEN_FILTER,+ database: WRITABLE_DB_ID,+ query: {+ "source-table": tableId,+ filter: ["=", ["field", scoreFieldId, null], 0],+ },+ });++ H.createQuestion({+ name: TABLE_BASED_QUESTION_BROKEN_BREAKOUT,+ database: WRITABLE_DB_ID,+ query: {+ "source-table": tableId,+ breakout: [["field", scoreFieldId, null]],+ },+ });++ H.createQuestion({+ name: TABLE_BASED_QUESTION_BROKEN_AGGREGATION,+ database: WRITABLE_DB_ID,+ query: {+ "source-table": tableId,+ aggregation: [["avg", ["field", scoreFieldId, null]]],+ },+ });++ H.createQuestion({+ name: TABLE_BASED_QUESTION_BROKEN_EXPLICIT_JOIN,+ database: WRITABLE_DB_ID,+ query: {+ "source-table": tableId,+ joins: [+ {+ "source-table": tableId,+ alias: TRANSFORM_TABLE_DISPLAY_NAME,+ condition: [+ "=",+ ["field", statusFieldId, null],+ [+ "field",+ statusFieldId,+ { "join-alias": TRANSFORM_TABLE_DISPLAY_NAME },+ ],+ ],+ },+ ],+ aggregation: [+ [+ "max",+ [+ "field",+ scoreFieldId,+ { "join-alias": TRANSFORM_TABLE_DISPLAY_NAME },+ ],+ ],+ ],+ },+ });+ });+ });+ });+}++function createQuestionContent() {+ H.getTableId({ name: TRANSFORM_TABLE_NAME }).then((tableId) => {+ H.createQuestion({+ name: TABLE_BASED_QUESTION,+ database: WRITABLE_DB_ID,+ query: {+ "source-table": tableId,+ },+ collection_id: ADMIN_PERSONAL_COLLECTION_ID,+ }).then(({ body: card }) => {+ cy.wrap(card.id).as("questionId");+ H.createQuestion({+ name: QUESTION_BASED_QUESTION_BROKEN_FILTER,+ query: {+ "source-table": `card__${card.id}`,+ filter: [+ "and",+ [">", ["field", "PRICE", { "base-type": "type/Float" }], 10],+ ["=", ["field", "TAX", { "base-type": "type/Float" }], 0],+ ["=", ["field", "DISCOUNT", { "base-type": "type/Float" }], 0],+ ],+ },+ });+ });+ });+}++function createModelContent() {+ H.getTableId({ name: TRANSFORM_TABLE_NAME }).then((tableId) => {+ H.createQuestion({+ name: TABLE_BASED_MODEL,+ type: "model",+ database: WRITABLE_DB_ID,+ query: {+ "source-table": tableId,+ },+ }).then(({ body: card }) => {+ cy.wrap(card.id).as("modelId");+ H.createQuestion({+ name: MODEL_BASED_QUESTION_BROKEN_FILTER,+ query: {+ "source-table": `card__${card.id}`,+ filter: [+ "=",+ ["field", "AMOUNT", { "base-type": "type/Integer" }],+ 0,+ ],+ },+ });+ H.createQuestion({+ name: MODEL_BASED_MODEL_BROKEN_AGGREGATION,+ type: "model",+ query: {+ "source-table": `card__${card.id}`,+ filter: [+ "and",+ ["=", ["field", "QUANTITY", { "base-type": "type/Integer" }], 0],+ ["=", ["field", "SUBTOTAL", { "base-type": "type/Integer" }], 0],+ ["=", ["field", "TOTAL", { "base-type": "type/Integer" }], 0],+ ],+ aggregation: [+ ["distinct", ["field", "AMOUNT", { "base-type": "type/Integer" }]],+ ],+ },+ });+ });+ });+}++function waitForBreakingDependencies() {+ // The instance already has unrelated (Usage Analytics) breaking dependencies,+ // so a bare count check can pass before the test's own entities are analyzed.+ // Wait until every expected entity is present by name instead.+ H.waitForBreakingDependencies((nodes) =>+ BROKEN_DEPENDENCIES.every((name) =>+ nodes.some((node) => getNodeName(node) === name),+ ),+ );+}++function checkBrokenSidebar({+ title,+ transform,+ missingColumns,+ brokenDependents,+}: {+ title: string;+ transform?: string;+ missingColumns?: string[];+ brokenDependents?: string[];+}) {+ H.DependencyDiagnostics.sidebar().within(() => {+ H.DependencyDiagnostics.Sidebar.header()+ .findByText(title)+ .should("be.visible");+ if (transform) {+ H.DependencyDiagnostics.Sidebar.infoSection()+ .findByText(transform)+ .should("exist");+ }+ if (missingColumns) {+ H.DependencyDiagnostics.Sidebar.missingColumnsSection().within(() => {+ missingColumns.forEach((column) => {+ cy.findByText(column).should("exist");+ });+ });+ }+ if (brokenDependents) {+ H.DependencyDiagnostics.Sidebar.brokenDependentsSection().within(() => {+ brokenDependents.forEach((dependent) => {+ cy.findByText(dependent).should("exist");+ });+ });+ }+ });+}++function sortList({+ header,+ column,+ direction,+}: {+ header: string;+ column: DependencySortColumn;+ direction: SortDirection;+}) {+ H.DependencyDiagnostics.list().findByText(header).click();+ checkListUrlSort({ column, direction });+}++function checkListUrlSort({+ column,+ direction,+}: {+ column: DependencySortColumn;+ direction: SortDirection;+}) {+ cy.location("search")+ .should("include", `sort-column=${column}`)+ .and("include", `sort-direction=${direction}`);+}++function setupEntities({+ withReferences = false,+}: { withReferences?: boolean } = {}) {+ setupTableContent({ withReferences });+ setupModelContent({ withReferences });+ setupSegmentContent({ withReferences });+ setupMetricContent({ withReferences });+ setupSnippetContent({ withReferences });+}++function setupTableContent({+ withReferences = false,+}: {+ withReferences?: boolean;+}) {+ H.getTableId({ name: MANY_DATA_TYPES_TABLE_NAME }).then((tableId) => {+ cy.request("PUT", `/api/table/${tableId}`, {+ display_name: MANY_DATA_TYPES_TABLE_DISPLAY_NAME,+ description: TABLE_DESCRIPTION,+ owner_user_id: ADMIN_USER_ID,+ }).then(() => {+ if (withReferences) {+ createQuestionWithTableDataSource({+ name: `${MANY_DATA_TYPES_TABLE_DISPLAY_NAME} -> Question`,+ tableId,+ });+ }+ });+ });+}++function setupModelContent({+ withReferences = false,+}: {+ withReferences?: boolean;+}) {+ createModelWithTableDataSource({+ name: MODEL_FOR_QUESTION_DATA_SOURCE,+ tableId: ORDERS_ID,+ }).then(({ body: model }) => {+ if (withReferences) {+ createQuestionWithModelDataSource({+ name: `${MODEL_FOR_QUESTION_DATA_SOURCE} -> Question`,+ modelId: model.id,+ });+ }+ });++ createModelWithTableDataSource({+ name: MODEL_FOR_MODEL_DATA_SOURCE,+ tableId: ORDERS_ID,+ collectionId: FIRST_COLLECTION_ID,+ }).then(({ body: model }) => {+ if (withReferences) {+ createModelWithModelDataSource({+ name: `${MODEL_FOR_MODEL_DATA_SOURCE} -> Model`,+ modelId: model.id,+ });+ }+ });++ createModelWithTableDataSource({+ name: MODEL_FOR_METRIC_DATA_SOURCE,+ tableId: ORDERS_ID,+ collectionId: ADMIN_PERSONAL_COLLECTION_ID,+ }).then(({ body: model }) => {+ if (withReferences) {+ createMetricWithModelDataSource({+ name: `${MODEL_FOR_METRIC_DATA_SOURCE} -> Metric`,+ modelId: model.id,+ });+ }+ });++ createModelWithTableDataSource({+ name: MODEL_FOR_NATIVE_QUESTION_CARD_TAG,+ tableId: ORDERS_ID,+ }).then(({ body: model }) => {+ if (withReferences) {+ createNativeQuestionWithCardTag({+ name: `${MODEL_FOR_NATIVE_QUESTION_CARD_TAG} -> Question`,+ cardId: model.id,+ });+ }+ });++ createModelWithTableDataSource({+ name: MODEL_FOR_NATIVE_QUESTION_PARAMETER_SOURCE,+ tableId: PRODUCTS_ID,+ }).then(({ body: model }) => {+ if (withReferences) {+ createNativeQuestionWithParameterWithCardSource({+ name: `${MODEL_FOR_NATIVE_QUESTION_PARAMETER_SOURCE} -> Question`,+ tableName: "PRODUCTS",+ tableFieldId: PRODUCTS.CATEGORY,+ cardId: model.id,+ cardFieldName: "CATEGORY",+ });+ }+ });++ createModelWithTableDataSource({+ name: MODEL_FOR_DASHBOARD_CARD,+ tableId: ORDERS_ID,+ }).then(({ body: model }) => {+ if (withReferences) {+ createDashboardWithCard({+ name: `${MODEL_FOR_DASHBOARD_CARD} -> Dashboard Card`,+ cardId: model.id,+ });+ }+ });++ createModelWithTableDataSource({+ name: MODEL_FOR_DASHBOARD_PARAMETER_SOURCE,+ tableId: PRODUCTS_ID,+ }).then(({ body: model }) => {+ if (withReferences) {+ createDashboardWithParameterWithCardSource({+ name: `${MODEL_FOR_DASHBOARD_PARAMETER_SOURCE} -> Dashboard`,+ cardId: model.id,+ cardFieldName: "CATEGORY",+ });+ }+ });+}++function setupSegmentContent({+ withReferences = false,+}: {+ withReferences?: boolean;+}) {+ createSegmentWithTableDataSource({+ name: SEGMENT_FOR_QUESTION_FILTER,+ tableId: ORDERS_ID,+ }).then(({ body: segment }) => {+ if (withReferences) {+ createQuestionWithSegmentClause({+ name: `${SEGMENT_FOR_QUESTION_FILTER} -> Question`,+ tableId: ORDERS_ID,+ segmentId: segment.id,+ });+ }+ });++ createSegmentWithTableDataSource({+ name: SEGMENT_FOR_MODEL_FILTER,+ tableId: ORDERS_ID,+ }).then(({ body: segment }) => {+ if (withReferences) {+ createModelWithSegmentClause({+ name: `${SEGMENT_FOR_MODEL_FILTER} -> Model`,+ tableId: ORDERS_ID,+ segmentId: segment.id,+ });+ }+ });++ createSegmentWithTableDataSource({+ name: SEGMENT_FOR_SEGMENT_FILTER,+ tableId: ORDERS_ID,+ }).then(({ body: segment }) => {+ if (withReferences) {+ createSegmentWithSegmentClause({+ name: `${SEGMENT_FOR_SEGMENT_FILTER} -> Segment`,+ tableId: ORDERS_ID,+ segmentId: segment.id,+ });+ }+ });++ createSegmentWithTableDataSource({+ name: SEGMENT_FOR_METRIC_FILTER,+ tableId: ORDERS_ID,+ }).then(({ body: segment }) => {+ if (withReferences) {+ createMetricWithSegmentClause({+ name: `${SEGMENT_FOR_METRIC_FILTER} -> Metric`,+ tableId: ORDERS_ID,+ segmentId: segment.id,+ });+ }+ });+}++function setupMetricContent({+ withReferences = false,+}: {+ withReferences?: boolean;+}) {+ createMetricWithTableDataSource({+ name: METRIC_FOR_QUESTION_AGGREGATION,+ tableId: ORDERS_ID,+ }).then(({ body: metric }) => {+ if (withReferences) {+ createQuestionWithMetricClause({+ name: `${METRIC_FOR_QUESTION_AGGREGATION} -> Question`,+ tableId: ORDERS_ID,+ metricId: metric.id,+ });+ }+ });++ createMetricWithTableDataSource({+ name: METRIC_FOR_MODEL_AGGREGATION,+ tableId: ORDERS_ID,+ collectionId: FIRST_COLLECTION_ID,+ }).then(({ body: metric }) => {+ if (withReferences) {+ createModelWithMetricClause({+ name: `${METRIC_FOR_MODEL_AGGREGATION} -> Model`,+ tableId: ORDERS_ID,+ metricId: metric.id,+ });+ }+ });++ createMetricWithTableDataSource({+ name: METRIC_FOR_METRIC_AGGREGATION,+ tableId: ORDERS_ID,+ }).then(({ body: metric }) => {+ if (withReferences) {+ createMetricWithMetricClause({+ name: `${METRIC_FOR_METRIC_AGGREGATION} -> Metric`,+ tableId: ORDERS_ID,+ metricId: metric.id,+ });+ }+ });++ createMetricWithTableDataSource({+ name: METRIC_FOR_DASHBOARD_CARD,+ tableId: ORDERS_ID,+ }).then(({ body: metric }) => {+ if (withReferences) {+ createDashboardWithCard({+ name: `${METRIC_FOR_DASHBOARD_CARD} -> Dashboard Card`,+ cardId: metric.id,+ });+ }+ });+}++function setupSnippetContent({+ withReferences = false,+}: {+ withReferences?: boolean;+}) {+ createSnippetWithBasicFilter({+ name: SNIPPET_FOR_NATIVE_QUESTION_CARD_TAG,+ }).then(({ body: snippet }) => {+ if (withReferences) {+ createNativeQuestionWithSnippetTag({+ name: `${SNIPPET_FOR_NATIVE_QUESTION_CARD_TAG} -> Question`,+ tableName: "ORDERS",+ snippetId: snippet.id,+ snippetName: snippet.name,+ });+ }+ });++ createSnippetWithBasicFilter({ name: SNIPPET_FOR_SNIPPET_TAG }).then(+ ({ body: snippet }) => {+ if (withReferences) {+ createSnippetWithSnippetTag({+ name: `${SNIPPET_FOR_SNIPPET_TAG} -> Snippet`,+ snippetName: snippet.name,+ });+ }+ },+ );+}++function createQuestionWithModelDataSource({+ name,+ modelId,+}: {+ name: string;+ modelId: CardId;+}) {+ return H.createQuestion({+ name,+ type: "question",+ query: {+ "source-table": `card__${modelId}`,+ },+ });+}++function createQuestionWithTableDataSource({+ name,+ tableId,+}: {+ name: string;+ tableId: TableId;+}) {+ return H.createQuestion({+ name,+ type: "question",+ query: {+ "source-table": tableId,+ },+ });+}++function createQuestionWithSegmentClause({+ name,+ tableId,+ segmentId,+}: {+ name: string;+ tableId: TableId;+ segmentId: SegmentId;+}) {+ return H.createQuestion({+ name,+ type: "question",+ query: {+ "source-table": tableId,+ filter: ["segment", segmentId],+ },+ });+}++function createQuestionWithMetricClause({+ name,+ tableId,+ metricId,+}: {+ name: string;+ tableId: TableId;+ metricId: CardId;+}) {+ return H.createQuestion({+ name,+ type: "question",+ query: {+ "source-table": tableId,+ aggregation: [["metric", metricId]],+ },+ });+}++function createNativeQuestionWithCardTag({+ name,+ cardId,+}: {+ name: string;+ cardId: CardId;+}) {+ const tagName = `#${cardId}`;++ return H.createNativeQuestion({+ name,+ type: "question",+ native: {+ query: `select * from {{${tagName}}}`,+ "template-tags": {+ [tagName]: {+ id: "10422a0f-292d-10a3-fd90-407cc9e3e20e",+ type: "card",+ name: tagName,+ "display-name": tagName,+ "card-id": cardId,+ },+ },+ },+ });+}++function createNativeQuestionWithParameterWithCardSource({+ name,+ tableName,+ tableFieldId,+ cardId,+ cardFieldName,+}: {+ name: string;+ tableName: string;+ tableFieldId: FieldId;+ cardId: CardId;+ cardFieldName: string;+}) {+ return H.createNativeQuestion({+ name,+ native: {+ query: `select * from ${tableName} where {{filter}}`,+ "template-tags": {+ filter: {+ id: "10422a0f-292d-10a3-fd90-407cc9e3e20e",+ type: "dimension",+ name: "filter",+ "display-name": "Filter",+ dimension: ["field", tableFieldId, null],+ "widget-type": "string/=",+ },+ },+ },+ parameters: [+ createMockParameter({+ id: "10422a0f-292d-10a3-fd90-407cc9e3e20e",+ name: "Filter",+ slug: "filter",+ type: "string/=",+ target: ["dimension", ["template-tag", "filter"]],+ values_source_type: "card",+ values_source_config: {+ card_id: cardId,+ value_field: ["field", cardFieldName, { "base-type": "type/Text" }],+ },+ }),+ ],+ });+}++function createNativeQuestionWithSnippetTag({+ name,+ tableName,+ snippetId,+ snippetName,+}: {+ name: string;+ tableName: string;+ snippetId: NativeQuerySnippetId;+ snippetName: string;+}) {+ const tagName = `snippet: ${snippetName}`;++ return H.createNativeQuestion({+ name,+ type: "question",+ native: {+ query: `select * from ${tableName} where {{${tagName}}}`,+ "template-tags": {+ [tagName]: {+ id: "10422a0f-292d-10a3-fd90-407cc9e3e20e",+ type: "snippet",+ name: tagName,+ "display-name": snippetName,+ "snippet-id": snippetId,+ "snippet-name": snippetName,+ },+ },+ },+ });+}++function createModelWithTableDataSource({+ name,+ tableId,+ collectionId,+}: {+ name: string;+ tableId: TableId;+ collectionId?: CollectionId;+}) {+ return H.createQuestion({+ name,+ type: "model",+ query: {+ "source-table": tableId,+ },+ collection_id: collectionId,+ });+}++function createModelWithModelDataSource({+ name,+ modelId,+}: {+ name: string;+ modelId: CardId;+}) {+ return H.createQuestion({+ name,+ type: "model",+ query: {+ "source-table": `card__${modelId}`,+ },+ });+}++function createModelWithSegmentClause({+ name,+ tableId,+ segmentId,+}: {+ name: string;+ tableId: TableId;+ segmentId: SegmentId;+}) {+ return H.createQuestion({+ name,+ type: "model",+ query: {+ "source-table": tableId,+ filter: ["segment", segmentId],+ },+ });+}++function createModelWithMetricClause({+ name,+ tableId,+ metricId,+}: {+ name: string;+ tableId: TableId;+ metricId: CardId;+}) {+ return H.createQuestion({+ name,+ type: "model",+ query: {+ "source-table": tableId,+ aggregation: [["metric", metricId]],+ },+ });+}++function createSegmentWithTableDataSource({+ name,+ tableId,+}: {+ name: string;+ tableId: TableId;+}) {+ return H.createSegment({+ name,+ definition: {+ database: SAMPLE_DB_ID,+ type: "query",+ query: {+ "source-table": tableId,+ filter: ["=", "A", "A"],+ },+ },+ });+}++function createSegmentWithSegmentClause({+ name,+ tableId,+ segmentId,+}: {+ name: string;+ tableId: TableId;+ segmentId: SegmentId;+}) {+ return H.createSegment({+ name,+ definition: {+ database: SAMPLE_DB_ID,+ type: "query",+ query: {+ "source-table": tableId,+ filter: ["segment", segmentId],+ },+ },+ });+}++function createMetricWithTableDataSource({+ name,+ tableId,+ collectionId,+}: {+ name: string;+ tableId: TableId;+ collectionId?: CollectionId;+}) {+ return H.createQuestion({+ name,+ type: "metric",+ query: {+ "source-table": tableId,+ aggregation: [["count"]],+ },+ collection_id: collectionId,+ });+}++function createMetricWithModelDataSource({+ name,+ modelId,+}: {+ name: string;+ modelId: CardId;+}) {+ return H.createQuestion({+ name,+ type: "metric",+ query: {+ "source-table": `card__${modelId}`,+ aggregation: [["count"]],+ },+ });+}++function createMetricWithSegmentClause({+ name,+ tableId,+ segmentId,+}: {+ name: string;+ tableId: TableId;+ segmentId: SegmentId;+}) {+ return H.createQuestion({+ name,+ type: "metric",+ query: {+ "source-table": tableId,+ filter: ["segment", segmentId],+ aggregation: [["count"]],+ },+ });+}++function createMetricWithMetricClause({+ name,+ tableId,+ metricId,+}: {+ name: string;+ tableId: TableId;+ metricId: CardId;+}) {+ return H.createQuestion({+ name,+ type: "metric",+ query: {+ "source-table": tableId,+ aggregation: [["metric", metricId]],+ },+ });+}++function createSnippetWithBasicFilter({ name }: { name: string }) {+ return H.createSnippet({+ name,+ content: "1 = 1",+ });+}++function createSnippetWithSnippetTag({+ name,+ snippetName,+}: {+ name: string;+ snippetName: string;+}) {+ return H.createSnippet({+ name,+ content: `{{snippet: ${snippetName}}}`,+ });+}++function createDashboardWithCard({+ name,+ cardId,+}: {+ name: string;+ cardId: CardId;+}) {+ return H.createDashboard({ name }).then(({ body: dashboard }) => {+ H.updateDashboardCards({+ dashboard_id: dashboard.id,+ cards: [+ {+ card_id: cardId,+ },+ ],+ });+ });+}++function createDashboardWithParameterWithCardSource({+ name,+ cardId,+ cardFieldName,+}: {+ name: string;+ cardId: CardId;+ cardFieldName: string;+}) {+ return H.createDashboard({+ name,+ parameters: [+ createMockParameter({+ id: "10422a0f",+ name: "Filter",+ slug: "filter",+ type: "string/=",+ values_source_type: "card",+ values_source_config: {+ card_id: cardId,+ value_field: ["field", cardFieldName, { "base-type": "type/Text" }],+ },+ }),+ ],+ });+}++// The dependency graph is recomputed asynchronously when entities are created or+// updated (metabase#71037). `waitForBackfillComplete` only reports the global+// one-time backfill flag — it does NOT guarantee the entities `setupEntities()`+// just created have been classified into the unreferenced graph. The list page+// fires a single query on load, so visiting before that async analysis finishes+// renders an incomplete list and the `findByText` assertions time out (4000ms).+//+// Poll the unreferenced endpoint until every expected entity is present before+// visiting. Defaults to the full seeded set, which is a superset of what any+// individual test asserts, so a single arg-free call makes every list test+// deterministic. The writable-Postgres table reaches the graph via the slower+// async DB-sync path, so it is covered here too. Mirrors+// `waitForBreakingDependencies`.+function waitForUnreferencedAnalysis(expectedNames: string[] = ENTITY_NAMES) {+ H.waitForBackfillComplete();+ H.waitForUnreferencedEntities((nodes) => {+ const presentNames = new Set(nodes.map(getNodeName));+ return expectedNames.every((name) => presentNames.has(name));+ });+}++// The unreferenced endpoint returns one page, so narrow it with `query` when+// the expected entities are not all on the first page.+function waitForSearchedUnreferencedAnalysis({+ query,+ expectedNames,+ timeoutMs = 30000,+}: {+ query: string;+ expectedNames: string[];+ timeoutMs?: number;+}): Cypress.Chainable {+ const intervalMs = 100;++ return cy+ .request<ListUnreferencedGraphNodesResponse>({+ method: "GET",+ url: "/api/ee/dependencies/graph/unreferenced",+ qs: { query, "include-personal-collections": true },+ })+ .then(({ body }) => {+ const presentNames = new Set(body.data.map(getNodeName));+ if (expectedNames.every((name) => presentNames.has(name))) {+ return;+ }+ if (timeoutMs <= 0) {+ throw new Error("Unreferenced entities analysis retry timeout");+ }+ cy.wait(intervalMs);+ waitForSearchedUnreferencedAnalysis({+ query,+ expectedNames,+ timeoutMs: timeoutMs - intervalMs,+ });+ });+}++function checkUnreferencedSidebar({+ title,+ location,+ description,+ owner,+ createdBy,+ fields = [],+}: {+ title: string;+ location?: string;+ description?: string;+ owner?: string;+ createdBy?: string;+ fields?: string[];+}) {+ const Sidebar = H.DependencyDiagnostics.Sidebar;++ H.DependencyDiagnostics.sidebar().within(() => {+ Sidebar.header().findByText(title).should("be.visible");+ if (location) {+ Sidebar.locationSection()+ .findByText(location)+ .scrollIntoView()+ .should("be.visible");+ }+ if (description) {+ Sidebar.infoSection().should("contain.text", description);+ }+ if (owner) {+ Sidebar.infoSection().should("contain.text", owner);+ }+ if (createdBy) {+ Sidebar.infoSection().should("contain.text", createdBy);+ }+ if (fields.length > 0) {+ Sidebar.fieldsSection().within(() => {+ fields.forEach((field) => {+ cy.findByText(field).scrollIntoView().should("be.visible");+ });+ });+ }+ });+}++// Polls the saved list params, so that a page reload restores the last change.+function waitForSavedListParams({+ mode,+ isSaved,+ timeoutMs = 10000,+}: {+ mode: "broken" | "unreferenced";+ isSaved: (params: DependencyDiagnosticsUserParams) => boolean;+ timeoutMs?: number;+}): Cypress.Chainable {+ const intervalMs = 100;++ return cy+ .request<DependencyDiagnosticsUserParams | "">({+ method: "GET",+ url: `/api/user-key-value/namespace/dependency_diagnostics/key/${mode}`,+ })+ .then(({ body }) => {+ if (typeof body === "object" && body != null && isSaved(body)) {+ return;+ }+ if (timeoutMs <= 0) {+ throw new Error(`Saved ${mode} list params retry timeout`);+ }+ cy.wait(intervalMs);+ waitForSavedListParams({+ mode,+ isSaved,+ timeoutMs: timeoutMs - intervalMs,+ });+ });+}++function getNodeName(node: DependencyNode): string | undefined {+ const { data } = node;+ if ("display_name" in data && data.display_name) {+ return data.display_name;+ }+ return "name" in data ? data.name : undefined;+}++function checkList({+ visibleEntities = [],+ hiddenEntities = [],+}: {+ visibleEntities?: string[];+ hiddenEntities?: string[];+}) {+ H.DependencyDiagnostics.list().within(() => {+ visibleEntities.forEach((name) => {+ cy.findByText(name).scrollIntoView().should("be.visible");+ });+ hiddenEntities.forEach((name) => {+ cy.findByText(name).should("not.exist");+ });+ });+}++function checkListSorting({ visibleEntities }: { visibleEntities: string[] }) {+ H.DependencyDiagnostics.list().within(() => {+ visibleEntities.forEach((name, index) => {+ cy.findByText(name)+ .parents("[data-index]")+ .should("have.attr", "data-index", index.toString());+ });+ });+}diff --git a/e2e/test/scenarios/dependencies/dependency-graph.cy.spec.ts b/e2e/test/scenarios/dependencies/dependency-graph.cy.spec.tsindex 835e209bb59..fa1fd7e74b7 100644--- a/e2e/test/scenarios/dependencies/dependency-graph.cy.spec.ts+++ b/e2e/test/scenarios/dependencies/dependency-graph.cy.spec.ts@@ -32,11 +32,10 @@ const TABLE_BASED_MODEL_NAME = "Table-based model";const TABLE_BASED_MEASURE_NAME = "Table-based measure";const TABLE_BASED_METRIC_NAME = "Table-based metric";const TABLE_BASED_TRANSFORM_NAME = "Table-based transform";-const CARD_BASED_QUESTION_NAME = "Card-based question";-const CARD_BASED_MODEL_NAME = "Card-based model";-const CARD_BASED_METRIC_NAME = "Card-based metric";-const CARD_BASED_TRANSFORM_NAME = "Card-based transform";-const CARD_BASED_SNIPPET_NAME = "Card-based snippet";+const QUESTION_BASED_NAME_PREFIX = "Question-based";+const QUESTION_BASED_TRANSFORM_TABLE_NAME = "question_based_transform_table";+const MODEL_BASED_NAME_PREFIX = "Model-based";+const MODEL_BASED_TRANSFORM_TABLE_NAME = "model_based_transform_table";const MEASURE_BASED_QUESTION_NAME = "Measure-based question";const MEASURE_BASED_MODEL_NAME = "Measure-based model";const MEASURE_BASED_METRIC_NAME = "Measure-based metric";@@ -79,19 +78,26 @@ describe("scenarios > dependencies > dependency graph", () => {itemName,itemIcon,isRecentItem,+ eventDetail,+ eventCount,}: {itemName: string;itemIcon: IconName;isRecentItem: boolean;+ eventDetail: DependencyType;+ eventCount: number;}) {cy.log(`verify that "${itemName}" can be found via search`);H.DependencyGraph.entrySearchInput().clear().type(itemName);H.popover().findByText(itemName).click();- H.expectUnstructuredSnowplowEvent({- event: "dependency_entity_selected",- triggered_from: "dependency-graph",- event_detail: "table",- });+ H.expectUnstructuredSnowplowEvent(+ {+ event: "dependency_entity_selected",+ triggered_from: "dependency-graph",+ event_detail: eventDetail,+ },+ eventCount,+ );H.DependencyGraph.entryButton().should("have.text", itemName);H.DependencyGraph.entryButton().icon(itemIcon).should("be.visible");@@ -148,7 +154,7 @@ describe("scenarios > dependencies > dependency graph", () => {H.DependencyGraph.entryButton().icon("close").click();}- it("should be able to use inline search for all supported entity types", () => {+ it("should be able to use inline search and the entity picker for all supported entity types", () => {getScoreboardTableId().then((tableId) => {createTableBasedMetric({ tableId });createTableBasedTransform({ tableName: TABLE_NAME });@@ -159,36 +165,38 @@ describe("scenarios > dependencies > dependency graph", () => {itemName: "Products",itemIcon: "table",isRecentItem: true,+ eventDetail: "table",+ eventCount: 1,});testEntitySearch({itemName: "Orders, Count, Grouped by Created At (year)",itemIcon: "line",isRecentItem: true,+ eventDetail: "card",+ eventCount: 1,});testEntitySearch({itemName: "Orders Model",itemIcon: "model",isRecentItem: true,+ eventDetail: "card",+ eventCount: 2,});testEntitySearch({itemName: TABLE_BASED_METRIC_NAME,itemIcon: "metric",isRecentItem: false,+ eventDetail: "card",+ eventCount: 3,});testEntitySearch({itemName: TABLE_BASED_TRANSFORM_NAME,itemIcon: "transform",isRecentItem: false,+ eventDetail: "transform",+ eventCount: 1,});- });- it("should be able to use the entity picker for all supported entity types", () => {- getScoreboardTableId().then((tableId) => {- createTableBasedMetric({ tableId });- createTableBasedTransform({ tableName: TABLE_NAME });- });-- visitGraph();testEntityPicker({path: ["Databases", /Sample Database/, "Products"],itemIcon: "table",@@ -212,70 +220,103 @@ describe("scenarios > dependencies > dependency graph", () => {});});- describe("entity focus", () => {- it("should be possible to select an entity via search", () => {+ describe("dependent types", () => {+ it("should display dependencies for a table, filter them, and navigate to them", () => {getScoreboardTableId().then((tableId) => {- createTableBasedQuestion({ tableId }).then(({ body: card }) => {- visitGraphForEntity(card.id, "card");+ createDashboard().then(({ body: dashboard }) => {+ createTableBasedQuestion({+ name: "Question in root collection",+ tableId,+ });+ createTableBasedQuestion({+ name: "Question in first collection",+ tableId,+ collectionId: FIRST_COLLECTION_ID,+ });+ createTableBasedQuestion({+ name: "Question in second collection",+ tableId,+ collectionId: SECOND_COLLECTION_ID,+ });+ createTableBasedQuestion({+ name: "Question in personal collection",+ tableId,+ collectionId: ADMIN_PERSONAL_COLLECTION_ID,+ });+ createTableBasedQuestion({+ name: "Question in dashboard",+ tableId,+ dashboardId: dashboard.id,+ });});- });-- H.DependencyGraph.selectionButton().click();- H.popover().findByText(TABLE_DISPLAY_NAME).click();- H.DependencyGraph.graph().within(() => {- cy.findByLabelText(TABLE_DISPLAY_NAME).should("be.visible");- cy.findByLabelText(TABLE_BASED_QUESTION_NAME).should("be.visible");- });- });- });-- describe("dependent types", () => {- function verifyPanelNavigation({- itemTitle,- groupTitle,- dependentItemTitle,- dependentItemLocation,- }: {- itemTitle: string;- groupTitle: string;- dependentItemTitle: string;- dependentItemLocation?: string;- }) {- H.DependencyGraph.graph()- .findByLabelText(itemTitle)- .findByText(groupTitle)- .click();- H.DependencyGraph.dependencyPanel()- .findByLabelText(dependentItemTitle)- .within(() => {- if (dependentItemLocation) {- cy.findByText(dependentItemLocation).should("be.visible");- }- cy.findByText(dependentItemTitle).should("be.visible").click();+ createDocumentWithTableBasedQuestion({+ name: "Question in document",+ tableId,});- H.DependencyGraph.entryButton()- .findByText(dependentItemTitle)- .should("be.visible");- cy.go("back");- H.DependencyGraph.entryButton()- .findByText(itemTitle)- .should("be.visible");- }-- it("should display dependencies for a table and navigate to them", () => {- getScoreboardTableId().then((tableId) => {- createTableBasedQuestion({ tableId });createTableBasedModel({ tableId });createTableBasedMetric({ tableId });- createTableBasedTransform({ tableName: TABLE_NAME });+ createTableBasedTransform({ tableName: TABLE_NAME }).then(+ ({ body: transform }) => {+ H.runTransformAndWaitForSuccess(transform.id);+ },+ );createTableBasedSegment({ tableId });createTableBasedMeasure({ tableId });visitGraphForEntity(tableId, "table");});++ cy.log("question dependents and their locations");+ H.DependencyGraph.graph()+ .findByLabelText(TABLE_DISPLAY_NAME)+ .findByText("6 questions")+ .click();+ verifyItems({+ visibleItems: [+ "Question in dashboard",+ "Question in document",+ "Question in root collection",+ "Question in first collection",+ "Question in second collection",+ "Question in personal collection",+ ],+ });+ verifyItemLocation({+ itemTitle: "Question in root collection",+ location: ROOT_COLLECTION_NAME,+ });+ verifyItemLocation({+ itemTitle: "Question in first collection",+ location: FIRST_COLLECTION_NAME,+ });+ verifyItemLocation({+ itemTitle: "Question in dashboard",+ location: DASHBOARD_NAME,+ });+ verifyItemLocation({+ itemTitle: "Question in document",+ location: DOCUMENT_NAME,+ });++ cy.log("question dependents without items in personal collections");+ toggleFilter({+ filterName: "Include items in personal collections",+ });+ verifyItems({+ visibleItems: [+ "Question in dashboard",+ "Question in document",+ "Question in root collection",+ "Question in first collection",+ "Question in second collection",+ ],+ hiddenItems: ["Question in personal collection"],+ });+verifyPanelNavigation({itemTitle: TABLE_DISPLAY_NAME,- groupTitle: "1 question",- dependentItemTitle: TABLE_BASED_QUESTION_NAME,+ groupTitle: "6 questions",+ dependentItemTitle: "Question in document",+ dependentItemLocation: DOCUMENT_NAME,});verifyPanelNavigation({itemTitle: TABLE_DISPLAY_NAME,@@ -288,11 +329,6 @@ describe("scenarios > dependencies > dependency graph", () => {groupTitle: "1 metric",dependentItemTitle: TABLE_BASED_METRIC_NAME,});- verifyPanelNavigation({- itemTitle: TABLE_DISPLAY_NAME,- groupTitle: "1 transform",- dependentItemTitle: TABLE_BASED_TRANSFORM_NAME,- });verifyPanelNavigation({itemTitle: TABLE_DISPLAY_NAME,groupTitle: "1 segment",@@ -303,6 +339,27 @@ describe("scenarios > dependencies > dependency graph", () => {groupTitle: "1 measure",dependentItemTitle: TABLE_BASED_MEASURE_NAME,});++ cy.log("transform dependents");+ H.DependencyGraph.graph()+ .findByLabelText(TABLE_DISPLAY_NAME)+ .findByText("1 transform")+ .click();+ H.DependencyGraph.dependencyPanel()+ .findByText(TABLE_BASED_TRANSFORM_NAME)+ .click();+ H.DependencyGraph.entryButton()+ .findByText(TABLE_BASED_TRANSFORM_NAME)+ .should("be.visible");+ H.DependencyGraph.dependencyPanel()+ .findByRole("button", { name: "Close" })+ .click();+ H.DependencyGraph.dependencyPanel().should("not.exist");+ verifyPanelNavigation({+ itemTitle: TABLE_BASED_TRANSFORM_NAME,+ groupTitle: "1 table",+ dependentItemTitle: TRANSFORM_TABLE_DISPLAY_NAME,+ });});it("should display dependencies for a segment and navigate to them", () => {@@ -343,83 +400,59 @@ describe("scenarios > dependencies > dependency graph", () => {});});- it("should display dependencies for a question and navigate to them", () => {- getScoreboardTableId()- .then((tableId) => createTableBasedQuestion({ tableId }))- .then(({ body: card }) => {- createCardBasedQuestion({ cardId: card.id });- createCardBasedModel({ cardId: card.id });- createCardBasedMetric({ cardId: card.id });- createCardBasedTransform({ cardId: card.id });- createCardBasedSnippet({ cardId: card.id });- visitGraphForEntity(card.id, "card");+ it("should display dependencies for a question and a model and navigate to them", () => {+ getScoreboardTableId().then((tableId) => {+ createTableBasedQuestion({ tableId }).then(({ body: card }) => {+ createCardBasedDependents({+ cardId: card.id,+ namePrefix: QUESTION_BASED_NAME_PREFIX,+ transformTableName: QUESTION_BASED_TRANSFORM_TABLE_NAME,+ });+ cy.wrap(card.id).as("questionId");+ });+ createTableBasedModel({ tableId }).then(({ body: card }) => {+ createCardBasedDependents({+ cardId: card.id,+ namePrefix: MODEL_BASED_NAME_PREFIX,+ transformTableName: MODEL_BASED_TRANSFORM_TABLE_NAME,+ });});- verifyPanelNavigation({- itemTitle: TABLE_BASED_QUESTION_NAME,- groupTitle: "1 question",- dependentItemTitle: CARD_BASED_QUESTION_NAME,- });- verifyPanelNavigation({- itemTitle: TABLE_BASED_QUESTION_NAME,- groupTitle: "1 model",- dependentItemTitle: CARD_BASED_MODEL_NAME,- });- verifyPanelNavigation({- itemTitle: TABLE_BASED_QUESTION_NAME,- groupTitle: "1 metric",- dependentItemTitle: CARD_BASED_METRIC_NAME,});- verifyPanelNavigation({- itemTitle: TABLE_BASED_QUESTION_NAME,- groupTitle: "1 transform",- dependentItemTitle: CARD_BASED_TRANSFORM_NAME,+ cy.get<CardId>("@questionId").then((questionId) =>+ visitGraphForEntity(questionId, "card"),+ );++ cy.log("jump to an entity on the graph");+ H.DependencyGraph.graph().within(() => {+ cy.findByLabelText(TABLE_DISPLAY_NAME).should("be.visible");+ cy.findByLabelText(TABLE_BASED_QUESTION_NAME).should("be.visible");});- verifyPanelNavigation({+ verifyNodeCentered({ nodeLabel: TABLE_DISPLAY_NAME, isCentered: false });+ H.DependencyGraph.selectionButton().click();+ H.popover().findByText(TABLE_DISPLAY_NAME).click();+ verifyNodeCentered({ nodeLabel: TABLE_DISPLAY_NAME, isCentered: true });++ cy.log("question dependents");+ verifyCardDependentsNavigation({itemTitle: TABLE_BASED_QUESTION_NAME,- groupTitle: "1 snippet",- dependentItemTitle: CARD_BASED_SNIPPET_NAME,+ namePrefix: QUESTION_BASED_NAME_PREFIX,});- });- it("should display dependencies for a model and navigate to them", () => {- getScoreboardTableId()- .then((tableId) => createTableBasedModel({ tableId }))- .then(({ body: card }) => {- createCardBasedQuestion({ cardId: card.id });- createCardBasedModel({ cardId: card.id });- createCardBasedMetric({ cardId: card.id });- createCardBasedTransform({ cardId: card.id });- createCardBasedSnippet({ cardId: card.id });- visitGraphForEntity(card.id, "card");- });- verifyPanelNavigation({- itemTitle: TABLE_BASED_MODEL_NAME,- groupTitle: "1 question",- dependentItemTitle: CARD_BASED_QUESTION_NAME,- });- verifyPanelNavigation({- itemTitle: TABLE_BASED_MODEL_NAME,- groupTitle: "1 model",- dependentItemTitle: CARD_BASED_MODEL_NAME,- });- verifyPanelNavigation({- itemTitle: TABLE_BASED_MODEL_NAME,- groupTitle: "1 metric",- dependentItemTitle: CARD_BASED_METRIC_NAME,- });- verifyPanelNavigation({- itemTitle: TABLE_BASED_MODEL_NAME,- groupTitle: "1 transform",- dependentItemTitle: CARD_BASED_TRANSFORM_NAME,- });- verifyPanelNavigation({+ cy.log("model dependents");+ H.DependencyGraph.entryButton().icon("close").click();+ H.DependencyGraph.entrySearchInput().type(TABLE_BASED_MODEL_NAME);+ H.popover().findByText(TABLE_BASED_MODEL_NAME).click();+ H.DependencyGraph.entryButton().should(+ "have.text",+ TABLE_BASED_MODEL_NAME,+ );+ verifyCardDependentsNavigation({itemTitle: TABLE_BASED_MODEL_NAME,- groupTitle: "1 snippet",- dependentItemTitle: CARD_BASED_SNIPPET_NAME,+ namePrefix: MODEL_BASED_NAME_PREFIX,});});- it("should display dependencies for a model and navigate to them", () => {+ it("should display dependencies for a measure and navigate to them", () => {getScoreboardTableId().then((tableId) => {createTableBasedMeasure({ tableId }).then(({ body: measure }) => {createMeasureBasedQuestion({ tableId, measureId: measure.id });@@ -491,20 +524,6 @@ describe("scenarios > dependencies > dependency graph", () => {});});- it("should display dependencies for a transform and navigate to them", () => {- createTableBasedTransform({ tableName: TABLE_NAME }).then(- ({ body: transform }) => {- H.runTransformAndWaitForSuccess(transform.id);- visitGraphForEntity(transform.id, "transform");- },- );- verifyPanelNavigation({- itemTitle: TABLE_BASED_TRANSFORM_NAME,- groupTitle: "1 table",- dependentItemTitle: TRANSFORM_TABLE_DISPLAY_NAME,- });- });-it("should display dependencies for a snippet and navigate to them", () => {createEmptySnippet().then(({ body: snippet }) => {createSnippetBasedQuestion({@@ -546,149 +565,141 @@ describe("scenarios > dependencies > dependency graph", () => {dependentItemTitle: SNIPPET_BASED_SNIPPET_NAME,});});+ });+});- it("should display dependencies for a question in the root collection", () => {- getScoreboardTableId().then((tableId) => {- createTableBasedQuestion({ tableId });- visitGraphForEntity(tableId, "table");- });- verifyPanelNavigation({- itemTitle: TABLE_DISPLAY_NAME,- groupTitle: "1 question",- dependentItemTitle: TABLE_BASED_QUESTION_NAME,- dependentItemLocation: ROOT_COLLECTION_NAME,- });- });-- it("should display dependencies for a question in a non-root collection", () => {- getScoreboardTableId().then((tableId) => {- createTableBasedQuestion({- tableId,- collectionId: FIRST_COLLECTION_ID,- });- visitGraphForEntity(tableId, "table");- });- verifyPanelNavigation({- itemTitle: TABLE_DISPLAY_NAME,- groupTitle: "1 question",- dependentItemTitle: TABLE_BASED_QUESTION_NAME,- dependentItemLocation: FIRST_COLLECTION_NAME,- });- });+function visitGraph() {+ cy.visit(BASE_URL);+}- it("should display dependencies for a question in a dashboard", () => {- getScoreboardTableId().then((tableId) => {- createDashboard().then(({ body: dashboard }) => {- createTableBasedQuestion({ tableId, dashboardId: dashboard.id });- visitGraphForEntity(tableId, "table");- });- });- verifyPanelNavigation({- itemTitle: TABLE_DISPLAY_NAME,- groupTitle: "1 question",- dependentItemTitle: TABLE_BASED_QUESTION_NAME,- dependentItemLocation: DASHBOARD_NAME,- });- });+function toggleFilter({ filterName }: { filterName: string }) {+ H.DependencyGraph.dependencyPanel().icon("filter").click();+ H.popover().findByText(filterName).click();+ H.DependencyGraph.dependencyPanel().icon("filter").click();+}- it("should display dependencies for a question in a document", () => {- getScoreboardTableId().then((tableId) => {- createDocumentWithTableBasedQuestion({ tableId });- visitGraphForEntity(tableId, "table");- });- verifyPanelNavigation({- itemTitle: TABLE_DISPLAY_NAME,- groupTitle: "1 question",- dependentItemTitle: TABLE_BASED_QUESTION_NAME,- dependentItemLocation: DOCUMENT_NAME,- });- });+function verifyItems({+ visibleItems = [],+ hiddenItems = [],+}: {+ visibleItems?: string[];+ hiddenItems?: string[];+}) {+ H.DependencyGraph.dependencyPanel().within(() => {+ visibleItems.forEach((item) => cy.findByText(item).should("be.visible"));+ hiddenItems.forEach((item) => cy.findByText(item).should("not.exist"));});+}- describe("dependent filtering", () => {- function toggleFilter({ filterName }: { filterName: string }) {- H.DependencyGraph.dependencyPanel().icon("filter").click();- H.popover().findByText(filterName).click();- H.DependencyGraph.dependencyPanel().icon("filter").click();- }+function verifyItemLocation({+ itemTitle,+ location,+}: {+ itemTitle: string;+ location: string;+}) {+ H.DependencyGraph.dependencyPanel()+ .findByLabelText(itemTitle)+ .findByText(location)+ .should("be.visible");+}- function verifyItems({- visibleItems = [],- hiddenItems = [],- }: {- visibleItems?: string[];- hiddenItems?: string[];- }) {- H.DependencyGraph.dependencyPanel().within(() => {- visibleItems.forEach((item) =>- cy.findByText(item).should("be.visible"),- );- hiddenItems.forEach((item) => cy.findByText(item).should("not.exist"));- });- }+function verifyCardDependentsNavigation({+ itemTitle,+ namePrefix,+}: {+ itemTitle: string;+ namePrefix: string;+}) {+ const names = getCardBasedDependentNames(namePrefix);+ verifyPanelNavigation({+ itemTitle,+ groupTitle: "1 question",+ dependentItemTitle: names.question,+ });+ verifyPanelNavigation({+ itemTitle,+ groupTitle: "1 model",+ dependentItemTitle: names.model,+ });+ verifyPanelNavigation({+ itemTitle,+ groupTitle: "1 metric",+ dependentItemTitle: names.metric,+ });+ verifyPanelNavigation({+ itemTitle,+ groupTitle: "1 transform",+ dependentItemTitle: names.transform,+ });+ verifyPanelNavigation({+ itemTitle,+ groupTitle: "1 snippet",+ dependentItemTitle: names.snippet,+ });+}- it("should be able to filter questions", () => {- getScoreboardTableId().then((tableId) => {- createDashboard().then(({ body: dashboard }) => {- createTableBasedQuestion({- name: "Question in root collection",- tableId,- });- createTableBasedQuestion({- name: "Question in first collection",- tableId,- collectionId: FIRST_COLLECTION_ID,- });- createTableBasedQuestion({- name: "Question in second collection",- tableId,- collectionId: SECOND_COLLECTION_ID,- });- createTableBasedQuestion({- name: "Question in personal collection",- tableId,- collectionId: ADMIN_PERSONAL_COLLECTION_ID,- });- createTableBasedQuestion({- name: "Question in dashboard",- tableId,- dashboardId: dashboard.id,- });- });- visitGraphForEntity(tableId, "table");- });- H.DependencyGraph.graph()- .findByLabelText(TABLE_DISPLAY_NAME)- .findByText("5 questions")- .click();+function getElementCenter(element: HTMLElement) {+ const { left, top, width, height } = element.getBoundingClientRect();+ return { x: left + width / 2, y: top + height / 2 };+}- verifyItems({- visibleItems: [- "Question in dashboard",- "Question in root collection",- "Question in first collection",- "Question in second collection",- "Question in personal collection",- ],- });- toggleFilter({- filterName: "Include items in personal collections",- });- verifyItems({- visibleItems: [- "Question in dashboard",- "Question in root collection",- "Question in first collection",- "Question in second collection",- ],- hiddenItems: ["Question in personal collection"],+function verifyNodeCentered({+ nodeLabel,+ isCentered,+}: {+ nodeLabel: string;+ isCentered: boolean;+}) {+ const maxOffsetPx = 10;++ H.DependencyGraph.graph().then(($graph) => {+ const graphCenter = getElementCenter($graph[0]);+ H.DependencyGraph.graph()+ .findByLabelText(nodeLabel)+ .should(($node) => {+ const nodeCenter = getElementCenter($node[0]);+ const offsetPx = Math.hypot(+ nodeCenter.x - graphCenter.x,+ nodeCenter.y - graphCenter.y,+ );+ if (isCentered) {+ expect(offsetPx).to.be.lessThan(maxOffsetPx);+ } else {+ expect(offsetPx).to.be.greaterThan(maxOffsetPx);+ }});- });});-});+}-function visitGraph() {- cy.visit(BASE_URL);+function verifyPanelNavigation({+ itemTitle,+ groupTitle,+ dependentItemTitle,+ dependentItemLocation,+}: {+ itemTitle: string;+ groupTitle: string;+ dependentItemTitle: string;+ dependentItemLocation?: string;+}) {+ H.DependencyGraph.graph()+ .findByLabelText(itemTitle)+ .findByText(groupTitle)+ .click();+ H.DependencyGraph.dependencyPanel()+ .findByLabelText(dependentItemTitle)+ .within(() => {+ if (dependentItemLocation) {+ cy.findByText(dependentItemLocation).should("be.visible");+ }+ cy.findByText(dependentItemTitle).should("be.visible").click();+ });+ H.DependencyGraph.entryButton()+ .findByText(dependentItemTitle)+ .should("be.visible");+ cy.go("back");+ H.DependencyGraph.entryButton().findByText(itemTitle).should("be.visible");}function visitGraphForEntity(id: DependencyId, type: DependencyType) {@@ -763,6 +774,62 @@ function createTableBasedModel({});}+function getCardBasedDependentNames(namePrefix: string) {+ return {+ question: `${namePrefix} question`,+ model: `${namePrefix} model`,+ metric: `${namePrefix} metric`,+ transform: `${namePrefix} transform`,+ snippet: `${namePrefix} snippet`,+ };+}++function createCardBasedDependents({+ cardId,+ namePrefix,+ transformTableName,+}: {+ cardId: CardId;+ namePrefix: string;+ transformTableName: string;+}) {+ const names = getCardBasedDependentNames(namePrefix);+ createCardBasedCard({ name: names.question, type: "question", cardId });+ createCardBasedCard({ name: names.model, type: "model", cardId });+ H.createQuestion({+ name: names.metric,+ type: "metric",+ database: WRITABLE_DB_ID,+ query: {+ "source-table": `card__${cardId}`,+ aggregation: [["count"]],+ },+ });+ H.createTransform({+ name: names.transform,+ source: {+ type: "query",+ query: {+ database: WRITABLE_DB_ID,+ type: "query",+ query: {+ "source-table": `card__${cardId}`,+ },+ },+ },+ target: {+ type: "table",+ database: WRITABLE_DB_ID,+ schema: "public",+ name: transformTableName,+ },+ });+ H.createSnippet({+ name: names.snippet,+ content: `{{#${cardId}}}`,+ });+}+function createCardBasedCard({name,type,@@ -782,22 +849,6 @@ function createCardBasedCard({});}-function createCardBasedQuestion({ cardId }: { cardId: CardId }) {- return createCardBasedCard({- name: CARD_BASED_QUESTION_NAME,- type: "question",- cardId,- });-}--function createCardBasedModel({ cardId }: { cardId: CardId }) {- return createCardBasedCard({- name: CARD_BASED_MODEL_NAME,- type: "model",- cardId,- });-}-function createMetricBasedCard({name,type,@@ -931,18 +982,6 @@ function createTableBasedMetric({ tableId }: { tableId: TableId }) {});}-function createCardBasedMetric({ cardId }: { cardId: CardId }) {- return H.createQuestion({- name: CARD_BASED_METRIC_NAME,- type: "metric",- database: WRITABLE_DB_ID,- query: {- "source-table": `card__${cardId}`,- aggregation: [["count"]],- },- });-}-function createMetricBasedMetric({tableId,metricId,@@ -984,28 +1023,6 @@ function createTableBasedTransform({ tableName }: { tableName: string }) {});}-function createCardBasedTransform({ cardId }: { cardId: CardId }) {- return H.createTransform({- name: CARD_BASED_TRANSFORM_NAME,- source: {- type: "query",- query: {- database: WRITABLE_DB_ID,- type: "query",- query: {- "source-table": `card__${cardId}`,- },- },- },- target: {- type: "table",- database: WRITABLE_DB_ID,- schema: "public",- name: TRANSFORM_TABLE_NAME,- },- });-}-function createMetricBasedTransform({tableId,metricId,@@ -1082,13 +1099,6 @@ function createEmptySnippet() {});}-function createCardBasedSnippet({ cardId }: { cardId: CardId }) {- return H.createSnippet({- name: CARD_BASED_SNIPPET_NAME,- content: `{{#${cardId}}}`,- });-}-function createSnippetBasedSnippet({ snippetName }: { snippetName: string }) {return H.createSnippet({name: SNIPPET_BASED_SNIPPET_NAME,@@ -1207,8 +1217,10 @@ function createDashboard() {}function createDocumentWithTableBasedQuestion({+ name,tableId,}: {+ name: string;tableId: TableId;}) {return H.createDocument({@@ -1217,7 +1229,7 @@ function createDocumentWithTableBasedQuestion({cards: {"-1": createMockCard({id: -1,- name: TABLE_BASED_QUESTION_NAME,+ name,dataset_query: {database: WRITABLE_DB_ID,type: "query",diff --git a/e2e/test/scenarios/dependencies/dependency-unreferenced-list.cy.spec.ts b/e2e/test/scenarios/dependencies/dependency-unreferenced-list.cy.spec.tsdeleted file mode 100644index b833890b55f..00000000000--- a/e2e/test/scenarios/dependencies/dependency-unreferenced-list.cy.spec.ts+++ /dev/null@@ -1,1224 +0,0 @@-import { SAMPLE_DB_ID, USERS, WRITABLE_DB_ID } from "e2e/support/cypress_data";-import { SAMPLE_DATABASE } from "e2e/support/cypress_sample_database";-import {- ADMIN_PERSONAL_COLLECTION_ID,- ADMIN_USER_ID,- FIRST_COLLECTION_ID,-} from "e2e/support/cypress_sample_instance_data";-import type {- CardId,- CollectionId,- DependencyNode,- FieldId,- NativeQuerySnippetId,- SegmentId,- TableId,-} from "metabase-types/api";-import { createMockParameter } from "metabase-types/api/mocks";--const { H } = cy;-const { ORDERS_ID, PRODUCTS, PRODUCTS_ID } = SAMPLE_DATABASE;--const DATABASE_NAME = "Writable Postgres12";-const TABLE_NAME = "many_data_types";-const TABLE_DISPLAY_NAME = "Many Data Types";-const TABLE_DESCRIPTION = "This is a table with many data types";-const MODEL_FOR_QUESTION_DATA_SOURCE = "Model for question data source";-const MODEL_FOR_MODEL_DATA_SOURCE = "Model for model data source";-const MODEL_FOR_METRIC_DATA_SOURCE = "Model for metric data source";-const MODEL_FOR_NATIVE_QUESTION_CARD_TAG = "Model for native question card tag";-const MODEL_FOR_NATIVE_QUESTION_PARAMETER_SOURCE =- "Model for native question parameter source";-const MODEL_FOR_DASHBOARD_CARD = "Model for dashboard card";-const MODEL_FOR_DASHBOARD_PARAMETER_SOURCE =- "Model for dashboard parameter source";-const SEGMENT_FOR_QUESTION_FILTER = "Segment for question filter";-const SEGMENT_FOR_MODEL_FILTER = "Segment for model filter";-const SEGMENT_FOR_SEGMENT_FILTER = "Segment for segment filter";-const SEGMENT_FOR_METRIC_FILTER = "Segment for metric filter";-const METRIC_FOR_QUESTION_AGGREGATION = "Metric for question aggregation";-const METRIC_FOR_MODEL_AGGREGATION = "Metric for model aggregation";-const METRIC_FOR_METRIC_AGGREGATION = "Metric for metric aggregation";-const METRIC_FOR_DASHBOARD_CARD = "Metric for dashboard card";-const SNIPPET_FOR_NATIVE_QUESTION_CARD_TAG =- "Snippet for native question card tag";-const SNIPPET_FOR_SNIPPET_TAG = "Snippet for snippet tag";--const TABLE_NAMES = [TABLE_DISPLAY_NAME];--const MODEL_NAMES = [- MODEL_FOR_QUESTION_DATA_SOURCE,- MODEL_FOR_MODEL_DATA_SOURCE,- MODEL_FOR_METRIC_DATA_SOURCE,- MODEL_FOR_NATIVE_QUESTION_CARD_TAG,- MODEL_FOR_NATIVE_QUESTION_PARAMETER_SOURCE,- MODEL_FOR_DASHBOARD_CARD,- MODEL_FOR_DASHBOARD_PARAMETER_SOURCE,-];--const SEGMENT_NAMES = [- SEGMENT_FOR_QUESTION_FILTER,- SEGMENT_FOR_MODEL_FILTER,- SEGMENT_FOR_SEGMENT_FILTER,- SEGMENT_FOR_METRIC_FILTER,-];--const METRIC_NAMES = [- METRIC_FOR_QUESTION_AGGREGATION,- METRIC_FOR_MODEL_AGGREGATION,- METRIC_FOR_METRIC_AGGREGATION,- METRIC_FOR_DASHBOARD_CARD,-];--const SNIPPET_NAMES = [- SNIPPET_FOR_NATIVE_QUESTION_CARD_TAG,- SNIPPET_FOR_SNIPPET_TAG,-];--const ENTITY_NAMES = [- ...TABLE_NAMES,- ...MODEL_NAMES,- ...SEGMENT_NAMES,- ...METRIC_NAMES,- ...SNIPPET_NAMES,-];--// The unreferenced list also contains inactive tables of the shared writable DB-// (tables dropped by other specs stay visible on purpose — see #77714), so the-// full list can exceed one page. Tests that need to see all of the entities-// created by this spec at once narrow the list down with this search term,-// which matches every entity name above except the table's.-const ENTITY_SEARCH_TERM = "for";-const SEARCHABLE_ENTITY_NAMES = [- ...MODEL_NAMES,- ...SEGMENT_NAMES,- ...METRIC_NAMES,- ...SNIPPET_NAMES,-];--const MODELS_SORTED_BY_NAME = [- MODEL_FOR_DASHBOARD_CARD,- MODEL_FOR_DASHBOARD_PARAMETER_SOURCE,- MODEL_FOR_METRIC_DATA_SOURCE,- MODEL_FOR_MODEL_DATA_SOURCE,- MODEL_FOR_NATIVE_QUESTION_CARD_TAG,- MODEL_FOR_NATIVE_QUESTION_PARAMETER_SOURCE,- MODEL_FOR_QUESTION_DATA_SOURCE,-];--const MODELS_SORTED_BY_LOCATION = [- MODEL_FOR_METRIC_DATA_SOURCE,- MODEL_FOR_MODEL_DATA_SOURCE,- MODEL_FOR_QUESTION_DATA_SOURCE,- MODEL_FOR_NATIVE_QUESTION_CARD_TAG,- MODEL_FOR_NATIVE_QUESTION_PARAMETER_SOURCE,- MODEL_FOR_DASHBOARD_CARD,- MODEL_FOR_DASHBOARD_PARAMETER_SOURCE,-];--describe("scenarios > dependencies > unreferenced list", () => {- beforeEach(() => {- H.restore("postgres-writable");- H.resetTestTable({ type: "postgres", table: TABLE_NAME });- cy.signInAsAdmin();- H.activateToken("pro-self-hosted");- H.updateSetting("transforms-enabled", true);- H.resyncDatabase({ dbId: WRITABLE_DB_ID, tableName: TABLE_NAME });- cy.viewport(1600, 1400);- H.resetSnowplow();- });-- afterEach(() => {- H.expectNoBadSnowplowEvents();- });-- describe("analysis", () => {- it("should show unreferenced entities", () => {- setupEntities();- waitForUnreferencedAnalysis();- H.DependencyDiagnostics.visitUnreferencedEntities();- checkList({ visibleEntities: [TABLE_DISPLAY_NAME] });- H.DependencyDiagnostics.searchInput().type(ENTITY_SEARCH_TERM);- checkList({ visibleEntities: SEARCHABLE_ENTITY_NAMES });- });-- it("should not show referenced entities", () => {- setupEntities({ withReferences: true });- // These entities are referenced, so they should never appear in the- // unreferenced list — we can't poll for their presence. Wait for the- // global backfill so the analysis has run before asserting their absence.- H.waitForBackfillComplete();- H.DependencyDiagnostics.visitUnreferencedEntities();- H.DependencyDiagnostics.list().within(() => {- ENTITY_NAMES.forEach((name) => {- cy.findByText(name).should("not.exist");- });- });- });- });-- describe("search", () => {- it("should search for entities", () => {- setupEntities();- waitForUnreferencedAnalysis();- H.DependencyDiagnostics.visitUnreferencedEntities();- H.DependencyDiagnostics.searchInput().type(- MODEL_FOR_QUESTION_DATA_SOURCE,- );- checkList({- visibleEntities: [MODEL_FOR_QUESTION_DATA_SOURCE],- hiddenEntities: [MODEL_FOR_MODEL_DATA_SOURCE],- });- });-- it("should search for entities with type filters", () => {- setupEntities();- waitForUnreferencedAnalysis();- H.DependencyDiagnostics.visitUnreferencedEntities();- H.DependencyDiagnostics.searchInput().type("tag");- checkList({- visibleEntities: [- MODEL_FOR_NATIVE_QUESTION_CARD_TAG,- SNIPPET_FOR_SNIPPET_TAG,- ],- hiddenEntities: [MODEL_FOR_QUESTION_DATA_SOURCE],- });-- H.DependencyDiagnostics.filterButton().click();- H.popover().findByText("Snippet").click();- checkList({- visibleEntities: [MODEL_FOR_NATIVE_QUESTION_CARD_TAG],- hiddenEntities: [SNIPPET_FOR_SNIPPET_TAG],- });- });- });-- describe("filters", () => {- it("should filter entities by type", () => {- setupEntities();- waitForUnreferencedAnalysis();- H.DependencyDiagnostics.visitUnreferencedEntities();- H.DependencyDiagnostics.searchInput().type(ENTITY_SEARCH_TERM);- checkList({ visibleEntities: SEARCHABLE_ENTITY_NAMES });-- H.DependencyDiagnostics.filterButton().click();- H.popover().findByText("Model").click();- checkList({ hiddenEntities: [MODEL_FOR_NATIVE_QUESTION_CARD_TAG] });-- H.popover().findByText("Segment").click();- checkList({- hiddenEntities: [- MODEL_FOR_NATIVE_QUESTION_CARD_TAG,- SEGMENT_FOR_QUESTION_FILTER,- ],- });-- H.popover().findByText("Metric").click();- checkList({- hiddenEntities: [- MODEL_FOR_NATIVE_QUESTION_CARD_TAG,- SEGMENT_FOR_QUESTION_FILTER,- METRIC_FOR_QUESTION_AGGREGATION,- ],- });-- H.popover().findByText("Model").click();- checkList({ visibleEntities: [MODEL_FOR_NATIVE_QUESTION_CARD_TAG] });- });-- it("should persist filter changes after page reload", () => {- setupEntities();- waitForUnreferencedAnalysis();- H.DependencyDiagnostics.visitUnreferencedEntities();- checkList({ visibleEntities: MODEL_NAMES });-- H.DependencyDiagnostics.filterButton().click();- H.popover().findByText("Model").click();- checkList({ hiddenEntities: MODEL_NAMES });-- H.DependencyDiagnostics.visitUnreferencedEntities();- checkList({ visibleEntities: METRIC_NAMES, hiddenEntities: MODEL_NAMES });- });-- it("should filter by location", () => {- setupEntities();- waitForUnreferencedAnalysis();- H.DependencyDiagnostics.visitUnreferencedEntities();- H.DependencyDiagnostics.searchInput().type(ENTITY_SEARCH_TERM);- checkList({- visibleEntities: [- MODEL_FOR_MODEL_DATA_SOURCE,- MODEL_FOR_METRIC_DATA_SOURCE,- SNIPPET_FOR_NATIVE_QUESTION_CARD_TAG,- ],- });-- H.DependencyDiagnostics.filterButton().click();- H.popover().findByText("Include items in personal collections").click();- checkList({- visibleEntities: [- MODEL_FOR_MODEL_DATA_SOURCE,- SNIPPET_FOR_NATIVE_QUESTION_CARD_TAG,- ],- hiddenEntities: [MODEL_FOR_METRIC_DATA_SOURCE],- });-- H.popover().findByText("Include items in personal collections").click();- checkList({- visibleEntities: [- MODEL_FOR_MODEL_DATA_SOURCE,- MODEL_FOR_METRIC_DATA_SOURCE,- SNIPPET_FOR_NATIVE_QUESTION_CARD_TAG,- ],- });- });- });-- describe("sorting", () => {- it("should sort by name", () => {- setupEntities();- waitForUnreferencedAnalysis();- H.DependencyDiagnostics.visitUnreferencedEntities();- H.DependencyDiagnostics.searchInput().type("Model for");-- cy.log("sorted by name by default");- checkListSorting({- visibleEntities: MODELS_SORTED_BY_NAME,- });-- cy.log("sorted by name ascending");- H.DependencyDiagnostics.list().findByText("Name").click();- checkListSorting({- visibleEntities: MODELS_SORTED_BY_NAME,- });-- cy.log("sorted by name descending");- H.DependencyDiagnostics.list().findByText("Name").click();- checkListSorting({- visibleEntities: [...MODELS_SORTED_BY_NAME].reverse(),- });- });-- it("should sort by location", () => {- setupEntities();- waitForUnreferencedAnalysis();- H.DependencyDiagnostics.visitUnreferencedEntities();- H.DependencyDiagnostics.searchInput().type("Model for");-- cy.log("sorted by location ascending");- H.DependencyDiagnostics.list().findByText("Location").click();- checkListSorting({- visibleEntities: MODELS_SORTED_BY_LOCATION,- });-- cy.log("sorted by location descending");- H.DependencyDiagnostics.list().findByText("Location").click();- checkListSorting({- visibleEntities: [...MODELS_SORTED_BY_LOCATION].reverse(),- });- });-- it("should persist sorting changes after page reload", () => {- setupEntities();- waitForUnreferencedAnalysis();- H.DependencyDiagnostics.visitUnreferencedEntities();- H.DependencyDiagnostics.searchInput().type("Model for");-- H.DependencyDiagnostics.list().findByText("Location").click();- checkListSorting({ visibleEntities: MODELS_SORTED_BY_LOCATION });-- H.DependencyDiagnostics.visitUnreferencedEntities();- H.DependencyDiagnostics.searchInput().type("Model for");- checkListSorting({ visibleEntities: MODELS_SORTED_BY_LOCATION });- });- });-- describe("selecting entities", () => {- it("should show the sidebar for supported entities and trigger snowplow event", () => {- setupEntities();- waitForUnreferencedAnalysis();- H.DependencyDiagnostics.visitUnreferencedEntities();-- H.DependencyDiagnostics.list().findByText(TABLE_DISPLAY_NAME).click();- H.expectUnstructuredSnowplowEvent({- event: "dependency_diagnostics_entity_selected",- triggered_from: "unreferenced",- event_detail: "table",- });- checkSidebar({- title: TABLE_DISPLAY_NAME,- location: DATABASE_NAME,- description: TABLE_DESCRIPTION,- owner: `${USERS.admin.first_name} ${USERS.admin.last_name}`,- fields: ["ID", "UUID"],- });-- H.DependencyDiagnostics.searchInput().type(ENTITY_SEARCH_TERM);- H.DependencyDiagnostics.list()- .findByText(MODEL_FOR_QUESTION_DATA_SOURCE)- .click();- checkSidebar({- title: MODEL_FOR_QUESTION_DATA_SOURCE,- location: "Our analytics",- createdBy: "Bobby Tables",- fields: ["User ID"],- });-- H.DependencyDiagnostics.list()- .findByText(MODEL_FOR_MODEL_DATA_SOURCE)- .click();- checkSidebar({- title: MODEL_FOR_MODEL_DATA_SOURCE,- location: "First collection",- createdBy: "Bobby Tables",- });-- H.DependencyDiagnostics.list()- .findByText(SEGMENT_FOR_QUESTION_FILTER)- .click();- checkSidebar({- title: SEGMENT_FOR_QUESTION_FILTER,- location: "Orders",- createdBy: "Bobby Tables",- });-- H.DependencyDiagnostics.list()- .findByText(METRIC_FOR_QUESTION_AGGREGATION)- .click();- checkSidebar({- title: METRIC_FOR_QUESTION_AGGREGATION,- location: "Our analytics",- createdBy: "Bobby Tables",- });-- H.DependencyDiagnostics.list()- .findByText(METRIC_FOR_MODEL_AGGREGATION)- .click();- checkSidebar({- title: METRIC_FOR_MODEL_AGGREGATION,- location: "First collection",- createdBy: "Bobby Tables",- });-- H.DependencyDiagnostics.list()- .findByText(SNIPPET_FOR_NATIVE_QUESTION_CARD_TAG)- .click();- checkSidebar({- title: SNIPPET_FOR_NATIVE_QUESTION_CARD_TAG,- location: "SQL snippets",- createdBy: "Bobby Tables",- });-- cy.log("snowplow event when dependency graph link is clicked");- cy.findByRole("link", { name: "View in dependency graph" }).click();- H.expectUnstructuredSnowplowEvent({- event: "dependency_entity_selected",- triggered_from: "diagnostics-unreferenced-list",- event_detail: "snippet",- });- });- });-});--function setupEntities({- withReferences = false,-}: { withReferences?: boolean } = {}) {- setupTableContent({ withReferences });- setupModelContent({ withReferences });- setupSegmentContent({ withReferences });- setupMetricContent({ withReferences });- setupSnippetContent({ withReferences });-}--function setupTableContent({- withReferences = false,-}: {- withReferences?: boolean;-}) {- H.getTableId({ name: TABLE_NAME }).then((tableId) => {- cy.request("PUT", `/api/table/${tableId}`, {- display_name: TABLE_DISPLAY_NAME,- description: TABLE_DESCRIPTION,- owner_user_id: ADMIN_USER_ID,- }).then(() => {- if (withReferences) {- createQuestionWithTableDataSource({- name: `${TABLE_DISPLAY_NAME} -> Question`,- tableId,- });- }- });- });-}--function setupModelContent({- withReferences = false,-}: {- withReferences?: boolean;-}) {- createModelWithTableDataSource({- name: MODEL_FOR_QUESTION_DATA_SOURCE,- tableId: ORDERS_ID,- }).then(({ body: model }) => {- if (withReferences) {- createQuestionWithModelDataSource({- name: `${MODEL_FOR_QUESTION_DATA_SOURCE} -> Question`,- modelId: model.id,- });- }- });-- createModelWithTableDataSource({- name: MODEL_FOR_MODEL_DATA_SOURCE,- tableId: ORDERS_ID,- collectionId: FIRST_COLLECTION_ID,- }).then(({ body: model }) => {- if (withReferences) {- createModelWithModelDataSource({- name: `${MODEL_FOR_MODEL_DATA_SOURCE} -> Model`,- modelId: model.id,- });- }- });-- createModelWithTableDataSource({- name: MODEL_FOR_METRIC_DATA_SOURCE,- tableId: ORDERS_ID,- collectionId: ADMIN_PERSONAL_COLLECTION_ID,- }).then(({ body: model }) => {- if (withReferences) {- createMetricWithModelDataSource({- name: `${MODEL_FOR_METRIC_DATA_SOURCE} -> Metric`,- modelId: model.id,- });- }- });-- createModelWithTableDataSource({- name: MODEL_FOR_NATIVE_QUESTION_CARD_TAG,- tableId: ORDERS_ID,- }).then(({ body: model }) => {- if (withReferences) {- createNativeQuestionWithCardTag({- name: `${MODEL_FOR_NATIVE_QUESTION_CARD_TAG} -> Question`,- cardId: model.id,- });- }- });-- createModelWithTableDataSource({- name: MODEL_FOR_NATIVE_QUESTION_PARAMETER_SOURCE,- tableId: PRODUCTS_ID,- }).then(({ body: model }) => {- if (withReferences) {- createNativeQuestionWithParameterWithCardSource({- name: `${MODEL_FOR_NATIVE_QUESTION_PARAMETER_SOURCE} -> Question`,- tableName: "PRODUCTS",- tableFieldId: PRODUCTS.CATEGORY,- cardId: model.id,- cardFieldName: "CATEGORY",- });- }- });-- createModelWithTableDataSource({- name: MODEL_FOR_DASHBOARD_CARD,- tableId: ORDERS_ID,- }).then(({ body: model }) => {- if (withReferences) {- createDashboardWithCard({- name: `${MODEL_FOR_DASHBOARD_CARD} -> Dashboard Card`,- cardId: model.id,- });- }- });-- createModelWithTableDataSource({- name: MODEL_FOR_DASHBOARD_PARAMETER_SOURCE,- tableId: PRODUCTS_ID,- }).then(({ body: model }) => {- if (withReferences) {- createDashboardWithParameterWithCardSource({- name: `${MODEL_FOR_DASHBOARD_PARAMETER_SOURCE} -> Dashboard`,- cardId: model.id,- cardFieldName: "CATEGORY",- });- }- });-}--function setupSegmentContent({- withReferences = false,-}: {- withReferences?: boolean;-}) {- createSegmentWithTableDataSource({- name: SEGMENT_FOR_QUESTION_FILTER,- tableId: ORDERS_ID,- }).then(({ body: segment }) => {- if (withReferences) {- createQuestionWithSegmentClause({- name: `${SEGMENT_FOR_QUESTION_FILTER} -> Question`,- tableId: ORDERS_ID,- segmentId: segment.id,- });- }- });-- createSegmentWithTableDataSource({- name: SEGMENT_FOR_MODEL_FILTER,- tableId: ORDERS_ID,- }).then(({ body: segment }) => {- if (withReferences) {- createModelWithSegmentClause({- name: `${SEGMENT_FOR_MODEL_FILTER} -> Model`,- tableId: ORDERS_ID,- segmentId: segment.id,- });- }- });-- createSegmentWithTableDataSource({- name: SEGMENT_FOR_SEGMENT_FILTER,- tableId: ORDERS_ID,- }).then(({ body: segment }) => {- if (withReferences) {- createSegmentWithSegmentClause({- name: `${SEGMENT_FOR_SEGMENT_FILTER} -> Segment`,- tableId: ORDERS_ID,- segmentId: segment.id,- });- }- });-- createSegmentWithTableDataSource({- name: SEGMENT_FOR_METRIC_FILTER,- tableId: ORDERS_ID,- }).then(({ body: segment }) => {- if (withReferences) {- createMetricWithSegmentClause({- name: `${SEGMENT_FOR_METRIC_FILTER} -> Metric`,- tableId: ORDERS_ID,- segmentId: segment.id,- });- }- });-}--function setupMetricContent({- withReferences = false,-}: {- withReferences?: boolean;-}) {- createMetricWithTableDataSource({- name: METRIC_FOR_QUESTION_AGGREGATION,- tableId: ORDERS_ID,- }).then(({ body: metric }) => {- if (withReferences) {- createQuestionWithMetricClause({- name: `${METRIC_FOR_QUESTION_AGGREGATION} -> Question`,- tableId: ORDERS_ID,- metricId: metric.id,- });- }- });-- createMetricWithTableDataSource({- name: METRIC_FOR_MODEL_AGGREGATION,- tableId: ORDERS_ID,- collectionId: FIRST_COLLECTION_ID,- }).then(({ body: metric }) => {- if (withReferences) {- createModelWithMetricClause({- name: `${METRIC_FOR_MODEL_AGGREGATION} -> Model`,- tableId: ORDERS_ID,- metricId: metric.id,- });- }- });-- createMetricWithTableDataSource({- name: METRIC_FOR_METRIC_AGGREGATION,- tableId: ORDERS_ID,- }).then(({ body: metric }) => {- if (withReferences) {- createMetricWithMetricClause({- name: `${METRIC_FOR_METRIC_AGGREGATION} -> Metric`,- tableId: ORDERS_ID,- metricId: metric.id,- });- }- });-- createMetricWithTableDataSource({- name: METRIC_FOR_DASHBOARD_CARD,- tableId: ORDERS_ID,- }).then(({ body: metric }) => {- if (withReferences) {- createDashboardWithCard({- name: `${METRIC_FOR_DASHBOARD_CARD} -> Dashboard Card`,- cardId: metric.id,- });- }- });-}--function setupSnippetContent({- withReferences = false,-}: {- withReferences?: boolean;-}) {- createSnippetWithBasicFilter({- name: SNIPPET_FOR_NATIVE_QUESTION_CARD_TAG,- }).then(({ body: snippet }) => {- if (withReferences) {- createNativeQuestionWithSnippetTag({- name: `${SNIPPET_FOR_NATIVE_QUESTION_CARD_TAG} -> Question`,- tableName: "ORDERS",- snippetId: snippet.id,- snippetName: snippet.name,- });- }- });-- createSnippetWithBasicFilter({ name: SNIPPET_FOR_SNIPPET_TAG }).then(- ({ body: snippet }) => {- if (withReferences) {- createSnippetWithSnippetTag({- name: `${SNIPPET_FOR_SNIPPET_TAG} -> Snippet`,- snippetName: snippet.name,- });- }- },- );-}--function createQuestionWithModelDataSource({- name,- modelId,-}: {- name: string;- modelId: CardId;-}) {- return H.createQuestion({- name,- type: "question",- query: {- "source-table": `card__${modelId}`,- },- });-}--function createQuestionWithTableDataSource({- name,- tableId,-}: {- name: string;- tableId: TableId;-}) {- return H.createQuestion({- name,- type: "question",- query: {- "source-table": tableId,- },- });-}--function createQuestionWithSegmentClause({- name,- tableId,- segmentId,-}: {- name: string;- tableId: TableId;- segmentId: SegmentId;-}) {- return H.createQuestion({- name,- type: "question",- query: {- "source-table": tableId,- filter: ["segment", segmentId],- },- });-}--function createQuestionWithMetricClause({- name,- tableId,- metricId,-}: {- name: string;- tableId: TableId;- metricId: CardId;-}) {- return H.createQuestion({- name,- type: "question",- query: {- "source-table": tableId,- aggregation: [["metric", metricId]],- },- });-}--function createNativeQuestionWithCardTag({- name,- cardId,-}: {- name: string;- cardId: CardId;-}) {- const tagName = `#${cardId}`;-- return H.createNativeQuestion({- name,- type: "question",- native: {- query: `select * from {{${tagName}}}`,- "template-tags": {- [tagName]: {- id: "10422a0f-292d-10a3-fd90-407cc9e3e20e",- type: "card",- name: tagName,- "display-name": tagName,- "card-id": cardId,- },- },- },- });-}--function createNativeQuestionWithParameterWithCardSource({- name,- tableName,- tableFieldId,- cardId,- cardFieldName,-}: {- name: string;- tableName: string;- tableFieldId: FieldId;- cardId: CardId;- cardFieldName: string;-}) {- return H.createNativeQuestion({- name,- native: {- query: `select * from ${tableName} where {{filter}}`,- "template-tags": {- filter: {- id: "10422a0f-292d-10a3-fd90-407cc9e3e20e",- type: "dimension",- name: "filter",- "display-name": "Filter",- dimension: ["field", tableFieldId, null],- "widget-type": "string/=",- },- },- },- parameters: [- createMockParameter({- id: "10422a0f-292d-10a3-fd90-407cc9e3e20e",- name: "Filter",- slug: "filter",- type: "string/=",- target: ["dimension", ["template-tag", "filter"]],- values_source_type: "card",- values_source_config: {- card_id: cardId,- value_field: ["field", cardFieldName, { "base-type": "type/Text" }],- },- }),- ],- });-}--function createNativeQuestionWithSnippetTag({- name,- tableName,- snippetId,- snippetName,-}: {- name: string;- tableName: string;- snippetId: NativeQuerySnippetId;- snippetName: string;-}) {- const tagName = `snippet: ${snippetName}`;-- return H.createNativeQuestion({- name,- type: "question",- native: {- query: `select * from ${tableName} where {{${tagName}}}`,- "template-tags": {- [tagName]: {- id: "10422a0f-292d-10a3-fd90-407cc9e3e20e",- type: "snippet",- name: tagName,- "display-name": snippetName,- "snippet-id": snippetId,- "snippet-name": snippetName,- },- },- },- });-}--function createModelWithTableDataSource({- name,- tableId,- collectionId,-}: {- name: string;- tableId: TableId;- collectionId?: CollectionId;-}) {- return H.createQuestion({- name,- type: "model",- query: {- "source-table": tableId,- },- collection_id: collectionId,- });-}--function createModelWithModelDataSource({- name,- modelId,-}: {- name: string;- modelId: CardId;-}) {- return H.createQuestion({- name,- type: "model",- query: {- "source-table": `card__${modelId}`,- },- });-}--function createModelWithSegmentClause({- name,- tableId,- segmentId,-}: {- name: string;- tableId: TableId;- segmentId: SegmentId;-}) {- return H.createQuestion({- name,- type: "model",- query: {- "source-table": tableId,- filter: ["segment", segmentId],- },- });-}--function createModelWithMetricClause({- name,- tableId,- metricId,-}: {- name: string;- tableId: TableId;- metricId: CardId;-}) {- return H.createQuestion({- name,- type: "model",- query: {- "source-table": tableId,- aggregation: [["metric", metricId]],- },- });-}--function createSegmentWithTableDataSource({- name,- tableId,-}: {- name: string;- tableId: TableId;-}) {- return H.createSegment({- name,- definition: {- database: SAMPLE_DB_ID,- type: "query",- query: {- "source-table": tableId,- filter: ["=", "A", "A"],- },- },- });-}--function createSegmentWithSegmentClause({- name,- tableId,- segmentId,-}: {- name: string;- tableId: TableId;- segmentId: SegmentId;-}) {- return H.createSegment({- name,- definition: {- database: SAMPLE_DB_ID,- type: "query",- query: {- "source-table": tableId,- filter: ["segment", segmentId],- },- },- });-}--function createMetricWithTableDataSource({- name,- tableId,- collectionId,-}: {- name: string;- tableId: TableId;- collectionId?: CollectionId;-}) {- return H.createQuestion({- name,- type: "metric",- query: {- "source-table": tableId,- aggregation: [["count"]],- },- collection_id: collectionId,- });-}--function createMetricWithModelDataSource({- name,- modelId,-}: {- name: string;- modelId: CardId;-}) {- return H.createQuestion({- name,- type: "metric",- query: {- "source-table": `card__${modelId}`,- aggregation: [["count"]],- },- });-}--function createMetricWithSegmentClause({- name,- tableId,- segmentId,-}: {- name: string;- tableId: TableId;- segmentId: SegmentId;-}) {- return H.createQuestion({- name,- type: "metric",- query: {- "source-table": tableId,- filter: ["segment", segmentId],- aggregation: [["count"]],- },- });-}--function createMetricWithMetricClause({- name,- tableId,- metricId,-}: {- name: string;- tableId: TableId;- metricId: CardId;-}) {- return H.createQuestion({- name,- type: "metric",- query: {- "source-table": tableId,- aggregation: [["metric", metricId]],- },- });-}--function createSnippetWithBasicFilter({ name }: { name: string }) {- return H.createSnippet({- name,- content: "1 = 1",- });-}--function createSnippetWithSnippetTag({- name,- snippetName,-}: {- name: string;- snippetName: string;-}) {- return H.createSnippet({- name,- content: `{{snippet: ${snippetName}}}`,- });-}--function createDashboardWithCard({- name,- cardId,-}: {- name: string;- cardId: CardId;-}) {- return H.createDashboard({ name }).then(({ body: dashboard }) => {- H.updateDashboardCards({- dashboard_id: dashboard.id,- cards: [- {- card_id: cardId,- },- ],- });- });-}--function createDashboardWithParameterWithCardSource({- name,- cardId,- cardFieldName,-}: {- name: string;- cardId: CardId;- cardFieldName: string;-}) {- return H.createDashboard({- name,- parameters: [- createMockParameter({- id: "10422a0f",- name: "Filter",- slug: "filter",- type: "string/=",- values_source_type: "card",- values_source_config: {- card_id: cardId,- value_field: ["field", cardFieldName, { "base-type": "type/Text" }],- },- }),- ],- });-}--function getNodeName(node: DependencyNode): string | null | undefined {- if (node.type === "table") {- return node.data.display_name;- }- return "name" in node.data ? node.data.name : undefined;-}--// The dependency graph is recomputed asynchronously when entities are created or-// updated (metabase#71037). `waitForBackfillComplete` only reports the global-// one-time backfill flag — it does NOT guarantee the entities `setupEntities()`-// just created have been classified into the unreferenced graph. The list page-// fires a single query on load, so visiting before that async analysis finishes-// renders an incomplete list and the `findByText` assertions time out (4000ms).-//-// Poll the unreferenced endpoint until every expected entity is present before-// visiting. Defaults to the full seeded set, which is a superset of what any-// individual test asserts, so a single arg-free call makes every list test-// deterministic. The writable-Postgres table reaches the graph via the slower-// async DB-sync path, so it is covered here too. Mirrors the broken-list spec's-// `waitForBreakingDependencies` guard.-function waitForUnreferencedAnalysis(expectedNames: string[] = ENTITY_NAMES) {- H.waitForBackfillComplete();- H.waitForUnreferencedEntities((nodes) => {- const presentNames = new Set(nodes.map(getNodeName));- return expectedNames.every((name) => presentNames.has(name));- });-}--function checkList({- visibleEntities = [],- hiddenEntities = [],-}: {- visibleEntities?: string[];- hiddenEntities?: string[];-}) {- H.DependencyDiagnostics.list().within(() => {- visibleEntities.forEach((name) => {- cy.findByText(name).scrollIntoView().should("be.visible");- });- hiddenEntities.forEach((name) => {- cy.findByText(name).should("not.exist");- });- });-}--function checkListSorting({ visibleEntities }: { visibleEntities: string[] }) {- H.DependencyDiagnostics.list().within(() => {- visibleEntities.forEach((name, index) => {- cy.findByText(name)- .parents("[data-index]")- .should("have.attr", "data-index", index.toString());- });- });-}--function checkSidebar({- title,- location,- description,- owner,- createdBy,- fields = [],-}: {- title: string;- location?: string;- description?: string;- owner?: string;- createdBy?: string;- fields?: string[];-}) {- const Sidebar = H.DependencyDiagnostics.Sidebar;-- H.DependencyDiagnostics.sidebar().within(() => {- Sidebar.header().findByText(title).should("be.visible");- if (location) {- Sidebar.locationSection()- .findByText(location)- .scrollIntoView()- .should("be.visible");- }- if (description) {- Sidebar.infoSection().should("contain.text", description);- }- if (owner) {- Sidebar.infoSection().should("contain.text", owner);- }- if (createdBy) {- Sidebar.infoSection().should("contain.text", createdBy);- }- if (fields.length > 0) {- Sidebar.fieldsSection().within(() => {- fields.forEach((field) => {- cy.findByText(field).scrollIntoView().should("be.visible");- });- });- }- });-}