From 7fc56022ae4c7310be243a6c80fd11ce4f9c48b7 Mon Sep 17 00:00:00 2001 From: Marcel Date: Wed, 29 Apr 2026 01:17:45 +0200 Subject: [PATCH] test(person-mention): assert popup degrades to empty state on fetch reject MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Tester #5506 §4: there was a test for fetch returning ok:false but no test for the broad catch covering thrown rejections (DNS failure, TypeError: Failed to fetch). Pin that path so a future refactor can't accidentally bubble the error and crash the editor. Co-Authored-By: Claude Sonnet 4.6 --- .../PersonMentionEditor.svelte.spec.ts | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/frontend/src/lib/components/PersonMentionEditor.svelte.spec.ts b/frontend/src/lib/components/PersonMentionEditor.svelte.spec.ts index a0c77395..ea8df7fe 100644 --- a/frontend/src/lib/components/PersonMentionEditor.svelte.spec.ts +++ b/frontend/src/lib/components/PersonMentionEditor.svelte.spec.ts @@ -52,6 +52,12 @@ function mockFetchEmpty() { return fetchMock; } +function mockFetchRejects() { + const fetchMock = vi.fn().mockRejectedValue(new TypeError('Failed to fetch')); + vi.stubGlobal('fetch', fetchMock); + return fetchMock; +} + function getTextarea(): HTMLTextAreaElement { return document.querySelector('textarea')!; } @@ -182,6 +188,21 @@ describe('PersonMentionEditor — typeahead', () => { await expect.element(page.getByText('Keine Personen gefunden')).toBeInTheDocument(); }); + it('falls back to the empty state when the typeahead fetch rejects (network error)', async () => { + mockFetchRejects(); + renderHost(); + + const ta = getTextarea(); + ta.focus(); + ta.value = '@Aug'; + ta.selectionStart = 4; + ta.selectionEnd = 4; + ta.dispatchEvent(new Event('input', { bubbles: true })); + await flushDebounce(); + + await expect.element(page.getByText('Keine Personen gefunden')).toBeInTheDocument(); + }); + it('keeps the popup open when the query has a trailing space (multi-word names)', async () => { mockFetchWithPersons(); renderHost();