-
Notifications
You must be signed in to change notification settings - Fork 375
chore(Dropdown next) add testing #8446
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
Conversation
|
Preview: https://patternfly-react-pr-8446.surge.sh A11y report: https://patternfly-react-pr-8446-a11y.surge.sh |
48f35ed to
c71aca7
Compare
wise-king-sullyman
left a comment
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.
🔥 🔥 🔥 really awesome work on this! Just a few small comments.
|
|
||
| const dropdownChildren = <div>Dropdown children</div>; | ||
|
|
||
| test('renders dropdown', async () => { |
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.
It seems like all of the non userEvent tests shouldn't need to be async?
| test('renders passed toggle element', async () => { | ||
| render(<Dropdown toggle={toggleRef => toggle(toggleRef)}>{dropdownChildren}</Dropdown>); | ||
|
|
||
| expect(await screen.findByRole('button')).toBeVisible(); |
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.
| expect(await screen.findByRole('button')).toBeVisible(); | |
| expect(await screen.findByRole('button', { name: 'Dropdown' })).toBeVisible(); |
Nit: I would probably add the name option here. Just so that we know the test isn't a false positive, since we can't do that the typical way because of toggle being a required prop.
| test('passes zIndex to popper', async () => { | ||
| render( | ||
| <Dropdown zIndex={100} toggle={toggleRef => toggle(toggleRef)}> | ||
| {dropdownChildren} | ||
| </Dropdown> | ||
| ); | ||
|
|
||
| expect(await screen.findByText('zIndex: 100')).toBeVisible(); | ||
| }); | ||
|
|
||
| test('passes isOpen to popper', async () => { | ||
| render( | ||
| <Dropdown isOpen toggle={toggleRef => toggle(toggleRef)}> | ||
| {dropdownChildren} | ||
| </Dropdown> | ||
| ); | ||
|
|
||
| expect(await screen.findByText('isOpen: true')).toBeVisible(); | ||
| }); | ||
|
|
||
| test('passes onSelect callback', async () => { | ||
| const user = userEvent.setup(); | ||
|
|
||
| const onSelect = jest.fn(); | ||
| render( | ||
| <Dropdown onSelect={onSelect} toggle={toggleRef => toggle(toggleRef)}> | ||
| {dropdownChildren} | ||
| </Dropdown> | ||
| ); | ||
|
|
||
| const trigger = await screen.findByText('Mock item'); | ||
| await user.click(trigger); | ||
|
|
||
| expect(onSelect).toBeCalledTimes(1); | ||
| }); |
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.
Can you add default behavior tests for these props?
| /* test('onOpenChange is not called when not passed', async () => { | ||
| const user = userEvent.setup(); | ||
| const onOpenChange = jest.fn(); | ||
|
|
||
| render( | ||
| <Dropdown isOpen={true} toggle={toggleRef => toggle(toggleRef)}> | ||
| {dropdownChildren} | ||
| </Dropdown> | ||
| ); | ||
|
|
||
| const dropdown = await screen.findByRole('button'); | ||
| await user.click(dropdown); | ||
| await user.click(document.body); | ||
|
|
||
| await user.click(dropdown); | ||
| await user.keyboard('{Tab}'); | ||
|
|
||
| await user.click(dropdown); | ||
| await user.keyboard('{Escape}'); | ||
|
|
||
| expect(onOpenChange).not.toBeCalled(); | ||
| }); */ |
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.
Rather than have this test commented out I would use test.skip, makes it less likely to be forgotten.
|
|
||
| expect(screen.getByText('description: Test description')).toBeVisible(); | ||
| }); | ||
|
|
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.
Is there a particular reason that you didn't test itemId?
|
|
||
| test('matches snapshot', () => { | ||
| const { asFragment } = render( | ||
| <DropdownItem className="custom-class" description="Test description"> |
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.
You'll probably want to add a ouiaId prop here.
| /* | ||
| pressing enter key on a button calls a click event internally | ||
| so testing for a button click should be suficitient | ||
| */ |
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.
Thanks for adding this note!
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.
| /* | |
| pressing enter key on a button calls a click event internally | |
| so testing for a button click should be suficitient | |
| */ | |
| /* | |
| pressing enter or space key on a button calls a click event internally | |
| so testing for a button click should be sufficient | |
| */ |
There is one difference between clicking via mouse/touch and "clicking" via keyboard, that being with keyboard Enter/Space the first non-disabled dropdown item should receive focus. I don't believe that's something we can test via Cypress, though, since it's reliant on the detail property of the event object.
thatblindgeye
left a comment
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.
This is looking nice! Other than Austin's comments, had a couple more below
packages/react-integration/cypress/integration/dropdownnext.spec.ts
Outdated
Show resolved
Hide resolved
| /* | ||
| pressing enter key on a button calls a click event internally | ||
| so testing for a button click should be suficitient | ||
| */ |
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.
| /* | |
| pressing enter key on a button calls a click event internally | |
| so testing for a button click should be suficitient | |
| */ | |
| /* | |
| pressing enter or space key on a button calls a click event internally | |
| so testing for a button click should be sufficient | |
| */ |
There is one difference between clicking via mouse/touch and "clicking" via keyboard, that being with keyboard Enter/Space the first non-disabled dropdown item should receive focus. I don't believe that's something we can test via Cypress, though, since it's reliant on the detail property of the event object.
ddafffd to
9323963
Compare
|
Can you make the base of you PR "v5" instead of "main" please. Main is now feature frozen. |
What: Closes #7964
Additional issues: #8479