]> source.dussan.org Git - sonarqube.git/commitdiff
Update background task related types
authorWouter Admiraal <wouter.admiraal@sonarsource.com>
Mon, 14 Sep 2020 13:40:23 +0000 (15:40 +0200)
committersonartech <sonartech@sonarsource.com>
Tue, 29 Sep 2020 20:07:42 +0000 (20:07 +0000)
34 files changed:
server/sonar-web/src/main/js/api/ce.ts
server/sonar-web/src/main/js/app/components/ComponentContainer.tsx
server/sonar-web/src/main/js/app/components/__tests__/ComponentContainer-test.tsx
server/sonar-web/src/main/js/app/components/indexation/IndexationNotificationRenderer.tsx
server/sonar-web/src/main/js/app/components/nav/component/ComponentNav.tsx
server/sonar-web/src/main/js/app/components/nav/component/ComponentNavBgTaskNotif.tsx
server/sonar-web/src/main/js/app/components/nav/component/ComponentNavLicenseNotif.tsx
server/sonar-web/src/main/js/app/components/nav/component/__tests__/ComponentNavBgTaskNotif-test.tsx
server/sonar-web/src/main/js/app/components/nav/component/__tests__/ComponentNavLicenseNotif-test.tsx
server/sonar-web/src/main/js/app/components/nav/component/__tests__/__snapshots__/ComponentNavBgTaskNotif-test.tsx.snap
server/sonar-web/src/main/js/apps/background-tasks/__tests__/BackgroundTasks-test.tsx
server/sonar-web/src/main/js/apps/background-tasks/components/BackgroundTasksApp.tsx
server/sonar-web/src/main/js/apps/background-tasks/components/Footer.tsx
server/sonar-web/src/main/js/apps/background-tasks/components/ScannerContext.tsx
server/sonar-web/src/main/js/apps/background-tasks/components/Stacktrace.tsx
server/sonar-web/src/main/js/apps/background-tasks/components/StatusFilter.tsx
server/sonar-web/src/main/js/apps/background-tasks/components/Task.tsx
server/sonar-web/src/main/js/apps/background-tasks/components/TaskActions.tsx
server/sonar-web/src/main/js/apps/background-tasks/components/TaskComponent.tsx
server/sonar-web/src/main/js/apps/background-tasks/components/TaskStatus.tsx
server/sonar-web/src/main/js/apps/background-tasks/components/Tasks.tsx
server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/ScannerContext-test.tsx
server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/Stacktrace-test.tsx
server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/Task-test.tsx
server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/TaskActions-test.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__/Task-test.tsx.snap
server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/__snapshots__/TaskActions-test.tsx.snap
server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/__snapshots__/TaskComponent-test.tsx.snap
server/sonar-web/src/main/js/apps/background-tasks/constants.ts
server/sonar-web/src/main/js/apps/background-tasks/utils.ts
server/sonar-web/src/main/js/helpers/mocks/tasks.ts [new file with mode: 0644]
server/sonar-web/src/main/js/types/tasks.ts [new file with mode: 0644]
server/sonar-web/src/main/js/types/types.d.ts

index a4d1a03a5ca2eba5dd52595356e6e1b32cd445d2..e2b9a1f846cdf44796f5810d5b4bd3dd7fa99c75 100644 (file)
@@ -20,6 +20,7 @@
 import { getJSON, post, RequestData } from 'sonar-ui-common/helpers/request';
 import throwGlobalError from '../app/utils/throwGlobalError';
 import { IndexationStatus } from '../types/indexation';
