Skip to content

Commit

Permalink
fix: lint and unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
micaelae committed Sep 5, 2024
1 parent cc82bf4 commit eb0ad0e
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -296,15 +296,20 @@ describe('AssetPickerModal', () => {
).toBe(true);
});

it('should render network picker when networks prop is defined', () => {
it('should render network picker when onNetworkPickerClick prop is defined', () => {
const { getByText, getAllByRole } = renderWithProvider(
<AssetPickerModal
{...defaultProps}
header="selectNetworkHeader"
network={{
type: 'rpc',
ticker: 'ETH',
chainId: '0x1',
rpcUrl: 'https://rpcurl',
rpcPrefs: {
blockExplorerUrl: 'https://explorerurl',
imageUrl: 'https://image.com',
},
nickname: 'Network name',
}}
/>,
store,
Expand All @@ -314,7 +319,33 @@ describe('AssetPickerModal', () => {
expect(modalTitle).toBeInTheDocument();

expect(getAllByRole('img')).toHaveLength(2);
const modalContent = getByText('Select network');
const modalContent = getByText('Network name');
expect(modalContent).toBeInTheDocument();
});

it('should not render network picker when onNetworkPickerClick prop is not defined', () => {
const { getByText, getAllByRole } = renderWithProvider(
<AssetPickerModal
{...defaultProps}
onNetworkPickerClick={undefined}
header="selectNetworkHeader"
network={{
ticker: 'ETH',
chainId: '0x1',
rpcUrl: 'https://rpcurl',
rpcPrefs: {
blockExplorerUrl: 'https://explorerurl',
imageUrl: 'https://image.com',
},
nickname: 'Network name',
}}
/>,
store,
);

const modalTitle = getByText('selectNetworkHeader');
expect(modalTitle).toBeInTheDocument();

expect(getAllByRole('img')).toHaveLength(1);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -330,11 +330,7 @@ export function AssetPickerModal({
<Box className="network-picker">
<PickerNetwork
label={network?.nickname ?? 'Select network'}
src={
network?.rpcPrefs && 'imageUrl' in network.rpcPrefs
? (network.rpcPrefs.imageUrl as string)
: undefined
}
src={network?.rpcPrefs?.imageUrl}
onClick={onNetworkPickerClick}
data-testid="multichain-asset-picker__network"
/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
@use "design-system";

.multichain-asset-picker__network-modal {
overflow-y:auto;
overflow-y: auto;

.mm-modal-content__dialog {
overflow-y: scroll;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -314,10 +314,37 @@ describe('AssetPicker', () => {
onAssetChange={() => mockAssetChange()}
isDisabled
networkProps={{
network: { chainId: '0x1', type: 'rpc', ticker: 'ETH' },
network: {
chainId: '0x1',
ticker: 'ETH',
rpcUrl: 'https://rpcurl',
rpcPrefs: {
blockExplorerUrl: 'https://explorerurl',
imageUrl: './images/eth_logo.svg',
},
nickname: 'network',
},
networks: [
{ chainId: '0x1', type: 'rpc', ticker: 'ETH' },
{ chainId: '0xa', type: 'rpc', ticker: 'ETH' },
{
chainId: '0x1',
ticker: 'ETH',
rpcUrl: 'https://rpcurl',
rpcPrefs: {
blockExplorerUrl: 'https://explorerurl',
imageUrl: 'https://image.com',
},
nickname: 'Network name 3',
},
{
chainId: '0xa',
ticker: 'ETH',
rpcUrl: 'https://rpcurl',
rpcPrefs: {
blockExplorerUrl: 'https://explorerurl',
imageUrl: 'https://image.com',
},
nickname: 'Network name 4',
},
],
onNetworkChange: jest.fn(),
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ export function AssetPicker({
selectedNetwork?.rpcPrefs?.imageUrl ??
(selectedNetwork?.chainId &&
CHAIN_ID_TO_NETWORK_IMAGE_URL_MAP[
selectedNetwork.chainId
selectedNetwork.chainId as keyof typeof CHAIN_ID_TO_NETWORK_IMAGE_URL_MAP
])
}
backgroundColor={
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
cursor: not-allowed;
}

&__fallback{
&__fallback {
text-wrap: nowrap;
padding-left: 8px;
}
Expand Down

0 comments on commit eb0ad0e

Please sign in to comment.