Update formatChartLabel.test.ts

This commit is contained in:
Nate Kelley 2025-04-18 17:09:02 -06:00
parent 4321a4faad
commit 25b451a6b8
No known key found for this signature in database
GPG Key ID: FD90372AB8D98B4F
1 changed files with 92 additions and 0 deletions

View File

@ -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<BusterChartProps['columnLabelFormats']>;
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<BusterChartProps['columnLabelFormats']>;
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<BusterChartProps['columnLabelFormats']>;
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<BusterChartProps['columnLabelFormats']>;
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<BusterChartProps['columnLabelFormats']>;
let result = formatChartLabel(
'text_field__🔑__high_priority_item',
columnLabelFormats,
false,
false
);
expect(result).toBe('High Priority Item');
});
});