feat(#145): add DashboardRecentDocuments widget component
Shows recently reviewed documents as a dashboard widget with formatted dates. Renders nothing when the list is empty. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
48
frontend/src/lib/components/DashboardRecentDocuments.svelte
Normal file
48
frontend/src/lib/components/DashboardRecentDocuments.svelte
Normal file
@@ -0,0 +1,48 @@
|
||||
<script lang="ts">
|
||||
type Document = {
|
||||
id: string;
|
||||
title: string;
|
||||
documentDate?: string;
|
||||
sender?: { id: string; firstName: string; lastName: string };
|
||||
};
|
||||
|
||||
interface Props {
|
||||
recentDocs: Document[];
|
||||
}
|
||||
|
||||
let { recentDocs }: Props = $props();
|
||||
|
||||
function formatDate(dateStr: string): string {
|
||||
return new Intl.DateTimeFormat('de-DE', {
|
||||
day: 'numeric',
|
||||
month: 'long',
|
||||
year: 'numeric'
|
||||
}).format(new Date(dateStr + 'T12:00:00'));
|
||||
}
|
||||
</script>
|
||||
|
||||
{#if recentDocs.length > 0}
|
||||
<div data-testid="dashboard-recent-docs" class="border-brand-sand rounded-sm border bg-white p-6">
|
||||
<h2 class="mb-4 font-sans text-xs font-bold tracking-widest text-gray-400 uppercase">
|
||||
Zuletzt hinzugefügt
|
||||
</h2>
|
||||
{#each recentDocs as doc (doc.id)}
|
||||
<div class="border-brand-sand flex items-center justify-between border-b py-2 last:border-0">
|
||||
<a
|
||||
href="/documents/{doc.id}"
|
||||
class="font-serif text-sm text-ink hover:text-brand-navy hover:underline"
|
||||
>
|
||||
{doc.title}
|
||||
</a>
|
||||
{#if doc.documentDate}
|
||||
<span
|
||||
data-testid="doc-date-{doc.id}"
|
||||
class="ml-2 shrink-0 font-sans text-xs text-gray-400"
|
||||
>
|
||||
{formatDate(doc.documentDate)}
|
||||
</span>
|
||||
{/if}
|
||||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
{/if}
|
||||
@@ -0,0 +1,57 @@
|
||||
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);
|
||||
|
||||
type Document = {
|
||||
id: string;
|
||||
title: string;
|
||||
documentDate?: string;
|
||||
sender?: { id: string; firstName: string; lastName: string };
|
||||
};
|
||||
|
||||
function makeDoc(id: string, title: string, date?: string): Document {
|
||||
return { id, title, documentDate: date };
|
||||
}
|
||||
|
||||
describe('DashboardRecentDocuments', () => {
|
||||
it('renders nothing when recentDocs is empty', async () => {
|
||||
render(DashboardRecentDocuments, { recentDocs: [] });
|
||||
const widget = page.getByTestId('dashboard-recent-docs');
|
||||
await expect.element(widget).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('shows the widget when recentDocs are present', async () => {
|
||||
render(DashboardRecentDocuments, { recentDocs: [makeDoc('d1', 'Taufschein')] });
|
||||
const widget = page.getByTestId('dashboard-recent-docs');
|
||||
await expect.element(widget).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('renders a link to /documents/{id} for each document', async () => {
|
||||
const docs = [makeDoc('d1', 'Taufschein'), makeDoc('d2', 'Heiratsurkunde')];
|
||||
render(DashboardRecentDocuments, { recentDocs: docs });
|
||||
const links = page.getByRole('link');
|
||||
await expect.element(links.nth(0)).toHaveAttribute('href', '/documents/d1');
|
||||
await expect.element(links.nth(1)).toHaveAttribute('href', '/documents/d2');
|
||||
});
|
||||
|
||||
it('shows the document title in each row', async () => {
|
||||
render(DashboardRecentDocuments, {
|
||||
recentDocs: [makeDoc('d1', 'Sterbeurkunde 1930', '1930-05-12')]
|
||||
});
|
||||
await expect.element(page.getByText('Sterbeurkunde 1930')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('formats and displays the document date when present', async () => {
|
||||
render(DashboardRecentDocuments, { recentDocs: [makeDoc('d1', 'Dok', '1945-04-20')] });
|
||||
// The date should be visible in some formatted form
|
||||
const widget = page.getByTestId('dashboard-recent-docs');
|
||||
await expect.element(widget).toBeInTheDocument();
|
||||
// Just verify the date element exists (not exact format due to locale)
|
||||
const dateEl = page.getByTestId('doc-date-d1');
|
||||
await expect.element(dateEl).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user