|
1 | | -import React from 'react'; |
| 1 | +import React, { type ReactNode } from 'react'; |
2 | 2 | import { Alert, Platform, Pressable, Text } from 'react-native'; |
3 | 3 | import { |
4 | 4 | render, |
5 | 5 | screen, |
6 | 6 | fireEvent, |
7 | 7 | waitFor, |
8 | 8 | } from '@testing-library/react-native'; |
| 9 | +import type { AppBottomSheetRef } from '../components/bottomSheets/AppBottomSheet'; |
| 10 | +import type { WarningSheetData } from '../components/bottomSheets/WarningSheet'; |
9 | 11 |
|
10 | 12 | jest.mock('../context/ThemeContext', () => ({ |
11 | 13 | useTheme: () => ({ theme: require('./helpers/renderWithTheme').testTheme }), |
12 | 14 | })); |
13 | 15 |
|
14 | | -jest.mock('@gorhom/bottom-sheet', () => { |
15 | | - const ReactModule = require('react'); |
| 16 | +type MockSheetProps = { |
| 17 | + onDismiss?: () => void; |
| 18 | + children: ReactNode | ((state: { data?: WarningSheetData }) => ReactNode); |
| 19 | +}; |
| 20 | + |
| 21 | +jest.mock('../components/bottomSheets/AppBottomSheet', () => { |
| 22 | + const ReactModule: typeof React = require('react'); |
16 | 23 | const { View } = require('react-native'); |
17 | 24 |
|
18 | | - const BottomSheetModal = ReactModule.forwardRef((props: any, ref: any) => { |
19 | | - const [data, setData] = ReactModule.useState(null); |
| 25 | + const AppBottomSheet = ReactModule.forwardRef< |
| 26 | + AppBottomSheetRef<WarningSheetData>, |
| 27 | + MockSheetProps |
| 28 | + >((props, ref) => { |
| 29 | + const [state, setState] = ReactModule.useState<{ |
| 30 | + data?: WarningSheetData; |
| 31 | + } | null>(null); |
| 32 | + |
| 33 | + const close = () => { |
| 34 | + setState(null); |
| 35 | + props.onDismiss?.(); |
| 36 | + }; |
20 | 37 |
|
21 | 38 | ReactModule.useImperativeHandle(ref, () => ({ |
22 | | - present: (presented: any) => setData(presented ?? {}), |
23 | | - dismiss: () => { |
24 | | - setData(null); |
25 | | - props.onDismiss?.(); |
26 | | - }, |
| 39 | + present: (data?: WarningSheetData) => setState({ data }), |
| 40 | + dismiss: close, |
| 41 | + close, |
27 | 42 | })); |
28 | 43 |
|
29 | | - if (!data) return null; |
| 44 | + if (!state) return null; |
30 | 45 | return ( |
31 | 46 | <View> |
32 | 47 | {typeof props.children === 'function' |
33 | | - ? props.children({ data }) |
| 48 | + ? props.children(state) |
34 | 49 | : props.children} |
35 | 50 | </View> |
36 | 51 | ); |
37 | 52 | }); |
38 | 53 |
|
39 | | - return { |
40 | | - BottomSheetModal, |
41 | | - BottomSheetView: ({ children, style }: any) => ( |
42 | | - <View style={style}>{children}</View> |
43 | | - ), |
44 | | - BottomSheetBackdrop: () => null, |
45 | | - BottomSheetModalProvider: ({ children }: any) => <>{children}</>, |
46 | | - }; |
| 54 | + return { AppBottomSheet }; |
47 | 55 | }); |
48 | 56 |
|
49 | 57 | import { useConfirm } from '../hooks/useConfirm'; |
|
0 commit comments