@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.
Files changed (89) hide show
  1. package/CHANGELOG.md +8 -0
  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
@@ -0,0 +1,181 @@
1
+ var _circle, _CondensedButton, _CondensedButton2, _CondensedButton3, _CondensedButton4, _CondensedButton5, _CondensedButton6, _CondensedButton7;
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 { CondensedButton } from '../index';
31
+ describe('<CondensedButton/>', () => {
32
+ var _CondensedButton8;
33
+ const icon = /*#__PURE__*/React.createElement("svg", {
34
+ "data-title": "myIcon",
35
+ height: "1em",
36
+ width: "1em",
37
+ style: {
38
+ fill: 'currentcolor'
39
+ }
40
+ }, _circle || (_circle = /*#__PURE__*/React.createElement("circle", {
41
+ cx: "0.5em",
42
+ cy: "0.5em",
43
+ r: "0.5em"
44
+ })));
45
+ const iconSelector = 'svg[data-title="myIcon"]';
46
+ it('should render children', () => {
47
+ const children = 'Hello world';
48
+ render( /*#__PURE__*/React.createElement(CondensedButton, null, children));
49
+ const button = document.querySelector('button');
50
+ expect(button).toBeInTheDocument();
51
+ expect(button).toHaveTextContent(children);
52
+ });
53
+ it('should provide a focused getter', () => {
54
+ var _componentRef;
55
+ let componentRef;
56
+ render( /*#__PURE__*/React.createElement(CondensedButton, {
57
+ ref: component => {
58
+ componentRef = component;
59
+ }
60
+ }, "Hello"));
61
+ const button = screen.getByRole('button', {
62
+ name: 'Hello'
63
+ });
64
+ button.focus();
65
+ expect((_componentRef = componentRef) === null || _componentRef === void 0 ? void 0 : _componentRef.focused).toBe(true);
66
+ });
67
+ it('should provide a focus function', () => {
68
+ var _componentRef2;
69
+ let componentRef;
70
+ render( /*#__PURE__*/React.createElement(CondensedButton, {
71
+ ref: component => {
72
+ componentRef = component;
73
+ }
74
+ }, "Hello"));
75
+ const button = screen.getByRole('button', {
76
+ name: 'Hello'
77
+ });
78
+ (_componentRef2 = componentRef) === null || _componentRef2 === void 0 ? void 0 : _componentRef2.focus();
79
+ expect(document.activeElement).toBe(button);
80
+ });
81
+ it('should pass the type attribute', () => {
82
+ render(_CondensedButton || (_CondensedButton = /*#__PURE__*/React.createElement(CondensedButton, {
83
+ type: "submit"
84
+ }, "Hello")));
85
+ const button = screen.getByRole('button', {
86
+ name: 'Hello'
87
+ });
88
+ expect(button).toBeInTheDocument();
89
+ expect(button).toHaveAttribute('type', 'submit');
90
+ });
91
+ it('should pass the `elementRef` prop', async () => {
92
+ const elementRef = jest.fn();
93
+ render( /*#__PURE__*/React.createElement(CondensedButton, {
94
+ elementRef: elementRef
95
+ }, "Hello"));
96
+ const button = screen.getByRole('button', {
97
+ name: 'Hello'
98
+ });
99
+ expect(elementRef).toHaveBeenCalledWith(button);
100
+ });
101
+ it('should pass the `as` prop', () => {
102
+ const _render = render(_CondensedButton2 || (_CondensedButton2 = /*#__PURE__*/React.createElement(CondensedButton, {
103
+ as: "li"
104
+ }, "Hello"))),
105
+ container = _render.container;
106
+ const button = container.querySelector('[type="button"]');
107
+ expect(button).toBeInTheDocument();
108
+ expect(button).toHaveTextContent('Hello');
109
+ expect(button.tagName).toBe('LI');
110
+ });
111
+ it('should set the disabled attribute when `interaction` is set to disabled', () => {
112
+ render(_CondensedButton3 || (_CondensedButton3 = /*#__PURE__*/React.createElement(CondensedButton, {
113
+ interaction: "disabled"
114
+ }, "Hello")));
115
+ const button = screen.getByRole('button', {
116
+ name: 'Hello'
117
+ });
118
+ expect(button).toHaveAttribute('disabled');
119
+ });
120
+ it('should set the disabled attribute when `disabled` is set', () => {
121
+ render(_CondensedButton4 || (_CondensedButton4 = /*#__PURE__*/React.createElement(CondensedButton, {
122
+ disabled: true
123
+ }, "Hello")));
124
+ const button = screen.getByRole('button', {
125
+ name: 'Hello'
126
+ });
127
+ expect(button).toHaveAttribute('disabled');
128
+ });
129
+ it('should set the disabled attribute when `interaction` is set to readonly', () => {
130
+ render(_CondensedButton5 || (_CondensedButton5 = /*#__PURE__*/React.createElement(CondensedButton, {
131
+ interaction: "readonly"
132
+ }, "Hello")));
133
+ const button = screen.getByRole('button', {
134
+ name: 'Hello'
135
+ });
136
+ expect(button).toHaveAttribute('disabled');
137
+ });
138
+ it('should set the disabled attribute when `readOnly` is set', () => {
139
+ render(_CondensedButton6 || (_CondensedButton6 = /*#__PURE__*/React.createElement(CondensedButton, {
140
+ readOnly: true
141
+ }, "Hello")));
142
+ const button = screen.getByRole('button', {
143
+ name: 'Hello'
144
+ });
145
+ expect(button).toHaveAttribute('disabled');
146
+ });
147
+ it('should pass the `href` prop', () => {
148
+ render(_CondensedButton7 || (_CondensedButton7 = /*#__PURE__*/React.createElement(CondensedButton, {
149
+ href: "#"
150
+ }, "Hello")));
151
+ const linkButton = screen.getByRole('link', {
152
+ name: 'Hello'
153
+ });
154
+ expect(linkButton).toBeInTheDocument();
155
+ expect(linkButton).toHaveAttribute('href', '#');
156
+ });
157
+ it('should pass the `renderIcon` prop', async () => {
158
+ render(_CondensedButton8 || (_CondensedButton8 = /*#__PURE__*/React.createElement(CondensedButton, {
159
+ renderIcon: icon
160
+ }, "Hello")));
161
+ const svgIcon = document.querySelector(iconSelector);
162
+ const button = screen.getByRole('button', {
163
+ name: 'Hello'
164
+ });
165
+ expect(button).toBeInTheDocument();
166
+ expect(svgIcon).toBeInTheDocument();
167
+ });
168
+ it('should pass the `onClick` prop', async () => {
169
+ const onClick = jest.fn();
170
+ render( /*#__PURE__*/React.createElement(CondensedButton, {
171
+ onClick: onClick
172
+ }, "Hello"));
173
+ const button = screen.getByRole('button', {
174
+ name: 'Hello'
175
+ });
176
+ await userEvent.click(button);
177
+ await waitFor(() => {
178
+ expect(onClick).toHaveBeenCalledTimes(1);
179
+ });
180
+ });
181
+ });
@@ -0,0 +1,185 @@
1
+ var _circle;
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 { IconButton } from '../index';
31
+ describe('<IconButton/>', () => {
32
+ var _IconButton, _IconButton2, _IconButton3, _IconButton4, _IconButton5, _IconButton6, _IconButton7, _IconButton8, _IconButton9;
33
+ const icon = /*#__PURE__*/React.createElement("svg", {
34
+ "data-title": "myIcon",
35
+ height: "1em",
36
+ width: "1em",
37
+ style: {
38
+ fill: 'currentcolor'
39
+ }
40
+ }, _circle || (_circle = /*#__PURE__*/React.createElement("circle", {
41
+ cx: "0.5em",
42
+ cy: "0.5em",
43
+ r: "0.5em"
44
+ })));
45
+ const iconSelector = 'svg[data-title="myIcon"]';
46
+ it('should render an icon when provided as the `children` prop', () => {
47
+ render(_IconButton || (_IconButton = /*#__PURE__*/React.createElement(IconButton, {
48
+ screenReaderLabel: "some action"
49
+ }, icon)));
50
+ const svgIcon = document.querySelector(iconSelector);
51
+ const button = screen.getByRole('button');
52
+ expect(button).toBeInTheDocument();
53
+ expect(svgIcon).toBeInTheDocument();
54
+ expect(button).toHaveTextContent('some action');
55
+ });
56
+ it('should render an icon when provided as the `renderIcon` prop', () => {
57
+ render(_IconButton2 || (_IconButton2 = /*#__PURE__*/React.createElement(IconButton, {
58
+ screenReaderLabel: "some action",
59
+ renderIcon: icon
60
+ })));
61
+ const svgIcon = document.querySelector(iconSelector);
62
+ const button = screen.getByRole('button');
63
+ expect(button).toBeInTheDocument();
64
+ expect(svgIcon).toBeInTheDocument();
65
+ });
66
+ it('should provide a focused getter', () => {
67
+ var _componentRef;
68
+ let componentRef;
69
+ render( /*#__PURE__*/React.createElement(IconButton, {
70
+ screenReaderLabel: "some action",
71
+ renderIcon: icon,
72
+ ref: component => {
73
+ componentRef = component;
74
+ }
75
+ }));
76
+ const button = screen.getByRole('button');
77
+ button.focus();
78
+ expect((_componentRef = componentRef) === null || _componentRef === void 0 ? void 0 : _componentRef.focused).toBe(true);
79
+ });
80
+ it('should provide a focus function', () => {
81
+ var _componentRef2;
82
+ let componentRef;
83
+ render( /*#__PURE__*/React.createElement(IconButton, {
84
+ screenReaderLabel: "some action",
85
+ renderIcon: icon,
86
+ ref: component => {
87
+ componentRef = component;
88
+ }
89
+ }));
90
+ const button = screen.getByRole('button');
91
+ (_componentRef2 = componentRef) === null || _componentRef2 === void 0 ? void 0 : _componentRef2.focus();
92
+ expect(document.activeElement).toBe(button);
93
+ });
94
+ it('should pass the `href` prop', () => {
95
+ render(_IconButton3 || (_IconButton3 = /*#__PURE__*/React.createElement(IconButton, {
96
+ screenReaderLabel: "some action",
97
+ renderIcon: icon,
98
+ href: "#"
99
+ })));
100
+ const linkButton = screen.getByRole('link');
101
+ expect(linkButton).toBeInTheDocument();
102
+ expect(linkButton).toHaveAttribute('href', '#');
103
+ });
104
+ it('should pass the `type` prop', () => {
105
+ render(_IconButton4 || (_IconButton4 = /*#__PURE__*/React.createElement(IconButton, {
106
+ screenReaderLabel: "some action",
107
+ renderIcon: icon,
108
+ type: "reset"
109
+ })));
110
+ const button = screen.getByRole('button');
111
+ expect(button).toBeInTheDocument();
112
+ expect(button).toHaveAttribute('type', 'reset');
113
+ });
114
+ it('should pass the `elementRef` prop', () => {
115
+ const elementRef = jest.fn();
116
+ render( /*#__PURE__*/React.createElement(IconButton, {
117
+ screenReaderLabel: "some action",
118
+ renderIcon: icon,
119
+ elementRef: elementRef
120
+ }));
121
+ const button = screen.getByRole('button');
122
+ expect(elementRef).toHaveBeenCalledWith(button);
123
+ });
124
+ it('should pass the `as` prop', () => {
125
+ const _render = render(_IconButton5 || (_IconButton5 = /*#__PURE__*/React.createElement(IconButton, {
126
+ screenReaderLabel: "some action",
127
+ renderIcon: icon,
128
+ as: "li"
129
+ }))),
130
+ container = _render.container;
131
+ const button = container.querySelector('[type="button"]');
132
+ expect(button).toBeInTheDocument();
133
+ expect(button).toHaveTextContent('some action');
134
+ expect(button.tagName).toBe('LI');
135
+ });
136
+ it('should set the disabled attribute when `interaction` is set to disabled', () => {
137
+ render(_IconButton6 || (_IconButton6 = /*#__PURE__*/React.createElement(IconButton, {
138
+ screenReaderLabel: "some action",
139
+ renderIcon: icon,
140
+ interaction: "disabled"
141
+ })));
142
+ const button = screen.getByRole('button');
143
+ expect(button).toHaveAttribute('disabled');
144
+ });
145
+ it('should set the disabled attribute when `disabled` is set', () => {
146
+ render(_IconButton7 || (_IconButton7 = /*#__PURE__*/React.createElement(IconButton, {
147
+ screenReaderLabel: "some action",
148
+ renderIcon: icon,
149
+ disabled: true
150
+ })));
151
+ const button = screen.getByRole('button');
152
+ expect(button).toHaveAttribute('disabled');
153
+ });
154
+ it('should set the disabled attribute when `interaction` is set to readonly', () => {
155
+ render(_IconButton8 || (_IconButton8 = /*#__PURE__*/React.createElement(IconButton, {
156
+ screenReaderLabel: "some action",
157
+ renderIcon: icon,
158
+ interaction: "readonly"
159
+ })));
160
+ const button = screen.getByRole('button');
161
+ expect(button).toHaveAttribute('disabled');
162
+ });
163
+ it('should set the disabled attribute when `readOnly` is set', () => {
164
+ render(_IconButton9 || (_IconButton9 = /*#__PURE__*/React.createElement(IconButton, {
165
+ screenReaderLabel: "some action",
166
+ renderIcon: icon,
167
+ readOnly: true
168
+ })));
169
+ const button = screen.getByRole('button');
170
+ expect(button).toHaveAttribute('disabled');
171
+ });
172
+ it('should pass the `onClick` prop', async () => {
173
+ const onClick = jest.fn();
174
+ render( /*#__PURE__*/React.createElement(IconButton, {
175
+ screenReaderLabel: "some action",
176
+ renderIcon: icon,
177
+ onClick: onClick
178
+ }));
179
+ const button = screen.getByRole('button');
180
+ await userEvent.click(button);
181
+ await waitFor(() => {
182
+ expect(onClick).toHaveBeenCalledTimes(1);
183
+ });
184
+ });
185
+ });
@@ -0,0 +1,163 @@
1
+ var _svg;
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 { ToggleButton } from '../index';
31
+ describe('<ToggleButton />', () => {
32
+ var _ToggleButton, _ToggleButton2, _ToggleButton3, _ToggleButton4, _ToggleButton5, _ToggleButton6, _ToggleButton7, _ToggleButton8, _ToggleButton9;
33
+ const icon = _svg || (_svg = /*#__PURE__*/React.createElement("svg", {
34
+ "data-title": "myIcon",
35
+ height: "1em",
36
+ width: "1em"
37
+ }, /*#__PURE__*/React.createElement("circle", {
38
+ cx: "0.5em",
39
+ cy: "0.5em",
40
+ r: "0.5em"
41
+ })));
42
+ const iconSelector = 'svg[data-title="myIcon"]';
43
+ it('should render', () => {
44
+ render(_ToggleButton || (_ToggleButton = /*#__PURE__*/React.createElement(ToggleButton, {
45
+ screenReaderLabel: "This is a screen reader label",
46
+ renderIcon: icon,
47
+ renderTooltipContent: "This is tooltip content",
48
+ status: "pressed"
49
+ })));
50
+ const button = screen.getByRole('button');
51
+ const svgIcon = document.querySelector(iconSelector);
52
+ const tooltip = screen.getByRole('tooltip');
53
+ expect(button).toBeInTheDocument();
54
+ expect(button).toHaveTextContent('This is a screen reader label');
55
+ expect(svgIcon).toBeInTheDocument();
56
+ expect(tooltip).toBeInTheDocument();
57
+ expect(tooltip).toHaveTextContent('This is tooltip content');
58
+ });
59
+ it('should set `aria-pressed` to `true` if `status` is `pressed`', () => {
60
+ render(_ToggleButton2 || (_ToggleButton2 = /*#__PURE__*/React.createElement(ToggleButton, {
61
+ screenReaderLabel: "This is a screen reader label",
62
+ renderIcon: icon,
63
+ renderTooltipContent: "This is tooltip content",
64
+ status: "pressed"
65
+ })));
66
+ const button = screen.getByRole('button');
67
+ expect(button).toHaveAttribute('aria-pressed', 'true');
68
+ });
69
+ it('should set `aria-pressed` to `false` if `status` is `unpressed`', () => {
70
+ render(_ToggleButton3 || (_ToggleButton3 = /*#__PURE__*/React.createElement(ToggleButton, {
71
+ screenReaderLabel: "This is a screen reader label",
72
+ renderIcon: icon,
73
+ renderTooltipContent: "This is tooltip content",
74
+ status: "unpressed"
75
+ })));
76
+ const button = screen.getByRole('button');
77
+ expect(button).toHaveAttribute('aria-pressed', 'false');
78
+ });
79
+ it('should render an icon', () => {
80
+ render(_ToggleButton4 || (_ToggleButton4 = /*#__PURE__*/React.createElement(ToggleButton, {
81
+ screenReaderLabel: "This is a screen reader label",
82
+ renderIcon: icon,
83
+ renderTooltipContent: "This is tooltip content",
84
+ status: "pressed"
85
+ })));
86
+ const button = screen.getByRole('button');
87
+ const svgIcon = document.querySelector(iconSelector);
88
+ expect(button).toBeInTheDocument();
89
+ expect(svgIcon).toBeInTheDocument();
90
+ });
91
+ it('should pass the `as` prop', () => {
92
+ const _render = render(_ToggleButton5 || (_ToggleButton5 = /*#__PURE__*/React.createElement(ToggleButton, {
93
+ screenReaderLabel: "This is a screen reader label",
94
+ renderIcon: icon,
95
+ renderTooltipContent: "This is tooltip content",
96
+ as: "li",
97
+ status: "pressed"
98
+ }))),
99
+ container = _render.container;
100
+ const button = container.querySelector('[type="button"]');
101
+ expect(button).toBeInTheDocument();
102
+ expect(button.tagName).toBe('LI');
103
+ });
104
+ it('should set the disabled attribute when `interaction` prop is set to disabled', () => {
105
+ render(_ToggleButton6 || (_ToggleButton6 = /*#__PURE__*/React.createElement(ToggleButton, {
106
+ screenReaderLabel: "This is a screen reader label",
107
+ renderIcon: icon,
108
+ renderTooltipContent: "This is tooltip content",
109
+ interaction: "disabled",
110
+ status: "pressed"
111
+ })));
112
+ const button = screen.getByRole('button');
113
+ expect(button).toHaveAttribute('disabled');
114
+ });
115
+ it('should set the disabled attribute when `disabled` prop is set', () => {
116
+ render(_ToggleButton7 || (_ToggleButton7 = /*#__PURE__*/React.createElement(ToggleButton, {
117
+ screenReaderLabel: "This is a screen reader label",
118
+ renderIcon: icon,
119
+ renderTooltipContent: "This is tooltip content",
120
+ disabled: true,
121
+ status: "pressed"
122
+ })));
123
+ const button = screen.getByRole('button');
124
+ expect(button).toHaveAttribute('disabled');
125
+ });
126
+ it('should set the disabled attribute when `interaction` prop is set to readonly', () => {
127
+ render(_ToggleButton8 || (_ToggleButton8 = /*#__PURE__*/React.createElement(ToggleButton, {
128
+ screenReaderLabel: "This is a screen reader label",
129
+ renderIcon: icon,
130
+ renderTooltipContent: "This is tooltip content",
131
+ interaction: "readonly",
132
+ status: "pressed"
133
+ })));
134
+ const button = screen.getByRole('button');
135
+ expect(button).toHaveAttribute('disabled');
136
+ });
137
+ it('should set the disabled attribute when `readOnly` prop is set', () => {
138
+ render(_ToggleButton9 || (_ToggleButton9 = /*#__PURE__*/React.createElement(ToggleButton, {
139
+ screenReaderLabel: "This is a screen reader label",
140
+ renderIcon: icon,
141
+ renderTooltipContent: "This is tooltip content",
142
+ readOnly: true,
143
+ status: "pressed"
144
+ })));
145
+ const button = screen.getByRole('button');
146
+ expect(button).toHaveAttribute('disabled');
147
+ });
148
+ it('should pass the `onClick` prop', async () => {
149
+ const onClick = jest.fn();
150
+ render( /*#__PURE__*/React.createElement(ToggleButton, {
151
+ screenReaderLabel: "This is a screen reader label",
152
+ renderIcon: icon,
153
+ renderTooltipContent: "This is tooltip content",
154
+ onClick: onClick,
155
+ status: "pressed"
156
+ }));
157
+ const button = screen.getByRole('button');
158
+ await userEvent.click(button);
159
+ await waitFor(() => {
160
+ expect(onClick).toHaveBeenCalledTimes(1);
161
+ });
162
+ });
163
+ });