@@ -15,7 +15,6 @@ import DocumentContext from './DocumentContext.js';
15
15
16
16
import type { PDFDocumentProxy , PDFPageProxy } from 'pdfjs-dist' ;
17
17
import type { DocumentContextType , PageCallback } from './shared/types.js' ;
18
- import type { OptionalContentConfig } from 'pdfjs-dist/types/src/display/optional_content_config.js' ;
19
18
20
19
const pdfFile = await loadPDF ( '../../__mocks__/_pdf.pdf' ) ;
21
20
const pdfFile2 = await loadPDF ( '../../__mocks__/_pdf2.pdf' ) ;
@@ -739,7 +738,7 @@ describe('Page', () => {
739
738
expect ( annotationLayer ) . not . toBeInTheDocument ( ) ;
740
739
} ) ;
741
740
742
- it ( 'requests page to be rendered with default visibility for optionalContentConfig' , async ( ) => {
741
+ it ( 'requests page to be rendered with default visibility given no optionalContentConfig' , async ( ) => {
743
742
const { func : onRenderSuccess , promise : onRenderSuccessPromise } =
744
743
makeAsyncCallback < [ PageCallback ] > ( ) ;
745
744
@@ -754,36 +753,46 @@ describe('Page', () => {
754
753
await onRenderSuccessPromise ;
755
754
756
755
const pageCanvas = container . querySelector ( '.react-pdf__Page__canvas' ) as HTMLCanvasElement ;
757
- const context : CanvasRenderingContext2D = pageCanvas . getContext ( '2d' ) ! ;
758
- const imageData : ImageData = context . getImageData ( 100 , 100 , 1 , 1 ) ;
756
+ const context = pageCanvas . getContext ( '2d' ) ;
759
757
760
- // should render green pixel because the layer is visible
758
+ if ( ! context ) {
759
+ throw new Error ( 'CanvasRenderingContext2D is not available' ) ;
760
+ }
761
+
762
+ const imageData = context . getImageData ( 100 , 100 , 1 , 1 ) ;
763
+
764
+ // Should render green pixel because the layer is visible
761
765
expect ( imageData . data ) . toStrictEqual ( new Uint8ClampedArray ( [ 191 , 255 , 191 , 255 ] ) ) ;
762
766
} ) ;
763
767
764
768
it ( 'requests page to be rendered with given optionalContentConfig' , async ( ) => {
765
769
const { func : onRenderSuccess , promise : onRenderSuccessPromise } =
766
770
makeAsyncCallback < [ PageCallback ] > ( ) ;
767
- const optionalContentConfig : OptionalContentConfig = await pdf5 . getOptionalContentConfig ( ) ;
768
771
772
+ const optionalContentConfig = await pdf5 . getOptionalContentConfig ( ) ;
769
773
optionalContentConfig . setVisibility ( '1R' , false ) ;
770
774
771
775
const { container } = renderWithContext (
772
776
< Page onRenderSuccess = { onRenderSuccess } pageIndex = { 0 } /> ,
773
777
{
774
- optionalContentConfig,
775
778
linkService,
779
+ optionalContentConfig,
776
780
pdf : pdf5 ,
777
781
} ,
778
782
) ;
779
783
780
784
await onRenderSuccessPromise ;
781
785
782
786
const pageCanvas = container . querySelector ( '.react-pdf__Page__canvas' ) as HTMLCanvasElement ;
783
- const context : CanvasRenderingContext2D = pageCanvas . getContext ( '2d' ) ! ;
784
- const imageData : ImageData = context . getImageData ( 100 , 100 , 1 , 1 ) ;
787
+ const context = pageCanvas . getContext ( '2d' ) ;
788
+
789
+ if ( ! context ) {
790
+ throw new Error ( 'CanvasRenderingContext2D is not available' ) ;
791
+ }
792
+
793
+ const imageData = context . getImageData ( 100 , 100 , 1 , 1 ) ;
785
794
786
- // should render white pixel because the layer is hidden
795
+ // Should render white pixel because the layer is hidden
787
796
expect ( imageData . data ) . toStrictEqual ( new Uint8ClampedArray ( [ 255 , 255 , 255 , 255 ] ) ) ;
788
797
} ) ;
789
798
} ) ;
0 commit comments