import { describe, it, expect } from 'vitest'; import { startTimer, pauseTimer, remainingMs } from '../../src/lib/cooking'; describe('Timestamp-based kitchen timers', () => { it('does not display an extra second when the last render predates the start', () => { expect(remainingMs(startTimer({ remaining: 60000, endAt: null }, 1200), 1000)).toBe(60000); }); it('starts with an absolute deadline, not ticking state', () => { expect(startTimer({ remaining: 60000, endAt: null }, 1000).endAt).toBe(61000); }); it('survives navigation, sleep and serialized progress', () => { const timer = JSON.parse(JSON.stringify(startTimer({ remaining: 60000, endAt: null }, 1000))); expect(remainingMs(timer, 41000)).toBe(20000); expect(remainingMs(timer, 90000)).toBe(0); }); it('pauses precisely and resumes without drift', () => { const paused = pauseTimer(startTimer({ remaining: 60000, endAt: null }, 1000), 21000); expect(remainingMs(paused, 90000)).toBe(40000); expect(remainingMs(startTimer(paused, 90000), 100000)).toBe(30000); }); });