]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-14061 Azure DevOps settings validation
authorBelen Pruvost <belen.pruvost@sonarsource.com>
Thu, 26 Nov 2020 08:34:18 +0000 (10:34 +0200)
committersonartech <sonartech@sonarsource.com>
Thu, 26 Nov 2020 20:06:29 +0000 (20:06 +0000)
server/sonar-web/src/main/js/apps/settings/components/almIntegration/AlmBindingDefinitionBox.tsx
server/sonar-web/src/main/js/apps/settings/components/almIntegration/AlmIntegration.tsx
server/sonar-web/src/main/js/apps/settings/components/almIntegration/AlmTab.tsx
server/sonar-web/src/main/js/apps/settings/components/almIntegration/__tests__/AlmIntegration-test.tsx
server/sonar-web/src/main/js/apps/settings/components/almIntegration/__tests__/__snapshots__/AlmBindingDefinitionBox-test.tsx.snap
server/sonar-web/src/main/js/apps/settings/components/almIntegration/utils.ts

index fa55dca833d0658ba8d3e0c7388b062e619d7177..41c8c384ffeaa74b932ad1507c05aafa4d9463d8 100644 (file)
@@ -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 && <span>{definition.url}</span>}
       </div>
 
-      {!VALIDATED_ALMS.includes(alm) && (
+      {status.type === AlmSettingsBindingStatusType.Validating ? (
         <>
-          <div className="display-flex-row spacer-bottom">
-            <div className="huge-spacer-right">
+          <i className="spinner spacer-right" />
+          {translate('settings.almintegration.checking_configuration')}
+        </>
+      ) : (
+        <>
+          {status.type !== AlmSettingsBindingStatusType.Warning && (
+            <div className="display-flex-row spacer-bottom">
               <Tooltip overlay={importFeatureDescription}>
-                <span>{importFeatureTitle}</span>
-              </Tooltip>
-              <AlertSuccessIcon className="spacer-left" />
-            </div>
-            <div>
-              <Tooltip
-                overlay={translate('settings.almintegration.feature.alm_repo_import.description')}>
-                <span>{translate('settings.almintegration.feature.alm_repo_import.title')}</span>
+                <div className="huge-spacer-right">
+                  {importFeatureTitle}
+                  {STATUS_ICON[status.type]}
+                </div>
               </Tooltip>
-              {getImportFeatureStatus(
-                definition,
-                multipleDefinitions,
-                AlmSettingsBindingStatusType.Success
-              )}
+              <div>
+                <Tooltip
+                  overlay={translate(
+                    'settings.almintegration.feature.alm_repo_import.description'
+                  )}>
+                  <span>{translate('settings.almintegration.feature.alm_repo_import.title')}</span>
+                </Tooltip>
+                {getImportFeatureStatus(definition, multipleDefinitions, status.type)}
+              </div>
             </div>
-          </div>
+          )}
 
           <div className="width-50">
-            <Alert variant="info">{translate('settings.almintegration.no_validation')}</Alert>
-          </div>
-        </>
-      )}
-
-      {VALIDATED_ALMS.includes(alm) &&
-        (status.type === AlmSettingsBindingStatusType.Validating ? (
-          <>
-            <i className="spinner spacer-right" />
-            {translate('settings.almintegration.checking_configuration')}
-          </>
-        ) : (
-          <>
-            {status.type !== AlmSettingsBindingStatusType.Warning && (
-              <div className="display-flex-row spacer-bottom">
-                <Tooltip overlay={importFeatureDescription}>
-                  <div className="huge-spacer-right">
-                    {importFeatureTitle}
-                    {STATUS_ICON[status.type]}
-                  </div>
-                </Tooltip>
-                <div>
-                  <Tooltip
-                    overlay={translate(
-                      'settings.almintegration.feature.alm_repo_import.description'
-                    )}>
-                    <span>
-                      {translate('settings.almintegration.feature.alm_repo_import.title')}
-                    </span>
-                  </Tooltip>
-                  {getImportFeatureStatus(definition, multipleDefinitions, status.type)}
-                </div>
-              </div>
+            {status.type === AlmSettingsBindingStatusType.Warning && (
+              <Alert variant="warning">
+                {translate('settings.almintegration.could_not_validate')}
+              </Alert>
             )}
 
-            <div className="width-50">
-              {status.type === AlmSettingsBindingStatusType.Warning && (
-                <Alert variant="warning">
-                  {translate('settings.almintegration.could_not_validate')}
-                </Alert>
-              )}
-
-              {status.type === AlmSettingsBindingStatusType.Failure && (
-                <Alert variant="error">{status.failureMessage}</Alert>
-              )}
+            {status.type === AlmSettingsBindingStatusType.Failure && (
+              <Alert variant="error">{status.failureMessage}</Alert>
+            )}
 
-              {status.type === AlmSettingsBindingStatusType.Success && status.alertSuccess && (
-                <Alert variant="success">
-                  {translate('settings.almintegration.configuration_valid')}
-                </Alert>
-              )}
-            </div>
+            {status.type === AlmSettingsBindingStatusType.Success && status.alertSuccess && (
+              <Alert variant="success">
+                {translate('settings.almintegration.configuration_valid')}
+              </Alert>
+            )}
+          </div>
 
-            <Button className="big-spacer-top" onClick={() => props.onCheck(definition.key)}>
-              {translate('settings.almintegration.check_configuration')}
-            </Button>
-          </>
-        ))}
+          <Button className="big-spacer-top" onClick={() => props.onCheck(definition.key)}>
+            {translate('settings.almintegration.check_configuration')}
+          </Button>
+        </>
+      )}
     </div>
   );
 }
