@@ -21,6 +21,13 @@ const mockOnCloseBottomSheet = jest.fn((callback?: () => void) => {
2121 }
2222} ) ;
2323
24+ // Store the onClose prop passed to BottomSheet
25+ let capturedOnCloseProp : ( ( ) => void ) | undefined ;
26+ const getCapturedOnCloseProp = ( ) => capturedOnCloseProp ;
27+ const setCapturedOnCloseProp = ( fn : ( ( ) => void ) | undefined ) => {
28+ capturedOnCloseProp = fn ;
29+ } ;
30+
2431// Store reference for the mock to use (hoisting workaround)
2532const getMockOnCloseBottomSheet = ( ) => mockOnCloseBottomSheet ;
2633
@@ -35,12 +42,19 @@ jest.mock(
3542 {
3643 children,
3744 testID,
45+ onClose,
3846 } : {
3947 children : React . ReactNode ;
4048 testID ?: string ;
49+ onClose ?: ( ) => void ;
4150 } ,
4251 ref : React . Ref < { onCloseBottomSheet : ( callback ?: ( ) => void ) => void } > ,
4352 ) => {
53+ // Capture onClose prop for testing
54+ React . useEffect ( ( ) => {
55+ setCapturedOnCloseProp ( onClose ) ;
56+ } , [ onClose ] ) ;
57+
4458 React . useImperativeHandle ( ref , ( ) => ( {
4559 onCloseBottomSheet : ( callback ?: ( ) => void ) => {
4660 // Get the mock function at runtime to avoid hoisting issues
@@ -136,6 +150,7 @@ interface MockConfirmModalParams {
136150 onPress : jest . Mock ;
137151 variant ?: string ;
138152 } ;
153+ onClose ?: jest . Mock ;
139154}
140155
141156const createMockParams = (
@@ -156,6 +171,7 @@ describe('ConfirmModal', () => {
156171 jest . clearAllMocks ( ) ;
157172 mockStrings . mockClear ( ) ;
158173 mockUseParams . mockReturnValue ( createMockParams ( ) ) ;
174+ setCapturedOnCloseProp ( undefined ) ;
159175 // Restore mock implementation since jest.resetAllMocks() clears it
160176 mockOnCloseBottomSheet . mockImplementation ( ( callback ?: ( ) => void ) => {
161177 if ( callback ) {
@@ -266,6 +282,46 @@ describe('ConfirmModal', () => {
266282
267283 expect ( mockOnCloseBottomSheet ) . toHaveBeenCalledTimes ( 1 ) ;
268284 } ) ;
285+
286+ it ( 'closes bottom sheet without callback when close button is pressed' , ( ) => {
287+ const mockOnClose = jest . fn ( ) ;
288+ mockUseParams . mockReturnValue (
289+ createMockParams ( {
290+ onClose : mockOnClose ,
291+ } ) ,
292+ ) ;
293+
294+ const { getByTestId } = render ( < ConfirmModal /> ) ;
295+ const closeButton = getByTestId ( 'confirm-modal-close-button' ) ;
296+
297+ fireEvent . press ( closeButton ) ;
298+
299+ // handleCancel should close without passing callback (onClose is handled by BottomSheet prop)
300+ expect ( mockOnCloseBottomSheet ) . toHaveBeenCalledTimes ( 1 ) ;
301+ expect ( mockOnCloseBottomSheet ) . toHaveBeenCalledWith ( undefined ) ;
302+ } ) ;
303+
304+ it ( 'passes onClose callback to BottomSheet component' , ( ) => {
305+ const mockOnClose = jest . fn ( ) ;
306+ mockUseParams . mockReturnValue (
307+ createMockParams ( {
308+ onClose : mockOnClose ,
309+ } ) ,
310+ ) ;
311+
312+ render ( < ConfirmModal /> ) ;
313+
314+ // Verify onClose prop was passed to BottomSheet
315+ expect ( getCapturedOnCloseProp ( ) ) . toBe ( mockOnClose ) ;
316+ } ) ;
317+
318+ it ( 'does not pass onClose to BottomSheet when not provided' , ( ) => {
319+ mockUseParams . mockReturnValue ( createMockParams ( ) ) ;
320+
321+ render ( < ConfirmModal /> ) ;
322+
323+ expect ( getCapturedOnCloseProp ( ) ) . toBeUndefined ( ) ;
324+ } ) ;
269325 } ) ;
270326
271327 describe ( 'Edge Cases' , ( ) => {
0 commit comments