diff --git a/frontend/__tests__/utils/Util.test.tsx b/frontend/__tests__/utils/Util.test.tsx index 7a1c6e427..0f8848645 100644 --- a/frontend/__tests__/utils/Util.test.tsx +++ b/frontend/__tests__/utils/Util.test.tsx @@ -16,6 +16,7 @@ import { sortDateRanges, sortDisabledOptions, sortLegend, + sortReportInfos, transformToCleanedBuildKiteEmoji, updateResponseCrews, valueFormatter, @@ -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'; @@ -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[] = [ {