From b74bc080806dae4388ab3056090106480a3979aa Mon Sep 17 00:00:00 2001 From: dej611 Date: Tue, 21 Mar 2023 16:14:28 +0100 Subject: [PATCH] :white_check_mark: Add bit test --- .../public/components/metric_vis.test.tsx | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/plugins/chart_expressions/expression_metric/public/components/metric_vis.test.tsx b/src/plugins/chart_expressions/expression_metric/public/components/metric_vis.test.tsx index ae042038bf66e..2a31ad930b0dd 100644 --- a/src/plugins/chart_expressions/expression_metric/public/components/metric_vis.test.tsx +++ b/src/plugins/chart_expressions/expression_metric/public/components/metric_vis.test.tsx @@ -1401,6 +1401,26 @@ describe('MetricVisComponent', function () { expect(moreThanPetaValue).toBe('1 EB'); }); + it('correctly formats bits (decimal)', () => { + const base = 1000; + const bitFormat = { + id: 'number', + params: { pattern: '0.0bitd' }, + }; + + const { primary: bytesValue } = getFormattedMetrics(base - 1, 0, bitFormat); + expect(bytesValue).toBe('999 bit'); + + const { primary: kiloBytesValue } = getFormattedMetrics(Math.pow(base, 1), 0, bitFormat); + expect(kiloBytesValue).toBe('1 kbit'); + + const { primary: megaBytesValue } = getFormattedMetrics(Math.pow(base, 2), 0, bitFormat); + expect(megaBytesValue).toBe('1 Mbit'); + + const { primary: moreThanPetaValue } = getFormattedMetrics(Math.pow(base, 6), 0, bitFormat); + expect(moreThanPetaValue).toBe('1 Ebit'); + }); + it('correctly formats durations', () => { const { primary, secondary } = getFormattedMetrics(1, 1, { id: 'duration',