From e725910402563255e385d2af75f9eb13a41ee4f3 Mon Sep 17 00:00:00 2001 From: Marcel Date: Tue, 2 Jun 2026 19:41:15 +0200 Subject: [PATCH] test(activity): migrate ChronikFuerDichBox spec to shared $app/forms mock MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Load-bearing first migration (ADR-012): this is the hardest case — its enhance submit callback actually fires and reads the form result. Replaces the duplicated 23-line interceptor factory with vi.mock('$app/forms', () => ({ ...formsMock })) via $mocks, and the per-test mockFormResult mutation with formsMock.setFormResult({ type: 'failure' }). The reset now comes from the shared module's embedded beforeEach. The existing optimisticMarkRead/optimisticMarkAllRead-on-submit assertions remain as the positive proof the callback fired. Part of #560. Co-Authored-By: Claude Opus 4.8 --- .../ChronikFuerDichBox.svelte.spec.ts | 30 ++----------------- 1 file changed, 3 insertions(+), 27 deletions(-) diff --git a/frontend/src/lib/activity/ChronikFuerDichBox.svelte.spec.ts b/frontend/src/lib/activity/ChronikFuerDichBox.svelte.spec.ts index 8ffd6713..41f1f277 100644 --- a/frontend/src/lib/activity/ChronikFuerDichBox.svelte.spec.ts +++ b/frontend/src/lib/activity/ChronikFuerDichBox.svelte.spec.ts @@ -4,36 +4,12 @@ import { page, userEvent } from 'vitest/browser'; import ChronikFuerDichBox from './ChronikFuerDichBox.svelte'; import type { NotificationItem } from '$lib/notification/notifications.svelte'; +import * as formsMock from '$mocks/$app/forms'; -const mockFormResult = vi.hoisted(() => ({ type: 'success' as string })); - -vi.mock('$app/forms', () => ({ - enhance( - node: HTMLFormElement, - submit?: (opts: { - formData: FormData; - }) => (opts: { - result: { type: string; data?: Record }; - update: () => Promise; - }) => Promise - ) { - const handler = async (e: Event) => { - e.preventDefault(); - const cb = submit?.({ formData: new FormData(node) } as never); - if (typeof cb === 'function') { - await ( - cb as (o: { result: typeof mockFormResult; update: () => Promise }) => Promise - )({ result: mockFormResult, update: async () => {} }); - } - }; - node.addEventListener('submit', handler); - return { destroy: () => node.removeEventListener('submit', handler) }; - } -})); +vi.mock('$app/forms', () => ({ ...formsMock })); afterEach(() => { cleanup(); - mockFormResult.type = 'success'; }); function notif(partial: Partial): NotificationItem { @@ -176,7 +152,7 @@ describe('ChronikFuerDichBox', () => { }); it('shows an accessible error banner when the dismiss action returns a failure', async () => { - mockFormResult.type = 'failure'; + formsMock.setFormResult({ type: 'failure' }); render(ChronikFuerDichBox, { unread: [notif({ id: 'err-1' })], optimisticMarkRead: vi.fn(),