mirror of
https://github.com/pdfme/pdfme.git
synced 2026-06-03 03:40:51 -04:00
* refactor(schemas): add generic split range metadata * refactor(schemas): remove legacy split range fields * refactor(schemas): polish split range helpers
40 lines
1.1 KiB
TypeScript
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);
|
|
});
|
|
});
|