@@ -159,21 +159,115 @@ describe('ImageGalleryFooter', () => {
159159 } ) ;
160160 } ) ;
161161
162- it ( 'should trigger the share button onPress Handler' , async ( ) => {
162+ it ( 'should trigger the share button onPress Handler with local attachment and no mime_type ' , async ( ) => {
163163 const user = userEvent . setup ( ) ;
164164 const chatClient = await getTestClientWithUser ( { id : 'testID' } ) ;
165165 const saveFileMock = jest . spyOn ( NativeHandlers , 'saveFile' ) ;
166166 const shareImageMock = jest . spyOn ( NativeHandlers , 'shareImage' ) ;
167167 const deleteFileMock = jest . spyOn ( NativeHandlers , 'deleteFile' ) ;
168168
169+ const attachment = generateImageAttachment ( ) ;
170+
171+ render (
172+ < OverlayProvider >
173+ < ImageGalleryContext . Provider
174+ value = {
175+ {
176+ messages : [
177+ generateMessage ( {
178+ attachments : [ attachment ] ,
179+ } ) ,
180+ ] as unknown as LocalMessage [ ] ,
181+ } as unknown as ImageGalleryContextValue
182+ }
183+ >
184+ < Chat client = { chatClient } >
185+ < ImageGallery overlayOpacity = { { value : 1 } as SharedValue < number > } />
186+ </ Chat >
187+ </ ImageGalleryContext . Provider >
188+ </ OverlayProvider > ,
189+ ) ;
190+
191+ await waitFor ( ( ) => {
192+ user . press ( screen . queryByLabelText ( 'Share Button' ) as ReactTestInstance ) ;
193+ } ) ;
194+
195+ await waitFor ( ( ) => {
196+ expect ( saveFileMock ) . not . toHaveBeenCalled ( ) ;
197+ expect ( shareImageMock ) . toHaveBeenCalledWith ( {
198+ type : 'image/jpeg' ,
199+ url : attachment . image_url ,
200+ } ) ;
201+ expect ( deleteFileMock ) . not . toHaveBeenCalled ( ) ;
202+ } ) ;
203+ } ) ;
204+
205+ it ( 'should trigger the share button onPress Handler with local attachment and existing mime_type' , async ( ) => {
206+ const user = userEvent . setup ( ) ;
207+ const chatClient = await getTestClientWithUser ( { id : 'testID' } ) ;
208+ const saveFileMock = jest . spyOn ( NativeHandlers , 'saveFile' ) ;
209+ const shareImageMock = jest . spyOn ( NativeHandlers , 'shareImage' ) ;
210+ const deleteFileMock = jest . spyOn ( NativeHandlers , 'deleteFile' ) ;
211+
212+ const attachment = { ...generateImageAttachment ( ) , mime_type : 'image/png' } ;
213+
214+ render (
215+ < OverlayProvider >
216+ < ImageGalleryContext . Provider
217+ value = {
218+ {
219+ messages : [
220+ generateMessage ( {
221+ attachments : [ attachment ] ,
222+ } ) ,
223+ ] as unknown as LocalMessage [ ] ,
224+ } as unknown as ImageGalleryContextValue
225+ }
226+ >
227+ < Chat client = { chatClient } >
228+ < ImageGallery overlayOpacity = { { value : 1 } as SharedValue < number > } />
229+ </ Chat >
230+ </ ImageGalleryContext . Provider >
231+ </ OverlayProvider > ,
232+ ) ;
233+
234+ await waitFor ( ( ) => {
235+ user . press ( screen . queryByLabelText ( 'Share Button' ) as ReactTestInstance ) ;
236+ } ) ;
237+
238+ await waitFor ( ( ) => {
239+ expect ( saveFileMock ) . not . toHaveBeenCalled ( ) ;
240+ expect ( shareImageMock ) . toHaveBeenCalledWith ( {
241+ type : 'image/png' ,
242+ url : attachment . image_url ,
243+ } ) ;
244+ expect ( deleteFileMock ) . not . toHaveBeenCalled ( ) ;
245+ } ) ;
246+ } ) ;
247+
248+ it ( 'should trigger the share button onPress Handler with cdn attachment' , async ( ) => {
249+ const user = userEvent . setup ( ) ;
250+ const chatClient = await getTestClientWithUser ( { id : 'testID' } ) ;
251+ const saveFileMock = jest
252+ . spyOn ( NativeHandlers , 'saveFile' )
253+ . mockResolvedValue ( 'file:///local/asset/url' ) ;
254+ const shareImageMock = jest . spyOn ( NativeHandlers , 'shareImage' ) ;
255+ const deleteFileMock = jest . spyOn ( NativeHandlers , 'deleteFile' ) ;
256+
257+ const attachment = {
258+ ...generateImageAttachment ( ) ,
259+ image_url : 'https://my-image-service/image/123456' ,
260+ mime_type : 'image/png' ,
261+ } ;
262+
169263 render (
170264 < OverlayProvider >
171265 < ImageGalleryContext . Provider
172266 value = {
173267 {
174268 messages : [
175269 generateMessage ( {
176- attachments : [ generateImageAttachment ( ) ] ,
270+ attachments : [ attachment ] ,
177271 } ) ,
178272 ] as unknown as LocalMessage [ ] ,
179273 } as unknown as ImageGalleryContextValue
@@ -192,7 +286,10 @@ describe('ImageGalleryFooter', () => {
192286
193287 await waitFor ( ( ) => {
194288 expect ( saveFileMock ) . toHaveBeenCalled ( ) ;
195- expect ( shareImageMock ) . toHaveBeenCalled ( ) ;
289+ expect ( shareImageMock ) . toHaveBeenCalledWith ( {
290+ type : 'image/png' ,
291+ url : 'file:///local/asset/url' ,
292+ } ) ;
196293 expect ( deleteFileMock ) . toHaveBeenCalled ( ) ;
197294 } ) ;
198295 } ) ;
0 commit comments