mirror of
https://github.com/immich-app/immich.git
synced 2025-12-11 17:23:13 +03:00
- Rename classes: DayGroup → TimelineDay, MonthGroup → TimelineMonth - Use short variable names: dayGroup → day, monthGroup → month - Update all method names and properties for consistency - Convert relative imports to $lib alias convention No functional changes.
90 lines
2.7 KiB
TypeScript
90 lines
2.7 KiB
TypeScript
import { locale } from '$lib/stores/preferences.store';
|
|
import { parseUtcDate } from '$lib/utils/date-time';
|
|
import { formatDayTitle, toISOYearMonthUTC } from '$lib/utils/timeline-util';
|
|
import { DateTime } from 'luxon';
|
|
|
|
describe('formatDayTitle', () => {
|
|
beforeAll(() => {
|
|
vi.useFakeTimers();
|
|
process.env.TZ = 'UTC';
|
|
vi.setSystemTime(new Date('2024-07-27T12:00:00Z'));
|
|
});
|
|
|
|
afterAll(() => {
|
|
vi.useRealTimers();
|
|
delete process.env.TZ;
|
|
});
|
|
|
|
it('formats today', () => {
|
|
const date = parseUtcDate('2024-07-27T01:00:00Z');
|
|
locale.set('en');
|
|
expect(formatDayTitle(date)).toBe('today');
|
|
locale.set('es');
|
|
expect(formatDayTitle(date)).toBe('hoy');
|
|
});
|
|
|
|
it('formats yesterday', () => {
|
|
const date = parseUtcDate('2024-07-26T23:59:59Z');
|
|
locale.set('en');
|
|
expect(formatDayTitle(date)).toBe('yesterday');
|
|
locale.set('fr');
|
|
expect(formatDayTitle(date)).toBe('hier');
|
|
});
|
|
|
|
it('formats last week', () => {
|
|
const date = parseUtcDate('2024-07-21T00:00:00Z');
|
|
locale.set('en');
|
|
expect(formatDayTitle(date)).toBe('Sunday');
|
|
locale.set('ar-SA');
|
|
expect(formatDayTitle(date)).toBe('الأحد');
|
|
});
|
|
|
|
it('formats date 7 days ago', () => {
|
|
const date = parseUtcDate('2024-07-20T00:00:00Z');
|
|
locale.set('en');
|
|
expect(formatDayTitle(date)).toBe('Sat, Jul 20');
|
|
locale.set('de');
|
|
expect(formatDayTitle(date)).toBe('Sa., 20. Juli');
|
|
});
|
|
|
|
it('formats date this year', () => {
|
|
const date = parseUtcDate('2020-01-01T00:00:00Z');
|
|
locale.set('en');
|
|
expect(formatDayTitle(date)).toBe('Wed, Jan 1, 2020');
|
|
locale.set('ja');
|
|
expect(formatDayTitle(date)).toBe('2020年1月1日(水)');
|
|
});
|
|
|
|
it('formats future date', () => {
|
|
const tomorrow = parseUtcDate('2024-07-28T00:00:00Z');
|
|
locale.set('en');
|
|
expect(formatDayTitle(tomorrow)).toBe('Sun, Jul 28');
|
|
|
|
const nextMonth = parseUtcDate('2024-08-28T00:00:00Z');
|
|
locale.set('en');
|
|
expect(formatDayTitle(nextMonth)).toBe('Wed, Aug 28');
|
|
|
|
const nextYear = parseUtcDate('2025-01-10T12:00:00Z');
|
|
locale.set('en');
|
|
expect(formatDayTitle(nextYear)).toBe('Fri, Jan 10, 2025');
|
|
});
|
|
|
|
it('returns "Invalid DateTime" when date is invalid', () => {
|
|
const date = DateTime.invalid('test');
|
|
locale.set('en');
|
|
expect(formatDayTitle(date)).toBe('Invalid DateTime');
|
|
locale.set('es');
|
|
expect(formatDayTitle(date)).toBe('Invalid DateTime');
|
|
});
|
|
});
|
|
|
|
describe('toISOYearMonthUTC', () => {
|
|
it('should prefix year with 0s', () => {
|
|
expect(toISOYearMonthUTC({ year: 28, month: 1 })).toBe('0028-01-01T00:00:00.000Z');
|
|
});
|
|
|
|
it('should prefix month with 0s', () => {
|
|
expect(toISOYearMonthUTC({ year: 2025, month: 1 })).toBe('2025-01-01T00:00:00.000Z');
|
|
});
|
|
});
|