openpencil/tests/engine/render/canvas/component-label-text.test.ts
2026-05-18 03:11:48 +03:00

27 lines
836 B
TypeScript

import { describe, expect, test } from 'bun:test'
import { ellipsizeLabelText } from '#core/canvas/labels/text'
const fixedWidthFont = {
getGlyphIDs(text: string) {
return [...text].map((_, index) => index)
},
getGlyphWidths(glyphs: number[]) {
return glyphs.map(() => 10)
}
} as Parameters<typeof ellipsizeLabelText>[0]
describe('label text', () => {
test('keeps labels that fit inside the component width', () => {
expect(ellipsizeLabelText(fixedWidthFont, 'Button', 60)).toBe('Button')
})
test('ellipsizes labels that exceed the component width', () => {
expect(ellipsizeLabelText(fixedWidthFont, 'Very long component', 55)).toBe('Very…')
})
test('returns only ellipsis when only the ellipsis fits', () => {
expect(ellipsizeLabelText(fixedWidthFont, 'Component', 10)).toBe('…')
})
})