Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
name: VoiceOver
name: Screen Reader

on:
schedule:
- cron: "0 4 * * *"
workflow_dispatch:
pull_request:
paths:
- ".github/setup/**"
- ".github/workflows/voiceover.yml"
- "e2e/**"
- ".github/workflows/screen-reader.yml"
- "e2e/screen-reader.spec.ts"
- "package.json"
- "playwright.voiceover.config.ts"
- "playwright.screen-reader.config.ts"
- "pnpm-lock.yaml"
- "src/app/bases/**"
- "src/app/data-grid/lib/seeds.ts"
Expand All @@ -31,12 +29,11 @@ permissions:

env:
FORCE_COLOR: 3
GUIDEPUP_SETUP: "@guidepup/setup@0.29.3"

jobs:
voiceover:
runs-on: macos-latest
name: VoiceOver
nvda:
name: Screen Reader (Windows / NVDA)
runs-on: windows-2025
timeout-minutes: 30
env:
DATABASE_URL: postgresql://tablecn:securepassword@localhost:5432/tablecn
Expand All @@ -45,29 +42,16 @@ jobs:
uses: actions/checkout@v7
- uses: ./.github/setup

- name: Set up VoiceOver
run: npx -y "$GUIDEPUP_SETUP" setup --ci

- name: Turn off hot corners
run: |
for corner in tl tr bl br; do
defaults write com.apple.dock "wvous-$corner-corner" -int 0
done
killall Dock

- name: Install VoiceOver assets
run: npx -y "$GUIDEPUP_SETUP" install voiceover

- name: Install Playwright
run: pnpm exec playwright install chromium
- name: Install NVDA
run: pnpm test:screen-reader:install

- name: Test
run: pnpm test:voiceover
run: pnpm test:screen-reader

- name: Upload spoken phrase logs
if: ${{ failure() }}
uses: actions/upload-artifact@v7
with:
name: voiceover-spoken-phrase-logs
name: screen-reader-spoken-phrase-logs
path: test-results/
retention-days: 14
158 changes: 65 additions & 93 deletions e2e/voiceover.spec.ts → e2e/screen-reader.spec.ts
Original file line number Diff line number Diff line change
@@ -1,48 +1,49 @@
import { voiceOverTest as test } from "@guidepup/playwright";
import {
type ScreenReaderPlaywright,
screenReaderTest as test,
} from "@guidepup/playwright";
import { expect, type Page } from "@playwright/test";
import { execFile } from "node:child_process";
import fs from "node:fs/promises";
import { promisify } from "node:util";

const QUIET_MS = 2500;
const MAX_LISTEN_MS = 15_000;

const LAST_PHRASE_SCRIPT = `tell application "VoiceOver"
with transaction
return content of last phrase
end transaction
end tell`;

