1
1
import { renderHook } from '@testing-library/react-hooks' ;
2
2
import { sights } from '@monkvision/sights' ;
3
- import {
4
- ComplianceIssue ,
5
- ComplianceOptions ,
6
- Image ,
7
- ImageStatus ,
8
- Inspection ,
9
- } from '@monkvision/types' ;
3
+ import { ComplianceIssue , ComplianceOptions , Image , ImageStatus } from '@monkvision/types' ;
10
4
import { createEmptyMonkState , useMonkState } from '@monkvision/common' ;
11
5
import { useInspectionPoll } from '@monkvision/network' ;
12
6
import { act } from '@testing-library/react' ;
@@ -33,18 +27,16 @@ describe('useInspectionGalleryItems hook', () => {
33
27
it ( 'should initialize the gallery items using the local Monk state' , ( ) => {
34
28
const initialProps = createProps ( ) ;
35
29
const state = createEmptyMonkState ( ) ;
36
- state . inspections . push ( {
37
- id : initialProps . inspectionId ,
38
- images : [ 'image-1' , 'image-2' ] ,
39
- } as unknown as Inspection ) ;
40
30
state . images . push (
41
31
{
42
32
id : 'image-1' ,
33
+ inspectionId : initialProps . inspectionId ,
43
34
additionalData : { sight_id : 'test-sight-2' } ,
44
35
status : ImageStatus . SUCCESS ,
45
36
} as unknown as Image ,
46
37
{
47
38
id : 'image-2' ,
39
+ inspectionId : initialProps . inspectionId ,
48
40
status : ImageStatus . SUCCESS ,
49
41
} as unknown as Image ,
50
42
) ;
@@ -65,22 +57,21 @@ describe('useInspectionGalleryItems hook', () => {
65
57
it ( 'should properly update the items after each inspection poll' , ( ) => {
66
58
const initialProps = createProps ( ) ;
67
59
const entities = createEmptyMonkState ( ) ;
68
- entities . inspections . push ( {
69
- id : initialProps . inspectionId ,
70
- images : [ 'image-1' , 'image-2' , 'image-3' ] ,
71
- } as unknown as Inspection ) ;
72
60
entities . images . push (
73
61
{
74
62
id : 'image-1' ,
63
+ inspectionId : initialProps . inspectionId ,
75
64
additionalData : { sight_id : 'test-sight-1' } ,
76
65
status : ImageStatus . SUCCESS ,
77
66
} as unknown as Image ,
78
67
{
79
68
id : 'image-2' ,
69
+ inspectionId : initialProps . inspectionId ,
80
70
status : ImageStatus . SUCCESS ,
81
71
} as unknown as Image ,
82
72
{
83
73
id : 'image-3' ,
74
+ inspectionId : initialProps . inspectionId ,
84
75
additionalData : { sight_id : 'test-sight-3' } ,
85
76
status : ImageStatus . SUCCESS ,
86
77
} as unknown as Image ,
@@ -112,22 +103,21 @@ describe('useInspectionGalleryItems hook', () => {
112
103
it ( 'should put items to retake first in the list' , ( ) => {
113
104
const initialProps = createProps ( ) ;
114
105
const state = createEmptyMonkState ( ) ;
115
- state . inspections . push ( {
116
- id : initialProps . inspectionId ,
117
- images : [ 'image-1' , 'image-2' , 'image-3' ] ,
118
- } as unknown as Inspection ) ;
119
106
state . images . push (
120
107
{
121
108
id : 'image-1' ,
109
+ inspectionId : initialProps . inspectionId ,
122
110
additionalData : { sight_id : 'test-sight-1' } ,
123
111
status : ImageStatus . SUCCESS ,
124
112
} as unknown as Image ,
125
113
{
126
114
id : 'image-2' ,
115
+ inspectionId : initialProps . inspectionId ,
127
116
status : ImageStatus . NOT_COMPLIANT ,
128
117
} as unknown as Image ,
129
118
{
130
119
id : 'image-3' ,
120
+ inspectionId : initialProps . inspectionId ,
131
121
additionalData : { sight_id : 'test-sight-3' } ,
132
122
status : ImageStatus . NOT_COMPLIANT ,
133
123
} as unknown as Image ,
@@ -150,21 +140,20 @@ describe('useInspectionGalleryItems hook', () => {
150
140
const initialProps = createProps ( ) ;
151
141
initialProps . captureMode = false ;
152
142
const state = createEmptyMonkState ( ) ;
153
- state . inspections . push ( {
154
- id : initialProps . inspectionId ,
155
- images : [ 'image-1' , 'image-2' , 'image-3' ] ,
156
- } as unknown as Inspection ) ;
157
143
state . images . push (
158
144
{
159
145
id : 'image-1' ,
146
+ inspectionId : initialProps . inspectionId ,
160
147
additionalData : { sight_id : 'test-sight-1' } ,
161
148
} as unknown as Image ,
162
149
{
163
150
id : 'image-2' ,
151
+ inspectionId : initialProps . inspectionId ,
164
152
additionalData : { sight_id : 'test-sight-2' } ,
165
153
} as unknown as Image ,
166
154
{
167
155
id : 'image-3' ,
156
+ inspectionId : initialProps . inspectionId ,
168
157
additionalData : { sight_id : 'test-sight-3' } ,
169
158
} as unknown as Image ,
170
159
) ;
@@ -194,21 +183,20 @@ describe('useInspectionGalleryItems hook', () => {
194
183
const initialProps = createProps ( ) ;
195
184
initialProps . captureMode = true ;
196
185
const state = createEmptyMonkState ( ) ;
197
- state . inspections . push ( {
198
- id : initialProps . inspectionId ,
199
- images : [ 'image-1' , 'image-2' , 'image-3' ] ,
200
- } as unknown as Inspection ) ;
201
186
state . images . push (
202
187
{
203
188
id : 'image-1' ,
189
+ inspectionId : initialProps . inspectionId ,
204
190
additionalData : { sight_id : 'test-sight-1' , created_at : '2020-01-01T01:01:01.001Z' } ,
205
191
} as unknown as Image ,
206
192
{
207
193
id : 'image-2' ,
194
+ inspectionId : initialProps . inspectionId ,
208
195
additionalData : { sight_id : 'test-sight-1' , created_at : '1999-01-01T01:01:01.001Z' } ,
209
196
} as unknown as Image ,
210
197
{
211
198
id : 'image-3' ,
199
+ inspectionId : initialProps . inspectionId ,
212
200
additionalData : { sight_id : 'test-sight-1' , created_at : '2023-01-01T01:01:01.001Z' } ,
213
201
} as unknown as Image ,
214
202
) ;
@@ -229,17 +217,15 @@ describe('useInspectionGalleryItems hook', () => {
229
217
const initialProps = createProps ( ) ;
230
218
initialProps . captureMode = false ;
231
219
const state = createEmptyMonkState ( ) ;
232
- state . inspections . push ( {
233
- id : initialProps . inspectionId ,
234
- images : [ 'image-1' , 'image-2' ] ,
235
- } as unknown as Inspection ) ;
236
220
state . images . push (
237
221
{
238
222
id : 'image-1' ,
223
+ inspectionId : initialProps . inspectionId ,
239
224
additionalData : { sight_id : 'test-sight-1' , created_at : '2020-01-01T01:01:01.001Z' } ,
240
225
} as unknown as Image ,
241
226
{
242
227
id : 'image-2' ,
228
+ inspectionId : initialProps . inspectionId ,
243
229
additionalData : { sight_id : 'test-sight-1' , created_at : '1999-01-01T01:01:01.001Z' } ,
244
230
} as unknown as Image ,
245
231
) ;
@@ -290,12 +276,9 @@ describe('useInspectionGalleryItems hook', () => {
290
276
const initialProps = createProps ( ) ;
291
277
initialProps . refreshIntervalMs = 1234 ;
292
278
const state = createEmptyMonkState ( ) ;
293
- state . inspections . push ( {
294
- id : initialProps . inspectionId ,
295
- images : [ 'image-1' ] ,
296
- } as unknown as Inspection ) ;
297
279
state . images . push ( {
298
280
id : 'image-1' ,
281
+ inspectionId : initialProps . inspectionId ,
299
282
status : ImageStatus . UPLOADING ,
300
283
} as unknown as Image ) ;
301
284
( useMonkState as jest . Mock ) . mockImplementationOnce ( ( ) => ( { state } ) ) ;
@@ -314,12 +297,9 @@ describe('useInspectionGalleryItems hook', () => {
314
297
const initialProps = createProps ( ) ;
315
298
initialProps . refreshIntervalMs = 1234 ;
316
299
const state = createEmptyMonkState ( ) ;
317
- state . inspections . push ( {
318
- id : initialProps . inspectionId ,
319
- images : [ 'image-1' ] ,
320
- } as unknown as Inspection ) ;
321
300
state . images . push ( {
322
301
id : 'image-1' ,
302
+ inspectionId : initialProps . inspectionId ,
323
303
status : ImageStatus . COMPLIANCE_RUNNING ,
324
304
} as unknown as Image ) ;
325
305
( useMonkState as jest . Mock ) . mockImplementationOnce ( ( ) => ( { state } ) ) ;
@@ -338,12 +318,9 @@ describe('useInspectionGalleryItems hook', () => {
338
318
const initialProps = createProps ( ) ;
339
319
initialProps . refreshIntervalMs = undefined ;
340
320
const state = createEmptyMonkState ( ) ;
341
- state . inspections . push ( {
342
- id : initialProps . inspectionId ,
343
- images : [ 'image-1' ] ,
344
- } as unknown as Inspection ) ;
345
321
state . images . push ( {
346
322
id : 'image-1' ,
323
+ inspectionId : initialProps . inspectionId ,
347
324
status : ImageStatus . COMPLIANCE_RUNNING ,
348
325
} as unknown as Image ) ;
349
326
( useMonkState as jest . Mock ) . mockImplementationOnce ( ( ) => ( { state } ) ) ;
0 commit comments