-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathAccessibilityOverlay.test.ts
More file actions
201 lines (188 loc) · 5.98 KB
/
Copy pathAccessibilityOverlay.test.ts
File metadata and controls
201 lines (188 loc) · 5.98 KB
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
import { describe, expect, it } from "vitest";
import { createElement } from "react";
import { renderToStaticMarkup } from "react-dom/server";
import {
AccessibilityOverlay,
accessibilityDomTagName,
} from "./AccessibilityOverlay";
import type { AccessibilityNode } from "../../api/types";
describe("accessibilityDomTagName", () => {
it("uses source and component names for annotator-friendly custom tags", () => {
expect(
accessibilityDomTagName({
source: "nativescript",
type: "TabItem",
}),
).toBe("simdeck-tab-item");
expect(
accessibilityDomTagName({
source: "nativescript",
type: "Label",
}),
).toBe("simdeck-label");
expect(
accessibilityDomTagName({
source: "react-native",
type: "RangeAndFilterBar",
}),
).toBe("simdeck-range-and-filter-bar");
});
});
describe("AccessibilityOverlay", () => {
it("does not attach browser-native hover tooltips to selection nodes", () => {
const markup = renderToStaticMarkup(
createElement(AccessibilityOverlay, {
hoveredId: null,
roots: [
{
frame: { height: 844, width: 390, x: 0, y: 0 },
role: "application",
children: [
{
AXLabel: "Continue",
frame: { height: 48, width: 180, x: 105, y: 720 },
type: "Button",
},
],
},
],
selectedId: "",
}),
);
expect(markup).toContain('aria-label="SimDeck accessibility element');
expect(markup).not.toContain(" title=");
});
it("marks overlay nodes as app representations without bare disabled wording", () => {
const markup = renderToStaticMarkup(
createElement(AccessibilityOverlay, {
hoveredId: null,
roots: [
{
frame: { height: 844, width: 390, x: 0, y: 0 },
role: "application",
children: [
{
AXLabel: "Upgrade",
enabled: false,
frame: { height: 48, width: 180, x: 105, y: 720 },
nativeScript: {
testID: "upgrade-button",
type: "Button",
},
source: "nativescript",
sourceLocation: {
file: "/Users/dj/Developer/app/src/app.component.ts",
line: 12,
column: 8,
},
type: "Button",
},
],
},
],
selectedId: "",
}),
);
expect(markup).toContain(
'data-simdeck-overlay-node="accessibility-representation"',
);
expect(markup).toContain(
"SimDeck overlay node representing a simulator app element",
);
expect(markup).toContain('data-test-id="upgrade-button"');
expect(markup).toContain(
'data-simdeck-accessibility-source-location="/Users/dj/Developer/app/src/app.component.ts:12:8"',
);
expect(markup).toContain("simulator accessibility state enabled=false");
expect(markup).not.toContain(">disabled<");
expect(markup).not.toContain("; disabled");
expect(markup).not.toContain(" title=");
});
it("tolerates non-string accessibility metadata", () => {
const markup = renderToStaticMarkup(
createElement(AccessibilityOverlay, {
hoveredId: null,
roots: [
{
frame: { height: 844, width: 390, x: 0, y: 0 },
role: "application",
children: [
{
AXValue: 42,
frame: { height: 48, width: 180, x: 105, y: 720 },
placeholder: { text: "Email" },
sourceFile: null,
type: "TextField",
} as unknown as AccessibilityNode,
],
},
],
selectedId: "",
}),
);
expect(markup).toContain('data-simdeck-accessibility-value="42"');
expect(markup).toContain('data-simdeck-accessibility-label="42"');
});
it("draws label-free skeleton frames when requested", () => {
const markup = renderToStaticMarkup(
createElement(AccessibilityOverlay, {
hoveredId: null,
roots: [
{
frame: { height: 844, width: 390, x: 0, y: 0 },
role: "application",
children: [
{
AXLabel: "Continue",
frame: { height: 48, width: 180, x: 105, y: 720 },
type: "Button",
},
],
},
],
selectedId: "",
skeletonVisible: true,
}),
);
expect(markup).toContain("accessibility-rect skeleton");
expect(markup).not.toContain("<span>Continue</span>");
});
it("converts display-space frames into natural space for a rotated landscape display", () => {
// Landscape display (1210x834). The child is the right half of the display
// in display space; after the shell's 270deg rotation it must land in the
// bottom half of the natural (portrait) presentation box.
const roots = [
{
frame: { height: 834, width: 1210, x: 0, y: 0 },
role: "application",
children: [
{
AXLabel: "RightHalf",
frame: { height: 834, width: 605, x: 605, y: 0 },
type: "Button",
},
],
},
];
const rotated = renderToStaticMarkup(
createElement(AccessibilityOverlay, {
hoveredId: null,
roots,
rotationQuarterTurns: 3,
selectedId: "",
}),
);
// display right-half -> natural bottom-half.
expect(rotated).toContain("height:50%;left:0%;top:50%;width:100%");
const unrotated = renderToStaticMarkup(
createElement(AccessibilityOverlay, {
hoveredId: null,
roots,
rotationQuarterTurns: 0,
selectedId: "",
}),
);
// With no rotation the frame keeps its display-space placement (right half).
expect(unrotated).toContain("height:100%;left:50%;top:0%;width:50%");
});
});