Skip to content

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

Mash707
Copy link
Contributor

@Mash707 Mash707 commented Apr 9, 2025

Closes #11732

@patternfly-build
Copy link
Contributor

patternfly-build commented Apr 9, 2025

@Mash707
Copy link
Contributor Author

Mash707 commented Apr 9, 2025

@thatblindgeye should I also include a cypress test? There was some doubt regarding it in the issue.

Copy link
Contributor

@thatblindgeye thatblindgeye left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One file comment below. As for your question, we could probably handle testing in the unit tests. Ideally off the top of my head we'd want the following tests:

  • check that inert is on the <section> element by default
  • check that inert is NOT on the <section> when isExpanded is true

Then utilizing userEvents:

  • click the expandable toggle to expand it, then tab() and assert that first item is focused
  • click the expandable toggle to collapse it, then tab() and assert that the first item within that section doesn't have focus

We'd also want these to be in a new NavExpandable.test.tsx file. If you have any questions or run into any issues just let me know

@Mash707
Copy link
Contributor Author

Mash707 commented Apr 9, 2025

Thanks for the amazing instructions, will start working on the unit test.

@Mash707 Mash707 force-pushed the navigation-add-inert-attribute branch from 3d1172f to 5992339 Compare April 14, 2025 19:00
@Mash707
Copy link
Contributor Author

Mash707 commented Apr 14, 2025

  • check that inert is on the
    element by default
  • check that inert is NOT on the
    when isExpanded is true

@thatblindgeye I have added tests regarding these two. Let me know what you think

@Mash707 Mash707 requested a review from thatblindgeye April 14, 2025 19:04
Copy link
Contributor

@thatblindgeye thatblindgeye left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes for the current tests below. I'm also thinking that the other tests I mentioned might make more sense as Cypress integration tests than unit tests. We could use the existing Nav cypress demos to add these tests on, let me know if you have any thoughts or questions about that.

Comment on lines 9 to 15
const props = {
items: [
{ to: '#link1', label: 'Link 1' },
{ to: '#link2', label: 'Link 2' },
{ to: '#link3', label: 'Link 3' }
]
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can remove this object

]
};

describe('NavExpandable', () => {
Copy link
Contributor

Choose a reason for hiding this comment

The 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.

Comment on lines 18 to 20
beforeEach(() => {
jest.resetAllMocks();
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We shouldn't need this here

Comment on lines 5 to 7
import { NavItem } from '../NavItem';
import { Nav, NavContext } from '../Nav';
import { NavList } from '../NavList';
Copy link
Contributor

Choose a reason for hiding this comment

The 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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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.

@@ -0,0 +1,60 @@
import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
Copy link
Contributor

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

Copy link
Contributor Author

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.

jest.resetAllMocks();
});

test('check that inert is on the section element by default', () => {
Copy link
Contributor

Choose a reason for hiding this comment

The 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:

  • Let's update the test names similar to how other revamped tests we have, along the lines of "Renders with the inert attribute by default" and "Does not render with the intert attribute when isExpanded is true".
  • For the render method, let's just pass a NavExpandable with a title prop passed in
  • For the expect, we can use the getByLabelText matcher using the string you pass to the title prop and then assert that the inert attribute is/isn't there.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it, will make the necessary changes.

@Mash707
Copy link
Contributor Author

Mash707 commented Apr 20, 2025

I'm also thinking that the other tests I mentioned might make more sense as Cypress integration tests than unit tests. We could use the existing Nav cypress demos to add these tests on, let me know if you have any thoughts or questions about that.

I also think Cypress tests would be better since we have interactions like clicking and tabbing. I'll work on a draft and would be happy to get it reviewed.

@nicolethoen nicolethoen self-requested a review April 21, 2025 14:42
});

test('Does not render with the inert attribute when isExpanded is true', () => {
render(<NavExpandable id="grp-1" title="NavExpandable" isExpanded={true}></NavExpandable>);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tiny nit, for these boolean props we don't need to pass a truthy value in like this, as just isExpanded on its own will suffice.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Navigation - add inert attribute to content within a collapsed group
3 participants