import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; import { pausedUntilLabel, timeAgo } from './time'; describe('timeAgo', () => { beforeEach(() => { vi.useFakeTimers(); vi.setSystemTime(new Date('2026-10-03T12:00:00Z')); }); afterEach(() => vi.useRealTimers()); it.each([ ['2026-10-03T11:59:30Z', 'just now'], ['2026-10-03T11:55:00Z', '5m ago'], ['2026-10-03T09:00:00Z', '3h ago'], ['2026-09-30T12:00:00Z', '3d ago'], ['2026-10-03T12:00:10Z', 'just now'], // slight clock skew into the future ])('%s → %s', (iso, expected) => { expect(timeAgo(iso)).toBe(expected); }); }); describe('pausedUntilLabel', () => { const now = new Date(2026, 9, 3, 14, 0); it('says "until you turn it back on" for indefinite pauses', () => { expect(pausedUntilLabel(new Date(2126, 0, 1).toISOString(), now)).toBe('until you turn it back on'); }); it('shows a time for today and "tomorrow" past midnight', () => { expect(pausedUntilLabel(new Date(2026, 9, 3, 15, 0).toISOString(), now)).toMatch(/^until \d/); expect(pausedUntilLabel(new Date(2026, 9, 4, 1, 0).toISOString(), now)).toMatch(/^until tomorrow /); }); });