diff options
author | Stas Vilchik <stas.vilchik@sonarsource.com> | 2017-09-04 15:13:56 +0200 |
---|---|---|
committer | Janos Gyerik <janos.gyerik@sonarsource.com> | 2017-09-12 11:34:58 +0200 |
commit | 8490da5816150abf2258e2e5671c7ffa4f0fd72b (patch) | |
tree | 51f015272b29cbd8bdc9d453d239c37b4f70b5be /server | |
parent | 43a521d0f1c5919ec6511cc369dd99d0830c86ab (diff) | |
download | sonarqube-8490da5816150abf2258e2e5671c7ffa4f0fd72b.tar.gz sonarqube-8490da5816150abf2258e2e5671c7ffa4f0fd72b.zip |
SONAR-9736 fix project status
Diffstat (limited to 'server')
4 files changed, 173 insertions, 8 deletions
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 df4a432d5be..06a5f7889a8 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 @@ -113,6 +113,9 @@ export default class ComponentNav extends React.PureComponent<Props, State> { component={this.props.component} conf={this.props.conf} incremental={this.state.incremental} + isInProgress={this.state.isInProgress} + isFailed={this.state.isFailed} + isPending={this.state.isPending} /> <ComponentNavMenu 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 3be540c0d4f..ecf5562b8b9 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 @@ -18,6 +18,7 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ import * as React from 'react'; +import * as classNames from 'classnames'; import IncrementalBadge from './IncrementalBadge'; import BranchStatus from '../../../../components/common/BranchStatus'; import { Branch, Component, ComponentConfiguration } from '../../../types'; @@ -44,6 +45,8 @@ export default function ComponentNavMeta(props: Props) { (window as any).baseUrl + `/project/background_tasks?id=${encodeURIComponent(props.component.key)}`; + const shortBranch = props.branch && isShortLivingBranch(props.branch); + if (props.isInProgress) { const tooltip = canSeeBackgroundTasks ? translateWithParameters('component_navigation.status.in_progress.admin', backgroundTasksUrl) @@ -53,7 +56,7 @@ export default function ComponentNavMeta(props: Props) { key="isInProgress" overlay={<div dangerouslySetInnerHTML={{ __html: tooltip }} />} mouseLeaveDelay={2}> - <li> + <li className={classNames({ 'navbar-context-meta-branch': shortBranch })}> <i className="spinner" style={{ marginTop: '-1px' }} />{' '} <span className="text-info">{translate('background_task.status.IN_PROGRESS')}</span> </li> @@ -68,7 +71,7 @@ export default function ComponentNavMeta(props: Props) { key="isPending" overlay={<div dangerouslySetInnerHTML={{ __html: tooltip }} />} mouseLeaveDelay={2}> - <li> + <li className={classNames({ 'navbar-context-meta-branch': shortBranch })}> <PendingIcon /> <span>{translate('background_task.status.PENDING')}</span> </li> </Tooltip> @@ -82,7 +85,7 @@ export default function ComponentNavMeta(props: Props) { key="isFailed" overlay={<div dangerouslySetInnerHTML={{ __html: tooltip }} />} mouseLeaveDelay={2}> - <li> + <li className={classNames({ 'navbar-context-meta-branch': shortBranch })}> <span className="badge badge-danger"> {translate('background_task.status.FAILED')} </span> @@ -91,7 +94,7 @@ export default function ComponentNavMeta(props: Props) { ); } - if (props.component.analysisDate && (!props.branch || !isShortLivingBranch(props.branch))) { + if (props.component.analysisDate && !shortBranch) { metaList.push( <li key="analysisDate"> <DateTimeFormatter date={props.component.analysisDate} /> @@ -99,7 +102,7 @@ export default function ComponentNavMeta(props: Props) { ); } - if (props.component.version && (!props.branch || !isShortLivingBranch(props.branch))) { + if (props.component.version && !shortBranch) { metaList.push( <li key="version"> Version {props.component.version} @@ -109,16 +112,16 @@ export default function ComponentNavMeta(props: Props) { if (props.incremental) { metaList.push( - <li key="incremental"> + <li key="incremental" className={classNames({ 'navbar-context-meta-branch': shortBranch })}> <IncrementalBadge /> </li> ); } - if (props.branch && isShortLivingBranch(props.branch)) { + if (shortBranch) { metaList.push( <li className="navbar-context-meta-branch" key="branch-status"> - <BranchStatus branch={props.branch} /> + <BranchStatus branch={props.branch!} /> </li> ); } diff --git a/server/sonar-web/src/main/js/app/components/nav/component/__tests__/ComponentNav-test.tsx b/server/sonar-web/src/main/js/app/components/nav/component/__tests__/ComponentNav-test.tsx new file mode 100644 index 00000000000..6ae5fb1c768 --- /dev/null +++ b/server/sonar-web/src/main/js/app/components/nav/component/__tests__/ComponentNav-test.tsx @@ -0,0 +1,80 @@ +/* + * SonarQube + * Copyright (C) 2009-2016 SonarSource SA + * mailto:contact 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. + */ + +jest.mock('../ComponentNavFavorite', () => ({ + default: function ComponentNavFavorite() { + return null; + } +})); + +jest.mock('../ComponentNavBreadcrumbs', () => ({ + default: function ComponentNavBreadcrumbs() { + return null; + } +})); + +jest.mock('../ComponentNavMenu', () => ({ + default: function ComponentNavMenu() { + return null; + } +})); + +jest.mock('../../../RecentHistory', () => ({ + default: { add: jest.fn() } +})); + +jest.mock('../../../../../api/ce', () => ({ + getTasksForComponent: jest.fn(() => Promise.resolve({ queue: [] })) +})); + +import * as React from 'react'; +import { mount, shallow } from 'enzyme'; +import ComponentNav from '../ComponentNav'; + +const getTasksForComponent = require('../../../../../api/ce').getTasksForComponent as jest.Mock< + any +>; + +const component = { + breadcrumbs: [{ key: 'component', name: 'component', qualifier: 'TRK' }], + key: 'component', + name: 'component', + organization: 'org', + qualifier: 'TRK' +}; + +it('loads status', () => { + getTasksForComponent.mockClear(); + mount(<ComponentNav branches={[]} component={component} conf={{}} location={{}} />); + expect(getTasksForComponent).toBeCalledWith('component'); +}); + +it('renders', () => { + const wrapper = shallow( + <ComponentNav branches={[]} component={component} conf={{}} location={{}} /> + ); + wrapper.setState({ + incremental: true, + isFailed: true, + isInProgress: true, + isPending: true + }); + expect(wrapper).toMatchSnapshot(); +}); diff --git a/server/sonar-web/src/main/js/app/components/nav/component/__tests__/__snapshots__/ComponentNav-test.tsx.snap b/server/sonar-web/src/main/js/app/components/nav/component/__tests__/__snapshots__/ComponentNav-test.tsx.snap new file mode 100644 index 00000000000..f84eeda97aa --- /dev/null +++ b/server/sonar-web/src/main/js/app/components/nav/component/__tests__/__snapshots__/ComponentNav-test.tsx.snap @@ -0,0 +1,79 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`renders 1`] = ` +<ContextNavBar + height={65} + id="context-navigation" +> + <ComponentNavFavorite + component="component" + /> + <ComponentNavBreadcrumbs + breadcrumbs={ + Array [ + Object { + "key": "component", + "name": "component", + "qualifier": "TRK", + }, + ] + } + component={ + Object { + "breadcrumbs": Array [ + Object { + "key": "component", + "name": "component", + "qualifier": "TRK", + }, + ], + "key": "component", + "name": "component", + "organization": "org", + "qualifier": "TRK", + } + } + /> + <ComponentNavMeta + component={ + Object { + "breadcrumbs": Array [ + Object { + "key": "component", + "name": "component", + "qualifier": "TRK", + }, + ], + "key": "component", + "name": "component", + "organization": "org", + "qualifier": "TRK", + } + } + conf={Object {}} + incremental={true} + isFailed={true} + isInProgress={true} + isPending={true} + /> + <ComponentNavMenu + component={ + Object { + "breadcrumbs": Array [ + Object { + "key": "component", + "name": "component", + "qualifier": "TRK", + }, + ], + "key": "component", + "name": "component", + "organization": "org", + "qualifier": "TRK", + } + } + conf={Object {}} + location={Object {}} + /> +</ContextNavBar> +`; |