Files
familienarchiv/frontend/src/lib/shared/dashboard/ReaderStatsStrip.svelte.spec.ts
Marcel aabaa78f4d feat(dashboard): add reader dashboard components
Adds 5 new components for the permission-gated reader layout:
- ReaderStatsStrip: stat tiles (documents / persons / stories) linking to list pages
- ReaderPersonChips: top-N persons by doc count with avatar + name
- ReaderDraftsModule: blog draft list for BLOG_WRITE users
- ReaderRecentDocs: 5 most-recently-updated docs with Neu/Aktualisiert badge
- ReaderRecentStories: 3 latest published stories with 150-char HTML-stripped excerpt

Each component ships with a vitest-browser spec covering the key assertions.
Avatar color/initials logic is inlined to satisfy $lib/shared → $lib/person
boundary rule.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-07 21:39:35 +02:00

38 lines
1.4 KiB
TypeScript

import { describe, it, expect, afterEach } from 'vitest';
import { cleanup, render } from 'vitest-browser-svelte';
import { page } from 'vitest/browser';
import ReaderStatsStrip from './ReaderStatsStrip.svelte';
afterEach(() => {
cleanup();
});
describe('ReaderStatsStrip', () => {
it('renders a link to /documents', async () => {
render(ReaderStatsStrip, { documents: 42, persons: 7, stories: 3 });
const link = page.getByRole('link', { name: /42/ });
await expect.element(link).toHaveAttribute('href', '/documents');
});
it('renders a link to /persons', async () => {
render(ReaderStatsStrip, { documents: 42, persons: 7, stories: 3 });
const link = page.getByRole('link', { name: /7/ });
await expect.element(link).toHaveAttribute('href', '/persons');
});
it('renders a link to /geschichten', async () => {
render(ReaderStatsStrip, { documents: 42, persons: 7, stories: 3 });
const link = page.getByRole('link', { name: /3/ });
await expect.element(link).toHaveAttribute('href', '/geschichten');
});
it('shows "—" when documents count is null', async () => {
render(ReaderStatsStrip, { documents: null, persons: null, stories: null });
const links = page.getByRole('link');
await expect.element(links.first()).toBeInTheDocument();
const text = ((await links.first().element()) as HTMLElement).textContent;
expect(text).toContain('—');
});
});