@@ -12,17 +12,13 @@ import { loadPDF, makeAsyncCallback, muteConsole, restoreConsole } from '../test
12
12
13
13
const pdfFile = loadPDF ( './__mocks__/_pdf.pdf' ) ;
14
14
const pdfFile2 = loadPDF ( './__mocks__/_pdf2.pdf' ) ;
15
-
16
- vi . mock ( './Page/AnnotationLayer' , ( ) => ( {
17
- default : function AnnotationLayer ( ) {
18
- return < div className = "react-pdf__Page__annotations" /> ;
19
- } ,
20
- } ) ) ;
15
+ const pdfFile4 = loadPDF ( './__mocks__/_pdf4.pdf' ) ;
21
16
22
17
describe ( 'Page' , ( ) => {
23
18
// Loaded PDF file
24
19
let pdf ;
25
20
let pdf2 ;
21
+ let pdf4 ;
26
22
27
23
// Object with basic loaded page information that shall match after successful loading
28
24
const desiredLoadedPage = { } ;
@@ -52,6 +48,8 @@ describe('Page', () => {
52
48
53
49
registerPageArguments . push ( page . _pageIndex , expect . any ( HTMLDivElement ) ) ;
54
50
unregisterPageArguments = page . _pageIndex ;
51
+
52
+ pdf4 = await pdfjs . getDocument ( { data : pdfFile4 . arrayBuffer } ) . promise ;
55
53
} ) ;
56
54
57
55
describe ( 'loading' , ( ) => {
@@ -300,27 +298,50 @@ describe('Page', () => {
300
298
} ) ;
301
299
302
300
it ( 'requests page to be rendered with default rotation when given nothing' , async ( ) => {
303
- const { func : onLoadSuccess , promise : onLoadSuccessPromise } = makeAsyncCallback ( ) ;
304
- const instance = createRef ( ) ;
301
+ const { func : onRenderSuccess , promise : onRenderSuccessPromise } = makeAsyncCallback ( ) ;
305
302
306
- render ( < Page onLoadSuccess = { onLoadSuccess } pageIndex = { 0 } pdf = { pdf } ref = { instance } /> ) ;
303
+ const { container } = render (
304
+ < Page onRenderSuccess = { onRenderSuccess } pageIndex = { 0 } pdf = { pdf } renderMode = "svg" /> ,
305
+ ) ;
307
306
308
- await onLoadSuccessPromise ;
307
+ const page = await onRenderSuccessPromise ;
309
308
310
- expect ( instance . current . rotate ) . toBe ( 0 ) ;
309
+ const pageSvg = container . querySelector ( '.react-pdf__Page__svg' ) ;
310
+
311
+ const { width, height } = window . getComputedStyle ( pageSvg ) ;
312
+
313
+ const viewport = page . getViewport ( { scale : 1 } ) ;
314
+
315
+ // Expect the annotation layer not to be rotated
316
+ expect ( parseInt ( width , 10 ) ) . toBe ( Math . floor ( viewport . width ) ) ;
317
+ expect ( parseInt ( height , 10 ) ) . toBe ( Math . floor ( viewport . height ) ) ;
311
318
} ) ;
312
319
313
320
it ( 'requests page to be rendered with given rotation when given rotate prop' , async ( ) => {
314
- const { func : onLoadSuccess , promise : onLoadSuccessPromise } = makeAsyncCallback ( ) ;
315
- const instance = createRef ( ) ;
321
+ const { func : onRenderSuccess , promise : onRenderSuccessPromise } = makeAsyncCallback ( ) ;
322
+ const rotate = 90 ;
316
323
317
- render (
318
- < Page onLoadSuccess = { onLoadSuccess } pageIndex = { 0 } pdf = { pdf } rotate = { 90 } ref = { instance } /> ,
324
+ const { container } = render (
325
+ < Page
326
+ onRenderSuccess = { onRenderSuccess }
327
+ pageIndex = { 0 }
328
+ pdf = { pdf }
329
+ renderMode = "svg"
330
+ rotate = { rotate }
331
+ /> ,
319
332
) ;
320
333
321
- await onLoadSuccessPromise ;
334
+ const page = await onRenderSuccessPromise ;
335
+
336
+ const pageSvg = container . querySelector ( '.react-pdf__Page__svg' ) ;
337
+
338
+ const { width, height } = window . getComputedStyle ( pageSvg ) ;
322
339
323
- expect ( instance . current . rotate ) . toBe ( 90 ) ;
340
+ const viewport = page . getViewport ( { scale : 1 , rotation : rotate } ) ;
341
+
342
+ // Expect the annotation layer to be rotated
343
+ expect ( parseInt ( width , 10 ) ) . toBe ( Math . floor ( viewport . width ) ) ;
344
+ expect ( parseInt ( height , 10 ) ) . toBe ( Math . floor ( viewport . height ) ) ;
324
345
} ) ;
325
346
326
347
it ( 'requests page to be rendered in canvas mode by default' , async ( ) => {
@@ -530,74 +551,95 @@ describe('Page', () => {
530
551
} ) ;
531
552
532
553
it ( 'requests page to be rendered without forms by default' , async ( ) => {
533
- const { func : onLoadSuccess , promise : onLoadSuccessPromise } = makeAsyncCallback ( ) ;
534
- const instance = createRef ( ) ;
554
+ const { func : onRenderAnnotationLayerSuccess , promise : onRenderAnnotationLayerSuccessPromise } =
555
+ makeAsyncCallback ( ) ;
535
556
536
- render ( < Page onLoadSuccess = { onLoadSuccess } pageIndex = { 0 } pdf = { pdf } ref = { instance } /> ) ;
557
+ const { container } = render (
558
+ < Page
559
+ onRenderAnnotationLayerSuccess = { onRenderAnnotationLayerSuccess }
560
+ pageIndex = { 0 }
561
+ pdf = { pdf4 }
562
+ renderMode = "none"
563
+ /> ,
564
+ ) ;
537
565
538
566
expect . assertions ( 1 ) ;
539
567
540
- await onLoadSuccessPromise ;
568
+ await onRenderAnnotationLayerSuccessPromise ;
569
+
570
+ const textWidgetAnnotation = container . querySelector ( '.textWidgetAnnotation' ) ;
541
571
542
- expect ( instance . current . childContext . renderForms ) . toBeFalsy ( ) ;
572
+ expect ( textWidgetAnnotation ) . toBeFalsy ( ) ;
543
573
} ) ;
544
574
545
575
it ( 'requests page to be rendered with forms given renderForms = true' , async ( ) => {
546
- const { func : onLoadSuccess , promise : onLoadSuccessPromise } = makeAsyncCallback ( ) ;
547
- const instance = createRef ( ) ;
576
+ const { func : onRenderAnnotationLayerSuccess , promise : onRenderAnnotationLayerSuccessPromise } =
577
+ makeAsyncCallback ( ) ;
548
578
549
- render (
550
- < Page onLoadSuccess = { onLoadSuccess } pageIndex = { 0 } pdf = { pdf } ref = { instance } renderForms /> ,
579
+ const { container } = render (
580
+ < Page
581
+ onRenderAnnotationLayerSuccess = { onRenderAnnotationLayerSuccess }
582
+ pageIndex = { 0 }
583
+ pdf = { pdf4 }
584
+ renderForms
585
+ renderMode = "none"
586
+ /> ,
551
587
) ;
552
588
553
589
expect . assertions ( 1 ) ;
554
590
555
- await onLoadSuccessPromise ;
591
+ await onRenderAnnotationLayerSuccessPromise ;
592
+
593
+ const textWidgetAnnotation = container . querySelector ( '.textWidgetAnnotation' ) ;
556
594
557
- expect ( instance . current . childContext . renderForms ) . toBe ( true ) ;
595
+ expect ( textWidgetAnnotation ) . toBeTruthy ( ) ;
558
596
} ) ;
559
597
560
598
it ( 'requests page to be rendered with forms given legacy renderInteractiveForms = true' , async ( ) => {
561
- const { func : onLoadSuccess , promise : onLoadSuccessPromise } = makeAsyncCallback ( ) ;
562
- const instance = createRef ( ) ;
599
+ const { func : onRenderAnnotationLayerSuccess , promise : onRenderAnnotationLayerSuccessPromise } =
600
+ makeAsyncCallback ( ) ;
563
601
564
- render (
602
+ const { container } = render (
565
603
< Page
566
- onLoadSuccess = { onLoadSuccess }
604
+ onRenderAnnotationLayerSuccess = { onRenderAnnotationLayerSuccess }
567
605
pageIndex = { 0 }
568
- pdf = { pdf }
569
- ref = { instance }
606
+ pdf = { pdf4 }
570
607
renderInteractiveForms
608
+ renderMode = "none"
571
609
/> ,
572
610
) ;
573
611
574
612
expect . assertions ( 1 ) ;
575
613
576
- await onLoadSuccessPromise ;
614
+ await onRenderAnnotationLayerSuccessPromise ;
615
+
616
+ const textWidgetAnnotation = container . querySelector ( '.textWidgetAnnotation' ) ;
577
617
578
- expect ( instance . current . childContext . renderForms ) . toBe ( true ) ;
618
+ expect ( textWidgetAnnotation ) . toBeTruthy ( ) ;
579
619
} ) ;
580
620
581
621
it ( 'requests page to be rendered without forms given renderForms = false and legacy renderInteractiveForms = true' , async ( ) => {
582
- const { func : onLoadSuccess , promise : onLoadSuccessPromise } = makeAsyncCallback ( ) ;
583
- const instance = createRef ( ) ;
622
+ const { func : onRenderAnnotationLayerSuccess , promise : onRenderAnnotationLayerSuccessPromise } =
623
+ makeAsyncCallback ( ) ;
584
624
585
- render (
625
+ const { container } = render (
586
626
< Page
587
- onLoadSuccess = { onLoadSuccess }
627
+ onRenderAnnotationLayerSuccess = { onRenderAnnotationLayerSuccess }
588
628
pageIndex = { 0 }
589
- pdf = { pdf }
590
- ref = { instance }
629
+ pdf = { pdf4 }
591
630
renderForms = { false }
592
631
renderInteractiveForms
632
+ renderMode = "none"
593
633
/> ,
594
634
) ;
595
635
596
636
expect . assertions ( 1 ) ;
597
637
598
- await onLoadSuccessPromise ;
638
+ await onRenderAnnotationLayerSuccessPromise ;
639
+
640
+ const textWidgetAnnotation = container . querySelector ( '.textWidgetAnnotation' ) ;
599
641
600
- expect ( instance . current . childContext . renderForms ) . toBeFalsy ( ) ;
642
+ expect ( textWidgetAnnotation ) . toBeFalsy ( ) ;
601
643
} ) ;
602
644
603
645
it ( 'requests page to be rendered at its original size given nothing' , async ( ) => {
0 commit comments