Skip to content

Commit

Permalink
Add e2e test for solving warnings for non-unique identifiers via warn…
Browse files Browse the repository at this point in the history
…ings modal
  • Loading branch information
tkleinke committed Nov 10, 2023
1 parent fd8849a commit e56bccb
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 9 deletions.
8 changes: 4 additions & 4 deletions desktop/src/app/components/messages/m.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export class M extends MD { // = Messages Dictionary. For reasons of brevity of

// App Package
public static APP_ERROR_GENERIC_SAVE_ERROR = 'app.error.genericSaveError';
public static APP_RESET_SUCCESS = 'app.resetAppSuccess';
public static APP_CONTROLLER_SUCCESS = 'app.appControllerSuccess';

// Settings Package
public static SETTINGS_SUCCESS = 'settings.success';
Expand Down Expand Up @@ -340,10 +340,10 @@ export class M extends MD { // = Messages Dictionary. For reasons of brevity of
params: [],
hidden: false
};
this.msgs[M.APP_RESET_SUCCESS] = {
this.msgs[M.APP_CONTROLLER_SUCCESS] = {
content: i18n({
id: 'messages.app.resetSuccess',
value: 'Die Anwendung wurde erfolgreich zurückgesetzt.'
id: 'messages.app.appControllerSuccess',
value: 'Erfolgreich ausgeführt.'
}),
level: 'success',
params: [],
Expand Down
44 changes: 42 additions & 2 deletions desktop/src/app/services/app-controller.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Injectable } from '@angular/core';
import { AppConfigurator, DocumentConverter, ConfigReader, ConfigurationDocument, DocumentCache, Indexer, IndexFacade,
PouchdbDatastore, ProjectConfiguration } from 'idai-field-core';
PouchdbDatastore, ProjectConfiguration, Document } from 'idai-field-core';
import { SampleDataLoader } from './datastore/field/sampledata/sample-data-loader';
import { ThumbnailGenerator } from './imagestore/thumbnail-generator';
import { ImagesState } from '../components/image/overview/view/images-state';
Expand All @@ -22,6 +22,9 @@ const ipcRenderer = typeof window !== 'undefined'
@Injectable()
/**
* @author Daniel de Oliveira
* @author Thomas Kleinke
*
* Called from e2e tests
*/
export class AppController {

Expand All @@ -46,8 +49,45 @@ export class AppController {

ipcRenderer.on('resetApp', async () => {
await this.reset();
this.messages.add([M.APP_RESET_SUCCESS]);
this.messages.add([M.APP_CONTROLLER_SUCCESS]);
});

ipcRenderer.on('createNonUniqueIdentifierWarning', async () => {
await this.createNonUniqueIdentifierWarning();
this.messages.add([M.APP_CONTROLLER_SUCCESS]);
});
}


private async createNonUniqueIdentifierWarning() {

const document: Document = {
_id: '1',
resource: {
id: '1',
identifier: '1',
category: 'Place',
relations: {}
},
created: { date: new Date(), user: 'test' },
modified: []
};

await this.pouchdbDatastore.create(document, 'test');

document._id = '2';
document.resource.id = '2';

await this.pouchdbDatastore.create(document, 'test');

await Indexer.reindex(
this.indexFacade,
this.pouchdbDatastore.getDb(),
this.documentCache,
new DocumentConverter(this.projectConfiguration),
this.projectConfiguration,
false
);
}


Expand Down
10 changes: 8 additions & 2 deletions desktop/test/e2e/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,14 @@ export async function navigateTo(menu) {

export async function resetApp() {

await window.evaluate(() => require('@electron/remote').getCurrentWindow().webContents.send('resetApp'));
return waitForExist("//span[@class='message-content' and contains(text(), 'erfolgreich zurückgesetzt')]", 120000);
await sendMessageToAppController('resetApp');
}


export async function sendMessageToAppController(message: string) {

await window.evaluate(value => require('@electron/remote').getCurrentWindow().webContents.send(value), message);
return waitForExist("//span[@class='message-content' and contains(text(), 'Erfolgreich ausgeführt')]", 120000);
}


Expand Down
24 changes: 23 additions & 1 deletion desktop/test/e2e/warnings/warnings.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Field } from 'idai-field-core';
import { NavbarPage } from '../navbar.page';
import { ResourcesPage } from '../resources/resources.page';
import { navigateTo, resetApp, start, stop, waitForExist, waitForNotExist } from '../app';
import { navigateTo, resetApp, sendMessageToAppController, start, stop, waitForExist, waitForNotExist } from '../app';
import { ConfigurationPage } from '../configuration/configuration.page';
import { CategoryPickerPage } from '../widgets/category-picker.page';
import { EditConfigurationPage } from '../configuration/edit-configuration.page';
Expand Down Expand Up @@ -380,4 +380,26 @@ test.describe('warnings --', () => {
await waitForNotExist(await WarningsModalPage.getModalBody());
await waitForNotExist(await NavbarPage.getWarnings());
});


test('solve warnings for non-unique identifiers via warnings modal', async () => {

await waitForNotExist(await NavbarPage.getWarnings());
await sendMessageToAppController('createNonUniqueIdentifierWarning');
expect(await NavbarPage.getNumberOfWarnings()).toBe('2');

await NavbarPage.clickWarningsButton();
expect(await (await WarningsModalPage.getResource('1')).count()).toBe(2);
const sections = await WarningsModalPage.getSections();
expect(await sections.count()).toBe(1);
const sectionTitle = await WarningsModalPage.getSectionTitle(0);
expect(sectionTitle).toContain('Uneindeutiger Bezeichner');

await WarningsModalPage.clickEditButton(0);
await DoceditPage.typeInInputField('identifier', '2');
await DoceditPage.clickSaveDocument();

await waitForNotExist(await WarningsModalPage.getModalBody());
await waitForNotExist(await NavbarPage.getWarnings());
});
});

0 comments on commit e56bccb

Please sign in to comment.