Add `data-testid` to the `EthOverview` balances (#8951)

Both the primary and secondary balance components on `EthOverview` now
have `data-testid` props, so that they can be more easily referenced in
e2e tests.

This required the addition of a `data-testid` prop to the component
`UserPreferencedCurrencyDisplay`, which is passed through to the
underlying `CurrencyDisplay` component.
feature/default_network_editable
Mark Stacey 4 years ago committed by GitHub
parent ada59e2614
commit b485a9afb3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      test/e2e/metamask-responsive-ui.spec.js
  2. 2
      test/e2e/metamask-ui.spec.js
  3. 13
      ui/app/components/app/user-preferenced-currency-display/user-preferenced-currency-display.component.js
  4. 2
      ui/app/components/app/wallet-overview/eth-overview.js

@ -166,7 +166,7 @@ describe('MetaMask', function () {
}) })
it('balance renders', async function () { it('balance renders', async function () {
const balance = await driver.findElement(By.css('.eth-overview__primary-balance')) const balance = await driver.findElement(By.css('[data-testid="eth-overview__primary-currency"]'))
await driver.wait(until.elementTextMatches(balance, /100\s*ETH/)) await driver.wait(until.elementTextMatches(balance, /100\s*ETH/))
await driver.delay(regularDelayMs) await driver.delay(regularDelayMs)
}) })

@ -750,7 +750,7 @@ describe('MetaMask', function () {
}) })
it('renders the correct ETH balance', async function () { it('renders the correct ETH balance', async function () {
const balance = await driver.findElement(By.css('.eth-overview__primary-balance')) const balance = await driver.findElement(By.css('[data-testid="eth-overview__primary-currency"]'))
await driver.delay(regularDelayMs) await driver.delay(regularDelayMs)
await driver.wait(until.elementTextMatches(balance, /^87.*\s*ETH.*$/), 10000) await driver.wait(until.elementTextMatches(balance, /^87.*\s*ETH.*$/), 10000)
const tokenAmount = await balance.getText() const tokenAmount = await balance.getText()

@ -4,7 +4,16 @@ import { PRIMARY, SECONDARY, ETH } from '../../../helpers/constants/common'
import CurrencyDisplay from '../../ui/currency-display' import CurrencyDisplay from '../../ui/currency-display'
import { useUserPreferencedCurrency } from '../../../hooks/useUserPreferencedCurrency' import { useUserPreferencedCurrency } from '../../../hooks/useUserPreferencedCurrency'
export default function UserPreferencedCurrencyDisplay ({ type, showEthLogo, ethLogoHeight = 12, ethNumberOfDecimals, fiatNumberOfDecimals, numberOfDecimals: propsNumberOfDecimals, ...restProps }) { export default function UserPreferencedCurrencyDisplay ({
'data-testid': dataTestId,
ethLogoHeight = 12,
ethNumberOfDecimals,
fiatNumberOfDecimals,
numberOfDecimals: propsNumberOfDecimals,
showEthLogo,
type,
...restProps
}) {
const { currency, numberOfDecimals } = useUserPreferencedCurrency(type, { ethNumberOfDecimals, fiatNumberOfDecimals, numberOfDecimals: propsNumberOfDecimals }) const { currency, numberOfDecimals } = useUserPreferencedCurrency(type, { ethNumberOfDecimals, fiatNumberOfDecimals, numberOfDecimals: propsNumberOfDecimals })
const prefixComponent = useMemo(() => { const prefixComponent = useMemo(() => {
@ -20,6 +29,7 @@ export default function UserPreferencedCurrencyDisplay ({ type, showEthLogo, eth
<CurrencyDisplay <CurrencyDisplay
{...restProps} {...restProps}
currency={currency} currency={currency}
data-testid={dataTestId}
numberOfDecimals={numberOfDecimals} numberOfDecimals={numberOfDecimals}
prefixComponent={prefixComponent} prefixComponent={prefixComponent}
/> />
@ -28,6 +38,7 @@ export default function UserPreferencedCurrencyDisplay ({ type, showEthLogo, eth
UserPreferencedCurrencyDisplay.propTypes = { UserPreferencedCurrencyDisplay.propTypes = {
className: PropTypes.string, className: PropTypes.string,
'data-testid': PropTypes.string,
prefix: PropTypes.string, prefix: PropTypes.string,
value: PropTypes.string, value: PropTypes.string,
numberOfDecimals: PropTypes.oneOfType([PropTypes.string, PropTypes.number]), numberOfDecimals: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),

@ -50,6 +50,7 @@ const EthOverview = ({ className }) => {
className={classnames('eth-overview__primary-balance', { className={classnames('eth-overview__primary-balance', {
'eth-overview__cached-balance': balanceIsCached, 'eth-overview__cached-balance': balanceIsCached,
})} })}
data-testid="eth-overview__primary-currency"
value={balance} value={balance}
type={PRIMARY} type={PRIMARY}
ethNumberOfDecimals={4} ethNumberOfDecimals={4}
@ -66,6 +67,7 @@ const EthOverview = ({ className }) => {
'eth-overview__cached-secondary-balance': balanceIsCached, 'eth-overview__cached-secondary-balance': balanceIsCached,
'eth-overview__secondary-balance': !balanceIsCached, 'eth-overview__secondary-balance': !balanceIsCached,
})} })}
data-testid="eth-overview__secondary-currency"
value={balance} value={balance}
type={SECONDARY} type={SECONDARY}
ethNumberOfDecimals={4} ethNumberOfDecimals={4}

Loading…
Cancel
Save