@appsemble/e2e 0.40.7-node-brotli.0 → 0.40.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,8 +1,8 @@
1
- # ![](https://gitlab.com/appsemble/appsemble/-/raw/0.40.7-node-brotli.0/config/assets/logo.svg) Appsemble End 2 End Tests
1
+ # ![](https://gitlab.com/appsemble/appsemble/-/raw/0.40.8/config/assets/logo.svg) Appsemble End 2 End Tests
2
2
 
3
3
  > Run end 2 end tests on an Appsemble environment and provide Appsemble fixtures
4
4
 
5
- [![GitLab CI](https://gitlab.com/appsemble/appsemble/badges/0.40.7-node-brotli.0/pipeline.svg)](https://gitlab.com/appsemble/appsemble/-/releases/0.40.7-node-brotli.0)
5
+ [![GitLab CI](https://gitlab.com/appsemble/appsemble/badges/0.40.8/pipeline.svg)](https://gitlab.com/appsemble/appsemble/-/releases/0.40.8)
6
6
  [![Prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg)](https://prettier.io)
7
7
 
8
8
  ## Table of Contents
@@ -95,6 +95,28 @@ export const test = base.extend<object>({
95
95
  });
96
96
  ```
97
97
 
98
+ ## Resource lifecycle tracking
99
+
100
+ Resources created using `createTestResource` are tracked and automatically deleted at the end of the
101
+ test by default.
102
+
103
+ Set `trackBrowserResources` to `true` to also track resources created by browser `POST` requests:
104
+
105
+ ```ts
106
+ test.use({ trackBrowserResources: true });
107
+ ```
108
+
109
+ Set `autoCleanupResources` to `false` to preserve all tracked resources after the test. This can be
110
+ useful when inspecting resources created by a failed test.
111
+
112
+ ```ts
113
+ test.use({ autoCleanupResources: false });
114
+ ```
115
+
116
+ > **Note:** Only resources created by browser `POST` requests and resources created using the
117
+ > `createTestResource` are tracked. Resources created using other methods like webhooks do not get
118
+ > tracked.
119
+
98
120
  ## Contributing
99
121
 
100
122
  When writing end-to-end tests, have a look at the
@@ -102,5 +124,5 @@ When writing end-to-end tests, have a look at the
102
124
 
103
125
  ## License
104
126
 
105
- [LGPL-3.0-only](https://gitlab.com/appsemble/appsemble/-/blob/0.40.7-node-brotli.0/LICENSE.md) ©
127
+ [LGPL-3.0-only](https://gitlab.com/appsemble/appsemble/-/blob/0.40.8/LICENSE.md) ©
106
128
  [Appsemble](https://appsemble.com)
@@ -1,5 +1,6 @@
1
1
  import { AxeBuilder } from '@axe-core/playwright';
2
- type ImpactValue = NonNullable<Awaited<ReturnType<AxeBuilder['analyze']>>['violations'][number]['impact']>;
2
+ type AxeViolation = Awaited<ReturnType<AxeBuilder['analyze']>>['violations'][number];
3
+ type ImpactValue = NonNullable<AxeViolation['impact']>;
3
4
  export interface AccessibilityViolation {
4
5
  /**
5
6
  * The ID of the failing axe-core rule.
@@ -52,15 +53,23 @@ export interface AccessibilityFixtures {
52
53
  *
53
54
  * Starting at the current page, the crawl follows links to other pages of the same app. Paths
54
55
  * that only differ in numeric or UUID segments, such as resource detail pages, are scanned once.
56
+ * A link that redirects to a page that is already scanned is not scanned again.
55
57
  *
56
58
  * Each page is checked against WCAG 2.2 level A and AA using axe-core. A page scores 100 minus a
57
59
  * penalty per failing rule, regardless of how many elements fail it: 10 for critical, 7 for
58
60
  * serious, 3 for moderate and 1 for minor violations, with a minimum of 0.
59
61
  *
60
- * The report is attached to the test as `accessibility.json`, and the app score is added as the
62
+ * The report is attached to the test as `accessibility.json`. It is also attached as
63
+ * `accessibility.html`, a self-contained page that lists the failing elements of each rule with
64
+ * their block, selector, markup and how to fix them. The block is named with its path in the app
65
+ * definition, elements outside blocks belong to the app shell. The app score is added as the
61
66
  * `accessibility score` annotation, which the JUnit reporter writes as a test case property. The
62
67
  * score is also written as the metric `accessibility_<name>` to `accessibility-metrics.txt` in
63
- * the output directory of the project, in the format of a GitLab metrics report.
68
+ * the output directory of the project, in the format of a GitLab metrics report. The failing
69
+ * elements are written to `gl-accessibility-<name>.json` in the output directory of the project,
70
+ * in the Pa11y format of a GitLab accessibility report. GitLab compares these elements with the
71
+ * report of the target branch, so IDs in their selector and markup, which differ between
72
+ * pipelines, are masked.
64
73
  *
65
74
  * @param options Options for the crawl. `name` identifies the app in the metrics report.
66
75
  * `maxPages` limits the number of scanned pages, 50 by default.
@@ -9,26 +9,57 @@ const penalties = {
9
9
  moderate: 3,
10
10
  minor: 1,
11
11
  };
12
- const dynamicSegment = /^(\d+|[\da-f]{8}(?:-[\da-f]{4}){3}-[\da-f]{12})$/i;
13
- function getRoutePattern(url) {
14
- return url.pathname
15
- .split('/')
16
- .map((segment) => (dynamicSegment.test(segment) ? ':id' : segment))
17
- .join('/');
12
+ const dynamicSegment = /\/(?:\d+|[\da-f]{8}(?:-[\da-f]{4}){3}-[\da-f]{12})(?=[^\w-]|$)/gi;
13
+ function escapeHtml(value) {
14
+ return value
15
+ .replaceAll('&', '&amp;')
16
+ .replaceAll('<', '&lt;')
17
+ .replaceAll('>', '&gt;')
18
+ .replaceAll('"', '&quot;');
19
+ }
20
+ function maskIds(value) {
21
+ return value.replaceAll(dynamicSegment, '/:id');
18
22
  }
19
23
  export const test = base.extend({
20
24
  async scanAppAccessibility({ page }, use, testInfo) {
21
25
  await use(async ({ maxPages = 50, name }) => {
22
26
  const { origin } = new URL(page.url());
23
27
  const queue = [page.url()];
24
- const seen = new Set(queue.map((url) => getRoutePattern(new URL(url))));
28
+ const seen = new Set(queue.map((url) => maskIds(new URL(url).pathname)));
29
+ const scanned = new Set();
25
30
  const pages = [];
31
+ const failingRules = new Map();
26
32
  while (queue.length && pages.length < maxPages) {
27
- const url = queue.shift();
28
- await page.goto(url);
33
+ await page.goto(queue.shift());
29
34
  await page.waitForLoadState('networkidle');
35
+ const url = page.url();
36
+ const pattern = maskIds(new URL(url).pathname);
37
+ if (scanned.has(pattern)) {
38
+ continue;
39
+ }
40
+ scanned.add(pattern);
30
41
  const { violations } = await new AxeBuilder({ page }).withTags(wcagTags).analyze();
31
- pages.push({
42
+ const components = await page.evaluate((targets) => targets.map((paths) => paths.map((path) => {
43
+ let root = document;
44
+ let element;
45
+ for (const selector of path) {
46
+ element = root?.querySelector(selector);
47
+ root = element?.shadowRoot;
48
+ }
49
+ while (element) {
50
+ const block = element.closest('[data-block]');
51
+ if (block) {
52
+ const blockName = block.dataset.block;
53
+ const [scope, directory] = blockName.split('/');
54
+ return scope === '@appsemble'
55
+ ? `${blockName} (blocks/${directory}) at ${block.dataset.path}`
56
+ : `${blockName} at ${block.dataset.path}`;
57
+ }
58
+ element = element.getRootNode().host;
59
+ }
60
+ return 'app shell (packages/app)';
61
+ })), violations.map(({ nodes }) => nodes.map(({ target }) => target.flat())));
62
+ const pageReport = {
32
63
  url,
33
64
  score: Math.max(0, 100 - violations.reduce((sum, { impact }) => sum + (impact ? penalties[impact] : 0), 0)),
34
65
  violations: violations.map(({ help, helpUrl, id, impact, nodes }) => ({
@@ -38,7 +69,15 @@ export const test = base.extend({
38
69
  helpUrl,
39
70
  nodes: nodes.length,
40
71
  })),
41
- });
72
+ };
73
+ pages.push(pageReport);
74
+ failingRules.set(pageReport, violations.map((violation, index) => ({
75
+ ...violation,
76
+ nodes: violation.nodes.map((node, nodeIndex) => ({
77
+ ...node,
78
+ component: components[index][nodeIndex],
79
+ })),
80
+ })));
42
81
  const hrefs = await page
43
82
  .locator('a[href]')
44
83
  .evaluateAll((links) => links.map((link) => link.href));
@@ -46,9 +85,9 @@ export const test = base.extend({
46
85
  const link = new URL(href);
47
86
  link.hash = '';
48
87
  link.search = '';
49
- const pattern = getRoutePattern(link);
50
- if (link.origin === origin && !seen.has(pattern)) {
51
- seen.add(pattern);
88
+ const linkPattern = maskIds(link.pathname);
89
+ if (link.origin === origin && !seen.has(linkPattern)) {
90
+ seen.add(linkPattern);
52
91
  queue.push(String(link));
53
92
  }
54
93
  }
@@ -64,8 +103,67 @@ export const test = base.extend({
64
103
  path: reportPath,
65
104
  contentType: 'application/json',
66
105
  });
106
+ const sections = pages.map((pageReport, index) => {
107
+ const { score, url } = pageReport;
108
+ const rules = failingRules.get(pageReport).map(({ help, helpUrl, id, impact, nodes }) => `
109
+ <details>
110
+ <summary>${escapeHtml(`${impact ?? 'unknown'}: ${help} (${id}, failing elements: ${nodes.length})`)}</summary>
111
+ <p><a href="${escapeHtml(helpUrl)}">How to fix ${escapeHtml(id)}</a></p>
112
+ <ol>${nodes
113
+ .map(({ component, failureSummary, html, target }) => `
114
+ <li>
115
+ <p>${escapeHtml(component)}</p>
116
+ <code>${escapeHtml(target.flat().join(' >>> '))}</code>
117
+ <pre>${escapeHtml(html)}</pre>
118
+ <pre>${escapeHtml(failureSummary ?? '')}</pre>
119
+ </li>`)
120
+ .join('')}
121
+ </ol>
122
+ </details>`);
123
+ return `
124
+ <section aria-labelledby="page-${index}">
125
+ <h2 id="page-${index}"><a href="${escapeHtml(url)}">${escapeHtml(url)}</a></h2>
126
+ <p>Score: ${score}</p>${rules.length ? rules.join('') : '\n <p>No WCAG violations found.</p>'}
127
+ </section>`;
128
+ });
129
+ const htmlPath = testInfo.outputPath('accessibility.html');
130
+ await writeFile(htmlPath, `<!doctype html>
131
+ <html lang="en">
132
+ <head>
133
+ <meta charset="utf-8">
134
+ <title>${escapeHtml(`Accessibility report: ${name}`)}</title>
135
+ <style>
136
+ body { font-family: system-ui, sans-serif; margin: 2rem auto; max-width: 80rem; padding: 0 1rem; }
137
+ summary { cursor: pointer; }
138
+ pre { background: #f5f5f5; overflow-x: auto; padding: 0.5rem; white-space: pre-wrap; }
139
+ </style>
140
+ </head>
141
+ <body>
142
+ <h1>${escapeHtml(`Accessibility report: ${name}`)}</h1>
143
+ <p>Score: ${report.score}, the average of ${pages.length} pages checked against WCAG 2.2 A and AA.</p>${sections.join('')}
144
+ </body>
145
+ </html>
146
+ `);
147
+ await testInfo.attach('accessibility.html', { path: htmlPath, contentType: 'text/html' });
67
148
  testInfo.annotations.push({ type: 'accessibility score', description: String(report.score) });
68
149
  await appendFile(join(testInfo.project.outputDir, 'accessibility-metrics.txt'), `accessibility_${name} ${report.score}\n`);
150
+ await writeFile(join(testInfo.project.outputDir, `gl-accessibility-${name}.json`), JSON.stringify({
151
+ results: Object.fromEntries(pages.map((pageReport) => [
152
+ pageReport.url,
153
+ failingRules
154
+ .get(pageReport)
155
+ .flatMap(({ description, help, helpUrl, id, impact, nodes }) => nodes.map(({ component, html, target }) => ({
156
+ code: id,
157
+ type: 'error',
158
+ typeCode: 1,
159
+ message: `${help}: ${component}`,
160
+ context: maskIds(html),
161
+ selector: maskIds(target.flat().join(' >>> ')),
162
+ runner: 'axe',
163
+ runnerExtras: { description, impact, help, helpUrl },
164
+ }))),
165
+ ])),
166
+ }));
69
167
  return report;
70
168
  });
71
169
  },
@@ -1,4 +1,5 @@
1
1
  import { type Resource } from '@appsemble/types';
2
+ import { type TrackedResource } from './types.js';
2
3
  export interface ResourceFixtures {
3
4
  /**
4
5
  * Create resource from JSON input.
@@ -27,5 +28,38 @@ export interface ResourceFixtures {
27
28
  * @param id Id of the resource to delete.
28
29
  */
29
30
  deleteResource: (appId: number, resourceType: string, id: number) => Promise<void>;
31
+ /**
32
+ * Creates a resource for the given app.
33
+ *
34
+ * The resource is automatically deleted after the test by default.
35
+ *
36
+ * @param appId ID of the app which the resource belongs to
37
+ * @param type Resource type
38
+ * @param input Resource data
39
+ * @returns Created resource
40
+ */
41
+ createTestResource: (appId: number, type: string, input: unknown) => Promise<Resource>;
42
+ /**
43
+ * Waits until resources created by the browser have been added to `trackedResources`.
44
+ */
45
+ trackCreatedResources: () => Promise<void>;
46
+ /**
47
+ * Whether to track resources created through the browser during the current test.
48
+ */
49
+ trackBrowserResources: boolean;
50
+ /**
51
+ * Whether to delete tracked resources after the current test.
52
+ */
53
+ autoCleanupResources: boolean;
54
+ /**
55
+ * List of resources created during the current test
56
+ */
57
+ trackedResources: TrackedResource[];
58
+ /**
59
+ * Deletes all the resources that are being tracked in the `trackedResources` list.
60
+ *
61
+ * Runs automatically after the test completes if `autoCleanupResources` is enabled.
62
+ */
63
+ cleanupResources: null;
30
64
  }
31
65
  export declare const test: import("@playwright/test").TestType<import("@playwright/test").PlaywrightTestArgs & import("@playwright/test").PlaywrightTestOptions & ResourceFixtures, import("@playwright/test").PlaywrightWorkerArgs & import("@playwright/test").PlaywrightWorkerOptions>;
@@ -43,5 +43,74 @@ export const test = base.extend({
43
43
  expect(response.status()).toBe(204);
44
44
  });
45
45
  },
46
+ async trackedResources({}, use) {
47
+ await use([]);
48
+ },
49
+ async createTestResource({ createResource, trackedResources }, use) {
50
+ await use(async (appId, type, input) => {
51
+ const resource = await createResource(appId, type, input);
52
+ trackedResources.push({
53
+ appId,
54
+ type,
55
+ id: resource.id,
56
+ });
57
+ return resource;
58
+ });
59
+ },
60
+ trackBrowserResources: [false, { option: true }],
61
+ autoCleanupResources: [true, { option: true }],
62
+ trackCreatedResources: [
63
+ async ({ page, trackBrowserResources, trackedResources }, use) => {
64
+ if (!trackBrowserResources) {
65
+ await use(() => Promise.resolve());
66
+ return;
67
+ }
68
+ const pendingResponses = [];
69
+ function onResponse(response) {
70
+ if (response.request().method() !== 'POST' || !response.ok()) {
71
+ return;
72
+ }
73
+ const url = new URL(response.url());
74
+ const match = /^\/api\/apps\/(\d+)\/resources\/([^/]+)$/.exec(url.pathname);
75
+ if (!match) {
76
+ return;
77
+ }
78
+ const [, appId, type] = match;
79
+ const pendingResponse = response.json().then((resource) => {
80
+ const trackedResource = {
81
+ appId: Number(appId),
82
+ id: resource.id,
83
+ type: decodeURIComponent(type),
84
+ };
85
+ if (!trackedResources.some((entry) => entry.appId === trackedResource.appId &&
86
+ entry.id === trackedResource.id &&
87
+ entry.type === trackedResource.type)) {
88
+ trackedResources.push(trackedResource);
89
+ }
90
+ });
91
+ pendingResponses.push(pendingResponse);
92
+ }
93
+ async function waitForResponses() {
94
+ await Promise.all(pendingResponses);
95
+ }
96
+ page.on('response', onResponse);
97
+ await use(waitForResponses);
98
+ page.off('response', onResponse);
99
+ },
100
+ { auto: true },
101
+ ],
102
+ cleanupResources: [
103
+ async ({ autoCleanupResources, deleteResource, trackCreatedResources, trackedResources }, use) => {
104
+ await use(null);
105
+ if (!autoCleanupResources) {
106
+ return;
107
+ }
108
+ await trackCreatedResources();
109
+ for (const resource of trackedResources) {
110
+ await deleteResource(resource.appId, resource.type, resource.id);
111
+ }
112
+ },
113
+ { auto: true },
114
+ ],
46
115
  });
47
116
  //# sourceMappingURL=index.js.map
@@ -0,0 +1,5 @@
1
+ export interface TrackedResource {
2
+ appId: number;
3
+ id: number;
4
+ type: string;
5
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@appsemble/e2e",
3
- "version": "0.40.7-node-brotli.0",
3
+ "version": "0.40.8",
4
4
  "description": "End-to-end tests used for testing Appsemble apps in an existing environment.",
5
5
  "keywords": [
6
6
  "app",
@@ -40,9 +40,9 @@
40
40
  "@playwright/test": "Pinned exact and kept in sync with the mcr.microsoft.com/playwright:v<version>-noble tags of the `mermaid svgs`, `e2e node`, and `e2e keycloak` jobs in .gitlab-ci.yml; Renovate bumps them all together (see renovate.json)."
41
41
  },
42
42
  "dependencies": {
43
- "@appsemble/lang-sdk": "0.40.7-node-brotli.0",
44
- "@appsemble/node-utils": "0.40.7-node-brotli.0",
45
- "@appsemble/types": "0.40.7-node-brotli.0",
43
+ "@appsemble/lang-sdk": "0.40.8",
44
+ "@appsemble/node-utils": "0.40.8",
45
+ "@appsemble/types": "0.40.8",
46
46
  "@axe-core/playwright": "4.14.0",
47
47
  "@playwright/test": "1.64.1",
48
48
  "mailpit-api": "^2.1.0",
@@ -1,5 +1,7 @@
1
1
  import { defineConfig, devices } from '@playwright/test';
2
2
  const { APPSEMBLE_REVIEW_DOMAIN, APPSEMBLE_STAGING_DOMAIN, CI, CI_MERGE_REQUEST_IID, E2E_HOST } = process.env;
3
+ // Static UI tests scan fake sites, so their accessibility metrics stay out of the published report.
4
+ const staticOutputDir = 'test-results/static';
3
5
  /**
4
6
  * See https://playwright.dev/docs/test-configuration.
5
7
  */
@@ -14,8 +16,12 @@ export default defineConfig({
14
16
  // Amount of workers to run tests with
15
17
  workers: CI ? 2 : 1,
16
18
  // Reporter to use. See https://playwright.dev/docs/test-reporters
17
- // Written to the repository root, so attachment paths resolve against the CI job artifacts
18
- reporter: [['junit', { outputFile: '../../junit.xml' }]],
19
+ reporter: [
20
+ // Written to the repository root, so attachment paths resolve against the CI job artifacts
21
+ ['junit', { outputFile: '../../junit.xml' }],
22
+ // CI shards write blob reports, which the `e2e report` job merges into one HTML report
23
+ CI ? ['blob'] : ['html', { open: 'never' }],
24
+ ],
19
25
  // Prevent the pipeline from timing out
20
26
  maxFailures: 6,
21
27
  // Overall test timeout - increased for CI stability with cold server starts
@@ -41,18 +47,21 @@ export default defineConfig({
41
47
  {
42
48
  name: 'static-chromium',
43
49
  testDir: './tests/static-ui',
50
+ outputDir: staticOutputDir,
44
51
  use: { ...devices['Desktop Chrome'] },
45
52
  fullyParallel: true,
46
53
  },
47
54
  {
48
55
  name: 'static-firefox',
49
56
  testDir: './tests/static-ui',
57
+ outputDir: staticOutputDir,
50
58
  use: { ...devices['Desktop Firefox'] },
51
59
  fullyParallel: true,
52
60
  },
53
61
  {
54
62
  name: 'static-safari',
55
63
  testDir: './tests/static-ui',
64
+ outputDir: staticOutputDir,
56
65
  use: { ...devices['Desktop Safari'] },
57
66
  fullyParallel: true,
58
67
  },
@@ -38,5 +38,41 @@ test.describe('Accessibility', () => {
38
38
  const { pages, score } = await scanAppAccessibility({ name: 'notes' });
39
39
  expect(score, JSON.stringify(pages, null, 2)).toBeGreaterThanOrEqual(minimumScore);
40
40
  });
41
+ test('unlittered app scores at least the minimum', async ({ createApp, createResource, page, scanAppAccessibility, uploadAppMessages, visitApp, }) => {
42
+ const appDefinition = await readFile('../../apps/unlittered/app-definition.yaml', 'utf8');
43
+ const messages = JSON.parse(await readFile('../../apps/unlittered/i18n/en.json', 'utf8'));
44
+ const appId = (await createApp(organizationId, appDefinition)).id;
45
+ appIds.push(appId);
46
+ await uploadAppMessages(appId, 'en', messages);
47
+ await createResource(appId, 'litter', {
48
+ notes: 'A broken bottle on the pavement',
49
+ process: 'Collection',
50
+ location: { latitude: 52.37, longitude: 4.89 },
51
+ });
52
+ await visitApp(appId);
53
+ await page.waitForURL('**/report-litter');
54
+ const { pages, score } = await scanAppAccessibility({ name: 'unlittered' });
55
+ expect(score, JSON.stringify(pages, null, 2)).toBeGreaterThanOrEqual(minimumScore);
56
+ });
57
+ test('bicycle store app scores at least the minimum', async ({ changeAppMemberRole, createApp, createResource, giveAppConsent, loginAppAppsembleOAuth, page, scanAppAccessibility, visitApp, }) => {
58
+ const appDefinition = await readFile('../../apps/bicycle-store/app-definition.yaml', 'utf8');
59
+ const appId = (await createApp(organizationId, appDefinition)).id;
60
+ appIds.push(appId);
61
+ await giveAppConsent(appId);
62
+ await changeAppMemberRole(appId, 'manager');
63
+ await createResource(appId, 'bicycles', { type: 'City bike', stock: 3, image: '0' }, [
64
+ new Blob([await readFile('mock-data/tux.png')], { type: 'image/png' }),
65
+ ]);
66
+ await createResource(appId, 'saleHistory', {
67
+ bicycle: 'City bike',
68
+ saleDate: new Date().toISOString(),
69
+ buyerPhoneNumber: 1234567890,
70
+ });
71
+ await visitApp(appId);
72
+ await loginAppAppsembleOAuth();
73
+ await page.waitForURL('**/inventory');
74
+ const { pages, score } = await scanAppAccessibility({ name: 'bicycle_store' });
75
+ expect(score, JSON.stringify(pages, null, 2)).toBeGreaterThanOrEqual(minimumScore);
76
+ });
41
77
  });
42
78
  //# sourceMappingURL=accessibility.spec.js.map
@@ -3,6 +3,10 @@ import { expect, authenticatedTest as test } from '../../index.js';
3
3
  let appId;
4
4
  let organizationId;
5
5
  test.describe('Person', () => {
6
+ test.use({
7
+ trackBrowserResources: true,
8
+ autoCleanupResources: true,
9
+ });
6
10
  test.beforeAll(async ({ createApp, createOrganization, randomTestId, uploadAppMessages }) => {
7
11
  const appDefinition = await readFile('../../apps/person/app-definition.yaml', 'utf8');
8
12
  const englishTranslations = JSON.parse(await readFile('../../apps/person/i18n/en.json', 'utf8'));
@@ -18,6 +22,17 @@ test.describe('Person', () => {
18
22
  await visitApp(appId);
19
23
  await page.waitForURL('**/person-registration-form');
20
24
  });
25
+ test('should show person in person list', async ({ page, createTestResource, randomTestId }) => {
26
+ const firstName = randomTestId();
27
+ const lastName = randomTestId();
28
+ await createTestResource(appId, 'person', {
29
+ firstName,
30
+ lastName,
31
+ email: 'test@appsemble.com',
32
+ });
33
+ await page.getByRole('link', { name: 'Person List' }).click();
34
+ await expect(page.getByRole('row', { name: `${firstName} ${lastName}` })).toBeVisible();
35
+ });
21
36
  test('should submit a new person and view it', async ({ page }) => {
22
37
  const date = Date.now();
23
38
  const firstName = `First name ${date}`;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,76 @@
1
+ import { readFile } from 'node:fs/promises';
2
+ import { join } from 'node:path';
3
+ import { pathToFileURL } from 'node:url';
4
+ import { expect, baseTest as test } from '../../index.js';
5
+ const origin = 'https://report.test';
6
+ const pages = {
7
+ '/': '<h1>Home</h1><a href="/about">About</a><a href="/home">Home</a>',
8
+ '/about': `<h1>About</h1><img id="logo" src="/apps/42/icon"><a href="/apps/42"></a><a href="/apps/43"></a>
9
+ <div data-block="@appsemble/image" data-path="pages.1.blocks.0">
10
+ <div id="host"><template shadowrootmode="open"><img id="photo"></template></div>
11
+ </div>`,
12
+ '/home': "<script>history.replaceState(null, '', '/')</script>",
13
+ };
14
+ test.describe('Accessibility report', () => {
15
+ test.beforeEach(async ({ browserName, page }) => {
16
+ test.skip(browserName !== 'chromium', 'The axe-core results do not depend on the browser');
17
+ await page.route(`${origin}/**`, (route) => route.fulfill({
18
+ contentType: 'text/html',
19
+ body: `<!doctype html><html lang="en"><title>Page</title><main>${pages[new URL(route.request().url()).pathname] ?? ''}</main></html>`,
20
+ }));
21
+ });
22
+ test('scans each page once', async ({ page, scanAppAccessibility }) => {
23
+ await page.goto(origin);
24
+ const report = await scanAppAccessibility({ name: 'static_redirect' });
25
+ expect(report.pages.map(({ url }) => url).toSorted()).toStrictEqual([
26
+ `${origin}/`,
27
+ `${origin}/about`,
28
+ `${origin}/apps/42`,
29
+ ]);
30
+ });
31
+ test('lists the failing elements of each crawled page', async ({ page, scanAppAccessibility, }, testInfo) => {
32
+ await page.goto(origin);
33
+ await scanAppAccessibility({ name: 'static_report' });
34
+ const { path } = testInfo.attachments.find(({ name }) => name === 'accessibility.html');
35
+ await page.goto(String(pathToFileURL(path)));
36
+ const about = page.getByRole('region', { name: `${origin}/about` });
37
+ await about.getByText('Images must have alternative text').click();
38
+ const logo = about.getByRole('listitem').filter({ hasText: '#logo' });
39
+ await expect(logo.getByText('app shell (packages/app)')).toBeVisible();
40
+ await expect(logo.getByText('<img id="logo"')).toBeVisible();
41
+ await expect(about
42
+ .getByRole('listitem')
43
+ .filter({ hasText: '#host >>> #photo' })
44
+ .getByText('@appsemble/image (blocks/image) at pages.1.blocks.0')).toBeVisible();
45
+ await expect(about.getByRole('link', { name: 'How to fix image-alt' })).toBeVisible();
46
+ await expect(page
47
+ .getByRole('region', { name: `${origin}/`, exact: true })
48
+ .getByText('No WCAG violations found.')).toBeVisible();
49
+ });
50
+ test('reports the failing elements of each crawled page to GitLab', async ({ page, scanAppAccessibility, }, testInfo) => {
51
+ await page.goto(origin);
52
+ await scanAppAccessibility({ name: 'static_gitlab' });
53
+ const { results } = JSON.parse(await readFile(join(testInfo.project.outputDir, 'gl-accessibility-static_gitlab.json'), 'utf8'));
54
+ expect(results[`${origin}/`]).toStrictEqual([]);
55
+ expect(results[`${origin}/about`]).toStrictEqual([
56
+ expect.objectContaining({
57
+ code: 'image-alt',
58
+ type: 'error',
59
+ selector: '#logo',
60
+ message: 'Images must have alternative text: app shell (packages/app)',
61
+ context: '<img id="logo" src="/apps/:id/icon">',
62
+ }),
63
+ expect.objectContaining({
64
+ code: 'image-alt',
65
+ selector: '#host >>> #photo',
66
+ message: 'Images must have alternative text: @appsemble/image (blocks/image) at pages.1.blocks.0',
67
+ }),
68
+ ...Array.from({ length: 2 }, () => expect.objectContaining({
69
+ code: 'link-name',
70
+ selector: 'a[href="/apps/:id"]',
71
+ context: '<a href="/apps/:id"></a>',
72
+ })),
73
+ ]);
74
+ });
75
+ });
76
+ //# sourceMappingURL=accessibility-report.spec.js.map