@@ -10,8 +10,6 @@ describe('src/elements/content-sidebar/activity-feed/useAnnotattionAPI', () => {
1010 updateAnnotation = jest . fn ( ) ,
1111 deleteAnnotation = jest . fn ( ) ,
1212 createAnnotationReply = jest . fn ,
13- deleteComment = jest . fn ( ) ,
14- updateComment = jest . fn ( ) ,
1513 } ) => {
1614 const getAnnotationsAPI = ( ) => ( {
1715 createAnnotationReply,
@@ -20,14 +18,8 @@ describe('src/elements/content-sidebar/activity-feed/useAnnotattionAPI', () => {
2018 deleteAnnotation,
2119 } ) ;
2220
23- const getThreadedCommentsAPI = ( ) => ( {
24- deleteComment,
25- updateComment,
26- } ) ;
27-
2821 return {
2922 getAnnotationsAPI,
30- getThreadedCommentsAPI,
3123 } ;
3224 } ;
3325
@@ -38,7 +30,6 @@ describe('src/elements/content-sidebar/activity-feed/useAnnotattionAPI', () => {
3830 renderHook ( ( ) =>
3931 useAnnotationAPI ( {
4032 api : getApi ( { } ) ,
41- currentUser : { } ,
4233 fileId : 'fileId' ,
4334 filePermissions,
4435 annotationId : annotation . id ,
@@ -47,80 +38,80 @@ describe('src/elements/content-sidebar/activity-feed/useAnnotattionAPI', () => {
4738 } ) ,
4839 ) ;
4940
50- test ( 'Should return correct default values' , ( ) => {
51- const { result } = getHook ( ) ;
52-
53- expect ( result . current . annotation ) . toEqual ( undefined ) ;
54- expect ( result . current . isLoading ) . toEqual ( true ) ;
55- expect ( result . current . error ) . toEqual ( undefined ) ;
56- expect ( result . current . replies ) . toEqual ( [ ] ) ;
57- } ) ;
58-
59- test ( 'Should call fetch annotation on mount' , ( ) => {
60- const { replies, ...normalizedAnnotation } = annotation ;
61- const mockGetAnnotation = jest . fn ( ( fileId , annotationId , permissions , successCallback ) => {
62- successCallback ( annotation ) ;
63- } ) ;
41+ test ( 'should call api function on handleFetch with correct arguments' , ( ) => {
42+ const mockSuccessCallback = jest . fn ( ) ;
43+ const mockGetAnnotation = jest . fn ( ) ;
6444 const api = getApi ( { getAnnotation : mockGetAnnotation } ) ;
6545
6646 const { result } = getHook ( { api } ) ;
6747
48+ act ( ( ) => {
49+ result . current . handleFetch ( { annotationId : annotation . id , successCallback : mockSuccessCallback } ) ;
50+ } ) ;
51+
6852 expect ( mockGetAnnotation ) . toBeCalledWith (
6953 'fileId' ,
7054 annotation . id ,
7155 { can_annotate : true , can_view_annotations : true } ,
72- expect . any ( Function ) ,
73- expect . any ( Function ) ,
56+ mockSuccessCallback ,
57+ errorCallback ,
7458 true ,
7559 ) ;
76-
77- expect ( result . current . isLoading ) . toEqual ( false ) ;
78- expect ( result . current . error ) . toEqual ( undefined ) ;
79- expect ( result . current . annotation ) . toEqual ( normalizedAnnotation ) ;
80- expect ( result . current . replies ) . toEqual ( replies ) ;
8160 } ) ;
8261
83- test ( 'should call api function on handleEdit with correct arguments and set pending state' , ( ) => {
62+ test ( 'should call api function on handleEdit with correct arguments' , ( ) => {
63+ const mockSuccessCallback = jest . fn ( ) ;
8464 const mockUpdateAnnotation = jest . fn ( ) ;
8565 const api = getApi ( { updateAnnotation : mockUpdateAnnotation } ) ;
8666 const { result } = getHook ( { api } ) ;
8767
8868 act ( ( ) => {
89- result . current . handleEdit ( annotation . id , 'new text' , { can_edit : true } ) ;
69+ result . current . handleEdit ( {
70+ id : annotation . id ,
71+ permissions : { can_edit : true } ,
72+ successCallback : mockSuccessCallback ,
73+ text : 'new text' ,
74+ } ) ;
9075 } ) ;
9176
9277 expect ( mockUpdateAnnotation ) . toBeCalledWith (
9378 'fileId' ,
9479 annotation . id ,
9580 { can_edit : true } ,
9681 { message : 'new text' } ,
97- expect . any ( Function ) ,
98- expect . any ( Function ) ,
82+ mockSuccessCallback ,
83+ errorCallback ,
9984 ) ;
100- expect ( result . current . annotation . isPending ) . toEqual ( true ) ;
10185 } ) ;
10286
10387 test ( 'should call api function on handleStatusChange with correct arguments' , ( ) => {
88+ const mockSuccessCallback = jest . fn ( ) ;
10489 const mockUpdateAnnotation = jest . fn ( ) ;
10590 const api = getApi ( { updateAnnotation : mockUpdateAnnotation } ) ;
10691 const { result } = getHook ( { api } ) ;
10792
10893 act ( ( ) => {
109- result . current . handleStatusChange ( annotation . id , 'resolved' , { can_resolve : true } ) ;
94+ result . current . handleStatusChange ( {
95+ id : annotation . id ,
96+ permissions : { can_resolve : true } ,
97+ status : 'resolved' ,
98+ successCallback : mockSuccessCallback ,
99+ } ) ;
110100 } ) ;
111101
112102 expect ( mockUpdateAnnotation ) . toBeCalledWith (
113103 'fileId' ,
114104 annotation . id ,
115105 { can_resolve : true } ,
116106 { status : 'resolved' } ,
117- expect . any ( Function ) ,
118- expect . any ( Function ) ,
107+ mockSuccessCallback ,
108+ errorCallback ,
119109 ) ;
120- expect ( result . current . annotation . isPending ) . toEqual ( true ) ;
121110 } ) ;
122111
123112 test ( 'should call api function on handleDelete with correct arguments' , ( ) => {
113+ const mockSuccessCallback = jest . fn ( ) ;
114+
124115 const mockDeleteAnnotation = jest . fn ( ) ;
125116 const api = getApi ( { deleteAnnotation : mockDeleteAnnotation } ) ;
126117 const { result } = getHook ( { api } ) ;
@@ -129,74 +120,16 @@ describe('src/elements/content-sidebar/activity-feed/useAnnotattionAPI', () => {
129120 result . current . handleDelete ( {
130121 id : annotation . id ,
131122 permissions : { can_delete : true } ,
123+ successCallback : mockSuccessCallback ,
132124 } ) ;
133125 } ) ;
134126
135127 expect ( mockDeleteAnnotation ) . toBeCalledWith (
136128 'fileId' ,
137129 annotation . id ,
138130 { can_delete : true } ,
139- expect . any ( Function ) ,
140- expect . any ( Function ) ,
131+ mockSuccessCallback ,
132+ errorCallback ,
141133 ) ;
142- expect ( result . current . annotation . isPending ) . toEqual ( true ) ;
143- } ) ;
144-
145- test ( 'should call api function on handleDeleteReply and set correct values on successCallback' , ( ) => {
146- const mockDeleteComment = jest . fn ( ( { successCallback } ) => {
147- successCallback ( ) ;
148- } ) ;
149- const api = getApi ( { deleteComment : mockDeleteComment } ) ;
150- const { id, permissions } = annotation . replies [ 0 ] ;
151- const { result } = getHook ( { api } ) ;
152-
153- act ( ( ) => {
154- result . current . handleDeleteReply ( { id, permissions } ) ;
155- } ) ;
156- expect ( result . current . replies . length ) . toEqual ( 0 ) ;
157- } ) ;
158-
159- test ( 'should call api function on handleEditReply and set correct values on successCallback' , ( ) => {
160- const message = 'New message' ;
161- const updatedReply = { ...annotation . replies [ 0 ] , message } ;
162- const mockUpdateComment = jest . fn ( ( { successCallback } ) => {
163- successCallback ( updatedReply ) ;
164- } ) ;
165- const mockGetAnnotation = jest . fn ( ( fileId , annotationId , permissions , successCallback ) => {
166- successCallback ( annotation ) ;
167- } ) ;
168- const api = getApi ( { updateComment : mockUpdateComment , getAnnotation : mockGetAnnotation } ) ;
169- const { id, permissions } = annotation . replies [ 0 ] ;
170-
171- const { result } = getHook ( { api } ) ;
172-
173- act ( ( ) => {
174- result . current . handleEditReply ( id , message , undefined , false , permissions ) ;
175- } ) ;
176-
177- expect ( result . current . replies [ 0 ] . isPending ) . toEqual ( false ) ;
178- expect ( result . current . replies [ 0 ] . message ) . toEqual ( message ) ;
179- } ) ;
180-
181- test ( 'should call api function on handleCreateReply and set correct values on successCallback' , ( ) => {
182- const message = 'New message' ;
183- const newReply = { ...annotation . replies [ 0 ] , message, id : 'reply_new' } ;
184- const mockCreateAnnotationReply = jest . fn ( ( fileId , annotationId , permissions , newMessage , successCallback ) => {
185- successCallback ( newReply ) ;
186- } ) ;
187- const mockGetAnnotation = jest . fn ( ( fileId , annotationId , permissions , successCallback ) => {
188- successCallback ( annotation ) ;
189- } ) ;
190- const api = getApi ( { createAnnotationReply : mockCreateAnnotationReply , getAnnotation : mockGetAnnotation } ) ;
191-
192- const { result } = getHook ( { api } ) ;
193-
194- act ( ( ) => {
195- result . current . handleCreateReply ( message ) ;
196- } ) ;
197-
198- const createdReply = result . current . replies [ 1 ] ;
199- expect ( createdReply . isPending ) . toEqual ( false ) ;
200- expect ( createdReply . message ) . toEqual ( message ) ;
201134 } ) ;
202135} ) ;
0 commit comments