Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 5 additions & 33 deletions app/components/UI/FundActionMenu/FundActionMenu.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import React from 'react';
import { render, fireEvent, waitFor } from '@testing-library/react-native';
import { useNavigation, useRoute } from '@react-navigation/native';
import { useSelector } from 'react-redux';
import mockSafeAreaContext from 'react-native-safe-area-context/jest/mock';

// External dependencies.
import { MetaMetricsEvents } from '../../../core/Analytics';
Expand All @@ -20,37 +21,7 @@ import { trace, TraceName } from '../../../util/trace';
import FundActionMenu from './FundActionMenu';
import { RampsButtonClickData } from '../Ramp/hooks/useRampsButtonClickData';

// Mock BottomSheet component
jest.mock(
'../../../component-library/components/BottomSheets/BottomSheet',
() => {
const { View } = jest.requireActual('react-native');
const { forwardRef, useImperativeHandle } = jest.requireActual('react');

const MockBottomSheet = forwardRef(
(props: { children: React.ReactNode }, ref: React.Ref<unknown>) => {
useImperativeHandle(ref, () => ({
onOpenBottomSheet: jest.fn(),
onCloseBottomSheet: jest.fn((callback?: () => void) => {
if (callback) callback();
}),
}));

return (
<View testID="bottom-sheet" {...props}>
{props.children}
</View>
);
},
);

return {
__esModule: true,
default: MockBottomSheet,
};
},
);

jest.mock('react-native-safe-area-context', () => mockSafeAreaContext);
// Mock dependencies
jest.mock('@react-navigation/native');
jest.mock('react-redux', () => ({
Expand Down Expand Up @@ -130,6 +101,7 @@ describe('FundActionMenu', () => {
// Setup default mocks
mockUseNavigation.mockReturnValue({
navigate: mockNavigate,
goBack: jest.fn(),
} as never);

mockUseRoute.mockReturnValue({
Expand Down Expand Up @@ -177,7 +149,7 @@ describe('FundActionMenu', () => {
describe('Component Rendering', () => {
it('renders correctly with default props', () => {
const { getByTestId } = render(<FundActionMenu />);
expect(getByTestId('bottom-sheet')).toBeOnTheScreen();
expect(getByTestId('fund-action-menu-bottom-sheet')).toBeOnTheScreen();
});

it('renders deposit button when deposit is enabled', () => {
Expand Down Expand Up @@ -662,7 +634,7 @@ describe('FundActionMenu', () => {
it('properly integrates with BottomSheet ref methods', () => {
const { getByTestId } = render(<FundActionMenu />);

expect(getByTestId('bottom-sheet')).toBeOnTheScreen();
expect(getByTestId('fund-action-menu-bottom-sheet')).toBeOnTheScreen();
});

it('displays correct strings from i18n', () => {
Expand Down
19 changes: 13 additions & 6 deletions app/components/UI/FundActionMenu/FundActionMenu.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
// Third party dependencies.
import React, { useCallback, useRef, useMemo } from 'react';
import { useSelector } from 'react-redux';
import { useRoute } from '@react-navigation/native';
import { useNavigation, useRoute } from '@react-navigation/native';

// External dependencies.
import BottomSheet, {
BottomSheetRef,
} from '../../../component-library/components/BottomSheets/BottomSheet';
import { selectChainId } from '../../../selectors/networkController';
import { MetaMetricsEvents } from '../../../core/Analytics';
import { IconName, Box } from '@metamask/design-system-react-native';
import {
IconName,
Box,
BottomSheet,
BottomSheetRef,
} from '@metamask/design-system-react-native';
import ActionListItem from '../../../component-library/components-temp/ActionListItem';
import useRampNetwork from '../Ramp/Aggregator/hooks/useRampNetwork';
import { getDecimalChainId } from '../../../util/networks';
Expand All @@ -36,6 +38,7 @@ import { useRampsButtonClickData } from '../Ramp/hooks/useRampsButtonClickData';

const FundActionMenu = () => {
const sheetRef = useRef<BottomSheetRef>(null);
const navigation = useNavigation();
const route = useRoute<FundActionMenuRouteProp>();

const customOnBuy = route.params?.onBuy;
Expand Down Expand Up @@ -231,7 +234,11 @@ const FundActionMenu = () => {
);

return (
<BottomSheet ref={sheetRef}>
<BottomSheet
ref={sheetRef}
goBack={navigation.goBack}
testID="fund-action-menu-bottom-sheet"
>
<Box twClassName="py-4">
{actionConfigs.map(
(config) =>
Expand Down
Loading