diff options
author | Viktor Vorona <viktor.vorona@sonarsource.com> | 2024-02-22 12:00:30 +0100 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2024-02-22 20:02:53 +0000 |
commit | b312363fc8736cf2d38103d5fc6f97328e85a109 (patch) | |
tree | ba70a31454af009b0c764af2eee1a3cc3433c7c5 /server/sonar-web/src | |
parent | 1c8187671280d84c680057eb02f8f9e3e50ae2ad (diff) | |
download | sonarqube-b312363fc8736cf2d38103d5fc6f97328e85a109.tar.gz sonarqube-b312363fc8736cf2d38103d5fc6f97328e85a109.zip |
SONAR-21692 fix leftovers with act warnings
Diffstat (limited to 'server/sonar-web/src')
6 files changed, 35 insertions, 29 deletions
diff --git a/server/sonar-web/src/main/js/app/components/__tests__/StartupModal-test.tsx b/server/sonar-web/src/main/js/app/components/__tests__/StartupModal-test.tsx index 01be426d2fb..99f1d7f37ec 100644 --- a/server/sonar-web/src/main/js/app/components/__tests__/StartupModal-test.tsx +++ b/server/sonar-web/src/main/js/app/components/__tests__/StartupModal-test.tsx @@ -19,6 +19,7 @@ */ import userEvent from '@testing-library/user-event'; import * as React from 'react'; +import { showLicense } from '../../../api/editions'; import { save } from '../../../helpers/storage'; import { mockAppState, mockCurrentUser } from '../../../helpers/testMocks'; import { renderApp } from '../../../helpers/testReactTestingUtils'; @@ -60,10 +61,8 @@ it('should check license and open on its own', async () => { const user = userEvent.setup(); renderStartupModal(); - await new Promise(setImmediate); - + expect(await ui.modalHeader.find()).toBeInTheDocument(); expect(save).toHaveBeenCalled(); - expect(ui.modalHeader.get()).toBeInTheDocument(); await user.click(ui.licensePageLink.get()); @@ -77,10 +76,10 @@ it.each([ ], ['Cannot admin', { appState: mockAppState({ canAdmin: false, edition: EditionKey.enterprise }) }], ['User is not logged in', { currentUser: mockCurrentUser() }], -])('should not open when not necessary: %s', async (_, props: Partial<StartupModal['props']>) => { +])('should not open when not necessary: %s', (_, props: Partial<StartupModal['props']>) => { renderStartupModal(props); - await new Promise(setImmediate); + expect(showLicense).not.toHaveBeenCalled(); expect(save).not.toHaveBeenCalled(); expect(ui.modalHeader.query()).not.toBeInTheDocument(); diff --git a/server/sonar-web/src/main/js/app/components/nav/component/__tests__/ComponentNav-test.tsx b/server/sonar-web/src/main/js/app/components/nav/component/__tests__/ComponentNav-test.tsx index c711da7c938..1331723adba 100644 --- a/server/sonar-web/src/main/js/app/components/nav/component/__tests__/ComponentNav-test.tsx +++ b/server/sonar-web/src/main/js/app/components/nav/component/__tests__/ComponentNav-test.tsx @@ -18,13 +18,24 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ import { screen } from '@testing-library/react'; +import userEvent from '@testing-library/user-event'; import React from 'react'; +import AlmSettingsServiceMock from '../../../../../api/mocks/AlmSettingsServiceMock'; +import BranchesServiceMock from '../../../../../api/mocks/BranchesServiceMock'; import { mockProjectAlmBindingConfigurationErrors } from '../../../../../helpers/mocks/alm-settings'; import { mockComponent } from '../../../../../helpers/mocks/component'; import { renderApp } from '../../../../../helpers/testReactTestingUtils'; import { ComponentQualifier } from '../../../../../types/component'; import ComponentNav, { ComponentNavProps } from '../ComponentNav'; +const branchesHandler = new BranchesServiceMock(); +const almHandler = new AlmSettingsServiceMock(); + +afterEach(() => { + branchesHandler.reset(); + almHandler.reset(); +}); + it('renders correctly when the project binding is incorrect', () => { renderComponentNav({ projectBindingErrors: mockProjectAlmBindingConfigurationErrors(), @@ -35,8 +46,9 @@ it('renders correctly when the project binding is incorrect', () => { }); it('correctly returns focus to the Project Information link when the drawer is closed', async () => { + const user = userEvent.setup(); renderComponentNav(); - screen.getByRole('link', { name: 'project.info.title' }).click(); + await user.click(screen.getByRole('link', { name: 'project.info.title' })); expect(await screen.findByText('/project/information?id=my-project')).toBeInTheDocument(); }); diff --git a/server/sonar-web/src/main/js/apps/quality-gates/components/Conditions.tsx b/server/sonar-web/src/main/js/apps/quality-gates/components/Conditions.tsx index dbac85e2521..b66f0808576 100644 --- a/server/sonar-web/src/main/js/apps/quality-gates/components/Conditions.tsx +++ b/server/sonar-web/src/main/js/apps/quality-gates/components/Conditions.tsx @@ -189,14 +189,14 @@ export default function Conditions({ qualityGate, isFetching }: Readonly<Props>) {uniqDuplicates.length > 0 && ( <FlagMessage variant="warning" className="sw-flex sw-mb-4"> - <p> + <div> <p>{translate('quality_gates.duplicated_conditions')}</p> <ul className="sw-my-2 sw-list-disc sw-pl-10"> {uniqDuplicates.map((d) => ( <li key={d.metric.key}>{getLocalizedMetricName(d.metric)}</li> ))} </ul> - </p> + </div> </FlagMessage> )} diff --git a/server/sonar-web/src/main/js/apps/settings/components/pullRequestDecorationBinding/AlmSpecificForm.tsx b/server/sonar-web/src/main/js/apps/settings/components/pullRequestDecorationBinding/AlmSpecificForm.tsx index 5fe2cffb0ad..719a08495fc 100644 --- a/server/sonar-web/src/main/js/apps/settings/components/pullRequestDecorationBinding/AlmSpecificForm.tsx +++ b/server/sonar-web/src/main/js/apps/settings/components/pullRequestDecorationBinding/AlmSpecificForm.tsx @@ -94,12 +94,10 @@ function renderHelp({ help, helpExample, helpParams = {}, id }: CommonFieldProps function renderLabel(props: LabelProps) { const { optional, id } = props; return ( - <SubHeading> - <label htmlFor={id}> - {translate('settings.pr_decoration.binding.form', id)} - {!optional && <MandatoryFieldMarker />} - </label> - </SubHeading> + <label htmlFor={id}> + {translate('settings.pr_decoration.binding.form', id)} + {!optional && <MandatoryFieldMarker />} + </label> ); } diff --git a/server/sonar-web/src/main/js/components/controls/__tests__/ComponentReportActions-test.tsx b/server/sonar-web/src/main/js/components/controls/__tests__/ComponentReportActions-test.tsx index 640e645e528..b056fc86315 100644 --- a/server/sonar-web/src/main/js/components/controls/__tests__/ComponentReportActions-test.tsx +++ b/server/sonar-web/src/main/js/components/controls/__tests__/ComponentReportActions-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 { screen } from '@testing-library/react'; +import { screen, waitFor } from '@testing-library/react'; import userEvent from '@testing-library/user-event'; import * as React from 'react'; import { @@ -59,7 +59,7 @@ it('should not render anything when no status', async () => { // Loading expect(screen.queryByRole('button')).not.toBeInTheDocument(); - await new Promise(setImmediate); // Make sure we wait until we're done loading + await waitFor(() => expect(getReportStatus).toHaveBeenCalled()); // No status expect(screen.queryByRole('button')).not.toBeInTheDocument(); @@ -70,15 +70,15 @@ it('should not render anything when branch is purgeable', async () => { branch: mockBranch({ excludedFromPurge: false }), }); - await new Promise(setImmediate); // Make sure we wait until we're done loading + await waitFor(() => expect(getReportStatus).toHaveBeenCalled()); expect(screen.queryByRole('button')).not.toBeInTheDocument(); }); -it('should not render anything without governance', async () => { +it('should not render anything without governance', () => { renderComponentReportActions({ appState: mockAppState({ qualifiers: [] }) }); - await new Promise(setImmediate); // Make sure we wait until we're done loading + expect(getReportStatus).not.toHaveBeenCalled(); expect(screen.queryByRole('button')).not.toBeInTheDocument(); }); @@ -120,8 +120,6 @@ it('should allow user to (un)subscribe', async () => { expect(subscribeToEmailReport).toHaveBeenCalledWith(component.key, branch.name); expect(await screen.findByRole('status')).toBeInTheDocument(); - await new Promise(setImmediate); - // And unsubscribe! await user.click(button); @@ -143,8 +141,6 @@ it('should prevent user to subscribe if no email', async () => { renderComponentReportActions({ currentUser: mockLoggedInUser({ email: undefined }) }); - await new Promise(setImmediate); - await user.click( await screen.findByRole('button', { name: 'component_report.report.qualifier.TRK', diff --git a/server/sonar-web/src/main/js/components/controls/__tests__/Favorite-test.tsx b/server/sonar-web/src/main/js/components/controls/__tests__/Favorite-test.tsx index a95e6bce367..946a5ca6ead 100644 --- a/server/sonar-web/src/main/js/components/controls/__tests__/Favorite-test.tsx +++ b/server/sonar-web/src/main/js/components/controls/__tests__/Favorite-test.tsx @@ -18,6 +18,7 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ import { screen } from '@testing-library/react'; +import userEvent from '@testing-library/user-event'; import * as React from 'react'; import { addFavorite, removeFavorite } from '../../../api/favorites'; import { renderComponent } from '../../../helpers/testReactTestingUtils'; @@ -30,11 +31,12 @@ jest.mock('../../../api/favorites', () => ({ })); it('renders and behaves correctly', async () => { + const user = userEvent.setup(); renderFavorite({ favorite: false }); let button = screen.getByRole('button'); expect(button).toBeInTheDocument(); - button.click(); + await user.click(button); await new Promise(setImmediate); expect(addFavorite).toHaveBeenCalled(); @@ -42,7 +44,7 @@ it('renders and behaves correctly', async () => { expect(button).toBeInTheDocument(); expect(button).toHaveFocus(); - button.click(); + await user.click(button); await new Promise(setImmediate); expect(removeFavorite).toHaveBeenCalled(); @@ -53,14 +55,13 @@ it('renders and behaves correctly', async () => { it('correctly calls handleFavorite if passed', async () => { const handleFavorite = jest.fn(); + const user = userEvent.setup(); renderFavorite({ handleFavorite }); - screen.getByRole('button').click(); - await new Promise(setImmediate); + await user.click(screen.getByRole('button')); expect(handleFavorite).toHaveBeenCalledWith('foo', false); - screen.getByRole('button').click(); - await new Promise(setImmediate); + await user.click(screen.getByRole('button')); expect(handleFavorite).toHaveBeenCalledWith('foo', true); }); |