|
| 1 | +import React from 'react'; |
| 2 | +import { render } from '@testing-library/react-native'; |
| 3 | +import SecurityBadgeBottomSheet from './SecurityBadgeBottomSheet'; |
| 4 | +import { IconName, IconColor } from '@metamask/design-system-react-native'; |
| 5 | +import { strings } from '../../../../../locales/i18n'; |
| 6 | +import { MetaMetricsEvents } from '../../../../core/Analytics'; |
| 7 | + |
| 8 | +const mockTrackEvent = jest.fn(); |
| 9 | +const mockCreateEventBuilder = jest.fn(() => ({ |
| 10 | + addProperties: jest.fn().mockReturnThis(), |
| 11 | + build: jest.fn().mockReturnValue({}), |
| 12 | +})); |
| 13 | + |
| 14 | +jest.mock('../../../hooks/useAnalytics/useAnalytics', () => ({ |
| 15 | + useAnalytics: () => ({ |
| 16 | + trackEvent: mockTrackEvent, |
| 17 | + createEventBuilder: mockCreateEventBuilder, |
| 18 | + }), |
| 19 | +})); |
| 20 | + |
| 21 | +jest.mock('react-native-safe-area-context', () => ({ |
| 22 | + useSafeAreaInsets: () => ({ top: 0, bottom: 0, left: 0, right: 0 }), |
| 23 | + useSafeAreaFrame: () => ({ x: 0, y: 0, width: 390, height: 844 }), |
| 24 | + SafeAreaProvider: ({ children }: { children: React.ReactNode }) => children, |
| 25 | +})); |
| 26 | + |
| 27 | +const mockRouteParams = { |
| 28 | + icon: IconName.SecurityTick, |
| 29 | + iconColor: IconColor.SuccessDefault, |
| 30 | + title: 'Test Title', |
| 31 | + description: 'Test Description', |
| 32 | + source: 'badge', |
| 33 | + severity: 'Verified', |
| 34 | + tokenAddress: '0x1234567890abcdef', |
| 35 | + tokenSymbol: 'TEST', |
| 36 | + chainId: '0x1', |
| 37 | +}; |
| 38 | + |
| 39 | +jest.mock('@react-navigation/native', () => ({ |
| 40 | + ...jest.requireActual('@react-navigation/native'), |
| 41 | + useRoute: () => ({ |
| 42 | + params: mockRouteParams, |
| 43 | + }), |
| 44 | + useNavigation: () => ({ |
| 45 | + navigate: jest.fn(), |
| 46 | + goBack: jest.fn(), |
| 47 | + }), |
| 48 | +})); |
| 49 | + |
| 50 | +describe('SecurityBadgeBottomSheet', () => { |
| 51 | + beforeEach(() => { |
| 52 | + jest.clearAllMocks(); |
| 53 | + }); |
| 54 | + |
| 55 | + it('renders without crashing', () => { |
| 56 | + const { getByText } = render(<SecurityBadgeBottomSheet />); |
| 57 | + expect(getByText('Test Title')).toBeTruthy(); |
| 58 | + expect(getByText('Test Description')).toBeTruthy(); |
| 59 | + }); |
| 60 | + |
| 61 | + it('tracks bottom sheet opened event on mount', () => { |
| 62 | + render(<SecurityBadgeBottomSheet />); |
| 63 | + |
| 64 | + expect(mockCreateEventBuilder).toHaveBeenCalledWith( |
| 65 | + MetaMetricsEvents.SECURITY_TRUST_BOTTOM_SHEET_OPENED, |
| 66 | + ); |
| 67 | + expect(mockTrackEvent).toHaveBeenCalled(); |
| 68 | + }); |
| 69 | + |
| 70 | + it('displays "Got it" button when onProceed is not provided', () => { |
| 71 | + const { getByText, queryByText } = render(<SecurityBadgeBottomSheet />); |
| 72 | + |
| 73 | + expect(getByText(strings('security_trust.got_it'))).toBeTruthy(); |
| 74 | + expect(queryByText(strings('security_trust.proceed'))).toBeNull(); |
| 75 | + expect(queryByText(strings('security_trust.cancel'))).toBeNull(); |
| 76 | + }); |
| 77 | + |
| 78 | + it('displays title and description from route params', () => { |
| 79 | + const { getByText } = render(<SecurityBadgeBottomSheet />); |
| 80 | + |
| 81 | + expect(getByText('Test Title')).toBeTruthy(); |
| 82 | + expect(getByText('Test Description')).toBeTruthy(); |
| 83 | + }); |
| 84 | +}); |
0 commit comments