*/
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';
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());
],
['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();
* 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(),
});
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();
});
{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>
)}
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>
);
}
* 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 {
// 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();
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();
});
expect(subscribeToEmailReport).toHaveBeenCalledWith(component.key, branch.name);
expect(await screen.findByRole('status')).toBeInTheDocument();
- await new Promise(setImmediate);
-
// And unsubscribe!
await user.click(button);
renderComponentReportActions({ currentUser: mockLoggedInUser({ email: undefined }) });
- await new Promise(setImmediate);
-
await user.click(
await screen.findByRole('button', {
name: 'component_report.report.qualifier.TRK',
* 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';
}));
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();
expect(button).toBeInTheDocument();
expect(button).toHaveFocus();
- button.click();
+ await user.click(button);
await new Promise(setImmediate);
expect(removeFavorite).toHaveBeenCalled();
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);
});