@instructure/ui-buttons 9.2.1-snapshot-1 → 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/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
|
@@ -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 _runAxeCheck = require("@instructure/ui-axe-check/lib/runAxeCheck.js");
|
|
@@ -34,6 +35,7 @@ var _circle, _Button, _Button2, _Button3, _Button4, _Button5, _Button6, _Button7
|
|
|
34
35
|
describe('<Button/>', () => {
|
|
35
36
|
var _Button9;
|
|
36
37
|
let consoleWarningMock;
|
|
38
|
+
let consoleErrorMock;
|
|
37
39
|
const iconSelector = 'svg[data-title="myIcon"]';
|
|
38
40
|
const icon = /*#__PURE__*/_react.default.createElement("svg", {
|
|
39
41
|
"data-title": "myIcon",
|
|
@@ -49,10 +51,12 @@ describe('<Button/>', () => {
|
|
|
49
51
|
})));
|
|
50
52
|
beforeEach(() => {
|
|
51
53
|
// Mocking console to prevent test output pollution
|
|
52
|
-
consoleWarningMock =
|
|
54
|
+
consoleWarningMock = _vitest.vi.spyOn(console, 'warn').mockImplementation(() => {});
|
|
55
|
+
consoleErrorMock = _vitest.vi.spyOn(console, 'error').mockImplementation(() => {});
|
|
53
56
|
});
|
|
54
57
|
afterEach(() => {
|
|
55
58
|
consoleWarningMock.mockRestore();
|
|
59
|
+
consoleErrorMock.mockRestore();
|
|
56
60
|
});
|
|
57
61
|
it('should render children', () => {
|
|
58
62
|
const children = 'Hello world';
|
|
@@ -112,7 +116,7 @@ describe('<Button/>', () => {
|
|
|
112
116
|
expect(button).toHaveAttribute('type', 'submit');
|
|
113
117
|
});
|
|
114
118
|
it('should pass the `elementRef` prop', () => {
|
|
115
|
-
const elementRef =
|
|
119
|
+
const elementRef = _vitest.vi.fn();
|
|
116
120
|
(0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.Button, {
|
|
117
121
|
elementRef: elementRef
|
|
118
122
|
}, "Hello"));
|
|
@@ -189,7 +193,7 @@ describe('<Button/>', () => {
|
|
|
189
193
|
expect(svgIcon).toBeInTheDocument();
|
|
190
194
|
});
|
|
191
195
|
it('should pass the `onClick` prop', async () => {
|
|
192
|
-
const onClick =
|
|
196
|
+
const onClick = _vitest.vi.fn();
|
|
193
197
|
(0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.Button, {
|
|
194
198
|
onClick: onClick
|
|
195
199
|
}, "Hello"));
|
|
@@ -251,7 +255,7 @@ describe('<Button/>', () => {
|
|
|
251
255
|
expect(button.tagName).toBe('SPAN');
|
|
252
256
|
});
|
|
253
257
|
it('should set role="button"', () => {
|
|
254
|
-
const onClick =
|
|
258
|
+
const onClick = _vitest.vi.fn();
|
|
255
259
|
const _render4 = (0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.Button, {
|
|
256
260
|
as: "span",
|
|
257
261
|
onClick: onClick
|
|
@@ -262,7 +266,7 @@ describe('<Button/>', () => {
|
|
|
262
266
|
expect(button).toHaveAttribute('role', 'button');
|
|
263
267
|
});
|
|
264
268
|
it('should set tabIndex="0"', () => {
|
|
265
|
-
const onClick =
|
|
269
|
+
const onClick = _vitest.vi.fn();
|
|
266
270
|
(0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.Button, {
|
|
267
271
|
as: "span",
|
|
268
272
|
onClick: onClick
|
|
@@ -272,7 +276,7 @@ describe('<Button/>', () => {
|
|
|
272
276
|
expect(button).toHaveAttribute('tabIndex', '0');
|
|
273
277
|
});
|
|
274
278
|
it('should pass down the type prop to the button element', () => {
|
|
275
|
-
const onClick =
|
|
279
|
+
const onClick = _vitest.vi.fn();
|
|
276
280
|
(0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.Button, {
|
|
277
281
|
type: "submit",
|
|
278
282
|
onClick: onClick
|
|
@@ -282,7 +286,7 @@ describe('<Button/>', () => {
|
|
|
282
286
|
expect(button).toHaveAttribute('type', 'submit');
|
|
283
287
|
});
|
|
284
288
|
it('focuses with the focus helper', () => {
|
|
285
|
-
const onFocus =
|
|
289
|
+
const onFocus = _vitest.vi.fn();
|
|
286
290
|
(0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.Button, {
|
|
287
291
|
onFocus: onFocus
|
|
288
292
|
}, "Hello World"));
|
|
@@ -293,7 +297,7 @@ describe('<Button/>', () => {
|
|
|
293
297
|
});
|
|
294
298
|
describe('onClick', () => {
|
|
295
299
|
it('should call onClick when clicked', async () => {
|
|
296
|
-
const onClick =
|
|
300
|
+
const onClick = _vitest.vi.fn();
|
|
297
301
|
(0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.Button, {
|
|
298
302
|
onClick: onClick
|
|
299
303
|
}, "Hello World"));
|
|
@@ -306,7 +310,7 @@ describe('<Button/>', () => {
|
|
|
306
310
|
});
|
|
307
311
|
});
|
|
308
312
|
it('should not call onClick when button is disabled', async () => {
|
|
309
|
-
const onClick =
|
|
313
|
+
const onClick = _vitest.vi.fn();
|
|
310
314
|
(0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.Button, {
|
|
311
315
|
disabled: true,
|
|
312
316
|
onClick: onClick
|
|
@@ -320,7 +324,7 @@ describe('<Button/>', () => {
|
|
|
320
324
|
});
|
|
321
325
|
});
|
|
322
326
|
it('should not call onClick when button is readOnly', async () => {
|
|
323
|
-
const onClick =
|
|
327
|
+
const onClick = _vitest.vi.fn();
|
|
324
328
|
(0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.Button, {
|
|
325
329
|
readOnly: true,
|
|
326
330
|
onClick: onClick
|
|
@@ -334,7 +338,7 @@ describe('<Button/>', () => {
|
|
|
334
338
|
});
|
|
335
339
|
});
|
|
336
340
|
it('should not call onClick when button is disabled and an href prop is provided', async () => {
|
|
337
|
-
const onClick =
|
|
341
|
+
const onClick = _vitest.vi.fn();
|
|
338
342
|
(0, _react2.render)(_Button16 || (_Button16 = /*#__PURE__*/_react.default.createElement(_index.Button, {
|
|
339
343
|
href: "#"
|
|
340
344
|
}, "Hello World")));
|
|
@@ -347,7 +351,7 @@ describe('<Button/>', () => {
|
|
|
347
351
|
});
|
|
348
352
|
});
|
|
349
353
|
it('should not call onClick when button is readOnly and an href prop is provided', async () => {
|
|
350
|
-
const onClick =
|
|
354
|
+
const onClick = _vitest.vi.fn();
|
|
351
355
|
(0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.Button, {
|
|
352
356
|
readOnly: true,
|
|
353
357
|
onClick: onClick,
|
|
@@ -362,7 +366,7 @@ describe('<Button/>', () => {
|
|
|
362
366
|
});
|
|
363
367
|
});
|
|
364
368
|
it('should call onClick when space key is pressed if href is provided', async () => {
|
|
365
|
-
const onClick =
|
|
369
|
+
const onClick = _vitest.vi.fn();
|
|
366
370
|
(0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.Button, {
|
|
367
371
|
onClick: onClick,
|
|
368
372
|
href: "#"
|
|
@@ -376,7 +380,7 @@ describe('<Button/>', () => {
|
|
|
376
380
|
});
|
|
377
381
|
});
|
|
378
382
|
it('should call onClick when enter key is pressed when not a button or link', async () => {
|
|
379
|
-
const onClick =
|
|
383
|
+
const onClick = _vitest.vi.fn();
|
|
380
384
|
(0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.Button, {
|
|
381
385
|
as: "span",
|
|
382
386
|
onClick: onClick
|
|
@@ -390,7 +394,7 @@ describe('<Button/>', () => {
|
|
|
390
394
|
});
|
|
391
395
|
});
|
|
392
396
|
it('should not call onClick when button is disabled and space key is pressed', async () => {
|
|
393
|
-
const onClick =
|
|
397
|
+
const onClick = _vitest.vi.fn();
|
|
394
398
|
(0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.Button, {
|
|
395
399
|
disabled: true,
|
|
396
400
|
onClick: onClick,
|
|
@@ -405,7 +409,7 @@ describe('<Button/>', () => {
|
|
|
405
409
|
});
|
|
406
410
|
});
|
|
407
411
|
it('should not call onClick when button is readOnly and space key is pressed', async () => {
|
|
408
|
-
const onClick =
|
|
412
|
+
const onClick = _vitest.vi.fn();
|
|
409
413
|
(0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.Button, {
|
|
410
414
|
readOnly: true,
|
|
411
415
|
onClick: onClick,
|
|
@@ -422,7 +426,7 @@ describe('<Button/>', () => {
|
|
|
422
426
|
});
|
|
423
427
|
describe('for a11y', () => {
|
|
424
428
|
it('should meet standards when onClick is given', async () => {
|
|
425
|
-
const onClick =
|
|
429
|
+
const onClick = _vitest.vi.fn();
|
|
426
430
|
(0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.Button, {
|
|
427
431
|
onClick: onClick
|
|
428
432
|
}, "Hello World"));
|
|
@@ -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");
|
|
@@ -34,7 +35,7 @@ describe('<CloseButton />', () => {
|
|
|
34
35
|
let consoleWarningMock;
|
|
35
36
|
beforeEach(() => {
|
|
36
37
|
// Mocking console to prevent test output pollution
|
|
37
|
-
consoleWarningMock =
|
|
38
|
+
consoleWarningMock = _vitest.vi.spyOn(console, 'warn').mockImplementation(() => {});
|
|
38
39
|
});
|
|
39
40
|
afterEach(() => {
|
|
40
41
|
consoleWarningMock.mockRestore();
|
|
@@ -51,7 +52,7 @@ describe('<CloseButton />', () => {
|
|
|
51
52
|
expect(button).toHaveTextContent('Close');
|
|
52
53
|
});
|
|
53
54
|
it('should pass the `onClick` prop', async () => {
|
|
54
|
-
const onClick =
|
|
55
|
+
const onClick = _vitest.vi.fn();
|
|
55
56
|
(0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.CloseButton, {
|
|
56
57
|
onClick: onClick,
|
|
57
58
|
screenReaderLabel: "Hello"
|
|
@@ -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");
|
|
@@ -91,7 +92,7 @@ describe('<CondensedButton/>', () => {
|
|
|
91
92
|
expect(button).toHaveAttribute('type', 'submit');
|
|
92
93
|
});
|
|
93
94
|
it('should pass the `elementRef` prop', async () => {
|
|
94
|
-
const elementRef =
|
|
95
|
+
const elementRef = _vitest.vi.fn();
|
|
95
96
|
(0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.CondensedButton, {
|
|
96
97
|
elementRef: elementRef
|
|
97
98
|
}, "Hello"));
|
|
@@ -168,7 +169,7 @@ describe('<CondensedButton/>', () => {
|
|
|
168
169
|
expect(svgIcon).toBeInTheDocument();
|
|
169
170
|
});
|
|
170
171
|
it('should pass the `onClick` prop', async () => {
|
|
171
|
-
const onClick =
|
|
172
|
+
const onClick = _vitest.vi.fn();
|
|
172
173
|
(0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.CondensedButton, {
|
|
173
174
|
onClick: onClick
|
|
174
175
|
}, "Hello"));
|
|
@@ -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");
|
|
@@ -114,7 +115,7 @@ describe('<IconButton/>', () => {
|
|
|
114
115
|
expect(button).toHaveAttribute('type', 'reset');
|
|
115
116
|
});
|
|
116
117
|
it('should pass the `elementRef` prop', () => {
|
|
117
|
-
const elementRef =
|
|
118
|
+
const elementRef = _vitest.vi.fn();
|
|
118
119
|
(0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.IconButton, {
|
|
119
120
|
screenReaderLabel: "some action",
|
|
120
121
|
renderIcon: icon,
|
|
@@ -172,7 +173,7 @@ describe('<IconButton/>', () => {
|
|
|
172
173
|
expect(button).toHaveAttribute('disabled');
|
|
173
174
|
});
|
|
174
175
|
it('should pass the `onClick` prop', async () => {
|
|
175
|
-
const onClick =
|
|
176
|
+
const onClick = _vitest.vi.fn();
|
|
176
177
|
(0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.IconButton, {
|
|
177
178
|
screenReaderLabel: "some action",
|
|
178
179
|
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");
|
|
@@ -148,7 +149,7 @@ describe('<ToggleButton />', () => {
|
|
|
148
149
|
expect(button).toHaveAttribute('disabled');
|
|
149
150
|
});
|
|
150
151
|
it('should pass the `onClick` prop', async () => {
|
|
151
|
-
const onClick =
|
|
152
|
+
const onClick = _vitest.vi.fn();
|
|
152
153
|
(0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.ToggleButton, {
|
|
153
154
|
screenReaderLabel: "This is a screen reader label",
|
|
154
155
|
renderIcon: icon,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@instructure/ui-buttons",
|
|
3
|
-
"version": "9.2.1-snapshot-
|
|
3
|
+
"version": "9.2.1-snapshot-2",
|
|
4
4
|
"description": "Accessible button components",
|
|
5
5
|
"author": "Instructure, Inc. Engineering and Product Design",
|
|
6
6
|
"module": "./es/index.js",
|
|
@@ -23,31 +23,32 @@
|
|
|
23
23
|
},
|
|
24
24
|
"license": "MIT",
|
|
25
25
|
"devDependencies": {
|
|
26
|
-
"@instructure/ui-axe-check": "9.2.1-snapshot-
|
|
27
|
-
"@instructure/ui-babel-preset": "9.2.1-snapshot-
|
|
28
|
-
"@instructure/ui-test-utils": "9.2.1-snapshot-
|
|
29
|
-
"@instructure/ui-themes": "9.2.1-snapshot-
|
|
26
|
+
"@instructure/ui-axe-check": "9.2.1-snapshot-2",
|
|
27
|
+
"@instructure/ui-babel-preset": "9.2.1-snapshot-2",
|
|
28
|
+
"@instructure/ui-test-utils": "9.2.1-snapshot-2",
|
|
29
|
+
"@instructure/ui-themes": "9.2.1-snapshot-2",
|
|
30
30
|
"@testing-library/jest-dom": "^6.4.5",
|
|
31
31
|
"@testing-library/react": "^15.0.7",
|
|
32
|
-
"@testing-library/user-event": "^14.5.2"
|
|
32
|
+
"@testing-library/user-event": "^14.5.2",
|
|
33
|
+
"vitest": "^1.6.0"
|
|
33
34
|
},
|
|
34
35
|
"dependencies": {
|
|
35
36
|
"@babel/runtime": "^7.24.5",
|
|
36
|
-
"@instructure/console": "9.2.1-snapshot-
|
|
37
|
-
"@instructure/emotion": "9.2.1-snapshot-
|
|
38
|
-
"@instructure/shared-types": "9.2.1-snapshot-
|
|
39
|
-
"@instructure/ui-a11y-content": "9.2.1-snapshot-
|
|
40
|
-
"@instructure/ui-a11y-utils": "9.2.1-snapshot-
|
|
41
|
-
"@instructure/ui-color-utils": "9.2.1-snapshot-
|
|
42
|
-
"@instructure/ui-dom-utils": "9.2.1-snapshot-
|
|
43
|
-
"@instructure/ui-icons": "9.2.1-snapshot-
|
|
44
|
-
"@instructure/ui-position": "9.2.1-snapshot-
|
|
45
|
-
"@instructure/ui-prop-types": "9.2.1-snapshot-
|
|
46
|
-
"@instructure/ui-react-utils": "9.2.1-snapshot-
|
|
47
|
-
"@instructure/ui-testable": "9.2.1-snapshot-
|
|
48
|
-
"@instructure/ui-tooltip": "9.2.1-snapshot-
|
|
49
|
-
"@instructure/ui-utils": "9.2.1-snapshot-
|
|
50
|
-
"@instructure/ui-view": "9.2.1-snapshot-
|
|
37
|
+
"@instructure/console": "9.2.1-snapshot-2",
|
|
38
|
+
"@instructure/emotion": "9.2.1-snapshot-2",
|
|
39
|
+
"@instructure/shared-types": "9.2.1-snapshot-2",
|
|
40
|
+
"@instructure/ui-a11y-content": "9.2.1-snapshot-2",
|
|
41
|
+
"@instructure/ui-a11y-utils": "9.2.1-snapshot-2",
|
|
42
|
+
"@instructure/ui-color-utils": "9.2.1-snapshot-2",
|
|
43
|
+
"@instructure/ui-dom-utils": "9.2.1-snapshot-2",
|
|
44
|
+
"@instructure/ui-icons": "9.2.1-snapshot-2",
|
|
45
|
+
"@instructure/ui-position": "9.2.1-snapshot-2",
|
|
46
|
+
"@instructure/ui-prop-types": "9.2.1-snapshot-2",
|
|
47
|
+
"@instructure/ui-react-utils": "9.2.1-snapshot-2",
|
|
48
|
+
"@instructure/ui-testable": "9.2.1-snapshot-2",
|
|
49
|
+
"@instructure/ui-tooltip": "9.2.1-snapshot-2",
|
|
50
|
+
"@instructure/ui-utils": "9.2.1-snapshot-2",
|
|
51
|
+
"@instructure/ui-view": "9.2.1-snapshot-2",
|
|
51
52
|
"keycode": "^2.2.1",
|
|
52
53
|
"prop-types": "^15.8.1"
|
|
53
54
|
},
|
|
@@ -24,6 +24,8 @@
|
|
|
24
24
|
|
|
25
25
|
import React from 'react'
|
|
26
26
|
import { render, screen, waitFor } from '@testing-library/react'
|
|
27
|
+
import { vi } from 'vitest'
|
|
28
|
+
import type { MockInstance } from 'vitest'
|
|
27
29
|
import userEvent from '@testing-library/user-event'
|
|
28
30
|
import '@testing-library/jest-dom'
|
|
29
31
|
|
|
@@ -31,15 +33,22 @@ import { BaseButton } from '../index'
|
|
|
31
33
|
import { runAxeCheck } from '@instructure/ui-axe-check'
|
|
32
34
|
|
|
33
35
|
describe('<BaseButton/>', () => {
|
|
34
|
-
let consoleWarningMock:
|
|
36
|
+
let consoleWarningMock: ReturnType<typeof vi.spyOn>
|
|
37
|
+
let consoleErrorMock: ReturnType<typeof vi.spyOn>
|
|
35
38
|
|
|
36
39
|
beforeEach(() => {
|
|
37
|
-
// Mocking console to prevent test output pollution
|
|
38
|
-
consoleWarningMock =
|
|
40
|
+
// Mocking console to prevent test output pollution and expect for messages
|
|
41
|
+
consoleWarningMock = vi
|
|
42
|
+
.spyOn(console, 'warn')
|
|
43
|
+
.mockImplementation(() => {}) as MockInstance
|
|
44
|
+
consoleErrorMock = vi
|
|
45
|
+
.spyOn(console, 'error')
|
|
46
|
+
.mockImplementation(() => {}) as MockInstance
|
|
39
47
|
})
|
|
40
48
|
|
|
41
49
|
afterEach(() => {
|
|
42
50
|
consoleWarningMock.mockRestore()
|
|
51
|
+
consoleErrorMock.mockRestore()
|
|
43
52
|
})
|
|
44
53
|
|
|
45
54
|
it('should render a button and the children as button text', () => {
|
|
@@ -88,7 +97,7 @@ describe('<BaseButton/>', () => {
|
|
|
88
97
|
})
|
|
89
98
|
|
|
90
99
|
it('should set role="button"', () => {
|
|
91
|
-
const onClick =
|
|
100
|
+
const onClick = vi.fn()
|
|
92
101
|
|
|
93
102
|
const { container } = render(
|
|
94
103
|
<BaseButton as="span" onClick={onClick}>
|
|
@@ -103,7 +112,7 @@ describe('<BaseButton/>', () => {
|
|
|
103
112
|
})
|
|
104
113
|
|
|
105
114
|
it('should set tabIndex="0"', () => {
|
|
106
|
-
const onClick =
|
|
115
|
+
const onClick = vi.fn()
|
|
107
116
|
|
|
108
117
|
render(
|
|
109
118
|
<BaseButton as="span" onClick={onClick}>
|
|
@@ -118,7 +127,7 @@ describe('<BaseButton/>', () => {
|
|
|
118
127
|
})
|
|
119
128
|
|
|
120
129
|
it('should pass down the type prop to the button element', async () => {
|
|
121
|
-
const onClick =
|
|
130
|
+
const onClick = vi.fn()
|
|
122
131
|
render(
|
|
123
132
|
<BaseButton type="submit" onClick={onClick}>
|
|
124
133
|
Hello World
|
|
@@ -155,7 +164,7 @@ describe('<BaseButton/>', () => {
|
|
|
155
164
|
})
|
|
156
165
|
|
|
157
166
|
it('should provide an elementRef prop', async () => {
|
|
158
|
-
const elementRef =
|
|
167
|
+
const elementRef = vi.fn()
|
|
159
168
|
render(<BaseButton elementRef={elementRef}>Hello World</BaseButton>)
|
|
160
169
|
|
|
161
170
|
const button = screen.getByRole('button', { name: 'Hello World' })
|
|
@@ -165,7 +174,7 @@ describe('<BaseButton/>', () => {
|
|
|
165
174
|
|
|
166
175
|
describe('onClick', () => {
|
|
167
176
|
it('should call onClick when clicked', async () => {
|
|
168
|
-
const onClick =
|
|
177
|
+
const onClick = vi.fn()
|
|
169
178
|
render(<BaseButton onClick={onClick}>Hello World</BaseButton>)
|
|
170
179
|
|
|
171
180
|
const button = screen.getByRole('button', { name: 'Hello World' })
|
|
@@ -178,7 +187,7 @@ describe('<BaseButton/>', () => {
|
|
|
178
187
|
})
|
|
179
188
|
|
|
180
189
|
it('should not call onClick when interaction is "disabled"', async () => {
|
|
181
|
-
const onClick =
|
|
190
|
+
const onClick = vi.fn()
|
|
182
191
|
|
|
183
192
|
render(
|
|
184
193
|
<BaseButton interaction="disabled" onClick={onClick}>
|
|
@@ -195,7 +204,7 @@ describe('<BaseButton/>', () => {
|
|
|
195
204
|
})
|
|
196
205
|
|
|
197
206
|
it('should not call onClick when disabled is set"', async () => {
|
|
198
|
-
const onClick =
|
|
207
|
+
const onClick = vi.fn()
|
|
199
208
|
|
|
200
209
|
render(
|
|
201
210
|
<BaseButton disabled onClick={onClick}>
|
|
@@ -212,7 +221,7 @@ describe('<BaseButton/>', () => {
|
|
|
212
221
|
})
|
|
213
222
|
|
|
214
223
|
it('should not call onClick when interaction is "readonly"', async () => {
|
|
215
|
-
const onClick =
|
|
224
|
+
const onClick = vi.fn()
|
|
216
225
|
|
|
217
226
|
render(
|
|
218
227
|
<BaseButton interaction="readonly" onClick={onClick}>
|
|
@@ -229,7 +238,7 @@ describe('<BaseButton/>', () => {
|
|
|
229
238
|
})
|
|
230
239
|
|
|
231
240
|
it('should not call onClick when readOnly is set', async () => {
|
|
232
|
-
const onClick =
|
|
241
|
+
const onClick = vi.fn()
|
|
233
242
|
|
|
234
243
|
render(
|
|
235
244
|
<BaseButton readOnly onClick={onClick}>
|
|
@@ -246,7 +255,7 @@ describe('<BaseButton/>', () => {
|
|
|
246
255
|
})
|
|
247
256
|
|
|
248
257
|
it('should not call onClick when button is disabled and an href prop is provided', async () => {
|
|
249
|
-
const onClick =
|
|
258
|
+
const onClick = vi.fn()
|
|
250
259
|
|
|
251
260
|
render(<BaseButton href="#">Hello World</BaseButton>)
|
|
252
261
|
|
|
@@ -260,7 +269,7 @@ describe('<BaseButton/>', () => {
|
|
|
260
269
|
})
|
|
261
270
|
|
|
262
271
|
it('should not call onClick when interaction is "readonly" and an href prop is provided', async () => {
|
|
263
|
-
const onClick =
|
|
272
|
+
const onClick = vi.fn()
|
|
264
273
|
|
|
265
274
|
render(
|
|
266
275
|
<BaseButton interaction="readonly" onClick={onClick} href="#">
|
|
@@ -278,7 +287,7 @@ describe('<BaseButton/>', () => {
|
|
|
278
287
|
})
|
|
279
288
|
|
|
280
289
|
it('should call onClick when space key is pressed if href is provided', async () => {
|
|
281
|
-
const onClick =
|
|
290
|
+
const onClick = vi.fn()
|
|
282
291
|
|
|
283
292
|
render(
|
|
284
293
|
<BaseButton onClick={onClick} href="#">
|
|
@@ -296,7 +305,7 @@ describe('<BaseButton/>', () => {
|
|
|
296
305
|
})
|
|
297
306
|
|
|
298
307
|
it('should call onClick when enter key is pressed when not a button or link', async () => {
|
|
299
|
-
const onClick =
|
|
308
|
+
const onClick = vi.fn()
|
|
300
309
|
|
|
301
310
|
render(
|
|
302
311
|
<BaseButton as="span" onClick={onClick}>
|
|
@@ -314,7 +323,7 @@ describe('<BaseButton/>', () => {
|
|
|
314
323
|
})
|
|
315
324
|
|
|
316
325
|
it('should not call onClick when interaction is "disabled" and space key is pressed', async () => {
|
|
317
|
-
const onClick =
|
|
326
|
+
const onClick = vi.fn()
|
|
318
327
|
|
|
319
328
|
render(
|
|
320
329
|
<BaseButton interaction="disabled" onClick={onClick} href="#">
|
|
@@ -332,7 +341,7 @@ describe('<BaseButton/>', () => {
|
|
|
332
341
|
})
|
|
333
342
|
|
|
334
343
|
it('should not call onClick when interaction is "readonly" and space key is pressed', async () => {
|
|
335
|
-
const onClick =
|
|
344
|
+
const onClick = vi.fn()
|
|
336
345
|
|
|
337
346
|
render(
|
|
338
347
|
<BaseButton interaction="readonly" onClick={onClick} href="#">
|
|
@@ -371,7 +380,7 @@ describe('<BaseButton/>', () => {
|
|
|
371
380
|
|
|
372
381
|
describe('for a11y', () => {
|
|
373
382
|
it('should meet standards when onClick is given', async () => {
|
|
374
|
-
const onClick =
|
|
383
|
+
const onClick = vi.fn()
|
|
375
384
|
|
|
376
385
|
render(<BaseButton onClick={onClick}>Hello World</BaseButton>)
|
|
377
386
|
|
|
@@ -24,6 +24,7 @@
|
|
|
24
24
|
|
|
25
25
|
import React from 'react'
|
|
26
26
|
import { render, screen, waitFor } from '@testing-library/react'
|
|
27
|
+
import { vi } from 'vitest'
|
|
27
28
|
import userEvent from '@testing-library/user-event'
|
|
28
29
|
import '@testing-library/jest-dom'
|
|
29
30
|
|
|
@@ -32,7 +33,8 @@ import { BaseButton } from '../../BaseButton'
|
|
|
32
33
|
import { Button } from '../index'
|
|
33
34
|
|
|
34
35
|
describe('<Button/>', () => {
|
|
35
|
-
let consoleWarningMock:
|
|
36
|
+
let consoleWarningMock: ReturnType<typeof vi.spyOn>
|
|
37
|
+
let consoleErrorMock: ReturnType<typeof vi.spyOn>
|
|
36
38
|
const iconSelector = 'svg[data-title="myIcon"]'
|
|
37
39
|
|
|
38
40
|
const icon = (
|
|
@@ -48,11 +50,17 @@ describe('<Button/>', () => {
|
|
|
48
50
|
|
|
49
51
|
beforeEach(() => {
|
|
50
52
|
// Mocking console to prevent test output pollution
|
|
51
|
-
consoleWarningMock =
|
|
53
|
+
consoleWarningMock = vi
|
|
54
|
+
.spyOn(console, 'warn')
|
|
55
|
+
.mockImplementation(() => {}) as any
|
|
56
|
+
consoleErrorMock = vi
|
|
57
|
+
.spyOn(console, 'error')
|
|
58
|
+
.mockImplementation(() => {}) as any
|
|
52
59
|
})
|
|
53
60
|
|
|
54
61
|
afterEach(() => {
|
|
55
62
|
consoleWarningMock.mockRestore()
|
|
63
|
+
consoleErrorMock.mockRestore()
|
|
56
64
|
})
|
|
57
65
|
|
|
58
66
|
it('should render children', () => {
|
|
@@ -125,7 +133,7 @@ describe('<Button/>', () => {
|
|
|
125
133
|
})
|
|
126
134
|
|
|
127
135
|
it('should pass the `elementRef` prop', () => {
|
|
128
|
-
const elementRef =
|
|
136
|
+
const elementRef = vi.fn()
|
|
129
137
|
render(<Button elementRef={elementRef}>Hello</Button>)
|
|
130
138
|
|
|
131
139
|
const button = screen.getByRole('button', { name: 'Hello' })
|
|
@@ -195,7 +203,7 @@ describe('<Button/>', () => {
|
|
|
195
203
|
})
|
|
196
204
|
|
|
197
205
|
it('should pass the `onClick` prop', async () => {
|
|
198
|
-
const onClick =
|
|
206
|
+
const onClick = vi.fn()
|
|
199
207
|
render(<Button onClick={onClick}>Hello</Button>)
|
|
200
208
|
|
|
201
209
|
const button = screen.getByRole('button', { name: 'Hello' })
|
|
@@ -263,7 +271,7 @@ describe('<Button/>', () => {
|
|
|
263
271
|
})
|
|
264
272
|
|
|
265
273
|
it('should set role="button"', () => {
|
|
266
|
-
const onClick =
|
|
274
|
+
const onClick = vi.fn()
|
|
267
275
|
const { container } = render(
|
|
268
276
|
<Button as="span" onClick={onClick}>
|
|
269
277
|
Hello World
|
|
@@ -276,7 +284,7 @@ describe('<Button/>', () => {
|
|
|
276
284
|
})
|
|
277
285
|
|
|
278
286
|
it('should set tabIndex="0"', () => {
|
|
279
|
-
const onClick =
|
|
287
|
+
const onClick = vi.fn()
|
|
280
288
|
render(
|
|
281
289
|
<Button as="span" onClick={onClick}>
|
|
282
290
|
Hello World
|
|
@@ -289,7 +297,7 @@ describe('<Button/>', () => {
|
|
|
289
297
|
})
|
|
290
298
|
|
|
291
299
|
it('should pass down the type prop to the button element', () => {
|
|
292
|
-
const onClick =
|
|
300
|
+
const onClick = vi.fn()
|
|
293
301
|
render(
|
|
294
302
|
<Button type="submit" onClick={onClick}>
|
|
295
303
|
Hello World
|
|
@@ -302,7 +310,7 @@ describe('<Button/>', () => {
|
|
|
302
310
|
})
|
|
303
311
|
|
|
304
312
|
it('focuses with the focus helper', () => {
|
|
305
|
-
const onFocus =
|
|
313
|
+
const onFocus = vi.fn()
|
|
306
314
|
render(<Button onFocus={onFocus}>Hello World</Button>)
|
|
307
315
|
|
|
308
316
|
const button = screen.getByRole('button')
|
|
@@ -315,7 +323,7 @@ describe('<Button/>', () => {
|
|
|
315
323
|
|
|
316
324
|
describe('onClick', () => {
|
|
317
325
|
it('should call onClick when clicked', async () => {
|
|
318
|
-
const onClick =
|
|
326
|
+
const onClick = vi.fn()
|
|
319
327
|
render(<Button onClick={onClick}>Hello World</Button>)
|
|
320
328
|
|
|
321
329
|
const button = screen.getByRole('button', { name: 'Hello World' })
|
|
@@ -328,7 +336,7 @@ describe('<Button/>', () => {
|
|
|
328
336
|
})
|
|
329
337
|
|
|
330
338
|
it('should not call onClick when button is disabled', async () => {
|
|
331
|
-
const onClick =
|
|
339
|
+
const onClick = vi.fn()
|
|
332
340
|
|
|
333
341
|
render(
|
|
334
342
|
<Button disabled onClick={onClick}>
|
|
@@ -345,7 +353,7 @@ describe('<Button/>', () => {
|
|
|
345
353
|
})
|
|
346
354
|
|
|
347
355
|
it('should not call onClick when button is readOnly', async () => {
|
|
348
|
-
const onClick =
|
|
356
|
+
const onClick = vi.fn()
|
|
349
357
|
|
|
350
358
|
render(
|
|
351
359
|
<Button readOnly onClick={onClick}>
|
|
@@ -362,7 +370,7 @@ describe('<Button/>', () => {
|
|
|
362
370
|
})
|
|
363
371
|
|
|
364
372
|
it('should not call onClick when button is disabled and an href prop is provided', async () => {
|
|
365
|
-
const onClick =
|
|
373
|
+
const onClick = vi.fn()
|
|
366
374
|
|
|
367
375
|
render(<Button href="#">Hello World</Button>)
|
|
368
376
|
|
|
@@ -376,7 +384,7 @@ describe('<Button/>', () => {
|
|
|
376
384
|
})
|
|
377
385
|
|
|
378
386
|
it('should not call onClick when button is readOnly and an href prop is provided', async () => {
|
|
379
|
-
const onClick =
|
|
387
|
+
const onClick = vi.fn()
|
|
380
388
|
|
|
381
389
|
render(
|
|
382
390
|
<Button readOnly onClick={onClick} href="#">
|
|
@@ -393,7 +401,7 @@ describe('<Button/>', () => {
|
|
|
393
401
|
})
|
|
394
402
|
|
|
395
403
|
it('should call onClick when space key is pressed if href is provided', async () => {
|
|
396
|
-
const onClick =
|
|
404
|
+
const onClick = vi.fn()
|
|
397
405
|
|
|
398
406
|
render(
|
|
399
407
|
<Button onClick={onClick} href="#">
|
|
@@ -410,7 +418,7 @@ describe('<Button/>', () => {
|
|
|
410
418
|
})
|
|
411
419
|
|
|
412
420
|
it('should call onClick when enter key is pressed when not a button or link', async () => {
|
|
413
|
-
const onClick =
|
|
421
|
+
const onClick = vi.fn()
|
|
414
422
|
|
|
415
423
|
render(
|
|
416
424
|
<Button as="span" onClick={onClick}>
|
|
@@ -427,7 +435,7 @@ describe('<Button/>', () => {
|
|
|
427
435
|
})
|
|
428
436
|
|
|
429
437
|
it('should not call onClick when button is disabled and space key is pressed', async () => {
|
|
430
|
-
const onClick =
|
|
438
|
+
const onClick = vi.fn()
|
|
431
439
|
|
|
432
440
|
render(
|
|
433
441
|
<Button disabled onClick={onClick} href="#">
|
|
@@ -444,7 +452,7 @@ describe('<Button/>', () => {
|
|
|
444
452
|
})
|
|
445
453
|
|
|
446
454
|
it('should not call onClick when button is readOnly and space key is pressed', async () => {
|
|
447
|
-
const onClick =
|
|
455
|
+
const onClick = vi.fn()
|
|
448
456
|
|
|
449
457
|
render(
|
|
450
458
|
<Button readOnly onClick={onClick} href="#">
|
|
@@ -463,7 +471,7 @@ describe('<Button/>', () => {
|
|
|
463
471
|
|
|
464
472
|
describe('for a11y', () => {
|
|
465
473
|
it('should meet standards when onClick is given', async () => {
|
|
466
|
-
const onClick =
|
|
474
|
+
const onClick = vi.fn()
|
|
467
475
|
render(<Button onClick={onClick}>Hello World</Button>)
|
|
468
476
|
|
|
469
477
|
const button = screen.getByRole('button', { name: 'Hello World' })
|