aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-qa-util
diff options
context:
space:
mode:
authorStas Vilchik <stas.vilchik@sonarsource.com>2018-01-29 14:21:28 +0100
committerGitHub <noreply@github.com>2018-01-29 14:21:28 +0100
commitcebce15815204aa189f63f9e1b86143b258898d2 (patch)
tree5a3a773405e86a42e29c12c3e447951052bec6e9 /server/sonar-qa-util
parentad504279d97bd55d8c191b1ffb793c6f005ffa5a (diff)
downloadsonarqube-cebce15815204aa189f63f9e1b86143b258898d2.tar.gz
sonarqube-cebce15815204aa189f63f9e1b86143b258898d2.zip
rewrite rules app with react (#2982)
Diffstat (limited to 'server/sonar-qa-util')
-rw-r--r--server/sonar-qa-util/src/main/java/org/sonarqube/qa/util/QProfileTester.java13
-rw-r--r--server/sonar-qa-util/src/main/java/org/sonarqube/qa/util/pageobjects/QualityProfilePage.java1
-rw-r--r--server/sonar-qa-util/src/main/java/org/sonarqube/qa/util/pageobjects/RuleDetails.java234
-rw-r--r--server/sonar-qa-util/src/main/java/org/sonarqube/qa/util/pageobjects/RuleItem.java19
-rw-r--r--server/sonar-qa-util/src/main/java/org/sonarqube/qa/util/pageobjects/RulesPage.java99
5 files changed, 344 insertions, 22 deletions
diff --git a/server/sonar-qa-util/src/main/java/org/sonarqube/qa/util/QProfileTester.java b/server/sonar-qa-util/src/main/java/org/sonarqube/qa/util/QProfileTester.java
index d295cbce3e2..2609faaa7c0 100644
--- a/server/sonar-qa-util/src/main/java/org/sonarqube/qa/util/QProfileTester.java
+++ b/server/sonar-qa-util/src/main/java/org/sonarqube/qa/util/QProfileTester.java
@@ -77,6 +77,19 @@ public class QProfileTester {
return this;
}
+ public QProfileTester activateRule(QualityProfile profile, String ruleKey, String severity) {
+ return activateRule(profile.getKey(), ruleKey, severity);
+ }
+
+ public QProfileTester activateRule(String profileKey, String ruleKey, String severity) {
+ ActivateRuleRequest request = new ActivateRuleRequest()
+ .setKey(profileKey)
+ .setRule(ruleKey)
+ .setSeverity(severity);
+ service().activateRule(request);
+ return this;
+ }
+
public QProfileTester deactivateRule(QualityProfile profile, String ruleKey) {
service().deactivateRule(new DeactivateRuleRequest().setKey(profile.getKey()).setRule(ruleKey));
return this;
diff --git a/server/sonar-qa-util/src/main/java/org/sonarqube/qa/util/pageobjects/QualityProfilePage.java b/server/sonar-qa-util/src/main/java/org/sonarqube/qa/util/pageobjects/QualityProfilePage.java
index 1366b7f9aa3..9dbb657f824 100644
--- a/server/sonar-qa-util/src/main/java/org/sonarqube/qa/util/pageobjects/QualityProfilePage.java
+++ b/server/sonar-qa-util/src/main/java/org/sonarqube/qa/util/pageobjects/QualityProfilePage.java
@@ -37,7 +37,6 @@ public class QualityProfilePage {
public RulesPage showMissingSonarWayRules() {
Selenide.$(".quality-profile-rules-sonarway-missing")
.shouldBe(Condition.visible).$("a").click();
- Selenide.$(".coding-rules").shouldBe(Condition.visible);
return Selenide.page(RulesPage.class);
}
diff --git a/server/sonar-qa-util/src/main/java/org/sonarqube/qa/util/pageobjects/RuleDetails.java b/server/sonar-qa-util/src/main/java/org/sonarqube/qa/util/pageobjects/RuleDetails.java
index bbf79fc50c8..75bfe6ccb0c 100644
--- a/server/sonar-qa-util/src/main/java/org/sonarqube/qa/util/pageobjects/RuleDetails.java
+++ b/server/sonar-qa-util/src/main/java/org/sonarqube/qa/util/pageobjects/RuleDetails.java
@@ -19,15 +19,243 @@
*/
package org.sonarqube.qa.util.pageobjects;
-import com.codeborne.selenide.Selenide;
+import com.codeborne.selenide.Condition;
+import com.codeborne.selenide.SelenideElement;
+import java.util.Locale;
import static com.codeborne.selenide.Condition.text;
+import static com.codeborne.selenide.Condition.visible;
+import static com.codeborne.selenide.Selenide.$;
public class RuleDetails {
+ RuleDetails() {
+ $(".coding-rule-details").shouldBe(visible);
+ }
+
+ public RuleDetails shouldHaveType(String type) {
+ $(".coding-rules-detail-property[data-meta=\"type\"]").shouldHave(text(type));
+ return this;
+ }
+
+ public RuleDetails shouldHaveSeverity(String severity) {
+ $(".coding-rules-detail-property[data-meta=\"severity\"]").shouldHave(text(severity));
+ return this;
+ }
+
+ public RuleDetails shouldHaveDescription(String description) {
+ $(".js-rule-description").shouldHave(text(description));
+ return this;
+ }
+
+ public RuleDetails shouldBeActivatedOn(String profileKey) {
+ $("#coding-rules-detail-quality-profiles [data-profile=\"" + profileKey + "\"]").shouldBe(visible);
+ return this;
+ }
+
+ public RuleDetails shouldNotBeActivatedOn(String profileName) {
+ $("#coding-rules-detail-quality-profiles").shouldNotHave(text(profileName));
+ return this;
+ }
+
+ public RuleDetails shouldHaveTotalIssues(int issues) {
+ $(".js-rule-issues h3").shouldHave(text(String.valueOf(issues)));
+ return this;
+ }
+
+ public RuleDetails shouldHaveIssuesOnProject(String projectName, int issues) {
+ $(".coding-rules-most-violated-projects").shouldHave(
+ Condition.and("", text(projectName), text(String.valueOf(issues))));
+ return this;
+ }
+
+ public RuleDetails shouldHaveCustomRule(String ruleKey) {
+ takeCustomRule(ruleKey).shouldBe(visible);
+ return this;
+ }
+
+ public RuleDetails shouldNotHaveCustomRule(String ruleKey) {
+ takeCustomRule(ruleKey).shouldNotBe(visible);
+ return this;
+ }
+
+ public RuleDetails createCustomRule(String ruleName) {
+ $(".js-create-custom-rule").click();
+ modal().shouldBe(visible);
+
+ $("#coding-rules-custom-rule-creation-name").val(ruleName);
+ $("#coding-rules-custom-rule-creation-html-description").val("description");
+ $("#coding-rules-custom-rule-creation-create").click();
+
+ modal().shouldNotBe(visible);
+ return this;
+ }
+
+ public RuleDetails reactivateCustomRule(String ruleName) {
+ $(".js-create-custom-rule").click();
+ modal().shouldBe(visible);
+
+ $("#coding-rules-custom-rule-creation-name").val(ruleName);
+ $("#coding-rules-custom-rule-creation-html-description").val("description");
+ $("#coding-rules-custom-rule-creation-create").click();
+
+ modal().find(".alert-warning").shouldBe(visible);
+ $("#coding-rules-custom-rule-creation-reactivate").click();
+
+ modal().shouldNotBe(visible);
+ return this;
+ }
+
+ public RuleDetails deleteCustomRule(String ruleKey) {
+ takeCustomRule(ruleKey).$(".js-delete-custom-rule").click();
+ modal().shouldBe(visible);
+ modal().find("button").click();
+ modal().shouldNotBe(visible);
+ return this;
+ }
+
+ public RuleActivation activate() {
+ $("#coding-rules-quality-profile-activate").click();
+ modal().shouldBe(visible);
+ return new RuleActivation();
+ }
+
+ private static SelenideElement modal() {
+ return $(".modal");
+ }
+
+ private static SelenideElement takeCustomRule(String ruleKey) {
+ return $("#coding-rules-detail-custom-rules tr[data-rule=\"" + ruleKey + "\"]");
+ }
+
+ private static SelenideElement getActiveProfileElement(String profileKey) {
+ return $("#coding-rules-detail-quality-profiles [data-profile=\"" + profileKey + "\"]");
+ }
+
+ public ExtendedDescription extendDescription() {
+ return new ExtendedDescription().start();
+ }
+
+ public Tags tags() {
+ return new Tags();
+ }
+
+ public RuleActivation changeActivationOn(String profileKey) {
+ getActiveProfileElement(profileKey).$(".coding-rules-detail-quality-profile-change").click();
+ modal().shouldBe(visible);
+ return new RuleActivation();
+ }
+
+ public RuleDetails activationShouldHaveParameter(String profileKey, String parameter, String value) {
+ getActiveProfileElement(profileKey).$$(".coding-rules-detail-quality-profile-parameter")
+ .findBy(Condition.and("", text(parameter), text(value)))
+ .shouldBe(visible);
+ return this;
+ }
+
+ public RuleDetails activationShouldHaveSeverity(String profileKey, String severity) {
+ getActiveProfileElement(profileKey).$(".coding-rules-detail-quality-profile-severity .icon-severity-" + severity.toLowerCase(Locale.ENGLISH)).shouldBe(visible);
+ return this;
+ }
- public RuleDetails shouldBeActivatedOn(String profileName) {
- Selenide.$("#coding-rules-detail-quality-profiles").shouldHave(text(profileName));
+ public RuleDetails revertActivationToParentDefinition(String profileKey) {
+ getActiveProfileElement(profileKey).$(".coding-rules-detail-quality-profile-revert").click();
+ modal().shouldBe(visible);
+ $(".modal button").click();
+ modal().shouldNotBe(visible);
return this;
}
+ public static class ExtendedDescription {
+ public ExtendedDescription start() {
+ $("#coding-rules-detail-extend-description").click();
+ textArea().shouldBe(visible);
+ return this;
+ }
+
+ public ExtendedDescription cancel() {
+ $("#coding-rules-detail-extend-description-cancel").click();
+ textArea().shouldNotBe(visible);
+ return this;
+ }
+
+ public ExtendedDescription type(String text) {
+ textArea().val(text);
+ return this;
+ }
+
+ public ExtendedDescription submit() {
+ $("#coding-rules-detail-extend-description-submit").click();
+ textArea().shouldNotBe(visible);
+ return this;
+ }
+
+ public ExtendedDescription remove() {
+ $("#coding-rules-detail-extend-description-remove").click();
+ modal().shouldBe(visible);
+ $("#coding-rules-detail-extend-description-remove-submit").click();
+ modal().shouldNotBe(visible);
+ textArea().shouldNotBe(visible);
+ return this;
+ }
+
+ private static SelenideElement textArea() {
+ return $("#coding-rules-detail-extend-description-text");
+ }
+ }
+
+ public static class Tags {
+ public Tags shouldHaveNoTags() {
+ element().shouldHave(text("No tags"));
+ return this;
+ }
+
+ public Tags shouldHaveTags(String... tags) {
+ for (String tag : tags) {
+ element().shouldHave(text(tag));
+ }
+ return this;
+ }
+
+ public Tags edit() {
+ element().$("button").click();
+ return this;
+ }
+
+ public Tags select(String tag) {
+ element().$$(".menu a").findBy(text(tag)).click();
+ return this;
+ }
+
+ public Tags search(String query) {
+ element().$(".search-box-input").val(query);
+ return this;
+ }
+
+ public Tags done() {
+ element().$(".search-box-input").pressEscape();
+ return this;
+ }
+
+ private static SelenideElement element() {
+ return $(".coding-rules-detail-property[data-meta=\"tags\"]");
+ }
+ }
+
+ public static class RuleActivation {
+ public RuleActivation select(String profileKey) {
+ $(".modal .js-profile .Select-input input").val(profileKey).pressEnter();
+ return this;
+ }
+
+ public RuleActivation fill(String parameter, String value) {
+ $(".modal-field input[name=\"" + parameter + "\"]").val(value);
+ return this;
+ }
+
+ public RuleActivation save() {
+ $(".modal button").click();
+ modal().shouldNotBe(visible);
+ return this;
+ }
+ }
}
diff --git a/server/sonar-qa-util/src/main/java/org/sonarqube/qa/util/pageobjects/RuleItem.java b/server/sonar-qa-util/src/main/java/org/sonarqube/qa/util/pageobjects/RuleItem.java
index 4084ba9815c..a61a371ebde 100644
--- a/server/sonar-qa-util/src/main/java/org/sonarqube/qa/util/pageobjects/RuleItem.java
+++ b/server/sonar-qa-util/src/main/java/org/sonarqube/qa/util/pageobjects/RuleItem.java
@@ -21,21 +21,30 @@ package org.sonarqube.qa.util.pageobjects;
import com.codeborne.selenide.SelenideElement;
+import static com.codeborne.selenide.Condition.visible;
+
public class RuleItem {
private final SelenideElement elt;
- public RuleItem(SelenideElement elt) {
+ RuleItem(SelenideElement elt) {
this.elt = elt;
}
- public SelenideElement getTitle() {
- return elt.$(".coding-rule-title");
+ public RuleItem filterSimilarRules(String field) {
+ elt.$(".js-rule-filter").click();
+ elt.$(".dropdown-menu a[data-field=\"" + field + "\"]").click();
+ return this;
}
- public SelenideElement getMetadata() {
- return elt.$(".coding-rule-meta");
+ public RuleDetails open() {
+ elt.$(".coding-rule-title a").click();
+ return new RuleDetails();
}
+ public RuleItem shouldDisplayDeactivate() {
+ elt.$(".coding-rules-detail-quality-profile-deactivate").shouldBe(visible);
+ return this;
+ }
}
diff --git a/server/sonar-qa-util/src/main/java/org/sonarqube/qa/util/pageobjects/RulesPage.java b/server/sonar-qa-util/src/main/java/org/sonarqube/qa/util/pageobjects/RulesPage.java
index 77b82e33060..1e4e0605bf6 100644
--- a/server/sonar-qa-util/src/main/java/org/sonarqube/qa/util/pageobjects/RulesPage.java
+++ b/server/sonar-qa-util/src/main/java/org/sonarqube/qa/util/pageobjects/RulesPage.java
@@ -21,46 +21,119 @@ package org.sonarqube.qa.util.pageobjects;
import com.codeborne.selenide.Condition;
import com.codeborne.selenide.ElementsCollection;
-import com.codeborne.selenide.Selenide;
import com.codeborne.selenide.SelenideElement;
-import org.openqa.selenium.By;
+
+import static com.codeborne.selenide.Condition.exist;
+import static com.codeborne.selenide.Condition.visible;
+import static com.codeborne.selenide.Selenide.$;
+import static com.codeborne.selenide.Selenide.$$;
public class RulesPage extends Navigation {
public RulesPage() {
- Selenide.$(By.cssSelector(".coding-rules")).should(Condition.exist);
+ $("#coding-rules-page").should(exist);
}
public int getTotal() {
// warning - number is localized
- return Integer.parseInt(Selenide.$("#coding-rules-total").text());
+ return Integer.parseInt($("#coding-rules-total").text());
}
public ElementsCollection getSelectedFacetItems(String facetName) {
- SelenideElement facet = Selenide.$(".search-navigator-facet-box[data-property='"+ facetName+"']").shouldBe(Condition.visible);
- return facet.$$(".js-facet.active");
+ return getFacetElement(facetName).$$(".facet.active");
}
public RulesPage shouldHaveTotalRules(Integer total) {
- Selenide.$("#coding-rules-total").shouldHave(Condition.text(total.toString()));
+ $(".js-page-counter-total").shouldHave(Condition.text(total.toString()));
+ return this;
+ }
+
+ public RulesPage shouldDisplayRules(String... ruleKeys) {
+ for (String key : ruleKeys) {
+ getRuleElement(key).shouldBe(visible);
+ }
+ return this;
+ }
+
+ public RulesPage shouldNotDisplayRules(String... ruleKeys) {
+ for (String key : ruleKeys) {
+ getRuleElement(key).shouldNotBe(visible);
+ }
return this;
}
public RulesPage openFacet(String facet) {
- Selenide.$(".search-navigator-facet-box[data-property=\"" + facet + "\"] .js-facet-toggle").click();
+ getFacetElement(facet).$(".search-navigator-facet-header a").click();
+ return this;
+ }
+
+ public RulesPage selectFacetItem(String facet, String value) {
+ getFacetElement(facet).$(".facet[data-facet=\"" + value + "\"]").click();
return this;
}
- public RulesPage selectFacetItemByText(String facet, String itemText) {
- Selenide.$$(".search-navigator-facet-box[data-property=\"" + facet + "\"] .js-facet")
- .findBy(Condition.text(itemText)).click();
+ public RulesPage selectInactive() {
+ getFacetElement("profile").$(".active .js-inactive").click();
+ return this;
+ }
+
+ public RulesPage shouldHaveDisabledFacet(String facet) {
+ $(".search-navigator-facet-box-forbidden[data-property=\"" + facet + "\"]").shouldBe(visible);
+ return this;
+ }
+
+ public RulesPage shouldNotHaveDisabledFacet(String facet) {
+ $(".search-navigator-facet-box-forbidden[data-property=\"" + facet + "\"]").shouldNotBe(visible);
return this;
}
public RuleDetails openFirstRule() {
- Selenide.$$(".js-rule").first().click();
- Selenide.$(".coding-rules-details").shouldBe(Condition.visible);
+ $$(".coding-rule-title a").first().click();
return new RuleDetails();
}
+ public RuleItem takeRule(String ruleKey) {
+ return new RuleItem(getRuleElement(ruleKey));
+ }
+
+ public RulesPage search(String query) {
+ $("#coding-rules-search .search-box-input").val(query);
+ return this;
+ }
+
+ public RulesPage clearAllFilters() {
+ $("#coding-rules-clear-all-filters").click();
+ return this;
+ }
+
+ public RulesPage closeDetails() {
+ $(".js-back").click();
+ $(".coding-rule-details").shouldNotBe(visible);
+ return this;
+ }
+
+ public RulesPage activateRule(String ruleKey) {
+ getRuleElement(ruleKey).$(".coding-rules-detail-quality-profile-activate").click();
+ $(".modal").shouldBe(visible);
+ $(".modal button").click();
+ $(".modal").shouldNotBe(visible);
+ getRuleElement(ruleKey).$(".coding-rules-detail-quality-profile-activate").shouldNotBe(visible);
+ return this;
+ }
+
+ public RulesPage deactivateRule(String ruleKey) {
+ getRuleElement(ruleKey).$(".coding-rules-detail-quality-profile-deactivate").click();
+ $(".modal button").click();
+ getRuleElement(ruleKey).$(".coding-rules-detail-quality-profile-deactivate").shouldNotBe(visible);
+ return this;
+ }
+
+ private static SelenideElement getRuleElement(String key) {
+ return $(".coding-rule[data-rule=\"" + key + "\"]");
+ }
+
+ private static SelenideElement getFacetElement(String facet) {
+ return $(".search-navigator-facet-box[data-property=\"" + facet + "\"]");
+ }
+
}