-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: enhance test coverage for toast
- Loading branch information
Showing
3 changed files
with
182 additions
and
144 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
packages/react/src/toast/__tests__/ToastController.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { screen } from '@testing-library/react'; | ||
import userEvent from '@testing-library/user-event'; | ||
import { render } from '@tonic-ui/react/test-utils/render'; | ||
import { Toast, ToastController } from '@tonic-ui/react/src'; | ||
|
||
jest.useFakeTimers(); | ||
|
||
describe('ToastController', () => { | ||
test('pauses timeout on mouse enter and resumes on mouse leave', async () => { | ||
const user = userEvent.setup({ | ||
// Disable action delay to allow `await user.hover(element)` to complete immediately | ||
// Reference: https://github.com/testing-library/user-event/issues/833 | ||
delay: null, | ||
}); | ||
const onClose = jest.fn(); | ||
const duration = 5000; | ||
|
||
render( | ||
<ToastController | ||
duration={duration} | ||
onClose={onClose} | ||
> | ||
<Toast data-testid="toast"> | ||
This is a toast | ||
</Toast> | ||
</ToastController> | ||
); | ||
|
||
const toast = screen.getByTestId('toast'); | ||
|
||
// Simulate mouse enter, which should pause the timeout | ||
await user.hover(toast); | ||
|
||
// Timeout should be paused | ||
jest.advanceTimersByTime(duration); | ||
expect(onClose).not.toHaveBeenCalled(); | ||
|
||
// Simulate mouse leave, which should resume the timeout | ||
await user.unhover(toast); | ||
|
||
// Timeout should be resumed | ||
jest.advanceTimersByTime(duration); | ||
expect(onClose).toHaveBeenCalled(); | ||
}); | ||
}); |
142 changes: 0 additions & 142 deletions
142
packages/react/src/toast/__tests__/ToastTransitionGroup.js
This file was deleted.
Oops, something went wrong.