You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
31 lines
1.1 KiB
TypeScript
31 lines
1.1 KiB
TypeScript
import { describe, expect, it } from 'vitest'
|
|
import { groupPulse, lastMonths, type PulseEvent } from '../src/pulse'
|
|
|
|
describe('lastMonths', () => {
|
|
it('returns 12 months ending at the given date, oldest first', () => {
|
|
const m = lastMonths('2026-07-17')
|
|
expect(m).toHaveLength(12)
|
|
expect(m[0]).toBe('2025-08')
|
|
expect(m[11]).toBe('2026-07')
|
|
})
|
|
it('crosses year boundaries correctly', () => {
|
|
expect(lastMonths('2026-01-05', 3)).toEqual(['2025-11', '2025-12', '2026-01'])
|
|
})
|
|
})
|
|
|
|
describe('groupPulse', () => {
|
|
const ev = (lane: number, date: string, id: string): PulseEvent =>
|
|
({ id, lane, date, label: id, tone: 'accent' })
|
|
const months = lastMonths('2026-07-17')
|
|
|
|
it('buckets events by lane and month', () => {
|
|
const g = groupPulse([ev(0, '2026-07-01', 'a'), ev(0, '2026-07-30', 'b'), ev(2, '2025-08-09', 'c')], months)
|
|
expect(g.get('0:11')?.map((e) => e.id)).toEqual(['a', 'b'])
|
|
expect(g.get('2:0')?.map((e) => e.id)).toEqual(['c'])
|
|
})
|
|
it('drops events outside the window', () => {
|
|
const g = groupPulse([ev(1, '2024-01-01', 'old'), ev(1, '2027-01-01', 'future')], months)
|
|
expect(g.size).toBe(0)
|
|
})
|
|
})
|