import { login } from "../helpers"; const path = require("path"); // ignore automatic import mess-up... // const getDashboardStatistics = (what) => { // return cy.get(`[data-cy="dashboard.stats.${what}"]`); // }; // // const clickOnDetailsLink = (within) => { // cy.get(`[data-cy="dashboard.stats.${within}"]`).within(() => { // cy.get('[data-cy="basebox.detailsLink"]').click(); // }); // }; // function getCurrentDate() { const date = new Date(); const year = date.getFullYear(); const month = String(date.getMonth() + 1).padStart(2, "0"); // Months are zero-based const day = String(date.getDate()).padStart(2, "0"); return `${year}-${month}-${day}`; } function verifyExportFileExists(fileName) { const downloadsFolder = Cypress.config("downloadsFolder"); cy.readFile( path.join(downloadsFolder, `${fileName}_${getCurrentDate()}.xlsx`) ).should("exist"); } function testExport(url, fileName) { cy.visit(url); cy.get('[data-cy="export-button"]').click(); verifyExportFileExists(fileName); } describe("dashboardExport.cy.js", () => { beforeEach(() => { cy.manageCommand( "cypress_reset --create-assignment-evaluation --create-feedback-responses --create-course-completion-performance-criteria --create-attendance-days" ); }); describe("as supervisor", () => { beforeEach(() => { login("test-supervisor1@example.com", "test"); }); it("should download the attendance export", () => { testExport("/statistic/test-lehrgang/attendance", "export_anwesenheit"); }); it("should download the competence elements export", () => { testExport( "/statistic/test-lehrgang/assignment", "export_kompetenznachweis_elemente" ); }); it("should download the feedback export", () => { testExport("/statistic/test-lehrgang/feedback", "export_feedback"); }); }); describe("as trainer", () => { beforeEach(() => { login("test-trainer1@example.com", "test"); }); it("should download the attendance export", () => { testExport("/statistic/test-lehrgang/attendance", "export_anwesenheit"); }); it("should download the competence elements export", () => { testExport( "/statistic/test-lehrgang/assignment", "export_kompetenznachweis_elemente" ); }); it("should download the feedback export", () => { testExport("/statistic/test-lehrgang/feedback", "export_feedback"); }); }); });