@instructure/ui-checkbox 9.2.1-snapshot-0 → 9.2.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 +1 -1
- package/README.md +2 -2
- package/es/Checkbox/CheckboxFacade/__new-tests__/CheckboxFacade.test.js +12 -0
- package/es/Checkbox/ToggleFacade/__new-tests__/ToggleFacade.test.js +12 -0
- package/es/Checkbox/__new-tests__/Checkbox.test.js +23 -11
- package/es/CheckboxGroup/__new-tests__/CheckboxGroup.test.js +18 -6
- package/lib/Checkbox/CheckboxFacade/__new-tests__/CheckboxFacade.test.js +12 -0
- package/lib/Checkbox/ToggleFacade/__new-tests__/ToggleFacade.test.js +12 -0
- package/lib/Checkbox/__new-tests__/Checkbox.test.js +23 -11
- package/lib/CheckboxGroup/__new-tests__/CheckboxGroup.test.js +18 -6
- package/package.json +21 -20
- package/src/Checkbox/CheckboxFacade/__new-tests__/CheckboxFacade.test.tsx +19 -0
- package/src/Checkbox/ToggleFacade/__new-tests__/ToggleFacade.test.tsx +19 -0
- package/src/Checkbox/__new-tests__/Checkbox.test.tsx +30 -11
- package/src/CheckboxGroup/__new-tests__/CheckboxGroup.test.tsx +25 -6
- package/tsconfig.build.tsbuildinfo +1 -1
- package/types/Checkbox/CheckboxFacade/__new-tests__/CheckboxFacade.test.d.ts.map +1 -1
- package/types/Checkbox/ToggleFacade/__new-tests__/ToggleFacade.test.d.ts.map +1 -1
- package/types/Checkbox/__new-tests__/Checkbox.test.d.ts.map +1 -1
- package/types/CheckboxGroup/__new-tests__/CheckboxGroup.test.d.ts.map +1 -1
|
@@ -24,6 +24,7 @@
|
|
|
24
24
|
|
|
25
25
|
import React from 'react'
|
|
26
26
|
import { fireEvent, render, screen, waitFor } from '@testing-library/react'
|
|
27
|
+
import { vi } from 'vitest'
|
|
27
28
|
import userEvent from '@testing-library/user-event'
|
|
28
29
|
import '@testing-library/jest-dom'
|
|
29
30
|
|
|
@@ -51,6 +52,24 @@ const renderCheckbox = (props?: Partial<CheckboxProps>) => {
|
|
|
51
52
|
}
|
|
52
53
|
|
|
53
54
|
describe('<Checkbox />', () => {
|
|
55
|
+
let consoleWarningMock: ReturnType<typeof vi.spyOn>
|
|
56
|
+
let consoleErrorMock: ReturnType<typeof vi.spyOn>
|
|
57
|
+
|
|
58
|
+
beforeEach(() => {
|
|
59
|
+
// Mocking console to prevent test output pollution
|
|
60
|
+
consoleWarningMock = vi
|
|
61
|
+
.spyOn(console, 'warn')
|
|
62
|
+
.mockImplementation(() => {}) as any
|
|
63
|
+
consoleErrorMock = vi
|
|
64
|
+
.spyOn(console, 'error')
|
|
65
|
+
.mockImplementation(() => {}) as any
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
afterEach(() => {
|
|
69
|
+
consoleWarningMock.mockRestore()
|
|
70
|
+
consoleErrorMock.mockRestore()
|
|
71
|
+
})
|
|
72
|
+
|
|
54
73
|
it('renders an input with type "checkbox"', () => {
|
|
55
74
|
renderCheckbox()
|
|
56
75
|
const inputElem = screen.getByRole('checkbox')
|
|
@@ -88,8 +107,8 @@ describe('<Checkbox />', () => {
|
|
|
88
107
|
|
|
89
108
|
describe('events', () => {
|
|
90
109
|
it('when clicked, fires onClick and onChange events', async () => {
|
|
91
|
-
const onClick =
|
|
92
|
-
const onChange =
|
|
110
|
+
const onClick = vi.fn()
|
|
111
|
+
const onChange = vi.fn()
|
|
93
112
|
renderCheckbox({ onClick, onChange })
|
|
94
113
|
const checkboxElement = screen.getByRole('checkbox')
|
|
95
114
|
|
|
@@ -102,8 +121,8 @@ describe('<Checkbox />', () => {
|
|
|
102
121
|
})
|
|
103
122
|
|
|
104
123
|
it('when clicked, does not call onClick or onChange when disabled', async () => {
|
|
105
|
-
const onClick =
|
|
106
|
-
const onChange =
|
|
124
|
+
const onClick = vi.fn()
|
|
125
|
+
const onChange = vi.fn()
|
|
107
126
|
renderCheckbox({ onClick, onChange, disabled: true })
|
|
108
127
|
const checkboxElement = screen.getByRole('checkbox')
|
|
109
128
|
|
|
@@ -117,8 +136,8 @@ describe('<Checkbox />', () => {
|
|
|
117
136
|
})
|
|
118
137
|
|
|
119
138
|
it('when clicked, does not call onClick or onChange when readOnly', async () => {
|
|
120
|
-
const onClick =
|
|
121
|
-
const onChange =
|
|
139
|
+
const onClick = vi.fn()
|
|
140
|
+
const onChange = vi.fn()
|
|
122
141
|
renderCheckbox({ onClick, onChange, readOnly: true })
|
|
123
142
|
const checkboxElement = screen.getByRole('checkbox')
|
|
124
143
|
|
|
@@ -131,7 +150,7 @@ describe('<Checkbox />', () => {
|
|
|
131
150
|
})
|
|
132
151
|
|
|
133
152
|
it('calls onChange when enter key is pressed', async () => {
|
|
134
|
-
const onChange =
|
|
153
|
+
const onChange = vi.fn()
|
|
135
154
|
renderCheckbox({ onChange })
|
|
136
155
|
const checkboxElement = screen.getByRole('checkbox')
|
|
137
156
|
|
|
@@ -143,7 +162,7 @@ describe('<Checkbox />', () => {
|
|
|
143
162
|
})
|
|
144
163
|
|
|
145
164
|
it('responds to onBlur event', async () => {
|
|
146
|
-
const onBlur =
|
|
165
|
+
const onBlur = vi.fn()
|
|
147
166
|
renderCheckbox({ onBlur })
|
|
148
167
|
|
|
149
168
|
userEvent.tab()
|
|
@@ -155,7 +174,7 @@ describe('<Checkbox />', () => {
|
|
|
155
174
|
})
|
|
156
175
|
|
|
157
176
|
it('responds to onFocus event', async () => {
|
|
158
|
-
const onFocus =
|
|
177
|
+
const onFocus = vi.fn()
|
|
159
178
|
renderCheckbox({ onFocus })
|
|
160
179
|
|
|
161
180
|
userEvent.tab()
|
|
@@ -178,7 +197,7 @@ describe('<Checkbox />', () => {
|
|
|
178
197
|
})
|
|
179
198
|
|
|
180
199
|
it('calls onMouseOver', async () => {
|
|
181
|
-
const onMouseOver =
|
|
200
|
+
const onMouseOver = vi.fn()
|
|
182
201
|
renderCheckbox({ onMouseOver })
|
|
183
202
|
const checkboxElement = screen.getByRole('checkbox')
|
|
184
203
|
|
|
@@ -190,7 +209,7 @@ describe('<Checkbox />', () => {
|
|
|
190
209
|
})
|
|
191
210
|
|
|
192
211
|
it('calls onMouseOut', async () => {
|
|
193
|
-
const onMouseOut =
|
|
212
|
+
const onMouseOut = vi.fn()
|
|
194
213
|
renderCheckbox({ onMouseOut })
|
|
195
214
|
const checkboxElement = screen.getByRole('checkbox')
|
|
196
215
|
|
|
@@ -24,6 +24,7 @@
|
|
|
24
24
|
|
|
25
25
|
import React from 'react'
|
|
26
26
|
import { fireEvent, render, screen, waitFor } from '@testing-library/react'
|
|
27
|
+
import { vi } from 'vitest'
|
|
27
28
|
import userEvent from '@testing-library/user-event'
|
|
28
29
|
import '@testing-library/jest-dom'
|
|
29
30
|
|
|
@@ -56,6 +57,24 @@ const renderCheckboxGroup = (props?: Partial<CheckboxGroupProps>) => {
|
|
|
56
57
|
}
|
|
57
58
|
|
|
58
59
|
describe('<CheckboxGroup />', () => {
|
|
60
|
+
let consoleWarningMock: ReturnType<typeof vi.spyOn>
|
|
61
|
+
let consoleErrorMock: ReturnType<typeof vi.spyOn>
|
|
62
|
+
|
|
63
|
+
beforeEach(() => {
|
|
64
|
+
// Mocking console to prevent test output pollution
|
|
65
|
+
consoleWarningMock = vi
|
|
66
|
+
.spyOn(console, 'warn')
|
|
67
|
+
.mockImplementation(() => {}) as any
|
|
68
|
+
consoleErrorMock = vi
|
|
69
|
+
.spyOn(console, 'error')
|
|
70
|
+
.mockImplementation(() => {}) as any
|
|
71
|
+
})
|
|
72
|
+
|
|
73
|
+
afterEach(() => {
|
|
74
|
+
consoleWarningMock.mockRestore()
|
|
75
|
+
consoleErrorMock.mockRestore()
|
|
76
|
+
})
|
|
77
|
+
|
|
59
78
|
it('adds the name props to all Checkbox types', () => {
|
|
60
79
|
renderCheckboxGroup({ name: TEST_NAME })
|
|
61
80
|
const checkboxes = screen.getAllByRole('checkbox')
|
|
@@ -86,7 +105,7 @@ describe('<CheckboxGroup />', () => {
|
|
|
86
105
|
})
|
|
87
106
|
|
|
88
107
|
it('does not call the onChange prop when disabled', async () => {
|
|
89
|
-
const onChange =
|
|
108
|
+
const onChange = vi.fn()
|
|
90
109
|
renderCheckboxGroup({ onChange, disabled: true })
|
|
91
110
|
const checkboxElement = screen.getAllByRole('checkbox')[0]
|
|
92
111
|
|
|
@@ -99,7 +118,7 @@ describe('<CheckboxGroup />', () => {
|
|
|
99
118
|
})
|
|
100
119
|
|
|
101
120
|
it('does not call the onChange prop when readOnly', async () => {
|
|
102
|
-
const onChange =
|
|
121
|
+
const onChange = vi.fn()
|
|
103
122
|
renderCheckboxGroup({ onChange, readOnly: true })
|
|
104
123
|
const checkboxElement = screen.getAllByRole('checkbox')[0]
|
|
105
124
|
|
|
@@ -112,7 +131,7 @@ describe('<CheckboxGroup />', () => {
|
|
|
112
131
|
})
|
|
113
132
|
|
|
114
133
|
it('should not update the value when the value prop is set', async () => {
|
|
115
|
-
const onChange =
|
|
134
|
+
const onChange = vi.fn()
|
|
116
135
|
renderCheckboxGroup({ onChange, value: ['tester'] })
|
|
117
136
|
const checkboxes = screen.getAllByRole('checkbox')
|
|
118
137
|
|
|
@@ -129,7 +148,7 @@ describe('<CheckboxGroup />', () => {
|
|
|
129
148
|
})
|
|
130
149
|
|
|
131
150
|
it('should add the checkbox value to the value list when it is checked', async () => {
|
|
132
|
-
const onChange =
|
|
151
|
+
const onChange = vi.fn()
|
|
133
152
|
renderCheckboxGroup({ onChange })
|
|
134
153
|
const checkboxes = screen.getAllByRole('checkbox')
|
|
135
154
|
|
|
@@ -156,7 +175,7 @@ describe('<CheckboxGroup />', () => {
|
|
|
156
175
|
})
|
|
157
176
|
|
|
158
177
|
it('should remove the checkbox value from the value list when it is unchecked', async () => {
|
|
159
|
-
const onChange =
|
|
178
|
+
const onChange = vi.fn()
|
|
160
179
|
const defaultValue = [TEST_VALUE_1, TEST_VALUE_2]
|
|
161
180
|
renderCheckboxGroup({ onChange, defaultValue })
|
|
162
181
|
const checkboxes = screen.getAllByRole('checkbox')
|
|
@@ -174,7 +193,7 @@ describe('<CheckboxGroup />', () => {
|
|
|
174
193
|
})
|
|
175
194
|
|
|
176
195
|
it('passes the array of selected values to onChange handler', async () => {
|
|
177
|
-
const onChange =
|
|
196
|
+
const onChange = vi.fn()
|
|
178
197
|
const defaultValue = [TEST_VALUE_2]
|
|
179
198
|
renderCheckboxGroup({ onChange, defaultValue })
|
|
180
199
|
const checkboxes = screen.getAllByRole('checkbox')
|