From: Wouter Admiraal Date: Mon, 11 Feb 2019 07:50:45 +0000 (+0100) Subject: SONAR-11700 Show QG badge instead of issue breakdown for PRs and SLBs X-Git-Tag: 7.7~81 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=09d4e61cd5c314c00fc6dddb6dbc08c2425d0cf3;p=sonarqube.git SONAR-11700 Show QG badge instead of issue breakdown for PRs and SLBs --- diff --git a/server/sonar-web/src/main/js/app/components/ComponentContainer.tsx b/server/sonar-web/src/main/js/app/components/ComponentContainer.tsx index 2defb5847f9..86b953bf60e 100644 --- a/server/sonar-web/src/main/js/app/components/ComponentContainer.tsx +++ b/server/sonar-web/src/main/js/app/components/ComponentContainer.tsx @@ -26,7 +26,6 @@ import ComponentNav from './nav/component/ComponentNav'; import { getBranches, getPullRequests } from '../../api/branches'; import { getTasksForComponent, getAnalysisStatus } from '../../api/ce'; import { getComponentData } from '../../api/components'; -import { getMeasures } from '../../api/measures'; import { getComponentNavigation } from '../../api/nav'; import { fetchOrganization, requireAuthorization } from '../../store/rootActions'; import { STATUSES } from '../../apps/background-tasks/constants'; @@ -52,7 +51,6 @@ interface Props { interface State { branchLike?: T.BranchLike; branchLikes: T.BranchLike[]; - branchMeasures?: T.Measure[]; component?: T.Component; currentTask?: T.Task; isPending: boolean; @@ -120,13 +118,11 @@ export class ComponentContainer extends React.PureComponent { return component; }) .then(this.fetchBranches) - .then(this.fetchBranchMeasures) - .then(({ branchLike, branchLikes, component, branchMeasures }) => { + .then(({ branchLike, branchLikes, component }) => { if (this.mounted) { this.setState({ branchLike, branchLikes, - branchMeasures, component, loading: false }); @@ -168,33 +164,6 @@ export class ComponentContainer extends React.PureComponent { return Promise.resolve({ branchLikes: [], component }); }; - fetchBranchMeasures = ({ - branchLike, - branchLikes, - component - }: { - branchLike: T.BranchLike; - branchLikes: T.BranchLike[]; - component: T.Component; - }): Promise<{ - branchLike?: T.BranchLike; - branchLikes: T.BranchLike[]; - branchMeasures?: T.Measure[]; - component: T.Component; - }> => { - const project = component.breadcrumbs.find(({ qualifier }) => qualifier === 'TRK'); - if (project && (isShortLivingBranch(branchLike) || isPullRequest(branchLike))) { - return getMeasures({ - component: project.key, - metricKeys: 'new_coverage,new_duplicated_lines_density', - ...getBranchLikeQuery(branchLike) - }).then(measures => { - return { branchLike, branchLikes, branchMeasures: measures, component }; - }); - } - return Promise.resolve({ branchLike, branchLikes, component }); - }; - fetchStatus = (component: T.Component) => { getTasksForComponent(component.key).then( ({ current, queue }) => { @@ -312,16 +281,14 @@ export class ComponentContainer extends React.PureComponent { handleBranchesChange = () => { if (this.mounted && this.state.component) { - this.fetchBranches(this.state.component) - .then(this.fetchBranchMeasures) - .then( - ({ branchLike, branchLikes, branchMeasures }) => { - if (this.mounted) { - this.setState({ branchLike, branchLikes, branchMeasures }); - } - }, - () => {} - ); + this.fetchBranches(this.state.component).then( + ({ branchLike, branchLikes }) => { + if (this.mounted) { + this.setState({ branchLike, branchLikes }); + } + }, + () => {} + ); } }; @@ -341,7 +308,6 @@ export class ComponentContainer extends React.PureComponent { !['FIL', 'UTS'].includes(component.qualifier) && ( { expect(getPullRequests).toBeCalledWith('projectKey'); }); -it('updates the branch measures', async () => { - (getComponentNavigation as jest.Mock).mockResolvedValueOnce({ - breadcrumbs: [{ key: 'foo', name: 'Foo', qualifier: 'TRK' }], - key: 'foo' - }); - (getBranches as jest.Mock).mockResolvedValueOnce([ - { isMain: false, mergeBranch: 'master', name: 'feature', type: 'SHORT' } - ]); - (getPullRequests as jest.Mock).mockResolvedValueOnce([]); - const wrapper = shallowRender({ - location: { query: { id: 'foo', branch: 'feature' } } as Location - }); - wrapper.setState({ - branchLikes: [mainBranch], - component: { breadcrumbs: [{ key: 'foo', name: 'Foo', qualifier: 'TRK' }] } as T.Component, - loading: false - }); - - await new Promise(setImmediate); - expect(getBranches).toBeCalledWith('foo'); - - await new Promise(setImmediate); - expect(getMeasures).toBeCalledWith({ - component: 'foo', - metricKeys: 'new_coverage,new_duplicated_lines_density', - branch: 'feature' - }); -}); - it('loads organization', async () => { (isSonarCloud as jest.Mock).mockReturnValue(true); (getComponentData as jest.Mock).mockResolvedValueOnce({ organization: 'org' }); diff --git a/server/sonar-web/src/main/js/app/components/nav/component/ComponentNav.tsx b/server/sonar-web/src/main/js/app/components/nav/component/ComponentNav.tsx index ccc74f892f7..02e9d6a01de 100644 --- a/server/sonar-web/src/main/js/app/components/nav/component/ComponentNav.tsx +++ b/server/sonar-web/src/main/js/app/components/nav/component/ComponentNav.tsx @@ -30,7 +30,6 @@ import './ComponentNav.css'; interface Props { branchLikes: T.BranchLike[]; - branchMeasures?: T.Measure[]; currentBranchLike: T.BranchLike | undefined; component: T.Component; currentTask?: T.Task; @@ -96,7 +95,6 @@ export default class ComponentNav extends React.PureComponent { /> diff --git a/server/sonar-web/src/main/js/app/components/nav/component/ComponentNavBranchesMenuItem.tsx b/server/sonar-web/src/main/js/app/components/nav/component/ComponentNavBranchesMenuItem.tsx index 1c340a7d071..f05afbd4bfe 100644 --- a/server/sonar-web/src/main/js/app/components/nav/component/ComponentNavBranchesMenuItem.tsx +++ b/server/sonar-web/src/main/js/app/components/nav/component/ComponentNavBranchesMenuItem.tsx @@ -69,7 +69,7 @@ export default function ComponentNavBranchesMenuItem({ branchLike, ...props }: P )}
- +
diff --git a/server/sonar-web/src/main/js/app/components/nav/component/ComponentNavMeta.tsx b/server/sonar-web/src/main/js/app/components/nav/component/ComponentNavMeta.tsx index f2d056453d9..9eb4704aa43 100644 --- a/server/sonar-web/src/main/js/app/components/nav/component/ComponentNavMeta.tsx +++ b/server/sonar-web/src/main/js/app/components/nav/component/ComponentNavMeta.tsx @@ -20,7 +20,6 @@ import * as React from 'react'; import { connect } from 'react-redux'; import ComponentNavWarnings from './ComponentNavWarnings'; -import BranchMeasures from '../../../../components/common/BranchMeasures'; import BranchStatus from '../../../../components/common/BranchStatus'; import DateTimeFormatter from '../../../../components/intl/DateTimeFormatter'; import Favorite from '../../../../components/controls/Favorite'; @@ -43,18 +42,11 @@ interface StateProps { interface Props extends StateProps { branchLike?: T.BranchLike; - branchMeasures?: T.Measure[]; component: T.Component; warnings: string[]; } -export function ComponentNavMeta({ - branchLike, - branchMeasures, - component, - currentUser, - warnings -}: Props) { +export function ComponentNavMeta({ branchLike, component, currentUser, warnings }: Props) { const mainBranch = !branchLike || isMainBranch(branchLike); const longBranch = isLongLivingBranch(branchLike); const currentPage = getCurrentPage(component, branchLike); @@ -104,17 +96,6 @@ export function ComponentNavMeta({ )} - {branchMeasures && - branchMeasures.length > 0 && ( - <> - - - - )} )} diff --git a/server/sonar-web/src/main/js/app/components/nav/component/__tests__/ComponentNavMeta-test.tsx b/server/sonar-web/src/main/js/app/components/nav/component/__tests__/ComponentNavMeta-test.tsx index 374ffca8fd9..aa8efb0ba7a 100644 --- a/server/sonar-web/src/main/js/app/components/nav/component/__tests__/ComponentNavMeta-test.tsx +++ b/server/sonar-web/src/main/js/app/components/nav/component/__tests__/ComponentNavMeta-test.tsx @@ -20,79 +20,43 @@ import * as React from 'react'; import { shallow } from 'enzyme'; import { ComponentNavMeta } from '../ComponentNavMeta'; - -const COMPONENT = { - analysisDate: '2017-01-02T00:00:00.000Z', - breadcrumbs: [], - key: 'foo', - name: 'Foo', - organization: 'org', - qualifier: 'TRK', - version: '0.0.1' -}; - -const MEASURES = [ - { metric: 'new_coverage', value: '0', periods: [{ index: 1, value: '95.9943' }] }, - { metric: 'new_duplicated_lines_density', periods: [{ index: 1, value: '3.5' }] } -]; +import { + mockShortLivingBranch, + mockComponent, + mockCurrentUser, + mockLongLivingBranch, + mockPullRequest +} from '../../../../../helpers/testMocks'; it('renders status of short-living branch', () => { - const branch: T.ShortLivingBranch = { - isMain: false, - mergeBranch: 'master', - name: 'feature', - status: { bugs: 0, codeSmells: 2, qualityGateStatus: 'ERROR', vulnerabilities: 3 }, - type: 'SHORT' - }; - expect( - shallow( - - ) - ).toMatchSnapshot(); + expect(shallowRender()).toMatchSnapshot(); }); it('renders meta for long-living branch', () => { - const branch: T.LongLivingBranch = { - isMain: false, - name: 'release', - status: { qualityGateStatus: 'OK' }, - type: 'LONG' - }; - expect( - shallow( - - ) - ).toMatchSnapshot(); + expect(shallowRender({ branchLike: mockLongLivingBranch() })).toMatchSnapshot(); }); it('renders meta for pull request', () => { - const pullRequest: T.PullRequest = { - base: 'master', - branch: 'feature', - key: '1234', - status: { bugs: 0, codeSmells: 2, qualityGateStatus: 'ERROR', vulnerabilities: 3 }, - title: 'Feature PR', - url: 'https://example.com/pull/1234' - }; expect( - shallow( - - ) + shallowRender({ + branchLike: mockPullRequest({ + status: { bugs: 0, codeSmells: 2, qualityGateStatus: 'ERROR', vulnerabilities: 3 }, + url: 'https://example.com/pull/1234' + }) + }) ).toMatchSnapshot(); }); + +function shallowRender(props = {}) { + return shallow( + + ); +} diff --git a/server/sonar-web/src/main/js/app/components/nav/component/__tests__/__snapshots__/ComponentNavBranchesMenuItem-test.tsx.snap b/server/sonar-web/src/main/js/app/components/nav/component/__tests__/__snapshots__/ComponentNavBranchesMenuItem-test.tsx.snap index 25528a5523c..3df35d2137e 100644 --- a/server/sonar-web/src/main/js/app/components/nav/component/__tests__/__snapshots__/ComponentNavBranchesMenuItem-test.tsx.snap +++ b/server/sonar-web/src/main/js/app/components/nav/component/__tests__/__snapshots__/ComponentNavBranchesMenuItem-test.tsx.snap @@ -49,7 +49,6 @@ exports[`renders main branch 1`] = ` "name": "master", } } - concise={true} /> @@ -67,7 +66,7 @@ exports[`renders short-living branch 1`] = ` style={Object {}} to={ Object { - "pathname": "/project/issues", + "pathname": "/dashboard", "query": Object { "branch": "foo", "id": "component", @@ -117,7 +116,6 @@ exports[`renders short-living branch 1`] = ` "type": "SHORT", } } - concise={true} /> @@ -135,7 +133,7 @@ exports[`renders short-living orhpan branch 1`] = ` style={Object {}} to={ Object { - "pathname": "/project/issues", + "pathname": "/dashboard", "query": Object { "branch": "foo", "id": "component", @@ -187,7 +185,6 @@ exports[`renders short-living orhpan branch 1`] = ` "type": "SHORT", } } - concise={true} /> diff --git a/server/sonar-web/src/main/js/app/components/nav/component/__tests__/__snapshots__/ComponentNavMeta-test.tsx.snap b/server/sonar-web/src/main/js/app/components/nav/component/__tests__/__snapshots__/ComponentNavMeta-test.tsx.snap index 35f80d6ab41..c7637342d5c 100644 --- a/server/sonar-web/src/main/js/app/components/nav/component/__tests__/__snapshots__/ComponentNavMeta-test.tsx.snap +++ b/server/sonar-web/src/main/js/app/components/nav/component/__tests__/__snapshots__/ComponentNavMeta-test.tsx.snap @@ -55,16 +55,17 @@ exports[`renders meta for pull request 1`] = ` - - `; diff --git a/server/sonar-web/src/main/js/app/types.d.ts b/server/sonar-web/src/main/js/app/types.d.ts index f412c82962d..816f12440e7 100644 --- a/server/sonar-web/src/main/js/app/types.d.ts +++ b/server/sonar-web/src/main/js/app/types.d.ts @@ -100,6 +100,7 @@ declare namespace T { analysisDate?: string; isMain: boolean; name: string; + status?: { qualityGateStatus: string }; } export type BranchLike = Branch | PullRequest; @@ -429,13 +430,11 @@ declare namespace T { export interface LongLivingBranch extends Branch { isMain: false; - status?: { qualityGateStatus: string }; type: 'LONG'; } export interface MainBranch extends Branch { isMain: true; - status?: { qualityGateStatus: string }; } export interface Measure extends MeasureIntern { diff --git a/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/__snapshots__/TaskComponent-test.tsx.snap b/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/__snapshots__/TaskComponent-test.tsx.snap index b054cb915e8..4b510fa8d43 100644 --- a/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/__snapshots__/TaskComponent-test.tsx.snap +++ b/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/__snapshots__/TaskComponent-test.tsx.snap @@ -61,7 +61,7 @@ exports[`renders correctly for branches and pullrequest 1`] = ` style={Object {}} to={ Object { - "pathname": "/project/issues", + "pathname": "/dashboard", "query": Object { "branch": "feature", "id": "foo", @@ -154,7 +154,7 @@ exports[`renders correctly for branches and pullrequest 3`] = ` style={Object {}} to={ Object { - "pathname": "/project/issues", + "pathname": "/dashboard", "query": Object { "id": "foo", "pullRequest": "pr-89", diff --git a/server/sonar-web/src/main/js/components/SourceViewer/components/__tests__/__snapshots__/MeasuresOverlay-test.tsx.snap b/server/sonar-web/src/main/js/components/SourceViewer/components/__tests__/__snapshots__/MeasuresOverlay-test.tsx.snap index fb658fc95a2..3fe6740c037 100644 --- a/server/sonar-web/src/main/js/components/SourceViewer/components/__tests__/__snapshots__/MeasuresOverlay-test.tsx.snap +++ b/server/sonar-web/src/main/js/components/SourceViewer/components/__tests__/__snapshots__/MeasuresOverlay-test.tsx.snap @@ -24,7 +24,7 @@ exports[`should render source file 1`] = ` style={Object {}} to={ Object { - "pathname": "/project/issues", + "pathname": "/dashboard", "query": Object { "branch": "feature", "id": "project-key", @@ -383,7 +383,7 @@ exports[`should render source file 2`] = ` style={Object {}} to={ Object { - "pathname": "/project/issues", + "pathname": "/dashboard", "query": Object { "branch": "feature", "id": "project-key", @@ -1348,7 +1348,7 @@ exports[`should render test file 1`] = ` style={Object {}} to={ Object { - "pathname": "/project/issues", + "pathname": "/dashboard", "query": Object { "branch": "feature", "id": "project-key", diff --git a/server/sonar-web/src/main/js/components/common/BranchMeasures.tsx b/server/sonar-web/src/main/js/components/common/BranchMeasures.tsx deleted file mode 100644 index 8d37f920d72..00000000000 --- a/server/sonar-web/src/main/js/components/common/BranchMeasures.tsx +++ /dev/null @@ -1,139 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2019 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 * as classNames from 'classnames'; -import { FormattedMessage } from 'react-intl'; -import { Link } from 'react-router'; -import { getLeakValue } from '../measure/utils'; -import CoverageRating from '../ui/CoverageRating'; -import { formatMeasure } from '../../helpers/measures'; -import HelpTooltip from '../controls/HelpTooltip'; -import { translate } from '../../helpers/l10n'; -import DuplicationsRating from '../ui/DuplicationsRating'; -import { getComponentDrilldownUrl } from '../../helpers/urls'; - -interface Props { - branchLike: T.BranchLike; - componentKey: string; - measures: T.Measure[]; -} - -export default function BranchMeasures({ branchLike, componentKey, measures }: Props) { - const newCoverage = measures.find(measure => measure.metric === 'new_coverage'); - const newDuplications = measures.find( - measure => measure.metric === 'new_duplicated_lines_density' - ); - if (!newCoverage && !newDuplications) { - return null; - } - - return ( -
- - -
- ); -} - -interface MeasureProps { - branchLike: T.BranchLike; - className?: string; - componentKey: string; - measure: T.Measure | undefined; -} - -export function BranchCoverage({ branchLike, className, componentKey, measure }: MeasureProps) { - const value = getLeakValue(measure); - return ( -
- - - {value !== undefined ? formatMeasure(value, 'PERCENT') : '–'} - - - {translate('layout.measures')} - - ) - }} - /> - ) : ( - translate('branches.measures.new_coverage.missing') - ) - } - /> -
- ); -} - -export function BranchDuplications({ branchLike, className, componentKey, measure }: MeasureProps) { - const value = getLeakValue(measure); - return ( -
- - - {value !== undefined ? formatMeasure(value, 'PERCENT') : '–'} - - - {translate('layout.measures')} - - ) - }} - /> - ) : ( - translate('branches.measures.new_duplicated_lines_density.missing') - ) - } - /> -
- ); -} diff --git a/server/sonar-web/src/main/js/components/common/BranchStatus.tsx b/server/sonar-web/src/main/js/components/common/BranchStatus.tsx index 439fef2822a..6345b0de276 100644 --- a/server/sonar-web/src/main/js/components/common/BranchStatus.tsx +++ b/server/sonar-web/src/main/js/components/common/BranchStatus.tsx @@ -18,91 +18,17 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ import * as React from 'react'; -import StatusIndicator from './StatusIndicator'; import Level from '../ui/Level'; -import BugIcon from '../icons-components/BugIcon'; -import CodeSmellIcon from '../icons-components/CodeSmellIcon'; -import HelpTooltip from '../controls/HelpTooltip'; -import Tooltip from '../controls/Tooltip'; -import VulnerabilityIcon from '../icons-components/VulnerabilityIcon'; -import { - getBranchQualityGateColor, - isShortLivingBranch, - isPullRequest, - isLongLivingBranch, - isMainBranch -} from '../../helpers/branches'; -import { translateWithParameters } from '../../helpers/l10n'; -import { formatMeasure } from '../../helpers/measures'; import './BranchStatus.css'; interface Props { branchLike: T.BranchLike; - concise?: boolean; } -export default function BranchStatus({ branchLike, concise = false }: Props) { - if (isShortLivingBranch(branchLike) || isPullRequest(branchLike)) { - if (!branchLike.status) { - return null; - } - - const totalIssues = - branchLike.status.bugs + branchLike.status.vulnerabilities + branchLike.status.codeSmells; - const status = branchLike.status.qualityGateStatus; - const indicatorColor = getBranchQualityGateColor(status); - const shouldDisplayHelper = status === 'OK' && totalIssues > 0; - - const label = - translateWithParameters('overview.quality_gate_x', formatMeasure(status, 'LEVEL')) + - (status !== 'OK' - ? ' ' + translateWithParameters('overview.quality_gate_failed_with_x', totalIssues) - : ''); - - return concise ? ( - -
    -
  • {totalIssues}
  • -
  • - -
  • -
-
- ) : ( -
    -
  • - -
  • -
  • - {branchLike.status.bugs} - -
  • -
  • - {branchLike.status.vulnerabilities} - -
  • -
  • - {branchLike.status.codeSmells} - -
  • - {shouldDisplayHelper && ( - - )} -
- ); - } else if (isLongLivingBranch(branchLike) || isMainBranch(branchLike)) { - if (!branchLike.status) { - return null; - } - - return ; +export default function BranchStatus({ branchLike }: Props) { + if (!branchLike.status) { + return null; } - return null; + + return ; } diff --git a/server/sonar-web/src/main/js/components/common/__tests__/BranchMeasures-test.tsx b/server/sonar-web/src/main/js/components/common/__tests__/BranchMeasures-test.tsx deleted file mode 100644 index 3ea160e8989..00000000000 --- a/server/sonar-web/src/main/js/components/common/__tests__/BranchMeasures-test.tsx +++ /dev/null @@ -1,65 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2019 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 BranchMeasures, { BranchCoverage, BranchDuplications } from '../BranchMeasures'; - -const MEASURES = [ - { metric: 'new_coverage', value: '0', periods: [{ index: 1, value: '95.9943' }] }, - { metric: 'new_duplicated_lines_density', periods: [{ index: 1, value: '3.5' }] } -]; - -const pr: T.PullRequest = { base: 'master', branch: 'feature-x', key: '5', title: '' }; - -describe('BranchMeasures', () => { - it('should render coverage and duplications', () => { - expect( - shallow() - ).toMatchSnapshot(); - }); - - it('should render correctly when coverage is missing', () => { - expect( - shallow() - ).toMatchSnapshot(); - }); - - it('should not render anything', () => { - expect( - shallow().type() - ).toBeNull(); - }); -}); - -describe('BranchCoverage', () => { - it('should render correctly', () => { - expect( - shallow() - ).toMatchSnapshot(); - }); -}); - -describe('BranchDuplications', () => { - it('should render correctly', () => { - expect( - shallow() - ).toMatchSnapshot(); - }); -}); diff --git a/server/sonar-web/src/main/js/components/common/__tests__/BranchStatus-test.tsx b/server/sonar-web/src/main/js/components/common/__tests__/BranchStatus-test.tsx index 54fa84deeb9..c09200b9880 100644 --- a/server/sonar-web/src/main/js/components/common/__tests__/BranchStatus-test.tsx +++ b/server/sonar-web/src/main/js/components/common/__tests__/BranchStatus-test.tsx @@ -21,44 +21,14 @@ import * as React from 'react'; import { shallow } from 'enzyme'; import BranchStatus from '../BranchStatus'; -it('renders status of short-living branches', () => { - checkShort('OK', 0, 0, 0); - checkShort('WARN', 0, 1, 0); - checkShort('ERROR', 7, 3, 6); - checkShort('OK', 0, 0, 1); - - function checkShort( - qualityGateStatus: string, - bugs: number, - codeSmells: number, - vulnerabilities: number - ) { - const shortBranch: T.ShortLivingBranch = { - isMain: false, - mergeBranch: 'master', - name: 'foo', - status: { bugs, codeSmells, qualityGateStatus, vulnerabilities }, - type: 'SHORT' - }; - expect(shallow()).toMatchSnapshot(); - } -}); - -it('renders status of long-living branches', () => { - const branch: T.LongLivingBranch = { isMain: false, name: 'foo', type: 'LONG' }; - expect(getWrapper(branch).type()).toBeNull(); - expect(getWrapper(branch, 'OK')).toMatchSnapshot(); - expect(getWrapper(branch, 'ERROR')).toMatchSnapshot(); -}); - -it('renders status of main branch', () => { +it('should render correctly', () => { const branch: T.MainBranch = { isMain: true, name: 'foo' }; expect(getWrapper(branch).type()).toBeNull(); expect(getWrapper(branch, 'OK')).toMatchSnapshot(); expect(getWrapper(branch, 'ERROR')).toMatchSnapshot(); }); -function getWrapper(branch: T.MainBranch | T.LongLivingBranch, qualityGateStatus?: string) { +function getWrapper(branch: T.MainBranch, qualityGateStatus?: string) { if (qualityGateStatus) { branch.status = { qualityGateStatus }; } diff --git a/server/sonar-web/src/main/js/components/common/__tests__/__snapshots__/BranchMeasures-test.tsx.snap b/server/sonar-web/src/main/js/components/common/__tests__/__snapshots__/BranchMeasures-test.tsx.snap deleted file mode 100644 index 6734123c4ca..00000000000 --- a/server/sonar-web/src/main/js/components/common/__tests__/__snapshots__/BranchMeasures-test.tsx.snap +++ /dev/null @@ -1,185 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`BranchCoverage should render correctly 1`] = ` -
- - - 96.0% - - - layout.measures - , - } - } - /> - } - /> -
-`; - -exports[`BranchDuplications should render correctly 1`] = ` -
- - - 3.5% - - - layout.measures - , - } - } - /> - } - /> -
-`; - -exports[`BranchMeasures should render correctly when coverage is missing 1`] = ` -
- - -
-`; - -exports[`BranchMeasures should render coverage and duplications 1`] = ` -
- - -
-`; diff --git a/server/sonar-web/src/main/js/components/common/__tests__/__snapshots__/BranchStatus-test.tsx.snap b/server/sonar-web/src/main/js/components/common/__tests__/__snapshots__/BranchStatus-test.tsx.snap index 8a731ff9f0b..df907fd0bfb 100644 --- a/server/sonar-web/src/main/js/components/common/__tests__/__snapshots__/BranchStatus-test.tsx.snap +++ b/server/sonar-web/src/main/js/components/common/__tests__/__snapshots__/BranchStatus-test.tsx.snap @@ -1,190 +1,15 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`renders status of long-living branches 1`] = ` +exports[`should render correctly 1`] = ` `; -exports[`renders status of long-living branches 2`] = ` +exports[`should render correctly 2`] = ` `; - -exports[`renders status of main branch 1`] = ` - -`; - -exports[`renders status of main branch 2`] = ` - -`; - -exports[`renders status of short-living branches 1`] = ` -
    -
  • - -
  • -
  • - 0 - -
  • -
  • - 0 - -
  • -
  • - 0 - -
  • -
-`; - -exports[`renders status of short-living branches 2`] = ` -
    -
  • - -
  • -
  • - 0 - -
  • -
  • - 0 - -
  • -
  • - 1 - -
  • -
-`; - -exports[`renders status of short-living branches 3`] = ` -
    -
  • - -
  • -
  • - 7 - -
  • -
  • - 6 - -
  • -
  • - 3 - -
  • -
-`; - -exports[`renders status of short-living branches 4`] = ` -
    -
  • - -
  • -
  • - 0 - -
  • -
  • - 1 - -
  • -
  • - 0 - -
  • - -
-`; diff --git a/server/sonar-web/src/main/js/helpers/testMocks.ts b/server/sonar-web/src/main/js/helpers/testMocks.ts index dc0927642f8..30cc2c1f81b 100644 --- a/server/sonar-web/src/main/js/helpers/testMocks.ts +++ b/server/sonar-web/src/main/js/helpers/testMocks.ts @@ -188,6 +188,23 @@ export function mockQualityGate(overrides: Partial = {}): T.Quali }; } +export function mockPullRequest(overrides: Partial = {}): T.PullRequest { + return { + analysisDate: '2018-01-01', + base: 'master', + branch: 'feature/foo/bar', + status: { + bugs: 0, + codeSmells: 0, + qualityGateStatus: 'OK', + vulnerabilities: 0 + }, + key: '1001', + title: 'Foo Bar feature', + ...overrides + }; +} + export function mockQualityProfile(overrides: Partial = {}): Profile { return { activeDeprecatedRuleCount: 2, @@ -236,3 +253,37 @@ export function mockRule(overrides: Partial = {}): T.Rule { ...overrides } as T.Rule; } + +export function mockShortLivingBranch( + overrides: Partial = {} +): T.ShortLivingBranch { + return { + analysisDate: '2018-01-01', + isMain: false, + name: 'release-1.0', + mergeBranch: 'master', + status: { + bugs: 0, + codeSmells: 0, + qualityGateStatus: 'OK', + vulnerabilities: 0 + }, + type: 'SHORT', + ...overrides + }; +} + +export function mockLongLivingBranch( + overrides: Partial = {} +): T.LongLivingBranch { + return { + analysisDate: '2018-01-01', + isMain: false, + name: 'master', + status: { + qualityGateStatus: 'OK' + }, + type: 'LONG', + ...overrides + }; +} diff --git a/server/sonar-web/src/main/js/helpers/urls.ts b/server/sonar-web/src/main/js/helpers/urls.ts index c7090bc6770..cf255e6919b 100644 --- a/server/sonar-web/src/main/js/helpers/urls.ts +++ b/server/sonar-web/src/main/js/helpers/urls.ts @@ -83,11 +83,11 @@ export function getLongLivingBranchUrl(project: string, branch: string): Locatio } export function getShortLivingBranchUrl(project: string, branch: string): Location { - return { pathname: '/project/issues', query: { branch, id: project, resolved: 'false' } }; + return { pathname: '/dashboard', query: { branch, id: project, resolved: 'false' } }; } export function getPullRequestUrl(project: string, pullRequest: string): Location { - return { pathname: '/project/issues', query: { id: project, pullRequest, resolved: 'false' } }; + return { pathname: '/dashboard', query: { id: project, pullRequest, resolved: 'false' } }; } /**