-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
420 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
3 changes: 3 additions & 0 deletions
3
app/components/UI/NetworkAssetLogo/__snapshots__/index.test.tsx.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`NetworkAssetLogo Component matches the snapshot for non-mainnet 1`] = `null`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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( | ||
<NetworkAssetLogo | ||
chainId="42" | ||
ticker="DAI" | ||
style={{}} | ||
big | ||
biggest={false} | ||
testID="network-asset-logo" | ||
/>, | ||
); | ||
|
||
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(<NetworkAssetLogo {...props} />); | ||
|
||
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(<NetworkAssetLogo {...props} />); | ||
|
||
expect(TokenIcon).toHaveBeenCalledWith( | ||
{ | ||
big: props.big, | ||
biggest: props.biggest, | ||
symbol: props.ticker, | ||
style: props.style, | ||
testID: props.testID, | ||
}, | ||
{}, | ||
); | ||
}); | ||
}); |
196 changes: 196 additions & 0 deletions
196
app/components/Views/AssetOptions/AssetOptions.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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( | ||
<AssetOptions | ||
route={{ | ||
params: { | ||
address: '0x123', | ||
isNativeCurrency: false, | ||
}, | ||
}} | ||
/>, | ||
); | ||
|
||
expect(toJSON()).toMatchSnapshot(); | ||
}); | ||
|
||
it('renders correctly and displays options', () => { | ||
const { getByText } = render( | ||
<AssetOptions | ||
route={{ | ||
params: { | ||
address: '0x123', | ||
isNativeCurrency: false, | ||
}, | ||
}} | ||
/>, | ||
); | ||
|
||
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( | ||
<AssetOptions | ||
route={{ | ||
params: { | ||
address: '0x123', | ||
isNativeCurrency: false, | ||
}, | ||
}} | ||
/>, | ||
); | ||
|
||
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( | ||
<AssetOptions | ||
route={{ | ||
params: { | ||
address: '0x123', | ||
isNativeCurrency: false, | ||
}, | ||
}} | ||
/>, | ||
); | ||
|
||
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( | ||
<AssetOptions | ||
route={{ | ||
params: { | ||
address: '0x123', | ||
isNativeCurrency: false, | ||
}, | ||
}} | ||
/>, | ||
); | ||
|
||
fireEvent.press(getByText(strings('asset_details.options.token_details'))); | ||
expect(mockNavigation.navigate).toHaveBeenCalledWith('AssetDetails'); | ||
}); | ||
}); |
Oops, something went wrong.