@instructure/ui-buttons 8.55.0 → 8.55.1-snapshot-3

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 (89) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/es/BaseButton/__new-tests__/BaseButton.test.js +361 -0
  3. package/es/Button/__new-tests__/Button.test.js +459 -0
  4. package/es/CloseButton/__new-tests__/CloseButton.test.js +63 -0
  5. package/es/CondensedButton/__new-tests__/CondensedButton.test.js +181 -0
  6. package/es/IconButton/__new-tests__/IconButton.test.js +185 -0
  7. package/es/ToggleButton/__new-tests__/ToggleButton.test.js +163 -0
  8. package/lib/BaseButton/__new-tests__/BaseButton.test.js +363 -0
  9. package/lib/Button/__new-tests__/Button.test.js +461 -0
  10. package/lib/CloseButton/__new-tests__/CloseButton.test.js +65 -0
  11. package/lib/CondensedButton/__new-tests__/CondensedButton.test.js +183 -0
  12. package/lib/IconButton/__new-tests__/IconButton.test.js +187 -0
  13. package/lib/ToggleButton/__new-tests__/ToggleButton.test.js +165 -0
  14. package/package.json +22 -20
  15. package/src/BaseButton/__new-tests__/BaseButton.test.tsx +407 -0
  16. package/src/Button/__new-tests__/Button.test.tsx +500 -0
  17. package/src/CloseButton/__new-tests__/CloseButton.test.tsx +70 -0
  18. package/src/CondensedButton/__new-tests__/CondensedButton.test.tsx +186 -0
  19. package/src/IconButton/__new-tests__/IconButton.test.tsx +214 -0
  20. package/src/ToggleButton/__new-tests__/ToggleButton.test.tsx +200 -0
  21. package/tsconfig.build.json +2 -3
  22. package/tsconfig.build.tsbuildinfo +1 -1
  23. package/types/BaseButton/__new-tests__/BaseButton.test.d.ts +2 -0
  24. package/types/BaseButton/__new-tests__/BaseButton.test.d.ts.map +1 -0
  25. package/types/Button/__new-tests__/Button.test.d.ts +2 -0
  26. package/types/Button/__new-tests__/Button.test.d.ts.map +1 -0
  27. package/types/CloseButton/__new-tests__/CloseButton.test.d.ts +2 -0
  28. package/types/CloseButton/__new-tests__/CloseButton.test.d.ts.map +1 -0
  29. package/types/CondensedButton/__new-tests__/CondensedButton.test.d.ts +2 -0
  30. package/types/CondensedButton/__new-tests__/CondensedButton.test.d.ts.map +1 -0
  31. package/types/IconButton/__new-tests__/IconButton.test.d.ts +2 -0
  32. package/types/IconButton/__new-tests__/IconButton.test.d.ts.map +1 -0
  33. package/types/ToggleButton/__new-tests__/ToggleButton.test.d.ts +2 -0
  34. package/types/ToggleButton/__new-tests__/ToggleButton.test.d.ts.map +1 -0
  35. package/es/BaseButton/BaseButtonLocator.js +0 -34
  36. package/es/BaseButton/locator.js +0 -27
  37. package/es/Button/ButtonLocator.js +0 -33
  38. package/es/Button/locator.js +0 -28
  39. package/es/CloseButton/CloseButtonLocator.js +0 -29
  40. package/es/CloseButton/locator.js +0 -27
  41. package/es/CondensedButton/CondensedButtonLocator.js +0 -33
  42. package/es/CondensedButton/locator.js +0 -26
  43. package/es/IconButton/IconButtonLocator.js +0 -33
  44. package/es/IconButton/locator.js +0 -26
  45. package/es/ToggleButton/ToggleButtonLocator.js +0 -46
  46. package/lib/BaseButton/BaseButtonLocator.js +0 -39
  47. package/lib/BaseButton/locator.js +0 -37
  48. package/lib/Button/ButtonLocator.js +0 -39
  49. package/lib/Button/locator.js +0 -39
  50. package/lib/CloseButton/CloseButtonLocator.js +0 -34
  51. package/lib/CloseButton/locator.js +0 -37
  52. package/lib/CondensedButton/CondensedButtonLocator.js +0 -39
  53. package/lib/CondensedButton/locator.js +0 -37
  54. package/lib/IconButton/IconButtonLocator.js +0 -39
  55. package/lib/IconButton/locator.js +0 -37
  56. package/lib/ToggleButton/ToggleButtonLocator.js +0 -51
  57. package/src/BaseButton/BaseButtonLocator.ts +0 -35
  58. package/src/BaseButton/locator.ts +0 -28
  59. package/src/Button/ButtonLocator.ts +0 -34
  60. package/src/Button/locator.ts +0 -27
  61. package/src/CloseButton/CloseButtonLocator.ts +0 -29
  62. package/src/CloseButton/locator.ts +0 -28
  63. package/src/CondensedButton/CondensedButtonLocator.ts +0 -34
  64. package/src/CondensedButton/locator.ts +0 -27
  65. package/src/IconButton/IconButtonLocator.ts +0 -34
  66. package/src/IconButton/locator.ts +0 -27
  67. package/src/ToggleButton/ToggleButtonLocator.ts +0 -44
  68. package/types/BaseButton/BaseButtonLocator.d.ts +0 -577
  69. package/types/BaseButton/BaseButtonLocator.d.ts.map +0 -1
  70. package/types/BaseButton/locator.d.ts +0 -4
  71. package/types/BaseButton/locator.d.ts.map +0 -1
  72. package/types/Button/ButtonLocator.d.ts +0 -577
  73. package/types/Button/ButtonLocator.d.ts.map +0 -1
  74. package/types/Button/locator.d.ts +0 -581
  75. package/types/Button/locator.d.ts.map +0 -1
  76. package/types/CloseButton/CloseButtonLocator.d.ts +0 -566
  77. package/types/CloseButton/CloseButtonLocator.d.ts.map +0 -1
  78. package/types/CloseButton/locator.d.ts +0 -4
  79. package/types/CloseButton/locator.d.ts.map +0 -1
  80. package/types/CondensedButton/CondensedButtonLocator.d.ts +0 -577
  81. package/types/CondensedButton/CondensedButtonLocator.d.ts.map +0 -1
  82. package/types/CondensedButton/locator.d.ts +0 -4
  83. package/types/CondensedButton/locator.d.ts.map +0 -1
  84. package/types/IconButton/IconButtonLocator.d.ts +0 -577
  85. package/types/IconButton/IconButtonLocator.d.ts.map +0 -1
  86. package/types/IconButton/locator.d.ts +0 -4
  87. package/types/IconButton/locator.d.ts.map +0 -1
  88. package/types/ToggleButton/ToggleButtonLocator.d.ts +0 -582
  89. package/types/ToggleButton/ToggleButtonLocator.d.ts.map +0 -1
