feat(#145): add DashboardNeedsMetadata widget component

Shows documents with missing metadata as a dashboard widget with links
to the enrich workflow. Renders nothing when the list is empty.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Marcel
2026-03-29 00:40:48 +01:00
parent 2ce95f2542
commit 1d08522df8
2 changed files with 87 additions and 0 deletions

View File

@@ -0,0 +1,38 @@
<script lang="ts">
type IncompleteDocumentDTO = {
id: string;
title: string;
};
interface Props {
incompleteDocs: IncompleteDocumentDTO[];
}
let { incompleteDocs }: Props = $props();
</script>
{#if incompleteDocs.length > 0}
<div
data-testid="dashboard-needs-metadata"
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">
Metadaten fehlen
</h2>
{#each incompleteDocs as doc (doc.id)}
<div class="border-brand-sand flex items-center border-b py-2 last:border-0">
<a
href="/enrich/{doc.id}"
class="font-serif text-sm text-ink hover:text-brand-navy hover:underline"
>
{doc.title}
</a>
</div>
{/each}
<div class="mt-4">
<a href="/enrich" class="font-sans text-xs text-brand-navy/60 hover:text-brand-navy">
Alle anzeigen
</a>
</div>
</div>
{/if}

View File

@@ -0,0 +1,49 @@
import { describe, it, expect, afterEach } from 'vitest';
import { cleanup, render } from 'vitest-browser-svelte';
import { page } from 'vitest/browser';
import DashboardNeedsMetadata from './DashboardNeedsMetadata.svelte';
afterEach(cleanup);
type IncompleteDocumentDTO = {
id: string;
title: string;
};
function makeDoc(id: string, title: string): IncompleteDocumentDTO {
return { id, title };
}
describe('DashboardNeedsMetadata', () => {
it('renders nothing when incompleteDocs is empty', async () => {
render(DashboardNeedsMetadata, { incompleteDocs: [] });
const widget = page.getByTestId('dashboard-needs-metadata');
await expect.element(widget).not.toBeInTheDocument();
});
it('shows the widget when incompleteDocs are present', async () => {
render(DashboardNeedsMetadata, { incompleteDocs: [makeDoc('d1', 'Taufschein')] });
const widget = page.getByTestId('dashboard-needs-metadata');
await expect.element(widget).toBeInTheDocument();
});
it('renders a link to /enrich/{id} for each document', async () => {
const docs = [makeDoc('d1', 'Taufschein'), makeDoc('d2', 'Heiratsurkunde')];
render(DashboardNeedsMetadata, { incompleteDocs: docs });
const links = page.getByRole('link');
await expect.element(links.nth(0)).toHaveAttribute('href', '/enrich/d1');
await expect.element(links.nth(1)).toHaveAttribute('href', '/enrich/d2');
});
it('shows the document title in each row', async () => {
render(DashboardNeedsMetadata, { incompleteDocs: [makeDoc('d1', 'Sterbeurkunde 1930')] });
await expect.element(page.getByText('Sterbeurkunde 1930')).toBeInTheDocument();
});
it('shows a "Alle anzeigen" link to /enrich', async () => {
render(DashboardNeedsMetadata, { incompleteDocs: [makeDoc('d1', 'Dok')] });
const allLink = page.getByRole('link', { name: /Alle anzeigen/i });
await expect.element(allLink).toHaveAttribute('href', '/enrich');
});
});