diff --git a/frontend/e2e/persons.spec.ts b/frontend/e2e/persons.spec.ts index 736e7fee..3aca3b51 100644 --- a/frontend/e2e/persons.spec.ts +++ b/frontend/e2e/persons.spec.ts @@ -125,6 +125,29 @@ test.describe('Person detail — sent and received documents', () => { await expect(page.getByRole('heading', { name: /Empfangene Dokumente/i })).toBeVisible(); await page.screenshot({ path: 'test-results/e2e/person-sent-received.png' }); }); + + test('shows year range next to document count when documents have dates', async ({ page }) => { + // Navigate to the first person who has documents with dates + await page.goto('/persons'); + const personLinks = page.locator('a[href^="/persons/"]:not([href="/persons/new"])'); + const count = await personLinks.count(); + + for (let i = 0; i < count; i++) { + await page.goto('/persons'); + await personLinks.nth(i).click(); + await page.waitForSelector('[data-hydrated]'); + + // Check if either section heading has a year range (4 digits) + const sentHeading = page.getByRole('heading', { name: /Gesendete Dokumente/i }).locator('..'); + const hasYearRange = await sentHeading.locator('span').filter({ hasText: /\d{4}/ }).count(); + if (hasYearRange > 0) { + await expect(sentHeading.locator('span').filter({ hasText: /\d{4}/ }).first()).toBeVisible(); + await page.screenshot({ path: 'test-results/e2e/person-year-range.png' }); + return; + } + } + // If no person has dated documents, the test is a no-op (year range is optional) + }); }); test.describe('Person detail — conversations link', () => { diff --git a/frontend/src/routes/persons/[id]/+page.svelte b/frontend/src/routes/persons/[id]/+page.svelte index c88269cd..01b2dfff 100644 --- a/frontend/src/routes/persons/[id]/+page.svelte +++ b/frontend/src/routes/persons/[id]/+page.svelte @@ -24,15 +24,18 @@ const allDocuments = $derived([...sentDocuments, ...receivedDocuments]); - const docStats = $derived(() => { - const dated = allDocuments.filter(d => d.documentDate); - const years = dated.map(d => parseInt(d.documentDate!.substring(0, 4))); - return { - total: allDocuments.length, - minYear: years.length ? Math.min(...years) : null, - maxYear: years.length ? Math.max(...years) : null, - }; - }); + function yearRange(docs: typeof sentDocuments) { + const years = docs + .filter(d => d.documentDate) + .map(d => parseInt(d.documentDate!.substring(0, 4))); + if (!years.length) return null; + const min = Math.min(...years); + const max = Math.max(...years); + return min === max ? `${min}` : `${min} – ${max}`; + } + + const sentYearRange = $derived(yearRange(sentDocuments)); + const receivedYearRange = $derived(yearRange(receivedDocuments)); const coCorrespondents = $derived(() => { const freq = new Map(); @@ -327,21 +330,6 @@ {/if} - - {#if docStats().total > 0} -
- {docStats().total} Dokumente - {#if docStats().minYear !== null} - · - {#if docStats().minYear === docStats().maxYear} - {docStats().minYear} - {:else} - {docStats().minYear} – {docStats().maxYear} - {/if} - {/if} -
- {/if} - {#if allDocuments.length > 0}
@@ -362,6 +350,9 @@ {sentDocuments.length} + {#if sentYearRange} + {sentYearRange} + {/if}
{#if sentDocuments.length === 0} @@ -423,6 +414,9 @@ {receivedDocuments.length} + {#if receivedYearRange} + {receivedYearRange} + {/if} {#if receivedDocuments.length === 0}