From 169e1ad9de06879f027acbae63eabeb534adbd03 Mon Sep 17 00:00:00 2001 From: Marcel Date: Sat, 6 Jun 2026 17:54:25 +0200 Subject: [PATCH] test(search): cover smart-mode chip lifecycle hooks (#739) SearchFilterBar drives chip-clearing via onModeToggle (mode switch) and onSmartSearch (new query); pin that callback contract. Co-Authored-By: Claude Opus 4.8 --- .../src/routes/SearchFilterBar.svelte.spec.ts | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/frontend/src/routes/SearchFilterBar.svelte.spec.ts b/frontend/src/routes/SearchFilterBar.svelte.spec.ts index 446cd046..fa389d8c 100644 --- a/frontend/src/routes/SearchFilterBar.svelte.spec.ts +++ b/frontend/src/routes/SearchFilterBar.svelte.spec.ts @@ -195,3 +195,39 @@ describe('SearchFilterBar – tagQ live filter', () => { vi.unstubAllGlobals(); }); }); + +describe('SearchFilterBar – smart-mode chip lifecycle hooks', () => { + // The interpretation chips live in the result area (parent page). SearchFilterBar + // drives chip-clearing through callbacks: onModeToggle (mode switch) and + // onSmartSearch (new query). These tests pin that contract. + it('invokes onModeToggle when toggling back to keyword mode (parent clears chips)', async () => { + const onModeToggle = vi.fn(); + render(SearchFilterBar, { + ...defaultProps, + sort: 'DATE', + dir: 'desc', + smartMode: true, + onModeToggle + }); + await page.getByRole('button', { name: /KI/ }).click(); + expect(onModeToggle).toHaveBeenCalledOnce(); + }); + + it('invokes onSmartSearch when a new query is submitted in smart mode (parent resets chips)', async () => { + const onSmartSearch = vi.fn(); + render(SearchFilterBar, { + ...defaultProps, + sort: 'DATE', + dir: 'desc', + smartMode: true, + onSmartSearch + }); + const input = page.getByPlaceholder('Titel, Personen, Tags durchsuchen…'); + await input.fill('Walter im Krieg'); + await input.click(); + (document.activeElement as HTMLElement).dispatchEvent( + new KeyboardEvent('keydown', { key: 'Enter', bubbles: true }) + ); + await vi.waitFor(() => expect(onSmartSearch).toHaveBeenCalled()); + }); +});