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'));
return null;
}
-it('should display messages', () => {
+it('should display messages', async () => {
jest.useFakeTimers();
// we render anything, the GlobalMessageContainer is rendered independently from routing
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();
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
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) {
).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<ComponentNavProps> = {}) {
* 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';
},
[],
);
- 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();
* 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';
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();
});
});
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 () => {
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 () => {
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');
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);
+ });
});
});
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 () => {
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 () => {
* 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';
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();
},
* 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';
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();
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',
});
});
+const appLoaded = async () => {
+ await waitFor(() => {
+ expect(screen.getByText('loading')).toBeInTheDocument();
+ });
+
+ await waitFor(() => {
+ expect(screen.queryByText('loading')).not.toBeInTheDocument();
+ });
+};
+
function renderApp(props = {}, userProps = {}) {
return renderComponent(
<CurrentUserContextProvider currentUser={mockCurrentUser({ isLoggedIn: true, ...userProps })}>
* 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';
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
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();
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();
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');
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();
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 () => {
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();
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();
});
* 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';
});
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();
});
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');
});
* 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';
});
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 () => {
});
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());
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 () => {
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()));
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()));
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()));
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()));
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()));
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()));
},
});
- expect(await github.configurationValidityError.find()).toBeInTheDocument();
+ expect(
+ await github.configurationValidityError.find(undefined, { timeout: 10000 }),
+ ).toBeInTheDocument();
await act(() => user.click(github.checkConfigButton.get()));
* 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';
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());
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());
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());
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());