Skip to content
Snippets Groups Projects
Unverified Commit 58e81192 authored by Nemanja Glumac's avatar Nemanja Glumac Committed by GitHub
Browse files

Fix E2E models metadata flakes (#35188)

* Fix model metadata flakes

* Do not use hard-coded ID

* Tweak tests

* Make viewport wider in order to fit the table content
parent e43bf373
Branches
Tags
No related merge requests found
import { popover } from "e2e/support/helpers";
import { popover, interceptIfNotPreviouslyDefined } from "e2e/support/helpers";
export function saveMetadataChanges() {
interceptIfNotPreviouslyDefined({
method: "POST",
url: "/api/dataset",
alias: "dataset",
});
cy.intercept("PUT", `/api/card/*`).as("updateModelMetadata");
cy.findByTestId("dataset-edit-bar").button("Save changes").click();
cy.wait("@updateModelMetadata");
cy.findByTestId("dataset-edit-bar").should("not.exist");
cy.wait("@dataset");
}
export function openColumnOptions(column) {
cy.findByText(column).click();
const columnNameRegex = new RegExp(`^${column}$`);
cy.findAllByTestId("header-cell")
.contains(columnNameRegex)
.should("be.visible")
.click();
}
export function renameColumn(oldName, newName) {
......@@ -9,10 +29,14 @@ export function renameColumn(oldName, newName) {
}
export function setColumnType(oldType, newType) {
cy.findByText(oldType).click();
cy.findByTestId("sidebar-right")
.findAllByTestId("select-button")
.contains(oldType)
.click();
cy.get(".ReactVirtualized__Grid.MB-Select").scrollTo("top");
cy.findByPlaceholderText("Search for a special type").type(newType);
cy.findByText(newType).click();
popover().findByLabelText(newType).click();
}
export function mapColumnTo({ table, column } = {}) {
......
......@@ -104,8 +104,8 @@ export function selectFromDropdown(option, clickOpts) {
}
export function startQuestionFromModel(modelName) {
cy.findByText("New").click();
cy.findByText("Question").should("be.visible").click();
cy.findByTestId("app-bar").findByText("New").click();
popover().findByText("Question").should("be.visible").click();
cy.findByText("Models").click();
cy.findByText(modelName).click();
}
......@@ -14,12 +14,14 @@ import {
mapColumnTo,
setModelMetadata,
sidebar,
saveMetadataChanges,
} from "e2e/support/helpers";
import { ORDERS_QUESTION_ID } from "e2e/support/cypress_sample_instance_data";
import { SAMPLE_DATABASE } from "e2e/support/cypress_sample_database";
import { startQuestionFromModel } from "./helpers/e2e-models-helpers";
const { PEOPLE, PRODUCTS, PRODUCTS_ID, REVIEWS } = SAMPLE_DATABASE;
const { PEOPLE, PRODUCTS, PRODUCTS_ID, REVIEWS, ORDERS_ID, ORDERS } =
SAMPLE_DATABASE;
describe("scenarios > models metadata", () => {
beforeEach(() => {
......@@ -31,19 +33,25 @@ describe("scenarios > models metadata", () => {
describe("GUI model", () => {
beforeEach(() => {
// Convert saved question "Orders" into a model
cy.request("PUT", `/api/card/${ORDERS_QUESTION_ID}`, {
const modelDetails = {
name: "GUI Model",
query: {
"source-table": ORDERS_ID,
limit: 5,
},
dataset: true,
});
};
cy.visit(`/model/${ORDERS_QUESTION_ID}`);
cy.createQuestion(modelDetails).then(({ body: { id } }) => {
cy.visit(`/model/${id}`);
cy.wait("@dataset");
});
});
it("should edit GUI model metadata", () => {
openQuestionActions();
popover().findByTextEnsureVisible("89%").trigger("mouseenter");
popover().findByTextEnsureVisible("89%").realHover();
cy.findByTestId("tooltip-content").within(() => {
cy.findByText(
......@@ -54,55 +62,61 @@ describe("scenarios > models metadata", () => {
);
});
popover().findByText("Edit metadata").click();
popover().findByTextEnsureVisible("Edit metadata").click();
cy.url().should("include", "/metadata");
cy.findByTextEnsureVisible("Product ID");
openColumnOptions("Subtotal");
renameColumn("Subtotal", "Pre-tax");
setColumnType("No special type", "Cost");
cy.button("Save changes").click();
saveMetadataChanges();
cy.log(
"Ensure that a question created from this model inherits its metadata.",
);
startQuestionFromModel("GUI Model");
visualize();
cy.findByTestId("TableInteractive-root").findByText("Pre-tax ($)");
cy.findAllByTestId("header-cell")
.should("contain", "Pre-tax ($)")
.and("not.contain", "Subtotal");
});
it("allows for canceling changes", () => {
openQuestionActions();
popover().findByText("Edit metadata").click();
popover().findByTextEnsureVisible("Edit metadata").click();
openColumnOptions("Subtotal");
renameColumn("Subtotal", "Pre-tax");
setColumnType("No special type", "Cost");
cy.button("Cancel").click();
cy.findByTestId("dataset-edit-bar").button("Cancel").click();
modal().button("Discard changes").click();
cy.findByTestId("TableInteractive-root").findByText("Subtotal");
cy.findAllByTestId("header-cell")
.should("contain", "Subtotal")
.and("not.contain", "Pre-tax");
});
it("clears custom metadata when a model is turned back into a question", () => {
openQuestionActions();
popover().findByText("Edit metadata").click();
popover().findByTextEnsureVisible("Edit metadata").click();
openColumnOptions("Subtotal");
renameColumn("Subtotal", "Pre-tax");
setColumnType("No special type", "Cost");
cy.button("Save changes").click();
saveMetadataChanges();
cy.findAllByTestId("header-cell")
.should("contain", "Pre-tax ($)")
.and("not.contain", "Subtotal");
openQuestionActions();
popover().findByText("Turn back to saved question").click();
popover().findByTextEnsureVisible("Turn back to saved question").click();
cy.wait("@cardQuery");
cy.wait("@dataset");
cy.findByTestId("TableInteractive-root").findByText("Subtotal");
cy.findAllByTestId("header-cell")
.should("contain", "Subtotal")
.and("not.contain", "Pre-tax ($)");
});
});
......@@ -112,7 +126,7 @@ describe("scenarios > models metadata", () => {
name: "Native Model",
dataset: true,
native: {
query: "SELECT * FROM ORDERS",
query: "SELECT * FROM ORDERS LIMIT 5",
},
},
{ visitQuestion: true },
......@@ -120,9 +134,7 @@ describe("scenarios > models metadata", () => {
openQuestionActions();
popover().within(() => {
cy.findByTextEnsureVisible("37%").trigger("mouseenter");
});
popover().findByTextEnsureVisible("37%").realHover();
cy.findByTestId("tooltip-content").within(() => {
cy.findByText(
......@@ -133,25 +145,29 @@ describe("scenarios > models metadata", () => {
);
});
popover().findByText("Edit metadata").click();
popover().findByTextEnsureVisible("Edit metadata").click();
cy.url().should("include", "/metadata");
cy.findByTextEnsureVisible("PRODUCT_ID");
openColumnOptions("SUBTOTAL");
mapColumnTo({ table: "Orders", column: "Subtotal" });
renameColumn("Subtotal", "Pre-tax");
setColumnType("No special type", "Cost");
saveMetadataChanges();
cy.button("Save changes").click();
cy.findAllByTestId("header-cell")
.should("contain", "Pre-tax ($)")
.and("not.contain", "Subtotal");
cy.log(
"Ensure that a question created from this model inherits its metadata.",
);
startQuestionFromModel("Native Model");
visualize();
cy.findByTestId("TableInteractive-root").findByText("Pre-tax ($)");
cy.findAllByTestId("header-cell")
.should("contain", "Pre-tax ($)")
.and("not.contain", "Subtotal");
});
it("should allow setting column relations (metabase#29318)", () => {
......@@ -160,18 +176,18 @@ describe("scenarios > models metadata", () => {
name: "Native Model",
dataset: true,
native: {
query: "SELECT * FROM ORDERS",
query: "SELECT * FROM ORDERS LIMIT 5",
},
},
{ visitQuestion: true },
);
openQuestionActions();
popover().findByText("Edit metadata").click();
popover().findByTextEnsureVisible("Edit metadata").click();
openColumnOptions("USER_ID");
setColumnType("No special type", "Foreign Key");
sidebar().findByText("Select a target").click();
popover().findByText("People → ID").click();
cy.findByTestId("dataset-edit-bar").button("Save changes").click();
saveMetadataChanges();
// TODO: Not much to do with it at the moment beyond saving it.
// Check that the relation is automatically suggested in the notebook once it is implemented.
});
......@@ -182,25 +198,25 @@ describe("scenarios > models metadata", () => {
name: "Native Model",
dataset: true,
native: {
query: "SELECT * FROM ORDERS",
query: "SELECT * FROM ORDERS LIMIT 5",
},
},
{ visitQuestion: true },
);
openQuestionActions();
popover().within(() => {
cy.findByText("Edit query definition").click();
});
popover().findByTextEnsureVisible("Edit query definition").click();
cy.get(".ace_content").type(
"{selectAll}{backspace}SELECT TOTAL FROM ORDERS",
"{selectAll}{backspace}SELECT TOTAL FROM ORDERS LIMIT 5",
);
cy.findByTestId("editor-tabs-metadata-name").click();
cy.wait("@dataset");
cy.findByTestId("header-cell").should("have.length", 1);
cy.findAllByTestId("header-cell")
.should("have.length", 1)
.and("have.text", "TOTAL");
cy.findByLabelText("Display name").should("have.value", "TOTAL");
});
......@@ -211,34 +227,31 @@ describe("scenarios > models metadata", () => {
name: "Native Model",
dataset: true,
native: {
query: "SELECT * FROM ORDERS",
query: "SELECT * FROM ORDERS LIMIT 5",
},
}).then(({ body: { id: nativeModelId } }) => {
cy.visit(`/model/${nativeModelId}/metadata`);
cy.wait("@cardQuery");
cy.findByTextEnsureVisible("PRODUCT_ID");
});
openColumnOptions("SUBTOTAL");
mapColumnTo({ table: "Orders", column: "Subtotal" });
setColumnType("No special type", "Cost");
cy.button("Save changes").click();
saveMetadataChanges();
// Revision 1
cy.log("Revision 1");
cy.findAllByTestId("header-cell")
.should("contain", "Subtotal ($)")
.and("not.contain", "SUBTOTAL");
openQuestionActions();
popover().findByText("Edit metadata").click();
popover().findByTextEnsureVisible("Edit metadata").click();
cy.findByTextEnsureVisible("TAX");
// Revision 2
cy.log("Revision 2");
openColumnOptions("TAX");
mapColumnTo({ table: "Orders", column: "Tax" });
setColumnType("No special type", "Cost");
cy.button("Save changes").click();
saveMetadataChanges();
cy.findAllByTestId("header-cell")
.should("contain", "Subtotal ($)")
......@@ -260,14 +273,14 @@ describe("scenarios > models metadata", () => {
.and("contain", "TAX");
});
describe("native models metadata overwrites", () => {
describe("native models metadata overwrites", { viewportWidth: 1400 }, () => {
beforeEach(() => {
cy.createNativeQuestion(
{
name: "Native Model",
dataset: true,
native: {
query: "select * from orders",
query: "select * from orders limit 10",
},
},
{ wrapId: true, idAlias: "modelId" },
......@@ -278,7 +291,7 @@ describe("scenarios > models metadata", () => {
if (field.display_name === "USER_ID") {
return {
...field,
id: 11,
id: ORDERS.USER_ID,
display_name: "User ID",
semantic_type: "type/FK",
fk_target_field_id: PEOPLE.ID,
......@@ -295,8 +308,6 @@ describe("scenarios > models metadata", () => {
};
});
});
cy.intercept("POST", "/api/dataset").as("dataset");
});
it("should allow drills on FK columns", () => {
......@@ -311,10 +322,10 @@ describe("scenarios > models metadata", () => {
cy.findByTestId("object-detail").within(() => {
cy.findByText("68883"); // zip
cy.findAllByText("Hudson Borer");
cy.icon("close").click();
cy.wait("@dataset");
});
cy.go("back"); // close modal
cy.wait("@dataset");
cy.go("back"); // navigate away from drilled table
cy.wait("@dataset");
......@@ -374,17 +385,18 @@ describe("scenarios > models metadata", () => {
dataset: true,
query: {
"source-table": PRODUCTS_ID,
limit: 5,
},
};
cy.createQuestion(questionDetails, { visitQuestion: true });
cy.findAllByTestId("header-cell").should("not.contain", "Vendor");
openQuestionActions();
cy.findByTestId("TableInteractive-root")
.findByText("Vendor")
.should("not.exist");
popover().findByText("Edit metadata").click();
cy.findByTestId("TableInteractive-root")
.findByText("Vendor")
popover().findByTextEnsureVisible("Edit metadata").click();
cy.findAllByTestId("header-cell")
.contains(/^Vendor$/)
.should("be.visible");
});
});
......@@ -392,7 +404,7 @@ describe("scenarios > models metadata", () => {
function drillFK({ id }) {
cy.get(".Table-FK").contains(id).first().click();
popover().findByText("View details").click();
popover().findByTextEnsureVisible("View details").click();
}
function drillDashboardFK({ id }) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment