1- import React from 'react' ;
1+ import React , { createRef } from 'react' ;
22import { fireEvent , render } from '@testing-library/react-native' ;
3+ import type { BottomSheetRef } from '@metamask/design-system-react-native' ;
34import PerpsCancelAllOrdersView from './PerpsCancelAllOrdersView' ;
45import { usePerpsCancelAllOrders , usePerpsLiveOrders } from '../../hooks' ;
56
@@ -41,25 +42,6 @@ jest.mock('@metamask/design-system-twrnc-preset', () => {
4142 return { useTailwind : ( ) => tw } ;
4243} ) ;
4344
44- // BottomSheet overwrites refs via useImperativeHandle; stub keeps external sheetRef usable.
45- jest . mock ( '@metamask/design-system-react-native' , ( ) => {
46- const MockReact = jest . requireActual < typeof React > ( 'react' ) ;
47- const { View } = jest . requireActual ( 'react-native' ) ;
48- const actual = jest . requireActual ( '@metamask/design-system-react-native' ) ;
49-
50- const BottomSheet = MockReact . forwardRef (
51- ( { children } : { children : React . ReactNode } , _ref : React . Ref < unknown > ) => (
52- < View > { children } </ View >
53- ) ,
54- ) ;
55- BottomSheet . displayName = 'BottomSheet' ;
56-
57- return {
58- ...actual ,
59- BottomSheet,
60- } ;
61- } ) ;
62-
6345const mockUsePerpsLiveOrders = usePerpsLiveOrders as jest . MockedFunction <
6446 typeof usePerpsLiveOrders
6547> ;
@@ -212,37 +194,23 @@ describe('PerpsCancelAllOrdersView', () => {
212194 expect ( mockGoBack ) . toHaveBeenCalled ( ) ;
213195 } ) ;
214196
215- it ( 'closes via sheetRef when used with an external sheetRef' , ( ) => {
197+ it ( 'does not navigate back when closing with an external sheetRef' , ( ) => {
216198 // Arrange
217199 const mockOnClose = jest . fn ( ) ;
218- const mockOnCloseBottomSheet = jest . fn ( ( callback ?: ( ) => void ) =>
219- callback ?.( ) ,
220- ) ;
221- const mockSheetRef = {
222- current : {
223- onOpenBottomSheet : jest . fn ( ) ,
224- onCloseBottomSheet : mockOnCloseBottomSheet ,
225- } ,
226- } ;
200+ const sheetRef = createRef < BottomSheetRef | null > ( ) ;
227201
228202 // Act — with orders
229203 const { getByTestId, unmount } = render (
230- < PerpsCancelAllOrdersView
231- sheetRef = { mockSheetRef }
232- onClose = { mockOnClose }
233- /> ,
204+ < PerpsCancelAllOrdersView sheetRef = { sheetRef } onClose = { mockOnClose } /> ,
234205 ) ;
235206
236- // Assert — overlay mode closes via sheetRef instead of navigation goBack
207+ // Assert — overlay mode closes via sheetRef, not navigation. goBack
237208 fireEvent . press ( getByTestId ( 'header-close' ) ) ;
238- expect ( mockOnCloseBottomSheet ) . toHaveBeenCalled ( ) ;
239- expect ( mockOnClose ) . toHaveBeenCalled ( ) ;
240209 expect ( mockGoBack ) . not . toHaveBeenCalled ( ) ;
241210
242211 // Act — empty state overlay path
243212 unmount ( ) ;
244- mockOnClose . mockClear ( ) ;
245- mockOnCloseBottomSheet . mockClear ( ) ;
213+ mockGoBack . mockClear ( ) ;
246214 mockUsePerpsLiveOrders . mockReturnValue ( {
247215 orders : [ ] ,
248216 isInitialLoading : false ,
@@ -252,15 +220,10 @@ describe('PerpsCancelAllOrdersView', () => {
252220 orderCount : 0 ,
253221 } ) ;
254222 const { getByTestId : getEmptyTestId } = render (
255- < PerpsCancelAllOrdersView
256- sheetRef = { mockSheetRef }
257- onClose = { mockOnClose }
258- /> ,
223+ < PerpsCancelAllOrdersView sheetRef = { sheetRef } onClose = { mockOnClose } /> ,
259224 ) ;
260225
261226 fireEvent . press ( getEmptyTestId ( 'header-close' ) ) ;
262- expect ( mockOnCloseBottomSheet ) . toHaveBeenCalled ( ) ;
263- expect ( mockOnClose ) . toHaveBeenCalled ( ) ;
264227 expect ( mockGoBack ) . not . toHaveBeenCalled ( ) ;
265228 } ) ;
266229} ) ;
0 commit comments