From fe58d75d14ca6bc0005c6110a32d648ffdd361d1 Mon Sep 17 00:00:00 2001 From: Mathieu Suen Date: Thu, 30 Sep 2021 16:57:18 +0200 Subject: SONAR-15458 Add SonarLint promotion for failed Quality Gate --- .../js/apps/overview/branches/QualityGatePanel.tsx | 5 + .../overview/branches/QualityGatePanelSection.tsx | 2 +- .../__snapshots__/QualityGatePanel-test.tsx.snap | 165 +++++++++++++++++++++ .../QualityGatePanelSection-test.tsx.snap | 8 +- .../overview/components/SonarLintPromotion.tsx | 79 ++++++++++ .../__tests__/SonarLintPromition-test.tsx | 63 ++++++++ .../__snapshots__/SonarLintPromition-test.tsx.snap | 28 ++++ .../overview/pullRequests/PullRequestOverview.tsx | 3 + .../PullRequestOverview-test.tsx.snap | 25 ++++ .../sonar-web/src/main/js/apps/overview/styles.css | 9 ++ .../src/main/js/components/icons/SonarLintIcon.tsx | 42 ++++++ server/sonar-web/src/main/js/types/types.d.ts | 1 + 12 files changed, 425 insertions(+), 5 deletions(-) create mode 100644 server/sonar-web/src/main/js/apps/overview/components/SonarLintPromotion.tsx create mode 100644 server/sonar-web/src/main/js/apps/overview/components/__tests__/SonarLintPromition-test.tsx create mode 100644 server/sonar-web/src/main/js/apps/overview/components/__tests__/__snapshots__/SonarLintPromition-test.tsx.snap create mode 100644 server/sonar-web/src/main/js/components/icons/SonarLintIcon.tsx (limited to 'server/sonar-web/src/main/js') diff --git a/server/sonar-web/src/main/js/apps/overview/branches/QualityGatePanel.tsx b/server/sonar-web/src/main/js/apps/overview/branches/QualityGatePanel.tsx index 161e1c686eb..2954827ba40 100644 --- a/server/sonar-web/src/main/js/apps/overview/branches/QualityGatePanel.tsx +++ b/server/sonar-web/src/main/js/apps/overview/branches/QualityGatePanel.tsx @@ -18,12 +18,14 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ import classNames from 'classnames'; +import { flatMap } from 'lodash'; import * as React from 'react'; import HelpTooltip from '../../../components/controls/HelpTooltip'; import { Alert } from '../../../components/ui/Alert'; import DeferredSpinner from '../../../components/ui/DeferredSpinner'; import { translate, translateWithParameters } from '../../../helpers/l10n'; import { QualityGateStatus } from '../../../types/quality-gates'; +import SonarLintPromotion from '../components/SonarLintPromotion'; import QualityGatePanelSection from './QualityGatePanelSection'; export interface QualityGatePanelProps { @@ -116,6 +118,9 @@ export function QualityGatePanel(props: QualityGatePanelProps) { )} + qgStatus.failedConditions)} + /> ); } diff --git a/server/sonar-web/src/main/js/apps/overview/branches/QualityGatePanelSection.tsx b/server/sonar-web/src/main/js/apps/overview/branches/QualityGatePanelSection.tsx index 5a557597687..3470d679423 100644 --- a/server/sonar-web/src/main/js/apps/overview/branches/QualityGatePanelSection.tsx +++ b/server/sonar-web/src/main/js/apps/overview/branches/QualityGatePanelSection.tsx @@ -23,7 +23,7 @@ import { isDiffMetric } from '../../../helpers/measures'; import { BranchLike } from '../../../types/branch-like'; import { ComponentQualifier } from '../../../types/component'; import { QualityGateStatus } from '../../../types/quality-gates'; -import { QualityGateConditions } from '../components/QualityGateConditions'; +import QualityGateConditions from '../components/QualityGateConditions'; export interface QualityGatePanelSectionProps { branchLike?: BranchLike; diff --git a/server/sonar-web/src/main/js/apps/overview/branches/__tests__/__snapshots__/QualityGatePanel-test.tsx.snap b/server/sonar-web/src/main/js/apps/overview/branches/__tests__/__snapshots__/QualityGatePanel-test.tsx.snap index 580ccebe664..4c5d74724c9 100644 --- a/server/sonar-web/src/main/js/apps/overview/branches/__tests__/__snapshots__/QualityGatePanel-test.tsx.snap +++ b/server/sonar-web/src/main/js/apps/overview/branches/__tests__/__snapshots__/QualityGatePanel-test.tsx.snap @@ -182,6 +182,81 @@ exports[`should render correctly for applications 1`] = ` /> + `; @@ -320,6 +395,35 @@ exports[`should render correctly for applications 2`] = ` /> + `; @@ -424,6 +528,35 @@ exports[`should render correctly for projects 1`] = ` /> + `; @@ -466,6 +599,9 @@ exports[`should render correctly for projects 2`] = ` + `; @@ -585,5 +721,34 @@ exports[`should render correctly for projects 3`] = ` /> + `; diff --git a/server/sonar-web/src/main/js/apps/overview/branches/__tests__/__snapshots__/QualityGatePanelSection-test.tsx.snap b/server/sonar-web/src/main/js/apps/overview/branches/__tests__/__snapshots__/QualityGatePanelSection-test.tsx.snap index 99121173ca4..84bd6cb3285 100644 --- a/server/sonar-web/src/main/js/apps/overview/branches/__tests__/__snapshots__/QualityGatePanelSection-test.tsx.snap +++ b/server/sonar-web/src/main/js/apps/overview/branches/__tests__/__snapshots__/QualityGatePanelSection-test.tsx.snap @@ -9,7 +9,7 @@ exports[`should render correctly 1`] = ` > quality_gates.conditions.new_code - quality_gates.conditions.overall_code - quality_gates.conditions.new_code - quality_gates.conditions.overall_code - + CONDITIONS_TO_SHOW.includes(qgCondition.metric as MetricKey) && qgCondition.level === 'ERROR' + ); + if (!showMessage || currentUser.usingSonarLintConnectedMode) { + return null; + } + return ( +
+ + + SonarLint + + + + ) + }} + /> +
+ ); +} + +export default withCurrentUser(SonarLintPromotion); diff --git a/server/sonar-web/src/main/js/apps/overview/components/__tests__/SonarLintPromition-test.tsx b/server/sonar-web/src/main/js/apps/overview/components/__tests__/SonarLintPromition-test.tsx new file mode 100644 index 00000000000..261794c900a --- /dev/null +++ b/server/sonar-web/src/main/js/apps/overview/components/__tests__/SonarLintPromition-test.tsx @@ -0,0 +1,63 @@ +/* + * SonarQube + * Copyright (C) 2009-2021 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 { shallow } from 'enzyme'; +import * as React from 'react'; +import { mockQualityGateStatusCondition } from '../../../../helpers/mocks/quality-gates'; +import { mockCurrentUser } from '../../../../helpers/testMocks'; +import { MetricKey } from '../../../../types/metrics'; +import { SonarLintPromotion, SonarLintPromotionProps } from '../SonarLintPromotion'; + +it('should render correctly', () => { + expect(shallowRender().type()).toBeNull(); + expect( + shallowRender({ currentUser: mockCurrentUser({ usingSonarLintConnectedMode: true }) }).type() + ).toBeNull(); + expect( + shallowRender({ + qgConditions: [mockQualityGateStatusCondition({ metric: MetricKey.new_bugs, level: 'ERROR' })] + }) + ).toMatchSnapshot('has failed condition'); +}); + +it.each( + [ + MetricKey.new_blocker_violations, + MetricKey.new_critical_violations, + MetricKey.new_info_violations, + MetricKey.new_violations, + MetricKey.new_major_violations, + MetricKey.new_minor_violations, + MetricKey.new_code_smells, + MetricKey.new_bugs, + MetricKey.new_vulnerabilities, + MetricKey.new_security_rating, + MetricKey.new_maintainability_rating, + MetricKey.new_reliability_rating + ].map(Array.of) +)('should show message for %s', metric => { + const wrapper = shallowRender({ + qgConditions: [mockQualityGateStatusCondition({ metric: metric as string })] + }); + expect(wrapper.type()).not.toBeNull(); +}); + +function shallowRender(props: Partial = {}) { + return shallow(); +} diff --git a/server/sonar-web/src/main/js/apps/overview/components/__tests__/__snapshots__/SonarLintPromition-test.tsx.snap b/server/sonar-web/src/main/js/apps/overview/components/__tests__/__snapshots__/SonarLintPromition-test.tsx.snap new file mode 100644 index 00000000000..e0d43e8cda1 --- /dev/null +++ b/server/sonar-web/src/main/js/apps/overview/components/__tests__/__snapshots__/SonarLintPromition-test.tsx.snap @@ -0,0 +1,28 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`should render correctly: has failed condition 1`] = ` +
+ + + SonarLint + + + , + } + } + /> +
+`; diff --git a/server/sonar-web/src/main/js/apps/overview/pullRequests/PullRequestOverview.tsx b/server/sonar-web/src/main/js/apps/overview/pullRequests/PullRequestOverview.tsx index 8c542df49e1..d6a0cdcb7ef 100644 --- a/server/sonar-web/src/main/js/apps/overview/pullRequests/PullRequestOverview.tsx +++ b/server/sonar-web/src/main/js/apps/overview/pullRequests/PullRequestOverview.tsx @@ -37,6 +37,7 @@ import IssueLabel from '../components/IssueLabel'; import IssueRating from '../components/IssueRating'; import MeasurementLabel from '../components/MeasurementLabel'; import QualityGateConditions from '../components/QualityGateConditions'; +import SonarLintPromotion from '../components/SonarLintPromotion'; import '../styles.css'; import { MeasurementType, PR_METRICS } from '../utils'; import AfterMergeEstimate from './AfterMergeEstimate'; @@ -197,6 +198,8 @@ export class PullRequestOverview extends React.PureComponent { /> + + {failedConditions.length > 0 && ( diff --git a/server/sonar-web/src/main/js/apps/overview/pullRequests/__tests__/__snapshots__/PullRequestOverview-test.tsx.snap b/server/sonar-web/src/main/js/apps/overview/pullRequests/__tests__/__snapshots__/PullRequestOverview-test.tsx.snap index 8af79d11f7e..c3348c42010 100644 --- a/server/sonar-web/src/main/js/apps/overview/pullRequests/__tests__/__snapshots__/PullRequestOverview-test.tsx.snap +++ b/server/sonar-web/src/main/js/apps/overview/pullRequests/__tests__/__snapshots__/PullRequestOverview-test.tsx.snap @@ -53,6 +53,28 @@ exports[`should render correctly for a failed QG 1`] = ` } level="ERROR" /> +
+
+ + + + + + + + + + ); +} diff --git a/server/sonar-web/src/main/js/types/types.d.ts b/server/sonar-web/src/main/js/types/types.d.ts index 9391ec3b94b..8173bca1ff1 100644 --- a/server/sonar-web/src/main/js/types/types.d.ts +++ b/server/sonar-web/src/main/js/types/types.d.ts @@ -218,6 +218,7 @@ declare namespace T { export interface CurrentUser { isLoggedIn: boolean; permissions?: { global: string[] }; + usingSonarLintConnectedMode?: boolean; } export interface CurrentUserSetting { -- cgit v1.2.3