@instructure/ui-number-input 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.
- package/CHANGELOG.md +1 -1
- package/package.json +14 -14
- package/tsconfig.build.tsbuildinfo +1 -1
- package/es/NumberInput/__new-tests__/NumberInput.test.js +0 -284
- package/lib/NumberInput/__new-tests__/NumberInput.test.js +0 -287
- package/src/NumberInput/__new-tests__/NumberInput.test.tsx +0 -322
- package/types/NumberInput/__new-tests__/NumberInput.test.d.ts +0 -2
- package/types/NumberInput/__new-tests__/NumberInput.test.d.ts.map +0 -1
|
@@ -1,322 +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, waitFor } from '@testing-library/react'
|
|
26
|
-
import userEvent from '@testing-library/user-event'
|
|
27
|
-
import { vi } from 'vitest'
|
|
28
|
-
import { runAxeCheck } from '@instructure/ui-axe-check'
|
|
29
|
-
import '@testing-library/jest-dom'
|
|
30
|
-
|
|
31
|
-
import { NumberInput } from '../index'
|
|
32
|
-
import NumberInputExamples from '../__examples__/NumberInput.examples'
|
|
33
|
-
// eslint-disable-next-line no-restricted-imports
|
|
34
|
-
import { generateA11yTests } from '@instructure/ui-scripts/lib/test/generateA11yTests'
|
|
35
|
-
import { IconZoomInLine, IconZoomOutLine } from '@instructure/ui-icons'
|
|
36
|
-
|
|
37
|
-
describe('<NumberInput />', () => {
|
|
38
|
-
let consoleWarningMock: ReturnType<typeof vi.spyOn>
|
|
39
|
-
let consoleErrorMock: ReturnType<typeof vi.spyOn>
|
|
40
|
-
|
|
41
|
-
beforeEach(() => {
|
|
42
|
-
// Mocking console to prevent test output pollution
|
|
43
|
-
consoleWarningMock = vi
|
|
44
|
-
.spyOn(console, 'warn')
|
|
45
|
-
.mockImplementation(() => {}) as any
|
|
46
|
-
consoleErrorMock = vi
|
|
47
|
-
.spyOn(console, 'error')
|
|
48
|
-
.mockImplementation(() => {}) as any
|
|
49
|
-
})
|
|
50
|
-
|
|
51
|
-
afterEach(() => {
|
|
52
|
-
consoleWarningMock.mockRestore()
|
|
53
|
-
consoleErrorMock.mockRestore()
|
|
54
|
-
})
|
|
55
|
-
|
|
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(
|
|
75
|
-
'span[class$="-formFieldLayout__label"]'
|
|
76
|
-
)
|
|
77
|
-
|
|
78
|
-
expect(label).toHaveTextContent('Label')
|
|
79
|
-
})
|
|
80
|
-
|
|
81
|
-
it('passes the input element to inputRef', async () => {
|
|
82
|
-
const inputRef = vi.fn()
|
|
83
|
-
render(<NumberInput renderLabel="Label" inputRef={inputRef} />)
|
|
84
|
-
const input = screen.getByRole('spinbutton')
|
|
85
|
-
|
|
86
|
-
expect(inputRef).toHaveBeenCalledTimes(1)
|
|
87
|
-
expect(inputRef).toHaveBeenCalledWith(input)
|
|
88
|
-
})
|
|
89
|
-
|
|
90
|
-
it('passes change events to onChange handler', async () => {
|
|
91
|
-
const onChange = vi.fn()
|
|
92
|
-
render(<NumberInput renderLabel="Label" onChange={onChange} />)
|
|
93
|
-
const input = screen.getByRole('spinbutton')
|
|
94
|
-
|
|
95
|
-
userEvent.type(input, '5')
|
|
96
|
-
|
|
97
|
-
await waitFor(() => {
|
|
98
|
-
const event = onChange.mock.calls[0][0]
|
|
99
|
-
const args = onChange.mock.calls[0][1]
|
|
100
|
-
expect(onChange).toHaveBeenCalledTimes(1)
|
|
101
|
-
expect(args).toBe('5')
|
|
102
|
-
expect(event.target.value).toBe('5')
|
|
103
|
-
})
|
|
104
|
-
})
|
|
105
|
-
|
|
106
|
-
it('passes keyboard events to the onKeyDown handler', async () => {
|
|
107
|
-
const onKeyDown = vi.fn()
|
|
108
|
-
render(<NumberInput renderLabel="Label" onKeyDown={onKeyDown} />)
|
|
109
|
-
const input = screen.getByRole('spinbutton')
|
|
110
|
-
|
|
111
|
-
userEvent.type(input, '5')
|
|
112
|
-
|
|
113
|
-
await waitFor(() => {
|
|
114
|
-
expect(onKeyDown).toHaveBeenCalledTimes(1)
|
|
115
|
-
})
|
|
116
|
-
})
|
|
117
|
-
|
|
118
|
-
it('passes blur events to onBlur handler', async () => {
|
|
119
|
-
const onBlur = vi.fn()
|
|
120
|
-
render(<NumberInput renderLabel="Label" onBlur={onBlur} />)
|
|
121
|
-
|
|
122
|
-
userEvent.tab()
|
|
123
|
-
userEvent.tab()
|
|
124
|
-
|
|
125
|
-
await waitFor(() => {
|
|
126
|
-
expect(onBlur).toHaveBeenCalledTimes(1)
|
|
127
|
-
})
|
|
128
|
-
})
|
|
129
|
-
|
|
130
|
-
it('passes focus events to onFocus handler', async () => {
|
|
131
|
-
const onFocus = vi.fn()
|
|
132
|
-
render(<NumberInput renderLabel="Label" onFocus={onFocus} />)
|
|
133
|
-
const input = screen.getByRole('spinbutton')
|
|
134
|
-
|
|
135
|
-
input.focus()
|
|
136
|
-
|
|
137
|
-
await waitFor(() => {
|
|
138
|
-
expect(onFocus).toHaveBeenCalledTimes(1)
|
|
139
|
-
})
|
|
140
|
-
})
|
|
141
|
-
|
|
142
|
-
it('shows arrow spinbuttons by default', async () => {
|
|
143
|
-
const { container } = render(<NumberInput renderLabel="Label" />)
|
|
144
|
-
const buttons = container.querySelectorAll(
|
|
145
|
-
'button[class$="-numberInput_arrow'
|
|
146
|
-
)
|
|
147
|
-
|
|
148
|
-
expect(buttons).toHaveLength(2)
|
|
149
|
-
})
|
|
150
|
-
|
|
151
|
-
it('hides arrow spinbuttons when showArrows is false', async () => {
|
|
152
|
-
const { container } = render(
|
|
153
|
-
<NumberInput renderLabel="Label" showArrows={false} />
|
|
154
|
-
)
|
|
155
|
-
const buttons = container.querySelectorAll(
|
|
156
|
-
'button[class$="-numberInput_arrow'
|
|
157
|
-
)
|
|
158
|
-
|
|
159
|
-
expect(buttons).toHaveLength(0)
|
|
160
|
-
})
|
|
161
|
-
|
|
162
|
-
it('calls onIncrement when up arrow spinbutton is clicked', async () => {
|
|
163
|
-
const onIncrement = vi.fn()
|
|
164
|
-
const { container } = render(
|
|
165
|
-
<NumberInput renderLabel="Label" onIncrement={onIncrement} />
|
|
166
|
-
)
|
|
167
|
-
const buttons = container.querySelectorAll(
|
|
168
|
-
'button[class$="-numberInput_arrow'
|
|
169
|
-
)
|
|
170
|
-
|
|
171
|
-
userEvent.click(buttons[0])
|
|
172
|
-
|
|
173
|
-
await waitFor(() => {
|
|
174
|
-
expect(onIncrement).toHaveBeenCalledTimes(1)
|
|
175
|
-
})
|
|
176
|
-
})
|
|
177
|
-
|
|
178
|
-
it('does not call onIncrement when `interaction` is set to readonly', async () => {
|
|
179
|
-
const onIncrement = vi.fn()
|
|
180
|
-
const { container } = render(
|
|
181
|
-
<NumberInput
|
|
182
|
-
renderLabel="Label"
|
|
183
|
-
interaction="readonly"
|
|
184
|
-
onIncrement={onIncrement}
|
|
185
|
-
/>
|
|
186
|
-
)
|
|
187
|
-
const buttons = container.querySelectorAll(
|
|
188
|
-
'button[class$="-numberInput_arrow'
|
|
189
|
-
)
|
|
190
|
-
|
|
191
|
-
userEvent.click(buttons[0])
|
|
192
|
-
|
|
193
|
-
await waitFor(() => {
|
|
194
|
-
expect(onIncrement).toHaveBeenCalledTimes(0)
|
|
195
|
-
})
|
|
196
|
-
})
|
|
197
|
-
|
|
198
|
-
it('does not call onIncrement when `readOnly` is set', async () => {
|
|
199
|
-
const onIncrement = vi.fn()
|
|
200
|
-
const { container } = render(
|
|
201
|
-
<NumberInput renderLabel="Label" readOnly onIncrement={onIncrement} />
|
|
202
|
-
)
|
|
203
|
-
const buttons = container.querySelectorAll(
|
|
204
|
-
'button[class$="-numberInput_arrow'
|
|
205
|
-
)
|
|
206
|
-
|
|
207
|
-
userEvent.click(buttons[0])
|
|
208
|
-
|
|
209
|
-
await waitFor(() => {
|
|
210
|
-
expect(onIncrement).toHaveBeenCalledTimes(0)
|
|
211
|
-
})
|
|
212
|
-
})
|
|
213
|
-
|
|
214
|
-
it('calls onDecrement when down arrow spinbutton is clicked', async () => {
|
|
215
|
-
const onDecrement = vi.fn()
|
|
216
|
-
const { container } = render(
|
|
217
|
-
<NumberInput renderLabel="Label" onDecrement={onDecrement} />
|
|
218
|
-
)
|
|
219
|
-
|
|
220
|
-
const buttons = container.querySelectorAll(
|
|
221
|
-
'button[class$="-numberInput_arrow'
|
|
222
|
-
)
|
|
223
|
-
|
|
224
|
-
userEvent.click(buttons[1])
|
|
225
|
-
|
|
226
|
-
await waitFor(() => {
|
|
227
|
-
expect(onDecrement).toHaveBeenCalledTimes(1)
|
|
228
|
-
})
|
|
229
|
-
})
|
|
230
|
-
|
|
231
|
-
it('does not call onDecrement when `interaction` is set to readonly', async () => {
|
|
232
|
-
const onDecrement = vi.fn()
|
|
233
|
-
const { container } = render(
|
|
234
|
-
<NumberInput
|
|
235
|
-
renderLabel="Label"
|
|
236
|
-
interaction="readonly"
|
|
237
|
-
onDecrement={onDecrement}
|
|
238
|
-
/>
|
|
239
|
-
)
|
|
240
|
-
const buttons = container.querySelectorAll(
|
|
241
|
-
'button[class$="-numberInput_arrow'
|
|
242
|
-
)
|
|
243
|
-
|
|
244
|
-
userEvent.click(buttons[1])
|
|
245
|
-
|
|
246
|
-
await waitFor(() => {
|
|
247
|
-
expect(onDecrement).toHaveBeenCalledTimes(0)
|
|
248
|
-
})
|
|
249
|
-
})
|
|
250
|
-
|
|
251
|
-
it('does not call onDecrement when `readOnly` is set', async () => {
|
|
252
|
-
const onDecrement = vi.fn()
|
|
253
|
-
const { container } = render(
|
|
254
|
-
<NumberInput renderLabel="Label" readOnly onDecrement={onDecrement} />
|
|
255
|
-
)
|
|
256
|
-
const buttons = container.querySelectorAll(
|
|
257
|
-
'button[class$="-numberInput_arrow'
|
|
258
|
-
)
|
|
259
|
-
|
|
260
|
-
userEvent.click(buttons[1])
|
|
261
|
-
|
|
262
|
-
await waitFor(() => {
|
|
263
|
-
expect(onDecrement).toHaveBeenCalledTimes(0)
|
|
264
|
-
})
|
|
265
|
-
})
|
|
266
|
-
|
|
267
|
-
it('puts inputMode prop to input', async () => {
|
|
268
|
-
render(<NumberInput renderLabel="Label" inputMode="decimal" />)
|
|
269
|
-
const input = screen.getByRole('spinbutton')
|
|
270
|
-
|
|
271
|
-
expect(input).toHaveAttribute('inputMode', 'decimal')
|
|
272
|
-
})
|
|
273
|
-
|
|
274
|
-
describe('with generated examples', () => {
|
|
275
|
-
const generatedComponents = generateA11yTests(
|
|
276
|
-
NumberInput,
|
|
277
|
-
NumberInputExamples
|
|
278
|
-
)
|
|
279
|
-
for (const component of generatedComponents) {
|
|
280
|
-
it(component.description, async () => {
|
|
281
|
-
const { container } = render(component.content)
|
|
282
|
-
const axeCheck = await runAxeCheck(container)
|
|
283
|
-
expect(axeCheck).toBe(true)
|
|
284
|
-
})
|
|
285
|
-
}
|
|
286
|
-
})
|
|
287
|
-
|
|
288
|
-
it('renders custom interactive icons', async () => {
|
|
289
|
-
const onDecrement = vi.fn()
|
|
290
|
-
const onIncrement = vi.fn()
|
|
291
|
-
const { container } = render(
|
|
292
|
-
<NumberInput
|
|
293
|
-
renderLabel="Label"
|
|
294
|
-
onIncrement={onIncrement}
|
|
295
|
-
onDecrement={onDecrement}
|
|
296
|
-
renderIcons={{
|
|
297
|
-
increase: <IconZoomInLine />,
|
|
298
|
-
decrease: <IconZoomOutLine />
|
|
299
|
-
}}
|
|
300
|
-
/>
|
|
301
|
-
)
|
|
302
|
-
|
|
303
|
-
const zoomInIcon = container.querySelector('svg[name="IconZoomIn"]')
|
|
304
|
-
const zoomOutIcon = container.querySelector('svg[name="IconZoomOut"]')
|
|
305
|
-
expect(zoomInIcon).toBeInTheDocument()
|
|
306
|
-
expect(zoomOutIcon).toBeInTheDocument()
|
|
307
|
-
|
|
308
|
-
const buttons = container.querySelectorAll(
|
|
309
|
-
'button[class$="-numberInput_arrow'
|
|
310
|
-
)
|
|
311
|
-
|
|
312
|
-
userEvent.click(buttons[0])
|
|
313
|
-
await waitFor(() => {
|
|
314
|
-
expect(onIncrement).toHaveBeenCalledTimes(1)
|
|
315
|
-
})
|
|
316
|
-
|
|
317
|
-
userEvent.click(buttons[1])
|
|
318
|
-
await waitFor(() => {
|
|
319
|
-
expect(onDecrement).toHaveBeenCalledTimes(1)
|
|
320
|
-
})
|
|
321
|
-
})
|
|
322
|
-
})
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"NumberInput.test.d.ts","sourceRoot":"","sources":["../../../src/NumberInput/__new-tests__/NumberInput.test.tsx"],"names":[],"mappings":"AA4BA,OAAO,2BAA2B,CAAA"}
|