|
| 1 | +import {UNBREAKABLE_GAP} from '../../utils'; |
| 2 | +import {formatNumericValues} from '../dataFormatters'; |
| 3 | + |
| 4 | +describe('formatNumericValues', () => { |
| 5 | + it('should return ["", ""] when both value and total are undefined', () => { |
| 6 | + const result = formatNumericValues(); |
| 7 | + expect(result).toEqual(['', '']); |
| 8 | + }); |
| 9 | + |
| 10 | + it('should format value correctly when total is undefined', () => { |
| 11 | + const result = formatNumericValues(1000); |
| 12 | + expect(result).toEqual([`1${UNBREAKABLE_GAP}k`, '']); |
| 13 | + }); |
| 14 | + |
| 15 | + it('should format total correctly when value is undefined', () => { |
| 16 | + const result = formatNumericValues(undefined, 1_000_000); |
| 17 | + expect(result).toEqual(['', `1${UNBREAKABLE_GAP}m`]); |
| 18 | + }); |
| 19 | + |
| 20 | + it('should format both value and total correctly', () => { |
| 21 | + const result = formatNumericValues(1024, 2048); |
| 22 | + expect(result).toEqual(['1', `2${UNBREAKABLE_GAP}k`]); |
| 23 | + }); |
| 24 | + it('should format value with label if set', () => { |
| 25 | + const result = formatNumericValues(1024, 2048, undefined, undefined, true); |
| 26 | + expect(result).toEqual([`1${UNBREAKABLE_GAP}k`, `2${UNBREAKABLE_GAP}k`]); |
| 27 | + }); |
| 28 | + |
| 29 | + it('should return ["0", formattedTotal] when value is 0', () => { |
| 30 | + const result = formatNumericValues(0, 2048); |
| 31 | + expect(result).toEqual(['0', `2${UNBREAKABLE_GAP}k`]); |
| 32 | + }); |
| 33 | + |
| 34 | + it('should use provided size and delimiter', () => { |
| 35 | + const result = formatNumericValues(5120, 10240, 'billion', '/'); |
| 36 | + expect(result).toEqual(['0', '0/b']); |
| 37 | + }); |
| 38 | + |
| 39 | + it('should handle non-numeric total gracefully', () => { |
| 40 | + const result = formatNumericValues(2048, 'Not a number' as any); |
| 41 | + expect(result).toEqual([`2${UNBREAKABLE_GAP}k`, '']); |
| 42 | + }); |
| 43 | +}); |
0 commit comments