Changeset View
Changeset View
Standalone View
Standalone View
web/cashtab/src/utils/__tests__/cashMethods.test.js
import { fromSmallestDenomination } from '@utils/cashMethods'; | import { fromSmallestDenomination, formatBalance } from '@utils/cashMethods'; | ||||
describe('Correctly executes cash utility functions', () => { | describe('Correctly executes cash utility functions', () => { | ||||
it(`Correctly converts smallest base unit to smallest decimal for cashDecimals = 2`, () => { | it(`Correctly converts smallest base unit to smallest decimal for cashDecimals = 2`, () => { | ||||
expect(fromSmallestDenomination(1, 2)).toBe(0.01); | expect(fromSmallestDenomination(1, 2)).toBe(0.01); | ||||
}); | }); | ||||
it(`Correctly converts largest base unit to smallest decimal for cashDecimals = 2`, () => { | it(`Correctly converts largest base unit to smallest decimal for cashDecimals = 2`, () => { | ||||
expect(fromSmallestDenomination(1000000012345678, 2)).toBe( | expect(fromSmallestDenomination(1000000012345678, 2)).toBe( | ||||
10000000123456.78, | 10000000123456.78, | ||||
); | ); | ||||
}); | }); | ||||
it(`Correctly converts smallest base unit to smallest decimal for cashDecimals = 8`, () => { | it(`Correctly converts smallest base unit to smallest decimal for cashDecimals = 8`, () => { | ||||
expect(fromSmallestDenomination(1, 8)).toBe(0.00000001); | expect(fromSmallestDenomination(1, 8)).toBe(0.00000001); | ||||
}); | }); | ||||
it(`Correctly converts largest base unit to smallest decimal for cashDecimals = 8`, () => { | it(`Correctly converts largest base unit to smallest decimal for cashDecimals = 8`, () => { | ||||
expect(fromSmallestDenomination(1000000012345678, 8)).toBe( | expect(fromSmallestDenomination(1000000012345678, 8)).toBe( | ||||
10000000.12345678, | 10000000.12345678, | ||||
); | ); | ||||
}); | }); | ||||
it(`Formats a large number to add commas`, () => { | |||||
expect(formatBalance(1000000012345678)).toBe('1,000,000,012,345,678'); | |||||
}); | |||||
it(`Formats a large number with 2 decimal places to add commas`, () => { | |||||
expect(formatBalance(10000000123456.78)).toBe('10,000,000,123,456.78'); | |||||
}); | |||||
}); | }); |