import { describe, expect, it } from 'vitest' import { beijingDate, overviewRange, overviewRangeOptions } from './overviewRange' describe('overview completed calendar days', () => { it('excludes today and uses exactly fifteen or three days through yesterday', () => { expect(overviewRangeOptions.some(option => option.value === 'TODAY')).toBe(false) expect(overviewRange('LAST_15_DAYS', '2026-10-14')).toEqual({ rangePreset: 'CUSTOM', startDate: '2026-09-29', endDate: '2026-10-13' }) expect(overviewRange('LAST_3_DAYS', '2026-01-02')).toMatchObject({ startDate: '2025-12-30', endDate: '2026-01-01' }) expect(() => overviewRange('TODAY', '2026-10-14')).toThrow() }) it('offers the same four complete-day shortcuts and custom range', () => { expect(overviewRangeOptions.map(option => option.label)).toEqual(['最近3天', '最近7天', '最近15天', '最近30天', '自定义']) expect(overviewRange('LAST_7_DAYS', '2026-10-14')).toMatchObject({ startDate: '2026-10-07', endDate: '2026-10-13' }) expect(overviewRange('LAST_30_DAYS', '2026-10-14')).toMatchObject({ startDate: '2026-09-14', endDate: '2026-10-13' }) }) it('rejects custom today and future, allows yesterday and follows Beijing midnight', () => { expect(() => overviewRange('CUSTOM', '2026-10-14', '2026-10-01', '2026-10-14')).toThrow('最晚为昨日') expect(() => overviewRange('CUSTOM', '2026-10-14', '2026-10-01', '2026-10-15')).toThrow('最晚为昨日') expect(overviewRange('CUSTOM', '2026-10-14', '2026-10-13', '2026-10-13')).toMatchObject({ startDate: '2026-10-13', endDate: '2026-10-13' }) expect(beijingDate(Date.parse('2026-10-13T15:59:59Z'))).toBe('2026-10-13') expect(beijingDate(Date.parse('2026-10-13T16:00:00Z'))).toBe('2026-10-14') }) })