Added test cases

Signed-off-by: bogdannechyporenko <bogdannechiporenko@gmail.com>
This commit is contained in:
bogdannechyporenko
2022-11-15 14:16:51 +01:00
parent f9bbb3be37
commit 176cd00ea3
3 changed files with 58 additions and 2 deletions
@@ -49,6 +49,22 @@ describe('date formatters', () => {
'$0.0000023',
]);
});
it('Correctly formats values in euros to two significant digits', () => {
const values = [
0.00000040925, 0.21, 0.0000004, 0.4139877878, 0.00000234566,
];
const formattedValues = values.map(val =>
lengthyCurrencyFormatter('EUR').format(val),
);
expect(formattedValues).toEqual([
'€0.00000041',
'€0.21',
'€0.00000040',
'€0.41',
'€0.0000023',
]);
});
});
describe.each`
@@ -0,0 +1,40 @@
/*
* Copyright 2020 The Backstage Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { formatGraphValue, tooltipItemOf } from './graphs';
import { DataKey } from '../types';
describe('graphs', () => {
it('formatGraphValue', () => {
expect(formatGraphValue('SEK')(1000, 0)).toEqual('SEK 1,000');
expect(formatGraphValue('EUR')(1000, 0)).toEqual('€1,000');
expect(formatGraphValue('USD')(1000, 0)).toEqual('$1,000');
});
it('tooltipItemOf', () => {
expect(
tooltipItemOf('EUR', {
value: '1000',
color: 'red',
dataKey: DataKey.Current,
name: 'Kubernetes',
}),
).toEqual({
fill: 'red',
label: 'Kubernetes',
value: '€1,000',
});
});
});
+2 -2
View File
@@ -45,8 +45,8 @@ export const tooltipItemOf = (
payload: Payload<string, string>,
) => {
const value =
typeof payload.value === 'number'
? currencyFormatter(baseCurrency).format(payload.value)
payload.value && !isNaN(Number(payload.value))
? currencyFormatter(baseCurrency).format(Number(payload.value))
: payload.value;
const fill = payload.color as string;