@instructure/ui-checkbox 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.
Files changed (23) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/package.json +19 -19
  3. package/tsconfig.build.tsbuildinfo +1 -1
  4. package/es/Checkbox/CheckboxFacade/__new-tests__/CheckboxFacade.test.js +0 -60
  5. package/es/Checkbox/ToggleFacade/__new-tests__/ToggleFacade.test.js +0 -60
  6. package/es/Checkbox/__new-tests__/Checkbox.test.js +0 -234
  7. package/es/CheckboxGroup/__new-tests__/CheckboxGroup.test.js +0 -228
  8. package/lib/Checkbox/CheckboxFacade/__new-tests__/CheckboxFacade.test.js +0 -61
  9. package/lib/Checkbox/ToggleFacade/__new-tests__/ToggleFacade.test.js +0 -61
  10. package/lib/Checkbox/__new-tests__/Checkbox.test.js +0 -237
  11. package/lib/CheckboxGroup/__new-tests__/CheckboxGroup.test.js +0 -230
  12. package/src/Checkbox/CheckboxFacade/__new-tests__/CheckboxFacade.test.tsx +0 -66
  13. package/src/Checkbox/ToggleFacade/__new-tests__/ToggleFacade.test.tsx +0 -66
  14. package/src/Checkbox/__new-tests__/Checkbox.test.tsx +0 -248
  15. package/src/CheckboxGroup/__new-tests__/CheckboxGroup.test.tsx +0 -236
  16. package/types/Checkbox/CheckboxFacade/__new-tests__/CheckboxFacade.test.d.ts +0 -2
  17. package/types/Checkbox/CheckboxFacade/__new-tests__/CheckboxFacade.test.d.ts.map +0 -1
  18. package/types/Checkbox/ToggleFacade/__new-tests__/ToggleFacade.test.d.ts +0 -2
  19. package/types/Checkbox/ToggleFacade/__new-tests__/ToggleFacade.test.d.ts.map +0 -1
  20. package/types/Checkbox/__new-tests__/Checkbox.test.d.ts +0 -2
  21. package/types/Checkbox/__new-tests__/Checkbox.test.d.ts.map +0 -1
  22. package/types/CheckboxGroup/__new-tests__/CheckboxGroup.test.d.ts +0 -2
  23. package/types/CheckboxGroup/__new-tests__/CheckboxGroup.test.d.ts.map +0 -1
