Files
pdfme/packages/common/__tests__/splitRange.test.ts
Kyohei Fukuda 616ace4aed [codex] Add generic split range metadata (#1469)
* refactor(schemas): add generic split range metadata

* refactor(schemas): remove legacy split range fields

* refactor(schemas): polish split range helpers
2026-05-06 11:55:10 +09:00

40 lines
1.1 KiB
TypeScript

import { describe, expect, test } from 'vitest';
import { createDynamicLayoutSplitRange, getDynamicLayoutSplitRange } from '../src/index.js';
import { Schema } from '../src/schema.js';
describe('dynamic layout split range', () => {
test('creates a generic split range', () => {
expect(createDynamicLayoutSplitRange('textLine', 1, 3)).toEqual({
unit: 'textLine',
start: 1,
end: 3,
});
});
test('reads matching ranges and ignores non-matching units', () => {
const schema = {
__splitRange: { unit: 'textLine', start: 2, end: 4 },
};
expect(getDynamicLayoutSplitRange(schema, 'textLine')).toEqual({
start: 2,
end: 4,
});
expect(getDynamicLayoutSplitRange(schema, 'listItem')).toBeUndefined();
});
test('requires non-empty split range units', () => {
const result = Schema.safeParse({
name: 'field',
type: 'text',
content: '',
position: { x: 0, y: 0 },
width: 10,
height: 10,
__splitRange: { unit: '', start: 0 },
});
expect(result.success).toBe(false);
});
});