V2 Wizard: OpenSCAP edit tests

Edit mode is now fully tested and working for OpenSCAP profiles. A
handler for the PUT request was added and the fixtures were updated to
support this.

`EditImageWizard.tsx`: Previously we dispatched `initializeWizard()`
while waiting for the blueprintDetails to load. This meant that the
state was incorrect (empty) while the blueprintDetails request was
in flight.

`requestMapper.tsx`: Correctly populate state in edit mode if the
blueprint contains a custom file system – previously custom mountpoints
were dropped and automatic mode was selected.

`spyOnRequest()`: Differentiate between request types (e.g. GET, PUT)
for the same endpoint.
This commit is contained in:
lucasgarfield 2024-04-29 16:54:26 +02:00 committed by Lucas Garfield
parent c1d6053083
commit 61b23216f4
19 changed files with 236 additions and 117 deletions

View file

@ -10,7 +10,7 @@ import {
enterBlueprintName,
goToRegistrationStep,
interceptBlueprintRequest,
render,
renderCreateMode,
} from '../../wizardTestUtils';
jest.mock('@redhat-cloud-services/frontend-components/useChrome', () => ({
@ -54,7 +54,7 @@ const goToReviewStep = async () => {
describe('validates name', () => {
test('with invalid name', async () => {
await render();
await renderCreateMode();
await goToRegistrationStep();
await clickRegisterLater();
await goToDetailsStep();
@ -66,7 +66,7 @@ describe('validates name', () => {
});
test('with valid name', async () => {
await render();
await renderCreateMode();
await goToRegistrationStep();
await clickRegisterLater();
await goToDetailsStep();
@ -79,7 +79,7 @@ describe('validates name', () => {
describe('registration request generated correctly', () => {
test('without description', async () => {
await render();
await renderCreateMode();
await goToRegistrationStep();
await clickRegisterLater();
await goToDetailsStep();
@ -93,7 +93,7 @@ describe('registration request generated correctly', () => {
});
test('with description', async () => {
await render();
await renderCreateMode();
await goToRegistrationStep();
await clickRegisterLater();
await goToDetailsStep();

View file

@ -8,7 +8,7 @@ import {
clickRegisterLater,
enterBlueprintName,
interceptBlueprintRequest,
render,
renderCreateMode,
} from '../../wizardTestUtils';
jest.mock('@redhat-cloud-services/frontend-components/useChrome', () => ({
@ -104,7 +104,7 @@ const goToReviewStep = async () => {
describe('file system configuration request generated correctly', () => {
test('10 GiB / correct', async () => {
await render();
await renderCreateMode();
await goToFileSystemConfigurationStep();
await clickManuallyConfigurePartitions();
await goToReviewStep();
@ -126,7 +126,7 @@ describe('file system configuration request generated correctly', () => {
});
test('15 GiB / correct', async () => {
await render();
await renderCreateMode();
await goToFileSystemConfigurationStep();
await clickManuallyConfigurePartitions();
await changePartitionSize();
@ -149,7 +149,7 @@ describe('file system configuration request generated correctly', () => {
});
test('MiB / correct', async () => {
await render();
await renderCreateMode();
await goToFileSystemConfigurationStep();
await clickManuallyConfigurePartitions();
await changePartitionUnitsToMiB();
@ -172,7 +172,7 @@ describe('file system configuration request generated correctly', () => {
});
test('KiB / correct', async () => {
await render();
await renderCreateMode();
await goToFileSystemConfigurationStep();
await clickManuallyConfigurePartitions();
await changePartitionUnitsToKiB();
@ -195,7 +195,7 @@ describe('file system configuration request generated correctly', () => {
});
test('/home correct', async () => {
await render();
await renderCreateMode();
await goToFileSystemConfigurationStep();
await clickManuallyConfigurePartitions();
await addPartition();
@ -222,7 +222,7 @@ describe('file system configuration request generated correctly', () => {
});
test('/home/cakerecipes correct', async () => {
await render();
await renderCreateMode();
await goToFileSystemConfigurationStep();
await clickManuallyConfigurePartitions();
await addPartition();

View file

@ -12,7 +12,7 @@ import {
clickNext,
renderCustomRoutesWithReduxRouter,
} from '../../../../testUtils';
import { render } from '../../wizardTestUtils';
import { renderCreateMode } from '../../wizardTestUtils';
const routes = [
{
@ -283,53 +283,53 @@ describe('Check step consistency', () => {
describe('set release using query parameter', () => {
test('rhel 9 by default (no query parameter)', async () => {
await render();
await renderCreateMode();
await screen.findByText('Red Hat Enterprise Linux (RHEL) 9');
});
test('rhel 9 by default (invalid query parameter)', async () => {
await render({ release: 'rhel9001' });
await renderCreateMode({ release: 'rhel9001' });
await screen.findByText('Red Hat Enterprise Linux (RHEL) 9');
});
test('rhel 8 (query parameter provided)', async () => {
await render({ release: 'rhel8' });
await renderCreateMode({ release: 'rhel8' });
await screen.findByText('Red Hat Enterprise Linux (RHEL) 8');
});
});
describe('set architecture using query parameter', () => {
test('x86_64 by default (no query parameter)', async () => {
await render();
await renderCreateMode();
await screen.findByText('x86_64');
});
test('x86_64 by default (invalid query parameter)', async () => {
await render({ arch: 'arm' });
await renderCreateMode({ arch: 'arm' });
await screen.findByText('x86_64');
});
test('aarch64 (query parameter provided)', async () => {
await render({ arch: 'aarch64' });
await renderCreateMode({ arch: 'aarch64' });
await screen.findByText('aarch64');
});
});
describe('set target using query parameter', () => {
test('no target by default (no query parameter)', async () => {
await render();
await renderCreateMode();
const nextButton = await screen.findByRole('button', { name: /Next/ });
expect(nextButton).toBeDisabled();
});
test('no target by default (invalid query parameter)', async () => {
await render({ target: 'azure' });
await renderCreateMode({ target: 'azure' });
const nextButton = await screen.findByRole('button', { name: /Next/ });
expect(nextButton).toBeDisabled();
});
test('image-installer (query parameter provided)', async () => {
await render({ target: 'iso' });
await renderCreateMode({ target: 'iso' });
await clickToReview();
const targetExpandable = await screen.findByRole('button', {
name: /Target environments/,
@ -339,7 +339,7 @@ describe('set target using query parameter', () => {
});
test('guest-installer (query parameter provided)', async () => {
await render({ target: 'qcow2' });
await renderCreateMode({ target: 'qcow2' });
await clickToReview();
const targetExpandable = await screen.findByRole('button', {
name: /Target environments/,

View file

@ -1,15 +1,21 @@
import { screen } from '@testing-library/react';
import { userEvent } from '@testing-library/user-event';
import { CREATE_BLUEPRINT } from '../../../../../constants';
import { CREATE_BLUEPRINT, EDIT_BLUEPRINT } from '../../../../../constants';
import { CreateBlueprintRequest } from '../../../../../store/imageBuilderApi';
import {
baseCreateBlueprintRequest,
mockBlueprintIds,
oscapCreateBlueprintRequest,
} from '../../../../fixtures/blueprints';
import { clickNext } from '../../../../testUtils';
import {
blueprintRequest,
clickRegisterLater,
enterBlueprintName,
interceptBlueprintRequest,
render,
interceptEditBlueprintRequest,
renderCreateMode,
renderEditMode,
} from '../../wizardTestUtils';
jest.mock('@redhat-cloud-services/frontend-components/useChrome', () => ({
@ -85,32 +91,10 @@ const goToReviewStep = async () => {
await clickNext(); // Custom repositories
await clickNext(); // Additional packages
await clickNext(); // Details
await enterBlueprintName();
await enterBlueprintName('oscap');
await clickNext(); // Review
};
const expectedOpenscapCisL1 = {
profile_id: 'xccdf_org.ssgproject.content_profile_cis_workstation_l1',
};
const expectedPackagesCisL1 = ['aide', 'neovim'];
const expectedServicesCisL1 = {
enabled: ['crond', 'neovim-service'],
disabled: ['rpcbind', 'autofs', 'nftables'],
masked: ['nfs-server', 'emacs-service'],
};
const expectedKernelCisL1 = {
append: 'audit_backlog_limit=8192 audit=1',
};
const expectedFilesystemCisL1 = [
{ min_size: 10737418240, mountpoint: '/' },
{ min_size: 1073741824, mountpoint: '/tmp' },
{ min_size: 1073741824, mountpoint: '/home' },
];
const expectedOpenscapCisL2 = {
profile_id: 'xccdf_org.ssgproject.content_profile_cis_workstation_l2',
};
@ -134,29 +118,20 @@ const expectedFilesystemCisL2 = [
describe('oscap', () => {
test('add a profile', async () => {
await render();
await renderCreateMode();
await goToOscapStep();
await selectProfile();
await goToReviewStep();
const receivedRequest = await interceptBlueprintRequest(CREATE_BLUEPRINT);
const expectedRequest: CreateBlueprintRequest = {
...blueprintRequest,
customizations: {
packages: expectedPackagesCisL1,
openscap: expectedOpenscapCisL1,
services: expectedServicesCisL1,
kernel: expectedKernelCisL1,
filesystem: expectedFilesystemCisL1,
},
};
const expectedRequest = oscapCreateBlueprintRequest;
expect(receivedRequest).toEqual(expectedRequest);
});
test('remove a profile', async () => {
await render();
await renderCreateMode();
await goToOscapStep();
await selectProfile();
await selectNone();
@ -165,14 +140,15 @@ describe('oscap', () => {
const receivedRequest = await interceptBlueprintRequest(CREATE_BLUEPRINT);
const expectedRequest: CreateBlueprintRequest = {
...blueprintRequest,
...baseCreateBlueprintRequest,
name: 'oscap',
};
expect(receivedRequest).toEqual(expectedRequest);
});
test('change profile', async () => {
await render();
await renderCreateMode();
await goToOscapStep();
await selectProfile();
await selectDifferentProfile();
@ -181,7 +157,7 @@ describe('oscap', () => {
const receivedRequest = await interceptBlueprintRequest(CREATE_BLUEPRINT);
const expectedRequest: CreateBlueprintRequest = {
...blueprintRequest,
...baseCreateBlueprintRequest,
customizations: {
packages: expectedPackagesCisL2,
openscap: expectedOpenscapCisL2,
@ -189,8 +165,23 @@ describe('oscap', () => {
kernel: expectedKernelCisL2,
filesystem: expectedFilesystemCisL2,
},
name: 'oscap',
};
expect(receivedRequest).toEqual(expectedRequest);
});
});
describe('oscap edit mode', () => {
test('edit mode works', async () => {
const id = mockBlueprintIds['oscap'];
await renderEditMode(id);
// starts on review step
const receivedRequest = await interceptEditBlueprintRequest(
`${EDIT_BLUEPRINT}/${id}`
);
const expectedRequest = oscapCreateBlueprintRequest;
expect(receivedRequest).toEqual(expectedRequest);
});
});

View file

@ -9,7 +9,7 @@ import {
clickRegisterLater,
enterBlueprintName,
interceptBlueprintRequest,
render,
renderCreateMode,
} from '../../wizardTestUtils';
jest.mock('@redhat-cloud-services/frontend-components/useChrome', () => ({
@ -108,7 +108,7 @@ describe('packages request generated correctly', () => {
const expectedPackages: string[] = ['test'];
test('with custom packages', async () => {
await render();
await renderCreateMode();
await goToPackagesStep();
await searchForPackage();
await selectFirstPackage();
@ -126,7 +126,7 @@ describe('packages request generated correctly', () => {
});
test('deselecting a package removes it from the request', async () => {
await render();
await renderCreateMode();
await goToPackagesStep();
await searchForPackage();
await selectFirstPackage();
@ -158,7 +158,7 @@ describe('package recommendations', () => {
const expectedPackagesWithoutRecommendations: string[] = ['test'];
test('selecting single recommendation adds it to the request', async () => {
await render();
await renderCreateMode();
await goToPackagesStep();
await searchForPackage();
await selectFirstPackage();
@ -178,7 +178,7 @@ describe('package recommendations', () => {
});
test('clicking "Add all packages" adds all recommendations to the request', async () => {
await render();
await renderCreateMode();
await goToPackagesStep();
await searchForPackage();
await selectFirstPackage();
@ -198,7 +198,7 @@ describe('package recommendations', () => {
});
test('deselecting a package recommendation removes it from the request', async () => {
await render();
await renderCreateMode();
await goToPackagesStep();
await searchForPackage();
await selectFirstPackage();

View file

@ -9,7 +9,7 @@ import {
import { clickNext } from '../../../../testUtils';
import {
enterBlueprintName,
render,
renderCreateMode,
interceptBlueprintRequest,
goToRegistrationStep,
clickRegisterLater,
@ -94,7 +94,7 @@ describe('registration request generated correctly', () => {
};
test('register + insights + rhc', async () => {
await render();
await renderCreateMode();
await goToRegistrationStep();
await selectActivationKey();
await goToReviewStep();
@ -117,7 +117,7 @@ describe('registration request generated correctly', () => {
});
test('register + insights', async () => {
await render();
await renderCreateMode();
await goToRegistrationStep();
await clickShowAdditionalConnectionOptions();
await deselectEnableRemoteRemediations();
@ -142,7 +142,7 @@ describe('registration request generated correctly', () => {
});
test('register', async () => {
await render();
await renderCreateMode();
await goToRegistrationStep();
await clickShowAdditionalConnectionOptions();
await deselectPredictiveAnalytics();
@ -167,7 +167,7 @@ describe('registration request generated correctly', () => {
});
test('register Later', async () => {
await render();
await renderCreateMode();
await goToRegistrationStep();
await clickShowAdditionalConnectionOptions();
await clickRegisterLater();

View file

@ -13,7 +13,7 @@ import {
clickRegisterLater,
enterBlueprintName,
interceptBlueprintRequest,
render,
renderCreateMode,
} from '../../wizardTestUtils';
jest.mock('@redhat-cloud-services/frontend-components/useChrome', () => ({
@ -124,7 +124,7 @@ describe('repositories request generated correctly', () => {
};
test('with custom repositories', async () => {
await render();
await renderCreateMode();
await goToRepositoriesStep();
await selectFirstRepository();
await goToReviewStep();
@ -142,7 +142,7 @@ describe('repositories request generated correctly', () => {
});
test('with custom repository with module_hotfixes', async () => {
await render();
await renderCreateMode();
await goToRepositoriesStep();
await selectNginxRepository();
await goToReviewStep();
@ -160,7 +160,7 @@ describe('repositories request generated correctly', () => {
});
test('deselecting a custom repository removes it from the request', async () => {
await render();
await renderCreateMode();
await goToRepositoriesStep();
await selectFirstRepository();
await deselectFirstRepository();

View file

@ -13,7 +13,7 @@ import {
clickRegisterLater,
enterBlueprintName,
interceptBlueprintRequest,
render,
renderCreateMode,
} from '../../wizardTestUtils';
jest.mock('@redhat-cloud-services/frontend-components/useChrome', () => ({
@ -112,7 +112,7 @@ describe('repository snapshot tab - ', () => {
];
test('select use a snapshot with 1 repo selected', async () => {
await render();
await renderCreateMode();
await goToSnapshotStep();
await selectUseSnapshot();
await updateDatePickerWithValue('04/22/2024');
@ -143,7 +143,7 @@ describe('repository snapshot tab - ', () => {
});
test('select use a snapshot with no repos selected', async () => {
await render();
await renderCreateMode();
await goToSnapshotStep();
await selectUseSnapshot();
await updateDatePickerWithValue('04/22/2024');

View file

@ -12,7 +12,7 @@ import {
clickRegisterLater,
enterBlueprintName,
interceptBlueprintRequest,
render,
renderCreateMode,
} from '../../../wizardTestUtils';
jest.mock('@redhat-cloud-services/frontend-components/useChrome', () => ({
@ -52,7 +52,7 @@ const goToReview = async () => {
};
const selectAwsTarget = async () => {
await render();
await renderCreateMode();
const awsCard = await screen.findByTestId('upload-aws');
await userEvent.click(awsCard);
await clickNext();

View file

@ -12,7 +12,7 @@ import {
clickRegisterLater,
enterBlueprintName,
interceptBlueprintRequest,
render,
renderCreateMode,
} from '../../../wizardTestUtils';
jest.mock('@redhat-cloud-services/frontend-components/useChrome', () => ({
@ -52,7 +52,7 @@ const goToReview = async () => {
};
const selectAzureTarget = async () => {
await render();
await renderCreateMode();
const azureCard = await screen.findByTestId('upload-azure');
await userEvent.click(azureCard);
await clickNext();

View file

@ -15,7 +15,7 @@ import {
enterBlueprintName,
imageRequest,
interceptBlueprintRequest,
render,
renderCreateMode,
} from '../../wizardTestUtils';
jest.mock('@redhat-cloud-services/frontend-components/useChrome', () => ({
@ -67,7 +67,7 @@ const createGCPCloudImage = (
};
const clickGCPTarget = async () => {
await render();
await renderCreateMode();
const googleOption = await screen.findByTestId('upload-google');
await userEvent.click(googleOption);
await clickNext();

View file

@ -22,7 +22,7 @@ import {
goToRegistrationStep,
imageRequest,
interceptBlueprintRequest,
render,
renderCreateMode,
} from '../../wizardTestUtils';
jest.mock('@redhat-cloud-services/frontend-components/useChrome', () => ({
@ -130,7 +130,7 @@ const goToReviewStep = async () => {
describe('distribution request generated correctly', () => {
test('rhel-8', async () => {
await render();
await renderCreateMode();
await selectRhel8();
await goToReviewStep();
const receivedRequest = await interceptBlueprintRequest(CREATE_BLUEPRINT);
@ -144,7 +144,7 @@ describe('distribution request generated correctly', () => {
});
test('rhel-9', async () => {
await render();
await renderCreateMode();
await selectRhel9();
await goToReviewStep();
const receivedRequest = await interceptBlueprintRequest(CREATE_BLUEPRINT);
@ -158,7 +158,7 @@ describe('distribution request generated correctly', () => {
});
test('centos-9', async () => {
await render();
await renderCreateMode();
await selectCentos9();
await goToReviewStep();
const receivedRequest = await interceptBlueprintRequest(CREATE_BLUEPRINT);
@ -172,7 +172,7 @@ describe('distribution request generated correctly', () => {
});
test('centos-8', async () => {
await render();
await renderCreateMode();
await selectCentos8();
await goToReviewStep();
const receivedRequest = await interceptBlueprintRequest(CREATE_BLUEPRINT);
@ -188,7 +188,7 @@ describe('distribution request generated correctly', () => {
describe('architecture request generated correctly', () => {
test('x86_64', async () => {
await render();
await renderCreateMode();
await selectX86_64();
await goToReviewStep();
const receivedRequest = await interceptBlueprintRequest(CREATE_BLUEPRINT);
@ -206,7 +206,7 @@ describe('architecture request generated correctly', () => {
});
test('aarch64', async () => {
await render();
await renderCreateMode();
await selectAarch64();
await goToReviewStep();
const receivedRequest = await interceptBlueprintRequest(CREATE_BLUEPRINT);