@instructure/ui-breadcrumb 10.19.2-snapshot-2 → 10.19.2-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.
@@ -1,127 +0,0 @@
1
- var _BreadcrumbLink, _BreadcrumbLink2, _BreadcrumbLink3, _BreadcrumbLink4, _BreadcrumbLink5, _BreadcrumbLink6;
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 { fireEvent, render, screen } from '@testing-library/react';
27
- import { vi } from 'vitest';
28
- import '@testing-library/jest-dom';
29
- import { runAxeCheck } from '@instructure/ui-axe-check';
30
- import { BreadcrumbLink } from '../index';
31
- import { jsx as _jsx } from "@emotion/react/jsx-runtime";
32
- const TEST_TEXT_01 = 'Account';
33
- const TEST_LINK = 'http://instructure-test.com';
34
- const TEST_TO = '/example';
35
- describe('<BreadcrumbLink />', () => {
36
- let consoleWarningMock;
37
- let consoleErrorMock;
38
- beforeEach(() => {
39
- // Mocking console to prevent test output pollution
40
- consoleWarningMock = vi.spyOn(console, 'warn').mockImplementation(() => {});
41
- consoleErrorMock = vi.spyOn(console, 'error').mockImplementation(() => {});
42
- });
43
- afterEach(() => {
44
- consoleWarningMock.mockRestore();
45
- consoleErrorMock.mockRestore();
46
- });
47
- it('should render an anchor tag when given a href prop', () => {
48
- render(_BreadcrumbLink || (_BreadcrumbLink = _jsx(BreadcrumbLink, {
49
- href: TEST_LINK,
50
- children: TEST_TEXT_01
51
- })));
52
- const anchor = screen.getByRole('link');
53
- expect(anchor).toHaveAttribute('href', TEST_LINK);
54
- });
55
- it('should render as a button and respond to onClick event', () => {
56
- const onClick = vi.fn();
57
- render(_jsx(BreadcrumbLink, {
58
- onClick: onClick,
59
- children: TEST_TEXT_01
60
- }));
61
- const button = screen.getByRole('button');
62
- fireEvent.click(button);
63
- expect(onClick).toHaveBeenCalledTimes(1);
64
- });
65
- it('should respond to mouseEnter event when provided with onMouseEnter prop', () => {
66
- const onMouseEnter = vi.fn();
67
- render(_jsx(BreadcrumbLink, {
68
- onMouseEnter: onMouseEnter,
69
- href: TEST_LINK,
70
- children: TEST_TEXT_01
71
- }));
72
- const link = screen.getByRole('link');
73
- fireEvent.mouseEnter(link);
74
- expect(onMouseEnter).toHaveBeenCalledTimes(1);
75
- });
76
- it('should allow to prop to pass through', () => {
77
- const _render = render(_BreadcrumbLink2 || (_BreadcrumbLink2 = _jsx(BreadcrumbLink, {
78
- to: TEST_TO,
79
- children: TEST_TEXT_01
80
- }))),
81
- container = _render.container;
82
- const link = container.querySelector('a');
83
- expect(link).toBeInTheDocument();
84
- expect(link).toHaveAttribute('to', TEST_TO);
85
- });
86
- it('should not render a link when not given an href prop', () => {
87
- const _render2 = render(_BreadcrumbLink3 || (_BreadcrumbLink3 = _jsx(BreadcrumbLink, {
88
- children: TEST_TEXT_01
89
- }))),
90
- container = _render2.container;
91
- const elementWithHref = container.querySelector('[href]');
92
- const anchor = container.querySelector('a');
93
- const span = container.querySelector('span');
94
- expect(elementWithHref).toBeNull();
95
- expect(anchor).toBeNull();
96
- expect(span).toBeInTheDocument();
97
- expect(span).toHaveTextContent(TEST_TEXT_01);
98
- });
99
- it('should not render a button when not given an onClick prop', () => {
100
- const _render3 = render(_BreadcrumbLink4 || (_BreadcrumbLink4 = _jsx(BreadcrumbLink, {
101
- children: TEST_TEXT_01
102
- }))),
103
- container = _render3.container;
104
- const button = container.querySelector('button');
105
- const span = container.querySelector('span');
106
- expect(button).toBeNull();
107
- expect(span).toBeInTheDocument();
108
- expect(span).toHaveTextContent(TEST_TEXT_01);
109
- });
110
- it('should meet a11y standards as a link', async () => {
111
- const _render4 = render(_BreadcrumbLink5 || (_BreadcrumbLink5 = _jsx(BreadcrumbLink, {
112
- href: TEST_LINK,
113
- children: TEST_TEXT_01
114
- }))),
115
- container = _render4.container;
116
- const axeCheck = await runAxeCheck(container);
117
- expect(axeCheck).toBe(true);
118
- });
119
- it('should meet a11y standards as a span', async () => {
120
- const _render5 = render(_BreadcrumbLink6 || (_BreadcrumbLink6 = _jsx(BreadcrumbLink, {
121
- children: TEST_TEXT_01
122
- }))),
123
- container = _render5.container;
124
- const axeCheck = await runAxeCheck(container);
125
- expect(axeCheck).toBe(true);
126
- });
127
- });
@@ -1,170 +0,0 @@
1
- var _Breadcrumb, _Breadcrumb2, _Breadcrumb3, _Breadcrumb4, _Breadcrumb5, _Breadcrumb6, _Breadcrumb7;
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 { render, screen } from '@testing-library/react';
27
- import { vi } from 'vitest';
28
- import '@testing-library/jest-dom';
29
-
30
- // eslint-disable-next-line no-restricted-imports
31
- import { generateA11yTests } from '@instructure/ui-scripts/lib/test/generateA11yTests';
32
- import { runAxeCheck } from '@instructure/ui-axe-check';
33
- import { Breadcrumb } from '../index';
34
- import BreadcrumbExamples from '../__examples__/Breadcrumb.examples';
35
- import { jsx as _jsx, jsxs as _jsxs } from "@emotion/react/jsx-runtime";
36
- const TEST_LABEL = 'You are here:';
37
- const TEST_TEXT_01 = 'Account';
38
- const TEST_TEXT_02 = 'Settings';
39
- const TEST_LINK = 'http://instructure-test.com';
40
- describe('<Breadcrumb />', () => {
41
- let consoleWarningMock;
42
- let consoleErrorMock;
43
- beforeEach(() => {
44
- // Mocking console to prevent test output pollution and expect for messages
45
- consoleWarningMock = vi.spyOn(console, 'warn').mockImplementation(() => {});
46
- consoleErrorMock = vi.spyOn(console, 'error').mockImplementation(() => {});
47
- });
48
- afterEach(() => {
49
- consoleWarningMock.mockRestore();
50
- consoleErrorMock.mockRestore();
51
- });
52
- it('should be accessible', async () => {
53
- const _render = render(_Breadcrumb || (_Breadcrumb = _jsxs(Breadcrumb, {
54
- label: TEST_LABEL,
55
- children: [_jsx(Breadcrumb.Link, {
56
- href: TEST_LINK,
57
- children: TEST_TEXT_01
58
- }), _jsx(Breadcrumb.Link, {
59
- children: TEST_TEXT_02
60
- })]
61
- }))),
62
- container = _render.container;
63
- const axeCheck = await runAxeCheck(container);
64
- expect(axeCheck).toBe(true);
65
- });
66
- describe('with generated examples', () => {
67
- const generatedComponents = generateA11yTests(Breadcrumb, BreadcrumbExamples);
68
- it.each(generatedComponents)('should be accessible with example: $description', async ({
69
- content
70
- }) => {
71
- const _render2 = render(content),
72
- container = _render2.container;
73
- const axeCheck = await runAxeCheck(container);
74
- expect(axeCheck).toBe(true);
75
- });
76
- });
77
- it('should render the label as an aria-label attribute', () => {
78
- render(_Breadcrumb2 || (_Breadcrumb2 = _jsx(Breadcrumb, {
79
- label: TEST_LABEL,
80
- children: _jsx(Breadcrumb.Link, {
81
- children: TEST_TEXT_01
82
- })
83
- })));
84
- const label = screen.getByLabelText(TEST_LABEL);
85
- expect(label).toBeInTheDocument();
86
- expect(label).toHaveAttribute('aria-label', TEST_LABEL);
87
- });
88
- it('should render an icon as a separator', () => {
89
- const _render3 = render(_Breadcrumb3 || (_Breadcrumb3 = _jsxs(Breadcrumb, {
90
- label: TEST_LABEL,
91
- children: [_jsx(Breadcrumb.Link, {
92
- href: TEST_LINK,
93
- children: TEST_TEXT_01
94
- }), _jsx(Breadcrumb.Link, {
95
- children: TEST_TEXT_02
96
- })]
97
- }))),
98
- container = _render3.container;
99
- const icon = container.querySelector('svg');
100
- expect(icon).toBeInTheDocument();
101
- expect(icon).toHaveAttribute('aria-hidden', 'true');
102
- });
103
- it('should add aria-current="page" to the last element by default', () => {
104
- const _render4 = render(_Breadcrumb4 || (_Breadcrumb4 = _jsxs(Breadcrumb, {
105
- label: TEST_LABEL,
106
- children: [_jsx(Breadcrumb.Link, {
107
- href: TEST_LINK,
108
- children: TEST_TEXT_01
109
- }), _jsx(Breadcrumb.Link, {
110
- children: TEST_TEXT_02
111
- })]
112
- }))),
113
- container = _render4.container;
114
- const links = container.querySelectorAll('[class$="--block-link"]');
115
- const firstLink = links[0];
116
- const lastLink = links[links.length - 1];
117
- expect(firstLink).not.toHaveAttribute('aria-current', 'page');
118
- expect(lastLink).toHaveAttribute('aria-current', 'page');
119
- });
120
- it('should add aria-current="page" to the element if isCurrent is true', () => {
121
- const _render5 = render(_Breadcrumb5 || (_Breadcrumb5 = _jsxs(Breadcrumb, {
122
- label: TEST_LABEL,
123
- children: [_jsx(Breadcrumb.Link, {
124
- isCurrentPage: true,
125
- href: TEST_LINK,
126
- children: TEST_TEXT_01
127
- }), _jsx(Breadcrumb.Link, {
128
- children: TEST_TEXT_02
129
- })]
130
- }))),
131
- container = _render5.container;
132
- const links = container.querySelectorAll('[class$="--block-link"]');
133
- const firstLink = links[0];
134
- const lastLink = links[links.length - 1];
135
- expect(firstLink).toHaveAttribute('aria-current', 'page');
136
- expect(lastLink).not.toHaveAttribute('aria-current', 'page');
137
- });
138
- it('should throw a warning when multiple elements have isCurrent set to true', () => {
139
- render(_Breadcrumb6 || (_Breadcrumb6 = _jsxs(Breadcrumb, {
140
- label: TEST_LABEL,
141
- children: [_jsx(Breadcrumb.Link, {
142
- isCurrentPage: true,
143
- href: TEST_LINK,
144
- children: TEST_TEXT_01
145
- }), _jsx(Breadcrumb.Link, {
146
- isCurrentPage: true,
147
- children: TEST_TEXT_02
148
- })]
149
- })));
150
- expect(consoleWarningMock).toHaveBeenCalledWith(expect.stringContaining('Warning: Multiple elements with isCurrentPage=true found. Only one element should be set to current.'));
151
- });
152
- it('should not add aria-current="page" to the last element if it set to false', () => {
153
- const _render6 = render(_Breadcrumb7 || (_Breadcrumb7 = _jsxs(Breadcrumb, {
154
- label: TEST_LABEL,
155
- children: [_jsx(Breadcrumb.Link, {
156
- href: TEST_LINK,
157
- children: TEST_TEXT_01
158
- }), _jsx(Breadcrumb.Link, {
159
- isCurrentPage: false,
160
- children: TEST_TEXT_02
161
- })]
162
- }))),
163
- container = _render6.container;
164
- const links = container.querySelectorAll('[class$="--block-link"]');
165
- const firstLink = links[0];
166
- const lastLink = links[links.length - 1];
167
- expect(firstLink).not.toHaveAttribute('aria-current', 'page');
168
- expect(lastLink).not.toHaveAttribute('aria-current', 'page');
169
- });
170
- });
@@ -1,128 +0,0 @@
1
- "use strict";
2
-
3
- var _react = require("@testing-library/react");
4
- var _vitest = require("vitest");
5
- require("@testing-library/jest-dom");
6
- var _runAxeCheck = require("@instructure/ui-axe-check/lib/runAxeCheck.js");
7
- var _index = require("../index");
8
- var _jsxRuntime = require("@emotion/react/jsx-runtime");
9
- var _BreadcrumbLink, _BreadcrumbLink2, _BreadcrumbLink3, _BreadcrumbLink4, _BreadcrumbLink5, _BreadcrumbLink6;
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
- const TEST_TEXT_01 = 'Account';
34
- const TEST_LINK = 'http://instructure-test.com';
35
- const TEST_TO = '/example';
36
- describe('<BreadcrumbLink />', () => {
37
- let consoleWarningMock;
38
- let consoleErrorMock;
39
- beforeEach(() => {
40
- // Mocking console to prevent test output pollution
41
- consoleWarningMock = _vitest.vi.spyOn(console, 'warn').mockImplementation(() => {});
42
- consoleErrorMock = _vitest.vi.spyOn(console, 'error').mockImplementation(() => {});
43
- });
44
- afterEach(() => {
45
- consoleWarningMock.mockRestore();
46
- consoleErrorMock.mockRestore();
47
- });
48
- it('should render an anchor tag when given a href prop', () => {
49
- (0, _react.render)(_BreadcrumbLink || (_BreadcrumbLink = (0, _jsxRuntime.jsx)(_index.BreadcrumbLink, {
50
- href: TEST_LINK,
51
- children: TEST_TEXT_01
52
- })));
53
- const anchor = _react.screen.getByRole('link');
54
- expect(anchor).toHaveAttribute('href', TEST_LINK);
55
- });
56
- it('should render as a button and respond to onClick event', () => {
57
- const onClick = _vitest.vi.fn();
58
- (0, _react.render)((0, _jsxRuntime.jsx)(_index.BreadcrumbLink, {
59
- onClick: onClick,
60
- children: TEST_TEXT_01
61
- }));
62
- const button = _react.screen.getByRole('button');
63
- _react.fireEvent.click(button);
64
- expect(onClick).toHaveBeenCalledTimes(1);
65
- });
66
- it('should respond to mouseEnter event when provided with onMouseEnter prop', () => {
67
- const onMouseEnter = _vitest.vi.fn();
68
- (0, _react.render)((0, _jsxRuntime.jsx)(_index.BreadcrumbLink, {
69
- onMouseEnter: onMouseEnter,
70
- href: TEST_LINK,
71
- children: TEST_TEXT_01
72
- }));
73
- const link = _react.screen.getByRole('link');
74
- _react.fireEvent.mouseEnter(link);
75
- expect(onMouseEnter).toHaveBeenCalledTimes(1);
76
- });
77
- it('should allow to prop to pass through', () => {
78
- const _render = (0, _react.render)(_BreadcrumbLink2 || (_BreadcrumbLink2 = (0, _jsxRuntime.jsx)(_index.BreadcrumbLink, {
79
- to: TEST_TO,
80
- children: TEST_TEXT_01
81
- }))),
82
- container = _render.container;
83
- const link = container.querySelector('a');
84
- expect(link).toBeInTheDocument();
85
- expect(link).toHaveAttribute('to', TEST_TO);
86
- });
87
- it('should not render a link when not given an href prop', () => {
88
- const _render2 = (0, _react.render)(_BreadcrumbLink3 || (_BreadcrumbLink3 = (0, _jsxRuntime.jsx)(_index.BreadcrumbLink, {
89
- children: TEST_TEXT_01
90
- }))),
91
- container = _render2.container;
92
- const elementWithHref = container.querySelector('[href]');
93
- const anchor = container.querySelector('a');
94
- const span = container.querySelector('span');
95
- expect(elementWithHref).toBeNull();
96
- expect(anchor).toBeNull();
97
- expect(span).toBeInTheDocument();
98
- expect(span).toHaveTextContent(TEST_TEXT_01);
99
- });
100
- it('should not render a button when not given an onClick prop', () => {
101
- const _render3 = (0, _react.render)(_BreadcrumbLink4 || (_BreadcrumbLink4 = (0, _jsxRuntime.jsx)(_index.BreadcrumbLink, {
102
- children: TEST_TEXT_01
103
- }))),
104
- container = _render3.container;
105
- const button = container.querySelector('button');
106
- const span = container.querySelector('span');
107
- expect(button).toBeNull();
108
- expect(span).toBeInTheDocument();
109
- expect(span).toHaveTextContent(TEST_TEXT_01);
110
- });
111
- it('should meet a11y standards as a link', async () => {
112
- const _render4 = (0, _react.render)(_BreadcrumbLink5 || (_BreadcrumbLink5 = (0, _jsxRuntime.jsx)(_index.BreadcrumbLink, {
113
- href: TEST_LINK,
114
- children: TEST_TEXT_01
115
- }))),
116
- container = _render4.container;
117
- const axeCheck = await (0, _runAxeCheck.runAxeCheck)(container);
118
- expect(axeCheck).toBe(true);
119
- });
120
- it('should meet a11y standards as a span', async () => {
121
- const _render5 = (0, _react.render)(_BreadcrumbLink6 || (_BreadcrumbLink6 = (0, _jsxRuntime.jsx)(_index.BreadcrumbLink, {
122
- children: TEST_TEXT_01
123
- }))),
124
- container = _render5.container;
125
- const axeCheck = await (0, _runAxeCheck.runAxeCheck)(container);
126
- expect(axeCheck).toBe(true);
127
- });
128
- });
@@ -1,171 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
- var _react = require("@testing-library/react");
5
- var _vitest = require("vitest");
6
- require("@testing-library/jest-dom");
7
- var _generateA11yTests = require("@instructure/ui-scripts/lib/test/generateA11yTests");
8
- var _runAxeCheck = require("@instructure/ui-axe-check/lib/runAxeCheck.js");
9
- var _index = require("../index");
10
- var _Breadcrumb8 = _interopRequireDefault(require("../__examples__/Breadcrumb.examples"));
11
- var _jsxRuntime = require("@emotion/react/jsx-runtime");
12
- var _Breadcrumb, _Breadcrumb2, _Breadcrumb3, _Breadcrumb4, _Breadcrumb5, _Breadcrumb6, _Breadcrumb7;
13
- /*
14
- * The MIT License (MIT)
15
- *
16
- * Copyright (c) 2015 - present Instructure, Inc.
17
- *
18
- * Permission is hereby granted, free of charge, to any person obtaining a copy
19
- * of this software and associated documentation files (the "Software"), to deal
20
- * in the Software without restriction, including without limitation the rights
21
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
22
- * copies of the Software, and to permit persons to whom the Software is
23
- * furnished to do so, subject to the following conditions:
24
- *
25
- * The above copyright notice and this permission notice shall be included in all
26
- * copies or substantial portions of the Software.
27
- *
28
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
29
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
30
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
31
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
32
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
33
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
34
- * SOFTWARE.
35
- */
36
- // eslint-disable-next-line no-restricted-imports
37
- const TEST_LABEL = 'You are here:';
38
- const TEST_TEXT_01 = 'Account';
39
- const TEST_TEXT_02 = 'Settings';
40
- const TEST_LINK = 'http://instructure-test.com';
41
- describe('<Breadcrumb />', () => {
42
- let consoleWarningMock;
43
- let consoleErrorMock;
44
- beforeEach(() => {
45
- // Mocking console to prevent test output pollution and expect for messages
46
- consoleWarningMock = _vitest.vi.spyOn(console, 'warn').mockImplementation(() => {});
47
- consoleErrorMock = _vitest.vi.spyOn(console, 'error').mockImplementation(() => {});
48
- });
49
- afterEach(() => {
50
- consoleWarningMock.mockRestore();
51
- consoleErrorMock.mockRestore();
52
- });
53
- it('should be accessible', async () => {
54
- const _render = (0, _react.render)(_Breadcrumb || (_Breadcrumb = (0, _jsxRuntime.jsxs)(_index.Breadcrumb, {
55
- label: TEST_LABEL,
56
- children: [(0, _jsxRuntime.jsx)(_index.Breadcrumb.Link, {
57
- href: TEST_LINK,
58
- children: TEST_TEXT_01
59
- }), (0, _jsxRuntime.jsx)(_index.Breadcrumb.Link, {
60
- children: TEST_TEXT_02
61
- })]
62
- }))),
63
- container = _render.container;
64
- const axeCheck = await (0, _runAxeCheck.runAxeCheck)(container);
65
- expect(axeCheck).toBe(true);
66
- });
67
- describe('with generated examples', () => {
68
- const generatedComponents = (0, _generateA11yTests.generateA11yTests)(_index.Breadcrumb, _Breadcrumb8.default);
69
- it.each(generatedComponents)('should be accessible with example: $description', async ({
70
- content
71
- }) => {
72
- const _render2 = (0, _react.render)(content),
73
- container = _render2.container;
74
- const axeCheck = await (0, _runAxeCheck.runAxeCheck)(container);
75
- expect(axeCheck).toBe(true);
76
- });
77
- });
78
- it('should render the label as an aria-label attribute', () => {
79
- (0, _react.render)(_Breadcrumb2 || (_Breadcrumb2 = (0, _jsxRuntime.jsx)(_index.Breadcrumb, {
80
- label: TEST_LABEL,
81
- children: (0, _jsxRuntime.jsx)(_index.Breadcrumb.Link, {
82
- children: TEST_TEXT_01
83
- })
84
- })));
85
- const label = _react.screen.getByLabelText(TEST_LABEL);
86
- expect(label).toBeInTheDocument();
87
- expect(label).toHaveAttribute('aria-label', TEST_LABEL);
88
- });
89
- it('should render an icon as a separator', () => {
90
- const _render3 = (0, _react.render)(_Breadcrumb3 || (_Breadcrumb3 = (0, _jsxRuntime.jsxs)(_index.Breadcrumb, {
91
- label: TEST_LABEL,
92
- children: [(0, _jsxRuntime.jsx)(_index.Breadcrumb.Link, {
93
- href: TEST_LINK,
94
- children: TEST_TEXT_01
95
- }), (0, _jsxRuntime.jsx)(_index.Breadcrumb.Link, {
96
- children: TEST_TEXT_02
97
- })]
98
- }))),
99
- container = _render3.container;
100
- const icon = container.querySelector('svg');
101
- expect(icon).toBeInTheDocument();
102
- expect(icon).toHaveAttribute('aria-hidden', 'true');
103
- });
104
- it('should add aria-current="page" to the last element by default', () => {
105
- const _render4 = (0, _react.render)(_Breadcrumb4 || (_Breadcrumb4 = (0, _jsxRuntime.jsxs)(_index.Breadcrumb, {
106
- label: TEST_LABEL,
107
- children: [(0, _jsxRuntime.jsx)(_index.Breadcrumb.Link, {
108
- href: TEST_LINK,
109
- children: TEST_TEXT_01
110
- }), (0, _jsxRuntime.jsx)(_index.Breadcrumb.Link, {
111
- children: TEST_TEXT_02
112
- })]
113
- }))),
114
- container = _render4.container;
115
- const links = container.querySelectorAll('[class$="--block-link"]');
116
- const firstLink = links[0];
117
- const lastLink = links[links.length - 1];
118
- expect(firstLink).not.toHaveAttribute('aria-current', 'page');
119
- expect(lastLink).toHaveAttribute('aria-current', 'page');
120
- });
121
- it('should add aria-current="page" to the element if isCurrent is true', () => {
122
- const _render5 = (0, _react.render)(_Breadcrumb5 || (_Breadcrumb5 = (0, _jsxRuntime.jsxs)(_index.Breadcrumb, {
123
- label: TEST_LABEL,
124
- children: [(0, _jsxRuntime.jsx)(_index.Breadcrumb.Link, {
125
- isCurrentPage: true,
126
- href: TEST_LINK,
127
- children: TEST_TEXT_01
128
- }), (0, _jsxRuntime.jsx)(_index.Breadcrumb.Link, {
129
- children: TEST_TEXT_02
130
- })]
131
- }))),
132
- container = _render5.container;
133
- const links = container.querySelectorAll('[class$="--block-link"]');
134
- const firstLink = links[0];
135
- const lastLink = links[links.length - 1];
136
- expect(firstLink).toHaveAttribute('aria-current', 'page');
137
- expect(lastLink).not.toHaveAttribute('aria-current', 'page');
138
- });
139
- it('should throw a warning when multiple elements have isCurrent set to true', () => {
140
- (0, _react.render)(_Breadcrumb6 || (_Breadcrumb6 = (0, _jsxRuntime.jsxs)(_index.Breadcrumb, {
141
- label: TEST_LABEL,
142
- children: [(0, _jsxRuntime.jsx)(_index.Breadcrumb.Link, {
143
- isCurrentPage: true,
144
- href: TEST_LINK,
145
- children: TEST_TEXT_01
146
- }), (0, _jsxRuntime.jsx)(_index.Breadcrumb.Link, {
147
- isCurrentPage: true,
148
- children: TEST_TEXT_02
149
- })]
150
- })));
151
- expect(consoleWarningMock).toHaveBeenCalledWith(expect.stringContaining('Warning: Multiple elements with isCurrentPage=true found. Only one element should be set to current.'));
152
- });
153
- it('should not add aria-current="page" to the last element if it set to false', () => {
154
- const _render6 = (0, _react.render)(_Breadcrumb7 || (_Breadcrumb7 = (0, _jsxRuntime.jsxs)(_index.Breadcrumb, {
155
- label: TEST_LABEL,
156
- children: [(0, _jsxRuntime.jsx)(_index.Breadcrumb.Link, {
157
- href: TEST_LINK,
158
- children: TEST_TEXT_01
159
- }), (0, _jsxRuntime.jsx)(_index.Breadcrumb.Link, {
160
- isCurrentPage: false,
161
- children: TEST_TEXT_02
162
- })]
163
- }))),
164
- container = _render6.container;
165
- const links = container.querySelectorAll('[class$="--block-link"]');
166
- const firstLink = links[0];
167
- const lastLink = links[links.length - 1];
168
- expect(firstLink).not.toHaveAttribute('aria-current', 'page');
169
- expect(lastLink).not.toHaveAttribute('aria-current', 'page');
170
- });
171
- });