From 9f7c9cd7c2b0a6c71048a34f1431941a6c61cc36 Mon Sep 17 00:00:00 2001 From: Marcel Date: Sun, 10 May 2026 02:10:03 +0200 Subject: [PATCH] test(dashboard): cover DashboardRecentDocuments branches Empty list early return, heading + per-doc row rendering, title link href, date visibility tied to updatedAt, stats footnote presence toggled by stats.totalDocuments. 7 tests covering ~16 of the dashboard section's branches. Refs #496. Co-Authored-By: Claude Sonnet 4.6 --- .../DashboardRecentDocuments.svelte.test.ts | 71 +++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 frontend/src/lib/shared/dashboard/DashboardRecentDocuments.svelte.test.ts diff --git a/frontend/src/lib/shared/dashboard/DashboardRecentDocuments.svelte.test.ts b/frontend/src/lib/shared/dashboard/DashboardRecentDocuments.svelte.test.ts new file mode 100644 index 00000000..f42d0c58 --- /dev/null +++ b/frontend/src/lib/shared/dashboard/DashboardRecentDocuments.svelte.test.ts @@ -0,0 +1,71 @@ +import { describe, it, expect, afterEach } from 'vitest'; +import { cleanup, render } from 'vitest-browser-svelte'; +import { page } from 'vitest/browser'; +import DashboardRecentDocuments from './DashboardRecentDocuments.svelte'; + +afterEach(cleanup); + +const makeDoc = (overrides: Record = {}) => ({ + id: 'd1', + title: 'Brief 1923', + updatedAt: '2026-04-15T10:00:00Z', + ...overrides +}); + +describe('DashboardRecentDocuments', () => { + it('renders nothing when recentDocs is empty', async () => { + render(DashboardRecentDocuments, { props: { recentDocs: [] } }); + + expect(document.querySelector('[data-testid="dashboard-recent-docs"]')).toBeNull(); + }); + + it('renders the heading and one row per doc', async () => { + render(DashboardRecentDocuments, { + props: { recentDocs: [makeDoc({ id: 'd1', title: 'A' }), makeDoc({ id: 'd2', title: 'B' })] } + }); + + await expect.element(page.getByRole('heading', { name: /zuletzt aktiv/i })).toBeVisible(); + expect(document.querySelectorAll('[data-testid^="doc-row-"]').length).toBe(2); + }); + + it('renders the title as a link to the document detail', async () => { + render(DashboardRecentDocuments, { props: { recentDocs: [makeDoc()] } }); + + await expect + .element(page.getByRole('link', { name: 'Brief 1923' })) + .toHaveAttribute('href', '/documents/d1'); + }); + + it('renders the formatted date when updatedAt is present', async () => { + render(DashboardRecentDocuments, { props: { recentDocs: [makeDoc()] } }); + + expect(document.querySelector('[data-testid="doc-date-d1"]')).not.toBeNull(); + }); + + it('omits the date when updatedAt is undefined', async () => { + render(DashboardRecentDocuments, { + props: { recentDocs: [makeDoc({ updatedAt: undefined })] } + }); + + expect(document.querySelector('[data-testid="doc-date-d1"]')).toBeNull(); + }); + + it('renders the stats footnote when stats.totalDocuments is set', async () => { + render(DashboardRecentDocuments, { + props: { + recentDocs: [makeDoc()], + stats: { totalDocuments: 50, totalPersons: 12 } as unknown as never + } + }); + + const footnote = document.querySelector('[data-testid="dashboard-stats-footnote"]'); + expect(footnote?.textContent).toContain('50'); + expect(footnote?.textContent).toContain('12'); + }); + + it('omits the stats footnote when stats is null', async () => { + render(DashboardRecentDocuments, { props: { recentDocs: [makeDoc()], stats: null } }); + + expect(document.querySelector('[data-testid="dashboard-stats-footnote"]')).toBeNull(); + }); +});