Skip to content

Commit

Permalink
ADM-973 [frontend] feat: add test for sortReportInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
Mandy-Tang committed Jul 12, 2024
1 parent 9d6afa0 commit ba14381
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions frontend/__tests__/utils/Util.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
sortDateRanges,
sortDisabledOptions,
sortLegend,
sortReportInfos,
transformToCleanedBuildKiteEmoji,
updateResponseCrews,
valueFormatter,
Expand All @@ -33,6 +34,7 @@ import {
import { CleanedBuildKiteEmoji, OriginBuildKiteEmoji } from '@src/constants/emojis/emoji';
import { ICycleTimeSetting, IPipelineConfig } from '@src/context/Metrics/metricsSlice';
import { IPipeline } from '@src/context/config/pipelineTool/verifyResponseSlice';
import { IReportInfo } from '../../src/hooks/useGenerateReportEffect';
import { BoardInfoResponse } from '@src/hooks/useGetBoardInfo';
import { EMPTY_STRING } from '@src/constants/commons';
import { PIPELINE_TOOL_TYPES } from '../fixtures';
Expand Down Expand Up @@ -447,6 +449,46 @@ describe('sortDateRanges function', () => {
});
});

describe('sortReportInfos function', () => {
const reportInfos = [
{
id: '2024-03-19T00:00:00.000+08:00',
reportData: {},
},
{
id: '2024-02-01T00:00:00.000+08:00',
reportData: {},
},
{
id: '2024-04-01T00:00:00.000+08:00',
reportData: {},
},
];
const expectResult = [
{
id: '2024-04-01T00:00:00.000+08:00',
reportData: {},
},
{
id: '2024-03-19T00:00:00.000+08:00',
reportData: {},
},
{
id: '2024-02-01T00:00:00.000+08:00',
reportData: {},
},
];
it('should descend reportInfos', () => {
const sortedReportInfos = sortReportInfos(reportInfos as IReportInfo[]);
expect(sortedReportInfos).toStrictEqual(expectResult);
});

it('should ascend reportInfos', () => {
const sortedReportInfos = sortReportInfos(reportInfos as IReportInfo[], false);
expect(sortedReportInfos).toStrictEqual(expectResult.reverse());
});
});

describe('combineBoardInfo function', () => {
const boardInfoResponses: BoardInfoResponse[] = [
{
Expand Down

0 comments on commit ba14381

Please sign in to comment.