1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-10-22 19:26:13 +02:00
metamask-extension/ui/hooks/useTokenDisplayValue.test.js
Mark Stacey ba54a3d83b
Update ESLint config to v8 (#12886)
The ESLint config has been updated to v8. The breaking changes are:

* The Prettier rule `quoteProps` has been changed from `consistent` to
`as-needed`, meaning that if one key requires quoting, only that key is
quoted rather than all keys.
* The ESLint rule `no-shadow` has been made more strict. It now
prevents globals from being shadowed as well.

Most of these changes were applied with `yarn lint:fix`. Only the
shadowing changes required manual fixing (shadowing variable names were
either replaced with destructuring or renamed).

The dependency `globalThis` was added to the list of dynamic
dependencies in the build system, where it should have been already.
This was causing `depcheck` to fail because the new lint rules required
removing the one place where `globalThis` had been erroneously imported
previously.

A rule requiring a newline between multiline blocks and expressions has
been disabled temporarily to make this PR smaller and to avoid
introducing conflicts with other PRs.
2021-12-09 15:36:24 -03:30

139 lines
2.8 KiB
JavaScript

import { renderHook } from '@testing-library/react-hooks';
import sinon from 'sinon';
import * as tokenUtil from '../helpers/utils/token-util';
import * as txUtil from '../helpers/utils/transactions.util';
import { useTokenDisplayValue } from './useTokenDisplayValue';
const tests = [
{
token: {
symbol: 'DAI',
decimals: 18,
},
tokenData: {
args: 'decoded-params1',
},
tokenValue: '1000000000000000000',
displayValue: '1',
},
{
token: {
symbol: 'DAI',
decimals: 18,
},
tokenData: {
args: 'decoded-params2',
},
tokenValue: '10000000000000000000',
displayValue: '10',
},
{
token: {
symbol: 'DAI',
decimals: 18,
},
tokenData: {
args: 'decoded-params3',
},
tokenValue: '1500000000000000000',
displayValue: '1.5',
},
{
token: {
symbol: 'DAI',
decimals: 18,
},
tokenData: {
args: 'decoded-params4',
},
tokenValue: '1756000000000000000',
displayValue: '1.756',
},
{
token: {
symbol: 'DAI',
decimals: 18,
},
tokenData: {
args: 'decoded-params5',
},
tokenValue: '25500000000000000000',
displayValue: '25.5',
},
{
token: {
symbol: 'USDC',
decimals: 6,
},
tokenData: {
args: 'decoded-params6',
},
tokenValue: '1000000',
displayValue: '1',
},
{
token: {
symbol: 'USDC',
decimals: 6,
},
tokenData: {
args: 'decoded-params7',
},
tokenValue: '10000000',
displayValue: '10',
},
{
token: {
symbol: 'USDC',
decimals: 6,
},
tokenData: {
args: 'decoded-params8',
},
tokenValue: '1500000',
displayValue: '1.5',
},
{
token: {
symbol: 'USDC',
decimals: 6,
},
tokenData: {
args: 'decoded-params9',
},
tokenValue: '1756000',
displayValue: '1.756',
},
{
token: {
symbol: 'USDC',
decimals: 6,
},
tokenData: {
args: 'decoded-params10',
},
tokenValue: '25500000',
displayValue: '25.5',
},
];
describe('useTokenDisplayValue', () => {
tests.forEach(({ displayValue, token, tokenData, tokenValue }, idx) => {
describe(`when input is decimals: ${token.decimals} and value: ${tokenValue}`, () => {
it(`should return ${displayValue} as displayValue`, () => {
const getTokenValueStub = sinon.stub(tokenUtil, 'getTokenValueParam');
const getTokenDataStub = sinon.stub(txUtil, 'getTokenData');
getTokenDataStub.callsFake(() => tokenData);
getTokenValueStub.callsFake(() => tokenValue);
const { result } = renderHook(() =>
useTokenDisplayValue(`${idx}-fakestring`, token),
);
sinon.restore();
expect(result.current).toStrictEqual(displayValue);
});
});
});
});