@@ -0,0 +1,459 @@
1
+ var _circle, _Button, _Button2, _Button3, _Button4, _Button5, _Button6, _Button7, _Button8, _Button10, _Button11, _Button12, _Button13, _Button14, _Button15, _Button16, _Button17, _Button18;
2
+ /*
3
+ * The MIT License (MIT)
4
+ *
5
+ * Copyright (c) 2015 - present Instructure, Inc.
6
+ *
7
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ * of this software and associated documentation files (the "Software"), to deal
9
+ * in the Software without restriction, including without limitation the rights
10
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ * copies of the Software, and to permit persons to whom the Software is
12
+ * furnished to do so, subject to the following conditions:
13
+ *
14
+ * The above copyright notice and this permission notice shall be included in all
15
+ * copies or substantial portions of the Software.
16
+ *
17
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ * SOFTWARE.
24
+ */
25
+
26
+ import React from 'react';
27
+ import { render, screen, waitFor } from '@testing-library/react';
28
+ import userEvent from '@testing-library/user-event';
29
+ import '@testing-library/jest-dom';
30
+ import { runAxeCheck } from '@instructure/ui-axe-check';
31
+ import { Button } from '../index';
32
+ describe('<Button/>', () => {
33
+ var _Button9;
34
+ let consoleWarningMock;
35
+ const iconSelector = 'svg[data-title="myIcon"]';
36
+ const icon = /*#__PURE__*/React.createElement("svg", {
37
+ "data-title": "myIcon",
38
+ height: "1em",
39
+ width: "1em",
40
+ style: {
41
+ fill: 'currentcolor'
42
+ }
43
+ }, _circle || (_circle = /*#__PURE__*/React.createElement("circle", {
44
+ cx: "0.5em",
45
+ cy: "0.5em",
46
+ r: "0.5em"
47
+ })));
48
+ beforeEach(() => {
49
+ // Mocking console to prevent test output pollution
50
+ consoleWarningMock = jest.spyOn(console, 'warn').mockImplementation();
51
+ });
52
+ afterEach(() => {
53
+ consoleWarningMock.mockRestore();
54
+ });
55
+ it('should render children', () => {
56
+ const children = 'Hello world';
57
+ render( /*#__PURE__*/React.createElement(Button, null, children));
58
+ const button = document.querySelector('button');
59
+ expect(button).toBeInTheDocument();
60
+ expect(button).toHaveTextContent(children);
61
+ });
62
+ it('should render a button', () => {
63
+ render(_Button || (_Button = /*#__PURE__*/React.createElement(Button, null, "Hello World")));
64
+ const button = screen.getByRole('button', {
65
+ name: 'Hello World'
66
+ });
67
+ expect(button).toBeInTheDocument();
68
+ expect(button).toHaveAttribute('type', 'button');
69
+ });
70
+ it('should provide a focused getter', () => {
71
+ var _componentRef;
72
+ let componentRef;
73
+ render( /*#__PURE__*/React.createElement(Button
74
+ //@ts-expect-error TODO this is coming from ReactComponentWrapper
75
+ , {
76
+ ref: component => {
77
+ componentRef = component;
78
+ }
79
+ }, "Hello"));
80
+ const button = screen.getByRole('button', {
81
+ name: 'Hello'
82
+ });
83
+ button.focus();
84
+ expect((_componentRef = componentRef) === null || _componentRef === void 0 ? void 0 : _componentRef.focused).toBe(true);
85
+ });
86
+ it('should provide a focus function', () => {
87
+ var _componentRef2;
88
+ let componentRef;
89
+ render( /*#__PURE__*/React.createElement(Button
90
+ //@ts-expect-error TODO this is coming from ReactComponentWrapper
91
+ , {
92
+ ref: component => {
93
+ componentRef = component;
94
+ }
95
+ }, "Hello"));
96
+ const button = screen.getByRole('button', {
97
+ name: 'Hello'
98
+ });
99
+ (_componentRef2 = componentRef) === null || _componentRef2 === void 0 ? void 0 : _componentRef2.focus();
100
+ expect(document.activeElement).toBe(button);
101
+ });
102
+ it('should pass the type attribute', () => {
103
+ render(_Button2 || (_Button2 = /*#__PURE__*/React.createElement(Button, {
104
+ type: "submit"
105
+ }, "Hello")));
106
+ const button = screen.getByRole('button', {
107
+ name: 'Hello'
108
+ });
109
+ expect(button).toBeInTheDocument();
110
+ expect(button).toHaveAttribute('type', 'submit');
111
+ });
112
+ it('should pass the `elementRef` prop', () => {
113
+ const elementRef = jest.fn();
114
+ render( /*#__PURE__*/React.createElement(Button, {
115
+ elementRef: elementRef
116
+ }, "Hello"));
117
+ const button = screen.getByRole('button', {
118
+ name: 'Hello'
119
+ });
120
+ expect(elementRef).toHaveBeenCalledWith(button);
121
+ });
122
+ it('should pass the `as` prop', () => {
123
+ const _render = render(_Button3 || (_Button3 = /*#__PURE__*/React.createElement(Button, {
124
+ as: "li"
125
+ }, "Hello"))),
126
+ container = _render.container;
127
+ const button = container.querySelector('[type="button"]');
128
+ expect(button).toBeInTheDocument();
129
+ expect(button).toHaveTextContent('Hello');
130
+ expect(button.tagName).toBe('LI');
131
+ });
132
+ it('should set the disabled attribute when `interaction` is set to disabled', () => {
133
+ render(_Button4 || (_Button4 = /*#__PURE__*/React.createElement(Button, {
134
+ interaction: "disabled"
135
+ }, "Hello")));
136
+ const button = screen.getByRole('button', {
137
+ name: 'Hello'
138
+ });
139
+ expect(button).toHaveAttribute('disabled');
140
+ });
141
+ it('should set the disabled attribute when `disabled` is set', () => {
142
+ render(_Button5 || (_Button5 = /*#__PURE__*/React.createElement(Button, {
143
+ disabled: true
144
+ }, "Hello")));
145
+ const button = screen.getByRole('button', {
146
+ name: 'Hello'
147
+ });
148
+ expect(button).toHaveAttribute('disabled');
149
+ });
150
+ it('should set the disabled attribute when `interaction` is set to readonly', () => {
151
+ render(_Button6 || (_Button6 = /*#__PURE__*/React.createElement(Button, {
152
+ interaction: "readonly"
153
+ }, "Hello")));
154
+ const button = screen.getByRole('button', {
155
+ name: 'Hello'
156
+ });
157
+ expect(button).toHaveAttribute('disabled');
158
+ });
159
+ it('should set the disabled attribute when `readOnly` is set', () => {
160
+ render(_Button7 || (_Button7 = /*#__PURE__*/React.createElement(Button, {
161
+ readOnly: true
162
+ }, "Hello")));
163
+ const button = screen.getByRole('button', {
164
+ name: 'Hello'
165
+ });
166
+ expect(button).toHaveAttribute('disabled');
167
+ });
168
+ it('should pass the `href` prop', () => {
169
+ render(_Button8 || (_Button8 = /*#__PURE__*/React.createElement(Button, {
170
+ href: "#"
171
+ }, "Hello")));
172
+ const linkButton = screen.getByRole('link', {
173
+ name: 'Hello'
174
+ });
175
+ expect(linkButton).toBeInTheDocument();
176
+ expect(linkButton).toHaveAttribute('href', '#');
177
+ });
178
+ it('should pass the `renderIcon` prop', () => {
179
+ render(_Button9 || (_Button9 = /*#__PURE__*/React.createElement(Button, {
180
+ renderIcon: icon
181
+ }, "Hello")));
182
+ const svgIcon = document.querySelector(iconSelector);
183
+ const button = screen.getByRole('button', {
184
+ name: 'Hello'
185
+ });
186
+ expect(button).toBeInTheDocument();
187
+ expect(svgIcon).toBeInTheDocument();
188
+ });
189
+ it('should pass the `onClick` prop', async () => {
190
+ const onClick = jest.fn();
191
+ render( /*#__PURE__*/React.createElement(Button, {
192
+ onClick: onClick
193
+ }, "Hello"));
194
+ const button = screen.getByRole('button', {
195
+ name: 'Hello'
196
+ });
197
+ await userEvent.click(button);
198
+ await waitFor(() => {
199
+ expect(onClick).toHaveBeenCalledTimes(1);
200
+ });
201
+ });
202
+ it('should render the children as button text', () => {
203
+ render(_Button10 || (_Button10 = /*#__PURE__*/React.createElement(Button, null, "Hello World")));
204
+ const button = screen.getByRole('button');
205
+ expect(button).toBeInTheDocument();
206
+ expect(button).toHaveTextContent('Hello World');
207
+ });
208
+ it('should render a button', async () => {
209
+ render(_Button11 || (_Button11 = /*#__PURE__*/React.createElement(Button, null, "Hello World")));
210
+ const button = screen.getByRole('button');
211
+ expect(button).toBeInTheDocument();
212
+ expect(button).toHaveAttribute('type', 'button');
213
+ expect(button).toHaveTextContent('Hello World');
214
+ });
215
+ it('should not error with a null child', () => {
216
+ render(_Button12 || (_Button12 = /*#__PURE__*/React.createElement(Button, null, "Hello World", null)));
217
+ const button = screen.getByRole('button', {
218
+ name: 'Hello World'
219
+ });
220
+ expect(button).toBeInTheDocument();
221
+ });
222
+ it('should render a link styled as a button if href is provided', () => {
223
+ render(_Button13 || (_Button13 = /*#__PURE__*/React.createElement(Button, {
224
+ href: "example.html"
225
+ }, "Hello World")));
226
+ const button = screen.getAllByRole('link', {
227
+ name: 'Hello World'
228
+ });
229
+ expect(button).toHaveLength(1);
230
+ expect(button[0]).toHaveAttribute('href', 'example.html');
231
+ });
232
+ it('should render as a link when `to` prop is provided', () => {
233
+ const _render2 = render(_Button14 || (_Button14 = /*#__PURE__*/React.createElement(Button, {
234
+ to: "/example"
235
+ }, "Test"))),
236
+ container = _render2.container;
237
+ const linkButton = container.querySelector('a');
238
+ expect(linkButton).toBeInTheDocument();
239
+ expect(linkButton).toHaveAttribute('to', '/example');
240
+ });
241
+ it('should render designated tag if `as` prop is specified', () => {
242
+ const _render3 = render(_Button15 || (_Button15 = /*#__PURE__*/React.createElement(Button, {
243
+ as: "span"
244
+ }, "Hello World"))),
245
+ container = _render3.container;
246
+ const button = container.querySelector('[type="button"]');
247
+ expect(button).toBeInTheDocument();
248
+ expect(button).toHaveTextContent('Hello World');
249
+ expect(button.tagName).toBe('SPAN');
250
+ });
251
+ it('should set role="button"', () => {
252
+ const onClick = jest.fn();
253
+ const _render4 = render( /*#__PURE__*/React.createElement(Button, {
254
+ as: "span",
255
+ onClick: onClick
256
+ }, "Hello World")),
257
+ container = _render4.container;
258
+ const button = container.querySelector('[type="button"]');
259
+ expect(button).toBeInTheDocument();
260
+ expect(button).toHaveAttribute('role', 'button');
261
+ });
262
+ it('should set tabIndex="0"', () => {
263
+ const onClick = jest.fn();
264
+ render( /*#__PURE__*/React.createElement(Button, {
265
+ as: "span",
266
+ onClick: onClick
267
+ }, "Hello World"));
268
+ const button = screen.getByRole('button');
269
+ expect(button).toBeInTheDocument();
270
+ expect(button).toHaveAttribute('tabIndex', '0');
271
+ });
272
+ it('should pass down the type prop to the button element', () => {
273
+ const onClick = jest.fn();
274
+ render( /*#__PURE__*/React.createElement(Button, {
275
+ type: "submit",
276
+ onClick: onClick
277
+ }, "Hello World"));
278
+ const button = screen.getByRole('button');
279
+ expect(button).toBeInTheDocument();
280
+ expect(button).toHaveAttribute('type', 'submit');
281
+ });
282
+ it('focuses with the focus helper', () => {
283
+ const onFocus = jest.fn();
284
+ render( /*#__PURE__*/React.createElement(Button, {
285
+ onFocus: onFocus
286
+ }, "Hello World"));
287
+ const button = screen.getByRole('button');
288
+ button.focus();
289
+ expect(onFocus).toHaveBeenCalled();
290
+ expect(document.activeElement).toBe(button);
291
+ });
292
+ describe('onClick', () => {
293
+ it('should call onClick when clicked', async () => {
294
+ const onClick = jest.fn();
295
+ render( /*#__PURE__*/React.createElement(Button, {
296
+ onClick: onClick
297
+ }, "Hello World"));
298
+ const button = screen.getByRole('button', {
299
+ name: 'Hello World'
300
+ });
301
+ await userEvent.click(button);
302
+ await waitFor(() => {
303
+ expect(onClick).toHaveBeenCalled();
304
+ });
305
+ });
306
+ it('should not call onClick when button is disabled', async () => {
307
+ const onClick = jest.fn();
308
+ render( /*#__PURE__*/React.createElement(Button, {
309
+ disabled: true,
310
+ onClick: onClick
311
+ }, "Hello World"));
312
+ const button = screen.getByRole('button', {
313
+ name: 'Hello World'
314
+ });
315
+ await userEvent.click(button);
316
+ await waitFor(() => {
317
+ expect(onClick).not.toHaveBeenCalled();
318
+ });
319
+ });
320
+ it('should not call onClick when button is readOnly', async () => {
321
+ const onClick = jest.fn();
322
+ render( /*#__PURE__*/React.createElement(Button, {
323
+ readOnly: true,
324
+ onClick: onClick
325
+ }, "Hello World"));
326
+ const button = screen.getByRole('button', {
327
+ name: 'Hello World'
328
+ });
329
+ await userEvent.click(button);
330
+ await waitFor(() => {
331
+ expect(onClick).not.toHaveBeenCalled();
332
+ });
333
+ });
334
+ it('should not call onClick when button is disabled and an href prop is provided', async () => {
335
+ const onClick = jest.fn();
336
+ render(_Button16 || (_Button16 = /*#__PURE__*/React.createElement(Button, {
337
+ href: "#"
338
+ }, "Hello World")));
339
+ const button = screen.getByRole('link', {
340
+ name: 'Hello World'
341
+ });
342
+ await userEvent.click(button);
343
+ await waitFor(() => {
344
+ expect(onClick).not.toHaveBeenCalled();
345
+ });
346
+ });
347
+ it('should not call onClick when button is readOnly and an href prop is provided', async () => {
348
+ const onClick = jest.fn();
349
+ render( /*#__PURE__*/React.createElement(Button, {
350
+ readOnly: true,
351
+ onClick: onClick,
352
+ href: "#"
353
+ }, "Hello World"));
354
+ const button = screen.getByRole('link', {
355
+ name: 'Hello World'
356
+ });
357
+ await userEvent.click(button);
358
+ await waitFor(() => {
359
+ expect(onClick).not.toHaveBeenCalled();
360
+ });
361
+ });
362
+ it('should call onClick when space key is pressed if href is provided', async () => {
363
+ const onClick = jest.fn();
364
+ render( /*#__PURE__*/React.createElement(Button, {
365
+ onClick: onClick,
366
+ href: "#"
367
+ }, "Hello World"));
368
+ const button = screen.getByRole('link', {
369
+ name: 'Hello World'
370
+ });
371
+ await userEvent.type(button, '{space}');
372
+ await waitFor(() => {
373
+ expect(onClick).toHaveBeenCalled();
374
+ });
375
+ });
376
+ it('should call onClick when enter key is pressed when not a button or link', async () => {
377
+ const onClick = jest.fn();
378
+ render( /*#__PURE__*/React.createElement(Button, {
379
+ as: "span",
380
+ onClick: onClick
381
+ }, "Hello World"));
382
+ const button = screen.getByRole('button', {
383
+ name: 'Hello World'
384
+ });
385
+ await userEvent.type(button, '{enter}');
386
+ await waitFor(() => {
387
+ expect(onClick).toHaveBeenCalled();
388
+ });
389
+ });
390
+ it('should not call onClick when button is disabled and space key is pressed', async () => {
391
+ const onClick = jest.fn();
392
+ render( /*#__PURE__*/React.createElement(Button, {
393
+ disabled: true,
394
+ onClick: onClick,
395
+ href: "#"
396
+ }, "Hello World"));
397
+ const button = screen.getByRole('link', {
398
+ name: 'Hello World'
399
+ });
400
+ await userEvent.type(button, '{spaec}');
401
+ await waitFor(() => {
402
+ expect(onClick).not.toHaveBeenCalled();
403
+ });
404
+ });
405
+ it('should not call onClick when button is readOnly and space key is pressed', async () => {
406
+ const onClick = jest.fn();
407
+ render( /*#__PURE__*/React.createElement(Button, {
408
+ readOnly: true,
409
+ onClick: onClick,
410
+ href: "#"
411
+ }, "Hello World"));
412
+ const button = screen.getByRole('link', {
413
+ name: 'Hello World'
414
+ });
415
+ await userEvent.type(button, '{space}');
416
+ await waitFor(() => {
417
+ expect(onClick).not.toHaveBeenCalled();
418
+ });
419
+ });
420
+ });
421
+ describe('for a11y', () => {
422
+ it('should meet standards when onClick is given', async () => {
423
+ const onClick = jest.fn();
424
+ render( /*#__PURE__*/React.createElement(Button, {
425
+ onClick: onClick
426
+ }, "Hello World"));
427
+ const button = screen.getByRole('button', {
428
+ name: 'Hello World'
429
+ });
430
+ await userEvent.click(button);
431
+ await waitFor(async () => {
432
+ const axeCheck = await runAxeCheck(button);
433
+ expect(axeCheck).toBe(true);
434
+ });
435
+ });
436
+ describe('when disabled', () => {
437
+ it('sets the disabled attribute so that the button is not in tab order', () => {
438
+ render(_Button17 || (_Button17 = /*#__PURE__*/React.createElement(Button, {
439
+ disabled: true
440
+ }, "Hello World")));
441
+ const button = screen.getByRole('button', {
442
+ name: 'Hello World'
443
+ });
444
+ expect(button).toHaveAttribute('disabled');
445
+ });
446
+ });
447
+ describe('when readOnly', () => {
448
+ it('sets the disabled attribute so that the button is not in tab order', () => {
449
+ render(_Button18 || (_Button18 = /*#__PURE__*/React.createElement(Button, {
450
+ readOnly: true
451
+ }, "Hello World")));
452
+ const button = screen.getByRole('button', {
453
+ name: 'Hello World'
454
+ });
455
+ expect(button).toHaveAttribute('disabled');
456
+ });
457
+ });
458
+ });
459
+ });
@@ -0,0 +1,63 @@
1
+ var _CloseButton;
2
+ /*
3
+ * The MIT License (MIT)
4
+ *
5
+ * Copyright (c) 2015 - present Instructure, Inc.
6
+ *
7
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ * of this software and associated documentation files (the "Software"), to deal
9
+ * in the Software without restriction, including without limitation the rights
10
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ * copies of the Software, and to permit persons to whom the Software is
12
+ * furnished to do so, subject to the following conditions:
13
+ *
14
+ * The above copyright notice and this permission notice shall be included in all
15
+ * copies or substantial portions of the Software.
16
+ *
17
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ * SOFTWARE.
24
+ */
25
+
26
+ import React from 'react';
27
+ import { render, screen, waitFor } from '@testing-library/react';
28
+ import userEvent from '@testing-library/user-event';
29
+ import '@testing-library/jest-dom';
30
+ import { CloseButton } from '../index';
31
+ describe('<CloseButton />', () => {
32
+ let consoleWarningMock;
33
+ beforeEach(() => {
34
+ // Mocking console to prevent test output pollution
35
+ consoleWarningMock = jest.spyOn(console, 'warn').mockImplementation();
36
+ });
37
+ afterEach(() => {
38
+ consoleWarningMock.mockRestore();
39
+ });
40
+ it('should render with x icon', async () => {
41
+ render(_CloseButton || (_CloseButton = /*#__PURE__*/React.createElement(CloseButton, {
42
+ screenReaderLabel: "Close"
43
+ })));
44
+ const button = screen.getByRole('button');
45
+ const icon = document.querySelector('svg');
46
+ expect(icon).toBeInTheDocument();
47
+ expect(icon).toHaveAttribute('name', 'IconX');
48
+ expect(button).toBeInTheDocument();
49
+ expect(button).toHaveTextContent('Close');
50
+ });
51
+ it('should pass the `onClick` prop', async () => {
52
+ const onClick = jest.fn();
53
+ render( /*#__PURE__*/React.createElement(CloseButton, {
54
+ onClick: onClick,
55
+ screenReaderLabel: "Hello"
56
+ }));
57
+ const button = screen.getByRole('button');
58
+ await userEvent.click(button);
59
+ await waitFor(() => {
60
+ expect(onClick).toHaveBeenCalledTimes(1);
61
+ });
62
+ });
63
+ });