-
Notifications
You must be signed in to change notification settings - Fork 381
feat(navigation) - add inert attribute to NavExpandable #11749
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| import { render, screen } from '@testing-library/react'; | ||
| import userEvent from '@testing-library/user-event'; | ||
| import '@testing-library/jest-dom'; | ||
| import { NavExpandable } from '../NavExpandable'; | ||
| import { NavItem } from '../NavItem'; | ||
| import { Nav, NavContext } from '../Nav'; | ||
| import { NavList } from '../NavList'; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So for the purposes of this set of unit tests, we don't need any of these other Nav components. We really only want to test that NavExpandable behaves/works the way we expect. Sometimes that does involve importing other components/creating mocks, but for the tests relevant to this PR we can get away wthout them.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh great, reduced the code by a lot. I am new to writing tests so learning a lot. |
||
|
|
||
| const props = { | ||
| items: [ | ||
| { to: '#link1', label: 'Link 1' }, | ||
| { to: '#link2', label: 'Link 2' }, | ||
| { to: '#link3', label: 'Link 3' } | ||
| ] | ||
| }; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can remove this object |
||
|
|
||
| describe('NavExpandable', () => { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Currently I think we rarely use the describe block in our revamped tests; I personally try to use it more to separate out lengthy amounts of tests that can be grouped together. For now I think we can remove the describe block and just have each test on its own. |
||
| beforeEach(() => { | ||
| jest.resetAllMocks(); | ||
| }); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We shouldn't need this here |
||
|
|
||
| test('check that inert is on the section element by default', () => { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For the 2 tests here, with the above comments taken into account, we can slim down the code written:
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Got it, will make the necessary changes. |
||
| render( | ||
| <Nav onSelect={jest.fn()} onToggle={jest.fn()}> | ||
| <NavList> | ||
| <NavExpandable id="grp-1" title="Expandable group" data-testid="test-id"> | ||
| {props.items.map((item) => ( | ||
| <NavItem to={item.to} key={item.to}> | ||
| {item.label} | ||
| </NavItem> | ||
| ))} | ||
| </NavExpandable> | ||
| </NavList> | ||
| </Nav> | ||
| ); | ||
| const wrapper = screen.getByTestId('test-id'); | ||
| const section = wrapper.querySelector('.pf-v6-c-nav__subnav'); | ||
| expect(section).toHaveAttribute('inert', ''); | ||
| }); | ||
|
|
||
| test('check that inert is NOT on the section when isExpanded is true', () => { | ||
| render( | ||
| <Nav onSelect={jest.fn()} onToggle={jest.fn()}> | ||
| <NavList> | ||
| <NavExpandable id="grp-1" title="Expandable group" isExpanded={true} data-testid="test-id"> | ||
| {props.items.map((item) => ( | ||
| <NavItem to={item.to} key={item.to}> | ||
| {item.label} | ||
| </NavItem> | ||
| ))} | ||
| </NavExpandable> | ||
| </NavList> | ||
| </Nav> | ||
| ); | ||
|
|
||
| const wrapper = screen.getByTestId('test-id'); | ||
| const section = wrapper.querySelector('.pf-v6-c-nav__subnav'); | ||
| expect(section).not.toHaveAttribute('inert', ''); | ||
| }); | ||
| }); | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this isn't being used let's remove this import
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was testing some things out with the remaining two tests, missed removing it before pushing changes.