@instructure/ui-range-input 10.19.2-snapshot-3 → 10.19.2-snapshot-5

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.
@@ -1,277 +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, expect } from 'vitest'
27
- import type { MockInstance } from 'vitest'
28
- import { runAxeCheck } from '@instructure/ui-axe-check'
29
-
30
- import '@testing-library/jest-dom'
31
- import { RangeInput } from '../index'
32
-
33
- describe('<RangeInput />', () => {
34
- let consoleWarningMock: ReturnType<typeof vi.spyOn>
35
-
36
- beforeEach(() => {
37
- // Mocking console to prevent test output pollution
38
- consoleWarningMock = vi
39
- .spyOn(console, 'warn')
40
- .mockImplementation(() => {}) as MockInstance
41
- })
42
-
43
- afterEach(() => {
44
- consoleWarningMock.mockRestore()
45
- })
46
-
47
- it('renders an input with type "range"', async () => {
48
- const { container } = render(
49
- <RangeInput label="Opacity" name="opacity" max={100} min={0} />
50
- )
51
-
52
- const label = container.querySelector('[class$="-formFieldLayout__label"]')
53
- const input = container.querySelector('[class$="-rangeInput__input"]')
54
-
55
- expect(label).toBeInTheDocument()
56
- expect(label).toHaveTextContent('Opacity')
57
-
58
- expect(input).toBeInTheDocument()
59
- expect(input!.tagName).toBe('INPUT')
60
- expect(input).toHaveAttribute('name', 'opacity')
61
- expect(input).toHaveAttribute('type', 'range')
62
- })
63
-
64
- it('displays the default value', async () => {
65
- const { container } = render(
66
- <RangeInput
67
- label="Opacity"
68
- name="opacity"
69
- max={100}
70
- min={0}
71
- defaultValue={42}
72
- />
73
- )
74
- const output = container.querySelector('[class$="-rangeInput__value"]')
75
-
76
- expect(output).toHaveTextContent('42')
77
- })
78
-
79
- it('sets input value to default value', async () => {
80
- const { container } = render(
81
- <RangeInput
82
- label="Opacity"
83
- name="opacity"
84
- max={100}
85
- min={0}
86
- defaultValue={25}
87
- />
88
- )
89
- const input = container.querySelector('input')
90
-
91
- expect(input).toHaveValue('25')
92
- })
93
-
94
- it('sets input value to controlled value', async () => {
95
- const { container } = render(
96
- <RangeInput
97
- label="Opacity"
98
- name="opacity"
99
- max={100}
100
- min={0}
101
- value={25}
102
- onChange={() => {}}
103
- />
104
- )
105
- const input = container.querySelector('input')
106
-
107
- expect(input).toHaveValue('25')
108
- })
109
-
110
- it('should provide an inputRef prop', async () => {
111
- const inputRef = vi.fn()
112
- const { container } = render(
113
- <RangeInput
114
- label="Opacity"
115
- name="opacity"
116
- max={100}
117
- min={0}
118
- defaultValue={42}
119
- inputRef={inputRef}
120
- />
121
- )
122
- const input = container.querySelector('input')
123
-
124
- expect(inputRef).toHaveBeenCalledWith(input)
125
- })
126
-
127
- describe('thumbVariant prop', () => {
128
- it('should throw deprecation warning by default', async () => {
129
- render(
130
- <RangeInput
131
- label="Opacity"
132
- name="opacity"
133
- max={100}
134
- min={0}
135
- defaultValue={30}
136
- />
137
- )
138
-
139
- const expectedErrorMessage =
140
- "Warning: [RangeInput] The 'deprecated' value for the `thumbVariant` prop is deprecated. The `deprecated` variant is not fully accessible and will be removed in V9. The connected theme variables will be removed as well: `handleShadowColor`, `handleFocusOutlineColor`, `handleFocusOutlineWidth`. Please use the `accessible` variant."
141
-
142
- expect(consoleWarningMock).toHaveBeenCalledWith(
143
- expect.stringContaining(expectedErrorMessage),
144
- expect.any(String)
145
- )
146
- })
147
-
148
- it('should throw deprecation warning when explicitly "deprecated"', async () => {
149
- render(
150
- <RangeInput
151
- label="Opacity"
152
- name="opacity"
153
- max={100}
154
- min={0}
155
- defaultValue={30}
156
- thumbVariant="deprecated"
157
- />
158
- )
159
-
160
- const expectedErrorMessage =
161
- "Warning: [RangeInput] The 'deprecated' value for the `thumbVariant` prop is deprecated. The `deprecated` variant is not fully accessible and will be removed in V9. The connected theme variables will be removed as well: `handleShadowColor`, `handleFocusOutlineColor`, `handleFocusOutlineWidth`. Please use the `accessible` variant."
162
-
163
- expect(consoleWarningMock).toHaveBeenCalledWith(
164
- expect.stringContaining(expectedErrorMessage),
165
- expect.any(String)
166
- )
167
- })
168
-
169
- it('should not throw deprecation warning when "accessible"', async () => {
170
- render(
171
- <RangeInput
172
- label="Opacity"
173
- name="opacity"
174
- max={100}
175
- min={0}
176
- defaultValue={30}
177
- thumbVariant="accessible"
178
- />
179
- )
180
-
181
- expect(consoleWarningMock).not.toHaveBeenCalled()
182
- })
183
- })
184
-
185
- it('sets min value', async () => {
186
- render(<RangeInput label="Opacity" name="opacity" max={100} min={25} />)
187
- const input = screen.getByLabelText('Opacity')
188
-
189
- expect(input).toHaveAttribute('min', '25')
190
- })
191
-
192
- it('sets max value', async () => {
193
- render(<RangeInput label="Opacity" name="opacity" max={75} min={0} />)
194
-
195
- const input = screen.getByLabelText('Opacity')
196
-
197
- expect(input).toHaveAttribute('max', '75')
198
- })
199
-
200
- it('sets step value', async () => {
201
- render(
202
- <RangeInput label="Opacity" name="opacity" max={100} min={0} step={5} />
203
- )
204
- const input = screen.getByLabelText('Opacity')
205
-
206
- expect(input).toHaveAttribute('step', '5')
207
- })
208
-
209
- it('formats the value displayed', async () => {
210
- const { container } = render(
211
- <RangeInput
212
- label="Opacity"
213
- name="opacity"
214
- max={100}
215
- min={0}
216
- defaultValue={45}
217
- formatValue={(value) => {
218
- return `${value}%`
219
- }}
220
- />
221
- )
222
- const output = container.querySelector('[class$="-rangeInput__value"]')
223
-
224
- expect(output).toHaveTextContent('45%')
225
- })
226
-
227
- it('hides the value when displayValue is false', async () => {
228
- const { container } = render(
229
- <RangeInput
230
- label="Opacity"
231
- name="opacity"
232
- max={100}
233
- min={0}
234
- displayValue={false}
235
- />
236
- )
237
- const output = container.querySelector('[class$="-rangeInput__value"]')
238
-
239
- expect(output).not.toBeInTheDocument()
240
- })
241
-
242
- describe('for a11y', () => {
243
- it('should meet standards', async () => {
244
- const { container } = render(
245
- <RangeInput
246
- label="Opacity"
247
- name="opacity"
248
- max={100}
249
- min={0}
250
- defaultValue={50}
251
- />
252
- )
253
- const axeCheck = await runAxeCheck(container)
254
- expect(axeCheck).toBe(true)
255
- })
256
-
257
- it('formats the aria-valuetext attribute', async () => {
258
- const { container } = render(
259
- <RangeInput
260
- label="Opacity"
261
- name="opacity"
262
- max={100}
263
- min={0}
264
- defaultValue={40}
265
- formatValue={(value) => {
266
- return `${value}%`
267
- }}
268
- />
269
- )
270
- const input = container.querySelector('input')
271
- const output = container.querySelector('[class$="-rangeInput__value"]')
272
-
273
- expect(input).toHaveAttribute('aria-valuetext', '40%')
274
- expect(output).toHaveTextContent('40%')
275
- })
276
- })
277
- })
@@ -1,2 +0,0 @@
1
- import '@testing-library/jest-dom';
2
- //# sourceMappingURL=RangeInput.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"RangeInput.test.d.ts","sourceRoot":"","sources":["../../../src/RangeInput/__new-tests__/RangeInput.test.tsx"],"names":[],"mappings":"AA6BA,OAAO,2BAA2B,CAAA"}