Fixed a few minor bugs
This commit is contained in:
27
src/lib/lunch.test.js
Normal file
27
src/lib/lunch.test.js
Normal file
@@ -0,0 +1,27 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { lunchGuidance } from './lunch.js';
|
||||
import { atLocalTime } from './time.js';
|
||||
const at = (time) => atLocalTime('2026-09-07', time);
|
||||
const day = { date: '2026-09-07', status: 'active', plannedEndTs: at('17:30') };
|
||||
const settings = { lunchStart: '12:00', lunchMinutes: 45 };
|
||||
|
||||
describe('lunch clock hints', () => {
|
||||
it('uses the configured lunch time without starting lunch automatically', () => {
|
||||
const entries = [{ kind: 'work', startTs: at('08:00'), endTs: null }];
|
||||
expect(lunchGuidance(day, entries, settings, at('11:59'))).toBeNull();
|
||||
expect(lunchGuidance(day, entries, settings, at('12:00'))).toEqual({ resumeTs: null, due: true });
|
||||
expect(entries[0].endTs).toBeNull();
|
||||
});
|
||||
it('uses the real lunch start and configured duration for the return hint', () => {
|
||||
const entries = [{ kind: 'lunch', startTs: at('12:15'), endTs: null }];
|
||||
expect(lunchGuidance(day, entries, settings, at('12:30'))).toEqual({ resumeTs: at('13:00'), due: false });
|
||||
expect(lunchGuidance(day, entries, settings, at('13:00')).due).toBe(true);
|
||||
expect(entries[0].endTs).toBeNull();
|
||||
});
|
||||
it('stops suggesting lunch after it was taken or after the day ends', () => {
|
||||
const entries = [{ kind: 'lunch', startTs: at('12:00'), endTs: at('12:45') }];
|
||||
expect(lunchGuidance(day, entries, settings, at('14:00'))).toBeNull();
|
||||
expect(lunchGuidance(day, [], settings, at('18:00'))).toBeNull();
|
||||
expect(lunchGuidance({ ...day, status: 'closed' }, [], settings, at('12:00'))).toBeNull();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user