From: Grégoire Aubert Date: Mon, 4 Jun 2018 11:34:57 +0000 (+0200) Subject: SONAR-10849 Display default quality gate by default X-Git-Tag: 7.5~1088 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=20dbd44984a97b58745ddd363614c33f86339f37;p=sonarqube.git SONAR-10849 Display default quality gate by default --- diff --git a/server/sonar-qa-util/src/main/java/org/sonarqube/qa/util/pageobjects/QualityGatePage.java b/server/sonar-qa-util/src/main/java/org/sonarqube/qa/util/pageobjects/QualityGatePage.java index 88184259707..6c1ad63a38e 100644 --- a/server/sonar-qa-util/src/main/java/org/sonarqube/qa/util/pageobjects/QualityGatePage.java +++ b/server/sonar-qa-util/src/main/java/org/sonarqube/qa/util/pageobjects/QualityGatePage.java @@ -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; diff --git a/server/sonar-web/src/main/js/apps/quality-gates/components/Intro.tsx b/server/sonar-web/src/main/js/apps/quality-gates/components/Intro.tsx index ea5edc9180c..bbf59a9610d 100644 --- a/server/sonar-web/src/main/js/apps/quality-gates/components/Intro.tsx +++ b/server/sonar-web/src/main/js/apps/quality-gates/components/Intro.tsx @@ -18,17 +18,39 @@ * 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 ( -
-
-
-

{translate('quality_gates.intro.1')}

-

{translate('quality_gates.intro.2')}

+interface Props { + organization?: string; + qualityGates: QualityGate[]; + router: InjectedRouter; +} + +export default class Intro extends React.PureComponent { + 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 ( +
+
+
+

{translate('quality_gates.intro.1')}

+

{translate('quality_gates.intro.2')}

+
-
- ); + ); + } } 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 index 00000000000..c14c5adbd12 --- /dev/null +++ b/server/sonar-web/src/main/js/apps/quality-gates/components/__tests__/Intro-test.tsx @@ -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( + + ); + expect(replace).toHaveBeenCalledWith({ pathname: '/organizations/foo/quality_gates/show/1' }); +}); + +it('should display the intro', () => { + expect( + shallow() + ).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 index 00000000000..ba1263977b9 --- /dev/null +++ b/server/sonar-web/src/main/js/apps/quality-gates/components/__tests__/__snapshots__/Intro-test.tsx.snap @@ -0,0 +1,22 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`should display the intro 1`] = ` +
+
+
+

+ quality_gates.intro.1 +

+

+ quality_gates.intro.2 +

+
+
+
+`; 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 43bafe8510d..0658aadd6ea 100644 --- a/tests/src/test/java/org/sonarqube/tests/qualityGate/OrganizationQualityGateUiTest.java +++ b/tests/src/test/java/org/sonarqube/tests/qualityGate/OrganizationQualityGateUiTest.java @@ -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 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 95e2a177566..29d9f115973 100644 --- a/tests/src/test/java/org/sonarqube/tests/qualityGate/QualityGateUiTest.java +++ b/tests/src/test/java/org/sonarqube/tests/qualityGate/QualityGateUiTest.java @@ -118,7 +118,7 @@ public class QualityGateUiTest { .logIn().submitCredentials(admin) .openQualityGates() .canCreateQG() - .displayIntro(); + .displayQualityGateDetail("Sonar way"); } @Test