Skip to content

The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:

Remove parsing from file download e2e tests (#65081)

Fraser2f49744ee104
diff --git a/e2e/support/helpers/e2e-downloads-helpers.ts b/e2e/support/helpers/e2e-downloads-helpers.ts
index 8f143c6e175..1ed1957e502 100644
--- a/e2e/support/helpers/e2e-downloads-helpers.ts
+++ b/e2e/support/helpers/e2e-downloads-helpers.ts
@@ -1,5 +1,3 @@
-import xlsx, { type Sheet } from "xlsx";
-
import {
getDashboardCard,
getDashboardCardMenu,
@@ -16,10 +14,6 @@ interface DownloadAndAssertParams {
/** a download URL when you want to override the one generated by this util */
downloadUrl?: string;
downloadMethod?: "POST" | "GET";
- /** tell SheetJs not to parse values */
- raw?: boolean;
- /** preview the results in the console log */
- logResults?: boolean;
/** downloading is tested on an embedded resource */
isEmbed?: boolean;
/** downloading is tested on a dashboard */
@@ -28,6 +22,22 @@ interface DownloadAndAssertParams {
dashboardId?: number;
enableFormatting?: boolean;
pivoting?: "pivoted" | "non-pivoted";
+ /** Assert that parameters in request body match expected values */
+ assertParameters?: any[];
+}
+
+export interface DownloadRequestData {
+ request: {
+ url: string;
+ method: string;
+ body?: any;
+ headers?: Record<string, string>;
+ };
+ response: {
+ statusCode: number;
+ headers: Record<string, string>;
+ contentType: string | null;
+ };
}
export const exportFromDashcard = (format: string) => {
@@ -40,27 +50,25 @@ export const exportFromDashcard = (format: string) => {
};
/**
- * Trigger the download of CSV or XLSX files and assert on the results in the related sheet.
+ * Trigger the download of CSV or XLSX files and assert on the request/response.
* It applies to both unsaved questions (queries) and the saved ones.
+ * This function verifies that the correct HTTP request is made with proper parameters
+ * and that the response has the correct content type.
*/
-export function downloadAndAssert(
- {
- fileType,
- questionId,
- raw,
- logResults,
- publicUuid,
- dashcardId,
- dashboardId,
- downloadUrl,
- downloadMethod = "POST",
- isDashboard,
- isEmbed = false,
- enableFormatting = true,
- pivoting,
- }: DownloadAndAssertParams,
- callback: (data: Sheet) => void,
-) {
+export function downloadAndAssert({
+ fileType,
+ questionId,
+ publicUuid,
+ dashcardId,
+ dashboardId,
+ downloadUrl,
+ downloadMethod = "POST",
+ isDashboard,
+ isEmbed = false,
+ enableFormatting = true,
+ pivoting,
+ assertParameters,
+}: DownloadAndAssertParams) {
const { method, endpoint } = downloadUrl
? { method: downloadMethod, endpoint: downloadUrl }
: getEndpoint({
@@ -75,22 +83,46 @@ export function downloadAndAssert(
* https://github.com/cypress-io/cypress-example-recipes/blob/master/examples/testing-dom__download/cypress/integration/form-submission-spec.js
*/
- cy.intercept(method, endpoint, (req) => {
- /**
- * We must redirect in order to avoid Cypress being stuck on waiting for the new page to load.
- * Intentionally redirecting to a non-existing page.
- *
- * Explanation:
- * If we redirect to ANY of the existing pages, there's a lot of requests that need to complete for that page.
- * - This helper function is usually the last piece of code to execute in any given test.
- * - As soon as the assertions are complete, the new test starts
- * - Assertions are usually faster than all of the previously mentioned requests from the redirect
- * - This results in the next test being polluted with the requests that didn't finish from the last one.
- * - Those "spill-over" requests end up in the beforeEach hook of the next test and can have unexpected results.
- */
-
- req.redirect("/foo");
- }).as("fileDownload");
+ if (method === "POST") {
+ // For POST requests, we need to redirect to prevent Cypress from hanging
+ cy.intercept(method, endpoint, (req) => {
+ /**
+ * We must redirect in order to avoid Cypress being stuck on waiting for the new page to load.
+ * Intentionally redirecting to a non-existing page.
+ *
+ * Explanation:
+ * If we redirect to ANY of the existing pages, there's a lot of requests that need to complete for that page.
+ * - This helper function is usually the last piece of code to execute in any given test.
+ * - As soon as the assertions are complete, the new test starts
+ * - Assertions are usually faster than all of the previously mentioned requests from the redirect
+ * - This results in the next test being polluted with the requests that didn't finish from the last one.
+ * - Those "spill-over" requests end up in the beforeEach hook of the next test and can have unexpected results.
+ */
+
+ req.continue((res) => {
+ const expectedContentType =
+ fileType === "csv"
+ ? "text/csv"
+ : "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
+
+ expect(res.statusCode).to.eq(200);
+ expect(res.headers["content-type"]).to.include(expectedContentType);
+
+ if (assertParameters && req.body?.parameters) {
+ expect(req.body.parameters).to.have.lengthOf(assertParameters.length);
+ assertParameters.forEach((expectedParam, index) => {
+ expect(req.body.parameters[index]).to.deep.include(expectedParam);
+ });
+ }
+
+ // After assertions pass, redirect to prevent navigation
+ res.send({ statusCode: 302, headers: { location: "/foo" } });
+ });
+ }).as("fileDownload");
+ } else {
+ // For GET requests the server redirects automatically so no need to do it manually
+ cy.intercept(method, endpoint).as("fileDownload");
+ }
cy.log(`Downloading ${fileType} file`);
@@ -137,35 +169,9 @@ export function downloadAndAssert(
cy.findByTestId("download-results-button").click();
});
- cy.wait("@fileDownload")
- .its("request")
- .then((req) => {
- // The payload for the xlsx is in the binary form
- fileType === "xlsx" && Object.assign(req, { encoding: "binary" });
-
- cy.request(req).then(({ body }) => {
- ensureDownloadStatusDismissed();
- const { SheetNames, Sheets } = xlsx.read(body, {
- // See the full list of Parsing options: https://github.com/SheetJS/sheetjs#parsing-options
- type: "binary",
- raw,
- });
-
- const sheetName = SheetNames[0];
- const sheet = Sheets[sheetName];
-
- logResults && console.log(sheet);
-
- callback(sheet);
- });
- });
-}
-
-export function assertSheetRowsCount(expectedCount: number) {
- return (sheet: any) => {
- const range = xlsx.utils.decode_range(sheet["!ref"]);
- expect(range.e.r).to.eq(expectedCount);
- };
+ cy.wait("@fileDownload").then(() => {
+ ensureDownloadStatusDismissed();
+ });
}
export function assertNotEmptyObject(data: any) {
diff --git a/e2e/test/scenarios/dashboard-cards/dashboard-card-reproductions.cy.spec.js b/e2e/test/scenarios/dashboard-cards/dashboard-card-reproductions.cy.spec.js
index 79fb169faa1..c7e8e2fe480 100644
--- a/e2e/test/scenarios/dashboard-cards/dashboard-card-reproductions.cy.spec.js
+++ b/e2e/test/scenarios/dashboard-cards/dashboard-card-reproductions.cy.spec.js
@@ -1610,26 +1610,12 @@ describe("issue 63416", () => {
H.toggleFilterWidgetValues(["Doohickey"]);
- H.downloadAndAssert(
- {
- fileType: "csv",
- isDashboard: true,
- logResults: true,
- downloadMethod: "POST",
- downloadUrl: "/api/dashboard/10/dashcard/*/card/*/query/csv",
- },
- (sheet) => {
- expect(sheet["A1"].v).to.eq("Created At: Month");
- expect(sheet["B1"].v).to.eq("Count");
-
- expect(sheet["A2"].v).to.eq("January, 2024");
- expect(sheet["B2"].v).to.eq(113);
-
- expect(sheet["A3"].v).to.eq("February, 2024");
- expect(sheet["B3"].v).to.eq(87);
-
- H.assertSheetRowsCount(28)(sheet);
- },
- );
+ H.downloadAndAssert({
+ fileType: "csv",
+ isDashboard: true,
+ downloadMethod: "POST",
+ downloadUrl: "/api/dashboard/10/dashcard/*/card/*/query/csv",
+ assertParameters: [{ type: "string/=", value: ["Doohickey"] }],
+ });
});
});
diff --git a/e2e/test/scenarios/embedding/embed-resource-downloads.cy.spec.ts b/e2e/test/scenarios/embedding/embed-resource-downloads.cy.spec.ts
index cf1c6a16241..dbb9412103f 100644
--- a/e2e/test/scenarios/embedding/embed-resource-downloads.cy.spec.ts
+++ b/e2e/test/scenarios/embedding/embed-resource-downloads.cy.spec.ts
@@ -396,25 +396,14 @@ H.describeWithSnowplowEE(
});
cy.findByRole("heading", { name: QUESTION_NAME }).realHover();
- H.downloadAndAssert(
- {
- isDashboard: false,
- isEmbed: true,
- enableFormatting: true,
- fileType: "csv",
- downloadUrl: "/api/embed/card/*/query/csv*",
- downloadMethod: "GET",
- },
- (sheet) => {
- expect(sheet["A2"].v).to.eq(FIRST_ROW[0]);
- expect(sheet["B2"].v).to.eq(FIRST_ROW[1]);
- expect(sheet["C2"].v).to.eq(FIRST_ROW[2]);
-
- expect(sheet["A3"].v).to.eq(SECOND_ROW[0]);
- expect(sheet["B3"].v).to.eq(SECOND_ROW[1]);
- expect(sheet["C3"].v).to.eq(SECOND_ROW[2]);
- },
- );
+ H.downloadAndAssert({
+ isDashboard: false,
+ isEmbed: true,
+ enableFormatting: true,
+ fileType: "csv",
+ downloadUrl: "/api/embed/card/*/query/csv*",
+ downloadMethod: "GET",
+ });
H.expectUnstructuredSnowplowEvent({
event: "download_results_clicked",
@@ -500,21 +489,14 @@ H.describeWithSnowplowEE(
});
cy.findByRole("heading", { name: QUESTION_NAME }).realHover();
- H.downloadAndAssert(
- {
- isDashboard: false,
- isEmbed: true,
- enableFormatting: true,
- fileType: "csv",
- downloadUrl: "/api/embed/card/*/query/csv*",
- downloadMethod: "GET",
- },
- (sheet) => {
- expect(sheet["A2"].v).to.eq(FIRST_ROW[0]);
- expect(sheet["B2"].v).to.eq(FIRST_ROW[1]);
- expect(sheet["C2"].v).to.eq(FIRST_ROW[2]);
- },
- );
+ H.downloadAndAssert({
+ isDashboard: false,
+ isEmbed: true,
+ enableFormatting: true,
+ fileType: "csv",
+ downloadUrl: "/api/embed/card/*/query/csv*",
+ downloadMethod: "GET",
+ });
});
});
});
diff --git a/e2e/test/scenarios/embedding/embedding-dashboard.cy.spec.js b/e2e/test/scenarios/embedding/embedding-dashboard.cy.spec.js
index 82a3a6ff29f..90c53bdad05 100644
--- a/e2e/test/scenarios/embedding/embedding-dashboard.cy.spec.js
+++ b/e2e/test/scenarios/embedding/embedding-dashboard.cy.spec.js
@@ -524,24 +524,13 @@ describe("scenarios > embedding > dashboard parameters", () => {
cy.log("test downloading result (metabase#36721)");
H.getDashboardCard().realHover();
- H.downloadAndAssert(
- {
- fileType: "csv",
- isDashboard: true,
- isEmbed: true,
- logResults: true,
- downloadUrl: "/api/embed/dashboard/*/dashcard/*/card/*/csv*",
- downloadMethod: "GET",
- },
- (sheet) => {
- expect(sheet["A1"].v).to.eq("ID");
- expect(sheet["A2"].v).to.eq(9);
- expect(sheet["B1"].v).to.eq("EAN");
- expect(sheet["B2"].v).to.eq(7217466997444);
-
- H.assertSheetRowsCount(54)(sheet);
- },
- );
+ H.downloadAndAssert({
+ fileType: "csv",
+ isDashboard: true,
+ isEmbed: true,
+ downloadUrl: "/api/embed/dashboard/*/dashcard/*/card/*/csv*",
+ downloadMethod: "GET",
+ });
cy.log(
"The PDF download button should be clickable when there is no title, but has parameters (metabase#59503)",
diff --git a/e2e/test/scenarios/filters/filter-bigint.cy.spec.ts b/e2e/test/scenarios/filters/filter-bigint.cy.spec.ts
index d70d6bfe3a9..77349d4fec9 100644
--- a/e2e/test/scenarios/filters/filter-bigint.cy.spec.ts
+++ b/e2e/test/scenarios/filters/filter-bigint.cy.spec.ts
@@ -1,5 +1,3 @@
-import type { Sheet } from "xlsx";
-
import { WRITABLE_DB_ID } from "e2e/support/cypress_data";
import type {
DashboardDetails,
@@ -1225,29 +1223,14 @@ SELECT CAST('${POSITIVE_DECIMAL_VALUE}' AS DECIMAL) AS NUMBER`,
});
}
- function testExport({
- columnName,
- formattedMinValue,
- formattedMaxValue,
- }: {
- columnName: string;
- formattedMinValue: string;
- formattedMaxValue: string;
- }) {
+ function testExport() {
cy.get("@questionId").then((questionId) => {
- H.downloadAndAssert(
- {
- fileType: "csv",
- questionId: Number(questionId),
- isDashboard: false,
- enableFormatting: true,
- },
- (sheet: Sheet) => {
- expect(sheet["A1"].v).to.eq(columnName);
- expect(sheet["A2"].w).to.eq(formattedMinValue);
- expect(sheet["A4"].w).to.eq(formattedMaxValue);
- },
- );
+ H.downloadAndAssert({
+ fileType: "csv",
+ questionId: Number(questionId),
+ isDashboard: false,
+ enableFormatting: true,
+ });
});
}
@@ -1256,31 +1239,15 @@ SELECT CAST('${POSITIVE_DECIMAL_VALUE}' AS DECIMAL) AS NUMBER`,
cy.log("BIGINT");
setupTableQuestion({ tableName: BIGINT_PK_TABLE_NAME });
- testExport({
- columnName: "ID",
- formattedMinValue: MIN_BIGINT_VALUE,
- formattedMaxValue: MAX_BIGINT_VALUE,
- });
+ testExport();
setupNestedQuestion({ sourceQuestionDetails: bigIntQuestionDetails });
- testExport({
- columnName: "NUMBER",
- formattedMinValue: FORMATTED_MIN_BIGINT_VALUE,
- formattedMaxValue: FORMATTED_MAX_BIGINT_VALUE,
- });
+ testExport();
cy.log("DECIMAL");
setupTableQuestion({ tableName: DECIMAL_PK_TABLE_NAME });
- testExport({
- columnName: "ID",
- formattedMinValue: NEGATIVE_DECIMAL_VALUE,
- formattedMaxValue: POSITIVE_DECIMAL_VALUE,
- });
+ testExport();
setupNestedQuestion({ sourceQuestionDetails: decimalQuestionDetails });
- testExport({
- columnName: "NUMBER",
- formattedMinValue: FORMATTED_NEGATIVE_DECIMAL_VALUE,
- formattedMaxValue: FORMATTED_POSITIVE_DECIMAL_VALUE,
- });
+ testExport();
});
it("dashboards + click behavior", () => {
diff --git a/e2e/test/scenarios/permissions/download-permissions.cy.spec.js b/e2e/test/scenarios/permissions/download-permissions.cy.spec.js
index d86e697a807..41b8ca99c39 100644
--- a/e2e/test/scenarios/permissions/download-permissions.cy.spec.js
+++ b/e2e/test/scenarios/permissions/download-permissions.cy.spec.js
@@ -154,10 +154,7 @@ describe("scenarios > admin > permissions > data > downloads", () => {
cy.signInAsNormalUser();
H.visitQuestion(ORDERS_QUESTION_ID);
- H.downloadAndAssert(
- { fileType: "xlsx", questionId: ORDERS_QUESTION_ID },
- H.assertSheetRowsCount(10000),
- );
+ H.downloadAndAssert({ fileType: "xlsx", questionId: ORDERS_QUESTION_ID });
});
describe("native questions", () => {
@@ -181,29 +178,20 @@ describe("scenarios > admin > permissions > data > downloads", () => {
cy.get("@nativeQuestionId").then((id) => {
H.visitQuestion(id);
- H.downloadAndAssert(
- { fileType: "xlsx", questionId: id },
- H.assertSheetRowsCount(18760),
- );
+ H.downloadAndAssert({ fileType: "xlsx", questionId: id });
// Make sure we can download results from an ad-hoc nested query based on a native question
cy.findByText("Explore results").click();
cy.wait("@dataset");
- H.downloadAndAssert(
- { fileType: "xlsx" },
- H.assertSheetRowsCount(18760),
- );
+ H.downloadAndAssert({ fileType: "xlsx" });
// Make sure we can download results from a native model
cy.request("PUT", `/api/card/${id}`, { name: "Native Model" });
H.visitQuestion(id);
- H.downloadAndAssert(
- { fileType: "xlsx", questionId: id },
- H.assertSheetRowsCount(18760),
- );
+ H.downloadAndAssert({ fileType: "xlsx", questionId: id });
});
});
@@ -243,29 +231,20 @@ describe("scenarios > admin > permissions > data > downloads", () => {
cy.get("@nativeQuestionId").then((id) => {
H.visitQuestion(id);
- H.downloadAndAssert(
- { fileType: "xlsx", questionId: id },
- H.assertSheetRowsCount(10000),
- );
+ H.downloadAndAssert({ fileType: "xlsx", questionId: id });
// Ad-hoc nested query based on a native question should also have a download row limit
cy.findByText("Explore results").click();
cy.wait("@dataset");
- H.downloadAndAssert(
- { fileType: "xlsx" },
- H.assertSheetRowsCount(10000),
- );
+ H.downloadAndAssert({ fileType: "xlsx" });
// Convert question to a model, which should also have a download row limit
cy.request("PUT", `/api/card/${id}`, { name: "Native Model" });
H.visitQuestion(id);
- H.downloadAndAssert(
- { fileType: "xlsx", questionId: id },
- H.assertSheetRowsCount(10000),
- );
+ H.downloadAndAssert({ fileType: "xlsx", questionId: id });
});
});
});
diff --git a/e2e/test/scenarios/sharing/downloads/downloads.cy.spec.js b/e2e/test/scenarios/sharing/downloads/downloads.cy.spec.js
index 3afd6031a6d..55e4b403907 100644
--- a/e2e/test/scenarios/sharing/downloads/downloads.cy.spec.js
+++ b/e2e/test/scenarios/sharing/downloads/downloads.cy.spec.js
@@ -61,10 +61,7 @@ describe("scenarios > question > download", () => {
// eslint-disable-next-line no-unscoped-text-selectors -- deprecated usage
cy.contains("18,760");
- H.downloadAndAssert({ fileType }, (sheet) => {
- expect(sheet["A1"].v).to.eq("Count");
- expect(sheet["A2"].v).to.eq(18760);
- });
+ H.downloadAndAssert({ fileType });
H.expectUnstructuredSnowplowEvent({
event: "download_results_clicked",
@@ -106,27 +103,15 @@ describe("scenarios > question > download", () => {
cy.get("@questionId").then((questionId) => {
const opts = { questionId, fileType };
- H.downloadAndAssert(
- {
- ...opts,
- enableFormatting: true,
- },
- (sheet) => {
- expect(sheet["A1"].v).to.eq("Total");
- expect(sheet["A2"].w).to.eq("USD 39.72");
- },
- );
+ H.downloadAndAssert({
+ ...opts,
+ enableFormatting: true,
+ });
- H.downloadAndAssert(
- {
- ...opts,
- enableFormatting: false,
- },
- (sheet) => {
- expect(sheet["A1"].v).to.eq("Total");
- expect(sheet["A2"].v).to.eq(39.718145389078366);
- },
- );
+ H.downloadAndAssert({
+ ...opts,
+ enableFormatting: false,
+ });
});
});
});
@@ -148,28 +133,16 @@ describe("scenarios > question > download", () => {
{ visitQuestion: true },
);
- H.downloadAndAssert(
- {
- enableFormatting: true,
- fileType: "csv",
- },
- (sheet) => {
- expect(sheet["B1"].v).to.eq("Doohickey");
- expect(sheet["B2"].w).to.eq("13");
- },
- );
+ H.downloadAndAssert({
+ enableFormatting: true,
+ fileType: "csv",
+ });
- H.downloadAndAssert(
- {
- enableFormatting: true,
- pivoting: "non-pivoted",
- fileType: "csv",
- },
- (sheet) => {
- expect(sheet["B1"].v).to.eq("Category");
- expect(sheet["B2"].w).to.eq("Doohickey");
- },
- );
+ H.downloadAndAssert({
+ enableFormatting: true,
+ pivoting: "non-pivoted",
+ fileType: "csv",
+ });
});
describe("download format preference", () => {
@@ -331,18 +304,10 @@ describe("scenarios > question > download", () => {
testCases.forEach((fileType) => {
const opts = { questionId, fileType };
- H.downloadAndAssert(
- {
- ...opts,
- enableFormatting: true,
- },
- (sheet) => {
- expect(sheet["A1"].v).to.eq("Left Total");
- expect(sheet["A2"].v).to.closeTo(159.35, 0.01);
- expect(sheet["B1"].v).to.eq("Right Total");
- expect(sheet["B2"].v).to.closeTo(159.35, 0.01);
- },
- );
+ H.downloadAndAssert({
+ ...opts,
+ enableFormatting: true,
+ });
});
});
});
@@ -441,20 +406,12 @@ describe("scenarios > question > download", () => {
cy.findByTestId("legend-caption").contains("20868").click();
- H.downloadAndAssert(
- {
- fileType: "xlsx",
- questionId,
- dashboardId,
- dashcardId: id,
- },
- (sheet) => {
- expect(sheet["A1"].v).to.eq("ID");
- expect(sheet["A2"].v).to.eq(1);
-
- H.assertSheetRowsCount(1)(sheet);
- },
- );
+ H.downloadAndAssert({
+ fileType: "xlsx",
+ questionId,
+ dashboardId,
+ dashcardId: id,
+ });
});
});
});
@@ -587,21 +544,11 @@ H.describeWithSnowplow("[snowplow] scenarios > dashboard", () => {
});
function assertOrdersExport(length) {
- H.downloadAndAssert(
- {
- fileType: "xlsx",
- questionId: ORDERS_QUESTION_ID,
- dashcardId: ORDERS_DASHBOARD_DASHCARD_ID,
- dashboardId: ORDERS_DASHBOARD_ID,
- isDashboard: true,
- },
- (sheet) => {
- expect(sheet["A1"].v).to.eq("ID");
- expect(sheet["A2"].v).to.eq(1);
- expect(sheet["B1"].v).to.eq("User ID");
- expect(sheet["B2"].v).to.eq(1);
-
- H.assertSheetRowsCount(length)(sheet);
- },
- );
+ H.downloadAndAssert({
+ fileType: "xlsx",
+ questionId: ORDERS_QUESTION_ID,
+ dashcardId: ORDERS_DASHBOARD_DASHCARD_ID,
+ dashboardId: ORDERS_DASHBOARD_ID,
+ isDashboard: true,
+ });
}
diff --git a/e2e/test/scenarios/sharing/downloads/sharing-download-reproductions.cy.spec.js b/e2e/test/scenarios/sharing/downloads/sharing-download-reproductions.cy.spec.js
index 10bd6154242..06b03b7a863 100644
--- a/e2e/test/scenarios/sharing/downloads/sharing-download-reproductions.cy.spec.js
+++ b/e2e/test/scenarios/sharing/downloads/sharing-download-reproductions.cy.spec.js
@@ -29,10 +29,7 @@ describe("issue 10803", () => {
testCases.forEach((fileType) => {
it(`should format the date properly for ${fileType} in saved questions (metabase#10803)`, () => {
cy.get("@questionId").then((questionId) => {
- H.downloadAndAssert(
- { fileType, questionId, logResults: true, raw: true },
- testWorkbookDatetimes,
- );
+ H.downloadAndAssert({ fileType, questionId });
});
});
@@ -43,25 +40,8 @@ describe("issue 10803", () => {
H.NativeEditor.focus().type("{movetoend} ");
H.runNativeQuery();
- H.downloadAndAssert({ fileType, raw: true }, testWorkbookDatetimes);
+ H.downloadAndAssert({ fileType });
});
-
- function testWorkbookDatetimes(sheet) {
- expect(sheet["A1"].v).to.eq("birth_date");
- expect(sheet["B1"].v).to.eq("created_at");
-
- // Excel and CSV will have different formats
- if (fileType === "csv") {
- expect(sheet["A2"].v).to.eq("June 3, 2026, 12:00 AM");
- expect(sheet["B2"].v).to.eq("June 3, 2026, 11:41 PM");
- } else if (fileType === "xlsx") {
- // We tell the xlsx library to read raw and not parse dates
- // So for the _date_ format we expect an integer
- // And for timestamp, we expect a float
- expect(sheet["A2"].v).to.eq(46176);
- expect(sheet["B2"].v).to.eq(46176.98707175926);
- }
- }
});
});
@@ -72,14 +52,6 @@ describe("issue 18382", () => {
* We want to make sure it still works when loaded into a new(er) Metabase version.
*/
- function assertion(sheet) {
- expect(sheet["A1"].v).to.eq("MOD:Title");
- expect(sheet["B1"].v).to.eq("MOD:ID");
- expect(sheet["C1"].v).to.eq("MOD:Reviewer");
-
- expect(sheet["A2"].v).to.eq("Aerodynamic Concrete Bench");
- }
-
const questionDetails = {
dataset_query: {
database: SAMPLE_DB_ID,
@@ -158,7 +130,7 @@ describe("issue 18382", () => {
// TODO: Please remove this line when issue gets fixed
cy.skipOn(fileType === "csv");
- H.downloadAndAssert({ fileType }, assertion);
+ H.downloadAndAssert({ fileType });
});
});
});
@@ -176,11 +148,6 @@ describe("issue 18440", () => {
const testCases = ["csv", "xlsx"];
- function assertion(sheet) {
- expect(sheet["C1"].v).to.eq("Product ID");
- expect(sheet["C2"].v).to.eq("Awesome Concrete Shoes");
- }
-
beforeEach(() => {
cy.intercept("POST", "/api/card").as("saveQuestion");
@@ -204,7 +171,7 @@ describe("issue 18440", () => {
// eslint-disable-next-line no-unscoped-text-selectors -- deprecated usage
cy.findByText("Awesome Concrete Shoes");
- H.downloadAndAssert({ fileType }, assertion);
+ H.downloadAndAssert({ fileType });
});
it(`export should include a column with remapped values for ${fileType} for a saved question (metabase#18440-2)`, () => {
@@ -214,7 +181,7 @@ describe("issue 18440", () => {
cy.findByText("Product ID");
cy.findByText("Awesome Concrete Shoes");
- H.downloadAndAssert({ fileType, questionId: id }, assertion);
+ H.downloadAndAssert({ fileType, questionId: id });
});
});
});
@@ -235,10 +202,6 @@ describe("issue 18573", () => {
},
},
};
- function assertion(sheet) {
- expect(sheet["C1"].v).to.eq("Foo");
- expect(sheet["C2"].v).to.eq("Awesome Concrete Shoes");
- }
beforeEach(() => {
H.restore();
@@ -260,7 +223,7 @@ describe("issue 18573", () => {
// eslint-disable-next-line no-unscoped-text-selectors -- deprecated usage
cy.findByText("Awesome Concrete Shoes");
- H.downloadAndAssert({ fileType: "xlsx" }, assertion);
+ H.downloadAndAssert({ fileType: "xlsx" });
});
});
@@ -282,21 +245,6 @@ describe("issue 18729", () => {
display: "line",
};
- 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");
- }
-
beforeEach(() => {
H.restore();
cy.signInAsAdmin();
@@ -306,7 +254,7 @@ describe("issue 18729", () => {
it(`should properly format the 'X of Y'dates in ${fileType} exports (metabase#18729)`, () => {
H.visitQuestionAdhoc(questionDetails);
- H.downloadAndAssert({ fileType }, assertion);
+ H.downloadAndAssert({ fileType });
});
});
});
@@ -360,22 +308,14 @@ describe("issue 19889", () => {
testCases.forEach((fileType) => {
it("should order columns correctly in unsaved native query exports", () => {
- H.downloadAndAssert({ fileType, raw: true }, (sheet) => {
- expect(sheet["A1"].v).to.equal("column b");
- expect(sheet["B1"].v).to.equal("column a");
- expect(sheet["C1"].v).to.equal("column c");
- });
+ H.downloadAndAssert({ fileType });
});
it("should order columns correctly in saved native query exports", () => {
saveAndOverwrite();
cy.get("@questionId").then((questionId) => {
- H.downloadAndAssert({ fileType, questionId, raw: true }, (sheet) => {
- expect(sheet["A1"].v).to.equal("column b");
- expect(sheet["B1"].v).to.equal("column a");
- expect(sheet["C1"].v).to.equal("column c");
- });
+ H.downloadAndAssert({ fileType, questionId });
});
});
@@ -391,11 +331,7 @@ describe("issue 19889", () => {
cy.get("@questionId").then((questionId) => {
H.visitQuestion(questionId);
- H.downloadAndAssert({ fileType, questionId, raw: true }, (sheet) => {
- expect(sheet["A1"].v).to.equal("column x");
- expect(sheet["B1"].v).to.equal("column y");
- expect(sheet["C1"].v).to.equal("column c");
- });
+ H.downloadAndAssert({ fileType, questionId });
});
});
});
@@ -430,19 +366,11 @@ describe("metabase#28834", () => {
it("should be able to export unsaved native query results as CSV even after the query has changed", () => {
const fileType = "csv";
- H.downloadAndAssert({ fileType, raw: true }, (sheet) => {
- expect(sheet["A1"].v).to.equal("column a");
- expect(sheet["A2"].v).to.equal("1");
- expect(sheet["A3"]).to.be.undefined;
- });
+ H.downloadAndAssert({ fileType });
});
it("should be able to export unsaved native query results as XLSX even after the query has changed", () => {
const fileType = "xlsx";
- H.downloadAndAssert({ fileType, raw: true }, (sheet) => {
- expect(sheet["A1"].v).to.equal("column a");
- expect(sheet["A2"].v).to.equal(1);
- expect(sheet["A3"]).to.be.undefined;
- });
+ H.downloadAndAssert({ fileType });
});
});
diff --git a/e2e/test/scenarios/sharing/public-question.cy.spec.js b/e2e/test/scenarios/sharing/public-question.cy.spec.js
index 607b4ea61ec..d703966297b 100644
--- a/e2e/test/scenarios/sharing/public-question.cy.spec.js
+++ b/e2e/test/scenarios/sharing/public-question.cy.spec.js
@@ -1,5 +1,3 @@
-import xlsx from "xlsx";
-
const { H } = cy;
import { SAMPLE_DATABASE } from "e2e/support/cypress_sample_database";
@@ -78,10 +76,7 @@ describe("scenarios > public > question", () => {
cy.get("@uuid").then((publicUuid) => {
H.main().realHover();
- H.downloadAndAssert(
- { fileType: "xlsx", questionId: id, publicUuid },
- H.assertSheetRowsCount(5),
- );
+ H.downloadAndAssert({ fileType: "xlsx", questionId: id, publicUuid });
});
});
});
@@ -217,27 +212,6 @@ describe("scenarios > question > public link with extension", () => {
},
).as("questionId");
});
-
- it("should download a json file when a public link with .json is shared", () => {
- downloadPublicFileURL("json", (response) => {
- expect(response.body[0]).to.deep.eq({ ID: 1 });
- });
- });
-
- ["csv", "xlsx"].forEach((fileType) =>
- it(`should download a ${fileType} file when a public link with .${fileType} is shared`, () => {
- downloadPublicFileURL(fileType, (response) => {
- const { SheetNames, Sheets } = xlsx.read(response.body, {
- type: "binary",
- });
-
- const sheetName = SheetNames[0];
- const sheet = Sheets[sheetName];
- expect(sheet["A1"].v).to.eq("ID");
- expect(sheet["A2"].v).to.eq(1);
- });
- }),
- );
});
describe("scenarios [EE] > public > question", () => {
@@ -306,27 +280,3 @@ const visitPublicURL = () => {
cy.visit(publicURL);
});
};
-
-const downloadPublicFileURL = (fileType, validationCallback) => {
- H.openSharingMenu("Create a public link");
-
- H.popover().findByText(fileType).click();
-
- H.popover().findByTestId("public-link-input").invoke("val").as("publicUrl");
-
- cy.get("@publicUrl").should(
- "match",
- new RegExp(`\\/public\\/question\\/.*\\.${fileType}`),
- );
-
- cy.get("@publicUrl").then((url) => {
- cy.request({
- method: "GET",
- url: url,
- followRedirect: true,
- encoding: "binary",
- }).then((response) => {
- validationCallback(response);
- });
- });
-};
diff --git a/e2e/test/scenarios/sharing/public-resource-downloads.cy.spec.ts b/e2e/test/scenarios/sharing/public-resource-downloads.cy.spec.ts
index c32ee416995..242670e1769 100644
--- a/e2e/test/scenarios/sharing/public-resource-downloads.cy.spec.ts
+++ b/e2e/test/scenarios/sharing/public-resource-downloads.cy.spec.ts
@@ -141,17 +141,14 @@ H.describeWithSnowplowEE(
const uuid = publicLink.split("/").at(-1);
- H.downloadAndAssert(
- {
- publicUuid: uuid,
- fileType: "csv",
- questionId: ORDERS_BY_YEAR_QUESTION_ID,
- isDashboard: true,
- isEmbed: true,
- dashcardId: ORDERS_DASHBOARD_DASHCARD_ID,
- },
- H.assertNotEmptyObject,
- );
+ H.downloadAndAssert({
+ publicUuid: uuid,
+ fileType: "csv",
+ questionId: ORDERS_BY_YEAR_QUESTION_ID,
+ isDashboard: true,
+ isEmbed: true,
+ dashcardId: ORDERS_DASHBOARD_DASHCARD_ID,
+ });
H.expectUnstructuredSnowplowEvent({
event: "download_results_clicked",
@@ -234,16 +231,13 @@ H.describeWithSnowplowEE(
const uuid = publicLink.split("/").at(-1);
- H.downloadAndAssert(
- {
- publicUuid: uuid,
- fileType: "csv",
- questionId: ORDERS_BY_YEAR_QUESTION_ID,
- isDashboard: false,
- isEmbed: true,
- },
- H.assertNotEmptyObject,
- );
+ H.downloadAndAssert({
+ publicUuid: uuid,
+ fileType: "csv",
+ questionId: ORDERS_BY_YEAR_QUESTION_ID,
+ isDashboard: false,
+ isEmbed: true,
+ });
H.expectUnstructuredSnowplowEvent({
event: "download_results_clicked",
@@ -314,16 +308,13 @@ H.describeWithSnowplowEE(
cy.location("pathname").then((pathname) => {
const uuid = pathname.split("/").at(-1);
- H.downloadAndAssert(
- {
- publicUuid: uuid,
- fileType: "csv",
- questionId: ORDERS_BY_YEAR_QUESTION_ID,
- isDashboard: false,
- isEmbed: true,
- },
- H.assertNotEmptyObject,
- );
+ H.downloadAndAssert({
+ publicUuid: uuid,
+ fileType: "csv",
+ questionId: ORDERS_BY_YEAR_QUESTION_ID,
+ isDashboard: false,
+ isEmbed: true,
+ });
cy.get<{ request: Request }>("@fileDownload").then(({ request }) => {
const url = new URL(request.url);
diff --git a/package.json b/package.json
index c252c75334d..26ad11ea049 100644
--- a/package.json
+++ b/package.json
@@ -363,7 +363,6 @@
"webpack-dev-server": "^5.2.1",
"webpack-notifier": "1.15.0",
"webpack-stats-plugin": "^1.1.3",
- "xlsx": "https://cdn.sheetjs.com/xlsx-0.20.2/xlsx-0.20.2.tgz",
"yaml-lint": "~1.6.0",
"yarn-deduplicate": "^6.0.2"
},
diff --git a/yarn.lock b/yarn.lock
index 26c2d416430..cec4701ceeb 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -22282,10 +22282,6 @@ xdg-basedir@^4.0.0:
resolved "https://registry.yarnpkg.com/xdg-basedir/-/xdg-basedir-4.0.0.tgz#4bc8d9984403696225ef83a1573cbbcb4e79db13"
integrity sha512-PSNhEJDejZYV7h50BohL09Er9VaIefr2LMAf3OEmpCkjOi34eYyQYAXUTjEQtZJTKcF0E2UKTh+osDLsgNim9Q==
-"xlsx@https://cdn.sheetjs.com/xlsx-0.20.2/xlsx-0.20.2.tgz":
- version "0.20.2"
- resolved "https://cdn.sheetjs.com/xlsx-0.20.2/xlsx-0.20.2.tgz#0f64eeed3f1a46e64724620c3553f2dbd3cd2d7d"
-
xml-name-validator@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/xml-name-validator/-/xml-name-validator-4.0.0.tgz#79a006e2e63149a8600f15430f0a4725d1524835"