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';
interface State {
branchLike?: T.BranchLike;
branchLikes: T.BranchLike[];
- branchMeasures?: T.Measure[];
component?: T.Component;
currentTask?: T.Task;
isPending: boolean;
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
});
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 }) => {
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 });
+ }
+ },
+ () => {}
+ );
}
};
!['FIL', 'UTS'].includes(component.qualifier) && (
<ComponentNav
branchLikes={branchLikes}
- branchMeasures={this.state.branchMeasures}
component={component}
currentBranchLike={branchLike}
currentTask={currentTask}
expect(getPullRequests).toBeCalledWith('projectKey');
});
-it('updates the branch measures', async () => {
- (getComponentNavigation as jest.Mock<any>).mockResolvedValueOnce({
- breadcrumbs: [{ key: 'foo', name: 'Foo', qualifier: 'TRK' }],
- key: 'foo'
- });
- (getBranches as jest.Mock<any>).mockResolvedValueOnce([
- { isMain: false, mergeBranch: 'master', name: 'feature', type: 'SHORT' }
- ]);
- (getPullRequests as jest.Mock<any>).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<any>).mockResolvedValueOnce({ organization: 'org' });
interface Props {
branchLikes: T.BranchLike[];
- branchMeasures?: T.Measure[];
currentBranchLike: T.BranchLike | undefined;
component: T.Component;
currentTask?: T.Task;
/>
<ComponentNavMeta
branchLike={currentBranchLike}
- branchMeasures={this.props.branchMeasures}
component={component}
warnings={this.props.warnings}
/>
)}
</div>
<div className="big-spacer-left note">
- <BranchStatus branchLike={branchLike} concise={true} />
+ <BranchStatus branchLike={branchLike} />
</div>
</Link>
</li>
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';
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);
</a>
)}
<BranchStatus branchLike={branchLike} />
- {branchMeasures &&
- branchMeasures.length > 0 && (
- <>
- <span className="vertical-separator big-spacer-left big-spacer-right" />
- <BranchMeasures
- branchLike={branchLike}
- componentKey={component.key}
- measures={branchMeasures}
- />
- </>
- )}
</div>
)}
</div>
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(
- <ComponentNavMeta
- branchLike={branch}
- branchMeasures={MEASURES}
- component={COMPONENT}
- currentUser={{ isLoggedIn: false }}
- warnings={[]}
- />
- )
- ).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(
- <ComponentNavMeta
- branchLike={branch}
- component={COMPONENT}
- currentUser={{ isLoggedIn: false }}
- warnings={[]}
- />
- )
- ).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(
- <ComponentNavMeta
- branchLike={pullRequest}
- component={COMPONENT}
- currentUser={{ isLoggedIn: false }}
- warnings={[]}
- />
- )
+ shallowRender({
+ branchLike: mockPullRequest({
+ status: { bugs: 0, codeSmells: 2, qualityGateStatus: 'ERROR', vulnerabilities: 3 },
+ url: 'https://example.com/pull/1234'
+ })
+ })
).toMatchSnapshot();
});
+
+function shallowRender(props = {}) {
+ return shallow(
+ <ComponentNavMeta
+ branchLike={mockShortLivingBranch({
+ status: { bugs: 0, codeSmells: 2, qualityGateStatus: 'ERROR', vulnerabilities: 3 }
+ })}
+ component={mockComponent({ analysisDate: '2017-01-02T00:00:00.000Z', version: '0.0.1' })}
+ currentUser={mockCurrentUser({ isLoggedIn: false })}
+ warnings={[]}
+ {...props}
+ />
+ );
+}
"name": "master",
}
}
- concise={true}
/>
</div>
</Link>
style={Object {}}
to={
Object {
- "pathname": "/project/issues",
+ "pathname": "/dashboard",
"query": Object {
"branch": "foo",
"id": "component",
"type": "SHORT",
}
}
- concise={true}
/>
</div>
</Link>
style={Object {}}
to={
Object {
- "pathname": "/project/issues",
+ "pathname": "/dashboard",
"query": Object {
"branch": "foo",
"id": "component",
"type": "SHORT",
}
}
- concise={true}
/>
</div>
</Link>
<BranchStatus
branchLike={
Object {
+ "analysisDate": "2018-01-01",
"base": "master",
- "branch": "feature",
- "key": "1234",
+ "branch": "feature/foo/bar",
+ "key": "1001",
"status": Object {
"bugs": 0,
"codeSmells": 2,
"qualityGateStatus": "ERROR",
"vulnerabilities": 3,
},
- "title": "Feature PR",
+ "title": "Foo Bar feature",
"url": "https://example.com/pull/1234",
}
}
<BranchStatus
branchLike={
Object {
+ "analysisDate": "2018-01-01",
"isMain": false,
"mergeBranch": "master",
- "name": "feature",
+ "name": "release-1.0",
"status": Object {
"bugs": 0,
"codeSmells": 2,
}
}
/>
- <span
- className="vertical-separator big-spacer-left big-spacer-right"
- />
- <BranchMeasures
- branchLike={
- Object {
- "isMain": false,
- "mergeBranch": "master",
- "name": "feature",
- "status": Object {
- "bugs": 0,
- "codeSmells": 2,
- "qualityGateStatus": "ERROR",
- "vulnerabilities": 3,
- },
- "type": "SHORT",
- }
- }
- componentKey="foo"
- measures={
- Array [
- Object {
- "metric": "new_coverage",
- "periods": Array [
- Object {
- "index": 1,
- "value": "95.9943",
- },
- ],
- "value": "0",
- },
- Object {
- "metric": "new_duplicated_lines_density",
- "periods": Array [
- Object {
- "index": 1,
- "value": "3.5",
- },
- ],
- },
- ]
- }
- />
</div>
</div>
`;
analysisDate?: string;
isMain: boolean;
name: string;
+ status?: { qualityGateStatus: string };
}
export type BranchLike = Branch | PullRequest;
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 {
style={Object {}}
to={
Object {
- "pathname": "/project/issues",
+ "pathname": "/dashboard",
"query": Object {
"branch": "feature",
"id": "foo",
style={Object {}}
to={
Object {
- "pathname": "/project/issues",
+ "pathname": "/dashboard",
"query": Object {
"id": "foo",
"pullRequest": "pr-89",
style={Object {}}
to={
Object {
- "pathname": "/project/issues",
+ "pathname": "/dashboard",
"query": Object {
"branch": "feature",
"id": "project-key",
style={Object {}}
to={
Object {
- "pathname": "/project/issues",
+ "pathname": "/dashboard",
"query": Object {
"branch": "feature",
"id": "project-key",
style={Object {}}
to={
Object {
- "pathname": "/project/issues",
+ "pathname": "/dashboard",
"query": Object {
"branch": "feature",
"id": "project-key",
+++ /dev/null
-/*
- * 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 (
- <div className="display-inline-flex-center">
- <BranchCoverage branchLike={branchLike} componentKey={componentKey} measure={newCoverage} />
- <BranchDuplications
- branchLike={branchLike}
- className="big-spacer-left"
- componentKey={componentKey}
- measure={newDuplications}
- />
- </div>
- );
-}
-
-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 (
- <div className={classNames('display-inline-flex-center', className)}>
- <CoverageRating size="small" value={value} />
- <span className="little-spacer-left">
- {value !== undefined ? formatMeasure(value, 'PERCENT') : '–'}
- </span>
- <HelpTooltip
- className="little-spacer-left"
- overlay={
- measure ? (
- <FormattedMessage
- defaultMessage={translate('branches.measures.new_coverage.help')}
- id="branches.measures.new_coverage.help"
- values={{
- link: (
- <Link
- to={getComponentDrilldownUrl({
- componentKey,
- branchLike,
- metric: 'new_coverage'
- })}>
- {translate('layout.measures')}
- </Link>
- )
- }}
- />
- ) : (
- translate('branches.measures.new_coverage.missing')
- )
- }
- />
- </div>
- );
-}
-
-export function BranchDuplications({ branchLike, className, componentKey, measure }: MeasureProps) {
- const value = getLeakValue(measure);
- return (
- <div className={classNames('display-inline-flex-center', className)}>
- <DuplicationsRating size="small" value={Number(value)} />
- <span className="little-spacer-left">
- {value !== undefined ? formatMeasure(value, 'PERCENT') : '–'}
- </span>
- <HelpTooltip
- className="little-spacer-left"
- overlay={
- measure ? (
- <FormattedMessage
- defaultMessage={translate('branches.measures.new_duplicated_lines_density.help')}
- id="branches.measures.new_duplicated_lines_density.help"
- values={{
- link: (
- <Link
- to={getComponentDrilldownUrl({
- componentKey,
- branchLike,
- metric: 'new_duplicated_lines_density'
- })}>
- {translate('layout.measures')}
- </Link>
- )
- }}
- />
- ) : (
- translate('branches.measures.new_duplicated_lines_density.missing')
- )
- }
- />
- </div>
- );
-}
* 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 ? (
- <Tooltip overlay={label} placement="right">
- <ul className="branch-status">
- <li>{totalIssues}</li>
- <li className="spacer-left">
- <StatusIndicator color={indicatorColor} size="small" />
- </li>
- </ul>
- </Tooltip>
- ) : (
- <ul className="branch-status">
- <li className="little-spacer-right">
- <StatusIndicator color={indicatorColor} size="small" />
- </li>
- <li className="spacer-left">
- {branchLike.status.bugs}
- <BugIcon className="little-spacer-left" />
- </li>
- <li className="spacer-left">
- {branchLike.status.vulnerabilities}
- <VulnerabilityIcon className="little-spacer-left" />
- </li>
- <li className="spacer-left">
- {branchLike.status.codeSmells}
- <CodeSmellIcon className="little-spacer-left" />
- </li>
- {shouldDisplayHelper && (
- <HelpTooltip
- className="spacer-left"
- overlay={translateWithParameters(
- 'branches.short_lived.quality_gate.description',
- totalIssues
- )}
- tagName="li"
- />
- )}
- </ul>
- );
- } else if (isLongLivingBranch(branchLike) || isMainBranch(branchLike)) {
- if (!branchLike.status) {
- return null;
- }
-
- return <Level level={branchLike.status.qualityGateStatus} small={true} />;
+export default function BranchStatus({ branchLike }: Props) {
+ if (!branchLike.status) {
+ return null;
}
- return null;
+
+ return <Level level={branchLike.status.qualityGateStatus} small={true} />;
}
+++ /dev/null
-/*
- * 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(<BranchMeasures branchLike={pr} componentKey="foo" measures={MEASURES} />)
- ).toMatchSnapshot();
- });
-
- it('should render correctly when coverage is missing', () => {
- expect(
- shallow(<BranchMeasures branchLike={pr} componentKey="foo" measures={[MEASURES[1]]} />)
- ).toMatchSnapshot();
- });
-
- it('should not render anything', () => {
- expect(
- shallow(<BranchMeasures branchLike={pr} componentKey="foo" measures={[]} />).type()
- ).toBeNull();
- });
-});
-
-describe('BranchCoverage', () => {
- it('should render correctly', () => {
- expect(
- shallow(<BranchCoverage branchLike={pr} componentKey="foo" measure={MEASURES[0]} />)
- ).toMatchSnapshot();
- });
-});
-
-describe('BranchDuplications', () => {
- it('should render correctly', () => {
- expect(
- shallow(<BranchDuplications branchLike={pr} componentKey="foo" measure={MEASURES[1]} />)
- ).toMatchSnapshot();
- });
-});
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(<BranchStatus branchLike={shortBranch} />)).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 };
}
+++ /dev/null
-// Jest Snapshot v1, https://goo.gl/fbAQLP
-
-exports[`BranchCoverage should render correctly 1`] = `
-<div
- className="display-inline-flex-center"
->
- <CoverageRating
- size="small"
- value="95.9943"
- />
- <span
- className="little-spacer-left"
- >
- 96.0%
- </span>
- <HelpTooltip
- className="little-spacer-left"
- overlay={
- <FormattedMessage
- defaultMessage="branches.measures.new_coverage.help"
- id="branches.measures.new_coverage.help"
- values={
- Object {
- "link": <Link
- onlyActiveOnIndex={false}
- style={Object {}}
- to={
- Object {
- "pathname": "/component_measures",
- "query": Object {
- "id": "foo",
- "metric": "new_coverage",
- "pullRequest": "5",
- },
- }
- }
- >
- layout.measures
- </Link>,
- }
- }
- />
- }
- />
-</div>
-`;
-
-exports[`BranchDuplications should render correctly 1`] = `
-<div
- className="display-inline-flex-center"
->
- <DuplicationsRating
- size="small"
- value={3.5}
- />
- <span
- className="little-spacer-left"
- >
- 3.5%
- </span>
- <HelpTooltip
- className="little-spacer-left"
- overlay={
- <FormattedMessage
- defaultMessage="branches.measures.new_duplicated_lines_density.help"
- id="branches.measures.new_duplicated_lines_density.help"
- values={
- Object {
- "link": <Link
- onlyActiveOnIndex={false}
- style={Object {}}
- to={
- Object {
- "pathname": "/component_measures",
- "query": Object {
- "id": "foo",
- "metric": "new_duplicated_lines_density",
- "pullRequest": "5",
- },
- }
- }
- >
- layout.measures
- </Link>,
- }
- }
- />
- }
- />
-</div>
-`;
-
-exports[`BranchMeasures should render correctly when coverage is missing 1`] = `
-<div
- className="display-inline-flex-center"
->
- <BranchCoverage
- branchLike={
- Object {
- "base": "master",
- "branch": "feature-x",
- "key": "5",
- "title": "",
- }
- }
- componentKey="foo"
- />
- <BranchDuplications
- branchLike={
- Object {
- "base": "master",
- "branch": "feature-x",
- "key": "5",
- "title": "",
- }
- }
- className="big-spacer-left"
- componentKey="foo"
- measure={
- Object {
- "metric": "new_duplicated_lines_density",
- "periods": Array [
- Object {
- "index": 1,
- "value": "3.5",
- },
- ],
- }
- }
- />
-</div>
-`;
-
-exports[`BranchMeasures should render coverage and duplications 1`] = `
-<div
- className="display-inline-flex-center"
->
- <BranchCoverage
- branchLike={
- Object {
- "base": "master",
- "branch": "feature-x",
- "key": "5",
- "title": "",
- }
- }
- componentKey="foo"
- measure={
- Object {
- "metric": "new_coverage",
- "periods": Array [
- Object {
- "index": 1,
- "value": "95.9943",
- },
- ],
- "value": "0",
- }
- }
- />
- <BranchDuplications
- branchLike={
- Object {
- "base": "master",
- "branch": "feature-x",
- "key": "5",
- "title": "",
- }
- }
- className="big-spacer-left"
- componentKey="foo"
- measure={
- Object {
- "metric": "new_duplicated_lines_density",
- "periods": Array [
- Object {
- "index": 1,
- "value": "3.5",
- },
- ],
- }
- }
- />
-</div>
-`;
// Jest Snapshot v1, https://goo.gl/fbAQLP
-exports[`renders status of long-living branches 1`] = `
+exports[`should render correctly 1`] = `
<Level
level="OK"
small={true}
/>
`;
-exports[`renders status of long-living branches 2`] = `
+exports[`should render correctly 2`] = `
<Level
level="ERROR"
small={true}
/>
`;
-
-exports[`renders status of main branch 1`] = `
-<Level
- level="OK"
- small={true}
-/>
-`;
-
-exports[`renders status of main branch 2`] = `
-<Level
- level="ERROR"
- small={true}
-/>
-`;
-
-exports[`renders status of short-living branches 1`] = `
-<ul
- className="branch-status"
->
- <li
- className="little-spacer-right"
- >
- <StatusIndicator
- color="green"
- size="small"
- />
- </li>
- <li
- className="spacer-left"
- >
- 0
- <BugIcon
- className="little-spacer-left"
- />
- </li>
- <li
- className="spacer-left"
- >
- 0
- <VulnerabilityIcon
- className="little-spacer-left"
- />
- </li>
- <li
- className="spacer-left"
- >
- 0
- <CodeSmellIcon
- className="little-spacer-left"
- />
- </li>
-</ul>
-`;
-
-exports[`renders status of short-living branches 2`] = `
-<ul
- className="branch-status"
->
- <li
- className="little-spacer-right"
- >
- <StatusIndicator
- color="orange"
- size="small"
- />
- </li>
- <li
- className="spacer-left"
- >
- 0
- <BugIcon
- className="little-spacer-left"
- />
- </li>
- <li
- className="spacer-left"
- >
- 0
- <VulnerabilityIcon
- className="little-spacer-left"
- />
- </li>
- <li
- className="spacer-left"
- >
- 1
- <CodeSmellIcon
- className="little-spacer-left"
- />
- </li>
-</ul>
-`;
-
-exports[`renders status of short-living branches 3`] = `
-<ul
- className="branch-status"
->
- <li
- className="little-spacer-right"
- >
- <StatusIndicator
- color="red"
- size="small"
- />
- </li>
- <li
- className="spacer-left"
- >
- 7
- <BugIcon
- className="little-spacer-left"
- />
- </li>
- <li
- className="spacer-left"
- >
- 6
- <VulnerabilityIcon
- className="little-spacer-left"
- />
- </li>
- <li
- className="spacer-left"
- >
- 3
- <CodeSmellIcon
- className="little-spacer-left"
- />
- </li>
-</ul>
-`;
-
-exports[`renders status of short-living branches 4`] = `
-<ul
- className="branch-status"
->
- <li
- className="little-spacer-right"
- >
- <StatusIndicator
- color="green"
- size="small"
- />
- </li>
- <li
- className="spacer-left"
- >
- 0
- <BugIcon
- className="little-spacer-left"
- />
- </li>
- <li
- className="spacer-left"
- >
- 1
- <VulnerabilityIcon
- className="little-spacer-left"
- />
- </li>
- <li
- className="spacer-left"
- >
- 0
- <CodeSmellIcon
- className="little-spacer-left"
- />
- </li>
- <HelpTooltip
- className="spacer-left"
- overlay="branches.short_lived.quality_gate.description.1"
- tagName="li"
- />
-</ul>
-`;
};
}
+export function mockPullRequest(overrides: Partial<T.PullRequest> = {}): 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> = {}): Profile {
return {
activeDeprecatedRuleCount: 2,
...overrides
} as T.Rule;
}
+
+export function mockShortLivingBranch(
+ overrides: Partial<T.ShortLivingBranch> = {}
+): 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> = {}
+): T.LongLivingBranch {
+ return {
+ analysisDate: '2018-01-01',
+ isMain: false,
+ name: 'master',
+ status: {
+ qualityGateStatus: 'OK'
+ },
+ type: 'LONG',
+ ...overrides
+ };
+}
}
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' } };
}
/**