feat(HMS-3582): add first boot step to wizard

This commit is contained in:
Amir 2024-04-18 18:29:46 +03:00 committed by Lucas Garfield
parent c88a0323f2
commit 6f9c4f3864
23 changed files with 401 additions and 12 deletions

View file

@ -166,6 +166,7 @@ describe('Step Packages', () => {
test('clicking Next loads Image name', async () => {
await setUp();
await clickNext();
await clickNext();
await screen.findByRole('heading', {

View file

@ -418,6 +418,7 @@ describe('Step Upload to AWS', () => {
await clickNext();
await clickNext();
await clickNext();
await clickNext();
await enterBlueprintName();
await clickNext();
@ -611,6 +612,7 @@ describe('Step Registration', () => {
await clickNext();
await clickNext();
await clickNext();
await clickNext();
await enterBlueprintName();
await clickNext();
const review = await screen.findByTestId('review-registration');
@ -658,6 +660,7 @@ describe('Step Registration', () => {
await clickNext();
await clickNext();
await clickNext();
await clickNext();
await enterBlueprintName();
await clickNext();
const review = await screen.findByTestId('review-registration');
@ -706,6 +709,7 @@ describe('Step Registration', () => {
await clickNext();
await clickNext();
await clickNext();
await clickNext();
await enterBlueprintName();
await clickNext();
const review = await screen.findByTestId('review-registration');
@ -737,6 +741,7 @@ describe('Step Registration', () => {
await clickNext();
await clickNext();
await clickNext();
await clickNext();
await enterBlueprintName();
await clickNext();
await screen.findByText('Register the system later');
@ -896,7 +901,9 @@ describe('Step Details', () => {
await clickNext();
// skip fsc
await clickNext();
// skip snapshots
// skip snapshot
await clickNext();
//skip firstBoot
await clickNext();
};
@ -979,6 +986,8 @@ describe('Step Review', () => {
// skip packages
await clickNext();
await clickNext();
// skip firstboot
await clickNext();
// skip Details
const blueprintName = await screen.findByRole('textbox', {
name: /blueprint name/i,
@ -1042,6 +1051,8 @@ describe('Step Review', () => {
// skip repositories
await clickNext();
await clickNext();
// skip First boot
await clickNext();
const blueprintName = await screen.findByRole('textbox', {
name: /blueprint name/i,
});
@ -1223,7 +1234,7 @@ describe('Keyboard accessibility', () => {
// TODO: Focus on textbox on Packages step
await clickNext();
await clickNext();
// TODO: Focus on textbox on Details step
await clickNext();
}, 20000);

View file

@ -39,6 +39,8 @@ const goToDetailsStep = async () => {
await clickNext();
await clickNext();
await clickNext();
await clickNext();
await clickNext();
};
const enterBlueprintDescription = async () => {

View file

@ -103,6 +103,7 @@ const goToReviewStep = async () => {
await clickNext();
await clickNext();
await clickNext();
await clickNext();
await enterBlueprintName();
await clickNext();
};

View file

@ -0,0 +1,126 @@
import { screen } from '@testing-library/react';
import { userEvent } from '@testing-library/user-event';
import {
CREATE_BLUEPRINT,
FIRST_BOOT_SERVICE,
FIRST_BOOT_SERVICE_DATA,
} from '../../../../../constants';
import { File as ImageBuilderFile } from '../../../../../store/imageBuilderApi';
import { clickNext } from '../../../../testUtils';
import {
blueprintRequest,
clickRegisterLater,
enterBlueprintName,
interceptBlueprintRequest,
renderCreateMode,
} from '../../wizardTestUtils';
import '@testing-library/jest-dom';
jest.mock('@redhat-cloud-services/frontend-components/useChrome', () => ({
useChrome: () => ({
auth: {
getUser: () => {
return {
identity: {
internal: {
org_id: 5,
},
},
};
},
},
isBeta: () => true,
isProd: () => true,
getEnvironment: () => 'prod',
}),
}));
const goToFirstBootStep = async (): Promise<void> => {
const guestImageCheckBox = await screen.findByRole('checkbox', {
name: /virtualization guest image checkbox/i,
});
await userEvent.click(guestImageCheckBox);
await clickNext();
await clickNext(); // Registration
await clickRegisterLater();
await clickNext(); // OpenSCAP
await clickNext(); // File System
await clickNext(); // Custom repositories
await clickNext(); // Additional packages
await clickNext(); // Snapshot
await clickNext(); // First Boot
};
const openCodeEditor = async (): Promise<void> => {
const startBtn = await screen.findByRole('button', {
name: /Start from scratch/i,
});
await userEvent.click(startBtn);
};
const uploadFile = async (): Promise<void> => {
const fileInput: HTMLElement | null =
// eslint-disable-next-line testing-library/no-node-access
document.querySelector('input[type="file"]');
if (fileInput) {
const file = new File([SCRIPT], 'script.sh', { type: 'text/x-sh' });
await userEvent.upload(fileInput, file);
}
};
const goToReviewStep = async (): Promise<void> => {
await clickNext(); // Details
await enterBlueprintName();
await clickNext(); // Review
};
const SCRIPT = `#!/bin/bash
systemctl enable cockpit.socket`;
const BASE64_SCRIPT = btoa(SCRIPT);
const firstBootData: ImageBuilderFile[] = [
{
path: '/etc/systemd/system/custom-first-boot.service',
data: FIRST_BOOT_SERVICE_DATA,
data_encoding: 'base64',
ensure_parents: true,
},
{
path: '/usr/local/sbin/custom-first-boot',
data: BASE64_SCRIPT,
data_encoding: 'base64',
mode: '0774',
ensure_parents: true,
},
];
describe('First Boot step', () => {
test('should render First Boot step', async () => {
await renderCreateMode();
await goToFirstBootStep();
expect(screen.getByText('First boot configuration')).toBeInTheDocument();
});
describe('validate first boot request ', () => {
test('should validate first boot request', async () => {
await renderCreateMode();
await goToFirstBootStep();
await openCodeEditor();
await uploadFile();
await goToReviewStep();
const receivedRequest = await interceptBlueprintRequest(CREATE_BLUEPRINT);
const expectedRequest = {
...blueprintRequest,
customizations: {
files: firstBootData,
services: { enabled: [FIRST_BOOT_SERVICE] },
},
};
expect(receivedRequest).toEqual(expectedRequest);
});
});
});

View file

@ -60,6 +60,7 @@ const clickToReview = async () => {
await clickNext(); // skip SnapshotRepositories
await clickNext(); // skip Repositories
await clickNext(); // skip Packages
await clickNext(); // skip First Boot
const nameInput = await screen.findByRole('textbox', {
name: /blueprint name/i,
});

View file

@ -90,6 +90,7 @@ const goToReviewStep = async () => {
await clickNext(); // Snapshot repositories
await clickNext(); // Custom repositories
await clickNext(); // Additional packages
await clickNext(); // FirstBoot
await clickNext(); // Details
await enterBlueprintName('oscap');
await clickNext(); // Review

View file

@ -53,6 +53,7 @@ const goToPackagesStep = async () => {
};
const goToReviewStep = async () => {
await clickNext(); // First Boot
await clickNext(); // Details
await enterBlueprintName();
await clickNext(); // Review

View file

@ -71,6 +71,7 @@ const goToReviewStep = async () => {
await clickNext();
await clickNext();
await clickNext();
await clickNext();
await enterBlueprintName();
await clickNext();
};

View file

@ -51,6 +51,7 @@ const goToRepositoriesStep = async () => {
const goToReviewStep = async () => {
await clickNext(); // Additional packages
await clickNext();
await clickNext(); // First Boot
await clickNext(); // Details
await enterBlueprintName();
await clickNext(); // Review

View file

@ -47,6 +47,7 @@ const goToReview = async () => {
await clickNext(); // Custom repositories
await clickNext(); // Additional packages
await clickNext(); // Details
await clickNext(); // FirstBoot
await enterBlueprintName();
await clickNext(); // Review
};

View file

@ -46,6 +46,7 @@ const goToReview = async () => {
await clickNext(); // Snapshot repositories
await clickNext(); // Custom repositories
await clickNext(); // Additional packages
await clickNext(); // FirstBoot
await clickNext(); // Details
await enterBlueprintName();
await clickNext(); // Review

View file

@ -48,6 +48,7 @@ const goToReview = async () => {
await clickNext(); // Custom repositories
await clickNext(); // Additional packages
await clickNext(); // Details
await clickNext(); // FirstBoot
await enterBlueprintName();
await clickNext(); // Review
};

View file

@ -123,6 +123,7 @@ const goToReviewStep = async () => {
await clickNext(); // Snapshots
await clickNext(); // Custom repositories
await clickNext(); // Additional packages
await clickNext(); // First boot
await clickNext(); // Details
await enterBlueprintName();
await clickNext(); // Review