@instructure/ui-radio-input 10.6.0 → 10.6.1-snapshot-2
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 +8 -0
- package/es/RadioInput/__new-tests__/RadioInput.test.js +225 -0
- package/es/RadioInputGroup/__new-tests__/RadioInputGroup.test.js +241 -0
- package/lib/RadioInput/__new-tests__/RadioInput.test.js +227 -0
- package/lib/RadioInputGroup/__new-tests__/RadioInputGroup.test.js +243 -0
- package/package.json +17 -13
- package/src/RadioInput/__new-tests__/RadioInput.test.tsx +291 -0
- package/src/RadioInputGroup/__new-tests__/RadioInputGroup.test.tsx +231 -0
- package/tsconfig.build.json +2 -2
- package/tsconfig.build.tsbuildinfo +1 -1
- package/types/RadioInput/__new-tests__/RadioInput.test.d.ts +2 -0
- package/types/RadioInput/__new-tests__/RadioInput.test.d.ts.map +1 -0
- package/types/RadioInputGroup/__new-tests__/RadioInputGroup.test.d.ts +2 -0
- package/types/RadioInputGroup/__new-tests__/RadioInputGroup.test.d.ts.map +1 -0
- package/es/RadioInput/RadioInputLocator.js +0 -29
- package/es/RadioInput/locator.js +0 -27
- package/es/RadioInputGroup/RadioInputGroupLocator.js +0 -29
- package/es/RadioInputGroup/locator.js +0 -27
- package/lib/RadioInput/RadioInputLocator.js +0 -34
- package/lib/RadioInput/locator.js +0 -37
- package/lib/RadioInputGroup/RadioInputGroupLocator.js +0 -34
- package/lib/RadioInputGroup/locator.js +0 -37
- package/src/RadioInput/RadioInputLocator.ts +0 -30
- package/src/RadioInput/locator.ts +0 -28
- package/src/RadioInputGroup/RadioInputGroupLocator.ts +0 -30
- package/src/RadioInputGroup/locator.ts +0 -28
- package/types/RadioInput/RadioInputLocator.d.ts +0 -310
- package/types/RadioInput/RadioInputLocator.d.ts.map +0 -1
- package/types/RadioInput/locator.d.ts +0 -4
- package/types/RadioInput/locator.d.ts.map +0 -1
- package/types/RadioInputGroup/RadioInputGroupLocator.d.ts +0 -310
- package/types/RadioInputGroup/RadioInputGroupLocator.d.ts.map +0 -1
- package/types/RadioInputGroup/locator.d.ts +0 -4
- package/types/RadioInputGroup/locator.d.ts.map +0 -1
|
@@ -0,0 +1,291 @@
|
|
|
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 React from 'react'
|
|
26
|
+
import { render, waitFor, fireEvent } from '@testing-library/react'
|
|
27
|
+
import userEvent from '@testing-library/user-event'
|
|
28
|
+
import type { MockInstance } from 'vitest'
|
|
29
|
+
import { vi } from 'vitest'
|
|
30
|
+
|
|
31
|
+
import '@testing-library/jest-dom'
|
|
32
|
+
import { runAxeCheck } from '@instructure/ui-axe-check'
|
|
33
|
+
import { RadioInput } from '../index'
|
|
34
|
+
|
|
35
|
+
describe('<RadioInput />', () => {
|
|
36
|
+
let consoleWarningMock: ReturnType<typeof vi.spyOn>
|
|
37
|
+
let consoleErrorMock: ReturnType<typeof vi.spyOn>
|
|
38
|
+
|
|
39
|
+
beforeEach(() => {
|
|
40
|
+
// Mocking console to prevent test output pollution
|
|
41
|
+
consoleWarningMock = vi
|
|
42
|
+
.spyOn(console, 'warn')
|
|
43
|
+
.mockImplementation(() => {}) as MockInstance
|
|
44
|
+
consoleErrorMock = vi
|
|
45
|
+
.spyOn(console, 'error')
|
|
46
|
+
.mockImplementation(() => {}) as MockInstance
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
afterEach(() => {
|
|
50
|
+
consoleWarningMock.mockRestore()
|
|
51
|
+
consoleErrorMock.mockRestore()
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
it('renders an input with type "radio"', async () => {
|
|
55
|
+
const { container } = render(
|
|
56
|
+
<RadioInput label="fake label" value="someValue" name="someName" />
|
|
57
|
+
)
|
|
58
|
+
|
|
59
|
+
const input = container.querySelector('input')
|
|
60
|
+
|
|
61
|
+
expect(input).toBeInTheDocument()
|
|
62
|
+
expect(input).toHaveAttribute('type', 'radio')
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
describe('events', () => {
|
|
66
|
+
it('responds to onClick event', async () => {
|
|
67
|
+
const onClick = vi.fn()
|
|
68
|
+
|
|
69
|
+
const { container } = render(
|
|
70
|
+
<RadioInput
|
|
71
|
+
label="fake label"
|
|
72
|
+
value="someValue"
|
|
73
|
+
name="someName"
|
|
74
|
+
onClick={onClick}
|
|
75
|
+
/>
|
|
76
|
+
)
|
|
77
|
+
|
|
78
|
+
const input = container.querySelector('input')
|
|
79
|
+
|
|
80
|
+
userEvent.click(input!)
|
|
81
|
+
|
|
82
|
+
await waitFor(() => {
|
|
83
|
+
expect(onClick).toHaveBeenCalled()
|
|
84
|
+
})
|
|
85
|
+
})
|
|
86
|
+
|
|
87
|
+
it('does not respond to onClick event when disabled', async () => {
|
|
88
|
+
const onClick = vi.fn()
|
|
89
|
+
|
|
90
|
+
const { container } = render(
|
|
91
|
+
<RadioInput
|
|
92
|
+
disabled
|
|
93
|
+
label="fake label"
|
|
94
|
+
value="someValue"
|
|
95
|
+
name="someName"
|
|
96
|
+
onClick={onClick}
|
|
97
|
+
/>
|
|
98
|
+
)
|
|
99
|
+
|
|
100
|
+
const input = container.querySelector('input')
|
|
101
|
+
|
|
102
|
+
fireEvent.click(input!)
|
|
103
|
+
|
|
104
|
+
await waitFor(() => {
|
|
105
|
+
expect(onClick).not.toHaveBeenCalled()
|
|
106
|
+
expect(input).toBeDisabled()
|
|
107
|
+
})
|
|
108
|
+
})
|
|
109
|
+
|
|
110
|
+
it('does not respond to onClick event when readOnly', async () => {
|
|
111
|
+
const onClick = vi.fn()
|
|
112
|
+
|
|
113
|
+
const { container } = render(
|
|
114
|
+
<RadioInput
|
|
115
|
+
readOnly
|
|
116
|
+
label="fake label"
|
|
117
|
+
value="someValue"
|
|
118
|
+
name="someName"
|
|
119
|
+
onClick={onClick}
|
|
120
|
+
/>
|
|
121
|
+
)
|
|
122
|
+
|
|
123
|
+
const input = container.querySelector('input')
|
|
124
|
+
|
|
125
|
+
fireEvent.click(input!)
|
|
126
|
+
|
|
127
|
+
await waitFor(() => {
|
|
128
|
+
expect(onClick).not.toHaveBeenCalled()
|
|
129
|
+
expect(input).toBeDisabled()
|
|
130
|
+
})
|
|
131
|
+
})
|
|
132
|
+
|
|
133
|
+
it('responds to onChange event', async () => {
|
|
134
|
+
const onChange = vi.fn()
|
|
135
|
+
|
|
136
|
+
const { container } = render(
|
|
137
|
+
<RadioInput
|
|
138
|
+
label="fake label"
|
|
139
|
+
value="someValue"
|
|
140
|
+
name="someName"
|
|
141
|
+
onChange={onChange}
|
|
142
|
+
/>
|
|
143
|
+
)
|
|
144
|
+
|
|
145
|
+
const input = container.querySelector('input')
|
|
146
|
+
|
|
147
|
+
userEvent.click(input!)
|
|
148
|
+
|
|
149
|
+
await waitFor(() => {
|
|
150
|
+
expect(onChange).toHaveBeenCalled()
|
|
151
|
+
})
|
|
152
|
+
})
|
|
153
|
+
|
|
154
|
+
it('does not respond to onChange event when disabled', async () => {
|
|
155
|
+
const onChange = vi.fn()
|
|
156
|
+
|
|
157
|
+
const { container } = render(
|
|
158
|
+
<RadioInput
|
|
159
|
+
disabled
|
|
160
|
+
label="fake label"
|
|
161
|
+
value="someValue"
|
|
162
|
+
name="someName"
|
|
163
|
+
onChange={onChange}
|
|
164
|
+
/>
|
|
165
|
+
)
|
|
166
|
+
|
|
167
|
+
const input = container.querySelector('input')
|
|
168
|
+
|
|
169
|
+
fireEvent.click(input!)
|
|
170
|
+
|
|
171
|
+
await waitFor(() => {
|
|
172
|
+
expect(onChange).not.toHaveBeenCalled()
|
|
173
|
+
})
|
|
174
|
+
})
|
|
175
|
+
|
|
176
|
+
it('does not respond to onChange event when readOnly', async () => {
|
|
177
|
+
const onChange = vi.fn()
|
|
178
|
+
|
|
179
|
+
const { container } = render(
|
|
180
|
+
<RadioInput
|
|
181
|
+
readOnly
|
|
182
|
+
label="fake label"
|
|
183
|
+
value="someValue"
|
|
184
|
+
name="someName"
|
|
185
|
+
onChange={onChange}
|
|
186
|
+
/>
|
|
187
|
+
)
|
|
188
|
+
|
|
189
|
+
const input = container.querySelector('input')
|
|
190
|
+
|
|
191
|
+
fireEvent.click(input!)
|
|
192
|
+
|
|
193
|
+
await waitFor(() => {
|
|
194
|
+
expect(onChange).not.toHaveBeenCalled()
|
|
195
|
+
})
|
|
196
|
+
})
|
|
197
|
+
|
|
198
|
+
it('responds to onBlur event', async () => {
|
|
199
|
+
const onBlur = vi.fn()
|
|
200
|
+
|
|
201
|
+
const { container } = render(
|
|
202
|
+
<RadioInput
|
|
203
|
+
label="fake label"
|
|
204
|
+
value="someValue"
|
|
205
|
+
name="someName"
|
|
206
|
+
onBlur={onBlur}
|
|
207
|
+
/>
|
|
208
|
+
)
|
|
209
|
+
|
|
210
|
+
const input = container.querySelector('input')
|
|
211
|
+
|
|
212
|
+
fireEvent.focusOut(input!)
|
|
213
|
+
|
|
214
|
+
await waitFor(() => {
|
|
215
|
+
expect(onBlur).toHaveBeenCalled()
|
|
216
|
+
})
|
|
217
|
+
})
|
|
218
|
+
|
|
219
|
+
it('responds to onFocus event', async () => {
|
|
220
|
+
const onFocus = vi.fn()
|
|
221
|
+
|
|
222
|
+
const { container } = render(
|
|
223
|
+
<RadioInput
|
|
224
|
+
label="fake label"
|
|
225
|
+
value="someValue"
|
|
226
|
+
name="someName"
|
|
227
|
+
onFocus={onFocus}
|
|
228
|
+
/>
|
|
229
|
+
)
|
|
230
|
+
const input = container.querySelector('input')
|
|
231
|
+
|
|
232
|
+
fireEvent.focus(input!)
|
|
233
|
+
|
|
234
|
+
await waitFor(() => {
|
|
235
|
+
expect(onFocus).toHaveBeenCalled()
|
|
236
|
+
})
|
|
237
|
+
})
|
|
238
|
+
|
|
239
|
+
it('sets input to checked when selected', async () => {
|
|
240
|
+
const { container } = render(
|
|
241
|
+
<RadioInput
|
|
242
|
+
checked
|
|
243
|
+
label="fake label"
|
|
244
|
+
value="someValue"
|
|
245
|
+
name="someName"
|
|
246
|
+
/>
|
|
247
|
+
)
|
|
248
|
+
const input = container.querySelector('input')
|
|
249
|
+
|
|
250
|
+
expect(input).toHaveAttribute('checked')
|
|
251
|
+
})
|
|
252
|
+
|
|
253
|
+
it('focuses with the focus helper', async () => {
|
|
254
|
+
let ref: RadioInput
|
|
255
|
+
|
|
256
|
+
const { container } = render(
|
|
257
|
+
<RadioInput
|
|
258
|
+
label="fake label"
|
|
259
|
+
value="someValue"
|
|
260
|
+
name="someName"
|
|
261
|
+
// @ts-expect-error this is managed by the testing framework
|
|
262
|
+
ref={(el) => (ref = el)}
|
|
263
|
+
/>
|
|
264
|
+
)
|
|
265
|
+
|
|
266
|
+
const input = container.querySelector('input')
|
|
267
|
+
|
|
268
|
+
ref!.focus()
|
|
269
|
+
|
|
270
|
+
await waitFor(() => {
|
|
271
|
+
expect(document.activeElement).toBe(input)
|
|
272
|
+
})
|
|
273
|
+
})
|
|
274
|
+
})
|
|
275
|
+
|
|
276
|
+
describe('for a11y', () => {
|
|
277
|
+
it('simple variant should meet a11y standards', async () => {
|
|
278
|
+
const { container } = render(
|
|
279
|
+
<RadioInput
|
|
280
|
+
variant="simple"
|
|
281
|
+
label="fake label"
|
|
282
|
+
value="someValue"
|
|
283
|
+
name="someName"
|
|
284
|
+
/>
|
|
285
|
+
)
|
|
286
|
+
const axeCheck = await runAxeCheck(container)
|
|
287
|
+
|
|
288
|
+
expect(axeCheck).toBe(true)
|
|
289
|
+
})
|
|
290
|
+
})
|
|
291
|
+
})
|
|
@@ -0,0 +1,231 @@
|
|
|
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 React from 'react'
|
|
26
|
+
import { render, waitFor, fireEvent } from '@testing-library/react'
|
|
27
|
+
import userEvent from '@testing-library/user-event'
|
|
28
|
+
import type { MockInstance } from 'vitest'
|
|
29
|
+
import { vi } from 'vitest'
|
|
30
|
+
|
|
31
|
+
import '@testing-library/jest-dom'
|
|
32
|
+
import { runAxeCheck } from '@instructure/ui-axe-check'
|
|
33
|
+
import { RadioInput } from '../../RadioInput'
|
|
34
|
+
import { RadioInputGroup } from '../index'
|
|
35
|
+
|
|
36
|
+
describe('<RadioInputGroup />', () => {
|
|
37
|
+
let consoleWarningMock: ReturnType<typeof vi.spyOn>
|
|
38
|
+
let consoleErrorMock: ReturnType<typeof vi.spyOn>
|
|
39
|
+
|
|
40
|
+
beforeEach(() => {
|
|
41
|
+
// Mocking console to prevent test output pollution and expect for messages
|
|
42
|
+
consoleWarningMock = vi
|
|
43
|
+
.spyOn(console, 'warn')
|
|
44
|
+
.mockImplementation(() => {}) as MockInstance
|
|
45
|
+
consoleErrorMock = vi
|
|
46
|
+
.spyOn(console, 'error')
|
|
47
|
+
.mockImplementation(() => {}) as MockInstance
|
|
48
|
+
})
|
|
49
|
+
|
|
50
|
+
afterEach(() => {
|
|
51
|
+
consoleWarningMock.mockRestore()
|
|
52
|
+
consoleErrorMock.mockRestore()
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
it('adds the name props to all RadioInput types', async () => {
|
|
56
|
+
const { container } = render(
|
|
57
|
+
<RadioInputGroup name="fruit" description="Select a fruit">
|
|
58
|
+
<RadioInput label="Apple" value="apple" />
|
|
59
|
+
<RadioInput label="Banana" value="banana" />
|
|
60
|
+
<RadioInput label="Orange" value="orange" />
|
|
61
|
+
</RadioInputGroup>
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
const inputs = await container.querySelectorAll('input[name="fruit"]')
|
|
65
|
+
|
|
66
|
+
expect(inputs.length).toBe(3)
|
|
67
|
+
})
|
|
68
|
+
|
|
69
|
+
it('requires an `onChange` prop with a `value` prop', async () => {
|
|
70
|
+
render(
|
|
71
|
+
<RadioInputGroup name="fruit" description="Select a fruit" value="banana">
|
|
72
|
+
<RadioInput label="Apple" value="apple" />
|
|
73
|
+
<RadioInput label="Banana" value="banana" />
|
|
74
|
+
<RadioInput label="Orange" value="orange" />
|
|
75
|
+
</RadioInputGroup>
|
|
76
|
+
)
|
|
77
|
+
|
|
78
|
+
const expectedErrorMessage = `provided a 'value' prop without an 'onChange' handler`
|
|
79
|
+
|
|
80
|
+
expect(consoleErrorMock).toHaveBeenCalledWith(
|
|
81
|
+
expect.any(String),
|
|
82
|
+
expect.any(String),
|
|
83
|
+
expect.stringContaining(expectedErrorMessage),
|
|
84
|
+
expect.any(String)
|
|
85
|
+
)
|
|
86
|
+
})
|
|
87
|
+
|
|
88
|
+
it('calls the onChange prop', async () => {
|
|
89
|
+
const onChange = vi.fn()
|
|
90
|
+
const { container } = render(
|
|
91
|
+
<RadioInputGroup
|
|
92
|
+
name="fruit"
|
|
93
|
+
description="Select a fruit"
|
|
94
|
+
onChange={onChange}
|
|
95
|
+
>
|
|
96
|
+
<RadioInput label="Apple" value="apple" />
|
|
97
|
+
<RadioInput label="Banana" value="banana" />
|
|
98
|
+
<RadioInput label="Orange" value="orange" />
|
|
99
|
+
</RadioInputGroup>
|
|
100
|
+
)
|
|
101
|
+
const input = container.querySelector('input')
|
|
102
|
+
|
|
103
|
+
userEvent.click(input!)
|
|
104
|
+
|
|
105
|
+
await waitFor(() => {
|
|
106
|
+
expect(onChange).toHaveBeenCalled()
|
|
107
|
+
})
|
|
108
|
+
})
|
|
109
|
+
|
|
110
|
+
it('does not call the onChange prop when disabled', async () => {
|
|
111
|
+
const onChange = vi.fn()
|
|
112
|
+
const { container } = render(
|
|
113
|
+
<RadioInputGroup
|
|
114
|
+
disabled
|
|
115
|
+
name="fruit"
|
|
116
|
+
description="Select a fruit"
|
|
117
|
+
onChange={onChange}
|
|
118
|
+
>
|
|
119
|
+
<RadioInput label="Apple" value="apple" />
|
|
120
|
+
<RadioInput label="Banana" value="banana" />
|
|
121
|
+
<RadioInput label="Orange" value="orange" />
|
|
122
|
+
</RadioInputGroup>
|
|
123
|
+
)
|
|
124
|
+
const input = container.querySelector('input')
|
|
125
|
+
|
|
126
|
+
fireEvent.click(input!)
|
|
127
|
+
|
|
128
|
+
await waitFor(() => {
|
|
129
|
+
expect(onChange).not.toHaveBeenCalled()
|
|
130
|
+
expect(input).toBeDisabled()
|
|
131
|
+
})
|
|
132
|
+
})
|
|
133
|
+
|
|
134
|
+
it('does not call the onChange prop when readOnly', async () => {
|
|
135
|
+
const onChange = vi.fn()
|
|
136
|
+
const { container } = render(
|
|
137
|
+
<RadioInputGroup
|
|
138
|
+
readOnly
|
|
139
|
+
name="fruit"
|
|
140
|
+
description="Select a fruit"
|
|
141
|
+
onChange={onChange}
|
|
142
|
+
>
|
|
143
|
+
<RadioInput label="Apple" value="apple" />
|
|
144
|
+
<RadioInput label="Banana" value="banana" />
|
|
145
|
+
<RadioInput label="Orange" value="orange" />
|
|
146
|
+
</RadioInputGroup>
|
|
147
|
+
)
|
|
148
|
+
const input = container.querySelector('input')
|
|
149
|
+
|
|
150
|
+
fireEvent.click(input!)
|
|
151
|
+
|
|
152
|
+
await waitFor(() => {
|
|
153
|
+
expect(onChange).not.toHaveBeenCalled()
|
|
154
|
+
expect(input).toBeDisabled()
|
|
155
|
+
})
|
|
156
|
+
})
|
|
157
|
+
|
|
158
|
+
it('should not update the value when the value prop is set', async () => {
|
|
159
|
+
const { container } = render(
|
|
160
|
+
<RadioInputGroup
|
|
161
|
+
name="fruit"
|
|
162
|
+
description="Select a fruit"
|
|
163
|
+
value="orange"
|
|
164
|
+
onChange={() => {}}
|
|
165
|
+
>
|
|
166
|
+
<RadioInput label="Apple" value="apple" />
|
|
167
|
+
<RadioInput label="Banana" value="banana" />
|
|
168
|
+
<RadioInput label="Orange" value="orange" />
|
|
169
|
+
</RadioInputGroup>
|
|
170
|
+
)
|
|
171
|
+
const banana = container.querySelector('input[value="banana"]')
|
|
172
|
+
const orange = container.querySelector('input[value="orange"]')
|
|
173
|
+
|
|
174
|
+
expect(orange).toHaveAttribute('checked')
|
|
175
|
+
|
|
176
|
+
userEvent.click(banana!)
|
|
177
|
+
|
|
178
|
+
await waitFor(() => {
|
|
179
|
+
expect(orange).toHaveAttribute('checked')
|
|
180
|
+
})
|
|
181
|
+
})
|
|
182
|
+
|
|
183
|
+
it('adds the correct tabindex to RadioInputs when none are checked', async () => {
|
|
184
|
+
const { container } = render(
|
|
185
|
+
<RadioInputGroup name="fruit" description="Select a fruit">
|
|
186
|
+
<RadioInput label="Apple" value="apple" />
|
|
187
|
+
<RadioInput label="Banana" value="banana" />
|
|
188
|
+
<RadioInput label="Orange" value="orange" />
|
|
189
|
+
</RadioInputGroup>
|
|
190
|
+
)
|
|
191
|
+
const inputs = container.querySelectorAll('input[name="fruit"]')
|
|
192
|
+
|
|
193
|
+
expect(inputs[0]).toHaveAttribute('tabindex', '0')
|
|
194
|
+
expect(inputs[1]).toHaveAttribute('tabindex', '-1')
|
|
195
|
+
expect(inputs[2]).toHaveAttribute('tabindex', '-1')
|
|
196
|
+
})
|
|
197
|
+
|
|
198
|
+
it('adds the correct tabindex to RadioInputs when checked', async () => {
|
|
199
|
+
const { container } = render(
|
|
200
|
+
<RadioInputGroup
|
|
201
|
+
name="fruit"
|
|
202
|
+
description="Select a fruit"
|
|
203
|
+
defaultValue="banana"
|
|
204
|
+
>
|
|
205
|
+
<RadioInput label="Apple" value="apple" />
|
|
206
|
+
<RadioInput label="Banana" value="banana" />
|
|
207
|
+
<RadioInput label="Orange" value="orange" />
|
|
208
|
+
</RadioInputGroup>
|
|
209
|
+
)
|
|
210
|
+
const inputs = container.querySelectorAll('input[name="fruit"]')
|
|
211
|
+
|
|
212
|
+
expect(inputs[0]).toHaveAttribute('tabindex', '-1')
|
|
213
|
+
expect(inputs[1]).toHaveAttribute('tabindex', '0')
|
|
214
|
+
expect(inputs[2]).toHaveAttribute('tabindex', '-1')
|
|
215
|
+
})
|
|
216
|
+
|
|
217
|
+
describe('for a11y', () => {
|
|
218
|
+
it('should meet a11y standards', async () => {
|
|
219
|
+
const { container } = render(
|
|
220
|
+
<RadioInputGroup name="fruit" description="Select a fruit">
|
|
221
|
+
<RadioInput label="Apple" value="apple" />
|
|
222
|
+
<RadioInput label="Banana" value="banana" />
|
|
223
|
+
<RadioInput label="Orange" value="orange" />
|
|
224
|
+
</RadioInputGroup>
|
|
225
|
+
)
|
|
226
|
+
const axeCheck = await runAxeCheck(container)
|
|
227
|
+
|
|
228
|
+
expect(axeCheck).toBe(true)
|
|
229
|
+
})
|
|
230
|
+
})
|
|
231
|
+
})
|
package/tsconfig.build.json
CHANGED
|
@@ -16,8 +16,8 @@
|
|
|
16
16
|
{ "path": "../ui-testable/tsconfig.build.json" },
|
|
17
17
|
{ "path": "../ui-babel-preset/tsconfig.build.json" },
|
|
18
18
|
{ "path": "../ui-color-utils/tsconfig.build.json" },
|
|
19
|
-
{ "path": "../ui-test-locator/tsconfig.build.json" },
|
|
20
19
|
{ "path": "../ui-test-utils/tsconfig.build.json" },
|
|
21
|
-
{ "path": "../ui-themes/tsconfig.build.json" }
|
|
20
|
+
{ "path": "../ui-themes/tsconfig.build.json" },
|
|
21
|
+
{ "path": "../ui-axe-check/tsconfig.build.json" }
|
|
22
22
|
]
|
|
23
23
|
}
|