2022-02-16 17:59:39 +01:00
|
|
|
import React from 'react';
|
|
|
|
import configureMockStore from 'redux-mock-store';
|
|
|
|
import { fireEvent } from '@testing-library/react';
|
|
|
|
import { renderWithProvider } from '../../../test/lib/render-helpers';
|
2022-10-06 16:43:52 +02:00
|
|
|
import Identicon from '../../components/ui/identicon';
|
2022-03-07 19:54:36 +01:00
|
|
|
import { isEqualCaseInsensitive } from '../../../shared/modules/string-utils';
|
2022-02-16 17:59:39 +01:00
|
|
|
import TokenDetailsPage from './token-details-page';
|
|
|
|
|
2022-03-22 20:46:18 +01:00
|
|
|
const testTokenAddress = '0xC011a73ee8576Fb46F5E1c5751cA3B9Fe0af2a6F';
|
2022-02-16 17:59:39 +01:00
|
|
|
const state = {
|
|
|
|
metamask: {
|
|
|
|
selectedAddress: '0xAddress',
|
|
|
|
contractExchangeRates: {
|
|
|
|
'0xAnotherToken': 0.015,
|
|
|
|
},
|
|
|
|
useTokenDetection: true,
|
|
|
|
tokenList: {
|
2022-03-22 20:46:18 +01:00
|
|
|
'0xc011a73ee8576fb46f5e1c5751ca3b9fe0af2a6f': {
|
|
|
|
address: '0xc011a73ee8576fb46f5e1c5751ca3b9fe0af2a6f',
|
|
|
|
aggregators: [
|
|
|
|
'Aave',
|
|
|
|
'Bancor',
|
|
|
|
'CMC',
|
|
|
|
'Crypto.com',
|
|
|
|
'CoinGecko',
|
|
|
|
'1inch',
|
|
|
|
'Paraswap',
|
|
|
|
'PMM',
|
|
|
|
'Synthetix',
|
|
|
|
'Zapper',
|
|
|
|
'Zerion',
|
|
|
|
'0x',
|
|
|
|
],
|
2022-02-16 17:59:39 +01:00
|
|
|
decimals: 18,
|
2022-03-22 20:46:18 +01:00
|
|
|
iconUrl: 'https://assets.coingecko.com/coins/images/3406/large/SNX.png',
|
|
|
|
name: 'Synthetix Network Token',
|
|
|
|
occurrences: 12,
|
|
|
|
symbol: 'SNX',
|
2022-02-16 17:59:39 +01:00
|
|
|
},
|
|
|
|
'0x1f9840a85d5af5bf1d1762f925bdaddc4201f984': {
|
|
|
|
address: '0x1f9840a85d5af5bf1d1762f925bdaddc4201f984',
|
2022-03-22 20:46:18 +01:00
|
|
|
aggregators: [
|
|
|
|
'Aave',
|
|
|
|
'Bancor',
|
|
|
|
'CMC',
|
|
|
|
'Crypto.com',
|
|
|
|
'CoinGecko',
|
|
|
|
'1inch',
|
|
|
|
'Paraswap',
|
|
|
|
'PMM',
|
|
|
|
'Zapper',
|
|
|
|
'Zerion',
|
|
|
|
'0x',
|
|
|
|
],
|
2022-02-16 17:59:39 +01:00
|
|
|
decimals: 18,
|
2022-03-22 20:46:18 +01:00
|
|
|
iconUrl:
|
|
|
|
'https://images.prismic.io/token-price-prod/d0352dd9-5de8-4633-839d-bc3422c44d9c_UNI%404x.png',
|
|
|
|
name: 'Uniswap',
|
|
|
|
occurrences: 11,
|
|
|
|
symbol: 'UNI',
|
2022-02-16 17:59:39 +01:00
|
|
|
},
|
2022-03-22 20:46:18 +01:00
|
|
|
'0x0bc529c00c6401aef6d220be8c6ea1667f6ad93e': {
|
|
|
|
address: '0x0bc529c00c6401aef6d220be8c6ea1667f6ad93e',
|
|
|
|
aggregators: [
|
|
|
|
'Aave',
|
|
|
|
'Bancor',
|
|
|
|
'CMC',
|
|
|
|
'Crypto.com',
|
|
|
|
'CoinGecko',
|
|
|
|
'1inch',
|
|
|
|
'Paraswap',
|
|
|
|
'PMM',
|
|
|
|
'Zapper',
|
|
|
|
'Zerion',
|
|
|
|
'0x',
|
|
|
|
],
|
2022-02-16 17:59:39 +01:00
|
|
|
decimals: 18,
|
2022-03-22 20:46:18 +01:00
|
|
|
iconUrl:
|
|
|
|
'https://images.prismic.io/token-price-prod/917bc4fa-59d4-40f5-a3ef-33035698ffe0_YFIxxxhdpi.png',
|
|
|
|
name: 'yearn.finance',
|
|
|
|
occurrences: 11,
|
|
|
|
symbol: 'YFI',
|
2022-02-16 17:59:39 +01:00
|
|
|
},
|
2022-03-22 20:46:18 +01:00
|
|
|
'0x408e41876cccdc0f92210600ef50372656052a38': {
|
|
|
|
address: '0x408e41876cccdc0f92210600ef50372656052a38',
|
|
|
|
aggregators: [
|
|
|
|
'Aave',
|
|
|
|
'Bancor',
|
|
|
|
'CMC',
|
|
|
|
'Crypto.com',
|
|
|
|
'CoinGecko',
|
|
|
|
'1inch',
|
|
|
|
'Paraswap',
|
|
|
|
'PMM',
|
|
|
|
'Zapper',
|
|
|
|
'Zerion',
|
|
|
|
'0x',
|
|
|
|
],
|
2022-02-16 17:59:39 +01:00
|
|
|
decimals: 18,
|
2022-03-22 20:46:18 +01:00
|
|
|
iconUrl: 'https://crypto.com/price/coin-data/icon/REN/color_icon.png',
|
|
|
|
name: 'Republic Token',
|
|
|
|
occurrences: 11,
|
|
|
|
symbol: 'REN',
|
|
|
|
},
|
|
|
|
'0x2260fac5e5542a773aa44fbcfedf7c193bc2c599': {
|
|
|
|
address: '0x2260fac5e5542a773aa44fbcfedf7c193bc2c599',
|
|
|
|
aggregators: [
|
|
|
|
'Aave',
|
|
|
|
'Bancor',
|
|
|
|
'CMC',
|
|
|
|
'Crypto.com',
|
|
|
|
'CoinGecko',
|
|
|
|
'1inch',
|
|
|
|
'Paraswap',
|
|
|
|
'PMM',
|
|
|
|
'Zapper',
|
|
|
|
'Zerion',
|
|
|
|
'0x',
|
|
|
|
],
|
|
|
|
decimals: 8,
|
|
|
|
iconUrl:
|
|
|
|
'https://images.prismic.io/token-price-prod/c27778b1-f402-45f0-9225-f24f24b0518a_WBTC-xxxhdpi.png',
|
|
|
|
name: 'Wrapped BTC',
|
|
|
|
occurrences: 11,
|
|
|
|
symbol: 'WBTC',
|
2022-02-16 17:59:39 +01:00
|
|
|
},
|
2022-03-22 20:46:18 +01:00
|
|
|
'0x9f8f72aa9304c8b593d555f12ef6589cc3a579a2': {
|
|
|
|
address: '0x9f8f72aa9304c8b593d555f12ef6589cc3a579a2',
|
|
|
|
aggregators: [
|
|
|
|
'Aave',
|
|
|
|
'Bancor',
|
|
|
|
'CMC',
|
|
|
|
'Crypto.com',
|
|
|
|
'CoinGecko',
|
|
|
|
'1inch',
|
|
|
|
'Paraswap',
|
|
|
|
'PMM',
|
|
|
|
'Zapper',
|
|
|
|
'Zerion',
|
|
|
|
'0x',
|
|
|
|
],
|
2022-02-16 17:59:39 +01:00
|
|
|
decimals: 18,
|
2022-03-22 20:46:18 +01:00
|
|
|
iconUrl: 'https://crypto.com/price/coin-data/icon/MKR/color_icon.png',
|
|
|
|
name: 'MakerDAO',
|
|
|
|
occurrences: 11,
|
|
|
|
symbol: 'MKR',
|
2022-02-16 17:59:39 +01:00
|
|
|
},
|
2022-03-22 20:46:18 +01:00
|
|
|
'0x514910771af9ca656af840dff83e8264ecf986ca': {
|
|
|
|
address: '0x514910771af9ca656af840dff83e8264ecf986ca',
|
|
|
|
aggregators: [
|
|
|
|
'Aave',
|
|
|
|
'Bancor',
|
|
|
|
'CMC',
|
|
|
|
'Crypto.com',
|
|
|
|
'CoinGecko',
|
|
|
|
'1inch',
|
|
|
|
'Paraswap',
|
|
|
|
'PMM',
|
|
|
|
'Zapper',
|
|
|
|
'Zerion',
|
|
|
|
'0x',
|
|
|
|
],
|
2022-02-16 17:59:39 +01:00
|
|
|
decimals: 18,
|
2022-03-22 20:46:18 +01:00
|
|
|
iconUrl: 'https://crypto.com/price/coin-data/icon/LINK/color_icon.png',
|
|
|
|
name: 'ChainLink Token',
|
|
|
|
occurrences: 11,
|
|
|
|
symbol: 'LINK',
|
2022-02-16 17:59:39 +01:00
|
|
|
},
|
2022-03-22 20:46:18 +01:00
|
|
|
'0x6b175474e89094c44da98b954eedeac495271d0f': {
|
|
|
|
address: '0x6b175474e89094c44da98b954eedeac495271d0f',
|
|
|
|
aggregators: [
|
|
|
|
'Aave',
|
|
|
|
'Bancor',
|
|
|
|
'CMC',
|
|
|
|
'Crypto.com',
|
|
|
|
'CoinGecko',
|
|
|
|
'1inch',
|
|
|
|
'Paraswap',
|
|
|
|
'PMM',
|
|
|
|
'Zapper',
|
|
|
|
'Zerion',
|
|
|
|
'0x',
|
|
|
|
],
|
2022-02-16 17:59:39 +01:00
|
|
|
decimals: 18,
|
2022-03-22 20:46:18 +01:00
|
|
|
iconUrl: 'https://crypto.com/price/coin-data/icon/DAI/color_icon.png',
|
|
|
|
name: 'Dai Stablecoin',
|
|
|
|
occurrences: 11,
|
|
|
|
symbol: 'DAI',
|
2022-02-16 17:59:39 +01:00
|
|
|
},
|
2022-03-22 20:46:18 +01:00
|
|
|
'0x04fa0d235c4abf4bcf4787af4cf447de572ef828': {
|
|
|
|
address: '0x04fa0d235c4abf4bcf4787af4cf447de572ef828',
|
|
|
|
aggregators: [
|
|
|
|
'Bancor',
|
|
|
|
'CMC',
|
|
|
|
'Crypto.com',
|
|
|
|
'CoinGecko',
|
|
|
|
'1inch',
|
|
|
|
'Paraswap',
|
|
|
|
'PMM',
|
|
|
|
'Zapper',
|
|
|
|
'Zerion',
|
|
|
|
'0x',
|
|
|
|
],
|
2022-02-16 17:59:39 +01:00
|
|
|
decimals: 18,
|
2022-03-22 20:46:18 +01:00
|
|
|
iconUrl:
|
|
|
|
'https://images.prismic.io/token-price-prod/e2850554-ccf6-4514-9c3c-a17e19dea82f_UMAxxxhdpi.png',
|
|
|
|
name: 'UMA',
|
|
|
|
occurrences: 10,
|
|
|
|
symbol: 'UMA',
|
2022-02-16 17:59:39 +01:00
|
|
|
},
|
|
|
|
},
|
2023-05-02 17:53:20 +02:00
|
|
|
providerConfig: {
|
2022-02-16 17:59:39 +01:00
|
|
|
type: 'mainnet',
|
|
|
|
nickname: '',
|
|
|
|
},
|
|
|
|
preferences: {
|
|
|
|
showFiatInTestnets: true,
|
|
|
|
},
|
|
|
|
tokens: [
|
|
|
|
{
|
2022-02-23 17:20:42 +01:00
|
|
|
address: testTokenAddress,
|
2022-03-22 20:46:18 +01:00
|
|
|
symbol: 'SNX',
|
2022-02-16 17:59:39 +01:00
|
|
|
decimals: 18,
|
2022-02-23 17:20:42 +01:00
|
|
|
image: 'testImage',
|
2022-02-16 17:59:39 +01:00
|
|
|
isERC721: false,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
address: '0xaD6D458402F60fD3Bd25163575031ACDce07538U',
|
|
|
|
symbol: 'DAU',
|
|
|
|
decimals: 18,
|
|
|
|
image: null,
|
|
|
|
isERC721: false,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2022-02-23 17:20:42 +01:00
|
|
|
jest.mock('react-router-dom', () => {
|
|
|
|
const original = jest.requireActual('react-router-dom');
|
|
|
|
return {
|
|
|
|
...original,
|
|
|
|
useHistory: () => ({
|
|
|
|
push: jest.fn(),
|
2022-03-02 17:01:53 +01:00
|
|
|
}),
|
|
|
|
useParams: () => ({
|
|
|
|
address: testTokenAddress,
|
2022-02-23 17:20:42 +01:00
|
|
|
}),
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
2022-02-16 17:59:39 +01:00
|
|
|
describe('TokenDetailsPage', () => {
|
|
|
|
it('should render title "Token details" in token details page', () => {
|
|
|
|
const store = configureMockStore()(state);
|
|
|
|
const { getByText } = renderWithProvider(<TokenDetailsPage />, store);
|
|
|
|
expect(getByText('Token details')).toBeInTheDocument();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should close token details page when close button is clicked', () => {
|
|
|
|
const store = configureMockStore()(state);
|
|
|
|
const { container } = renderWithProvider(<TokenDetailsPage />, store);
|
|
|
|
const onCloseBtn = container.querySelector('.token-details__closeButton');
|
|
|
|
fireEvent.click(onCloseBtn);
|
|
|
|
expect(onCloseBtn).toBeDefined();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should render an icon image', () => {
|
2022-02-23 17:20:42 +01:00
|
|
|
const token = state.metamask.tokens.find(({ address }) =>
|
|
|
|
isEqualCaseInsensitive(address, testTokenAddress),
|
|
|
|
);
|
|
|
|
const iconImage = (
|
|
|
|
<Identicon diameter={32} address={testTokenAddress} image={token.image} />
|
2022-02-16 17:59:39 +01:00
|
|
|
);
|
2022-02-23 17:20:42 +01:00
|
|
|
expect(iconImage).toBeDefined();
|
2022-02-16 17:59:39 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should render token contract address title in token details page', () => {
|
|
|
|
const store = configureMockStore()(state);
|
|
|
|
const { getByText } = renderWithProvider(<TokenDetailsPage />, store);
|
2022-08-08 21:01:38 +02:00
|
|
|
expect(getByText('Token contract address')).toBeInTheDocument();
|
2022-02-16 17:59:39 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should render token contract address in token details page', () => {
|
|
|
|
const store = configureMockStore()(state);
|
|
|
|
const { getByText } = renderWithProvider(<TokenDetailsPage />, store);
|
2022-02-23 17:20:42 +01:00
|
|
|
expect(getByText(testTokenAddress)).toBeInTheDocument();
|
2022-02-16 17:59:39 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should call copy button when click is simulated', () => {
|
|
|
|
const store = configureMockStore()(state);
|
|
|
|
const { container } = renderWithProvider(<TokenDetailsPage />, store);
|
|
|
|
const handleCopyBtn = container.querySelector('.token-details__copyIcon');
|
|
|
|
fireEvent.click(handleCopyBtn);
|
|
|
|
expect(handleCopyBtn).toBeDefined();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should render token decimal title in token details page', () => {
|
|
|
|
const store = configureMockStore()(state);
|
|
|
|
const { getByText } = renderWithProvider(<TokenDetailsPage />, store);
|
2022-08-08 21:01:38 +02:00
|
|
|
expect(getByText('Token decimal:')).toBeInTheDocument();
|
2022-02-16 17:59:39 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should render number of token decimals in token details page', () => {
|
|
|
|
const store = configureMockStore()(state);
|
|
|
|
const { getByText } = renderWithProvider(<TokenDetailsPage />, store);
|
|
|
|
expect(getByText('18')).toBeInTheDocument();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should render current network title in token details page', () => {
|
|
|
|
const store = configureMockStore()(state);
|
|
|
|
const { getByText } = renderWithProvider(<TokenDetailsPage />, store);
|
|
|
|
expect(getByText('Network:')).toBeInTheDocument();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should render current network in token details page', () => {
|
|
|
|
const store = configureMockStore()(state);
|
|
|
|
const { getByText } = renderWithProvider(<TokenDetailsPage />, store);
|
|
|
|
expect(getByText('Ethereum Mainnet')).toBeInTheDocument();
|
|
|
|
});
|
|
|
|
|
2022-03-22 20:46:18 +01:00
|
|
|
it('should render token list title in token details page', () => {
|
|
|
|
const store = configureMockStore()(state);
|
|
|
|
const { getByText } = renderWithProvider(<TokenDetailsPage />, store);
|
|
|
|
expect(getByText('Token lists:')).toBeInTheDocument();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should render token list for the token in token details page', () => {
|
|
|
|
const store = configureMockStore()(state);
|
|
|
|
const { getByText } = renderWithProvider(<TokenDetailsPage />, store);
|
|
|
|
expect(
|
|
|
|
getByText(
|
|
|
|
'Aave, Bancor, CMC, Crypto.com, CoinGecko, 1inch, Paraswap, PMM, Synthetix, Zapper, Zerion, 0x.',
|
|
|
|
),
|
|
|
|
).toBeInTheDocument();
|
|
|
|
});
|
|
|
|
|
2022-02-16 17:59:39 +01:00
|
|
|
it('should call hide token button when button is clicked in token details page', () => {
|
|
|
|
const store = configureMockStore()(state);
|
|
|
|
const { container } = renderWithProvider(<TokenDetailsPage />, store);
|
|
|
|
const hideTokenBtn = container.querySelector(
|
|
|
|
'.token-details__hide-token-button',
|
|
|
|
);
|
|
|
|
fireEvent.click(hideTokenBtn);
|
|
|
|
expect(hideTokenBtn).toBeDefined();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should render label of hide token button in token details page', () => {
|
|
|
|
const store = configureMockStore()(state);
|
|
|
|
const { getByText } = renderWithProvider(<TokenDetailsPage />, store);
|
|
|
|
expect(getByText('Hide token')).toBeInTheDocument();
|
|
|
|
});
|
|
|
|
});
|