aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-web
diff options
context:
space:
mode:
authorViktor Vorona <viktor.vorona@sonarsource.com>2024-02-20 12:33:24 +0100
committersonartech <sonartech@sonarsource.com>2024-02-20 20:02:38 +0000
commit9dad49eb7171c374a67b5352cb5bd4db79589e6e (patch)
treea3b5cf0e634be49051c98f9231a1bae6673c3288 /server/sonar-web
parent2bfa1d52031005a5ead4d92a9451c260d3878cc0 (diff)
downloadsonarqube-9dad49eb7171c374a67b5352cb5bd4db79589e6e.tar.gz
sonarqube-9dad49eb7171c374a67b5352cb5bd4db79589e6e.zip
SONAR-21692 Remove act() that are not needed
Diffstat (limited to 'server/sonar-web')
-rw-r--r--server/sonar-web/design-system/src/components/input/__tests__/DateRangePicker-test.tsx6
-rw-r--r--server/sonar-web/design-system/src/components/input/__tests__/SearchSelectDropdown-test.tsx6
-rw-r--r--server/sonar-web/src/main/js/app/components/__tests__/ComponentContainer-test.tsx16
-rw-r--r--server/sonar-web/src/main/js/app/components/__tests__/KeyboardShortcutsModal-test.tsx7
-rw-r--r--server/sonar-web/src/main/js/apps/issues/components/__tests__/IssueOpenInIdeButton-test.tsx42
-rw-r--r--server/sonar-web/src/main/js/apps/issues/components/__tests__/IssuesNewStatusAndTransitionGuide-test.tsx21
-rw-r--r--server/sonar-web/src/main/js/apps/permissions/project/components/__tests__/PermissionsProject-it.tsx30
-rw-r--r--server/sonar-web/src/main/js/apps/permissions/test-utils.ts4
-rw-r--r--server/sonar-web/src/main/js/apps/projectInformation/about/components/__tests__/MetaTags-test.tsx6
-rw-r--r--server/sonar-web/src/main/js/apps/projectInformation/badges/__tests__/ProjectBadges-test.tsx20
-rw-r--r--server/sonar-web/src/main/js/apps/projectInformation/projectRegulatoryReport/__tests__/RegulatoryReport-it.tsx12
-rw-r--r--server/sonar-web/src/main/js/apps/projectKey/__tests__/ProjectKeyApp-it.tsx5
-rw-r--r--server/sonar-web/src/main/js/apps/projectNewCode/components/__tests__/ProjectNewCodeDefinitionApp-it.tsx5
-rw-r--r--server/sonar-web/src/main/js/apps/security-hotspots/__tests__/SecurityHotspotsApp-it.tsx30
-rw-r--r--server/sonar-web/src/main/js/apps/settings/components/pullRequestDecorationBinding/__tests__/PRDecorationBinding-it.tsx11
-rw-r--r--server/sonar-web/src/main/js/components/controls/__tests__/Toggler-test.tsx13
-rw-r--r--server/sonar-web/src/main/js/components/issue/__tests__/Issue-it.tsx70
-rw-r--r--server/sonar-web/src/main/js/components/new-code-definition/__tests__/NCDAutoUpdateMessage-test.tsx9
18 files changed, 104 insertions, 209 deletions
diff --git a/server/sonar-web/design-system/src/components/input/__tests__/DateRangePicker-test.tsx b/server/sonar-web/design-system/src/components/input/__tests__/DateRangePicker-test.tsx
index 65d0625d6cf..d552d33d231 100644
--- a/server/sonar-web/design-system/src/components/input/__tests__/DateRangePicker-test.tsx
+++ b/server/sonar-web/design-system/src/components/input/__tests__/DateRangePicker-test.tsx
@@ -17,7 +17,7 @@
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-import { act, screen } from '@testing-library/react';
+import { screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { formatISO, parseISO } from 'date-fns';
import { byRole } from '../../../../../src/main/js/helpers/testSelector';
@@ -58,9 +58,7 @@ it('behaves correctly', async () => {
onChange.mockClear();
- act(() => {
- jest.runAllTimers();
- });
+ jest.runAllTimers();
const previousButton = nav.byRole('button', { name: 'previous_month_x' });
const nextButton = nav.byRole('button', { name: 'next_month_x' });
diff --git a/server/sonar-web/design-system/src/components/input/__tests__/SearchSelectDropdown-test.tsx b/server/sonar-web/design-system/src/components/input/__tests__/SearchSelectDropdown-test.tsx
index 9f24bd11675..0e0c83c33bc 100644
--- a/server/sonar-web/design-system/src/components/input/__tests__/SearchSelectDropdown-test.tsx
+++ b/server/sonar-web/design-system/src/components/input/__tests__/SearchSelectDropdown-test.tsx
@@ -17,7 +17,7 @@
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-import { act, screen } from '@testing-library/react';
+import { screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { renderWithContext } from '../../../helpers/testUtils';
import { FCProps } from '../../../types/misc';
@@ -65,9 +65,7 @@ it('should handle key navigation', async () => {
expect(screen.queryByText('different')).not.toBeInTheDocument();
await user.keyboard('{Escape}');
expect(await screen.findByText('different')).toBeInTheDocument();
- await act(async () => {
- await user.keyboard('{Escape}');
- });
+ await user.keyboard('{Escape}');
expect(screen.queryByText('different')).not.toBeInTheDocument();
await user.tab({ shift: true });
await user.keyboard('{ArrowDown}');
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 573998a779f..559aff2cf18 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
@@ -17,7 +17,7 @@
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-import { act, screen, waitFor } from '@testing-library/react';
+import { screen, waitFor } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import React, { useContext } from 'react';
import { Route } from 'react-router-dom';
@@ -203,7 +203,7 @@ describe('getTasksForComponent', () => {
});
await waitFor(() => expect(getTasksForComponent).toHaveBeenCalledTimes(1));
- act(() => jest.runOnlyPendingTimers());
+ jest.runOnlyPendingTimers();
// Second round, the queue is now empty, hence we assume the previous task
// was done. We immediately load the component again.
@@ -219,7 +219,7 @@ describe('getTasksForComponent', () => {
expect(getTasksForComponent).toHaveBeenCalledTimes(3);
// Make sure the timeout was cleared. It should not be called again.
- act(() => jest.runAllTimers());
+ jest.runAllTimers();
// The number of calls haven't changed.
await waitFor(() => {
@@ -252,7 +252,7 @@ describe('getTasksForComponent', () => {
});
await waitFor(() => expect(getTasksForComponent).toHaveBeenCalledTimes(1));
- act(() => jest.runOnlyPendingTimers());
+ jest.runOnlyPendingTimers();
// Second round, nothing in the queue, BUT a success task is current. This
// means the queue was processed too quick for us to see, and we didn't see
@@ -308,7 +308,7 @@ describe('getTasksForComponent', () => {
// status endpoint.
await waitFor(() => expect(getTasksForComponent).toHaveBeenCalledTimes(1));
- act(() => jest.runOnlyPendingTimers());
+ jest.runOnlyPendingTimers();
// Second round, nothing in the queue, and a success task is current. This
// implies the current task was updated, and previously we displayed some information
@@ -475,7 +475,7 @@ describe('tutorials', () => {
await waitFor(() => expect(getTasksForComponent).toHaveBeenCalledTimes(1));
- act(() => jest.runOnlyPendingTimers());
+ jest.runOnlyPendingTimers();
expect(mockedReplace).not.toHaveBeenCalled();
await waitFor(() => expect(getTasksForComponent).toHaveBeenCalledTimes(2));
@@ -515,7 +515,7 @@ describe('tutorials', () => {
await waitFor(() => expect(getTasksForComponent).toHaveBeenCalledTimes(1));
- act(() => jest.runOnlyPendingTimers());
+ jest.runOnlyPendingTimers();
expect(mockedReplace).not.toHaveBeenCalled();
await waitFor(() => expect(getTasksForComponent).toHaveBeenCalledTimes(2));
@@ -559,7 +559,7 @@ describe('tutorials', () => {
await waitFor(() => expect(getTasksForComponent).toHaveBeenCalledTimes(1));
- act(() => jest.runOnlyPendingTimers());
+ jest.runOnlyPendingTimers();
expect(mockedReplace).not.toHaveBeenCalled();
await waitFor(() => expect(getTasksForComponent).toHaveBeenCalledTimes(2));
diff --git a/server/sonar-web/src/main/js/app/components/__tests__/KeyboardShortcutsModal-test.tsx b/server/sonar-web/src/main/js/app/components/__tests__/KeyboardShortcutsModal-test.tsx
index e7830580862..56b562d92c5 100644
--- a/server/sonar-web/src/main/js/app/components/__tests__/KeyboardShortcutsModal-test.tsx
+++ b/server/sonar-web/src/main/js/app/components/__tests__/KeyboardShortcutsModal-test.tsx
@@ -17,7 +17,6 @@
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-import { act } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import React from 'react';
import { renderComponent } from '../../../helpers/testReactTestingUtils';
@@ -30,7 +29,7 @@ it('should render correctly', async () => {
expect(ui.modalTitle.query()).not.toBeInTheDocument();
- await act(() => user.keyboard('?'));
+ await user.keyboard('?');
expect(ui.modalTitle.get()).toBeInTheDocument();
@@ -43,7 +42,7 @@ it('should ignore other keydownes', async () => {
const user = userEvent.setup();
renderKeyboardShortcutsModal();
- await act(() => user.keyboard('!'));
+ await user.keyboard('!');
expect(ui.modalTitle.query()).not.toBeInTheDocument();
});
@@ -54,7 +53,7 @@ it('should ignore events in an input', async () => {
renderKeyboardShortcutsModal();
await user.click(ui.textInput.get());
- await act(() => user.keyboard('?'));
+ await user.keyboard('?');
expect(ui.modalTitle.query()).not.toBeInTheDocument();
});
diff --git a/server/sonar-web/src/main/js/apps/issues/components/__tests__/IssueOpenInIdeButton-test.tsx b/server/sonar-web/src/main/js/apps/issues/components/__tests__/IssueOpenInIdeButton-test.tsx
index 5109e4a9429..3dc7783093f 100644
--- a/server/sonar-web/src/main/js/apps/issues/components/__tests__/IssueOpenInIdeButton-test.tsx
+++ b/server/sonar-web/src/main/js/apps/issues/components/__tests__/IssueOpenInIdeButton-test.tsx
@@ -17,7 +17,7 @@
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-import { act, screen } from '@testing-library/react';
+import { screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { addGlobalErrorMessage, addGlobalSuccessMessage } from 'design-system';
import * as React from 'react';
@@ -84,13 +84,11 @@ it('handles button click with no ide found', async () => {
renderComponentIssueOpenInIdeButton();
- await act(async () => {
- await user.click(
- screen.getByRole('button', {
- name: 'open_in_ide',
- }),
- );
- });
+ await user.click(
+ screen.getByRole('button', {
+ name: 'open_in_ide',
+ }),
+ );
expect(probeSonarLintServers).toHaveBeenCalledWith();
@@ -118,13 +116,11 @@ it('handles button click with one ide found', async () => {
renderComponentIssueOpenInIdeButton();
- await act(async () => {
- await user.click(
- screen.getByRole('button', {
- name: 'open_in_ide',
- }),
- );
- });
+ await user.click(
+ screen.getByRole('button', {
+ name: 'open_in_ide',
+ }),
+ );
expect(probeSonarLintServers).toHaveBeenCalledWith();
@@ -150,13 +146,11 @@ it('handles button click with several ides found', async () => {
renderComponentIssueOpenInIdeButton();
- await act(async () => {
- await user.click(
- screen.getByRole('button', {
- name: 'open_in_ide',
- }),
- );
- });
+ await user.click(
+ screen.getByRole('button', {
+ name: 'open_in_ide',
+ }),
+ );
expect(probeSonarLintServers).toHaveBeenCalledWith();
@@ -172,9 +166,7 @@ it('handles button click with several ides found', async () => {
expect(secondIde).toBeInTheDocument();
- await act(async () => {
- await user.click(secondIde);
- });
+ await user.click(secondIde);
expect(openSonarLintIssue).toHaveBeenCalledWith({
branchName: undefined,
diff --git a/server/sonar-web/src/main/js/apps/issues/components/__tests__/IssuesNewStatusAndTransitionGuide-test.tsx b/server/sonar-web/src/main/js/apps/issues/components/__tests__/IssuesNewStatusAndTransitionGuide-test.tsx
index be5ad17457a..361b63f0e8a 100644
--- a/server/sonar-web/src/main/js/apps/issues/components/__tests__/IssuesNewStatusAndTransitionGuide-test.tsx
+++ b/server/sonar-web/src/main/js/apps/issues/components/__tests__/IssuesNewStatusAndTransitionGuide-test.tsx
@@ -17,7 +17,6 @@
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-import { act } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import React from 'react';
import IssuesServiceMock from '../../../../api/mocks/IssuesServiceMock';
@@ -47,29 +46,19 @@ it('should display status guide', async () => {
expect(await ui.guidePopup.find()).toBeInTheDocument();
expect(ui.guidePopup.get()).toHaveTextContent('guiding.issue_accept.1.title');
- await act(async () => {
- await user.click(ui.guidePopup.byRole('button', { name: 'next' }).get());
- });
+ await user.click(ui.guidePopup.byRole('button', { name: 'next' }).get());
expect(ui.guidePopup.get()).toHaveTextContent('guiding.issue_accept.2.title');
- await act(async () => {
- await user.click(ui.guidePopup.byRole('button', { name: 'go_back' }).get());
- });
+ await user.click(ui.guidePopup.byRole('button', { name: 'go_back' }).get());
expect(ui.guidePopup.get()).toHaveTextContent('guiding.issue_accept.1.title');
- await act(async () => {
- await user.click(ui.guidePopup.byRole('button', { name: 'next' }).get());
- });
- await act(async () => {
- await user.click(ui.guidePopup.byRole('button', { name: 'next' }).get());
- });
+ await user.click(ui.guidePopup.byRole('button', { name: 'next' }).get());
+ await user.click(ui.guidePopup.byRole('button', { name: 'next' }).get());
expect(ui.guidePopup.get()).toHaveTextContent('guiding.issue_accept.3.title');
expect(ui.guidePopup.byRole('button', { name: 'Next' }).query()).not.toBeInTheDocument();
- await act(async () => {
- await user.click(ui.guidePopup.byRole('button', { name: 'close' }).get());
- });
+ await user.click(ui.guidePopup.byRole('button', { name: 'close' }).get());
expect(ui.guidePopup.query()).not.toBeInTheDocument();
});
diff --git a/server/sonar-web/src/main/js/apps/permissions/project/components/__tests__/PermissionsProject-it.tsx b/server/sonar-web/src/main/js/apps/permissions/project/components/__tests__/PermissionsProject-it.tsx
index 93f83ab7077..be981f86084 100644
--- a/server/sonar-web/src/main/js/apps/permissions/project/components/__tests__/PermissionsProject-it.tsx
+++ b/server/sonar-web/src/main/js/apps/permissions/project/components/__tests__/PermissionsProject-it.tsx
@@ -17,7 +17,7 @@
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-import { act, screen, waitFor } from '@testing-library/react';
+import { screen, waitFor } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import AlmSettingsServiceMock from '../../../../../api/mocks/AlmSettingsServiceMock';
import GithubProvisioningServiceMock from '../../../../../api/mocks/GithubProvisioningServiceMock';
@@ -155,9 +155,7 @@ describe('assigning/revoking permissions', () => {
expect(
ui.projectPermissionCheckbox('sonar-users', Permissions.Browse).query(),
).not.toBeInTheDocument();
- await act(async () => {
- await ui.turnProjectPrivate();
- });
+ await ui.turnProjectPrivate();
expect(ui.visibilityRadio(Visibility.Private).get()).toBeChecked();
expect(
ui.projectPermissionCheckbox('sonar-users', Permissions.Browse).get(),
@@ -165,9 +163,7 @@ describe('assigning/revoking permissions', () => {
await ui.turnProjectPublic();
expect(ui.makePublicDisclaimer.get()).toBeInTheDocument();
- await act(async () => {
- await ui.confirmTurnProjectPublic();
- });
+ await ui.confirmTurnProjectPublic();
expect(ui.visibilityRadio(Visibility.Public).get()).toBeChecked();
});
@@ -260,9 +256,7 @@ describe('GH provisioning', () => {
expect(ui.visibilityRadio(Visibility.Public).get()).toBeDisabled();
expect(ui.visibilityRadio(Visibility.Public).get()).toBeChecked();
expect(ui.visibilityRadio(Visibility.Private).get()).toBeDisabled();
- await act(async () => {
- await ui.turnProjectPrivate();
- });
+ await ui.turnProjectPrivate();
expect(ui.visibilityRadio(Visibility.Private).get()).not.toBeChecked();
});
@@ -282,9 +276,7 @@ describe('GH provisioning', () => {
expect(ui.visibilityRadio(Visibility.Public).get()).not.toHaveClass('disabled');
expect(ui.visibilityRadio(Visibility.Public).get()).toBeChecked();
expect(ui.visibilityRadio(Visibility.Private).get()).not.toHaveClass('disabled');
- await act(async () => {
- await ui.turnProjectPrivate();
- });
+ await ui.turnProjectPrivate();
expect(ui.visibilityRadio(Visibility.Private).get()).toBeChecked();
});
@@ -304,9 +296,7 @@ describe('GH provisioning', () => {
expect(ui.visibilityRadio(Visibility.Public).get()).not.toHaveClass('disabled');
expect(ui.visibilityRadio(Visibility.Public).get()).toBeChecked();
expect(ui.visibilityRadio(Visibility.Private).get()).not.toHaveClass('disabled');
- await act(async () => {
- await ui.turnProjectPrivate();
- });
+ await ui.turnProjectPrivate();
expect(ui.visibilityRadio(Visibility.Private).get()).toBeChecked();
});
@@ -345,9 +335,7 @@ describe('GH provisioning', () => {
expect(ui.confirmRemovePermissionDialog.get()).toHaveTextContent(
`${Permissions.IssueAdmin}Alexa`,
);
- await act(() =>
- user.click(ui.confirmRemovePermissionDialog.byRole('button', { name: 'confirm' }).get()),
- );
+ await user.click(ui.confirmRemovePermissionDialog.byRole('button', { name: 'confirm' }).get());
expect(ui.projectPermissionCheckbox('Alexa', Permissions.IssueAdmin).get()).not.toBeChecked();
expect(ui.projectPermissionCheckbox('sonar-users', Permissions.Browse).get()).toBeChecked();
@@ -357,9 +345,7 @@ describe('GH provisioning', () => {
expect(ui.confirmRemovePermissionDialog.get()).toHaveTextContent(
`${Permissions.Browse}sonar-users`,
);
- await act(() =>
- user.click(ui.confirmRemovePermissionDialog.byRole('button', { name: 'confirm' }).get()),
- );
+ await user.click(ui.confirmRemovePermissionDialog.byRole('button', { name: 'confirm' }).get());
expect(ui.projectPermissionCheckbox('sonar-users', Permissions.Browse).get()).not.toBeChecked();
expect(ui.projectPermissionCheckbox('sonar-admins', Permissions.Admin).get()).toBeChecked();
expect(ui.projectPermissionCheckbox('sonar-admins', Permissions.Admin).get()).toHaveAttribute(
diff --git a/server/sonar-web/src/main/js/apps/permissions/test-utils.ts b/server/sonar-web/src/main/js/apps/permissions/test-utils.ts
index 75bf924b247..9bec30dc8bd 100644
--- a/server/sonar-web/src/main/js/apps/permissions/test-utils.ts
+++ b/server/sonar-web/src/main/js/apps/permissions/test-utils.ts
@@ -17,7 +17,7 @@
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-import { act, waitFor } from '@testing-library/react';
+import { waitFor } from '@testing-library/react';
import { UserEvent } from '@testing-library/user-event/dist/types/setup/setup';
import selectEvent from 'react-select-event';
import { byRole, byText } from '../../helpers/testSelector';
@@ -72,7 +72,7 @@ export function getPageObject(user: UserEvent) {
});
},
async toggleProjectPermission(target: string, permission: Permissions) {
- await act(() => user.click(ui.projectPermissionCheckbox(target, permission).get()));
+ await user.click(ui.projectPermissionCheckbox(target, permission).get());
},
async toggleGlobalPermission(target: string, permission: Permissions) {
await user.click(ui.globalPermissionCheckbox(target, permission).get());
diff --git a/server/sonar-web/src/main/js/apps/projectInformation/about/components/__tests__/MetaTags-test.tsx b/server/sonar-web/src/main/js/apps/projectInformation/about/components/__tests__/MetaTags-test.tsx
index b5f1f980280..fea012025a3 100644
--- a/server/sonar-web/src/main/js/apps/projectInformation/about/components/__tests__/MetaTags-test.tsx
+++ b/server/sonar-web/src/main/js/apps/projectInformation/about/components/__tests__/MetaTags-test.tsx
@@ -17,7 +17,7 @@
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-import { act, screen } from '@testing-library/react';
+import { screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import * as React from 'react';
import { setApplicationTags, setProjectTags } from '../../../../../api/components';
@@ -61,7 +61,7 @@ it('should allow to edit tags for a project', async () => {
expect(await screen.findByText('foo, bar')).toBeInTheDocument();
expect(screen.getByRole('button')).toBeInTheDocument();
- await act(() => user.click(screen.getByRole('button', { name: 'foo bar +' })));
+ await user.click(screen.getByRole('button', { name: 'foo bar +' }));
expect(await screen.findByRole('checkbox', { name: 'best' })).toBeInTheDocument();
@@ -94,7 +94,7 @@ it('should set tags for an app', async () => {
}),
});
- await act(() => user.click(screen.getByRole('button', { name: 'no_tags +' })));
+ await user.click(screen.getByRole('button', { name: 'no_tags +' }));
await user.click(await screen.findByRole('checkbox', { name: 'best' }));
diff --git a/server/sonar-web/src/main/js/apps/projectInformation/badges/__tests__/ProjectBadges-test.tsx b/server/sonar-web/src/main/js/apps/projectInformation/badges/__tests__/ProjectBadges-test.tsx
index cc4f31375fe..240d5917a8a 100644
--- a/server/sonar-web/src/main/js/apps/projectInformation/badges/__tests__/ProjectBadges-test.tsx
+++ b/server/sonar-web/src/main/js/apps/projectInformation/badges/__tests__/ProjectBadges-test.tsx
@@ -17,7 +17,7 @@
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-import { act, fireEvent, screen, waitFor } from '@testing-library/react';
+import { fireEvent, screen, waitFor } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import * as React from 'react';
import selectEvent from 'react-select-event';
@@ -93,12 +93,10 @@ it('should update params', async () => {
),
).toBeInTheDocument();
- await act(async () => {
- await selectEvent.select(
- screen.getByLabelText('overview.badges.format'),
- 'overview.badges.options.formats.url',
- );
- });
+ await selectEvent.select(
+ screen.getByLabelText('overview.badges.format'),
+ 'overview.badges.options.formats.url',
+ );
expect(
screen.getByText(
@@ -106,9 +104,7 @@ it('should update params', async () => {
),
).toBeInTheDocument();
- await act(async () => {
- await selectEvent.openMenu(screen.getByLabelText('overview.badges.metric'));
- });
+ await selectEvent.openMenu(screen.getByLabelText('overview.badges.metric'));
fireEvent.click(screen.getByText(`metric.${MetricKey.coverage}.name`));
expect(
@@ -146,9 +142,7 @@ it('should warn about deprecated metrics', async () => {
renderProjectBadges();
await appLoaded();
- await act(async () => {
- await selectEvent.openMenu(screen.getByLabelText('overview.badges.metric'));
- });
+ await selectEvent.openMenu(screen.getByLabelText('overview.badges.metric'));
fireEvent.click(screen.getByText(`metric.${MetricKey.bugs}.name (deprecated)`));
expect(
diff --git a/server/sonar-web/src/main/js/apps/projectInformation/projectRegulatoryReport/__tests__/RegulatoryReport-it.tsx b/server/sonar-web/src/main/js/apps/projectInformation/projectRegulatoryReport/__tests__/RegulatoryReport-it.tsx
index 1ebe9b3c440..c21631e8c35 100644
--- a/server/sonar-web/src/main/js/apps/projectInformation/projectRegulatoryReport/__tests__/RegulatoryReport-it.tsx
+++ b/server/sonar-web/src/main/js/apps/projectInformation/projectRegulatoryReport/__tests__/RegulatoryReport-it.tsx
@@ -17,7 +17,7 @@
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-import { act, screen } from '@testing-library/react';
+import { screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import * as React from 'react';
import BranchesServiceMock from '../../../../api/mocks/BranchesServiceMock';
@@ -57,17 +57,13 @@ describe('RegulatoryReport tests', () => {
expect(ui.moreInfo.get()).toBeInTheDocument();
expect(ui.branchSelect.get()).toBeInTheDocument();
- await act(async () => {
- await user.click(ui.branchSelect.get());
- await user.keyboard('[ArrowDown][Enter]');
- });
+ await user.click(ui.branchSelect.get());
+ await user.keyboard('[ArrowDown][Enter]');
expect(ui.downloadButton.get()).toBeInTheDocument();
expect(screen.queryByText('regulatory_page.download_start.sentence')).not.toBeInTheDocument();
- await act(async () => {
- await user.click(ui.downloadButton.get());
- });
+ await user.click(ui.downloadButton.get());
expect(screen.getByText('regulatory_page.download_start.sentence')).toBeInTheDocument();
});
diff --git a/server/sonar-web/src/main/js/apps/projectKey/__tests__/ProjectKeyApp-it.tsx b/server/sonar-web/src/main/js/apps/projectKey/__tests__/ProjectKeyApp-it.tsx
index 887923c7ff3..5cc1cf22da5 100644
--- a/server/sonar-web/src/main/js/apps/projectKey/__tests__/ProjectKeyApp-it.tsx
+++ b/server/sonar-web/src/main/js/apps/projectKey/__tests__/ProjectKeyApp-it.tsx
@@ -21,7 +21,6 @@ import { within } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { last } from 'lodash';
import React from 'react';
-import { act } from 'react-dom/test-utils';
import { Route } from 'react-router-dom';
import ComponentsServiceMock from '../../../api/mocks/ComponentsServiceMock';
import { renderAppWithComponentContext } from '../../../helpers/testReactTestingUtils';
@@ -58,9 +57,7 @@ it('can update project key', async () => {
// Dialog should show old and new keys
expect(within(ui.updateKeyDialog.get()).getByText(oldKey)).toBeInTheDocument();
expect(within(ui.updateKeyDialog.get()).getByText(newKey)).toBeInTheDocument();
- await act(async () => {
- await user.click(last(ui.updateInputButton.getAll()) as HTMLElement);
- });
+ await user.click(last(ui.updateInputButton.getAll()) as HTMLElement);
expect(ui.updateInputButton.get()).toBeDisabled();
expect(ui.newKeyInput.get()).toHaveValue(newKey);
diff --git a/server/sonar-web/src/main/js/apps/projectNewCode/components/__tests__/ProjectNewCodeDefinitionApp-it.tsx b/server/sonar-web/src/main/js/apps/projectNewCode/components/__tests__/ProjectNewCodeDefinitionApp-it.tsx
index f15b977a390..9e38c437191 100644
--- a/server/sonar-web/src/main/js/apps/projectNewCode/components/__tests__/ProjectNewCodeDefinitionApp-it.tsx
+++ b/server/sonar-web/src/main/js/apps/projectNewCode/components/__tests__/ProjectNewCodeDefinitionApp-it.tsx
@@ -17,7 +17,6 @@
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-import { act } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { last } from 'lodash';
import selectEvent from 'react-select-event';
@@ -350,9 +349,7 @@ it('should correctly dismiss branch banner', async () => {
expect(await ui.branchNCDsBanner.find()).toBeInTheDocument();
const user = userEvent.setup();
- await act(async () => {
- await user.click(ui.dismissButton.get());
- });
+ await user.click(ui.dismissButton.get());
expect(ui.branchNCDsBanner.query()).not.toBeInTheDocument();
});
diff --git a/server/sonar-web/src/main/js/apps/security-hotspots/__tests__/SecurityHotspotsApp-it.tsx b/server/sonar-web/src/main/js/apps/security-hotspots/__tests__/SecurityHotspotsApp-it.tsx
index 85876734ec1..18bd0d2432a 100644
--- a/server/sonar-web/src/main/js/apps/security-hotspots/__tests__/SecurityHotspotsApp-it.tsx
+++ b/server/sonar-web/src/main/js/apps/security-hotspots/__tests__/SecurityHotspotsApp-it.tsx
@@ -17,7 +17,7 @@
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-import { act, screen, waitFor } from '@testing-library/react';
+import { screen, waitFor } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import React from 'react';
import { Route } from 'react-router-dom';
@@ -210,9 +210,7 @@ describe('CRUD', () => {
await user.click(await ui.activeAssignee.find());
await user.click(ui.inputAssignee.get());
- await act(async () => {
- await user.keyboard('User');
- });
+ await user.keyboard('User');
expect(getUsers).toHaveBeenLastCalledWith({ q: 'User' });
await user.keyboard('{Enter}');
@@ -233,9 +231,7 @@ describe('CRUD', () => {
await user.click(screen.getByRole('textbox', { name: 'hotspots.status.add_comment_optional' }));
await user.keyboard(comment);
- await act(async () => {
- await user.click(ui.changeStatus.get());
- });
+ await user.click(ui.changeStatus.get());
expect(ui.continueReviewingButton.get()).toBeInTheDocument();
await user.click(ui.continueReviewingButton.get());
@@ -328,22 +324,22 @@ describe('navigation', () => {
const user = userEvent.setup();
renderSecurityHotspotsApp();
- await act(() => user.keyboard('{ArrowLeft}'));
+ await user.keyboard('{ArrowLeft}');
expect(ui.codeContent.get()).toBeInTheDocument();
- await act(() => user.keyboard('{ArrowRight}'));
+ await user.keyboard('{ArrowRight}');
expect(ui.riskContent.get()).toBeInTheDocument();
- await act(() => user.keyboard('{ArrowRight}'));
+ await user.keyboard('{ArrowRight}');
expect(ui.vulnerabilityContent.get()).toBeInTheDocument();
- await act(() => user.keyboard('{ArrowRight}'));
+ await user.keyboard('{ArrowRight}');
expect(ui.fixContent.get()).toBeInTheDocument();
- await act(() => user.keyboard('{ArrowRight}'));
+ await user.keyboard('{ArrowRight}');
expect(ui.addCommentButton.get()).toBeInTheDocument();
- await act(() => user.keyboard('{ArrowRight}'));
+ await user.keyboard('{ArrowRight}');
expect(ui.addCommentButton.get()).toBeInTheDocument();
});
@@ -401,9 +397,7 @@ it('after status change, should be able to disable success dialog show', async (
await user.click(await ui.reviewButton.find());
await user.click(ui.toReviewStatus.get());
- await act(async () => {
- await user.click(ui.changeStatus.get());
- });
+ await user.click(ui.changeStatus.get());
await user.click(ui.dontShowSuccessDialogCheckbox.get());
expect(ui.dontShowSuccessDialogCheckbox.get()).toBeChecked();
@@ -413,9 +407,7 @@ it('after status change, should be able to disable success dialog show', async (
await user.click(await ui.reviewButton.find());
await user.click(ui.toReviewStatus.get());
- await act(async () => {
- await user.click(ui.changeStatus.get());
- });
+ await user.click(ui.changeStatus.get());
expect(ui.continueReviewingButton.query()).not.toBeInTheDocument();
});
diff --git a/server/sonar-web/src/main/js/apps/settings/components/pullRequestDecorationBinding/__tests__/PRDecorationBinding-it.tsx b/server/sonar-web/src/main/js/apps/settings/components/pullRequestDecorationBinding/__tests__/PRDecorationBinding-it.tsx
index 1e46b1c9b4c..0ed191083a1 100644
--- a/server/sonar-web/src/main/js/apps/settings/components/pullRequestDecorationBinding/__tests__/PRDecorationBinding-it.tsx
+++ b/server/sonar-web/src/main/js/apps/settings/components/pullRequestDecorationBinding/__tests__/PRDecorationBinding-it.tsx
@@ -17,7 +17,6 @@
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-import { act } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import React from 'react';
import selectEvent from 'react-select-event';
@@ -108,11 +107,11 @@ it.each([
await ui.setInput(inputId, value);
}
// Save form and check for errors
- await act(() => user.click(ui.saveButton.get()));
+ await user.click(ui.saveButton.get());
expect(await ui.validationMsg('cute error').find()).toBeInTheDocument();
// Check validation with errors
- await act(() => user.click(ui.validateButton.get()));
+ await user.click(ui.validateButton.get());
expect(ui.validationMsg('cute error').get()).toBeInTheDocument();
// Save form and check for errors
@@ -121,12 +120,12 @@ it.each([
Object.keys(list).find((key) => key.endsWith('.repository')) as string,
'Anything',
);
- await act(() => user.click(ui.saveButton.get()));
+ await user.click(ui.saveButton.get());
expect(
await ui.validationMsg('settings.pr_decoration.binding.check_configuration.success').find(),
).toBeInTheDocument();
- await act(() => user.click(ui.validateButton.get()));
+ await user.click(ui.validateButton.get());
expect(
ui.validationMsg('settings.pr_decoration.binding.check_configuration.success').get(),
).toBeInTheDocument();
@@ -141,7 +140,7 @@ it.each([
expect(ui.saveButton.query()).not.toBeInTheDocument();
// Reset binding
- await act(() => user.click(ui.resetButton.get()));
+ await user.click(ui.resetButton.get());
expect(ui.input('', 'textbox').query()).not.toBeInTheDocument();
expect(ui.input('', 'switch').query()).not.toBeInTheDocument();
},
diff --git a/server/sonar-web/src/main/js/components/controls/__tests__/Toggler-test.tsx b/server/sonar-web/src/main/js/components/controls/__tests__/Toggler-test.tsx
index 17b9444195d..7d991277c82 100644
--- a/server/sonar-web/src/main/js/components/controls/__tests__/Toggler-test.tsx
+++ b/server/sonar-web/src/main/js/components/controls/__tests__/Toggler-test.tsx
@@ -17,7 +17,7 @@
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-import { act, render } from '@testing-library/react';
+import { act, fireEvent, render } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { UserEvent } from '@testing-library/user-event/dist/types/setup/setup';
import * as React from 'react';
@@ -43,17 +43,13 @@ const ui = {
async function openToggler(user: UserEvent) {
await user.click(ui.toggleButton.get());
- act(() => {
- jest.runAllTimers();
- });
+ jest.runAllTimers();
expect(ui.overlayButton.get()).toBeInTheDocument();
}
function focusOut() {
- act(() => {
- ui.overlayButton.get().focus();
- ui.outButton.get().focus();
- });
+ fireEvent.focus(ui.overlayButton.get());
+ fireEvent.focus(ui.outButton.get());
}
it('should handle key up/down', async () => {
@@ -201,6 +197,7 @@ it('should open/close correctly when default props is applied', async () => {
expect(await ui.overlayButton.find()).toBeInTheDocument();
// Focus out should close
+ // I have no idea why only act + this 2 lines work, but fireEvent.focus does not
act(() => {
ui.overlayButton.get().focus();
ui.outButton.get().focus();
diff --git a/server/sonar-web/src/main/js/components/issue/__tests__/Issue-it.tsx b/server/sonar-web/src/main/js/components/issue/__tests__/Issue-it.tsx
index eb03a1dc21e..d116e14daf8 100644
--- a/server/sonar-web/src/main/js/components/issue/__tests__/Issue-it.tsx
+++ b/server/sonar-web/src/main/js/components/issue/__tests__/Issue-it.tsx
@@ -17,7 +17,7 @@
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-import { act, screen } from '@testing-library/react';
+import { screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { omit, pick } from 'lodash';
import * as React from 'react';
@@ -268,58 +268,38 @@ function getPageObject() {
async addComment(content: string) {
await user.click(selectors.commentAddBtn.get());
await user.type(selectors.commentTextInput.get(), content);
- await act(async () => {
- await user.click(selectors.commentSaveBtn.get());
- });
+ await user.click(selectors.commentSaveBtn.get());
},
async updateComment(content: string) {
await user.click(selectors.commentEditBtn.get());
await user.type(selectors.commentTextInput.get(), content);
- await act(async () => {
- await user.keyboard(`{Control>}{${KeyboardKeys.Enter}}{/Control}`);
- });
+ await user.keyboard(`{Control>}{${KeyboardKeys.Enter}}{/Control}`);
},
async deleteComment() {
await user.click(selectors.commentDeleteBtn.get());
- await act(async () => {
- await user.click(selectors.commentConfirmDeleteBtn.get());
- });
+ await user.click(selectors.commentConfirmDeleteBtn.get());
},
async updateType(currentType: IssueType, newType: IssueType) {
await user.click(selectors.updateTypeBtn(currentType).get());
- await act(async () => {
- await user.click(selectors.setTypeBtn(newType).get());
- });
+ await user.click(selectors.setTypeBtn(newType).get());
},
async updateSeverity(currentSeverity: IssueSeverity, newSeverity: IssueSeverity) {
await user.click(selectors.updateSeverityBtn(currentSeverity).get());
- await act(async () => {
- await user.click(selectors.setSeverityBtn(newSeverity).get());
- });
+ await user.click(selectors.setSeverityBtn(newSeverity).get());
},
async updateStatus(currentStatus: IssueStatus, transition: IssueTransition) {
await user.click(selectors.updateStatusBtn(currentStatus).get());
- await act(async () => {
- await user.click(selectors.setStatusBtn(transition).get());
- });
+ await user.click(selectors.setStatusBtn(transition).get());
},
async updateAssignee(currentAssignee: string, newAssignee: string) {
await user.click(selectors.updateAssigneeBtn(currentAssignee).get());
- await act(async () => {
- await user.type(selectors.assigneeSearchInput.get(), newAssignee);
- });
- await act(async () => {
- await user.click(selectors.setAssigneeBtn(new RegExp(newAssignee)).get());
- });
+ await user.type(selectors.assigneeSearchInput.get(), newAssignee);
+ await user.click(selectors.setAssigneeBtn(new RegExp(newAssignee)).get());
},
async addTag(tag: string, currentTagList?: string[]) {
await user.click(selectors.updateTagsBtn(currentTagList).get());
- await act(async () => {
- await user.click(selectors.toggleTagCheckbox(tag).get());
- });
- await act(async () => {
- await user.keyboard('{Escape}');
- });
+ await user.click(selectors.toggleTagCheckbox(tag).get());
+ await user.keyboard('{Escape}');
},
async showChangelog() {
await user.click(selectors.toggleChangelogBtn.get());
@@ -332,39 +312,25 @@ function getPageObject() {
await user.click(selectors.issueMessageLink.get());
},
async pressDismissShortcut() {
- await act(async () => {
- await user.keyboard(`{${KeyboardKeys.Escape}}`);
- });
+ await user.keyboard(`{${KeyboardKeys.Escape}}`);
},
async pressTransitionShortcut() {
- await act(async () => {
- await user.keyboard(`{${KeyboardKeys.KeyF}}`);
- });
+ await user.keyboard(`{${KeyboardKeys.KeyF}}`);
},
async pressAssignShortcut() {
- await act(async () => {
- await user.keyboard(`{${KeyboardKeys.KeyA}}`);
- });
+ await user.keyboard(`{${KeyboardKeys.KeyA}}`);
},
async pressAssignToMeShortcut() {
- await act(async () => {
- await user.keyboard(`{${KeyboardKeys.KeyM}}`);
- });
+ await user.keyboard(`{${KeyboardKeys.KeyM}}`);
},
async pressSeverityShortcut() {
- await act(async () => {
- await user.keyboard(`{${KeyboardKeys.KeyI}}`);
- });
+ await user.keyboard(`{${KeyboardKeys.KeyI}}`);
},
async pressTagsShortcut() {
- await act(async () => {
- await user.keyboard(`{${KeyboardKeys.KeyT}}`);
- });
+ await user.keyboard(`{${KeyboardKeys.KeyT}}`);
},
async pressCheckShortcut() {
- await act(async () => {
- await user.keyboard(`{${KeyboardKeys.Space}}`);
- });
+ await user.keyboard(`{${KeyboardKeys.Space}}`);
},
};
diff --git a/server/sonar-web/src/main/js/components/new-code-definition/__tests__/NCDAutoUpdateMessage-test.tsx b/server/sonar-web/src/main/js/components/new-code-definition/__tests__/NCDAutoUpdateMessage-test.tsx
index 9a83f40f706..4cb7063e1f9 100644
--- a/server/sonar-web/src/main/js/components/new-code-definition/__tests__/NCDAutoUpdateMessage-test.tsx
+++ b/server/sonar-web/src/main/js/components/new-code-definition/__tests__/NCDAutoUpdateMessage-test.tsx
@@ -17,7 +17,6 @@
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-import { act } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import React from 'react';
import { Route } from 'react-router-dom';
@@ -117,9 +116,7 @@ describe('Global NCD update notification banner', () => {
renderGlobalMessage();
expect(await ui.globalBannerContent.find()).toBeVisible();
const user = userEvent.setup();
- await act(async () => {
- await user.click(ui.reviewLink.get());
- });
+ await user.click(ui.reviewLink.get());
expect(await ui.adminNcdMessage.find()).toBeVisible();
});
});
@@ -213,9 +210,7 @@ describe('Project NCD update notification banner', () => {
renderProjectMessage(component);
expect(await ui.projectBannerContent.find()).toBeVisible();
const user = userEvent.setup();
- await act(async () => {
- await user.click(ui.reviewLink.get());
- });
+ await user.click(ui.reviewLink.get());
expect(await ui.projectNcdMessage.find()).toBeVisible();
});
});