mirror of
https://github.com/olehomelchenko/astrolabe.git
synced 2026-08-08 10:12:34 +00:00
Add durable toasts with an inline action button
This commit is contained in:
@@ -171,6 +171,45 @@ describe('Toaster exit animation (two-phase dismiss)', () => {
|
||||
vi.useRealTimers();
|
||||
});
|
||||
|
||||
test('a durable toast does not auto-dismiss, and its action runs then dismisses it', () => {
|
||||
vi.useFakeTimers();
|
||||
const onClick = vi.fn();
|
||||
let id: string;
|
||||
act(() => {
|
||||
id = useNotificationStore.getState().notify({
|
||||
kind: 'info',
|
||||
title: 'Update available',
|
||||
message: 'A new version is ready.',
|
||||
durable: true,
|
||||
action: { label: 'Reload', onClick },
|
||||
});
|
||||
root.render(<Toaster />);
|
||||
});
|
||||
|
||||
// Well past the auto-dismiss window — still present (durable).
|
||||
act(() => {
|
||||
vi.advanceTimersByTime(60000);
|
||||
});
|
||||
expect(useNotificationStore.getState().notifications.some((n) => n.id === id!)).toBe(true);
|
||||
|
||||
// The action button runs the handler, then the toast exits.
|
||||
const actionBtn = Array.from(container.querySelectorAll('button')).find(
|
||||
(b) => b.textContent === 'Reload',
|
||||
);
|
||||
expect(actionBtn).toBeTruthy();
|
||||
act(() => {
|
||||
actionBtn!.dispatchEvent(new MouseEvent('click', { bubbles: true }));
|
||||
});
|
||||
expect(onClick).toHaveBeenCalledTimes(1);
|
||||
|
||||
act(() => {
|
||||
vi.advanceTimersByTime(TOAST_EXIT_MS);
|
||||
});
|
||||
expect(useNotificationStore.getState().notifications.some((n) => n.id === id!)).toBe(false);
|
||||
|
||||
vi.useRealTimers();
|
||||
});
|
||||
|
||||
test('clicking close twice does not reset the exit timer', () => {
|
||||
vi.useFakeTimers();
|
||||
let id: string;
|
||||
|
||||
Reference in New Issue
Block a user