Skip to content

Commit

Permalink
Merge branch 'main' into ADM-794
Browse files Browse the repository at this point in the history
  • Loading branch information
yulongcai authored Feb 1, 2024
2 parents 4e9ed2f + e41ff49 commit b1f38c3
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import {
} from '@test/fixtures';
import { PipelineMetricSelection } from '@src/containers/MetricsStep/DeploymentFrequencySettings/PipelineMetricSelection';
import { updatePipelineToolVerifyResponseSteps } from '@src/context/config/configSlice';
import { act, render, waitFor, within, screen } from '@testing-library/react';
import { act, render, screen, waitFor, within } from '@testing-library/react';
import { IPipelineConfig } from '@src/context/Metrics/metricsSlice';
import { metricsClient } from '@src/clients/MetricsClient';
import { PipelineSetting } from '@src/context/interface';
import { setupStore } from '@test/utils/setupStoreUtil';
import userEvent from '@testing-library/user-event';
import { Provider } from 'react-redux';
Expand Down Expand Up @@ -70,7 +70,7 @@ describe('PipelineMetricSelection', () => {
const mockUpdatePipeline = jest.fn();

const setup = async (
deploymentFrequencySetting: PipelineSetting,
deploymentFrequencySetting: IPipelineConfig,
isShowRemoveButton: boolean,
isDuplicated: boolean,
) => {
Expand Down
6 changes: 3 additions & 3 deletions frontend/__tests__/containers/ReportStep/ReportStep.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,12 @@ describe('Report Step', () => {
store.dispatch(updateMetrics(params));
store.dispatch(addADeploymentFrequencySetting());
store.dispatch(
updateDeploymentFrequencySettings({ updateId: 0, label: 'organization', value: 'mock organization' }),
updateDeploymentFrequencySettings({ updateId: 1, label: 'organization', value: 'mock organization' }),
);
store.dispatch(
updateDeploymentFrequencySettings({ updateId: 0, label: 'pipelineName', value: 'mock pipeline name' }),
updateDeploymentFrequencySettings({ updateId: 1, label: 'pipelineName', value: 'mock pipeline name' }),
);
store.dispatch(updateDeploymentFrequencySettings({ updateId: 0, label: 'step', value: 'mock step1' }));
store.dispatch(updateDeploymentFrequencySettings({ updateId: 1, label: 'step', value: 'mock step1' }));
store.dispatch(
updatePipelineToolVerifyResponse({
pipelineList: [
Expand Down
4 changes: 2 additions & 2 deletions frontend/__tests__/context/metricsSlice.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -341,15 +341,15 @@ describe('saveMetricsSetting reducer', () => {
});

it('should add a deploymentFrequencySetting when handle addADeploymentFrequencySettings given initial state', () => {
const addedDeploymentFrequencySettings = [{ id: 0, organization: '', pipelineName: '', step: '', branches: [] }];
const addedDeploymentFrequencySettings = [{ id: 1, organization: '', pipelineName: '', step: '', branches: [] }];

const savedMetricsSetting = saveMetricsSettingReducer(initState, addADeploymentFrequencySetting());

expect(savedMetricsSetting.deploymentFrequencySettings).toEqual(addedDeploymentFrequencySettings);
});

it('should add a deploymentFrequencySetting when handle addADeploymentFrequencySettings but initState dont have DeploymentFrequencySettings', () => {
const addedDeploymentFrequencySettings = [{ id: 0, organization: '', pipelineName: '', step: '', branches: [] }];
const addedDeploymentFrequencySettings = [{ id: 1, organization: '', pipelineName: '', step: '', branches: [] }];

const initStateWithoutDeploymentFrequencySettings = {
...initState,
Expand Down
14 changes: 7 additions & 7 deletions frontend/src/context/Metrics/metricsSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
METRICS_CONSTANTS,
} from '@src/constants/resources';
import { pipeline } from '@src/context/config/pipelineTool/verifyResponseSlice';
import { initialBasicConfigState } from '@src/context/config/configSlice';
import { createSlice } from '@reduxjs/toolkit';
import camelCase from 'lodash.camelcase';
import { RootState } from '@src/store';
Expand Down Expand Up @@ -212,12 +211,14 @@ export const metricsSlice = createSlice({
state.cycleTimeSettingsType = action.payload;
},
addADeploymentFrequencySetting: (state) => {
const { deploymentFrequencySettings, importedData } = state;
const newId =
state.deploymentFrequencySettings.length >= 1
? state.deploymentFrequencySettings[state.deploymentFrequencySettings.length - 1].id + 1
: 0;
Math.max(
deploymentFrequencySettings[deploymentFrequencySettings.length - 1]?.id ?? 0,
importedData.importedDeployment[importedData.importedDeployment.length - 1]?.id ?? 0,
) + 1;
state.deploymentFrequencySettings = [
...state.deploymentFrequencySettings,
...deploymentFrequencySettings,
{ id: newId, organization: '', pipelineName: '', step: '', branches: [] },
];
},
Expand Down Expand Up @@ -488,8 +489,7 @@ export const selectOrganizationWarningMessage = (state: RootState, id: number) =

export const selectPipelineNameWarningMessage = (state: RootState, id: number) => {
const { deploymentWarningMessage } = state.metrics;
const warningMessage = deploymentWarningMessage;
return warningMessage.find((item) => item.id === id)?.pipelineName;
return deploymentWarningMessage.find((item) => item.id === id)?.pipelineName;
};

export const selectStepWarningMessage = (state: RootState, id: number) => {
Expand Down
7 changes: 0 additions & 7 deletions frontend/src/context/interface/index.tsx

This file was deleted.

6 changes: 3 additions & 3 deletions frontend/src/hooks/useMetricsStepValidationCheckContext.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { PipelineSetting } from '@src/context/interface';
import { IPipelineConfig } from '@src/context/Metrics/metricsSlice';
import React, { createContext, useContext } from 'react';

interface ProviderContextType {
getDuplicatedPipeLineIds: (pipelineSettings: PipelineSetting[]) => number[];
getDuplicatedPipeLineIds: (pipelineSettings: IPipelineConfig[]) => number[];
}

interface ContextProviderProps {
Expand All @@ -13,7 +13,7 @@ export const ValidationContext = createContext<ProviderContextType>({
getDuplicatedPipeLineIds: () => [],
});

const getDuplicatedPipeLineIds = (pipelineSettings: PipelineSetting[]) => {
const getDuplicatedPipeLineIds = (pipelineSettings: IPipelineConfig[]) => {
const errors: { [key: string]: number[] } = {};
pipelineSettings.forEach(({ id, organization, pipelineName, step }) => {
if (organization && pipelineName && step) {
Expand Down

0 comments on commit b1f38c3

Please sign in to comment.