From 0378d75224153eb3897acd6c5a471e5b17bf96dc Mon Sep 17 00:00:00 2001 From: Chris Scott <99081550+chriswritescode-dev@users.noreply.github.com> Date: Thu, 3 Dec 2026 16:21:44 +0000 Subject: [PATCH] Add axe-core mobile tab bar accessibility e2e suite --- e2e/mobile-tab-bar-a11y.spec.ts | 113 ++++++++++++++++++++++++++++++++ package.json | 1 + pnpm-lock.yaml | 51 ++++++-------- 3 files changed, 134 insertions(+), 31 deletions(-) create mode 100644 e2e/mobile-tab-bar-a11y.spec.ts diff --git a/e2e/mobile-tab-bar-a11y.spec.ts b/e2e/mobile-tab-bar-a11y.spec.ts new file mode 100644 index 00000000..1755d131 --- /dev/null +++ b/e2e/mobile-tab-bar-a11y.spec.ts @@ -0,0 +1,113 @@ +import { AxeBuilder } from '@axe-core/playwright' +import { request as playwrightRequest, type APIRequestContext, type Page } from '@playwright/test' +import { MANAGER_COLOR_THEME_ID, OPENCODE_THEMES, type ColorThemeId } from '../shared/src/themes' +import { test, expect, type RepoFixture } from './fixtures' +import { BASE_URL, STORAGE_STATE } from './env' + +type ThemeMode = 'dark' | 'light' + +interface TabBarView { + name: string + path: (repo: RepoFixture) => string + label: string + activeTab: string +} + +const MODES: ThemeMode[] = ['dark', 'light'] +const COLOR_THEME_IDS: ColorThemeId[] = [MANAGER_COLOR_THEME_ID, ...OPENCODE_THEMES.map((theme) => theme.id)] +const DEFAULT_APPEARANCE = { theme: 'dark', colorTheme: MANAGER_COLOR_THEME_ID } as const +const PRIMARY_NAV = 'Primary navigation' +const SCHEDULE_NAV = 'Schedule navigation' + +const VIEWS: TabBarView[] = [ + { name: 'schedules-mobile', path: () => '/schedules', label: PRIMARY_NAV, activeTab: 'Schedules' }, + { name: 'repo-schedules-mobile', path: (repo) => `/repos/${repo.id}/schedules`, label: SCHEDULE_NAV, activeTab: 'Jobs' }, +] + +let api: APIRequestContext + +test.use({ viewport: { width: 390, height: 844 }, hasTouch: true, isMobile: true }) + +test.beforeAll(async () => { + api = await playwrightRequest.newContext({ baseURL: BASE_URL, storageState: STORAGE_STATE }) +}) + +test.afterAll(async () => { + await api.patch('/api/settings', { data: { preferences: DEFAULT_APPEARANCE } }) + await api.dispose() +}) + +async function applyAppearance(colorTheme: ColorThemeId, mode: ThemeMode): Promise { + const response = await api.patch('/api/settings', { data: { preferences: { theme: mode, colorTheme } } }) + if (!response.ok()) { + throw new Error(`appearance update failed: ${response.status()} ${await response.text()}`) + } +} + +function expectedPrimaryOverride(colorTheme: ColorThemeId, mode: ThemeMode): string { + const theme = OPENCODE_THEMES.find((candidate) => candidate.id === colorTheme) + return theme ? theme[mode].primary.toLowerCase() : '' +} + +async function waitForAppearance(page: Page, colorTheme: ColorThemeId, mode: ThemeMode): Promise { + await expect + .poll(() => + page.evaluate(() => ({ + dark: document.documentElement.classList.contains('dark'), + primary: document.documentElement.style.getPropertyValue('--color-primary').trim().toLowerCase(), + })), + ) + .toEqual({ dark: mode === 'dark', primary: expectedPrimaryOverride(colorTheme, mode) }) + await page.evaluate(() => + Promise.allSettled( + document + .getAnimations() + .filter((animation) => animation instanceof CSSTransition) + .map((animation) => animation.finished), + ), + ) +} + +async function openTabBar(page: Page, path: string, label: string, colorTheme: ColorThemeId, mode: ThemeMode) { + await applyAppearance(colorTheme, mode) + await page.goto(path) + const nav = page.getByRole('navigation', { name: label }) + await expect(nav).toBeVisible() + await waitForAppearance(page, colorTheme, mode) + return nav +} + +test.describe('mobile tab bar accessibility', () => { + for (const view of VIEWS) { + for (const mode of MODES) { + test(`${view.name} tab bar passes color-contrast and target-size in Manager ${mode}`, async ({ page, repo }) => { + const nav = await openTabBar(page, view.path(repo), view.label, MANAGER_COLOR_THEME_ID, mode) + await expect(nav.getByRole('button', { name: view.activeTab })).toHaveAttribute('aria-current', 'true') + + const results = await new AxeBuilder({ page }) + .include(`nav[aria-label="${view.label}"]`) + .withRules(['color-contrast', 'target-size']) + .analyze() + + expect(results.violations).toEqual([]) + expect(results.passes.map((rule) => rule.id)).toEqual(expect.arrayContaining(['color-contrast', 'target-size'])) + }) + } + } + + for (const colorTheme of COLOR_THEME_IDS) { + for (const mode of MODES) { + test(`active tab meets color-contrast in ${colorTheme} ${mode}`, async ({ page }) => { + await openTabBar(page, '/schedules', PRIMARY_NAV, colorTheme, mode) + + const results = await new AxeBuilder({ page }) + .include(`nav[aria-label="${PRIMARY_NAV}"] [aria-current="true"]`) + .withRules(['color-contrast']) + .analyze() + + expect(results.violations).toEqual([]) + expect(results.passes.map((rule) => rule.id)).toContain('color-contrast') + }) + } + } +}) diff --git a/package.json b/package.json index 95bf9076..469a469e 100644 --- a/package.json +++ b/package.json @@ -40,6 +40,7 @@ "docker:restart": "docker-compose restart" }, "devDependencies": { + "@axe-core/playwright": "^4.14.1", "@oxlint/plugins": "1.93.0", "@playwright/test": "^1.64.0", "concurrently": "^9.1.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 3f0dc243..b0fc5ed0 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -44,6 +44,9 @@ importers: specifier: ^0.7.1 version: 0.7.1 devDependencies: + '@axe-core/playwright': + specifier: ^4.14.1 + version: 4.14.1(playwright-core@1.64.0) '@oxlint/plugins': specifier: 1.93.0 version: 1.93.0 @@ -497,6 +500,12 @@ packages: resolution: {integrity: sha512-sl4Bm6yiMNYrZKkqqDFWN0UfnWhlS8ivKxrYl+6t0gCLrqr8y3B2IqZZbFRkfaVVp7C/baApyh71P+LeE1A2sQ==} engines: {node: '>=18.0.0'} + '@axe-core/playwright@4.14.1': + resolution: {integrity: sha512-cSN1ijrWLnlOof22sPN4RtWGSoPpt7GzOVyOKomyhnPsy1fPNoRdBiJAUziuCRs8KoK50kKufiMUFt7itAuwOg==} + engines: {node: '>=22.12.0'} + peerDependencies: + playwright-core: '>= 1.0.0' + '@babel/code-frame@7.29.7': resolution: {integrity: sha512-Aup7aUOfpbAUg2ROOJN6Iw5f9DMBlzu0mIkm/malLQFN/YQgO48wCj0Kxa3sEHJvPVFg7siR+qRInwXd2qhQKw==} engines: {node: '>=6.9.0'} @@ -1336,13 +1345,11 @@ packages: resolution: {integrity: sha512-IG887NHjPJEw5D1dvNl9jPbcwNFREFKj2fnqEjdrwCnDRywtjNL7k7GgTo24NNlyMAZAq0OkoM0M0Sn6ex/Adg==} cpu: [arm64] os: [linux] - libc: [musl] '@opentui/core-linux-arm64-musl@0.9.9': resolution: {integrity: sha512-FdbKKXfXk6Y5z46wojVNnHyPuEns8Dn7/ONhYTgBi0Z/dBVc/aRWRYzXHIn7x3ZBLpA0fNU01wTAW3SxgOmBmQ==} cpu: [arm64] os: [linux] - libc: [musl] '@opentui/core-linux-arm64@0.8.4': resolution: {integrity: sha512-VGnBN3ItBwZog109wtPIou8pn93TseZwA5OZ05X2PYIYPw+IC6mVeO2Dn0qwwozLBDxeyH3ydbHMFlwzS4/fLg==} @@ -1358,13 +1365,11 @@ packages: resolution: {integrity: sha512-FAiH7wMt/ZbpP2w6TL62deNExTg5w6mujKUBSK89+gJV8FN4jk/K2xz9f522aYhC6SdbpyIKwS0oGIJldYLkcg==} cpu: [x64] os: [linux] - libc: [musl] '@opentui/core-linux-x64-musl@0.9.9': resolution: {integrity: sha512-LvFHYVK/oWTsjaMj7UknAWMmRlhfpo85vW+RALHd2Y/t0PnRCHlEr2uRWPAlrymqIxU4tqei6BIodQLozc0HLg==} cpu: [x64] os: [linux] - libc: [musl] '@opentui/core-linux-x64@0.8.4': resolution: {integrity: sha512-N/uxyaPpWkCZlDXz3fgHMfMuj1L3IVZ/xZ4JifUc4NW9bwa/CYWFJ5J5jBoy2QsAIqoqo8/OD3iFpXR4o12mNQ==} @@ -1460,56 +1465,48 @@ packages: engines: {node: ^20.19.0 || >=22.12.0} cpu: [arm64] os: [linux] - libc: [glibc] '@oxlint/binding-linux-arm64-musl@1.93.0': resolution: {integrity: sha512-zM8Fd/K8sqGvsBcJBZ3oVZ3ctGWbszA08IaGt5gFFF5RcunppAI/ZnAXbouABvnWeJ//S44KKlfPZnDDbeiphg==} engines: {node: ^20.19.0 || >=22.12.0} cpu: [arm64] os: [linux] - libc: [musl] '@oxlint/binding-linux-ppc64-gnu@1.93.0': resolution: {integrity: sha512-7qKCnvhZKDXJG2pdbLazd2hw4FxjJHbZOFrrbzyy5PdHfPLH9vnNUa1le01A8uItZuYKPBPncH+HCoEiFT4SgA==} engines: {node: ^20.19.0 || >=22.12.0} cpu: [ppc64] os: [linux] - libc: [glibc] '@oxlint/binding-linux-riscv64-gnu@1.93.0': resolution: {integrity: sha512-2pgulxC6G8V5wE750NJE/fRkf9aO6i6yoj10wyaR2EdiNtan4OemsOtsQ0ZTXGdY8Q3IoTmlND3GYvjJsvikYg==} engines: {node: ^20.19.0 || >=22.12.0} cpu: [riscv64] os: [linux] - libc: [glibc] '@oxlint/binding-linux-riscv64-musl@1.93.0': resolution: {integrity: sha512-yWsn6Gg2PnGG5jlyDz5+pHGiMTMiy4adaa4WRMzDgzB8efaShk1JMmTHIBSVLQMh0tYXRs4CN5uJCO79r4Mi4g==} engines: {node: ^20.19.0 || >=22.12.0} cpu: [riscv64] os: [linux] - libc: [musl] '@oxlint/binding-linux-s390x-gnu@1.93.0': resolution: {integrity: sha512-WCn5plwp/ezS2RDPQKp0/EXEVRr9/dDexUdRKmsMFqzNM5xBSZ1wbsi3PuMk1VfkMRnI5BuazCsziCWMXRDOlw==} engines: {node: ^20.19.0 || >=22.12.0} cpu: [s390x] os: [linux] - libc: [glibc] '@oxlint/binding-linux-x64-gnu@1.93.0': resolution: {integrity: sha512-F2CGjb9LAkzH+IYTZSzd1klQ1vk5z6Utjax64WeLByCkYXbVDbsun+Oy2hLfW2MDSKCvW+jwy/9ld0EPgdeu+A==} engines: {node: ^20.19.0 || >=22.12.0} cpu: [x64] os: [linux] - libc: [glibc] '@oxlint/binding-linux-x64-musl@1.93.0': resolution: {integrity: sha512-plf5DE2objcG8Tf7mXRuRa8tT8rzDkpjqXQtKoGsKHWkpgsialbON1+cCtoSEUTVbQUjXvuAm8vV9+3rR0yCBw==} engines: {node: ^20.19.0 || >=22.12.0} cpu: [x64] os: [linux] - libc: [musl] '@oxlint/binding-openharmony-arm64@1.93.0': resolution: {integrity: sha512-Kp2yJrKvoTe9FfKdO/xwLNUbs2bYTMKx0+aoQD1s0h/Tx0kSgtHSdGmrk8tTKdluosjFbo88qYRIaNIX43AfFw==} @@ -2098,67 +2095,56 @@ packages: resolution: {integrity: sha512-EHMUcDwhtdRGlXZsGSIuXSYwD5kOT9NVnx9sqzYiwAc91wfYOE1g1djOEDseZJKKqtHAHGwnGPQu3kytmfaXLQ==} cpu: [arm] os: [linux] - libc: [glibc] '@rollup/rollup-linux-arm-musleabihf@4.54.0': resolution: {integrity: sha512-+pBrqEjaakN2ySv5RVrj/qLytYhPKEUwk+e3SFU5jTLHIcAtqh2rLrd/OkbNuHJpsBgxsD8ccJt5ga/SeG0JmA==} cpu: [arm] os: [linux] - libc: [musl] '@rollup/rollup-linux-arm64-gnu@4.54.0': resolution: {integrity: sha512-NSqc7rE9wuUaRBsBp5ckQ5CVz5aIRKCwsoa6WMF7G01sX3/qHUw/z4pv+D+ahL1EIKy6Enpcnz1RY8pf7bjwng==} cpu: [arm64] os: [linux] - libc: [glibc] '@rollup/rollup-linux-arm64-musl@4.54.0': resolution: {integrity: sha512-gr5vDbg3Bakga5kbdpqx81m2n9IX8M6gIMlQQIXiLTNeQW6CucvuInJ91EuCJ/JYvc+rcLLsDFcfAD1K7fMofg==} cpu: [arm64] os: [linux] - libc: [musl] '@rollup/rollup-linux-loong64-gnu@4.54.0': resolution: {integrity: sha512-gsrtB1NA3ZYj2vq0Rzkylo9ylCtW/PhpLEivlgWe0bpgtX5+9j9EZa0wtZiCjgu6zmSeZWyI/e2YRX1URozpIw==} cpu: [loong64] os: [linux] - libc: [glibc] '@rollup/rollup-linux-ppc64-gnu@4.54.0': resolution: {integrity: sha512-y3qNOfTBStmFNq+t4s7Tmc9hW2ENtPg8FeUD/VShI7rKxNW7O4fFeaYbMsd3tpFlIg1Q8IapFgy7Q9i2BqeBvA==} cpu: [ppc64] os: [linux] - libc: [glibc] '@rollup/rollup-linux-riscv64-gnu@4.54.0': resolution: {integrity: sha512-89sepv7h2lIVPsFma8iwmccN7Yjjtgz0Rj/Ou6fEqg3HDhpCa+Et+YSufy27i6b0Wav69Qv4WBNl3Rs6pwhebQ==} cpu: [riscv64] os: [linux] - libc: [glibc] '@rollup/rollup-linux-riscv64-musl@4.54.0': resolution: {integrity: sha512-ZcU77ieh0M2Q8Ur7D5X7KvK+UxbXeDHwiOt/CPSBTI1fBmeDMivW0dPkdqkT4rOgDjrDDBUed9x4EgraIKoR2A==} cpu: [riscv64] os: [linux] - libc: [musl] '@rollup/rollup-linux-s390x-gnu@4.54.0': resolution: {integrity: sha512-2AdWy5RdDF5+4YfG/YesGDDtbyJlC9LHmL6rZw6FurBJ5n4vFGupsOBGfwMRjBYH7qRQowT8D/U4LoSvVwOhSQ==} cpu: [s390x] os: [linux] - libc: [glibc] '@rollup/rollup-linux-x64-gnu@4.54.0': resolution: {integrity: sha512-WGt5J8Ij/rvyqpFexxk3ffKqqbLf9AqrTBbWDk7ApGUzaIs6V+s2s84kAxklFwmMF/vBNGrVdYgbblCOFFezMQ==} cpu: [x64] os: [linux] - libc: [glibc] '@rollup/rollup-linux-x64-musl@4.54.0': resolution: {integrity: sha512-JzQmb38ATzHjxlPHuTH6tE7ojnMKM2kYNzt44LO/jJi8BpceEC8QuXYA908n8r3CNuG/B3BV8VR3Hi1rYtmPiw==} cpu: [x64] os: [linux] - libc: [musl] '@rollup/rollup-openharmony-arm64@4.54.0': resolution: {integrity: sha512-huT3fd0iC7jigGh7n3q/+lfPcXxBi+om/Rs3yiFxjvSxbSB6aohDFXbWvlspaqjeOh+hx7DDHS+5Es5qRkWkZg==} @@ -2315,28 +2301,24 @@ packages: engines: {node: '>= 10'} cpu: [arm64] os: [linux] - libc: [glibc] '@tailwindcss/oxide-linux-arm64-musl@4.1.18': resolution: {integrity: sha512-1px92582HkPQlaaCkdRcio71p8bc8i/ap5807tPRDK/uw953cauQBT8c5tVGkOwrHMfc2Yh6UuxaH4vtTjGvHg==} engines: {node: '>= 10'} cpu: [arm64] os: [linux] - libc: [musl] '@tailwindcss/oxide-linux-x64-gnu@4.1.18': resolution: {integrity: sha512-v3gyT0ivkfBLoZGF9LyHmts0Isc8jHZyVcbzio6Wpzifg/+5ZJpDiRiUhDLkcr7f/r38SWNe7ucxmGW3j3Kb/g==} engines: {node: '>= 10'} cpu: [x64] os: [linux] - libc: [glibc] '@tailwindcss/oxide-linux-x64-musl@4.1.18': resolution: {integrity: sha512-bhJ2y2OQNlcRwwgOAGMY0xTFStt4/wyU6pvI6LSuZpRgKQwxTec0/3Scu91O8ir7qCR3AuepQKLU/kX99FouqQ==} engines: {node: '>= 10'} cpu: [x64] os: [linux] - libc: [musl] '@tailwindcss/oxide-wasm32-wasi@4.1.18': resolution: {integrity: sha512-LffYTvPjODiP6PT16oNeUQJzNVyJl1cjIebq/rWWBF+3eDst5JGEFSc5cWxyRCJ0Mxl+KyIkqRxk1XPEs9x8TA==} @@ -2749,6 +2731,10 @@ packages: aws4fetch@1.0.20: resolution: {integrity: sha512-/djoAN709iY65ETD6LKCtyyEI04XIBP5xVvfmNxsEP0uJB5tyaGBztSryRr4HqMStr9R06PisQE7m9zDTXKu6g==} + axe-core@4.14.1: + resolution: {integrity: sha512-FHfa+lmNjQZfJz1q8wKqIDwC6DExcHt/pkjNQb09a3NPjCKg2rhu5qb2S4r76ASyFNNtuFooJpZe37OgudVGtQ==} + engines: {node: '>=4'} + b4a@1.7.3: resolution: {integrity: sha512-5Q2mfq2WfGuFp3uS//0s6baOJLMoVduPYVeNmDYxu5OUA1/cBfvr2RIS7vi62LdNj/urk1hfmj867I3qt6uZ7Q==} peerDependencies: @@ -3906,28 +3892,24 @@ packages: engines: {node: '>= 12.0.0'} cpu: [arm64] os: [linux] - libc: [glibc] lightningcss-linux-arm64-musl@1.30.2: resolution: {integrity: sha512-5Vh9dGeblpTxWHpOx8iauV02popZDsCYMPIgiuw97OJ5uaDsL86cnqSFs5LZkG3ghHoX5isLgWzMs+eD1YzrnA==} engines: {node: '>= 12.0.0'} cpu: [arm64] os: [linux] - libc: [musl] lightningcss-linux-x64-gnu@1.30.2: resolution: {integrity: sha512-Cfd46gdmj1vQ+lR6VRTTadNHu6ALuw2pKR9lYq4FnhvgBc4zWY1EtZcAc6EffShbb1MFrIPfLDXD6Xprbnni4w==} engines: {node: '>= 12.0.0'} cpu: [x64] os: [linux] - libc: [glibc] lightningcss-linux-x64-musl@1.30.2: resolution: {integrity: sha512-XJaLUUFXb6/QG2lGIW6aIk6jKdtjtcffUT0NKvIqhSBY3hh9Ch+1LCeH80dR9q9LBjG3ewbDjnumefsLsP6aiA==} engines: {node: '>= 12.0.0'} cpu: [x64] os: [linux] - libc: [musl] lightningcss-win32-arm64-msvc@1.30.2: resolution: {integrity: sha512-FZn+vaj7zLv//D/192WFFVA0RgHawIcHqLX9xuWiQt7P0PtdFEVaxgF9rjM/IRYHQXNnk61/H/gb2Ei+kUQ4xQ==} @@ -5584,6 +5566,11 @@ snapshots: '@aws/lambda-invoke-store@0.3.0': {} + '@axe-core/playwright@4.14.1(playwright-core@1.64.0)': + dependencies: + axe-core: 4.14.1 + playwright-core: 1.64.0 + '@babel/code-frame@7.29.7': dependencies: '@babel/helper-validator-identifier': 7.29.7 @@ -7911,6 +7898,8 @@ snapshots: aws4fetch@1.0.20: {} + axe-core@4.14.1: {} + b4a@1.7.3: {} babel-plugin-jsx-dom-expressions@0.40.11(@babel/core@7.29.7):