From 3167effa1b863970b18ce7a7c8ec99ba9078cd7e Mon Sep 17 00:00:00 2001 From: regexowl Date: Tue, 14 Jan 2025 10:56:42 +0100 Subject: [PATCH] Wizard: Add unleash flag and update tests This gates the step behind an unleash flag and updates the existing tests so they pass with the new step added. --- .../CreateImageWizard/CreateImageWizard.tsx | 11 +++- .../steps/Firewall/index.tsx | 16 +++++ .../steps/Details/Details.test.tsx | 1 + .../FileSystemConfiguration.test.tsx | 1 + .../steps/Firewall/Firewall.test.tsx | 66 +++++++++++++++++++ .../steps/FirstBoot/Firstboot.test.tsx | 2 + .../steps/Hostname/Hostname.test.tsx | 1 + .../steps/ImageOutput/ImageOutput.test.tsx | 1 + .../steps/Kernel/Kernel.test.tsx | 4 +- .../steps/Locale/Locale.test.tsx | 1 + .../steps/Oscap/Oscap.test.tsx | 1 + .../steps/Packages/Packages.test.tsx | 1 + .../steps/Registration/Registration.test.tsx | 1 + .../steps/Repositories/Repositories.test.tsx | 1 + .../steps/Review/Review.test.tsx | 1 + .../steps/Snapshot/Snapshot.test.tsx | 1 + .../TargetEnvironment/AwsTarget.test.tsx | 1 + .../TargetEnvironment/AzureTarget.test.tsx | 1 + .../TargetEnvironment/GCPTarget.test.tsx | 1 + .../steps/Timezone/Timezone.test.tsx | 1 + .../steps/Users/Users.test.tsx | 1 + src/test/setup.ts | 2 + 22 files changed, 112 insertions(+), 5 deletions(-) create mode 100644 src/Components/CreateImageWizard/steps/Firewall/index.tsx create mode 100644 src/test/Components/CreateImageWizard/steps/Firewall/Firewall.test.tsx diff --git a/src/Components/CreateImageWizard/CreateImageWizard.tsx b/src/Components/CreateImageWizard/CreateImageWizard.tsx index 78aebbdab..13295bbcf 100644 --- a/src/Components/CreateImageWizard/CreateImageWizard.tsx +++ b/src/Components/CreateImageWizard/CreateImageWizard.tsx @@ -15,6 +15,7 @@ import { useNavigate, useSearchParams } from 'react-router-dom'; import DetailsStep from './steps/Details'; import FileSystemStep from './steps/FileSystem'; import { FileSystemContext } from './steps/FileSystem/FileSystemTable'; +import FirewallStep from './steps/Firewall'; import FirstBootStep from './steps/FirstBoot'; import HostnameStep from './steps/Hostname'; import ImageOutputStep from './steps/ImageOutput'; @@ -142,6 +143,7 @@ const CreateImageWizard = ({ isEdit }: CreateImageWizardProps) => { const isLocaleEnabled = useFlag('image-builder.locale.enabled'); const isHostnameEnabled = useFlag('image-builder.hostname.enabled'); const isKernelEnabled = useFlag('image-builder.kernel.enabled'); + const isFirewallEnabled = useFlag('image-builder.firewall.enabled'); // Remove this and all fallthrough logic when snapshotting is enabled in Prod-stable // =========================TO REMOVE======================= @@ -228,7 +230,7 @@ const CreateImageWizard = ({ isEdit }: CreateImageWizardProps) => { let startIndex = 1; // default index if (isEdit) { - startIndex = 20; + startIndex = 21; } // Duplicating some of the logic from the Wizard component to allow for custom nav items status @@ -518,11 +520,14 @@ const CreateImageWizard = ({ isEdit }: CreateImageWizardProps) => { name="Firewall" id="wizard-firewall" key="wizard-firewall" - isHidden={true} + navItem={customStatusNavItem} + isHidden={!isFirewallEnabled} footer={ } - >, + > + + , { + return ( +
+ + Firewall + + Customize firewall settings for your image. +
+ ); +}; + +export default FirewallStep; diff --git a/src/test/Components/CreateImageWizard/steps/Details/Details.test.tsx b/src/test/Components/CreateImageWizard/steps/Details/Details.test.tsx index cc7846ce6..bf0e528ce 100644 --- a/src/test/Components/CreateImageWizard/steps/Details/Details.test.tsx +++ b/src/test/Components/CreateImageWizard/steps/Details/Details.test.tsx @@ -28,6 +28,7 @@ const goToDetailsStep = async () => { await clickNext(); // Locale await clickNext(); // Hostname await clickNext(); // Kernel + await clickNext(); // Firewall await clickNext(); // First boot script await clickNext(); // Details }; diff --git a/src/test/Components/CreateImageWizard/steps/FileSystemConfiguration/FileSystemConfiguration.test.tsx b/src/test/Components/CreateImageWizard/steps/FileSystemConfiguration/FileSystemConfiguration.test.tsx index 075c7e144..ad78819ca 100644 --- a/src/test/Components/CreateImageWizard/steps/FileSystemConfiguration/FileSystemConfiguration.test.tsx +++ b/src/test/Components/CreateImageWizard/steps/FileSystemConfiguration/FileSystemConfiguration.test.tsx @@ -117,6 +117,7 @@ const goToReviewStep = async () => { await clickNext(); // Locale await clickNext(); // Hostname await clickNext(); // Kernel + await clickNext(); // Firewall await clickNext(); // Details await enterBlueprintName(); await clickNext(); // Review diff --git a/src/test/Components/CreateImageWizard/steps/Firewall/Firewall.test.tsx b/src/test/Components/CreateImageWizard/steps/Firewall/Firewall.test.tsx new file mode 100644 index 000000000..f5a44ceb5 --- /dev/null +++ b/src/test/Components/CreateImageWizard/steps/Firewall/Firewall.test.tsx @@ -0,0 +1,66 @@ +import type { Router as RemixRouter } from '@remix-run/router'; +import { screen, waitFor } from '@testing-library/react'; +import { userEvent } from '@testing-library/user-event'; + +import { + clickBack, + clickNext, + verifyCancelButton, +} from '../../wizardTestUtils'; +import { clickRegisterLater, renderCreateMode } from '../../wizardTestUtils'; + +let router: RemixRouter | undefined = undefined; + +const goToFirewallStep = async () => { + const user = userEvent.setup(); + const guestImageCheckBox = await screen.findByRole('checkbox', { + name: /virtualization guest image checkbox/i, + }); + await waitFor(() => user.click(guestImageCheckBox)); + await clickNext(); // Registration + await clickRegisterLater(); + await clickNext(); // OpenSCAP + await clickNext(); // File system configuration + await clickNext(); // Snapshots + await clickNext(); // Custom repositories + await clickNext(); // Additional packages + await clickNext(); // Users + await clickNext(); // Timezone + await clickNext(); // Locale + await clickNext(); // Hostname + await clickNext(); // Kernel + await clickNext(); // Firewall +}; + +describe('Step Firewall', () => { + beforeEach(() => { + vi.clearAllMocks(); + router = undefined; + }); + + test('clicking Next loads First boot', async () => { + await renderCreateMode(); + await goToFirewallStep(); + await clickNext(); + await screen.findByRole('heading', { + name: 'First boot configuration', + }); + }); + + test('clicking Back loads Kernel', async () => { + await renderCreateMode(); + await goToFirewallStep(); + await clickBack(); + await screen.findByRole('heading', { name: 'Kernel' }); + }); + + test('clicking Cancel loads landing page', async () => { + await renderCreateMode(); + await goToFirewallStep(); + await verifyCancelButton(router); + }); +}); + +// TO DO Step Firewall -> revisit step button on Review works +// TO DO Firewall request generated correctly +// TO DO Firewall edit mode diff --git a/src/test/Components/CreateImageWizard/steps/FirstBoot/Firstboot.test.tsx b/src/test/Components/CreateImageWizard/steps/FirstBoot/Firstboot.test.tsx index 35d1bfe74..fa7e54f6d 100644 --- a/src/test/Components/CreateImageWizard/steps/FirstBoot/Firstboot.test.tsx +++ b/src/test/Components/CreateImageWizard/steps/FirstBoot/Firstboot.test.tsx @@ -50,6 +50,7 @@ const goToFirstBootStep = async (): Promise => { await clickNext(); // Locale await clickNext(); // Hostname await clickNext(); // Kernel + await clickNext(); // Firewall await clickNext(); // First Boot }; @@ -74,6 +75,7 @@ const goFromOscapToFirstBoot = async () => { await clickNext(); // Locale await clickNext(); // Hostname await clickNext(); // Kernel + await clickNext(); // Firewall await clickNext(); // First boot script }; diff --git a/src/test/Components/CreateImageWizard/steps/Hostname/Hostname.test.tsx b/src/test/Components/CreateImageWizard/steps/Hostname/Hostname.test.tsx index 87e4abaa2..7502c37b0 100644 --- a/src/test/Components/CreateImageWizard/steps/Hostname/Hostname.test.tsx +++ b/src/test/Components/CreateImageWizard/steps/Hostname/Hostname.test.tsx @@ -42,6 +42,7 @@ const goToHostnameStep = async () => { const goToReviewStep = async () => { await clickNext(); // Kernel + await clickNext(); // Firewall await clickNext(); // First boot script await clickNext(); // Details await enterBlueprintName(); diff --git a/src/test/Components/CreateImageWizard/steps/ImageOutput/ImageOutput.test.tsx b/src/test/Components/CreateImageWizard/steps/ImageOutput/ImageOutput.test.tsx index 78630ea04..6fec42001 100644 --- a/src/test/Components/CreateImageWizard/steps/ImageOutput/ImageOutput.test.tsx +++ b/src/test/Components/CreateImageWizard/steps/ImageOutput/ImageOutput.test.tsx @@ -140,6 +140,7 @@ const goToReviewStep = async () => { await clickNext(); // Locale await clickNext(); // Hostname await clickNext(); // Kernel + await clickNext(); // Firewall await clickNext(); // First boot await clickNext(); // Details await enterBlueprintName(); diff --git a/src/test/Components/CreateImageWizard/steps/Kernel/Kernel.test.tsx b/src/test/Components/CreateImageWizard/steps/Kernel/Kernel.test.tsx index cada521c2..65e54d024 100644 --- a/src/test/Components/CreateImageWizard/steps/Kernel/Kernel.test.tsx +++ b/src/test/Components/CreateImageWizard/steps/Kernel/Kernel.test.tsx @@ -37,12 +37,12 @@ describe('Step Kernel', () => { router = undefined; }); - test('clicking Next loads First boot script', async () => { + test('clicking Next loads Firewall', async () => { await renderCreateMode(); await goToKernelStep(); await clickNext(); await screen.findByRole('heading', { - name: 'First boot configuration', + name: 'Firewall', }); }); diff --git a/src/test/Components/CreateImageWizard/steps/Locale/Locale.test.tsx b/src/test/Components/CreateImageWizard/steps/Locale/Locale.test.tsx index ce1fd7fb9..8c5c94a6a 100644 --- a/src/test/Components/CreateImageWizard/steps/Locale/Locale.test.tsx +++ b/src/test/Components/CreateImageWizard/steps/Locale/Locale.test.tsx @@ -41,6 +41,7 @@ const goToLocaleStep = async () => { const goToReviewStep = async () => { await clickNext(); // Hostname await clickNext(); // Kernel + await clickNext(); // Firewall await clickNext(); // First boot await clickNext(); // Details await enterBlueprintName(); diff --git a/src/test/Components/CreateImageWizard/steps/Oscap/Oscap.test.tsx b/src/test/Components/CreateImageWizard/steps/Oscap/Oscap.test.tsx index 4e8c64c02..206e0a648 100644 --- a/src/test/Components/CreateImageWizard/steps/Oscap/Oscap.test.tsx +++ b/src/test/Components/CreateImageWizard/steps/Oscap/Oscap.test.tsx @@ -103,6 +103,7 @@ const goToReviewStep = async () => { await clickNext(); // Locale await clickNext(); // Hostname await clickNext(); // Kernel + await clickNext(); // Firewall await clickNext(); // FirstBoot await clickNext(); // Details await enterBlueprintName('Oscap test'); diff --git a/src/test/Components/CreateImageWizard/steps/Packages/Packages.test.tsx b/src/test/Components/CreateImageWizard/steps/Packages/Packages.test.tsx index 6cd83f666..258e6288b 100644 --- a/src/test/Components/CreateImageWizard/steps/Packages/Packages.test.tsx +++ b/src/test/Components/CreateImageWizard/steps/Packages/Packages.test.tsx @@ -57,6 +57,7 @@ const goToReviewStep = async () => { await clickNext(); // Locale await clickNext(); // Hostname await clickNext(); // Kernel + await clickNext(); // Firewall await clickNext(); // First Boot await clickNext(); // Details await enterBlueprintName(); diff --git a/src/test/Components/CreateImageWizard/steps/Registration/Registration.test.tsx b/src/test/Components/CreateImageWizard/steps/Registration/Registration.test.tsx index 8f3c9797c..9ef4dd7b6 100644 --- a/src/test/Components/CreateImageWizard/steps/Registration/Registration.test.tsx +++ b/src/test/Components/CreateImageWizard/steps/Registration/Registration.test.tsx @@ -100,6 +100,7 @@ const goToReviewStep = async () => { await clickNext(); // Locale await clickNext(); // Hostname await clickNext(); // Kernel + await clickNext(); // Firewall await clickNext(); // Details await enterBlueprintName(); await clickNext(); // Review diff --git a/src/test/Components/CreateImageWizard/steps/Repositories/Repositories.test.tsx b/src/test/Components/CreateImageWizard/steps/Repositories/Repositories.test.tsx index 39d9ba91a..6fb99cca3 100644 --- a/src/test/Components/CreateImageWizard/steps/Repositories/Repositories.test.tsx +++ b/src/test/Components/CreateImageWizard/steps/Repositories/Repositories.test.tsx @@ -50,6 +50,7 @@ const goToReviewStep = async () => { await clickNext(); // Locale await clickNext(); // Hostname await clickNext(); // Kernel + await clickNext(); // Firewall await clickNext(); // First Boot await clickNext(); // Details await enterBlueprintName(); diff --git a/src/test/Components/CreateImageWizard/steps/Review/Review.test.tsx b/src/test/Components/CreateImageWizard/steps/Review/Review.test.tsx index 67c5e6d4a..392c134a8 100644 --- a/src/test/Components/CreateImageWizard/steps/Review/Review.test.tsx +++ b/src/test/Components/CreateImageWizard/steps/Review/Review.test.tsx @@ -58,6 +58,7 @@ const goToReviewStep = async () => { await clickNext(); // Locale await clickNext(); // Hostname await clickNext(); // Kernel + await clickNext(); // Firewall await clickNext(); // First boot script await clickNext(); // Details await clickNext(); // Review diff --git a/src/test/Components/CreateImageWizard/steps/Snapshot/Snapshot.test.tsx b/src/test/Components/CreateImageWizard/steps/Snapshot/Snapshot.test.tsx index 4531c0f9f..abf589916 100644 --- a/src/test/Components/CreateImageWizard/steps/Snapshot/Snapshot.test.tsx +++ b/src/test/Components/CreateImageWizard/steps/Snapshot/Snapshot.test.tsx @@ -42,6 +42,7 @@ const goToReviewStep = async () => { await clickNext(); // Locale await clickNext(); // Hostname await clickNext(); // Kernel + await clickNext(); // Firewall await clickNext(); // First boot script await enterBlueprintName(); await clickNext(); // Review diff --git a/src/test/Components/CreateImageWizard/steps/TargetEnvironment/AwsTarget.test.tsx b/src/test/Components/CreateImageWizard/steps/TargetEnvironment/AwsTarget.test.tsx index 30037be65..e75db8984 100644 --- a/src/test/Components/CreateImageWizard/steps/TargetEnvironment/AwsTarget.test.tsx +++ b/src/test/Components/CreateImageWizard/steps/TargetEnvironment/AwsTarget.test.tsx @@ -49,6 +49,7 @@ const goToReview = async () => { await clickNext(); // Locale await clickNext(); // Hostname await clickNext(); // Kernel + await clickNext(); // Firewall await clickNext(); // FirstBoot await clickNext(); // Details await enterBlueprintName(); diff --git a/src/test/Components/CreateImageWizard/steps/TargetEnvironment/AzureTarget.test.tsx b/src/test/Components/CreateImageWizard/steps/TargetEnvironment/AzureTarget.test.tsx index d1b13b0f3..61fec493a 100644 --- a/src/test/Components/CreateImageWizard/steps/TargetEnvironment/AzureTarget.test.tsx +++ b/src/test/Components/CreateImageWizard/steps/TargetEnvironment/AzureTarget.test.tsx @@ -49,6 +49,7 @@ const goToReview = async () => { await clickNext(); // Locale await clickNext(); // Hostname await clickNext(); // Kernel + await clickNext(); // Firewall await clickNext(); // FirstBoot await clickNext(); // Details await enterBlueprintName(); diff --git a/src/test/Components/CreateImageWizard/steps/TargetEnvironment/GCPTarget.test.tsx b/src/test/Components/CreateImageWizard/steps/TargetEnvironment/GCPTarget.test.tsx index e1c2dc187..1d0d99f34 100644 --- a/src/test/Components/CreateImageWizard/steps/TargetEnvironment/GCPTarget.test.tsx +++ b/src/test/Components/CreateImageWizard/steps/TargetEnvironment/GCPTarget.test.tsx @@ -44,6 +44,7 @@ const goToReview = async () => { await clickNext(); // Locale await clickNext(); // Hostname await clickNext(); // Kernel + await clickNext(); // Firewall await clickNext(); // FirstBoot await clickNext(); // Details await enterBlueprintName(); diff --git a/src/test/Components/CreateImageWizard/steps/Timezone/Timezone.test.tsx b/src/test/Components/CreateImageWizard/steps/Timezone/Timezone.test.tsx index a0b086196..4f252506d 100644 --- a/src/test/Components/CreateImageWizard/steps/Timezone/Timezone.test.tsx +++ b/src/test/Components/CreateImageWizard/steps/Timezone/Timezone.test.tsx @@ -41,6 +41,7 @@ const goToReviewStep = async () => { await clickNext(); // Locale await clickNext(); // Hostname await clickNext(); // Kernel + await clickNext(); // Firewall await clickNext(); // First boot script await clickNext(); // Details await enterBlueprintName(); diff --git a/src/test/Components/CreateImageWizard/steps/Users/Users.test.tsx b/src/test/Components/CreateImageWizard/steps/Users/Users.test.tsx index f66b833b2..4439b1c2e 100644 --- a/src/test/Components/CreateImageWizard/steps/Users/Users.test.tsx +++ b/src/test/Components/CreateImageWizard/steps/Users/Users.test.tsx @@ -39,6 +39,7 @@ const goToReviewStep = async () => { await clickNext(); // Locale await clickNext(); // Hostname await clickNext(); // Kernel + await clickNext(); // Firewall await clickNext(); // First boot await clickNext(); // Details await enterBlueprintName(); diff --git a/src/test/setup.ts b/src/test/setup.ts index 40fb6c216..426ff99db 100644 --- a/src/test/setup.ts +++ b/src/test/setup.ts @@ -73,6 +73,8 @@ vi.mock('@unleash/proxy-client-react', () => ({ return true; case 'image-builder.kernel.enabled': return true; + case 'image-builder.firewall.enabled': + return true; case 'edgeParity.image-list': return true; case 'image-builder.edge.local-image-table':