Files
archie/e2e/checks/accessibility.cjs
T

69 lines
4.2 KiB
JavaScript

const assert = require('node:assert/strict');
module.exports = async ({ page, go, shot }) => {
await page.setViewportSize({ width: 360, height: 700 });
await go('/tasks');
await page.getByRole('button', { name: 'Jump to', exact: true }).click();
await page.getByRole('option', { name: 'New task', exact: true }).click();
const dialog = page.getByRole('dialog');
await dialog.waitFor();
await page.waitForTimeout(200);
const bounds = await dialog.boundingBox();
assert.ok(bounds.y >= 0 && bounds.y + bounds.height <= 700, 'New task dialog extends outside viewport');
await shot('phone-task-dialog-top');
const start = dialog.getByRole('button', { name: 'Start task', exact: true });
await start.scrollIntoViewIfNeeded();
const button = await start.boundingBox();
assert.ok(button.y >= 0 && button.y + button.height <= 700, 'Start task cannot be reached by scrolling');
await shot('phone-task-dialog');
const close = dialog.getByRole('button', { name: 'Close', exact: true });
await dialog.getByRole('button', { name: 'Cancel', exact: true }).focus();
await page.keyboard.press('Tab');
assert.ok(await close.evaluate(el => el === document.activeElement), 'Close is missing from keyboard tab order');
const closeBounds = await close.boundingBox();
assert.ok(closeBounds.y >= 0 && closeBounds.y + closeBounds.height <= 700, 'Close cannot be reached by keyboard');
await page.keyboard.press('Escape');
for (const [path, title] of [['/tasks', 'Tasks'], ['/events', 'Events'], ['/account', 'Your account'], ['/settings/models', 'Models | Instance'], ['/org/models', 'Models | Organisation']]) {
await go(path);
assert.equal(await page.title(), `${title} | Archie`);
}
await page.keyboard.press('Tab');
const skip = page.getByRole('link', { name: 'Skip to main content', exact: true });
assert.ok(await skip.evaluate(el => el === document.activeElement), 'Skip link is not the first keyboard stop');
await page.keyboard.press('Enter');
assert.equal(await page.evaluate(() => document.activeElement?.id), 'main-content');
await page.getByRole('button', { name: 'Sections', exact: true }).click();
await page.getByRole('navigation', { name: 'Sections', exact: true }).getByRole('link', { name: 'Tasks', exact: true }).click();
await page.waitForTimeout(300);
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();
await page.getByRole('option', { name: 'Events', exact: true }).click();
await page.waitForTimeout(300);
assert.equal(await page.evaluate(() => document.activeElement?.id), 'main-content', 'palette navigation did not focus main');
await page.getByRole('button', { name: 'Chat with Archie', exact: true }).click();
const composer = page.getByRole('textbox', { name: 'Message Archie', exact: true });
await composer.fill('Composition in progress');
const sent = [];
await page.route('**/api/chat/stream', async route => {
sent.push(route.request().postDataJSON().text);
await route.fulfill({ contentType: 'text/event-stream', body: 'data: {"type":"done","text":"Test response"}\n\n' });
});
for (const event of [{ isComposing: true }, { keyCode: 229 }]) {
await composer.dispatchEvent('keydown', { key: 'Enter', bubbles: true, cancelable: true, ...event });
assert.equal(await composer.inputValue(), 'Composition in progress', 'IME confirmation submitted the draft');
}
assert.equal(sent.length, 0);
await composer.press('Shift+Enter');
assert.ok((await composer.inputValue()).includes('\n'), 'Shift+Enter no longer inserts a newline');
await composer.fill('Ordinary Enter submits');
const request = page.waitForRequest('**/api/chat/stream');
await composer.press('Enter');
assert.equal((await request).postDataJSON().text, 'Ordinary Enter submits');
assert.equal(await composer.inputValue(), '');
await shot('chat-composition');
await page.getByRole('button', { name: 'Close chat', exact: true }).click();
const tab = page.getByRole('tab', { name: /^Map/ });
await tab.click();
assert.ok(await tab.evaluate(el => el === document.activeElement), 'query-only navigation stole focus');
};