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

[DataGrid] Prevents bubbling in menu header #3000

Merged
merged 6 commits into from
Nov 3, 2021

Conversation

alexfauquette
Copy link
Member

@alexfauquette alexfauquette commented Oct 27, 2021

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.

Copy link
Member

@m4theushw m4theushw left a 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?

@alexfauquette alexfauquette changed the title prevent bubbling in menu header [DataGrid] Prevents bubbling in menu header Oct 27, 2021
@alexfauquette alexfauquette self-assigned this Oct 27, 2021
@alexfauquette
Copy link
Member Author

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']));
Copy link
Member

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

Suggested change
await waitFor(() => expect(getColumnValues(0)).to.deep.equal(['Nike', 'Adidas', 'Puma']));
expect(getColumnValues(0)).to.deep.equal(['Nike', 'Adidas', 'Puma']);

Copy link
Member Author

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?

Copy link
Member

@oliviertassinari oliviertassinari Oct 29, 2021

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.

Copy link
Member

@oliviertassinari oliviertassinari Oct 29, 2021

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.

Copy link
Member

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.

Copy link
Member Author

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?

Copy link
Member

@oliviertassinari oliviertassinari Oct 30, 2021

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.

@oliviertassinari oliviertassinari added bug 🐛 Something doesn't work component: data grid This is the name of the generic UI component, not the React module! labels Oct 28, 2021
Copy link
Member

@m4theushw m4theushw left a 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

@alexfauquette alexfauquette merged commit 9fbc568 into mui:next Nov 3, 2021
@alexfauquette alexfauquette deleted the issue-1721 branch November 3, 2021 13:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Something doesn't work component: data grid This is the name of the generic UI component, not the React module!
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[DataGrid] Add option to stop bubbling of column headersort direction change event
3 participants