@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,60 +0,0 @@
1
- var _CheckboxFacade, _CheckboxFacade2;
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 { render, screen } from '@testing-library/react';
27
- import { vi } from 'vitest';
28
- import '@testing-library/jest-dom';
29
- import { runAxeCheck } from '@instructure/ui-axe-check';
30
- import { CheckboxFacade } from '../index';
31
- import { jsx as _jsx } from "@emotion/react/jsx-runtime";
32
- const TEST_TEXT = 'test-text';
33
- describe('<CheckboxFacade />', () => {
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('should render', () => {
46
- render(_CheckboxFacade || (_CheckboxFacade = _jsx(CheckboxFacade, {
47
- children: TEST_TEXT
48
- })));
49
- const facade = screen.getByText(TEST_TEXT);
50
- expect(facade).toBeInTheDocument();
51
- });
52
- it('should meet a11y standards', async () => {
53
- const _render = render(_CheckboxFacade2 || (_CheckboxFacade2 = _jsx(CheckboxFacade, {
54
- children: TEST_TEXT
55
- }))),
56
- container = _render.container;
57
- const axeCheck = await runAxeCheck(container);
58
- expect(axeCheck).toBe(true);
59
- });
60
- });
@@ -1,60 +0,0 @@
1
- var _ToggleFacade, _ToggleFacade2;
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 { render, screen } from '@testing-library/react';
27
- import { vi } from 'vitest';
28
- import '@testing-library/jest-dom';
29
- import { runAxeCheck } from '@instructure/ui-axe-check';
30
- import { ToggleFacade } from '../index';
31
- import { jsx as _jsx } from "@emotion/react/jsx-runtime";
32
- const TEST_TEXT = 'test-text';
33
- describe('<ToggleFacade />', () => {
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('should render', () => {
46
- render(_ToggleFacade || (_ToggleFacade = _jsx(ToggleFacade, {
47
- children: TEST_TEXT
48
- })));
49
- const facade = screen.getByText(TEST_TEXT);
50
- expect(facade).toBeInTheDocument();
51
- });
52
- it('should meet a11y standards', async () => {
53
- const _render = render(_ToggleFacade2 || (_ToggleFacade2 = _jsx(ToggleFacade, {
54
- children: TEST_TEXT
55
- }))),
56
- container = _render.container;
57
- const axeCheck = await runAxeCheck(container);
58
- expect(axeCheck).toBe(true);
59
- });
60
- });
@@ -1,234 +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 { createRef } from 'react';
26
- import { fireEvent, render, screen, waitFor } from '@testing-library/react';
27
- import { vi } from 'vitest';
28
- import userEvent from '@testing-library/user-event';
29
- import '@testing-library/jest-dom';
30
- import { runAxeCheck } from '@instructure/ui-axe-check';
31
- import { Checkbox } from '../index';
32
- import { jsx as _jsx } from "@emotion/react/jsx-runtime";
33
- const TEST_VALUE = 'test-value';
34
- const TEST_NAME = 'test-name';
35
- const TEST_LABEL = 'test-label';
36
- const initProps = {
37
- label: TEST_LABEL,
38
- defaultChecked: true,
39
- value: TEST_VALUE,
40
- name: TEST_NAME
41
- };
42
- const renderCheckbox = props => {
43
- const allProps = {
44
- ...initProps,
45
- ...props
46
- };
47
- return render(_jsx(Checkbox, {
48
- ...allProps
49
- }));
50
- };
51
- describe('<Checkbox />', () => {
52
- let consoleWarningMock;
53
- let consoleErrorMock;
54
- beforeEach(() => {
55
- // Mocking console to prevent test output pollution
56
- consoleWarningMock = vi.spyOn(console, 'warn').mockImplementation(() => {});
57
- consoleErrorMock = vi.spyOn(console, 'error').mockImplementation(() => {});
58
- });
59
- afterEach(() => {
60
- consoleWarningMock.mockRestore();
61
- consoleErrorMock.mockRestore();
62
- });
63
- it('renders an input with type "checkbox"', () => {
64
- renderCheckbox();
65
- const inputElem = screen.getByRole('checkbox');
66
- expect(inputElem).toBeInTheDocument();
67
- expect(inputElem.tagName).toBe('INPUT');
68
- expect(inputElem).toHaveAttribute('type', 'checkbox');
69
- });
70
- it('`simple` variant only displays a checkmark when checked', async () => {
71
- const _renderCheckbox = renderCheckbox({
72
- variant: 'simple',
73
- defaultChecked: false
74
- }),
75
- container = _renderCheckbox.container;
76
- const checkboxElement = container.querySelector('input[type="checkbox"]');
77
- const svgElement = container.querySelector('svg');
78
- expect(svgElement).not.toBeInTheDocument();
79
- userEvent.click(checkboxElement);
80
- await waitFor(() => {
81
- const svgElementAfterClick = container.querySelector('svg');
82
- expect(svgElementAfterClick).toBeInTheDocument();
83
- });
84
- });
85
- it('`simple` variant supports indeterminate/mixed state', () => {
86
- renderCheckbox({
87
- variant: 'simple',
88
- indeterminate: true
89
- });
90
- const inputElem = screen.getByRole('checkbox');
91
- expect(inputElem).toBeInTheDocument();
92
- expect(inputElem).toHaveAttribute('aria-checked', 'mixed');
93
- });
94
- it('should provide an inputRef prop', async () => {
95
- const inputRef = vi.fn();
96
- renderCheckbox({
97
- inputRef
98
- });
99
- const input = screen.getByRole('checkbox');
100
- expect(inputRef).toHaveBeenCalledWith(input);
101
- });
102
- describe('events', () => {
103
- it('when clicked, fires onClick and onChange events', async () => {
104
- const onClick = vi.fn();
105
- const onChange = vi.fn();
106
- renderCheckbox({
107
- onClick,
108
- onChange
109
- });
110
- const checkboxElement = screen.getByRole('checkbox');
111
- userEvent.click(checkboxElement);
112
- await waitFor(() => {
113
- expect(onClick).toHaveBeenCalled();
114
- expect(onChange).toHaveBeenCalled();
115
- });
116
- });
117
- it('when clicked, does not call onClick or onChange when disabled', async () => {
118
- const onClick = vi.fn();
119
- const onChange = vi.fn();
120
- renderCheckbox({
121
- onClick,
122
- onChange,
123
- disabled: true
124
- });
125
- const checkboxElement = screen.getByRole('checkbox');
126
- fireEvent.click(checkboxElement);
127
- await waitFor(() => {
128
- expect(onClick).not.toHaveBeenCalled();
129
- expect(onChange).not.toHaveBeenCalled();
130
- expect(checkboxElement).toBeDisabled();
131
- });
132
- });
133
- it('when clicked, does not call onClick or onChange when readOnly', async () => {
134
- const onClick = vi.fn();
135
- const onChange = vi.fn();
136
- renderCheckbox({
137
- onClick,
138
- onChange,
139
- readOnly: true
140
- });
141
- const checkboxElement = screen.getByRole('checkbox');
142
- fireEvent.click(checkboxElement);
143
- await waitFor(() => {
144
- expect(onClick).not.toHaveBeenCalled();
145
- expect(onChange).not.toHaveBeenCalled();
146
- });
147
- });
148
- it('calls onChange when enter key is pressed', async () => {
149
- const onChange = vi.fn();
150
- renderCheckbox({
151
- onChange
152
- });
153
- const checkboxElement = screen.getByRole('checkbox');
154
- userEvent.type(checkboxElement, '{enter}');
155
- await waitFor(() => {
156
- expect(onChange).toHaveBeenCalled();
157
- });
158
- });
159
- it('responds to onBlur event', async () => {
160
- const onBlur = vi.fn();
161
- renderCheckbox({
162
- onBlur
163
- });
164
- userEvent.tab();
165
- userEvent.tab();
166
- await waitFor(() => {
167
- expect(onBlur).toHaveBeenCalled();
168
- });
169
- });
170
- it('responds to onFocus event', async () => {
171
- const onFocus = vi.fn();
172
- renderCheckbox({
173
- onFocus
174
- });
175
- userEvent.tab();
176
- await waitFor(() => {
177
- expect(onFocus).toHaveBeenCalled();
178
- });
179
- });
180
- it('focuses with the focus helper', () => {
181
- var _checkboxRef$current;
182
- const checkboxRef = /*#__PURE__*/createRef();
183
- render(_jsx(Checkbox, {
184
- ref: checkboxRef,
185
- ...initProps
186
- }));
187
- const checkboxElement = screen.getByRole('checkbox');
188
- expect(checkboxElement).not.toHaveFocus();
189
- (_checkboxRef$current = checkboxRef.current) === null || _checkboxRef$current === void 0 ? void 0 : _checkboxRef$current.focus();
190
- expect(checkboxElement).toHaveFocus();
191
- });
192
- it('calls onMouseOver', async () => {
193
- const onMouseOver = vi.fn();
194
- renderCheckbox({
195
- onMouseOver
196
- });
197
- const checkboxElement = screen.getByRole('checkbox');
198
- userEvent.hover(checkboxElement);
199
- await waitFor(() => {
200
- expect(onMouseOver).toHaveBeenCalled();
201
- });
202
- });
203
- it('calls onMouseOut', async () => {
204
- const onMouseOut = vi.fn();
205
- renderCheckbox({
206
- onMouseOut
207
- });
208
- const checkboxElement = screen.getByRole('checkbox');
209
- userEvent.hover(checkboxElement);
210
- userEvent.unhover(checkboxElement);
211
- await waitFor(() => {
212
- expect(onMouseOut).toHaveBeenCalled();
213
- });
214
- });
215
- });
216
- describe('for a11y', () => {
217
- it('`simple` variant should meet standards', async () => {
218
- const _renderCheckbox2 = renderCheckbox({
219
- variant: 'simple'
220
- }),
221
- container = _renderCheckbox2.container;
222
- const axeCheck = await runAxeCheck(container);
223
- expect(axeCheck).toBe(true);
224
- });
225
- it('`toggle` variant should meet standards', async () => {
226
- const _renderCheckbox3 = renderCheckbox({
227
- variant: 'toggle'
228
- }),
229
- container = _renderCheckbox3.container;
230
- const axeCheck = await runAxeCheck(container);
231
- expect(axeCheck).toBe(true);
232
- });
233
- });
234
- });
@@ -1,228 +0,0 @@
1
- var _Checkbox, _Checkbox2;
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 { fireEvent, render, screen, waitFor } from '@testing-library/react';
27
- import { vi } from 'vitest';
28
- import userEvent from '@testing-library/user-event';
29
- import '@testing-library/jest-dom';
30
- import { runAxeCheck } from '@instructure/ui-axe-check';
31
- import { CheckboxGroup } from '../index';
32
- import { Checkbox } from '../../Checkbox';
33
- import { jsx as _jsx, jsxs as _jsxs } from "@emotion/react/jsx-runtime";
34
- const TEST_NAME = 'test-name';
35
- const TEST_DESCRIPTION = 'test-description';
36
- const TEST_ERROR_MESSAGE = 'test-error-message';
37
- const TEST_VALUE_1 = 'test-value-1';
38
- const TEST_VALUE_2 = 'test-value-2';
39
- const TEST_LABEL_1 = 'test-label-1';
40
- const TEST_LABEL_2 = 'test-label-2';
41
- const renderCheckboxGroup = props => {
42
- const allProps = {
43
- name: TEST_NAME,
44
- description: TEST_DESCRIPTION,
45
- ...props
46
- };
47
- return render(_jsxs(CheckboxGroup, {
48
- ...allProps,
49
- children: [_Checkbox || (_Checkbox = _jsx(Checkbox, {
50
- label: TEST_LABEL_1,
51
- value: TEST_VALUE_1
52
- })), _Checkbox2 || (_Checkbox2 = _jsx(Checkbox, {
53
- label: TEST_LABEL_2,
54
- value: TEST_VALUE_2
55
- }))]
56
- }));
57
- };
58
- describe('<CheckboxGroup />', () => {
59
- let consoleWarningMock;
60
- let consoleErrorMock;
61
- beforeEach(() => {
62
- // Mocking console to prevent test output pollution
63
- consoleWarningMock = vi.spyOn(console, 'warn').mockImplementation(() => {});
64
- consoleErrorMock = vi.spyOn(console, 'error').mockImplementation(() => {});
65
- });
66
- afterEach(() => {
67
- consoleWarningMock.mockRestore();
68
- consoleErrorMock.mockRestore();
69
- });
70
- it('adds the name props to all Checkbox types', () => {
71
- renderCheckboxGroup({
72
- name: TEST_NAME
73
- });
74
- const checkboxes = screen.getAllByRole('checkbox');
75
- expect(checkboxes.length).toBe(2);
76
- expect(checkboxes[0]).toHaveAttribute('name', TEST_NAME);
77
- expect(checkboxes[1]).toHaveAttribute('name', TEST_NAME);
78
- });
79
- it('links the messages to the fieldset via aria-describedby', () => {
80
- const _renderCheckboxGroup = renderCheckboxGroup({
81
- messages: [{
82
- text: TEST_ERROR_MESSAGE,
83
- type: 'error'
84
- }]
85
- }),
86
- container = _renderCheckboxGroup.container;
87
- const group = screen.getByRole('group');
88
- const ariaDesc = group.getAttribute('aria-describedby');
89
- const messageById = container.querySelector(`[id="${ariaDesc}"]`);
90
- expect(messageById).toBeInTheDocument();
91
- expect(messageById).toHaveTextContent(TEST_ERROR_MESSAGE);
92
- });
93
- it('displays description message inside the legend', () => {
94
- const _renderCheckboxGroup2 = renderCheckboxGroup({
95
- description: TEST_DESCRIPTION
96
- }),
97
- container = _renderCheckboxGroup2.container;
98
- const legend = container.querySelector('span[class$="-formFieldLayout__label"]');
99
- expect(legend).toBeInTheDocument();
100
- expect(legend).toHaveTextContent(TEST_DESCRIPTION);
101
- });
102
- it('does not call the onChange prop when disabled', async () => {
103
- const onChange = vi.fn();
104
- renderCheckboxGroup({
105
- onChange,
106
- disabled: true
107
- });
108
- const checkboxElement = screen.getAllByRole('checkbox')[0];
109
- fireEvent.click(checkboxElement);
110
- await waitFor(() => {
111
- expect(onChange).not.toHaveBeenCalled();
112
- expect(checkboxElement).toBeDisabled();
113
- });
114
- });
115
- it('does not call the onChange prop when readOnly', async () => {
116
- const onChange = vi.fn();
117
- renderCheckboxGroup({
118
- onChange,
119
- readOnly: true
120
- });
121
- const checkboxElement = screen.getAllByRole('checkbox')[0];
122
- fireEvent.click(checkboxElement);
123
- await waitFor(() => {
124
- expect(onChange).not.toHaveBeenCalled();
125
- expect(checkboxElement).toBeDisabled();
126
- });
127
- });
128
- it('should not update the value when the value prop is set', async () => {
129
- const onChange = vi.fn();
130
- renderCheckboxGroup({
131
- onChange,
132
- value: ['tester']
133
- });
134
- const checkboxes = screen.getAllByRole('checkbox');
135
- expect(checkboxes[0]).not.toBeChecked();
136
- expect(checkboxes[1]).not.toBeChecked();
137
- userEvent.click(checkboxes[0]);
138
- await waitFor(() => {
139
- expect(onChange).not.toHaveBeenCalled();
140
- expect(checkboxes[0]).not.toBeChecked();
141
- expect(checkboxes[1]).not.toBeChecked();
142
- });
143
- });
144
- it('should add the checkbox value to the value list when it is checked', async () => {
145
- const onChange = vi.fn();
146
- renderCheckboxGroup({
147
- onChange
148
- });
149
- const checkboxes = screen.getAllByRole('checkbox');
150
- expect(checkboxes[0]).not.toBeChecked();
151
- expect(checkboxes[1]).not.toBeChecked();
152
- userEvent.click(checkboxes[0]);
153
- userEvent.click(checkboxes[1]);
154
- await waitFor(() => {
155
- expect(checkboxes[0]).toBeChecked();
156
- expect(checkboxes[1]).toBeChecked();
157
- expect(onChange).toHaveBeenCalledWith([TEST_VALUE_1, TEST_VALUE_2]);
158
- });
159
- });
160
- it('should check the checkboxes based on the defaultValue prop', () => {
161
- const defaultValue = [TEST_VALUE_2];
162
- renderCheckboxGroup({
163
- defaultValue
164
- });
165
- const checkboxes = screen.getAllByRole('checkbox');
166
- expect(checkboxes[0]).not.toBeChecked();
167
- expect(checkboxes[1]).toBeChecked();
168
- });
169
- it('should remove the checkbox value from the value list when it is unchecked', async () => {
170
- const onChange = vi.fn();
171
- const defaultValue = [TEST_VALUE_1, TEST_VALUE_2];
172
- renderCheckboxGroup({
173
- onChange,
174
- defaultValue
175
- });
176
- const checkboxes = screen.getAllByRole('checkbox');
177
- expect(checkboxes[0]).toBeChecked();
178
- expect(checkboxes[1]).toBeChecked();
179
- userEvent.click(checkboxes[0]);
180
- await waitFor(() => {
181
- expect(checkboxes[0]).not.toBeChecked();
182
- expect(checkboxes[1]).toBeChecked();
183
- expect(onChange).toHaveBeenCalledWith([TEST_VALUE_2]);
184
- });
185
- });
186
- it('passes the array of selected values to onChange handler', async () => {
187
- const onChange = vi.fn();
188
- const defaultValue = [TEST_VALUE_2];
189
- renderCheckboxGroup({
190
- onChange,
191
- defaultValue
192
- });
193
- const checkboxes = screen.getAllByRole('checkbox');
194
- expect(checkboxes[0]).not.toBeChecked();
195
- expect(checkboxes[1]).toBeChecked();
196
- userEvent.click(checkboxes[0]);
197
- await waitFor(() => {
198
- expect(checkboxes[0]).toBeChecked();
199
- expect(checkboxes[1]).toBeChecked();
200
- expect(onChange).toHaveBeenCalledWith([TEST_VALUE_2, TEST_VALUE_1]);
201
- });
202
- });
203
- describe('for a11y', () => {
204
- it('should meet standards', async () => {
205
- const _renderCheckboxGroup3 = renderCheckboxGroup(),
206
- container = _renderCheckboxGroup3.container;
207
- const axeCheck = await runAxeCheck(container);
208
- expect(axeCheck).toBe(true);
209
- });
210
- it('adds the correct ARIA attributes', () => {
211
- const _renderCheckboxGroup4 = renderCheckboxGroup({
212
- disabled: true,
213
- messages: [{
214
- type: 'newError',
215
- text: 'abc'
216
- }],
217
- // @ts-ignore This is a valid attribute
218
- 'data-id': 'group'
219
- }),
220
- container = _renderCheckboxGroup4.container;
221
- const group = container.querySelector(`[data-id="group"]`);
222
- expect(group).toBeInTheDocument();
223
- expect(group).toHaveAttribute('aria-disabled', 'true');
224
- // ARIA role 'group' cannot have the 'aria-invalid' attribute
225
- expect(group).not.toHaveAttribute('aria-invalid');
226
- });
227
- });
228
- });
@@ -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 _CheckboxFacade, _CheckboxFacade2;
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('<CheckboxFacade />', () => {
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)(_CheckboxFacade || (_CheckboxFacade = (0, _jsxRuntime.jsx)(_index.CheckboxFacade, {
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)(_CheckboxFacade2 || (_CheckboxFacade2 = (0, _jsxRuntime.jsx)(_index.CheckboxFacade, {
55
- children: TEST_TEXT
56
- }))),
57
- container = _render.container;
58
- const axeCheck = await (0, _runAxeCheck.runAxeCheck)(container);
59
- expect(axeCheck).toBe(true);
60
- });
61
- });