fix(e2e+ui): e2e checks for the audit's failure classes, and the gaps they caught (#1767)
loading-errors now forces each list API (/api/tasks, /api/captures, /api/event-types, /api/tokens, /api/access/policies) to fail and asserts the page shows its error surface, never its empty-state copy. accessibility gains two static-route sweeps: every input/textarea/select/ button must have an accessible name, and every keyboard focus stop's indicator (ring var, outline, shadow or focus border) must clear 3:1 against the background behind it. phone-overflow sweeps every static route at 390x844 for horizontal scroll. The sweeps caught real gaps, fixed here: the DurationInput amount input had no accessible name and its unit select no focus indicator, and TabsContent and CodeBlockContent were focusable with outline-none and no ring. The stale 'Sections' list selector now matches the nav landmark.
This commit is contained in:
8 files changed
+178
-24
No files matched your search
@@ -1,9 +1,14 @@
|
||||
// Keyboard and phone access: the task dialog fits and tabs in order, pages
|
||||
// title correctly, the skip link and palette focus main content, and
|
||||
// query-only tab switches keep focus where it is.
|
||||
// query-only tab switches keep focus where it is. Then the audit's two
|
||||
// static sweeps (#1767): no unnamed controls on any route, and every keyboard
|
||||
// focus stop's indicator clears 3:1 against the background behind it.
|
||||
const assert = require('node:assert/strict');
|
||||
const { staticRoutes } = require('./helpers/routes.cjs');
|
||||
|
||||
module.exports = async ({ page, go, shot, settled }) => {
|
||||
module.exports = async ({ page, go, shot, fail, settled, tolerate }) => {
|
||||
// The extension catalogue 502 is a stack-environment issue, not this check.
|
||||
tolerate(/extensions\/catalogue/);
|
||||
await page.setViewportSize({ width: 390, height: 844 });
|
||||
await go('/tasks');
|
||||
await page.getByRole('button', { name: 'Jump to', exact: true }).click();
|
||||
@@ -36,7 +41,7 @@ module.exports = async ({ page, go, shot, settled }) => {
|
||||
await page.keyboard.press('Enter');
|
||||
assert.equal(await page.evaluate(() => document.activeElement?.id), 'main-content');
|
||||
await page.getByRole('button', { name: 'Toggle Sidebar', exact: true }).click();
|
||||
await page.getByRole('list', { name: 'Sections', exact: true }).getByRole('link', { name: 'Tasks', exact: true }).click();
|
||||
await page.getByRole('navigation', { name: 'Sections', exact: true }).getByRole('link', { name: 'Tasks', exact: true }).click();
|
||||
await page.waitForFunction(() => document.activeElement?.id === 'main-content', null, { timeout: 5000 }).catch(() => {});
|
||||
assert.equal(await page.evaluate(() => document.activeElement?.id), 'main-content', 'route navigation did not focus main');
|
||||
await page.getByRole('button', { name: 'Jump to', exact: true }).click();
|
||||
@@ -50,4 +55,122 @@ module.exports = async ({ page, go, shot, settled }) => {
|
||||
const tab = page.getByRole('tab', { name: /^Map/ });
|
||||
await tab.click();
|
||||
assert.ok(await tab.evaluate(el => el === document.activeElement), 'query-only navigation stole focus');
|
||||
|
||||
await page.setViewportSize({ width: 1440, height: 900 });
|
||||
|
||||
// Unnamed controls: every visible input, textarea, select, button or
|
||||
// widget role on each static route needs an accessible name (accname
|
||||
// order: labelledby, label, content, value, placeholder, title).
|
||||
for (const r of staticRoutes()) {
|
||||
await go(r);
|
||||
const unnamed = await page.evaluate(() => {
|
||||
const name = (el) => {
|
||||
const by = el.getAttribute('aria-labelledby');
|
||||
if (by) {
|
||||
const t = by.split(/\s+/).map((id) => (document.getElementById(id)?.textContent || '')).join(' ').trim();
|
||||
if (t) return t;
|
||||
}
|
||||
const al = el.getAttribute('aria-label');
|
||||
if (al && al.trim()) return al.trim();
|
||||
if (el.id) {
|
||||
const l = document.querySelector(`label[for="${CSS.escape(el.id)}"]`);
|
||||
if (l && l.textContent.trim()) return l.textContent.trim();
|
||||
}
|
||||
const wrap = el.closest('label');
|
||||
if (wrap && wrap.textContent.trim()) return wrap.textContent.trim();
|
||||
if (el.tagName === 'BUTTON' || el.getAttribute('role') === 'button' || el.getAttribute('role') === 'tab' || el.getAttribute('role') === 'switch') return el.textContent.trim();
|
||||
if (el.tagName === 'INPUT') {
|
||||
const t = (el.getAttribute('type') || 'text').toLowerCase();
|
||||
if (t === 'submit' || t === 'button' || t === 'reset') return el.value.trim();
|
||||
if (t === 'image') return (el.getAttribute('alt') || '').trim();
|
||||
}
|
||||
return (el.getAttribute('placeholder') || el.getAttribute('title') || '').trim();
|
||||
};
|
||||
return [...document.querySelectorAll('button, input, textarea, select, [role="button"], [role="tab"], [role="switch"], [role="checkbox"]')]
|
||||
.filter((el) => el.type !== 'hidden' && el.getClientRects().length)
|
||||
.filter((el) => !name(el))
|
||||
.map((el) => `${el.tagName.toLowerCase()}${el.id ? '#' + el.id : ''}: ${el.outerHTML.slice(0, 120)}`);
|
||||
});
|
||||
for (const u of unnamed) fail(`unnamed control on ${r}: ${u}`);
|
||||
}
|
||||
|
||||
// Focus contrast: Tab through each static route; the focused element's
|
||||
// outline or ring must clear 3:1 against the effective background behind it.
|
||||
const focusProbe = () => page.evaluate(() => {
|
||||
const el = document.activeElement;
|
||||
if (!el || el === document.body || el === document.documentElement) return null;
|
||||
const cs = getComputedStyle(el);
|
||||
const parse = (c) => {
|
||||
c = String(c).trim();
|
||||
let m = c.match(/rgba?\(([^)]+)\)/);
|
||||
if (m) {
|
||||
const p = m[1].split(',').map(Number);
|
||||
return { r: p[0], g: p[1], b: p[2], a: p.length > 3 ? p[3] : 1 };
|
||||
}
|
||||
m = c.match(/^#([0-9a-f]{3,8})$/i);
|
||||
if (m) {
|
||||
let h = m[1];
|
||||
if (h.length === 3 || h.length === 4) h = [...h].map((x) => x + x).join('');
|
||||
const n = parseInt(h.slice(0, 6), 16);
|
||||
return { r: (n >> 16) & 255, g: (n >> 8) & 255, b: n & 255, a: h.length === 8 ? parseInt(h.slice(6, 8), 16) / 255 : 1 };
|
||||
}
|
||||
return null;
|
||||
};
|
||||
const bgBehind = (start) => {
|
||||
for (let n = start; n; n = n.parentElement) {
|
||||
const c = parse(getComputedStyle(n).backgroundColor);
|
||||
if (c && c.a > 0) return c;
|
||||
}
|
||||
return { r: 255, g: 255, b: 255, a: 1 };
|
||||
};
|
||||
// An outer ring or outline is painted over the parent's background; an
|
||||
// inset one over the element's own. Score against whichever is higher.
|
||||
const bgSelf = bgBehind(el);
|
||||
const bgParent = bgBehind(el.parentElement);
|
||||
const over = (fg, bg) => {
|
||||
const a = fg.a + bg.a * (1 - fg.a);
|
||||
if (a === 0) return { r: 0, g: 0, b: 0 };
|
||||
return { r: (fg.r * fg.a + bg.r * bg.a * (1 - fg.a)) / a, g: (fg.g * fg.a + bg.g * bg.a * (1 - fg.a)) / a, b: (fg.b * fg.a + bg.b * bg.a * (1 - fg.a)) / a };
|
||||
};
|
||||
const lum = (c) => {
|
||||
const f = (v) => { v /= 255; return v <= 0.03928 ? v / 12.92 : Math.pow((v + 0.055) / 1.055, 2.4); };
|
||||
return 0.2126 * f(c.r) + 0.7152 * f(c.g) + 0.0722 * f(c.b);
|
||||
};
|
||||
const ratio = (c1, c2) => {
|
||||
const l1 = lum(c1), l2 = lum(c2);
|
||||
return (Math.max(l1, l2) + 0.05) / (Math.min(l1, l2) + 0.05);
|
||||
};
|
||||
let fg = null;
|
||||
// The ring lives in --tw-ring-shadow on :focus-visible; read the var
|
||||
// directly, then fall back to outline, any shadow layer, focus border.
|
||||
if (el.matches(':focus-visible')) {
|
||||
const m = cs.getPropertyValue('--tw-ring-shadow').match(/rgba?\([^)]+\)|#[0-9a-f]{3,8}\b/i);
|
||||
if (m) { const c = parse(m[0]); if (c && c.a > 0) fg = c; }
|
||||
}
|
||||
if (!fg && cs.outlineStyle !== 'none' && parseFloat(cs.outlineWidth) > 0) fg = parse(cs.outlineColor === 'currentcolor' ? cs.color : cs.outlineColor);
|
||||
if (!fg && cs.boxShadow && cs.boxShadow !== 'none') {
|
||||
for (const m of cs.boxShadow.matchAll(/rgba?\([^)]+\)|#[0-9a-f]{3,8}\b/gi)) {
|
||||
const c = parse(m[0]);
|
||||
if (c && c.a > 0) { fg = c; break; }
|
||||
}
|
||||
}
|
||||
if (!fg && el.matches(':focus-visible') && parseFloat(cs.borderTopWidth) > 0) {
|
||||
const c = parse(cs.borderTopColor);
|
||||
if (c && c.a > 0) fg = c;
|
||||
}
|
||||
const sig = `${el.tagName}#${el.id}:${(el.textContent || '').trim().slice(0, 30)}`;
|
||||
if (!fg) return { sig, ratio: 0 };
|
||||
return { sig, ratio: Math.max(ratio(over(fg, bgSelf), bgSelf), ratio(over(fg, bgParent), bgParent)) };
|
||||
});
|
||||
for (const r of staticRoutes()) {
|
||||
await go(r);
|
||||
let prev = '';
|
||||
for (let i = 0; i < 40; i++) {
|
||||
await page.keyboard.press('Tab');
|
||||
const info = await focusProbe();
|
||||
if (!info || info.sig === prev) break;
|
||||
prev = info.sig;
|
||||
if (info.ratio < 3) fail(`focus indicator under 3:1 on ${r} at ${info.sig} (ratio ${info.ratio.toFixed(2)})`);
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,19 @@
|
||||
// The dashboard's static routes, read from the router source so a new page is
|
||||
// swept automatically. Parameterised and redirect routes are skipped.
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
function staticRoutes() {
|
||||
const src = fs.readFileSync(path.join(__dirname, '../../../ui/src/router/index.ts'), 'utf8');
|
||||
const out = [];
|
||||
for (const line of src.split('\n')) {
|
||||
if (/redirect:/.test(line)) continue;
|
||||
const m = line.match(/path: "([^"]*)"/);
|
||||
if (!m || m[1].includes(':')) continue;
|
||||
if (m[1].startsWith('/')) out.push(m[1]);
|
||||
else if (m[1]) out.push('/org/' + m[1]);
|
||||
}
|
||||
return [...new Set(out)];
|
||||
}
|
||||
|
||||
module.exports = { staticRoutes };
|
||||
@@ -1,5 +1,7 @@
|
||||
const assert=require('node:assert/strict');
|
||||
module.exports=async({page,go,shot})=>{
|
||||
module.exports=async({page,go,shot,tolerate})=>{
|
||||
// The extension catalogue 502 is a stack-environment issue, not this check.
|
||||
tolerate(/extensions\/catalogue/);
|
||||
await page.route('**/api/access/policies',async route=>{await new Promise(r=>setTimeout(r,2200));await route.continue()});
|
||||
await go('/access/policies');
|
||||
assert.equal(await page.getByText('No policies yet.',{exact:true}).count(),0);
|
||||
@@ -16,4 +18,19 @@ module.exports=async({page,go,shot})=>{
|
||||
await page.getByRole('button',{name:'Retry runs',exact:true}).click();
|
||||
await page.getByRole('alert').filter({hasText:'Could not load recent runs'}).waitFor({state:'hidden'});
|
||||
await shot('recovered');
|
||||
// A failed list read is an error, never the empty state (#1767): force each
|
||||
// page's list API to 500 and check its empty-state copy stays hidden.
|
||||
const failList = async (pattern,path,emptyTexts,errorSel='[role=alert]')=>{
|
||||
await page.route(pattern,route=>route.fulfill({status:200,contentType:'application/json',body:'unreadable response'}));
|
||||
await go(path);
|
||||
await page.locator(errorSel).first().waitFor();
|
||||
for(const text of emptyTexts) assert.equal(await page.getByText(text,{exact:true}).count(),0,`${path} shows its empty state ("${text}") while the list read fails`);
|
||||
await page.unroute(pattern);
|
||||
};
|
||||
await failList('**/api/tasks*','/tasks',['No tasks yet'],'text=Archie is not responding');
|
||||
await failList('**/api/captures*','/events',['No captures yet']);
|
||||
await failList('**/api/event-types*','/events',['No event types yet']);
|
||||
await failList('**/api/tokens*','/account',['No tokens yet']);
|
||||
await failList('**/api/access/policies*','/org/policies',['No policies yet']);
|
||||
await shot('failed-reads-show-errors');
|
||||
};
|
||||
@@ -4,8 +4,11 @@
|
||||
// token form, /org/agents the agent rows and the grants card, /events the
|
||||
// sources table, the event-type rule editor and the mapping editor dialog.
|
||||
const assert = require('node:assert/strict');
|
||||
const { staticRoutes } = require('./helpers/routes.cjs');
|
||||
|
||||
module.exports = async ({ page, go, shot, fail, settled }) => {
|
||||
module.exports = async ({ page, go, shot, fail, settled, tolerate }) => {
|
||||
// The extension catalogue 502 is a stack-environment issue, not this check.
|
||||
tolerate(/extensions\/catalogue/);
|
||||
await page.setViewportSize({ width: 390, height: 844 });
|
||||
|
||||
const assertNoOverflow = async (label) => {
|
||||
@@ -58,4 +61,9 @@ module.exports = async ({ page, go, shot, fail, settled }) => {
|
||||
await assertNoOverflow('mapping editor dialog');
|
||||
await shot('mapping-editor');
|
||||
}
|
||||
|
||||
// Every static route fits 390px (#1767): horizontal scroll fails.
|
||||
for (const r of staticRoutes()) {
|
||||
await visit(r, `route ${r}`, null);
|
||||
}
|
||||
};
|
||||
+2
-16
@@ -1,24 +1,10 @@
|
||||
// Every static route loads without errors, renders, and shows no text with
|
||||
// stray leading, trailing or doubled spaces.
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
function routes() {
|
||||
const src = fs.readFileSync(path.join(__dirname, '../../ui/src/router/index.ts'), 'utf8');
|
||||
const out = [];
|
||||
for (const line of src.split('\n')) {
|
||||
if (/redirect:/.test(line)) continue;
|
||||
const m = line.match(/path: "([^"]*)"/);
|
||||
if (!m || m[1].includes(':')) continue;
|
||||
if (m[1].startsWith('/')) out.push(m[1]);
|
||||
else if (m[1]) out.push('/org/' + m[1]);
|
||||
}
|
||||
return [...new Set(out)];
|
||||
}
|
||||
const { staticRoutes } = require('./helpers/routes.cjs');
|
||||
|
||||
module.exports = async ({ page, go, shot, fail }) => {
|
||||
const stray = new Map();
|
||||
for (const r of routes()) {
|
||||
for (const r of staticRoutes()) {
|
||||
await go(r);
|
||||
await shot(r);
|
||||
// Log lines are data, not copy.
|
||||
|
||||
@@ -58,7 +58,7 @@ function getLines() {
|
||||
tabindex="0"
|
||||
:style="{ counterReset: `line ${startLine - 1}` }"
|
||||
:class="cn(
|
||||
'px-3 py-3 leading-relaxed group-has-data-[slot=code-block-header]/code-block:pt-2 group-has-data-[slot=code-block-footer]/code-block:pb-2 group-data-[size=sm]/code-block:px-2.5 group-data-[size=sm]/code-block:py-2.5 group-data-[size=sm]/code-block:group-has-data-[slot=code-block-header]/code-block:pt-1.5 min-h-0 min-w-0 scroll-fade-x scrollbar-thin overflow-auto text-start font-mono outline-none data-wrap:scroll-fade-y data-wrap:wrap-break-word data-wrap:whitespace-pre-wrap',
|
||||
'px-3 py-3 leading-relaxed group-has-data-[slot=code-block-header]/code-block:pt-2 group-has-data-[slot=code-block-footer]/code-block:pb-2 group-data-[size=sm]/code-block:px-2.5 group-data-[size=sm]/code-block:py-2.5 group-data-[size=sm]/code-block:group-has-data-[slot=code-block-header]/code-block:pt-1.5 min-h-0 min-w-0 scroll-fade-x scrollbar-thin overflow-auto text-start font-mono outline-none rounded-md focus-visible:ring-3 focus-visible:ring-ring data-wrap:scroll-fade-y data-wrap:wrap-break-word data-wrap:whitespace-pre-wrap',
|
||||
props.class,
|
||||
)"
|
||||
>
|
||||
|
||||
@@ -53,6 +53,7 @@ function emitChange() {
|
||||
:id="id"
|
||||
:model-value="amount"
|
||||
type="text"
|
||||
aria-label="Duration"
|
||||
:aria-invalid="invalid || ariaInvalid === true || ariaInvalid === 'true' ? true : undefined"
|
||||
@update:model-value="(value: string | number) => { amount = value; emitChange(); }"
|
||||
inputmode="decimal"
|
||||
@@ -63,7 +64,7 @@ function emitChange() {
|
||||
<select
|
||||
v-model="unit"
|
||||
aria-label="Unit"
|
||||
class="bg-transparent font-mono text-caption text-fg-muted outline-none"
|
||||
class="rounded-sm bg-transparent font-mono text-caption text-fg-muted outline-none focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring"
|
||||
:disabled="disabled"
|
||||
@change="emitChange"
|
||||
>
|
||||
|
||||
@@ -15,7 +15,7 @@ const delegatedProps = reactiveOmit(props, "class");
|
||||
<template>
|
||||
<TabsContent
|
||||
data-slot="tabs-content"
|
||||
:class="cn('text-label flex-1 outline-none', props.class)"
|
||||
:class="cn('text-label flex-1 rounded-md outline-none focus-visible:ring-3 focus-visible:ring-ring', props.class)"
|
||||
v-bind="delegatedProps"
|
||||
>
|
||||
<slot />
|
||||
|
||||
Reference in new issue
Block a user