54 lines
3.5 KiB
JavaScript
54 lines
3.5 KiB
JavaScript
// 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.
|
|
const assert = require('node:assert/strict');
|
|
|
|
module.exports = async ({ page, go, shot, settled }) => {
|
|
await page.setViewportSize({ width: 390, height: 844 });
|
|
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 settled();
|
|
const bounds = await dialog.boundingBox();
|
|
assert.ok(bounds.y >= 0 && bounds.y + bounds.height <= 844, '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 <= 844, '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 <= 844, '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.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();
|
|
await page.getByRole('option', { name: 'Events', 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', 'palette navigation did not focus main');
|
|
// The conversation panel is only open on some entries to this page; the
|
|
// focus check below needs it closed either way.
|
|
const hide = page.getByRole('button', { name: 'Hide conversation', exact: true });
|
|
if (await hide.count()) await hide.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');
|
|
};
|