From c59c9430bac3d12115ac8a2b41b0c97e2a48e0a9 Mon Sep 17 00:00:00 2001 From: subsingh-akamai Date: Fri, 22 Nov 2024 10:07:10 +0530 Subject: [PATCH] test: [M3-8393] - Cypress test for Account Maintenance CSV downloads (#11168) * Updated test confirm maintenance details in the tables - to validate entry in downloaded csv files * Added changeset: Cypress test for Account Maintenance CSV downloads * Removed console.log * Removed library - papaparse to parse csv;Implemented script to parse the csv file * Removed it.only from test * Using specific locator for Download CSV and added code to delete downloaded file after assertion * Refeactoring as per review comment for delete files * Added assertion in readFile to ensure file content is not empty --- .../pr-11168-tests-1730108478631.md | 5 + .../core/account/account-maintenance.spec.ts | 124 +++++++++++++++++- packages/manager/cypress/support/util/csv.ts | 48 +++++++ 3 files changed, 170 insertions(+), 7 deletions(-) create mode 100644 packages/manager/.changeset/pr-11168-tests-1730108478631.md create mode 100644 packages/manager/cypress/support/util/csv.ts diff --git a/packages/manager/.changeset/pr-11168-tests-1730108478631.md b/packages/manager/.changeset/pr-11168-tests-1730108478631.md new file mode 100644 index 00000000000..ac1f39b27cc --- /dev/null +++ b/packages/manager/.changeset/pr-11168-tests-1730108478631.md @@ -0,0 +1,5 @@ +--- +"@linode/manager": Tests +--- + +Cypress test for Account Maintenance CSV downloads ([#11168](https://github.com/linode/manager/pull/11168)) diff --git a/packages/manager/cypress/e2e/core/account/account-maintenance.spec.ts b/packages/manager/cypress/e2e/core/account/account-maintenance.spec.ts index 56292a96bd5..ba00f881332 100644 --- a/packages/manager/cypress/e2e/core/account/account-maintenance.spec.ts +++ b/packages/manager/cypress/e2e/core/account/account-maintenance.spec.ts @@ -1,5 +1,6 @@ import { mockGetMaintenance } from 'support/intercepts/account'; import { accountMaintenanceFactory } from 'src/factories'; +import { parseCsv } from 'support/util/csv'; describe('Maintenance', () => { /* @@ -7,6 +8,21 @@ describe('Maintenance', () => { * - When there is no pending maintenance, "No pending maintenance." is shown in the table. * - When there is no completed maintenance, "No completed maintenance." is shown in the table. */ + beforeEach(() => { + const downloadsFolder = Cypress.config('downloadsFolder'); + const filePatterns = '{pending-maintenance*,completed-maintenance*}'; + // Delete the file before the test + cy.exec(`rm -f ${downloadsFolder}/${filePatterns}`, { + failOnNonZeroExit: false, + }).then((result) => { + if (result.code === 0) { + cy.log(`Deleted file: ${filePatterns}`); + } else { + cy.log(`Failed to delete file: ${filePatterns}`); + } + }); + }); + it('table empty when no maintenance', () => { mockGetMaintenance([], []).as('getMaintenance'); @@ -118,12 +134,106 @@ describe('Maintenance', () => { }); }); - // Confirm download buttons work - cy.get('button') - .filter(':contains("Download CSV")') - .should('be.visible') - .should('be.enabled') - .click({ multiple: true }); - // TODO Need to add assertions to confirm CSV contains the expected contents on first trial (M3-8393) + // Validate content of the downloaded CSV for pending maintenance + cy.get('a[download*="pending-maintenance"]') + .invoke('attr', 'download') + .then((fileName) => { + const downloadsFolder = Cypress.config('downloadsFolder'); + + // Locate the element for pending-maintenance and then find its sibling