From 935ecc809124f311ecb17ee42ae82896b5028293 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Gr=C3=A9goire=20Aubert?= Date: Mon, 24 Jul 2017 14:13:34 +0200 Subject: [PATCH] SONAR-9565 Display quality gate directly if there is only one and the user can't edit --- .../components/QualityGatesApp.js | 16 ++++++++++----- .../pageobjects/ProjectDashboardPage.java | 5 +++-- .../pageobjects/QualityGatePage.java | 14 +++++++++++-- .../sonarqube/tests/OrganizationTester.java | 7 +++++++ .../OrganizationQualityGateUiTest.java | 20 +++++++++++++++---- .../tests/qualityGate/QualityGateUiTest.java | 13 ++++++++---- 6 files changed, 58 insertions(+), 17 deletions(-) diff --git a/server/sonar-web/src/main/js/apps/quality-gates/components/QualityGatesApp.js b/server/sonar-web/src/main/js/apps/quality-gates/components/QualityGatesApp.js index 3ac0da688cc..e197e6f0f83 100644 --- a/server/sonar-web/src/main/js/apps/quality-gates/components/QualityGatesApp.js +++ b/server/sonar-web/src/main/js/apps/quality-gates/components/QualityGatesApp.js @@ -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 ( -
+
diff --git a/tests/src/test/java/org/sonarqube/pageobjects/ProjectDashboardPage.java b/tests/src/test/java/org/sonarqube/pageobjects/ProjectDashboardPage.java index 673e037c193..f1d150e2c16 100644 --- a/tests/src/test/java/org/sonarqube/pageobjects/ProjectDashboardPage.java +++ b/tests/src/test/java/org/sonarqube/pageobjects/ProjectDashboardPage.java @@ -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; } diff --git a/tests/src/test/java/org/sonarqube/pageobjects/QualityGatePage.java b/tests/src/test/java/org/sonarqube/pageobjects/QualityGatePage.java index 3d7162f898d..4133bbfeb92 100644 --- a/tests/src/test/java/org/sonarqube/pageobjects/QualityGatePage.java +++ b/tests/src/test/java/org/sonarqube/pageobjects/QualityGatePage.java @@ -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; + } } diff --git a/tests/src/test/java/org/sonarqube/tests/OrganizationTester.java b/tests/src/test/java/org/sonarqube/tests/OrganizationTester.java index 2072e87822a..5550cd527c5 100644 --- a/tests/src/test/java/org/sonarqube/tests/OrganizationTester.java +++ b/tests/src/test/java/org/sonarqube/tests/OrganizationTester.java @@ -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); diff --git a/tests/src/test/java/org/sonarqube/tests/qualityGate/OrganizationQualityGateUiTest.java b/tests/src/test/java/org/sonarqube/tests/qualityGate/OrganizationQualityGateUiTest.java index 01ab1189d87..fc846cb244f 100644 --- a/tests/src/test/java/org/sonarqube/tests/qualityGate/OrganizationQualityGateUiTest.java +++ b/tests/src/test/java/org/sonarqube/tests/qualityGate/OrganizationQualityGateUiTest.java @@ -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"); + } } diff --git a/tests/src/test/java/org/sonarqube/tests/qualityGate/QualityGateUiTest.java b/tests/src/test/java/org/sonarqube/tests/qualityGate/QualityGateUiTest.java index acb207f5271..59fd4cbe738 100644 --- a/tests/src/test/java/org/sonarqube/tests/qualityGate/QualityGateUiTest.java +++ b/tests/src/test/java/org/sonarqube/tests/qualityGate/QualityGateUiTest.java @@ -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) { -- 2.39.5