From a4fb40e49666d422620e6aa6752021cdb0c83de0 Mon Sep 17 00:00:00 2001
From: Uladzimir Havenchyk <125459446+uladzimirdev@users.noreply.github.com>
Date: Tue, 2 Apr 2024 18:40:21 +0300
Subject: [PATCH] Add repro test for a model that uses another model and both
 have custom column with the same name (#40851)

* Add repro test for a model that uses another model and both have custom column with the same name

* Skip test

* Update e2e/test/scenarios/models/reproductions/39150-model-with-same-custom-column-name.cy.spec.js

Co-authored-by: Kamil Mielnik <kamil@kamilmielnik.com>

* Update e2e/test/scenarios/models/reproductions/39150-model-with-same-custom-column-name.cy.spec.js

Co-authored-by: Kamil Mielnik <kamil@kamilmielnik.com>

* Convert to ts and add question

---------

Co-authored-by: Kamil Mielnik <kamil@kamilmielnik.com>
---
 ...el-with-same-custom-column-name.cy.spec.ts | 48 +++++++++++++++++++
 1 file changed, 48 insertions(+)
 create mode 100644 e2e/test/scenarios/models/reproductions/39150-model-with-same-custom-column-name.cy.spec.ts

diff --git a/e2e/test/scenarios/models/reproductions/39150-model-with-same-custom-column-name.cy.spec.ts b/e2e/test/scenarios/models/reproductions/39150-model-with-same-custom-column-name.cy.spec.ts
new file mode 100644
index 00000000000..89c1f3ff79f
--- /dev/null
+++ b/e2e/test/scenarios/models/reproductions/39150-model-with-same-custom-column-name.cy.spec.ts
@@ -0,0 +1,48 @@
+import { SAMPLE_DATABASE } from "e2e/support/cypress_sample_database";
+import { createQuestion, restore } from "e2e/support/helpers";
+
+const { ORDERS_ID, ORDERS } = SAMPLE_DATABASE;
+
+// TODO: unskip once 39150 is fixed
+describe.skip("issue 39150", () => {
+  beforeEach(() => {
+    restore();
+    cy.signInAsAdmin();
+  });
+
+  ["model", "question"].forEach(type => {
+    it(`should render results if a ${type} depends on a ${type} and both have the same custom column name (metabase#39150)`, () => {
+      createQuestion({
+        type,
+        name: `${type} 39150`,
+        query: {
+          "source-table": ORDERS_ID,
+          expressions: {
+            Total: ["+", ["field", ORDERS.TOTAL, null], 1],
+          },
+          limit: 5,
+        },
+      }).then(({ body: { id: questionId } }) => {
+        createQuestion(
+          {
+            type,
+            name: `${type} 39150 Child`,
+            query: {
+              "source-table": `card__${questionId}`,
+              expressions: {
+                Total: ["+", ["field", ORDERS.TOTAL, null], 1],
+              },
+            },
+          },
+          { visitQuestion: true },
+        );
+      });
+
+      cy.log("verify that rendered result has 3 'Total' columns");
+
+      cy.findAllByTestId("header-cell")
+        .filter(":contains('Total')")
+        .should("have.length", 3);
+    });
+  });
+});
-- 
GitLab