Files
familienarchiv/frontend/src/lib/shared/dashboard/ReaderRecentDocs.svelte.test.ts
Marcel 2e0f85c360
All checks were successful
CI / Semgrep Security Scan (pull_request) Successful in 20s
CI / Compose Bucket Idempotency (pull_request) Successful in 1m2s
CI / Unit & Component Tests (pull_request) Successful in 3m50s
CI / OCR Service Tests (pull_request) Successful in 24s
CI / Backend Unit Tests (pull_request) Successful in 3m50s
CI / fail2ban Regex (pull_request) Successful in 43s
fix(review): address reviewer concerns from PR #661
- Replace brittle createdAt===updatedAt isNew() check with a 7-day
  recency window (created within last 7 days = new)
- Add createdAt/updatedAt to searchItem fixture in page.server.spec.ts
  and assert they are propagated to recentDocs
- Replace null timestamps in DocumentListItem test fixtures with a fixed
  LocalDateTime to satisfy the @Schema(required) contract

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-25 15:08:04 +02:00

98 lines
2.8 KiB
TypeScript

import { describe, it, expect, afterEach } from 'vitest';
import { cleanup, render } from 'vitest-browser-svelte';
import { page } from 'vitest/browser';
import ReaderRecentDocs from './ReaderRecentDocs.svelte';
afterEach(cleanup);
const makeDoc = (overrides: Record<string, unknown> = {}) => ({
id: 'd1',
title: 'Brief 1923',
createdAt: '2026-04-15T10:00:00Z',
updatedAt: '2026-04-15T10:00:00Z',
sender: { id: 's1', firstName: 'Anna', lastName: 'Schmidt', displayName: 'Anna Schmidt' },
...overrides
});
describe('ReaderRecentDocs', () => {
it('renders the heading', async () => {
render(ReaderRecentDocs, { props: { documents: [] } });
await expect
.element(page.getByRole('heading', { name: /zuletzt aktualisiert/i }))
.toBeVisible();
});
it('renders the all-documents link', async () => {
render(ReaderRecentDocs, { props: { documents: [] } });
await expect
.element(page.getByRole('link', { name: /alle dokumente/i }))
.toHaveAttribute('href', '/documents');
});
it('renders the New badge when document was created within the last 7 days', async () => {
const recentDate = new Date(Date.now() - 2 * 24 * 60 * 60 * 1000).toISOString();
const laterUpdate = new Date(Date.now() - 1 * 24 * 60 * 60 * 1000).toISOString();
render(ReaderRecentDocs, {
props: {
documents: [makeDoc({ createdAt: recentDate, updatedAt: laterUpdate })]
}
});
await expect.element(page.getByText('Neu')).toBeVisible();
});
it('hides the New badge when document was created more than 7 days ago', async () => {
render(ReaderRecentDocs, {
props: {
documents: [
makeDoc({
createdAt: '2026-04-15T10:00:00Z',
updatedAt: '2026-04-15T10:00:00Z'
})
]
}
});
await expect.element(page.getByText('Neu')).not.toBeInTheDocument();
});
it('renders the sender displayName', async () => {
render(ReaderRecentDocs, { props: { documents: [makeDoc()] } });
await expect.element(page.getByText('Anna Schmidt')).toBeVisible();
});
it('falls back to em-dash when sender is null', async () => {
render(ReaderRecentDocs, {
props: { documents: [makeDoc({ sender: null })] }
});
expect(document.body.textContent).toContain('—');
});
it('falls back to lastName when displayName is missing', async () => {
render(ReaderRecentDocs, {
props: {
documents: [
makeDoc({
sender: { id: 's1', firstName: 'Anna', lastName: 'Schmidt', displayName: null }
})
]
}
});
await expect.element(page.getByText(/Schmidt/)).toBeVisible();
});
it('renders the document link to /documents/{id}', async () => {
render(ReaderRecentDocs, { props: { documents: [makeDoc({ id: 'd-42' })] } });
const links = document.querySelectorAll('a[href^="/documents/"]');
expect(
Array.from(links).some((a) => (a as HTMLAnchorElement).href.includes('/documents/d-42'))
).toBe(true);
});
});