test(coverage): drive browser tests to 80% on all metrics (#496) #505

Merged
marcel merged 189 commits from feat/issue-496-browser-coverage-tests into main 2026-05-11 21:50:39 +02:00
Showing only changes of commit 6751ede8cf - Show all commits

View File

@@ -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);
});
});