Skip to content

Commit

Permalink
update test for formatDataNumber
Browse files Browse the repository at this point in the history
  • Loading branch information
alekseevaiana committed Jul 2, 2024
1 parent 26239ea commit c657651
Showing 1 changed file with 12 additions and 43 deletions.
55 changes: 12 additions & 43 deletions src/utils/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
safeIsSafe,
} from './helper'
import { ChainId } from './interfaces'
import { utils } from 'ethers'

describe('utils', () => {
describe('#getEtherscanLink', () => {
Expand Down Expand Up @@ -171,54 +170,24 @@ describe('utils', () => {
})

describe('formatDataNumber', () => {
it('formats a BigNumber string with default parameters', () => {
const input = utils.parseUnits('1234.56789', 18).toString()
expect(formatDataNumber(input)).toEqual('1,234.57')
it('handles format decimals correctly', () => {
const input = "2457565485783295579314012"
expect(formatDataNumber(input, 18, 2)).toEqual('2,457,565.49')
})

it('formats a BigNumber string with specified decimals', () => {
const input = utils.parseUnits('1234.56789', 18).toString()
expect(formatDataNumber(input, 18, 3)).toEqual('1,234.568')
it('handles dollar currency sign correctly', () => {
const input = "2457565485783295579314012"
expect(formatDataNumber(input, 18, 2, true)).toEqual('$2,457,565.49')
})

it('formats a BigNumber string as currency', () => {
const input = utils.parseUnits('1234.56789', 18).toString()
expect(formatDataNumber(input, 18, 2, true)).toEqual('$1,234.57')
it('handles compact value and currency sign correctly', () => {
const input = "2457565485783295579314012"
expect(formatDataNumber(input, 18, 2, true, true)).toEqual('$2.46M')
})

it('formats a BigNumber string as compact', () => {
const input = utils.parseUnits('1234567890', 18).toString()
expect(formatDataNumber(input, 18, 2, false, true)).toEqual('1.23B')
})

it('formats a BigNumber string with minimum decimals', () => {
const input = utils.parseUnits('0.00000001', 18).toString()
expect(formatDataNumber(input, 18, 2, false, false, 8)).toEqual('0.00000001')
})

it('returns formatted string with minimum decimals less than formatDecimal', () => {
const input = utils.parseUnits('0.001234', 18).toString()
expect(formatDataNumber(input, 18, 3, false, false, 2)).toEqual('0.001')
})

it('returns formatted string with currency and minimum decimals', () => {
const input = utils.parseUnits('0.00000001', 18).toString()
expect(formatDataNumber(input, 18, 2, true, false, 8)).toEqual('$0.00000001')
})

it('formats a number less than 0.01 correctly', () => {
const input = utils.parseUnits('0.0056789', 18).toString()
expect(formatDataNumber(input, 18, 2, true, false, 3)).toEqual('$0.006')
})

it('handles zero decimals correctly', () => {
const input = '1234567890'
expect(formatDataNumber(input, 0, 2)).toEqual('1,234,567,890.00')
})

it('formats a number correctly when minimumDecimals > formatDecimal', () => {
const input = utils.parseUnits('0.001234', 18).toString()
expect(formatDataNumber(input, 18, 2, false, false, 3)).toEqual('0.001')
it('handles compact format decimals and minimum decimals correctly', () => {
const input = "1000000000000000000"
expect(formatDataNumber(input, 18, 3, true, undefined, 4)).toEqual('$1.0000')
})
})
})

0 comments on commit c657651

Please sign in to comment.