diff --git a/android/.settings/org.eclipse.buildship.core.prefs b/android/.settings/org.eclipse.buildship.core.prefs index e8895216fd3c..948553877cf0 100644 --- a/android/.settings/org.eclipse.buildship.core.prefs +++ b/android/.settings/org.eclipse.buildship.core.prefs @@ -1,2 +1,13 @@ +arguments=--init-script /var/folders/j9/20w1vr5s10v1y55vbf73rbx40000gn/T/db3b08fc4a9ef609cb16b96b200fa13e563f396e9bb1ed0905fdab7bc3bc513b.gradle --init-script /var/folders/j9/20w1vr5s10v1y55vbf73rbx40000gn/T/52cde0cfcf3e28b8b7510e992210d9614505e0911af0c190bd590d7158574963.gradle +auto.sync=false +build.scans.enabled=false +connection.gradle.distribution=GRADLE_DISTRIBUTION(WRAPPER) connection.project.dir= eclipse.preferences.version=1 +gradle.user.home= +java.home=/Users/salim/Library/Java/JavaVirtualMachines/azul-16.0.2/Contents/Home +jvm.arguments= +offline.mode=false +override.workspace.settings=true +show.console.view=true +show.executions.view=true diff --git a/app/components/UI/NetworkAssetLogo/__snapshots__/index.test.tsx.snap b/app/components/UI/NetworkAssetLogo/__snapshots__/index.test.tsx.snap new file mode 100644 index 000000000000..315d31b10890 --- /dev/null +++ b/app/components/UI/NetworkAssetLogo/__snapshots__/index.test.tsx.snap @@ -0,0 +1,3 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`NetworkAssetLogo Component matches the snapshot for non-mainnet 1`] = `null`; diff --git a/app/components/UI/NetworkAssetLogo/index.test.tsx b/app/components/UI/NetworkAssetLogo/index.test.tsx new file mode 100644 index 000000000000..d283daa77d17 --- /dev/null +++ b/app/components/UI/NetworkAssetLogo/index.test.tsx @@ -0,0 +1,73 @@ +import React from 'react'; +import { render } from '@testing-library/react-native'; +import NetworkAssetLogo from '.'; +import TokenIcon from '../Swaps/components/TokenIcon'; +import { ChainId } from '@metamask/controller-utils'; + +// Mock the TokenIcon component +jest.mock('../Swaps/components/TokenIcon', () => jest.fn(() => null)); + +describe('NetworkAssetLogo Component', () => { + it('matches the snapshot for non-mainnet', () => { + const { toJSON } = render( + , + ); + + expect(toJSON()).toMatchSnapshot(); + }); + + it('renders TokenIcon with ETH for mainnet chainId', () => { + const props = { + chainId: ChainId.mainnet, + ticker: 'TEST', + style: { width: 50, height: 50 }, + big: true, + biggest: false, + testID: 'network-asset-logo', + }; + + render(); + + expect(TokenIcon).toHaveBeenCalledWith( + { + big: props.big, + biggest: props.biggest, + symbol: 'ETH', + style: props.style, + testID: props.testID, + }, + {}, + ); + }); + + it('renders TokenIcon with ticker for non-mainnet chainId', () => { + const props = { + chainId: '0x38', // Binance Smart Chain + ticker: 'BNB', + style: { width: 40, height: 40 }, + big: false, + biggest: true, + testID: 'network-asset-logo', + }; + + render(); + + expect(TokenIcon).toHaveBeenCalledWith( + { + big: props.big, + biggest: props.biggest, + symbol: props.ticker, + style: props.style, + testID: props.testID, + }, + {}, + ); + }); +}); diff --git a/app/components/Views/AssetOptions/AssetOptions.test.tsx b/app/components/Views/AssetOptions/AssetOptions.test.tsx new file mode 100644 index 000000000000..feb7453abf2a --- /dev/null +++ b/app/components/Views/AssetOptions/AssetOptions.test.tsx @@ -0,0 +1,196 @@ +import React from 'react'; +import { render, fireEvent } from '@testing-library/react-native'; +import { useNavigation } from '@react-navigation/native'; +import { useSelector } from 'react-redux'; +import AssetOptions from './AssetOptions'; +import { strings } from '../../../../locales/i18n'; + +// Mock dependencies +jest.mock('@react-navigation/native', () => ({ + useNavigation: jest.fn(), +})); + +jest.mock('react-redux', () => ({ + useSelector: jest.fn(), +})); + +jest.mock('react-native-safe-area-context', () => ({ + useSafeAreaInsets: jest.fn(() => ({ bottom: 10 })), +})); + +jest.mock('../../../component-library/hooks', () => ({ + useStyles: () => ({ styles: {} }), +})); + +jest.mock('../../../components/hooks/useMetrics', () => ({ + useMetrics: () => ({ + trackEvent: jest.fn(), + isEnabled: jest.fn(() => true), + }), +})); + +jest.mock('../../../components/UI/Swaps/utils/useBlockExplorer', () => + jest.fn(() => ({ + baseUrl: 'https://example-explorer.com', + token: (address: string) => `https://example-explorer.com/token/${address}`, + })), +); + +jest.mock('../../../core/Engine', () => ({ + context: { + TokensController: { + ignoreTokens: jest.fn(), + }, + NetworkController: { + findNetworkClientIdByChainId: jest.fn(() => 'test-network'), + }, + }, +})); + +jest.mock('../../../core/NotificationManager', () => ({ + showSimpleNotification: jest.fn(), +})); + +jest.mock('../../../util/Logger', () => ({ + log: jest.fn(), +})); + +jest.mock('../../../constants/navigation/Routes', () => ({ + MODAL: { + ROOT_MODAL_FLOW: 'RootModalFlow', + }, + BROWSER: { + HOME: 'BrowserHome', + VIEW: 'BrowserView', + }, +})); + +jest.mock('../../../selectors/networkController', () => ({ + selectChainId: jest.fn(() => '1'), + selectProviderConfig: jest.fn(() => ({})), + selectNetworkConfigurations: jest.fn(() => ({})), +})); + +jest.mock('../../../selectors/tokenListController', () => ({ + selectTokenList: jest.fn(() => ({})), +})); + +describe('AssetOptions Component', () => { + const mockNavigation = { + navigate: jest.fn(), + goBack: jest.fn(), + }; + + beforeEach(() => { + (useNavigation as jest.Mock).mockReturnValue(mockNavigation); + (useSelector as jest.Mock).mockImplementation((selector) => { + if (selector.name === 'selectChainId') return '1'; + if (selector.name === 'selectProviderConfig') return {}; + if (selector.name === 'selectTokenList') + return { '0x123': { symbol: 'ABC' } }; + return {}; + }); + }); + + afterEach(() => { + jest.clearAllMocks(); + }); + + it('matches the snapshot', () => { + const { toJSON } = render( + , + ); + + expect(toJSON()).toMatchSnapshot(); + }); + + it('renders correctly and displays options', () => { + const { getByText } = render( + , + ); + + expect( + getByText(strings('asset_details.options.view_on_portfolio')), + ).toBeTruthy(); + expect( + getByText(strings('asset_details.options.view_on_block')), + ).toBeTruthy(); + expect( + getByText(strings('asset_details.options.token_details')), + ).toBeTruthy(); + expect( + getByText(strings('asset_details.options.remove_token')), + ).toBeTruthy(); + }); + + it('handles "View on Block Explorer" press', () => { + const { getByText } = render( + , + ); + + fireEvent.press(getByText(strings('asset_details.options.view_on_block'))); + expect(mockNavigation.navigate).toHaveBeenCalledWith('Webview', { + screen: 'SimpleWebview', + params: { + url: 'https://example-explorer.com/token/0x123', + title: 'example-explorer.com', + }, + }); + }); + + it('handles "Remove Token" press', () => { + const { getByText } = render( + , + ); + + fireEvent.press(getByText(strings('asset_details.options.remove_token'))); + expect(mockNavigation.navigate).toHaveBeenCalledWith('RootModalFlow', { + screen: 'AssetHideConfirmation', + params: expect.anything(), + }); + }); + + it('handles "Token Details" press', () => { + const { getByText } = render( + , + ); + + fireEvent.press(getByText(strings('asset_details.options.token_details'))); + expect(mockNavigation.navigate).toHaveBeenCalledWith('AssetDetails'); + }); +}); diff --git a/app/components/Views/AssetOptions/__snapshots__/AssetOptions.test.tsx.snap b/app/components/Views/AssetOptions/__snapshots__/AssetOptions.test.tsx.snap new file mode 100644 index 000000000000..fdb892243bb4 --- /dev/null +++ b/app/components/Views/AssetOptions/__snapshots__/AssetOptions.test.tsx.snap @@ -0,0 +1,137 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`AssetOptions Component matches the snapshot 1`] = ` + + + + + + + + + + + View on Portfolio + + + + + + + + View on block explorer + + + + + + + + Token details + + + + + + + + Remove token + + + + + + +`;