]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-9565 Display quality gate directly if there is only one and the user can't...
authorGrégoire Aubert <gregoire.aubert@sonarsource.com>
Mon, 24 Jul 2017 12:13:34 +0000 (14:13 +0200)
committerGrégoire Aubert <gregoire.aubert@sonarsource.com>
Tue, 25 Jul 2017 07:20:30 +0000 (09:20 +0200)
server/sonar-web/src/main/js/apps/quality-gates/components/QualityGatesApp.js
tests/src/test/java/org/sonarqube/pageobjects/ProjectDashboardPage.java
tests/src/test/java/org/sonarqube/pageobjects/QualityGatePage.java
tests/src/test/java/org/sonarqube/tests/OrganizationTester.java
tests/src/test/java/org/sonarqube/tests/qualityGate/OrganizationQualityGateUiTest.java
tests/src/test/java/org/sonarqube/tests/qualityGate/QualityGateUiTest.java

index 3ac0da688ccc5ab70e229536be5233883684acaf..e197e6f0f8345a94cd6367453cd2e62e97c8274a 100644 (file)
@@ -41,11 +41,17 @@ export default class QualityGatesApp extends Component {
   }
 
   fetchQualityGates() {
-    Promise.all([fetchQualityGatesAppDetails(), fetchQualityGatesAPI()]).then(responses => {
-      const [details, qualityGates] = responses;
-      const { updateStore } = this.props;
-
+    Promise.all([
+      fetchQualityGatesAppDetails(),
+      fetchQualityGatesAPI()
+    ]).then(([details, qualityGates]) => {
+      const { organization, updateStore } = this.props;
       updateStore({ ...details, qualityGates });
+      if (qualityGates && qualityGates.length === 1 && !details.edit) {
+        this.context.router.replace(
+          getQualityGateUrl(qualityGates[0].id, organization && organization.key)
+        );
+      }
     });
   }
 
@@ -62,7 +68,7 @@ export default class QualityGatesApp extends Component {
     const defaultTitle = translate('quality_gates.page');
     const top = organization ? 95 : 30;
     return (
-      <div className="layout-page">
+      <div id="quality-gates-page" className="layout-page">
         <Helmet defaultTitle={defaultTitle} titleTemplate={'%s - ' + defaultTitle} />
 
         <div className="layout-page-side-outer">
index 673e037c1937edf6b937b82628b5523355c94bed..f1d150e2c1640b6c818daf90369eeebb20397403 100644 (file)
@@ -101,8 +101,9 @@ public class ProjectDashboardPage {
   }
 
   public ProjectDashboardPage hasQualityGateLink(String name, String link) {
-    SelenideElement elem = $(".overview-meta-header").should(exist)
-      .parent().find(By.linkText(name)).should(exist);
+    SelenideElement elem = $$(".overview-meta-card")
+      .findBy(text("Quality Gate")).should(exist)
+      .find(By.linkText(name)).should(exist);
     assertThat(elem.attr("href")).endsWith(link);
     return this;
   }
index 3d7162f898d26f17f584f3ccde4c4b04ae694042..4133bbfeb92d65b0fb106bd4a3df996e6204b719 100644 (file)
@@ -26,11 +26,11 @@ import static com.codeborne.selenide.Selenide.$$;
 
 public class QualityGatePage {
   public QualityGatePage() {
-    $(".quality-gates-results").shouldBe(Condition.visible);
+    $("#quality-gates-page").shouldBe(Condition.visible);
   }
 
   public QualityGatePage countQualityGates(Integer count) {
-    $$(".quality-gates-results .list-group-item").shouldHaveSize(count);
+    $$("#quality-gates-page .list-group-item").shouldHaveSize(count);
     return this;
   }
 
@@ -43,4 +43,14 @@ public class QualityGatePage {
     $("#quality-gate-add").shouldNot(Condition.exist);
     return this;
   }
+
+  public QualityGatePage displayIntro() {
+    $(".search-navigator-intro").should(Condition.exist).shouldBe(Condition.visible);
+    return this;
+  }
+
+  public QualityGatePage displayQualityGateDetail(String qualityGateName) {
+    $(".layout-page-main-header").shouldHave(Condition.text(qualityGateName));
+    return this;
+  }
 }
index 2072e87822a6ae31c5354f49f9bfa2c7f62fc539..5550cd527c53dd43b766b50edef49bc78b6b912e 100644 (file)
@@ -74,6 +74,13 @@ public class OrganizationTester {
     return this;
   }
 
+  public Organizations.Organization getDefaultOrganization() {
+    return service().search(SearchWsRequest.builder().build()).getOrganizationsList()
+      .stream()
+      .filter(o -> o.getKey().equals("default-organization"))
+      .findFirst().orElseThrow(() -> new IllegalStateException("Can't find default organization"));
+  }
+
   public OrganizationTester assertThatOrganizationDoesNotExist(String organizationKey) {
     SearchWsRequest request = new SearchWsRequest.Builder().setOrganizations(organizationKey).build();
     Organizations.SearchWsResponse searchWsResponse = service().search(request);
index 01ab1189d87748e7760e1973be4f1bc496ebe796..fc846cb244f054755fef03a08cf3fe99a588e276 100644 (file)
@@ -52,10 +52,14 @@ public class OrganizationQualityGateUiTest {
 
   private Organizations.Organization organization;
   private WsUsers.CreateWsResponse.User user;
+  private WsUsers.CreateWsResponse.User gateAdmin;
 
   @Before
   public void setUp() throws Exception {
     organization = tester.organizations().generate();
+    gateAdmin = tester.users().generate();
+    tester.organizations().addMember(tester.organizations().getDefaultOrganization(), gateAdmin);
+    tester.wsClient().permissions().addUser(new org.sonarqube.ws.client.permission.AddUserWsRequest().setLogin(gateAdmin.getLogin()).setPermission("gateadmin"));
     user = tester.users().generate();
     tester.organizations().addMember(organization, user);
     restoreProfile(orchestrator, getClass().getResource("/issue/with-many-rules.xml"), organization.getKey());
@@ -67,7 +71,7 @@ public class OrganizationQualityGateUiTest {
       .logIn().submitCredentials(user.getLogin())
       .openQualityGates(organization.getKey());
 
-    SelenideElement element = $(".navbar-context .navbar-nav")
+    SelenideElement element = $(".navbar-context .navbar-tabs")
       .find(By.linkText("Quality Gates"))
       .should(Condition.exist);
     assertThat(element.attr("href")).endsWith("/organizations/" + organization.getKey() + "/quality_gates");
@@ -76,9 +80,9 @@ public class OrganizationQualityGateUiTest {
   @Test
   public void should_display_available_quality_gates() {
     QualityGatePage page = tester.openBrowser()
-      .logIn().submitCredentials(user.getLogin())
+      .logIn().submitCredentials(gateAdmin.getLogin())
       .openQualityGates(organization.getKey());
-    page.countQualityGates(1);
+    page.countQualityGates(1).displayIntro();
   }
 
   @Test
@@ -88,7 +92,7 @@ public class OrganizationQualityGateUiTest {
       .openQualityGates(organization.getKey())
       .canNotCreateQG();
     tester.openBrowser()
-      .logIn().submitCredentials("admin")
+      .logIn().submitCredentials(gateAdmin.getLogin())
       .openQualityGates(organization.getKey())
       .canCreateQG();
   }
@@ -110,4 +114,12 @@ public class OrganizationQualityGateUiTest {
       .openProjectDashboard(project);
     page.hasQualityGateLink("SonarQube way", link);
   }
+
+  @Test
+  public void should_redirect_to_display_quality_gate_detail() {
+    QualityGatePage page = tester.openBrowser()
+      .logIn().submitCredentials(user.getLogin())
+      .openQualityGates(organization.getKey());
+    page.countQualityGates(1).displayQualityGateDetail("SonarQube way");
+  }
 }
index acb207f52715ed40cc88f2e64122c5f85a6aa989..59fd4cbe73819584d248305197f15ecc597d72e3 100644 (file)
@@ -42,6 +42,8 @@ import org.sonar.wsclient.qualitygate.UpdateCondition;
 import org.sonarqube.pageobjects.Navigation;
 import org.sonarqube.pageobjects.ProjectActivityPage;
 import org.sonarqube.tests.Tester;
+import org.sonarqube.ws.Organizations;
+import org.sonarqube.ws.WsUsers;
 
 import static com.codeborne.selenide.Selenide.$;
 import static org.apache.commons.lang.time.DateUtils.addDays;
@@ -119,7 +121,7 @@ public class QualityGateUiTest {
       .logIn().submitCredentials(login)
       .openQualityGates();
 
-    SelenideElement element = $(".navbar-global .navbar-nav")
+    SelenideElement element = $(".navbar-global .global-navbar-menu")
       .find(By.linkText("Quality Gates"))
       .should(Condition.exist);
     assertThat(element.attr("href")).endsWith("/quality_gates");
@@ -128,14 +130,17 @@ public class QualityGateUiTest {
   @Test
   public void should_not_allow_random_user_to_create() {
     String login = tester.users().generate().getLogin();
+    String admin = tester.users().generateAdministrator().getLogin();
     tester.openBrowser()
       .logIn().submitCredentials(login)
       .openQualityGates()
-      .canNotCreateQG();
+      .canNotCreateQG()
+      .displayQualityGateDetail("SonarQube way");
     tester.openBrowser()
-      .logIn().submitCredentials("admin")
+      .logIn().submitCredentials(admin)
       .openQualityGates()
-      .canCreateQG();
+      .canCreateQG()
+      .displayIntro();
   }
 
   private void scanSampleWithDate(String date) {