@instructure/ui-buttons 9.2.1-snapshot-0 → 9.2.1-snapshot-2
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/README.md +2 -2
- package/es/BaseButton/__new-tests__/BaseButton.test.js +22 -18
- package/es/Button/__new-tests__/Button.test.js +21 -17
- package/es/CloseButton/__new-tests__/CloseButton.test.js +3 -2
- package/es/CondensedButton/__new-tests__/CondensedButton.test.js +3 -2
- package/es/IconButton/__new-tests__/IconButton.test.js +3 -2
- package/es/ToggleButton/__new-tests__/ToggleButton.test.js +2 -1
- package/lib/BaseButton/__new-tests__/BaseButton.test.js +22 -18
- package/lib/Button/__new-tests__/Button.test.js +21 -17
- package/lib/CloseButton/__new-tests__/CloseButton.test.js +3 -2
- package/lib/CondensedButton/__new-tests__/CondensedButton.test.js +3 -2
- package/lib/IconButton/__new-tests__/IconButton.test.js +3 -2
- package/lib/ToggleButton/__new-tests__/ToggleButton.test.js +2 -1
- package/package.json +22 -21
- package/src/BaseButton/__new-tests__/BaseButton.test.tsx +28 -19
- package/src/Button/__new-tests__/Button.test.tsx +26 -18
- package/src/CloseButton/__new-tests__/CloseButton.test.tsx +6 -3
- package/src/CondensedButton/__new-tests__/CondensedButton.test.tsx +3 -2
- package/src/IconButton/__new-tests__/IconButton.test.tsx +3 -2
- package/src/ToggleButton/__new-tests__/ToggleButton.test.tsx +2 -1
- package/tsconfig.build.tsbuildinfo +1 -1
- package/types/BaseButton/__new-tests__/BaseButton.test.d.ts.map +1 -1
- package/types/Button/__new-tests__/Button.test.d.ts.map +1 -1
- package/types/CloseButton/__new-tests__/CloseButton.test.d.ts.map +1 -1
- package/types/CondensedButton/__new-tests__/CondensedButton.test.d.ts.map +1 -1
- package/types/IconButton/__new-tests__/IconButton.test.d.ts.map +1 -1
- package/types/ToggleButton/__new-tests__/ToggleButton.test.d.ts.map +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
-
## [9.2.1-snapshot-
|
|
6
|
+
## [9.2.1-snapshot-2](https://github.com/instructure/instructure-ui/compare/v9.2.0...v9.2.1-snapshot-2) (2024-07-10)
|
|
7
7
|
|
|
8
8
|
**Note:** Version bump only for package @instructure/ui-buttons
|
|
9
9
|
|
package/README.md
CHANGED
|
@@ -25,18 +25,22 @@ var _BaseButton, _BaseButton2, _BaseButton3, _BaseButton4, _BaseButton5, _svg, _
|
|
|
25
25
|
|
|
26
26
|
import React from 'react';
|
|
27
27
|
import { render, screen, waitFor } from '@testing-library/react';
|
|
28
|
+
import { vi } from 'vitest';
|
|
28
29
|
import userEvent from '@testing-library/user-event';
|
|
29
30
|
import '@testing-library/jest-dom';
|
|
30
31
|
import { BaseButton } from '../index';
|
|
31
32
|
import { runAxeCheck } from '@instructure/ui-axe-check';
|
|
32
33
|
describe('<BaseButton/>', () => {
|
|
33
34
|
let consoleWarningMock;
|
|
35
|
+
let consoleErrorMock;
|
|
34
36
|
beforeEach(() => {
|
|
35
|
-
// Mocking console to prevent test output pollution
|
|
36
|
-
consoleWarningMock =
|
|
37
|
+
// Mocking console to prevent test output pollution and expect for messages
|
|
38
|
+
consoleWarningMock = vi.spyOn(console, 'warn').mockImplementation(() => {});
|
|
39
|
+
consoleErrorMock = vi.spyOn(console, 'error').mockImplementation(() => {});
|
|
37
40
|
});
|
|
38
41
|
afterEach(() => {
|
|
39
42
|
consoleWarningMock.mockRestore();
|
|
43
|
+
consoleErrorMock.mockRestore();
|
|
40
44
|
});
|
|
41
45
|
it('should render a button and the children as button text', () => {
|
|
42
46
|
render(_BaseButton || (_BaseButton = /*#__PURE__*/React.createElement(BaseButton, null, "Hello World")));
|
|
@@ -79,7 +83,7 @@ describe('<BaseButton/>', () => {
|
|
|
79
83
|
expect(button.tagName).toBe('SPAN');
|
|
80
84
|
});
|
|
81
85
|
it('should set role="button"', () => {
|
|
82
|
-
const onClick =
|
|
86
|
+
const onClick = vi.fn();
|
|
83
87
|
const _render3 = render( /*#__PURE__*/React.createElement(BaseButton, {
|
|
84
88
|
as: "span",
|
|
85
89
|
onClick: onClick
|
|
@@ -90,7 +94,7 @@ describe('<BaseButton/>', () => {
|
|
|
90
94
|
expect(button).toHaveAttribute('role', 'button');
|
|
91
95
|
});
|
|
92
96
|
it('should set tabIndex="0"', () => {
|
|
93
|
-
const onClick =
|
|
97
|
+
const onClick = vi.fn();
|
|
94
98
|
render( /*#__PURE__*/React.createElement(BaseButton, {
|
|
95
99
|
as: "span",
|
|
96
100
|
onClick: onClick
|
|
@@ -102,7 +106,7 @@ describe('<BaseButton/>', () => {
|
|
|
102
106
|
expect(button).toHaveAttribute('tabIndex', '0');
|
|
103
107
|
});
|
|
104
108
|
it('should pass down the type prop to the button element', async () => {
|
|
105
|
-
const onClick =
|
|
109
|
+
const onClick = vi.fn();
|
|
106
110
|
render( /*#__PURE__*/React.createElement(BaseButton, {
|
|
107
111
|
type: "submit",
|
|
108
112
|
onClick: onClick
|
|
@@ -134,7 +138,7 @@ describe('<BaseButton/>', () => {
|
|
|
134
138
|
expect(document.activeElement).toBe(button);
|
|
135
139
|
});
|
|
136
140
|
it('should provide an elementRef prop', async () => {
|
|
137
|
-
const elementRef =
|
|
141
|
+
const elementRef = vi.fn();
|
|
138
142
|
render( /*#__PURE__*/React.createElement(BaseButton, {
|
|
139
143
|
elementRef: elementRef
|
|
140
144
|
}, "Hello World"));
|
|
@@ -145,7 +149,7 @@ describe('<BaseButton/>', () => {
|
|
|
145
149
|
});
|
|
146
150
|
describe('onClick', () => {
|
|
147
151
|
it('should call onClick when clicked', async () => {
|
|
148
|
-
const onClick =
|
|
152
|
+
const onClick = vi.fn();
|
|
149
153
|
render( /*#__PURE__*/React.createElement(BaseButton, {
|
|
150
154
|
onClick: onClick
|
|
151
155
|
}, "Hello World"));
|
|
@@ -158,7 +162,7 @@ describe('<BaseButton/>', () => {
|
|
|
158
162
|
});
|
|
159
163
|
});
|
|
160
164
|
it('should not call onClick when interaction is "disabled"', async () => {
|
|
161
|
-
const onClick =
|
|
165
|
+
const onClick = vi.fn();
|
|
162
166
|
render( /*#__PURE__*/React.createElement(BaseButton, {
|
|
163
167
|
interaction: "disabled",
|
|
164
168
|
onClick: onClick
|
|
@@ -172,7 +176,7 @@ describe('<BaseButton/>', () => {
|
|
|
172
176
|
});
|
|
173
177
|
});
|
|
174
178
|
it('should not call onClick when disabled is set"', async () => {
|
|
175
|
-
const onClick =
|
|
179
|
+
const onClick = vi.fn();
|
|
176
180
|
render( /*#__PURE__*/React.createElement(BaseButton, {
|
|
177
181
|
disabled: true,
|
|
178
182
|
onClick: onClick
|
|
@@ -186,7 +190,7 @@ describe('<BaseButton/>', () => {
|
|
|
186
190
|
});
|
|
187
191
|
});
|
|
188
192
|
it('should not call onClick when interaction is "readonly"', async () => {
|
|
189
|
-
const onClick =
|
|
193
|
+
const onClick = vi.fn();
|
|
190
194
|
render( /*#__PURE__*/React.createElement(BaseButton, {
|
|
191
195
|
interaction: "readonly",
|
|
192
196
|
onClick: onClick
|
|
@@ -200,7 +204,7 @@ describe('<BaseButton/>', () => {
|
|
|
200
204
|
});
|
|
201
205
|
});
|
|
202
206
|
it('should not call onClick when readOnly is set', async () => {
|
|
203
|
-
const onClick =
|
|
207
|
+
const onClick = vi.fn();
|
|
204
208
|
render( /*#__PURE__*/React.createElement(BaseButton, {
|
|
205
209
|
readOnly: true,
|
|
206
210
|
onClick: onClick
|
|
@@ -214,7 +218,7 @@ describe('<BaseButton/>', () => {
|
|
|
214
218
|
});
|
|
215
219
|
});
|
|
216
220
|
it('should not call onClick when button is disabled and an href prop is provided', async () => {
|
|
217
|
-
const onClick =
|
|
221
|
+
const onClick = vi.fn();
|
|
218
222
|
render(_BaseButton7 || (_BaseButton7 = /*#__PURE__*/React.createElement(BaseButton, {
|
|
219
223
|
href: "#"
|
|
220
224
|
}, "Hello World")));
|
|
@@ -227,7 +231,7 @@ describe('<BaseButton/>', () => {
|
|
|
227
231
|
});
|
|
228
232
|
});
|
|
229
233
|
it('should not call onClick when interaction is "readonly" and an href prop is provided', async () => {
|
|
230
|
-
const onClick =
|
|
234
|
+
const onClick = vi.fn();
|
|
231
235
|
render( /*#__PURE__*/React.createElement(BaseButton, {
|
|
232
236
|
interaction: "readonly",
|
|
233
237
|
onClick: onClick,
|
|
@@ -242,7 +246,7 @@ describe('<BaseButton/>', () => {
|
|
|
242
246
|
});
|
|
243
247
|
});
|
|
244
248
|
it('should call onClick when space key is pressed if href is provided', async () => {
|
|
245
|
-
const onClick =
|
|
249
|
+
const onClick = vi.fn();
|
|
246
250
|
render( /*#__PURE__*/React.createElement(BaseButton, {
|
|
247
251
|
onClick: onClick,
|
|
248
252
|
href: "#"
|
|
@@ -256,7 +260,7 @@ describe('<BaseButton/>', () => {
|
|
|
256
260
|
});
|
|
257
261
|
});
|
|
258
262
|
it('should call onClick when enter key is pressed when not a button or link', async () => {
|
|
259
|
-
const onClick =
|
|
263
|
+
const onClick = vi.fn();
|
|
260
264
|
render( /*#__PURE__*/React.createElement(BaseButton, {
|
|
261
265
|
as: "span",
|
|
262
266
|
onClick: onClick
|
|
@@ -270,7 +274,7 @@ describe('<BaseButton/>', () => {
|
|
|
270
274
|
});
|
|
271
275
|
});
|
|
272
276
|
it('should not call onClick when interaction is "disabled" and space key is pressed', async () => {
|
|
273
|
-
const onClick =
|
|
277
|
+
const onClick = vi.fn();
|
|
274
278
|
render( /*#__PURE__*/React.createElement(BaseButton, {
|
|
275
279
|
interaction: "disabled",
|
|
276
280
|
onClick: onClick,
|
|
@@ -285,7 +289,7 @@ describe('<BaseButton/>', () => {
|
|
|
285
289
|
});
|
|
286
290
|
});
|
|
287
291
|
it('should not call onClick when interaction is "readonly" and space key is pressed', async () => {
|
|
288
|
-
const onClick =
|
|
292
|
+
const onClick = vi.fn();
|
|
289
293
|
render( /*#__PURE__*/React.createElement(BaseButton, {
|
|
290
294
|
interaction: "readonly",
|
|
291
295
|
onClick: onClick,
|
|
@@ -322,7 +326,7 @@ describe('<BaseButton/>', () => {
|
|
|
322
326
|
});
|
|
323
327
|
describe('for a11y', () => {
|
|
324
328
|
it('should meet standards when onClick is given', async () => {
|
|
325
|
-
const onClick =
|
|
329
|
+
const onClick = vi.fn();
|
|
326
330
|
render( /*#__PURE__*/React.createElement(BaseButton, {
|
|
327
331
|
onClick: onClick
|
|
328
332
|
}, "Hello World"));
|
|
@@ -25,6 +25,7 @@ var _circle, _Button, _Button2, _Button3, _Button4, _Button5, _Button6, _Button7
|
|
|
25
25
|
|
|
26
26
|
import React from 'react';
|
|
27
27
|
import { render, screen, waitFor } from '@testing-library/react';
|
|
28
|
+
import { vi } from 'vitest';
|
|
28
29
|
import userEvent from '@testing-library/user-event';
|
|
29
30
|
import '@testing-library/jest-dom';
|
|
30
31
|
import { runAxeCheck } from '@instructure/ui-axe-check';
|
|
@@ -32,6 +33,7 @@ import { Button } from '../index';
|
|
|
32
33
|
describe('<Button/>', () => {
|
|
33
34
|
var _Button9;
|
|
34
35
|
let consoleWarningMock;
|
|
36
|
+
let consoleErrorMock;
|
|
35
37
|
const iconSelector = 'svg[data-title="myIcon"]';
|
|
36
38
|
const icon = /*#__PURE__*/React.createElement("svg", {
|
|
37
39
|
"data-title": "myIcon",
|
|
@@ -47,10 +49,12 @@ describe('<Button/>', () => {
|
|
|
47
49
|
})));
|
|
48
50
|
beforeEach(() => {
|
|
49
51
|
// Mocking console to prevent test output pollution
|
|
50
|
-
consoleWarningMock =
|
|
52
|
+
consoleWarningMock = vi.spyOn(console, 'warn').mockImplementation(() => {});
|
|
53
|
+
consoleErrorMock = vi.spyOn(console, 'error').mockImplementation(() => {});
|
|
51
54
|
});
|
|
52
55
|
afterEach(() => {
|
|
53
56
|
consoleWarningMock.mockRestore();
|
|
57
|
+
consoleErrorMock.mockRestore();
|
|
54
58
|
});
|
|
55
59
|
it('should render children', () => {
|
|
56
60
|
const children = 'Hello world';
|
|
@@ -110,7 +114,7 @@ describe('<Button/>', () => {
|
|
|
110
114
|
expect(button).toHaveAttribute('type', 'submit');
|
|
111
115
|
});
|
|
112
116
|
it('should pass the `elementRef` prop', () => {
|
|
113
|
-
const elementRef =
|
|
117
|
+
const elementRef = vi.fn();
|
|
114
118
|
render( /*#__PURE__*/React.createElement(Button, {
|
|
115
119
|
elementRef: elementRef
|
|
116
120
|
}, "Hello"));
|
|
@@ -187,7 +191,7 @@ describe('<Button/>', () => {
|
|
|
187
191
|
expect(svgIcon).toBeInTheDocument();
|
|
188
192
|
});
|
|
189
193
|
it('should pass the `onClick` prop', async () => {
|
|
190
|
-
const onClick =
|
|
194
|
+
const onClick = vi.fn();
|
|
191
195
|
render( /*#__PURE__*/React.createElement(Button, {
|
|
192
196
|
onClick: onClick
|
|
193
197
|
}, "Hello"));
|
|
@@ -249,7 +253,7 @@ describe('<Button/>', () => {
|
|
|
249
253
|
expect(button.tagName).toBe('SPAN');
|
|
250
254
|
});
|
|
251
255
|
it('should set role="button"', () => {
|
|
252
|
-
const onClick =
|
|
256
|
+
const onClick = vi.fn();
|
|
253
257
|
const _render4 = render( /*#__PURE__*/React.createElement(Button, {
|
|
254
258
|
as: "span",
|
|
255
259
|
onClick: onClick
|
|
@@ -260,7 +264,7 @@ describe('<Button/>', () => {
|
|
|
260
264
|
expect(button).toHaveAttribute('role', 'button');
|
|
261
265
|
});
|
|
262
266
|
it('should set tabIndex="0"', () => {
|
|
263
|
-
const onClick =
|
|
267
|
+
const onClick = vi.fn();
|
|
264
268
|
render( /*#__PURE__*/React.createElement(Button, {
|
|
265
269
|
as: "span",
|
|
266
270
|
onClick: onClick
|
|
@@ -270,7 +274,7 @@ describe('<Button/>', () => {
|
|
|
270
274
|
expect(button).toHaveAttribute('tabIndex', '0');
|
|
271
275
|
});
|
|
272
276
|
it('should pass down the type prop to the button element', () => {
|
|
273
|
-
const onClick =
|
|
277
|
+
const onClick = vi.fn();
|
|
274
278
|
render( /*#__PURE__*/React.createElement(Button, {
|
|
275
279
|
type: "submit",
|
|
276
280
|
onClick: onClick
|
|
@@ -280,7 +284,7 @@ describe('<Button/>', () => {
|
|
|
280
284
|
expect(button).toHaveAttribute('type', 'submit');
|
|
281
285
|
});
|
|
282
286
|
it('focuses with the focus helper', () => {
|
|
283
|
-
const onFocus =
|
|
287
|
+
const onFocus = vi.fn();
|
|
284
288
|
render( /*#__PURE__*/React.createElement(Button, {
|
|
285
289
|
onFocus: onFocus
|
|
286
290
|
}, "Hello World"));
|
|
@@ -291,7 +295,7 @@ describe('<Button/>', () => {
|
|
|
291
295
|
});
|
|
292
296
|
describe('onClick', () => {
|
|
293
297
|
it('should call onClick when clicked', async () => {
|
|
294
|
-
const onClick =
|
|
298
|
+
const onClick = vi.fn();
|
|
295
299
|
render( /*#__PURE__*/React.createElement(Button, {
|
|
296
300
|
onClick: onClick
|
|
297
301
|
}, "Hello World"));
|
|
@@ -304,7 +308,7 @@ describe('<Button/>', () => {
|
|
|
304
308
|
});
|
|
305
309
|
});
|
|
306
310
|
it('should not call onClick when button is disabled', async () => {
|
|
307
|
-
const onClick =
|
|
311
|
+
const onClick = vi.fn();
|
|
308
312
|
render( /*#__PURE__*/React.createElement(Button, {
|
|
309
313
|
disabled: true,
|
|
310
314
|
onClick: onClick
|
|
@@ -318,7 +322,7 @@ describe('<Button/>', () => {
|
|
|
318
322
|
});
|
|
319
323
|
});
|
|
320
324
|
it('should not call onClick when button is readOnly', async () => {
|
|
321
|
-
const onClick =
|
|
325
|
+
const onClick = vi.fn();
|
|
322
326
|
render( /*#__PURE__*/React.createElement(Button, {
|
|
323
327
|
readOnly: true,
|
|
324
328
|
onClick: onClick
|
|
@@ -332,7 +336,7 @@ describe('<Button/>', () => {
|
|
|
332
336
|
});
|
|
333
337
|
});
|
|
334
338
|
it('should not call onClick when button is disabled and an href prop is provided', async () => {
|
|
335
|
-
const onClick =
|
|
339
|
+
const onClick = vi.fn();
|
|
336
340
|
render(_Button16 || (_Button16 = /*#__PURE__*/React.createElement(Button, {
|
|
337
341
|
href: "#"
|
|
338
342
|
}, "Hello World")));
|
|
@@ -345,7 +349,7 @@ describe('<Button/>', () => {
|
|
|
345
349
|
});
|
|
346
350
|
});
|
|
347
351
|
it('should not call onClick when button is readOnly and an href prop is provided', async () => {
|
|
348
|
-
const onClick =
|
|
352
|
+
const onClick = vi.fn();
|
|
349
353
|
render( /*#__PURE__*/React.createElement(Button, {
|
|
350
354
|
readOnly: true,
|
|
351
355
|
onClick: onClick,
|
|
@@ -360,7 +364,7 @@ describe('<Button/>', () => {
|
|
|
360
364
|
});
|
|
361
365
|
});
|
|
362
366
|
it('should call onClick when space key is pressed if href is provided', async () => {
|
|
363
|
-
const onClick =
|
|
367
|
+
const onClick = vi.fn();
|
|
364
368
|
render( /*#__PURE__*/React.createElement(Button, {
|
|
365
369
|
onClick: onClick,
|
|
366
370
|
href: "#"
|
|
@@ -374,7 +378,7 @@ describe('<Button/>', () => {
|
|
|
374
378
|
});
|
|
375
379
|
});
|
|
376
380
|
it('should call onClick when enter key is pressed when not a button or link', async () => {
|
|
377
|
-
const onClick =
|
|
381
|
+
const onClick = vi.fn();
|
|
378
382
|
render( /*#__PURE__*/React.createElement(Button, {
|
|
379
383
|
as: "span",
|
|
380
384
|
onClick: onClick
|
|
@@ -388,7 +392,7 @@ describe('<Button/>', () => {
|
|
|
388
392
|
});
|
|
389
393
|
});
|
|
390
394
|
it('should not call onClick when button is disabled and space key is pressed', async () => {
|
|
391
|
-
const onClick =
|
|
395
|
+
const onClick = vi.fn();
|
|
392
396
|
render( /*#__PURE__*/React.createElement(Button, {
|
|
393
397
|
disabled: true,
|
|
394
398
|
onClick: onClick,
|
|
@@ -403,7 +407,7 @@ describe('<Button/>', () => {
|
|
|
403
407
|
});
|
|
404
408
|
});
|
|
405
409
|
it('should not call onClick when button is readOnly and space key is pressed', async () => {
|
|
406
|
-
const onClick =
|
|
410
|
+
const onClick = vi.fn();
|
|
407
411
|
render( /*#__PURE__*/React.createElement(Button, {
|
|
408
412
|
readOnly: true,
|
|
409
413
|
onClick: onClick,
|
|
@@ -420,7 +424,7 @@ describe('<Button/>', () => {
|
|
|
420
424
|
});
|
|
421
425
|
describe('for a11y', () => {
|
|
422
426
|
it('should meet standards when onClick is given', async () => {
|
|
423
|
-
const onClick =
|
|
427
|
+
const onClick = vi.fn();
|
|
424
428
|
render( /*#__PURE__*/React.createElement(Button, {
|
|
425
429
|
onClick: onClick
|
|
426
430
|
}, "Hello World"));
|
|
@@ -25,6 +25,7 @@ var _CloseButton;
|
|
|
25
25
|
|
|
26
26
|
import React from 'react';
|
|
27
27
|
import { render, screen, waitFor } from '@testing-library/react';
|
|
28
|
+
import { vi } from 'vitest';
|
|
28
29
|
import userEvent from '@testing-library/user-event';
|
|
29
30
|
import '@testing-library/jest-dom';
|
|
30
31
|
import { CloseButton } from '../index';
|
|
@@ -32,7 +33,7 @@ describe('<CloseButton />', () => {
|
|
|
32
33
|
let consoleWarningMock;
|
|
33
34
|
beforeEach(() => {
|
|
34
35
|
// Mocking console to prevent test output pollution
|
|
35
|
-
consoleWarningMock =
|
|
36
|
+
consoleWarningMock = vi.spyOn(console, 'warn').mockImplementation(() => {});
|
|
36
37
|
});
|
|
37
38
|
afterEach(() => {
|
|
38
39
|
consoleWarningMock.mockRestore();
|
|
@@ -49,7 +50,7 @@ describe('<CloseButton />', () => {
|
|
|
49
50
|
expect(button).toHaveTextContent('Close');
|
|
50
51
|
});
|
|
51
52
|
it('should pass the `onClick` prop', async () => {
|
|
52
|
-
const onClick =
|
|
53
|
+
const onClick = vi.fn();
|
|
53
54
|
render( /*#__PURE__*/React.createElement(CloseButton, {
|
|
54
55
|
onClick: onClick,
|
|
55
56
|
screenReaderLabel: "Hello"
|
|
@@ -25,6 +25,7 @@ var _circle, _CondensedButton, _CondensedButton2, _CondensedButton3, _CondensedB
|
|
|
25
25
|
|
|
26
26
|
import React from 'react';
|
|
27
27
|
import { render, screen, waitFor } from '@testing-library/react';
|
|
28
|
+
import { vi } from 'vitest';
|
|
28
29
|
import userEvent from '@testing-library/user-event';
|
|
29
30
|
import '@testing-library/jest-dom';
|
|
30
31
|
import { CondensedButton } from '../index';
|
|
@@ -89,7 +90,7 @@ describe('<CondensedButton/>', () => {
|
|
|
89
90
|
expect(button).toHaveAttribute('type', 'submit');
|
|
90
91
|
});
|
|
91
92
|
it('should pass the `elementRef` prop', async () => {
|
|
92
|
-
const elementRef =
|
|
93
|
+
const elementRef = vi.fn();
|
|
93
94
|
render( /*#__PURE__*/React.createElement(CondensedButton, {
|
|
94
95
|
elementRef: elementRef
|
|
95
96
|
}, "Hello"));
|
|
@@ -166,7 +167,7 @@ describe('<CondensedButton/>', () => {
|
|
|
166
167
|
expect(svgIcon).toBeInTheDocument();
|
|
167
168
|
});
|
|
168
169
|
it('should pass the `onClick` prop', async () => {
|
|
169
|
-
const onClick =
|
|
170
|
+
const onClick = vi.fn();
|
|
170
171
|
render( /*#__PURE__*/React.createElement(CondensedButton, {
|
|
171
172
|
onClick: onClick
|
|
172
173
|
}, "Hello"));
|
|
@@ -25,6 +25,7 @@ var _circle;
|
|
|
25
25
|
|
|
26
26
|
import React from 'react';
|
|
27
27
|
import { render, screen, waitFor } from '@testing-library/react';
|
|
28
|
+
import { vi } from 'vitest';
|
|
28
29
|
import userEvent from '@testing-library/user-event';
|
|
29
30
|
import '@testing-library/jest-dom';
|
|
30
31
|
import { IconButton } from '../index';
|
|
@@ -112,7 +113,7 @@ describe('<IconButton/>', () => {
|
|
|
112
113
|
expect(button).toHaveAttribute('type', 'reset');
|
|
113
114
|
});
|
|
114
115
|
it('should pass the `elementRef` prop', () => {
|
|
115
|
-
const elementRef =
|
|
116
|
+
const elementRef = vi.fn();
|
|
116
117
|
render( /*#__PURE__*/React.createElement(IconButton, {
|
|
117
118
|
screenReaderLabel: "some action",
|
|
118
119
|
renderIcon: icon,
|
|
@@ -170,7 +171,7 @@ describe('<IconButton/>', () => {
|
|
|
170
171
|
expect(button).toHaveAttribute('disabled');
|
|
171
172
|
});
|
|
172
173
|
it('should pass the `onClick` prop', async () => {
|
|
173
|
-
const onClick =
|
|
174
|
+
const onClick = vi.fn();
|
|
174
175
|
render( /*#__PURE__*/React.createElement(IconButton, {
|
|
175
176
|
screenReaderLabel: "some action",
|
|
176
177
|
renderIcon: icon,
|
|
@@ -25,6 +25,7 @@ var _svg;
|
|
|
25
25
|
|
|
26
26
|
import React from 'react';
|
|
27
27
|
import { render, screen, waitFor } from '@testing-library/react';
|
|
28
|
+
import { vi } from 'vitest';
|
|
28
29
|
import userEvent from '@testing-library/user-event';
|
|
29
30
|
import '@testing-library/jest-dom';
|
|
30
31
|
import { ToggleButton } from '../index';
|
|
@@ -146,7 +147,7 @@ describe('<ToggleButton />', () => {
|
|
|
146
147
|
expect(button).toHaveAttribute('disabled');
|
|
147
148
|
});
|
|
148
149
|
it('should pass the `onClick` prop', async () => {
|
|
149
|
-
const onClick =
|
|
150
|
+
const onClick = vi.fn();
|
|
150
151
|
render( /*#__PURE__*/React.createElement(ToggleButton, {
|
|
151
152
|
screenReaderLabel: "This is a screen reader label",
|
|
152
153
|
renderIcon: icon,
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
4
|
var _react = _interopRequireDefault(require("react"));
|
|
5
5
|
var _react2 = require("@testing-library/react");
|
|
6
|
+
var _vitest = require("vitest");
|
|
6
7
|
var _userEvent = _interopRequireDefault(require("@testing-library/user-event"));
|
|
7
8
|
require("@testing-library/jest-dom");
|
|
8
9
|
var _index = require("../index");
|
|
@@ -33,12 +34,15 @@ var _BaseButton, _BaseButton2, _BaseButton3, _BaseButton4, _BaseButton5, _svg, _
|
|
|
33
34
|
*/
|
|
34
35
|
describe('<BaseButton/>', () => {
|
|
35
36
|
let consoleWarningMock;
|
|
37
|
+
let consoleErrorMock;
|
|
36
38
|
beforeEach(() => {
|
|
37
|
-
// Mocking console to prevent test output pollution
|
|
38
|
-
consoleWarningMock =
|
|
39
|
+
// Mocking console to prevent test output pollution and expect for messages
|
|
40
|
+
consoleWarningMock = _vitest.vi.spyOn(console, 'warn').mockImplementation(() => {});
|
|
41
|
+
consoleErrorMock = _vitest.vi.spyOn(console, 'error').mockImplementation(() => {});
|
|
39
42
|
});
|
|
40
43
|
afterEach(() => {
|
|
41
44
|
consoleWarningMock.mockRestore();
|
|
45
|
+
consoleErrorMock.mockRestore();
|
|
42
46
|
});
|
|
43
47
|
it('should render a button and the children as button text', () => {
|
|
44
48
|
(0, _react2.render)(_BaseButton || (_BaseButton = /*#__PURE__*/_react.default.createElement(_index.BaseButton, null, "Hello World")));
|
|
@@ -81,7 +85,7 @@ describe('<BaseButton/>', () => {
|
|
|
81
85
|
expect(button.tagName).toBe('SPAN');
|
|
82
86
|
});
|
|
83
87
|
it('should set role="button"', () => {
|
|
84
|
-
const onClick =
|
|
88
|
+
const onClick = _vitest.vi.fn();
|
|
85
89
|
const _render3 = (0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.BaseButton, {
|
|
86
90
|
as: "span",
|
|
87
91
|
onClick: onClick
|
|
@@ -92,7 +96,7 @@ describe('<BaseButton/>', () => {
|
|
|
92
96
|
expect(button).toHaveAttribute('role', 'button');
|
|
93
97
|
});
|
|
94
98
|
it('should set tabIndex="0"', () => {
|
|
95
|
-
const onClick =
|
|
99
|
+
const onClick = _vitest.vi.fn();
|
|
96
100
|
(0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.BaseButton, {
|
|
97
101
|
as: "span",
|
|
98
102
|
onClick: onClick
|
|
@@ -104,7 +108,7 @@ describe('<BaseButton/>', () => {
|
|
|
104
108
|
expect(button).toHaveAttribute('tabIndex', '0');
|
|
105
109
|
});
|
|
106
110
|
it('should pass down the type prop to the button element', async () => {
|
|
107
|
-
const onClick =
|
|
111
|
+
const onClick = _vitest.vi.fn();
|
|
108
112
|
(0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.BaseButton, {
|
|
109
113
|
type: "submit",
|
|
110
114
|
onClick: onClick
|
|
@@ -136,7 +140,7 @@ describe('<BaseButton/>', () => {
|
|
|
136
140
|
expect(document.activeElement).toBe(button);
|
|
137
141
|
});
|
|
138
142
|
it('should provide an elementRef prop', async () => {
|
|
139
|
-
const elementRef =
|
|
143
|
+
const elementRef = _vitest.vi.fn();
|
|
140
144
|
(0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.BaseButton, {
|
|
141
145
|
elementRef: elementRef
|
|
142
146
|
}, "Hello World"));
|
|
@@ -147,7 +151,7 @@ describe('<BaseButton/>', () => {
|
|
|
147
151
|
});
|
|
148
152
|
describe('onClick', () => {
|
|
149
153
|
it('should call onClick when clicked', async () => {
|
|
150
|
-
const onClick =
|
|
154
|
+
const onClick = _vitest.vi.fn();
|
|
151
155
|
(0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.BaseButton, {
|
|
152
156
|
onClick: onClick
|
|
153
157
|
}, "Hello World"));
|
|
@@ -160,7 +164,7 @@ describe('<BaseButton/>', () => {
|
|
|
160
164
|
});
|
|
161
165
|
});
|
|
162
166
|
it('should not call onClick when interaction is "disabled"', async () => {
|
|
163
|
-
const onClick =
|
|
167
|
+
const onClick = _vitest.vi.fn();
|
|
164
168
|
(0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.BaseButton, {
|
|
165
169
|
interaction: "disabled",
|
|
166
170
|
onClick: onClick
|
|
@@ -174,7 +178,7 @@ describe('<BaseButton/>', () => {
|
|
|
174
178
|
});
|
|
175
179
|
});
|
|
176
180
|
it('should not call onClick when disabled is set"', async () => {
|
|
177
|
-
const onClick =
|
|
181
|
+
const onClick = _vitest.vi.fn();
|
|
178
182
|
(0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.BaseButton, {
|
|
179
183
|
disabled: true,
|
|
180
184
|
onClick: onClick
|
|
@@ -188,7 +192,7 @@ describe('<BaseButton/>', () => {
|
|
|
188
192
|
});
|
|
189
193
|
});
|
|
190
194
|
it('should not call onClick when interaction is "readonly"', async () => {
|
|
191
|
-
const onClick =
|
|
195
|
+
const onClick = _vitest.vi.fn();
|
|
192
196
|
(0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.BaseButton, {
|
|
193
197
|
interaction: "readonly",
|
|
194
198
|
onClick: onClick
|
|
@@ -202,7 +206,7 @@ describe('<BaseButton/>', () => {
|
|
|
202
206
|
});
|
|
203
207
|
});
|
|
204
208
|
it('should not call onClick when readOnly is set', async () => {
|
|
205
|
-
const onClick =
|
|
209
|
+
const onClick = _vitest.vi.fn();
|
|
206
210
|
(0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.BaseButton, {
|
|
207
211
|
readOnly: true,
|
|
208
212
|
onClick: onClick
|
|
@@ -216,7 +220,7 @@ describe('<BaseButton/>', () => {
|
|
|
216
220
|
});
|
|
217
221
|
});
|
|
218
222
|
it('should not call onClick when button is disabled and an href prop is provided', async () => {
|
|
219
|
-
const onClick =
|
|
223
|
+
const onClick = _vitest.vi.fn();
|
|
220
224
|
(0, _react2.render)(_BaseButton7 || (_BaseButton7 = /*#__PURE__*/_react.default.createElement(_index.BaseButton, {
|
|
221
225
|
href: "#"
|
|
222
226
|
}, "Hello World")));
|
|
@@ -229,7 +233,7 @@ describe('<BaseButton/>', () => {
|
|
|
229
233
|
});
|
|
230
234
|
});
|
|
231
235
|
it('should not call onClick when interaction is "readonly" and an href prop is provided', async () => {
|
|
232
|
-
const onClick =
|
|
236
|
+
const onClick = _vitest.vi.fn();
|
|
233
237
|
(0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.BaseButton, {
|
|
234
238
|
interaction: "readonly",
|
|
235
239
|
onClick: onClick,
|
|
@@ -244,7 +248,7 @@ describe('<BaseButton/>', () => {
|
|
|
244
248
|
});
|
|
245
249
|
});
|
|
246
250
|
it('should call onClick when space key is pressed if href is provided', async () => {
|
|
247
|
-
const onClick =
|
|
251
|
+
const onClick = _vitest.vi.fn();
|
|
248
252
|
(0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.BaseButton, {
|
|
249
253
|
onClick: onClick,
|
|
250
254
|
href: "#"
|
|
@@ -258,7 +262,7 @@ describe('<BaseButton/>', () => {
|
|
|
258
262
|
});
|
|
259
263
|
});
|
|
260
264
|
it('should call onClick when enter key is pressed when not a button or link', async () => {
|
|
261
|
-
const onClick =
|
|
265
|
+
const onClick = _vitest.vi.fn();
|
|
262
266
|
(0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.BaseButton, {
|
|
263
267
|
as: "span",
|
|
264
268
|
onClick: onClick
|
|
@@ -272,7 +276,7 @@ describe('<BaseButton/>', () => {
|
|
|
272
276
|
});
|
|
273
277
|
});
|
|
274
278
|
it('should not call onClick when interaction is "disabled" and space key is pressed', async () => {
|
|
275
|
-
const onClick =
|
|
279
|
+
const onClick = _vitest.vi.fn();
|
|
276
280
|
(0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.BaseButton, {
|
|
277
281
|
interaction: "disabled",
|
|
278
282
|
onClick: onClick,
|
|
@@ -287,7 +291,7 @@ describe('<BaseButton/>', () => {
|
|
|
287
291
|
});
|
|
288
292
|
});
|
|
289
293
|
it('should not call onClick when interaction is "readonly" and space key is pressed', async () => {
|
|
290
|
-
const onClick =
|
|
294
|
+
const onClick = _vitest.vi.fn();
|
|
291
295
|
(0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.BaseButton, {
|
|
292
296
|
interaction: "readonly",
|
|
293
297
|
onClick: onClick,
|
|
@@ -324,7 +328,7 @@ describe('<BaseButton/>', () => {
|
|
|
324
328
|
});
|
|
325
329
|
describe('for a11y', () => {
|
|
326
330
|
it('should meet standards when onClick is given', async () => {
|
|
327
|
-
const onClick =
|
|
331
|
+
const onClick = _vitest.vi.fn();
|
|
328
332
|
(0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.BaseButton, {
|
|
329
333
|
onClick: onClick
|
|
330
334
|
}, "Hello World"));
|