@@ -1,61 +0,0 @@
1
- "use strict";
2
-
3
- var _react = require("@testing-library/react");
4
- var _vitest = require("vitest");
5
- require("@testing-library/jest-dom");
6
- var _runAxeCheck = require("@instructure/ui-axe-check/lib/runAxeCheck.js");
7
- var _index = require("../index");
8
- var _jsxRuntime = require("@emotion/react/jsx-runtime");
9
- var _ToggleFacade, _ToggleFacade2;
10
- /*
11
- * The MIT License (MIT)
12
- *
13
- * Copyright (c) 2015 - present Instructure, Inc.
14
- *
15
- * Permission is hereby granted, free of charge, to any person obtaining a copy
16
- * of this software and associated documentation files (the "Software"), to deal
17
- * in the Software without restriction, including without limitation the rights
18
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
19
- * copies of the Software, and to permit persons to whom the Software is
20
- * furnished to do so, subject to the following conditions:
21
- *
22
- * The above copyright notice and this permission notice shall be included in all
23
- * copies or substantial portions of the Software.
24
- *
25
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
26
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
27
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
28
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
29
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
30
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
31
- * SOFTWARE.
32
- */
33
- const TEST_TEXT = 'test-text';
34
- describe('<ToggleFacade />', () => {
35
- let consoleWarningMock;
36
- let consoleErrorMock;
37
- beforeEach(() => {
38
- // Mocking console to prevent test output pollution
39
- consoleWarningMock = _vitest.vi.spyOn(console, 'warn').mockImplementation(() => {});
40
- consoleErrorMock = _vitest.vi.spyOn(console, 'error').mockImplementation(() => {});
41
- });
42
- afterEach(() => {
43
- consoleWarningMock.mockRestore();
44
- consoleErrorMock.mockRestore();
45
- });
46
- it('should render', () => {
47
- (0, _react.render)(_ToggleFacade || (_ToggleFacade = (0, _jsxRuntime.jsx)(_index.ToggleFacade, {
48
- children: TEST_TEXT
49
- })));
50
- const facade = _react.screen.getByText(TEST_TEXT);
51
- expect(facade).toBeInTheDocument();
52
- });
53
- it('should meet a11y standards', async () => {
54
- const _render = (0, _react.render)(_ToggleFacade2 || (_ToggleFacade2 = (0, _jsxRuntime.jsx)(_index.ToggleFacade, {
55
- children: TEST_TEXT
56
- }))),
57
- container = _render.container;
58
- const axeCheck = await (0, _runAxeCheck.runAxeCheck)(container);
59
- expect(axeCheck).toBe(true);
60
- });
61
- });
@@ -1,237 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
- var _react = require("react");
5
- var _react2 = require("@testing-library/react");
6
- var _vitest = require("vitest");
7
- var _userEvent = _interopRequireDefault(require("@testing-library/user-event"));
8
- require("@testing-library/jest-dom");
9
- var _runAxeCheck = require("@instructure/ui-axe-check/lib/runAxeCheck.js");
10
- var _index = require("../index");
11
- var _jsxRuntime = require("@emotion/react/jsx-runtime");
12
- /*
13
- * The MIT License (MIT)
14
- *
15
- * Copyright (c) 2015 - present Instructure, Inc.
16
- *
17
- * Permission is hereby granted, free of charge, to any person obtaining a copy
18
- * of this software and associated documentation files (the "Software"), to deal
19
- * in the Software without restriction, including without limitation the rights
20
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
21
- * copies of the Software, and to permit persons to whom the Software is
22
- * furnished to do so, subject to the following conditions:
23
- *
24
- * The above copyright notice and this permission notice shall be included in all
25
- * copies or substantial portions of the Software.
26
- *
27
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
28
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
29
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
30
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
31
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
32
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
33
- * SOFTWARE.
34
- */
35
-
36
- const TEST_VALUE = 'test-value';
37
- const TEST_NAME = 'test-name';
38
- const TEST_LABEL = 'test-label';
39
- const initProps = {
40
- label: TEST_LABEL,
41
- defaultChecked: true,
42
- value: TEST_VALUE,
43
- name: TEST_NAME
44
- };
45
- const renderCheckbox = props => {
46
- const allProps = {
47
- ...initProps,
48
- ...props
49
- };
50
- return (0, _react2.render)((0, _jsxRuntime.jsx)(_index.Checkbox, {
51
- ...allProps
52
- }));
53
- };
54
- describe('<Checkbox />', () => {
55
- let consoleWarningMock;
56
- let consoleErrorMock;
57
- beforeEach(() => {
58
- // Mocking console to prevent test output pollution
59
- consoleWarningMock = _vitest.vi.spyOn(console, 'warn').mockImplementation(() => {});
60
- consoleErrorMock = _vitest.vi.spyOn(console, 'error').mockImplementation(() => {});
61
- });
62
- afterEach(() => {
63
- consoleWarningMock.mockRestore();
64
- consoleErrorMock.mockRestore();
65
- });
66
- it('renders an input with type "checkbox"', () => {
67
- renderCheckbox();
68
- const inputElem = _react2.screen.getByRole('checkbox');
69
- expect(inputElem).toBeInTheDocument();
70
- expect(inputElem.tagName).toBe('INPUT');
71
- expect(inputElem).toHaveAttribute('type', 'checkbox');
72
- });
73
- it('`simple` variant only displays a checkmark when checked', async () => {
74
- const _renderCheckbox = renderCheckbox({
75
- variant: 'simple',
76
- defaultChecked: false
77
- }),
78
- container = _renderCheckbox.container;
79
- const checkboxElement = container.querySelector('input[type="checkbox"]');
80
- const svgElement = container.querySelector('svg');
81
- expect(svgElement).not.toBeInTheDocument();
82
- _userEvent.default.click(checkboxElement);
83
- await (0, _react2.waitFor)(() => {
84
- const svgElementAfterClick = container.querySelector('svg');
85
- expect(svgElementAfterClick).toBeInTheDocument();
86
- });
87
- });
88
- it('`simple` variant supports indeterminate/mixed state', () => {
89
- renderCheckbox({
90
- variant: 'simple',
91
- indeterminate: true
92
- });
93
- const inputElem = _react2.screen.getByRole('checkbox');
94
- expect(inputElem).toBeInTheDocument();
95
- expect(inputElem).toHaveAttribute('aria-checked', 'mixed');
96
- });
97
- it('should provide an inputRef prop', async () => {
98
- const inputRef = _vitest.vi.fn();
99
- renderCheckbox({
100
- inputRef
101
- });
102
- const input = _react2.screen.getByRole('checkbox');
103
- expect(inputRef).toHaveBeenCalledWith(input);
104
- });
105
- describe('events', () => {
106
- it('when clicked, fires onClick and onChange events', async () => {
107
- const onClick = _vitest.vi.fn();
108
- const onChange = _vitest.vi.fn();
109
- renderCheckbox({
110
- onClick,
111
- onChange
112
- });
113
- const checkboxElement = _react2.screen.getByRole('checkbox');
114
- _userEvent.default.click(checkboxElement);
115
- await (0, _react2.waitFor)(() => {
116
- expect(onClick).toHaveBeenCalled();
117
- expect(onChange).toHaveBeenCalled();
118
- });
119
- });
120
- it('when clicked, does not call onClick or onChange when disabled', async () => {
121
- const onClick = _vitest.vi.fn();
122
- const onChange = _vitest.vi.fn();
123
- renderCheckbox({
124
- onClick,
125
- onChange,
126
- disabled: true
127
- });
128
- const checkboxElement = _react2.screen.getByRole('checkbox');
129
- _react2.fireEvent.click(checkboxElement);
130
- await (0, _react2.waitFor)(() => {
131
- expect(onClick).not.toHaveBeenCalled();
132
- expect(onChange).not.toHaveBeenCalled();
133
- expect(checkboxElement).toBeDisabled();
134
- });
135
- });
136
- it('when clicked, does not call onClick or onChange when readOnly', async () => {
137
- const onClick = _vitest.vi.fn();
138
- const onChange = _vitest.vi.fn();
139
- renderCheckbox({
140
- onClick,
141
- onChange,
142
- readOnly: true
143
- });
144
- const checkboxElement = _react2.screen.getByRole('checkbox');
145
- _react2.fireEvent.click(checkboxElement);
146
- await (0, _react2.waitFor)(() => {
147
- expect(onClick).not.toHaveBeenCalled();
148
- expect(onChange).not.toHaveBeenCalled();
149
- });
150
- });
151
- it('calls onChange when enter key is pressed', async () => {
152
- const onChange = _vitest.vi.fn();
153
- renderCheckbox({
154
- onChange
155
- });
156
- const checkboxElement = _react2.screen.getByRole('checkbox');
157
- _userEvent.default.type(checkboxElement, '{enter}');
158
- await (0, _react2.waitFor)(() => {
159
- expect(onChange).toHaveBeenCalled();
160
- });
161
- });
162
- it('responds to onBlur event', async () => {
163
- const onBlur = _vitest.vi.fn();
164
- renderCheckbox({
165
- onBlur
166
- });
167
- _userEvent.default.tab();
168
- _userEvent.default.tab();
169
- await (0, _react2.waitFor)(() => {
170
- expect(onBlur).toHaveBeenCalled();
171
- });
172
- });
173
- it('responds to onFocus event', async () => {
174
- const onFocus = _vitest.vi.fn();
175
- renderCheckbox({
176
- onFocus
177
- });
178
- _userEvent.default.tab();
179
- await (0, _react2.waitFor)(() => {
180
- expect(onFocus).toHaveBeenCalled();
181
- });
182
- });
183
- it('focuses with the focus helper', () => {
184
- var _checkboxRef$current;
185
- const checkboxRef = /*#__PURE__*/(0, _react.createRef)();
186
- (0, _react2.render)((0, _jsxRuntime.jsx)(_index.Checkbox, {
187
- ref: checkboxRef,
188
- ...initProps
189
- }));
190
- const checkboxElement = _react2.screen.getByRole('checkbox');
191
- expect(checkboxElement).not.toHaveFocus();
192
- (_checkboxRef$current = checkboxRef.current) === null || _checkboxRef$current === void 0 ? void 0 : _checkboxRef$current.focus();
193
- expect(checkboxElement).toHaveFocus();
194
- });
195
- it('calls onMouseOver', async () => {
196
- const onMouseOver = _vitest.vi.fn();
197
- renderCheckbox({
198
- onMouseOver
199
- });
200
- const checkboxElement = _react2.screen.getByRole('checkbox');
201
- _userEvent.default.hover(checkboxElement);
202
- await (0, _react2.waitFor)(() => {
203
- expect(onMouseOver).toHaveBeenCalled();
204
- });
205
- });
206
- it('calls onMouseOut', async () => {
207
- const onMouseOut = _vitest.vi.fn();
208
- renderCheckbox({
209
- onMouseOut
210
- });
211
- const checkboxElement = _react2.screen.getByRole('checkbox');
212
- _userEvent.default.hover(checkboxElement);
213
- _userEvent.default.unhover(checkboxElement);
214
- await (0, _react2.waitFor)(() => {
215
- expect(onMouseOut).toHaveBeenCalled();
216
- });
217
- });
218
- });
219
- describe('for a11y', () => {
220
- it('`simple` variant should meet standards', async () => {
221
- const _renderCheckbox2 = renderCheckbox({
222
- variant: 'simple'
223
- }),
224
- container = _renderCheckbox2.container;
225
- const axeCheck = await (0, _runAxeCheck.runAxeCheck)(container);
226
- expect(axeCheck).toBe(true);
227
- });
228
- it('`toggle` variant should meet standards', async () => {
229
- const _renderCheckbox3 = renderCheckbox({
230
- variant: 'toggle'
231
- }),
232
- container = _renderCheckbox3.container;
233
- const axeCheck = await (0, _runAxeCheck.runAxeCheck)(container);
234
- expect(axeCheck).toBe(true);
235
- });
236
- });
237
- });
@@ -1,230 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
- var _react = require("@testing-library/react");
5
- var _vitest = require("vitest");
6
- var _userEvent = _interopRequireDefault(require("@testing-library/user-event"));
7
- require("@testing-library/jest-dom");
8
- var _runAxeCheck = require("@instructure/ui-axe-check/lib/runAxeCheck.js");
9
- var _index = require("../index");
10
- var _Checkbox3 = require("../../Checkbox");
11
- var _jsxRuntime = require("@emotion/react/jsx-runtime");
12
- var _Checkbox, _Checkbox2;
13
- /*
14
- * The MIT License (MIT)
15
- *
16
- * Copyright (c) 2015 - present Instructure, Inc.
17
- *
18
- * Permission is hereby granted, free of charge, to any person obtaining a copy
19
- * of this software and associated documentation files (the "Software"), to deal
20
- * in the Software without restriction, including without limitation the rights
21
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
22
- * copies of the Software, and to permit persons to whom the Software is
23
- * furnished to do so, subject to the following conditions:
24
- *
25
- * The above copyright notice and this permission notice shall be included in all
26
- * copies or substantial portions of the Software.
27
- *
28
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
29
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
30
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
31
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
32
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
33
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
34
- * SOFTWARE.
35
- */
36
- const TEST_NAME = 'test-name';
37
- const TEST_DESCRIPTION = 'test-description';
38
- const TEST_ERROR_MESSAGE = 'test-error-message';
39
- const TEST_VALUE_1 = 'test-value-1';
40
- const TEST_VALUE_2 = 'test-value-2';
41
- const TEST_LABEL_1 = 'test-label-1';
42
- const TEST_LABEL_2 = 'test-label-2';
43
- const renderCheckboxGroup = props => {
44
- const allProps = {
45
- name: TEST_NAME,
46
- description: TEST_DESCRIPTION,
47
- ...props
48
- };
49
- return (0, _react.render)((0, _jsxRuntime.jsxs)(_index.CheckboxGroup, {
50
- ...allProps,
51
- children: [_Checkbox || (_Checkbox = (0, _jsxRuntime.jsx)(_Checkbox3.Checkbox, {
52
- label: TEST_LABEL_1,
53
- value: TEST_VALUE_1
54
- })), _Checkbox2 || (_Checkbox2 = (0, _jsxRuntime.jsx)(_Checkbox3.Checkbox, {
55
- label: TEST_LABEL_2,
56
- value: TEST_VALUE_2
57
- }))]
58
- }));
59
- };
60
- describe('<CheckboxGroup />', () => {
61
- let consoleWarningMock;
62
- let consoleErrorMock;
63
- beforeEach(() => {
64
- // Mocking console to prevent test output pollution
65
- consoleWarningMock = _vitest.vi.spyOn(console, 'warn').mockImplementation(() => {});
66
- consoleErrorMock = _vitest.vi.spyOn(console, 'error').mockImplementation(() => {});
67
- });
68
- afterEach(() => {
69
- consoleWarningMock.mockRestore();
70
- consoleErrorMock.mockRestore();
71
- });
72
- it('adds the name props to all Checkbox types', () => {
73
- renderCheckboxGroup({
74
- name: TEST_NAME
75
- });
76
- const checkboxes = _react.screen.getAllByRole('checkbox');
77
- expect(checkboxes.length).toBe(2);
78
- expect(checkboxes[0]).toHaveAttribute('name', TEST_NAME);
79
- expect(checkboxes[1]).toHaveAttribute('name', TEST_NAME);
80
- });
81
- it('links the messages to the fieldset via aria-describedby', () => {
82
- const _renderCheckboxGroup = renderCheckboxGroup({
83
- messages: [{
84
- text: TEST_ERROR_MESSAGE,
85
- type: 'error'
86
- }]
87
- }),
88
- container = _renderCheckboxGroup.container;
89
- const group = _react.screen.getByRole('group');
90
- const ariaDesc = group.getAttribute('aria-describedby');
91
- const messageById = container.querySelector(`[id="${ariaDesc}"]`);
92
- expect(messageById).toBeInTheDocument();
93
- expect(messageById).toHaveTextContent(TEST_ERROR_MESSAGE);
94
- });
95
- it('displays description message inside the legend', () => {
96
- const _renderCheckboxGroup2 = renderCheckboxGroup({
97
- description: TEST_DESCRIPTION
98
- }),
99
- container = _renderCheckboxGroup2.container;
100
- const legend = container.querySelector('span[class$="-formFieldLayout__label"]');
101
- expect(legend).toBeInTheDocument();
102
- expect(legend).toHaveTextContent(TEST_DESCRIPTION);
103
- });
104
- it('does not call the onChange prop when disabled', async () => {
105
- const onChange = _vitest.vi.fn();
106
- renderCheckboxGroup({
107
- onChange,
108
- disabled: true
109
- });
110
- const checkboxElement = _react.screen.getAllByRole('checkbox')[0];
111
- _react.fireEvent.click(checkboxElement);
112
- await (0, _react.waitFor)(() => {
113
- expect(onChange).not.toHaveBeenCalled();
114
- expect(checkboxElement).toBeDisabled();
115
- });
116
- });
117
- it('does not call the onChange prop when readOnly', async () => {
118
- const onChange = _vitest.vi.fn();
119
- renderCheckboxGroup({
120
- onChange,
121
- readOnly: true
122
- });
123
- const checkboxElement = _react.screen.getAllByRole('checkbox')[0];
124
- _react.fireEvent.click(checkboxElement);
125
- await (0, _react.waitFor)(() => {
126
- expect(onChange).not.toHaveBeenCalled();
127
- expect(checkboxElement).toBeDisabled();
128
- });
129
- });
130
- it('should not update the value when the value prop is set', async () => {
131
- const onChange = _vitest.vi.fn();
132
- renderCheckboxGroup({
133
- onChange,
134
- value: ['tester']
135
- });
136
- const checkboxes = _react.screen.getAllByRole('checkbox');
137
- expect(checkboxes[0]).not.toBeChecked();
138
- expect(checkboxes[1]).not.toBeChecked();
139
- _userEvent.default.click(checkboxes[0]);
140
- await (0, _react.waitFor)(() => {
141
- expect(onChange).not.toHaveBeenCalled();
142
- expect(checkboxes[0]).not.toBeChecked();
143
- expect(checkboxes[1]).not.toBeChecked();
144
- });
145
- });
146
- it('should add the checkbox value to the value list when it is checked', async () => {
147
- const onChange = _vitest.vi.fn();
148
- renderCheckboxGroup({
149
- onChange
150
- });
151
- const checkboxes = _react.screen.getAllByRole('checkbox');
152
- expect(checkboxes[0]).not.toBeChecked();
153
- expect(checkboxes[1]).not.toBeChecked();
154
- _userEvent.default.click(checkboxes[0]);
155
- _userEvent.default.click(checkboxes[1]);
156
- await (0, _react.waitFor)(() => {
157
- expect(checkboxes[0]).toBeChecked();
158
- expect(checkboxes[1]).toBeChecked();
159
- expect(onChange).toHaveBeenCalledWith([TEST_VALUE_1, TEST_VALUE_2]);
160
- });
161
- });
162
- it('should check the checkboxes based on the defaultValue prop', () => {
163
- const defaultValue = [TEST_VALUE_2];
164
- renderCheckboxGroup({
165
- defaultValue
166
- });
167
- const checkboxes = _react.screen.getAllByRole('checkbox');
168
- expect(checkboxes[0]).not.toBeChecked();
169
- expect(checkboxes[1]).toBeChecked();
170
- });
171
- it('should remove the checkbox value from the value list when it is unchecked', async () => {
172
- const onChange = _vitest.vi.fn();
173
- const defaultValue = [TEST_VALUE_1, TEST_VALUE_2];
174
- renderCheckboxGroup({
175
- onChange,
176
- defaultValue
177
- });
178
- const checkboxes = _react.screen.getAllByRole('checkbox');
179
- expect(checkboxes[0]).toBeChecked();
180
- expect(checkboxes[1]).toBeChecked();
181
- _userEvent.default.click(checkboxes[0]);
182
- await (0, _react.waitFor)(() => {
183
- expect(checkboxes[0]).not.toBeChecked();
184
- expect(checkboxes[1]).toBeChecked();
185
- expect(onChange).toHaveBeenCalledWith([TEST_VALUE_2]);
186
- });
187
- });
188
- it('passes the array of selected values to onChange handler', async () => {
189
- const onChange = _vitest.vi.fn();
190
- const defaultValue = [TEST_VALUE_2];
191
- renderCheckboxGroup({
192
- onChange,
193
- defaultValue
194
- });
195
- const checkboxes = _react.screen.getAllByRole('checkbox');
196
- expect(checkboxes[0]).not.toBeChecked();
197
- expect(checkboxes[1]).toBeChecked();
198
- _userEvent.default.click(checkboxes[0]);
199
- await (0, _react.waitFor)(() => {
200
- expect(checkboxes[0]).toBeChecked();
201
- expect(checkboxes[1]).toBeChecked();
202
- expect(onChange).toHaveBeenCalledWith([TEST_VALUE_2, TEST_VALUE_1]);
203
- });
204
- });
205
- describe('for a11y', () => {
206
- it('should meet standards', async () => {
207
- const _renderCheckboxGroup3 = renderCheckboxGroup(),
208
- container = _renderCheckboxGroup3.container;
209
- const axeCheck = await (0, _runAxeCheck.runAxeCheck)(container);
210
- expect(axeCheck).toBe(true);
211
- });
212
- it('adds the correct ARIA attributes', () => {
213
- const _renderCheckboxGroup4 = renderCheckboxGroup({
214
- disabled: true,
215
- messages: [{
216
- type: 'newError',
217
- text: 'abc'
218
- }],
219
- // @ts-ignore This is a valid attribute
220
- 'data-id': 'group'
221
- }),
222
- container = _renderCheckboxGroup4.container;
223
- const group = container.querySelector(`[data-id="group"]`);
224
- expect(group).toBeInTheDocument();
225
- expect(group).toHaveAttribute('aria-disabled', 'true');
226
- // ARIA role 'group' cannot have the 'aria-invalid' attribute
227
- expect(group).not.toHaveAttribute('aria-invalid');
228
- });
229
- });
230
- });
@@ -1,66 +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 } from '@testing-library/react'
26
- import { vi } from 'vitest'
27
- import '@testing-library/jest-dom'
28
-
29
- import { runAxeCheck } from '@instructure/ui-axe-check'
30
- import { CheckboxFacade } from '../index'
31
-
32
- const TEST_TEXT = 'test-text'
33
-
34
- describe('<CheckboxFacade />', () => {
35
- let consoleWarningMock: ReturnType<typeof vi.spyOn>
36
- let consoleErrorMock: ReturnType<typeof vi.spyOn>
37
-
38
- beforeEach(() => {
39
- // Mocking console to prevent test output pollution
40
- consoleWarningMock = vi
41
- .spyOn(console, 'warn')
42
- .mockImplementation(() => {}) as any
43
- consoleErrorMock = vi
44
- .spyOn(console, 'error')
45
- .mockImplementation(() => {}) as any
46
- })
47
-
48
- afterEach(() => {
49
- consoleWarningMock.mockRestore()
50
- consoleErrorMock.mockRestore()
51
- })
52
-
53
- it('should render', () => {
54
- render(<CheckboxFacade>{TEST_TEXT}</CheckboxFacade>)
55
- const facade = screen.getByText(TEST_TEXT)
56
-
57
- expect(facade).toBeInTheDocument()
58
- })
59
-
60
- it('should meet a11y standards', async () => {
61
- const { container } = render(<CheckboxFacade>{TEST_TEXT}</CheckboxFacade>)
62
- const axeCheck = await runAxeCheck(container)
63
-
64
- expect(axeCheck).toBe(true)
65
- })
66
- })
@@ -1,66 +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 } from '@testing-library/react'
26
- import { vi } from 'vitest'
27
- import '@testing-library/jest-dom'
28
-
29
- import { runAxeCheck } from '@instructure/ui-axe-check'
30
- import { ToggleFacade } from '../index'
31
-
32
- const TEST_TEXT = 'test-text'
33
-
34
- describe('<ToggleFacade />', () => {
35
- let consoleWarningMock: ReturnType<typeof vi.spyOn>
36
- let consoleErrorMock: ReturnType<typeof vi.spyOn>
37
-
38
- beforeEach(() => {
39
- // Mocking console to prevent test output pollution
40
- consoleWarningMock = vi
41
- .spyOn(console, 'warn')
42
- .mockImplementation(() => {}) as any
43
- consoleErrorMock = vi
44
- .spyOn(console, 'error')
45
- .mockImplementation(() => {}) as any
46
- })
47
-
48
- afterEach(() => {
49
- consoleWarningMock.mockRestore()
50
- consoleErrorMock.mockRestore()
51
- })
52
-
53
- it('should render', () => {
54
- render(<ToggleFacade>{TEST_TEXT}</ToggleFacade>)
55
- const facade = screen.getByText(TEST_TEXT)
56
-
57
- expect(facade).toBeInTheDocument()
58
- })
59
-
60
- it('should meet a11y standards', async () => {
61
- const { container } = render(<ToggleFacade>{TEST_TEXT}</ToggleFacade>)
62
- const axeCheck = await runAxeCheck(container)
63
-
64
- expect(axeCheck).toBe(true)
65
- })
66
- })