From c2913b756b3719512f11d85c3bf43e91500e2845 Mon Sep 17 00:00:00 2001 From: Nemanja Glumac <31325167+nemanjaglumac@users.noreply.github.com> Date: Wed, 25 May 2022 17:00:00 +0200 Subject: [PATCH] Repros #22859: Multi-level nested questions with joins incorrect column aliasing (#22922) --- ...lti-nested-joins-wrong-aliasing.cy.spec.js | 108 ++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100644 frontend/test/metabase/scenarios/joins/reproductions/22859-multi-nested-joins-wrong-aliasing.cy.spec.js diff --git a/frontend/test/metabase/scenarios/joins/reproductions/22859-multi-nested-joins-wrong-aliasing.cy.spec.js b/frontend/test/metabase/scenarios/joins/reproductions/22859-multi-nested-joins-wrong-aliasing.cy.spec.js new file mode 100644 index 00000000000..9edecd61133 --- /dev/null +++ b/frontend/test/metabase/scenarios/joins/reproductions/22859-multi-nested-joins-wrong-aliasing.cy.spec.js @@ -0,0 +1,108 @@ +import { + restore, + popover, + visualize, + startNewQuestion, + openOrdersTable, +} from "__support__/e2e/cypress"; + +import { SAMPLE_DATABASE } from "__support__/e2e/cypress_sample_database"; + +const { REVIEWS, REVIEWS_ID, PRODUCTS, PRODUCTS_ID } = SAMPLE_DATABASE; + +const questionDetails = { + name: "22859-Q1", + query: { + "source-table": REVIEWS_ID, + joins: [ + { + fields: "all", + "source-table": PRODUCTS_ID, + condition: [ + "=", + ["field", REVIEWS.PRODUCT_ID, null], + ["field", PRODUCTS.ID, { "join-alias": "Products" }], + ], + alias: "Products", + }, + ], + }, +}; + +describe.skip("issue 22859 - multiple levels of nesting", () => { + beforeEach(() => { + cy.intercept("POST", "/api/card").as("saveQuestion"); + + restore(); + cy.signInAsAdmin(); + + cy.createQuestion(questionDetails, { wrapId: true, idAlias: "q1Id" }); + + // Join Orders table with the previously saved question and save it again + openOrdersTable({ mode: "notebook" }); + cy.findByText("Join data").click(); + + popover().within(() => { + cy.findByText("Sample Database").click(); + cy.findByText("Saved Questions").click(); + cy.findByText(questionDetails.name).click(); + }); + + popover() + .contains("Product ID") + .click(); + + popover() + .contains("Product ID") + .click(); + + visualize(); + + saveQuestion("22859-Q2"); + + cy.wait("@saveQuestion").then(({ response: { body } }) => + cy.wrap(body.id).as("q2Id"), + ); + + getJoinedTableColumnHeader(); + }); + + it("model based on multi-level nested saved question should work (metabase#22859-1)", () => { + cy.get("@q2Id").then(id => { + // Convert the second question to a model + cy.request("PUT", `/api/card/${id}`, { dataset: true }); + + cy.visit(`/model/${id}`); + cy.wait("@dataset"); + }); + + getJoinedTableColumnHeader(); + }); + + it("third level of nesting with joins should result in proper column aliasing (metabase#22859-2)", () => { + startNewQuestion(); + cy.findByText("Saved Questions").click(); + cy.findByText("22859-Q2").click(); + + visualize(); + + getJoinedTableColumnHeader(); + }); +}); + +function saveQuestion(name) { + cy.findByText("Save").click(); + cy.findByDisplayValue("Orders") + .clear() + .type(name) + .blur(); + + cy.button("Save").click(); + cy.button("Not now").click(); +} + +function getJoinedTableColumnHeader() { + cy.get("@q1Id").then(id => { + cy.findByText(`Question ${id} → ID`); + }); +} -- GitLab