V2Wizard/Details: Add request assertion tests

Adds tests to verify requets for images with names and descriptions are
formulated correctly.

Test functions shared/common to multiple steps were extracted to the
test utilities.
This commit is contained in:
lucasgarfield 2024-02-15 12:02:06 +01:00 committed by Klara Simickova
parent ef7582a8ff
commit d4c9534ecc
3 changed files with 122 additions and 16 deletions

View file

@ -0,0 +1,83 @@
import { screen } from '@testing-library/react';
import { userEvent } from '@testing-library/user-event';
import { CREATE_BLUEPRINT } from '../../../../../constants';
import { clickNext } from '../../../../testUtils';
import {
blueprintRequest,
clickRegisterLater,
enterBlueprintName,
goToRegistrationStep,
interceptBlueprintRequest,
render,
} from '../../wizardTestUtils';
jest.mock('@redhat-cloud-services/frontend-components/useChrome', () => ({
useChrome: () => ({
auth: {
getUser: () => {
return {
identity: {
internal: {
org_id: 5,
},
},
};
},
},
isBeta: () => false,
isProd: () => true,
getEnvironment: () => 'prod',
}),
}));
const goToDetailsStep = async () => {
await clickNext();
await clickNext();
await clickNext();
};
const enterBlueprintDescription = async () => {
const blueprintDescription = await screen.findByRole('textbox', {
name: /blueprint description/i,
});
await userEvent.type(blueprintDescription, 'Now with extra carmine!');
};
const goToReviewStep = async () => {
await clickNext();
};
describe('registration request generated correctly', () => {
test('without description', async () => {
await render();
await goToRegistrationStep();
await clickRegisterLater();
await goToDetailsStep();
await enterBlueprintName();
await goToReviewStep();
const receivedRequest = await interceptBlueprintRequest(CREATE_BLUEPRINT);
const expectedRequest = { ...blueprintRequest };
expect(receivedRequest).toEqual(expectedRequest);
});
test('with description', async () => {
await render();
await goToRegistrationStep();
await clickRegisterLater();
await goToDetailsStep();
await enterBlueprintName();
await enterBlueprintDescription();
await goToReviewStep();
const receivedRequest = await interceptBlueprintRequest(CREATE_BLUEPRINT);
const expectedRequest = {
...blueprintRequest,
description: 'Now with extra carmine!',
};
expect(receivedRequest).toEqual(expectedRequest);
});
});

View file

@ -11,6 +11,8 @@ import {
enterBlueprintName,
render,
interceptBlueprintRequest,
goToRegistrationStep,
clickRegisterLater,
} from '../../wizardTestUtils';
jest.mock('@redhat-cloud-services/frontend-components/useChrome', () => ({
@ -32,14 +34,6 @@ jest.mock('@redhat-cloud-services/frontend-components/useChrome', () => ({
}),
}));
const goToRegistrationStep = async () => {
const bareMetalCheckBox = await screen.findByRole('checkbox', {
name: /bare metal installer checkbox/i,
});
await userEvent.click(bareMetalCheckBox);
await clickNext();
};
const selectActivationKey = async () => {
const activationKeyDropdown = await screen.findByRole('textbox', {
name: 'Select activation key',
@ -70,13 +64,6 @@ const deselectPredictiveAnalytics = async () => {
await userEvent.click(checkBox);
};
const clickRegisterLater = async () => {
const radioButton = await screen.findByRole('radio', {
name: 'Register later',
});
await userEvent.click(radioButton);
};
const goToReviewStep = async () => {
await clickNext();
await clickNext();

View file

@ -5,8 +5,12 @@ import { userEvent } from '@testing-library/user-event';
import { MockedRequest } from 'msw';
import CreateImageWizard from '../../../Components/CreateImageWizardV2/CreateImageWizard';
import {
CreateBlueprintRequest,
ImageRequest,
} from '../../../store/imageBuilderApi';
import { server } from '../../mocks/server';
import { renderCustomRoutesWithReduxRouter } from '../../testUtils';
import { clickNext, renderCustomRoutesWithReduxRouter } from '../../testUtils';
export function spyOnRequest(pathname: string) {
return new Promise((resolve) => {
@ -34,10 +38,42 @@ const routes = [
},
];
export const imageRequest: ImageRequest = {
architecture: 'x86_64',
image_type: 'image-installer',
upload_request: {
options: {},
type: 'aws.s3',
},
};
export const blueprintRequest: CreateBlueprintRequest = {
name: 'Red Velvet',
description: '',
distribution: 'rhel-93',
image_requests: [imageRequest],
customizations: {},
};
export const render = async () => {
await renderCustomRoutesWithReduxRouter('imagewizard', {}, routes);
};
export const goToRegistrationStep = async () => {
const bareMetalCheckBox = await screen.findByRole('checkbox', {
name: /bare metal installer checkbox/i,
});
await userEvent.click(bareMetalCheckBox);
await clickNext();
};
export const clickRegisterLater = async () => {
const radioButton = await screen.findByRole('radio', {
name: 'Register later',
});
await userEvent.click(radioButton);
};
export const enterBlueprintName = async () => {
const blueprintName = await screen.findByRole('textbox', {
name: /blueprint name/i,