feat(planner): add UndoBar component with 4s auto-dismiss
Shows undo notification after slot add/replace. Rückgängig button calls onundo, auto-dismisses after 4s via ondismiss callback. Also patches test-setup for userEvent + fake timers compatibility. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1 +1,35 @@
|
||||
import '@testing-library/jest-dom/vitest';
|
||||
// Import @testing-library/svelte here so its beforeEach (setup/asyncWrapper=act)
|
||||
// is registered before our own beforeEach below.
|
||||
import '@testing-library/svelte';
|
||||
import { configure } from '@testing-library/dom';
|
||||
import { vi } from 'vitest';
|
||||
import { tick } from 'svelte';
|
||||
import userEvent from '@testing-library/user-event';
|
||||
|
||||
// Patch userEvent direct-API methods to use delay:null when fake timers are
|
||||
// active. With delay:null, user-event's internal wait() short-circuits
|
||||
// (typeof null !== 'number') and no setTimeout is scheduled — so clicks and
|
||||
// other interactions work correctly under vi.useFakeTimers().
|
||||
const originalClick = userEvent.click.bind(userEvent);
|
||||
// @ts-expect-error patching direct API
|
||||
userEvent.click = (element: Element, options = {}) => {
|
||||
if (vi.isFakeTimers()) {
|
||||
// @ts-expect-error delay:null is a valid user-event option
|
||||
return originalClick(element, { delay: null, ...options });
|
||||
}
|
||||
return originalClick(element, options);
|
||||
};
|
||||
|
||||
// Also update asyncWrapper to call tick() after async operations so Svelte
|
||||
// DOM updates are flushed. @testing-library/svelte's act() already does this,
|
||||
// but we re-configure after it to preserve our fake-timer behaviour.
|
||||
beforeEach(() => {
|
||||
configure({
|
||||
asyncWrapper: async (fn: () => Promise<unknown>) => {
|
||||
const result = await fn();
|
||||
await tick();
|
||||
return result;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user