-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelperFunctions.test.js
88 lines (75 loc) · 2.37 KB
/
helperFunctions.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import { formatCurrency, formatNumber } from './helperFunctions';
describe('lib: Helper Functions', () => {
describe('currency Formater', () => {
it('should format currency', () => {
const amounts = [
{
amount: 1000,
currencyPosition: 'front',
currency: 'RWF',
expected: 'RWF 1,000.00',
deicmalsToShow: 2
},
{
amount: 1000,
currencyPosition: 'back',
currency: 'RWF',
expected: '1,000.00 RWF',
deicmalsToShow: 2
},
{
amount: 10,
currencyPosition: 'back',
currency: 'KSH',
expected: '10.00 KSH',
deicmalsToShow: 2
},
{
amount: 1935.9987,
currencyPosition: 'front',
currency: 'UGS',
expected: 'UGS 1,935.999',
deicmalsToShow: 3
},
{
amount: 1935.9987,
currencyPosition: 'front',
currency: 'UGS',
expected: 'UGS 1,935.9987',
deicmalsToShow: 4
}
];
amounts.forEach((amount) => {
const result = formatCurrency(
amount.amount,
amount.currency,
amount.currencyPosition,
amount.deicmalsToShow
);
expect(result).toStrictEqual(amount.expected);
});
});
it('returns blank if current symbol not supplied', () => {
const result = formatCurrency('98.00.34');
expect(result).toEqual('');
});
it('defaults to front if currency position is invalid', () => {
const result = formatCurrency(1000, 'RWF', 'center', 2);
expect(result).toStrictEqual('RWF 1,000.00');
});
it('should return negative sign for negative number', () => {
const result = formatCurrency(-1000, 'RWF', 'center', 2);
expect(result).toStrictEqual('-RWF 1,000.00');
});
});
describe('number Formater', () => {
it('should format number', () => {
const num1 = formatNumber(99, 0)
expect(num1).toEqual(num1)
const num2 = formatNumber(99, 2)
expect(num2).toEqual("99.00")
const num3 = formatNumber(100.45, 2)
expect(num3).toEqual("100.45")
});
});
});