@instructure/ui-buttons 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 (33) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/package.json +20 -20
  3. package/tsconfig.build.tsbuildinfo +1 -1
  4. package/es/BaseButton/__new-tests__/BaseButton.test.js +0 -422
  5. package/es/Button/__new-tests__/Button.test.js +0 -495
  6. package/es/CloseButton/__new-tests__/CloseButton.test.js +0 -64
  7. package/es/CondensedButton/__new-tests__/CondensedButton.test.js +0 -197
  8. package/es/IconButton/__new-tests__/IconButton.test.js +0 -188
  9. package/es/ToggleButton/__new-tests__/ToggleButton.test.js +0 -165
  10. package/lib/BaseButton/__new-tests__/BaseButton.test.js +0 -424
  11. package/lib/Button/__new-tests__/Button.test.js +0 -497
  12. package/lib/CloseButton/__new-tests__/CloseButton.test.js +0 -66
  13. package/lib/CondensedButton/__new-tests__/CondensedButton.test.js +0 -199
  14. package/lib/IconButton/__new-tests__/IconButton.test.js +0 -190
  15. package/lib/ToggleButton/__new-tests__/ToggleButton.test.js +0 -167
  16. package/src/BaseButton/__new-tests__/BaseButton.test.tsx +0 -436
  17. package/src/Button/__new-tests__/Button.test.tsx +0 -498
  18. package/src/CloseButton/__new-tests__/CloseButton.test.tsx +0 -72
  19. package/src/CondensedButton/__new-tests__/CondensedButton.test.tsx +0 -186
  20. package/src/IconButton/__new-tests__/IconButton.test.tsx +0 -214
  21. package/src/ToggleButton/__new-tests__/ToggleButton.test.tsx +0 -200
  22. package/types/BaseButton/__new-tests__/BaseButton.test.d.ts +0 -2
  23. package/types/BaseButton/__new-tests__/BaseButton.test.d.ts.map +0 -1
  24. package/types/Button/__new-tests__/Button.test.d.ts +0 -2
  25. package/types/Button/__new-tests__/Button.test.d.ts.map +0 -1
  26. package/types/CloseButton/__new-tests__/CloseButton.test.d.ts +0 -2
  27. package/types/CloseButton/__new-tests__/CloseButton.test.d.ts.map +0 -1
  28. package/types/CondensedButton/__new-tests__/CondensedButton.test.d.ts +0 -2
  29. package/types/CondensedButton/__new-tests__/CondensedButton.test.d.ts.map +0 -1
  30. package/types/IconButton/__new-tests__/IconButton.test.d.ts +0 -2
  31. package/types/IconButton/__new-tests__/IconButton.test.d.ts.map +0 -1
  32. package/types/ToggleButton/__new-tests__/ToggleButton.test.d.ts +0 -2
  33. package/types/ToggleButton/__new-tests__/ToggleButton.test.d.ts.map +0 -1
