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();