Skip to content

Commit 0d52e36

Browse files
chore: tests
1 parent 2fff8e9 commit 0d52e36

1 file changed

Lines changed: 53 additions & 2 deletions

File tree

app/components/UI/Bridge/Views/BatchSellTokenSelect/BatchSellTokenSelect.test.tsx

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,18 @@ import React from 'react';
22
import { fireEvent, render } from '@testing-library/react-native';
33
import { TextColor as DSTextColor } from '@metamask/design-system-react-native';
44
import { CaipAssetType, CaipChainId, Hex } from '@metamask/utils';
5-
import { formatAddressToAssetId } from '@metamask/bridge-controller';
5+
import {
6+
formatAddressToAssetId,
7+
formatChainIdToCaip,
8+
} from '@metamask/bridge-controller';
69
import { BridgeToken } from '../../types';
710
import { BatchSellTokenSelect } from './BatchSellTokenSelect';
811
import { BatchSellTokenSelectSelectorsIDs } from './BatchSellTokenSelect.testIds';
912
import {
1013
buildBatchSellEligibleChains,
1114
removeStablecoinsFromSourceTokens,
1215
MAX_BATCH_SELL_SOURCE_TOKENS,
16+
SUPPORTED_BATCH_SELL_CHAIN_IDS,
1317
sortBatchSellTokens,
1418
} from './BatchSellTokenSelect.utils';
1519
import Routes from '../../../../../constants/navigation/Routes';
@@ -23,6 +27,7 @@ const mockDispatch = jest.fn();
2327
const mockNavigate = jest.fn();
2428
const mockGoBack = jest.fn();
2529
const mockSetOptions = jest.fn();
30+
const mockUseTokensWithBalance = jest.fn();
2631
let mockStablecoinsByChain: Record<CaipChainId, CaipAssetType[]> = {};
2732
let mockWalletTokens: BridgeToken[] = [];
2833
let mockPricePercentChangesByAddress: Record<string, number | undefined> = {};
@@ -307,7 +312,8 @@ jest.mock('../../../../../component-library/components/Buttons/Button', () => ({
307312
}));
308313

309314
jest.mock('../../hooks/useTokensWithBalance', () => ({
310-
useTokensWithBalance: () => mockWalletTokens,
315+
useTokensWithBalance: (options?: { chainIds?: CaipChainId[] }) =>
316+
mockUseTokensWithBalance(options),
311317
}));
312318

313319
jest.mock('../../../Tokens/hooks/useTokenPricePercentageChange', () => ({
@@ -550,6 +556,19 @@ describe('BatchSellTokenSelect', () => {
550556
mockWalletTokens = [
551557
createToken({ symbol: 'ETHA', name: 'Ethereum A', tokenFiatAmount: 10 }),
552558
];
559+
mockUseTokensWithBalance.mockImplementation(
560+
(options?: { chainIds?: CaipChainId[] }) => {
561+
if (!options?.chainIds) {
562+
return mockWalletTokens;
563+
}
564+
565+
return mockWalletTokens.filter((token) =>
566+
options.chainIds?.includes(
567+
formatChainIdToCaip(token.chainId) as CaipChainId,
568+
),
569+
);
570+
},
571+
);
553572
});
554573

555574
it('renders only eligible wallet tokens', () => {
@@ -613,6 +632,38 @@ describe('BatchSellTokenSelect', () => {
613632
).not.toBeOnTheScreen();
614633
});
615634

635+
it('does not render network pills for unsupported networks', () => {
636+
mockWalletTokens = [
637+
createToken({
638+
symbol: 'ETHA',
639+
name: 'Ethereum A',
640+
tokenFiatAmount: 10,
641+
}),
642+
createToken({
643+
symbol: 'AVAXA',
644+
name: 'Avalanche A',
645+
address: '0x2222222222222222222222222222222222222222',
646+
chainId: '0xa86a' as Hex,
647+
tokenFiatAmount: 100,
648+
}),
649+
];
650+
651+
const { getByTestId, queryByTestId, queryByText } = render(
652+
<BatchSellTokenSelect />,
653+
);
654+
655+
expect(mockUseTokensWithBalance).toHaveBeenCalledWith({
656+
chainIds: SUPPORTED_BATCH_SELL_CHAIN_IDS,
657+
});
658+
expect(
659+
getByTestId(getNetworkPillTestId('eip155:1' as CaipChainId)),
660+
).toBeOnTheScreen();
661+
expect(
662+
queryByTestId(getNetworkPillTestId('eip155:43114' as CaipChainId)),
663+
).not.toBeOnTheScreen();
664+
expect(queryByText('AVAXA')).not.toBeOnTheScreen();
665+
});
666+
616667
it('filters tokens to the selected network pill', () => {
617668
mockWalletTokens = [
618669
createToken({

0 commit comments

Comments
 (0)