Skip to content

Commit

Permalink
Add e2e test for creating complex field
Browse files Browse the repository at this point in the history
  • Loading branch information
tkleinke committed Aug 1, 2023
1 parent dd07d03 commit 2b335ad
Show file tree
Hide file tree
Showing 6 changed files with 114 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ <h5 *ngIf="!isNew" i18n="@@docedit.editEntry">Eintrag bearbeiten</h5>

<div class="modal-body bg-light">
<div *ngFor="let subfield of getSubfields()" class="subfield-section">
<label>{{getSubfieldLabel(subfield)}}</label>
<label class="complex-entry-modal-subfield-label">{{getSubfieldLabel(subfield)}}</label>
<span *ngIf="getSubfieldDescription(subfield)"
placement="left"
container="body"
Expand All @@ -24,7 +24,7 @@ <h5 *ngIf="!isNew" i18n="@@docedit.editEntry">Eintrag bearbeiten</h5>
(click)="confirm()">
<span i18n="@@buttons.ok">OK</span>
</button>
<div class="btn btn-secondary"
<div id="cancel-button" class="btn btn-secondary"
(click)="cancel()">
<span i18n="@@buttons.cancel">Abbrechen</span>
</div>
Expand Down
2 changes: 1 addition & 1 deletion desktop/src/app/components/docedit/core/forms/complex.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<input placeholder="Hinzufügen..." i18n-placeholder="@@docedit.forms.complex.add"
type="text" disabled class="form-control">
<div class="input-group-append">
<button class="btn btn-success" (click)="createEntry()">
<button class="btn btn-success create-complex-entry-button" (click)="createEntry()">
<span class="mdi mdi-plus-circle"></span>
</button>
</div>
Expand Down
40 changes: 40 additions & 0 deletions desktop/test/e2e/configuration/configuration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { DoceditPage } from '../docedit/docedit.page';
import { AddFieldModalPage } from './add-field-modal.page';
import { AddGroupModalPage } from './add-group-modal.page';
import { ManageValuelistsModalPage } from './manage-valuelists-modal.page';
import { DoceditComplexEntryModalPage } from '../docedit/docedit-complex-entry-modal.page';

const { test, expect } = require('@playwright/test');

Expand Down Expand Up @@ -730,4 +731,43 @@ test.describe('configuration --', () => {
await DoceditPage.clickSaveDocument();
expect(await ResourcesPage.getSelectedListItemShortDescriptionText()).toEqual('Value label');
});


test('create complex field', async () => {

await CategoryPickerPage.clickSelectCategory('Place');
await ConfigurationPage.clickAddFieldButton();
await AddFieldModalPage.typeInSearchFilterInput('complexField');
await AddFieldModalPage.clickCreateNewField();

await EditConfigurationPage.clickInputTypeSelectOption('complex');
await EditConfigurationPage.typeInTranslation(0, 0, 'Kompositfeld');

await EditConfigurationPage.typeInNewSubfield('subfield1');
await EditConfigurationPage.clickCreateSubfield();
await EditConfigurationPage.clickInputTypeSelectOption('boolean', true);
await EditConfigurationPage.typeInTranslation(0, 0, 'Unterfeld 1', true);
await EditConfigurationPage.clickConfirmSubfield();

await EditConfigurationPage.typeInNewSubfield('subfield2');
await EditConfigurationPage.clickCreateSubfield();
await EditConfigurationPage.clickInputTypeSelectOption('input', true);
await EditConfigurationPage.typeInTranslation(0, 0, 'Unterfeld 2', true);
await EditConfigurationPage.clickConfirmSubfield();

await EditConfigurationPage.clickConfirm();
await ConfigurationPage.save();

await NavbarPage.clickCloseNonResourcesTab();
await ResourcesPage.performCreateResource('P1', 'place');
await ResourcesPage.openEditByDoubleClickResource('P1');
await DoceditPage.clickCreateComplexEntry('test-complexField');
expect(await DoceditComplexEntryModalPage.getSubfieldLabel(0)).toEqual('Unterfeld 1');
expect(await DoceditComplexEntryModalPage.getSubfieldLabel(1)).toEqual('Unterfeld 2');
waitForExist(await DoceditComplexEntryModalPage.getSubfieldInputElement(0, 'boolean'));
waitForExist(await DoceditComplexEntryModalPage.getSubfieldInputElement(1, 'input'));

await DoceditComplexEntryModalPage.clickCancel();
await DoceditPage.clickCloseEdit();
});
});
36 changes: 32 additions & 4 deletions desktop/test/e2e/configuration/edit-configuration.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,27 @@ export class EditConfigurationPage {
}


public static clickConfirmSubfield() {

return click('#confirm-subfield-button');
}


public static clickAddValue() {

return click('#add-value-button');
}


public static clickInputTypeSelectOption(optionValue: string) {
public static clickCreateSubfield() {

return selectOption('#input-type-select', optionValue);
return click('#create-subfield-button');
}


public static clickInputTypeSelectOption(optionValue: string, isSubfield: boolean = false) {

return selectOption(this.getModalClass(isSubfield) + ' .input-type-select', optionValue);
}


Expand All @@ -101,9 +113,11 @@ export class EditConfigurationPage {

// type in

public static async typeInTranslation(inputIndex: number, translationIndex: number, text: string) {
public static async typeInTranslation(inputIndex: number, translationIndex: number, text: string,
isSubfield: boolean = false) {

const inputElement = (await getLocator('multi-language-input')).nth(inputIndex);
const inputElement = (await getLocator(this.getModalClass(isSubfield) + ' multi-language-input'))
.nth(inputIndex);
const translationElement = (await inputElement.locator('.language-input input')).nth(translationIndex);
return typeIn(translationElement, text);
}
Expand All @@ -119,4 +133,18 @@ export class EditConfigurationPage {

return typeIn('#new-value-input', valueId);
}


public static typeInNewSubfield(subfieldName: string) {

return typeIn('#new-subfield-input', subfieldName);
}


private static getModalClass(isSubfield: boolean) {

return isSubfield
? '.subfield-editor-modal-body'
: '.field-editor-modal-body';
}
}
33 changes: 33 additions & 0 deletions desktop/test/e2e/docedit/docedit-complex-entry-modal.page.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { click, getLocator, getText } from '../app';


/**
* @author Thomas Kleinke
*/
export class DoceditComplexEntryModalPage {

// click

public static async clickCancel() {

return click('#cancel-button');
}


// get text

public static async getSubfieldLabel(fieldIndex: number) {

const element = await getLocator('.subfield-section').nth(fieldIndex);
return getText(await element.locator('.complex-entry-modal-subfield-label'));
}


// elements

public static async getSubfieldInputElement(fieldIndex: number, inputType: string) {

const element = await getLocator('.subfield-section').nth(fieldIndex);
return element.locator('form-field-' + inputType);
}
}
6 changes: 6 additions & 0 deletions desktop/test/e2e/docedit/docedit.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,12 @@ export class DoceditPage {
}


public static clickCreateComplexEntry(fieldName: string) {

return click('#edit-form-element-' + fieldName + ' .create-complex-entry-button');
}


// get text

public static async getSimpleInputFieldValue(index) {
Expand Down

0 comments on commit 2b335ad

Please sign in to comment.