Skip to content

Conversation

@dominik-petrik
Copy link
Contributor

@dominik-petrik dominik-petrik commented Dec 14, 2022

What: Closes #7964

Additional issues: #8479

@dominik-petrik dominik-petrik marked this pull request as draft December 14, 2022 18:02
@patternfly-build
Copy link
Contributor

patternfly-build commented Dec 14, 2022

@dominik-petrik dominik-petrik marked this pull request as ready for review January 3, 2023 15:05
Copy link
Contributor

@wise-king-sullyman wise-king-sullyman left a 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 () => {
Copy link
Contributor

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();
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
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.

Comment on lines 116 to 166
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);
});
Copy link
Contributor

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?

Comment on lines 155 to 176
/* 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();
}); */
Copy link
Contributor

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();
});

Copy link
Contributor

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">
Copy link
Contributor

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.

Comment on lines 41 to 44
/*
pressing enter key on a button calls a click event internally
so testing for a button click should be suficitient
*/
Copy link
Contributor

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!

Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
/*
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.

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.

This is looking nice! Other than Austin's comments, had a couple more below

Comment on lines 41 to 44
/*
pressing enter key on a button calls a click event internally
so testing for a button click should be suficitient
*/
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
/*
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.

@tlabaj
Copy link
Contributor

tlabaj commented Jan 31, 2023

Can you make the base of you PR "v5" instead of "main" please. Main is now feature frozen.

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.

Dropdown Next: add testing

5 participants