-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Vitest: use browser mode #3222
Vitest: use browser mode #3222
Conversation
const resizeHandle = frame.locator('[role="columnheader"][aria-colindex="2"] div'); | ||
const { x, y } = (await resizeHandle.boundingBox())!; | ||
await resizeHandle.hover({ | ||
position: { x: 5, y: 5 } |
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.
Need to use a specific position otherwise the resized width is incorrect
@@ -13,7 +28,8 @@ export default defineConfig({ | |||
}, | |||
resolve: { | |||
alias: { | |||
lodash: 'lodash-es' | |||
lodash: isTest ? 'lodash' : 'lodash-es', |
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 this needed?
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.
@testing-library/jest-dom
installs lodash
, can't hurt to keep it.
expect(screen.getByRole('spinbutton', { name: 'col1-editor' })).toHaveValue(1230); | ||
const spy = vi.spyOn(window.HTMLElement.prototype, 'scrollIntoView'); | ||
await userEvent.keyboard('{enter}'); | ||
expect(spy).toHaveBeenCalled(); |
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 did we remove these checks?
expect(screen.getByRole('spinbutton', { name: 'col1-editor' })).toHaveValue(1230);
this checked that when typing on a cell, it opens the editor and the editor receives focus, and we continue typing in the editor
const spy = vi.spyOn(window.HTMLElement.prototype, 'scrollIntoView');
await userEvent.keyboard('{enter}');
expect(spy).toHaveBeenCalled();
this checked that we scrolled back to the cell even if we had scrolled past it (see await scrollGrid({ scrollTop: 2000 });
above)
Maybe we need more comments.
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 think it is better to check the actual row in the view instead of spying on scrollIntoView
test/column/renderEditCell.test.tsx
Outdated
expect(getCellsAtRowIndex(0)).toHaveLength(2); | ||
expect(getRows()[1]).toHaveTextContent('11'); | ||
const editor = screen.getByRole('spinbutton', { name: 'col1-editor' }); | ||
expect(editor).toHaveValue(1230); |
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.
Not sure what the new checks are for
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.
Basically we select the first cell and then scroll to the bottom. When we enable the editor (userEvent.keyboard('123');
) then the grid should scroll back to the top so I am checking
expect(getRows()[1]).toHaveTextContent('11');
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.
getRows()[1]
gets the second rendered row, no? Not necessarily the true "second" row.
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.
Correct. Is it not enough to check the second rendered row? We just want to ensure the editor is visible
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.
May be we can use something like toBeVisible
🤔
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 can just check grid.scrollTop
Co-authored-by: Nicolas Stepien <[email protected]>
Co-authored-by: Nicolas Stepien <[email protected]>
expect(getGrid()).toHaveStyle({ gridTemplateColumns: '100px 327.703px' }); | ||
}); | ||
|
||
test('should use the maxWidth if specified on auto resize', async () => { |
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.
Could also test minWidth
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 will add it in the nest PR
#3547
Using the new browser mode to run test in a real browser
https://vitest.dev/guide/browser.html
https://vitest.dev/guide/browser/interactivity-api.html
I think we should check all the tests if we can improve them now that they are running in a real browser.