diff --git a/goofy-client/apps/goofy-e2e/cypress.config.ts b/goofy-client/apps/goofy-e2e/cypress.config.ts index 9a49dde39416be544323860b89f605015d8f615a..21b3aad9fb32db1ae98081e63a3facb256b3593a 100644 --- a/goofy-client/apps/goofy-e2e/cypress.config.ts +++ b/goofy-client/apps/goofy-e2e/cypress.config.ts @@ -12,4 +12,4 @@ export default defineConfig({ return cypressEvents(on, config); } }, -}); \ No newline at end of file +}); diff --git a/goofy-client/apps/goofy-e2e/src/e2e/main-tests/vorgang-detailansicht/vorgang-exportieren.cy.ts b/goofy-client/apps/goofy-e2e/src/e2e/main-tests/vorgang-detailansicht/vorgang-exportieren.cy.ts index f860a6d99217dd94c8d807dd4c4f33bf92c4ff84..0e5cc6e24d453b4b316ee55d17045984eb1161ed 100644 --- a/goofy-client/apps/goofy-e2e/src/e2e/main-tests/vorgang-detailansicht/vorgang-exportieren.cy.ts +++ b/goofy-client/apps/goofy-e2e/src/e2e/main-tests/vorgang-detailansicht/vorgang-exportieren.cy.ts @@ -29,10 +29,11 @@ import { VorgangListE2EComponent } from '../../../components/vorgang/vorgang-lis import { VorgangE2E } from '../../../model/vorgang'; import { MainPage, waitForSpinnerToDisappear } from '../../../page-objects/main.po'; import { VorgangPage } from '../../../page-objects/vorgang.po'; -import { dropCollections } from '../../../support/cypress-helper'; -import { exist, notExist } from '../../../support/cypress.util'; +import { countDownloadFiles, deleteDownloadFolder, dropCollections } from '../../../support/cypress-helper'; +import { exist, haveValue, notExist } from '../../../support/cypress.util'; import { loginAsSabine } from '../../../support/user-util'; import { createVorgang, initVorgaenge } from '../../../support/vorgang-util'; +import * as fs from 'fs'; registerLocaleData(localeDe, 'de', localeDeExtra); @@ -83,11 +84,14 @@ describe('Vorgang exportieren', () => { exist(menuItem.getButton()); }) - it('should download', () => { + it('should have 1 file in download folder after download', () => { menuItem.getButton().click(); waitForSpinnerToDisappear(); - //TODO In Cypress 10+ implement something like https://docs.cypress.io/api/commands/task#Return-number-of-files-in-the-folder + countDownloadFiles().then((count) => { + expect(count).to.eq(1); + deleteDownloadFolder(); + }); }) it('should close menu after download', () => { diff --git a/goofy-client/apps/goofy-e2e/src/support/cypress-helper.ts b/goofy-client/apps/goofy-e2e/src/support/cypress-helper.ts index bde71f182f74051db676b6bf41da1e23ff93072c..62b64501d57ac8bfed9e3492f184b01eae723a5f 100644 --- a/goofy-client/apps/goofy-e2e/src/support/cypress-helper.ts +++ b/goofy-client/apps/goofy-e2e/src/support/cypress-helper.ts @@ -37,6 +37,8 @@ enum CypressTasks { INIT_VORGANG_DATA = 'initVorgangData', INIT_VORGANG_ATTACHED_ITEM_DATA = 'initVorgangAttachedItemData', INIT_USERMANAGER_DATA = 'initUsermanagerData', + COUNT_FILES = 'countFiles', + DELETE_FOLDER = 'deleteFolder' } enum MongoCollections { @@ -48,6 +50,8 @@ enum MongoCollections { USER = "User" } +const DOWNLOAD_FOLDER: string = 'cypress/downloads'; + export function login(userJsonPath: string): void { cy.fixture(userJsonPath).then(user => { cy.login(user.name, user.password); @@ -108,6 +112,14 @@ export function dropCollections() { cy.task(CypressTasks.DROP_USER_MANAGER_COLLECTIONS, [MongoCollections.USER]); } +export function countDownloadFiles(): Cypress.Chainable<number> { + return cy.task(CypressTasks.COUNT_FILES, DOWNLOAD_FOLDER); +} + +export function deleteDownloadFolder(): void { + cy.task(CypressTasks.DELETE_FOLDER, DOWNLOAD_FOLDER); +} + export function scrollToWindowBottom(): void { cy.window().scrollTo('bottom'); } @@ -143,7 +155,7 @@ export function reload(): void { } export function readFileFromDownloads(fileName: string) { - return cy.readFile(`cypress/downloads/${fileName}`); + return cy.readFile(`${DOWNLOAD_FOLDER}/${fileName}`); } export function pressTab(): void { diff --git a/goofy-client/apps/goofy-e2e/src/support/cypress-tasks.ts b/goofy-client/apps/goofy-e2e/src/support/cypress-tasks.ts index 6c6806b83b7e4cd4e2d8dbfcd48976a506dc6774..d92b9e80d3c05c57f3e62671449e84d4ecd40f5b 100644 --- a/goofy-client/apps/goofy-e2e/src/support/cypress-tasks.ts +++ b/goofy-client/apps/goofy-e2e/src/support/cypress-tasks.ts @@ -1,3 +1,4 @@ +import { rmdir } from 'fs'; import { Long, MongoClient, ObjectId } from 'mongodb'; const Binary = require('mongodb').Binary; @@ -43,7 +44,16 @@ module.exports = (on: any, config: any) => { console.log('dropUserManagerCollections: ', collections); dropUserManagerCollectionsFromDatabase(config, collections); return 0; - } + }, + countFiles(folderName:string) { + console.log('counting files in folder %s', folderName); + return countFiles(folderName); + }, + deleteFolder(folderName:string) { + console.log('deleting folder %s', folderName); + deleteFolder(folderName); + return 0; + }, }); // Workaround für Angular 13 und Cypress mit Webpack 4, @@ -295,4 +305,28 @@ function dropCollections(databaseUrl, databaseName, collections){ }); } }); +} + +function countFiles(folderName:string): Promise<number> { + return new Promise((resolve, reject) => { + fs.readdir(folderName, (err, files) => { + if (err) { + console.error(err) + return reject(err) + } + resolve(files.length) + }) + }) +} + +function deleteFolder(folderName:string): void { + new Promise((resolve, reject) => { + rmdir(folderName, { maxRetries: 10, recursive: true }, (err) => { + if (err) { + console.error(err) + return reject(err) + } + resolve(null) + }) + }) } \ No newline at end of file