test: Add package recommendations to the happy path test
This adds unit tests for package recommendations to the `Packages.test.tsx`, testing the happy path for: - adding single recommendation - adding all recommendations - removing a recommendation
This commit is contained in:
parent
371588e9a2
commit
6f6784df2d
1 changed files with 107 additions and 0 deletions
|
|
@ -69,6 +69,33 @@ const deselectFirstPackage = async () => {
|
|||
);
|
||||
};
|
||||
|
||||
const openRecommendationsExpandable = async () => {
|
||||
await userEvent.click(
|
||||
await screen.findByRole('button', { name: /recommended red hat packages/i })
|
||||
);
|
||||
};
|
||||
|
||||
const addSingleRecommendation = async () => {
|
||||
const addPackageButtons = await screen.findAllByText(/add package/i);
|
||||
await userEvent.click(addPackageButtons[0]);
|
||||
};
|
||||
|
||||
const addAllRecommendations = async () => {
|
||||
await userEvent.click(await screen.findByText(/add all packages/i));
|
||||
};
|
||||
|
||||
const switchToSelected = async () => {
|
||||
await userEvent.click(
|
||||
await screen.findByRole('button', { name: /selected \(\d*\)/i })
|
||||
);
|
||||
};
|
||||
|
||||
const deselectRecommendation = async () => {
|
||||
await userEvent.click(
|
||||
await screen.findByRole('checkbox', { name: /select row 1/i })
|
||||
);
|
||||
};
|
||||
|
||||
describe('packages request generated correctly', () => {
|
||||
const expectedPackages: string[] = ['test'];
|
||||
|
||||
|
|
@ -104,3 +131,83 @@ describe('packages request generated correctly', () => {
|
|||
expect(receivedRequest).toEqual(expectedRequest);
|
||||
});
|
||||
});
|
||||
|
||||
describe('package recommendations', () => {
|
||||
const expectedSinglePackageRecommendation: string[] = [
|
||||
'test', // recommendations are generated only when some packages have been selected
|
||||
'recommendedPackage1',
|
||||
];
|
||||
|
||||
const expectedAllPackageRecommendations: string[] = [
|
||||
'test', // recommendations are generated only when some packages have been selected
|
||||
'recommendedPackage1',
|
||||
'recommendedPackage2',
|
||||
'recommendedPackage3',
|
||||
'recommendedPackage4',
|
||||
'recommendedPackage5',
|
||||
];
|
||||
|
||||
const expectedPackagesWithoutRecommendations: string[] = ['test'];
|
||||
|
||||
test('selecting single recommendation adds it to the request', async () => {
|
||||
await render();
|
||||
await goToPackagesStep();
|
||||
await searchForPackage();
|
||||
await selectFirstPackage();
|
||||
await openRecommendationsExpandable();
|
||||
await addSingleRecommendation();
|
||||
await goToReviewStep();
|
||||
const receivedRequest = await interceptBlueprintRequest(CREATE_BLUEPRINT);
|
||||
|
||||
const expectedRequest: CreateBlueprintRequest = {
|
||||
...blueprintRequest,
|
||||
customizations: {
|
||||
packages: expectedSinglePackageRecommendation,
|
||||
},
|
||||
};
|
||||
|
||||
expect(receivedRequest).toEqual(expectedRequest);
|
||||
});
|
||||
|
||||
test('clicking "Add all packages" adds all recommendations to the request', async () => {
|
||||
await render();
|
||||
await goToPackagesStep();
|
||||
await searchForPackage();
|
||||
await selectFirstPackage();
|
||||
await openRecommendationsExpandable();
|
||||
await addAllRecommendations();
|
||||
await goToReviewStep();
|
||||
const receivedRequest = await interceptBlueprintRequest(CREATE_BLUEPRINT);
|
||||
|
||||
const expectedRequest: CreateBlueprintRequest = {
|
||||
...blueprintRequest,
|
||||
customizations: {
|
||||
packages: expectedAllPackageRecommendations,
|
||||
},
|
||||
};
|
||||
|
||||
expect(receivedRequest).toEqual(expectedRequest);
|
||||
});
|
||||
|
||||
test('deselecting a package recommendation removes it from the request', async () => {
|
||||
await render();
|
||||
await goToPackagesStep();
|
||||
await searchForPackage();
|
||||
await selectFirstPackage();
|
||||
await openRecommendationsExpandable();
|
||||
await addSingleRecommendation();
|
||||
await switchToSelected();
|
||||
await deselectRecommendation();
|
||||
await goToReviewStep();
|
||||
const receivedRequest = await interceptBlueprintRequest(CREATE_BLUEPRINT);
|
||||
|
||||
const expectedRequest: CreateBlueprintRequest = {
|
||||
...blueprintRequest,
|
||||
customizations: {
|
||||
packages: expectedPackagesWithoutRecommendations,
|
||||
},
|
||||
};
|
||||
|
||||
expect(receivedRequest).toEqual(expectedRequest);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue