Files

36 lines
1.4 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { expect, test } from 'claude-code/testing'
import { barre, duree, fenetres, ligneFenetre } from './usage'
const T0 = Date.parse('2026-10-31T12:00:00Z')
test('durée avant la remise à zéro', () => {
expect(duree(12 * 60000)).toBe('12 min')
expect(duree(130 * 60000)).toBe('2 h 10')
expect(duree(76 * 3600000)).toBe('3 j 4 h')
})
test('fenêtres 5 h puis hebdo, sans les autres ni une remise à zéro passée', () => {
expect(fenetres([
{ kind: 'seven_day', percentUsed: 18, resetsAt: '2026-10-31T11:00:00Z' },
{ kind: 'spend_limit', percentUsed: 3 },
{ kind: 'five_hour', percentUsed: 42.5, resetsAt: '2026-10-31T14:10:00Z' },
], T0)).toEqual([{ nom: '5 h', pourcent: 42.5, reste: '2 h 10' }, { nom: 'hebdo', pourcent: 18 }])
expect(fenetres([], T0)).toEqual([])
})
test('la barre reste dans sa largeur, même hors de 0 à 100', () => {
expect(barre(50, 10)).toBe('🟩🟩🟩🟩🟩⬛⬛⬛⬛⬛')
expect(barre(130, 4)).toBe('🟥🟥🟥🟥')
expect(barre(-5, 4)).toBe('⬛⬛⬛⬛')
})
test('couleur selon le remplissage', () => {
expect([69.9, 70, 89.9, 90].map(p => barre(p, 1))).toEqual(['🟩', '🟧', '🟧', '🟥'])
})
test('ligne d’une fenêtre', () => {
expect(ligneFenetre({ nom: '5 h', pourcent: 42.5, reste: '2 h 10' }, 4)).toBe('5 h 🟩🟩⬛⬛ 43 % (2 h 10)')
expect(ligneFenetre({ nom: 'hebdo', pourcent: 18 }, 4)).toBe('hebdo 🟩⬛⬛⬛ 18 %')
})