mirror of https://github.com/buster-so/buster.git
Update formatChartLabel.test.ts
This commit is contained in:
parent
4321a4faad
commit
25b451a6b8
|
@ -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');
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue