Skip to content

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

Consolidate schema viewer e2e tests (#83739)

Nemanja Glumacad2aee04d601
diff --git a/e2e/test/scenarios/schema-viewer/schema-viewer.cy.spec.ts b/e2e/test/scenarios/data-studio/schema-viewer.cy.spec.ts
similarity index 87%
rename from e2e/test/scenarios/schema-viewer/schema-viewer.cy.spec.ts
rename to e2e/test/scenarios/data-studio/schema-viewer.cy.spec.ts
index 0ed91ba3156..434a2b855af 100644
--- a/e2e/test/scenarios/schema-viewer/schema-viewer.cy.spec.ts
+++ b/e2e/test/scenarios/data-studio/schema-viewer.cy.spec.ts
@@ -18,6 +18,7 @@ const ERD_ALIAS = "erd";
// Layout constants mirrored from the SchemaViewer source. Keep in sync.
const MIN_ZOOM = 0.3;
const MIN_ZOOM_FOR_TARGET = 0.5;
+const TOP_MARGIN_PX = 50;
const SV_SCHEMA = "sv_test";
const SV_EXTRA_SCHEMA = "sv_extra";
@@ -108,26 +109,29 @@ function assertNodeInViewport(tableId: TableId) {
});
}
-describe("scenarios > schema-viewer (premium gating)", () => {
- beforeEach(() => {
- H.restore();
- cy.signInAsAdmin();
- cy.intercept("GET", "/api/ee/erd*").as(ERD_ALIAS);
- });
-
- it("renders the upsell page and never calls the ERD endpoint when :dependencies is not licensed", () => {
- cy.log("Visit the schema viewer URL without activating a token");
- cy.visit(BASE_URL);
-
- cy.log("Upsell page is shown");
- cy.findByRole("heading", {
- name: "Visualize your database structure",
- }).should("be.visible");
-
- cy.log("ERD endpoint was never called");
- cy.get(`@${ERD_ALIAS}.all`).should("have.length", 0);
+// Every camera move onto a table centres it horizontally and puts its top
+// edge TOP_MARGIN_PX below the top of the canvas.
+function assertNodeFocused(tableId: TableId) {
+ cy.get(".react-flow").should(($reactFlowNode) => {
+ const viewportRect = $reactFlowNode[0].getBoundingClientRect();
+ const $tableNode = Cypress.$(`[data-id="table-${tableId}"]`);
+ expect(
+ $tableNode.length,
+ `table-${tableId} should be in the DOM`,
+ ).to.be.greaterThan(0);
+ const tableNodeRect = $tableNode[0].getBoundingClientRect();
+ expect(
+ tableNodeRect.top - viewportRect.top,
+ `table-${tableId} top edge should be ${TOP_MARGIN_PX}px below the canvas top`,
+ ).to.be.closeTo(TOP_MARGIN_PX, 2);
+ const viewportCenterX = (viewportRect.left + viewportRect.right) / 2;
+ expect(
+ tableNodeRect.left < viewportCenterX &&
+ tableNodeRect.right > viewportCenterX,
+ `table-${tableId} should span the horizontal centre of the canvas`,
+ ).to.be.true;
});
-});
+}
describe("scenarios > schema-viewer (Sample Database happy path)", () => {
beforeEach(() => {
@@ -137,7 +141,7 @@ describe("scenarios > schema-viewer (Sample Database happy path)", () => {
cy.intercept("GET", "/api/ee/erd*").as(ERD_ALIAS);
});
- it("walks the full picker → canvas → selection → info panel → search → layout flow on the Sample Database", () => {
+ it("walks the full picker → canvas → selection → info panel → layout → search flow on the Sample Database, then keeps it across a reload and a bare-URL visit", () => {
cy.log("Bare URL renders the empty state with the picker auto-opened");
cy.visit(BASE_URL);
cy.findByTestId("schema-picker-button")
@@ -189,7 +193,7 @@ describe("scenarios > schema-viewer (Sample Database happy path)", () => {
MIN_ZOOM_FOR_TARGET,
),
);
- assertNodeInViewport(ORDERS_ID);
+ assertNodeFocused(ORDERS_ID);
cy.log(
"Click an FK link inside the info panel — camera pans to the target",
@@ -197,7 +201,7 @@ describe("scenarios > schema-viewer (Sample Database happy path)", () => {
infoPanel()
.findByRole("button", { name: /Products/i })
.click();
- assertNodeInViewport(PRODUCTS_ID);
+ assertNodeFocused(PRODUCTS_ID);
cy.log("Selection stays on Orders after FK link click");
infoPanel().findByRole("heading", { name: "ORDERS" }).should("be.visible");
@@ -222,10 +226,10 @@ describe("scenarios > schema-viewer (Sample Database happy path)", () => {
MIN_ZOOM_FOR_TARGET,
),
);
- assertNodeInViewport(ORDERS_ID);
+ assertNodeFocused(ORDERS_ID);
cy.log(
- "Double-click Reviews — camera zooms in onto Reviews and re-enables the focus-node button",
+ "Double-click Reviews — camera zooms in onto Reviews; the focus-node button stays shown",
);
tableNode(REVIEWS_ID).findByText("REVIEWS").dblclick();
assertViewportZoom((z) =>
@@ -233,8 +237,8 @@ describe("scenarios > schema-viewer (Sample Database happy path)", () => {
MIN_ZOOM_FOR_TARGET,
),
);
- assertNodeInViewport(REVIEWS_ID);
- cy.contains("button", "Focus node").should("not.be.disabled");
+ assertNodeFocused(REVIEWS_ID);
+ cy.contains("button", "Focus node").should("be.visible");
cy.log("Selection moved from Orders to Reviews — prior selection cleared");
infoPanel().findByRole("heading", { name: "REVIEWS" }).should("be.visible");
@@ -250,36 +254,28 @@ describe("scenarios > schema-viewer (Sample Database happy path)", () => {
);
tableNode(ORDERS_ID).findByText("USER_ID").click({ force: true });
- assertNodeInViewport(PEOPLE_ID);
+ assertNodeFocused(PEOPLE_ID);
cy.findAllByTestId("schema-viewer-edge-path")
.filter('[data-selected="true"]')
.should("have.length", 1);
cy.log(
- "Re-clicking the now-selected edge alternates the camera between source and target endpoints",
+ "Re-clicking the now-selected edge alternates the camera between source (Orders) and target (People)",
);
const selectedEdge = () => cy.get(".react-flow__edge.selected");
selectedEdge().click({ force: true });
- reactFlowViewport().invoke("attr", "style").as("zoomToSourceEnd");
+ assertNodeFocused(ORDERS_ID);
selectedEdge().click({ force: true });
- cy.get<string>("@zoomToSourceEnd").then((sourceTransform) => {
- reactFlowViewport()
- .invoke("attr", "style")
- .should((style) =>
- expect(
- style,
- "next click on the same edge should zoom to the OTHER endpoint",
- ).to.not.equal(sourceTransform),
- );
- });
+ assertNodeFocused(PEOPLE_ID);
cy.log(
"Search input filters by name; selecting an option triggers the camera",
);
searchInput().click().should("be.focused").type("ord");
- cy.findByRole("option", { name: /Orders/i }).should("be.visible");
- searchInput().type("{enter}");
- assertNodeInViewport(ORDERS_ID);
+ cy.findByRole("option", { name: /Orders/i })
+ .should("be.visible")
+ .click();
+ assertNodeFocused(ORDERS_ID);
cy.log("Empty result shows 'No tables found'");
searchInput().click().clear().type("zzz_nope_zzz");
@@ -287,13 +283,6 @@ describe("scenarios > schema-viewer (Sample Database happy path)", () => {
.findByText("No tables found")
.should("be.visible");
searchInput().type("{esc}");
- });
-
- it("URL state survives a hard reload, and the bare URL redirects back to the last opened (DB, schema)", () => {
- cy.log("Deep-link directly to Sample DB → PUBLIC");
- cy.visit(`${BASE_URL}?database-id=${SAMPLE_DB_ID}&schema=${PUBLIC_SCHEMA}`);
- cy.wait("@erd");
- tableNode(ORDERS_ID).should("be.visible");
cy.log("Hard reload reproduces the same canvas state");
cy.reload();
@@ -308,25 +297,24 @@ describe("scenarios > schema-viewer (Sample Database happy path)", () => {
.should("include", `database-id=${SAMPLE_DB_ID}`)
.and("include", `schema=${PUBLIC_SCHEMA}`);
tableNode(ORDERS_ID).should("be.visible");
- });
-
- it("opens the picker with the current selection highlighted, and supports Back navigation between databases and schemas", () => {
- cy.visit(`${BASE_URL}?database-id=${SAMPLE_DB_ID}&schema=${PUBLIC_SCHEMA}`);
- cy.wait("@erd");
- tableNode(ORDERS_ID).should("be.visible");
cy.log("Picker trigger shows the current schema name");
schemaPickerTrigger().should("contain", PUBLIC_SCHEMA);
cy.log(
- "Open the picker — drills directly into the schema list of the current DB",
+ "The picker opened on the bare URL stays open at the database list after the redirect",
);
- schemaPickerTrigger().click();
H.miniPicker().findByText("Sample Database").should("be.visible");
+ H.miniPicker().findByTestId("mini-picker-header").should("not.exist");
cy.log("Click outside the popover closes it");
cy.get("body").click(0, 0);
H.miniPicker().should("not.exist");
+
+ cy.log("The trigger re-opens the picker at the database list");
+ schemaPickerTrigger().click();
+ H.miniPicker().findByText("Sample Database").should("be.visible");
+ H.miniPicker().findByTestId("mini-picker-header").should("not.exist");
});
});
@@ -441,7 +429,7 @@ describe("scenarios > schema-viewer (writable Postgres: multi-schema, self-ref,
cy.wait("@erd");
cy.get<TableId>("@lookupId").then((id) => {
tableNode(id).should("be.visible");
- assertNodeInViewport(id);
+ assertNodeFocused(id);
});
cy.log("Edge count grows by one (products → lookup edge added)");
cy.get(".react-flow__edge").should("have.length", 3);
@@ -493,16 +481,34 @@ describe("scenarios > schema-viewer (writable Postgres: multi-schema, self-ref,
});
});
-describe("scenarios > schema-viewer (entry points + loader/error states)", () => {
+describe("scenarios > schema-viewer (upsell, entry points, loader and error states)", () => {
beforeEach(() => {
H.restore();
cy.signInAsAdmin();
- H.activateToken("bleeding-edge");
});
- it("Data Studio sidebar tab and Data Model 'Schema viewer' button both lead into the schema viewer", () => {
+ it("shows the upsell without :dependencies, then opens from the Data Studio sidebar (with a loader) and the Data Model 'View schema' action, and shows the error panel when the ERD request fails", () => {
cy.intercept("GET", "/api/ee/erd*").as(ERD_ALIAS);
+ cy.log("Visit the schema viewer URL without activating a token");
+ cy.visit(BASE_URL);
+
+ cy.log("Upsell page is shown");
+ cy.findByRole("heading", {
+ name: "Visualize your database structure",
+ }).should("be.visible");
+
+ cy.log("ERD endpoint was never called");
+ cy.get(`@${ERD_ALIAS}.all`).should("have.length", 0);
+
+ H.activateToken("bleeding-edge");
+ cy.intercept("GET", "/api/ee/erd*", (req) => {
+ req.on("response", (res) => {
+ res.setDelay(1500);
+ });
+ req.continue();
+ }).as("slowErd");
+
cy.log(
"Click 'Schema viewer' tab in the Data Studio sidebar — opens the bare schema viewer URL",
);
@@ -513,6 +519,16 @@ describe("scenarios > schema-viewer (entry points + loader/error states)", () =>
.findByText("Pick a schema to view")
.should("be.visible");
+ cy.log(
+ "Slow ERD response — the centred loader appears, then the canvas renders",
+ );
+ H.miniPicker().findByText("Sample Database").click();
+ H.miniPicker().findByText("PUBLIC").click();
+ cy.findByTestId("schema-viewer-loader").should("be.visible");
+ cy.wait("@slowErd");
+ cy.findByTestId("schema-viewer-loader").should("not.exist");
+ tableNode(ORDERS_ID).should("be.visible");
+
cy.log("Navigate to the Orders Data Model page via the table picker tree");
H.DataStudio.nav().findByText("Connected data").click();
cy.findAllByTestId("tree-item").contains("Orders").click();
@@ -522,17 +538,15 @@ describe("scenarios > schema-viewer (entry points + loader/error states)", () =>
);
H.DataModel.TableSection.getActionsMenuButton().click();
H.menu().findByText("View schema").click();
- cy.wait("@erd");
+ cy.wait("@slowErd");
cy.url()
.should("include", "/data-studio/schema-viewer")
.and("include", `database-id=${SAMPLE_DB_ID}`)
.and("include", `table-ids=${ORDERS_ID}`);
tableNode(ORDERS_ID).should("be.visible");
- cy.log("Focal table is on screen");
- assertNodeInViewport(ORDERS_ID);
- });
+ cy.log("Camera focuses the focal table");
+ assertNodeFocused(ORDERS_ID);
- it("renders the loader during a slow ERD fetch and the error panel when the request fails", () => {
cy.log("Force a 500 — error panel renders with the surfaced message");
cy.intercept("GET", "/api/ee/erd*", { statusCode: 500, body: "boom" }).as(
"erdError",
@@ -542,23 +556,6 @@ describe("scenarios > schema-viewer (entry points + loader/error states)", () =>
cy.findByTestId("schema-viewer-error")
.should("be.visible")
.should("contain", "boom");
- cy.log(
- "Slow the ERD response — the centred loader appears, then the canvas renders",
- );
- cy.intercept("GET", "/api/ee/erd*", (req) => {
- req.on("response", (res) => {
- res.setDelay(1500);
- });
- req.continue();
- }).as("slowErd");
- H.DataStudio.nav().findByLabelText("Semantic layer").click();
- H.DataStudio.nav().findByLabelText("Schema viewer").click();
- H.miniPicker().findByText("Sample Database").click();
- H.miniPicker().findByText("PUBLIC").click();
- cy.findByTestId("schema-viewer-loader").should("be.visible");
- cy.wait("@slowErd");
- cy.findByTestId("schema-viewer-loader").should("not.exist");
- tableNode(ORDERS_ID).should("be.visible");
});
});
diff --git a/enterprise/frontend/src/metabase-enterprise/schema_viewer/components/SchemaViewer/constants.ts b/enterprise/frontend/src/metabase-enterprise/schema_viewer/components/SchemaViewer/constants.ts
index c9f7ba7ff29..c674a692a48 100644
--- a/enterprise/frontend/src/metabase-enterprise/schema_viewer/components/SchemaViewer/constants.ts
+++ b/enterprise/frontend/src/metabase-enterprise/schema_viewer/components/SchemaViewer/constants.ts
@@ -3,7 +3,7 @@ export const HEADER_HEIGHT_PX = 56;
export const NODE_WIDTH_PX = 320;
const DEFAULT_ZOOM = 0.3;
-// (if this value changes, update the same constant in e2e/test/scenarios/schema-viewer/schema-viewer.cy.spec.ts)
+// (if this value changes, update the same constant in e2e/test/scenarios/data-studio/schema-viewer.cy.spec.ts)
export const MIN_ZOOM = 0.3;
export const MAX_ZOOM = 1;
export const FIT_VIEW_OPTIONS = {
diff --git a/enterprise/frontend/src/metabase-enterprise/schema_viewer/components/SchemaViewer/utils/zoom.ts b/enterprise/frontend/src/metabase-enterprise/schema_viewer/components/SchemaViewer/utils/zoom.ts
index 9b5f12d17f2..b7ba83a6d3c 100644
--- a/enterprise/frontend/src/metabase-enterprise/schema_viewer/components/SchemaViewer/utils/zoom.ts
+++ b/enterprise/frontend/src/metabase-enterprise/schema_viewer/components/SchemaViewer/utils/zoom.ts
@@ -8,7 +8,7 @@ type ZoomTarget = Pick<
"setCenter" | "getNodes"
>;
-// (if this value changes, update the same constant in e2e/test/scenarios/schema-viewer/schema-viewer.cy.spec.ts)
+// (if this value changes, update the same constant in e2e/test/scenarios/data-studio/schema-viewer.cy.spec.ts)
const MIN_ZOOM_FOR_TARGET = 0.5;
// How far below the viewport's top edge the header of the topmost target
// node should land.