From f6f294fa869fe92235e7d9a45753ffded454e74c Mon Sep 17 00:00:00 2001 From: 7PH Date: Fri, 14 Apr 2023 16:48:36 +0200 Subject: [PATCH] SONAR-18423 Migrate background tasks app to RTL --- .../js/api/mocks/ComputeEngineServiceMock.ts | 12 + .../__tests__/BackgroundTasks-it.tsx | 244 ++++++++++++----- ...ackgroundTasks-test.tsx => utils-test.tsx} | 44 ---- .../components/BackgroundTasksApp.tsx | 5 +- .../components/ScannerContext.tsx | 10 +- .../components/Stacktrace.tsx | 10 +- .../components/StatPendingCount.tsx | 4 +- .../components/TaskActions.tsx | 5 +- .../__tests__/BackgroundTasksApp-test.tsx | 100 ------- .../__tests__/NoWorkersSupportPopup-test.tsx | 26 -- .../__tests__/ScannerContext-test.tsx | 62 ----- .../components/__tests__/Stacktrace-test.tsx | 62 ----- .../__tests__/StatPendingCount-test.tsx | 59 ----- .../__tests__/StatPendingTime-test.tsx | 41 --- .../__tests__/StatStillFailing-test.tsx | 47 ---- .../components/__tests__/TaskActions-test.tsx | 71 ----- .../__tests__/TaskComponent-test.tsx | 40 --- .../components/__tests__/TaskDate-test.tsx | 33 --- .../components/__tests__/TaskStatus-test.tsx | 30 --- .../components/__tests__/Workers-test.tsx | 71 ----- .../components/__tests__/WorkersForm-test.tsx | 51 ---- .../BackgroundTasksApp-test.tsx.snap | 200 -------------- .../NoWorkersSupportPopup-test.tsx.snap | 26 -- .../ScannerContext-test.tsx.snap | 42 --- .../__snapshots__/Stacktrace-test.tsx.snap | 49 ---- .../StatPendingCount-test.tsx.snap | 26 -- .../StatPendingTime-test.tsx.snap | 20 -- .../StatStillFailing-test.tsx.snap | 40 --- .../__snapshots__/TaskActions-test.tsx.snap | 166 ------------ .../__snapshots__/TaskComponent-test.tsx.snap | 179 ------------- .../__snapshots__/TaskDate-test.tsx.snap | 45 ---- .../__snapshots__/TaskStatus-test.tsx.snap | 55 ---- .../__snapshots__/Workers-test.tsx.snap | 245 ------------------ .../__snapshots__/WorkersForm-test.tsx.snap | 207 --------------- .../resources/org/sonar/l10n/core.properties | 1 + 35 files changed, 205 insertions(+), 2123 deletions(-) rename server/sonar-web/src/main/js/apps/background-tasks/__tests__/{BackgroundTasks-test.tsx => utils-test.tsx} (56%) delete mode 100644 server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/BackgroundTasksApp-test.tsx delete mode 100644 server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/NoWorkersSupportPopup-test.tsx delete mode 100644 server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/ScannerContext-test.tsx delete mode 100644 server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/Stacktrace-test.tsx delete mode 100644 server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/StatPendingCount-test.tsx delete mode 100644 server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/StatPendingTime-test.tsx delete mode 100644 server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/StatStillFailing-test.tsx delete mode 100644 server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/TaskActions-test.tsx delete mode 100644 server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/TaskComponent-test.tsx delete mode 100644 server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/TaskDate-test.tsx delete mode 100644 server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/TaskStatus-test.tsx delete mode 100644 server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/Workers-test.tsx delete mode 100644 server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/WorkersForm-test.tsx delete mode 100644 server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/__snapshots__/BackgroundTasksApp-test.tsx.snap delete mode 100644 server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/__snapshots__/NoWorkersSupportPopup-test.tsx.snap delete mode 100644 server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/__snapshots__/ScannerContext-test.tsx.snap delete mode 100644 server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/__snapshots__/Stacktrace-test.tsx.snap delete mode 100644 server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/__snapshots__/StatPendingCount-test.tsx.snap delete mode 100644 server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/__snapshots__/StatPendingTime-test.tsx.snap delete mode 100644 server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/__snapshots__/StatStillFailing-test.tsx.snap delete mode 100644 server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/__snapshots__/TaskActions-test.tsx.snap delete mode 100644 server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/__snapshots__/TaskComponent-test.tsx.snap delete mode 100644 server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/__snapshots__/TaskDate-test.tsx.snap delete mode 100644 server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/__snapshots__/TaskStatus-test.tsx.snap delete mode 100644 server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/__snapshots__/Workers-test.tsx.snap delete mode 100644 server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/__snapshots__/WorkersForm-test.tsx.snap diff --git a/server/sonar-web/src/main/js/api/mocks/ComputeEngineServiceMock.ts b/server/sonar-web/src/main/js/api/mocks/ComputeEngineServiceMock.ts index 531acde76b4..d892eda5901 100644 --- a/server/sonar-web/src/main/js/api/mocks/ComputeEngineServiceMock.ts +++ b/server/sonar-web/src/main/js/api/mocks/ComputeEngineServiceMock.ts @@ -28,6 +28,7 @@ import { cancelTask, getActivity, getStatus, + getTask, getTypes, getWorkers, setWorkerCount, @@ -65,6 +66,7 @@ export default class ComputeEngineServiceMock { (getActivity as jest.Mock).mockImplementation(this.handleGetActivity); (getStatus as jest.Mock).mockImplementation(this.handleGetStatus); (getTypes as jest.Mock).mockImplementation(this.handleGetTypes); + (getTask as jest.Mock).mockImplementation(this.handleGetTask); (getWorkers as jest.Mock).mockImplementation(this.handleGetWorkers); (setWorkerCount as jest.Mock).mockImplementation(this.handleSetWorkerCount); @@ -165,6 +167,16 @@ export default class ComputeEngineServiceMock { handleGetTypes = () => Promise.resolve([...TASK_TYPES]); + handleGetTask = (id: string) => { + const task = this.tasks.find((t) => t.id === id); + + if (task) { + return Promise.resolve(task); + } + + return Promise.reject(); + }; + handleGetWorkers = () => Promise.resolve({ ...this.workers }); handleSetWorkerCount = (count: number) => { 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 30da2bf09f7..2db1eb701ce 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 @@ -19,39 +19,32 @@ */ 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 { byLabelText, byPlaceholderText, byRole, byText } from 'testing-library-selector'; import ComputeEngineServiceMock from '../../../api/mocks/ComputeEngineServiceMock'; import { mockAppState } from '../../../helpers/testMocks'; -import { renderAppWithAdminContext, RenderContext } from '../../../helpers/testReactTestingUtils'; +import { RenderContext, renderAppWithAdminContext } from '../../../helpers/testReactTestingUtils'; import { EditionKey } from '../../../types/editions'; import { TaskStatuses, TaskTypes } from '../../../types/tasks'; import routes from '../routes'; jest.mock('../../../api/ce'); -jest.mock('../constants', () => { - const contants = jest.requireActual('../constants'); - - return { ...contants, PAGE_SIZE: 9 }; -}); - -let computeEngineServiceMock: ComputeEngineServiceMock; +const computeEngineServiceMock = new ComputeEngineServiceMock(); beforeAll(() => { - computeEngineServiceMock = new ComputeEngineServiceMock(); + computeEngineServiceMock.reset(); }); afterEach(() => computeEngineServiceMock.reset()); describe('The Global background task page', () => { it('should display the list of workers and allow edit', async () => { - const user = userEvent.setup(); + const { ui, user } = getPageObject(); renderGlobalBackgroundTasksApp(); + await ui.appLoaded(); - expect( - within(await screen.findByText('background_tasks.number_of_workers')).getByText('2') - ).toBeInTheDocument(); + expect(within(ui.numberOfWorkers.get()).getByText('2')).toBeInTheDocument(); const editWorkersButton = screen.getByRole('button', { name: 'background_tasks.change_number_of_workers', @@ -76,13 +69,11 @@ describe('The Global background task page', () => { await user.click(within(modal).getByRole('button', { name: 'save' })); - expect( - within(await screen.findByText('background_tasks.number_of_workers')).getByText('4') - ).toBeInTheDocument(); + expect(within(ui.numberOfWorkers.get()).getByText('4')).toBeInTheDocument(); }); it('should display the list of tasks', async () => { - const user = userEvent.setup(); + const { ui, user } = getPageObject(); computeEngineServiceMock.clearTasks(); computeEngineServiceMock.addTask({ status: TaskStatuses.Canceled, type: TaskTypes.AppRefresh }); @@ -102,57 +93,54 @@ describe('The Global background task page', () => { }); renderGlobalBackgroundTasksApp(); + await ui.appLoaded(); - expect( - await screen.findByRole('heading', { name: 'background_tasks.page' }) - ).toBeInTheDocument(); + expect(ui.pageHeading.get()).toBeInTheDocument(); - expect(screen.getAllByRole('row')).toHaveLength(5); // including header, excluding pending (default filter) + expect(ui.getAllRows()).toHaveLength(4); - await changeTaskFilter(user, 'status', 'background_task.status.IN_PROGRESS'); - expect(await screen.findAllByRole('row')).toHaveLength(2); // including header + await ui.changeTaskFilter('status', 'background_task.status.IN_PROGRESS'); + expect(ui.getAllRows()).toHaveLength(1); - await changeTaskFilter(user, 'status', 'background_task.status.ALL'); - expect(await screen.findAllByRole('row')).toHaveLength(6); // including header + await ui.changeTaskFilter('status', 'background_task.status.ALL'); + expect(ui.getAllRows()).toHaveLength(5); - await changeTaskFilter(user, 'type', `background_task.type.${TaskTypes.AppRefresh}`); - expect(await screen.findAllByRole('row')).toHaveLength(4); // including header + await ui.changeTaskFilter('type', `background_task.type.${TaskTypes.AppRefresh}`); + expect(ui.getAllRows()).toHaveLength(3); - await user.click(screen.getByRole('checkbox', { name: 'yes' })); - expect(await screen.findAllByRole('row')).toHaveLength(3); // including header - await user.click(screen.getByRole('checkbox', { name: 'yes' })); + await user.click(ui.onlyLatestAnalysis.get()); + expect(ui.getAllRows()).toHaveLength(2); + await user.click(ui.onlyLatestAnalysis.get()); /* * Must test date range filters, but it requires refactoring the DateRange component */ - - const searchBox = screen.getByPlaceholderText('background_tasks.search_by_task_or_component'); - expect(searchBox).toBeInTheDocument(); - await user.click(searchBox); + await user.click(ui.search.get()); await user.keyboard('other'); - expect(await screen.findAllByRole('row')).toHaveLength(2); // including header + expect(ui.getAllRows()).toHaveLength(1); - //reset filters - await user.click(screen.getByRole('button', { name: 'reset_verb' })); - expect(screen.getAllByRole('row')).toHaveLength(5); + // Reset filters + await user.click(ui.resetFilters.get()); + expect(ui.getAllRows()).toHaveLength(4); - // reset tasks (internally) and reload: + // Reset tasks (internally) and reload: computeEngineServiceMock.reset(); - await changeTaskFilter(user, 'status', 'background_task.status.ALL'); - await user.click(screen.getByRole('button', { name: 'reload' })); - expect(await screen.findAllByRole('row')).toHaveLength(2); + await ui.changeTaskFilter('status', 'background_task.status.ALL'); + await user.click(ui.reloadButton.get()); + expect(ui.getAllRows()).toHaveLength(1); }); it.each([[EditionKey.community], [EditionKey.developer], [EditionKey.enterprise]])( - 'Editions %s should not display node name', + '%s should not display node name', async (editionKey: EditionKey) => { + const { ui } = getPageObject(); givenOneTaskWithoutNodeNameAndOneWithNodeName(); renderGlobalBackgroundTasksApp({ appState: mockAppState({ edition: editionKey }) }); await waitFor(() => { - expect(screen.getAllByRole('row')).toHaveLength(3); // including header + expect(ui.getAllRows()).toHaveLength(2); }); expect(screen.queryByText('background_tasks.table.nodeName')).not.toBeInTheDocument(); @@ -160,44 +148,126 @@ describe('The Global background task page', () => { } ); - it('Node name should be shown in DCE edition', async () => { + it('DCE edition should display node name', async () => { + const { ui } = getPageObject(); givenOneTaskWithoutNodeNameAndOneWithNodeName(); renderGlobalBackgroundTasksApp({ appState: mockAppState({ edition: EditionKey.datacenter }) }); + await ui.appLoaded(); - await waitFor(async () => { - expect(await screen.findByText('background_tasks.table.nodeName')).toBeInTheDocument(); - }); + expect(screen.getByText('background_tasks.table.nodeName')).toBeInTheDocument(); - expect( - within(await screen.getAllByRole('row')[1]).getByText('best_node_ever') - ).toBeInTheDocument(); + expect(within(ui.getAllRows()[0]).getByText('best_node_ever')).toBeInTheDocument(); }); it('should handle task pagination', async () => { - const user = userEvent.setup(); + const { ui, user } = getPageObject(); computeEngineServiceMock.clearTasks(); - computeEngineServiceMock.createTasks(10); + computeEngineServiceMock.createTasks(101); renderGlobalBackgroundTasksApp(); + await ui.appLoaded(); - expect( - await screen.findByRole('heading', { name: 'background_tasks.page' }) - ).toBeInTheDocument(); + expect(ui.pageHeading.get()).toBeInTheDocument(); - expect(screen.getAllByRole('row')).toHaveLength(10); // including header + expect(ui.getAllRows()).toHaveLength(100); - user.click(screen.getByRole('button', { name: 'show_more' })); + user.click(ui.showMoreButton.get()); await waitFor(() => { - expect(screen.getAllByRole('row')).toHaveLength(11); // including header + expect(ui.getAllRows()).toHaveLength(101); + }); + }); + + it('should filter using row list', async () => { + const { ui, user } = getPageObject(); + + computeEngineServiceMock.clearTasks(); + computeEngineServiceMock.addTask({ status: TaskStatuses.Success }); + computeEngineServiceMock.addTask({ + status: TaskStatuses.Failed, + errorMessage: 'FooError', + errorStacktrace: 'FooStackTrace', + }); + computeEngineServiceMock.addTask({ + status: TaskStatuses.Failed, + warningCount: 2, + warnings: ['FooWarning1', 'FooWarning2'], + }); + computeEngineServiceMock.addTask({ + status: TaskStatuses.Success, + hasScannerContext: true, + scannerContext: 'FooScannerContext', }); + computeEngineServiceMock.addTask({ + componentKey: 'otherComponent', + status: TaskStatuses.Success, + }); + + renderGlobalBackgroundTasksApp(); + await ui.appLoaded(); + + // Filter by first task component + expect(ui.getAllRows()).toHaveLength(5); + await ui.clickOnTaskAction(0, 'background_tasks.filter_by_component_x.Foo'); + expect(ui.getAllRows()).toHaveLength(4); + + // Show second task error + await user.click(ui.resetFilters.get()); + await ui.clickOnTaskAction(1, 'background_tasks.show_stacktrace'); + expect(within(screen.getByRole('dialog')).getByText('FooStackTrace')).toBeInTheDocument(); + await user.click(screen.getByRole('button', { name: 'close' })); + + // Show third task warnings + await user.click(ui.resetFilters.get()); + await ui.clickOnTaskAction(2, 'background_tasks.show_warnings'); + expect(within(screen.getByRole('dialog')).getByText('FooWarning1')).toBeInTheDocument(); + expect(within(screen.getByRole('dialog')).getByText('FooWarning2')).toBeInTheDocument(); + await user.click(screen.getByRole('button', { name: 'close' })); + + // Show fourth task scanner context + await user.click(ui.resetFilters.get()); + await ui.clickOnTaskAction(3, 'background_tasks.show_scanner_context'); + expect(within(screen.getByRole('dialog')).getByText('FooScannerContext')).toBeInTheDocument(); + await user.click(screen.getByRole('button', { name: 'close' })); }); - /* - * Must also test row actions - */ + it('should cancel all pending tasks', async () => { + const { ui, user } = getPageObject(); + + computeEngineServiceMock.clearTasks(); + computeEngineServiceMock.addTask({ + status: TaskStatuses.Pending, + }); + computeEngineServiceMock.addTask({ + status: TaskStatuses.Pending, + }); + computeEngineServiceMock.addTask({ + status: TaskStatuses.Success, + }); + + renderGlobalBackgroundTasksApp({ + appState: mockAppState({ canAdmin: true }), + }); + await ui.appLoaded(); + + // Pending tasks should not be shown by default + expect(ui.getAllRows()).toHaveLength(1); + + // Verify two pending tasks are shown when filtering by pending + await ui.changeTaskFilter('status', 'background_task.status.PENDING'); + expect(ui.getAllRows()).toHaveLength(2); + + // Cancel all tasks + await user.click(ui.cancelAllButton.get()); + await user.click(ui.cancelAllButtonConfirm.get()); + expect(ui.getAllRows()).toHaveLength(0); + + // Go back to default filter, all tasks should now be shown + await ui.changeTaskFilter('status', 'background_task.status.ALL_EXCEPT_PENDING'); + expect(ui.getAllRows()).toHaveLength(3); + }); }); function givenOneTaskWithoutNodeNameAndOneWithNodeName() { @@ -219,9 +289,51 @@ function givenOneTaskWithoutNodeNameAndOneWithNodeName() { }); } -async function changeTaskFilter(user: UserEvent, fieldLabel: string, value: string) { - await user.click(screen.getByLabelText(fieldLabel, { selector: 'input' })); - await user.click(screen.getByText(value)); +function getPageObject() { + const user = userEvent.setup(); + + const selectors = { + loading: byLabelText('loading'), + pageHeading: byRole('heading', { name: 'background_tasks.page' }), + numberOfWorkers: byText('background_tasks.number_of_workers'), + onlyLatestAnalysis: byRole('checkbox', { name: 'yes' }), + search: byPlaceholderText('background_tasks.search_by_task_or_component'), + resetFilters: byRole('button', { name: 'reset_verb' }), + showMoreButton: byRole('button', { name: 'show_more' }), + reloadButton: byRole('button', { name: 'reload' }), + cancelAllButton: byRole('button', { description: 'background_tasks.cancel_all_tasks' }), + cancelAllButtonConfirm: byText('background_tasks.cancel_all_tasks.submit'), + row: byRole('row'), + }; + + const ui = { + ...selectors, + + appLoaded: async () => { + await waitFor(() => { + expect(selectors.loading.query()).not.toBeInTheDocument(); + }); + }, + + getAllRows: () => screen.getAllByRole('row').slice(1), // Excludes header + + changeTaskFilter: async (fieldLabel: string, value: string) => { + await user.click(screen.getByLabelText(fieldLabel, { selector: 'input' })); + await user.click(screen.getByText(value)); + }, + + clickOnTaskAction: async (rowIndex: number, label: string) => { + const row = ui.getAllRows()[rowIndex]; + expect(row).toBeVisible(); + await user.click(within(row).getByRole('button', { name: 'background_tasks.show_actions' })); + await user.click(within(row).getByRole('button', { name: label })); + }, + }; + + return { + ui, + user, + }; } function renderGlobalBackgroundTasksApp(context: RenderContext = {}) { 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__/utils-test.tsx similarity index 56% rename from server/sonar-web/src/main/js/apps/background-tasks/__tests__/BackgroundTasks-test.tsx rename to server/sonar-web/src/main/js/apps/background-tasks/__tests__/utils-test.tsx index bf64405bcae..51834814ebc 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__/utils-test.tsx @@ -17,52 +17,8 @@ * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -import { shallow } from 'enzyme'; -import * as React from 'react'; -import { click } from '../../../helpers/testUtils'; -import Search from '../components/Search'; -import { DEFAULT_FILTERS } from '../constants'; import { formatDuration } from '../utils'; -describe('Search', () => { - const defaultProps: Search['props'] = { - ...DEFAULT_FILTERS, - loading: false, - types: [], - onFilterUpdate: () => true, - onReload: () => true, - maxExecutedAt: undefined, - minSubmittedAt: undefined, - }; - - it('should render search form', () => { - const component = shallow(); - expect(component.find('SearchBox').exists()).toBe(true); - }); - - it('should not render search form', () => { - const component = shallow(); - expect(component.find('SearchBox').exists()).toBe(false); - }); - - it('should search', () => { - const searchSpy = jest.fn(); - const component = shallow(); - const searchInput = component.find('SearchBox'); - searchInput.prop('onChange')('some search query'); - expect(searchSpy).toHaveBeenCalledWith({ query: 'some search query' }); - }); - - it('should reload', () => { - const reloadSpy = jest.fn(); - const component = shallow(); - const reloadButton = component.find('.js-reload'); - expect(reloadSpy).not.toHaveBeenCalled(); - click(reloadButton); - expect(reloadSpy).toHaveBeenCalled(); - }); -}); - describe('Helpers', () => { describe('#formatDuration()', () => { it('should format 173ms', () => { 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 0b37e713584..7d8d47d5f7c 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 @@ -31,6 +31,7 @@ import withComponentContext from '../../../app/components/componentContext/withC import ListFooter from '../../../components/controls/ListFooter'; import Suggestions from '../../../components/embed-docs-modal/Suggestions'; import { Location, Router, withRouter } from '../../../components/hoc/withRouter'; +import DeferredSpinner from '../../../components/ui/DeferredSpinner'; import { toShortNotSoISOString } from '../../../helpers/dates'; import { translate } from '../../../helpers/l10n'; import { parseAsDate } from '../../../helpers/query'; @@ -38,7 +39,7 @@ import { Task, TaskStatuses } from '../../../types/tasks'; import { Component, Paging, RawQuery } from '../../../types/types'; import '../background-tasks.css'; import { CURRENTS, DEBOUNCE_DELAY, DEFAULT_FILTERS, PAGE_SIZE } from '../constants'; -import { mapFiltersToParameters, Query, updateTask } from '../utils'; +import { Query, mapFiltersToParameters, updateTask } from '../utils'; import Header from './Header'; import Search from './Search'; import Stats from './Stats'; @@ -217,7 +218,7 @@ export class BackgroundTasksApp extends React.PureComponent { return (
- +
); } 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 d9dd53769e0..a63cd07032e 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 @@ -20,6 +20,7 @@ import * as React from 'react'; import { getTask } from '../../../api/ce'; import Modal from '../../../components/controls/Modal'; +import { ResetButtonLink } from '../../../components/controls/buttons'; import { translate } from '../../../helpers/l10n'; import { Task } from '../../../types/tasks'; @@ -53,11 +54,6 @@ export default class ScannerContext extends React.PureComponent { }); } - handleCloseClick = (event: React.SyntheticEvent) => { - event.preventDefault(); - this.props.onClose(); - }; - render() { const { task } = this.props; const { scannerContext } = this.state; @@ -84,9 +80,7 @@ export default class ScannerContext extends React.PureComponent {
- - {translate('close')} - + {translate('close')}
); 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 bb2d6856372..367ad202a30 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 @@ -20,6 +20,7 @@ import * as React from 'react'; import { getTask } from '../../../api/ce'; import Modal from '../../../components/controls/Modal'; +import { ResetButtonLink } from '../../../components/controls/buttons'; import { translate } from '../../../helpers/l10n'; import { Task } from '../../../types/tasks'; @@ -61,11 +62,6 @@ export default class Stacktrace extends React.PureComponent { ); } - handleCloseClick = (event: React.SyntheticEvent) => { - event.preventDefault(); - this.props.onClose(); - }; - render() { const { task } = this.props; const { loading, stacktrace } = this.state; @@ -100,9 +96,9 @@ export default class Stacktrace extends React.PureComponent { ); diff --git a/server/sonar-web/src/main/js/apps/background-tasks/components/StatPendingCount.tsx b/server/sonar-web/src/main/js/apps/background-tasks/components/StatPendingCount.tsx index 68e5a41c530..a6e96160426 100644 --- a/server/sonar-web/src/main/js/apps/background-tasks/components/StatPendingCount.tsx +++ b/server/sonar-web/src/main/js/apps/background-tasks/components/StatPendingCount.tsx @@ -20,9 +20,9 @@ import * as React from 'react'; import withAppStateContext from '../../../app/components/app-state/withAppStateContext'; import { colors } from '../../../app/theme'; -import { ClearButton } from '../../../components/controls/buttons'; import ConfirmButton from '../../../components/controls/ConfirmButton'; import Tooltip from '../../../components/controls/Tooltip'; +import { ClearButton } from '../../../components/controls/buttons'; import { translate } from '../../../helpers/l10n'; import { AppState } from '../../../types/appstate'; @@ -32,7 +32,7 @@ export interface Props { pendingCount?: number; } -export function StatPendingCount({ appState, onCancelAllPending, pendingCount }: Props) { +function StatPendingCount({ appState, onCancelAllPending, pendingCount }: Props) { if (pendingCount === undefined) { return null; } 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 d71c305bb4d..35ade871b49 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 @@ -104,7 +104,10 @@ export default class TaskActions extends React.PureComponent { return ( - + {canFilter && task.componentName && ( {translateWithParameters( 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 deleted file mode 100644 index 83f5a92548f..00000000000 --- a/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/BackgroundTasksApp-test.tsx +++ /dev/null @@ -1,100 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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 { shallow } from 'enzyme'; -import * as React from 'react'; -import { mockComponent } from '../../../../helpers/mocks/component'; -import { mockLocation, mockRouter } from '../../../../helpers/testMocks'; -import { waitAndUpdate } from '../../../../helpers/testUtils'; -import { BackgroundTasksApp } from '../BackgroundTasksApp'; - -jest.mock('../../../../api/ce', () => ({ - getTypes: jest.fn().mockResolvedValue({ - taskTypes: ['REPORT', 'PROJECT_EXPORT', 'PROJECT_IMPORT', 'VIEW_REFRESH'], - }), - getActivity: jest.fn().mockResolvedValue({ - tasks: [ - { - id: 'AWkGcOThOiAPiP5AE-kM', - type: 'VIEW_REFRESH', - nodeName: 'node_CE_server_1', - componentId: 'AWBLZYhGOUrjxRA-u6ex', - componentKey: 'sonar-csharp', - componentName: 'SonarC#', - componentQualifier: 'APP', - status: 'FAILED', - submittedAt: '2019-02-19T16:47:35+0100', - startedAt: '2019-02-19T16:47:36+0100', - executedAt: '2019-02-19T16:47:36+0100', - executionTimeMs: 16, - logs: false, - errorMessage: - 'Analyses suspended. Please set a valid license for the Edition you installed.', - hasScannerContext: false, - errorType: 'LICENSING', - warningCount: 0, - warnings: [], - }, - { - id: 'AWkGcOThOiAPiP5AE-kL', - type: 'VIEW_REFRESH', - componentId: 'AV2ZaHs1Wa2znA6pDz1l', - componentKey: 'c-cpp-build-wrapper', - componentName: 'C/C++ Build Wrapper', - componentQualifier: 'APP', - status: 'SUCCESS', - submittedAt: '2019-02-19T16:47:35+0100', - startedAt: '2019-02-19T16:47:36+0100', - executedAt: '2019-02-19T16:47:36+0100', - executionTimeMs: 19, - logs: false, - hasScannerContext: false, - warningCount: 0, - warnings: [], - }, - ], - paging: { total: 2, pageIndex: 1 }, - }), - getStatus: jest.fn().mockResolvedValue({ pending: 0, failing: 15, inProgress: 0 }), - cancelAllTasks: jest.fn().mockResolvedValue({}), - cancelTask: jest.fn().mockResolvedValue({}), -})); - -beforeEach(() => { - jest.clearAllMocks(); -}); - -it('should render correctly', async () => { - const wrapper = shallowRender(); - expect(wrapper).toMatchSnapshot('initial'); - - await waitAndUpdate(wrapper); - expect(wrapper).toMatchSnapshot('loaded'); -}); - -function shallowRender(props: Partial = {}) { - return shallow( - - ); -} diff --git a/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/NoWorkersSupportPopup-test.tsx b/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/NoWorkersSupportPopup-test.tsx deleted file mode 100644 index 091a1bc7029..00000000000 --- a/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/NoWorkersSupportPopup-test.tsx +++ /dev/null @@ -1,26 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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 { shallow } from 'enzyme'; -import * as React from 'react'; -import NoWorkersSupportPopup from '../NoWorkersSupportPopup'; - -it('should render correctly', () => { - expect(shallow()).toMatchSnapshot(); -}); 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 deleted file mode 100644 index 3cbfa29123d..00000000000 --- a/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/ScannerContext-test.tsx +++ /dev/null @@ -1,62 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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 { shallow } from 'enzyme'; -import * as React from 'react'; -import { mockTask } from '../../../../helpers/mocks/tasks'; -import { click } from '../../../../helpers/testUtils'; -import { TaskTypes } from '../../../../types/tasks'; -import ScannerContext from '../ScannerContext'; - -jest.mock('../../../../api/ce', () => ({ - getTask: jest.fn(() => Promise.resolve({ scannerContext: 'context' })), -})); - -const getTask = require('../../../../api/ce').getTask as jest.Mock; - -const task = mockTask({ - componentName: 'foo', - id: '123', - type: TaskTypes.Report, -}); - -beforeEach(() => { - getTask.mockClear(); -}); - -it('renders', () => { - const wrapper = shallow(); - wrapper.setState({ scannerContext: 'context' }); - expect(wrapper).toMatchSnapshot(); -}); - -it('closes', () => { - const onClose = jest.fn(); - const wrapper = shallow(); - click(wrapper.find('.js-modal-close')); - expect(onClose).toHaveBeenCalled(); -}); - -it('fetches scanner context on mount', async () => { - const wrapper = shallow(); - expect(wrapper.state()).toEqual({}); - expect(getTask).toHaveBeenCalledWith('123', ['scannerContext']); - await new Promise(setImmediate); - expect(wrapper.state()).toEqual({ scannerContext: 'context' }); -}); 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 deleted file mode 100644 index 82a32cf9d45..00000000000 --- a/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/Stacktrace-test.tsx +++ /dev/null @@ -1,62 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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 { shallow } from 'enzyme'; -import * as React from 'react'; -import { mockTask } from '../../../../helpers/mocks/tasks'; -import { click } from '../../../../helpers/testUtils'; -import { TaskTypes } from '../../../../types/tasks'; -import Stacktrace from '../Stacktrace'; - -jest.mock('../../../../api/ce', () => ({ - getTask: jest.fn(() => Promise.resolve({ errorStacktrace: 'stacktrace' })), -})); - -const getTask = require('../../../../api/ce').getTask as jest.Mock; - -const task = mockTask({ - componentName: 'foo', - id: '123', - type: TaskTypes.Report, -}); - -beforeEach(() => { - getTask.mockClear(); -}); - -it('renders', () => { - const wrapper = shallow(); - wrapper.setState({ loading: false, stacktrace: 'stacktrace' }); - expect(wrapper).toMatchSnapshot(); -}); - -it('closes', () => { - const onClose = jest.fn(); - const wrapper = shallow(); - click(wrapper.find('.js-modal-close')); - expect(onClose).toHaveBeenCalled(); -}); - -it('fetches scanner context on mount', async () => { - const wrapper = shallow(); - expect(wrapper.state()).toEqual({ loading: true }); - expect(getTask).toHaveBeenCalledWith('123', ['stacktrace']); - await new Promise(setImmediate); - expect(wrapper.state()).toEqual({ loading: false, stacktrace: 'stacktrace' }); -}); diff --git a/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/StatPendingCount-test.tsx b/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/StatPendingCount-test.tsx deleted file mode 100644 index c096b240a57..00000000000 --- a/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/StatPendingCount-test.tsx +++ /dev/null @@ -1,59 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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 { shallow } from 'enzyme'; -import * as React from 'react'; -import { mockAppState } from '../../../../helpers/testMocks'; -import { Props, StatPendingCount } from '../StatPendingCount'; - -it('should render correctly', () => { - expect(shallowRender()).toMatchSnapshot(); -}); - -it('should not render', () => { - expect(shallowRender({ pendingCount: undefined }).type()).toBeNull(); -}); - -it('should not show cancel pending button', () => { - expect(shallowRender({ pendingCount: 0 }).find('ConfirmButton').exists()).toBe(false); - expect( - shallowRender({ appState: mockAppState({ canAdmin: false }) }) - .find('ConfirmButton') - .exists() - ).toBe(false); -}); - -it('should trigger cancelling pending', () => { - const onCancelAllPending = jest.fn(); - const result = shallowRender({ onCancelAllPending }); - expect(onCancelAllPending).not.toHaveBeenCalled(); - result.find('ConfirmButton').prop('onConfirm')(); - expect(onCancelAllPending).toHaveBeenCalled(); -}); - -function shallowRender(props: Partial = {}) { - return shallow( - - ); -} diff --git a/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/StatPendingTime-test.tsx b/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/StatPendingTime-test.tsx deleted file mode 100644 index 1610f4c1b0b..00000000000 --- a/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/StatPendingTime-test.tsx +++ /dev/null @@ -1,41 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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 { shallow } from 'enzyme'; -import * as React from 'react'; -import StatPendingTime, { Props } from '../StatPendingTime'; - -it('should render correctly', () => { - expect(shallowRender()).toMatchSnapshot(); -}); - -it('should not render', () => { - expect(shallowRender({ pendingCount: undefined }).type()).toBeNull(); - expect(shallowRender({ pendingCount: 0 }).type()).toBeNull(); - expect(shallowRender({ pendingTime: undefined }).type()).toBeNull(); -}); - -it('should not render when pending time is too small', () => { - expect(shallowRender({ pendingTime: 0 }).find('.emphasised-measure').exists()).toBe(false); - expect(shallowRender({ pendingTime: 900 }).find('.emphasised-measure').exists()).toBe(false); -}); - -function shallowRender(props: Partial = {}) { - return shallow(); -} diff --git a/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/StatStillFailing-test.tsx b/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/StatStillFailing-test.tsx deleted file mode 100644 index 9566c7e6ca7..00000000000 --- a/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/StatStillFailing-test.tsx +++ /dev/null @@ -1,47 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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 { shallow } from 'enzyme'; -import * as React from 'react'; -import { click } from '../../../../helpers/testUtils'; -import StatStillFailing, { Props } from '../StatStillFailing'; - -it('should render correctly', () => { - expect(shallowRender()).toMatchSnapshot(); -}); - -it('should not render', () => { - expect(shallowRender({ failingCount: undefined }).type()).toBeNull(); -}); - -it('should render without the filter link', () => { - expect(shallowRender({ failingCount: 0 })).toMatchSnapshot(); -}); - -it('should trigger filtering failures', () => { - const onShowFailing = jest.fn(); - const result = shallowRender({ onShowFailing }); - expect(onShowFailing).not.toHaveBeenCalled(); - click(result.find('ButtonLink')); - expect(onShowFailing).toHaveBeenCalled(); -}); - -function shallowRender(props: Partial = {}) { - return shallow(); -} 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 deleted file mode 100644 index a214e6fa89d..00000000000 --- a/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/TaskActions-test.tsx +++ /dev/null @@ -1,71 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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 { shallow } from 'enzyme'; -import * as React from 'react'; -import { mockTask } from '../../../../helpers/mocks/tasks'; -import { click } from '../../../../helpers/testUtils'; -import { Task, TaskStatuses } from '../../../../types/tasks'; -import TaskActions from '../TaskActions'; - -it('renders', () => { - expect(shallowRender()).toMatchSnapshot(); - expect(shallowRender({ status: TaskStatuses.Success })).toMatchSnapshot(); - expect(shallowRender({ hasScannerContext: true })).toMatchSnapshot(); - expect(shallowRender({ errorMessage: 'error!' })).toMatchSnapshot(); - expect(shallowRender({}, { component: { key: 'foo' } })).toMatchSnapshot(); -}); - -it('shows stack trace', () => { - const wrapper = shallowRender({ errorMessage: 'error!' }); - click(wrapper.find('.js-task-show-stacktrace')); - expect(wrapper.find('Stacktrace')).toMatchSnapshot(); - wrapper.find('Stacktrace').prop('onClose')(); - wrapper.update(); - expect(wrapper.find('Stacktrace').exists()).toBe(false); -}); - -it('shows scanner context', () => { - const wrapper = shallowRender({ hasScannerContext: true }); - click(wrapper.find('.js-task-show-scanner-context')); - expect(wrapper.find('ScannerContext')).toMatchSnapshot(); - wrapper.find('ScannerContext').prop('onClose')(); - wrapper.update(); - expect(wrapper.find('ScannerContext').exists()).toBe(false); -}); - -it('shows warnings', () => { - const wrapper = shallowRender({ warningCount: 2 }); - click(wrapper.find('.js-task-show-warnings')); - expect(wrapper.find('withCurrentUserContext(AnalysisWarningsModal)')).toMatchSnapshot(); - wrapper.find('withCurrentUserContext(AnalysisWarningsModal)').prop('onClose')(); - wrapper.update(); - expect(wrapper.find('withCurrentUserContext(AnalysisWarningsModal)').exists()).toBe(false); -}); - -function shallowRender(fields?: Partial, props?: Partial) { - return shallow( - - ); -} 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 deleted file mode 100644 index a79b2c0b270..00000000000 --- a/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/TaskComponent-test.tsx +++ /dev/null @@ -1,40 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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 { 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', () => { - expect(shallowRender()).toMatchSnapshot(); - expect(shallowRender({ componentKey: undefined })).toMatchSnapshot('undefined key'); - expect(shallowRender({ componentQualifier: ComponentQualifier.Portfolio })).toMatchSnapshot( - 'portfolio' - ); - expect(shallowRender({ branch: 'feature' })).toMatchSnapshot('branch'); - expect(shallowRender({ branch: 'branch-6.7' })).toMatchSnapshot('branch'); - expect(shallowRender({ pullRequest: 'pr-89' })).toMatchSnapshot('pull request'); -}); - -function shallowRender(taskOverrides: Partial = {}) { - return shallow(); -} diff --git a/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/TaskDate-test.tsx b/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/TaskDate-test.tsx deleted file mode 100644 index ea581dea34b..00000000000 --- a/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/TaskDate-test.tsx +++ /dev/null @@ -1,33 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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 { shallow } from 'enzyme'; -import * as React from 'react'; -import TaskDate from '../TaskDate'; - -it('renders', () => { - expect(shallow()).toMatchSnapshot(); - expect(shallow()).toMatchSnapshot(); - expect( - shallow() - ).toMatchSnapshot(); - expect( - shallow() - ).toMatchSnapshot(); -}); diff --git a/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/TaskStatus-test.tsx b/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/TaskStatus-test.tsx deleted file mode 100644 index 9990c576c68..00000000000 --- a/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/TaskStatus-test.tsx +++ /dev/null @@ -1,30 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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 { shallow } from 'enzyme'; -import * as React from 'react'; -import TaskStatus from '../TaskStatus'; - -it('renders', () => { - expect.assertions(5); - const statuses = ['PENDING', 'IN_PROGRESS', 'SUCCESS', 'FAILED', 'CANCELED']; - statuses.forEach((status) => { - expect(shallow()).toMatchSnapshot(); - }); -}); diff --git a/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/Workers-test.tsx b/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/Workers-test.tsx deleted file mode 100644 index 8a0537b6224..00000000000 --- a/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/Workers-test.tsx +++ /dev/null @@ -1,71 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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 { shallow } from 'enzyme'; -import * as React from 'react'; -import { click } from '../../../../helpers/testUtils'; -import Workers from '../Workers'; - -it('renders', () => { - const wrapper = shallow(); - expect(wrapper).toMatchSnapshot(); - - wrapper.setState({ - canSetWorkerCount: true, - loading: false, - workerCount: 1, - }); - expect(wrapper).toMatchSnapshot(); - - wrapper.setState({ workerCount: 2 }); - expect(wrapper).toMatchSnapshot(); - - wrapper.setState({ canSetWorkerCount: false }); - expect(wrapper).toMatchSnapshot(); -}); - -it('opens form', () => { - const wrapper = shallow(); - - wrapper.setState({ - canSetWorkerCount: true, - loading: false, - workerCount: 1, - }); - expect(wrapper).toMatchSnapshot(); - - click(wrapper.find('.js-edit')); - expect(wrapper).toMatchSnapshot(); -}); - -it('updates worker count', () => { - const wrapper = shallow(); - - wrapper.setState({ - canSetWorkerCount: true, - formOpen: true, - loading: false, - workerCount: 1, - }); - expect(wrapper).toMatchSnapshot(); - - wrapper.find('WorkersForm').prop('onClose')(7); - wrapper.update(); - expect(wrapper).toMatchSnapshot(); -}); diff --git a/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/WorkersForm-test.tsx b/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/WorkersForm-test.tsx deleted file mode 100644 index 43b537a8eea..00000000000 --- a/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/WorkersForm-test.tsx +++ /dev/null @@ -1,51 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2023 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. - */ -/* eslint-disable import/first */ -jest.mock('../../../../api/ce', () => ({ - setWorkerCount: () => Promise.resolve(), -})); - -import { shallow } from 'enzyme'; -import * as React from 'react'; -import Select from '../../../../components/controls/Select'; -import { submit } from '../../../../helpers/testUtils'; -import WorkersForm from '../WorkersForm'; - -it('changes select', () => { - const wrapper = shallow(); - expect(wrapper).toMatchSnapshot(); - - wrapper.find(Select).prop('onChange')({ value: 7 }); - wrapper.update(); - expect(wrapper).toMatchSnapshot(); -}); - -it('returns new worker count', async () => { - const onClose = jest.fn(); - const wrapper = shallow(); - (wrapper.instance() as WorkersForm).mounted = true; - wrapper.find(Select).prop('onChange')({ value: 7 }); - - wrapper.update(); - submit(wrapper.find('form')); - - await new Promise(setImmediate); - expect(onClose).toHaveBeenCalled(); -}); 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 deleted file mode 100644 index f3363add97f..00000000000 --- a/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/__snapshots__/BackgroundTasksApp-test.tsx.snap +++ /dev/null @@ -1,200 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`should render correctly: initial 1`] = ` -
- - -
-`; - -exports[`should render correctly: loaded 1`] = ` -
- - -
- - - - -
-`; diff --git a/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/__snapshots__/NoWorkersSupportPopup-test.tsx.snap b/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/__snapshots__/NoWorkersSupportPopup-test.tsx.snap deleted file mode 100644 index ad292a7ded2..00000000000 --- a/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/__snapshots__/NoWorkersSupportPopup-test.tsx.snap +++ /dev/null @@ -1,26 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`should render correctly 1`] = ` - -

- - background_tasks.add_more_workers - -

-

- background_tasks.add_more_workers.text -

-

- - learn_more - -

-
-`; diff --git a/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/__snapshots__/ScannerContext-test.tsx.snap b/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/__snapshots__/ScannerContext-test.tsx.snap deleted file mode 100644 index 4515f08bff8..00000000000 --- a/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/__snapshots__/ScannerContext-test.tsx.snap +++ /dev/null @@ -1,42 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`renders 1`] = ` - -
-

- background_tasks.scanner_context - : - foo - [ - background_task.type.REPORT - ] -

-
-
-
-      context
-    
-
- -
-`; diff --git a/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/__snapshots__/Stacktrace-test.tsx.snap b/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/__snapshots__/Stacktrace-test.tsx.snap deleted file mode 100644 index aaf5962266d..00000000000 --- a/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/__snapshots__/Stacktrace-test.tsx.snap +++ /dev/null @@ -1,49 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`renders 1`] = ` - -
-

- background_tasks.error_stacktrace - : - foo - [ - background_task.type.REPORT - ] -

-
-
-
-

- background_tasks.error_stacktrace -

-
-        stacktrace
-      
-
-
- -
-`; diff --git a/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/__snapshots__/StatPendingCount-test.tsx.snap b/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/__snapshots__/StatPendingCount-test.tsx.snap deleted file mode 100644 index c68b3903d4a..00000000000 --- a/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/__snapshots__/StatPendingCount-test.tsx.snap +++ /dev/null @@ -1,26 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`should render correctly 1`] = ` - - - 5 - - - background_tasks.pending - - - - - -`; diff --git a/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/__snapshots__/StatPendingTime-test.tsx.snap b/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/__snapshots__/StatPendingTime-test.tsx.snap deleted file mode 100644 index 85a355501c1..00000000000 --- a/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/__snapshots__/StatPendingTime-test.tsx.snap +++ /dev/null @@ -1,20 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`should render correctly 1`] = ` - - - 15s - - - background_tasks.pending_time - - - -`; diff --git a/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/__snapshots__/StatStillFailing-test.tsx.snap b/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/__snapshots__/StatStillFailing-test.tsx.snap deleted file mode 100644 index 98ba7bb6e06..00000000000 --- a/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/__snapshots__/StatStillFailing-test.tsx.snap +++ /dev/null @@ -1,40 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`should render correctly 1`] = ` - - - 5 - - - background_tasks.failures - - - -`; - -exports[`should render without the filter link 1`] = ` - - - 0 - - - background_tasks.failures - - - -`; 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 deleted file mode 100644 index f0b52ade1c0..00000000000 --- a/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/__snapshots__/TaskActions-test.tsx.snap +++ /dev/null @@ -1,166 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`renders 1`] = ` - - - - background_tasks.filter_by_component_x.Foo - - - background_tasks.cancel_task - - - -`; - -exports[`renders 2`] = ` - - - - background_tasks.filter_by_component_x.Foo - - - -`; - -exports[`renders 3`] = ` - - - - background_tasks.filter_by_component_x.Foo - - - background_tasks.cancel_task - - - background_tasks.show_scanner_context - - - -`; - -exports[`renders 4`] = ` - - - - background_tasks.filter_by_component_x.Foo - - - background_tasks.cancel_task - - - background_tasks.show_stacktrace - - - -`; - -exports[`renders 5`] = ` - - - - background_tasks.cancel_task - - - -`; - -exports[`shows scanner context 1`] = ` - -`; - -exports[`shows stack trace 1`] = ` - -`; - -exports[`shows warnings 1`] = ` - -`; 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 deleted file mode 100644 index 6b9c12aa240..00000000000 --- a/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/__snapshots__/TaskComponent-test.tsx.snap +++ /dev/null @@ -1,179 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`renders correctly 1`] = ` - - - - - - Foo - - - -`; - -exports[`renders correctly: branch 1`] = ` - - - - Foo - - - / - - feature - - - - -`; - -exports[`renders correctly: branch 2`] = ` - - - - Foo - - - / - - branch-6.7 - - - - -`; - -exports[`renders correctly: portfolio 1`] = ` - - - - - - Foo - - - -`; - -exports[`renders correctly: pull request 1`] = ` - - - - Foo - - - / - - pr-89 - - - - -`; - -exports[`renders correctly: undefined key 1`] = ` - - - AXR8jg_0mF2ZsYr8Wzs2 - - - -`; diff --git a/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/__snapshots__/TaskDate-test.tsx.snap b/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/__snapshots__/TaskDate-test.tsx.snap deleted file mode 100644 index 7a5dbb2dc43..00000000000 --- a/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/__snapshots__/TaskDate-test.tsx.snap +++ /dev/null @@ -1,45 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`renders 1`] = ` - -`; - -exports[`renders 2`] = ` - - - -`; - -exports[`renders 3`] = ` - - - -`; - -exports[`renders 4`] = ` - - - (+4d) - - - -`; diff --git a/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/__snapshots__/TaskStatus-test.tsx.snap b/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/__snapshots__/TaskStatus-test.tsx.snap deleted file mode 100644 index d4df3ea0961..00000000000 --- a/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/__snapshots__/TaskStatus-test.tsx.snap +++ /dev/null @@ -1,55 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`renders 1`] = ` - - - -`; - -exports[`renders 2`] = ` - - - -`; - -exports[`renders 3`] = ` - - - background_task.status.SUCCESS - - -`; - -exports[`renders 4`] = ` - - - background_task.status.FAILED - - -`; - -exports[`renders 5`] = ` - - - background_task.status.CANCELED - - -`; diff --git a/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/__snapshots__/Workers-test.tsx.snap b/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/__snapshots__/Workers-test.tsx.snap deleted file mode 100644 index 6cefea0b1b2..00000000000 --- a/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/__snapshots__/Workers-test.tsx.snap +++ /dev/null @@ -1,245 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`opens form 1`] = ` -
- - background_tasks.number_of_workers - - 1 - - - - - -
-`; - -exports[`opens form 2`] = ` -
- - background_tasks.number_of_workers - - 1 - - - - - - -
-`; - -exports[`renders 1`] = ` -
- - background_tasks.number_of_workers - - -
-`; - -exports[`renders 2`] = ` -
- - background_tasks.number_of_workers - - 1 - - - - - -
-`; - -exports[`renders 3`] = ` -
- - - - - - - background_tasks.number_of_workers - - 2 - - - - - -
-`; - -exports[`renders 4`] = ` -
- - - - - - - background_tasks.number_of_workers - - 2 - - - } - > - - -
-`; - -exports[`updates worker count 1`] = ` -
- - background_tasks.number_of_workers - - 1 - - - - - - -
-`; - -exports[`updates worker count 2`] = ` -
- - - - - - - background_tasks.number_of_workers - - 7 - - - - - -
-`; diff --git a/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/__snapshots__/WorkersForm-test.tsx.snap b/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/__snapshots__/WorkersForm-test.tsx.snap deleted file mode 100644 index aa434b1ece9..00000000000 --- a/server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/__snapshots__/WorkersForm-test.tsx.snap +++ /dev/null @@ -1,207 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`changes select 1`] = ` - -
-

- background_tasks.change_number_of_workers -

-
-
-
- - - background_tasks.change_number_of_workers.hint - -
- -
-
-`; diff --git a/sonar-core/src/main/resources/org/sonar/l10n/core.properties b/sonar-core/src/main/resources/org/sonar/l10n/core.properties index 1e77d9d9ca1..00a380dd05a 100644 --- a/sonar-core/src/main/resources/org/sonar/l10n/core.properties +++ b/sonar-core/src/main/resources/org/sonar/l10n/core.properties @@ -3243,6 +3243,7 @@ background_tasks.cancel_all_tasks.text=Are you sure you want to cancel all pendi background_tasks.cancel_all_tasks.submit=Cancel All background_tasks.scanner_context=Scanner Context background_tasks.show_scanner_context=Show Scanner Context +background_tasks.show_actions=Show actions background_tasks.show_stacktrace=Show Error Details background_tasks.show_warnings=Show Warnings background_tasks.error_message=Error Message -- 2.39.5