@instructure/ui-a11y-utils 10.19.2-snapshot-2 → 10.19.2-snapshot-4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +1 -1
- package/package.json +9 -9
- package/tsconfig.build.tsbuildinfo +1 -1
- package/es/__new-tests__/FocusRegionManager.test.js +0 -208
- package/es/__new-tests__/ScreenReaderFocusRegion.test.js +0 -226
- package/es/__new-tests__/hasVisibleChildren.test.js +0 -41
- package/es/__new-tests__/scopeTab.test.js +0 -90
- package/lib/__new-tests__/FocusRegionManager.test.js +0 -209
- package/lib/__new-tests__/ScreenReaderFocusRegion.test.js +0 -227
- package/lib/__new-tests__/hasVisibleChildren.test.js +0 -42
- package/lib/__new-tests__/scopeTab.test.js +0 -91
- package/src/__new-tests__/FocusRegionManager.test.tsx +0 -151
- package/src/__new-tests__/ScreenReaderFocusRegion.test.tsx +0 -238
- package/src/__new-tests__/hasVisibleChildren.test.tsx +0 -39
- package/src/__new-tests__/scopeTab.test.tsx +0 -104
- package/types/__new-tests__/FocusRegionManager.test.d.ts +0 -2
- package/types/__new-tests__/FocusRegionManager.test.d.ts.map +0 -1
- package/types/__new-tests__/ScreenReaderFocusRegion.test.d.ts +0 -2
- package/types/__new-tests__/ScreenReaderFocusRegion.test.d.ts.map +0 -1
- package/types/__new-tests__/hasVisibleChildren.test.d.ts +0 -2
- package/types/__new-tests__/hasVisibleChildren.test.d.ts.map +0 -1
- package/types/__new-tests__/scopeTab.test.d.ts +0 -2
- package/types/__new-tests__/scopeTab.test.d.ts.map +0 -1
|
@@ -1,151 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* The MIT License (MIT)
|
|
3
|
-
*
|
|
4
|
-
* Copyright (c) 2015 - present Instructure, Inc.
|
|
5
|
-
*
|
|
6
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
-
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
-
* in the Software without restriction, including without limitation the rights
|
|
9
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
-
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
-
* furnished to do so, subject to the following conditions:
|
|
12
|
-
*
|
|
13
|
-
* The above copyright notice and this permission notice shall be included in all
|
|
14
|
-
* copies or substantial portions of the Software.
|
|
15
|
-
*
|
|
16
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
-
* SOFTWARE.
|
|
23
|
-
*/
|
|
24
|
-
|
|
25
|
-
import { render, screen, waitFor } from '@testing-library/react'
|
|
26
|
-
import '@testing-library/jest-dom'
|
|
27
|
-
|
|
28
|
-
import { FocusRegionManager } from '../FocusRegionManager'
|
|
29
|
-
|
|
30
|
-
describe('FocusRegionManager', () => {
|
|
31
|
-
beforeEach(async () => {
|
|
32
|
-
FocusRegionManager.clearEntries()
|
|
33
|
-
})
|
|
34
|
-
|
|
35
|
-
it('should focus the first tabbable element when focused', async () => {
|
|
36
|
-
render(
|
|
37
|
-
<div data-test-parent role="main" aria-label="test app" id="test-parent3">
|
|
38
|
-
<div data-test-ignore role="alert">
|
|
39
|
-
<span>test alert</span>
|
|
40
|
-
</div>
|
|
41
|
-
<div data-test-child>
|
|
42
|
-
<div data-test-descendant></div>
|
|
43
|
-
<div data-test-descendant>
|
|
44
|
-
<div data-test-descendant>
|
|
45
|
-
<button data-testid="button">click me</button>
|
|
46
|
-
</div>
|
|
47
|
-
</div>
|
|
48
|
-
</div>
|
|
49
|
-
<div data-test-parent aria-hidden="true" id="test-parent2">
|
|
50
|
-
<div data-test-child></div>
|
|
51
|
-
<div
|
|
52
|
-
role="dialog"
|
|
53
|
-
aria-label="some content"
|
|
54
|
-
data-test-parent
|
|
55
|
-
id="test-parent1"
|
|
56
|
-
>
|
|
57
|
-
<div data-testid="content">
|
|
58
|
-
<div>Hello world</div>
|
|
59
|
-
<button data-testid="first-tabbable">click me</button>
|
|
60
|
-
<button>or click me</button>
|
|
61
|
-
</div>
|
|
62
|
-
<span data-test-child>
|
|
63
|
-
<ul data-test-descendant>
|
|
64
|
-
<li data-test-descendant>item 1</li>
|
|
65
|
-
<li data-test-descendant>item 2</li>
|
|
66
|
-
<li data-test-descendant>item 3</li>
|
|
67
|
-
</ul>
|
|
68
|
-
</span>
|
|
69
|
-
</div>
|
|
70
|
-
</div>
|
|
71
|
-
<div data-test-child aria-hidden="true">
|
|
72
|
-
<div data-test-descendant></div>
|
|
73
|
-
<div data-test-descendant></div>
|
|
74
|
-
</div>
|
|
75
|
-
<iframe id="frame" title="frame"></iframe>
|
|
76
|
-
</div>
|
|
77
|
-
)
|
|
78
|
-
|
|
79
|
-
const button = screen.getByTestId('button')
|
|
80
|
-
const content = screen.getByTestId('content')
|
|
81
|
-
const firstTabbable = screen.getByTestId('first-tabbable')
|
|
82
|
-
|
|
83
|
-
button.focus()
|
|
84
|
-
|
|
85
|
-
expect(document.activeElement).toBe(button)
|
|
86
|
-
|
|
87
|
-
FocusRegionManager.focusRegion(content)
|
|
88
|
-
|
|
89
|
-
await waitFor(() => {
|
|
90
|
-
expect(document.activeElement).toBe(firstTabbable)
|
|
91
|
-
})
|
|
92
|
-
})
|
|
93
|
-
|
|
94
|
-
it('should return focus when blurred', async () => {
|
|
95
|
-
render(
|
|
96
|
-
<div data-test-parent role="main" aria-label="test app" id="test-parent3">
|
|
97
|
-
<div data-test-ignore role="alert">
|
|
98
|
-
<span>test alert</span>
|
|
99
|
-
</div>
|
|
100
|
-
<div data-test-child>
|
|
101
|
-
<div data-test-descendant></div>
|
|
102
|
-
<div data-test-descendant>
|
|
103
|
-
<div data-test-descendant>
|
|
104
|
-
<button data-testid="button">click me</button>
|
|
105
|
-
</div>
|
|
106
|
-
</div>
|
|
107
|
-
</div>
|
|
108
|
-
<div data-test-parent aria-hidden="true" id="test-parent2">
|
|
109
|
-
<div data-test-child></div>
|
|
110
|
-
<div
|
|
111
|
-
role="dialog"
|
|
112
|
-
aria-label="some content"
|
|
113
|
-
data-test-parent
|
|
114
|
-
id="test-parent1"
|
|
115
|
-
>
|
|
116
|
-
<div data-testid="content">
|
|
117
|
-
<div>Hello world</div>
|
|
118
|
-
<button data-test-first-tabbable>click me</button>
|
|
119
|
-
<button>or click me</button>
|
|
120
|
-
</div>
|
|
121
|
-
<span data-test-child>
|
|
122
|
-
<ul data-test-descendant>
|
|
123
|
-
<li data-test-descendant>item 1</li>
|
|
124
|
-
<li data-test-descendant>item 2</li>
|
|
125
|
-
<li data-test-descendant>item 3</li>
|
|
126
|
-
</ul>
|
|
127
|
-
</span>
|
|
128
|
-
</div>
|
|
129
|
-
</div>
|
|
130
|
-
<div data-test-child aria-hidden="true">
|
|
131
|
-
<div data-test-descendant></div>
|
|
132
|
-
<div data-test-descendant></div>
|
|
133
|
-
</div>
|
|
134
|
-
<iframe id="frame" title="frame"></iframe>
|
|
135
|
-
</div>
|
|
136
|
-
)
|
|
137
|
-
const button = screen.getByTestId('button')
|
|
138
|
-
const content = screen.getByTestId('content')
|
|
139
|
-
|
|
140
|
-
button.focus()
|
|
141
|
-
|
|
142
|
-
expect(document.activeElement).toBe(button)
|
|
143
|
-
|
|
144
|
-
FocusRegionManager.focusRegion(content)
|
|
145
|
-
FocusRegionManager.blurRegion(content)
|
|
146
|
-
|
|
147
|
-
await waitFor(() => {
|
|
148
|
-
expect(document.activeElement).toBe(button)
|
|
149
|
-
})
|
|
150
|
-
})
|
|
151
|
-
})
|
|
@@ -1,238 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* The MIT License (MIT)
|
|
3
|
-
*
|
|
4
|
-
* Copyright (c) 2015 - present Instructure, Inc.
|
|
5
|
-
*
|
|
6
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
-
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
-
* in the Software without restriction, including without limitation the rights
|
|
9
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
-
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
-
* furnished to do so, subject to the following conditions:
|
|
12
|
-
*
|
|
13
|
-
* The above copyright notice and this permission notice shall be included in all
|
|
14
|
-
* copies or substantial portions of the Software.
|
|
15
|
-
*
|
|
16
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
-
* SOFTWARE.
|
|
23
|
-
*/
|
|
24
|
-
|
|
25
|
-
import { render, screen, waitFor } from '@testing-library/react'
|
|
26
|
-
import '@testing-library/jest-dom'
|
|
27
|
-
|
|
28
|
-
import { ScreenReaderFocusRegion } from '../ScreenReaderFocusRegion'
|
|
29
|
-
|
|
30
|
-
describe('ScreenReaderFocusRegion', () => {
|
|
31
|
-
const element = (
|
|
32
|
-
<div
|
|
33
|
-
data-testid="parent"
|
|
34
|
-
role="main"
|
|
35
|
-
aria-label="test app"
|
|
36
|
-
id="test-parent3"
|
|
37
|
-
>
|
|
38
|
-
<div data-testid="ignore" role="alert">
|
|
39
|
-
<span>test alert</span>
|
|
40
|
-
</div>
|
|
41
|
-
<div data-testid="child">
|
|
42
|
-
<div data-testid="descendant">foo</div>
|
|
43
|
-
<div data-testid="descendant">
|
|
44
|
-
<div data-testid="descendant">bar</div>
|
|
45
|
-
</div>
|
|
46
|
-
</div>
|
|
47
|
-
<div data-testid="parent" aria-hidden="true" id="test-parent2">
|
|
48
|
-
<div data-testid="child"></div>
|
|
49
|
-
<div
|
|
50
|
-
role="dialog"
|
|
51
|
-
aria-label="some content"
|
|
52
|
-
data-testid="parent"
|
|
53
|
-
id="test-parent1"
|
|
54
|
-
>
|
|
55
|
-
<div data-testid="content">
|
|
56
|
-
<div>Hello world</div>
|
|
57
|
-
<button>click me</button>
|
|
58
|
-
<button>or click me</button>
|
|
59
|
-
</div>
|
|
60
|
-
<span data-testid="child">
|
|
61
|
-
<ul data-testid="descendant">
|
|
62
|
-
<li data-testid="descendant">item 1</li>
|
|
63
|
-
<li data-testid="descendant">item 2</li>
|
|
64
|
-
<li data-testid="descendant">item 3</li>
|
|
65
|
-
</ul>
|
|
66
|
-
</span>
|
|
67
|
-
</div>
|
|
68
|
-
</div>
|
|
69
|
-
<div data-testid="child-initial-hidden" aria-hidden="true">
|
|
70
|
-
<div data-testid="descendant">foo</div>
|
|
71
|
-
<div data-testid="descendant">bar</div>
|
|
72
|
-
</div>
|
|
73
|
-
</div>
|
|
74
|
-
)
|
|
75
|
-
|
|
76
|
-
it('should accept a function for liveRegion', async () => {
|
|
77
|
-
render(element)
|
|
78
|
-
|
|
79
|
-
const ignore = screen.getByTestId('ignore')
|
|
80
|
-
const content = screen.getByTestId('content')
|
|
81
|
-
|
|
82
|
-
const screenReaderFocusRegion = new ScreenReaderFocusRegion(content, {
|
|
83
|
-
liveRegion: () => ignore,
|
|
84
|
-
shouldContainFocus: true
|
|
85
|
-
})
|
|
86
|
-
|
|
87
|
-
screenReaderFocusRegion.activate()
|
|
88
|
-
|
|
89
|
-
await waitFor(() => {
|
|
90
|
-
expect(ignore).not.toHaveAttribute('aria-hidden')
|
|
91
|
-
})
|
|
92
|
-
})
|
|
93
|
-
|
|
94
|
-
it("should apply aria-hidden to all children of content's parent nodes unless they are live regions", async () => {
|
|
95
|
-
render(element)
|
|
96
|
-
|
|
97
|
-
const ignore = screen.getByTestId('ignore')
|
|
98
|
-
const content = screen.getByTestId('content')
|
|
99
|
-
const children = screen.getAllByTestId('child')
|
|
100
|
-
|
|
101
|
-
const screenReaderFocusRegion = new ScreenReaderFocusRegion(content, {
|
|
102
|
-
liveRegion: ignore,
|
|
103
|
-
shouldContainFocus: true
|
|
104
|
-
})
|
|
105
|
-
|
|
106
|
-
screenReaderFocusRegion.activate()
|
|
107
|
-
|
|
108
|
-
children.forEach((node) => {
|
|
109
|
-
expect(node).toHaveAttribute('aria-hidden')
|
|
110
|
-
})
|
|
111
|
-
|
|
112
|
-
expect(ignore).not.toHaveAttribute('aria-hidden')
|
|
113
|
-
})
|
|
114
|
-
|
|
115
|
-
it("should mute designated attributes for content's parent nodes", async () => {
|
|
116
|
-
render(element)
|
|
117
|
-
|
|
118
|
-
const content = screen.getByTestId('content')
|
|
119
|
-
const parents = screen.getAllByTestId('parent')
|
|
120
|
-
|
|
121
|
-
const screenReaderFocusRegion = new ScreenReaderFocusRegion(content)
|
|
122
|
-
screenReaderFocusRegion.activate()
|
|
123
|
-
|
|
124
|
-
parents.forEach((node) => {
|
|
125
|
-
expect(node).not.toHaveAttribute('aria-hidden')
|
|
126
|
-
expect(node).not.toHaveAttribute('aria-label')
|
|
127
|
-
expect(node).not.toHaveAttribute('role')
|
|
128
|
-
})
|
|
129
|
-
})
|
|
130
|
-
|
|
131
|
-
it('should not apply aria-hidden to descendants', async () => {
|
|
132
|
-
render(element)
|
|
133
|
-
|
|
134
|
-
const content = screen.getByTestId('content')
|
|
135
|
-
const descendants = screen.getAllByTestId('descendant')
|
|
136
|
-
|
|
137
|
-
const screenReaderFocusRegion = new ScreenReaderFocusRegion(content)
|
|
138
|
-
screenReaderFocusRegion.activate()
|
|
139
|
-
|
|
140
|
-
descendants.forEach((node) => {
|
|
141
|
-
expect(node).not.toHaveAttribute('aria-hidden')
|
|
142
|
-
})
|
|
143
|
-
})
|
|
144
|
-
|
|
145
|
-
it('should not apply aria-hidden to dynamically added descendants of content', async () => {
|
|
146
|
-
render(element)
|
|
147
|
-
|
|
148
|
-
const content = screen.getByTestId('content')
|
|
149
|
-
const screenReaderFocusRegion = new ScreenReaderFocusRegion(content)
|
|
150
|
-
|
|
151
|
-
screenReaderFocusRegion.activate()
|
|
152
|
-
|
|
153
|
-
const desc = document.createElement('div')
|
|
154
|
-
content.appendChild(desc)
|
|
155
|
-
|
|
156
|
-
screenReaderFocusRegion.handleDOMMutation([
|
|
157
|
-
{ addedNodes: [desc], removedNodes: [] } as unknown as MutationRecord
|
|
158
|
-
])
|
|
159
|
-
|
|
160
|
-
Array.from(content.childNodes).forEach((node) => {
|
|
161
|
-
expect(node).not.toHaveAttribute('aria-hidden')
|
|
162
|
-
})
|
|
163
|
-
})
|
|
164
|
-
|
|
165
|
-
it('should remove aria-hidden from children unless they had aria-hidden before', async () => {
|
|
166
|
-
render(element)
|
|
167
|
-
|
|
168
|
-
const content = screen.getByTestId('content')
|
|
169
|
-
const screenReaderFocusRegion = new ScreenReaderFocusRegion(content)
|
|
170
|
-
|
|
171
|
-
const childNodes = screen.getAllByTestId('child')
|
|
172
|
-
const exception = screen.getByTestId('child-initial-hidden')
|
|
173
|
-
|
|
174
|
-
screenReaderFocusRegion.activate()
|
|
175
|
-
screenReaderFocusRegion.deactivate()
|
|
176
|
-
|
|
177
|
-
childNodes.forEach((node) => {
|
|
178
|
-
expect(node).not.toHaveAttribute('aria-hidden')
|
|
179
|
-
})
|
|
180
|
-
|
|
181
|
-
expect(exception).toHaveAttribute('aria-hidden')
|
|
182
|
-
})
|
|
183
|
-
|
|
184
|
-
it('should properly restore and unmute parent attributes', async () => {
|
|
185
|
-
render(element)
|
|
186
|
-
|
|
187
|
-
const content = screen.getByTestId('content')
|
|
188
|
-
const screenReaderFocusRegion = new ScreenReaderFocusRegion(content)
|
|
189
|
-
|
|
190
|
-
const parentNodes = screen.getAllByTestId('parent')
|
|
191
|
-
const attrsMap: Record<string, Attr[]> = {}
|
|
192
|
-
|
|
193
|
-
parentNodes.forEach((node) => {
|
|
194
|
-
attrsMap[node.getAttribute('id')!] = [...node.attributes]
|
|
195
|
-
})
|
|
196
|
-
|
|
197
|
-
screenReaderFocusRegion.activate()
|
|
198
|
-
screenReaderFocusRegion.deactivate()
|
|
199
|
-
|
|
200
|
-
parentNodes.forEach((node) => {
|
|
201
|
-
const preNodeAttrs = attrsMap[node.getAttribute('id')!]
|
|
202
|
-
const postNodeAttrs = [...node.attributes]
|
|
203
|
-
|
|
204
|
-
// both should have same number of attributes
|
|
205
|
-
expect(preNodeAttrs.length).toEqual(postNodeAttrs.length)
|
|
206
|
-
|
|
207
|
-
preNodeAttrs.forEach((preNodeAttribute) => {
|
|
208
|
-
const matchingAttribute = postNodeAttrs.filter(
|
|
209
|
-
(postNodeAttribute) =>
|
|
210
|
-
preNodeAttribute.name === postNodeAttribute.name
|
|
211
|
-
)[0]
|
|
212
|
-
|
|
213
|
-
expect(matchingAttribute.value).toEqual(preNodeAttribute.value)
|
|
214
|
-
})
|
|
215
|
-
})
|
|
216
|
-
})
|
|
217
|
-
|
|
218
|
-
it('should not apply aria-hidden to elements that have aria-live attributes', async () => {
|
|
219
|
-
render(
|
|
220
|
-
<div data-testid="main" role="main" aria-label="test app">
|
|
221
|
-
<div data-testid="live" aria-live="assertive"></div>
|
|
222
|
-
<div data-testid="regular"></div>
|
|
223
|
-
<div data-testid="content"></div>
|
|
224
|
-
</div>
|
|
225
|
-
)
|
|
226
|
-
|
|
227
|
-
const content = screen.getByTestId('content')
|
|
228
|
-
const screenReaderFocusRegion = new ScreenReaderFocusRegion(content)
|
|
229
|
-
|
|
230
|
-
screenReaderFocusRegion.activate()
|
|
231
|
-
|
|
232
|
-
const liveRegion = screen.getByTestId('live')
|
|
233
|
-
const regularRegion = screen.getByTestId('regular')
|
|
234
|
-
|
|
235
|
-
expect(liveRegion).not.toHaveAttribute('aria-hidden')
|
|
236
|
-
expect(regularRegion).toHaveAttribute('aria-hidden')
|
|
237
|
-
})
|
|
238
|
-
})
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* The MIT License (MIT)
|
|
3
|
-
*
|
|
4
|
-
* Copyright (c) 2015 - present Instructure, Inc.
|
|
5
|
-
*
|
|
6
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
-
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
-
* in the Software without restriction, including without limitation the rights
|
|
9
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
-
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
-
* furnished to do so, subject to the following conditions:
|
|
12
|
-
*
|
|
13
|
-
* The above copyright notice and this permission notice shall be included in all
|
|
14
|
-
* copies or substantial portions of the Software.
|
|
15
|
-
*
|
|
16
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
-
* SOFTWARE.
|
|
23
|
-
*/
|
|
24
|
-
|
|
25
|
-
import '@testing-library/jest-dom'
|
|
26
|
-
|
|
27
|
-
import { ScreenReaderContent } from '@instructure/ui-a11y-content'
|
|
28
|
-
import { hasVisibleChildren } from '../hasVisibleChildren'
|
|
29
|
-
|
|
30
|
-
describe('hasVisibleChildren', () => {
|
|
31
|
-
it('should not count ScreenReaderContent as visible content', async () => {
|
|
32
|
-
expect(
|
|
33
|
-
hasVisibleChildren(<ScreenReaderContent>Foo</ScreenReaderContent>)
|
|
34
|
-
).toBe(false)
|
|
35
|
-
})
|
|
36
|
-
it('should count everything else as visible', async () => {
|
|
37
|
-
expect(hasVisibleChildren(<div>Foo</div>)).toBe(true)
|
|
38
|
-
})
|
|
39
|
-
})
|
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* The MIT License (MIT)
|
|
3
|
-
*
|
|
4
|
-
* Copyright (c) 2015 - present Instructure, Inc.
|
|
5
|
-
*
|
|
6
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
-
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
-
* in the Software without restriction, including without limitation the rights
|
|
9
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
-
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
-
* furnished to do so, subject to the following conditions:
|
|
12
|
-
*
|
|
13
|
-
* The above copyright notice and this permission notice shall be included in all
|
|
14
|
-
* copies or substantial portions of the Software.
|
|
15
|
-
*
|
|
16
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
-
* SOFTWARE.
|
|
23
|
-
*/
|
|
24
|
-
|
|
25
|
-
import { render, screen, waitFor } from '@testing-library/react'
|
|
26
|
-
import { vi } from 'vitest'
|
|
27
|
-
import '@testing-library/jest-dom'
|
|
28
|
-
|
|
29
|
-
import { scopeTab } from '../scopeTab'
|
|
30
|
-
|
|
31
|
-
const MOCK_EVENT = new KeyboardEvent('mockEvent', { shiftKey: false })
|
|
32
|
-
MOCK_EVENT.preventDefault = () => {}
|
|
33
|
-
|
|
34
|
-
describe('scopeTab', () => {
|
|
35
|
-
it('should scope tab within container', async () => {
|
|
36
|
-
render(
|
|
37
|
-
<div>
|
|
38
|
-
<div data-testid="container">
|
|
39
|
-
<input data-testid="first" />
|
|
40
|
-
<input data-testid="second" />
|
|
41
|
-
</div>
|
|
42
|
-
</div>
|
|
43
|
-
)
|
|
44
|
-
|
|
45
|
-
const container = screen.getByTestId('container')
|
|
46
|
-
const first = screen.getByTestId('first')
|
|
47
|
-
const second = screen.getByTestId('second')
|
|
48
|
-
|
|
49
|
-
second.focus()
|
|
50
|
-
|
|
51
|
-
await waitFor(() => {
|
|
52
|
-
expect(document.activeElement).toBe(second)
|
|
53
|
-
})
|
|
54
|
-
|
|
55
|
-
scopeTab(container, MOCK_EVENT as any)
|
|
56
|
-
|
|
57
|
-
await waitFor(() => {
|
|
58
|
-
expect(document.activeElement).toBe(first)
|
|
59
|
-
})
|
|
60
|
-
})
|
|
61
|
-
|
|
62
|
-
it('should not attempt scoping when no tabbable children', async () => {
|
|
63
|
-
render(
|
|
64
|
-
<div>
|
|
65
|
-
<div data-testid="container">Hello</div>
|
|
66
|
-
<input />
|
|
67
|
-
</div>
|
|
68
|
-
)
|
|
69
|
-
|
|
70
|
-
const input = screen.getByRole('textbox')
|
|
71
|
-
const container = screen.getByTestId('container')
|
|
72
|
-
|
|
73
|
-
input.focus()
|
|
74
|
-
|
|
75
|
-
scopeTab(container, MOCK_EVENT as any)
|
|
76
|
-
|
|
77
|
-
await waitFor(() => {
|
|
78
|
-
expect(document.activeElement).toBe(input)
|
|
79
|
-
})
|
|
80
|
-
})
|
|
81
|
-
|
|
82
|
-
it('should execute callback when provided instead of default behavior', async () => {
|
|
83
|
-
const cb = vi.fn()
|
|
84
|
-
|
|
85
|
-
render(
|
|
86
|
-
<div>
|
|
87
|
-
<div data-testid="container">
|
|
88
|
-
<input />
|
|
89
|
-
</div>
|
|
90
|
-
</div>
|
|
91
|
-
)
|
|
92
|
-
|
|
93
|
-
const input = screen.getByRole('textbox')
|
|
94
|
-
const container = screen.getByTestId('container')
|
|
95
|
-
|
|
96
|
-
input.focus()
|
|
97
|
-
|
|
98
|
-
scopeTab(container, MOCK_EVENT as any, cb)
|
|
99
|
-
|
|
100
|
-
await waitFor(() => {
|
|
101
|
-
expect(cb).toHaveBeenCalled()
|
|
102
|
-
})
|
|
103
|
-
})
|
|
104
|
-
})
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"FocusRegionManager.test.d.ts","sourceRoot":"","sources":["../../src/__new-tests__/FocusRegionManager.test.tsx"],"names":[],"mappings":"AAyBA,OAAO,2BAA2B,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ScreenReaderFocusRegion.test.d.ts","sourceRoot":"","sources":["../../src/__new-tests__/ScreenReaderFocusRegion.test.tsx"],"names":[],"mappings":"AAyBA,OAAO,2BAA2B,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"hasVisibleChildren.test.d.ts","sourceRoot":"","sources":["../../src/__new-tests__/hasVisibleChildren.test.tsx"],"names":[],"mappings":"AAwBA,OAAO,2BAA2B,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"scopeTab.test.d.ts","sourceRoot":"","sources":["../../src/__new-tests__/scopeTab.test.tsx"],"names":[],"mappings":"AA0BA,OAAO,2BAA2B,CAAA"}
|