test suit updated
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
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);
|
||||
expect(width).toBe(5 * 14 * 0.6); // 42
|
||||
});
|
||||
|
||||
it('should return 0 for empty string', () => {
|
||||
expect(estimateTextWidth('', 14)).toBe(0);
|
||||
});
|
||||
|
||||
it('should scale linearly with font size', () => {
|
||||
const w1 = estimateTextWidth('test', 10);
|
||||
const w2 = estimateTextWidth('test', 20);
|
||||
expect(w2).toBe(w1 * 2);
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user