From ba6ee4d6696aa45cdc4b684b7aaa49e71401f3e7 Mon Sep 17 00:00:00 2001 From: Aurelien Poscia Date: Thu, 22 Dec 2022 10:01:18 +0100 Subject: [PATCH] SONAR-14128 display node name in background tasks for DCE --- .../__tests__/BackgroundTasks-it.tsx | 57 ++++++++++++++++++- .../apps/background-tasks/components/Task.tsx | 7 ++- .../components/TaskNodeName.tsx | 32 +++++++++++ .../background-tasks/components/Tasks.tsx | 12 +++- .../__tests__/BackgroundTasksApp-test.tsx | 1 + .../BackgroundTasksApp-test.tsx.snap | 3 +- server/sonar-web/src/main/js/types/tasks.ts | 1 + .../resources/org/sonar/l10n/core.properties | 1 + 8 files changed, 108 insertions(+), 6 deletions(-) create mode 100644 server/sonar-web/src/main/js/apps/background-tasks/components/TaskNodeName.tsx diff --git a/server/sonar-web/src/main/js/apps/background-tasks/__tests__/BackgroundTasks-it.tsx b/server/sonar-web/src/main/js/apps/background-tasks/__tests__/BackgroundTasks-it.tsx index 266237abc2d..d4c410b9f3a 100644 --- a/server/sonar-web/src/main/js/apps/background-tasks/__tests__/BackgroundTasks-it.tsx +++ b/server/sonar-web/src/main/js/apps/background-tasks/__tests__/BackgroundTasks-it.tsx @@ -22,7 +22,9 @@ import { screen, waitFor, within } from '@testing-library/react'; import userEvent from '@testing-library/user-event'; import { UserEvent } from '@testing-library/user-event/dist/types/setup/setup'; import ComputeEngineServiceMock from '../../../api/mocks/ComputeEngineServiceMock'; -import { renderAppWithAdminContext } from '../../../helpers/testReactTestingUtils'; +import { mockAppState } from '../../../helpers/testMocks'; +import { renderAppWithAdminContext, RenderContext } from '../../../helpers/testReactTestingUtils'; +import { EditionKey } from '../../../types/editions'; import { TaskStatuses, TaskTypes } from '../../../types/tasks'; import routes from '../routes'; @@ -141,6 +143,36 @@ describe('The Global background task page', () => { expect(await screen.findAllByRole('row')).toHaveLength(2); }); + it.each([[EditionKey.community], [EditionKey.developer], [EditionKey.enterprise]])( + 'Editions %s should not display node name', + async (editionKey: EditionKey) => { + givenOneTaskWithoutNodeNameAndOneWithNodeName(); + + renderGlobalBackgroundTasksApp({ appState: mockAppState({ edition: editionKey }) }); + + await waitFor(() => { + expect(screen.getAllByRole('row')).toHaveLength(3); // including header + }); + + expect(screen.queryByText('background_tasks.table.nodeName')).not.toBeInTheDocument(); + expect(screen.queryByText('best_node_ever')).not.toBeInTheDocument(); + } + ); + + it('Node name should be shown in DCE edition', async () => { + givenOneTaskWithoutNodeNameAndOneWithNodeName(); + + renderGlobalBackgroundTasksApp({ appState: mockAppState({ edition: EditionKey.datacenter }) }); + + await waitFor(async () => { + expect(await screen.findByText('background_tasks.table.nodeName')).toBeInTheDocument(); + }); + + expect( + within(await screen.getAllByRole('row')[1]).getByText('best_node_ever') + ).toBeInTheDocument(); + }); + it('should handle task pagination', async () => { const user = userEvent.setup(); @@ -167,11 +199,30 @@ describe('The Global background task page', () => { */ }); +function givenOneTaskWithoutNodeNameAndOneWithNodeName() { + computeEngineServiceMock.clearTasks(); + computeEngineServiceMock.addTask({ + executedAt: '2022-02-03T11:45:36+0200', + submittedAt: '2022-02-03T11:45:35+0200', + executionTimeMs: 167, + status: TaskStatuses.InProgress, + type: TaskTypes.IssueSync, + nodeName: 'best_node_ever', + }); + computeEngineServiceMock.addTask({ + executedAt: '2022-02-03T11:45:35+0200', + submittedAt: '2022-02-03T11:45:34+0200', + executionTimeMs: 167, + status: TaskStatuses.InProgress, + type: TaskTypes.IssueSync, + }); +} + async function changeTaskFilter(user: UserEvent, fieldLabel: string, value: string) { await user.click(screen.getByLabelText(fieldLabel, { selector: 'input' })); await user.click(screen.getByText(value)); } -function renderGlobalBackgroundTasksApp() { - renderAppWithAdminContext('admin/background_tasks', routes, {}); +function renderGlobalBackgroundTasksApp(context: RenderContext = {}) { + renderAppWithAdminContext('admin/background_tasks', routes, context); } 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 cf18ecb12d5..a1c1baead8d 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,8 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ import * as React from 'react'; +import { AppState } from '../../../types/appstate'; +import { EditionKey } from '../../../types/editions'; import { Task as ITask } from '../../../types/tasks'; import TaskActions from './TaskActions'; import TaskComponent from './TaskComponent'; @@ -25,6 +27,7 @@ import TaskDate from './TaskDate'; import TaskDay from './TaskDay'; import TaskExecutionTime from './TaskExecutionTime'; import TaskId from './TaskId'; +import TaskNodeName from './TaskNodeName'; import TaskStatus from './TaskStatus'; import TaskSubmitter from './TaskSubmitter'; @@ -34,10 +37,11 @@ interface Props { onFilterTask: (task: ITask) => void; task: ITask; previousTask?: ITask; + appState: AppState; } export default function Task(props: Props) { - const { task, component, onCancelTask, onFilterTask, previousTask } = props; + const { task, component, onCancelTask, onFilterTask, previousTask, appState } = props; return ( @@ -45,6 +49,7 @@ export default function Task(props: Props) { + {appState?.edition === EditionKey.datacenter && } +
{nodeName}
+ + ); +} 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 987bcff59dd..1947785f0c8 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 @@ -19,7 +19,10 @@ */ import classNames from 'classnames'; import * as React from 'react'; +import withAppStateContext from '../../../app/components/app-state/withAppStateContext'; import { translate } from '../../../helpers/l10n'; +import { AppState } from '../../../types/appstate'; +import { EditionKey } from '../../../types/editions'; import { Task as ITask } from '../../../types/tasks'; import Task from './Task'; @@ -29,9 +32,10 @@ interface Props { loading: boolean; onCancelTask: (task: ITask) => Promise; onFilterTask: (task: ITask) => void; + appState: AppState; } -export default function Tasks({ tasks, component, loading, onCancelTask, onFilterTask }: Props) { +export function Tasks({ tasks, component, loading, onCancelTask, onFilterTask, appState }: Props) { const className = classNames('data zebra zebra-hover background-tasks', { 'new-loading': loading, }); @@ -45,6 +49,9 @@ export default function Tasks({ tasks, component, loading, onCancelTask, onFilte {translate('background_tasks.table.task')} {translate('background_tasks.table.id')} {translate('background_tasks.table.submitter')} + {appState?.edition === EditionKey.datacenter && ( + {translate('background_tasks.table.nodeName')} + )}   {translate('background_tasks.table.submitted')} {translate('background_tasks.table.started')} @@ -62,6 +69,7 @@ export default function Tasks({ tasks, component, loading, onCancelTask, onFilte onFilterTask={onFilterTask} previousTask={index > 0 ? tasks[index - 1] : undefined} task={task} + appState={appState} /> ))} @@ -69,3 +77,5 @@ export default function Tasks({ tasks, component, loading, onCancelTask, onFilte ); } + +export default withAppStateContext(Tasks); diff --git a/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/BackgroundTasksApp-test.tsx b/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/BackgroundTasksApp-test.tsx index bce1ed12fe0..04fd4c55d47 100644 --- a/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/BackgroundTasksApp-test.tsx +++ b/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/BackgroundTasksApp-test.tsx @@ -33,6 +33,7 @@ jest.mock('../../../../api/ce', () => ({ { id: 'AWkGcOThOiAPiP5AE-kM', type: 'VIEW_REFRESH', + nodeName: 'node_CE_server_1', componentId: 'AWBLZYhGOUrjxRA-u6ex', componentKey: 'sonar-csharp', componentName: 'SonarC#', diff --git a/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/__snapshots__/BackgroundTasksApp-test.tsx.snap b/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/__snapshots__/BackgroundTasksApp-test.tsx.snap index 2789a48d441..afb200f89f2 100644 --- a/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/__snapshots__/BackgroundTasksApp-test.tsx.snap +++ b/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/__snapshots__/BackgroundTasksApp-test.tsx.snap @@ -116,7 +116,7 @@ exports[`should render correctly: loaded 1`] = ` } } /> -