From 50c3530030bb5ce24a4902348e0dd6049628db91 Mon Sep 17 00:00:00 2001
From: Nemanja Glumac <31325167+nemanjaglumac@users.noreply.github.com>
Date: Mon, 1 Nov 2021 21:10:47 +0100
Subject: [PATCH] #18729 Repro: XLSX export of "X of Y" (eg. Month of Year) is
 formatted as date column (#18792)

---
 .../18729-date-formatting-x-of-y.cy.spec.js   | 61 +++++++++++++++++++
 1 file changed, 61 insertions(+)
 create mode 100644 frontend/test/metabase/scenarios/downloads/reproductions/18729-date-formatting-x-of-y.cy.spec.js

diff --git a/frontend/test/metabase/scenarios/downloads/reproductions/18729-date-formatting-x-of-y.cy.spec.js b/frontend/test/metabase/scenarios/downloads/reproductions/18729-date-formatting-x-of-y.cy.spec.js
new file mode 100644
index 00000000000..b24ddf8fb2a
--- /dev/null
+++ b/frontend/test/metabase/scenarios/downloads/reproductions/18729-date-formatting-x-of-y.cy.spec.js
@@ -0,0 +1,61 @@
+import {
+  restore,
+  downloadAndAssert,
+  visitQuestionAdhoc,
+} from "__support__/e2e/cypress";
+import { SAMPLE_DATASET } from "__support__/e2e/cypress_sample_dataset";
+
+const { ORDERS, ORDERS_ID, PRODUCTS } = SAMPLE_DATASET;
+
+const questionDetails = {
+  dataset_query: {
+    database: 1,
+    query: {
+      "source-table": ORDERS_ID,
+      aggregation: [["count"]],
+      breakout: [
+        ["field", ORDERS.CREATED_AT, { "temporal-unit": "month-of-year" }],
+        ["field", PRODUCTS.CATEGORY, { "source-field": ORDERS.PRODUCT_ID }],
+      ],
+      limit: 2,
+    },
+    type: "query",
+  },
+  display: "line",
+};
+
+describe("issue 18729", () => {
+  beforeEach(() => {
+    cy.intercept("POST", "/api/dataset").as("dataset");
+
+    restore();
+    cy.signInAsAdmin();
+  });
+
+  ["csv", "xlsx"].forEach(fileType => {
+    it(`should properly format the 'X of Y'dates in ${fileType} exports (metabase#18729)`, () => {
+      // TODO: Remove this line once the issue gets resolved
+      cy.skipOn(fileType === "xlsx");
+
+      visitQuestionAdhoc(questionDetails);
+      cy.wait("@dataset");
+
+      downloadAndAssert({ fileType }, assertion);
+    });
+  });
+});
+
+function assertion(sheet) {
+  // It currently says only "Created At", but that is already covered in an issue #18219.
+
+  // TODO: When 18219 gets fixed, uncomment the following assertion and delete the `contain` one.
+  // expect(sheet["A1"].v).to.eq("Created At: Month of year");
+  expect(sheet["A1"].v).to.contain("Created At");
+
+  // Based on how this issue gets resolved, the following assertions might need to change!
+
+  expect(sheet["A2"].v).to.eq(1);
+  expect(sheet["A2"].t).to.eq("n");
+  // Parsed values are always in the form of a string
+  expect(sheet["A2"].w).to.eq("1");
+}
-- 
GitLab