test/CreateImageWizard: test hostname step on cockpit

This commit is contained in:
Sanne Raymaekers 2025-02-06 17:21:45 +01:00 committed by Klara Simickova
parent 9def3f61cb
commit 0624f4a23d
6 changed files with 57 additions and 20 deletions

View file

@ -27,12 +27,17 @@ const goToHostnameStep = async () => {
name: /virtualization guest image checkbox/i,
});
await waitFor(() => user.click(guestImageCheckBox));
await clickNext(); // Registration
await clickRegisterLater();
await clickNext(); // OpenSCAP
if (!process.env.IS_ON_PREMISE) {
await clickNext(); // Registration
await clickRegisterLater();
await clickNext(); // OpenSCAP
}
await clickNext(); // File system configuration
await clickNext(); // Snapshots
await clickNext(); // Custom repositories
if (!process.env.IS_ON_PREMISE) {
await clickNext(); // Snapshots
await clickNext(); // Custom repositories
}
await clickNext(); // Additional packages
await clickNext(); // Users
await clickNext(); // Timezone
@ -44,7 +49,9 @@ const goToReviewStep = async () => {
await clickNext(); // Kernel
await clickNext(); // Firewall
await clickNext(); // Services
await clickNext(); // First boot script
if (!process.env.IS_ON_PREMISE) {
await clickNext(); // First boot script
}
await clickNext(); // Details
await enterBlueprintName();
await clickNext(); // Review

View file

@ -10,6 +10,7 @@ import {
CreateBlueprintRequest,
ImageRequest,
} from '../../../store/imageBuilderApi';
import { getLastBlueprintReq } from '../../mocks/cockpit/cockpitFile';
import { server } from '../../mocks/server';
import { renderCustomRoutesWithReduxRouter } from '../../testUtils';
@ -40,10 +41,15 @@ const routes = [
path: 'insights/image-builder/imagewizard/:composeId?',
element: <ImageWizard />,
},
// cockpit routes
{
path: '/imageWizard',
path: '/imageWizard/:composeId?',
element: <ImageWizard />,
},
{
path: '/',
element: <div />,
},
];
export const imageRequest: ImageRequest = {
@ -88,7 +94,10 @@ export const renderCreateMode = async (searchParams = {}) => {
};
export const renderEditMode = async (id: string) => {
await renderCustomRoutesWithReduxRouter(`imagewizard/${id}`, {}, routes);
const pathName = process.env.IS_ON_PREMISE
? `/imagewizard/${id}`
: `imagewizard/${id}`;
await renderCustomRoutesWithReduxRouter(pathName, {}, routes);
};
export const selectGuestImageTarget = async () => {
@ -162,6 +171,10 @@ export const interceptBlueprintRequest = async (requestPathname: string) => {
});
await waitFor(() => user.click(saveButton));
if (process.env.IS_ON_PREMISE) {
return JSON.parse(getLastBlueprintReq());
}
return await receivedRequestPromise;
};
@ -176,6 +189,10 @@ export const interceptEditBlueprintRequest = async (
});
await waitFor(() => user.click(saveButton));
if (process.env.IS_ON_PREMISE) {
return JSON.parse(getLastBlueprintReq());
}
return await receivedRequestPromise;
};

View file

@ -7,3 +7,5 @@ vitest run -t 'Images Table render ImagesTable' \
vitest run -t 'Create Image Wizard renders component' \
src/test/Components/CreateImageWizard/CreateImageWizard.test.tsx
vitest run src/test/Components/CreateImageWizard/steps/Hostname/Hostname.test.tsx

View file

@ -1,19 +1,12 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
import path from 'path';
import { mockGetBlueprints } from '../../fixtures/blueprints';
import { mockComposes } from '../../fixtures/composes';
import { getMockBlueprintResponse } from '../../fixtures/editMode';
const readBlueprint = (id: string): Promise<string> => {
for (const bp of mockGetBlueprints.data) {
if (bp.id === id) {
return new Promise((resolve) => {
resolve(JSON.stringify(bp));
});
}
}
return new Promise((resolve) => {
resolve('{}');
resolve(JSON.stringify(getMockBlueprintResponse(id) || {}));
});
};
@ -30,6 +23,15 @@ const readCompose = (id: string): Promise<string> => {
});
};
// Contains a list of all blueprint create or edit requests
const lastRequest = {
blueprints: [] as string[],
};
export const getLastBlueprintReq = () => {
return lastRequest.blueprints[lastRequest.blueprints.length - 1];
};
export const cockpitFile = (filepath: string) => {
return {
read: (): Promise<string> => {
@ -43,6 +45,12 @@ export const cockpitFile = (filepath: string) => {
return readCompose(file.name);
},
close: () => {},
replace: (contents: string) => {},
replace: (contents: string) => {
const file = path.parse(filepath);
const dir = path.parse(file.dir);
if (file.name === dir.name) {
lastRequest.blueprints.push(contents);
}
},
};
};

View file

@ -24,6 +24,9 @@ export default {
file: cockpitFile,
spawn: (args: string[], attributes: object): Promise<string | Uint8Array> => {
return new Promise((resolve) => {
if (args.length && args[0] === 'uname') {
resolve('x86_64');
}
resolve('');
});
},

View file

@ -6,8 +6,8 @@ type osRelease = {
export const read_os_release = (): Promise<osRelease> => {
return new Promise((resolve) => {
resolve({
ID: '',
VERSION_ID: '',
ID: 'rhel',
VERSION_ID: '9',
});
});
};