From 9185ced7d163951ab0c5b537be08fc52fe25f14e Mon Sep 17 00:00:00 2001 From: David Cho-Lerat Date: Thu, 23 Nov 2023 11:54:16 +0100 Subject: [PATCH] SONAR-21017 Tests: get => find + add timeouts that will be reverted by the upcoming RTL upgrade --- .../input/__tests__/MultiSelectMenu-test.tsx | 2 +- .../__tests__/GlobalMessagesContainer-it.tsx | 8 ++- .../IndexationContextProvider-test.tsx | 6 +- .../component/__tests__/ComponentNav-test.tsx | 4 +- .../nav/component/__tests__/Header-test.tsx | 15 +++-- .../js/apps/groups/__tests__/GroupsApp-it.tsx | 63 +++++++++++++++---- .../branches/__tests__/BranchOverview-it.tsx | 10 +-- .../components/__tests__/App-test.tsx | 18 +++++- .../ProjectNewCodeDefinitionApp-it.tsx | 49 ++++++++++++--- .../__tests__/ProjectManagementApp-it.tsx | 8 ++- .../__tests__/QualityProfileApp-it.tsx | 6 +- .../__tests__/QualityProfilesApp-it.tsx | 10 ++- .../components/__tests__/Login-it.tsx | 2 +- .../__tests__/NewCodeDefinition-it.tsx | 15 ++++- .../__tests__/Authentication-it.tsx | 32 +++++++--- .../__tests__/NCDAutoUpdateMessage-test.tsx | 55 +++++++++++++--- 16 files changed, 246 insertions(+), 57 deletions(-) diff --git a/server/sonar-web/design-system/src/components/input/__tests__/MultiSelectMenu-test.tsx b/server/sonar-web/design-system/src/components/input/__tests__/MultiSelectMenu-test.tsx index 9c2a7520aa9..5f572df9b51 100644 --- a/server/sonar-web/design-system/src/components/input/__tests__/MultiSelectMenu-test.tsx +++ b/server/sonar-web/design-system/src/components/input/__tests__/MultiSelectMenu-test.tsx @@ -42,7 +42,7 @@ it('should allow selecting and deselecting a new option', async () => { await user.keyboard('new option'); jest.runAllTimers(); // skip the debounce - expect(screen.getByText('new option')).toBeInTheDocument(); + expect(await screen.findByText('new option')).toBeInTheDocument(); await user.click(screen.getByText('new option')); diff --git a/server/sonar-web/src/main/js/app/components/__tests__/GlobalMessagesContainer-it.tsx b/server/sonar-web/src/main/js/app/components/__tests__/GlobalMessagesContainer-it.tsx index f89127aa2b0..908c4026f53 100644 --- a/server/sonar-web/src/main/js/app/components/__tests__/GlobalMessagesContainer-it.tsx +++ b/server/sonar-web/src/main/js/app/components/__tests__/GlobalMessagesContainer-it.tsx @@ -26,7 +26,7 @@ function NullComponent() { return null; } -it('should display messages', () => { +it('should display messages', async () => { jest.useFakeTimers(); // we render anything, the GlobalMessageContainer is rendered independently from routing @@ -35,14 +35,16 @@ it('should display messages', () => { addGlobalErrorMessage('This is an error'); addGlobalSuccessMessage('This was a triumph!'); - expect(screen.getByRole('alert')).toHaveTextContent('This is an error'); + expect(await screen.findByRole('alert')).toHaveTextContent('This is an error'); expect(screen.getByRole('status')).toHaveTextContent('This was a triumph!'); // No duplicate message addGlobalErrorMessage('This is an error'); expect(screen.getByRole('alert')).toHaveTextContent(/^This is an error$/); addGlobalSuccessMessage('This was a triumph!'); - expect(screen.getByRole('status')).toHaveTextContent(/^This was a triumph!This was a triumph!$/); + expect(await screen.findByRole('status')).toHaveTextContent( + /^This was a triumph!This was a triumph!$/, + ); jest.runAllTimers(); diff --git a/server/sonar-web/src/main/js/app/components/indexation/__tests__/IndexationContextProvider-test.tsx b/server/sonar-web/src/main/js/app/components/indexation/__tests__/IndexationContextProvider-test.tsx index 0c7d1eb9e2a..1482fd0020a 100644 --- a/server/sonar-web/src/main/js/app/components/indexation/__tests__/IndexationContextProvider-test.tsx +++ b/server/sonar-web/src/main/js/app/components/indexation/__tests__/IndexationContextProvider-test.tsx @@ -48,7 +48,7 @@ it('should not start polling if no issue sync is needed', () => { expect(IndexationNotificationHelper.startPolling).not.toHaveBeenCalled(); }); -it('should update the state on new status', () => { +it('should update the state on new status', async () => { renderIndexationContextProvider(); const triggerNewStatus = jest.mocked(IndexationNotificationHelper.startPolling).mock @@ -63,7 +63,9 @@ it('should update the state on new status', () => { triggerNewStatus(newStatus); - expect(byText('{"status":{"hasFailures":false,"isCompleted":true}}').get()).toBeInTheDocument(); + expect( + await byText('{"status":{"hasFailures":false,"isCompleted":true}}').find(), + ).toBeInTheDocument(); }); function renderIndexationContextProvider(props?: IndexationContextProviderProps) { 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 b184d09f82a..4cf2233bd48 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 @@ -57,10 +57,10 @@ it('renders correctly when the project binding is incorrect', () => { ).toBeInTheDocument(); }); -it('correctly returns focus to the Project Information link when the drawer is closed', () => { +it('correctly returns focus to the Project Information link when the drawer is closed', async () => { renderComponentNav(); screen.getByRole('link', { name: 'project.info.title' }).click(); - expect(screen.getByText('/project/information?id=my-project')).toBeInTheDocument(); + expect(await screen.findByText('/project/information?id=my-project')).toBeInTheDocument(); }); function renderComponentNav(props: Partial = {}) { diff --git a/server/sonar-web/src/main/js/app/components/nav/component/__tests__/Header-test.tsx b/server/sonar-web/src/main/js/app/components/nav/component/__tests__/Header-test.tsx index 48962968102..b0201af9146 100644 --- a/server/sonar-web/src/main/js/app/components/nav/component/__tests__/Header-test.tsx +++ b/server/sonar-web/src/main/js/app/components/nav/component/__tests__/Header-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 AlmSettingsServiceMock from '../../../../../api/mocks/AlmSettingsServiceMock'; @@ -169,9 +169,16 @@ it('should show the correct help tooltip when branch support is not enabled', as }, [], ); - expect( - await screen.findByText('branch_like_navigation.no_branch_support.title.mr'), - ).toBeInTheDocument(); + + await waitFor( + async () => { + expect( + await screen.findByText('branch_like_navigation.no_branch_support.title.mr'), + ).toBeInTheDocument(); + }, + { timeout: 10000 }, + ); + expect( screen.getByText('branch_like_navigation.no_branch_support.content_x.mr.alm.gitlab'), ).toBeInTheDocument(); diff --git a/server/sonar-web/src/main/js/apps/groups/__tests__/GroupsApp-it.tsx b/server/sonar-web/src/main/js/apps/groups/__tests__/GroupsApp-it.tsx index 34263fe216e..97429109251 100644 --- a/server/sonar-web/src/main/js/apps/groups/__tests__/GroupsApp-it.tsx +++ b/server/sonar-web/src/main/js/apps/groups/__tests__/GroupsApp-it.tsx @@ -18,7 +18,7 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -import { screen, within } from '@testing-library/react'; +import { screen, waitFor, within } from '@testing-library/react'; import userEvent from '@testing-library/user-event'; import * as React from 'react'; import { act } from 'react-dom/test-utils'; @@ -103,8 +103,14 @@ describe('in non managed mode', () => { it('should render all groups', async () => { renderGroupsApp(); - await act(async () => expect(await ui.localGroupRow.find()).toBeInTheDocument()); - expect(ui.managedGroupRow.get()).toBeInTheDocument(); + await waitFor( + async () => { + expect(await ui.localGroupRow.find()).toBeInTheDocument(); + }, + { timeout: 10000 }, + ); + + expect(await ui.managedGroupRow.find()).toBeInTheDocument(); expect(ui.localGroupRowWithLocalBadge.query()).not.toBeInTheDocument(); }); @@ -143,7 +149,13 @@ describe('in non managed mode', () => { }); expect(await ui.managedGroupRow.find()).toBeInTheDocument(); - expect(ui.localGroupRow.query()).not.toBeInTheDocument(); + + await waitFor( + async () => { + expect(await ui.localGroupRow.query()).not.toBeInTheDocument(); + }, + { timeout: 10000 }, + ); }); it('should be able to edit a group', async () => { @@ -178,7 +190,13 @@ describe('in non managed mode', () => { const user = userEvent.setup(); renderGroupsApp(); - await act(async () => expect(await ui.localGroupRow.find()).toBeInTheDocument()); + await waitFor( + async () => { + expect(await ui.localGroupRow.find()).toBeInTheDocument(); + }, + { timeout: 10000 }, + ); + expect(await ui.localGroupEditMembersButton.find()).toBeInTheDocument(); await act(async () => { @@ -213,8 +231,19 @@ describe('in non managed mode', () => { const user = userEvent.setup(); renderGroupsApp(); - await act(async () => expect(await ui.localGroupRow.find()).toBeInTheDocument()); - expect(ui.managedGroupRow.get()).toBeInTheDocument(); + await waitFor( + async () => { + expect(await ui.localGroupRow.find()).toBeInTheDocument(); + }, + { timeout: 10000 }, + ); + + await waitFor( + async () => { + expect(await ui.managedGroupRow.find()).toBeInTheDocument(); + }, + { timeout: 10000 }, + ); await act(async () => { await user.type(await ui.searchInput.find(), 'local'); @@ -228,14 +257,22 @@ describe('in non managed mode', () => { const user = userEvent.setup(); renderGroupsApp(); - await act(async () => expect(await ui.localGroupRow.find()).toBeInTheDocument()); + await waitFor( + async () => { + expect(await ui.localGroupRow.find()).toBeInTheDocument(); + }, + { timeout: 10000 }, + ); + expect(await screen.findAllByRole('row')).toHaveLength(3); await act(async () => { await user.click(await ui.showMore.find()); }); - expect(await screen.findAllByRole('row')).toHaveLength(5); + await waitFor(async () => { + expect(await screen.findAllByRole('row')).toHaveLength(5); + }); }); }); @@ -270,7 +307,10 @@ describe('in manage mode', () => { await act(async () => { await user.click(ui.deleteDialogButton.get()); }); - expect(ui.localGroupRowWithLocalBadge.query()).not.toBeInTheDocument(); + + await waitFor(() => { + expect(ui.localGroupRowWithLocalBadge.query()).not.toBeInTheDocument(); + }); }); it('should not be able to delete or edit a managed group', async () => { @@ -300,7 +340,8 @@ describe('in manage mode', () => { await act(async () => expect(await ui.localAndManagedFilter.find()).toBeInTheDocument()); expect(await ui.localGroupRowWithLocalBadge.find()).toBeInTheDocument(); - expect(ui.managedGroupRow.get()).toBeInTheDocument(); + + expect(await ui.managedGroupRow.find()).toBeInTheDocument(); }); it('should render list of managed groups', async () => { diff --git a/server/sonar-web/src/main/js/apps/overview/branches/__tests__/BranchOverview-it.tsx b/server/sonar-web/src/main/js/apps/overview/branches/__tests__/BranchOverview-it.tsx index 2fa2f27f4e6..435e54ca0fe 100644 --- a/server/sonar-web/src/main/js/apps/overview/branches/__tests__/BranchOverview-it.tsx +++ b/server/sonar-web/src/main/js/apps/overview/branches/__tests__/BranchOverview-it.tsx @@ -18,7 +18,7 @@ * 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 { getMeasuresWithPeriodAndMetrics } from '../../../../api/measures'; @@ -487,9 +487,11 @@ it.each([ await screen.findByText('overview.quality_gate.status'); - expect( - screen.queryByText(/overview.quality_profiles_update_after_sq_upgrade.message/) !== null, - ).toBe(expected); + await waitFor(() => + expect( + screen.queryByText(/overview.quality_profiles_update_after_sq_upgrade.message/) !== null, + ).toBe(expected), + ); jest.useRealTimers(); }, diff --git a/server/sonar-web/src/main/js/apps/overview/components/__tests__/App-test.tsx b/server/sonar-web/src/main/js/apps/overview/components/__tests__/App-test.tsx index f8ed71133a4..aab093e3ad7 100644 --- a/server/sonar-web/src/main/js/apps/overview/components/__tests__/App-test.tsx +++ b/server/sonar-web/src/main/js/apps/overview/components/__tests__/App-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 * as React from 'react'; import BranchesServiceMock from '../../../../api/mocks/BranchesServiceMock'; import ComputeEngineServiceMock from '../../../../api/mocks/ComputeEngineServiceMock'; @@ -42,12 +42,16 @@ beforeEach(() => { it('should render Empty Overview for Application with no analysis', async () => { renderApp({ component: mockComponent({ qualifier: ComponentQualifier.Application }) }); + await appLoaded(); + expect(await screen.findByText('provisioning.no_analysis.application')).toBeInTheDocument(); }); it('should render Empty Overview on main branch with no analysis', async () => { renderApp({}, mockCurrentUser()); + await appLoaded(); + expect( await screen.findByText('provisioning.no_analysis_on_main_branch.main'), ).toBeInTheDocument(); @@ -56,6 +60,8 @@ it('should render Empty Overview on main branch with no analysis', async () => { it('should render Empty Overview on main branch with multiple branches with bad configuration', async () => { renderApp({ branchLikes: [mockBranch(), mockBranch()] }); + await appLoaded(); + expect( await screen.findByText( 'provisioning.no_analysis_on_main_branch.bad_configuration.main.branches.main_branch', @@ -116,6 +122,16 @@ describe('Permission provisioning', () => { }); }); +const appLoaded = async () => { + await waitFor(() => { + expect(screen.getByText('loading')).toBeInTheDocument(); + }); + + await waitFor(() => { + expect(screen.queryByText('loading')).not.toBeInTheDocument(); + }); +}; + function renderApp(props = {}, userProps = {}) { return renderComponent( 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 93449f2b24f..a716a77d19a 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,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 } from '@testing-library/react'; +import { act, waitFor } from '@testing-library/react'; import userEvent from '@testing-library/user-event'; import { last } from 'lodash'; import selectEvent from 'react-select-event'; @@ -60,7 +60,13 @@ it('renders correctly without branch support feature', async () => { renderProjectNewCodeDefinitionApp(); await ui.appIsLoaded(); - expect(await ui.generalSettingRadio.find()).toBeChecked(); + await waitFor( + async () => { + expect(await ui.generalSettingRadio.find()).toBeChecked(); + }, + { timeout: 10000 }, + ); + expect(ui.specificAnalysisRadio.query()).not.toBeInTheDocument(); // User is not admin @@ -95,7 +101,13 @@ it('can set previous version specific setting', async () => { renderProjectNewCodeDefinitionApp(); await ui.appIsLoaded(); - expect(await ui.previousVersionRadio.find()).toHaveClass('disabled'); + await waitFor( + async () => { + expect(await ui.previousVersionRadio.find()).toHaveClass('disabled'); + }, + { timeout: 10000 }, + ); + await ui.setPreviousVersionSetting(); expect(ui.previousVersionRadio.get()).toBeChecked(); @@ -116,7 +128,13 @@ it('can set number of days specific setting', async () => { renderProjectNewCodeDefinitionApp(); await ui.appIsLoaded(); - expect(await ui.numberDaysRadio.find()).toHaveClass('disabled'); + await waitFor( + async () => { + expect(await ui.numberDaysRadio.find()).toHaveClass('disabled'); + }, + { timeout: 10000 }, + ); + await ui.setNumberDaysSetting('10'); expect(ui.numberDaysRadio.get()).toBeChecked(); @@ -167,7 +185,13 @@ it('cannot set specific analysis setting', async () => { renderProjectNewCodeDefinitionApp(); await ui.appIsLoaded(); - expect(await ui.specificAnalysisRadio.find()).toBeChecked(); + await waitFor( + async () => { + expect(await ui.specificAnalysisRadio.find()).toBeChecked(); + }, + { timeout: 10000 }, + ); + expect(ui.baselineSpecificAnalysisDate.get()).toBeInTheDocument(); expect(ui.specificAnalysisRadio.get()).toHaveClass('disabled'); @@ -286,7 +310,13 @@ it('should display NCD banner if some branches had their NCD automatically chang featureList: [Feature.BranchSupport], }); - expect(await ui.branchNCDsBanner.find()).toBeInTheDocument(); + await waitFor( + async () => { + expect(await ui.branchNCDsBanner.find()).toBeInTheDocument(); + }, + { timeout: 10000 }, + ); + expect( ui.branchNCDsBanner.byText('new_code_definition.auto_update.branch.list_itemmaster32150').get(), ).toBeInTheDocument(); @@ -351,7 +381,12 @@ it('should correctly dismiss branch banner', async () => { featureList: [Feature.BranchSupport], }); - expect(await ui.branchNCDsBanner.find()).toBeInTheDocument(); + await waitFor( + async () => { + expect(await ui.branchNCDsBanner.find()).toBeInTheDocument(); + }, + { timeout: 10000 }, + ); const user = userEvent.setup(); await act(async () => { diff --git a/server/sonar-web/src/main/js/apps/projectsManagement/__tests__/ProjectManagementApp-it.tsx b/server/sonar-web/src/main/js/apps/projectsManagement/__tests__/ProjectManagementApp-it.tsx index da9fd74d2ba..dffc35358ad 100644 --- a/server/sonar-web/src/main/js/apps/projectsManagement/__tests__/ProjectManagementApp-it.tsx +++ b/server/sonar-web/src/main/js/apps/projectsManagement/__tests__/ProjectManagementApp-it.tsx @@ -544,7 +544,13 @@ it('should not apply permissions for github projects', async () => { it('should not show local badge for applications and portfolios', async () => { authHandler.githubProvisioningStatus = true; renderProjectManagementApp({}, {}, { featureList: [Feature.GithubProvisioning] }); - await waitFor(() => expect(screen.getAllByText('local')).toHaveLength(3)); + + await waitFor( + async () => { + expect(await screen.findAllByText('local')).toHaveLength(3); + }, + { timeout: 10000 }, + ); await selectEvent.select(ui.qualifierFilter.get(), 'qualifiers.VW'); expect(screen.queryByText('local')).not.toBeInTheDocument(); diff --git a/server/sonar-web/src/main/js/apps/quality-profiles/__tests__/QualityProfileApp-it.tsx b/server/sonar-web/src/main/js/apps/quality-profiles/__tests__/QualityProfileApp-it.tsx index 729626185f3..48a65ae7cb1 100644 --- a/server/sonar-web/src/main/js/apps/quality-profiles/__tests__/QualityProfileApp-it.tsx +++ b/server/sonar-web/src/main/js/apps/quality-profiles/__tests__/QualityProfileApp-it.tsx @@ -445,7 +445,11 @@ describe('Users with no permission', () => { it('should not be able to grant permission to a user', async () => { renderQualityProfile(); - expect(await screen.findByText('Good old PHP quality profile')).toBeInTheDocument(); + + await ui.waitForDataLoaded(); + + expect(await screen.findAllByText('Good old PHP quality profile')).toHaveLength(2); + expect(ui.permissionSection.query()).not.toBeInTheDocument(); }); diff --git a/server/sonar-web/src/main/js/apps/quality-profiles/__tests__/QualityProfilesApp-it.tsx b/server/sonar-web/src/main/js/apps/quality-profiles/__tests__/QualityProfilesApp-it.tsx index 3e30fd68b4b..af778f3c083 100644 --- a/server/sonar-web/src/main/js/apps/quality-profiles/__tests__/QualityProfilesApp-it.tsx +++ b/server/sonar-web/src/main/js/apps/quality-profiles/__tests__/QualityProfilesApp-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, getByText, screen } from '@testing-library/react'; +import { act, getByText, screen, waitFor } from '@testing-library/react'; import userEvent from '@testing-library/user-event'; import selectEvent from 'react-select-event'; import QualityProfilesServiceMock from '../../../api/mocks/QualityProfilesServiceMock'; @@ -181,7 +181,13 @@ describe('Evolution', () => { }); renderQualityProfiles(); - expect(await ui.recentlyAddedRulesRegion.find()).toBeInTheDocument(); + await waitFor( + async () => { + expect(await ui.recentlyAddedRulesRegion.find()).toBeInTheDocument(); + }, + { timeout: 10000 }, + ); + expect(ui.newRuleLink.get()).toBeInTheDocument(); expect(ui.seeAllNewRulesLink.get()).toBeInTheDocument(); }); diff --git a/server/sonar-web/src/main/js/apps/sessions/components/__tests__/Login-it.tsx b/server/sonar-web/src/main/js/apps/sessions/components/__tests__/Login-it.tsx index 48a13602ed3..7864492228b 100644 --- a/server/sonar-web/src/main/js/apps/sessions/components/__tests__/Login-it.tsx +++ b/server/sonar-web/src/main/js/apps/sessions/components/__tests__/Login-it.tsx @@ -104,7 +104,7 @@ it('should behave correctly', async () => { await user.type(passwordField, 'invalid'); // Don't use userEvent.click() here. This allows us to more easily see the loading state changes. submitButton.click(); - expect(submitButton).toBeDisabled(); // Loading. + await waitFor(() => expect(submitButton).toBeDisabled()); // Loading. await waitFor(() => { expect(addGlobalErrorMessage).toHaveBeenCalledWith('login.authentication_failed'); }); diff --git a/server/sonar-web/src/main/js/apps/settings/components/__tests__/NewCodeDefinition-it.tsx b/server/sonar-web/src/main/js/apps/settings/components/__tests__/NewCodeDefinition-it.tsx index 2d4621dadc0..681f23691bf 100644 --- a/server/sonar-web/src/main/js/apps/settings/components/__tests__/NewCodeDefinition-it.tsx +++ b/server/sonar-web/src/main/js/apps/settings/components/__tests__/NewCodeDefinition-it.tsx @@ -17,6 +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 { waitFor } from '@testing-library/react'; import userEvent from '@testing-library/user-event'; import * as React from 'react'; import { MessageTypes } from '../../../../api/messages'; @@ -108,7 +109,12 @@ it('displays information message when NCD is automatically updated', async () => }); renderNewCodePeriod(); - expect(await ui.ncdAutoUpdateMessage.find()).toBeVisible(); + await waitFor( + async () => { + expect(await ui.ncdAutoUpdateMessage.find()).toBeVisible(); + }, + { timeout: 10000 }, + ); }); it('dismisses information message when NCD is automatically updated', async () => { @@ -120,7 +126,12 @@ it('dismisses information message when NCD is automatically updated', async () = }); renderNewCodePeriod(); - expect(await ui.ncdAutoUpdateMessage.find()).toBeVisible(); + await waitFor( + async () => { + expect(await ui.ncdAutoUpdateMessage.find()).toBeVisible(); + }, + { timeout: 10000 }, + ); const user = userEvent.setup(); await user.click(ui.ncdAutoUpdateMessageDismiss.get()); diff --git a/server/sonar-web/src/main/js/apps/settings/components/authentication/__tests__/Authentication-it.tsx b/server/sonar-web/src/main/js/apps/settings/components/authentication/__tests__/Authentication-it.tsx index 18c872bacdd..c36346c4768 100644 --- a/server/sonar-web/src/main/js/apps/settings/components/authentication/__tests__/Authentication-it.tsx +++ b/server/sonar-web/src/main/js/apps/settings/components/authentication/__tests__/Authentication-it.tsx @@ -569,7 +569,9 @@ describe('Github tab', () => { renderAuthentication([Feature.GithubProvisioning]); await github.enableConfiguration(user); - await waitFor(() => expect(github.configurationValiditySuccess.query()).toBeInTheDocument()); + expect( + await github.configurationValiditySuccess.find(undefined, { timeout: 10000 }), + ).toBeInTheDocument(); }); it('should display that config is valid for both provisioning with multiple orgs', async () => { @@ -590,7 +592,9 @@ describe('Github tab', () => { renderAuthentication([Feature.GithubProvisioning]); await github.enableConfiguration(user); - await waitFor(() => expect(github.configurationValiditySuccess.query()).toBeInTheDocument()); + expect( + await github.configurationValiditySuccess.find(undefined, { timeout: 10000 }), + ).toBeInTheDocument(); expect(github.configurationValiditySuccess.get()).toHaveTextContent('2'); await act(() => user.click(github.viewConfigValidityDetailsButton.get())); @@ -626,7 +630,9 @@ describe('Github tab', () => { renderAuthentication([Feature.GithubProvisioning]); await github.enableConfiguration(user); - await waitFor(() => expect(github.configurationValidityWarning.get()).toBeInTheDocument()); + expect( + await github.configurationValidityWarning.find(undefined, { timeout: 10000 }), + ).toBeInTheDocument(); expect(github.configurationValidityWarning.get()).toHaveTextContent(errorMessage); await act(() => user.click(github.viewConfigValidityDetailsButton.get())); @@ -660,7 +666,9 @@ describe('Github tab', () => { renderAuthentication([Feature.GithubProvisioning]); await github.enableConfiguration(user); - await waitFor(() => expect(github.configurationValiditySuccess.get()).toBeInTheDocument()); + expect( + await github.configurationValiditySuccess.find(undefined, { timeout: 10000 }), + ).toBeInTheDocument(); expect(github.configurationValiditySuccess.get()).toHaveTextContent('1'); await act(() => user.click(github.viewConfigValidityDetailsButton.get())); @@ -692,7 +700,9 @@ describe('Github tab', () => { renderAuthentication([Feature.GithubProvisioning]); await github.enableConfiguration(user); - await waitFor(() => expect(github.configurationValidityError.query()).toBeInTheDocument()); + expect( + await github.configurationValidityError.find(undefined, { timeout: 10000 }), + ).toBeInTheDocument(); expect(github.configurationValidityError.get()).toHaveTextContent(errorMessage); await act(() => user.click(github.viewConfigValidityDetailsButton.get())); @@ -718,7 +728,9 @@ describe('Github tab', () => { renderAuthentication([Feature.GithubProvisioning]); await github.enableConfiguration(user); - await waitFor(() => expect(github.configurationValiditySuccess.query()).toBeInTheDocument()); + expect( + await github.configurationValiditySuccess.find(undefined, { timeout: 10000 }), + ).toBeInTheDocument(); expect(github.configurationValiditySuccess.get()).not.toHaveTextContent(errorMessage); await act(() => user.click(github.viewConfigValidityDetailsButton.get())); @@ -759,7 +771,9 @@ describe('Github tab', () => { renderAuthentication([Feature.GithubProvisioning]); await github.enableConfiguration(user); - await waitFor(() => expect(github.configurationValiditySuccess.query()).toBeInTheDocument()); + expect( + await github.configurationValiditySuccess.find(undefined, { timeout: 10000 }), + ).toBeInTheDocument(); await act(() => user.click(github.viewConfigValidityDetailsButton.get())); @@ -813,7 +827,9 @@ describe('Github tab', () => { }, }); - expect(await github.configurationValidityError.find()).toBeInTheDocument(); + expect( + await github.configurationValidityError.find(undefined, { timeout: 10000 }), + ).toBeInTheDocument(); await act(() => user.click(github.checkConfigButton.get())); 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 aad1103dec6..af14a35d866 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,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 } from '@testing-library/react'; +import { act, waitFor } from '@testing-library/react'; import userEvent from '@testing-library/user-event'; import React from 'react'; import { Route } from 'react-router-dom'; @@ -84,13 +84,26 @@ describe('Global NCD update notification banner', () => { it('renders global banner if user is global admin', async () => { newCodeDefinitionMock.setNewCodePeriod(previouslyNonCompliantNewCodeDefinition); renderGlobalMessage(); - expect(await ui.globalBannerContent.find()).toBeVisible(); + + await waitFor( + async () => { + expect(await ui.globalBannerContent.find()).toBeVisible(); + }, + { timeout: 10000 }, + ); }); it('dismisses global banner', async () => { newCodeDefinitionMock.setNewCodePeriod(previouslyNonCompliantNewCodeDefinition); renderGlobalMessage(); - expect(await ui.globalBannerContent.find()).toBeVisible(); + + await waitFor( + async () => { + expect(await ui.globalBannerContent.find()).toBeVisible(); + }, + { timeout: 10000 }, + ); + const user = userEvent.setup(); await act(async () => { await user.click(ui.dismissButton.get()); @@ -117,7 +130,14 @@ describe('Global NCD update notification banner', () => { it('clicking on review link redirects to global NCD admin page', async () => { newCodeDefinitionMock.setNewCodePeriod(previouslyNonCompliantNewCodeDefinition); renderGlobalMessage(); - expect(await ui.globalBannerContent.find()).toBeVisible(); + + await waitFor( + async () => { + expect(await ui.globalBannerContent.find()).toBeVisible(); + }, + { timeout: 10000 }, + ); + const user = userEvent.setup(); await act(async () => { await user.click(ui.reviewLink.get()); @@ -181,13 +201,26 @@ describe('Project NCD update notification banner', () => { it('renders project banner if user is project admin', async () => { newCodeDefinitionMock.setNewCodePeriod(previouslyNonCompliantNewCodeDefinition); renderProjectMessage(component); - expect(await ui.projectBannerContent.find()).toBeVisible(); + + await waitFor( + async () => { + expect(await ui.projectBannerContent.find()).toBeVisible(); + }, + { timeout: 10000 }, + ); }); it('dismisses project banner', async () => { newCodeDefinitionMock.setNewCodePeriod(previouslyNonCompliantNewCodeDefinition); renderProjectMessage(component); - expect(await ui.projectBannerContent.find()).toBeVisible(); + + await waitFor( + async () => { + expect(await ui.projectBannerContent.find()).toBeVisible(); + }, + { timeout: 10000 }, + ); + const user = userEvent.setup(); await act(async () => { await user.click(ui.dismissButton.get()); @@ -214,8 +247,16 @@ describe('Project NCD update notification banner', () => { it('clicking on review link redirects to project NCD admin page', async () => { newCodeDefinitionMock.setNewCodePeriod(previouslyNonCompliantNewCodeDefinition); + renderProjectMessage(component); - expect(await ui.projectBannerContent.find()).toBeVisible(); + + await waitFor( + async () => { + expect(await ui.projectBannerContent.find()).toBeVisible(); + }, + { timeout: 10000 }, + ); + const user = userEvent.setup(); await act(async () => { await user.click(ui.reviewLink.get()); -- 2.39.5