@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,183 @@
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 _circle, _CondensedButton, _CondensedButton2, _CondensedButton3, _CondensedButton4, _CondensedButton5, _CondensedButton6, _CondensedButton7;
10
+ /*
11
+ * The MIT License (MIT)
12
+ *
13
+ * Copyright (c) 2015 - present Instructure, Inc.
14
+ *
15
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
16
+ * of this software and associated documentation files (the "Software"), to deal
17
+ * in the Software without restriction, including without limitation the rights
18
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
19
+ * copies of the Software, and to permit persons to whom the Software is
20
+ * furnished to do so, subject to the following conditions:
21
+ *
22
+ * The above copyright notice and this permission notice shall be included in all
23
+ * copies or substantial portions of the Software.
24
+ *
25
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
26
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
27
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
28
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
29
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
30
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
31
+ * SOFTWARE.
32
+ */
33
+ describe('<CondensedButton/>', () => {
34
+ var _CondensedButton8;
35
+ const icon = /*#__PURE__*/_react.default.createElement("svg", {
36
+ "data-title": "myIcon",
37
+ height: "1em",
38
+ width: "1em",
39
+ style: {
40
+ fill: 'currentcolor'
41
+ }
42
+ }, _circle || (_circle = /*#__PURE__*/_react.default.createElement("circle", {
43
+ cx: "0.5em",
44
+ cy: "0.5em",
45
+ r: "0.5em"
46
+ })));
47
+ const iconSelector = 'svg[data-title="myIcon"]';
48
+ it('should render children', () => {
49
+ const children = 'Hello world';
50
+ (0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.CondensedButton, null, children));
51
+ const button = document.querySelector('button');
52
+ expect(button).toBeInTheDocument();
53
+ expect(button).toHaveTextContent(children);
54
+ });
55
+ it('should provide a focused getter', () => {
56
+ var _componentRef;
57
+ let componentRef;
58
+ (0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.CondensedButton, {
59
+ ref: component => {
60
+ componentRef = component;
61
+ }
62
+ }, "Hello"));
63
+ const button = _react2.screen.getByRole('button', {
64
+ name: 'Hello'
65
+ });
66
+ button.focus();
67
+ expect((_componentRef = componentRef) === null || _componentRef === void 0 ? void 0 : _componentRef.focused).toBe(true);
68
+ });
69
+ it('should provide a focus function', () => {
70
+ var _componentRef2;
71
+ let componentRef;
72
+ (0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.CondensedButton, {
73
+ ref: component => {
74
+ componentRef = component;
75
+ }
76
+ }, "Hello"));
77
+ const button = _react2.screen.getByRole('button', {
78
+ name: 'Hello'
79
+ });
80
+ (_componentRef2 = componentRef) === null || _componentRef2 === void 0 ? void 0 : _componentRef2.focus();
81
+ expect(document.activeElement).toBe(button);
82
+ });
83
+ it('should pass the type attribute', () => {
84
+ (0, _react2.render)(_CondensedButton || (_CondensedButton = /*#__PURE__*/_react.default.createElement(_index.CondensedButton, {
85
+ type: "submit"
86
+ }, "Hello")));
87
+ const button = _react2.screen.getByRole('button', {
88
+ name: 'Hello'
89
+ });
90
+ expect(button).toBeInTheDocument();
91
+ expect(button).toHaveAttribute('type', 'submit');
92
+ });
93
+ it('should pass the `elementRef` prop', async () => {
94
+ const elementRef = jest.fn();
95
+ (0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.CondensedButton, {
96
+ elementRef: elementRef
97
+ }, "Hello"));
98
+ const button = _react2.screen.getByRole('button', {
99
+ name: 'Hello'
100
+ });
101
+ expect(elementRef).toHaveBeenCalledWith(button);
102
+ });
103
+ it('should pass the `as` prop', () => {
104
+ const _render = (0, _react2.render)(_CondensedButton2 || (_CondensedButton2 = /*#__PURE__*/_react.default.createElement(_index.CondensedButton, {
105
+ as: "li"
106
+ }, "Hello"))),
107
+ container = _render.container;
108
+ const button = container.querySelector('[type="button"]');
109
+ expect(button).toBeInTheDocument();
110
+ expect(button).toHaveTextContent('Hello');
111
+ expect(button.tagName).toBe('LI');
112
+ });
113
+ it('should set the disabled attribute when `interaction` is set to disabled', () => {
114
+ (0, _react2.render)(_CondensedButton3 || (_CondensedButton3 = /*#__PURE__*/_react.default.createElement(_index.CondensedButton, {
115
+ interaction: "disabled"
116
+ }, "Hello")));
117
+ const button = _react2.screen.getByRole('button', {
118
+ name: 'Hello'
119
+ });
120
+ expect(button).toHaveAttribute('disabled');
121
+ });
122
+ it('should set the disabled attribute when `disabled` is set', () => {
123
+ (0, _react2.render)(_CondensedButton4 || (_CondensedButton4 = /*#__PURE__*/_react.default.createElement(_index.CondensedButton, {
124
+ disabled: true
125
+ }, "Hello")));
126
+ const button = _react2.screen.getByRole('button', {
127
+ name: 'Hello'
128
+ });
129
+ expect(button).toHaveAttribute('disabled');
130
+ });
131
+ it('should set the disabled attribute when `interaction` is set to readonly', () => {
132
+ (0, _react2.render)(_CondensedButton5 || (_CondensedButton5 = /*#__PURE__*/_react.default.createElement(_index.CondensedButton, {
133
+ interaction: "readonly"
134
+ }, "Hello")));
135
+ const button = _react2.screen.getByRole('button', {
136
+ name: 'Hello'
137
+ });
138
+ expect(button).toHaveAttribute('disabled');
139
+ });
140
+ it('should set the disabled attribute when `readOnly` is set', () => {
141
+ (0, _react2.render)(_CondensedButton6 || (_CondensedButton6 = /*#__PURE__*/_react.default.createElement(_index.CondensedButton, {
142
+ readOnly: true
143
+ }, "Hello")));
144
+ const button = _react2.screen.getByRole('button', {
145
+ name: 'Hello'
146
+ });
147
+ expect(button).toHaveAttribute('disabled');
148
+ });
149
+ it('should pass the `href` prop', () => {
150
+ (0, _react2.render)(_CondensedButton7 || (_CondensedButton7 = /*#__PURE__*/_react.default.createElement(_index.CondensedButton, {
151
+ href: "#"
152
+ }, "Hello")));
153
+ const linkButton = _react2.screen.getByRole('link', {
154
+ name: 'Hello'
155
+ });
156
+ expect(linkButton).toBeInTheDocument();
157
+ expect(linkButton).toHaveAttribute('href', '#');
158
+ });
159
+ it('should pass the `renderIcon` prop', async () => {
160
+ (0, _react2.render)(_CondensedButton8 || (_CondensedButton8 = /*#__PURE__*/_react.default.createElement(_index.CondensedButton, {
161
+ renderIcon: icon
162
+ }, "Hello")));
163
+ const svgIcon = document.querySelector(iconSelector);
164
+ const button = _react2.screen.getByRole('button', {
165
+ name: 'Hello'
166
+ });
167
+ expect(button).toBeInTheDocument();
168
+ expect(svgIcon).toBeInTheDocument();
169
+ });
170
+ it('should pass the `onClick` prop', async () => {
171
+ const onClick = jest.fn();
172
+ (0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.CondensedButton, {
173
+ onClick: onClick
174
+ }, "Hello"));
175
+ const button = _react2.screen.getByRole('button', {
176
+ name: 'Hello'
177
+ });
178
+ await _userEvent.default.click(button);
179
+ await (0, _react2.waitFor)(() => {
180
+ expect(onClick).toHaveBeenCalledTimes(1);
181
+ });
182
+ });
183
+ });
@@ -0,0 +1,187 @@
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 _circle;
10
+ /*
11
+ * The MIT License (MIT)
12
+ *
13
+ * Copyright (c) 2015 - present Instructure, Inc.
14
+ *
15
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
16
+ * of this software and associated documentation files (the "Software"), to deal
17
+ * in the Software without restriction, including without limitation the rights
18
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
19
+ * copies of the Software, and to permit persons to whom the Software is
20
+ * furnished to do so, subject to the following conditions:
21
+ *
22
+ * The above copyright notice and this permission notice shall be included in all
23
+ * copies or substantial portions of the Software.
24
+ *
25
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
26
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
27
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
28
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
29
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
30
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
31
+ * SOFTWARE.
32
+ */
33
+ describe('<IconButton/>', () => {
34
+ var _IconButton, _IconButton2, _IconButton3, _IconButton4, _IconButton5, _IconButton6, _IconButton7, _IconButton8, _IconButton9;
35
+ const icon = /*#__PURE__*/_react.default.createElement("svg", {
36
+ "data-title": "myIcon",
37
+ height: "1em",
38
+ width: "1em",
39
+ style: {
40
+ fill: 'currentcolor'
41
+ }
42
+ }, _circle || (_circle = /*#__PURE__*/_react.default.createElement("circle", {
43
+ cx: "0.5em",
44
+ cy: "0.5em",
45
+ r: "0.5em"
46
+ })));
47
+ const iconSelector = 'svg[data-title="myIcon"]';
48
+ it('should render an icon when provided as the `children` prop', () => {
49
+ (0, _react2.render)(_IconButton || (_IconButton = /*#__PURE__*/_react.default.createElement(_index.IconButton, {
50
+ screenReaderLabel: "some action"
51
+ }, icon)));
52
+ const svgIcon = document.querySelector(iconSelector);
53
+ const button = _react2.screen.getByRole('button');
54
+ expect(button).toBeInTheDocument();
55
+ expect(svgIcon).toBeInTheDocument();
56
+ expect(button).toHaveTextContent('some action');
57
+ });
58
+ it('should render an icon when provided as the `renderIcon` prop', () => {
59
+ (0, _react2.render)(_IconButton2 || (_IconButton2 = /*#__PURE__*/_react.default.createElement(_index.IconButton, {
60
+ screenReaderLabel: "some action",
61
+ renderIcon: icon
62
+ })));
63
+ const svgIcon = document.querySelector(iconSelector);
64
+ const button = _react2.screen.getByRole('button');
65
+ expect(button).toBeInTheDocument();
66
+ expect(svgIcon).toBeInTheDocument();
67
+ });
68
+ it('should provide a focused getter', () => {
69
+ var _componentRef;
70
+ let componentRef;
71
+ (0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.IconButton, {
72
+ screenReaderLabel: "some action",
73
+ renderIcon: icon,
74
+ ref: component => {
75
+ componentRef = component;
76
+ }
77
+ }));
78
+ const button = _react2.screen.getByRole('button');
79
+ button.focus();
80
+ expect((_componentRef = componentRef) === null || _componentRef === void 0 ? void 0 : _componentRef.focused).toBe(true);
81
+ });
82
+ it('should provide a focus function', () => {
83
+ var _componentRef2;
84
+ let componentRef;
85
+ (0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.IconButton, {
86
+ screenReaderLabel: "some action",
87
+ renderIcon: icon,
88
+ ref: component => {
89
+ componentRef = component;
90
+ }
91
+ }));
92
+ const button = _react2.screen.getByRole('button');
93
+ (_componentRef2 = componentRef) === null || _componentRef2 === void 0 ? void 0 : _componentRef2.focus();
94
+ expect(document.activeElement).toBe(button);
95
+ });
96
+ it('should pass the `href` prop', () => {
97
+ (0, _react2.render)(_IconButton3 || (_IconButton3 = /*#__PURE__*/_react.default.createElement(_index.IconButton, {
98
+ screenReaderLabel: "some action",
99
+ renderIcon: icon,
100
+ href: "#"
101
+ })));
102
+ const linkButton = _react2.screen.getByRole('link');
103
+ expect(linkButton).toBeInTheDocument();
104
+ expect(linkButton).toHaveAttribute('href', '#');
105
+ });
106
+ it('should pass the `type` prop', () => {
107
+ (0, _react2.render)(_IconButton4 || (_IconButton4 = /*#__PURE__*/_react.default.createElement(_index.IconButton, {
108
+ screenReaderLabel: "some action",
109
+ renderIcon: icon,
110
+ type: "reset"
111
+ })));
112
+ const button = _react2.screen.getByRole('button');
113
+ expect(button).toBeInTheDocument();
114
+ expect(button).toHaveAttribute('type', 'reset');
115
+ });
116
+ it('should pass the `elementRef` prop', () => {
117
+ const elementRef = jest.fn();
118
+ (0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.IconButton, {
119
+ screenReaderLabel: "some action",
120
+ renderIcon: icon,
121
+ elementRef: elementRef
122
+ }));
123
+ const button = _react2.screen.getByRole('button');
124
+ expect(elementRef).toHaveBeenCalledWith(button);
125
+ });
126
+ it('should pass the `as` prop', () => {
127
+ const _render = (0, _react2.render)(_IconButton5 || (_IconButton5 = /*#__PURE__*/_react.default.createElement(_index.IconButton, {
128
+ screenReaderLabel: "some action",
129
+ renderIcon: icon,
130
+ as: "li"
131
+ }))),
132
+ container = _render.container;
133
+ const button = container.querySelector('[type="button"]');
134
+ expect(button).toBeInTheDocument();
135
+ expect(button).toHaveTextContent('some action');
136
+ expect(button.tagName).toBe('LI');
137
+ });
138
+ it('should set the disabled attribute when `interaction` is set to disabled', () => {
139
+ (0, _react2.render)(_IconButton6 || (_IconButton6 = /*#__PURE__*/_react.default.createElement(_index.IconButton, {
140
+ screenReaderLabel: "some action",
141
+ renderIcon: icon,
142
+ interaction: "disabled"
143
+ })));
144
+ const button = _react2.screen.getByRole('button');
145
+ expect(button).toHaveAttribute('disabled');
146
+ });
147
+ it('should set the disabled attribute when `disabled` is set', () => {
148
+ (0, _react2.render)(_IconButton7 || (_IconButton7 = /*#__PURE__*/_react.default.createElement(_index.IconButton, {
149
+ screenReaderLabel: "some action",
150
+ renderIcon: icon,
151
+ disabled: true
152
+ })));
153
+ const button = _react2.screen.getByRole('button');
154
+ expect(button).toHaveAttribute('disabled');
155
+ });
156
+ it('should set the disabled attribute when `interaction` is set to readonly', () => {
157
+ (0, _react2.render)(_IconButton8 || (_IconButton8 = /*#__PURE__*/_react.default.createElement(_index.IconButton, {
158
+ screenReaderLabel: "some action",
159
+ renderIcon: icon,
160
+ interaction: "readonly"
161
+ })));
162
+ const button = _react2.screen.getByRole('button');
163
+ expect(button).toHaveAttribute('disabled');
164
+ });
165
+ it('should set the disabled attribute when `readOnly` is set', () => {
166
+ (0, _react2.render)(_IconButton9 || (_IconButton9 = /*#__PURE__*/_react.default.createElement(_index.IconButton, {
167
+ screenReaderLabel: "some action",
168
+ renderIcon: icon,
169
+ readOnly: true
170
+ })));
171
+ const button = _react2.screen.getByRole('button');
172
+ expect(button).toHaveAttribute('disabled');
173
+ });
174
+ it('should pass the `onClick` prop', async () => {
175
+ const onClick = jest.fn();
176
+ (0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.IconButton, {
177
+ screenReaderLabel: "some action",
178
+ renderIcon: icon,
179
+ onClick: onClick
180
+ }));
181
+ const button = _react2.screen.getByRole('button');
182
+ await _userEvent.default.click(button);
183
+ await (0, _react2.waitFor)(() => {
184
+ expect(onClick).toHaveBeenCalledTimes(1);
185
+ });
186
+ });
187
+ });
@@ -0,0 +1,165 @@
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 _svg;
10
+ /*
11
+ * The MIT License (MIT)
12
+ *
13
+ * Copyright (c) 2015 - present Instructure, Inc.
14
+ *
15
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
16
+ * of this software and associated documentation files (the "Software"), to deal
17
+ * in the Software without restriction, including without limitation the rights
18
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
19
+ * copies of the Software, and to permit persons to whom the Software is
20
+ * furnished to do so, subject to the following conditions:
21
+ *
22
+ * The above copyright notice and this permission notice shall be included in all
23
+ * copies or substantial portions of the Software.
24
+ *
25
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
26
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
27
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
28
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
29
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
30
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
31
+ * SOFTWARE.
32
+ */
33
+ describe('<ToggleButton />', () => {
34
+ var _ToggleButton, _ToggleButton2, _ToggleButton3, _ToggleButton4, _ToggleButton5, _ToggleButton6, _ToggleButton7, _ToggleButton8, _ToggleButton9;
35
+ const icon = _svg || (_svg = /*#__PURE__*/_react.default.createElement("svg", {
36
+ "data-title": "myIcon",
37
+ height: "1em",
38
+ width: "1em"
39
+ }, /*#__PURE__*/_react.default.createElement("circle", {
40
+ cx: "0.5em",
41
+ cy: "0.5em",
42
+ r: "0.5em"
43
+ })));
44
+ const iconSelector = 'svg[data-title="myIcon"]';
45
+ it('should render', () => {
46
+ (0, _react2.render)(_ToggleButton || (_ToggleButton = /*#__PURE__*/_react.default.createElement(_index.ToggleButton, {
47
+ screenReaderLabel: "This is a screen reader label",
48
+ renderIcon: icon,
49
+ renderTooltipContent: "This is tooltip content",
50
+ status: "pressed"
51
+ })));
52
+ const button = _react2.screen.getByRole('button');
53
+ const svgIcon = document.querySelector(iconSelector);
54
+ const tooltip = _react2.screen.getByRole('tooltip');
55
+ expect(button).toBeInTheDocument();
56
+ expect(button).toHaveTextContent('This is a screen reader label');
57
+ expect(svgIcon).toBeInTheDocument();
58
+ expect(tooltip).toBeInTheDocument();
59
+ expect(tooltip).toHaveTextContent('This is tooltip content');
60
+ });
61
+ it('should set `aria-pressed` to `true` if `status` is `pressed`', () => {
62
+ (0, _react2.render)(_ToggleButton2 || (_ToggleButton2 = /*#__PURE__*/_react.default.createElement(_index.ToggleButton, {
63
+ screenReaderLabel: "This is a screen reader label",
64
+ renderIcon: icon,
65
+ renderTooltipContent: "This is tooltip content",
66
+ status: "pressed"
67
+ })));
68
+ const button = _react2.screen.getByRole('button');
69
+ expect(button).toHaveAttribute('aria-pressed', 'true');
70
+ });
71
+ it('should set `aria-pressed` to `false` if `status` is `unpressed`', () => {
72
+ (0, _react2.render)(_ToggleButton3 || (_ToggleButton3 = /*#__PURE__*/_react.default.createElement(_index.ToggleButton, {
73
+ screenReaderLabel: "This is a screen reader label",
74
+ renderIcon: icon,
75
+ renderTooltipContent: "This is tooltip content",
76
+ status: "unpressed"
77
+ })));
78
+ const button = _react2.screen.getByRole('button');
79
+ expect(button).toHaveAttribute('aria-pressed', 'false');
80
+ });
81
+ it('should render an icon', () => {
82
+ (0, _react2.render)(_ToggleButton4 || (_ToggleButton4 = /*#__PURE__*/_react.default.createElement(_index.ToggleButton, {
83
+ screenReaderLabel: "This is a screen reader label",
84
+ renderIcon: icon,
85
+ renderTooltipContent: "This is tooltip content",
86
+ status: "pressed"
87
+ })));
88
+ const button = _react2.screen.getByRole('button');
89
+ const svgIcon = document.querySelector(iconSelector);
90
+ expect(button).toBeInTheDocument();
91
+ expect(svgIcon).toBeInTheDocument();
92
+ });
93
+ it('should pass the `as` prop', () => {
94
+ const _render = (0, _react2.render)(_ToggleButton5 || (_ToggleButton5 = /*#__PURE__*/_react.default.createElement(_index.ToggleButton, {
95
+ screenReaderLabel: "This is a screen reader label",
96
+ renderIcon: icon,
97
+ renderTooltipContent: "This is tooltip content",
98
+ as: "li",
99
+ status: "pressed"
100
+ }))),
101
+ container = _render.container;
102
+ const button = container.querySelector('[type="button"]');
103
+ expect(button).toBeInTheDocument();
104
+ expect(button.tagName).toBe('LI');
105
+ });
106
+ it('should set the disabled attribute when `interaction` prop is set to disabled', () => {
107
+ (0, _react2.render)(_ToggleButton6 || (_ToggleButton6 = /*#__PURE__*/_react.default.createElement(_index.ToggleButton, {
108
+ screenReaderLabel: "This is a screen reader label",
109
+ renderIcon: icon,
110
+ renderTooltipContent: "This is tooltip content",
111
+ interaction: "disabled",
112
+ status: "pressed"
113
+ })));
114
+ const button = _react2.screen.getByRole('button');
115
+ expect(button).toHaveAttribute('disabled');
116
+ });
117
+ it('should set the disabled attribute when `disabled` prop is set', () => {
118
+ (0, _react2.render)(_ToggleButton7 || (_ToggleButton7 = /*#__PURE__*/_react.default.createElement(_index.ToggleButton, {
119
+ screenReaderLabel: "This is a screen reader label",
120
+ renderIcon: icon,
121
+ renderTooltipContent: "This is tooltip content",
122
+ disabled: true,
123
+ status: "pressed"
124
+ })));
125
+ const button = _react2.screen.getByRole('button');
126
+ expect(button).toHaveAttribute('disabled');
127
+ });
128
+ it('should set the disabled attribute when `interaction` prop is set to readonly', () => {
129
+ (0, _react2.render)(_ToggleButton8 || (_ToggleButton8 = /*#__PURE__*/_react.default.createElement(_index.ToggleButton, {
130
+ screenReaderLabel: "This is a screen reader label",
131
+ renderIcon: icon,
132
+ renderTooltipContent: "This is tooltip content",
133
+ interaction: "readonly",
134
+ status: "pressed"
135
+ })));
136
+ const button = _react2.screen.getByRole('button');
137
+ expect(button).toHaveAttribute('disabled');
138
+ });
139
+ it('should set the disabled attribute when `readOnly` prop is set', () => {
140
+ (0, _react2.render)(_ToggleButton9 || (_ToggleButton9 = /*#__PURE__*/_react.default.createElement(_index.ToggleButton, {
141
+ screenReaderLabel: "This is a screen reader label",
142
+ renderIcon: icon,
143
+ renderTooltipContent: "This is tooltip content",
144
+ readOnly: true,
145
+ status: "pressed"
146
+ })));
147
+ const button = _react2.screen.getByRole('button');
148
+ expect(button).toHaveAttribute('disabled');
149
+ });
150
+ it('should pass the `onClick` prop', async () => {
151
+ const onClick = jest.fn();
152
+ (0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.ToggleButton, {
153
+ screenReaderLabel: "This is a screen reader label",
154
+ renderIcon: icon,
155
+ renderTooltipContent: "This is tooltip content",
156
+ onClick: onClick,
157
+ status: "pressed"
158
+ }));
159
+ const button = _react2.screen.getByRole('button');
160
+ await _userEvent.default.click(button);
161
+ await (0, _react2.waitFor)(() => {
162
+ expect(onClick).toHaveBeenCalledTimes(1);
163
+ });
164
+ });
165
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@instructure/ui-buttons",
3
- "version": "8.55.0",
3
+ "version": "8.55.1-snapshot-3",
4
4
  "description": "Accessible button components",
5
5
  "author": "Instructure, Inc. Engineering and Product Design",
6
6
  "module": "./es/index.js",
@@ -23,28 +23,30 @@
23
23
  },
