import { describe, expect, test } from 'vitest';
import { Document, Page, View, Text, Svg, Polygon } from '@react-pdf/renderer';
import renderToImage from './renderComponent';
const text =
'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.';
const mount = async (children, pageProps = {}) => {
const image = await renderToImage(
{children}
,
);
return image;
};
const leftFloat = (pageProps) =>
mount(
{text}
,
pageProps,
);
const rightFloat = (pageProps) =>
mount(
{text}
,
pageProps,
);
const multipleFloats = (pageProps) =>
mount(
{text}
,
pageProps,
);
const splitWrappedText = (pageProps) =>
mount(
<>
Title
{text} {text} {text} {text} {text} {text}
>,
pageProps,
);
const circleShapeOutside = (pageProps) =>
mount(
{text} {text}
,
pageProps,
);
const polygonShapeOutside = (pageProps) =>
mount(
{text} {text}
,
pageProps,
);
const clearElements = (pageProps) =>
mount(
Wrapping text between floats.
clear left
clear both
,
pageProps,
);
describe('float (legacy engine)', () => {
test('should wrap text around left float', async () => {
expect(await leftFloat({})).toMatchImageSnapshot();
});
test('should wrap text around right float', async () => {
expect(await rightFloat({})).toMatchImageSnapshot();
});
test('should wrap text between multiple floats', async () => {
expect(await multipleFloats({})).toMatchImageSnapshot();
});
test('should split wrapped text across pages instead of moving it whole', async () => {
expect(await splitWrappedText({})).toMatchImageSnapshot();
});
test('should position clear elements below floats', async () => {
expect(await clearElements({})).toMatchImageSnapshot();
});
test('should wrap text around circle shape-outside', async () => {
expect(await circleShapeOutside({})).toMatchImageSnapshot();
});
test('should wrap text around polygon shape-outside', async () => {
expect(await polygonShapeOutside({})).toMatchImageSnapshot();
});
});
describe('float (next engine)', () => {
test('should wrap text around left float', async () => {
expect(
await leftFloat({ experimentalPagination: true }),
).toMatchImageSnapshot();
});
test('should wrap text around right float', async () => {
expect(
await rightFloat({ experimentalPagination: true }),
).toMatchImageSnapshot();
});
test('should wrap text between multiple floats', async () => {
expect(
await multipleFloats({ experimentalPagination: true }),
).toMatchImageSnapshot();
});
test('should split wrapped text across pages instead of moving it whole', async () => {
expect(
await splitWrappedText({ experimentalPagination: true }),
).toMatchImageSnapshot();
});
test('should position clear elements below floats', async () => {
expect(
await clearElements({ experimentalPagination: true }),
).toMatchImageSnapshot();
});
test('should wrap text around circle shape-outside', async () => {
expect(
await circleShapeOutside({ experimentalPagination: true }),
).toMatchImageSnapshot();
});
test('should wrap text around polygon shape-outside', async () => {
expect(
await polygonShapeOutside({ experimentalPagination: true }),
).toMatchImageSnapshot();
});
});