import { fireEvent, render } from '@testing-library/react';
import * as PdfJs from 'pdfjs-dist';
import * as React from 'react';
import { mockAllIsIntersecting } from '../../../test-utils/mockIntersectionObserver';
import { PdfJsApiContext, Viewer, type PdfJsApiProvider } from '../src';
test('fileUrl as a prop', async () => {
const apiProvider = PdfJs as unknown as PdfJsApiProvider;
const App = ({ fileUrl }) => (
);
const { findByText, rerender } = render();
mockAllIsIntersecting(true);
const firstText = await findByText('Adobe Acrobat PDF Files');
expect(firstText).toHaveClass('rpv-core__text-layer-text');
rerender();
const text = await findByText('A Simple PDF File');
expect(text).toHaveClass('rpv-core__text-layer-text');
});
test('fileUrl as a state', async () => {
const apiProvider = PdfJs as unknown as PdfJsApiProvider;
const App = () => {
const [fileUrl, setFileUrl] = React.useState(global['__HELLO_PDF__']);
return (
);
};
const { getByText, findByText } = render();
mockAllIsIntersecting(true);
let firstText = await findByText('Hello, world!');
expect(firstText).toHaveClass('rpv-core__text-layer-text');
// Click the `Load document 1` button
fireEvent.click(getByText('Load document 1'));
firstText = await findByText('Adobe Acrobat PDF Files');
expect(firstText).toHaveClass('rpv-core__text-layer-text');
// Click the `Load document 2` button
fireEvent.click(getByText('Load document 2'));
const text = await findByText('A Simple PDF File');
expect(text).toHaveClass('rpv-core__text-layer-text');
});