Repository navigation
Expand file tree
/
Copy patha11y.spec.ts
More file actions
188 lines (175 loc) · 8.95 KB
/
Copy patha11y.spec.ts
File metadata and controls
188 lines (175 loc) · 8.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
/**
* Automated axe checks on critical routes (runs in CI with Playwright webServer).
*/
import AxeBuilder from '@axe-core/playwright';
import { expect, test } from '@playwright/test';
import { clickNavItem, ensureBlankProject, selectEnglish, waitForSpaReady } from './helpers';
async function assertNoSeriousViolations(page: import('@playwright/test').Page, label: string) {
const results = await new AxeBuilder({ page }).analyze();
const serious = results.violations.filter(
(v) => v.impact === 'serious' || v.impact === 'critical',
);
expect(serious, `${label}: ${JSON.stringify(serious, null, 2)}`).toHaveLength(0);
}
test.describe('Accessibility (axe)', () => {
// QNBS-v3: emulate prefers-reduced-motion so component animations (e.g. WelcomePortal's
// fade-in) settle instantly. Without this, axe samples blended mid-animation colors and
// reports phantom color-contrast failures. page.emulateMedia is well-typed (test.use()
// rejects reducedMotion in this Playwright version). Scoped here so VRT baselines (captured
// without reduced motion) stay untouched.
test.beforeEach(async ({ page }) => {
await page.emulateMedia({ reducedMotion: 'reduce' });
});
test('welcome / home has no serious axe violations', async ({ page }) => {
await page.goto('/');
// QNBS-v3: waitForSpaReady instead of domcontentloaded — avoids "Execution context was
// destroyed" when axe runs while React / i18n init triggers an in-page navigation.
await waitForSpaReady(page);
await assertNoSeriousViolations(page, 'welcome');
});
test('settings accessibility hub has no serious axe violations', async ({ page }) => {
await page.goto('/');
await ensureBlankProject(page);
// QNBS-v3: clickNavItem — sidebar(page) is hidden md:flex, fails on Mobile Chrome
await clickNavItem(page, /Settings/i);
await page.getByRole('button', { name: /Accessibility|Barrierefreiheit/i }).click();
await expect(
page.getByRole('heading', {
name: /Accessibility Settings|Barrierefreiheitseinstellungen/i,
}),
).toBeVisible({
timeout: 15000,
});
await assertNoSeriousViolations(page, 'settings-accessibility');
});
test('command palette open has no serious axe violations', async ({ page }) => {
await page.goto('/');
await selectEnglish(page);
await ensureBlankProject(page);
// QNBS-v3: command-palette-trigger is hidden sm:block (invisible on Mobile Chrome <640px);
// fall back to Ctrl+K keyboard shortcut which works on all viewports
const trigger = page.locator('[data-tour="command-palette-trigger"]');
if (await trigger.isVisible({ timeout: 2000 }).catch(() => false)) {
await trigger.click();
} else {
await page.keyboard.press('Control+k');
}
await expect(page.locator('#command-palette-listbox')).toBeVisible({ timeout: 15000 });
await assertNoSeriousViolations(page, 'command-palette');
await page.keyboard.press('Escape');
});
test('writer version control panel has no serious axe violations', async ({ page }) => {
await page.goto('/');
await selectEnglish(page);
await ensureBlankProject(page);
// QNBS-v3: clickNavItem — sidebar(page) is hidden md:flex, fails on Mobile Chrome
await clickNavItem(page, /AI Writing Studio|Writer/i);
// QNBS-v3: getByRole — ARIA excludes display:none elements; works for both mobile + desktop VC buttons
await page.getByRole('button', { name: /Versions/i }).click();
await expect(page.locator('#version-control-heading')).toBeVisible({ timeout: 15000 });
await assertNoSeriousViolations(page, 'writer-version-control');
await page.keyboard.press('Escape');
});
test('characters view has no serious axe violations', async ({ page }) => {
await page.goto('/');
await selectEnglish(page);
await ensureBlankProject(page);
await clickNavItem(page, /Characters/i);
await page.waitForLoadState('domcontentloaded');
await page.waitForTimeout(500);
await assertNoSeriousViolations(page, 'characters-view');
});
test('world view has no serious axe violations', async ({ page }) => {
await page.goto('/');
await selectEnglish(page);
await ensureBlankProject(page);
await clickNavItem(page, /World Building/i);
await page.waitForLoadState('domcontentloaded');
await page.waitForTimeout(500);
await assertNoSeriousViolations(page, 'world-view');
});
test('plot board has no serious axe violations', async ({ page }) => {
await page.goto('/');
await selectEnglish(page);
await ensureBlankProject(page);
await clickNavItem(page, /Scene Board/i);
await page.waitForLoadState('domcontentloaded');
await page.waitForTimeout(500);
await assertNoSeriousViolations(page, 'plot-board');
});
test('help view has no serious axe violations', async ({ page }) => {
await page.goto('/');
await selectEnglish(page);
await ensureBlankProject(page);
await clickNavItem(page, /Help/i);
await page.waitForLoadState('domcontentloaded');
await page.waitForTimeout(500);
await assertNoSeriousViolations(page, 'help-view');
});
// QNBS-v3: light color scheme + explicit Writer's Sepia — the plain "welcome" test above no longer covers sepia now that the default preset changed, so this closes that gap deterministically rather than relying on default/persistence.
test('light sepia dashboard has no serious axe violations', async ({ page }) => {
await page.emulateMedia({ colorScheme: 'light', reducedMotion: 'reduce' });
await page.goto('/');
await waitForSpaReady(page);
await selectEnglish(page);
await ensureBlankProject(page);
await clickNavItem(page, /Settings/i);
await page.getByRole('button', { name: /Appearance|Erscheinungsbild/i }).click();
await page.getByRole('button', { name: /Writer's Sepia/i }).click();
// Confirm light-theme + appearance-sepia are both applied before running axe
await page.waitForFunction(
() =>
document.body.classList.contains('light-theme') &&
document.body.classList.contains('appearance-sepia'),
{ timeout: 8000 },
);
await clickNavItem(page, /Dashboard/i);
// QNBS-v3: waits for the lazy-loaded Dashboard to actually render before scanning — clickNavItem/domcontentloaded resolve before the view mounts, so a fixed sleep could scan a stale/empty page.
await expect(page.locator('#projectTitle')).toBeVisible({ timeout: 15_000 });
await assertNoSeriousViolations(page, 'light-sepia-home');
});
// QNBS-v3: dark color scheme + explicit Writer's Sepia selection (not relying on it being the default, which changed) so this keeps exercising .dark-theme.appearance-sepia's token set (primary 14.7:1, muted 5.3:1 on worst-case bg).
test('dark sepia theme has no serious axe violations', async ({ page }) => {
await page.emulateMedia({ colorScheme: 'dark', reducedMotion: 'reduce' });
await page.goto('/');
await waitForSpaReady(page);
await selectEnglish(page);
await ensureBlankProject(page);
await clickNavItem(page, /Settings/i);
await page.getByRole('button', { name: /Appearance|Erscheinungsbild/i }).click();
await page.getByRole('button', { name: /Writer's Sepia/i }).click();
// Confirm dark-theme + appearance-sepia are both applied before running axe
await page.waitForFunction(
() =>
document.body.classList.contains('dark-theme') &&
document.body.classList.contains('appearance-sepia'),
{ timeout: 8000 },
);
await assertNoSeriousViolations(page, 'dark-sepia-settings');
await clickNavItem(page, /Dashboard/i);
// QNBS-v3: waits for the lazy-loaded Dashboard to actually render before scanning — see the light-sepia test's identical rationale above.
await expect(page.locator('#projectTitle')).toBeVisible({ timeout: 15_000 });
await assertNoSeriousViolations(page, 'dark-sepia-home');
});
// QNBS-v3: overrides the describe-level reducedMotion:'reduce' emulation to prove the Dashboard's real, fully-settled end state is AA-compliant on its own — not only the reduced-motion path other tests in this file exercise.
test('dashboard has no serious axe violations after motion settles (normal motion)', async ({
page,
}) => {
await page.emulateMedia({ reducedMotion: 'no-preference' });
await page.goto('/');
await waitForSpaReady(page);
await selectEnglish(page);
await ensureBlankProject(page);
await clickNavItem(page, /Dashboard/i);
await expect(page.locator('#projectTitle')).toBeVisible({ timeout: 15_000 });
// QNBS-v3: each staggered card's fade-in delay scales with its own --index, so waiting for every .animate-in element's computed opacity to settle is more robust than tracking each caller's index by hand.
await page.waitForFunction(
() =>
Array.from(document.querySelectorAll<HTMLElement>('.animate-in')).every(
(el) => getComputedStyle(el).opacity === '1',
),
{ timeout: 8000 },
);
await assertNoSeriousViolations(page, 'normal-motion-home');
});
});