aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-web/src
diff options
context:
space:
mode:
authorWouter Admiraal <wouter.admiraal@sonarsource.com>2020-09-14 15:40:23 +0200
committersonartech <sonartech@sonarsource.com>2020-09-29 20:07:42 +0000
commit626469caaa8b060f79f101cffff214d23c7e611b (patch)
treece4793e5b9fc7cad42b76adb6c82ffb6bf37251e /server/sonar-web/src
parentdae0f392c72132be88af4a73d98875fdf477de50 (diff)
downloadsonarqube-626469caaa8b060f79f101cffff214d23c7e611b.tar.gz
sonarqube-626469caaa8b060f79f101cffff214d23c7e611b.zip
Update background task related types
Diffstat (limited to 'server/sonar-web/src')
-rw-r--r--server/sonar-web/src/main/js/api/ce.ts9
-rw-r--r--server/sonar-web/src/main/js/app/components/ComponentContainer.tsx18
-rw-r--r--server/sonar-web/src/main/js/app/components/__tests__/ComponentContainer-test.tsx13
-rw-r--r--server/sonar-web/src/main/js/app/components/indexation/IndexationNotificationRenderer.tsx6
-rw-r--r--server/sonar-web/src/main/js/app/components/nav/component/ComponentNav.tsx6
-rw-r--r--server/sonar-web/src/main/js/app/components/nav/component/ComponentNavBgTaskNotif.tsx5
-rw-r--r--server/sonar-web/src/main/js/app/components/nav/component/ComponentNavLicenseNotif.tsx3
-rw-r--r--server/sonar-web/src/main/js/app/components/nav/component/__tests__/ComponentNavBgTaskNotif-test.tsx85
-rw-r--r--server/sonar-web/src/main/js/app/components/nav/component/__tests__/ComponentNavLicenseNotif-test.tsx28
-rw-r--r--server/sonar-web/src/main/js/app/components/nav/component/__tests__/__snapshots__/ComponentNavBgTaskNotif-test.tsx.snap78
-rw-r--r--server/sonar-web/src/main/js/apps/background-tasks/__tests__/BackgroundTasks-test.tsx12
-rw-r--r--server/sonar-web/src/main/js/apps/background-tasks/components/BackgroundTasksApp.tsx11
-rw-r--r--server/sonar-web/src/main/js/apps/background-tasks/components/Footer.tsx3
-rw-r--r--server/sonar-web/src/main/js/apps/background-tasks/components/ScannerContext.tsx3
-rw-r--r--server/sonar-web/src/main/js/apps/background-tasks/components/Stacktrace.tsx3
-rw-r--r--server/sonar-web/src/main/js/apps/background-tasks/components/StatusFilter.tsx11
-rw-r--r--server/sonar-web/src/main/js/apps/background-tasks/components/Task.tsx9
-rw-r--r--server/sonar-web/src/main/js/apps/background-tasks/components/TaskActions.tsx10
-rw-r--r--server/sonar-web/src/main/js/apps/background-tasks/components/TaskComponent.tsx5
-rw-r--r--server/sonar-web/src/main/js/apps/background-tasks/components/TaskStatus.tsx12
-rw-r--r--server/sonar-web/src/main/js/apps/background-tasks/components/Tasks.tsx7
-rw-r--r--server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/ScannerContext-test.tsx8
-rw-r--r--server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/Stacktrace-test.tsx8
-rw-r--r--server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/Task-test.tsx17
-rw-r--r--server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/TaskActions-test.tsx16
-rw-r--r--server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/TaskComponent-test.tsx17
-rw-r--r--server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/__snapshots__/Task-test.tsx.snap38
-rw-r--r--server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/__snapshots__/TaskActions-test.tsx.snap32
-rw-r--r--server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/__snapshots__/TaskComponent-test.tsx.snap22
-rw-r--r--server/sonar-web/src/main/js/apps/background-tasks/constants.ts12
-rw-r--r--server/sonar-web/src/main/js/apps/background-tasks/utils.ts21
-rw-r--r--server/sonar-web/src/main/js/helpers/mocks/tasks.ts36
-rw-r--r--server/sonar-web/src/main/js/types/tasks.ts60
-rw-r--r--server/sonar-web/src/main/js/types/types.d.ts28
34 files changed, 354 insertions, 298 deletions
diff --git a/server/sonar-web/src/main/js/api/ce.ts b/server/sonar-web/src/main/js/api/ce.ts
index a4d1a03a5ca..e2b9a1f846c 100644
--- a/server/sonar-web/src/main/js/api/ce.ts
+++ b/server/sonar-web/src/main/js/api/ce.ts
@@ -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);
}
diff --git a/server/sonar-web/src/main/js/app/components/ComponentContainer.tsx b/server/sonar-web/src/main/js/app/components/ComponentContainer.tsx
index 82d48a415ba..dc540a9b5b4 100644
--- a/server/sonar-web/src/main/js/app/components/ComponentContainer.tsx
+++ b/server/sonar-web/src/main/js/app/components/ComponentContainer.tsx
@@ -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;
diff --git a/server/sonar-web/src/main/js/app/components/__tests__/ComponentContainer-test.tsx b/server/sonar-web/src/main/js/app/components/__tests__/ComponentContainer-test.tsx
index d96dc9a6d24..0a23c044138 100644
--- a/server/sonar-web/src/main/js/app/components/__tests__/ComponentContainer-test.tsx
+++ b/server/sonar-web/src/main/js/app/components/__tests__/ComponentContainer-test.tsx
@@ -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
diff --git a/server/sonar-web/src/main/js/app/components/indexation/IndexationNotificationRenderer.tsx b/server/sonar-web/src/main/js/app/components/indexation/IndexationNotificationRenderer.tsx
index a945219678f..bd828e91ba7 100644
--- a/server/sonar-web/src/main/js/app/components/indexation/IndexationNotificationRenderer.tsx
+++ b/server/sonar-web/src/main/js/app/components/indexation/IndexationNotificationRenderer.tsx
@@ -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}
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 ceeae0dbbf6..1e0f7fb0455 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
@@ -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}
diff --git a/server/sonar-web/src/main/js/app/components/nav/component/ComponentNavBgTaskNotif.tsx b/server/sonar-web/src/main/js/app/components/nav/component/ComponentNavBgTaskNotif.tsx
index c0da78bb3cc..3454c4c7464 100644
--- a/server/sonar-web/src/main/js/app/components/nav/component/ComponentNavBgTaskNotif.tsx
+++ b/server/sonar-web/src/main/js/app/components/nav/component/ComponentNavBgTaskNotif.tsx
@@ -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)
diff --git a/server/sonar-web/src/main/js/app/components/nav/component/ComponentNavLicenseNotif.tsx b/server/sonar-web/src/main/js/app/components/nav/component/ComponentNavLicenseNotif.tsx
index 3c97fa52d3e..348468a05cb 100644
--- a/server/sonar-web/src/main/js/app/components/nav/component/ComponentNavLicenseNotif.tsx
+++ b/server/sonar-web/src/main/js/app/components/nav/component/ComponentNavLicenseNotif.tsx
@@ -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 {
diff --git a/server/sonar-web/src/main/js/app/components/nav/component/__tests__/ComponentNavBgTaskNotif-test.tsx b/server/sonar-web/src/main/js/app/components/nav/component/__tests__/ComponentNavBgTaskNotif-test.tsx
index c9f9c14c727..39dfcd2d3b2 100644
--- a/server/sonar-web/src/main/js/app/components/nav/component/__tests__/ComponentNavBgTaskNotif-test.tsx
+++ b/server/sonar-web/src/main/js/app/components/nav/component/__tests__/ComponentNavBgTaskNotif-test.tsx
@@ -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}
/>
);
diff --git a/server/sonar-web/src/main/js/app/components/nav/component/__tests__/ComponentNavLicenseNotif-test.tsx b/server/sonar-web/src/main/js/app/components/nav/component/__tests__/ComponentNavLicenseNotif-test.tsx
index 390f667121b..a4786387181 100644
--- a/server/sonar-web/src/main/js/app/components/nav/component/__tests__/ComponentNavLicenseNotif-test.tsx
+++ b/server/sonar-web/src/main/js/app/components/nav/component/__tests__/ComponentNavLicenseNotif-test.tsx
@@ -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}
/>
);
diff --git a/server/sonar-web/src/main/js/app/components/nav/component/__tests__/__snapshots__/ComponentNavBgTaskNotif-test.tsx.snap b/server/sonar-web/src/main/js/app/components/nav/component/__tests__/__snapshots__/ComponentNavBgTaskNotif-test.tsx.snap
index 75e4cbb58f0..dad46cb8300 100644
--- a/server/sonar-web/src/main/js/app/components/nav/component/__tests__/__snapshots__/ComponentNavBgTaskNotif-test.tsx.snap
+++ b/server/sonar-web/src/main/js/app/components/nav/component/__tests__/__snapshots__/ComponentNavBgTaskNotif-test.tsx.snap
@@ -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>
+`;
diff --git a/server/sonar-web/src/main/js/apps/background-tasks/__tests__/BackgroundTasks-test.tsx b/server/sonar-web/src/main/js/apps/background-tasks/__tests__/BackgroundTasks-test.tsx
index 2e4410f064f..531899a4228 100644
--- a/server/sonar-web/src/main/js/apps/background-tasks/__tests__/BackgroundTasks-test.tsx
+++ b/server/sonar-web/src/main/js/apps/background-tasks/__tests__/BackgroundTasks-test.tsx
@@ -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,
diff --git a/server/sonar-web/src/main/js/apps/background-tasks/components/BackgroundTasksApp.tsx b/server/sonar-web/src/main/js/apps/background-tasks/components/BackgroundTasksApp.tsx
index aad93b01500..ade7100f7c9 100644
--- a/server/sonar-web/src/main/js/apps/background-tasks/components/BackgroundTasksApp.tsx
+++ b/server/sonar-web/src/main/js/apps/background-tasks/components/BackgroundTasksApp.tsx
@@ -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
});
};
diff --git a/server/sonar-web/src/main/js/apps/background-tasks/components/Footer.tsx b/server/sonar-web/src/main/js/apps/background-tasks/components/Footer.tsx
index c8469c0148e..55b6bbf6f6c 100644
--- a/server/sonar-web/src/main/js/apps/background-tasks/components/Footer.tsx
+++ b/server/sonar-web/src/main/js/apps/background-tasks/components/Footer.tsx
@@ -19,11 +19,12 @@
*/
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) {
diff --git a/server/sonar-web/src/main/js/apps/background-tasks/components/ScannerContext.tsx b/server/sonar-web/src/main/js/apps/background-tasks/components/ScannerContext.tsx
index 7192adffa45..9d6f6db227a 100644
--- a/server/sonar-web/src/main/js/apps/background-tasks/components/ScannerContext.tsx
+++ b/server/sonar-web/src/main/js/apps/background-tasks/components/ScannerContext.tsx
@@ -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 {
diff --git a/server/sonar-web/src/main/js/apps/background-tasks/components/Stacktrace.tsx b/server/sonar-web/src/main/js/apps/background-tasks/components/Stacktrace.tsx
index 40123322782..c4e9759c481 100644
--- a/server/sonar-web/src/main/js/apps/background-tasks/components/Stacktrace.tsx
+++ b/server/sonar-web/src/main/js/apps/background-tasks/components/Stacktrace.tsx
@@ -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 {
diff --git a/server/sonar-web/src/main/js/apps/background-tasks/components/StatusFilter.tsx b/server/sonar-web/src/main/js/apps/background-tasks/components/StatusFilter.tsx
index ead309a5247..08216fecc7a 100644
--- a/server/sonar-web/src/main/js/apps/background-tasks/components/StatusFilter.tsx
+++ b/server/sonar-web/src/main/js/apps/background-tasks/components/StatusFilter.tsx
@@ -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 (
diff --git a/server/sonar-web/src/main/js/apps/background-tasks/components/Task.tsx b/server/sonar-web/src/main/js/apps/background-tasks/components/Task.tsx
index 77668127438..f0dfb5eb72d 100644
--- a/server/sonar-web/src/main/js/apps/background-tasks/components/Task.tsx
+++ b/server/sonar-web/src/main/js/apps/background-tasks/components/Task.tsx
@@ -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) {
diff --git a/server/sonar-web/src/main/js/apps/background-tasks/components/TaskActions.tsx b/server/sonar-web/src/main/js/apps/background-tasks/components/TaskActions.tsx
index f9352185a85..9810754e5d5 100644
--- a/server/sonar-web/src/main/js/apps/background-tasks/components/TaskActions.tsx
+++ b/server/sonar-web/src/main/js/apps/background-tasks/components/TaskActions.tsx
@@ -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 =
diff --git a/server/sonar-web/src/main/js/apps/background-tasks/components/TaskComponent.tsx b/server/sonar-web/src/main/js/apps/background-tasks/components/TaskComponent.tsx
index 18a7ffb4322..dde40b7a8b0 100644
--- a/server/sonar-web/src/main/js/apps/background-tasks/components/TaskComponent.tsx
+++ b/server/sonar-web/src/main/js/apps/background-tasks/components/TaskComponent.tsx
@@ -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) {
diff --git a/server/sonar-web/src/main/js/apps/background-tasks/components/TaskStatus.tsx b/server/sonar-web/src/main/js/apps/background-tasks/components/TaskStatus.tsx
index cceca136940..0caddd28efb 100644
--- a/server/sonar-web/src/main/js/apps/background-tasks/components/TaskStatus.tsx
+++ b/server/sonar-web/src/main/js/apps/background-tasks/components/TaskStatus.tsx
@@ -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:
diff --git a/server/sonar-web/src/main/js/apps/background-tasks/components/Tasks.tsx b/server/sonar-web/src/main/js/apps/background-tasks/components/Tasks.tsx
index 8847b78e37b..60d234862c9 100644
--- a/server/sonar-web/src/main/js/apps/background-tasks/components/Tasks.tsx
+++ b/server/sonar-web/src/main/js/apps/background-tasks/components/Tasks.tsx
@@ -20,14 +20,15 @@
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) {
diff --git a/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/ScannerContext-test.tsx b/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/ScannerContext-test.tsx
index 8b98bfbb492..8bca2905acc 100644
--- a/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/ScannerContext-test.tsx
+++ b/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/ScannerContext-test.tsx
@@ -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();
diff --git a/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/Stacktrace-test.tsx b/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/Stacktrace-test.tsx
index 95dd1749b4a..22b4df23d48 100644
--- a/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/Stacktrace-test.tsx
+++ b/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/Stacktrace-test.tsx
@@ -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();
diff --git a/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/Task-test.tsx b/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/Task-test.tsx
index f49bc154670..2de844d3059 100644
--- a/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/Task-test.tsx
+++ b/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/Task-test.tsx
@@ -19,24 +19,11 @@
*/
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();
});
diff --git a/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/TaskActions-test.tsx b/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/TaskActions-test.tsx
index 4842ce74854..00679184af5 100644
--- a/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/TaskActions-test.tsx
+++ b/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/TaskActions-test.tsx
@@ -20,11 +20,13 @@
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}
/>
);
diff --git a/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/TaskComponent-test.tsx b/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/TaskComponent-test.tsx
index 13477c7d4dc..b76153e4303 100644
--- a/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/TaskComponent-test.tsx
+++ b/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/TaskComponent-test.tsx
@@ -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 })} />);
}
diff --git a/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/__snapshots__/Task-test.tsx.snap b/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/__snapshots__/Task-test.tsx.snap
index fc95e82d35c..54747921035 100644
--- a/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/__snapshots__/Task-test.tsx.snap
+++ b/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/__snapshots__/Task-test.tsx.snap
@@ -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",
}
}
diff --git a/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/__snapshots__/TaskActions-test.tsx.snap b/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/__snapshots__/TaskActions-test.tsx.snap
index 0d460cfddc0..9da384c60c4 100644
--- a/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/__snapshots__/TaskActions-test.tsx.snap
+++ b/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/__snapshots__/TaskActions-test.tsx.snap
@@ -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"
/>
`;
diff --git a/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/__snapshots__/TaskComponent-test.tsx.snap b/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/__snapshots__/TaskComponent-test.tsx.snap
index c6704006123..271ad4cfde2 100644
--- a/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/__snapshots__/TaskComponent-test.tsx.snap
+++ b/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/__snapshots__/TaskComponent-test.tsx.snap
@@ -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"
diff --git a/server/sonar-web/src/main/js/apps/background-tasks/constants.ts b/server/sonar-web/src/main/js/apps/background-tasks/constants.ts
index ec685551027..1b91567b066 100644
--- a/server/sonar-web/src/main/js/apps/background-tasks/constants.ts
+++ b/server/sonar-web/src/main/js/apps/background-tasks/constants.ts
@@ -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 = {
diff --git a/server/sonar-web/src/main/js/apps/background-tasks/utils.ts b/server/sonar-web/src/main/js/apps/background-tasks/utils.ts
index 35c4aae2c4d..da855ab68ce 100644
--- a/server/sonar-web/src/main/js/apps/background-tasks/utils.ts
+++ b/server/sonar-web/src/main/js/apps/background-tasks/utils.ts
@@ -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
index 00000000000..db0c6b08569
--- /dev/null
+++ b/server/sonar-web/src/main/js/helpers/mocks/tasks.ts
@@ -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
index 00000000000..8efac5a7f2b
--- /dev/null
+++ b/server/sonar-web/src/main/js/types/tasks.ts
@@ -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[];
+}
diff --git a/server/sonar-web/src/main/js/types/types.d.ts b/server/sonar-web/src/main/js/types/types.d.ts
index 687fb81f70a..3128665d161 100644
--- a/server/sonar-web/src/main/js/types/types.d.ts
+++ b/server/sonar-web/src/main/js/types/types.d.ts
@@ -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;