Skip to content

Commit 5992339

Browse files
committed
added two unit tests
1 parent 6ff7557 commit 5992339

File tree

3 files changed

+64
-0
lines changed

3 files changed

+64
-0
lines changed

Diff for: packages/react-core/src/components/Nav/__tests__/Generated/__snapshots__/NavExpandable.test.tsx.snap

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ exports[`NavExpandable should match snapshot (auto-generated) 1`] = `
3939
aria-labelledby="''"
4040
class="pf-v6-c-nav__subnav"
4141
hidden=""
42+
inert=""
4243
>
4344
<h2
4445
class="pf-v6-screen-reader"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import { render, screen } from '@testing-library/react';
2+
import userEvent from '@testing-library/user-event';
3+
import '@testing-library/jest-dom';
4+
import { NavExpandable } from '../NavExpandable';
5+
import { NavItem } from '../NavItem';
6+
import { Nav, NavContext } from '../Nav';
7+
import { NavList } from '../NavList';
8+
9+
const props = {
10+
items: [
11+
{ to: '#link1', label: 'Link 1' },
12+
{ to: '#link2', label: 'Link 2' },
13+
{ to: '#link3', label: 'Link 3' }
14+
]
15+
};
16+
17+
describe('NavExpandable', () => {
18+
beforeEach(() => {
19+
jest.resetAllMocks();
20+
});
21+
22+
test('check that inert is on the section element by default', () => {
23+
render(
24+
<Nav onSelect={jest.fn()} onToggle={jest.fn()}>
25+
<NavList>
26+
<NavExpandable id="grp-1" title="Expandable group" data-testid="test-id">
27+
{props.items.map((item) => (
28+
<NavItem to={item.to} key={item.to}>
29+
{item.label}
30+
</NavItem>
31+
))}
32+
</NavExpandable>
33+
</NavList>
34+
</Nav>
35+
);
36+
const wrapper = screen.getByTestId('test-id');
37+
const section = wrapper.querySelector('.pf-v6-c-nav__subnav');
38+
expect(section).toHaveAttribute('inert', '');
39+
});
40+
41+
test('check that inert is NOT on the section when isExpanded is true', () => {
42+
render(
43+
<Nav onSelect={jest.fn()} onToggle={jest.fn()}>
44+
<NavList>
45+
<NavExpandable id="grp-1" title="Expandable group" isExpanded={true} data-testid="test-id">
46+
{props.items.map((item) => (
47+
<NavItem to={item.to} key={item.to}>
48+
{item.label}
49+
</NavItem>
50+
))}
51+
</NavExpandable>
52+
</NavList>
53+
</Nav>
54+
);
55+
56+
const wrapper = screen.getByTestId('test-id');
57+
const section = wrapper.querySelector('.pf-v6-c-nav__subnav');
58+
expect(section).not.toHaveAttribute('inert', '');
59+
});
60+
});

Diff for: packages/react-core/src/components/Nav/__tests__/__snapshots__/Nav.test.tsx.snap

+3
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ exports[`Nav Expandable Nav List - Trigger toggle 1`] = `
223223
aria-labelledby="grp-1"
224224
class="pf-v6-c-nav__subnav"
225225
hidden=""
226+
inert=""
226227
>
227228
<ul
228229
class="pf-v6-c-nav__list"
@@ -355,6 +356,7 @@ exports[`Nav Expandable Nav List 1`] = `
355356
aria-labelledby="grp-1"
356357
class="pf-v6-c-nav__subnav"
357358
hidden=""
359+
inert=""
358360
>
359361
<ul
360362
class="pf-v6-c-nav__list"
@@ -486,6 +488,7 @@ exports[`Nav Expandable Nav List with aria label 1`] = `
486488
aria-labelledby="grp-1"
487489
class="pf-v6-c-nav__subnav"
488490
hidden=""
491+
inert=""
489492
>
490493
<h2
491494
class="pf-v6-screen-reader"

0 commit comments

Comments
 (0)