@@ -3,7 +3,6 @@ import { sights } from '@monkvision/sights';
3
3
import { ComplianceIssue , ComplianceOptions , Image , ImageStatus } from '@monkvision/types' ;
4
4
import { createEmptyMonkState , useMonkState } from '@monkvision/common' ;
5
5
import { useInspectionPoll } from '@monkvision/network' ;
6
- import { act } from '@testing-library/react' ;
7
6
import { useInspectionGalleryItems } from '../../../../src/components/InspectionGallery/hooks' ;
8
7
import { InspectionGalleryProps } from '../../../../src' ;
9
8
@@ -56,8 +55,16 @@ describe('useInspectionGalleryItems hook', () => {
56
55
57
56
it ( 'should properly update the items after each inspection poll' , ( ) => {
58
57
const initialProps = createProps ( ) ;
59
- const entities = createEmptyMonkState ( ) ;
60
- entities . images . push (
58
+ const entitiesMock1 = createEmptyMonkState ( ) ;
59
+ entitiesMock1 . images . push ( {
60
+ id : 'image-1' ,
61
+ sightId : 'test-sight-1' ,
62
+ inspectionId : initialProps . inspectionId ,
63
+ status : ImageStatus . SUCCESS ,
64
+ } as unknown as Image ) ;
65
+
66
+ const entitiesMock2 = createEmptyMonkState ( ) ;
67
+ entitiesMock2 . images . push (
61
68
{
62
69
id : 'image-1' ,
63
70
inspectionId : initialProps . inspectionId ,
@@ -67,33 +74,26 @@ describe('useInspectionGalleryItems hook', () => {
67
74
{
68
75
id : 'image-2' ,
69
76
inspectionId : initialProps . inspectionId ,
70
- status : ImageStatus . SUCCESS ,
71
- } as unknown as Image ,
72
- {
73
- id : 'image-3' ,
74
- inspectionId : initialProps . inspectionId ,
75
- sightId : 'test-sight-3' ,
77
+ sightId : 'test-sight-2' ,
76
78
status : ImageStatus . SUCCESS ,
77
79
} as unknown as Image ,
78
80
) ;
79
- const { result, unmount } = renderHook ( useInspectionGalleryItems , { initialProps } ) ;
81
+ ( useMonkState as jest . Mock ) . mockImplementationOnce ( ( ) => ( { state : entitiesMock1 } ) ) ;
82
+ const { result, unmount, rerender } = renderHook ( useInspectionGalleryItems , { initialProps } ) ;
80
83
81
84
expect ( result . current ) . toEqual ( [
82
- { isAddDamage : false , isTaken : false , sightId : 'test-sight-1' } ,
85
+ { isAddDamage : false , isTaken : true , image : entitiesMock1 . images [ 0 ] } ,
83
86
{ isAddDamage : false , isTaken : false , sightId : 'test-sight-2' } ,
84
87
{ isAddDamage : false , isTaken : false , sightId : 'test-sight-3' } ,
85
88
{ isAddDamage : true } ,
86
89
] ) ;
87
- expect ( useInspectionPoll ) . toHaveBeenCalledWith (
88
- expect . objectContaining ( { onSuccess : expect . any ( Function ) } ) ,
89
- ) ;
90
- const { onSuccess } = ( useInspectionPoll as jest . Mock ) . mock . calls [ 0 ] [ 0 ] ;
91
- act ( ( ) => onSuccess ( entities ) ) ;
90
+
91
+ ( useMonkState as jest . Mock ) . mockImplementationOnce ( ( ) => ( { state : entitiesMock2 } ) ) ;
92
+ rerender ( ) ;
92
93
expect ( result . current ) . toEqual ( [
93
- { isAddDamage : false , isTaken : true , image : entities . images [ 0 ] } ,
94
- { isAddDamage : false , isTaken : false , sightId : 'test-sight-2' } ,
95
- { isAddDamage : false , isTaken : true , image : entities . images [ 2 ] } ,
96
- { isAddDamage : false , isTaken : true , image : entities . images [ 1 ] } ,
94
+ { isAddDamage : false , isTaken : true , image : entitiesMock2 . images [ 0 ] } ,
95
+ { isAddDamage : false , isTaken : true , image : entitiesMock2 . images [ 1 ] } ,
96
+ { isAddDamage : false , isTaken : false , sightId : 'test-sight-3' } ,
97
97
{ isAddDamage : true } ,
98
98
] ) ;
99
99
0 commit comments