@@ -1,498 +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 { vi } from 'vitest'
27
- import userEvent from '@testing-library/user-event'
28
- import '@testing-library/jest-dom'
29
-
30
- import { runAxeCheck } from '@instructure/ui-axe-check'
31
- import { BaseButton } from '../../BaseButton'
32
- import { Button } from '../index'
33
-
34
- describe('<Button/>', () => {
35
- let consoleWarningMock: ReturnType<typeof vi.spyOn>
36
- let consoleErrorMock: ReturnType<typeof vi.spyOn>
37
- const iconSelector = 'svg[data-title="myIcon"]'
38
-
39
- const icon = (
40
- <svg
41
- data-title="myIcon"
42
- height="1em"
43
- width="1em"
44
- style={{ fill: 'currentcolor' }}
45
- >
46
- <circle cx="0.5em" cy="0.5em" r="0.5em" />
47
- </svg>
48
- )
49
-
50
- beforeEach(() => {
51
- // Mocking console to prevent test output pollution
52
- consoleWarningMock = vi
53
- .spyOn(console, 'warn')
54
- .mockImplementation(() => {}) as any
55
- consoleErrorMock = vi
56
- .spyOn(console, 'error')
57
- .mockImplementation(() => {}) as any
58
- })
59
-
60
- afterEach(() => {
61
- consoleWarningMock.mockRestore()
62
- consoleErrorMock.mockRestore()
63
- })
64
-
65
- it('should render children', () => {
66
- const children = 'Hello world'
67
-
68
- render(<Button>{children}</Button>)
69
-
70
- const button = document.querySelector('button')
71
-
72
- expect(button).toBeInTheDocument()
73
- expect(button).toHaveTextContent(children)
74
- })
75
-
76
- it('should render a button', async () => {
77
- render(<Button>Hello World</Button>)
78
-
79
- const button = screen.getByRole('button')
80
-
81
- expect(button).toBeInTheDocument()
82
- expect(button).toHaveAttribute('type', 'button')
83
- expect(button).toHaveTextContent('Hello World')
84
- })
85
-
86
- it('should provide a focused getter', () => {
87
- let componentRef: BaseButton | undefined
88
-
89
- render(
90
- <Button
91
- //@ts-expect-error TODO this is coming from ReactComponentWrapper
92
- ref={(component: BaseButton) => {
93
- componentRef = component
94
- }}
95
- >
96
- Hello
97
- </Button>
98
- )
99
- const button = screen.getByRole('button', { name: 'Hello' })
100
-
101
- button.focus()
102
-
103
- expect(componentRef?.focused).toBe(true)
104
- })
105
-
106
- it('should provide a focus function', () => {
107
- let componentRef: BaseButton | undefined
108
-
109
- render(
110
- <Button
111
- //@ts-expect-error TODO this is coming from ReactComponentWrapper
112
- ref={(component: BaseButton) => {
113
- componentRef = component
114
- }}
115
- >
116
- Hello
117
- </Button>
118
- )
119
- const button = screen.getByRole('button', { name: 'Hello' })
120
-
121
- componentRef?.focus()
122
-
123
- expect(document.activeElement).toBe(button)
124
- })
125
-
126
- it('should pass the type attribute', () => {
127
- render(<Button type="submit">Hello</Button>)
128
-
129
- const button = screen.getByRole('button', { name: 'Hello' })
130
-
131
- expect(button).toBeInTheDocument()
132
- expect(button).toHaveAttribute('type', 'submit')
133
- })
134
-
135
- it('should pass the `elementRef` prop', () => {
136
- const elementRef = vi.fn()
137
- render(<Button elementRef={elementRef}>Hello</Button>)
138
-
139
- const button = screen.getByRole('button', { name: 'Hello' })
140
-
141
- expect(elementRef).toHaveBeenCalledWith(button)
142
- })
143
-
144
- it('should pass the `as` prop', () => {
145
- const { container } = render(<Button as="li">Hello</Button>)
146
-
147
- const button = container.querySelector('[type="button"]')
148
-
149
- expect(button).toBeInTheDocument()
150
- expect(button).toHaveTextContent('Hello')
151
- expect(button!.tagName).toBe('LI')
152
- })
153
-
154
- it('should set the disabled attribute when `interaction` is set to disabled', () => {
155
- render(<Button interaction="disabled">Hello</Button>)
156
-
157
- const button = screen.getByRole('button', { name: 'Hello' })
158
-
159
- expect(button).toHaveAttribute('disabled')
160
- })
161
-
162
- it('should set the disabled attribute when `disabled` is set', () => {
163
- render(<Button disabled>Hello</Button>)
164
-
165
- const button = screen.getByRole('button', { name: 'Hello' })
166
-
167
- expect(button).toHaveAttribute('disabled')
168
- })
169
-
170
- it('should set the disabled attribute when `interaction` is set to readonly', () => {
171
- render(<Button interaction="readonly">Hello</Button>)
172
-
173
- const button = screen.getByRole('button', { name: 'Hello' })
174
-
175
- expect(button).toHaveAttribute('disabled')
176
- })
177
-
178
- it('should set the disabled attribute when `readOnly` is set', () => {
179
- render(<Button readOnly>Hello</Button>)
180
-
181
- const button = screen.getByRole('button', { name: 'Hello' })
182
-
183
- expect(button).toHaveAttribute('disabled')
184
- })
185
-
186
- it('should pass the `href` prop', () => {
187
- render(<Button href="#">Hello</Button>)
188
-
189
- const linkButton = screen.getByRole('link', { name: 'Hello' })
190
-
191
- expect(linkButton).toBeInTheDocument()
192
- expect(linkButton).toHaveAttribute('href', '#')
193
- })
194
-
195
- it('should pass the `renderIcon` prop', () => {
196
- render(<Button renderIcon={icon}>Hello</Button>)
197
-
198
- const svgIcon = document.querySelector(iconSelector)
199
- const button = screen.getByRole('button', { name: 'Hello' })
200
-
201
- expect(button).toBeInTheDocument()
202
- expect(svgIcon).toBeInTheDocument()
203
- })
204
-
205
- it('should pass the `onClick` prop', async () => {
206
- const onClick = vi.fn()
207
- render(<Button onClick={onClick}>Hello</Button>)
208
-
209
- const button = screen.getByRole('button', { name: 'Hello' })
210
-
211
- await userEvent.click(button)
212
-
213
- await waitFor(() => {
214
- expect(onClick).toHaveBeenCalledTimes(1)
215
- })
216
- })
217
-
218
- it('should render the children as button text', () => {
219
- render(<Button>Hello World</Button>)
220
-
221
- const button = screen.getByRole('button')
222
-
223
- expect(button).toBeInTheDocument()
224
- expect(button).toHaveTextContent('Hello World')
225
- })
226
-
227
- it('should not error with a null child', () => {
228
- render(<Button>Hello World{null}</Button>)
229
-
230
- const button = screen.getByRole('button', { name: 'Hello World' })
231
-
232
- expect(button).toBeInTheDocument()
233
- })
234
-
235
- it('should render a link styled as a button if href is provided', () => {
236
- render(<Button href="example.html">Hello World</Button>)
237
-
238
- const button = screen.getAllByRole('link', { name: 'Hello World' })
239
-
240
- expect(button).toHaveLength(1)
241
- expect(button[0]).toHaveAttribute('href', 'example.html')
242
- })
243
-
244
- it('should render as a link when `to` prop is provided', () => {
245
- const { container } = render(<Button to="/example">Test</Button>)
246
-
247
- const linkButton = container.querySelector('a')
248
-
249
- expect(linkButton).toBeInTheDocument()
250
- expect(linkButton).toHaveAttribute('to', '/example')
251
- })
252
-
253
- it('should render designated tag if `as` prop is specified', () => {
254
- const { container } = render(<Button as="span">Hello World</Button>)
255
-
256
- const button = container.querySelector('[type="button"]')
257
-
258
- expect(button).toBeInTheDocument()
259
- expect(button).toHaveTextContent('Hello World')
260
- expect(button!.tagName).toBe('SPAN')
261
- })
262
-
263
- it('should set role="button"', () => {
264
- const onClick = vi.fn()
265
- const { container } = render(
266
- <Button as="span" onClick={onClick}>
267
- Hello World
268
- </Button>
269
- )
270
- const button = container.querySelector('[type="button"]')
271
-
272
- expect(button).toBeInTheDocument()
273
- expect(button).toHaveAttribute('role', 'button')
274
- })
275
-
276
- it('should set tabIndex="0"', () => {
277
- const onClick = vi.fn()
278
- render(
279
- <Button as="span" onClick={onClick}>
280
- Hello World
281
- </Button>
282
- )
283
- const button = screen.getByRole('button')
284
-
285
- expect(button).toBeInTheDocument()
286
- expect(button).toHaveAttribute('tabIndex', '0')
287
- })
288
-
289
- it('should pass down the type prop to the button element', () => {
290
- const onClick = vi.fn()
291
- render(
292
- <Button type="submit" onClick={onClick}>
293
- Hello World
294
- </Button>
295
- )
296
- const button = screen.getByRole('button')
297
-
298
- expect(button).toBeInTheDocument()
299
- expect(button).toHaveAttribute('type', 'submit')
300
- })
301
-
302
- it('focuses with the focus helper', () => {
303
- const onFocus = vi.fn()
304
- render(<Button onFocus={onFocus}>Hello World</Button>)
305
-
306
- const button = screen.getByRole('button')
307
-
308
- button.focus()
309
-
310
- expect(onFocus).toHaveBeenCalled()
311
- expect(document.activeElement).toBe(button)
312
- })
313
-
314
- describe('onClick', () => {
315
- it('should call onClick when clicked', async () => {
316
- const onClick = vi.fn()
317
- render(<Button onClick={onClick}>Hello World</Button>)
318
-
319
- const button = screen.getByRole('button', { name: 'Hello World' })
320
-
321
- await userEvent.click(button)
322
-
323
- await waitFor(() => {
324
- expect(onClick).toHaveBeenCalled()
325
- })
326
- })
327
-
328
- it('should not call onClick when button is disabled', async () => {
329
- const onClick = vi.fn()
330
-
331
- render(
332
- <Button disabled onClick={onClick}>
333
- Hello World
334
- </Button>
335
- )
336
- const button = screen.getByRole('button', { name: 'Hello World' })
337
-
338
- await userEvent.click(button)
339
-
340
- await waitFor(() => {
341
- expect(onClick).not.toHaveBeenCalled()
342
- })
343
- })
344
-
345
- it('should not call onClick when button is readOnly', async () => {
346
- const onClick = vi.fn()
347
-
348
- render(
349
- <Button readOnly onClick={onClick}>
350
- Hello World
351
- </Button>
352
- )
353
- const button = screen.getByRole('button', { name: 'Hello World' })
354
-
355
- await userEvent.click(button)
356
-
357
- await waitFor(() => {
358
- expect(onClick).not.toHaveBeenCalled()
359
- })
360
- })
361
-
362
- it('should not call onClick when button is disabled and an href prop is provided', async () => {
363
- const onClick = vi.fn()
364
-
365
- render(<Button href="#">Hello World</Button>)
366
-
367
- const button = screen.getByRole('link', { name: 'Hello World' })
368
-
369
- await userEvent.click(button)
370
-
371
- await waitFor(() => {
372
- expect(onClick).not.toHaveBeenCalled()
373
- })
374
- })
375
-
376
- it('should not call onClick when button is readOnly and an href prop is provided', async () => {
377
- const onClick = vi.fn()
378
-
379
- render(
380
- <Button readOnly onClick={onClick} href="#">
381
- Hello World
382
- </Button>
383
- )
384
- const button = screen.getByRole('link', { name: 'Hello World' })
385
-
386
- await userEvent.click(button)
387
-
388
- await waitFor(() => {
389
- expect(onClick).not.toHaveBeenCalled()
390
- })
391
- })
392
-
393
- it('should call onClick when space key is pressed if href is provided', async () => {
394
- const onClick = vi.fn()
395
-
396
- render(
397
- <Button onClick={onClick} href="#">
398
- Hello World
399
- </Button>
400
- )
401
- const button = screen.getByRole('link', { name: 'Hello World' })
402
-
403
- await userEvent.type(button, '{space}')
404
-
405
- await waitFor(() => {
406
- expect(onClick).toHaveBeenCalled()
407
- })
408
- })
409
-
410
- it('should call onClick when enter key is pressed when not a button or link', async () => {
411
- const onClick = vi.fn()
412
-
413
- render(
414
- <Button as="span" onClick={onClick}>
415
- Hello World
416
- </Button>
417
- )
418
- const button = screen.getByRole('button', { name: 'Hello World' })
419
-
420
- await userEvent.type(button, '{enter}')
421
-
422
- await waitFor(() => {
423
- expect(onClick).toHaveBeenCalled()
424
- })
425
- })
426
-
427
- it('should not call onClick when button is disabled and space key is pressed', async () => {
428
- const onClick = vi.fn()
429
-
430
- render(
431
- <Button disabled onClick={onClick} href="#">
432
- Hello World
433
- </Button>
434
- )
435
- const button = screen.getByRole('link', { name: 'Hello World' })
436
-
437
- await userEvent.type(button, '{spaec}')
438
-
439
- await waitFor(() => {
440
- expect(onClick).not.toHaveBeenCalled()
441
- })
442
- })
443
-
444
- it('should not call onClick when button is readOnly and space key is pressed', async () => {
445
- const onClick = vi.fn()
446
-
447
- render(
448
- <Button readOnly onClick={onClick} href="#">
449
- Hello World
450
- </Button>
451
- )
452
- const button = screen.getByRole('link', { name: 'Hello World' })
453
-
454
- await userEvent.type(button, '{space}')
455
-
456
- await waitFor(() => {
457
- expect(onClick).not.toHaveBeenCalled()
458
- })
459
- })
460
- })
461
-
462
- describe('for a11y', () => {
463
- it('should meet standards when onClick is given', async () => {
464
- const onClick = vi.fn()
465
- render(<Button onClick={onClick}>Hello World</Button>)
466
-
467
- const button = screen.getByRole('button', { name: 'Hello World' })
468
-
469
- await userEvent.click(button)
470
-
471
- await waitFor(async () => {
472
- const axeCheck = await runAxeCheck(button)
473
-
474
- expect(axeCheck).toBe(true)
475
- })
476
- })
477
-
478
- describe('when disabled', () => {
479
- it('sets the disabled attribute so that the button is not in tab order', () => {
480
- render(<Button disabled>Hello World</Button>)
481
-
482
- const button = screen.getByRole('button', { name: 'Hello World' })
483
-
484
- expect(button).toHaveAttribute('disabled')
485
- })
486
- })
487
-
488
- describe('when readOnly', () => {
489
- it('sets the disabled attribute so that the button is not in tab order', () => {
490
- render(<Button readOnly>Hello World</Button>)
491
-
492
- const button = screen.getByRole('button', { name: 'Hello World' })
493
-
494
- expect(button).toHaveAttribute('disabled')
495
- })
496
- })
497
- })
498
- })
@@ -1,72 +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 { vi } from 'vitest'
27
- import userEvent from '@testing-library/user-event'
28
- import '@testing-library/jest-dom'
29
-
30
- import { CloseButton } from '../index'
31
-
32
- describe('<CloseButton />', () => {
33
- let consoleWarningMock: ReturnType<typeof vi.spyOn>
34
-
35
- beforeEach(() => {
36
- // Mocking console to prevent test output pollution
37
- consoleWarningMock = vi
38
- .spyOn(console, 'warn')
39
- .mockImplementation(() => {}) as any
40
- })
41
-
42
- afterEach(() => {
43
- consoleWarningMock.mockRestore()
44
- })
45
-
46
- it('should render with x icon', async () => {
47
- render(<CloseButton screenReaderLabel="Close" />)
48
-
49
- const button = screen.getByRole('button')
50
-
51
- const icon = document.querySelector('svg')
52
-
53
- expect(icon).toBeInTheDocument()
54
- expect(icon).toHaveAttribute('name', 'IconX')
55
- expect(button).toBeInTheDocument()
56
- expect(button).toHaveTextContent('Close')
57
- })
58
-
59
- it('should pass the `onClick` prop', async () => {
60
- const onClick = vi.fn()
61
-
62
- render(<CloseButton onClick={onClick} screenReaderLabel="Hello" />)
63
-
64
- const button = screen.getByRole('button')
65
-
66
- await userEvent.click(button)
67
-
68
- await waitFor(() => {
69
- expect(onClick).toHaveBeenCalledTimes(1)
70
- })
71
- })
72
- })