24
24
  "license": "MIT",
25
25
  "devDependencies": {
26
- "@instructure/ui-babel-preset": "8.55.0",
27
- "@instructure/ui-test-locator": "8.55.0",
28
- "@instructure/ui-test-queries": "8.55.0",
29
- "@instructure/ui-test-utils": "8.55.0",
30
- "@instructure/ui-themes": "8.55.0"
26
+ "@instructure/ui-axe-check": "8.55.1-snapshot-3",
27
+ "@instructure/ui-babel-preset": "8.55.1-snapshot-3",
28
+ "@instructure/ui-test-utils": "8.55.1-snapshot-3",
29
+ "@instructure/ui-themes": "8.55.1-snapshot-3",
30
+ "@testing-library/jest-dom": "^6.1.4",
31
+ "@testing-library/react": "^14.1.2",
32
+ "@testing-library/user-event": "^14.5.1"
31
33
  },
32
34
  "dependencies": {
33
35
  "@babel/runtime": "^7.23.2",
34
- "@instructure/console": "8.55.0",
35
- "@instructure/emotion": "8.55.0",
36
- "@instructure/shared-types": "8.55.0",
37
- "@instructure/ui-a11y-content": "8.55.0",
38
- "@instructure/ui-a11y-utils": "8.55.0",
39
- "@instructure/ui-color-utils": "8.55.0",
40
- "@instructure/ui-dom-utils": "8.55.0",
41
- "@instructure/ui-icons": "8.55.0",
42
- "@instructure/ui-position": "8.55.0",
43
- "@instructure/ui-react-utils": "8.55.0",
44
- "@instructure/ui-testable": "8.55.0",
45
- "@instructure/ui-tooltip": "8.55.0",
46
- "@instructure/ui-utils": "8.55.0",
47
- "@instructure/ui-view": "8.55.0",
36
+ "@instructure/console": "8.55.1-snapshot-3",
37
+ "@instructure/emotion": "8.55.1-snapshot-3",
38
+ "@instructure/shared-types": "8.55.1-snapshot-3",
39
+ "@instructure/ui-a11y-content": "8.55.1-snapshot-3",
40
+ "@instructure/ui-a11y-utils": "8.55.1-snapshot-3",
41
+ "@instructure/ui-color-utils": "8.55.1-snapshot-3",
42
+ "@instructure/ui-dom-utils": "8.55.1-snapshot-3",
43
+ "@instructure/ui-icons": "8.55.1-snapshot-3",
44
+ "@instructure/ui-position": "8.55.1-snapshot-3",
45
+ "@instructure/ui-react-utils": "8.55.1-snapshot-3",
46
+ "@instructure/ui-testable": "8.55.1-snapshot-3",
47
+ "@instructure/ui-tooltip": "8.55.1-snapshot-3",
48
+ "@instructure/ui-utils": "8.55.1-snapshot-3",
49
+ "@instructure/ui-view": "8.55.1-snapshot-3",
48
50
  "keycode": "^2.2.1",
49
51
  "prop-types": "^15.8.1"
50
52
  },