|
| 1 | +import { describe, expect, test } from 'vitest'; |
| 2 | +import FontStore from '@react-pdf/font'; |
| 3 | + |
| 4 | +import layout from '../src'; |
| 5 | + |
| 6 | +const fontStore = new FontStore(); |
| 7 | + |
| 8 | +const view = (style: any, props: any = {}): any => ({ |
| 9 | + type: 'VIEW', |
| 10 | + props, |
| 11 | + style, |
| 12 | + box: {}, |
| 13 | + children: [], |
| 14 | +}); |
| 15 | + |
| 16 | +// A trailing minPresenceAhead is the one place the engines diverge: legacy |
| 17 | +// moves the node to its own page, the new engine leaves it in place. That |
| 18 | +// difference tells us which engine ran. |
| 19 | +const doc = (pageProps: any = {}): any => ({ |
| 20 | + type: 'DOCUMENT', |
| 21 | + props: {}, |
| 22 | + children: [ |
| 23 | + { |
| 24 | + type: 'PAGE', |
| 25 | + props: { size: [100, 100], ...pageProps }, |
| 26 | + style: {}, |
| 27 | + box: {}, |
| 28 | + children: [ |
| 29 | + view({ height: 60 }), |
| 30 | + view({ height: 30 }, { minPresenceAhead: 500 }), |
| 31 | + ], |
| 32 | + }, |
| 33 | + ], |
| 34 | +}); |
| 35 | + |
| 36 | +describe('pagination engine selection', () => { |
| 37 | + test('legacy by default', async () => { |
| 38 | + const result = await layout(doc(), fontStore); |
| 39 | + |
| 40 | + expect(result.children).toHaveLength(2); |
| 41 | + }); |
| 42 | + |
| 43 | + test('experimentalPagination opts into the new engine', async () => { |
| 44 | + const result = await layout( |
| 45 | + doc({ experimentalPagination: true }), |
| 46 | + fontStore, |
| 47 | + ); |
| 48 | + |
| 49 | + expect(result.children).toHaveLength(1); |
| 50 | + }); |
| 51 | + |
| 52 | + test('a page layout implies the new engine', async () => { |
| 53 | + const pageLayout = (_: any, children: any[]) => children; |
| 54 | + const result = await layout(doc({ layout: pageLayout }), fontStore); |
| 55 | + |
| 56 | + expect(result.children).toHaveLength(1); |
| 57 | + }); |
| 58 | +}); |
0 commit comments