Skip to content

Commit 2925b42

Browse files
committed
refactor test
1 parent 31e2061 commit 2925b42

File tree

3 files changed

+26
-15
lines changed

3 files changed

+26
-15
lines changed

testing/e2e/src/global/global.setup.spec.ts

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { LoginCredentials } from '@opendatacapture/schemas/auth';
2-
import { expect, test } from '@playwright/test';
32

43
import { initAppOptions } from '../helpers/data';
4+
import { expect, test } from '../helpers/fixtures';
55

66
test.skip(() => process.env.GLOBAL_SETUP_COMPLETE === '1');
77

@@ -12,20 +12,9 @@ test.describe.serial(() => {
1212
expect(response.status()).toBe(200);
1313
await expect(response.json()).resolves.toMatchObject({ isSetup: false });
1414
});
15-
test('successful setup', async ({ page }) => {
16-
await page.goto('/setup');
17-
await expect(page).toHaveURL('/setup');
18-
const setupForm = page.locator('form[data-cy="setup-form"]');
19-
await setupForm.locator('input[name="firstName"]').fill(initAppOptions.admin.firstName);
20-
await setupForm.locator('input[name="lastName"]').fill(initAppOptions.admin.lastName);
21-
await setupForm.locator('input[name="username"]').fill(initAppOptions.admin.username);
22-
await setupForm.locator('input[name="password"]').fill(initAppOptions.admin.password);
23-
await setupForm.locator('input[name="confirmPassword"]').fill(initAppOptions.admin.password);
24-
await setupForm.locator('#initDemo-true').click();
25-
await setupForm.locator('input[name="dummySubjectCount"]').fill(initAppOptions.dummySubjectCount.toString());
26-
await setupForm.locator('input[name="recordsPerSubject"]').fill(initAppOptions.recordsPerSubject.toString());
27-
await setupForm.getByLabel('Submit').click();
28-
await expect(page).toHaveURL('/dashboard');
15+
test('successful setup', async ({ setupPage }) => {
16+
await setupPage.fillSetupForm(initAppOptions);
17+
await setupPage.expect.toHaveURL('/dashboard');
2918
});
3019
test('setup state after initialization', async ({ request }) => {
3120
const response = await request.get('/api/v1/setup');

testing/e2e/src/pages/__root.page.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,6 @@ export abstract class RootPage {
1515

1616
async goto() {
1717
await this.$ref.goto(this.defaultUrl);
18+
await this.$ref.waitForURL(this.defaultUrl);
1819
}
1920
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,26 @@
1+
import type { InitAppOptions } from '@opendatacapture/schemas/setup';
2+
import type { Locator, Page } from '@playwright/test';
3+
14
import { RootPage } from './__root.page';
25

36
export class SetupPage extends RootPage {
47
protected readonly defaultUrl = '/setup';
8+
readonly setupForm: Locator;
9+
10+
constructor(page: Page) {
11+
super(page);
12+
this.setupForm = page.getByTestId('setup-form');
13+
}
14+
15+
async fillSetupForm({ admin, dummySubjectCount, recordsPerSubject }: InitAppOptions) {
16+
await this.setupForm.locator('input[name="firstName"]').fill(admin.firstName);
17+
await this.setupForm.locator('input[name="lastName"]').fill(admin.lastName);
18+
await this.setupForm.locator('input[name="username"]').fill(admin.username);
19+
await this.setupForm.locator('input[name="password"]').fill(admin.password);
20+
await this.setupForm.locator('input[name="confirmPassword"]').fill(admin.password);
21+
await this.setupForm.locator('#initDemo-true').click();
22+
await this.setupForm.locator('input[name="dummySubjectCount"]').fill(dummySubjectCount?.toString() ?? '');
23+
await this.setupForm.locator('input[name="recordsPerSubject"]').fill(recordsPerSubject?.toString() ?? '');
24+
await this.setupForm.getByLabel('Submit').click();
25+
}
526
}

0 commit comments

Comments
 (0)