diff --git a/web/src/components/ui/charts/BusterChartJS/helpers/formatChartLabel.test.ts b/web/src/components/ui/charts/BusterChartJS/helpers/formatChartLabel.test.ts index 8a8344de6..a9449de54 100644 --- a/web/src/components/ui/charts/BusterChartJS/helpers/formatChartLabel.test.ts +++ b/web/src/components/ui/charts/BusterChartJS/helpers/formatChartLabel.test.ts @@ -147,4 +147,96 @@ describe('formatChartLabel', () => { const result = formatChartLabel('numeric_field__🔑__1234.567', columnLabelFormats, true, false); expect(result).toBe('$1,234.57 USD'); }); + + it('should format compact numbers correctly', () => { + const columnLabelFormats = { + numeric_field: { + style: 'number', + compactNumbers: true, + columnType: 'number', + displayName: '', + numberSeparatorStyle: ',', + minimumFractionDigits: 1, + maximumFractionDigits: 1, + multiplier: 1, + makeLabelHumanReadable: true + } + } satisfies NonNullable; + + const result = formatChartLabel('numeric_field__🔑__1234567', columnLabelFormats, true, false); + expect(result).toBe('1.2M'); + }); + + it('should apply multiplier to numbers correctly', () => { + const columnLabelFormats = { + numeric_field: { + style: 'number', + compactNumbers: false, + columnType: 'number', + displayName: '', + numberSeparatorStyle: ',', + minimumFractionDigits: 2, + maximumFractionDigits: 2, + multiplier: 100, + suffix: '%', + makeLabelHumanReadable: true + } + } satisfies NonNullable; + + const result = formatChartLabel('numeric_field__🔑__0.756', columnLabelFormats, true, false); + expect(result).toBe('75.60%'); + }); + + it('should handle negative numbers with custom formatting', () => { + const columnLabelFormats = { + numeric_field: { + style: 'number', + compactNumbers: false, + columnType: 'number', + displayName: '', + numberSeparatorStyle: ',', + minimumFractionDigits: 0, + maximumFractionDigits: 0, + prefix: '(', + suffix: ')', + makeLabelHumanReadable: true + } + } satisfies NonNullable; + + const result = formatChartLabel('numeric_field__🔑__-42', columnLabelFormats, true, false); + expect(result).toBe('(-42)'); + }); + + it('should handle text fields with custom display names', () => { + const columnLabelFormats = { + text_field: { + style: 'string', + columnType: 'text', + displayName: 'Customer Status', + makeLabelHumanReadable: true + } + } satisfies NonNullable; + + const result = formatChartLabel('text_field__🔑__active', columnLabelFormats, false, false); + expect(result).toBe('Active'); + }); + + it('should handle text fields with special characters and spaces', () => { + const columnLabelFormats = { + text_field: { + style: 'string', + columnType: 'text', + displayName: '', + makeLabelHumanReadable: true + } + } satisfies NonNullable; + + let result = formatChartLabel( + 'text_field__🔑__high_priority_item', + columnLabelFormats, + false, + false + ); + expect(result).toBe('High Priority Item'); + }); });