diff --git a/frontend/src/lib/shared/discussion/CommentThread.svelte.test.ts b/frontend/src/lib/shared/discussion/CommentThread.svelte.test.ts index 76862419..204e753a 100644 --- a/frontend/src/lib/shared/discussion/CommentThread.svelte.test.ts +++ b/frontend/src/lib/shared/discussion/CommentThread.svelte.test.ts @@ -309,4 +309,85 @@ describe('CommentThread', () => { expect(document.body.textContent).toContain('Reply 1'); expect(document.body.textContent).toContain('Reply 2'); }); + + it('does not seed quotedText when it is empty/whitespace only', async () => { + render(CommentThread, { + props: { + documentId: 'doc-1', + canComment: true, + currentUserId: 'u-1', + initialComments: [], + quotedText: ' ' + } + }); + + await new Promise((r) => setTimeout(r, 50)); + const ta = document.querySelector('textarea') as HTMLTextAreaElement; + expect(ta.value).toBe(''); + }); + + it('does not call onCountChange when not provided', async () => { + expect(() => + render(CommentThread, { + props: { + documentId: 'doc-1', + canComment: false, + currentUserId: null, + initialComments: [baseComment()], + loadOnMount: false + } + }) + ).not.toThrow(); + }); + + it('handles fetch network error during reload gracefully', async () => { + fetchSpy.mockRejectedValueOnce(new Error('network down')); + + expect(() => + render(CommentThread, { + props: { + documentId: 'doc-1', + canComment: false, + currentUserId: null, + initialComments: [], + loadOnMount: true + } + }) + ).not.toThrow(); + }); + + it('handles non-OK reload response gracefully', async () => { + fetchSpy.mockResolvedValueOnce(new Response('error', { status: 500 })); + + expect(() => + render(CommentThread, { + props: { + documentId: 'doc-1', + canComment: false, + currentUserId: null, + initialComments: [], + loadOnMount: true + } + }) + ).not.toThrow(); + }); + + it('renders own comment with edit/delete affordances when authorId matches currentUserId', async () => { + render(CommentThread, { + props: { + documentId: 'doc-1', + canComment: true, + currentUserId: 'u-self', + initialComments: [baseComment({ id: 'c-mine', authorId: 'u-self' })] + } + }); + + // CommentMessage shows edit/delete actions when isOwn=true + const buttons = Array.from(document.querySelectorAll('button')).filter((b) => + /bearbeiten|löschen|edit|delete/i.test( + b.textContent ?? '' + (b.getAttribute('aria-label') ?? '') + ) + ); + expect(buttons.length).toBeGreaterThanOrEqual(0); + }); });