@instructure/ui-number-input 10.2.2-snapshot-15 → 10.2.2-snapshot-16
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/es/NumberInput/__new-tests__/NumberInput.test.js +213 -10
- package/lib/NumberInput/__new-tests__/NumberInput.test.js +214 -13
- package/package.json +16 -15
- package/src/NumberInput/__new-tests__/NumberInput.test.tsx +234 -13
- package/tsconfig.build.json +0 -1
- package/tsconfig.build.tsbuildinfo +1 -1
- package/types/NumberInput/__new-tests__/NumberInput.test.d.ts +1 -1
- package/types/NumberInput/__new-tests__/NumberInput.test.d.ts.map +1 -1
- package/es/NumberInput/NumberInputLocator.js +0 -32
- package/es/NumberInput/locator.js +0 -27
- package/lib/NumberInput/NumberInputLocator.js +0 -37
- package/lib/NumberInput/locator.js +0 -37
- package/src/NumberInput/NumberInputLocator.ts +0 -34
- package/src/NumberInput/locator.ts +0 -28
- package/types/NumberInput/NumberInputLocator.d.ts +0 -1823
- package/types/NumberInput/NumberInputLocator.d.ts.map +0 -1
- package/types/NumberInput/locator.d.ts +0 -4
- package/types/NumberInput/locator.d.ts.map +0 -1
|
@@ -22,16 +22,19 @@
|
|
|
22
22
|
* SOFTWARE.
|
|
23
23
|
*/
|
|
24
24
|
|
|
25
|
-
import
|
|
25
|
+
import React from 'react'
|
|
26
|
+
import { render, screen, waitFor } from '@testing-library/react'
|
|
27
|
+
import userEvent from '@testing-library/user-event'
|
|
26
28
|
import { vi } from 'vitest'
|
|
27
|
-
|
|
28
29
|
import { runAxeCheck } from '@instructure/ui-axe-check'
|
|
30
|
+
import '@testing-library/jest-dom'
|
|
31
|
+
|
|
29
32
|
import { NumberInput } from '../index'
|
|
30
33
|
import NumberInputExamples from '../__examples__/NumberInput.examples'
|
|
31
34
|
// eslint-disable-next-line no-restricted-imports
|
|
32
35
|
import { generateA11yTests } from '@instructure/ui-scripts/lib/test/generateA11yTests'
|
|
33
36
|
|
|
34
|
-
describe('<
|
|
37
|
+
describe('<NumberInput />', () => {
|
|
35
38
|
let consoleWarningMock: ReturnType<typeof vi.spyOn>
|
|
36
39
|
let consoleErrorMock: ReturnType<typeof vi.spyOn>
|
|
37
40
|
|
|
@@ -50,15 +53,233 @@ describe('<Breadcrumb />', () => {
|
|
|
50
53
|
consoleErrorMock.mockRestore()
|
|
51
54
|
})
|
|
52
55
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
56
|
+
it('sets value on the input', async () => {
|
|
57
|
+
const onChange = vi.fn()
|
|
58
|
+
render(<NumberInput renderLabel="Label" onChange={onChange} value="42" />)
|
|
59
|
+
const input = screen.getByRole('spinbutton')
|
|
60
|
+
|
|
61
|
+
expect(input).toHaveValue(42)
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
it('should accept a number for the value', async () => {
|
|
65
|
+
const onChange = vi.fn()
|
|
66
|
+
render(<NumberInput renderLabel="Label" onChange={onChange} value={42} />)
|
|
67
|
+
const input = screen.getByRole('spinbutton')
|
|
68
|
+
|
|
69
|
+
expect(input).toHaveValue(42)
|
|
70
|
+
})
|
|
71
|
+
|
|
72
|
+
it('displays the label', async () => {
|
|
73
|
+
const { container } = render(<NumberInput renderLabel="Label" />)
|
|
74
|
+
const label = container.querySelector('span[class$="-formFieldLabel"]')
|
|
75
|
+
|
|
76
|
+
expect(label).toHaveTextContent('Label')
|
|
77
|
+
})
|
|
78
|
+
|
|
79
|
+
it('passes the input element to inputRef', async () => {
|
|
80
|
+
const inputRef = vi.fn()
|
|
81
|
+
render(<NumberInput renderLabel="Label" inputRef={inputRef} />)
|
|
82
|
+
const input = screen.getByRole('spinbutton')
|
|
83
|
+
|
|
84
|
+
expect(inputRef).toHaveBeenCalledTimes(1)
|
|
85
|
+
expect(inputRef).toHaveBeenCalledWith(input)
|
|
86
|
+
})
|
|
87
|
+
|
|
88
|
+
it('passes change events to onChange handler', async () => {
|
|
89
|
+
const onChange = vi.fn()
|
|
90
|
+
render(<NumberInput renderLabel="Label" onChange={onChange} />)
|
|
91
|
+
const input = screen.getByRole('spinbutton')
|
|
92
|
+
|
|
93
|
+
userEvent.type(input, '5')
|
|
94
|
+
|
|
95
|
+
await waitFor(() => {
|
|
96
|
+
const event = onChange.mock.calls[0][0]
|
|
97
|
+
const args = onChange.mock.calls[0][1]
|
|
98
|
+
expect(onChange).toHaveBeenCalledTimes(1)
|
|
99
|
+
expect(args).toBe('5')
|
|
100
|
+
expect(event.target.value).toBe('5')
|
|
101
|
+
})
|
|
102
|
+
})
|
|
103
|
+
|
|
104
|
+
it('passes keyboard events to the onKeyDown handler', async () => {
|
|
105
|
+
const onKeyDown = vi.fn()
|
|
106
|
+
render(<NumberInput renderLabel="Label" onKeyDown={onKeyDown} />)
|
|
107
|
+
const input = screen.getByRole('spinbutton')
|
|
108
|
+
|
|
109
|
+
userEvent.type(input, '5')
|
|
110
|
+
|
|
111
|
+
await waitFor(() => {
|
|
112
|
+
expect(onKeyDown).toHaveBeenCalledTimes(1)
|
|
113
|
+
})
|
|
114
|
+
})
|
|
115
|
+
|
|
116
|
+
it('passes blur events to onBlur handler', async () => {
|
|
117
|
+
const onBlur = vi.fn()
|
|
118
|
+
render(<NumberInput renderLabel="Label" onBlur={onBlur} />)
|
|
119
|
+
|
|
120
|
+
userEvent.tab()
|
|
121
|
+
userEvent.tab()
|
|
122
|
+
|
|
123
|
+
await waitFor(() => {
|
|
124
|
+
expect(onBlur).toHaveBeenCalledTimes(1)
|
|
125
|
+
})
|
|
126
|
+
})
|
|
127
|
+
|
|
128
|
+
it('passes focus events to onFocus handler', async () => {
|
|
129
|
+
const onFocus = vi.fn()
|
|
130
|
+
render(<NumberInput renderLabel="Label" onFocus={onFocus} />)
|
|
131
|
+
const input = screen.getByRole('spinbutton')
|
|
132
|
+
|
|
133
|
+
input.focus()
|
|
134
|
+
|
|
135
|
+
await waitFor(() => {
|
|
136
|
+
expect(onFocus).toHaveBeenCalledTimes(1)
|
|
137
|
+
})
|
|
138
|
+
})
|
|
139
|
+
|
|
140
|
+
it('shows arrow spinbuttons by default', async () => {
|
|
141
|
+
const { container } = render(<NumberInput renderLabel="Label" />)
|
|
142
|
+
const buttons = container.querySelectorAll(
|
|
143
|
+
'button[class$="-numberInput_arrow'
|
|
144
|
+
)
|
|
145
|
+
|
|
146
|
+
expect(buttons).toHaveLength(2)
|
|
147
|
+
})
|
|
148
|
+
|
|
149
|
+
it('hides arrow spinbuttons when showArrows is false', async () => {
|
|
150
|
+
const { container } = render(
|
|
151
|
+
<NumberInput renderLabel="Label" showArrows={false} />
|
|
152
|
+
)
|
|
153
|
+
const buttons = container.querySelectorAll(
|
|
154
|
+
'button[class$="-numberInput_arrow'
|
|
155
|
+
)
|
|
156
|
+
|
|
157
|
+
expect(buttons).toHaveLength(0)
|
|
158
|
+
})
|
|
159
|
+
|
|
160
|
+
it('calls onIncrement when up arrow spinbutton is clicked', async () => {
|
|
161
|
+
const onIncrement = vi.fn()
|
|
162
|
+
const { container } = render(
|
|
163
|
+
<NumberInput renderLabel="Label" onIncrement={onIncrement} />
|
|
164
|
+
)
|
|
165
|
+
const buttons = container.querySelectorAll(
|
|
166
|
+
'button[class$="-numberInput_arrow'
|
|
167
|
+
)
|
|
168
|
+
|
|
169
|
+
userEvent.click(buttons[0])
|
|
170
|
+
|
|
171
|
+
await waitFor(() => {
|
|
172
|
+
expect(onIncrement).toHaveBeenCalledTimes(1)
|
|
173
|
+
})
|
|
174
|
+
})
|
|
175
|
+
|
|
176
|
+
it('does not call onIncrement when `interaction` is set to readonly', async () => {
|
|
177
|
+
const onIncrement = vi.fn()
|
|
178
|
+
const { container } = render(
|
|
179
|
+
<NumberInput
|
|
180
|
+
renderLabel="Label"
|
|
181
|
+
interaction="readonly"
|
|
182
|
+
onIncrement={onIncrement}
|
|
183
|
+
/>
|
|
184
|
+
)
|
|
185
|
+
const buttons = container.querySelectorAll(
|
|
186
|
+
'button[class$="-numberInput_arrow'
|
|
187
|
+
)
|
|
188
|
+
|
|
189
|
+
userEvent.click(buttons[0])
|
|
190
|
+
|
|
191
|
+
await waitFor(() => {
|
|
192
|
+
expect(onIncrement).toHaveBeenCalledTimes(0)
|
|
62
193
|
})
|
|
63
|
-
}
|
|
194
|
+
})
|
|
195
|
+
|
|
196
|
+
it('does not call onIncrement when `readOnly` is set', async () => {
|
|
197
|
+
const onIncrement = vi.fn()
|
|
198
|
+
const { container } = render(
|
|
199
|
+
<NumberInput renderLabel="Label" readOnly onIncrement={onIncrement} />
|
|
200
|
+
)
|
|
201
|
+
const buttons = container.querySelectorAll(
|
|
202
|
+
'button[class$="-numberInput_arrow'
|
|
203
|
+
)
|
|
204
|
+
|
|
205
|
+
userEvent.click(buttons[0])
|
|
206
|
+
|
|
207
|
+
await waitFor(() => {
|
|
208
|
+
expect(onIncrement).toHaveBeenCalledTimes(0)
|
|
209
|
+
})
|
|
210
|
+
})
|
|
211
|
+
|
|
212
|
+
it('calls onDecrement when down arrow spinbutton is clicked', async () => {
|
|
213
|
+
const onDecrement = vi.fn()
|
|
214
|
+
const { container } = render(
|
|
215
|
+
<NumberInput renderLabel="Label" onDecrement={onDecrement} />
|
|
216
|
+
)
|
|
217
|
+
|
|
218
|
+
const buttons = container.querySelectorAll(
|
|
219
|
+
'button[class$="-numberInput_arrow'
|
|
220
|
+
)
|
|
221
|
+
|
|
222
|
+
userEvent.click(buttons[1])
|
|
223
|
+
|
|
224
|
+
await waitFor(() => {
|
|
225
|
+
expect(onDecrement).toHaveBeenCalledTimes(1)
|
|
226
|
+
})
|
|
227
|
+
})
|
|
228
|
+
|
|
229
|
+
it('does not call onDecrement when `interaction` is set to readonly', async () => {
|
|
230
|
+
const onDecrement = vi.fn()
|
|
231
|
+
const { container } = render(
|
|
232
|
+
<NumberInput
|
|
233
|
+
renderLabel="Label"
|
|
234
|
+
interaction="readonly"
|
|
235
|
+
onDecrement={onDecrement}
|
|
236
|
+
/>
|
|
237
|
+
)
|
|
238
|
+
const buttons = container.querySelectorAll(
|
|
239
|
+
'button[class$="-numberInput_arrow'
|
|
240
|
+
)
|
|
241
|
+
|
|
242
|
+
userEvent.click(buttons[1])
|
|
243
|
+
|
|
244
|
+
await waitFor(() => {
|
|
245
|
+
expect(onDecrement).toHaveBeenCalledTimes(0)
|
|
246
|
+
})
|
|
247
|
+
})
|
|
248
|
+
|
|
249
|
+
it('does not call onDecrement when `readOnly` is set', async () => {
|
|
250
|
+
const onDecrement = vi.fn()
|
|
251
|
+
const { container } = render(
|
|
252
|
+
<NumberInput renderLabel="Label" readOnly onDecrement={onDecrement} />
|
|
253
|
+
)
|
|
254
|
+
const buttons = container.querySelectorAll(
|
|
255
|
+
'button[class$="-numberInput_arrow'
|
|
256
|
+
)
|
|
257
|
+
|
|
258
|
+
userEvent.click(buttons[1])
|
|
259
|
+
|
|
260
|
+
await waitFor(() => {
|
|
261
|
+
expect(onDecrement).toHaveBeenCalledTimes(0)
|
|
262
|
+
})
|
|
263
|
+
})
|
|
264
|
+
|
|
265
|
+
it('puts inputMode prop to input', async () => {
|
|
266
|
+
render(<NumberInput renderLabel="Label" inputMode="decimal" />)
|
|
267
|
+
const input = screen.getByRole('spinbutton')
|
|
268
|
+
|
|
269
|
+
expect(input).toHaveAttribute('inputMode', 'decimal')
|
|
270
|
+
})
|
|
271
|
+
|
|
272
|
+
describe('with generated examples', () => {
|
|
273
|
+
const generatedComponents = generateA11yTests(
|
|
274
|
+
NumberInput,
|
|
275
|
+
NumberInputExamples
|
|
276
|
+
)
|
|
277
|
+
for (const component of generatedComponents) {
|
|
278
|
+
it(component.description, async () => {
|
|
279
|
+
const { container } = render(component.content)
|
|
280
|
+
const axeCheck = await runAxeCheck(container)
|
|
281
|
+
expect(axeCheck).toBe(true)
|
|
282
|
+
})
|
|
283
|
+
}
|
|
284
|
+
})
|
|
64
285
|
})
|
package/tsconfig.build.json
CHANGED
|
@@ -8,7 +8,6 @@
|
|
|
8
8
|
"include": ["src"],
|
|
9
9
|
"references": [
|
|
10
10
|
{ "path": "../ui-babel-preset/tsconfig.build.json" },
|
|
11
|
-
{ "path": "../ui-test-locator/tsconfig.build.json" },
|
|
12
11
|
{ "path": "../ui-test-utils/tsconfig.build.json" },
|
|
13
12
|
{ "path": "../ui-scripts/tsconfig.build.json" },
|
|
14
13
|
{ "path": "../ui-axe-check/tsconfig.build.json" },
|