@instructure/ui-buttons 8.55.1-snapshot-0 → 8.55.1-snapshot-4

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