fix(timeline): drop zero-count segments from the zeitstrahl meta line
A timeline with content in only one category rendered a misleading "0 Briefe" / "0 Ereignisse" segment. Only push a count segment when its count is greater than zero; the grouping label and (when present) the range are unchanged. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -18,8 +18,13 @@ const metaLine = $derived.by(() => {
|
||||
if (meta.firstYear !== null && meta.lastYear !== null) {
|
||||
segments.push(`${meta.firstYear}–${meta.lastYear}`);
|
||||
}
|
||||
segments.push(m.timeline_letters_count({ count: meta.letterCount }));
|
||||
segments.push(m.timeline_events_count({ count: meta.eventCount }));
|
||||
// A zero-count segment ("0 Briefe") reads as a data error — drop it.
|
||||
if (meta.letterCount > 0) {
|
||||
segments.push(m.timeline_letters_count({ count: meta.letterCount }));
|
||||
}
|
||||
if (meta.eventCount > 0) {
|
||||
segments.push(m.timeline_events_count({ count: meta.eventCount }));
|
||||
}
|
||||
segments.push(m.timeline_grouping_date());
|
||||
return segments.join(' · ');
|
||||
});
|
||||
|
||||
@@ -75,4 +75,23 @@ describe('/zeitstrahl page', () => {
|
||||
render(Page, { data: pageData(makeTimelineDTO()) });
|
||||
expect(document.querySelector('[data-testid="timeline-meta"]')).toBeNull();
|
||||
});
|
||||
|
||||
it('drops the letters segment instead of showing "0 Briefe" (REQ-002)', () => {
|
||||
render(Page, {
|
||||
data: pageData(makeTimelineDTO({ years: [makeYear(1914, [event('Geburt')])] }))
|
||||
});
|
||||
const sub = document.querySelector('[data-testid="timeline-meta"]');
|
||||
expect(sub).not.toBeNull();
|
||||
expect(sub?.textContent).not.toContain(m.timeline_letters_count({ count: 0 }));
|
||||
expect(sub?.textContent).toContain(m.timeline_grouping_date());
|
||||
});
|
||||
|
||||
it('drops the events segment instead of showing "0 Ereignisse" (REQ-002)', () => {
|
||||
render(Page, {
|
||||
data: pageData(makeTimelineDTO({ undated: [makeEntry({ documentId: 'u1' })] }))
|
||||
});
|
||||
const sub = document.querySelector('[data-testid="timeline-meta"]');
|
||||
expect(sub).not.toBeNull();
|
||||
expect(sub?.textContent).not.toContain(m.timeline_events_count({ count: 0 }));
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user