test: Move clicking helper functions to wizardTestUtils

As clicking helper functions are used only in the context of Wizard, this moves them to an appropriate place.
This commit is contained in:
regexowl 2024-08-09 15:00:05 +02:00 committed by Ondřej Ezr
parent a3abc29f51
commit d0412db518
18 changed files with 66 additions and 83 deletions

View file

@ -5,17 +5,18 @@ import { screen, waitFor } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { http, HttpResponse } from 'msw';
import CreateImageWizard from '../../../Components/CreateImageWizard/CreateImageWizard';
import ShareImageModal from '../../../Components/ShareImageModal/ShareImageModal';
import { PROVISIONING_API } from '../../../constants';
import { server } from '../../mocks/server';
import {
clickBack,
clickNext,
getNextButton,
renderCustomRoutesWithReduxRouter,
verifyCancelButton,
} from '../../testUtils';
} from './wizardTestUtils';
import CreateImageWizard from '../../../Components/CreateImageWizard/CreateImageWizard';
import ShareImageModal from '../../../Components/ShareImageModal/ShareImageModal';
import { PROVISIONING_API } from '../../../constants';
import { server } from '../../mocks/server';
import { renderCustomRoutesWithReduxRouter } from '../../testUtils';
const routes = [
{

View file

@ -3,9 +3,11 @@ import React from 'react';
import { screen, waitFor } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { clickNext } from './wizardTestUtils';
import CreateImageWizard from '../../../Components/CreateImageWizard/CreateImageWizard';
import ShareImageModal from '../../../Components/ShareImageModal/ShareImageModal';
import { clickNext, renderCustomRoutesWithReduxRouter } from '../../testUtils';
import { renderCustomRoutesWithReduxRouter } from '../../testUtils';
const routes = [
{

View file

@ -5,14 +5,10 @@ import { screen, waitFor, within } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { selectCustomRepo } from './wizardTestUtils';
import { clickBack, clickNext, verifyCancelButton } from './wizardTestUtils';
import CreateImageWizard from '../../../Components/CreateImageWizard/CreateImageWizard';
import {
clickBack,
clickNext,
renderCustomRoutesWithReduxRouter,
verifyCancelButton,
} from '../../testUtils';
import { renderCustomRoutesWithReduxRouter } from '../../testUtils';
const routes = [
{

View file

@ -9,18 +9,18 @@ import {
enterBlueprintName,
openAndDismissSaveAndBuildModal,
} from './wizardTestUtils';
import {
clickBack,
clickNext,
getNextButton,
verifyCancelButton,
} from './wizardTestUtils';
import CreateImageWizard from '../../../Components/CreateImageWizard/CreateImageWizard';
import ShareImageModal from '../../../Components/ShareImageModal/ShareImageModal';
import { PROVISIONING_API } from '../../../constants';
import { server } from '../../mocks/server';
import {
clickBack,
clickNext,
getNextButton,
renderCustomRoutesWithReduxRouter,
verifyCancelButton,
} from '../../testUtils';
import { renderCustomRoutesWithReduxRouter } from '../../testUtils';
const routes = [
{

View file

@ -4,7 +4,7 @@ import { userEvent } from '@testing-library/user-event';
import { CREATE_BLUEPRINT, EDIT_BLUEPRINT } from '../../../../../constants';
import { mockBlueprintIds } from '../../../../fixtures/blueprints';
import { detailsCreateBlueprintRequest } from '../../../../fixtures/editMode';
import { clickNext, getNextButton } from '../../../../testUtils';
import { clickNext, getNextButton } from '../../wizardTestUtils';
import {
blueprintRequest,
clickRegisterLater,

View file

@ -10,7 +10,7 @@ import {
} from '../../../../../constants';
import { mockBlueprintIds } from '../../../../fixtures/blueprints';
import { fscCreateBlueprintRequest } from '../../../../fixtures/editMode';
import { clickNext } from '../../../../testUtils';
import { clickNext } from '../../wizardTestUtils';
import {
blueprintRequest,
clickRegisterLater,

View file

@ -13,7 +13,7 @@ import {
firstBootCreateBlueprintRequest,
firstBootData,
} from '../../../../fixtures/editMode';
import { clickNext, getNextButton } from '../../../../testUtils';
import { clickNext, getNextButton } from '../../wizardTestUtils';
import {
blueprintRequest,
clickRegisterLater,

View file

@ -26,10 +26,8 @@ import {
rhel9CreateBlueprintRequest,
x86_64CreateBlueprintRequest,
} from '../../../../fixtures/editMode';
import {
clickNext,
renderCustomRoutesWithReduxRouter,
} from '../../../../testUtils';
import { renderCustomRoutesWithReduxRouter } from '../../../../testUtils';
import { clickNext } from '../../wizardTestUtils';
import {
blueprintRequest,
clickRegisterLater,

View file

@ -13,7 +13,7 @@ import {
expectedServicesCisL2,
oscapCreateBlueprintRequest,
} from '../../../../fixtures/editMode';
import { clickNext } from '../../../../testUtils';
import { clickNext } from '../../wizardTestUtils';
import {
clickRegisterLater,
enterBlueprintName,

View file

@ -11,7 +11,7 @@ import {
expectedSinglePackageRecommendation,
packagesCreateBlueprintRequest,
} from '../../../../fixtures/editMode';
import { clickNext } from '../../../../testUtils';
import { clickNext } from '../../wizardTestUtils';
import { selectCustomRepo } from '../../wizardTestUtils';
import {
blueprintRequest,

View file

@ -24,12 +24,12 @@ import {
import { mockBlueprintIds } from '../../../../fixtures/blueprints';
import { registrationCreateBlueprintRequest } from '../../../../fixtures/editMode';
import { server } from '../../../../mocks/server';
import { renderCustomRoutesWithReduxRouter } from '../../../../testUtils';
import {
clickBack,
clickNext,
renderCustomRoutesWithReduxRouter,
verifyCancelButton,
} from '../../../../testUtils';
} from '../../wizardTestUtils';
import {
enterBlueprintName,
renderCreateMode,

View file

@ -13,7 +13,7 @@ import {
expectedPayloadRepositories,
repositoriesCreateBlueprintRequest,
} from '../../../../fixtures/editMode';
import { clickNext } from '../../../../testUtils';
import { clickNext } from '../../wizardTestUtils';
import {
blueprintRequest,
clickRegisterLater,

View file

@ -9,7 +9,7 @@ import {
expectedPayloadRepositories,
snapshotCreateBlueprintRequest,
} from '../../../../fixtures/editMode';
import { clickNext } from '../../../../testUtils';
import { clickNext } from '../../wizardTestUtils';
import {
blueprintRequest,
clickRegisterLater,

View file

@ -8,7 +8,7 @@ import {
} from '../../../../../store/imageBuilderApi';
import { mockBlueprintIds } from '../../../../fixtures/blueprints';
import { awsCreateBlueprintRequest } from '../../../../fixtures/editMode';
import { clickBack, clickNext } from '../../../../testUtils';
import { clickBack, clickNext } from '../../wizardTestUtils';
import {
blueprintRequest,
clickRegisterLater,

View file

@ -8,7 +8,7 @@ import {
} from '../../../../../store/imageBuilderApi';
import { mockBlueprintIds } from '../../../../fixtures/blueprints';
import { azureCreateBlueprintRequest } from '../../../../fixtures/editMode';
import { clickBack, clickNext } from '../../../../testUtils';
import { clickBack, clickNext } from '../../wizardTestUtils';
import {
blueprintRequest,
clickRegisterLater,

View file

@ -10,7 +10,7 @@ import {
} from '../../../../../store/imageBuilderApi';
import { mockBlueprintIds } from '../../../../fixtures/blueprints';
import { gcpCreateBlueprintRequest } from '../../../../fixtures/editMode';
import { clickBack, clickNext } from '../../../../testUtils';
import { clickBack, clickNext } from '../../wizardTestUtils';
import {
blueprintRequest,
clickRegisterLater,

View file

@ -1,5 +1,6 @@
import React from 'react';
import type { Router as RemixRouter } from '@remix-run/router';
import { screen, waitFor } from '@testing-library/react';
import { userEvent } from '@testing-library/user-event';
@ -10,11 +11,7 @@ import {
ImageRequest,
} from '../../../store/imageBuilderApi';
import { server } from '../../mocks/server';
import {
clickBack,
clickNext,
renderCustomRoutesWithReduxRouter,
} from '../../testUtils';
import { renderCustomRoutesWithReduxRouter } from '../../testUtils';
type RequestTypes = 'GET' | 'PUT' | 'POST' | 'DELETE';
@ -169,3 +166,33 @@ export const interceptEditBlueprintRequest = async (
return await receivedRequestPromise;
};
export const clickBack = async () => {
const user = userEvent.setup();
const backBtn = await screen.findByRole('button', { name: /Back/ });
await waitFor(() => user.click(backBtn));
};
export const clickNext = async () => {
const user = userEvent.setup();
const nextBtn = await screen.findByRole('button', { name: /Next/ });
await waitFor(() => user.click(nextBtn));
};
export const clickCancel = async () => {
const user = userEvent.setup();
const cancelBtn = await screen.findByRole('button', { name: /Cancel/ });
await waitFor(() => user.click(cancelBtn));
};
export const getNextButton = async () => {
const next = await screen.findByRole('button', { name: /Next/ });
return next;
};
export const verifyCancelButton = async (router: RemixRouter | undefined) => {
await clickCancel();
if (router) {
expect(router.state.location.pathname).toBe('/insights/image-builder');
}
};

View file

@ -1,8 +1,7 @@
import React from 'react';
import { configureStore } from '@reduxjs/toolkit';
import { screen, render, waitFor } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { render } from '@testing-library/react';
import { Provider } from 'react-redux';
import { createMemoryRouter, RouterProvider } from 'react-router-dom';
@ -46,43 +45,3 @@ export const renderCustomRoutesWithReduxRouter = async (
return { router, store };
};
export const renderWithProvider = (
component,
container,
preloadedState = {}
) => {
const store = configureStore({ reducer, middleware, preloadedState });
return render(<Provider store={store}>{component}</Provider>, {
container: container,
});
};
export const clickBack = async () => {
const user = userEvent.setup();
const backBtn = await screen.findByRole('button', { name: /Back/ });
await waitFor(() => user.click(backBtn));
};
export const clickNext = async () => {
const user = userEvent.setup();
const nextBtn = await screen.findByRole('button', { name: /Next/ });
await waitFor(() => user.click(nextBtn));
};
export const clickCancel = async () => {
const user = userEvent.setup();
const cancelBtn = await screen.findByRole('button', { name: /Cancel/ });
await waitFor(() => user.click(cancelBtn));
};
export const getNextButton = async () => {
const next = await screen.findByRole('button', { name: /Next/ });
return next;
};
export const verifyCancelButton = async (router) => {
await clickCancel();
expect(router.state.location.pathname).toBe('/insights/image-builder');
};