1
- import { Blob } from 'node:buffer' ;
2
1
import { beforeAll , describe , expect , it , vi } from 'vitest' ;
3
2
import React , { createRef } from 'react' ;
4
3
import { fireEvent , render } from '@testing-library/react' ;
@@ -275,7 +274,7 @@ describe('Page', () => {
275
274
expect ( inputRef . current ) . toBeInstanceOf ( HTMLDivElement ) ;
276
275
} ) ;
277
276
278
- it ( 'passes canvas element to PageCanvas properly' , async ( ) => {
277
+ it ( 'passes canvas element to Canvas properly' , async ( ) => {
279
278
const { func : onLoadSuccess , promise : onLoadSuccessPromise } = makeAsyncCallback ( ) ;
280
279
281
280
const canvasRef = createRef < HTMLCanvasElement > ( ) ;
@@ -394,15 +393,12 @@ describe('Page', () => {
394
393
expect ( page ) . toMatchObject ( desiredLoadedPage ) ;
395
394
} ) ;
396
395
397
- it ( 'requests page to be rendered with default rotation when given nothing' , async ( ) => {
398
- const originalBlob = globalThis . Blob ;
399
- globalThis . Blob = Blob as unknown as typeof globalThis . Blob ;
400
-
396
+ it . skip ( 'requests page to be rendered with default rotation when given nothing' , async ( ) => {
401
397
const { func : onRenderSuccess , promise : onRenderSuccessPromise } =
402
398
makeAsyncCallback < [ PageCallback ] > ( ) ;
403
399
404
400
const { container } = renderWithContext (
405
- < Page onRenderSuccess = { onRenderSuccess } pageIndex = { 0 } renderMode = "svg" /> ,
401
+ < Page onRenderSuccess = { onRenderSuccess } pageIndex = { 0 } /> ,
406
402
{
407
403
linkService,
408
404
pdf,
@@ -411,29 +407,24 @@ describe('Page', () => {
411
407
412
408
const [ page ] = await onRenderSuccessPromise ;
413
409
414
- const pageSvg = container . querySelector ( '.react-pdf__Page__svg ' ) as SVGElement ;
410
+ const pageCanvas = container . querySelector ( '.react-pdf__Page__canvas ' ) as HTMLCanvasElement ;
415
411
416
- const { width, height } = window . getComputedStyle ( pageSvg ) ;
412
+ const { width, height } = window . getComputedStyle ( pageCanvas ) ;
417
413
418
414
const viewport = page . getViewport ( { scale : 1 } ) ;
419
415
420
- // Expect the SVG layer not to be rotated
416
+ // Expect the canvas layer not to be rotated
421
417
expect ( parseInt ( width , 10 ) ) . toBe ( Math . floor ( viewport . width ) ) ;
422
418
expect ( parseInt ( height , 10 ) ) . toBe ( Math . floor ( viewport . height ) ) ;
423
-
424
- globalThis . Blob = originalBlob ;
425
419
} ) ;
426
420
427
- it ( 'requests page to be rendered with given rotation when given rotate prop' , async ( ) => {
428
- const originalBlob = globalThis . Blob ;
429
- globalThis . Blob = Blob as unknown as typeof globalThis . Blob ;
430
-
421
+ it . skip ( 'requests page to be rendered with given rotation when given rotate prop' , async ( ) => {
431
422
const { func : onRenderSuccess , promise : onRenderSuccessPromise } =
432
423
makeAsyncCallback < [ PageCallback ] > ( ) ;
433
424
const rotate = 90 ;
434
425
435
426
const { container } = renderWithContext (
436
- < Page onRenderSuccess = { onRenderSuccess } pageIndex = { 0 } renderMode = "svg" rotate = { rotate } /> ,
427
+ < Page onRenderSuccess = { onRenderSuccess } pageIndex = { 0 } rotate = { rotate } /> ,
437
428
{
438
429
linkService,
439
430
pdf,
@@ -442,17 +433,15 @@ describe('Page', () => {
442
433
443
434
const [ page ] = await onRenderSuccessPromise ;
444
435
445
- const pageSvg = container . querySelector ( '.react-pdf__Page__svg ' ) as SVGElement ;
436
+ const pageCanvas = container . querySelector ( '.react-pdf__Page__canvas ' ) as HTMLCanvasElement ;
446
437
447
- const { width, height } = window . getComputedStyle ( pageSvg ) ;
438
+ const { width, height } = window . getComputedStyle ( pageCanvas ) ;
448
439
449
440
const viewport = page . getViewport ( { scale : 1 , rotation : rotate } ) ;
450
441
451
- // Expect the SVG layer to be rotated
442
+ // Expect the canvas layer to be rotated
452
443
expect ( parseInt ( width , 10 ) ) . toBe ( Math . floor ( viewport . width ) ) ;
453
444
expect ( parseInt ( height , 10 ) ) . toBe ( Math . floor ( viewport . height ) ) ;
454
-
455
- globalThis . Blob = originalBlob ;
456
445
} ) ;
457
446
458
447
it ( 'requests page to be rendered in canvas mode by default' , async ( ) => {
@@ -486,15 +475,13 @@ describe('Page', () => {
486
475
} ,
487
476
) ;
488
477
489
- expect . assertions ( 2 ) ;
478
+ expect . assertions ( 1 ) ;
490
479
491
480
await onLoadSuccessPromise ;
492
481
493
482
const pageCanvas = container . querySelector ( '.react-pdf__Page__canvas' ) ;
494
- const pageSVG = container . querySelector ( '.react-pdf__Page__svg' ) ;
495
483
496
484
expect ( pageCanvas ) . not . toBeInTheDocument ( ) ;
497
- expect ( pageSVG ) . not . toBeInTheDocument ( ) ;
498
485
} ) ;
499
486
500
487
it ( 'requests page to be rendered in canvas mode when given renderMode = "canvas"' , async ( ) => {
@@ -546,26 +533,6 @@ describe('Page', () => {
546
533
expect ( customRenderer ) . toBeInTheDocument ( ) ;
547
534
} ) ;
548
535
549
- it ( 'requests page to be rendered in SVG mode when given renderMode = "svg"' , async ( ) => {
550
- const { func : onLoadSuccess , promise : onLoadSuccessPromise } = makeAsyncCallback ( ) ;
551
-
552
- const { container } = renderWithContext (
553
- < Page onLoadSuccess = { onLoadSuccess } pageIndex = { 0 } renderMode = "svg" /> ,
554
- {
555
- linkService,
556
- pdf,
557
- } ,
558
- ) ;
559
-
560
- expect . assertions ( 1 ) ;
561
-
562
- await onLoadSuccessPromise ;
563
-
564
- const pageSVG = container . querySelector ( '.react-pdf__Page__svg' ) ;
565
-
566
- expect ( pageSVG ) . toBeInTheDocument ( ) ;
567
- } ) ;
568
-
569
536
it ( 'requests text content to be rendered by default' , async ( ) => {
570
537
const { func : onLoadSuccess , promise : onLoadSuccessPromise } = makeAsyncCallback ( ) ;
571
538
@@ -676,26 +643,6 @@ describe('Page', () => {
676
643
expect ( textLayer ) . toBeInTheDocument ( ) ;
677
644
} ) ;
678
645
679
- it ( 'renders TextLayer when given renderMode = "svg"' , async ( ) => {
680
- const { func : onLoadSuccess , promise : onLoadSuccessPromise } = makeAsyncCallback ( ) ;
681
-
682
- const { container } = renderWithContext (
683
- < Page onLoadSuccess = { onLoadSuccess } pageIndex = { 0 } renderMode = "svg" renderTextLayer /> ,
684
- {
685
- linkService,
686
- pdf,
687
- } ,
688
- ) ;
689
-
690
- expect . assertions ( 1 ) ;
691
-
692
- await onLoadSuccessPromise ;
693
-
694
- const textLayer = container . querySelector ( '.react-pdf__Page__textContent' ) ;
695
-
696
- expect ( textLayer ) . toBeInTheDocument ( ) ;
697
- } ) ;
698
-
699
646
it ( 'requests annotations to be rendered by default' , async ( ) => {
700
647
const { func : onLoadSuccess , promise : onLoadSuccessPromise } = makeAsyncCallback ( ) ;
701
648
0 commit comments