Skip to content

Commit c54a3f9

Browse files
Remove test for barchart but add test for computeUnitLabelAndRoundReferenceValue fn
If data is compute correctly, recharts should display data correctly
1 parent 01aead2 commit c54a3f9

File tree

2 files changed

+33
-73
lines changed

2 files changed

+33
-73
lines changed

src/lib/components/barchartv2/Barchart.component.test.tsx

Lines changed: 2 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
import { render, screen, waitFor } from '@testing-library/react';
1+
import { getRoles, render, screen, waitFor } from '@testing-library/react';
22
import React from 'react';
33
import Barchart, { BarchartProps } from './Barchart.component';
44
import { getWrapper } from '../../testUtils';
5+
import { debug } from 'jest-preview';
56

67
const ONE_DAY_IN_MILLISECONDS = 24 * 60 * 60 * 1000;
78
const ONE_HOUR_IN_MILLISECONDS = 60 * 60 * 1000;
@@ -241,75 +242,4 @@ describe('Barchart', () => {
241242
expect(screen.getByText('50')).toBeInTheDocument();
242243
});
243244
});
244-
245-
describe('Unit range', () => {
246-
it('should render with reference line and unit range', async () => {
247-
const testUnitRange: BarchartProps['unitRange'] = [
248-
{
249-
threshold: 1000,
250-
label: 'kB',
251-
},
252-
{
253-
threshold: 0,
254-
label: 'B',
255-
},
256-
];
257-
const testBars: BarchartProps['bars'] = [
258-
{
259-
label: 'Success',
260-
data: [
261-
['category1', 200],
262-
['category2', 560],
263-
['category3', 640],
264-
],
265-
color: 'green',
266-
},
267-
];
268-
const { Wrapper } = getWrapper();
269-
render(
270-
<Wrapper>
271-
<Barchart type="category" bars={testBars} unitRange={testUnitRange} />
272-
</Wrapper>,
273-
);
274-
275-
await waitFor(() => {
276-
// 1000 B is the reference value, 2 elements with the text "1000 B" rendered by recharts
277-
const referenceValue = screen.getAllByText(/1000 B/i);
278-
expect(referenceValue).toHaveLength(2);
279-
});
280-
});
281-
282-
it('should render with the unit label', () => {
283-
const testBars: BarchartProps['bars'] = [
284-
{
285-
label: 'Success',
286-
data: [
287-
['category1', 2220],
288-
['category2', 2500],
289-
['category3', 3000],
290-
],
291-
color: 'green',
292-
},
293-
];
294-
295-
const testUnitRange: BarchartProps['unitRange'] = [
296-
{
297-
threshold: 1000,
298-
label: 'kB',
299-
},
300-
{
301-
threshold: 1000000,
302-
label: 'MB',
303-
},
304-
];
305-
const { Wrapper } = getWrapper();
306-
render(
307-
<Wrapper>
308-
<Barchart type="category" bars={testBars} unitRange={testUnitRange} />
309-
</Wrapper>,
310-
);
311-
// Two elements with the text "10 kB" rendered
312-
expect(screen.getAllByText(/10 kB/i)).toHaveLength(2);
313-
});
314-
});
315245
});

src/lib/components/barchartv2/utils.test.ts

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ describe('formatPrometheusDataToChartData', () => {
220220
});
221221
});
222222
describe('computeUnitLabelAndRoundReferenceValue', () => {
223-
it('should compute the unit label and round reference value correctly', () => {
223+
it('should compute the unit label and round reference value correctly when reaching threshold', () => {
224224
const data = [
225225
{
226226
category: 'category1',
@@ -249,5 +249,35 @@ describe('formatPrometheusDataToChartData', () => {
249249
},
250250
]);
251251
});
252+
it('should compute the unit label and round reference value correctly when threshold is 0', () => {
253+
const data = [
254+
{
255+
category: 'category1',
256+
success: 680,
257+
},
258+
];
259+
const maxValue = 680;
260+
const unitRange: UnitRange = [
261+
{
262+
threshold: 0,
263+
label: 'B',
264+
},
265+
{
266+
threshold: 1000,
267+
label: 'kB',
268+
},
269+
];
270+
const result = computeUnitLabelAndRoundReferenceValue(
271+
data,
272+
maxValue,
273+
unitRange,
274+
);
275+
276+
expect(result.unitLabel).toBe('B');
277+
expect(result.roundReferenceValue).toBe(1000);
278+
expect(result.rechartsData).toEqual([
279+
{ category: 'category1', success: 680 },
280+
]);
281+
});
252282
});
253283
});

0 commit comments

Comments
 (0)