+import { Task } from '../types/tasks';
 
 export function getAnalysisStatus(data: {
   component: string;
@@ -38,7 +39,7 @@ export function getAnalysisStatus(data: {
   return getJSON('/api/ce/analysis_status', data).catch(throwGlobalError);
 }
 
-export function getActivity(data: RequestData): Promise<{ tasks: T.Task[] }> {
+export function getActivity(data: RequestData): Promise<{ tasks: Task[] }> {
   return getJSON('/api/ce/activity', data);
 }
 
@@ -52,7 +53,7 @@ export function getStatus(
   return getJSON('/api/ce/activity_status', data);
 }
 
-export function getTask(id: string, additionalFields?: string[]): Promise<T.Task> {
+export function getTask(id: string, additionalFields?: string[]): Promise<Task> {
   return getJSON('/api/ce/task', { id, additionalFields }).then(r => r.task);
 }
 
@@ -67,9 +68,7 @@ export function cancelAllTasks(): Promise<any> {
   return post('/api/ce/cancel_all');
 }
 
-export function getTasksForComponent(
-  component: string
-): Promise<{ queue: T.Task[]; current: T.Task }> {
+export function getTasksForComponent(component: string): Promise<{ queue: Task[]; current: Task }> {
   return getJSON('/api/ce/component', { component }).catch(throwGlobalError);
 }
 
index 82d48a415ba42a687984b5909184bf2aae81d860..dc540a9b5b412da26859170a6a6a06c410ff5f98 100644 (file)
@@ -24,7 +24,6 @@ import { getBranches, getPullRequests } from '../../api/branches';
 import { getAnalysisStatus, getTasksForComponent } from '../../api/ce';
 import { getComponentData } from '../../api/components';
 import { getComponentNavigation } from '../../api/nav';
-import { STATUSES } from '../../apps/background-tasks/constants';
 import { Location, Router, withRouter } from '../../components/hoc/withRouter';
 import {
   getBranchLikeQuery,
@@ -40,6 +39,7 @@ import {
 } from '../../store/rootActions';
 import { BranchLike } from '../../types/branch-like';
 import { isPortfolioLike } from '../../types/component';
+import { Task, TaskStatuses } from '../../types/tasks';
 import ComponentContainerNotFound from './ComponentContainerNotFound';
 import { ComponentContext } from './ComponentContext';
 import PageUnavailableDueToIndexation from './indexation/PageUnavailableDueToIndexation';
@@ -58,10 +58,10 @@ interface State {
   branchLike?: BranchLike;
   branchLikes: BranchLike[];
   component?: T.Component;
-  currentTask?: T.Task;
+  currentTask?: Task;
   isPending: boolean;
   loading: boolean;
-  tasksInProgress?: T.Task[];
+  tasksInProgress?: Task[];
   warnings: string[];
 }
 
@@ -189,7 +189,7 @@ export class ComponentContainer extends React.PureComponent<Props, State> {
               const newCurrentTask = this.getCurrentTask(current, branchLike);
               const pendingTasks = this.getPendingTasks(queue, branchLike);
               const newTasksInProgress = pendingTasks.filter(
-                task => task.status === STATUSES.IN_PROGRESS
+                task => task.status === TaskStatuses.InProgress
               );
 
               const currentTaskChanged =
@@ -214,7 +214,7 @@ export class ComponentContainer extends React.PureComponent<Props, State> {
                 );
               }
 
-              const isPending = pendingTasks.some(task => task.status === STATUSES.PENDING);
+              const isPending = pendingTasks.some(task => task.status === TaskStatuses.Pending);
               return {
                 currentTask: newCurrentTask,
                 isPending,
@@ -254,21 +254,21 @@ export class ComponentContainer extends React.PureComponent<Props, State> {
       : branchLikes.find(b => isBranch(b) && (query.branch ? b.name === query.branch : b.isMain));
   };
 
-  getCurrentTask = (current: T.Task, branchLike?: BranchLike) => {
+  getCurrentTask = (current: Task, branchLike?: BranchLike) => {
     if (!current) {
       return undefined;
     }
 
-    return current.status === STATUSES.FAILED || this.isSameBranch(current, branchLike)
+    return current.status === TaskStatuses.Failed || this.isSameBranch(current, branchLike)
       ? current
       : undefined;
   };
 
-  getPendingTasks = (pendingTasks: T.Task[], branchLike?: BranchLike) => {
+  getPendingTasks = (pendingTasks: Task[], branchLike?: BranchLike) => {
     return pendingTasks.filter(task => this.isSameBranch(task, branchLike));
   };
 
-  isSameBranch = (task: Pick<T.Task, 'branch' | 'pullRequest'>, branchLike?: BranchLike) => {
+  isSameBranch = (task: Pick<Task, 'branch' | 'pullRequest'>, branchLike?: BranchLike) => {
     if (branchLike) {
       if (isMainBranch(branchLike)) {
         return (!task.pullRequest && !task.branch) || branchLike.name === task.branch;
index d96dc9a6d24b47e2baa4f7a64deb71c414801352..0a23c0441385ff5adcc11997647a36da792809a9 100644 (file)
@@ -24,10 +24,11 @@ import { getBranches, getPullRequests } from '../../../api/branches';
 import { getTasksForComponent } from '../../../api/ce';
 import { getComponentData } from '../../../api/components';
 import { getComponentNavigation } from '../../../api/nav';
-import { STATUSES } from '../../../apps/background-tasks/constants';
 import { mockBranch, mockMainBranch, mockPullRequest } from '../../../helpers/mocks/branch-like';
+import { mockTask } from '../../../helpers/mocks/tasks';
 import { mockComponent, mockLocation, mockRouter } from '../../../helpers/testMocks';
 import { ComponentQualifier } from '../../../types/component';
+import { TaskStatuses } from '../../../types/tasks';
 import { ComponentContainer } from '../ComponentContainer';
 import PageUnavailableDueToIndexation from '../indexation/PageUnavailableDueToIndexation';
 
@@ -147,9 +148,9 @@ it('filters correctly the pending tasks for a main branch', () => {
   expect(component.isSameBranch({ branch: 'branch-6.7' }, pullRequest)).toBe(false);
   expect(component.isSameBranch({ pullRequest: pullRequest.key }, pullRequest)).toBe(true);
 
-  const currentTask = { pullRequest: pullRequest.key, status: STATUSES.IN_PROGRESS } as T.Task;
-  const failedTask = { ...currentTask, status: STATUSES.FAILED };
-  const pendingTasks = [currentTask, { branch: branch3.name } as T.Task, {} as T.Task];
+  const currentTask = mockTask({ pullRequest: pullRequest.key, status: TaskStatuses.InProgress });
+  const failedTask = { ...currentTask, status: TaskStatuses.Failed };
+  const pendingTasks = [currentTask, mockTask({ branch: branch3.name }), mockTask()];
   expect(component.getCurrentTask(currentTask, undefined)).toBeUndefined();
   expect(component.getCurrentTask(failedTask, mainBranch)).toBe(failedTask);
   expect(component.getCurrentTask(currentTask, mainBranch)).toBeUndefined();
@@ -162,7 +163,7 @@ it('reload component after task progress finished', async () => {
   jest.useFakeTimers();
   (getTasksForComponent as jest.Mock<any>)
     .mockResolvedValueOnce({
-      queue: [{ id: 'foo', status: STATUSES.IN_PROGRESS }]
+      queue: [{ id: 'foo', status: TaskStatuses.InProgress }]
     })
     .mockResolvedValueOnce({
       queue: []
@@ -205,7 +206,7 @@ it('reloads component after task progress finished, and moves straight to curren
   });
   (getTasksForComponent as jest.Mock<any>)
     .mockResolvedValueOnce({ queue: [] })
-    .mockResolvedValueOnce({ queue: [], current: { id: 'foo', status: STATUSES.SUCCESS } });
+    .mockResolvedValueOnce({ queue: [], current: { id: 'foo', status: TaskStatuses.Success } });
   const wrapper = shallowRender();
 
   // First round, nothing in the queue, and component navigation was not called
index a945219678f6f6adc40cac6dfce77fbe9e79bfa5..bd828e91ba792aa2da5ec5880c907004204eec09 100644 (file)
@@ -23,8 +23,8 @@ import { FormattedMessage } from 'react-intl';
 import { Link } from 'react-router';
 import { Alert, AlertProps } from 'sonar-ui-common/components/ui/Alert';
 import { translate, translateWithParameters } from 'sonar-ui-common/helpers/l10n';
-import { BackgroundTaskTypes, STATUSES } from '../../../apps/background-tasks/constants';
 import { IndexationNotificationType } from '../../../types/indexation';
+import { TaskStatuses, TaskTypes } from '../../../types/tasks';
 
 export interface IndexationNotificationRendererProps {
   type: IndexationNotificationType;
@@ -142,8 +142,8 @@ function renderBackgroundTasksPageLink(hasError: boolean, text: string) {
       to={{
         pathname: '/admin/background_tasks',
         query: {
-          taskType: BackgroundTaskTypes.IssueSync,
-          status: hasError ? STATUSES.FAILED : undefined
+          taskType: TaskTypes.IssueSync,
+          status: hasError ? TaskStatuses.Failed : undefined
         }
       }}>
       {text}
index ceeae0dbbf64e6479e9cd9b18a35bf0b68244b0d..1e0f7fb0455cef70a9e19dd9290f478307301074 100644 (file)
@@ -20,9 +20,9 @@
 import * as classNames from 'classnames';
 import * as React from 'react';
 import ContextNavBar from 'sonar-ui-common/components/ui/ContextNavBar';
-import { STATUSES } from '../../../../apps/background-tasks/constants';
 import { BranchLike } from '../../../../types/branch-like';
 import { ComponentQualifier } from '../../../../types/component';
+import { Task, TaskStatuses } from '../../../../types/tasks';
 import { rawSizes } from '../../../theme';
 import RecentHistory from '../../RecentHistory';
 import ComponentNavBgTaskNotif from './ComponentNavBgTaskNotif';
@@ -36,7 +36,7 @@ interface Props {
   branchLikes: BranchLike[];
   currentBranchLike: BranchLike | undefined;
   component: T.Component;
-  currentTask?: T.Task;
+  currentTask?: Task;
   currentTaskOnSameBranch?: boolean;
   isInProgress?: boolean;
   isPending?: boolean;
@@ -75,7 +75,7 @@ export default function ComponentNav(props: Props) {
   }, [component, component.key]);
 
   let notifComponent;
-  if (isInProgress || isPending || (currentTask && currentTask.status === STATUSES.FAILED)) {
+  if (isInProgress || isPending || (currentTask && currentTask.status === TaskStatuses.Failed)) {
     notifComponent = (
       <ComponentNavBgTaskNotif
         component={component}
index c0da78bb3cc2ae1df5fa8080c12a7f313d4d5970..3454c4c74643916a49a12d3636676faae5593b83 100644 (file)
@@ -24,11 +24,12 @@ import { Alert } from 'sonar-ui-common/components/ui/Alert';
 import { hasMessage, translate } from 'sonar-ui-common/helpers/l10n';
 import { STATUSES } from '../../../../apps/background-tasks/constants';
 import { getComponentBackgroundTaskUrl } from '../../../../helpers/urls';
+import { Task, TaskStatuses } from '../../../../types/tasks';
 import ComponentNavLicenseNotif from './ComponentNavLicenseNotif';
 
 interface Props {
   component: T.Component;
-  currentTask?: T.Task;
+  currentTask?: Task;
   currentTaskOnSameBranch?: boolean;
   isInProgress?: boolean;
   isPending?: boolean;
@@ -79,7 +80,7 @@ export default class ComponentNavBgTaskNotif extends React.PureComponent<Props>
           {this.renderMessage('component_navigation.status.pending', STATUSES.ALL)}
         </Alert>
       );
-    } else if (currentTask && currentTask.status === STATUSES.FAILED) {
+    } else if (currentTask && currentTask.status === TaskStatuses.Failed) {
       if (
         currentTask.errorType &&
         hasMessage('license.component_navigation.button', currentTask.errorType)
index 3c97fa52d3eda8344c5b837f4ac7b57378e22af1..348468a05cbb30b5fcbbde7e243f5ff30ec68497 100644 (file)
@@ -24,10 +24,11 @@ import { translate, translateWithParameters } from 'sonar-ui-common/helpers/l10n
 import { isValidLicense } from '../../../../api/marketplace';
 import { withAppState } from '../../../../components/hoc/withAppState';
 import { ComponentQualifier } from '../../../../types/component';
+import { Task } from '../../../../types/tasks';
 
 interface Props {
   appState: Pick<T.AppState, 'canAdmin'>;
-  currentTask?: T.Task;
+  currentTask?: Task;
 }
 
 interface State {
index c9f9c14c72784a5104de56fa5a9a834987118129..39dfcd2d3b2c12909d4036d1280b241a88e4ee68 100644 (file)
@@ -19,6 +19,9 @@
  */
 import { shallow } from 'enzyme';
 import * as React from 'react';
+import { mockTask } from '../../../../../helpers/mocks/tasks';
+import { mockComponent } from '../../../../../helpers/testMocks';
+import { TaskStatuses } from '../../../../../types/tasks';
 import ComponentNavBgTaskNotif from '../ComponentNavBgTaskNotif';
 
 jest.mock('sonar-ui-common/helpers/l10n', () => ({
@@ -26,67 +29,49 @@ jest.mock('sonar-ui-common/helpers/l10n', () => ({
   hasMessage: jest.fn().mockReturnValue(true)
 }));
 
-const component = {
-  analysisDate: '2017-01-02T00:00:00.000Z',
-  breadcrumbs: [],
-  key: 'foo',
-  name: 'Foo',
-  organization: 'org',
-  qualifier: 'TRK',
-  version: '0.0.1'
-};
-
-it('renders background task error correctly', () => {
-  expect(getWrapper()).toMatchSnapshot();
-});
-
-it('renders background task error correctly for a different branch/PR', () => {
+it('renders correctly', () => {
+  expect(shallowRender()).toMatchSnapshot('default');
+  expect(shallowRender({ isPending: true })).toMatchSnapshot('pending');
+  expect(
+    shallowRender({
+      component: mockComponent({ configuration: { showBackgroundTasks: true } }),
+      isPending: true
+    })
+  ).toMatchSnapshot('pending for admins');
+  expect(shallowRender({ isInProgress: true, isPending: true })).toMatchSnapshot('in progress');
+  expect(
+    shallowRender({
+      currentTask: mockTask({
+        status: TaskStatuses.Failed,
+        errorType: 'LICENSING',
+        errorMessage: 'Foo'
+      })
+    })
+  ).toMatchSnapshot('license issue');
   expect(
-    getWrapper({
-      currentTask: { branch: 'my/branch', status: 'FAILED' } as T.Task,
+    shallowRender({
+      currentTask: mockTask({ branch: 'my/branch', status: TaskStatuses.Failed }),
       currentTaskOnSameBranch: false
     })
-  ).toMatchSnapshot();
+  ).toMatchSnapshot('branch');
   expect(
-    getWrapper({
-      currentTask: {
+    shallowRender({
+      currentTask: mockTask({
         pullRequest: '650',
         pullRequestTitle: 'feature/my_pr',
-        status: 'FAILED'
-      } as T.Task,
+        status: TaskStatuses.Failed
+      }),
       currentTaskOnSameBranch: false
     })
-  ).toMatchSnapshot();
-});
-
-it('renders background task pending info correctly', () => {
-  expect(getWrapper({ isPending: true })).toMatchSnapshot();
-});
-
-it('renders background task pending info correctly for admin', () => {
-  expect(
-    getWrapper({
-      component: { ...component, configuration: { showBackgroundTasks: true } },
-      isPending: true
-    })
-  ).toMatchSnapshot();
-});
-
-it('renders background task in progress info correctly', () => {
-  expect(getWrapper({ isInProgress: true, isPending: true })).toMatchSnapshot();
-});
-
-it('renders background task license info correctly', () => {
-  expect(
-    getWrapper({ currentTask: { status: 'FAILED', errorType: 'LICENSING', errorMessage: 'Foo' } })
-  ).toMatchSnapshot();
+  ).toMatchSnapshot('pul request');
+  expect(shallowRender({ currentTask: undefined })).toMatchSnapshot('no current task');
 });
 
-function getWrapper(props = {}) {
-  return shallow(
+function shallowRender(props: Partial<ComponentNavBgTaskNotif['props']> = {}) {
+  return shallow<ComponentNavBgTaskNotif>(
     <ComponentNavBgTaskNotif
-      component={component}
-      currentTask={{ status: 'FAILED' } as T.Task}
+      component={mockComponent()}
+      currentTask={mockTask({ status: TaskStatuses.Failed })}
       {...props}
     />
   );
index 390f667121b754c7dbeac46900ae299d889fd4d5..a47863871818ca29f68e0fe099bbff0509f257bb 100644 (file)
@@ -21,6 +21,8 @@ import { shallow } from 'enzyme';
 import * as React from 'react';
 import { waitAndUpdate } from 'sonar-ui-common/helpers/testUtils';
 import { isValidLicense } from '../../../../../api/marketplace';
+import { mockTask } from '../../../../../helpers/mocks/tasks';
+import { TaskStatuses } from '../../../../../types/tasks';
 import { ComponentNavLicenseNotif } from '../ComponentNavLicenseNotif';
 
 jest.mock('sonar-ui-common/helpers/l10n', () => ({
@@ -38,14 +40,22 @@ beforeEach(() => {
 
 it('renders background task license info correctly', async () => {
   let wrapper = getWrapper({
-    currentTask: { status: 'FAILED', errorType: 'LICENSING', errorMessage: 'Foo' } as T.Task
+    currentTask: mockTask({
+      status: TaskStatuses.Failed,
+      errorType: 'LICENSING',
+      errorMessage: 'Foo'
+    })
   });
   await waitAndUpdate(wrapper);
   expect(wrapper).toMatchSnapshot();
 
   wrapper = getWrapper({
     appState: { canAdmin: false },
-    currentTask: { status: 'FAILED', errorType: 'LICENSING', errorMessage: 'Foo' } as T.Task
+    currentTask: mockTask({
+      status: TaskStatuses.Failed,
+      errorType: 'LICENSING',
+      errorMessage: 'Foo'
+    })
   });
   await waitAndUpdate(wrapper);
   expect(wrapper).toMatchSnapshot();
@@ -54,7 +64,11 @@ it('renders background task license info correctly', async () => {
 it('renders a different message if the license is valid', async () => {
   (isValidLicense as jest.Mock<any>).mockResolvedValueOnce({ isValidLicense: true });
   const wrapper = getWrapper({
-    currentTask: { status: 'FAILED', errorType: 'LICENSING', errorMessage: 'Foo' } as T.Task
+    currentTask: mockTask({
+      status: TaskStatuses.Failed,
+      errorType: 'LICENSING',
+      errorMessage: 'Foo'
+    })
   });
   await waitAndUpdate(wrapper);
   expect(wrapper).toMatchSnapshot();
@@ -63,7 +77,11 @@ it('renders a different message if the license is valid', async () => {
 it('renders correctly for LICENSING_LOC error', async () => {
   (isValidLicense as jest.Mock<any>).mockResolvedValueOnce({ isValidLicense: true });
   const wrapper = getWrapper({
-    currentTask: { status: 'FAILED', errorType: 'LICENSING_LOC', errorMessage: 'Foo' } as T.Task
+    currentTask: mockTask({
+      status: TaskStatuses.Failed,
+      errorType: 'LICENSING_LOC',
+      errorMessage: 'Foo'
+    })
   });
   await waitAndUpdate(wrapper);
   expect(wrapper).toMatchSnapshot();
@@ -73,7 +91,7 @@ function getWrapper(props: Partial<ComponentNavLicenseNotif['props']> = {}) {
   return shallow(
     <ComponentNavLicenseNotif
       appState={{ canAdmin: true }}
-      currentTask={{ errorMessage: 'Foo', errorType: 'LICENSING' } as T.Task}
+      currentTask={mockTask({ errorMessage: 'Foo', errorType: 'LICENSING' })}
       {...props}
     />
   );
index 75e4cbb58f03b214753e0976d0ef57cc5ac55b57..dad46cb8300a351b2223da9205748e30b730d289 100644 (file)
@@ -1,25 +1,6 @@
 // Jest Snapshot v1, https://goo.gl/fbAQLP
 
-exports[`renders background task error correctly 1`] = `
-<Alert
-  display="banner"
-  variant="error"
->
-  <FormattedMessage
-    defaultMessage="component_navigation.status.failed_X"
-    id="component_navigation.status.failed_X"
-    values={
-      Object {
-        "branch": undefined,
-        "type": "background_task.type.",
-        "url": undefined,
-      }
-    }
-  />
-</Alert>
-`;
-
-exports[`renders background task error correctly for a different branch/PR 1`] = `
+exports[`renders correctly: branch 1`] = `
 <Alert
   display="banner"
   variant="error"
@@ -30,7 +11,7 @@ exports[`renders background task error correctly for a different branch/PR 1`] =
     values={
       Object {
         "branch": "my/branch",
-        "type": "background_task.type.",
+        "type": "background_task.type.REPORT",
         "url": undefined,
       }
     }
@@ -38,18 +19,18 @@ exports[`renders background task error correctly for a different branch/PR 1`] =
 </Alert>
 `;
 
-exports[`renders background task error correctly for a different branch/PR 2`] = `
+exports[`renders correctly: default 1`] = `
 <Alert
   display="banner"
   variant="error"
 >
   <FormattedMessage
-    defaultMessage="component_navigation.status.failed_branch_X"
-    id="component_navigation.status.failed_branch_X"
+    defaultMessage="component_navigation.status.failed_X"
+    id="component_navigation.status.failed_X"
     values={
       Object {
-        "branch": "650 - feature/my_pr",
-        "type": "background_task.type.",
+        "branch": undefined,
+        "type": "background_task.type.REPORT",
         "url": undefined,
       }
     }
@@ -57,7 +38,7 @@ exports[`renders background task error correctly for a different branch/PR 2`] =
 </Alert>
 `;
 
-exports[`renders background task in progress info correctly 1`] = `
+exports[`renders correctly: in progress 1`] = `
 <Alert
   display="banner"
   variant="info"
@@ -68,7 +49,7 @@ exports[`renders background task in progress info correctly 1`] = `
     values={
       Object {
         "branch": undefined,
-        "type": "background_task.type.",
+        "type": "background_task.type.REPORT",
         "url": undefined,
       }
     }
@@ -76,19 +57,29 @@ exports[`renders background task in progress info correctly 1`] = `
 </Alert>
 `;
 
-exports[`renders background task license info correctly 1`] = `
+exports[`renders correctly: license issue 1`] = `
 <Connect(withAppState(ComponentNavLicenseNotif))
   currentTask={
     Object {
+      "analysisId": "x123",
+      "componentKey": "foo",
+      "componentName": "Foo",
+      "componentQualifier": "TRK",
       "errorMessage": "Foo",
       "errorType": "LICENSING",
+      "id": "AXR8jg_0mF2ZsYr8Wzs2",
+      "organization": "bar",
       "status": "FAILED",
+      "submittedAt": "2020-09-11T11:45:35+0200",
+      "type": "REPORT",
     }
   }
 />
 `;
 
-exports[`renders background task pending info correctly 1`] = `
+exports[`renders correctly: no current task 1`] = `""`;
+
+exports[`renders correctly: pending 1`] = `
 <Alert
   display="banner"
   variant="info"
@@ -99,7 +90,7 @@ exports[`renders background task pending info correctly 1`] = `
     values={
       Object {
         "branch": undefined,
-        "type": "background_task.type.",
+        "type": "background_task.type.REPORT",
         "url": undefined,
       }
     }
@@ -107,7 +98,7 @@ exports[`renders background task pending info correctly 1`] = `
 </Alert>
 `;
 
-exports[`renders background task pending info correctly for admin 1`] = `
+exports[`renders correctly: pending for admins 1`] = `
 <Alert
   display="banner"
   variant="info"
@@ -118,7 +109,7 @@ exports[`renders background task pending info correctly for admin 1`] = `
     values={
       Object {
         "branch": undefined,
-        "type": "background_task.type.",
+        "type": "background_task.type.REPORT",
         "url": <Link
           onlyActiveOnIndex={false}
           style={Object {}}
@@ -126,7 +117,7 @@ exports[`renders background task pending info correctly for admin 1`] = `
             Object {
               "pathname": "/project/background_tasks",
               "query": Object {
-                "id": "foo",
+                "id": "my-project",
                 "status": "__ALL__",
               },
             }
@@ -139,3 +130,22 @@ exports[`renders background task pending info correctly for admin 1`] = `
   />
 </Alert>
 `;
+
+exports[`renders correctly: pul request 1`] = `
+<Alert
+  display="banner"
+  variant="error"
+>
+  <FormattedMessage
+    defaultMessage="component_navigation.status.failed_branch_X"
+    id="component_navigation.status.failed_branch_X"
+    values={
+      Object {
+        "branch": "650 - feature/my_pr",
+        "type": "background_task.type.REPORT",
+        "url": undefined,
+      }
+    }
+  />
+</Alert>
+`;
index 2e4410f064f018ddfb5df7effe0b86baeac529e9..531899a4228782eb8a03f5bd9102bf2500655537 100644 (file)
@@ -21,19 +21,9 @@ import { shallow } from 'enzyme';
 import * as React from 'react';
 import { click } from 'sonar-ui-common/helpers/testUtils';
 import Search from '../components/Search';
-import { CURRENTS, DEFAULT_FILTERS, STATUSES } from '../constants';
+import { DEFAULT_FILTERS } from '../constants';
 import { formatDuration } from '../utils';
 
-describe('Constants', () => {
-  it('should have STATUSES', () => {
-    expect(Object.keys(STATUSES).length).toBe(7);
-  });
-
-  it('should have CURRENTS', () => {
-    expect(Object.keys(CURRENTS).length).toBe(2);
-  });
-});
-
 describe('Search', () => {
   const defaultProps: Search['props'] = {
     ...DEFAULT_FILTERS,
index aad93b01500b9644ab4f680f09729139832111f9..ade7100f7c997902934aa176cad7c6b2411edf6e 100644 (file)
@@ -34,8 +34,9 @@ import {
 import Suggestions from '../../../app/components/embed-docs-modal/Suggestions';
 import { Location, Router } from '../../../components/hoc/withRouter';
 import { fetchOrganizations } from '../../../store/rootActions';
+import { Task, TaskStatuses } from '../../../types/tasks';
 import '../background-tasks.css';
-import { CURRENTS, DEBOUNCE_DELAY, DEFAULT_FILTERS, STATUSES } from '../constants';
+import { CURRENTS, DEBOUNCE_DELAY, DEFAULT_FILTERS } from '../constants';
 import { mapFiltersToParameters, Query, updateTask } from '../utils';
 import Footer from './Footer';
 import Header from './Header';
@@ -55,7 +56,7 @@ interface State {
   loading: boolean;
   pendingCount: number;
   pendingTime?: number;
-  tasks: T.Task[];
+  tasks: Task[];
   types?: string[];
 }
 
@@ -161,7 +162,7 @@ export class BackgroundTasksApp extends React.PureComponent<Props, State> {
     });
   };
 
-  handleCancelTask = (task: T.Task) => {
+  handleCancelTask = (task: Task) => {
     this.setState({ loading: true });
 
     return cancelTaskAPI(task.id).then(nextTask => {
@@ -174,14 +175,14 @@ export class BackgroundTasksApp extends React.PureComponent<Props, State> {
     }, this.stopLoading);
   };
 
-  handleFilterTask = (task: T.Task) => {
+  handleFilterTask = (task: Task) => {
     this.handleFilterUpdate({ query: task.componentKey });
   };
 
   handleShowFailing = () => {
     this.handleFilterUpdate({
       ...DEFAULT_FILTERS,
-      status: STATUSES.FAILED,
+      status: TaskStatuses.Failed,
       currents: CURRENTS.ONLY_CURRENTS
     });
   };
index c8469c0148e39fb46ad9afe27081960a0477a2f9..55b6bbf6f6c91940941f4c8eb3bf207f220ad92f 100644 (file)
  */
 import * as React from 'react';
 import { translateWithParameters } from 'sonar-ui-common/helpers/l10n';
+import { Task } from '../../../types/tasks';
 
 const LIMIT = 1000;
 
 interface Props {
-  tasks: T.Task[];
+  tasks: Task[];
 }
 
 export default function Footer({ tasks }: Props) {
index 7192adffa45dd9343e08b1a12ef91f6376cd8a0d..9d6f6db227a2a717b95cf371e9919b2af2c7e41b 100644 (file)
@@ -21,10 +21,11 @@ import * as React from 'react';
 import Modal from 'sonar-ui-common/components/controls/Modal';
 import { translate } from 'sonar-ui-common/helpers/l10n';
 import { getTask } from '../../../api/ce';
+import { Task } from '../../../types/tasks';
 
 interface Props {
   onClose: () => void;
-  task: Pick<T.Task, 'componentName' | 'id' | 'type'>;
+  task: Pick<Task, 'componentName' | 'id' | 'type'>;
 }
 
 interface State {
index 40123322782b9106c6a3ce534dc281d1499a76b7..c4e9759c48130941f2636153fbb08dbfcfbb2180 100644 (file)
@@ -21,10 +21,11 @@ import * as React from 'react';
 import Modal from 'sonar-ui-common/components/controls/Modal';
 import { translate } from 'sonar-ui-common/helpers/l10n';
 import { getTask } from '../../../api/ce';
+import { Task } from '../../../types/tasks';
 
 interface Props {
   onClose: () => void;
-  task: Pick<T.Task, 'componentName' | 'errorMessage' | 'id' | 'type'>;
+  task: Pick<Task, 'componentName' | 'errorMessage' | 'id' | 'type'>;
 }
 
 interface State {
index ead309a524718c561cb34e892ba3ec18250b870f..08216fecc7ae4db9ddeffaa330efb7b9f4b54171 100644 (file)
@@ -20,6 +20,7 @@
 import * as React from 'react';
 import Select from 'sonar-ui-common/components/controls/Select';
 import { translate } from 'sonar-ui-common/helpers/l10n';
+import { TaskStatuses } from '../../../types/tasks';
 import { STATUSES } from '../constants';
 
 interface Props {
@@ -39,11 +40,11 @@ export default class StatusFilter extends React.PureComponent<Props> {
         value: STATUSES.ALL_EXCEPT_PENDING,
         label: translate('background_task.status.ALL_EXCEPT_PENDING')
       },
-      { value: STATUSES.PENDING, label: translate('background_task.status.PENDING') },
-      { value: STATUSES.IN_PROGRESS, label: translate('background_task.status.IN_PROGRESS') },
-      { value: STATUSES.SUCCESS, label: translate('background_task.status.SUCCESS') },
-      { value: STATUSES.FAILED, label: translate('background_task.status.FAILED') },
-      { value: STATUSES.CANCELED, label: translate('background_task.status.CANCELED') }
+      { value: TaskStatuses.Pending, label: translate('background_task.status.PENDING') },
+      { value: TaskStatuses.InProgress, label: translate('background_task.status.IN_PROGRESS') },
+      { value: TaskStatuses.Success, label: translate('background_task.status.SUCCESS') },
+      { value: TaskStatuses.Failed, label: translate('background_task.status.FAILED') },
+      { value: TaskStatuses.Canceled, label: translate('background_task.status.CANCELED') }
     ];
 
     return (
index 77668127438f7c6683ba110f965b7664f8893d31..f0dfb5eb72d108edb3a17a8c14ca6781bf18ff00 100644 (file)
@@ -18,6 +18,7 @@
  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  */
 import * as React from 'react';
+import { Task as ITask } from '../../../types/tasks';
 import TaskActions from './TaskActions';
 import TaskComponent from './TaskComponent';
 import TaskDate from './TaskDate';
@@ -29,10 +30,10 @@ import TaskSubmitter from './TaskSubmitter';
 
 interface Props {
   component?: unknown;
-  onCancelTask: (task: T.Task) => Promise<void>;
-  onFilterTask: (task: T.Task) => void;
-  task: T.Task;
-  previousTask?: T.Task;
+  onCancelTask: (task: ITask) => Promise<void>;
+  onFilterTask: (task: ITask) => void;
+  task: ITask;
+  previousTask?: ITask;
 }
 
 export default function Task(props: Props) {
index f9352185a8557010713f7cf0c6c511ff29a1cf71..9810754e5d5ad878b8e9471ba4081bc003176446 100644 (file)
@@ -24,7 +24,7 @@ import ActionsDropdown, {
 import ConfirmModal from 'sonar-ui-common/components/controls/ConfirmModal';
 import { lazyLoadComponent } from 'sonar-ui-common/components/lazyLoadComponent';
 import { translate, translateWithParameters } from 'sonar-ui-common/helpers/l10n';
-import { STATUSES } from '../constants';
+import { Task, TaskStatuses } from '../../../types/tasks';
 import ScannerContext from './ScannerContext';
 import Stacktrace from './Stacktrace';
 
@@ -35,9 +35,9 @@ const AnalysisWarningsModal = lazyLoadComponent(
 
 interface Props {
   component?: unknown;
-  onCancelTask: (task: T.Task) => Promise<void>;
-  onFilterTask: (task: T.Task) => void;
-  task: T.Task;
+  onCancelTask: (task: Task) => Promise<void>;
+  onFilterTask: (task: Task) => void;
+  task: Task;
 }
 
 interface State {
@@ -99,7 +99,7 @@ export default class TaskActions extends React.PureComponent<Props, State> {
     const { component, task } = this.props;
 
     const canFilter = component === undefined;
-    const canCancel = task.status === STATUSES.PENDING;
+    const canCancel = task.status === TaskStatuses.Pending;
     const canShowStacktrace = task.errorMessage !== undefined;
     const canShowWarnings = task.warningCount !== undefined && task.warningCount > 0;
     const hasActions =
index 18a7ffb43220ec51998182ea4fc2be8b7e6f0d61..dde40b7a8b05e5438b13d68976ecf2b8d5d2981a 100644 (file)
@@ -30,10 +30,11 @@ import {
   getPullRequestUrl
 } from '../../../helpers/urls';
 import { isPortfolioLike } from '../../../types/component';
+import { Task } from '../../../types/tasks';
 import TaskType from './TaskType';
 
 interface Props {
-  task: T.Task;
+  task: Task;
 }
 
 export default function TaskComponent({ task }: Props) {
@@ -84,7 +85,7 @@ export default function TaskComponent({ task }: Props) {
   );
 }
 
-function getTaskComponentUrl(componentKey: string, task: T.Task) {
+function getTaskComponentUrl(componentKey: string, task: Task) {
   if (isPortfolioLike(task.componentQualifier)) {
     return getPortfolioUrl(componentKey);
   } else if (task.branch) {
index cceca1369400ddd7b2461897aff252bb5668658a..0caddd28efb720d2df6236eafcc57622797ea087 100644 (file)
@@ -20,7 +20,7 @@
 import * as React from 'react';
 import PendingIcon from 'sonar-ui-common/components/icons/PendingIcon';
 import { translate } from 'sonar-ui-common/helpers/l10n';
-import { STATUSES } from '../constants';
+import { TaskStatuses } from '../../../types/tasks';
 
 interface Props {
   status: string;
@@ -30,23 +30,23 @@ export default function TaskStatus({ status }: Props) {
   let inner;
 
   switch (status) {
-    case STATUSES.PENDING:
+    case TaskStatuses.Pending:
       inner = <PendingIcon />;
       break;
-    case STATUSES.IN_PROGRESS:
+    case TaskStatuses.InProgress:
       inner = <i className="spinner" />;
       break;
-    case STATUSES.SUCCESS:
+    case TaskStatuses.Success:
       inner = (
         <span className="badge badge-success">{translate('background_task.status.SUCCESS')}</span>
       );
       break;
-    case STATUSES.FAILED:
+    case TaskStatuses.Failed:
       inner = (
         <span className="badge badge-error">{translate('background_task.status.FAILED')}</span>
       );
       break;
-    case STATUSES.CANCELED:
+    case TaskStatuses.Canceled:
       inner = <span className="badge">{translate('background_task.status.CANCELED')}</span>;
       break;
     default:
index 8847b78e37b8e1ba21f9b8f5d56b71fa33df75ba..60d234862c9d38accae400b0b90de66a4bab1728 100644 (file)
 import * as classNames from 'classnames';
 import * as React from 'react';
 import { translate } from 'sonar-ui-common/helpers/l10n';
+import { Task as ITask } from '../../../types/tasks';
 import Task from './Task';
 
 interface Props {
-  tasks: T.Task[];
+  tasks: ITask[];
   component?: unknown;
   loading: boolean;
-  onCancelTask: (task: T.Task) => Promise<void>;
-  onFilterTask: (task: T.Task) => void;
+  onCancelTask: (task: ITask) => Promise<void>;
+  onFilterTask: (task: ITask) => void;
 }
 
 export default function Tasks({ tasks, component, loading, onCancelTask, onFilterTask }: Props) {
index 8b98bfbb492771a7081be166419cade53ec9f76e..8bca2905acc46e58d027104b0a245fe203ff85ba 100644 (file)
@@ -20,6 +20,8 @@
 import { shallow } from 'enzyme';
 import * as React from 'react';
 import { click } from 'sonar-ui-common/helpers/testUtils';
+import { mockTask } from '../../../../helpers/mocks/tasks';
+import { TaskTypes } from '../../../../types/tasks';
 import ScannerContext from '../ScannerContext';
 
 jest.mock('../../../../api/ce', () => ({
@@ -28,11 +30,11 @@ jest.mock('../../../../api/ce', () => ({
 
 const getTask = require('../../../../api/ce').getTask as jest.Mock<any>;
 
-const task = {
+const task = mockTask({
   componentName: 'foo',
   id: '123',
-  type: 'REPORT'
-};
+  type: TaskTypes.Report
+});
 
 beforeEach(() => {
   getTask.mockClear();
index 95dd1749b4a010247f339f4ca0257497410a33f3..22b4df23d4832b0d9eae336d1642a9171d8c8302 100644 (file)
@@ -20,6 +20,8 @@
 import { shallow } from 'enzyme';
 import * as React from 'react';
 import { click } from 'sonar-ui-common/helpers/testUtils';
+import { mockTask } from '../../../../helpers/mocks/tasks';
+import { TaskTypes } from '../../../../types/tasks';
 import Stacktrace from '../Stacktrace';
 
 jest.mock('../../../../api/ce', () => ({
@@ -28,11 +30,11 @@ jest.mock('../../../../api/ce', () => ({
 
 const getTask = require('../../../../api/ce').getTask as jest.Mock<any>;
 
-const task = {
+const task = mockTask({
   componentName: 'foo',
   id: '123',
-  type: 'REPORT'
-};
+  type: TaskTypes.Report
+});
 
 beforeEach(() => {
   getTask.mockClear();
index f49bc154670dd4b1a748d613c7f6ccf290ea65cb..2de844d30599008ab0382cfd7a6e98be3bf480e0 100644 (file)
  */
 import { shallow } from 'enzyme';
 import * as React from 'react';
+import { mockTask } from '../../../../helpers/mocks/tasks';
 import Task from '../Task';
 
 it('renders', () => {
   expect(
-    shallow(
-      <Task
-        onCancelTask={jest.fn()}
-        onFilterTask={jest.fn()}
-        task={{
-          componentName: 'foo',
-          id: '123',
-          organization: 'org',
-          status: 'PENDING',
-          submittedAt: '2017-01-01',
-          submitterLogin: 'yoda',
-          type: 'REPORT'
-        }}
-      />
-    )
+    shallow(<Task onCancelTask={jest.fn()} onFilterTask={jest.fn()} task={mockTask()} />)
   ).toMatchSnapshot();
 });
index 4842ce74854532d50d91901e5d501628a3bccc39..00679184af545311bf06ed21c83bcac2060f5899 100644 (file)
 import { shallow } from 'enzyme';
 import * as React from 'react';
 import { click } from 'sonar-ui-common/helpers/testUtils';
+import { mockTask } from '../../../../helpers/mocks/tasks';
+import { Task, TaskStatuses } from '../../../../types/tasks';
 import TaskActions from '../TaskActions';
 
 it('renders', () => {
   expect(shallowRender()).toMatchSnapshot();
-  expect(shallowRender({ status: 'SUCCESS' })).toMatchSnapshot();
+  expect(shallowRender({ status: TaskStatuses.Success })).toMatchSnapshot();
   expect(shallowRender({ hasScannerContext: true })).toMatchSnapshot();
   expect(shallowRender({ errorMessage: 'error!' })).toMatchSnapshot();
   expect(shallowRender({}, { component: { key: 'foo' } })).toMatchSnapshot();
@@ -57,20 +59,12 @@ it('shows warnings', () => {
   expect(wrapper.find('AnalysisWarningsModal').exists()).toBe(false);
 });
 
-function shallowRender(fields?: Partial<T.Task>, props?: Partial<TaskActions['props']>) {
+function shallowRender(fields?: Partial<Task>, props?: Partial<TaskActions['props']>) {
   return shallow(
     <TaskActions
       onCancelTask={jest.fn()}
       onFilterTask={jest.fn()}
-      task={{
-        componentName: 'foo',
-        status: 'PENDING',
-        id: '123',
-        organization: 'org',
-        submittedAt: '2017-01-01',
-        type: 'REPORT',
-        ...fields
-      }}
+      task={mockTask({ ...fields })}
       {...props}
     />
   );
index 13477c7d4dc86c9ff509a44ad6a65720a0739044..b76153e4303f33d7200ddd96150c9b9e279a5b0f 100644 (file)
@@ -19,7 +19,9 @@
  */
 import { shallow } from 'enzyme';
 import * as React from 'react';
+import { mockTask } from '../../../../helpers/mocks/tasks';
 import { ComponentQualifier } from '../../../../types/component';
+import { Task } from '../../../../types/tasks';
 import TaskComponent from '../TaskComponent';
 
 it('renders correctly', () => {
@@ -33,17 +35,6 @@ it('renders correctly', () => {
   expect(shallowRender({ pullRequest: 'pr-89' })).toMatchSnapshot('pull request');
 });
 
-function shallowRender(taskOverrides: Partial<T.Task> = {}) {
-  const TASK = {
-    componentKey: 'foo',
-    componentName: 'foo',
-    componentQualifier: 'TRK',
-    id: 'bar',
-    organization: 'org',
-    status: 'PENDING',
-    submittedAt: '2017-01-01',
-    submitterLogin: 'yoda',
-    type: 'REPORT'
-  };
-  return shallow(<TaskComponent task={{ ...TASK, ...taskOverrides }} />);
+function shallowRender(taskOverrides: Partial<Task> = {}) {
+  return shallow(<TaskComponent task={mockTask({ ...taskOverrides })} />);
 }
index fc95e82d35c74ab941cea426a39e0df29b53a537..54747921035389c3ee1eecdb39fff799b970d01e 100644 (file)
@@ -8,33 +8,33 @@ exports[`renders 1`] = `
   <TaskComponent
     task={
       Object {
-        "componentName": "foo",
-        "id": "123",
-        "organization": "org",
+        "analysisId": "x123",
+        "componentKey": "foo",
+        "componentName": "Foo",
+        "componentQualifier": "TRK",
+        "id": "AXR8jg_0mF2ZsYr8Wzs2",
+        "organization": "bar",
         "status": "PENDING",
-        "submittedAt": "2017-01-01",
-        "submitterLogin": "yoda",
+        "submittedAt": "2020-09-11T11:45:35+0200",
         "type": "REPORT",
       }
     }
   />
   <TaskId
-    id="123"
-  />
-  <TaskSubmitter
-    submitter="yoda"
+    id="AXR8jg_0mF2ZsYr8Wzs2"
   />
+  <TaskSubmitter />
   <TaskDay
-    submittedAt="2017-01-01"
+    submittedAt="2020-09-11T11:45:35+0200"
   />
   <TaskDate
-    date="2017-01-01"
+    date="2020-09-11T11:45:35+0200"
   />
   <TaskDate
-    baseDate="2017-01-01"
+    baseDate="2020-09-11T11:45:35+0200"
   />
   <TaskDate
-    baseDate="2017-01-01"
+    baseDate="2020-09-11T11:45:35+0200"
   />
   <TaskExecutionTime />
   <TaskActions
@@ -42,12 +42,14 @@ exports[`renders 1`] = `
     onFilterTask={[MockFunction]}
     task={
       Object {
-        "componentName": "foo",
-        "id": "123",
-        "organization": "org",
+        "analysisId": "x123",
+        "componentKey": "foo",
+        "componentName": "Foo",
+        "componentQualifier": "TRK",
+        "id": "AXR8jg_0mF2ZsYr8Wzs2",
+        "organization": "bar",
         "status": "PENDING",
-        "submittedAt": "2017-01-01",
-        "submitterLogin": "yoda",
+        "submittedAt": "2020-09-11T11:45:35+0200",
         "type": "REPORT",
       }
     }
index 0d460cfddc07a337b1da00309ef0f7416d2db60b..9da384c60c4ee6896da1829d254c198eaf0f423a 100644 (file)
@@ -11,7 +11,7 @@ exports[`renders 1`] = `
       className="js-task-filter"
       onClick={[Function]}
     >
-      background_tasks.filter_by_component_x.foo
+      background_tasks.filter_by_component_x.Foo
     </ActionsDropdownItem>
     <ActionsDropdownItem
       className="js-task-cancel"
@@ -35,7 +35,7 @@ exports[`renders 2`] = `
       className="js-task-filter"
       onClick={[Function]}
     >
-      background_tasks.filter_by_component_x.foo
+      background_tasks.filter_by_component_x.Foo
     </ActionsDropdownItem>
   </ActionsDropdown>
 </td>
@@ -52,7 +52,7 @@ exports[`renders 3`] = `
       className="js-task-filter"
       onClick={[Function]}
     >
-      background_tasks.filter_by_component_x.foo
+      background_tasks.filter_by_component_x.Foo
     </ActionsDropdownItem>
     <ActionsDropdownItem
       className="js-task-cancel"
@@ -82,7 +82,7 @@ exports[`renders 4`] = `
       className="js-task-filter"
       onClick={[Function]}
     >
-      background_tasks.filter_by_component_x.foo
+      background_tasks.filter_by_component_x.Foo
     </ActionsDropdownItem>
     <ActionsDropdownItem
       className="js-task-cancel"
@@ -124,12 +124,15 @@ exports[`shows scanner context 1`] = `
   onClose={[Function]}
   task={
     Object {
-      "componentName": "foo",
+      "analysisId": "x123",
+      "componentKey": "foo",
+      "componentName": "Foo",
+      "componentQualifier": "TRK",
       "hasScannerContext": true,
-      "id": "123",
-      "organization": "org",
+      "id": "AXR8jg_0mF2ZsYr8Wzs2",
+      "organization": "bar",
       "status": "PENDING",
-      "submittedAt": "2017-01-01",
+      "submittedAt": "2020-09-11T11:45:35+0200",
       "type": "REPORT",
     }
   }
@@ -141,12 +144,15 @@ exports[`shows stack trace 1`] = `
   onClose={[Function]}
   task={
     Object {
-      "componentName": "foo",
+      "analysisId": "x123",
+      "componentKey": "foo",
+      "componentName": "Foo",
+      "componentQualifier": "TRK",
       "errorMessage": "error!",
-      "id": "123",
-      "organization": "org",
+      "id": "AXR8jg_0mF2ZsYr8Wzs2",
+      "organization": "bar",
       "status": "PENDING",
-      "submittedAt": "2017-01-01",
+      "submittedAt": "2020-09-11T11:45:35+0200",
       "type": "REPORT",
     }
   }
@@ -156,6 +162,6 @@ exports[`shows stack trace 1`] = `
 exports[`shows warnings 1`] = `
 <AnalysisWarningsModal
   onClose={[Function]}
-  taskId="123"
+  taskId="AXR8jg_0mF2ZsYr8Wzs2"
 />
 `;
index c6704006123f0cf6ebb9045f6df1fe498c872f17..271ad4cfde2404dea09f1f1efb2a335db2112df8 100644 (file)
@@ -10,7 +10,7 @@ exports[`renders correctly 1`] = `
     />
   </span>
   <Connect(Organization)
-    organizationKey="org"
+    organizationKey="bar"
   />
   <Link
     className="spacer-right"
@@ -26,7 +26,7 @@ exports[`renders correctly 1`] = `
       }
     }
   >
-    foo
+    Foo
   </Link>
   <TaskType
     type="REPORT"
@@ -40,7 +40,7 @@ exports[`renders correctly: branch 1`] = `
     className="little-spacer-right"
   />
   <Connect(Organization)
-    organizationKey="org"
+    organizationKey="bar"
   />
   <Link
     className="spacer-right"
@@ -56,7 +56,7 @@ exports[`renders correctly: branch 1`] = `
       }
     }
   >
-    foo
+    Foo
     <span
       className="text-limited text-text-top"
       title="feature"
@@ -86,7 +86,7 @@ exports[`renders correctly: branch 2`] = `
     className="little-spacer-right"
   />
   <Connect(Organization)
-    organizationKey="org"
+    organizationKey="bar"
   />
   <Link
     className="spacer-right"
@@ -102,7 +102,7 @@ exports[`renders correctly: branch 2`] = `
       }
     }
   >
-    foo
+    Foo
     <span
       className="text-limited text-text-top"
       title="branch-6.7"
@@ -136,7 +136,7 @@ exports[`renders correctly: portfolio 1`] = `
     />
   </span>
   <Connect(Organization)
-    organizationKey="org"
+    organizationKey="bar"
   />
   <Link
     className="spacer-right"
@@ -151,7 +151,7 @@ exports[`renders correctly: portfolio 1`] = `
       }
     }
   >
-    foo
+    Foo
   </Link>
   <TaskType
     type="REPORT"
@@ -165,7 +165,7 @@ exports[`renders correctly: pull request 1`] = `
     className="little-spacer-right"
   />
   <Connect(Organization)
-    organizationKey="org"
+    organizationKey="bar"
   />
   <Link
     className="spacer-right"
@@ -181,7 +181,7 @@ exports[`renders correctly: pull request 1`] = `
       }
     }
   >
-    foo
+    Foo
     <span
       className="text-limited text-text-top"
     >
@@ -209,7 +209,7 @@ exports[`renders correctly: undefined key 1`] = `
   <span
     className="note"
   >
-    bar
+    AXR8jg_0mF2ZsYr8Wzs2
   </span>
   <TaskType
     type="REPORT"
index ec685551027a28c6df90a5fc709d151694c803e6..1b91567b066d5b454439a809a86fdfb765e26f44 100644 (file)
@@ -21,19 +21,9 @@ import { Query } from './utils';
 
 export const STATUSES = {
   ALL: '__ALL__',
-  ALL_EXCEPT_PENDING: '__ALL_EXCEPT_PENDING__',
-  PENDING: 'PENDING',
-  IN_PROGRESS: 'IN_PROGRESS',
-  SUCCESS: 'SUCCESS',
-  FAILED: 'FAILED',
-  CANCELED: 'CANCELED'
+  ALL_EXCEPT_PENDING: '__ALL_EXCEPT_PENDING__'
 };
 
-export enum BackgroundTaskTypes {
-  Report = 'REPORT',
-  IssueSync = 'ISSUE_SYNC'
-}
-
 export const ALL_TYPES = 'ALL_TYPES';
 
 export const CURRENTS = {
index 35c4aae2c4dc743700db6af17411d14d16ca5028..da855ab68ce18226e99a1c3c63e3d37b841ab7a4 100644 (file)
@@ -18,6 +18,7 @@
  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  */
 import { toShortNotSoISOString } from 'sonar-ui-common/helpers/dates';
+import { Task, TaskStatuses } from '../../types/tasks';
 import { ALL_TYPES, CURRENTS, STATUSES } from './constants';
 
 export interface Query {
@@ -29,7 +30,7 @@ export interface Query {
   taskType: string;
 }
 
-export function updateTask(tasks: T.Task[], newTask: T.Task) {
+export function updateTask(tasks: Task[], newTask: Task) {
   return tasks.map(task => (task.id === newTask.id ? newTask : task));
 }
 
@@ -38,18 +39,18 @@ export function mapFiltersToParameters(filters: Partial<Query> = {}) {
 
   if (filters.status === STATUSES.ALL) {
     parameters.status = [
-      STATUSES.PENDING,
-      STATUSES.IN_PROGRESS,
-      STATUSES.SUCCESS,
-      STATUSES.FAILED,
-      STATUSES.CANCELED
+      TaskStatuses.Pending,
+      TaskStatuses.InProgress,
+      TaskStatuses.Success,
+      TaskStatuses.Failed,
+      TaskStatuses.Canceled
     ].join();
   } else if (filters.status === STATUSES.ALL_EXCEPT_PENDING) {
     parameters.status = [
-      STATUSES.IN_PROGRESS,
-      STATUSES.SUCCESS,
-      STATUSES.FAILED,
-      STATUSES.CANCELED
+      TaskStatuses.InProgress,
+      TaskStatuses.Success,
+      TaskStatuses.Failed,
+      TaskStatuses.Canceled
     ].join();
   } else {
     parameters.status = filters.status;
diff --git a/server/sonar-web/src/main/js/helpers/mocks/tasks.ts b/server/sonar-web/src/main/js/helpers/mocks/tasks.ts
new file mode 100644 (file)
index 0000000..db0c6b0
--- /dev/null
@@ -0,0 +1,36 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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 { ComponentQualifier } from '../../types/component';
+import { Task, TaskStatuses, TaskTypes } from '../../types/tasks';
+
+export function mockTask(overrides: Partial<Task> = {}): Task {
+  return {
+    analysisId: 'x123',
+    componentKey: 'foo',
+    componentName: 'Foo',
+    componentQualifier: ComponentQualifier.Project,
+    id: 'AXR8jg_0mF2ZsYr8Wzs2',
+    organization: 'bar',
+    status: TaskStatuses.Pending,
+    submittedAt: '2020-09-11T11:45:35+0200',
+    type: TaskTypes.Report,
+    ...overrides
+  };
+}
diff --git a/server/sonar-web/src/main/js/types/tasks.ts b/server/sonar-web/src/main/js/types/tasks.ts
new file mode 100644 (file)
index 0000000..8efac5a
--- /dev/null
@@ -0,0 +1,60 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 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.
+ */
+
+export enum TaskTypes {
+  Report = 'REPORT',
+  IssueSync = 'ISSUE_SYNC'
+}
+
+export enum TaskStatuses {
+  Pending = 'PENDING',
+  InProgress = 'IN_PROGRESS',
+  Success = 'SUCCESS',
+  Failed = 'FAILED',
+  Canceled = 'CANCELED'
+}
+
+export interface Task {
+  analysisId?: string;
+  branch?: string;
+  componentKey?: string;
+  componentName?: string;
+  componentQualifier?: string;
+  errorMessage?: string;
+  errorStacktrace?: string;
+  errorType?: string;
+  executedAt?: string;
+  executionTimeMs?: number;
+  hasErrorStacktrace?: boolean;
+  hasScannerContext?: boolean;
+  id: string;
+  logs?: boolean;
+  organization: string;
+  pullRequest?: string;
+  pullRequestTitle?: string;
+  scannerContext?: string;
+  startedAt?: string;
+  status: TaskStatuses;
+  submittedAt: string;
+  submitterLogin?: string;
+  type: TaskTypes;
+  warningCount?: number;
+  warnings?: string[];
+}
index 687fb81f70a0dd7be1e0564010dec145fba06e46..3128665d16143f75323fe1ade1bf960001ce1768 100644 (file)
@@ -917,34 +917,6 @@ declare namespace T {
     | 'DB_MIGRATION_NEEDED'
     | 'DB_MIGRATION_RUNNING';
 
-  export interface Task {
-    analysisId?: string;
-    branch?: string;
-    componentKey?: string;
-    componentName?: string;
-    componentQualifier?: string;
-    errorMessage?: string;
-    errorStacktrace?: string;
-    errorType?: string;
-    executedAt?: string;
-    executionTimeMs?: number;
-    hasErrorStacktrace?: boolean;
-    hasScannerContext?: boolean;
-    id: string;
-    logs?: boolean;
-    organization: string;
-    pullRequest?: string;
-    pullRequestTitle?: string;
-    scannerContext?: string;
-    startedAt?: string;
-    status: string;
-    submittedAt: string;
-    submitterLogin?: string;
-    type: string;
-    warningCount?: number;
-    warnings?: string[];
-  }
-
   export interface TestCase {
     coveredLines: number;
     durationInMs: number;