Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vedantprajapati committed Jan 4, 2025
1 parent 81b907a commit 1b06413
Showing 1 changed file with 43 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ import {
extractForecastValuesFromTooltipParams,
formatForecastTooltipSeries,
rebaseForecastDatum,
reorderForecastSeries,
} from '../../src/utils/forecast';
import { ForecastSeriesEnum } from '../../src/types';
import { SeriesOption } from 'echarts';

describe('extractForecastSeriesContext', () => {
it('should extract the correct series name and type', () => {
Expand All @@ -46,6 +48,47 @@ describe('extractForecastSeriesContext', () => {
});
});

describe('reorderForecastSeries', () => {
it('should reorder the forecast series and preserve values', () => {
const input: SeriesOption[] = [
{ id: `series${ForecastSeriesEnum.Observation}`, data: [10, 20, 30] },
{ id: `series${ForecastSeriesEnum.ForecastTrend}`, data: [15, 25, 35] },
{ id: `series${ForecastSeriesEnum.ForecastLower}`, data: [5, 15, 25] },
{ id: `series${ForecastSeriesEnum.ForecastUpper}`, data: [25, 35, 45] },
];
const expectedOutput: SeriesOption[] = [
{ id: `series${ForecastSeriesEnum.ForecastLower}`, data: [5, 15, 25] },
{ id: `series${ForecastSeriesEnum.ForecastUpper}`, data: [25, 35, 45] },
{ id: `series${ForecastSeriesEnum.ForecastTrend}`, data: [15, 25, 35] },
{ id: `series${ForecastSeriesEnum.Observation}`, data: [10, 20, 30] },
];
expect(reorderForecastSeries(input)).toEqual(expectedOutput);
});

it('should handle an empty array', () => {
expect(reorderForecastSeries([])).toEqual([]);
});

it('should not reorder if no relevant series are present', () => {
const input: SeriesOption[] = [{ id: 'some-other-series' }];
expect(reorderForecastSeries(input)).toEqual(input);
});

it('should handle undefined ids', () => {
const input: SeriesOption[] = [
{ id: `series${ForecastSeriesEnum.ForecastLower}` },
{ id: undefined },
{ id: `series${ForecastSeriesEnum.ForecastTrend}` },
];
const expectedOutput: SeriesOption[] = [
{ id: `series${ForecastSeriesEnum.ForecastLower}` },
{ id: `series${ForecastSeriesEnum.ForecastTrend}` },
{ id: undefined },
];
expect(reorderForecastSeries(input)).toEqual(expectedOutput);
});
});

describe('rebaseForecastDatum', () => {
it('should subtract lower confidence level from upper value', () => {
expect(
Expand Down

0 comments on commit 1b06413

Please sign in to comment.