test.describe("data table", () => {
test.beforeEach(async ({ page, voiceOver }) => {
test.beforeEach(async ({ page, screenReader }) => {
await page.goto("/bases/radix?view=table", { timeout: 120_000 });
await expect(page.locator("table tbody tr").first()).toBeVisible({
timeout: 60_000,
});
await voiceOver.navigateToWebContent();
await screenReader.navigateToWebContent();
});

test("speaks one result count after typing a search", async ({ page }) => {
const spoken = await listen("search", () =>
page
.getByPlaceholder("Search tasks...")
.pressSequentially("pixel", { delay: 150 }),
);
test("speaks one result count after typing a search", async ({
page,
screenReader,
}) => {
const search = page.getByPlaceholder("Search tasks...");
await search.focus();

const spoken = await listen(screenReader, "search", async () => {
await search.pressSequentially("pixel", { delay: 150 });
await expect(resultStatus(page)).toHaveText("7 results");
});

expectSpokenOnce(spoken, "7 results");
expect(spoken).not.toMatch(/\b(?!7 )\d+ results?\b/);
});

test("speaks the page after moving to the next page", async ({ page }) => {
const spoken = await listen("next page", () =>
page.getByRole("button", { name: "Go to next page" }).click(),
);
test("speaks the page after moving to the next page", async ({
page,
screenReader,
}) => {
const spoken = await listen(screenReader, "next page", async () => {
await page.getByRole("button", { name: "Go to next page" }).click();
await expect(resultStatus(page)).toHaveText("100 results, page 2 of 10");
});

expectSpokenOnce(spoken, "100 results, page 2 of 10");
});

test("speaks the selection count once", async ({ page }) => {
const spoken = await listen("select row", () =>
test("speaks the selection count once", async ({ page, screenReader }) => {
const spoken = await listen(screenReader, "select row", () =>
page.locator("tbody [role=checkbox]").first().click(),
);

Expand All @@ -51,92 +52,102 @@ test.describe("data table", () => {
});

test.describe("data grid", () => {
test.beforeEach(async ({ page, voiceOver }) => {
test.beforeEach(async ({ page, screenReader }) => {
await page.goto("/bases/radix?view=grid", { timeout: 120_000 });
await expect(
page.locator("[role=grid] [role=gridcell][aria-colindex]").first(),
).toBeVisible({ timeout: 60_000 });
await voiceOver.navigateToWebContent();
await screenReader.navigateToWebContent();
});

test("speaks a sort and a row selection once each", async ({ page }) => {
test("speaks a sort and a row selection once each", async ({
page,
screenReader,
}) => {
const grid = page.getByRole("grid");
await grid
.getByRole("columnheader", { name: "Name" })
.getByRole("button")
.click();

const sorted = await listen("sort", () =>
const sorted = await listen(screenReader, "sort", () =>
page.getByRole("menuitemcheckbox", { name: "Sort ascending" }).click(),
);
expectSpokenOnce(sorted, "Sorted by Name, ascending");

const selected = await listen("select row", () =>
const selected = await listen(screenReader, "select row", () =>
grid.getByRole("gridcell", { name: "Select row 1", exact: true }).click(),
);
expectSpokenOnce(selected, "Row 1 selected");
});

test("speaks an edit, its undo and its redo without the toast", async ({
page,
screenReader,
}) => {
await listen("focus cell", () => bodyCell(page, 2, 2).click());
await bodyCell(page, 2, 2).click();

const edited = await listen("edit", async () => {
const edited = await listen(screenReader, "edit", async () => {
await page.keyboard.press("Enter");
await page.keyboard.press("ControlOrMeta+a");
await page.keyboard.type("Edited");
await page.keyboard.press("Enter");
});
expectSpokenOnce(edited, "Name updated");

const undone = await listen("undo", async () => {
const undone = await listen(screenReader, "undo", async () => {
await page.keyboard.press("ControlOrMeta+z");
await expect(toast(page)).toHaveText("Action undone");
});
expectSpokenOnce(undone, "Undo: Name updated");
expect(undone).not.toContain("Action undone");

const redone = await listen("redo", async () => {
const redone = await listen(screenReader, "redo", async () => {
await page.keyboard.press("ControlOrMeta+Shift+z");
await expect(toast(page)).toHaveText("Action redone");
});
expectSpokenOnce(redone, "Redo: Name updated");
expect(redone).not.toContain("Action redone");
});

test("speaks a paste once", async ({ page, context }) => {
test("speaks a paste once", async ({ page, context, screenReader }) => {
await context.grantPermissions(["clipboard-read", "clipboard-write"]);
await listen("focus cell", () => bodyCell(page, 2, 2).click());
await bodyCell(page, 2, 2).click();
await page.evaluate(() =>
navigator.clipboard.writeText("Ada Lovelace\t36\nGrace Hopper\t85"),
);

const pasted = await listen("paste", async () => {
const pasted = await listen(screenReader, "paste", async () => {
await page.keyboard.press("ControlOrMeta+v");
await expect(toast(page)).toHaveText("4 cells pasted");
});
// The toast repeats this text, and VoiceOver's last phrase can't tell two identical phrases apart.
expectSpokenOnce(pasted, "4 cells pasted");
});

test("speaks the cell when moving between cells", async ({ page }) => {
await listen("focus cell", () => bodyCell(page, 2, 2).click());
test("speaks the cell when moving between cells", async ({
page,
screenReader,
}) => {
await bodyCell(page, 2, 2).click();

const down = await listen("arrow down", () =>
const down = await listen(screenReader, "arrow down", () =>
page.keyboard.press("ArrowDown"),
);
await expect(bodyCell(page, 3, 2)).toBeFocused();
expect(down).toContain(await cellText(page, 3, 2));

const right = await listen("arrow right", () =>
const right = await listen(screenReader, "arrow right", () =>
page.keyboard.press("ArrowRight"),
);
await expect(bodyCell(page, 3, 3)).toBeFocused();
expect(right).toContain(await cellText(page, 3, 3));
});
});

function resultStatus(page: Page) {
return page.locator("[data-slot=data-table] > [role=status]");
}

function bodyCell(page: Page, row: number, col: number) {
return page.locator(
`[role=grid] [role=row][aria-rowindex='${row}'] [role=gridcell][aria-colindex='${col}']`,
Expand All @@ -151,58 +162,19 @@ function toast(page: Page) {
return page.locator("[data-sonner-toast]").first();
}

// Guidepup polls after each action and sleeps while a long phrase is spoken,
// so it misses a short announcement that VoiceOver speaks right after focus moves.
async function listen(label: string, action: () => Promise<unknown>) {
const phrases: string[] = [];
let last = await readLastPhrase();
const acting = new AbortController();
let lastChange = Date.now();
const startedAt = Date.now();

const polling = (async () => {
while (
(!acting.signal.aborted || Date.now() - lastChange < QUIET_MS) &&
Date.now() - startedAt < MAX_LISTEN_MS
) {
const phrase = await readLastPhrase();
if (phrase && phrase !== last) {
phrases.push(phrase);
last = phrase;
lastChange = Date.now();
}
}
})();

try {
await action();
} finally {
acting.abort();
lastChange = Date.now();
await polling;
}
async function listen(
screenReader: ScreenReaderPlaywright,
label: string,
action: () => Promise<unknown>,
) {
const { spokenPhrase } = await screenReader.capture(action, {
capture: true,
});

const file = test.info().outputPath("spoken-phrase-log.jsonl");
await fs.appendFile(file, `${JSON.stringify({ label, phrases })}\n`);
console.log(`[voiceover] ${label}: ${JSON.stringify(phrases)}`);
return phrases.join(" | ");
}

const execFileAsync = promisify(execFile);

async function readLastPhrase() {
try {
const { stdout } = await execFileAsync("osascript", [
"-e",
LAST_PHRASE_SCRIPT,
]);
return stdout
.trim()
.replace(/^missing value$/, "")
.replace(/\s\s+/g, " ");
} catch {
return "";
}
await fs.appendFile(file, `${JSON.stringify({ label, spokenPhrase })}\n`);
console.log(`[screen reader] ${label}: ${JSON.stringify(spokenPhrase)}`);
return spokenPhrase;
}

function expectSpokenOnce(spoken: string, message: string) {
Expand Down
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
"test": "vitest run",
"test:e2e": "playwright test",
"test:a11y": "playwright test --project=a11y",
"test:voiceover": "playwright test -c playwright.voiceover.config.ts",
"test:screen-reader": "playwright test -c playwright.screen-reader.config.ts",
"test:screen-reader:install": "guidepup install",
"test:screen-reader:setup": "guidepup setup",
"table:record": "playwright test -c playwright.record.config.ts",
"profile:scroll": "tsx --tsconfig ./tsconfig.scripts.json scripts/profile-data-grid-scroll.ts",
"dev:docker": "pnpm db:start && pnpm dev",
Expand Down Expand Up @@ -93,6 +95,7 @@
"@faker-js/faker": "^10.6.0",
"@guidepup/guidepup": "^0.40.0",
"@guidepup/playwright": "^0.21.0",
"@guidepup/setup": "^0.29.3",
"@guidepup/virtual-screen-reader": "^0.33.0",
"@playwright/test": "^1.63.0",
"@rolldown/plugin-babel": "^0.3.0",
Expand Down
2 changes: 1 addition & 1 deletion playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export default defineConfig({
testIgnore: [
"**/record-data-table-launch.spec.ts",
"**/a11y.spec.ts",
"**/voiceover.spec.ts",
"**/screen-reader.spec.ts",
],
use: { ...devices["Desktop Chrome"] },
},
Expand Down
Loading
Loading