|
| 1 | +import React from 'react'; |
| 2 | +import { fireEvent } from '@testing-library/react-native'; |
| 3 | +import { TransactionMeta } from '@metamask/transaction-controller'; |
| 4 | +import { Hex } from '@metamask/utils'; |
| 5 | +import renderWithProvider from '../../../../../../util/test/renderWithProvider'; |
| 6 | +import { strings } from '../../../../../../../locales/i18n'; |
| 7 | +import { useMultichainBlockExplorerTxUrl } from '../../../../../UI/Bridge/hooks/useMultichainBlockExplorerTxUrl'; |
| 8 | +import Routes from '../../../../../../constants/navigation/Routes'; |
| 9 | +import { useNetworkName } from '../../../hooks/useNetworkName'; |
| 10 | +import { useTokenWithBalance } from '../../../hooks/tokens/useTokenWithBalance'; |
| 11 | +import { selectBridgeHistoryForAccount } from '../../../../../../selectors/bridgeStatusController'; |
| 12 | +import { useBridgeTxHistoryData } from '../../../../../../util/bridge/hooks/useBridgeTxHistoryData'; |
| 13 | +import { useTokenAmount } from '../../../hooks/useTokenAmount'; |
| 14 | +import { useTransactionDetails } from '../../../hooks/activity/useTransactionDetails'; |
| 15 | +import { SourceHashSummaryLine } from './source-hash-summary-line'; |
| 16 | + |
| 17 | +const mockNavigate = jest.fn(); |
| 18 | + |
| 19 | +jest.mock('../../../../../UI/Bridge/hooks/useMultichainBlockExplorerTxUrl'); |
| 20 | +jest.mock('../../../hooks/useNetworkName'); |
| 21 | +jest.mock('../../../hooks/tokens/useTokenWithBalance'); |
| 22 | +jest.mock('../../../../../../selectors/bridgeStatusController'); |
| 23 | +jest.mock('../../../../../../util/bridge/hooks/useBridgeTxHistoryData'); |
| 24 | +jest.mock('../../../hooks/useTokenAmount'); |
| 25 | +jest.mock('../../../hooks/activity/useTransactionDetails'); |
| 26 | + |
| 27 | +jest.mock('@react-navigation/native', () => ({ |
| 28 | + ...jest.requireActual('@react-navigation/native'), |
| 29 | + useNavigation: () => ({ |
| 30 | + navigate: mockNavigate, |
| 31 | + }), |
| 32 | +})); |
| 33 | + |
| 34 | +function render() { |
| 35 | + return renderWithProvider( |
| 36 | + <SourceHashSummaryLine |
| 37 | + parentTransaction={ |
| 38 | + { |
| 39 | + id: 'parent-id', |
| 40 | + chainId: '0x1', |
| 41 | + submittedTime: 1755719285723, |
| 42 | + metamaskPay: { |
| 43 | + tokenAddress: '0x123', |
| 44 | + chainId: '0x1', |
| 45 | + }, |
| 46 | + } as unknown as TransactionMeta |
| 47 | + } |
| 48 | + sourceHash={'0xabc' as Hex} |
| 49 | + />, |
| 50 | + { |
| 51 | + state: { |
| 52 | + engine: { |
| 53 | + backgroundState: { |
| 54 | + TransactionController: { transactions: [] }, |
| 55 | + }, |
| 56 | + }, |
| 57 | + }, |
| 58 | + }, |
| 59 | + ); |
| 60 | +} |
| 61 | + |
| 62 | +describe('SourceHashSummaryLine', () => { |
| 63 | + const useMultichainBlockExplorerTxUrlMock = jest.mocked( |
| 64 | + useMultichainBlockExplorerTxUrl, |
| 65 | + ); |
| 66 | + const useNetworkNameMock = jest.mocked(useNetworkName); |
| 67 | + const useTokenWithBalanceMock = jest.mocked(useTokenWithBalance); |
| 68 | + |
| 69 | + beforeEach(() => { |
| 70 | + jest.resetAllMocks(); |
| 71 | + |
| 72 | + useMultichainBlockExplorerTxUrlMock.mockReturnValue({ |
| 73 | + explorerTxUrl: 'https://explorer.example', |
| 74 | + explorerName: 'Explorer', |
| 75 | + } as ReturnType<typeof useMultichainBlockExplorerTxUrl>); |
| 76 | + |
| 77 | + useNetworkNameMock.mockReturnValue('Ethereum'); |
| 78 | + useTokenWithBalanceMock.mockReturnValue({ symbol: 'USDC' } as ReturnType< |
| 79 | + typeof useTokenWithBalance |
| 80 | + >); |
| 81 | + |
| 82 | + jest.mocked(selectBridgeHistoryForAccount).mockReturnValue({}); |
| 83 | + jest.mocked(useBridgeTxHistoryData).mockReturnValue({ |
| 84 | + bridgeTxHistoryItem: undefined, |
| 85 | + isBridgeComplete: null, |
| 86 | + }); |
| 87 | + jest |
| 88 | + .mocked(useTokenAmount) |
| 89 | + .mockReturnValue({} as ReturnType<typeof useTokenAmount>); |
| 90 | + jest.mocked(useTransactionDetails).mockReturnValue({ |
| 91 | + transactionMeta: {} as TransactionMeta, |
| 92 | + }); |
| 93 | + }); |
| 94 | + |
| 95 | + it('renders send title', () => { |
| 96 | + const { getByText } = render(); |
| 97 | + |
| 98 | + expect( |
| 99 | + getByText( |
| 100 | + strings('transaction_details.summary_title.bridge_send', { |
| 101 | + sourceSymbol: 'USDC', |
| 102 | + sourceChain: 'Ethereum', |
| 103 | + }), |
| 104 | + ), |
| 105 | + ).toBeDefined(); |
| 106 | + }); |
| 107 | + |
| 108 | + it('navigates to block explorer when button is pressed', () => { |
| 109 | + const { getByTestId } = render(); |
| 110 | + |
| 111 | + fireEvent.press(getByTestId('block-explorer-button')); |
| 112 | + |
| 113 | + expect(mockNavigate).toHaveBeenCalledWith(Routes.WEBVIEW.MAIN, { |
| 114 | + screen: Routes.WEBVIEW.SIMPLE, |
| 115 | + params: { |
| 116 | + url: 'https://explorer.example', |
| 117 | + title: 'Explorer', |
| 118 | + }, |
| 119 | + }); |
| 120 | + }); |
| 121 | +}); |
0 commit comments