spb/spbgit Public MIT
SPB Git — the platform hosting itself
JavaScript 73.9%
CSS 11.7%
Nunjucks 11.6%
Shell 2.7%
1/**2 * ─────────────────────────────────────────────3 * SPB Git — Personal Git Platform4 * ─────────────────────────────────────────────5 * Author : Simon-Pierre Boucher6 * Contact : contact@spboucher.ai7 * File : test/unit/activity.test.mjs8 * Purpose : Unit tests — contribution calendar building9 * License : MIT © Simon-Pierre Boucher10 * ─────────────────────────────────────────────11 */1213import { describe, it, expect } from 'vitest';14import { bucketByDay, buildCalendar, calendarSvg } from '../../src/stats/activity.mjs';1516describe('bucketByDay', () => {17 it('groups unix timestamps by UTC day', () => {18 const noon = Date.UTC(2026, 0, 15, 12) / 1000;19 const evening = Date.UTC(2026, 0, 15, 22) / 1000;20 const nextDay = Date.UTC(2026, 0, 16, 1) / 1000;21 const days = bucketByDay([noon, evening, nextDay]);22 expect(days.get('2026-01-15')).toBe(2);23 expect(days.get('2026-01-16')).toBe(1);24 });25});2627describe('buildCalendar', () => {28 it('builds 52 weeks ending today with levels 0-4', () => {29 const today = new Date(Date.UTC(2026, 7, 9));30 const days = new Map([31 ['2026-08-09', 12],32 ['2026-08-08', 3],33 ['2026-08-01', 1],34 ]);35 const cal = buildCalendar(days, today);36 expect(cal.weeks).toHaveLength(52);37 expect(cal.total).toBe(16);38 expect(cal.max).toBe(12);39 const flat = cal.weeks.flat().filter(Boolean);40 const busiest = flat.find((d) => d.date === '2026-08-09');41 expect(busiest.level).toBe(4);42 const light = flat.find((d) => d.date === '2026-08-01');43 expect(light.level).toBe(1);44 // Last cell of the grid is today.45 expect(flat[flat.length - 1].date).toBe('2026-08-09');46 });47});4849describe('calendarSvg', () => {50 it('renders an accessible SVG with tooltips', () => {51 const cal = buildCalendar(new Map([['2026-08-09', 2]]), new Date(Date.UTC(2026, 7, 9)));52 const svg = calendarSvg(cal);53 expect(svg).toContain('<svg');54 expect(svg).toContain('role="img"');55 expect(svg).toContain('<title>2 commits on 2026-08-09</title>');56 });57});58