Skip to content
Snippets Groups Projects
Unverified Commit f7a5a918 authored by Damon P. Cortesi's avatar Damon P. Cortesi Committed by GitHub
Browse files

Reproduce datetime downloads (#13745)


* Adds Cypress tests for saved/unsaved questions and date/time formatting.

Co-authored-by: default avatarNemanja <31325167+nemanjaglumac@users.noreply.github.com>
Co-authored-by: default avatarflamber <1447303+flamber@users.noreply.github.com>
parent dc53ed19
Branches
Tags
No related merge requests found
......@@ -8,6 +8,24 @@ const testCases = [
{ type: "xlsx", firstSheetName: "Query result" },
];
function testWorkbookDatetimes(workbook, download_type, sheetName) {
expect(workbook.SheetNames[0]).to.eq(sheetName);
expect(workbook.Sheets[sheetName]["A1"].v).to.eq("birth_date");
expect(workbook.Sheets[sheetName]["B1"].v).to.eq("created_at");
// Excel and CSV will have different formats
if (download_type === "csv") {
expect(workbook.Sheets[sheetName]["A2"].v).to.eq("2020-06-03");
expect(workbook.Sheets[sheetName]["B2"].v).to.eq("2020-06-03T23:41:23");
} else if (download_type === "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(workbook.Sheets[sheetName]["A2"].v).to.eq(43985);
expect(workbook.Sheets[sheetName]["B2"].v).to.eq(43985.98707175926);
}
}
describe("scenarios > question > download", () => {
before(restore);
beforeEach(() => {
......@@ -56,4 +74,93 @@ describe("scenarios > question > download", () => {
});
});
});
describe("for saved questions - metabase#10803", () => {
it("should format the date properly", () => {
cy.request("POST", "/api/card", {
name: "10803",
dataset_query: {
type: "native",
native: {
query:
"SELECT PARSEDATETIME('2020-06-03', 'yyyy-MM-dd') AS \"birth_date\", PARSEDATETIME('2020-06-03 23:41:23', 'yyyy-MM-dd hh:mm:ss') AS \"created_at\"",
"template-tags": {},
},
database: 1,
},
display: "table",
description: null,
visualization_settings: {},
collection_id: null,
}).then(({ body }) => {
cy.wrap(testCases).each(testCase => {
cy.log(`downloading a ${testCase.type} file`);
const endpoint = `/api/card/${body.id}/query/${testCase.type}`;
cy.request({
url: endpoint,
method: "POST",
encoding: "binary",
}).then(resp => {
const workbook = xlsx.read(resp.body, {
type: "binary",
raw: true,
});
testWorkbookDatetimes(
workbook,
testCase.type,
testCase.firstSheetName,
);
});
});
});
});
});
describe("for unsaved questions - metabase#10803", () => {
it("should format the date properly", () => {
// Find existing question "10803"
cy.visit("/collection/root");
cy.findByText("10803").click();
cy.contains(/open editor/i).click();
cy.get(".ace_editor").type("{movetoend} "); // Adds a space at the end of the query to make it "dirty"
cy.get(".Icon-play")
.first()
.click();
cy.get(".Icon-download").click();
cy.wrap(testCases).each(testCase => {
cy.log(`downloading a ${testCase.type} file`);
const downloadClassName = `.Icon-${testCase.type}`;
const endpoint = `/api/dataset/${testCase.type}`;
cy.get(downloadClassName)
.parent()
.parent()
.get('input[name="query"]')
.invoke("val")
.then(download_query_params => {
cy.request({
url: endpoint,
method: "POST",
form: true,
body: { query: download_query_params },
encoding: "binary",
}).then(resp => {
const workbook = xlsx.read(resp.body, {
type: "binary",
raw: true,
});
testWorkbookDatetimes(
workbook,
testCase.type,
testCase.firstSheetName,
);
});
});
});
});
});
});
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment