test(timeline): add failing dateLabel facade spec
Red phase for the timeline date-label helper. Asserts delegation to the shared formatDocumentDate (localized DAY de/en, SEASON de, same-year RANGE) and the null cases for UNKNOWN/empty eventDate. The runtime mock path keeps the `.js` suffix so it matches the import under test. Refs #778 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
60
frontend/src/lib/timeline/dateLabel.spec.ts
Normal file
60
frontend/src/lib/timeline/dateLabel.spec.ts
Normal file
@@ -0,0 +1,60 @@
|
||||
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
||||
import { getLocale } from '$lib/paraglide/runtime.js';
|
||||
import { formatDocumentDate } from '$lib/shared/utils/documentDate';
|
||||
import { timelineDateLabel } from './dateLabel';
|
||||
|
||||
// The mocked path MUST include the `.js` suffix to match the import in
|
||||
// dateLabel.ts — a specifier mismatch silently skips the mock and the helper
|
||||
// would resolve the real locale.
|
||||
vi.mock('$lib/paraglide/runtime.js', () => ({ getLocale: vi.fn(() => 'de') }));
|
||||
|
||||
describe('timelineDateLabel', () => {
|
||||
beforeEach(() => {
|
||||
// Default every test to German; locale-specific tests override below.
|
||||
vi.mocked(getLocale).mockReturnValue('de');
|
||||
});
|
||||
|
||||
it('renders a DAY date localized in German (REQ-001/REQ-002)', () => {
|
||||
const label = timelineDateLabel('1916-07-28', 'DAY');
|
||||
expect(label).toContain('28');
|
||||
expect(label).toContain('Juli');
|
||||
});
|
||||
|
||||
it('renders a DAY date localized in English (REQ-001/REQ-002)', () => {
|
||||
vi.mocked(getLocale).mockReturnValue('en');
|
||||
const label = timelineDateLabel('1916-07-28', 'DAY');
|
||||
expect(label).toContain('July');
|
||||
});
|
||||
|
||||
it('renders a SEASON date with the German season word (REQ-001/REQ-002)', () => {
|
||||
const label = timelineDateLabel('1916-04-01', 'SEASON');
|
||||
expect(label).toContain('Frühling');
|
||||
});
|
||||
|
||||
it('returns null for UNKNOWN precision even with a date (REQ-003)', () => {
|
||||
expect(timelineDateLabel('1916-07-28', 'UNKNOWN')).toBeNull();
|
||||
});
|
||||
|
||||
it('returns null for UNKNOWN precision without a date (REQ-003)', () => {
|
||||
expect(timelineDateLabel(null, 'UNKNOWN')).toBeNull();
|
||||
});
|
||||
|
||||
it('returns null for APPROX with a null eventDate, without calling the formatter (REQ-004)', () => {
|
||||
expect(timelineDateLabel(null, 'APPROX')).toBeNull();
|
||||
});
|
||||
|
||||
it('returns null for DAY with an empty-string eventDate (REQ-004)', () => {
|
||||
expect(timelineDateLabel('', 'DAY')).toBeNull();
|
||||
});
|
||||
|
||||
it('delegates a same-year RANGE to formatDocumentDate (REQ-001/REQ-002)', () => {
|
||||
const expected = formatDocumentDate('1914-01-01', 'RANGE', '1914-11-11', null, 'de');
|
||||
expect(timelineDateLabel('1914-01-01', 'RANGE', '1914-11-11')).toBe(expected);
|
||||
});
|
||||
|
||||
it('treats undefined eventDateEnd identically to null for RANGE (REQ-004)', () => {
|
||||
expect(timelineDateLabel('1914-01-01', 'RANGE', undefined)).toBe(
|
||||
timelineDateLabel('1914-01-01', 'RANGE', null)
|
||||
);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user