Skip to content

Commit 459f2d7

Browse files
committed
Feedback in naming and documentation
1 parent be52263 commit 459f2d7

File tree

7 files changed

+65
-161
lines changed

7 files changed

+65
-161
lines changed

packages/web-forms/e2e/README.md

+7-12
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
1-
# E2E Tests for `@getodk/web-forms`
1+
# E2E tests for `@getodk/web-forms`
22

33
This directory contains end-to-end (E2E) tests for the `@getodk/web-forms` package, which powers form filling and submission editing of ODK forms in a web browser. These tests use [Playwright](https://playwright.dev/) to simulate user interactions and ensure the package works as expected in real-world scenarios.
44

5-
## Folder Structure
5+
## Folder structure
66

77
The E2E tests are located in `packages/web-forms/e2e/`. Here's the structure and purpose of each directory:
88

99
```
1010
e2e/
1111
├── fixtures/ # Sample forms and data for testing.
1212
├── page-objects/ # Page Object Model structure for e2e tests, organizing UI abstractions into pages and reusable controls.
13-
├── controls/ # Reusable controls such as form fields, UI components, etc.
14-
├── GeopointComponent.ts # Example of a reusable control for the geopoint question type.
13+
├── controls/ # Reusable controls such as form fields, UI elements, etc.
14+
├── GeopointControl.ts # Example of a reusable control for the geopoint question type.
1515
├── pages/ # Full page representations.
1616
├── FormPage.ts # Example of a full page representation for a form.
1717
├── specs/ # Test specification files.
1818
├── geopoint.test.ts # Example of a test file for the geopoint question type.
1919
```
2020

21-
### Key Components
21+
### Key concepts
2222

2323
- **Fixtures**: Reusable test data (e.g., sample XForms) to simulate real-world use cases. Add new forms here as needed.
2424
- **Page Objects**: Implements the [Page Object Model (POM)](https://playwright.dev/docs/pom) pattern to encapsulate UI interactions, enhancing test readability and maintainability.
2525
- **Specs**: Test files organized by feature (e.g., rendering, submission). Name new tests descriptively to reflect their coverage.
2626

27-
## Getting Started
27+
## Getting started
2828

2929
1. **Build the project**
3030
In the root folder run:
@@ -46,13 +46,8 @@ e2e/
4646
yarn workspace @getodk/web-forms test:e2e <filepath, e.g. e2e/specs/geopoint.test.ts>
4747
```
4848

49-
3. **Add new tests**
50-
- Create fixtures in `fixtures/` if needed.
51-
- Update or add Page Objects in `page-objects/` for new UI elements.
52-
- Write tests in `specs/` with descriptive names.
53-
5449
## Contributing
5550

56-
- Keep tests focused: one feature per file.
51+
- Keep tests focused.
5752
- Use POM methods in `pages-objects/` for UI actions.
5853
- Add fixtures for new scenarios instead of hardcoding data.

packages/web-forms/e2e/page-objects/pages/PreviewPage.ts

+8-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { expect, Page } from '@playwright/test';
22

3-
const BASE_URL = 'http://localhost:5173';
3+
const DEV_BASE_URL = 'http://localhost:5173';
4+
const BUILD_BASE_URL = 'http://localhost:5174';
45

56
export class PreviewPage {
67
private readonly page: Page;
@@ -9,15 +10,17 @@ export class PreviewPage {
910
this.page = page;
1011
}
1112

12-
async goToPage() {
13-
await this.page.goto(BASE_URL);
13+
async goToDevPage() {
14+
await this.page.goto(DEV_BASE_URL);
15+
}
16+
17+
async goToBuildPage() {
18+
await this.page.goto(BUILD_BASE_URL);
1419
}
1520

1621
/**
1722
* Opens a preexisting demo form by navigating through the demo forms UI.
1823
*
19-
* @TODO Add support for uploading XML forms from /e2e/fixtures directory for test-specific scenarios
20-
*
2124
* @param {string} accordionName - The name of the demo forms category accordion
2225
* @param {string} formLinkName - The exact name of the demo form link to open
2326
* @param {string} formTitle - The expected title of the form, used to verify successful loading

packages/web-forms/e2e/specs/build/preview-form-render.test.ts

-130
This file was deleted.

packages/web-forms/e2e/specs/build/style.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ import { PreviewPage } from '../../page-objects/pages/PreviewPage.js';
33

44
test('Build includes component-defined styles', async ({ page }) => {
55
const previewPage = new PreviewPage(page);
6-
await previewPage.goToPage();
6+
await previewPage.goToBuildPage();
77

88
// This ensures that the application is loaded before proceeding forward.
9-
await expect(page.getByText('Demo Forms').first()).toBeVisible();
9+
await expect(page.getByText('ODK Web Forms Preview').first()).toBeVisible();
1010

1111
// Get the (Sass-defined) large breakpoint size
1212
// [In theory, if we can get this and it's not a number, we've already validated styles. Below expands on that to leave some breadcrumbs]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { expect, test } from '@playwright/test';
2+
import { PreviewPage } from '../../page-objects/pages/PreviewPage.js';
3+
4+
test.describe('Web Forms Preview Demo Forms', () => {
5+
test('demo forms load', async ({ context, page }) => {
6+
const previewPage = new PreviewPage(page);
7+
await previewPage.goToBuildPage();
8+
9+
const formPreviewLinks = await page.locator('.form-preview-link').all();
10+
11+
expect(formPreviewLinks.length).toBeGreaterThan(0);
12+
13+
for (const link of formPreviewLinks) {
14+
const [formPreviewPage] = await Promise.all([context.waitForEvent('page'), link.click()]);
15+
16+
await formPreviewPage.waitForSelector(
17+
'.form-initialization-status.error, .form-initialization-status.ready',
18+
{
19+
state: 'attached',
20+
}
21+
);
22+
23+
const [failureDialog] = await formPreviewPage.locator('.form-load-failure-dialog').all();
24+
25+
expect(failureDialog).toBeUndefined();
26+
27+
await formPreviewPage.close();
28+
}
29+
});
30+
});

packages/web-forms/e2e/specs/geopoint.test.ts

+16-10
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ test.describe('Geopoint Question Type', () => {
1212
formPage = new FormPage(page);
1313

1414
const previewPage = new PreviewPage(page);
15-
await previewPage.goToPage();
15+
await previewPage.goToDevPage();
1616
await previewPage.openDemoForm('geopoint', 'geopoint.xml', 'Geopoint');
1717
});
1818

@@ -33,11 +33,11 @@ test.describe('Geopoint Question Type', () => {
3333
await formPage.expectLabel('Where are you filling out the survey?');
3434
await formPage.expectHint('(No autosave)');
3535
await formPage.geopoint.openDialog();
36-
await formPage.geopoint.expectGeopointDialog('Finding your location', '10m - Good accuracy');
36+
await formPage.geopoint.expectGeopointDialog('Finding your location', '10 m - Good accuracy');
3737
await formPage.geopoint.saveLocation();
3838

3939
await formPage.geopoint.expectGeopointFormattedValue(
40-
['Accuracy: 10m', 'Latitude: 40.7128', 'Longitude: -74.006'],
40+
['Accuracy: 10 m', 'Latitude: 40.7128', 'Longitude: -74.006'],
4141
'Good accuracy'
4242
);
4343
});
@@ -52,11 +52,14 @@ test.describe('Geopoint Question Type', () => {
5252

5353
await formPage.expectLabel('Where are you filling out the survey?');
5454
await formPage.geopoint.openDialog();
55-
await formPage.geopoint.expectGeopointDialog('Finding your location', '500m - Poor accuracy');
55+
await formPage.geopoint.expectGeopointDialog(
56+
'Finding your location',
57+
'500 m - Poor accuracy'
58+
);
5659
await formPage.geopoint.saveLocation();
5760

5861
await formPage.geopoint.expectGeopointFormattedValue(
59-
['Accuracy: 500m', 'Latitude: 80.5128', 'Longitude: -99.9099'],
62+
['Accuracy: 500 m', 'Latitude: 80.5128', 'Longitude: -99.9099'],
6063
'Poor accuracy'
6164
);
6265
});
@@ -70,11 +73,14 @@ test.describe('Geopoint Question Type', () => {
7073
});
7174

7275
await formPage.geopoint.openDialog();
73-
await formPage.geopoint.expectGeopointDialog('Finding your location', '350m - Poor accuracy');
76+
await formPage.geopoint.expectGeopointDialog(
77+
'Finding your location',
78+
'350 m - Poor accuracy'
79+
);
7480
await formPage.geopoint.saveLocation();
7581

7682
await formPage.geopoint.expectGeopointFormattedValue(
77-
['Accuracy: 350m', 'Latitude: 79.5128', 'Longitude: -95.9099'],
83+
['Accuracy: 350 m', 'Latitude: 79.5128', 'Longitude: -95.9099'],
7884
'Poor accuracy'
7985
);
8086

@@ -86,11 +92,11 @@ test.describe('Geopoint Question Type', () => {
8692
});
8793

8894
await formPage.geopoint.retryCapture();
89-
await formPage.geopoint.expectGeopointDialog('Finding your location', '7m - Good accuracy');
95+
await formPage.geopoint.expectGeopointDialog('Finding your location', '7 m - Good accuracy');
9096
await formPage.geopoint.saveLocation();
9197

9298
await formPage.geopoint.expectGeopointFormattedValue(
93-
['Accuracy: 7m', 'Latitude: 80.5128', 'Longitude: -99.9099'],
99+
['Accuracy: 7 m', 'Latitude: 80.5128', 'Longitude: -99.9099'],
94100
'Good accuracy'
95101
);
96102
});
@@ -107,7 +113,7 @@ test.describe('Geopoint Question Type', () => {
107113
formPage = new FormPage(page);
108114

109115
const previewPage = new PreviewPage(page);
110-
await previewPage.goToPage();
116+
await previewPage.goToDevPage();
111117
await previewPage.openDemoForm('geopoint', 'geopoint.xml', 'Geopoint');
112118
});
113119

packages/web-forms/e2e/specs/note.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ test.describe('Note Question Type', () => {
99
formPage = new FormPage(page);
1010

1111
const previewPage = new PreviewPage(page);
12-
await previewPage.goToPage();
12+
await previewPage.goToDevPage();
1313
await previewPage.openDemoForm('notes', '2-all-possible-notes.xml', 'Notes');
1414
});
1515

@@ -48,7 +48,7 @@ test.describe('Note Question Type', () => {
4848

4949
await formPage.expectLabel('A note with geopoint type');
5050
await formPage.geopoint.expectGeopointFormattedValue([
51-
'Accuracy: 150m',
51+
'Accuracy: 150 m',
5252
'Latitude: 38.253094215699576',
5353
'Longitude: 21.756382658677467',
5454
]);

0 commit comments

Comments
 (0)