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] Fix double-click issue #1919

Merged
merged 3 commits into from Jun 18, 2021

Conversation

oliviertassinari
Copy link
Member

@oliviertassinari oliviertassinari commented Jun 17, 2021

Fix the double click issue: #1141 (comment). In the recording, you can see that I click twice, and the state stays the same. checked indeterminate is the same state as unchecked indeterminate. In core v5 we removed the visual distinction to match screen readers.

Note that the fix is mostly removing code we don't need* (*assuming it's better to not react to clicks on the checkbox when there are no rows).

I worked on this because #1879 didn't seem to go in a rigorous direction. I'm mostly interested in the test case and isolation. I'm a believer that the quality of the tests ultimately drives the quality of the code.

@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 Jun 17, 2021
expect(getColumnValues(1)).to.deep.equal(['Puma']);
fireEvent.click(selectAll);
// TODO fix, should be only 2
expect(Array.from(apiRef.current.getSelectedRows().keys())).to.deep.equal([0, 1, 2]);
Copy link
Member

Choose a reason for hiding this comment

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

fine to use apiRef to assert the state but your test coverage would be higher if you check the Mui-selected css class on the row

Copy link
Member Author

Choose a reason for hiding this comment

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

True, we can replace it. I had a similar thought last week on another PR. Then realized it was needed because of pagination/virtualization, but here, we don't.

On another note, I didn't use .to.have.keys() as in the other tests because when the test fails, the error message is crap (try removing the change in the source and see how the test behaves on HEAD)

Copy link
Member Author

Choose a reason for hiding this comment

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

but your test coverage would be higher if you check the Mui-selected css class on the row

@dtassone My bad, no we can't, I got trapped 😁. The selected rows 0 and 1 are not visible, they are filtered. I would have needed to assert the "X rows selected" message at the footer.

I'm a believer that the quality of the tests ultimately drives the quality of the code

I was mostly interested in making sure that each bug has its corresponding failing test case. For instance, if we fix 3 bugs, and only cover one with the tests. Something diverges from the standard.

});
expect(getColumnValues(1)).to.deep.equal(['Puma']);
fireEvent.click(selectAll);
// TODO fix, should be only 2
Copy link
Member

Choose a reason for hiding this comment

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

Yup, this will get fixed by removing React.memo after which we get the updated visible rows in GridHeaderCheckbox.

Copy link
Member

@ZeeshanTamboli ZeeshanTamboli left a comment

Choose a reason for hiding this comment

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

Nice removal of unnecessary state usage from GridHeaderCheckbox. Looks good to me!

@oliviertassinari oliviertassinari merged commit a75eb4f into mui:master Jun 18, 2021
@oliviertassinari oliviertassinari deleted the fix-4-checkbox-state branch June 18, 2021 22:44
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.

None yet

3 participants