Commit 4d85775d authored by eddie's avatar eddie Committed by GitHub

fix: update CurrencyList unit tests (#6321)

* fix: testing snapshot updates

* fix: remove inline style and update snapshots tests
parent c1c59ca6
import { screen } from '@testing-library/react'
import { Currency, CurrencyAmount as mockCurrencyAmount, Token as mockToken } from '@uniswap/sdk-core' import { Currency, CurrencyAmount as mockCurrencyAmount, Token as mockToken } from '@uniswap/sdk-core'
import { DAI, USDC_MAINNET, WBTC } from 'constants/tokens' import { DAI, USDC_MAINNET, WBTC } from 'constants/tokens'
import * as mockJSBI from 'jsbi' import * as mockJSBI from 'jsbi'
...@@ -42,37 +43,38 @@ jest.mock('../../../state/connection/hooks', () => { ...@@ -42,37 +43,38 @@ jest.mock('../../../state/connection/hooks', () => {
}) })
it('renders loading rows when isLoading is true', () => { it('renders loading rows when isLoading is true', () => {
const { asFragment } = render( const component = render(
<CurrencyList <CurrencyList
height={10} height={10}
currencies={[]} currencies={[]}
otherListTokens={[]} otherListTokens={[]}
selectedCurrency={null} selectedCurrency={null}
onCurrencySelect={noOp} onCurrencySelect={noOp}
showImportView={noOp}
setImportToken={noOp}
isLoading={true} isLoading={true}
searchQuery="" searchQuery=""
isAddressSearch="" isAddressSearch=""
/> />
) )
expect(asFragment()).toMatchSnapshot() expect(component.findByTestId('loading-rows')).toBeTruthy()
expect(screen.queryByText('Wrapped BTC')).not.toBeInTheDocument()
expect(screen.queryByText('DAI')).not.toBeInTheDocument()
expect(screen.queryByText('USDC')).not.toBeInTheDocument()
}) })
it('renders currency rows correctly when currencies list is non-empty', () => { it('renders currency rows correctly when currencies list is non-empty', () => {
const { asFragment } = render( render(
<CurrencyList <CurrencyList
height={10} height={10}
currencies={[DAI, USDC_MAINNET, WBTC]} currencies={[DAI, USDC_MAINNET, WBTC]}
otherListTokens={[]} otherListTokens={[]}
selectedCurrency={null} selectedCurrency={null}
onCurrencySelect={noOp} onCurrencySelect={noOp}
showImportView={noOp}
setImportToken={noOp}
isLoading={false} isLoading={false}
searchQuery="" searchQuery=""
isAddressSearch="" isAddressSearch=""
/> />
) )
expect(asFragment()).toMatchSnapshot() expect(screen.getByText('Wrapped BTC')).toBeInTheDocument()
expect(screen.getByText('DAI')).toBeInTheDocument()
expect(screen.getByText('USDC')).toBeInTheDocument()
}) })
...@@ -20,7 +20,7 @@ import CurrencyLogo from '../../Logo/CurrencyLogo' ...@@ -20,7 +20,7 @@ import CurrencyLogo from '../../Logo/CurrencyLogo'
import Row, { RowFixed } from '../../Row' import Row, { RowFixed } from '../../Row'
import { MouseoverTooltip } from '../../Tooltip' import { MouseoverTooltip } from '../../Tooltip'
import { LoadingRows, MenuItem } from '../styleds' import { LoadingRows, MenuItem } from '../styleds'
import * as styles from './index.css' import { scrollbarStyle } from './index.css'
function currencyKey(currency: Currency): string { function currencyKey(currency: Currency): string {
return currency.isToken ? currency.address : 'ETHER' return currency.isToken ? currency.address : 'ETHER'
...@@ -65,6 +65,10 @@ const WarningContainer = styled.div` ...@@ -65,6 +65,10 @@ const WarningContainer = styled.div`
margin-left: 0.3em; margin-left: 0.3em;
` `
const ListWrapper = styled.div`
padding-right: 0.25rem;
`
function Balance({ balance }: { balance: CurrencyAmount<Currency> }) { function Balance({ balance }: { balance: CurrencyAmount<Currency> }) {
return <StyledBalanceText title={balance.toExact()}>{balance.toSignificant(4)}</StyledBalanceText> return <StyledBalanceText title={balance.toExact()}>{balance.toSignificant(4)}</StyledBalanceText>
} }
...@@ -212,7 +216,7 @@ export const formatAnalyticsEventProperties = ( ...@@ -212,7 +216,7 @@ export const formatAnalyticsEventProperties = (
}) })
const LoadingRow = () => ( const LoadingRow = () => (
<LoadingRows> <LoadingRows data-testid="loading-rows">
<div /> <div />
<div /> <div />
<div /> <div />
...@@ -290,10 +294,10 @@ export default function CurrencyList({ ...@@ -290,10 +294,10 @@ export default function CurrencyList({
}, []) }, [])
return ( return (
<div style={{ paddingRight: '4px' }}> <ListWrapper>
{isLoading ? ( {isLoading ? (
<FixedSizeList <FixedSizeList
className={styles.scrollbarStyle} className={scrollbarStyle}
height={height} height={height}
ref={fixedListRef as any} ref={fixedListRef as any}
width="100%" width="100%"
...@@ -305,7 +309,7 @@ export default function CurrencyList({ ...@@ -305,7 +309,7 @@ export default function CurrencyList({
</FixedSizeList> </FixedSizeList>
) : ( ) : (
<FixedSizeList <FixedSizeList
className={styles.scrollbarStyle} className={scrollbarStyle}
height={height} height={height}
ref={fixedListRef as any} ref={fixedListRef as any}
width="100%" width="100%"
...@@ -317,6 +321,6 @@ export default function CurrencyList({ ...@@ -317,6 +321,6 @@ export default function CurrencyList({
{Row} {Row}
</FixedSizeList> </FixedSizeList>
)} )}
</div> </ListWrapper>
) )
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment