Skip to content

Commit

Permalink
Merge branch 'main' into ADM-834
Browse files Browse the repository at this point in the history
  • Loading branch information
PengxiWPix authored Apr 7, 2024
2 parents ec9228a + 9d87a76 commit f8af83b
Show file tree
Hide file tree
Showing 11 changed files with 430 additions and 94 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {
initDeploymentFrequencySettings,
saveUsers,
updateShouldGetBoardConfig,
updateShouldGetPipelineConfig,
} from '@src/context/Metrics/metricsSlice';
Expand Down Expand Up @@ -133,7 +132,6 @@ describe('DateRangePickerSection', () => {
expect(updateShouldGetBoardConfig).toHaveBeenCalledWith(true);
expect(updateShouldGetPipelineConfig).toHaveBeenCalledWith(true);
expect(initDeploymentFrequencySettings).toHaveBeenCalled();
expect(saveUsers).toHaveBeenCalledWith([]);
});

it('should dispatch update configuration when change endDate', async () => {
Expand All @@ -145,7 +143,6 @@ describe('DateRangePickerSection', () => {
expect(updateShouldGetBoardConfig).toHaveBeenCalledWith(true);
expect(updateShouldGetPipelineConfig).toHaveBeenCalledWith(true);
expect(initDeploymentFrequencySettings).toHaveBeenCalled();
expect(saveUsers).toHaveBeenCalledWith([]);
});
});