index ed6c0c964f0eaf3cc1d8e1a3b614e7986203d5fc..0bb9f013a85dc3b714922f0b18ec7f206a46beb2 100644 (file)
@@ -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<T.AppState, 'branchesEnabled' | 'multipleAlmEnabled'>;
@@ -70,7 +70,7 @@ export class AlmIntegration extends React.PureComponent<Props, State> {
     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)
           );
index 34a31756ac76bcb02a05320791899176bd531793..5fbb9ffcdfa90f02ca0e16d45a040e05a131ba68 100644 (file)
@@ -25,7 +25,6 @@ import {
 } from '../../../../types/alm-settings';
 import { AlmBindingDefinitionFormChildrenProps } from './AlmBindingDefinitionForm';
 import AlmTabRenderer from './AlmTabRenderer';
-import { VALIDATED_ALMS } from './utils';
 
 interface Props<B> {
   alm: AlmKeys;
@@ -98,9 +97,7 @@ export default class AlmTab<B extends AlmBindingDefinition> 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) {
index 2bb0d8445805c7df153161e11f6a1a2a6690b141..d24361dbfdefd549f9dc1e503a3f402d208b1f63 100644 (file)
@@ -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');
index 2fd332649c62e76f1779b828a3fc6f65929267bd..5a3af1e526019f0764518812559c603522801ec0 100644 (file)
@@ -32,55 +32,10 @@ exports[`should render correctly: Azure DevOps 1`] = `
       key
     </h3>
   </div>
-  <div
-    className="display-flex-row spacer-bottom"
-  >
-    <div
-      className="huge-spacer-right"
-    >
-      <Tooltip
-        overlay="settings.almintegration.feature.pr_decoration.description"
-      >
-        <span>
-          settings.almintegration.feature.pr_decoration.title
-        </span>
-      </Tooltip>
-      <AlertSuccessIcon
-        className="spacer-left"
-      />
-    </div>
-    <div>
-      <Tooltip
-        overlay="settings.almintegration.feature.alm_repo_import.description"
-      >
-        <span>
-          settings.almintegration.feature.alm_repo_import.title
-        </span>
-      </Tooltip>
-      <div
-        className="display-inline-flex-center"
-      >
-        <strong
-          className="spacer-left"
-        >
-          settings.almintegration.feature.alm_repo_import.disabled
-        </strong>
-        <HelpTooltip
-          className="little-spacer-left"
-          overlay="settings.almintegration.feature.alm_repo_import.disabled.no_url"
-        />
-      </div>
-    </div>
-  </div>
-  <div
-    className="width-50"
-  >
-    <Alert
-      variant="info"
-    >
-      settings.almintegration.no_validation
-    </Alert>
-  </div>
+  <i
+    className="spinner spacer-right"
+  />
+  settings.almintegration.checking_configuration
 </div>
 `;
 
index 5de5535b294ef16aa9bfc2e8abe856c74f26d404..7eb61aa79774fd8bb77f04d4b0b7ba0fcce9169a 100644 (file)
@@ -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];