Skip to content
Snippets Groups Projects
Unverified Commit f93c156e authored by Anton Kulyk's avatar Anton Kulyk Committed by GitHub
Browse files

Show model metadata changes revisions (#19913)

* Remove saving changes from `setColumnType` helper

* Use single POST request to create a model in cypress

* Add E2E test

* Display metadata editing revision events

* Change message
parent 829a608b
No related merge requests found
......@@ -93,7 +93,7 @@ const CHANGE_DESCRIPTIONS = {
[CHANGE_TYPE.REMOVE]: getCollectionChangeDescription,
},
// Questions
// Questions & Models
dataset: {
[CHANGE_TYPE.UPDATE]: (wasDataset, isDataset) =>
isDataset
......@@ -113,6 +113,11 @@ const CHANGE_DESCRIPTIONS = {
[CHANGE_TYPE.UPDATE]: t`changed the visualization settings`,
[CHANGE_TYPE.REMOVE]: t`changed the visualization settings`,
},
result_metadata: {
[CHANGE_TYPE.ADD]: t`edited the metadata`,
[CHANGE_TYPE.UPDATE]: t`edited the metadata`,
[CHANGE_TYPE.REMOVE]: t`edited the metadata`,
},
// Dashboards
cards: {
......
......@@ -276,6 +276,16 @@ describe("getRevisionDescription | questions", () => {
"changed this from a model to a saved question",
);
});
it("handles metadata changes for models", () => {
const revision = getSimpleRevision({
field: "result_metadata",
before: [{ foo: "" }],
after: [{ foo: "bar" }],
});
expect(getRevisionDescription(revision)).toBe("edited the metadata");
});
});
describe("getRevisionDescription | dashboards", () => {
......
......@@ -14,9 +14,7 @@ export function setColumnType(oldType, newType) {
cy.findByText(oldType).click();
cy.get(".ReactVirtualized__Grid.MB-Select").scrollTo("top");
cy.findByPlaceholderText("Search for a special type").type(newType);
cy.findByText(newType).click();
cy.button("Save changes").click();
}
export function mapColumnTo({ table, column } = {}) {
......
......@@ -48,6 +48,7 @@ describe("scenarios > models metadata", () => {
renameColumn("Subtotal", "Pre-tax");
setColumnType("No special type", "Cost");
cy.button("Save changes").click();
startQuestionFromModel("GUI Model");
......@@ -56,16 +57,16 @@ describe("scenarios > models metadata", () => {
});
it("should edit native model metadata", () => {
cy.createNativeQuestion({
name: "Native Model",
native: {
query: "SELECT * FROM ORDERS",
cy.createNativeQuestion(
{
name: "Native Model",
dataset: true,
native: {
query: "SELECT * FROM ORDERS",
},
},
}).then(({ body: { id: nativeModelId } }) => {
cy.request("PUT", `/api/card/${nativeModelId}`, { dataset: true });
cy.visit(`/model/${nativeModelId}`);
});
{ visitQuestion: true },
);
openDetailsSidebar();
......@@ -92,9 +93,60 @@ describe("scenarios > models metadata", () => {
setColumnType("No special type", "Cost");
cy.button("Save changes").click();
startQuestionFromModel("Native Model");
visualize();
cy.findByText("Pre-tax ($)");
});
it("should allow reverting to a specific metadata revision", () => {
cy.intercept("POST", "/api/revision/revert").as("revert");
cy.createNativeQuestion({
name: "Native Model",
dataset: true,
native: {
query: "SELECT * FROM ORDERS",
},
}).then(({ body: { id: nativeModelId } }) => {
cy.visit(`/model/${nativeModelId}/metadata`);
});
openColumnOptions("SUBTOTAL");
mapColumnTo({ table: "Orders", column: "Subtotal" });
setColumnType("No special type", "Cost");
cy.button("Save changes").click();
// Revision 1
cy.findByText("Subtotal ($)");
cy.findByText("Tax ($)").should("not.exist");
openDetailsSidebar();
cy.findByText("Customize metadata").click();
// Revision 2
openColumnOptions("TAX");
mapColumnTo({ table: "Orders", column: "Tax" });
setColumnType("No special type", "Cost");
cy.button("Save changes").click();
cy.findByText("Subtotal ($)");
cy.findByText("Tax ($)");
cy.reload();
openDetailsSidebar();
sidebar().within(() => {
cy.findByText("History").click();
cy.findAllByText("Revert")
.first()
.click();
});
cy.wait("@revert");
cy.findByText("Subtotal ($)");
cy.findByText("Tax ($)").should("not.exist");
cy.findByText("TAX");
});
});
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment