@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.
- package/CHANGELOG.md +8 -0
- package/es/BaseButton/__new-tests__/BaseButton.test.js +361 -0
- package/es/Button/__new-tests__/Button.test.js +459 -0
- package/es/CloseButton/__new-tests__/CloseButton.test.js +63 -0
- package/es/CondensedButton/__new-tests__/CondensedButton.test.js +181 -0
- package/es/IconButton/__new-tests__/IconButton.test.js +185 -0
- package/es/ToggleButton/__new-tests__/ToggleButton.test.js +163 -0
- package/lib/BaseButton/__new-tests__/BaseButton.test.js +363 -0
- package/lib/Button/__new-tests__/Button.test.js +461 -0
- package/lib/CloseButton/__new-tests__/CloseButton.test.js +65 -0
- package/lib/CondensedButton/__new-tests__/CondensedButton.test.js +183 -0
- package/lib/IconButton/__new-tests__/IconButton.test.js +187 -0
- package/lib/ToggleButton/__new-tests__/ToggleButton.test.js +165 -0
- package/package.json +22 -20
- package/src/BaseButton/__new-tests__/BaseButton.test.tsx +407 -0
- package/src/Button/__new-tests__/Button.test.tsx +500 -0
- package/src/CloseButton/__new-tests__/CloseButton.test.tsx +70 -0
- package/src/CondensedButton/__new-tests__/CondensedButton.test.tsx +186 -0
- package/src/IconButton/__new-tests__/IconButton.test.tsx +214 -0
- package/src/ToggleButton/__new-tests__/ToggleButton.test.tsx +200 -0
- package/tsconfig.build.json +2 -3
- package/tsconfig.build.tsbuildinfo +1 -1
- package/types/BaseButton/__new-tests__/BaseButton.test.d.ts +2 -0
- package/types/BaseButton/__new-tests__/BaseButton.test.d.ts.map +1 -0
- package/types/Button/__new-tests__/Button.test.d.ts +2 -0
- package/types/Button/__new-tests__/Button.test.d.ts.map +1 -0
- package/types/CloseButton/__new-tests__/CloseButton.test.d.ts +2 -0
- package/types/CloseButton/__new-tests__/CloseButton.test.d.ts.map +1 -0
- package/types/CondensedButton/__new-tests__/CondensedButton.test.d.ts +2 -0
- package/types/CondensedButton/__new-tests__/CondensedButton.test.d.ts.map +1 -0
- package/types/IconButton/__new-tests__/IconButton.test.d.ts +2 -0
- package/types/IconButton/__new-tests__/IconButton.test.d.ts.map +1 -0
- package/types/ToggleButton/__new-tests__/ToggleButton.test.d.ts +2 -0
- package/types/ToggleButton/__new-tests__/ToggleButton.test.d.ts.map +1 -0
- package/es/BaseButton/BaseButtonLocator.js +0 -34
- package/es/BaseButton/locator.js +0 -27
- package/es/Button/ButtonLocator.js +0 -33
- package/es/Button/locator.js +0 -28
- package/es/CloseButton/CloseButtonLocator.js +0 -29
- package/es/CloseButton/locator.js +0 -27
- package/es/CondensedButton/CondensedButtonLocator.js +0 -33
- package/es/CondensedButton/locator.js +0 -26
- package/es/IconButton/IconButtonLocator.js +0 -33
- package/es/IconButton/locator.js +0 -26
- package/es/ToggleButton/ToggleButtonLocator.js +0 -46
- package/lib/BaseButton/BaseButtonLocator.js +0 -39
- package/lib/BaseButton/locator.js +0 -37
- package/lib/Button/ButtonLocator.js +0 -39
- package/lib/Button/locator.js +0 -39
- package/lib/CloseButton/CloseButtonLocator.js +0 -34
- package/lib/CloseButton/locator.js +0 -37
- package/lib/CondensedButton/CondensedButtonLocator.js +0 -39
- package/lib/CondensedButton/locator.js +0 -37
- package/lib/IconButton/IconButtonLocator.js +0 -39
- package/lib/IconButton/locator.js +0 -37
- package/lib/ToggleButton/ToggleButtonLocator.js +0 -51
- package/src/BaseButton/BaseButtonLocator.ts +0 -35
- package/src/BaseButton/locator.ts +0 -28
- package/src/Button/ButtonLocator.ts +0 -34
- package/src/Button/locator.ts +0 -27
- package/src/CloseButton/CloseButtonLocator.ts +0 -29
- package/src/CloseButton/locator.ts +0 -28
- package/src/CondensedButton/CondensedButtonLocator.ts +0 -34
- package/src/CondensedButton/locator.ts +0 -27
- package/src/IconButton/IconButtonLocator.ts +0 -34
- package/src/IconButton/locator.ts +0 -27
- package/src/ToggleButton/ToggleButtonLocator.ts +0 -44
- package/types/BaseButton/BaseButtonLocator.d.ts +0 -577
- package/types/BaseButton/BaseButtonLocator.d.ts.map +0 -1
- package/types/BaseButton/locator.d.ts +0 -4
- package/types/BaseButton/locator.d.ts.map +0 -1
- package/types/Button/ButtonLocator.d.ts +0 -577
- package/types/Button/ButtonLocator.d.ts.map +0 -1
- package/types/Button/locator.d.ts +0 -581
- package/types/Button/locator.d.ts.map +0 -1
- package/types/CloseButton/CloseButtonLocator.d.ts +0 -566
- package/types/CloseButton/CloseButtonLocator.d.ts.map +0 -1
- package/types/CloseButton/locator.d.ts +0 -4
- package/types/CloseButton/locator.d.ts.map +0 -1
- package/types/CondensedButton/CondensedButtonLocator.d.ts +0 -577
- package/types/CondensedButton/CondensedButtonLocator.d.ts.map +0 -1
- package/types/CondensedButton/locator.d.ts +0 -4
- package/types/CondensedButton/locator.d.ts.map +0 -1
- package/types/IconButton/IconButtonLocator.d.ts +0 -577
- package/types/IconButton/IconButtonLocator.d.ts.map +0 -1
- package/types/IconButton/locator.d.ts +0 -4
- package/types/IconButton/locator.d.ts.map +0 -1
- package/types/ToggleButton/ToggleButtonLocator.d.ts +0 -582
- package/types/ToggleButton/ToggleButtonLocator.d.ts.map +0 -1
|
@@ -0,0 +1,363 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
var _react = _interopRequireDefault(require("react"));
|
|
5
|
+
var _react2 = require("@testing-library/react");
|
|
6
|
+
var _userEvent = _interopRequireDefault(require("@testing-library/user-event"));
|
|
7
|
+
require("@testing-library/jest-dom");
|
|
8
|
+
var _index = require("../index");
|
|
9
|
+
var _runAxeCheck = require("@instructure/ui-axe-check/lib/runAxeCheck.js");
|
|
10
|
+
var _BaseButton, _BaseButton2, _BaseButton3, _BaseButton4, _BaseButton5, _svg, _BaseButton6, _BaseButton7, _BaseButton8, _BaseButton9, _BaseButton10, _BaseButton11;
|
|
11
|
+
/*
|
|
12
|
+
* The MIT License (MIT)
|
|
13
|
+
*
|
|
14
|
+
* Copyright (c) 2015 - present Instructure, Inc.
|
|
15
|
+
*
|
|
16
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
17
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
18
|
+
* in the Software without restriction, including without limitation the rights
|
|
19
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
20
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
21
|
+
* furnished to do so, subject to the following conditions:
|
|
22
|
+
*
|
|
23
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
24
|
+
* copies or substantial portions of the Software.
|
|
25
|
+
*
|
|
26
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
27
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
28
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
29
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
30
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
31
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
32
|
+
* SOFTWARE.
|
|
33
|
+
*/
|
|
34
|
+
describe('<BaseButton/>', () => {
|
|
35
|
+
let consoleWarningMock;
|
|
36
|
+
beforeEach(() => {
|
|
37
|
+
// Mocking console to prevent test output pollution
|
|
38
|
+
consoleWarningMock = jest.spyOn(console, 'warn').mockImplementation();
|
|
39
|
+
});
|
|
40
|
+
afterEach(() => {
|
|
41
|
+
consoleWarningMock.mockRestore();
|
|
42
|
+
});
|
|
43
|
+
it('should render a button and the children as button text', () => {
|
|
44
|
+
(0, _react2.render)(_BaseButton || (_BaseButton = /*#__PURE__*/_react.default.createElement(_index.BaseButton, null, "Hello World")));
|
|
45
|
+
const button = document.querySelector('button');
|
|
46
|
+
expect(button).toBeInTheDocument();
|
|
47
|
+
expect(button).toHaveTextContent('Hello World');
|
|
48
|
+
});
|
|
49
|
+
it('should not error with a null child', () => {
|
|
50
|
+
(0, _react2.render)(_BaseButton2 || (_BaseButton2 = /*#__PURE__*/_react.default.createElement(_index.BaseButton, null, "Hello World", null)));
|
|
51
|
+
const button = document.querySelector('button');
|
|
52
|
+
expect(button).toBeInTheDocument();
|
|
53
|
+
expect(button).toHaveTextContent('Hello World');
|
|
54
|
+
});
|
|
55
|
+
it('should render a link styled as a button if href is provided', () => {
|
|
56
|
+
(0, _react2.render)(_BaseButton3 || (_BaseButton3 = /*#__PURE__*/_react.default.createElement(_index.BaseButton, {
|
|
57
|
+
href: "example.html"
|
|
58
|
+
}, "Hello World")));
|
|
59
|
+
const linkButton = _react2.screen.getByRole('link', {
|
|
60
|
+
name: 'Hello World'
|
|
61
|
+
});
|
|
62
|
+
expect(linkButton).toBeInTheDocument();
|
|
63
|
+
expect(linkButton).toHaveAttribute('href', 'example.html');
|
|
64
|
+
});
|
|
65
|
+
it('should render as a link when `to` prop is provided', () => {
|
|
66
|
+
const _render = (0, _react2.render)(_BaseButton4 || (_BaseButton4 = /*#__PURE__*/_react.default.createElement(_index.BaseButton, {
|
|
67
|
+
to: "/example"
|
|
68
|
+
}, "Test"))),
|
|
69
|
+
container = _render.container;
|
|
70
|
+
const linkButton = container.querySelector('a');
|
|
71
|
+
expect(linkButton.getAttribute('to')).toBe('/example');
|
|
72
|
+
});
|
|
73
|
+
it('should render designated tag if `as` prop is specified', () => {
|
|
74
|
+
const _render2 = (0, _react2.render)(_BaseButton5 || (_BaseButton5 = /*#__PURE__*/_react.default.createElement(_index.BaseButton, {
|
|
75
|
+
as: "span"
|
|
76
|
+
}, "Hello World"))),
|
|
77
|
+
container = _render2.container;
|
|
78
|
+
const button = container.querySelector('[type="button"]');
|
|
79
|
+
expect(button).toBeInTheDocument();
|
|
80
|
+
expect(button).toHaveTextContent('Hello World');
|
|
81
|
+
expect(button.tagName).toBe('SPAN');
|
|
82
|
+
});
|
|
83
|
+
it('should set role="button"', () => {
|
|
84
|
+
const onClick = jest.fn();
|
|
85
|
+
const _render3 = (0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.BaseButton, {
|
|
86
|
+
as: "span",
|
|
87
|
+
onClick: onClick
|
|
88
|
+
}, "Hello World")),
|
|
89
|
+
container = _render3.container;
|
|
90
|
+
const button = container.querySelector('span[type="button"]');
|
|
91
|
+
expect(button).toBeInTheDocument();
|
|
92
|
+
expect(button).toHaveAttribute('role', 'button');
|
|
93
|
+
});
|
|
94
|
+
it('should set tabIndex="0"', () => {
|
|
95
|
+
const onClick = jest.fn();
|
|
96
|
+
(0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.BaseButton, {
|
|
97
|
+
as: "span",
|
|
98
|
+
onClick: onClick
|
|
99
|
+
}, "Hello World"));
|
|
100
|
+
const button = _react2.screen.getByRole('button', {
|
|
101
|
+
name: 'Hello World'
|
|
102
|
+
});
|
|
103
|
+
expect(button).toBeInTheDocument();
|
|
104
|
+
expect(button).toHaveAttribute('tabIndex', '0');
|
|
105
|
+
});
|
|
106
|
+
it('should pass down the type prop to the button element', async () => {
|
|
107
|
+
const onClick = jest.fn();
|
|
108
|
+
(0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.BaseButton, {
|
|
109
|
+
type: "submit",
|
|
110
|
+
onClick: onClick
|
|
111
|
+
}, "Hello World"));
|
|
112
|
+
const button = _react2.screen.getByRole('button', {
|
|
113
|
+
name: 'Hello World'
|
|
114
|
+
});
|
|
115
|
+
expect(button).toBeInTheDocument();
|
|
116
|
+
expect(button).toHaveAttribute('type', 'submit');
|
|
117
|
+
});
|
|
118
|
+
it('should pass down an icon via the icon property', () => {
|
|
119
|
+
const SomeIcon = () => _svg || (_svg = /*#__PURE__*/_react.default.createElement("svg", null, /*#__PURE__*/_react.default.createElement("circle", {
|
|
120
|
+
cx: "25",
|
|
121
|
+
cy: "75",
|
|
122
|
+
r: "20"
|
|
123
|
+
})));
|
|
124
|
+
(0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.BaseButton, {
|
|
125
|
+
renderIcon: SomeIcon
|
|
126
|
+
}, "Hello World"));
|
|
127
|
+
const icon = document.querySelector('svg');
|
|
128
|
+
expect(icon).toBeInTheDocument();
|
|
129
|
+
});
|
|
130
|
+
it('focuses with the focus helper', async () => {
|
|
131
|
+
(0, _react2.render)(_BaseButton6 || (_BaseButton6 = /*#__PURE__*/_react.default.createElement(_index.BaseButton, null, "Hello World")));
|
|
132
|
+
const button = _react2.screen.getByRole('button', {
|
|
133
|
+
name: 'Hello World'
|
|
134
|
+
});
|
|
135
|
+
button.focus();
|
|
136
|
+
expect(document.activeElement).toBe(button);
|
|
137
|
+
});
|
|
138
|
+
it('should provide an elementRef prop', async () => {
|
|
139
|
+
const elementRef = jest.fn();
|
|
140
|
+
(0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.BaseButton, {
|
|
141
|
+
elementRef: elementRef
|
|
142
|
+
}, "Hello World"));
|
|
143
|
+
const button = _react2.screen.getByRole('button', {
|
|
144
|
+
name: 'Hello World'
|
|
145
|
+
});
|
|
146
|
+
expect(elementRef).toBeCalledWith(button);
|
|
147
|
+
});
|
|
148
|
+
describe('onClick', () => {
|
|
149
|
+
it('should call onClick when clicked', async () => {
|
|
150
|
+
const onClick = jest.fn();
|
|
151
|
+
(0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.BaseButton, {
|
|
152
|
+
onClick: onClick
|
|
153
|
+
}, "Hello World"));
|
|
154
|
+
const button = _react2.screen.getByRole('button', {
|
|
155
|
+
name: 'Hello World'
|
|
156
|
+
});
|
|
157
|
+
await _userEvent.default.click(button);
|
|
158
|
+
await (0, _react2.waitFor)(() => {
|
|
159
|
+
expect(onClick).toHaveBeenCalledTimes(1);
|
|
160
|
+
});
|
|
161
|
+
});
|
|
162
|
+
it('should not call onClick when interaction is "disabled"', async () => {
|
|
163
|
+
const onClick = jest.fn();
|
|
164
|
+
(0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.BaseButton, {
|
|
165
|
+
interaction: "disabled",
|
|
166
|
+
onClick: onClick
|
|
167
|
+
}, "Hello World"));
|
|
168
|
+
const button = _react2.screen.getByRole('button', {
|
|
169
|
+
name: 'Hello World'
|
|
170
|
+
});
|
|
171
|
+
await _userEvent.default.click(button);
|
|
172
|
+
await (0, _react2.waitFor)(() => {
|
|
173
|
+
expect(onClick).not.toHaveBeenCalled();
|
|
174
|
+
});
|
|
175
|
+
});
|
|
176
|
+
it('should not call onClick when disabled is set"', async () => {
|
|
177
|
+
const onClick = jest.fn();
|
|
178
|
+
(0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.BaseButton, {
|
|
179
|
+
disabled: true,
|
|
180
|
+
onClick: onClick
|
|
181
|
+
}, "Hello World"));
|
|
182
|
+
const button = _react2.screen.getByRole('button', {
|
|
183
|
+
name: 'Hello World'
|
|
184
|
+
});
|
|
185
|
+
await _userEvent.default.click(button);
|
|
186
|
+
await (0, _react2.waitFor)(() => {
|
|
187
|
+
expect(onClick).not.toHaveBeenCalled();
|
|
188
|
+
});
|
|
189
|
+
});
|
|
190
|
+
it('should not call onClick when interaction is "readonly"', async () => {
|
|
191
|
+
const onClick = jest.fn();
|
|
192
|
+
(0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.BaseButton, {
|
|
193
|
+
interaction: "readonly",
|
|
194
|
+
onClick: onClick
|
|
195
|
+
}, "Hello World"));
|
|
196
|
+
const button = _react2.screen.getByRole('button', {
|
|
197
|
+
name: 'Hello World'
|
|
198
|
+
});
|
|
199
|
+
await _userEvent.default.click(button);
|
|
200
|
+
await (0, _react2.waitFor)(() => {
|
|
201
|
+
expect(onClick).not.toHaveBeenCalled();
|
|
202
|
+
});
|
|
203
|
+
});
|
|
204
|
+
it('should not call onClick when readOnly is set', async () => {
|
|
205
|
+
const onClick = jest.fn();
|
|
206
|
+
(0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.BaseButton, {
|
|
207
|
+
readOnly: true,
|
|
208
|
+
onClick: onClick
|
|
209
|
+
}, "Hello World"));
|
|
210
|
+
const button = _react2.screen.getByRole('button', {
|
|
211
|
+
name: 'Hello World'
|
|
212
|
+
});
|
|
213
|
+
await _userEvent.default.click(button);
|
|
214
|
+
await (0, _react2.waitFor)(() => {
|
|
215
|
+
expect(onClick).not.toHaveBeenCalled();
|
|
216
|
+
});
|
|
217
|
+
});
|
|
218
|
+
it('should not call onClick when button is disabled and an href prop is provided', async () => {
|
|
219
|
+
const onClick = jest.fn();
|
|
220
|
+
(0, _react2.render)(_BaseButton7 || (_BaseButton7 = /*#__PURE__*/_react.default.createElement(_index.BaseButton, {
|
|
221
|
+
href: "#"
|
|
222
|
+
}, "Hello World")));
|
|
223
|
+
const button = _react2.screen.getByRole('link', {
|
|
224
|
+
name: 'Hello World'
|
|
225
|
+
});
|
|
226
|
+
await _userEvent.default.click(button);
|
|
227
|
+
await (0, _react2.waitFor)(() => {
|
|
228
|
+
expect(onClick).not.toHaveBeenCalled();
|
|
229
|
+
});
|
|
230
|
+
});
|
|
231
|
+
it('should not call onClick when interaction is "readonly" and an href prop is provided', async () => {
|
|
232
|
+
const onClick = jest.fn();
|
|
233
|
+
(0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.BaseButton, {
|
|
234
|
+
interaction: "readonly",
|
|
235
|
+
onClick: onClick,
|
|
236
|
+
href: "#"
|
|
237
|
+
}, "Hello World"));
|
|
238
|
+
const button = _react2.screen.getByRole('link', {
|
|
239
|
+
name: 'Hello World'
|
|
240
|
+
});
|
|
241
|
+
await _userEvent.default.click(button);
|
|
242
|
+
await (0, _react2.waitFor)(() => {
|
|
243
|
+
expect(onClick).not.toHaveBeenCalled();
|
|
244
|
+
});
|
|
245
|
+
});
|
|
246
|
+
it('should call onClick when space key is pressed if href is provided', async () => {
|
|
247
|
+
const onClick = jest.fn();
|
|
248
|
+
(0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.BaseButton, {
|
|
249
|
+
onClick: onClick,
|
|
250
|
+
href: "#"
|
|
251
|
+
}, "Hello World"));
|
|
252
|
+
const button = _react2.screen.getByRole('link', {
|
|
253
|
+
name: 'Hello World'
|
|
254
|
+
});
|
|
255
|
+
await _userEvent.default.type(button, '{space}');
|
|
256
|
+
await (0, _react2.waitFor)(() => {
|
|
257
|
+
expect(onClick).toHaveBeenCalled();
|
|
258
|
+
});
|
|
259
|
+
});
|
|
260
|
+
it('should call onClick when enter key is pressed when not a button or link', async () => {
|
|
261
|
+
const onClick = jest.fn();
|
|
262
|
+
(0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.BaseButton, {
|
|
263
|
+
as: "span",
|
|
264
|
+
onClick: onClick
|
|
265
|
+
}, "Hello World"));
|
|
266
|
+
const button = _react2.screen.getByRole('button', {
|
|
267
|
+
name: 'Hello World'
|
|
268
|
+
});
|
|
269
|
+
await _userEvent.default.type(button, '{enter}');
|
|
270
|
+
await (0, _react2.waitFor)(() => {
|
|
271
|
+
expect(onClick).toHaveBeenCalled();
|
|
272
|
+
});
|
|
273
|
+
});
|
|
274
|
+
it('should not call onClick when interaction is "disabled" and space key is pressed', async () => {
|
|
275
|
+
const onClick = jest.fn();
|
|
276
|
+
(0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.BaseButton, {
|
|
277
|
+
interaction: "disabled",
|
|
278
|
+
onClick: onClick,
|
|
279
|
+
href: "#"
|
|
280
|
+
}, "Hello World"));
|
|
281
|
+
const button = _react2.screen.getByRole('link', {
|
|
282
|
+
name: 'Hello World'
|
|
283
|
+
});
|
|
284
|
+
await _userEvent.default.type(button, '{space}');
|
|
285
|
+
await (0, _react2.waitFor)(() => {
|
|
286
|
+
expect(onClick).not.toHaveBeenCalled();
|
|
287
|
+
});
|
|
288
|
+
});
|
|
289
|
+
it('should not call onClick when interaction is "readonly" and space key is pressed', async () => {
|
|
290
|
+
const onClick = jest.fn();
|
|
291
|
+
(0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.BaseButton, {
|
|
292
|
+
interaction: "readonly",
|
|
293
|
+
onClick: onClick,
|
|
294
|
+
href: "#"
|
|
295
|
+
}, "Hello World"));
|
|
296
|
+
const button = _react2.screen.getByRole('link', {
|
|
297
|
+
name: 'Hello World'
|
|
298
|
+
});
|
|
299
|
+
await _userEvent.default.type(button, '{space}');
|
|
300
|
+
await (0, _react2.waitFor)(() => {
|
|
301
|
+
expect(onClick).not.toHaveBeenCalled();
|
|
302
|
+
});
|
|
303
|
+
});
|
|
304
|
+
});
|
|
305
|
+
describe('when passing down props to View', () => {
|
|
306
|
+
it("passes cursor='pointer' to View by default", async () => {
|
|
307
|
+
(0, _react2.render)(_BaseButton8 || (_BaseButton8 = /*#__PURE__*/_react.default.createElement(_index.BaseButton, null, "Hello World")));
|
|
308
|
+
const button = _react2.screen.getByRole('button', {
|
|
309
|
+
name: 'Hello World'
|
|
310
|
+
});
|
|
311
|
+
const style = window.getComputedStyle(button);
|
|
312
|
+
expect(style.cursor).toBe('pointer');
|
|
313
|
+
});
|
|
314
|
+
it("passes cursor='not-allowed' to View when disabled", async () => {
|
|
315
|
+
(0, _react2.render)(_BaseButton9 || (_BaseButton9 = /*#__PURE__*/_react.default.createElement(_index.BaseButton, {
|
|
316
|
+
interaction: "disabled"
|
|
317
|
+
}, "Hello World")));
|
|
318
|
+
const button = _react2.screen.getByRole('button', {
|
|
319
|
+
name: 'Hello World'
|
|
320
|
+
});
|
|
321
|
+
const style = window.getComputedStyle(button);
|
|
322
|
+
expect(style.cursor).toBe('not-allowed');
|
|
323
|
+
});
|
|
324
|
+
});
|
|
325
|
+
describe('for a11y', () => {
|
|
326
|
+
it('should meet standards when onClick is given', async () => {
|
|
327
|
+
const onClick = jest.fn();
|
|
328
|
+
(0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.BaseButton, {
|
|
329
|
+
onClick: onClick
|
|
330
|
+
}, "Hello World"));
|
|
331
|
+
const button = _react2.screen.getByRole('button', {
|
|
332
|
+
name: 'Hello World'
|
|
333
|
+
});
|
|
334
|
+
await _userEvent.default.click(button);
|
|
335
|
+
await (0, _react2.waitFor)(async () => {
|
|
336
|
+
const axeCheck = await (0, _runAxeCheck.runAxeCheck)(button);
|
|
337
|
+
expect(axeCheck).toBe(true);
|
|
338
|
+
});
|
|
339
|
+
});
|
|
340
|
+
describe('when disabled', () => {
|
|
341
|
+
it('sets the disabled attribute so that the button is not in tab order', () => {
|
|
342
|
+
(0, _react2.render)(_BaseButton10 || (_BaseButton10 = /*#__PURE__*/_react.default.createElement(_index.BaseButton, {
|
|
343
|
+
interaction: "disabled"
|
|
344
|
+
}, "Hello World")));
|
|
345
|
+
const button = _react2.screen.getByRole('button', {
|
|
346
|
+
name: 'Hello World'
|
|
347
|
+
});
|
|
348
|
+
expect(button).toHaveAttribute('disabled');
|
|
349
|
+
});
|
|
350
|
+
});
|
|
351
|
+
describe('when readonly', () => {
|
|
352
|
+
it('sets the disabled attribute so that the button is not in tab order', async () => {
|
|
353
|
+
(0, _react2.render)(_BaseButton11 || (_BaseButton11 = /*#__PURE__*/_react.default.createElement(_index.BaseButton, {
|
|
354
|
+
interaction: "readonly"
|
|
355
|
+
}, "Hello World")));
|
|
356
|
+
const button = _react2.screen.getByRole('button', {
|
|
357
|
+
name: 'Hello World'
|
|
358
|
+
});
|
|
359
|
+
expect(button).toHaveAttribute('disabled');
|
|
360
|
+
});
|
|
361
|
+
});
|
|
362
|
+
});
|
|
363
|
+
});
|