Expand Down
155 changes: 135 additions & 20 deletions frontend/__tests__/context/metricsSlice.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,39 @@ import saveMetricsSettingReducer, {
addADeploymentFrequencySetting,
deleteADeploymentFrequencySetting,
initDeploymentFrequencySettings,
updateCycleTimeSettings,
resetMetricData,
saveDoneColumn,
savePipelineCrews,
saveTargetFields,
saveUsers,
selectAdvancedSettings,
selectAssigneeFilter,
selectClassificationWarningMessage,
selectCycleTimeSettings,
selectCycleTimeWarningMessage,
selectDeploymentFrequencySettings,
selectMetricsContent,
selectOrganizationWarningMessage,
selectPipelineNameWarningMessage,
selectRealDoneWarningMessage,
selectReworkTimesSettings,
selectShouldGetBoardConfig,
selectShouldGetPipelineConfig,
selectStepWarningMessage,
selectTreatFlagCardAsBlock,
setCycleTimeSettingsType,
updateAdvancedSettings,
updateAssigneeFilter,
updateCycleTimeSettings,
updateDeploymentFrequencySettings,
updateMetricsImportedData,
updateMetricsState,
updatePipelineSettings,
updatePipelineStep,
updateTreatFlagCardAsBlock,
updateAssigneeFilter,
resetMetricData,
savePipelineCrews,
setCycleTimeSettingsType,
updateShouldGetPipelineConfig,
updateShouldGetBoardConfig,
updateAdvancedSettings,
updateReworkTimesSettings,
selectShouldGetBoardConfig,
selectShouldGetPipelineConfig,
selectAdvancedSettings,
selectAssigneeFilter,
selectClassificationWarningMessage,
selectCycleTimeSettings,
selectCycleTimeWarningMessage,
selectMetricsContent,
selectRealDoneWarningMessage,
selectReworkTimesSettings,
selectTreatFlagCardAsBlock,
updateShouldGetBoardConfig,
updateShouldGetPipelineConfig,
updateTreatFlagCardAsBlock,
} from '@src/context/Metrics/metricsSlice';
import {
CLASSIFICATION_WARNING_MESSAGE,
Expand Down Expand Up @@ -81,6 +81,7 @@ const initState = {
realDoneWarningMessage: null,
deploymentWarningMessage: [],
leadTimeWarningMessage: [],
firstTimeRoadMetricData: true,
};

const mockJiraResponse = {
Expand Down Expand Up @@ -1036,6 +1037,120 @@ describe('saveMetricsSetting reducer', () => {
);
});

describe('should update metrics when reload metric page', () => {
it.each([{ isProjectCreated: false }, { isProjectCreated: true }])(
'should update classification correctly when reload metrics page',
(mockData) => {
const savedMetricsSetting = saveMetricsSettingReducer(
{
...initState,
firstTimeRoadMetricData: false,
targetFields: [
{ key: 'issuetype', name: 'Issue Type', flag: false },
{ key: 'parent', name: 'Parent', flag: true },
],
},
updateMetricsState({
...mockJiraResponse,
...mockData,
targetFields: [
{
key: 'parent',
name: 'Parent',
flag: false,
},
{
key: 'customfield_10061',
name: 'Story testing',
flag: false,
},
],
}),
);
expect(savedMetricsSetting.targetFields).toEqual([
{ key: 'parent', name: 'Parent', flag: true },
{ key: 'customfield_10061', name: 'Story testing', flag: false },
]);
},
);

it.each([{ isProjectCreated: true }, { isProjectCreated: false }])(
'should update board crews user correctly when reload metrics page',
(mockData) => {
const savedMetricsSetting = saveMetricsSettingReducer(
{
...initState,
firstTimeRoadMetricData: false,
users: ['User A', 'User B', 'C'],
},
updateMetricsState({ ...mockJiraResponse, ...mockData }),
);
expect(savedMetricsSetting.users).toEqual(['User A', 'User B']);
},
);

it.each([CYCLE_TIME_SETTINGS_TYPES.BY_COLUMN, CYCLE_TIME_SETTINGS_TYPES.BY_STATUS])(
'should update cycle time settings correctly when reload metrics page',
(cycleTimeSettingsType) => {
const savedMetricsSetting = saveMetricsSettingReducer(
{
...initState,
firstTimeRoadMetricData: false,
cycleTimeSettingsType,
cycleTimeSettings: [
{
column: 'TODO',
status: 'TODO',
value: 'To do',
},
{
column: 'Doing',
status: 'DOING',
value: 'In Dev',
},
{
column: 'Blocked',
status: 'BLOCKED',
value: 'Block',
},
],
},
updateMetricsState({
...mockJiraResponse,
jiraColumns: [
{
key: 'To Do',
value: {
name: 'TODO',
statuses: ['TODO'],
},
},
{
key: 'In Progress',
value: {
name: 'Doing',
statuses: ['DOING'],
},
},
],
}),
);
expect(savedMetricsSetting.cycleTimeSettings).toEqual([
{
column: 'TODO',
status: 'TODO',
value: 'To do',
},
{
column: 'Doing',
status: 'DOING',
value: 'In Dev',
},
]);
},
);
});

it('should set warningMessage have value when the values in the import file are less than those in the response', () => {
const mockUpdateMetricsStateArguments = {
...mockJiraResponse,
Expand Down
141 changes: 136 additions & 5 deletions frontend/__tests__/utils/Util.test.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
import {
convertCycleTimeSettings,
exportToJsonFile,
filterAndMapCycleTimeSettings,
findCaseInsensitiveType,
formatDuplicatedNameWithSuffix,
formatMillisecondsToHours,
formatMinToHours,
getDisabledOptions,
getJiraBoardToken,
getRealDoneStatus,
transformToCleanedBuildKiteEmoji,
formatDuplicatedNameWithSuffix,
getDisabledOptions,
getSortedAndDeduplicationBoardingMapping,
sortDisabledOptions,
transformToCleanedBuildKiteEmoji,
} from '@src/utils/util';
import { CleanedBuildKiteEmoji, OriginBuildKiteEmoji } from '@src/constants/emojis/emoji';
import { CYCLE_TIME_SETTINGS_TYPES } from '@src/constants/resources';
import { IPipelineConfig } from '@src/context/Metrics/metricsSlice';
import { CYCLE_TIME_SETTINGS_TYPES, METRICS_CONSTANTS } from '@src/constants/resources';
import { ICycleTimeSetting, IPipelineConfig } from '@src/context/Metrics/metricsSlice';
import { EMPTY_STRING } from '@src/constants/commons';
import { PIPELINE_TOOL_TYPES } from '../fixtures';

Expand Down Expand Up @@ -270,3 +272,132 @@ describe('formatDuplicatedNameWithSuffix function', () => {
expect(result).toStrictEqual(expectResult);
});
});

describe('getSortedAndDeduplicationBoardingMapping function', () => {
it('should sorted and deduplication boarding mapping', () => {
const boardingMapping: ICycleTimeSetting[] = [
METRICS_CONSTANTS.cycleTimeEmptyStr,
METRICS_CONSTANTS.analysisValue,
METRICS_CONSTANTS.testingValue,
METRICS_CONSTANTS.doneValue,
METRICS_CONSTANTS.todoValue,
METRICS_CONSTANTS.cycleTimeEmptyStr,
METRICS_CONSTANTS.blockValue,
METRICS_CONSTANTS.inDevValue,
METRICS_CONSTANTS.reviewValue,
METRICS_CONSTANTS.waitingValue,
METRICS_CONSTANTS.reviewValue,
].map((value) => ({
value: value,
status: '',
column: '',
}));
const expectResult = [
METRICS_CONSTANTS.cycleTimeEmptyStr,
METRICS_CONSTANTS.todoValue,
METRICS_CONSTANTS.analysisValue,
METRICS_CONSTANTS.inDevValue,
METRICS_CONSTANTS.blockValue,
METRICS_CONSTANTS.reviewValue,
METRICS_CONSTANTS.waitingValue,
METRICS_CONSTANTS.testingValue,
METRICS_CONSTANTS.doneValue,
];
const result = getSortedAndDeduplicationBoardingMapping(boardingMapping);
expect(result).toStrictEqual(expectResult);
});
});

describe('convertCycleTimeSettings function', () => {
const mockCycleTime = [
{
column: 'TODO',
status: 'TODO',
value: 'To do',
},
{
column: 'Doing',
status: 'DOING',
value: 'In Dev',
},
{
column: 'Blocked',
status: 'BLOCKED',
value: 'Block',
},
{
column: 'Review',
status: 'REVIEW',
value: 'Review',
},
{
column: 'READY FOR TESTING',
status: 'WAIT FOR TEST',
value: 'Waiting for testing',
},
{
column: 'Testing',
status: 'TESTING',
value: 'Testing',
},
{
column: 'Done',
status: 'DONE',
value: '',
},
];
it('convert cycle time settings correctly by status', () => {
const expectResult = [
{
TODO: 'To do',
},
{
DOING: 'In Dev',
},
{
BLOCKED: 'Block',
},
{
REVIEW: 'Review',
},
{
'WAIT FOR TEST': 'Waiting for testing',
},
{
TESTING: 'Testing',
},
{
DONE: '',
},
];
const result = convertCycleTimeSettings(CYCLE_TIME_SETTINGS_TYPES.BY_STATUS, mockCycleTime);
expect(result).toStrictEqual(expectResult);
});
it('convert cycle time settings correctly by column', () => {
const expectResult = [
{
TODO: 'To do',
},
{
Doing: 'In Dev',
},
{
Blocked: 'Block',
},
{
Review: 'Review',
},
{
'READY FOR TESTING': 'Waiting for testing',
},
{
Testing: 'Testing',
},
{
Done: '----',
},
];
const result = convertCycleTimeSettings(CYCLE_TIME_SETTINGS_TYPES.BY_COLUMN, mockCycleTime);
expect(result).toStrictEqual(expectResult);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {
} from '@src/constants/resources';
import {
initDeploymentFrequencySettings,
saveUsers,
updateShouldGetBoardConfig,
updateShouldGetPipelineConfig,
} from '@src/context/Metrics/metricsSlice';
Expand Down Expand Up @@ -53,7 +52,6 @@ export const DateRangePicker = ({ startDate, endDate, index }: IRangePickerProps
dispatch(updateShouldGetBoardConfig(true));
dispatch(updateShouldGetPipelineConfig(true));
dispatch(initDeploymentFrequencySettings());
dispatch(saveUsers([]));
};

const changeStartDate = (value: Nullable<Dayjs>) => {
Expand Down
Loading

0 comments on commit f8af83b

Please sign in to comment.