@instructure/ui-link 9.2.1-snapshot-9 → 9.2.1-snapshot-11

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.
@@ -0,0 +1,364 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+ var _react = _interopRequireDefault(require("react"));
5
+ var _userEvent = require("@testing-library/user-event");
6
+ var _react2 = require("@testing-library/react");
7
+ require("@testing-library/jest-dom");
8
+ var _vitest = require("vitest");
9
+ var _runAxeCheck = require("@instructure/ui-axe-check/lib/runAxeCheck.js");
10
+ var _index = require("../index");
11
+ var _Link, _Link2, _Link3, _svg, _TruncateText2, _svg2, _Link4, _Link5, _Link6, _Link7, _Link8, _Link9, _Link10, _Link11, _Link12, _Link13, _Link14, _Link15, _Link16, _Link17;
12
+ /*
13
+ * The MIT License (MIT)
14
+ *
15
+ * Copyright (c) 2015 - present Instructure, Inc.
16
+ *
17
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
18
+ * of this software and associated documentation files (the "Software"), to deal
19
+ * in the Software without restriction, including without limitation the rights
20
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
21
+ * copies of the Software, and to permit persons to whom the Software is
22
+ * furnished to do so, subject to the following conditions:
23
+ *
24
+ * The above copyright notice and this permission notice shall be included in all
25
+ * copies or substantial portions of the Software.
26
+ *
27
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
28
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
29
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
30
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
31
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
32
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
33
+ * SOFTWARE.
34
+ */
35
+ //<unknown> is needed for React 17 compatibility
36
+ class TruncateText extends _react.default.Component {
37
+ render() {
38
+ return /*#__PURE__*/_react.default.createElement("span", null, this.props.children);
39
+ }
40
+ }
41
+ TruncateText.displayName = "TruncateText";
42
+ describe('<Link />', () => {
43
+ let consoleErrorMock;
44
+ beforeEach(() => {
45
+ // Mocking console to prevent test output pollution
46
+ consoleErrorMock = _vitest.vi.spyOn(console, 'error').mockImplementation(() => {});
47
+ });
48
+ afterEach(() => {
49
+ consoleErrorMock.mockRestore();
50
+ });
51
+ it('should render the children as text content', async () => {
52
+ (0, _react2.render)(_Link || (_Link = /*#__PURE__*/_react.default.createElement(_index.Link, {
53
+ href: "https://instructure.design"
54
+ }, "Hello World")));
55
+ const link = _react2.screen.getByRole('link');
56
+ expect(link).toHaveTextContent('Hello World');
57
+ });
58
+ it('should render a button', async () => {
59
+ const onClick = _vitest.vi.fn();
60
+ (0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.Link, {
61
+ onClick: onClick
62
+ }, "Hello World"));
63
+ const button = _react2.screen.getByRole('button');
64
+ expect(button).toHaveAttribute('type', 'button');
65
+ });
66
+ it('should meet a11y standards', async () => {
67
+ const _render = (0, _react2.render)(_Link2 || (_Link2 = /*#__PURE__*/_react.default.createElement(_index.Link, {
68
+ href: "https://instructure.design"
69
+ }, "Hello World"))),
70
+ container = _render.container;
71
+ const axeCheck = await (0, _runAxeCheck.runAxeCheck)(container);
72
+ expect(axeCheck).toBe(true);
73
+ });
74
+ it('should focus with the focus helper', async () => {
75
+ let linkRef;
76
+ (0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.Link, {
77
+ href: "https://instructure.design",
78
+ elementRef: el => {
79
+ linkRef = el;
80
+ }
81
+ }, "Hello World"));
82
+ const linkElement = _react2.screen.getByRole('link');
83
+ linkRef.focus();
84
+ expect(linkElement).toHaveFocus();
85
+ });
86
+ it('should display block when TruncateText is a child', async () => {
87
+ (0, _react2.render)(_Link3 || (_Link3 = /*#__PURE__*/_react.default.createElement(_index.Link, {
88
+ href: "example.html"
89
+ }, /*#__PURE__*/_react.default.createElement(TruncateText, null, "Hello World"))));
90
+ const link = _react2.screen.getByRole('link');
91
+ expect(link).toHaveStyle('display: block');
92
+ });
93
+ it('should display inline-flex when TruncateText is a child and there is an icon', async () => {
94
+ const customIcon = _svg || (_svg = /*#__PURE__*/_react.default.createElement("svg", {
95
+ height: "24",
96
+ width: "24"
97
+ }, /*#__PURE__*/_react.default.createElement("title", null, "Custom icon"), /*#__PURE__*/_react.default.createElement("circle", {
98
+ cx: "50",
99
+ cy: "50",
100
+ r: "40"
101
+ })));
102
+ (0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.Link, {
103
+ href: "example.html",
104
+ renderIcon: customIcon
105
+ }, _TruncateText2 || (_TruncateText2 = /*#__PURE__*/_react.default.createElement(TruncateText, null, "Hello World"))));
106
+ const link = _react2.screen.getByRole('link');
107
+ expect(link).toHaveStyle('display: inline-flex');
108
+ });
109
+ it('should call the onClick prop when clicked', async () => {
110
+ const onClick = _vitest.vi.fn();
111
+ (0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.Link, {
112
+ onClick: onClick
113
+ }, "Hello World"));
114
+ const link = _react2.screen.getByRole('button');
115
+ _userEvent.userEvent.click(link);
116
+ await (0, _react2.waitFor)(() => {
117
+ expect(onClick).toHaveBeenCalledTimes(1);
118
+ });
119
+ });
120
+ it('should call the onMouseEnter prop when mouseEntered', async () => {
121
+ const onMouseEnter = _vitest.vi.fn();
122
+ const _render2 = (0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.Link, {
123
+ onMouseEnter: onMouseEnter
124
+ }, "Hello World")),
125
+ container = _render2.container;
126
+ const link = container.querySelector('span[class$="-link"]');
127
+ _userEvent.userEvent.hover(link);
128
+ await (0, _react2.waitFor)(() => {
129
+ expect(onMouseEnter).toHaveBeenCalledTimes(1);
130
+ });
131
+ });
132
+ it('should pass down an icon via the icon property', async () => {
133
+ const customIcon = _svg2 || (_svg2 = /*#__PURE__*/_react.default.createElement("svg", {
134
+ "data-testid": "svg",
135
+ height: "100",
136
+ width: "100"
137
+ }, /*#__PURE__*/_react.default.createElement("title", null, "Custom icon"), /*#__PURE__*/_react.default.createElement("circle", {
138
+ cx: "50",
139
+ cy: "50",
140
+ r: "40"
141
+ })));
142
+ (0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.Link, {
143
+ href: "https://instructure.design",
144
+ renderIcon: customIcon
145
+ }, "Hello World"));
146
+ const title = _react2.screen.getByText('Custom icon');
147
+ const icon = _react2.screen.getByTestId('svg');
148
+ expect(title).toBeInTheDocument();
149
+ expect(icon).toBeInTheDocument();
150
+ });
151
+ describe('when interaction is disabled', () => {
152
+ it('should apply aria-disabled when interaction is disabled', async () => {
153
+ (0, _react2.render)(_Link4 || (_Link4 = /*#__PURE__*/_react.default.createElement(_index.Link, {
154
+ href: "example.html",
155
+ interaction: "disabled"
156
+ }, "Hello World")));
157
+ const link = _react2.screen.getByRole('link');
158
+ expect(link).toHaveAttribute('aria-disabled');
159
+ });
160
+ });
161
+ it('should apply aria-disabled when `disabled` is set', async () => {
162
+ (0, _react2.render)(_Link5 || (_Link5 = /*#__PURE__*/_react.default.createElement(_index.Link, {
163
+ href: "example.html",
164
+ disabled: true
165
+ }, "Hello World")));
166
+ const link = _react2.screen.getByRole('link');
167
+ expect(link).toHaveAttribute('aria-disabled');
168
+ });
169
+ it('should not be clickable when interaction is disabled', async () => {
170
+ const onClick = _vitest.vi.fn();
171
+ (0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.Link, {
172
+ onClick: onClick,
173
+ interaction: "disabled"
174
+ }, "Hello World"));
175
+ const button = _react2.screen.getByRole('button');
176
+ expect(button).toHaveAttribute('aria-disabled', 'true');
177
+ });
178
+ it('should not be clickable when `disabled` is set', async () => {
179
+ const onClick = _vitest.vi.fn();
180
+ (0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.Link, {
181
+ onClick: onClick,
182
+ disabled: true
183
+ }, "Hello World"));
184
+ const button = _react2.screen.getByRole('button');
185
+ expect(button).toHaveAttribute('aria-disabled', 'true');
186
+ });
187
+ });
188
+ describe('with `as` prop', () => {
189
+ describe('with `onClick`', () => {
190
+ it('should render designated tag', async () => {
191
+ const onClick = _vitest.vi.fn();
192
+ (0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.Link, {
193
+ as: "a",
194
+ onClick: onClick
195
+ }, "Hello World"));
196
+ const link = _react2.screen.getByText('Hello World');
197
+ expect(link.tagName).toBe('A');
198
+ });
199
+ it('should set role="button"', async () => {
200
+ const onClick = _vitest.vi.fn();
201
+ (0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.Link, {
202
+ as: "span",
203
+ onClick: onClick
204
+ }, "Hello World"));
205
+ const spanLink = _react2.screen.getByRole('button');
206
+ expect(spanLink).toHaveAttribute('role', 'button');
207
+ });
208
+ });
209
+ describe('should not set type="button", unless it is actually a button', () => {
210
+ it('should not set type="button" on other things like <span>s', async () => {
211
+ const onClick = _vitest.vi.fn();
212
+ (0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.Link, {
213
+ as: "span",
214
+ onClick: onClick
215
+ }, "Hello World"));
216
+ const link = _react2.screen.getByText('Hello World');
217
+ expect(link).not.toHaveAttribute('type', 'button');
218
+ });
219
+ it('should set type="button" on <button>s', async () => {
220
+ const onClick = _vitest.vi.fn();
221
+ (0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.Link, {
222
+ as: "button",
223
+ onClick: onClick
224
+ }, "Hello World"));
225
+ const button = _react2.screen.getByText('Hello World');
226
+ expect(button).toHaveAttribute('type', 'button');
227
+ });
228
+ it('should set tabIndex="0"', async () => {
229
+ const onClick = _vitest.vi.fn();
230
+ (0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.Link, {
231
+ as: "span",
232
+ onClick: onClick
233
+ }, "Hello World"));
234
+ const spanLink = _react2.screen.getByText('Hello World');
235
+ expect(spanLink).toHaveAttribute('tabIndex', '0');
236
+ });
237
+ });
238
+ describe('without `onClick`', () => {
239
+ it('should render designated tag', async () => {
240
+ (0, _react2.render)(_Link6 || (_Link6 = /*#__PURE__*/_react.default.createElement(_index.Link, {
241
+ as: "a"
242
+ }, "Hello World")));
243
+ const link = _react2.screen.getByText('Hello World');
244
+ expect(link.tagName).toBe('A');
245
+ });
246
+ it('should not set role="button"', async () => {
247
+ (0, _react2.render)(_Link7 || (_Link7 = /*#__PURE__*/_react.default.createElement(_index.Link, {
248
+ as: "span"
249
+ }, "Hello World")));
250
+ const link = _react2.screen.getByText('Hello World');
251
+ expect(link).not.toHaveAttribute('role', 'button');
252
+ });
253
+ it('should not set type="button"', async () => {
254
+ (0, _react2.render)(_Link8 || (_Link8 = /*#__PURE__*/_react.default.createElement(_index.Link, {
255
+ as: "span"
256
+ }, "Hello World")));
257
+ const link = _react2.screen.getByText('Hello World');
258
+ expect(link).not.toHaveAttribute('type', 'button');
259
+ });
260
+ it('should not set tabIndex="0"', async () => {
261
+ (0, _react2.render)(_Link9 || (_Link9 = /*#__PURE__*/_react.default.createElement(_index.Link, {
262
+ as: "span"
263
+ }, "Hello World")));
264
+ const link = _react2.screen.getByText('Hello World');
265
+ expect(link).not.toHaveAttribute('tabIndex', '0');
266
+ });
267
+ });
268
+ describe('when an href is provided', () => {
269
+ it('should render an anchor element', async () => {
270
+ (0, _react2.render)(_Link10 || (_Link10 = /*#__PURE__*/_react.default.createElement(_index.Link, {
271
+ href: "example.html"
272
+ }, "Hello World")));
273
+ const link = _react2.screen.getByRole('link');
274
+ expect(link.tagName).toBe('A');
275
+ });
276
+ it('should set the href attribute', async () => {
277
+ (0, _react2.render)(_Link11 || (_Link11 = /*#__PURE__*/_react.default.createElement(_index.Link, {
278
+ href: "example.html"
279
+ }, "Hello World")));
280
+ const link = _react2.screen.getByRole('link');
281
+ expect(link).toHaveAttribute('href', 'example.html');
282
+ });
283
+ it('should not set role="button"', async () => {
284
+ (0, _react2.render)(_Link12 || (_Link12 = /*#__PURE__*/_react.default.createElement(_index.Link, {
285
+ href: "example.html"
286
+ }, "Hello World")));
287
+ const link = _react2.screen.getByRole('link');
288
+ expect(link).not.toHaveAttribute('role', 'button');
289
+ });
290
+ it('should not set type="button"', async () => {
291
+ (0, _react2.render)(_Link13 || (_Link13 = /*#__PURE__*/_react.default.createElement(_index.Link, {
292
+ href: "example.html"
293
+ }, "Hello World")));
294
+ const link = _react2.screen.getByRole('link');
295
+ expect(link).not.toHaveAttribute('type', 'button');
296
+ });
297
+ });
298
+ describe('when a `role` is provided', () => {
299
+ it('should set role', async () => {
300
+ (0, _react2.render)(_Link14 || (_Link14 = /*#__PURE__*/_react.default.createElement(_index.Link, {
301
+ href: "example.html",
302
+ role: "button"
303
+ }, "Hello World")));
304
+ const link = _react2.screen.getByText('Hello World');
305
+ expect(link).toHaveAttribute('role', 'button');
306
+ });
307
+ it('should not override button role when it is forced by default', async () => {
308
+ const onClick = _vitest.vi.fn();
309
+ (0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.Link, {
310
+ role: "link",
311
+ onClick: onClick,
312
+ as: "a"
313
+ }, "Hello World"));
314
+ const link = _react2.screen.getByText('Hello World');
315
+ expect(link).toHaveAttribute('role', 'button');
316
+ });
317
+ });
318
+ describe('when a `forceButtonRole` is set to false', () => {
319
+ it('should not force button role', async () => {
320
+ const onClick = _vitest.vi.fn();
321
+ (0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.Link, {
322
+ onClick: onClick,
323
+ as: "a",
324
+ forceButtonRole: false
325
+ }, "Hello World"));
326
+ const link = _react2.screen.getByText('Hello World');
327
+ expect(link).not.toHaveAttribute('role');
328
+ });
329
+ it('should override button role with `role` prop', async () => {
330
+ const onClick = _vitest.vi.fn();
331
+ (0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.Link, {
332
+ role: "link",
333
+ onClick: onClick,
334
+ as: "a",
335
+ forceButtonRole: false
336
+ }, "Hello World"));
337
+ const link = _react2.screen.getByText('Hello World');
338
+ expect(link).toHaveAttribute('role', 'link');
339
+ });
340
+ });
341
+ describe('when a `to` is provided', () => {
342
+ it('should render an anchor element', async () => {
343
+ (0, _react2.render)(_Link15 || (_Link15 = /*#__PURE__*/_react.default.createElement(_index.Link, {
344
+ to: "/example"
345
+ }, "Hello World")));
346
+ const link = _react2.screen.getByText('Hello World');
347
+ expect(link.tagName).toBe('A');
348
+ });
349
+ it('should set the to attribute', async () => {
350
+ (0, _react2.render)(_Link16 || (_Link16 = /*#__PURE__*/_react.default.createElement(_index.Link, {
351
+ to: "/example"
352
+ }, "Hello World")));
353
+ const link = _react2.screen.getByText('Hello World');
354
+ expect(link).toHaveAttribute('to', '/example');
355
+ });
356
+ it('should not set role="button"', async () => {
357
+ (0, _react2.render)(_Link17 || (_Link17 = /*#__PURE__*/_react.default.createElement(_index.Link, {
358
+ to: "/example"
359
+ }, "Hello World")));
360
+ const link = _react2.screen.getByText('Hello World');
361
+ expect(link).not.toHaveAttribute('role', 'button');
362
+ });
363
+ });
364
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@instructure/ui-link",
3
- "version": "9.2.1-snapshot-9",
3
+ "version": "9.2.1-snapshot-11",
4
4
  "description": "A component for creating links",
