From 8490da5816150abf2258e2e5671c7ffa4f0fd72b Mon Sep 17 00:00:00 2001 From: Stas Vilchik Date: Mon, 4 Sep 2017 15:13:56 +0200 Subject: [PATCH] SONAR-9736 fix project status --- .../components/nav/component/ComponentNav.tsx | 3 + .../nav/component/ComponentNavMeta.tsx | 19 +++-- .../component/__tests__/ComponentNav-test.tsx | 80 +++++++++++++++++++ .../__snapshots__/ComponentNav-test.tsx.snap | 79 ++++++++++++++++++ 4 files changed, 173 insertions(+), 8 deletions(-) create mode 100644 server/sonar-web/src/main/js/app/components/nav/component/__tests__/ComponentNav-test.tsx create mode 100644 server/sonar-web/src/main/js/app/components/nav/component/__tests__/__snapshots__/ComponentNav-test.tsx.snap 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 { component={this.props.component} conf={this.props.conf} incremental={this.state.incremental} + isInProgress={this.state.isInProgress} + isFailed={this.state.isFailed} + isPending={this.state.isPending} /> } mouseLeaveDelay={2}> -
  • +
  • {' '} {translate('background_task.status.IN_PROGRESS')}
  • @@ -68,7 +71,7 @@ export default function ComponentNavMeta(props: Props) { key="isPending" overlay={
    } mouseLeaveDelay={2}> -
  • +
  • {translate('background_task.status.PENDING')}
  • @@ -82,7 +85,7 @@ export default function ComponentNavMeta(props: Props) { key="isFailed" overlay={
    } mouseLeaveDelay={2}> -
  • +
  • {translate('background_task.status.FAILED')} @@ -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(
  • @@ -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(
  • Version {props.component.version} @@ -109,16 +112,16 @@ export default function ComponentNavMeta(props: Props) { if (props.incremental) { metaList.push( -
  • +
  • ); } - if (props.branch && isShortLivingBranch(props.branch)) { + if (shortBranch) { metaList.push(
  • - +
  • ); } 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(); + expect(getTasksForComponent).toBeCalledWith('component'); +}); + +it('renders', () => { + const wrapper = shallow( + + ); + 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`] = ` + + + + + + +`; -- 2.39.5