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