test(bulk-upload): add cancel-path coverage for discard-all confirm dialog
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -3,6 +3,7 @@ import { goto } from '$app/navigation';
|
||||
import { cleanup, render } from 'vitest-browser-svelte';
|
||||
import { page, userEvent } from 'vitest/browser';
|
||||
import BulkDocumentEditLayout from './BulkDocumentEditLayout.svelte';
|
||||
import { createConfirmService, CONFIRM_KEY } from '$lib/services/confirm.svelte.js';
|
||||
|
||||
vi.mock('$app/navigation', () => ({ goto: vi.fn() }));
|
||||
|
||||
@@ -289,6 +290,29 @@ describe('BulkDocumentEditLayout', () => {
|
||||
expect(mockFetch).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('discard-all does not clear files when the user cancels the confirm dialog', async () => {
|
||||
const service = createConfirmService();
|
||||
const { container } = render(BulkDocumentEditLayout, {
|
||||
context: new Map([[CONFIRM_KEY, service]])
|
||||
});
|
||||
await addFilesViaInput(container, [makeFile('a.pdf'), makeFile('b.pdf')]);
|
||||
|
||||
const discardBtn = container.querySelector(
|
||||
'button[data-testid="discard-all-btn"]'
|
||||
) as HTMLButtonElement;
|
||||
discardBtn.click();
|
||||
|
||||
// The confirm dialog should open (service.options not null)
|
||||
await vi.waitFor(() => expect(service.options).not.toBeNull(), { timeout: 1000 });
|
||||
|
||||
// Cancel — files should remain
|
||||
service.settle(false);
|
||||
await vi.waitFor(
|
||||
() => expect(container.querySelector('[data-testid="file-switcher-strip"]')).not.toBeNull(),
|
||||
{ timeout: 1000 }
|
||||
);
|
||||
});
|
||||
|
||||
it('discard-all resets to N=0 state and shows drop zone', async () => {
|
||||
const { container } = render(BulkDocumentEditLayout, {});
|
||||
await addFilesViaInput(container, [makeFile('a.pdf'), makeFile('b.pdf')]);
|
||||
|
||||
Reference in New Issue
Block a user