|
1 | 1 | const plh = require('./../dist/index.js');
|
2 | 2 |
|
3 |
| -const cases = { |
4 |
| - string: '10000', |
5 |
| - stringReversed: '00001', |
6 |
| - stringOnly: '10000', |
7 |
| - int: 12345, |
8 |
| - intReversed: 54321, |
9 |
| - arr: [], |
10 |
| - number: 10000, |
11 |
| - float: 1234.5678, |
12 |
| - floatDotString: '1234.5678', |
13 |
| - floatWithCustomDelimiter: '1 234,567 8', |
14 |
| - floatString: '1234,5678', |
15 |
| - floatFormatted: '1 234.567 8', |
16 |
| - floatEnFormatted: '1,234.567,8', |
17 |
| - floatStringFormatted: '1 234,567 8', |
18 |
| - floatStringRuFormatted: '1 234,567 8', |
19 |
| - exponential: 1e-7, |
20 |
| - exponentialJustString: '1e-7', |
21 |
| - stringFormatted: '10 000', |
22 |
| - stringRuFormatted: '10 000', |
23 |
| - stringEnFormatted: '10,000', |
24 |
| - exponentialString: '0.0000001', |
25 |
| - exponentialEnFormatted: '0.000,000,1', |
26 |
| - exponentialFormatted: '0.000 000 1', |
27 |
| - trashString: 'test' |
28 |
| -}; |
29 |
| - |
30 |
| -describe('dist-test', () => { |
31 |
| - it('test formattedPrice with one argument', () => { |
| 3 | +describe('plh.formattedPrice tests', () => { |
| 4 | + it('compare plh.formattedPrice the same works with different types', () => { |
| 5 | + expect(plh.formattedPrice(10000)).toEqual(plh.formattedPrice('10000')); |
| 6 | + expect(plh.formattedPrice(1000.1234)).toEqual(plh.formattedPrice('1000.1234')); |
| 7 | + expect(plh.formattedPrice(1e-7)).toEqual(plh.formattedPrice('1e-7')); |
| 8 | + }); |
| 9 | + |
| 10 | + it('testing plh.formattedPrice with different values', () => { |
32 | 11 | expect(plh.formattedPrice(10000)).toEqual('10,000');
|
33 |
| - expect(plh.formattedPrice(cases.exponential)).toEqual(cases.exponentialJustString); |
34 |
| - expect(plh.formattedPrice(cases.trashString)).toEqual(cases.trashString); |
35 |
| - }); |
36 |
| - |
37 |
| - it('test formattedPrice with several arguments', () => { |
38 |
| - expect(plh.formattedPrice({ value: 1000.1234, delimiter:',',separator:'.' })).toEqual('1.000,123.4'); |
39 |
| - expect(plh.formattedPrice({ value:'1000.1234', delimiter:',',separator:'.' })).toEqual('1.000,123.4'); |
40 |
| - expect(plh.formattedPrice({ value:'1000.1234', delimiter:'.',separator:'.' })).toEqual(false); |
41 |
| - expect(plh.formattedPrice({ value:'1000.1234', delimiter:',',separator:',' })).toEqual(false); |
42 |
| - expect(plh.formattedPrice({ value:'1000.1234', delimiter:' ',separator:' ' })).toEqual(false); |
43 |
| - expect(plh.formattedPrice({ value:'1000.1234', delimiter:'.' })).toEqual('1,000.123,4'); |
44 |
| - expect(plh.formattedPrice({ value: 1000.1234, lang: 'en' })).toEqual('1,000.123,4'); |
45 |
| - expect(plh.formattedPrice({ value:'1000.1234', separator:'.' })).toEqual('1.000,123.4'); |
46 |
| - expect(plh.formattedPrice({ value:'1000.1234', separator:' ' })).toEqual('1 000.123 4'); |
47 |
| - expect(plh.formattedPrice({ value:'1000.1234', delimiter:',', separator:' ' })).toEqual('1 000,123 4'); |
48 |
| - expect(plh.formattedPrice({ value: cases.floatString, delimiter:',', separator: ' ' })).toEqual(cases.floatWithCustomDelimiter); |
49 |
| - }); |
50 |
| - |
51 |
| - it('test combine formattedPrice with exponentFormatter', () => { |
52 |
| - expect(plh.formattedPrice(plh.exponentFormatter(cases.exponential))).toEqual(cases.exponentialEnFormatted); |
53 |
| - }); |
54 |
| - |
55 |
| - it('exponentFormatter', () => { |
56 |
| - expect(plh.exponentFormatter(cases.number)).toEqual(cases.string); |
57 |
| - expect(plh.exponentFormatter(cases.string)).toEqual(cases.string); |
58 |
| - expect(plh.exponentFormatter(cases.float)).toEqual(cases.floatDotString); |
59 |
| - expect(plh.exponentFormatter(cases.exponential)).toEqual(cases.exponentialString); |
60 |
| - expect(plh.exponentFormatter(cases.trashString)).toEqual(cases.trashString); |
61 |
| - expect(plh.exponentFormatter(cases.floatString)).toEqual(cases.floatString); |
| 12 | + expect(plh.formattedPrice('1000.1234')).toEqual('1,000.123,4'); |
| 13 | + expect(plh.formattedPrice(1e-7)).toEqual('1e-7'); |
| 14 | + expect(plh.formattedPrice('test')).toEqual(false); |
| 15 | + expect(plh.formattedPrice('t1000')).toEqual(false); |
| 16 | + expect(plh.formattedPrice(1000.1234, { separator: '.' })).toEqual('1.000,123.4'); |
| 17 | + expect(plh.formattedPrice('1000.1234', { separator: '.' })).toEqual('1.000,123.4'); |
| 18 | + expect(plh.formattedPrice('0.0000001', { separator: '.' })).toEqual('0,000.000.1'); |
| 19 | + }); |
| 20 | + |
| 21 | + it('testing plh.formattedPrice with different separators', () => { |
| 22 | + expect(plh.formattedPrice(1000.1234, { separator: ',' })).toEqual('1,000.123,4'); |
| 23 | + expect(plh.formattedPrice(1000.1234, { separator: ' ' })).toEqual('1 000.123 4'); |
| 24 | + }); |
| 25 | + |
| 26 | + it('testing plh.formattedPrice with different delimiters', () => { |
| 27 | + // ToDo: Fix this. Must be 1.000,123.4' |
| 28 | + expect(plh.formattedPrice(1000.1234, { delimiter: ',' })).toEqual('1,000.123,4'); |
| 29 | + expect(plh.formattedPrice(1000.1234, { delimiter: '.' })).toEqual('1,000.123,4'); |
| 30 | + expect(plh.formattedPrice(1000.1234, { delimiter: ' ' })).toEqual('1,000 123,4'); |
| 31 | + }); |
| 32 | + |
| 33 | + it('testing plh.formattedPrice with the same separators and delimiters', () => { |
| 34 | + expect(plh.formattedPrice(1000.1234, { separator: '.', delimiter: '.' })).toEqual(false); |
| 35 | + expect(plh.formattedPrice(1000.1234, { separator: ',', delimiter: ',' })).toEqual(false); |
| 36 | + expect(plh.formattedPrice(1000.1234, { separator: ' ', delimiter: ' ' })).toEqual(false); |
| 37 | + }); |
| 38 | + |
| 39 | + it('test plh.formattedPrice with several options', () => { |
| 40 | + expect(plh.formattedPrice(1000.1234, { separator: '.', delimiter: ',' })).toEqual('1.000,123.4'); |
| 41 | + expect(plh.formattedPrice(1000.1234, { separator: ',', delimiter: '.' })).toEqual('1,000.123,4'); |
| 42 | + expect(plh.formattedPrice(1000.1234, { separator: ' ', delimiter: ',' })).toEqual('1 000,123 4'); |
| 43 | + expect(plh.formattedPrice(1000.1234, { separator: ' ', delimiter: '.' })).toEqual('1 000.123 4'); |
| 44 | + expect(plh.formattedPrice(1000.1234, { separator: ',', delimiter: ' ' })).toEqual('1,000 123,4'); |
| 45 | + }); |
| 46 | + |
| 47 | + it('test plh.formattedPrice with lang', () => { |
| 48 | + expect(plh.formattedPrice(1000.1234, { lang: 'en' })).toEqual('1,000.123,4'); |
| 49 | + }); |
| 50 | + |
| 51 | + it('plh.exponentFormatter', () => { |
| 52 | + expect(plh.exponentFormatter(1e-8)).toBe('0.00000001'); |
| 53 | + expect(plh.exponentFormatter(1e-20)).toBe('0.00000000000000000001'); |
| 54 | + expect(plh.exponentFormatter(1000)).toBe('1000'); |
62 | 55 | });
|
63 | 56 | });
|
0 commit comments