Skip to content

Commit

Permalink
Pull externalLinkRel unit tests into linkService group
Browse files Browse the repository at this point in the history
  • Loading branch information
wojtekmaj committed Jan 10, 2024
1 parent 290d179 commit 90aadb5
Showing 1 changed file with 29 additions and 29 deletions.
58 changes: 29 additions & 29 deletions packages/react-pdf/src/Document.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -547,41 +547,41 @@ describe('Document', () => {
expect(link.target).toBe(target);
},
);
});

it.each`
externalLinkRel | rel
${null} | ${'noopener noreferrer nofollow'}
${'noopener'} | ${'noopener'}
${'noreferrer'} | ${'noreferrer'}
${'nofollow'} | ${'nofollow'}
`(
'returns externalLinkRel = $rel given externalLinkRel prop = $externalLinkRel',
async ({ externalLinkRel, rel }) => {
const {
func: onRenderAnnotationLayerSuccess,
promise: onRenderAnnotationLayerSuccessPromise,
} = makeAsyncCallback();
it.each`
externalLinkRel | rel
${null} | ${'noopener noreferrer nofollow'}
${'noopener'} | ${'noopener'}
${'noreferrer'} | ${'noreferrer'}
${'nofollow'} | ${'nofollow'}
`(
'returns externalLinkRel = $rel given externalLinkRel prop = $externalLinkRel',
async ({ externalLinkRel, rel }) => {
const {
func: onRenderAnnotationLayerSuccess,
promise: onRenderAnnotationLayerSuccessPromise,
} = makeAsyncCallback();

const { container } = render(
<Document externalLinkRel={externalLinkRel} file={pdfFile.file}>
<Page
onRenderAnnotationLayerSuccess={onRenderAnnotationLayerSuccess}
renderMode="none"
pageNumber={1}
/>
</Document>,
);
const { container } = render(
<Document externalLinkRel={externalLinkRel} file={pdfFile.file}>
<Page
onRenderAnnotationLayerSuccess={onRenderAnnotationLayerSuccess}
renderMode="none"
pageNumber={1}
/>
</Document>,
);

expect.assertions(1);
expect.assertions(1);

await onRenderAnnotationLayerSuccessPromise;
await onRenderAnnotationLayerSuccessPromise;

const link = container.querySelector('a') as HTMLAnchorElement;
const link = container.querySelector('a') as HTMLAnchorElement;

expect(link.rel).toBe(rel);
},
);
expect(link.rel).toBe(rel);
},
);
});

it('calls onClick callback when clicked a page (sample of mouse events family)', () => {
const onClick = vi.fn();
Expand Down

0 comments on commit 90aadb5

Please sign in to comment.