@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
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,14 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [10.6.1-snapshot-2](https://github.com/instructure/instructure-ui/compare/v10.6.0...v10.6.1-snapshot-2) (2024-11-19)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @instructure/ui-radio-input
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
6
14
|
# [10.6.0](https://github.com/instructure/instructure-ui/compare/v10.5.0...v10.6.0) (2024-11-18)
|
|
7
15
|
|
|
8
16
|
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
var _RadioInput, _RadioInput2, _RadioInput3;
|
|
2
|
+
/*
|
|
3
|
+
* The MIT License (MIT)
|
|
4
|
+
*
|
|
5
|
+
* Copyright (c) 2015 - present Instructure, Inc.
|
|
6
|
+
*
|
|
7
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
9
|
+
* in the Software without restriction, including without limitation the rights
|
|
10
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
11
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
12
|
+
* furnished to do so, subject to the following conditions:
|
|
13
|
+
*
|
|
14
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
15
|
+
* copies or substantial portions of the Software.
|
|
16
|
+
*
|
|
17
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
19
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
20
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
21
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
22
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
23
|
+
* SOFTWARE.
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
import React from 'react';
|
|
27
|
+
import { render, waitFor, fireEvent } from '@testing-library/react';
|
|
28
|
+
import userEvent from '@testing-library/user-event';
|
|
29
|
+
import { vi } from 'vitest';
|
|
30
|
+
import '@testing-library/jest-dom';
|
|
31
|
+
import { runAxeCheck } from '@instructure/ui-axe-check';
|
|
32
|
+
import { RadioInput } from '../index';
|
|
33
|
+
describe('<RadioInput />', () => {
|
|
34
|
+
let consoleWarningMock;
|
|
35
|
+
let consoleErrorMock;
|
|
36
|
+
beforeEach(() => {
|
|
37
|
+
// Mocking console to prevent test output pollution
|
|
38
|
+
consoleWarningMock = vi.spyOn(console, 'warn').mockImplementation(() => {});
|
|
39
|
+
consoleErrorMock = vi.spyOn(console, 'error').mockImplementation(() => {});
|
|
40
|
+
});
|
|
41
|
+
afterEach(() => {
|
|
42
|
+
consoleWarningMock.mockRestore();
|
|
43
|
+
consoleErrorMock.mockRestore();
|
|
44
|
+
});
|
|
45
|
+
it('renders an input with type "radio"', async () => {
|
|
46
|
+
const _render = render(_RadioInput || (_RadioInput = /*#__PURE__*/React.createElement(RadioInput, {
|
|
47
|
+
label: "fake label",
|
|
48
|
+
value: "someValue",
|
|
49
|
+
name: "someName"
|
|
50
|
+
}))),
|
|
51
|
+
container = _render.container;
|
|
52
|
+
const input = container.querySelector('input');
|
|
53
|
+
expect(input).toBeInTheDocument();
|
|
54
|
+
expect(input).toHaveAttribute('type', 'radio');
|
|
55
|
+
});
|
|
56
|
+
describe('events', () => {
|
|
57
|
+
it('responds to onClick event', async () => {
|
|
58
|
+
const onClick = vi.fn();
|
|
59
|
+
const _render2 = render(/*#__PURE__*/React.createElement(RadioInput, {
|
|
60
|
+
label: "fake label",
|
|
61
|
+
value: "someValue",
|
|
62
|
+
name: "someName",
|
|
63
|
+
onClick: onClick
|
|
64
|
+
})),
|
|
65
|
+
container = _render2.container;
|
|
66
|
+
const input = container.querySelector('input');
|
|
67
|
+
userEvent.click(input);
|
|
68
|
+
await waitFor(() => {
|
|
69
|
+
expect(onClick).toHaveBeenCalled();
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
it('does not respond to onClick event when disabled', async () => {
|
|
73
|
+
const onClick = vi.fn();
|
|
74
|
+
const _render3 = render(/*#__PURE__*/React.createElement(RadioInput, {
|
|
75
|
+
disabled: true,
|
|
76
|
+
label: "fake label",
|
|
77
|
+
value: "someValue",
|
|
78
|
+
name: "someName",
|
|
79
|
+
onClick: onClick
|
|
80
|
+
})),
|
|
81
|
+
container = _render3.container;
|
|
82
|
+
const input = container.querySelector('input');
|
|
83
|
+
fireEvent.click(input);
|
|
84
|
+
await waitFor(() => {
|
|
85
|
+
expect(onClick).not.toHaveBeenCalled();
|
|
86
|
+
expect(input).toBeDisabled();
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
it('does not respond to onClick event when readOnly', async () => {
|
|
90
|
+
const onClick = vi.fn();
|
|
91
|
+
const _render4 = render(/*#__PURE__*/React.createElement(RadioInput, {
|
|
92
|
+
readOnly: true,
|
|
93
|
+
label: "fake label",
|
|
94
|
+
value: "someValue",
|
|
95
|
+
name: "someName",
|
|
96
|
+
onClick: onClick
|
|
97
|
+
})),
|
|
98
|
+
container = _render4.container;
|
|
99
|
+
const input = container.querySelector('input');
|
|
100
|
+
fireEvent.click(input);
|
|
101
|
+
await waitFor(() => {
|
|
102
|
+
expect(onClick).not.toHaveBeenCalled();
|
|
103
|
+
expect(input).toBeDisabled();
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
it('responds to onChange event', async () => {
|
|
107
|
+
const onChange = vi.fn();
|
|
108
|
+
const _render5 = render(/*#__PURE__*/React.createElement(RadioInput, {
|
|
109
|
+
label: "fake label",
|
|
110
|
+
value: "someValue",
|
|
111
|
+
name: "someName",
|
|
112
|
+
onChange: onChange
|
|
113
|
+
})),
|
|
114
|
+
container = _render5.container;
|
|
115
|
+
const input = container.querySelector('input');
|
|
116
|
+
userEvent.click(input);
|
|
117
|
+
await waitFor(() => {
|
|
118
|
+
expect(onChange).toHaveBeenCalled();
|
|
119
|
+
});
|
|
120
|
+
});
|
|
121
|
+
it('does not respond to onChange event when disabled', async () => {
|
|
122
|
+
const onChange = vi.fn();
|
|
123
|
+
const _render6 = render(/*#__PURE__*/React.createElement(RadioInput, {
|
|
124
|
+
disabled: true,
|
|
125
|
+
label: "fake label",
|
|
126
|
+
value: "someValue",
|
|
127
|
+
name: "someName",
|
|
128
|
+
onChange: onChange
|
|
129
|
+
})),
|
|
130
|
+
container = _render6.container;
|
|
131
|
+
const input = container.querySelector('input');
|
|
132
|
+
fireEvent.click(input);
|
|
133
|
+
await waitFor(() => {
|
|
134
|
+
expect(onChange).not.toHaveBeenCalled();
|
|
135
|
+
});
|
|
136
|
+
});
|
|
137
|
+
it('does not respond to onChange event when readOnly', async () => {
|
|
138
|
+
const onChange = vi.fn();
|
|
139
|
+
const _render7 = render(/*#__PURE__*/React.createElement(RadioInput, {
|
|
140
|
+
readOnly: true,
|
|
141
|
+
label: "fake label",
|
|
142
|
+
value: "someValue",
|
|
143
|
+
name: "someName",
|
|
144
|
+
onChange: onChange
|
|
145
|
+
})),
|
|
146
|
+
container = _render7.container;
|
|
147
|
+
const input = container.querySelector('input');
|
|
148
|
+
fireEvent.click(input);
|
|
149
|
+
await waitFor(() => {
|
|
150
|
+
expect(onChange).not.toHaveBeenCalled();
|
|
151
|
+
});
|
|
152
|
+
});
|
|
153
|
+
it('responds to onBlur event', async () => {
|
|
154
|
+
const onBlur = vi.fn();
|
|
155
|
+
const _render8 = render(/*#__PURE__*/React.createElement(RadioInput, {
|
|
156
|
+
label: "fake label",
|
|
157
|
+
value: "someValue",
|
|
158
|
+
name: "someName",
|
|
159
|
+
onBlur: onBlur
|
|
160
|
+
})),
|
|
161
|
+
container = _render8.container;
|
|
162
|
+
const input = container.querySelector('input');
|
|
163
|
+
fireEvent.focusOut(input);
|
|
164
|
+
await waitFor(() => {
|
|
165
|
+
expect(onBlur).toHaveBeenCalled();
|
|
166
|
+
});
|
|
167
|
+
});
|
|
168
|
+
it('responds to onFocus event', async () => {
|
|
169
|
+
const onFocus = vi.fn();
|
|
170
|
+
const _render9 = render(/*#__PURE__*/React.createElement(RadioInput, {
|
|
171
|
+
label: "fake label",
|
|
172
|
+
value: "someValue",
|
|
173
|
+
name: "someName",
|
|
174
|
+
onFocus: onFocus
|
|
175
|
+
})),
|
|
176
|
+
container = _render9.container;
|
|
177
|
+
const input = container.querySelector('input');
|
|
178
|
+
fireEvent.focus(input);
|
|
179
|
+
await waitFor(() => {
|
|
180
|
+
expect(onFocus).toHaveBeenCalled();
|
|
181
|
+
});
|
|
182
|
+
});
|
|
183
|
+
it('sets input to checked when selected', async () => {
|
|
184
|
+
const _render10 = render(_RadioInput2 || (_RadioInput2 = /*#__PURE__*/React.createElement(RadioInput, {
|
|
185
|
+
checked: true,
|
|
186
|
+
label: "fake label",
|
|
187
|
+
value: "someValue",
|
|
188
|
+
name: "someName"
|
|
189
|
+
}))),
|
|
190
|
+
container = _render10.container;
|
|
191
|
+
const input = container.querySelector('input');
|
|
192
|
+
expect(input).toHaveAttribute('checked');
|
|
193
|
+
});
|
|
194
|
+
it('focuses with the focus helper', async () => {
|
|
195
|
+
let ref;
|
|
196
|
+
const _render11 = render(/*#__PURE__*/React.createElement(RadioInput, {
|
|
197
|
+
label: "fake label",
|
|
198
|
+
value: "someValue",
|
|
199
|
+
name: "someName"
|
|
200
|
+
// @ts-expect-error this is managed by the testing framework
|
|
201
|
+
,
|
|
202
|
+
ref: el => ref = el
|
|
203
|
+
})),
|
|
204
|
+
container = _render11.container;
|
|
205
|
+
const input = container.querySelector('input');
|
|
206
|
+
ref.focus();
|
|
207
|
+
await waitFor(() => {
|
|
208
|
+
expect(document.activeElement).toBe(input);
|
|
209
|
+
});
|
|
210
|
+
});
|
|
211
|
+
});
|
|
212
|
+
describe('for a11y', () => {
|
|
213
|
+
it('simple variant should meet a11y standards', async () => {
|
|
214
|
+
const _render12 = render(_RadioInput3 || (_RadioInput3 = /*#__PURE__*/React.createElement(RadioInput, {
|
|
215
|
+
variant: "simple",
|
|
216
|
+
label: "fake label",
|
|
217
|
+
value: "someValue",
|
|
218
|
+
name: "someName"
|
|
219
|
+
}))),
|
|
220
|
+
container = _render12.container;
|
|
221
|
+
const axeCheck = await runAxeCheck(container);
|
|
222
|
+
expect(axeCheck).toBe(true);
|
|
223
|
+
});
|
|
224
|
+
});
|
|
225
|
+
});
|
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
var _RadioInputGroup, _RadioInputGroup2, _RadioInput, _RadioInput2, _RadioInput3, _RadioInput4, _RadioInput5, _RadioInput6, _RadioInput7, _RadioInput8, _RadioInput9, _RadioInput10, _RadioInput11, _RadioInput12, _RadioInputGroup3, _RadioInputGroup4, _RadioInputGroup5;
|
|
2
|
+
/*
|
|
3
|
+
* The MIT License (MIT)
|
|
4
|
+
*
|
|
5
|
+
* Copyright (c) 2015 - present Instructure, Inc.
|
|
6
|
+
*
|
|
7
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
9
|
+
* in the Software without restriction, including without limitation the rights
|
|
10
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
11
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
12
|
+
* furnished to do so, subject to the following conditions:
|
|
13
|
+
*
|
|
14
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
15
|
+
* copies or substantial portions of the Software.
|
|
16
|
+
*
|
|
17
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
19
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
20
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
21
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
22
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
23
|
+
* SOFTWARE.
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
import React from 'react';
|
|
27
|
+
import { render, waitFor, fireEvent } from '@testing-library/react';
|
|
28
|
+
import userEvent from '@testing-library/user-event';
|
|
29
|
+
import { vi } from 'vitest';
|
|
30
|
+
import '@testing-library/jest-dom';
|
|
31
|
+
import { runAxeCheck } from '@instructure/ui-axe-check';
|
|
32
|
+
import { RadioInput } from '../../RadioInput';
|
|
33
|
+
import { RadioInputGroup } from '../index';
|
|
34
|
+
describe('<RadioInputGroup />', () => {
|
|
35
|
+
let consoleWarningMock;
|
|
36
|
+
let consoleErrorMock;
|
|
37
|
+
beforeEach(() => {
|
|
38
|
+
// Mocking console to prevent test output pollution and expect for messages
|
|
39
|
+
consoleWarningMock = vi.spyOn(console, 'warn').mockImplementation(() => {});
|
|
40
|
+
consoleErrorMock = vi.spyOn(console, 'error').mockImplementation(() => {});
|
|
41
|
+
});
|
|
42
|
+
afterEach(() => {
|
|
43
|
+
consoleWarningMock.mockRestore();
|
|
44
|
+
consoleErrorMock.mockRestore();
|
|
45
|
+
});
|
|
46
|
+
it('adds the name props to all RadioInput types', async () => {
|
|
47
|
+
const _render = render(_RadioInputGroup || (_RadioInputGroup = /*#__PURE__*/React.createElement(RadioInputGroup, {
|
|
48
|
+
name: "fruit",
|
|
49
|
+
description: "Select a fruit"
|
|
50
|
+
}, /*#__PURE__*/React.createElement(RadioInput, {
|
|
51
|
+
label: "Apple",
|
|
52
|
+
value: "apple"
|
|
53
|
+
}), /*#__PURE__*/React.createElement(RadioInput, {
|
|
54
|
+
label: "Banana",
|
|
55
|
+
value: "banana"
|
|
56
|
+
}), /*#__PURE__*/React.createElement(RadioInput, {
|
|
57
|
+
label: "Orange",
|
|
58
|
+
value: "orange"
|
|
59
|
+
})))),
|
|
60
|
+
container = _render.container;
|
|
61
|
+
const inputs = await container.querySelectorAll('input[name="fruit"]');
|
|
62
|
+
expect(inputs.length).toBe(3);
|
|
63
|
+
});
|
|
64
|
+
it('requires an `onChange` prop with a `value` prop', async () => {
|
|
65
|
+
render(_RadioInputGroup2 || (_RadioInputGroup2 = /*#__PURE__*/React.createElement(RadioInputGroup, {
|
|
66
|
+
name: "fruit",
|
|
67
|
+
description: "Select a fruit",
|
|
68
|
+
value: "banana"
|
|
69
|
+
}, /*#__PURE__*/React.createElement(RadioInput, {
|
|
70
|
+
label: "Apple",
|
|
71
|
+
value: "apple"
|
|
72
|
+
}), /*#__PURE__*/React.createElement(RadioInput, {
|
|
73
|
+
label: "Banana",
|
|
74
|
+
value: "banana"
|
|
75
|
+
}), /*#__PURE__*/React.createElement(RadioInput, {
|
|
76
|
+
label: "Orange",
|
|
77
|
+
value: "orange"
|
|
78
|
+
}))));
|
|
79
|
+
const expectedErrorMessage = `provided a 'value' prop without an 'onChange' handler`;
|
|
80
|
+
expect(consoleErrorMock).toHaveBeenCalledWith(expect.any(String), expect.any(String), expect.stringContaining(expectedErrorMessage), expect.any(String));
|
|
81
|
+
});
|
|
82
|
+
it('calls the onChange prop', async () => {
|
|
83
|
+
const onChange = vi.fn();
|
|
84
|
+
const _render2 = render(/*#__PURE__*/React.createElement(RadioInputGroup, {
|
|
85
|
+
name: "fruit",
|
|
86
|
+
description: "Select a fruit",
|
|
87
|
+
onChange: onChange
|
|
88
|
+
}, _RadioInput || (_RadioInput = /*#__PURE__*/React.createElement(RadioInput, {
|
|
89
|
+
label: "Apple",
|
|
90
|
+
value: "apple"
|
|
91
|
+
})), _RadioInput2 || (_RadioInput2 = /*#__PURE__*/React.createElement(RadioInput, {
|
|
92
|
+
label: "Banana",
|
|
93
|
+
value: "banana"
|
|
94
|
+
})), _RadioInput3 || (_RadioInput3 = /*#__PURE__*/React.createElement(RadioInput, {
|
|
95
|
+
label: "Orange",
|
|
96
|
+
value: "orange"
|
|
97
|
+
})))),
|
|
98
|
+
container = _render2.container;
|
|
99
|
+
const input = container.querySelector('input');
|
|
100
|
+
userEvent.click(input);
|
|
101
|
+
await waitFor(() => {
|
|
102
|
+
expect(onChange).toHaveBeenCalled();
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
it('does not call the onChange prop when disabled', async () => {
|
|
106
|
+
const onChange = vi.fn();
|
|
107
|
+
const _render3 = render(/*#__PURE__*/React.createElement(RadioInputGroup, {
|
|
108
|
+
disabled: true,
|
|
109
|
+
name: "fruit",
|
|
110
|
+
description: "Select a fruit",
|
|
111
|
+
onChange: onChange
|
|
112
|
+
}, _RadioInput4 || (_RadioInput4 = /*#__PURE__*/React.createElement(RadioInput, {
|
|
113
|
+
label: "Apple",
|
|
114
|
+
value: "apple"
|
|
115
|
+
})), _RadioInput5 || (_RadioInput5 = /*#__PURE__*/React.createElement(RadioInput, {
|
|
116
|
+
label: "Banana",
|
|
117
|
+
value: "banana"
|
|
118
|
+
})), _RadioInput6 || (_RadioInput6 = /*#__PURE__*/React.createElement(RadioInput, {
|
|
119
|
+
label: "Orange",
|
|
120
|
+
value: "orange"
|
|
121
|
+
})))),
|
|
122
|
+
container = _render3.container;
|
|
123
|
+
const input = container.querySelector('input');
|
|
124
|
+
fireEvent.click(input);
|
|
125
|
+
await waitFor(() => {
|
|
126
|
+
expect(onChange).not.toHaveBeenCalled();
|
|
127
|
+
expect(input).toBeDisabled();
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
it('does not call the onChange prop when readOnly', async () => {
|
|
131
|
+
const onChange = vi.fn();
|
|
132
|
+
const _render4 = render(/*#__PURE__*/React.createElement(RadioInputGroup, {
|
|
133
|
+
readOnly: true,
|
|
134
|
+
name: "fruit",
|
|
135
|
+
description: "Select a fruit",
|
|
136
|
+
onChange: onChange
|
|
137
|
+
}, _RadioInput7 || (_RadioInput7 = /*#__PURE__*/React.createElement(RadioInput, {
|
|
138
|
+
label: "Apple",
|
|
139
|
+
value: "apple"
|
|
140
|
+
})), _RadioInput8 || (_RadioInput8 = /*#__PURE__*/React.createElement(RadioInput, {
|
|
141
|
+
label: "Banana",
|
|
142
|
+
value: "banana"
|
|
143
|
+
})), _RadioInput9 || (_RadioInput9 = /*#__PURE__*/React.createElement(RadioInput, {
|
|
144
|
+
label: "Orange",
|
|
145
|
+
value: "orange"
|
|
146
|
+
})))),
|
|
147
|
+
container = _render4.container;
|
|
148
|
+
const input = container.querySelector('input');
|
|
149
|
+
fireEvent.click(input);
|
|
150
|
+
await waitFor(() => {
|
|
151
|
+
expect(onChange).not.toHaveBeenCalled();
|
|
152
|
+
expect(input).toBeDisabled();
|
|
153
|
+
});
|
|
154
|
+
});
|
|
155
|
+
it('should not update the value when the value prop is set', async () => {
|
|
156
|
+
const _render5 = render(/*#__PURE__*/React.createElement(RadioInputGroup, {
|
|
157
|
+
name: "fruit",
|
|
158
|
+
description: "Select a fruit",
|
|
159
|
+
value: "orange",
|
|
160
|
+
onChange: () => {}
|
|
161
|
+
}, _RadioInput10 || (_RadioInput10 = /*#__PURE__*/React.createElement(RadioInput, {
|
|
162
|
+
label: "Apple",
|
|
163
|
+
value: "apple"
|
|
164
|
+
})), _RadioInput11 || (_RadioInput11 = /*#__PURE__*/React.createElement(RadioInput, {
|
|
165
|
+
label: "Banana",
|
|
166
|
+
value: "banana"
|
|
167
|
+
})), _RadioInput12 || (_RadioInput12 = /*#__PURE__*/React.createElement(RadioInput, {
|
|
168
|
+
label: "Orange",
|
|
169
|
+
value: "orange"
|
|
170
|
+
})))),
|
|
171
|
+
container = _render5.container;
|
|
172
|
+
const banana = container.querySelector('input[value="banana"]');
|
|
173
|
+
const orange = container.querySelector('input[value="orange"]');
|
|
174
|
+
expect(orange).toHaveAttribute('checked');
|
|
175
|
+
userEvent.click(banana);
|
|
176
|
+
await waitFor(() => {
|
|
177
|
+
expect(orange).toHaveAttribute('checked');
|
|
178
|
+
});
|
|
179
|
+
});
|
|
180
|
+
it('adds the correct tabindex to RadioInputs when none are checked', async () => {
|
|
181
|
+
const _render6 = render(_RadioInputGroup3 || (_RadioInputGroup3 = /*#__PURE__*/React.createElement(RadioInputGroup, {
|
|
182
|
+
name: "fruit",
|
|
183
|
+
description: "Select a fruit"
|
|
184
|
+
}, /*#__PURE__*/React.createElement(RadioInput, {
|
|
185
|
+
label: "Apple",
|
|
186
|
+
value: "apple"
|
|
187
|
+
}), /*#__PURE__*/React.createElement(RadioInput, {
|
|
188
|
+
label: "Banana",
|
|
189
|
+
value: "banana"
|
|
190
|
+
}), /*#__PURE__*/React.createElement(RadioInput, {
|
|
191
|
+
label: "Orange",
|
|
192
|
+
value: "orange"
|
|
193
|
+
})))),
|
|
194
|
+
container = _render6.container;
|
|
195
|
+
const inputs = container.querySelectorAll('input[name="fruit"]');
|
|
196
|
+
expect(inputs[0]).toHaveAttribute('tabindex', '0');
|
|
197
|
+
expect(inputs[1]).toHaveAttribute('tabindex', '-1');
|
|
198
|
+
expect(inputs[2]).toHaveAttribute('tabindex', '-1');
|
|
199
|
+
});
|
|
200
|
+
it('adds the correct tabindex to RadioInputs when checked', async () => {
|
|
201
|
+
const _render7 = render(_RadioInputGroup4 || (_RadioInputGroup4 = /*#__PURE__*/React.createElement(RadioInputGroup, {
|
|
202
|
+
name: "fruit",
|
|
203
|
+
description: "Select a fruit",
|
|
204
|
+
defaultValue: "banana"
|
|
205
|
+
}, /*#__PURE__*/React.createElement(RadioInput, {
|
|
206
|
+
label: "Apple",
|
|
207
|
+
value: "apple"
|
|
208
|
+
}), /*#__PURE__*/React.createElement(RadioInput, {
|
|
209
|
+
label: "Banana",
|
|
210
|
+
value: "banana"
|
|
211
|
+
}), /*#__PURE__*/React.createElement(RadioInput, {
|
|
212
|
+
label: "Orange",
|
|
213
|
+
value: "orange"
|
|
214
|
+
})))),
|
|
215
|
+
container = _render7.container;
|
|
216
|
+
const inputs = container.querySelectorAll('input[name="fruit"]');
|
|
217
|
+
expect(inputs[0]).toHaveAttribute('tabindex', '-1');
|
|
218
|
+
expect(inputs[1]).toHaveAttribute('tabindex', '0');
|
|
219
|
+
expect(inputs[2]).toHaveAttribute('tabindex', '-1');
|
|
220
|
+
});
|
|
221
|
+
describe('for a11y', () => {
|
|
222
|
+
it('should meet a11y standards', async () => {
|
|
223
|
+
const _render8 = render(_RadioInputGroup5 || (_RadioInputGroup5 = /*#__PURE__*/React.createElement(RadioInputGroup, {
|
|
224
|
+
name: "fruit",
|
|
225
|
+
description: "Select a fruit"
|
|
226
|
+
}, /*#__PURE__*/React.createElement(RadioInput, {
|
|
227
|
+
label: "Apple",
|
|
228
|
+
value: "apple"
|
|
229
|
+
}), /*#__PURE__*/React.createElement(RadioInput, {
|
|
230
|
+
label: "Banana",
|
|
231
|
+
value: "banana"
|
|
232
|
+
}), /*#__PURE__*/React.createElement(RadioInput, {
|
|
233
|
+
label: "Orange",
|
|
234
|
+
value: "orange"
|
|
235
|
+
})))),
|
|
236
|
+
container = _render8.container;
|
|
237
|
+
const axeCheck = await runAxeCheck(container);
|
|
238
|
+
expect(axeCheck).toBe(true);
|
|
239
|
+
});
|
|
240
|
+
});
|
|
241
|
+
});
|