]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-10849 Display default quality gate by default
authorGrégoire Aubert <gregoire.aubert@sonarsource.com>
Mon, 4 Jun 2018 11:34:57 +0000 (13:34 +0200)
committerSonarTech <sonartech@sonarsource.com>
Wed, 6 Jun 2018 18:20:50 +0000 (20:20 +0200)
server/sonar-qa-util/src/main/java/org/sonarqube/qa/util/pageobjects/QualityGatePage.java
server/sonar-web/src/main/js/apps/quality-gates/components/Intro.tsx
server/sonar-web/src/main/js/apps/quality-gates/components/__tests__/Intro-test.tsx [new file with mode: 0644]
server/sonar-web/src/main/js/apps/quality-gates/components/__tests__/__snapshots__/Intro-test.tsx.snap [new file with mode: 0644]
tests/src/test/java/org/sonarqube/tests/qualityGate/OrganizationQualityGateUiTest.java
tests/src/test/java/org/sonarqube/tests/qualityGate/QualityGateUiTest.java

index 8818425970713c5adb24ccc5bbc9a212904dad88..6c1ad63a38e0364417026f20cd79086ae4844e37 100644 (file)
@@ -53,11 +53,6 @@ public class QualityGatePage {
     return this;
   }
 
-  public QualityGatePage displayIntro() {
-    $(".search-navigator-intro").should(exist).shouldBe(visible);
-    return this;
-  }
-
   public QualityGatePage displayQualityGateDetail(String qualityGateName) {
     $(".layout-page-main-header").shouldHave(text(qualityGateName));
     return this;
index ea5edc9180c84d89928ca27a47311f63976ce23f..bbf59a9610d12916964d92fc69b643011da32b0e 100644 (file)
  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  */
 import * as React from 'react';
+import { InjectedRouter } from 'react-router';
 import { translate } from '../../../helpers/l10n';
+import { QualityGate } from '../../../app/types';
+import { getQualityGateUrl } from '../../../helpers/urls';
 
-export default function Intro() {
-  return (
-    <div className="layout-page-main">
-      <div className="layout-page-main-inner">
-        <div className="search-navigator-intro markdown">
-          <p>{translate('quality_gates.intro.1')}</p>
-          <p>{translate('quality_gates.intro.2')}</p>
+interface Props {
+  organization?: string;
+  qualityGates: QualityGate[];
+  router: InjectedRouter;
+}
+
+export default class Intro extends React.PureComponent<Props> {
+  componentDidMount() {
+    const defaultQualityGate = this.props.qualityGates.find(qualityGate =>
+      Boolean(qualityGate.isDefault)
+    );
+    if (defaultQualityGate) {
+      this.props.router.replace(
+        getQualityGateUrl(String(defaultQualityGate.id), this.props.organization)
+      );
+    }
+  }
+
+  render() {
+    return (
+      <div className="layout-page-main">
+        <div className="layout-page-main-inner">
+          <div className="search-navigator-intro markdown">
+            <p>{translate('quality_gates.intro.1')}</p>
+            <p>{translate('quality_gates.intro.2')}</p>
+          </div>
         </div>
       </div>
-    </div>
-  );
+    );
+  }
 }
diff --git a/server/sonar-web/src/main/js/apps/quality-gates/components/__tests__/Intro-test.tsx b/server/sonar-web/src/main/js/apps/quality-gates/components/__tests__/Intro-test.tsx
new file mode 100644 (file)
index 0000000..c14c5ad
--- /dev/null
@@ -0,0 +1,40 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2018 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+import * as React from 'react';
+import { shallow } from 'enzyme';
+import Intro from '../Intro';
+
+it('should redirect to detail of default quality gate', () => {
+  const replace = jest.fn();
+  shallow(
+    <Intro
+      organization="foo"
+      qualityGates={[{ id: 1, name: 'Bar', isDefault: true }]}
+      router={{ replace } as any}
+    />
+  );
+  expect(replace).toHaveBeenCalledWith({ pathname: '/organizations/foo/quality_gates/show/1' });
+});
+
+it('should display the intro', () => {
+  expect(
+    shallow(<Intro organization="foo" qualityGates={[]} router={{} as any} />)
+  ).toMatchSnapshot();
+});
diff --git a/server/sonar-web/src/main/js/apps/quality-gates/components/__tests__/__snapshots__/Intro-test.tsx.snap b/server/sonar-web/src/main/js/apps/quality-gates/components/__tests__/__snapshots__/Intro-test.tsx.snap
new file mode 100644 (file)
index 0000000..ba12639
--- /dev/null
@@ -0,0 +1,22 @@
+// Jest Snapshot v1, https://goo.gl/fbAQLP
+
+exports[`should display the intro 1`] = `
+<div
+  className="layout-page-main"
+>
+  <div
+    className="layout-page-main-inner"
+  >
+    <div
+      className="search-navigator-intro markdown"
+    >
+      <p>
+        quality_gates.intro.1
+      </p>
+      <p>
+        quality_gates.intro.2
+      </p>
+    </div>
+  </div>
+</div>
+`;
index 43bafe8510d7c2c742f74e15341c5b4e63f5e221..0658aadd6ea24db4909b244425cfa45f9efb07d6 100644 (file)
@@ -85,7 +85,7 @@ public class OrganizationQualityGateUiTest {
     QualityGatePage page = tester.openBrowser()
       .logIn().submitCredentials(gateAdmin.getLogin())
       .openQualityGates(organization.getKey());
-    page.countQualityGates(1).displayIntro();
+    page.countQualityGates(1).displayQualityGateDetail("Sonar way");
   }
 
   @Test
index 95e2a177566d67c965980a21c9f9595a1361cdc5..29d9f1159732af759d8636f7ec26615c0a40e628 100644 (file)
@@ -118,7 +118,7 @@ public class QualityGateUiTest {
       .logIn().submitCredentials(admin)
       .openQualityGates()
       .canCreateQG()
-      .displayIntro();
+      .displayQualityGateDetail("Sonar way");
   }
 
   @Test