From 9f1798ca1838c8da6c06b24fdb1e16624eaf08d0 Mon Sep 17 00:00:00 2001 From: Albert <Albert.Bruns@mgm-tp.com> Date: Fri, 21 Mar 2025 09:51:47 +0100 Subject: [PATCH] OZG-7473 e2e --- .../aggregation-mapping-form.e2e.component.ts | 48 +++++------- .../aggregation-mapping.e2e.component.ts | 23 +++++- .../aggregation-mapping.cy.ts | 75 ++++++++++++------- .../aggregation-mapping.helper.ts | 65 ++++++++++++++++ .../admin-e2e/src/support/cypress-helper.ts | 2 + ...ggregation-mapping-field-form.component.ts | 2 +- ...ion-mapping-field-list-form.component.html | 4 +- ...gregation-mapping-list-item.component.html | 4 +- 8 files changed, 160 insertions(+), 63 deletions(-) create mode 100644 alfa-client/apps/admin-e2e/src/helper/aggregation-mapping/aggregation-mapping.helper.ts diff --git a/alfa-client/apps/admin-e2e/src/components/aggregation-mapping/aggregation-mapping-form.e2e.component.ts b/alfa-client/apps/admin-e2e/src/components/aggregation-mapping/aggregation-mapping-form.e2e.component.ts index 112cc9e0aa..2545b8b6b6 100644 --- a/alfa-client/apps/admin-e2e/src/components/aggregation-mapping/aggregation-mapping-form.e2e.component.ts +++ b/alfa-client/apps/admin-e2e/src/components/aggregation-mapping/aggregation-mapping-form.e2e.component.ts @@ -1,67 +1,57 @@ -import { enterWith } from '../../support/cypress.util'; - export class AggregationMappingFormE2EComponent { + private readonly rootElement: string = 'aggregation-mapping-form'; + private readonly nameInput: string = 'aggregation-mapping-name-text-input'; private readonly formEngineInput: string = 'form-engine-name-text-input'; private readonly formIdInput: string = 'form-id-text-input'; - private readonly formDataFieldInput: string = 'mapping-field-'; + private readonly dataFieldInputPrefix: string = 'aggregation-mapping-field-mapping-form-'; + private readonly sourceMappingFieldInputPrefix: string = 'source-mapping-field-'; + private readonly targetMappingFieldInputPrefix: string = 'target-mapping-field-'; private readonly addDataFieldButton: string = 'add-mapping-button'; private readonly deleteDataFieldButtonPrefix: string = 'remove-mapping-button-'; private readonly saveButton: string = 'save-button'; private readonly cancelButton: string = 'cancel-button'; - public getFormEngineInput(): Cypress.Chainable<Element> { - return cy.getTestElement(this.formEngineInput); + public getRootElement(): Cypress.Chainable<Element> { + return cy.getTestElement(this.rootElement); } - public enterFormEngine(text: string): void { - enterWith(this.getFormEngineInput(), text); + public getNameInput(): Cypress.Chainable<Element> { + return cy.getTestElement(this.nameInput); + } + + public getFormEngineInput(): Cypress.Chainable<Element> { + return cy.getTestElement(this.formEngineInput); } public getFormIdInput(): Cypress.Chainable<Element> { return cy.getTestElement(this.formIdInput); } - public enterFormId(text: string): void { - enterWith(this.getFormIdInput(), text); + public getDataFieldInput(index: number): Cypress.Chainable<Element> { + return cy.getTestElement(`${this.dataFieldInputPrefix}${index}`); } public getAddFieldButton(): Cypress.Chainable<Element> { return cy.getTestElement(this.addDataFieldButton); } - public addField(): void { - this.getAddFieldButton().click(); + public getSourceMappingFieldInput(index: number): Cypress.Chainable<Element> { + return cy.getTestElement(`${this.sourceMappingFieldInputPrefix}${index}-text-input`); } - public getDataFieldInput(index: number): Cypress.Chainable<Element> { - return cy.getTestElement(this.formDataFieldInput + index + '-text-input'); - } - - public enterDataFieldPath(text: string, index: number): void { - enterWith(this.getDataFieldInput(index), text); + public getTargetMappingFieldInput(index: number): Cypress.Chainable<Element> { + return cy.getTestElement(`${this.targetMappingFieldInputPrefix}${index}-text-input`); } public getDataFieldDeleteButton(index: number): Cypress.Chainable<Element> { return cy.getTestElement(this.deleteDataFieldButtonPrefix + index); } - public deleteDataField(index: number): void { - this.getDataFieldDeleteButton(index).click(); - } - public getSaveButton(): Cypress.Chainable<Element> { return cy.getTestElement(this.saveButton); } - public save(): void { - this.getSaveButton().click(); - } - public getCancelButton(): Cypress.Chainable<Element> { return cy.getTestElement(this.cancelButton); } - - public cancel(): void { - this.getCancelButton().click(); - } } diff --git a/alfa-client/apps/admin-e2e/src/components/aggregation-mapping/aggregation-mapping.e2e.component.ts b/alfa-client/apps/admin-e2e/src/components/aggregation-mapping/aggregation-mapping.e2e.component.ts index 8e9ad4a76d..10e67b06e5 100644 --- a/alfa-client/apps/admin-e2e/src/components/aggregation-mapping/aggregation-mapping.e2e.component.ts +++ b/alfa-client/apps/admin-e2e/src/components/aggregation-mapping/aggregation-mapping.e2e.component.ts @@ -1,12 +1,27 @@ export class AggregationMappingE2EComponent { - private readonly locatorHeaderText: string = 'aggregation-mapping-header-text'; - private readonly locatorWeitereFelderAuswertenButton = 'weitere-felder-auswerten-button'; + private readonly headerText: string = 'aggregation-mapping-header-text'; + private readonly listItemName: string = 'list-item-name'; + private readonly listItemFormEngineName: string = 'list-item-form-engine-name'; + private readonly listItemFormId: string = 'list-item-form-id'; + private readonly weitereFelderAuswertenButton = 'weitere-felder-auswerten-button'; public getHeaderText(): Cypress.Chainable<Element> { - return cy.getTestElement(this.locatorHeaderText); + return cy.getTestElement(this.headerText); + } + + public getListItemName(): Cypress.Chainable<Element> { + return cy.getTestElementWithClass(this.listItemName); + } + + public getListItemFormEngineName(): Cypress.Chainable<Element> { + return cy.getTestElementWithClass(this.listItemFormEngineName); + } + + public getListItemFormId(): Cypress.Chainable<Element> { + return cy.getTestElementWithClass(this.listItemFormId); } public getWeitereFelderAuswertenButton(): Cypress.Chainable<Element> { - return cy.getTestElement(this.locatorWeitereFelderAuswertenButton); + return cy.getTestElement(this.weitereFelderAuswertenButton); } } diff --git a/alfa-client/apps/admin-e2e/src/e2e/main-tests/aggregation-mapping/aggregation-mapping.cy.ts b/alfa-client/apps/admin-e2e/src/e2e/main-tests/aggregation-mapping/aggregation-mapping.cy.ts index 91ed35a2dd..e1a594ff31 100644 --- a/alfa-client/apps/admin-e2e/src/e2e/main-tests/aggregation-mapping/aggregation-mapping.cy.ts +++ b/alfa-client/apps/admin-e2e/src/e2e/main-tests/aggregation-mapping/aggregation-mapping.cy.ts @@ -1,57 +1,82 @@ +import { AggregationMapping, FieldMapping } from '@admin-client/reporting-shared'; import { AggregationMappingFormE2EComponent } from '../../../components/aggregation-mapping/aggregation-mapping-form.e2e.component'; import { AggregationMappingE2EComponent } from '../../../components/aggregation-mapping/aggregation-mapping.e2e.component'; -import { exist, haveValue } from '../../../support/cypress.util'; +import { E2EAggregationMappingHelper } from '../../../helper/aggregation-mapping/aggregation-mapping.helper'; +import { dropCollections } from '../../../support/cypress-helper'; +import { exist, notExist } from '../../../support/cypress.util'; import { loginAsDaria } from '../../../support/user-util'; describe('Aggregation Mapping hinzufügen', () => { const component: AggregationMappingE2EComponent = new AggregationMappingE2EComponent(); - const fieldsFormComponent: AggregationMappingFormE2EComponent = new AggregationMappingFormE2EComponent(); + const formComponent: AggregationMappingFormE2EComponent = new AggregationMappingFormE2EComponent(); - const dataText1: string = 'Eingabe A'; - const dataText2: string = 'Eingabe B'; + const helper: E2EAggregationMappingHelper = new E2EAggregationMappingHelper(); + + const fieldMapping0: FieldMapping = { + sourcePath: '/path/to/source/a', + targetPath: '/path/to/target/a', + }; + + const fieldMapping1: FieldMapping = { + sourcePath: '/path/to/source/b', + targetPath: '/path/to/target/b', + }; + + const aggregationMapping: AggregationMapping = { + name: 'Aggregation Mapping', + formIdentifier: { + formEngineName: 'formEngineName', + formId: 'formId', + }, + mappings: [fieldMapping0, fieldMapping1], + }; before(() => { loginAsDaria(); }); + after(() => { + dropCollections(); + }); + it('should show "Weitere Felder auswerten" button', () => { exist(component.getWeitereFelderAuswertenButton()); }); - it('should have all form elements after button click', () => { + it('should show form after button click', () => { component.getWeitereFelderAuswertenButton().click(); - exist(fieldsFormComponent.getFormEngineInput()); - exist(fieldsFormComponent.getFormIdInput()); - exist(fieldsFormComponent.getDataFieldInput(0)); - exist(fieldsFormComponent.getDataFieldDeleteButton(0)); - exist(fieldsFormComponent.getAddFieldButton()); - exist(fieldsFormComponent.getSaveButton()); - exist(fieldsFormComponent.getCancelButton()); + exist(formComponent.getRootElement()); + }); + + it('should navigate to aggregation mapping on cancel', () => { + formComponent.getCancelButton().click(); + + exist(component.getWeitereFelderAuswertenButton()); }); - it('should add data field', () => { - fieldsFormComponent.addField(); + it('should add data field in form', () => { + component.getWeitereFelderAuswertenButton().click(); + formComponent.getAddFieldButton().click(); - exist(fieldsFormComponent.getDataFieldInput(1)); + exist(formComponent.getDataFieldInput(1)); }); - it('should enter text in both data fields', () => { - fieldsFormComponent.enterDataFieldPath(dataText1, 0); - fieldsFormComponent.enterDataFieldPath(dataText2, 1); + it('should fill out form with two data fields', () => { + helper.enterForm(aggregationMapping); - haveValue(fieldsFormComponent.getDataFieldInput(0), dataText1); - haveValue(fieldsFormComponent.getDataFieldInput(1), dataText2); + helper.verifyForm(aggregationMapping); }); it('should delete data fields', () => { - fieldsFormComponent.deleteDataField(0); - haveValue(fieldsFormComponent.getDataFieldInput(0), dataText2); + formComponent.getDataFieldDeleteButton(0).click(); + + notExist(formComponent.getDataFieldInput(1)); }); - it('should navigate to aggregation mapping on cancel', () => { - fieldsFormComponent.cancel(); + it('should show aggregation mapping in list after save', () => { + formComponent.getSaveButton().click(); - exist(component.getWeitereFelderAuswertenButton()); + helper.verifyAggregationMappingInList(aggregationMapping); }); }); diff --git a/alfa-client/apps/admin-e2e/src/helper/aggregation-mapping/aggregation-mapping.helper.ts b/alfa-client/apps/admin-e2e/src/helper/aggregation-mapping/aggregation-mapping.helper.ts new file mode 100644 index 0000000000..b36249dc2f --- /dev/null +++ b/alfa-client/apps/admin-e2e/src/helper/aggregation-mapping/aggregation-mapping.helper.ts @@ -0,0 +1,65 @@ +import { AggregationMapping, FieldMapping } from '@admin-client/reporting-shared'; +import { AggregationMappingFormE2EComponent } from '../../components/aggregation-mapping/aggregation-mapping-form.e2e.component'; +import { AggregationMappingE2EComponent } from '../../components/aggregation-mapping/aggregation-mapping.e2e.component'; +import { enterWith, haveText, haveValue } from '../../support/cypress.util'; + +export class E2EAggregationMappingHelper { + private component: AggregationMappingE2EComponent = new AggregationMappingE2EComponent(); + private formComponent: AggregationMappingFormE2EComponent = new AggregationMappingFormE2EComponent(); + + public enterName(text: string): void { + enterWith(this.formComponent.getNameInput(), text); + } + + public enterFormEngine(text: string): void { + enterWith(this.formComponent.getFormEngineInput(), text); + } + + public enterFormId(text: string): void { + enterWith(this.formComponent.getFormIdInput(), text); + } + + public enterSourcePath(text: string, index: number): void { + enterWith(this.formComponent.getSourceMappingFieldInput(index), text); + } + + public enterTargetPath(text: string, index: number): void { + enterWith(this.formComponent.getTargetMappingFieldInput(index), text); + } + + public enterFieldMapping(fieldMapping: FieldMapping, index: number): void { + this.enterSourcePath(fieldMapping.sourcePath, index); + this.enterTargetPath(fieldMapping.targetPath, index); + } + + public enterForm(aggregationMapping: AggregationMapping): void { + this.enterName(aggregationMapping.name); + this.enterFormEngine(aggregationMapping.formIdentifier.formEngineName); + this.enterFormId(aggregationMapping.formIdentifier.formId); + + aggregationMapping.mappings.forEach((fieldMapping, index) => { + this.enterFieldMapping(fieldMapping, index); + }); + } + + public verifyFieldMapping(fieldMapping: FieldMapping, index: number): void { + haveValue(this.formComponent.getSourceMappingFieldInput(index), fieldMapping.sourcePath); + haveValue(this.formComponent.getTargetMappingFieldInput(index), fieldMapping.targetPath); + } + + public verifyForm(aggregationMapping: AggregationMapping): void { + haveValue(this.formComponent.getNameInput(), aggregationMapping.name); + haveValue(this.formComponent.getFormEngineInput(), aggregationMapping.formIdentifier.formEngineName); + haveValue(this.formComponent.getFormIdInput(), aggregationMapping.formIdentifier.formId); + + aggregationMapping.mappings.forEach((fieldMapping, index) => { + this.verifyFieldMapping(fieldMapping, index); + }); + } + + public verifyAggregationMappingInList(aggregationMapping: AggregationMapping): void { + haveText(this.component.getListItemName(), aggregationMapping.name); + haveText(this.component.getListItemFormEngineName(), aggregationMapping.formIdentifier.formEngineName); + haveText(this.component.getListItemFormId(), aggregationMapping.formIdentifier.formId); + } +} diff --git a/alfa-client/apps/admin-e2e/src/support/cypress-helper.ts b/alfa-client/apps/admin-e2e/src/support/cypress-helper.ts index a48d664eb7..83e7bb11f0 100644 --- a/alfa-client/apps/admin-e2e/src/support/cypress-helper.ts +++ b/alfa-client/apps/admin-e2e/src/support/cypress-helper.ts @@ -31,6 +31,7 @@ enum CypressTasks { enum MongoCollections { ORGANISATIONS_EINHEIT = 'organisationsEinheit', + SETTINGS = 'settings', } const DOWNLOAD_FOLDER: string = 'cypress/downloads'; @@ -110,4 +111,5 @@ export function initOrganisationsEinheitenData(data: OrganisationsEinheitE2E[]): export function dropCollections() { cy.task(CypressTasks.DROP_COLLECTIONS, [MongoCollections.ORGANISATIONS_EINHEIT]); + cy.task(CypressTasks.DROP_COLLECTIONS, [MongoCollections.SETTINGS]); } diff --git a/alfa-client/libs/admin/aggregation-mapping/src/lib/aggregation-mapping-form-container/aggregation-mapping-form/aggregation-mapping-field-list-form/aggregation-mapping-field-form/aggregation-mapping-field-form.component.ts b/alfa-client/libs/admin/aggregation-mapping/src/lib/aggregation-mapping-form-container/aggregation-mapping-form/aggregation-mapping-field-list-form/aggregation-mapping-field-form/aggregation-mapping-field-form.component.ts index e80a74f035..d7e2e1f162 100644 --- a/alfa-client/libs/admin/aggregation-mapping/src/lib/aggregation-mapping-form-container/aggregation-mapping-form/aggregation-mapping-field-list-form/aggregation-mapping-field-form/aggregation-mapping-field-form.component.ts +++ b/alfa-client/libs/admin/aggregation-mapping/src/lib/aggregation-mapping-form-container/aggregation-mapping-form/aggregation-mapping-field-list-form/aggregation-mapping-field-form/aggregation-mapping-field-form.component.ts @@ -6,7 +6,7 @@ import { ButtonComponent, DeleteIconComponent } from '@ods/system'; import { AggregationMappingFormService } from '../../aggregation-mapping-form.service'; @Component({ - selector: 'admin-aggregatin-mapping-field-form', + selector: 'admin-aggregation-mapping-field-form', standalone: true, templateUrl: './aggregation-mapping-field-form.component.html', imports: [ButtonComponent, DeleteIconComponent, ReactiveFormsModule, TextEditorComponent], diff --git a/alfa-client/libs/admin/aggregation-mapping/src/lib/aggregation-mapping-form-container/aggregation-mapping-form/aggregation-mapping-field-list-form/aggregation-mapping-field-list-form.component.html b/alfa-client/libs/admin/aggregation-mapping/src/lib/aggregation-mapping-form-container/aggregation-mapping-form/aggregation-mapping-field-list-form/aggregation-mapping-field-list-form.component.html index ee829b2a70..958c7f9d5f 100644 --- a/alfa-client/libs/admin/aggregation-mapping/src/lib/aggregation-mapping-form-container/aggregation-mapping-form/aggregation-mapping-field-list-form/aggregation-mapping-field-list-form.component.html +++ b/alfa-client/libs/admin/aggregation-mapping/src/lib/aggregation-mapping-form-container/aggregation-mapping-form/aggregation-mapping-field-list-form/aggregation-mapping-field-list-form.component.html @@ -1,10 +1,10 @@ <form [formGroup]="formService.form"> <div class="flex flex-col" [formArrayName]="AggregationMappingFormService.FIELD_MAPPINGS"> <div *ngFor="let ignore of mappingsFormArray; let i = index"> - <admin-aggregatin-mapping-field-form + <admin-aggregation-mapping-field-form [index]="i" [attr.data-test-id]="'aggregation-mapping-field-mapping-form-' + i" - ></admin-aggregatin-mapping-field-form> + ></admin-aggregation-mapping-field-form> </div> </div> </form> diff --git a/alfa-client/libs/admin/aggregation-mapping/src/lib/aggregation-mapping-list-container/aggregation-mapping-list/aggregation-mapping-list-item/aggregation-mapping-list-item.component.html b/alfa-client/libs/admin/aggregation-mapping/src/lib/aggregation-mapping-list-container/aggregation-mapping-list/aggregation-mapping-list-item/aggregation-mapping-list-item.component.html index 6a04409309..d7d2401653 100644 --- a/alfa-client/libs/admin/aggregation-mapping/src/lib/aggregation-mapping-list-container/aggregation-mapping-list/aggregation-mapping-list-item/aggregation-mapping-list-item.component.html +++ b/alfa-client/libs/admin/aggregation-mapping/src/lib/aggregation-mapping-list-container/aggregation-mapping-list/aggregation-mapping-list-item/aggregation-mapping-list-item.component.html @@ -1,11 +1,11 @@ <ods-list-item [path]="aggregationMapping | toResourceUri" [attr.data-test-id]="aggregationMapping.name | convertForDataTest"> <dl class="flex w-full"> - <div class="w-1/2"> + <div class="flex-1"> <dt class="sr-only">Name</dt> <dd class="font-semibold" data-test-class="fullname">{{ aggregationMapping.name }}</dd> </div> <!-- Remove null safe check operator after backend provides correct data. --> - <div class="flex-wrap w-1/2"> + <div class="flex-wrap flex-1"> <dt class="sr-only">Formengine</dt> <dd>{{ aggregationMapping.formIdentifier?.formEngineName }}</dd> -- GitLab