5
5
  "author": "Instructure, Inc. Engineering and Product Design",
6
6
  "module": "./es/index.js",
@@ -24,25 +24,28 @@
24
24
  "license": "MIT",
25
25
  "dependencies": {
26
26
  "@babel/runtime": "^7.24.5",
27
- "@instructure/console": "9.2.1-snapshot-9",
28
- "@instructure/emotion": "9.2.1-snapshot-9",
29
- "@instructure/shared-types": "9.2.1-snapshot-9",
30
- "@instructure/ui-a11y-utils": "9.2.1-snapshot-9",
31
- "@instructure/ui-color-utils": "9.2.1-snapshot-9",
32
- "@instructure/ui-dom-utils": "9.2.1-snapshot-9",
33
- "@instructure/ui-icons": "9.2.1-snapshot-9",
34
- "@instructure/ui-prop-types": "9.2.1-snapshot-9",
35
- "@instructure/ui-react-utils": "9.2.1-snapshot-9",
36
- "@instructure/ui-testable": "9.2.1-snapshot-9",
37
- "@instructure/ui-view": "9.2.1-snapshot-9",
27
+ "@instructure/console": "9.2.1-snapshot-11",
28
+ "@instructure/emotion": "9.2.1-snapshot-11",
29
+ "@instructure/shared-types": "9.2.1-snapshot-11",
30
+ "@instructure/ui-a11y-utils": "9.2.1-snapshot-11",
31
+ "@instructure/ui-color-utils": "9.2.1-snapshot-11",
32
+ "@instructure/ui-dom-utils": "9.2.1-snapshot-11",
33
+ "@instructure/ui-icons": "9.2.1-snapshot-11",
34
+ "@instructure/ui-prop-types": "9.2.1-snapshot-11",
35
+ "@instructure/ui-react-utils": "9.2.1-snapshot-11",
36
+ "@instructure/ui-testable": "9.2.1-snapshot-11",
37
+ "@instructure/ui-view": "9.2.1-snapshot-11",
38
38
  "prop-types": "^15.8.1"
39
39
  },
40
40
  "devDependencies": {
41
- "@instructure/ui-babel-preset": "9.2.1-snapshot-9",
42
- "@instructure/ui-test-locator": "9.2.1-snapshot-9",
43
- "@instructure/ui-test-queries": "9.2.1-snapshot-9",
44
- "@instructure/ui-test-utils": "9.2.1-snapshot-9",
45
- "@instructure/ui-themes": "9.2.1-snapshot-9"
41
+ "@instructure/ui-axe-check": "9.2.1-snapshot-11",
42
+ "@instructure/ui-babel-preset": "9.2.1-snapshot-11",
43
+ "@instructure/ui-test-utils": "9.2.1-snapshot-11",
44
+ "@instructure/ui-themes": "9.2.1-snapshot-11",
45
+ "@testing-library/jest-dom": "^6.4.5",
46
+ "@testing-library/react": "^15.0.7",
47
+ "@testing-library/user-event": "^14.5.2",
48
+ "vitest": "^1.6.0"
46
49
  },
47
50
  "peerDependencies": {
48
51
  "react": ">=16.8 <=18"