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

@ -7,7 +7,7 @@ import { mapRequestToState } from './utilities/requestMapper';
import { useAppDispatch } from '../../store/hooks';
import { useGetBlueprintQuery } from '../../store/imageBuilderApi';
import { loadWizardState, initializeWizard } from '../../store/wizardSlice';
import { loadWizardState } from '../../store/wizardSlice';
import { resolveRelPath } from '../../Utilities/path';
type EditImageWizardProps = {
@ -18,15 +18,18 @@ const EditImageWizard = ({ blueprintId }: EditImageWizardProps) => {
const dispatch = useAppDispatch();
const navigate = useNavigate();
const { data: blueprintDetails, error } = useGetBlueprintQuery({
const {
data: blueprintDetails,
error,
isSuccess,
} = useGetBlueprintQuery({
id: blueprintId,
});
useEffect(() => {
if (blueprintId && blueprintDetails) {
const editBlueprintState = mapRequestToState(blueprintDetails);
dispatch(loadWizardState(editBlueprintState));
} else {
dispatch(initializeWizard());
}
}, [blueprintId, blueprintDetails, dispatch]);
useEffect(() => {
@ -36,7 +39,7 @@ const EditImageWizard = ({ blueprintId }: EditImageWizardProps) => {
navigate(resolveRelPath(''));
}
}, [error, navigate]);
return <CreateImageWizard isEdit />;
return isSuccess ? <CreateImageWizard isEdit /> : undefined;
};
export default EditImageWizard;

View file

@ -120,6 +120,18 @@ export const mapRequestToState = (request: BlueprintResponse): wizardState => {
const azureUploadOptions = azure?.upload_request
.options as AzureUploadRequestOptions;
const fileSystem = request.customizations.filesystem
? {
mode: 'manual',
partitions: request.customizations.filesystem,
isNextButtonTouched: true,
}
: {
mode: 'automatic',
partitions: [],
isNextButtonTouched: true,
};
return {
wizardMode,
details: {
@ -134,12 +146,7 @@ export const mapRequestToState = (request: BlueprintResponse): wizardState => {
profile: request.customizations.openscap
?.profile_id as DistributionProfileItem,
},
fileSystem: {
mode: 'automatic',
partitions: [],
isNextButtonTouched: true,
},
fileSystem: fileSystem,
architecture: request.image_requests[0].architecture,
distribution: request.distribution,
imageTypes: request.image_requests.map((image) => image.image_type),