From 681a96fbb4c756658c9d6ba3791dff771b54561c Mon Sep 17 00:00:00 2001 From: sebo <sebastian.bergandy@external.mgm-cp.com> Date: Wed, 26 Feb 2025 15:59:34 +0100 Subject: [PATCH] OZG-5977 adopt wiedervorlage e2e for multi upload --- .../attachment/attachment.e2e.component.ts | 17 ++ .../wiedervorlage-attachment.cy.ts | 161 +++++------------- .../file-upload-list-item.component.html | 4 +- .../file-upload-list-item.component.spec.ts | 17 +- .../file-upload-list-item.component.ts | 10 +- .../multi-file-upload.component.html | 2 +- 6 files changed, 81 insertions(+), 130 deletions(-) diff --git a/alfa-client/apps/alfa-e2e/src/components/attachment/attachment.e2e.component.ts b/alfa-client/apps/alfa-e2e/src/components/attachment/attachment.e2e.component.ts index c7988c3ce9..090ce7a95a 100644 --- a/alfa-client/apps/alfa-e2e/src/components/attachment/attachment.e2e.component.ts +++ b/alfa-client/apps/alfa-e2e/src/components/attachment/attachment.e2e.component.ts @@ -48,6 +48,10 @@ export class AttachmentListE2EComponent { return new AttachmentE2EItem(fileName); } + public getLoadingOrErrorItem(fileName: string): LoadingErrorAttachmentE2EItem { + return new LoadingErrorAttachmentE2EItem(fileName); + } + public getDownloadAttachmentsButton(): Cypress.Chainable<JQuery<HTMLElement>> { return this.getRoot().findTestElementWithClass(this.downloadAttachmentsButton); } @@ -79,3 +83,16 @@ class AttachmentE2EItem { return this.getRoot().findTestElementWithClass(this.locatorDownloadButton); } } + +class LoadingErrorAttachmentE2EItem { + private locatorRoot: string; + private readonly attachmentSuffixLocattor: string = '-file-upload-list-item-attachment-upload'; + + constructor(private fileName: string) { + this.locatorRoot = convertToDataTestId(this.fileName) + this.attachmentSuffixLocattor; + } + + public getRoot() { + return cy.getTestElement(this.locatorRoot); + } +} diff --git a/alfa-client/apps/alfa-e2e/src/e2e/main-tests/wiedervorlage-attachment/wiedervorlage-attachment.cy.ts b/alfa-client/apps/alfa-e2e/src/e2e/main-tests/wiedervorlage-attachment/wiedervorlage-attachment.cy.ts index 753c03ac4b..a32737f51b 100644 --- a/alfa-client/apps/alfa-e2e/src/e2e/main-tests/wiedervorlage-attachment/wiedervorlage-attachment.cy.ts +++ b/alfa-client/apps/alfa-e2e/src/e2e/main-tests/wiedervorlage-attachment/wiedervorlage-attachment.cy.ts @@ -21,47 +21,26 @@ * Die sprachspezifischen Genehmigungen und Beschränkungen * unter der Lizenz sind dem Lizenztext zu entnehmen. */ -import { - AttachmentContainerE2EComponent, - AttachmentListE2EComponent, -} from 'apps/alfa-e2e/src/components/attachment/attachment.e2e.component'; +import { AttachmentContainerE2EComponent, AttachmentListE2EComponent, } from 'apps/alfa-e2e/src/components/attachment/attachment.e2e.component'; import { WiedervorlageSubnavigationE2EComponent } from 'apps/alfa-e2e/src/components/wiedervorlage/wiedervorlage-subnavigation'; -import { BinaryFileSnackbarMessageE2E } from 'apps/alfa-e2e/src/model/binary-file'; import { WiedervorlageE2E } from 'apps/alfa-e2e/src/model/wiedervorlage'; -import { - dropCollections, - readFileFromDownloads, - wait, -} from 'apps/alfa-e2e/src/support/cypress-helper'; +import { dropCollections, readFileFromDownloads, wait } from 'apps/alfa-e2e/src/support/cypress-helper'; import { initVorgangAttachedItem } from 'apps/alfa-e2e/src/support/vorgang-attached-item-util'; import { SnackBarE2EComponent } from '../../../components/ui/snackbar.e2e.component'; import { VorgangListE2EComponent } from '../../../components/vorgang/vorgang-list.e2e.component'; import { WiedervorlageInVorgangE2EComponent } from '../../../components/wiedervorlage/wiedervorlage-in-vorgang.e2e.component'; import { WiedervorlageE2EComponent } from '../../../components/wiedervorlage/wiedervorlage-page.e2e.component'; +import { BinaryFileSnackbarMessageE2E } from '../../../model/binary-file'; import { VorgangE2E } from '../../../model/vorgang'; import { MainPage, waitForSpinnerToDisappear } from '../../../page-objects/main.po'; import { VorgangPage } from '../../../page-objects/vorgang.po'; import { WiedervorlagePage } from '../../../page-objects/wiedervorlage.po'; -import { - containClass, - contains, - exist, - haveLength, - notContainClass, - notExist, -} from '../../../support/cypress.util'; -import { - TEST_FILE_WITHOUT_CONTENT, - TEST_FILE_WITH_CONTENT, - TEST_FILE_WITH_CONTENT_46MB, -} from '../../../support/data.util'; +import { containClass, contains, exist, haveLength, notContainClass, notExist } from '../../../support/cypress.util'; +import { TEST_FILE_WITH_CONTENT, TEST_FILE_WITH_CONTENT_46MB, TEST_FILE_WITHOUT_CONTENT } from '../../../support/data.util'; import { uploadEmptyFile, uploadFile } from '../../../support/file-upload'; import { loginAsSabine } from '../../../support/user-util'; import { createVorgang, initVorgang, objectIds } from '../../../support/vorgang-util'; -import { - createWiedervorlageAttachedItem, - createWiedervorlageItem, -} from '../../../support/wiedervorlage-util'; +import { createWiedervorlageAttachedItem, createWiedervorlageItem } from '../../../support/wiedervorlage-util'; describe('Wiedervorlage attachments', () => { const mainPage: MainPage = new MainPage(); @@ -74,13 +53,10 @@ describe('Wiedervorlage attachments', () => { const wiedervorlageContainerInVorgang = vorgangPage.getWiedervorlagenContainer(); const wiedervorlagePage: WiedervorlagePage = new WiedervorlagePage(); - const wiedervorlageContainer: WiedervorlageE2EComponent = - wiedervorlagePage.getWiedervorlageContainer(); - const attachmentContainer: AttachmentContainerE2EComponent = - wiedervorlageContainer.getAttachmentContainer(); + const wiedervorlageContainer: WiedervorlageE2EComponent = wiedervorlagePage.getWiedervorlageContainer(); + const attachmentContainer: AttachmentContainerE2EComponent = wiedervorlageContainer.getAttachmentContainer(); const attachmentList: AttachmentListE2EComponent = attachmentContainer.getList(); - const subnavigation: WiedervorlageSubnavigationE2EComponent = - wiedervorlagePage.getSubnavigation(); + const subnavigation: WiedervorlageSubnavigationE2EComponent = wiedervorlagePage.getSubnavigation(); const snackbar: SnackBarE2EComponent = mainPage.getSnackBar(); @@ -140,23 +116,17 @@ describe('Wiedervorlage attachments', () => { exist(attachmentList.getItem(TEST_FILE_WITH_CONTENT).getRoot()); }); - it('should error snackbar after upload to large file', { defaultCommandTimeout: 30000 }, () => { + it('should show failed upload', { defaultCommandTimeout: 30000 }, () => { uploadFile(attachmentContainer.getUploadInput(), TEST_FILE_WITH_CONTENT_46MB); waitForSpinnerToDisappear(); - exist(snackbar.getMessage()); + exist(attachmentList.getLoadingOrErrorItem(TEST_FILE_WITH_CONTENT_46MB).getRoot()); contains( - snackbar.getMessage(), + attachmentList.getLoadingOrErrorItem(TEST_FILE_WITH_CONTENT_46MB).getRoot(), BinaryFileSnackbarMessageE2E.ATTACHMENT_NOT_ADDED.replace('{size}', '40MB'), ); }); - it('should close snackbar on close button', () => { - snackbar.getCloseButton().click(); - - notExist(snackbar.getMessage()); - }); - it('should download attachment on click', () => { attachmentList.getItem(TEST_FILE_WITH_CONTENT).getDownloadButton().click(); waitForSpinnerToDisappear(); @@ -169,10 +139,7 @@ describe('Wiedervorlage attachments', () => { wiedervorlageContainer.getSpeichernButton().click(); exist(snackbar.getMessage()); - contains( - snackbar.getMessage(), - 'Die Wiedervorlage "' + WIEDERVORLAGE_WITH_ATTACHMENTS_BETREFF + '" wurde angelegt', - ); + contains(snackbar.getMessage(), 'Die Wiedervorlage "' + WIEDERVORLAGE_WITH_ATTACHMENTS_BETREFF + '" wurde angelegt'); exist(snackbar.getCloseButton()); }); @@ -183,9 +150,7 @@ describe('Wiedervorlage attachments', () => { }); it('should show attachments on wiedervorlage in vorgang-detail after save ', () => { - wiedervorlageContainerInVorgang - .getWiedervorlage(WIEDERVORLAGE_WITH_ATTACHMENTS_BETREFF) - .expandItem(); + wiedervorlageContainerInVorgang.getWiedervorlage(WIEDERVORLAGE_WITH_ATTACHMENTS_BETREFF).expandItem(); exist( wiedervorlageContainerInVorgang @@ -203,6 +168,14 @@ describe('Wiedervorlage attachments', () => { .getItem(TEST_FILE_WITH_CONTENT) .getRoot(), ); + notExist( + wiedervorlageContainerInVorgang + .getWiedervorlage(WIEDERVORLAGE_WITH_ATTACHMENTS_BETREFF) + .getAttachmentContainer() + .getList() + .getLoadingOrErrorItem(TEST_FILE_WITH_CONTENT_46MB) + .getRoot(), + ); }); it('should download empty attachment on click in list', () => { @@ -233,8 +206,9 @@ describe('Wiedervorlage attachments', () => { }); describe('Delete attachment', () => { - const wiedervorlageComp: WiedervorlageInVorgangE2EComponent = - wiedervorlageContainerInVorgang.getWiedervorlage(WIEDERVORLAGE_WITH_ATTACHMENTS_BETREFF); + const wiedervorlageComp: WiedervorlageInVorgangE2EComponent = wiedervorlageContainerInVorgang.getWiedervorlage( + WIEDERVORLAGE_WITH_ATTACHMENTS_BETREFF, + ); it('should open wiedervorlage page', () => { wiedervorlageComp.getLink().click(); @@ -256,66 +230,41 @@ describe('Wiedervorlage attachments', () => { wiedervorlageContainer.getSpeichernButton().click(); exist(snackbar.getMessage()); - contains( - snackbar.getMessage(), - `Die Wiedervorlage "${WIEDERVORLAGE_WITH_ATTACHMENTS_BETREFF}" wurde gespeichert`, - ); + contains(snackbar.getMessage(), `Die Wiedervorlage "${WIEDERVORLAGE_WITH_ATTACHMENTS_BETREFF}" wurde gespeichert`); snackbar.getCloseButton().click(); }); - it('(Skip reason in OZG-4658) check attachments in wiedervorlage list', () => { + it('check attachments in wiedervorlage list', () => { waitForSpinnerToDisappear(); wiedervorlageComp.getExpandButton(); wiedervorlageComp.expandItem(); - notExist( - wiedervorlageComp - .getAttachmentContainer() - .getList() - .getItem(TEST_FILE_WITHOUT_CONTENT) - .getRoot(), - ); - exist( - wiedervorlageComp - .getAttachmentContainer() - .getList() - .getItem(TEST_FILE_WITH_CONTENT) - .getRoot(), - ); + notExist(wiedervorlageComp.getAttachmentContainer().getList().getItem(TEST_FILE_WITHOUT_CONTENT).getRoot()); + exist(wiedervorlageComp.getAttachmentContainer().getList().getItem(TEST_FILE_WITH_CONTENT).getRoot()); }); }); describe('switch to wiedervorlage without attachments', () => { - const wiedervorlageComp: WiedervorlageInVorgangE2EComponent = - wiedervorlageContainerInVorgang.getWiedervorlage(wiedervorlage.betreff); + const wiedervorlageComp: WiedervorlageInVorgangE2EComponent = wiedervorlageContainerInVorgang.getWiedervorlage( + wiedervorlage.betreff, + ); it('should not show any attachments', () => { wiedervorlageComp.getLink().click(); waitForSpinnerToDisappear(); - notExist( - wiedervorlageComp - .getAttachmentContainer() - .getList() - .getItem(TEST_FILE_WITHOUT_CONTENT) - .getRoot(), - ); - notExist( - wiedervorlageComp - .getAttachmentContainer() - .getList() - .getItem(TEST_FILE_WITH_CONTENT) - .getRoot(), - ); + notExist(wiedervorlageComp.getAttachmentContainer().getList().getItem(TEST_FILE_WITHOUT_CONTENT).getRoot()); + notExist(wiedervorlageComp.getAttachmentContainer().getList().getItem(TEST_FILE_WITH_CONTENT).getRoot()); wiedervorlagePage.getSubnavigation().navigateBack(); }); }); describe('Same number of attachments after status change', () => { - const wiedervorlageComp: WiedervorlageInVorgangE2EComponent = - wiedervorlageContainerInVorgang.getWiedervorlage(WIEDERVORLAGE_WITH_ATTACHMENTS_BETREFF); + const wiedervorlageComp: WiedervorlageInVorgangE2EComponent = wiedervorlageContainerInVorgang.getWiedervorlage( + WIEDERVORLAGE_WITH_ATTACHMENTS_BETREFF, + ); it('should open wiedervorlage page', () => { wait(500); @@ -332,10 +281,7 @@ describe('Wiedervorlage attachments', () => { waitForSpinnerToDisappear(); containClass(wiedervorlageContainer.getStatusDot(), 'erledigt'); - contains( - snackBar.getMessage(), - `Die Wiedervorlage ${WIEDERVORLAGE_WITH_ATTACHMENTS_BETREFF} wurde erledigt`, - ); + contains(snackBar.getMessage(), `Die Wiedervorlage ${WIEDERVORLAGE_WITH_ATTACHMENTS_BETREFF} wurde erledigt`); }); it('should close snackBar on close', () => { @@ -350,10 +296,7 @@ describe('Wiedervorlage attachments', () => { waitForSpinnerToDisappear(); notContainClass(wiedervorlageContainer.getStatusDot(), 'erledigt'); - contains( - snackBar.getMessage(), - `Die Wiedervorlage ${WIEDERVORLAGE_WITH_ATTACHMENTS_BETREFF} wurde wiedereröffnet`, - ); + contains(snackBar.getMessage(), `Die Wiedervorlage ${WIEDERVORLAGE_WITH_ATTACHMENTS_BETREFF} wurde wiedereröffnet`); }); it('should close snackBar on close', () => { @@ -385,10 +328,7 @@ describe('Wiedervorlage attachments', () => { waitForSpinnerToDisappear(); exist(snackbar.getMessage()); - contains( - snackbar.getMessage(), - `Die Wiedervorlage "${WIEDERVORLAGE_WITH_ATTACHMENTS_BETREFF}" wurde gespeichert`, - ); + contains(snackbar.getMessage(), `Die Wiedervorlage "${WIEDERVORLAGE_WITH_ATTACHMENTS_BETREFF}" wurde gespeichert`); }); it('should close snackBar on close', () => { @@ -398,26 +338,15 @@ describe('Wiedervorlage attachments', () => { }); it('(Skip reason in OZG-4658) should have no attachments after save', () => { - const wiedervorlageComp: WiedervorlageInVorgangE2EComponent = - wiedervorlageContainerInVorgang.getWiedervorlage(WIEDERVORLAGE_WITH_ATTACHMENTS_BETREFF); + const wiedervorlageComp: WiedervorlageInVorgangE2EComponent = wiedervorlageContainerInVorgang.getWiedervorlage( + WIEDERVORLAGE_WITH_ATTACHMENTS_BETREFF, + ); wiedervorlageComp.getExpandButton(); wiedervorlageComp.expandItem(); - notExist( - wiedervorlageComp - .getAttachmentContainer() - .getList() - .getItem(TEST_FILE_WITHOUT_CONTENT) - .getRoot(), - ); - notExist( - wiedervorlageComp - .getAttachmentContainer() - .getList() - .getItem(TEST_FILE_WITH_CONTENT) - .getRoot(), - ); + notExist(wiedervorlageComp.getAttachmentContainer().getList().getItem(TEST_FILE_WITHOUT_CONTENT).getRoot()); + notExist(wiedervorlageComp.getAttachmentContainer().getList().getItem(TEST_FILE_WITH_CONTENT).getRoot()); }); }); }); diff --git a/alfa-client/libs/binary-file/src/lib/file-upload-list-container/file-upload-list-item/file-upload-list-item.component.html b/alfa-client/libs/binary-file/src/lib/file-upload-list-container/file-upload-list-item/file-upload-list-item.component.html index edb77f9c7d..c6e0aa4b17 100644 --- a/alfa-client/libs/binary-file/src/lib/file-upload-list-container/file-upload-list-item/file-upload-list-item.component.html +++ b/alfa-client/libs/binary-file/src/lib/file-upload-list-container/file-upload-list-item/file-upload-list-item.component.html @@ -5,7 +5,7 @@ [errorMessages]="uploadFile.uploadedFile.error | convertProblemDetailToErrorMessages" description="Anhang wird hochgeladen" [isLoading]="uploadFile.uploadedFile.loading" - data-test-id="file-upload-list-item-attachment-upload" + [attr.data-test-id]="(uploadFile.fileToUpload.name | convertForDataTest) + '-file-upload-list-item-attachment-upload'" ></ods-attachment> } @else if (uploadFile.uploadedFile.resource) { <ods-attachment-wrapper> @@ -13,7 +13,7 @@ [file]="uploadFile.uploadedFile.resource" [deletable]="true" (startDelete)="delete.emit({ key, binaryFileResource: $event })" - data-test-id="file-upload-list-item-uploaded" + [attr.data-test-id]="(uploadFile.uploadedFile.resource.name | convertForDataTest) + '-file-upload-list-item-uploaded'" > </alfa-binary-file2-container> </ods-attachment-wrapper> diff --git a/alfa-client/libs/binary-file/src/lib/file-upload-list-container/file-upload-list-item/file-upload-list-item.component.spec.ts b/alfa-client/libs/binary-file/src/lib/file-upload-list-container/file-upload-list-item/file-upload-list-item.component.spec.ts index f60c72fda9..8497dfcbc9 100644 --- a/alfa-client/libs/binary-file/src/lib/file-upload-list-container/file-upload-list-item/file-upload-list-item.component.spec.ts +++ b/alfa-client/libs/binary-file/src/lib/file-upload-list-container/file-upload-list-item/file-upload-list-item.component.spec.ts @@ -29,8 +29,10 @@ describe('FileUploadListItemComponent', () => { let component: FileUploadListItemComponent; let fixture: ComponentFixture<FileUploadListItemComponent>; - const attachmentTestId: string = getDataTestIdOf('file-upload-list-item-attachment-upload'); - const binaryFileContainerTestId: string = getDataTestIdOf('file-upload-list-item-uploaded'); + const file: File = createFile(); + const binaryFileResource: BinaryFileResource = createBinaryFileResource(); + const attachmentTestId: string = getDataTestIdOf(file.name + '-file-upload-list-item-attachment-upload'); + const binaryFileContainerTestId: string = getDataTestIdOf(binaryFileResource.name + '-file-upload-list-item-uploaded'); beforeEach(async () => { await TestBed.configureTestingModule({ @@ -50,8 +52,6 @@ describe('FileUploadListItemComponent', () => { }); describe('template', () => { - const file: File = createFile(); - beforeEach(() => { component.uploadFile.fileToUpload = file; }); @@ -74,7 +74,7 @@ describe('FileUploadListItemComponent', () => { }); it('should NOT exists on loaded', () => { - component.uploadFile.uploadedFile = createStateResource(createBinaryFileResource()); + component.uploadFile.uploadedFile = createStateResource(binaryFileResource); fixture.detectChanges(); @@ -82,7 +82,7 @@ describe('FileUploadListItemComponent', () => { }); it('should have inputs', () => { - component.uploadFile.fileToUpload = createFile(); + component.uploadFile.fileToUpload = file; component.uploadFile.uploadedFile = createEmptyStateResource(true); fixture.detectChanges(); @@ -97,7 +97,7 @@ describe('FileUploadListItemComponent', () => { describe('uploaded file', () => { it('should exists', () => { - component.uploadFile.uploadedFile = createStateResource(createBinaryFileResource()); + component.uploadFile.uploadedFile = createStateResource(binaryFileResource); fixture.detectChanges(); @@ -113,7 +113,7 @@ describe('FileUploadListItemComponent', () => { }); it('should have inputs', () => { - component.uploadFile.uploadedFile = createStateResource(createBinaryFileResource()); + component.uploadFile.uploadedFile = createStateResource(binaryFileResource); fixture.detectChanges(); @@ -131,7 +131,6 @@ describe('FileUploadListItemComponent', () => { it('should emit', () => { component.delete.emit = jest.fn(); component.key = 'test'; - const binaryFileResource: BinaryFileResource = createBinaryFileResource(); component.uploadFile.uploadedFile = createStateResource(binaryFileResource); fixture.detectChanges(); diff --git a/alfa-client/libs/binary-file/src/lib/file-upload-list-container/file-upload-list-item/file-upload-list-item.component.ts b/alfa-client/libs/binary-file/src/lib/file-upload-list-container/file-upload-list-item/file-upload-list-item.component.ts index 25527119bd..854f6f0466 100644 --- a/alfa-client/libs/binary-file/src/lib/file-upload-list-container/file-upload-list-item/file-upload-list-item.component.ts +++ b/alfa-client/libs/binary-file/src/lib/file-upload-list-container/file-upload-list-item/file-upload-list-item.component.ts @@ -1,6 +1,6 @@ import { BinaryFileModule } from '@alfa-client/binary-file'; import { FileToDelete, UploadFile } from '@alfa-client/binary-file-shared'; -import { ConvertProblemDetailToErrorMessagesPipe } from '@alfa-client/tech-shared'; +import { ConvertForDataTestPipe, ConvertProblemDetailToErrorMessagesPipe } from '@alfa-client/tech-shared'; import { Component, EventEmitter, Input, Output } from '@angular/core'; import { AttachmentComponent, AttachmentWrapperComponent } from '@ods/system'; @@ -8,7 +8,13 @@ import { AttachmentComponent, AttachmentWrapperComponent } from '@ods/system'; selector: 'ods-file-upload-list-item', standalone: true, templateUrl: './file-upload-list-item.component.html', - imports: [AttachmentComponent, AttachmentWrapperComponent, BinaryFileModule, ConvertProblemDetailToErrorMessagesPipe], + imports: [ + AttachmentComponent, + AttachmentWrapperComponent, + BinaryFileModule, + ConvertProblemDetailToErrorMessagesPipe, + ConvertForDataTestPipe, + ], }) export class FileUploadListItemComponent { @Input() key: string; diff --git a/alfa-client/libs/binary-file/src/lib/multi-file-upload/multi-file-upload.component.html b/alfa-client/libs/binary-file/src/lib/multi-file-upload/multi-file-upload.component.html index cdc81882c5..184ac868f9 100644 --- a/alfa-client/libs/binary-file/src/lib/multi-file-upload/multi-file-upload.component.html +++ b/alfa-client/libs/binary-file/src/lib/multi-file-upload/multi-file-upload.component.html @@ -3,7 +3,7 @@ [fileUploadType]="fileUploadType" [filesResource]="filesResource" [filesLinkRel]="filesLinkRelation" - data-test-id="multi-file-upload-list" + data-test-id="file-list" ></ods-file-upload-list-container> <ods-multi-file-upload-editor [fileUploadType]="fileUploadType" -- GitLab