|
| 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 | +}); |
0 commit comments