Browse Source

SONAR-21692 Remove act() that are not needed

tags/10.5.0.89998
Viktor Vorona 2 months ago
parent
commit
9dad49eb71
18 changed files with 104 additions and 209 deletions
  1. 2
    4
      server/sonar-web/design-system/src/components/input/__tests__/DateRangePicker-test.tsx
  2. 2
    4
      server/sonar-web/design-system/src/components/input/__tests__/SearchSelectDropdown-test.tsx
  3. 8
    8
      server/sonar-web/src/main/js/app/components/__tests__/ComponentContainer-test.tsx
  4. 3
    4
      server/sonar-web/src/main/js/app/components/__tests__/KeyboardShortcutsModal-test.tsx
  5. 17
    25
      server/sonar-web/src/main/js/apps/issues/components/__tests__/IssueOpenInIdeButton-test.tsx
  6. 5
    16
      server/sonar-web/src/main/js/apps/issues/components/__tests__/IssuesNewStatusAndTransitionGuide-test.tsx
  7. 8
    22
      server/sonar-web/src/main/js/apps/permissions/project/components/__tests__/PermissionsProject-it.tsx
  8. 2
    2
      server/sonar-web/src/main/js/apps/permissions/test-utils.ts
  9. 3
    3
      server/sonar-web/src/main/js/apps/projectInformation/about/components/__tests__/MetaTags-test.tsx
  10. 7
    13
      server/sonar-web/src/main/js/apps/projectInformation/badges/__tests__/ProjectBadges-test.tsx
  11. 4
    8
      server/sonar-web/src/main/js/apps/projectInformation/projectRegulatoryReport/__tests__/RegulatoryReport-it.tsx
  12. 1
    4
      server/sonar-web/src/main/js/apps/projectKey/__tests__/ProjectKeyApp-it.tsx
  13. 1
    4
      server/sonar-web/src/main/js/apps/projectNewCode/components/__tests__/ProjectNewCodeDefinitionApp-it.tsx
  14. 11
    19
      server/sonar-web/src/main/js/apps/security-hotspots/__tests__/SecurityHotspotsApp-it.tsx
  15. 5
    6
      server/sonar-web/src/main/js/apps/settings/components/pullRequestDecorationBinding/__tests__/PRDecorationBinding-it.tsx
  16. 5
    8
      server/sonar-web/src/main/js/components/controls/__tests__/Toggler-test.tsx
  17. 18
    52
      server/sonar-web/src/main/js/components/issue/__tests__/Issue-it.tsx
  18. 2
    7
      server/sonar-web/src/main/js/components/new-code-definition/__tests__/NCDAutoUpdateMessage-test.tsx

+ 2
- 4
server/sonar-web/design-system/src/components/input/__tests__/DateRangePicker-test.tsx View File

@@ -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' });

+ 2
- 4
server/sonar-web/design-system/src/components/input/__tests__/SearchSelectDropdown-test.tsx View File

@@ -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}');

+ 8
- 8
server/sonar-web/src/main/js/app/components/__tests__/ComponentContainer-test.tsx View File

@@ -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));

+ 3
- 4
server/sonar-web/src/main/js/app/components/__tests__/KeyboardShortcutsModal-test.tsx View File

@@ -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();
});

+ 17
- 25
server/sonar-web/src/main/js/apps/issues/components/__tests__/IssueOpenInIdeButton-test.tsx View File

@@ -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,

+ 5
- 16
server/sonar-web/src/main/js/apps/issues/components/__tests__/IssuesNewStatusAndTransitionGuide-test.tsx View File

@@ -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();
});

+ 8
- 22
server/sonar-web/src/main/js/apps/permissions/project/components/__tests__/PermissionsProject-it.tsx View File

@@ -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(

+ 2
- 2
server/sonar-web/src/main/js/apps/permissions/test-utils.ts View File

@@ -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());

+ 3
- 3
server/sonar-web/src/main/js/apps/projectInformation/about/components/__tests__/MetaTags-test.tsx View File

@@ -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' }));


+ 7
- 13
server/sonar-web/src/main/js/apps/projectInformation/badges/__tests__/ProjectBadges-test.tsx View File

@@ -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(

+ 4
- 8
server/sonar-web/src/main/js/apps/projectInformation/projectRegulatoryReport/__tests__/RegulatoryReport-it.tsx View File

@@ -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();
});

+ 1
- 4
server/sonar-web/src/main/js/apps/projectKey/__tests__/ProjectKeyApp-it.tsx View File

@@ -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);

+ 1
- 4
server/sonar-web/src/main/js/apps/projectNewCode/components/__tests__/ProjectNewCodeDefinitionApp-it.tsx View File

@@ -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();
});

+ 11
- 19
server/sonar-web/src/main/js/apps/security-hotspots/__tests__/SecurityHotspotsApp-it.tsx View File

@@ -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();
});

+ 5
- 6
server/sonar-web/src/main/js/apps/settings/components/pullRequestDecorationBinding/__tests__/PRDecorationBinding-it.tsx View File

@@ -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();
},

+ 5
- 8
server/sonar-web/src/main/js/components/controls/__tests__/Toggler-test.tsx View File

@@ -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();

+ 18
- 52
server/sonar-web/src/main/js/components/issue/__tests__/Issue-it.tsx View File

@@ -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}}`);
},
};


+ 2
- 7
server/sonar-web/src/main/js/components/new-code-definition/__tests__/NCDAutoUpdateMessage-test.tsx View File

@@ -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();
});
});

Loading…
Cancel
Save