@instructure/ui-tabs 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,52 +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 '@testing-library/jest-dom'
27
-
28
- import { Panel } from '../index'
29
-
30
- describe('<Tabs.Panel />', () => {
31
- it('should render children', async () => {
32
- render(
33
- <Panel isSelected renderTitle="Panel Title">
34
- Panel contents
35
- </Panel>
36
- )
37
- const children = screen.getByText('Panel contents')
38
-
39
- expect(children).toBeInTheDocument()
40
- })
41
-
42
- it('should have appropriate role attribute', async () => {
43
- const { container } = render(
44
- <Panel isSelected renderTitle="Panel Title">
45
- Panel contents
46
- </Panel>
47
- )
48
- const tabPanel = container.querySelector('[class$="-panel"]')
49
-
50
- expect(tabPanel).toHaveAttribute('role', 'tabpanel')
51
- })
52
- })
@@ -1,209 +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, waitFor } from '@testing-library/react'
26
- import { vi } from 'vitest'
27
- import userEvent from '@testing-library/user-event'
28
- import '@testing-library/jest-dom'
29
-
30
- import { Tab } from '../index'
31
-
32
- describe('<Tabs.Tab />', () => {
33
- it('should render children', async () => {
34
- render(
35
- <Tab id="foo" index={0} controls="foo-panel">
36
- Tab Label
37
- </Tab>
38
- )
39
- const children = screen.getByText('Tab Label')
40
-
41
- expect(children).toBeInTheDocument()
42
- })
43
-
44
- it('should have appropriate role attribute', async () => {
45
- render(
46
- <Tab id="foo" index={0} controls="foo-panel">
47
- Tab Label
48
- </Tab>
49
- )
50
- const tab = screen.getByRole('tab')
51
-
52
- expect(tab).toBeInTheDocument()
53
- })
54
-
55
- it('should have appropriate aria attributes', async () => {
56
- render(
57
- <Tab id="foo" index={0} controls="foo-panel">
58
- Tab Label
59
- </Tab>
60
- )
61
- const tab = screen.getByRole('tab')
62
-
63
- expect(tab).not.toHaveAttribute('aria-selected')
64
- expect(tab).not.toHaveAttribute('aria-disabled')
65
- })
66
-
67
- it('should set the aria-selected attribute', async () => {
68
- render(
69
- <Tab id="foo" index={0} controls="foo-panel" isSelected>
70
- Tab Label
71
- </Tab>
72
- )
73
- const tab = screen.getByRole('tab')
74
-
75
- expect(tab).toHaveAttribute('aria-selected', 'true')
76
- })
77
-
78
- it('should set the aria-disabled attribute', async () => {
79
- render(
80
- <Tab id="foo" index={0} controls="foo-panel" isDisabled>
81
- Tab Label
82
- </Tab>
83
- )
84
- const tab = screen.getByRole('tab')
85
-
86
- expect(tab).toHaveAttribute('aria-disabled', 'true')
87
- })
88
-
89
- it('should set the tabindex to 0 when selected', async () => {
90
- render(
91
- <Tab id="foo" index={0} controls="foo-panel" isSelected>
92
- Tab Label
93
- </Tab>
94
- )
95
- const tab = screen.getByRole('tab')
96
-
97
- expect(tab).toHaveAttribute('tabindex', '0')
98
- })
99
-
100
- it('should not set the tabindex when not selected', async () => {
101
- render(
102
- <Tab id="foo" index={0} controls="foo-panel">
103
- Tab Label
104
- </Tab>
105
- )
106
- const tab = screen.getByRole('tab')
107
-
108
- expect(tab).not.toHaveAttribute('tabindex')
109
- })
110
-
111
- it('should remove the tabindex attribute when disabled', async () => {
112
- render(
113
- <Tab id="foo" index={0} controls="foo-panel" isDisabled>
114
- Tab Label
115
- </Tab>
116
- )
117
- const tab = screen.getByRole('tab')
118
-
119
- expect(tab).not.toHaveAttribute('tabindex')
120
- })
121
-
122
- it('should call onClick when clicked', async () => {
123
- const onClick = vi.fn()
124
- const index = 2
125
-
126
- render(
127
- <Tab id="foo" index={index} controls="foo-panel" onClick={onClick}>
128
- Tab Label
129
- </Tab>
130
- )
131
- const tab = screen.getByRole('tab')
132
-
133
- await userEvent.click(tab)
134
-
135
- await waitFor(() => {
136
- expect(onClick).toHaveBeenCalled()
137
-
138
- const args = onClick.mock.calls[0][1]
139
- expect(args).toHaveProperty('index', index)
140
- })
141
- })
142
-
143
- it('should NOT call onClick when clicked and tab is disabled', async () => {
144
- const onClick = vi.fn()
145
-
146
- render(
147
- <Tab id="foo" index={0} controls="foo-panel" onClick={onClick} isDisabled>
148
- Tab Label
149
- </Tab>
150
- )
151
- const tab = screen.getByRole('tab')
152
-
153
- await userEvent.click(tab)
154
-
155
- await waitFor(() => {
156
- expect(onClick).not.toHaveBeenCalled()
157
- })
158
- })
159
-
160
- it('should call onKeyDown when keys are pressed and tab is selected', async () => {
161
- const onKeyDown = vi.fn()
162
- const index = 2
163
-
164
- render(
165
- <Tab
166
- id="foo"
167
- isSelected
168
- index={index}
169
- controls="foo-panel"
170
- onKeyDown={onKeyDown}
171
- >
172
- Tab Label
173
- </Tab>
174
- )
175
- const tab = screen.getByRole('tab')
176
-
177
- await userEvent.type(tab, '{enter}')
178
-
179
- await waitFor(() => {
180
- expect(onKeyDown).toHaveBeenCalled()
181
-
182
- const args = onKeyDown.mock.calls[0][1]
183
- expect(args).toHaveProperty('index', index)
184
- })
185
- })
186
-
187
- it('should NOT call onKeyDown when keys are pressed and tab is disabled', async () => {
188
- const onKeyDown = vi.fn()
189
-
190
- render(
191
- <Tab
192
- id="foo"
193
- index={0}
194
- controls="foo-panel"
195
- onKeyDown={onKeyDown}
196
- isDisabled
197
- >
198
- Tab Label
199
- </Tab>
200
- )
201
- const tab = screen.getByRole('tab')
202
-
203
- await userEvent.type(tab, '{enter}')
204
-
205
- await waitFor(() => {
206
- expect(onKeyDown).not.toHaveBeenCalled()
207
- })
208
- })
209
- })
@@ -1,430 +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 { useState } from 'react'
26
- import { render, screen, waitFor } from '@testing-library/react'
27
- import { vi } from 'vitest'
28
- import type { MockInstance } from 'vitest'
29
- import userEvent from '@testing-library/user-event'
30
- import '@testing-library/jest-dom'
31
-
32
- import { runAxeCheck } from '@instructure/ui-axe-check'
33
- import { Tabs } from '../index'
34
-
35
- const TabExample = (props: { onIndexChange: (arg: number) => void }) => {
36
- const [selectedIndex, setSelectedIndex] = useState(0)
37
- return (
38
- <Tabs
39
- onRequestTabChange={(_event, { index }) => {
40
- setSelectedIndex(index)
41
- props.onIndexChange(index)
42
- }}
43
- variant="default"
44
- margin="medium"
45
- >
46
- <Tabs.Panel
47
- renderTitle="First Tab"
48
- id="first"
49
- isSelected={selectedIndex === 0}
50
- active
51
- >
52
- <p>CONTENT</p>
53
- </Tabs.Panel>
54
- <Tabs.Panel
55
- renderTitle="Second Tab"
56
- id="second"
57
- isSelected={selectedIndex === 1}
58
- />
59
- <Tabs.Panel
60
- renderTitle="Third Tab"
61
- id="third"
62
- isSelected={selectedIndex === 2}
63
- />
64
- </Tabs>
65
- )
66
- }
67
-
68
- describe('<Tabs />', () => {
69
- const tab1Content = 'Tab 1 content'
70
- const tab2Content = 'Tab 2 content'
71
- const tab3Content = 'Tab 3 content'
72
-
73
- let consoleErrorMock: ReturnType<typeof vi.spyOn>
74
- let consoleWarningMock: ReturnType<typeof vi.spyOn>
75
-
76
- beforeEach(() => {
77
- // Mocking console to prevent test output pollution and expect for messages
78
- consoleErrorMock = vi
79
- .spyOn(console, 'error')
80
- .mockImplementation(() => {}) as MockInstance
81
-
82
- consoleWarningMock = vi
83
- .spyOn(console, 'warn')
84
- .mockImplementation(() => {}) as MockInstance
85
- })
86
-
87
- afterEach(() => {
88
- consoleErrorMock.mockRestore()
89
- consoleWarningMock.mockRestore()
90
- })
91
-
92
- it('should render the correct number of panels', () => {
93
- const { container } = render(
94
- <Tabs>
95
- <Tabs.Panel renderTitle="First Tab">Tab 1 content</Tabs.Panel>
96
- <Tabs.Panel renderTitle="Second Tab">Tab 2 content</Tabs.Panel>
97
- <Tabs.Panel renderTitle="Third Tab" isDisabled>
98
- Tab 3 content
99
- </Tabs.Panel>
100
- </Tabs>
101
- )
102
- const panels = container.querySelectorAll('[role="tabpanel"]')
103
-
104
- expect(panels.length).toBe(3)
105
- })
106
-
107
- it('should render with null children', async () => {
108
- const { container } = render(
109
- <Tabs>
110
- <Tabs.Panel renderTitle="First Tab">Tab 1 content</Tabs.Panel>
111
- <Tabs.Panel renderTitle="Second Tab">Tab 2 content</Tabs.Panel>
112
- <Tabs.Panel renderTitle="Third Tab" isDisabled>
113
- Tab 3 content
114
- </Tabs.Panel>
115
- {null}
116
- </Tabs>
117
- )
118
- const panels = container.querySelectorAll('[role="tabpanel"]')
119
-
120
- expect(panels.length).toBe(3)
121
- })
122
-
123
- it('should be okay with rendering without any children', async () => {
124
- render(<Tabs></Tabs>)
125
-
126
- expect(consoleErrorMock).not.toHaveBeenCalled()
127
- })
128
-
129
- it('should render correct number of tabs', async () => {
130
- render(
131
- <Tabs>
132
- <Tabs.Panel renderTitle="First Tab">Tab 1 content</Tabs.Panel>
133
- <Tabs.Panel renderTitle="Second Tab">Tab 2 content</Tabs.Panel>
134
- <Tabs.Panel renderTitle="Third Tab" isDisabled>
135
- Tab 3 content
136
- </Tabs.Panel>
137
- </Tabs>
138
- )
139
- const tabs = screen.getAllByRole('tab')
140
-
141
- expect(tabs.length).toBe(3)
142
- })
143
-
144
- it('should render same content for other tabs as for the active one', () => {
145
- const { container } = render(
146
- <Tabs>
147
- <Tabs.Panel renderTitle="First Tab" active>
148
- CONTENT
149
- </Tabs.Panel>
150
- <Tabs.Panel id="secondTab" renderTitle="Second Tab" isSelected>
151
- Child
152
- </Tabs.Panel>
153
- <Tabs.Panel renderTitle="Third Tab">Child</Tabs.Panel>
154
- </Tabs>
155
- )
156
-
157
- const tabContent = screen.getByText('CONTENT')
158
-
159
- expect(container).toBeInTheDocument()
160
- expect(tabContent).toBeInTheDocument()
161
-
162
- const childContent = screen.queryByText('Child')
163
-
164
- expect(childContent).toBeNull()
165
- })
166
-
167
- it('should render the same content in second tab when selected', async () => {
168
- const onIndexChange = vi.fn()
169
-
170
- const { container } = render(<TabExample onIndexChange={onIndexChange} />)
171
- expect(container).toBeInTheDocument()
172
-
173
- const secondTab = screen.getAllByRole('tab')[1]
174
-
175
- await userEvent.click(secondTab)
176
-
177
- await waitFor(() => {
178
- expect(onIndexChange).toHaveBeenCalledWith(1)
179
- })
180
-
181
- const panelContent = screen.queryByText('CONTENT')
182
-
183
- expect(panelContent).toBeInTheDocument()
184
- })
185
-
186
- it('should warn if multiple active tabs exist', () => {
187
- const { container } = render(
188
- <Tabs>
189
- <Tabs.Panel renderTitle="First Tab" active>
190
- Tab 1 content
191
- </Tabs.Panel>
192
- <Tabs.Panel renderTitle="Second Tab" active>
193
- Tab 2 content
194
- </Tabs.Panel>
195
- <Tabs.Panel renderTitle="Third Tab" isDisabled>
196
- Tab 3 content
197
- </Tabs.Panel>
198
- </Tabs>
199
- )
200
-
201
- expect(container.firstChild).toBeInTheDocument()
202
-
203
- expect(consoleErrorMock.mock.calls[0][0]).toEqual(
204
- 'Warning: [Tabs] Only one Panel can be marked as active.'
205
- )
206
- })
207
-
208
- it('should default to selecting the first tab', async () => {
209
- const { container } = render(
210
- <Tabs>
211
- <Tabs.Panel renderTitle="First Tab">{tab1Content}</Tabs.Panel>
212
- <Tabs.Panel renderTitle="Second Tab">{tab2Content}</Tabs.Panel>
213
- <Tabs.Panel renderTitle="Third Tab" isDisabled>
214
- {tab3Content}
215
- </Tabs.Panel>
216
- </Tabs>
217
- )
218
- const panelsContainer = container.querySelector(
219
- '[class$="panelsContainer"]'
220
- )
221
-
222
- expect(panelsContainer).toHaveTextContent(tab1Content)
223
- expect(screen.getByText(tab1Content)).toBeVisible()
224
-
225
- expect(panelsContainer).not.toHaveTextContent(tab2Content)
226
- expect(panelsContainer).not.toHaveTextContent(tab3Content)
227
- })
228
-
229
- it('should honor the isSelected prop', async () => {
230
- const { container } = render(
231
- <Tabs>
232
- <Tabs.Panel renderTitle="First Tab">{tab1Content}</Tabs.Panel>
233
- <Tabs.Panel renderTitle="Second Tab" isSelected>
234
- {tab2Content}
235
- </Tabs.Panel>
236
- <Tabs.Panel renderTitle="Third Tab" isDisabled>
237
- {tab3Content}
238
- </Tabs.Panel>
239
- </Tabs>
240
- )
241
- const panelsContainer = container.querySelector(
242
- '[class$="panelsContainer"]'
243
- )
244
-
245
- expect(panelsContainer).toHaveTextContent(tab2Content)
246
- expect(screen.getByText(tab2Content)).toBeVisible()
247
-
248
- expect(panelsContainer).not.toHaveTextContent(tab1Content)
249
- expect(panelsContainer).not.toHaveTextContent(tab3Content)
250
- })
251
-
252
- it('should not allow selecting a disabled tab', async () => {
253
- const { container } = render(
254
- <Tabs>
255
- <Tabs.Panel renderTitle="First Tab">Tab 1 content</Tabs.Panel>
256
- <Tabs.Panel renderTitle="Second Tab">Tab 2 content</Tabs.Panel>
257
- <Tabs.Panel renderTitle="Third Tab" isDisabled isSelected>
258
- Tab 3 content
259
- </Tabs.Panel>
260
- </Tabs>
261
- )
262
- const panelsContainer = container.querySelector(
263
- '[class$="panelsContainer"]'
264
- )
265
- const panels = container.querySelectorAll('[role="tabpanel"]')
266
-
267
- expect(panelsContainer).toHaveTextContent(tab1Content)
268
- expect(screen.getByText(tab1Content)).toBeVisible()
269
-
270
- expect(panelsContainer).not.toHaveTextContent(tab2Content)
271
- expect(panelsContainer).not.toHaveTextContent(tab3Content)
272
-
273
- expect(panels.length).toBe(3)
274
- expect(panels[0]).not.toHaveAttribute('aria-hidden', 'true')
275
- expect(panels[1]).toHaveAttribute('aria-hidden', 'true')
276
- expect(panels[2]).toHaveAttribute('aria-hidden', 'true')
277
- })
278
-
279
- it('should call onRequestTabChange when selection changes via click', async () => {
280
- const onChange = vi.fn()
281
-
282
- render(
283
- <Tabs onRequestTabChange={onChange}>
284
- <Tabs.Panel renderTitle="First Tab" isSelected id="one">
285
- Tab 1 content
286
- </Tabs.Panel>
287
- <Tabs.Panel renderTitle="Second Tab" id="two">
288
- Tab 2 content
289
- </Tabs.Panel>
290
- <Tabs.Panel renderTitle="Third Tab" isDisabled id="three">
291
- Tab 3 content
292
- </Tabs.Panel>
293
- </Tabs>
294
- )
295
- const secondTab = screen.getByText('Second Tab')
296
-
297
- await userEvent.click(secondTab)
298
-
299
- await waitFor(() => {
300
- expect(onChange).toHaveBeenCalled()
301
-
302
- const args = onChange.mock.calls[0][1]
303
-
304
- expect(args).toHaveProperty('index', 1)
305
- expect(args).toHaveProperty('id', 'two')
306
- })
307
- })
308
-
309
- it('should focus the selected tab when shouldFocusOnRender is set', async () => {
310
- render(
311
- <Tabs shouldFocusOnRender>
312
- <Tabs.Panel renderTitle="First Tab">Tab 1 content</Tabs.Panel>
313
- <Tabs.Panel renderTitle="Second Tab" isSelected>
314
- Tab 2 content
315
- </Tabs.Panel>
316
- <Tabs.Panel renderTitle="Third Tab" isDisabled>
317
- Tab 3 content
318
- </Tabs.Panel>
319
- </Tabs>
320
- )
321
- const secondTab = screen.getByText('Second Tab')
322
-
323
- await waitFor(() => {
324
- expect(document.activeElement).toBe(secondTab)
325
- })
326
- })
327
-
328
- it('should not call onRequestTabChange when clicking a disabled tab', async () => {
329
- const onChange = vi.fn()
330
- render(
331
- <Tabs onRequestTabChange={onChange}>
332
- <Tabs.Panel renderTitle="First Tab">Tab 1 content</Tabs.Panel>
333
- <Tabs.Panel renderTitle="Second Tab">Tab 2 content</Tabs.Panel>
334
- <Tabs.Panel renderTitle="Third Tab" isDisabled>
335
- Tab 3 content
336
- </Tabs.Panel>
337
- </Tabs>
338
- )
339
- const thirdTab = screen.getByText('Third Tab')
340
-
341
- await userEvent.click(thirdTab)
342
-
343
- await waitFor(() => {
344
- expect(onChange).not.toHaveBeenCalled()
345
- })
346
- })
347
-
348
- it('should meet a11y standards when set to the secondary variant', async () => {
349
- const { container } = render(
350
- <Tabs variant="secondary">
351
- <Tabs.Panel renderTitle="First Tab">Tab 1 content</Tabs.Panel>
352
- <Tabs.Panel renderTitle="Second Tab">Tab 2 content</Tabs.Panel>
353
- <Tabs.Panel renderTitle="Third Tab" isDisabled>
354
- Tab 3 content
355
- </Tabs.Panel>
356
- </Tabs>
357
- )
358
- const axeCheck = await runAxeCheck(container)
359
-
360
- expect(axeCheck).toBe(true)
361
- })
362
-
363
- it('should meet a11y standards when set to the default variant', async () => {
364
- const { container } = render(
365
- <Tabs variant="default">
366
- <Tabs.Panel renderTitle="First Tab">Tab 1 content</Tabs.Panel>
367
- <Tabs.Panel renderTitle="Second Tab">Tab 2 content</Tabs.Panel>
368
- <Tabs.Panel renderTitle="Third Tab" isDisabled>
369
- Tab 3 content
370
- </Tabs.Panel>
371
- </Tabs>
372
- )
373
- const axeCheck = await runAxeCheck(container)
374
-
375
- expect(axeCheck).toBe(true)
376
- })
377
-
378
- it('should link tabs with the corresponding panels via ids', async () => {
379
- const { container } = render(
380
- <Tabs>
381
- <Tabs.Panel renderTitle="First Tab">Tab 1 content</Tabs.Panel>
382
- <Tabs.Panel renderTitle="Second Tab">Tab 2 content</Tabs.Panel>
383
- <Tabs.Panel renderTitle="Third Tab" isDisabled>
384
- Tab 3 content
385
- </Tabs.Panel>
386
- </Tabs>
387
- )
388
- const firstTab = screen.getByText('First Tab')
389
- const firstPanel = container.querySelectorAll('[role="tabpanel"]')[0]
390
-
391
- expect(firstTab).toHaveAttribute('aria-controls', firstPanel.id)
392
- expect(firstPanel).toHaveAttribute('aria-labelledby', firstTab.id)
393
- })
394
-
395
- describe('with duplicate-named tabs', () => {
396
- it('should still render the correct number of panels', async () => {
397
- const { container } = render(
398
- <Tabs>
399
- <Tabs.Panel renderTitle="A Tab">Contents of first tab.</Tabs.Panel>
400
- <Tabs.Panel renderTitle="A Tab">Contents of second tab.</Tabs.Panel>
401
- <Tabs.Panel renderTitle="A Tab" isDisabled>
402
- Contents of third tab.
403
- </Tabs.Panel>
404
- </Tabs>
405
- )
406
- const tabPanels = container.querySelectorAll('[role="tabpanel"]')
407
-
408
- expect(tabPanels.length).toBe(3)
409
- })
410
- })
411
-
412
- describe('with nodes as tab titles', () => {
413
- it('should still render the correct number of panels', async () => {
414
- const { container } = render(
415
- <Tabs>
416
- <Tabs.Panel renderTitle={<div />}>Contents of first tab.</Tabs.Panel>
417
- <Tabs.Panel renderTitle={<span />}>
418
- Contents of second tab.
419
- </Tabs.Panel>
420
- <Tabs.Panel renderTitle={<img alt="example" />} isDisabled>
421
- Contents of third tab.
422
- </Tabs.Panel>
423
- </Tabs>
424
- )
425
- const tabPanels = container.querySelectorAll('[role="tabpanel"]')
426
-
427
- expect(tabPanels.length).toBe(3)
428
- })
429
- })
430
- })
@@ -1,2 +0,0 @@
1
- import '@testing-library/jest-dom';
2
- //# sourceMappingURL=Panel.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Panel.test.d.ts","sourceRoot":"","sources":["../../../../src/Tabs/Panel/__new-tests__/Panel.test.tsx"],"names":[],"mappings":"AAyBA,OAAO,2BAA2B,CAAA"}
@@ -1,2 +0,0 @@
1
- import '@testing-library/jest-dom';
2
- //# sourceMappingURL=Tab.test.d.ts.map