V2Wizard/Packages: Add tests for requests
Adds tests that verify using the custom packages step to add a custom package results in a correctly generated API request.
This commit is contained in:
parent
92f8f0016d
commit
ed61f17d58
1 changed files with 105 additions and 0 deletions
|
|
@ -0,0 +1,105 @@
|
|||
import { screen } from '@testing-library/react';
|
||||
import { userEvent } from '@testing-library/user-event';
|
||||
|
||||
import { CREATE_BLUEPRINT } from '../../../../../constants';
|
||||
import { CreateBlueprintRequest } from '../../../../../store/imageBuilderApi';
|
||||
import { clickNext } from '../../../../testUtils';
|
||||
import {
|
||||
blueprintRequest,
|
||||
clickRegisterLater,
|
||||
enterBlueprintName,
|
||||
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 goToPackagesStep = async () => {
|
||||
const bareMetalCheckBox = await screen.findByRole('checkbox', {
|
||||
name: /bare metal installer checkbox/i,
|
||||
});
|
||||
await userEvent.click(bareMetalCheckBox);
|
||||
await clickNext(); // Registration
|
||||
await clickRegisterLater();
|
||||
await clickNext(); // OpenSCAP
|
||||
await clickNext(); // Custom repositories
|
||||
await clickNext(); // Additional packages
|
||||
};
|
||||
|
||||
const goToReviewStep = async () => {
|
||||
await clickNext(); // Details
|
||||
await enterBlueprintName();
|
||||
await clickNext(); // Review
|
||||
};
|
||||
|
||||
const searchForPackage = async () => {
|
||||
const searchBox = await screen.findByRole('textbox', {
|
||||
name: /search packages/i,
|
||||
});
|
||||
await userEvent.type(searchBox, 'test');
|
||||
};
|
||||
|
||||
const selectFirstPackage = async () => {
|
||||
await userEvent.click(
|
||||
await screen.findByRole('checkbox', { name: /select row 0/i })
|
||||
);
|
||||
};
|
||||
|
||||
const deselectFirstPackage = async () => {
|
||||
await userEvent.click(
|
||||
await screen.findByRole('checkbox', { name: /select row 0/i })
|
||||
);
|
||||
};
|
||||
|
||||
describe('packages request generated correctly', () => {
|
||||
const expectedPackages: string[] = ['test'];
|
||||
|
||||
test('with custom packages', async () => {
|
||||
await render();
|
||||
await goToPackagesStep();
|
||||
await searchForPackage();
|
||||
await selectFirstPackage();
|
||||
await goToReviewStep();
|
||||
const receivedRequest = await interceptBlueprintRequest(CREATE_BLUEPRINT);
|
||||
|
||||
const expectedRequest: CreateBlueprintRequest = {
|
||||
...blueprintRequest,
|
||||
customizations: {
|
||||
packages: expectedPackages,
|
||||
},
|
||||
};
|
||||
|
||||
expect(receivedRequest).toEqual(expectedRequest);
|
||||
});
|
||||
|
||||
test('deselecting a package removes it from the request', async () => {
|
||||
await render();
|
||||
await goToPackagesStep();
|
||||
await searchForPackage();
|
||||
await selectFirstPackage();
|
||||
await deselectFirstPackage();
|
||||
await goToReviewStep();
|
||||
const receivedRequest = await interceptBlueprintRequest(CREATE_BLUEPRINT);
|
||||
|
||||
const expectedRequest = blueprintRequest;
|
||||
|
||||
expect(receivedRequest).toEqual(expectedRequest);
|
||||
});
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue