-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
[DataGrid] Prevents bubbling in menu header #3000
Conversation
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.
Looks good. Could you add at least two test cases: 1. ensuring that when [role="menu"]
receives a click, it won't change the sort and 2. ensuring that when "Sort by ASC" it does change the sort? You can use as example: /~https://github.com/mui-org/material-ui-x/blob/0512a1399cf42c2257d72462a9161f23efac0b20/packages/grid/x-grid/src/tests/columnHeaders.DataGridPro.test.tsx#L44 and /~https://github.com/mui-org/material-ui-x/blob/0512a1399cf42c2257d72462a9161f23efac0b20/packages/grid/data-grid/src/tests/sorting.DataGrid.test.tsx#L78-L80
The PR title should follow the pattern [Component] Imperative commit message
. Could you fix it?
1632943
to
d874714
Compare
Test added, And I confirm the first one "should not modify column order when menu is clicked" catch the bug (It does not pass on master) :) |
const menuList = screen.queryByRole('menu'); | ||
fireEvent.click(menuList); | ||
|
||
await waitFor(() => expect(getColumnValues(0)).to.deep.equal(['Nike', 'Adidas', 'Puma'])); |
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 the main upside of running the tests in the same JavaScript runtime as the component we don't need to wait in the large majority of the cases. Here, it runs synchronously. (fireEvent.click wraps the action with a React. act that tell him to be synchronous).
await waitFor(() => expect(getColumnValues(0)).to.deep.equal(['Nike', 'Adidas', 'Puma'])); | |
expect(getColumnValues(0)).to.deep.equal(['Nike', 'Adidas', 'Puma']); |
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.
OK, I observed that test break if I remove waitFor
to test that "menu" has been removed.
Is that because removing the menu first trigger an animation, and then delete the html element?
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.
Regarding the menu, we don't mock the time for it, so we have to wait for the transition to start. It's a different case.
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's probably this one /~https://github.com/reactjs/react-transition-group/blob/5aa3fd2d7e3354a7e42505d55af605ff44f74e2e/src/Transition.js#L326 that prevents us to be writing the test synchronously.
In the main repo, we mock the time for it.
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.
There're several other cases where we wait for the translation instead of mocking the time: /~https://github.com/mui-org/material-ui-x/blob/adc0468e18044f34cdffe7a084cfdab2f45bab62/packages/grid/data-grid/src/tests/rows.DataGrid.test.tsx#L208
I think we can leave as it is and fix this the other tests in a another PR.
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.
Sounds good to me. I open an issue for smoking time pointing to @oliviertassinari comment for mocking time, and merge this PR?
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.
My first comment was really about using async/await to its strict minimum. We removed the await on the get column value, which is synchronous, great.
I would recommend we revert the changes on the tests that are not related to the bug we go after. I personally think that it's OK-ish it use waitFor with the menu transition.
packages/grid/x-grid/src/tests/columnHeaders.DataGridPro.test.tsx
Outdated
Show resolved
Hide resolved
This is not recognized by GitHub: https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword |
c3bef60
to
aad7a15
Compare
aad7a15
to
8761534
Compare
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 pushed two commits to improve the tests. Always give preference to getByRole
/ queryByRole
because doing that we are also checking that the UI is accessible: https://testing-library.com/docs/queries/about#priority
Fix #1721
This prevents bubbling events to the menu header. The bubbling was problematic when people click on a modal, the event reach the menu header, and so modified the sorting.