feat: Dynamic currency (#36416)

This commit is contained in:
Richard Fogaca Nienkotter
2026-01-17 02:58:41 -03:00
committed by GitHub
parent 896947c787
commit f4474b2e3e
72 changed files with 3068 additions and 173 deletions

View File

@@ -492,3 +492,59 @@ describe('BigNumberWithTrendline - Aggregation Tests', () => {
expect(transformed.bigNumber).toStrictEqual(10);
});
});
test('BigNumberWithTrendline AUTO mode should detect single currency', () => {
const props = generateProps(
[
{ __timestamp: 1607558400000, value: 1000, currency_code: 'USD' },
{ __timestamp: 1607558500000, value: 2000, currency_code: 'USD' },
],
{
yAxisFormat: ',.2f',
currencyFormat: { symbol: 'AUTO', symbolPosition: 'prefix' },
},
);
props.datasource.currencyCodeColumn = 'currency_code';
const transformed = transformProps(props);
// The headerFormatter should include $ for USD
expect(transformed.headerFormatter(1000)).toContain('$');
});
test('BigNumberWithTrendline AUTO mode should use neutral formatting for mixed currencies', () => {
const props = generateProps(
[
{ __timestamp: 1607558400000, value: 1000, currency_code: 'USD' },
{ __timestamp: 1607558500000, value: 2000, currency_code: 'EUR' },
],
{
yAxisFormat: ',.2f',
currencyFormat: { symbol: 'AUTO', symbolPosition: 'prefix' },
},
);
props.datasource.currencyCodeColumn = 'currency_code';
const transformed = transformProps(props);
// With mixed currencies, should not show currency symbol
const formatted = transformed.headerFormatter(1000);
expect(formatted).not.toContain('$');
expect(formatted).not.toContain('€');
});
test('BigNumberWithTrendline should preserve static currency format', () => {
const props = generateProps(
[
{ __timestamp: 1607558400000, value: 1000, currency_code: 'USD' },
{ __timestamp: 1607558500000, value: 2000, currency_code: 'EUR' },
],
{
yAxisFormat: ',.2f',
currencyFormat: { symbol: 'GBP', symbolPosition: 'prefix' },
},
);
props.datasource.currencyCodeColumn = 'currency_code';
const transformed = transformProps(props);
// Static mode should always show £
expect(transformed.headerFormatter(1000)).toContain('£');
});