From 74f7665414df2b65cd7e3be3e3b1ca96280ffe0a Mon Sep 17 00:00:00 2001 From: Belen Pruvost Date: Thu, 26 Nov 2020 10:34:18 +0200 Subject: [PATCH] SONAR-14061 Azure DevOps settings validation --- .../AlmBindingDefinitionBox.tsx | 112 +++++++----------- .../almIntegration/AlmIntegration.tsx | 4 +- .../components/almIntegration/AlmTab.tsx | 5 +- .../__tests__/AlmIntegration-test.tsx | 7 +- .../AlmBindingDefinitionBox-test.tsx.snap | 53 +-------- .../components/almIntegration/utils.ts | 2 +- 6 files changed, 53 insertions(+), 130 deletions(-) diff --git a/server/sonar-web/src/main/js/apps/settings/components/almIntegration/AlmBindingDefinitionBox.tsx b/server/sonar-web/src/main/js/apps/settings/components/almIntegration/AlmBindingDefinitionBox.tsx index fa55dca833d..41c8c384ffe 100644 --- a/server/sonar-web/src/main/js/apps/settings/components/almIntegration/AlmBindingDefinitionBox.tsx +++ b/server/sonar-web/src/main/js/apps/settings/components/almIntegration/AlmBindingDefinitionBox.tsx @@ -33,7 +33,6 @@ import { AlmSettingsBindingStatus, AlmSettingsBindingStatusType } from '../../../../types/alm-settings'; -import { VALIDATED_ALMS } from './utils'; export interface AlmBindingDefinitionBoxProps { alm: AlmKeys; @@ -121,87 +120,56 @@ export default function AlmBindingDefinitionBox(props: AlmBindingDefinitionBoxPr {definition.url && {definition.url}} - {!VALIDATED_ALMS.includes(alm) && ( + {status.type === AlmSettingsBindingStatusType.Validating ? ( <> -
-
+ + {translate('settings.almintegration.checking_configuration')} + + ) : ( + <> + {status.type !== AlmSettingsBindingStatusType.Warning && ( +
- {importFeatureTitle} - - -
-
- - {translate('settings.almintegration.feature.alm_repo_import.title')} +
+ {importFeatureTitle} + {STATUS_ICON[status.type]} +
- {getImportFeatureStatus( - definition, - multipleDefinitions, - AlmSettingsBindingStatusType.Success - )} +
+ + {translate('settings.almintegration.feature.alm_repo_import.title')} + + {getImportFeatureStatus(definition, multipleDefinitions, status.type)} +
-
+ )}
- {translate('settings.almintegration.no_validation')} -
- - )} - - {VALIDATED_ALMS.includes(alm) && - (status.type === AlmSettingsBindingStatusType.Validating ? ( - <> - - {translate('settings.almintegration.checking_configuration')} - - ) : ( - <> - {status.type !== AlmSettingsBindingStatusType.Warning && ( -
- -
- {importFeatureTitle} - {STATUS_ICON[status.type]} -
-
-
- - - {translate('settings.almintegration.feature.alm_repo_import.title')} - - - {getImportFeatureStatus(definition, multipleDefinitions, status.type)} -
-
+ {status.type === AlmSettingsBindingStatusType.Warning && ( + + {translate('settings.almintegration.could_not_validate')} + )} -
- {status.type === AlmSettingsBindingStatusType.Warning && ( - - {translate('settings.almintegration.could_not_validate')} - - )} - - {status.type === AlmSettingsBindingStatusType.Failure && ( - {status.failureMessage} - )} + {status.type === AlmSettingsBindingStatusType.Failure && ( + {status.failureMessage} + )} - {status.type === AlmSettingsBindingStatusType.Success && status.alertSuccess && ( - - {translate('settings.almintegration.configuration_valid')} - - )} -
+ {status.type === AlmSettingsBindingStatusType.Success && status.alertSuccess && ( + + {translate('settings.almintegration.configuration_valid')} + + )} +
- - - ))} + + + )} ); } diff --git a/server/sonar-web/src/main/js/apps/settings/components/almIntegration/AlmIntegration.tsx b/server/sonar-web/src/main/js/apps/settings/components/almIntegration/AlmIntegration.tsx index ed6c0c964f0..0bb9f013a85 100644 --- a/server/sonar-web/src/main/js/apps/settings/components/almIntegration/AlmIntegration.tsx +++ b/server/sonar-web/src/main/js/apps/settings/components/almIntegration/AlmIntegration.tsx @@ -33,7 +33,7 @@ import { AlmSettingsBindingStatusType } from '../../../../types/alm-settings'; import AlmIntegrationRenderer from './AlmIntegrationRenderer'; -import { VALIDATED_ALMS } from './utils'; +import { ALM_KEY_LIST } from './utils'; interface Props { appState: Pick; @@ -70,7 +70,7 @@ export class AlmIntegration extends React.PureComponent { return this.fetchPullRequestDecorationSetting().then(definitions => { if (definitions) { // Validate all alms on load: - VALIDATED_ALMS.forEach(alm => { + ALM_KEY_LIST.forEach(alm => { this.state.definitions[alm].forEach((def: AlmBindingDefinition) => this.handleCheck(def.key, false) ); diff --git a/server/sonar-web/src/main/js/apps/settings/components/almIntegration/AlmTab.tsx b/server/sonar-web/src/main/js/apps/settings/components/almIntegration/AlmTab.tsx index 34a31756ac7..5fbb9ffcdfa 100644 --- a/server/sonar-web/src/main/js/apps/settings/components/almIntegration/AlmTab.tsx +++ b/server/sonar-web/src/main/js/apps/settings/components/almIntegration/AlmTab.tsx @@ -25,7 +25,6 @@ import { } from '../../../../types/alm-settings'; import { AlmBindingDefinitionFormChildrenProps } from './AlmBindingDefinitionForm'; import AlmTabRenderer from './AlmTabRenderer'; -import { VALIDATED_ALMS } from './utils'; interface Props { alm: AlmKeys; @@ -98,9 +97,7 @@ export default class AlmTab extends React.PureCo }) .then(this.props.onUpdateDefinitions) .then(() => { - if (VALIDATED_ALMS.includes(this.props.alm)) { - this.props.onCheck(config.key); - } + this.props.onCheck(config.key); }) .catch(() => { if (this.mounted) { diff --git a/server/sonar-web/src/main/js/apps/settings/components/almIntegration/__tests__/AlmIntegration-test.tsx b/server/sonar-web/src/main/js/apps/settings/components/almIntegration/__tests__/AlmIntegration-test.tsx index 2bb0d844580..d24361dbfde 100644 --- a/server/sonar-web/src/main/js/apps/settings/components/almIntegration/__tests__/AlmIntegration-test.tsx +++ b/server/sonar-web/src/main/js/apps/settings/components/almIntegration/__tests__/AlmIntegration-test.tsx @@ -32,7 +32,9 @@ import { AlmIntegration } from '../AlmIntegration'; jest.mock('../../../../../api/alm-settings', () => ({ countBindedProjects: jest.fn().mockResolvedValue(0), deleteConfiguration: jest.fn().mockResolvedValue(undefined), - getAlmDefinitions: jest.fn().mockResolvedValue({ bitbucket: [], github: [], gitlab: [] }), + getAlmDefinitions: jest + .fn() + .mockResolvedValue({ azure: [], bitbucket: [], github: [], gitlab: [] }), validateAlmSettings: jest.fn().mockResolvedValue('') })); @@ -56,7 +58,8 @@ it('should validate existing configurations', async () => { await waitAndUpdate(wrapper); - expect(validateAlmSettings).toBeCalledTimes(4); + expect(validateAlmSettings).toBeCalledTimes(5); + expect(validateAlmSettings).toBeCalledWith('a1'); expect(validateAlmSettings).toBeCalledWith('b1'); expect(validateAlmSettings).toBeCalledWith('gh1'); expect(validateAlmSettings).toBeCalledWith('gh2'); diff --git a/server/sonar-web/src/main/js/apps/settings/components/almIntegration/__tests__/__snapshots__/AlmBindingDefinitionBox-test.tsx.snap b/server/sonar-web/src/main/js/apps/settings/components/almIntegration/__tests__/__snapshots__/AlmBindingDefinitionBox-test.tsx.snap index 2fd332649c6..5a3af1e5260 100644 --- a/server/sonar-web/src/main/js/apps/settings/components/almIntegration/__tests__/__snapshots__/AlmBindingDefinitionBox-test.tsx.snap +++ b/server/sonar-web/src/main/js/apps/settings/components/almIntegration/__tests__/__snapshots__/AlmBindingDefinitionBox-test.tsx.snap @@ -32,55 +32,10 @@ exports[`should render correctly: Azure DevOps 1`] = ` key -
-
- - - settings.almintegration.feature.pr_decoration.title - - - -
-
- - - settings.almintegration.feature.alm_repo_import.title - - -
- - settings.almintegration.feature.alm_repo_import.disabled - - -
-
-
-
- - settings.almintegration.no_validation - -
+ + settings.almintegration.checking_configuration `; diff --git a/server/sonar-web/src/main/js/apps/settings/components/almIntegration/utils.ts b/server/sonar-web/src/main/js/apps/settings/components/almIntegration/utils.ts index 5de5535b294..7eb61aa7977 100644 --- a/server/sonar-web/src/main/js/apps/settings/components/almIntegration/utils.ts +++ b/server/sonar-web/src/main/js/apps/settings/components/almIntegration/utils.ts @@ -19,4 +19,4 @@ */ import { AlmKeys } from '../../../../types/alm-settings'; -export const VALIDATED_ALMS = [AlmKeys.Bitbucket, AlmKeys.GitHub, AlmKeys.GitLab]; +export const ALM_KEY_LIST = [AlmKeys.Azure, AlmKeys.Bitbucket, AlmKeys.GitHub, AlmKeys.GitLab]; -- 2.39.5