]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-9736 fix project status
authorStas Vilchik <stas.vilchik@sonarsource.com>
Mon, 4 Sep 2017 13:13:56 +0000 (15:13 +0200)
committerJanos Gyerik <janos.gyerik@sonarsource.com>
Tue, 12 Sep 2017 09:34:58 +0000 (11:34 +0200)
server/sonar-web/src/main/js/app/components/nav/component/ComponentNav.tsx
server/sonar-web/src/main/js/app/components/nav/component/ComponentNavMeta.tsx
server/sonar-web/src/main/js/app/components/nav/component/__tests__/ComponentNav-test.tsx [new file with mode: 0644]
server/sonar-web/src/main/js/app/components/nav/component/__tests__/__snapshots__/ComponentNav-test.tsx.snap [new file with mode: 0644]

index df4a432d5be3e896ed115b411dcc5a71d179e64c..06a5f7889a86ddbf94abbcd7a38210861be1e957 100644 (file)
@@ -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
index 3be540c0d4f1855c0f28bf0b310cf26a43b90ccd..ecf5562b8b9641a8ae1f595411acaf222bd9c884 100644 (file)
@@ -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 (file)
index 0000000..6ae5fb1
--- /dev/null
@@ -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 (file)
index 0000000..f84eeda
--- /dev/null
@@ -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>
+`;