Files
badgedex/test/svg-utils.test.js
T
echomike adcec5f67f
Node.js CI / build (push) Failing after 29m37s
horizontal padding fix
2026-07-17 15:30:06 +02:00

48 lines
1.4 KiB
JavaScript

const { FONT_FAMILY, calcFontSize, estimateTextWidth } = require('../src/lib/svg-utils');
describe('svg-utils', () => {
describe('FONT_FAMILY', () => {
it('should be a non-empty string', () => {
expect(typeof FONT_FAMILY).toBe('string');
expect(FONT_FAMILY.length).toBeGreaterThan(0);
});
it('should contain Verdana', () => {
expect(FONT_FAMILY).toContain('Verdana');
});
});
describe('calcFontSize', () => {
it('should return 60% of size rounded', () => {
expect(calcFontSize(24)).toBe(14);
expect(calcFontSize(100)).toBe(60);
expect(calcFontSize(16)).toBe(10);
});
it('should round correctly', () => {
expect(calcFontSize(25)).toBe(15);
expect(calcFontSize(33)).toBe(20); // 33 * 0.6 = 19.8 → 20
});
});
describe('estimateTextWidth', () => {
it('should estimate width based on text length and font size', () => {
const width = estimateTextWidth('Hello', 14);
// formula: text.length * fontSize * 0.7
expect(width).toBe(5 * 14 * 0.7); // 49
});
it('should return 0 for empty string', () => {
expect(estimateTextWidth('', 14)).toBe(0);
});
it('should scale with font size', () => {
const w1 = estimateTextWidth('test', 10);
const w2 = estimateTextWidth('test', 20);
expect(w1).toBe(4 * 10 * 0.7); // 28
expect(w2).toBe(4 * 20 * 0.7); // 56
});
});
});