Skip to content
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

Components: Fix no-node-access violations in Popover #46311

Merged
merged 1 commit into from
Dec 6, 2022

Conversation

tyxla
Copy link
Member

@tyxla tyxla commented Dec 5, 2022

What?

With the recent work to improve the quality of tests, we fixed a bunch of ESLint rule violations. This PR fixes a no-node-access rule violation in the Popover component.

Why?

The end goal is to enable that ESLint rule once all violations have been fixed.

How?

We're using a screen query instead of element.parentElement. For this purpose, we add a data-testid to the Popover element.

Testing Instructions

Verify all tests still pass.

@tyxla tyxla added [Type] Code Quality Issues or PRs that relate to code quality [Package] Components /packages/components labels Dec 5, 2022
@tyxla tyxla requested a review from ajitbohra as a code owner December 5, 2022 15:08
@tyxla tyxla self-assigned this Dec 5, 2022
Copy link
Member

@mirka mirka left a comment

Choose a reason for hiding this comment

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

Nit: I wonder if something like <Popover role="dialog"> (and then query by role) is a more realistic spec of what needs to happen. In a sense, for this "focus on mount" feature to be at all useful, three things need to be true:

  • A role can be applied
  • The element with that role is an ancestor of the popover content
  • The element with that role is going to be focused

expect( screen.getByTestId( 'popover-element' ) ).toHaveFocus() kind of circumvents the assertion of the relationship between the popover content and the focused element.

@tyxla
Copy link
Member Author

tyxla commented Dec 6, 2022

@mirka from my understanding, we can do that, but for someone looking at the test later it could create a false assumption that the Popover always has the dialog role, which isn't always the case. By using data-testid in the test fixture, we're clear enough that this is just for the means of the test.

@tyxla tyxla merged commit 968652c into trunk Dec 6, 2022
@tyxla tyxla deleted the fix/no-node-access-popover-tests branch December 6, 2022 15:02
@github-actions github-actions bot added this to the Gutenberg 14.8 milestone Dec 6, 2022
mpkelly pushed a commit to mpkelly/gutenberg that referenced this pull request Dec 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Package] Components /packages/components [Type] Code Quality Issues or PRs that relate to code quality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants