Skip to content

Commit d24bce1

Browse files
test(charts): cover fixedDecimals = false in formatTooltipValueWithUnit
Verify whole values render bare (e.g. "5 op/s", "20 kB") on both the re-derived-unit and no-unitRange paths, while fractional values keep up to two decimals. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 08d1876 commit d24bce1

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

src/lib/components/charts/common/chartUtils.test.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -490,4 +490,26 @@ describe('formatTooltipValueWithUnit', () => {
490490
it('returns "-" for non-finite values', () => {
491491
expect(formatTooltipValueWithUnit(NaN, 1000, unitRange, 'kop/s')).toBe('-');
492492
});
493+
494+
describe('with fixedDecimals = false (bare whole numbers)', () => {
495+
it('drops the trailing ".00" for whole values on the re-derived unit', () => {
496+
// Same input as the default case, which yields "5.00 op/s".
497+
expect(
498+
formatTooltipValueWithUnit(0.005, 1000, unitRange, 'kop/s', false),
499+
).toBe('5 op/s');
500+
});
501+
502+
it('still keeps up to two decimals for fractional values', () => {
503+
// 1.84 (stored) * 1000 = 1840 op/s → 1.84 kop/s
504+
expect(
505+
formatTooltipValueWithUnit(1.84, 1000, unitRange, 'kop/s', false),
506+
).toBe('1.84 kop/s');
507+
});
508+
509+
it('drops the trailing ".00" in the no-unit-range fallback', () => {
510+
expect(formatTooltipValueWithUnit(20, 1, undefined, 'kB', false)).toBe(
511+
'20 kB',
512+
);
513+
});
514+
});
493515
});

0 commit comments

Comments
 (0)