import { describe, it, expect } from 'vitest'; import { countStreakDays } from './streak.js'; const S = (...d: string[]) => new Set(d); const NONE = new Set(); describe('countStreakDays', () => { it('zählt aufeinanderfolgende volle Werktage', () => { // Mi/Di/Mo voll, heute Mi expect( countStreakDays({ today: '2026-06-10', fullDates: S('2026-06-10', '2026-06-09', '2026-06-08'), absenceDates: NONE, }), ).toBe(3); }); it('heute noch nicht reflektiert → Schonfrist (zählt ab gestern)', () => { expect( countStreakDays({ today: '2026-06-10', fullDates: S('2026-06-09', '2026-06-08'), absenceDates: NONE, }), ).toBe(2); }); it('bricht bei einem ausgelassenen Werktag', () => { // 06-09 fehlt expect( countStreakDays({ today: '2026-06-10', fullDates: S('2026-06-10', '2026-06-08'), absenceDates: NONE, }), ).toBe(1); }); it('Wochenende ist neutral (Fr + Mo zählt durch)', () => { // heute Mo 06-08, Fr 06-05 voll; 06-04 (Do) fehlt → 2 expect( countStreakDays({ today: '2026-06-08', fullDates: S('2026-06-08', '2026-06-05'), absenceDates: NONE, }), ).toBe(2); }); it('Abwesenheit ist neutral (überspringen, nicht brechen)', () => { // heute Mi 06-10 voll, Di 06-09 Urlaub, Mo 06-08 voll expect( countStreakDays({ today: '2026-06-10', fullDates: S('2026-06-10', '2026-06-08'), absenceDates: S('2026-06-09'), }), ).toBe(2); }); it('Feiertag bricht die Streak NICHT (Pfingstmontag 25.05.2026)', () => { // heute Mi 05-27, Di 05-26 voll, Mo 05-25 Pfingstmontag, Fr 05-22 voll expect( countStreakDays({ today: '2026-05-27', fullDates: S('2026-05-27', '2026-05-26', '2026-05-22'), absenceDates: NONE, }), ).toBe(3); }); it('Reflexion am Wochenende zählt nicht zu 0 (zählt Freitag)', () => { // heute Sa 06-06, voll am Sa + Fr 06-05; früher nichts expect( countStreakDays({ today: '2026-06-06', fullDates: S('2026-06-06', '2026-06-05'), absenceDates: NONE, }), ).toBe(1); }); it('leere Historie → 0', () => { expect(countStreakDays({ today: '2026-06-10', fullDates: NONE, absenceDates: NONE })).toBe(0); }); });