From 068c2ef256bcd2f0fcbdcbf98961613cac57a189 Mon Sep 17 00:00:00 2001 From: Marcel Date: Sat, 13 Jun 2026 23:21:07 +0200 Subject: [PATCH] fix(document): render full date for precision-less document chips A TimelineEvent's DocumentRef carries documentDate but no precision, so formatDocumentOption hit formatDocumentDate's undefined-precision path and surfaced the UNKNOWN label instead of the date. Default a missing precision to DAY so the chip shows the full date; add formatDocumentOption unit specs. Addresses PR #832 review (#781). Co-Authored-By: Claude Opus 4.8 --- .../lib/document/documentTypeahead.spec.ts | 20 +++++++++++++++++++ .../src/lib/document/documentTypeahead.ts | 5 ++++- 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 frontend/src/lib/document/documentTypeahead.spec.ts diff --git a/frontend/src/lib/document/documentTypeahead.spec.ts b/frontend/src/lib/document/documentTypeahead.spec.ts new file mode 100644 index 00000000..fa13beca --- /dev/null +++ b/frontend/src/lib/document/documentTypeahead.spec.ts @@ -0,0 +1,20 @@ +import { describe, expect, it } from 'vitest'; +import { formatDocumentOption, type DocumentOption } from './documentTypeahead'; + +describe('formatDocumentOption', () => { + it('returns the bare title when no documentDate is present', () => { + const doc: DocumentOption = { id: 'd1', title: 'Brief ohne Datum' }; + expect(formatDocumentOption(doc)).toBe('Brief ohne Datum'); + }); + + // #781: a TimelineEvent's DocumentRef carries documentDate but no precision. + // Missing precision must degrade to the full date (DAY), never the UNKNOWN label. + it('renders the full date when precision is absent (DocumentRef chip)', () => { + const doc: DocumentOption = { id: 'd1', title: 'Umzugsbrief', documentDate: '1925-04-01' }; + const label = formatDocumentOption(doc); + expect(label.startsWith('Umzugsbrief · ')).toBe(true); + expect(label).toContain('1925'); + // The undefined-precision fallback would otherwise surface the UNKNOWN word. + expect(label.toLowerCase()).not.toContain('unbekannt'); + }); +}); diff --git a/frontend/src/lib/document/documentTypeahead.ts b/frontend/src/lib/document/documentTypeahead.ts index 1b32fa78..4815bea9 100644 --- a/frontend/src/lib/document/documentTypeahead.ts +++ b/frontend/src/lib/document/documentTypeahead.ts @@ -42,9 +42,12 @@ export function createDocumentTypeahead() { export function formatDocumentOption(doc: DocumentOption): string { if (!doc.documentDate) return doc.title; + // A DocumentRef (#781 timeline chips) carries documentDate but no precision — + // default to DAY so the full date renders, rather than the UNKNOWN fallback + // formatDocumentDate would otherwise hit for an undefined precision. const label = formatDocumentDate( doc.documentDate, - doc.metaDatePrecision as DatePrecision, + (doc.metaDatePrecision as DatePrecision) ?? 'DAY', doc.metaDateEnd, null, getLocale()