@@ -29,17 +29,21 @@ describe('svg-utils', () => {
|
||||
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
|
||||
// formula: text.length * fontSize * 0.65 + fontSize * 0.8
|
||||
expect(width).toBe(5 * 14 * 0.65 + 14 * 0.8); // 56.7
|
||||
});
|
||||
|
||||
it('should return 0 for empty string', () => {
|
||||
expect(estimateTextWidth('', 14)).toBe(0);
|
||||
it('should include padding for empty string', () => {
|
||||
// Even empty strings get the base padding
|
||||
expect(estimateTextWidth('', 14)).toBe(14 * 0.8); // 11.2
|
||||
});
|
||||
|
||||
it('should scale linearly with font size', () => {
|
||||
it('should scale with font size', () => {
|
||||
const w1 = estimateTextWidth('test', 10);
|
||||
const w2 = estimateTextWidth('test', 20);
|
||||
expect(w2).toBe(w1 * 2);
|
||||
// w1 = 4*10*0.65 + 10*0.8 = 34
|
||||
// w2 = 4*20*0.65 + 20*0.8 = 68
|
||||
expect(w2).toBe(68);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user