From ac43ef2243c268ba257739df7bb16d14b61ae7e0 Mon Sep 17 00:00:00 2001 From: Marcel Date: Sun, 10 May 2026 03:04:00 +0200 Subject: [PATCH] test(activity): cover ChronikEmptyState branches Three variants (first-run, filter-empty, inbox-zero), title vs body visibility, data-variant attribute, accent vs ink-3 icon coloring. 5 tests, ~15 branches. Refs #496. Co-Authored-By: Claude Sonnet 4.6 --- .../activity/ChronikEmptyState.svelte.test.ts | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 frontend/src/lib/activity/ChronikEmptyState.svelte.test.ts diff --git a/frontend/src/lib/activity/ChronikEmptyState.svelte.test.ts b/frontend/src/lib/activity/ChronikEmptyState.svelte.test.ts new file mode 100644 index 00000000..920a76db --- /dev/null +++ b/frontend/src/lib/activity/ChronikEmptyState.svelte.test.ts @@ -0,0 +1,56 @@ +import { describe, it, expect, afterEach } from 'vitest'; +import { cleanup, render } from 'vitest-browser-svelte'; +import { page } from 'vitest/browser'; +import ChronikEmptyState from './ChronikEmptyState.svelte'; + +afterEach(cleanup); + +describe('ChronikEmptyState', () => { + it('renders the first-run title and body and the clock icon', async () => { + render(ChronikEmptyState, { props: { variant: 'first-run' as const } }); + + await expect.element(page.getByText('Noch nichts geschehen')).toBeVisible(); + await expect.element(page.getByText(/sobald jemand aus der familie/i)).toBeVisible(); + + const wrapper = document.querySelector('[data-testid="chronik-empty-state"]'); + expect(wrapper?.getAttribute('data-variant')).toBe('first-run'); + }); + + it('renders the filter-empty title and body', async () => { + render(ChronikEmptyState, { props: { variant: 'filter-empty' as const } }); + + await expect.element(page.getByText('Nichts in dieser Ansicht')).toBeVisible(); + await expect.element(page.getByText('In diesem Filter gibt es keine Einträge.')).toBeVisible(); + + const wrapper = document.querySelector('[data-testid="chronik-empty-state"]'); + expect(wrapper?.getAttribute('data-variant')).toBe('filter-empty'); + }); + + it('renders the inbox-zero title and no body paragraph', async () => { + render(ChronikEmptyState, { props: { variant: 'inbox-zero' as const } }); + + await expect.element(page.getByText('Keine neuen Erwähnungen')).toBeVisible(); + + // Only one

(the title) since body is empty + const wrapper = document.querySelector('[data-testid="chronik-empty-state"]'); + const paragraphs = wrapper?.querySelectorAll('p'); + expect(paragraphs?.length).toBe(1); + expect(wrapper?.getAttribute('data-variant')).toBe('inbox-zero'); + }); + + it('uses the accent color icon for inbox-zero (vs ink-3 for others)', async () => { + render(ChronikEmptyState, { props: { variant: 'inbox-zero' as const } }); + + const wrapper = document.querySelector('[data-testid="chronik-empty-state"]'); + const svg = wrapper?.querySelector('svg'); + expect(svg?.getAttribute('class')).toContain('text-accent'); + }); + + it('uses the ink-3 color icon for first-run', async () => { + render(ChronikEmptyState, { props: { variant: 'first-run' as const } }); + + const wrapper = document.querySelector('[data-testid="chronik-empty-state"]'); + const svg = wrapper?.querySelector('svg'); + expect(svg?.getAttribute('class')).toContain('text-ink-3'); + }); +});