Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: unit tests composables #16

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
102 changes: 95 additions & 7 deletions packages/ui-shared/lib/composables/useBigNumberFormatter.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,22 +48,110 @@ describe('useBigNumberFormatter', () => {
})
})

/*
describe('with decimal places', () => {
test('should return a big number', () => {
//
test('from string', () => {
const { valueToString } = useBigNumberFormatter(
computed(() => number.toString()),
{ decimalPlaces: 2, roundingMode: BigNumber.ROUND_DOWN }
)

expect(valueToString.value).eq(
new BigNumber(number.toString()).toFixed(2, BigNumber.ROUND_DOWN)
)
})
})

describe('with minimal decimal places', () => {
//
test('from string with lower value than decimal places', () => {
const { valueToString } = useBigNumberFormatter(
computed(() => '0.001'),
{ minimalDecimalPlaces: 2 }
)

expect(valueToString.value).eq('< 0.01')
})

test('from string with higher value than decimal places', () => {
const { valueToString } = useBigNumberFormatter(
computed(() => '0.10'),
{ minimalDecimalPlaces: 2 }
)

expect(valueToString.value).eq('0.10')
})
})

describe('with abbreviation floor', () => {
//
test('with number lower than abbreviation floor ', () => {
const { valueToString } = useBigNumberFormatter(
computed(() => '13999888'),
{ abbreviationFloor: 14000000 }
)

expect(valueToString.value).eq('13,999,888.00')
})

test('with number higher than abbreviation floor ,near ceiling ', () => {
const { valueToString } = useBigNumberFormatter(
computed(() => '13999888'),
{ abbreviationFloor: 13000000 }
)

expect(valueToString.value).eq('≈14M')
})

test('with number higher than abbreviation floor, near floor ', () => {
const { valueToString } = useBigNumberFormatter(
computed(() => '13199888'),
{ abbreviationFloor: 13000000 }
)

expect(valueToString.value).eq('≈13M')
})

test('with number higher than abbreviation floor, exact number ', () => {
const { valueToString } = useBigNumberFormatter(
computed(() => '13000000'),
{ abbreviationFloor: 13000000 }
)

expect(valueToString.value).eq('13M')
})
})

describe('with rounding mode', () => {
//
}) */
test('from string, round down ', () => {
const { valueToString } = useBigNumberFormatter(
computed(() => number.toString()),
{ roundingMode: BigNumber.ROUND_DOWN }
)

expect(valueToString.value).eq(
new BigNumber(number).toFixed(2, BigNumber.ROUND_DOWN)
)
})

test('from undefined ', () => {
const { valueToString } = useBigNumberFormatter(
computed(() => undefined),
{ roundingMode: BigNumber.ROUND_DOWN }
)

expect(valueToString.value).eq('0.00')
})
})

describe('with inj', () => {
test('from string ', () => {
const { valueWithGasBufferToString, valueToBigNumber } =
useBigNumberFormatter(
computed(() => '1.0000000000000000'),
{ injFee: 0.001, decimalPlaces: 5 }
)

expect(valueWithGasBufferToString.value).eq(
valueToBigNumber.value.minus(0.001).toFixed(5)
)
})
})
})