Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ADM-999 [frontend][backend]: fix e2e test and change the logic #1594

Merged
merged 3 commits into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 3 additions & 31 deletions frontend/__tests__/context/metricsSlice.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1638,11 +1638,8 @@ describe('saveMetricsSetting reducer', () => {
expect(savedMetricsSetting.sourceControlConfigurationSettings).toEqual(expectedSourceControlConfigurationSettings);
});

it('should return source control settings when handle updateSourceControlConfigurationSettingsFirstInto and isProjectCreated is true and setting is empty', () => {
const expectedSourceControlConfigurationSettings = [
{ id: 0, organization: '', repo: '', branches: [] },
{ id: 1, organization: '', repo: '', branches: [] },
];
it('should return source control settings when handle updateSourceControlConfigurationSettingsFirstInto and setting is empty', () => {
const expectedSourceControlConfigurationSettings = [{ id: 0, organization: '', repo: '', branches: [] }];
const savedMetricsSetting = saveMetricsSettingReducer(
initState,
updateSourceControlConfigurationSettingsFirstInto({
Expand All @@ -1655,31 +1652,7 @@ describe('saveMetricsSetting reducer', () => {
expect(savedMetricsSetting.sourceControlConfigurationSettings).toEqual(expectedSourceControlConfigurationSettings);
});

it('should return source control settings when handle updateSourceControlConfigurationSettingsFirstInto and isProjectCreated is true and setting is not empty', () => {
const existedSourceControlConfigurationSettings = [
{ id: 1, organization: 'test-org1', repo: 'test-repo1', branches: ['test-branch1'] },
];
const expectedSourceControlConfigurationSettings = [
{ id: 1, organization: 'test-org1', repo: 'test-repo1', branches: ['test-branch1'] },
];
const state = {
...initState,
sourceControlConfigurationSettings: existedSourceControlConfigurationSettings,
};

const savedMetricsSetting = saveMetricsSettingReducer(
state,
updateSourceControlConfigurationSettingsFirstInto({
name: ['test1', 'test2'],
isProjectCreated: true,
type: 'organization',
}),
);

expect(savedMetricsSetting.sourceControlConfigurationSettings).toEqual(expectedSourceControlConfigurationSettings);
});

it('should return source control settings when handle updateSourceControlConfigurationSettingsFirstInto and isProjectCreated is false and setting is empty', () => {
it('should return source control settings when handle updateSourceControlConfigurationSettingsFirstInto and setting is empty', () => {
const existedImportedSourceControlSettings = [
{ id: 1, organization: 'test-org1', repo: 'test-repo1', branches: ['test-branch1'] },
{ id: 2, organization: 'test-org2', repo: 'test-repo2', branches: ['test-branch2'] },
Expand All @@ -1698,7 +1671,6 @@ describe('saveMetricsSetting reducer', () => {
state,
updateSourceControlConfigurationSettingsFirstInto({
name: ['test-org1', 'test2'],
isProjectCreated: false,
type: 'organization',
}),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export const SourceControlConfiguration = () => {
setLoadingCompletedNumber={setLoadingCompletedNumber}
/>
))}
<AddButton onClick={handleAddSourceControl} text={'New Source Control'} />
<AddButton onClick={handleAddSourceControl} text={'New Repo'} />
{shouldShowCrews && (
<Crews
options={sourceControlCrews}
Expand Down
70 changes: 35 additions & 35 deletions frontend/src/context/Metrics/metricsSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -411,48 +411,48 @@ export const metricsSlice = createSlice({
},

updateSourceControlConfigurationSettingsFirstInto: (state, action) => {
const { name, isProjectCreated, type } = action.payload;
const { name, type } = action.payload;

const sourceControlConfigurationSettings = state.sourceControlConfigurationSettings;
if (isProjectCreated) {
state.sourceControlConfigurationSettings =
sourceControlConfigurationSettings.length > 0
? sourceControlConfigurationSettings
: name.map((it: string, index: number) => ({
id: index,

let validSourceControlConfigurationSettings =
sourceControlConfigurationSettings.length > 0
? sourceControlConfigurationSettings
: state.importedData.importedSourceControlSettings
.filter((it) => it.id !== undefined)
.map((it) => ({
id: it.id,
organization: it.organization,
repo: it.repo,
branches: it.branches,
}));
validSourceControlConfigurationSettings =
validSourceControlConfigurationSettings.length > 0
? validSourceControlConfigurationSettings
: [
{
id: 0,
organization: '',
repo: '',
branches: [],
}));
} else {
let validSourceControlConfigurationSettings =
sourceControlConfigurationSettings.length > 0
? sourceControlConfigurationSettings
: state.importedData.importedSourceControlSettings
.filter((it) => it.id !== undefined)
.map((it) => ({
id: it.id,
organization: it.organization,
repo: it.repo,
branches: it.branches,
}));

if (type === 'organization') {
validSourceControlConfigurationSettings = validSourceControlConfigurationSettings.filter(
(it) => it['organization'] === '' || name.includes(it['organization']),
);
} else if (type === 'repo') {
validSourceControlConfigurationSettings = validSourceControlConfigurationSettings.filter(
(it) => it['repo'] === '' || name.includes(it['repo']),
);
} else {
validSourceControlConfigurationSettings = validSourceControlConfigurationSettings.filter(
(it) => it['branches'].length === 0 || it['branches'].filter((branch) => name.includes(branch)),
);
}
},
];

state.sourceControlConfigurationSettings = validSourceControlConfigurationSettings;
if (type === 'organization') {
validSourceControlConfigurationSettings = validSourceControlConfigurationSettings.filter(
(it) => it['organization'] === '' || name.includes(it['organization']),
);
} else if (type === 'repo') {
validSourceControlConfigurationSettings = validSourceControlConfigurationSettings.filter(
(it) => it['repo'] === '' || name.includes(it['repo']),
);
} else {
validSourceControlConfigurationSettings = validSourceControlConfigurationSettings.filter(
(it) => it['branches'].length === 0 || it['branches'].filter((branch) => name.includes(branch)),
);
}

state.sourceControlConfigurationSettings = validSourceControlConfigurationSettings;
},

updateShouldGetBoardConfig: (state, action) => {
Expand Down
4 changes: 4 additions & 0 deletions frontend/src/context/config/configSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,9 @@ export const configSlice = createSlice({
updateSourceControl: (state, action) => {
state.sourceControl.config = action.payload;
},
clearSourceControlVerifiedResponse: (state) => {
state.sourceControl.verifiedResponse.repoList = { name: 'root', value: '-1', children: [] };
},
updateSourceControlVerifiedResponse: (state, action) => {
const namesList = ['organization', 'repo', 'branch', 'time', 'crew'];
const matchedRepoList = state.sourceControl.verifiedResponse.repoList;
Expand Down Expand Up @@ -249,6 +252,7 @@ export const {
updatePipelineTool,
updatePipelineToolVerifyResponse,
updateSourceControl,
clearSourceControlVerifiedResponse,
updateSourceControlVerifiedResponse,
updatePipelineToolVerifyResponseSteps,
resetImportedData,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import {
selectIsProjectCreated,
selectSourceControl,
updateSourceControlVerifiedResponse,
} from '@src/context/config/configSlice';
import { selectSourceControl, updateSourceControlVerifiedResponse } from '@src/context/config/configSlice';
import { updateSourceControlConfigurationSettingsFirstInto } from '@src/context/Metrics/metricsSlice';
import { sourceControlClient } from '@src/clients/sourceControl/SourceControlClient';
import { useAppDispatch, useAppSelector } from '@src/hooks/index';
Expand All @@ -20,7 +16,6 @@ export const useGetSourceControlConfigurationBranchEffect = (): IUseGetSourceCon
const [isLoading, setIsLoading] = useState<boolean>(false);
const [isGetBranch, setIsGetBranch] = useState<boolean>(false);
const restoredSourceControlInfo = useAppSelector(selectSourceControl);
const isProjectCreated = useAppSelector(selectIsProjectCreated);

function getEnumKeyByEnumValue(enumValue: string): SourceControlTypes {
return Object.entries(SourceControlTypes)
Expand Down Expand Up @@ -57,7 +52,6 @@ export const useGetSourceControlConfigurationBranchEffect = (): IUseGetSourceCon
dispatch(
updateSourceControlConfigurationSettingsFirstInto({
...response.data,
isProjectCreated,
type: 'branch',
}),
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import {
selectShouldGetSourceControlConfig,
updateSourceControlConfigurationSettingsFirstInto,
} from '@src/context/Metrics/metricsSlice';
import {
selectIsProjectCreated,
clearSourceControlVerifiedResponse,
selectSourceControl,
updateSourceControlVerifiedResponse,
} from '@src/context/config/configSlice';
import {
selectShouldGetSourceControlConfig,
updateSourceControlConfigurationSettingsFirstInto,
} from '@src/context/Metrics/metricsSlice';
import { ISourceControlGetOrganizationResponseDTO } from '@src/clients/sourceControl/dto/response';
import { sourceControlClient } from '@src/clients/sourceControl/SourceControlClient';
import { useAppDispatch, useAppSelector } from '@src/hooks/index';
Expand All @@ -20,6 +20,7 @@ export interface IUseGetSourceControlConfigurationStateInterface {
readonly info: ISourceControlGetOrganizationResponseDTO;
readonly isFirstFetch: boolean;
}

export const useGetSourceControlConfigurationOrganizationEffect =
(): IUseGetSourceControlConfigurationStateInterface => {
const defaultInfoStructure = {
Expand All @@ -34,7 +35,6 @@ export const useGetSourceControlConfigurationOrganizationEffect =
const restoredSourceControlInfo = useAppSelector(selectSourceControl);
const shouldGetSourceControlConfig = useAppSelector(selectShouldGetSourceControlConfig);
const [isFirstFetch, setIsFirstFetch] = useState(shouldGetSourceControlConfig);
const isProjectCreated = useAppSelector(selectIsProjectCreated);

function getEnumKeyByEnumValue(enumValue: string): SourceControlTypes {
return Object.entries(SourceControlTypes)
Expand All @@ -61,7 +61,6 @@ export const useGetSourceControlConfigurationOrganizationEffect =
dispatch(
updateSourceControlConfigurationSettingsFirstInto({
...response.data,
isProjectCreated,
type: 'organization',
}),
);
Expand All @@ -70,14 +69,19 @@ export const useGetSourceControlConfigurationOrganizationEffect =
setIsLoading(false);
setIsFirstFetch(false);
}
}, [dispatch, restoredSourceControlInfo.token, restoredSourceControlInfo.type, isProjectCreated]);
}, [dispatch, restoredSourceControlInfo.token, restoredSourceControlInfo.type]);

useEffect(() => {
if (!apiTouchedRef.current && !isLoading) {
apiTouchedRef.current = true;
getSourceControlInfo();
}
}, [getSourceControlInfo, isLoading]);

useEffect(() => {
dispatch(clearSourceControlVerifiedResponse());
}, [dispatch, restoredSourceControlInfo.token]);

return {
isLoading,
getSourceControlInfo,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
import {
DateRange,
selectIsProjectCreated,
selectSourceControl,
updateSourceControlVerifiedResponse,
} from '@src/context/config/configSlice';
import { DateRange, selectSourceControl, updateSourceControlVerifiedResponse } from '@src/context/config/configSlice';
import { updateSourceControlConfigurationSettingsFirstInto } from '@src/context/Metrics/metricsSlice';
import { sourceControlClient } from '@src/clients/sourceControl/SourceControlClient';
import { FULFILLED, SourceControlTypes } from '@src/constants/resources';
Expand All @@ -21,7 +16,6 @@ export const useGetSourceControlConfigurationRepoEffect = (): IUseGetSourceContr
const [isLoading, setIsLoading] = useState<boolean>(false);
const [isGetRepo, setIsGetRepo] = useState<boolean>(false);
const restoredSourceControlInfo = useAppSelector(selectSourceControl);
const isProjectCreated = useAppSelector(selectIsProjectCreated);

function getEnumKeyByEnumValue(enumValue: string): SourceControlTypes {
return Object.entries(SourceControlTypes)
Expand Down Expand Up @@ -58,7 +52,6 @@ export const useGetSourceControlConfigurationRepoEffect = (): IUseGetSourceContr
dispatch(
updateSourceControlConfigurationSettingsFirstInto({
...response.value.data,
isProjectCreated,
type: 'repo',
}),
);
Expand Down
Loading