@@ -3,14 +3,18 @@ import { mount } from 'enzyme';
3
3
4
4
import { Document } from '../entry.noworker' ;
5
5
6
- import file from './_pdf.buffer' ;
6
+ import {
7
+ fileArrayBuffer ,
8
+ fileBlob ,
9
+ fileFile ,
10
+ fileDataURI ,
11
+ } from '../../__mocks__/_pdf.buffer' ;
7
12
8
- const OK = Symbol ( 'OK' ) ;
13
+ import {
14
+ fileFile as fileFile2 ,
15
+ } from '../../__mocks__/_pdf2.buffer' ;
9
16
10
- const fileArrayBuffer = file . buffer ;
11
- const fileBlob = new Blob ( [ fileArrayBuffer ] , { type : 'application/pdf' } ) ;
12
- const fileFile = new File ( [ fileArrayBuffer ] , { type : 'application/pdf' } ) ;
13
- const fileDataURI = `data:application/pdf;base64,${ file . toString ( 'base64' ) } ` ;
17
+ const OK = Symbol ( 'OK' ) ;
14
18
15
19
/* eslint-disable comma-dangle */
16
20
@@ -28,9 +32,27 @@ const makeAsyncCallback = (callbackValue) => {
28
32
return { promise, func } ;
29
33
} ;
30
34
35
+ const desiredLoadedPdf = {
36
+ loadingTask : { } ,
37
+ pdfInfo : {
38
+ fingerprint : 'a62067476e69734bb8eb60122615dfbf' ,
39
+ numPages : 4 ,
40
+ } ,
41
+ transport : { } ,
42
+ } ;
43
+ const desiredLoadedPdf2 = {
44
+ loadingTask : { } ,
45
+ pdfInfo : {
46
+ fingerprint : '04d9eadd32916d728460daa283b37ff2' ,
47
+ numPages : 5 ,
48
+ } ,
49
+ transport : { } ,
50
+ } ;
51
+
52
+
31
53
describe ( 'Document' , ( ) => {
32
54
describe ( 'loading' , ( ) => {
33
- it ( 'loads a file via data URI properly' , async ( ) => {
55
+ it ( 'loads a file and calls onSourceSuccess and onLoadSuccess callbacks via data URI properly' , async ( ) => {
34
56
const { func : onSourceSuccess , promise : onSourceSuccessPromise } = makeAsyncCallback ( OK ) ;
35
57
const { func : onLoadSuccess , promise : onLoadSuccessPromise } = makeAsyncCallback ( ) ;
36
58
@@ -44,10 +66,10 @@ describe('Document', () => {
44
66
45
67
expect . assertions ( 2 ) ;
46
68
await expect ( onSourceSuccessPromise ) . resolves . toBe ( OK ) ;
47
- await expect ( onLoadSuccessPromise ) . resolves . toBeInstanceOf ( Object ) ;
69
+ await expect ( onLoadSuccessPromise ) . resolves . toMatchObject ( desiredLoadedPdf ) ;
48
70
} ) ;
49
71
50
- it ( 'loads a file via data URI properly (param object)' , async ( ) => {
72
+ it ( 'loads a file and calls onSourceSuccess and onLoadSuccess callbacks via data URI properly (param object)' , async ( ) => {
51
73
const { func : onSourceSuccess , promise : onSourceSuccessPromise } = makeAsyncCallback ( OK ) ;
52
74
const { func : onLoadSuccess , promise : onLoadSuccessPromise } = makeAsyncCallback ( ) ;
53
75
@@ -61,10 +83,10 @@ describe('Document', () => {
61
83
62
84
expect . assertions ( 2 ) ;
63
85
await expect ( onSourceSuccessPromise ) . resolves . toBe ( OK ) ;
64
- await expect ( onLoadSuccessPromise ) . resolves . toBeInstanceOf ( Object ) ;
86
+ await expect ( onLoadSuccessPromise ) . resolves . toMatchObject ( desiredLoadedPdf ) ;
65
87
} ) ;
66
88
67
- it ( 'loads a file via ArrayBuffer properly' , async ( ) => {
89
+ it ( 'loads a file and calls onSourceSuccess and onLoadSuccess callbacks via ArrayBuffer properly' , async ( ) => {
68
90
const { func : onSourceSuccess , promise : onSourceSuccessPromise } = makeAsyncCallback ( OK ) ;
69
91
const { func : onLoadSuccess , promise : onLoadSuccessPromise } = makeAsyncCallback ( ) ;
70
92
@@ -78,10 +100,10 @@ describe('Document', () => {
78
100
79
101
expect . assertions ( 2 ) ;
80
102
await expect ( onSourceSuccessPromise ) . resolves . toBe ( OK ) ;
81
- await expect ( onLoadSuccessPromise ) . resolves . toBeInstanceOf ( Object ) ;
103
+ await expect ( onLoadSuccessPromise ) . resolves . toMatchObject ( desiredLoadedPdf ) ;
82
104
} ) ;
83
105
84
- it ( 'loads a file via Blob properly' , async ( ) => {
106
+ it ( 'loads a file and calls onSourceSuccess and onLoadSuccess callbacks via Blob properly' , async ( ) => {
85
107
const { func : onSourceSuccess , promise : onSourceSuccessPromise } = makeAsyncCallback ( OK ) ;
86
108
const { func : onLoadSuccess , promise : onLoadSuccessPromise } = makeAsyncCallback ( ) ;
87
109
@@ -95,10 +117,10 @@ describe('Document', () => {
95
117
96
118
expect . assertions ( 2 ) ;
97
119
await expect ( onSourceSuccessPromise ) . resolves . toBe ( OK ) ;
98
- await expect ( onLoadSuccessPromise ) . resolves . toBeInstanceOf ( Object ) ;
120
+ await expect ( onLoadSuccessPromise ) . resolves . toMatchObject ( desiredLoadedPdf ) ;
99
121
} ) ;
100
122
101
- it ( 'loads a file via File properly' , async ( ) => {
123
+ it ( 'loads a file and calls onSourceSuccess and onLoadSuccess callbacks via File properly' , async ( ) => {
102
124
const { func : onSourceSuccess , promise : onSourceSuccessPromise } = makeAsyncCallback ( OK ) ;
103
125
const { func : onLoadSuccess , promise : onLoadSuccessPromise } = makeAsyncCallback ( ) ;
104
126
@@ -112,7 +134,36 @@ describe('Document', () => {
112
134
113
135
expect . assertions ( 2 ) ;
114
136
await expect ( onSourceSuccessPromise ) . resolves . toBe ( OK ) ;
115
- await expect ( onLoadSuccessPromise ) . resolves . toBeInstanceOf ( Object ) ;
137
+ await expect ( onLoadSuccessPromise ) . resolves . toMatchObject ( desiredLoadedPdf ) ;
138
+ } ) ;
139
+
140
+ it ( 'replaces a file properly' , async ( ) => {
141
+ const { func : onSourceSuccess , promise : onSourceSuccessPromise } = makeAsyncCallback ( OK ) ;
142
+ const { func : onLoadSuccess , promise : onLoadSuccessPromise } = makeAsyncCallback ( ) ;
143
+
144
+ const mountedComponent = mount (
145
+ < Document
146
+ file = { fileFile }
147
+ onLoadSuccess = { onLoadSuccess }
148
+ onSourceSuccess = { onSourceSuccess }
149
+ />
150
+ ) ;
151
+
152
+ expect . assertions ( 4 ) ;
153
+ await expect ( onSourceSuccessPromise ) . resolves . toBe ( OK ) ;
154
+ await expect ( onLoadSuccessPromise ) . resolves . toMatchObject ( desiredLoadedPdf ) ;
155
+
156
+ const { func : onSourceSuccess2 , promise : onSourceSuccessPromise2 } = makeAsyncCallback ( OK ) ;
157
+ const { func : onLoadSuccess2 , promise : onLoadSuccessPromise2 } = makeAsyncCallback ( ) ;
158
+
159
+ mountedComponent . setProps ( {
160
+ file : fileFile2 ,
161
+ onLoadSuccess : onLoadSuccess2 ,
162
+ onSourceSuccess : onSourceSuccess2 ,
163
+ } ) ;
164
+
165
+ await expect ( onSourceSuccessPromise2 ) . resolves . toBe ( OK ) ;
166
+ await expect ( onLoadSuccessPromise2 ) . resolves . toMatchObject ( desiredLoadedPdf2 ) ;
116
167
} ) ;
117
168
} ) ;
118
169
0 commit comments