-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
[test] Warn when focusing cells without syncing the state #3486
Conversation
This pull request has conflicts, please resolve those before we can evaluate the pull request. |
This pull request has conflicts, please resolve those before we can evaluate the pull request. |
This pull request has conflicts, please resolve those before we can evaluate the pull request. |
This pull request has conflicts, please resolve those before we can evaluate the pull request. |
This pull request has conflicts, please resolve those before we can evaluate the pull request. |
These are the results for the performance tests:
|
packages/grid/x-data-grid-pro/src/tests/editRows.DataGridPro.test.tsx
Outdated
Show resolved
Hide resolved
This pull request has conflicts, please resolve those before we can evaluate the pull request. |
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.
A big thanks for this PR, it explains why I was struggling to write tests on cell focus yesterday 😅
fireEvent.mouseUp(cell); | ||
fireEvent.click(cell); |
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.
why not fireClickEvent(cell)
?
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.
Maybe we could use mousePress
utility method from the core
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.
mousePress
doesn't work. Some tests fail but I don't know why.
@@ -104,6 +104,7 @@ describe('<DataGridPro /> - Edit Components', () => { | |||
); | |||
|
|||
const cell = getCell(0, 0); | |||
fireEvent.mouseUp(cell); |
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 it necessary?
In cellEditing.DataGridPro.test.tsx
you remove all the cell.focus()
but do not add fireEvent.mouseUp()
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.
Yes, even though it's a double click, it uses the cell that received mouseUp
to update the state. Below, cellParams
is assigned by the mouseUp
listener. If we don't fire it, the focus is never updated.
Previously, every time we had to
fireEvent.keyDown
in a cell, we would usually focus the cell withcell.focus()
first. This approach has the problem that it doesn't sync the focus state, because the grid doesn't listen to thefocus
event, but onlymouseup
andkeyup
. For some simple test cases this is not a problem, however, if the focus moves from one cell to another this might cause an unexpected behavior. Take as example the test I had to modify in #3484:Above we're navigating with the keyboard to the cell 9-2. After the keyboard event, the state is correctly updated to store that 9-2 is the focused cell. The problem comes if we try to focus another cell. For a brief moment it works, but if a rerender occurs in the meantime, the focus gets reset to the value in the state. This PR shows a warning every time that a cell receives focus while the state is not correctly synced. To fix the test above, we can drop
cell.focus()
and simulate a click:If you also need to ensure that a row is not selected when clicking, use
disableSelectionOnClick
or first focus on a column header and navigate with the arrow keys to the desired cell. The alternative to this PR would be to update the focus on thefocus
event, but I don't know if it's worth it to change this now. Thefocus
is always preceded by a click or keyboard event and we already use these events.