From dd6224d3217297bdb082ea4c663421a2e3dc3a04 Mon Sep 17 00:00:00 2001
From: Nemanja Glumac <31325167+nemanjaglumac@users.noreply.github.com>
Date: Fri, 23 Dec 2022 13:55:57 +0100
Subject: [PATCH] Repro #24839: Can't aggregate if source is the aggregated
 question (#27396)

---
 ...rce-question-with-summarization.cy.spec.js | 57 +++++++++++++++++++
 1 file changed, 57 insertions(+)
 create mode 100644 frontend/test/metabase/scenarios/question/reproductions/24839-summarize-source-question-with-summarization.cy.spec.js

diff --git a/frontend/test/metabase/scenarios/question/reproductions/24839-summarize-source-question-with-summarization.cy.spec.js b/frontend/test/metabase/scenarios/question/reproductions/24839-summarize-source-question-with-summarization.cy.spec.js
new file mode 100644
index 00000000000..bfcf68b3d04
--- /dev/null
+++ b/frontend/test/metabase/scenarios/question/reproductions/24839-summarize-source-question-with-summarization.cy.spec.js
@@ -0,0 +1,57 @@
+import { restore, visitQuestionAdhoc, popover } from "__support__/e2e/helpers";
+import { SAMPLE_DB_ID } from "__support__/e2e/cypress_data";
+import { SAMPLE_DATABASE } from "__support__/e2e/cypress_sample_database";
+
+const { ORDERS, ORDERS_ID } = SAMPLE_DATABASE;
+
+const questionDetails = {
+  name: "24839",
+  query: {
+    "source-table": ORDERS_ID,
+    aggregation: [
+      ["sum", ["field", ORDERS.QUANTITY, null]],
+      ["avg", ["field", ORDERS.TOTAL, null]],
+    ],
+    breakout: [["field", ORDERS.CREATED_AT, { "temporal-unit": "month" }]],
+  },
+  display: "line",
+};
+
+describe("issue 24839: should be able to summarize a nested question based on the source question with aggregations (metabase#24839)", () => {
+  beforeEach(() => {
+    restore();
+    cy.signInAsAdmin();
+
+    cy.createQuestion(questionDetails).then(({ body: { id } }) => {
+      // Start ad-hoc nested question based on the saved one
+      visitQuestionAdhoc({
+        dataset_query: {
+          database: SAMPLE_DB_ID,
+          query: { "source-table": `card__${id}` },
+          type: "query",
+        },
+      });
+    });
+  });
+
+  it.skip("from the notebook GUI (metabase#24839-1)", () => {
+    cy.icon("notebook").click();
+    cy.findByText("Summarize").click();
+    cy.findByText("Sum of ...").click();
+    popover()
+      .should("contain", "Sum of Quantity")
+      .and("contain", "Average of Total");
+  });
+
+  it("from a table header cell (metabase#24839-2)", () => {
+    cy.findAllByTestId("header-cell").contains("Average of Total").click();
+
+    popover().contains("Distinct values").click();
+
+    cy.get(".ScalarValue").invoke("text").should("eq", "49");
+
+    cy.findByTestId("aggregation-item")
+      .invoke("text")
+      .should("eq", "Distinct values of Average of Total");
+  });
+});
-- 
GitLab