]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-10572 Fix wrong link for branches in background tasks
authorGrégoire Aubert <gregoire.aubert@sonarsource.com>
Thu, 12 Apr 2018 13:56:29 +0000 (15:56 +0200)
committerSonarTech <sonartech@sonarsource.com>
Mon, 16 Apr 2018 18:20:47 +0000 (20:20 +0200)
server/sonar-web/src/main/js/apps/background-tasks/components/TaskComponent.tsx
server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/TaskComponent-test.tsx
server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/__snapshots__/TaskComponent-test.tsx.snap

index a81919215b15abf09ad837924caf80db04e32802..7d57ddf1205fb650230fee5e436b06da87e29ca2 100644 (file)
@@ -92,13 +92,14 @@ export default function TaskComponent({ task }: Props) {
 }
 
 function getTaskComponentUrl(componentKey: string, task: Task) {
-  if (task.branch && task.branchType === 'SHORT') {
-    return getShortLivingBranchUrl(componentKey, task.branchType);
-  } else if (task.branchType && task.branchType === 'LONG') {
-    return getLongLivingBranchUrl(componentKey, task.branchType);
+  if (task.branch) {
+    if (task.branchType === 'SHORT') {
+      return getShortLivingBranchUrl(componentKey, task.branch);
+    } else if (task.branchType === 'LONG') {
+      return getLongLivingBranchUrl(componentKey, task.branch);
+    }
   } else if (task.pullRequest) {
     return getPullRequestUrl(componentKey, task.pullRequest);
-  } else {
-    return getProjectUrl(componentKey);
   }
+  return getProjectUrl(componentKey);
 }
index 7518c51dc30588a25c7a750728f8ce07bd0ad5ea..ad89c600812324231b79def48ef860f3d7853069 100644 (file)
@@ -21,18 +21,28 @@ import * as React from 'react';
 import { shallow } from 'enzyme';
 import TaskComponent from '../TaskComponent';
 
-it('renders', () => {
-  const task = {
-    componentKey: 'foo',
-    componentName: 'foo',
-    componentQualifier: 'TRK',
-    id: 'bar',
-    organization: 'org',
-    status: 'PENDING',
-    submittedAt: '2017-01-01',
-    type: 'REPORT'
-  };
-  expect(shallow(<TaskComponent task={task} />)).toMatchSnapshot();
-  expect(shallow(<TaskComponent task={{ ...task, componentKey: undefined }} />)).toMatchSnapshot();
-  expect(shallow(<TaskComponent task={{ ...task, branch: 'feature' }} />)).toMatchSnapshot();
+const TASK = {
+  componentKey: 'foo',
+  componentName: 'foo',
+  componentQualifier: 'TRK',
+  id: 'bar',
+  organization: 'org',
+  status: 'PENDING',
+  submittedAt: '2017-01-01',
+  type: 'REPORT'
+};
+
+it('renders correctly', () => {
+  expect(shallow(<TaskComponent task={TASK} />)).toMatchSnapshot();
+  expect(shallow(<TaskComponent task={{ ...TASK, componentKey: undefined }} />)).toMatchSnapshot();
+});
+
+it('renders correctly for branches and pullrequest', () => {
+  expect(
+    shallow(<TaskComponent task={{ ...TASK, branch: 'feature', branchType: 'SHORT' }} />)
+  ).toMatchSnapshot();
+  expect(
+    shallow(<TaskComponent task={{ ...TASK, branch: 'branch-6.7', branchType: 'LONG' }} />)
+  ).toMatchSnapshot();
+  expect(shallow(<TaskComponent task={{ ...TASK, pullRequest: 'pr-89' }} />)).toMatchSnapshot();
 });
index f71a484187b6c58d4a599dba61e08a4b8424ad73..d1f54e342f5dc40094cba1c300653b1a23826155 100644 (file)
@@ -1,6 +1,6 @@
 // Jest Snapshot v1, https://goo.gl/fbAQLP
 
-exports[`renders 1`] = `
+exports[`renders correctly 1`] = `
 <td>
   <span
     className="little-spacer-right"
@@ -33,7 +33,7 @@ exports[`renders 1`] = `
 </td>
 `;
 
-exports[`renders 2`] = `
+exports[`renders correctly 2`] = `
 <td>
   <span
     className="note"
@@ -46,15 +46,11 @@ exports[`renders 2`] = `
 </td>
 `;
 
-exports[`renders 3`] = `
+exports[`renders correctly for branches and pullrequest 1`] = `
 <td>
-  <span
+  <ShortLivingBranchIcon
     className="little-spacer-right"
-  >
-    <QualifierIcon
-      qualifier="TRK"
-    />
-  </span>
+  />
   <Connect(Organization)
     organizationKey="org"
   />
@@ -64,9 +60,11 @@ exports[`renders 3`] = `
     style={Object {}}
     to={
       Object {
-        "pathname": "/dashboard",
+        "pathname": "/project/issues",
         "query": Object {
+          "branch": "feature",
           "id": "foo",
+          "resolved": "false",
         },
       }
     }
@@ -94,3 +92,97 @@ exports[`renders 3`] = `
   />
 </td>
 `;
+
+exports[`renders correctly for branches and pullrequest 2`] = `
+<td>
+  <LongLivingBranchIcon
+    className="little-spacer-right"
+  />
+  <Connect(Organization)
+    organizationKey="org"
+  />
+  <Link
+    className="spacer-right"
+    onlyActiveOnIndex={false}
+    style={Object {}}
+    to={
+      Object {
+        "pathname": "/dashboard",
+        "query": Object {
+          "branch": "branch-6.7",
+          "id": "foo",
+        },
+      }
+    }
+  >
+    foo
+    <span
+      className="text-limited text-text-top"
+      title="branch-6.7"
+    >
+      <span
+        style={
+          Object {
+            "marginLeft": 5,
+            "marginRight": 5,
+          }
+        }
+      >
+        /
+      </span>
+      branch-6.7
+    </span>
+  </Link>
+  <TaskType
+    type="REPORT"
+  />
+</td>
+`;
+
+exports[`renders correctly for branches and pullrequest 3`] = `
+<td>
+  <PullRequestIcon
+    className="little-spacer-right"
+  />
+  <Connect(Organization)
+    organizationKey="org"
+  />
+  <Link
+    className="spacer-right"
+    onlyActiveOnIndex={false}
+    style={Object {}}
+    to={
+      Object {
+        "pathname": "/project/issues",
+        "query": Object {
+          "id": "foo",
+          "pullRequest": "pr-89",
+          "resolved": "false",
+        },
+      }
+    }
+  >
+    foo
+    <Tooltip>
+      <span
+        className="text-limited text-text-top"
+      >
+        <span
+          style={
+            Object {
+              "marginLeft": 5,
+              "marginRight": 5,
+            }
+          }
+        >
+          /
+        </span>
+        pr-89
+      </span>
+    </Tooltip>
+  </Link>
+  <TaskType
+    type="REPORT"
+  />
+</td>
+`;