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