-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.test.ts
123 lines (104 loc) · 3.71 KB
/
index.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
import * as playwright from "playwright";
import {
awaitNvdaRecording,
createJestSpeechRecorder,
extendExpect,
} from "screen-reader-testing-library";
import type {} from "screen-reader-testing-library/matcherTypes";
const logFilePath = process.env.LOG_FILE_PATH;
extendExpect(expect, logFilePath!);
describe("chromium", () => {
const speechRecorder = createJestSpeechRecorder(logFilePath!);
let browser: playwright.Browser;
let page: playwright.Page;
beforeAll(async () => {
browser = await playwright.chromium.launch({ headless: false });
});
afterAll(async () => {
await browser.close();
});
beforeEach(async () => {
page = await browser.newPage();
});
afterEach(async () => {
await page.close();
});
it("matches the NVDA speech inline snapshot when searching the docs", async () => {
// Opening a new page with the same URL would trigger NVDA's focus caching.
// https://stackoverflow.com/questions/22517242/how-to-prevent-nvda-setting-focus-automatically-on-last-used-html-element
// We keep tests isolated by adding a random string to the URL that does not affect the page.
await page.goto(
"https://5f6a0f0de73ecc00085cbbe4--material-ui.netlify.app/?nvda-test-3"
);
// Without bringing it to front the adress bar will still be focused.
// NVDA wouldn't record any page actions
await page.bringToFront();
await awaitNvdaRecording();
await expect(async () => {
await page.keyboard.press("s");
}).toMatchSpeechInlineSnapshot(`
"banner landmark"
"Search, combo box, expanded, has auto complete, editable, Search…, blank"
`);
await expect(async () => {
await page.keyboard.type("Rating");
}).toMatchSpeechInlineSnapshot(``);
await expect(async () => {
await page.keyboard.press("ArrowDown");
}).toMatchSpeechInlineSnapshot(`
"list"
"Link to the result, 1 of 5"
`);
}, 20000);
it("matches the NVDA speech snapshot when searching the docs", async () => {
// Opening a new page with the same URL would trigger NVDA's focus caching.
// https://stackoverflow.com/questions/22517242/how-to-prevent-nvda-setting-focus-automatically-on-last-used-html-element
// We keep tests isolated by adding a random string to the URL that does not affect the page.
await page.goto(
"https://5f6a0f0de73ecc00085cbbe4--material-ui.netlify.app/?nvda-test-2"
);
// Without bringing it to front the adress bar will still be focused.
// NVDA wouldn't record any page actions
await page.bringToFront();
await awaitNvdaRecording();
await expect(async () => {
await page.keyboard.press("s");
}).toMatchSpeechSnapshot("Focused searchbox");
await expect(async () => {
await page.keyboard.type("Rating");
}).toMatchSpeechSnapshot("entered searchterm");
await expect(async () => {
await page.keyboard.press("ArrowDown");
}).toMatchSpeechSnapshot("navigated to first result");
}, 20000);
// Example for manually authored expectations
it("produces the expected NVDA speech output when searching the docs", async () => {
await page.goto(
"https://5f6a0f0de73ecc00085cbbe4--material-ui.netlify.app/"
);
// Without bringing it to front the adress bar will still be focused.
// NVDA wouldn't record any page actions
await page.bringToFront();
await awaitNvdaRecording();
await expect(async () => {
await page.keyboard.press("s");
}).toAnnounceNVDA([
["banner landmark"],
[
"Search",
"combo box",
"expanded",
"has auto complete",
"editable",
"Search…",
"blank",
],
]);
await expect(async () => {
await page.keyboard.type("Rating");
}).toAnnounceNVDA([]);
await expect(async () => {
await page.keyboard.press("ArrowDown");
}).toAnnounceNVDA([["list"], ["Link to the result", "1 of 5"]]);
}, 20000);
});