import { describe, it, expect, afterEach } from 'vitest'; import { cleanup, render } from 'vitest-browser-svelte'; import { page } from 'vitest/browser'; import DashboardResumeStrip from './DashboardResumeStrip.svelte'; afterEach(() => { cleanup(); localStorage.clear(); }); describe('DashboardResumeStrip', () => { it('renders nothing when no last-visited document in localStorage', async () => { render(DashboardResumeStrip, {}); const strip = page.getByTestId('resume-strip'); await expect.element(strip).not.toBeInTheDocument(); }); it('shows the strip with link when localStorage has a document', async () => { localStorage.setItem( 'familienarchiv.lastVisited', JSON.stringify({ id: 'doc-123', title: 'Geburtsurkunde 1920' }) ); render(DashboardResumeStrip, {}); const strip = page.getByTestId('resume-strip'); await expect.element(strip).toBeInTheDocument(); const link = page.getByRole('link', { name: /Geburtsurkunde 1920/ }); await expect.element(link).toBeInTheDocument(); await expect.element(link).toHaveAttribute('href', '/documents/doc-123'); }); it('uses title fallback text when title is empty', async () => { localStorage.setItem( 'familienarchiv.lastVisited', JSON.stringify({ id: 'doc-456', title: '' }) ); render(DashboardResumeStrip, {}); const strip = page.getByTestId('resume-strip'); await expect.element(strip).toBeInTheDocument(); const link = page.getByRole('link'); await expect.element(link).toHaveAttribute('href', '/documents/doc-456'); }); it('renders nothing when localStorage contains malformed JSON', async () => { localStorage.setItem('familienarchiv.lastVisited', '{not valid json'); render(DashboardResumeStrip, {}); const strip = page.getByTestId('resume-strip'); await expect.element(strip).not.toBeInTheDocument(); }); });