]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-9483 Add IT for the ui
authorGrégoire Aubert <gregoire.aubert@sonarsource.com>
Fri, 30 Jun 2017 14:29:01 +0000 (16:29 +0200)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Tue, 4 Jul 2017 14:29:36 +0000 (16:29 +0200)
tests/src/test/java/org/sonarqube/pageobjects/Navigation.java
tests/src/test/java/org/sonarqube/pageobjects/QualityProfilePage.java [new file with mode: 0644]
tests/src/test/java/org/sonarqube/pageobjects/RulesPage.java
tests/src/test/java/org/sonarqube/tests/qualityProfile/OrganizationQualityProfilesUiTest.java

index 54363129fec030c27a37d8bc7179c5bb5ea158fd..342d263546258d478f19168c84531c0e449e72c7 100644 (file)
@@ -127,6 +127,11 @@ public class Navigation {
     return open(url, MembersPage.class);
   }
 
+  public QualityProfilePage openQualityProfile(String language, String name, String organization) {
+    String profileUrl = "/quality_profiles/show?language=" + language + "&name=" + name;
+    return open("/organizations/" + organization + profileUrl , QualityProfilePage.class);
+  }
+
   public BackgroundTasksPage openBackgroundTasksPage() {
     return open("/background_tasks", BackgroundTasksPage.class);
   }
diff --git a/tests/src/test/java/org/sonarqube/pageobjects/QualityProfilePage.java b/tests/src/test/java/org/sonarqube/pageobjects/QualityProfilePage.java
new file mode 100644 (file)
index 0000000..9c21c69
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2017 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.
+ */
+package org.sonarqube.pageobjects;
+
+import com.codeborne.selenide.Condition;
+
+import static com.codeborne.selenide.Selenide.$;
+import static com.codeborne.selenide.Selenide.page;
+
+public class QualityProfilePage {
+  public QualityProfilePage() {
+    $("#quality-profile").shouldBe(Condition.visible);
+  }
+
+  public QualityProfilePage shouldHaveMissingSonarWayRules(Integer nbRules) {
+    $(".quality-profile-rules-sonarway-missing")
+      .shouldBe(Condition.visible)
+      .$("a").shouldHave(Condition.text(nbRules.toString()));
+    return this;
+  }
+
+  public RulesPage showMissingSonarWayRules() {
+    $(".quality-profile-rules-sonarway-missing")
+      .shouldBe(Condition.visible).$("a").click();
+    $(".coding-rules").shouldBe(Condition.visible);
+    return page(RulesPage.class);
+  }
+}
index 35eda0b68e3da0c81c6f5a5283012b9eb1687761..0122ae842da6b124d865e43021abd64cc408cd94 100644 (file)
@@ -21,10 +21,12 @@ package org.sonarqube.pageobjects;
 
 import com.codeborne.selenide.Condition;
 import com.codeborne.selenide.ElementsCollection;
+import com.codeborne.selenide.SelenideElement;
 import java.util.List;
 import java.util.stream.Collectors;
 import org.openqa.selenium.By;
 
+import static com.codeborne.selenide.Condition.text;
 import static com.codeborne.selenide.Selenide.$;
 import static com.codeborne.selenide.Selenide.$$;
 
@@ -49,4 +51,14 @@ public class RulesPage extends Navigation {
     // warning - number is localized
     return Integer.parseInt($("#coding-rules-total").text());
   }
+
+  public ElementsCollection getSelectedFacetItems(String facetName) {
+    SelenideElement facet = $(".search-navigator-facet-box[data-property='"+ facetName+"']").shouldBe(Condition.visible);
+    return facet.$$(".js-facet.active");
+  }
+
+  public RulesPage shouldHaveTotalRules(Integer total) {
+    $("#coding-rules-total").shouldHave(text(total.toString()));
+    return this;
+  }
 }
index 1d9b9c1e42068c7df821ccbbebc016cf4c3eb913..83f63e34439c14f6933bc4f108b39a5f44db9b3c 100644 (file)
@@ -22,6 +22,8 @@ package org.sonarqube.tests.qualityProfile;
 import com.codeborne.selenide.Condition;
 import com.sonar.orchestrator.Orchestrator;
 import com.sonar.orchestrator.build.SonarScanner;
+import org.sonarqube.pageobjects.QualityProfilePage;
+import org.sonarqube.pageobjects.RulesPage;
 import org.sonarqube.tests.Category6Suite;
 import org.junit.Before;
 import org.junit.ClassRule;
@@ -30,6 +32,7 @@ import org.junit.Rule;
 import org.junit.Test;
 import org.sonarqube.tests.Tester;
 import org.sonarqube.ws.Organizations;
+import org.sonarqube.ws.QualityProfiles;
 import org.sonarqube.ws.client.PostRequest;
 import org.sonarqube.ws.client.qualityprofile.AddProjectRequest;
 import org.sonarqube.ws.client.qualityprofile.ChangeParentRequest;
@@ -137,6 +140,21 @@ public class OrganizationQualityProfilesUiTest {
     tester.runHtmlTests("/organization/OrganizationQualityProfilesUiTest/should_restore.html");
   }
 
+  @Test
+  public void testSonarWayComparison() {
+    QualityProfiles.CreateWsResponse.QualityProfile xooProfile = tester.qProfiles().createXooProfile(organization);
+    tester.qProfiles().activateRule(xooProfile, "xoo:OneBugIssuePerLine");
+    tester.qProfiles().activateRule(xooProfile, "xoo:OneIssuePerLine");
+    Navigation nav = tester.openBrowser();
+    QualityProfilePage qpPage = nav.openQualityProfile(xooProfile.getLanguage(), xooProfile.getName(), organization.getKey());
+    qpPage.shouldHaveMissingSonarWayRules(2);
+    RulesPage rPage = qpPage.showMissingSonarWayRules();
+    rPage.shouldHaveTotalRules(2);
+    rPage.getSelectedFacetItems("qprofile")
+      .shouldHaveSize(2)
+      .findBy(Condition.cssClass("compare")).has(Condition.text("Sonar way"));
+  }
+
   private void createProfile(String language, String name) {
     tester.wsClient().wsConnector().call(
       new PostRequest("api/qualityprofiles/create")