import { describe, expect, it } from 'vitest'; import { fitFontSize } from './fit'; const options = { available: 500, preferred: 36, minimum: 20 }; describe('fitFontSize', () => { it('keeps the preferred size when the text is short', () => { expect(fitFontSize('10:00 – 18:30', options)).toBe(36); }); it('shrinks a long line rather than letting it wrap', () => { // Three periods, none on a round hour: the case that overflowed. const crowded = '09:30 – 12:00 · 13:30 – 16:00 · 17:00 – 19:30'; const size = fitFontSize(crowded, options); expect(size).toBeLessThan(36); expect(size * crowded.length * 0.54).toBeLessThanOrEqual(options.available); }); it('never goes below the floor, however long the text', () => { expect(fitFontSize('a'.repeat(500), options)).toBe(20); }); it('keeps the preferred size for empty text', () => { expect(fitFontSize('', options)).toBe(36); }); it('returns whole pixels', () => { expect(Number.isInteger(fitFontSize('10:00 – 13:00 · 14:00', options))).toBe(true); }); it('gives more room a larger size', () => { const narrow = fitFontSize('10:00 – 13:00 · 14:00 – 18:30', { ...options, available: 300 }); const wide = fitFontSize('10:00 – 13:00 · 14:00 – 18:30', { ...options, available: 700 }); expect(wide).toBeGreaterThan(narrow); }); });