diff --git a/src/Components/CreateImageWizard/formComponents/TargetEnvironment.js b/src/Components/CreateImageWizard/formComponents/TargetEnvironment.js index 8b2aceea..7b4a27a3 100644 --- a/src/Components/CreateImageWizard/formComponents/TargetEnvironment.js +++ b/src/Components/CreateImageWizard/formComponents/TargetEnvironment.js @@ -18,6 +18,7 @@ import { import { HelpIcon } from '@patternfly/react-icons'; import PropTypes from 'prop-types'; import { useField } from 'react-final-form'; +import { useSearchParams } from 'react-router-dom'; import { useGetArchitecturesQuery } from '../../../store/imageBuilderApi'; import { provisioningApi } from '../../../store/provisioningApi'; @@ -63,6 +64,16 @@ const TargetEnvironment = ({ label, isRequired, ...props }) => { const { isBeta } = useGetEnvironment(); const release = getState()?.values?.release; + const [searchParams] = useSearchParams(); + + // Set the target via search parameter + // Used by Insights assistant or external hyperlinks (access.redhat.com, developers.redhat.com) + const preloadTarget = searchParams.get('target'); + useEffect(() => { + preloadTarget === 'iso' && handleSetEnvironment('image-installer', true); + preloadTarget === 'qcow' && handleSetEnvironment('guest-image', true); + }, [preloadTarget]); + useEffect(() => { if (getState()?.values?.[input.name]) { setEnvironment(getState().values[input.name]); diff --git a/src/test/Components/CreateImageWizard/CreateImageWizard.test.js b/src/test/Components/CreateImageWizard/CreateImageWizard.test.js index 6498fa17..25ed8449 100644 --- a/src/test/Components/CreateImageWizard/CreateImageWizard.test.js +++ b/src/test/Components/CreateImageWizard/CreateImageWizard.test.js @@ -99,6 +99,18 @@ const getSourceDropdown = async () => { return sourceDropdown; }; +const clickToReview = async () => { + await clickNext(); + await userEvent.click( + await screen.findByRole('radio', { name: /Register later/ }) + ); + await clickNext(); // skip Registration + await clickNext(); // skip FSC + await clickNext(); // skip Repositories + await clickNext(); // skip Packages + await clickNext(); // skip Details +}; + beforeAll(() => { // scrollTo is not defined in jsdom window.HTMLElement.prototype.scrollTo = function () {}; @@ -1507,6 +1519,112 @@ describe('Click through all steps', () => { }, 20000); }); +describe('set release using query parameter', () => { + test('rhel 9 by default (no query parameter)', async () => { + ({ router } = await renderCustomRoutesWithReduxRouter( + 'imagewizard', + {}, + routes + )); + await screen.findByText('Red Hat Enterprise Linux (RHEL) 9'); + }); + + test('rhel 9 by default (invalid query parameter)', async () => { + ({ router } = await renderCustomRoutesWithReduxRouter( + 'imagewizard?release=rhel9000', + {}, + routes + )); + await screen.findByText('Red Hat Enterprise Linux (RHEL) 9'); + }); + + test('rhel 8 (query parameter provided)', async () => { + ({ router } = await renderCustomRoutesWithReduxRouter( + 'imagewizard?release=rhel8', + {}, + routes + )); + await screen.findByText('Red Hat Enterprise Linux (RHEL) 8'); + }); +}); +describe('set architecture using query parameter', () => { + test('x86_64 by default (no query parameter)', async () => { + ({ router } = await renderCustomRoutesWithReduxRouter( + 'imagewizard', + {}, + routes + )); + await screen.findByText('x86_64'); + }); + + test('x86_64 by default (invalid query parameter)', async () => { + ({ router } = await renderCustomRoutesWithReduxRouter( + 'imagewizard?arch=arm', + {}, + routes + )); + await screen.findByText('x86_64'); + }); + + test('aarch64 (query parameter provided)', async () => { + ({ router } = await renderCustomRoutesWithReduxRouter( + 'imagewizard?arch=aarch64', + {}, + routes + )); + await screen.findByText('aarch64'); + }); +}); +describe('set target using query parameter', () => { + test('no target by default (no query parameter)', async () => { + ({ router } = await renderCustomRoutesWithReduxRouter( + 'imagewizard', + {}, + routes + )); + const nextButton = await screen.findByRole('button', { name: /Next/ }); + expect(nextButton).toBeDisabled(); + }); + + test('no target by default (invalid query parameter)', async () => { + ({ router } = await renderCustomRoutesWithReduxRouter( + 'imagewizard?target=azure', + {}, + routes + )); + const nextButton = await screen.findByRole('button', { name: /Next/ }); + expect(nextButton).toBeDisabled(); + }); + + test('image-installer (query parameter provided)', async () => { + ({ router } = await renderCustomRoutesWithReduxRouter( + 'imagewizard?target=iso', + {}, + routes + )); + await clickToReview(); + const targetExpandable = await screen.findByRole('button', { + name: /Target environments/, + }); + await userEvent.click(targetExpandable); + await screen.findByText('Bare metal - Installer (.iso)'); + }); + + test('guest-installer (query parameter provided)', async () => { + ({ router } = await renderCustomRoutesWithReduxRouter( + 'imagewizard?target=qcow', + {}, + routes + )); + await clickToReview(); + const targetExpandable = await screen.findByRole('button', { + name: /Target environments/, + }); + await userEvent.click(targetExpandable); + await screen.findByText('Virtualization - Guest image (.qcow2)'); + }); +}); + describe('Keyboard accessibility', () => { const user = userEvent.setup(); const setUp = async () => { @@ -1656,60 +1774,3 @@ describe('Keyboard accessibility', () => { testTile(await screen.findByTestId('upload-azure')); }); }); - -describe('set release using query parameter', () => { - test('rhel 9 by default (no query parameter)', async () => { - ({ router } = await renderCustomRoutesWithReduxRouter( - 'imagewizard', - {}, - routes - )); - await screen.findByText('Red Hat Enterprise Linux (RHEL) 9'); - }); - - test('rhel 9 by default (invalid query parameter)', async () => { - ({ router } = await renderCustomRoutesWithReduxRouter( - 'imagewizard?release=rhel9000', - {}, - routes - )); - await screen.findByText('Red Hat Enterprise Linux (RHEL) 9'); - }); - - test('rhel 8 (query parameter provided)', async () => { - ({ router } = await renderCustomRoutesWithReduxRouter( - 'imagewizard?release=rhel8', - {}, - routes - )); - await screen.findByText('Red Hat Enterprise Linux (RHEL) 8'); - }); -}); -describe('set architecture using query parameter', () => { - test('x86_64 by default (no query parameter)', async () => { - ({ router } = await renderCustomRoutesWithReduxRouter( - 'imagewizard', - {}, - routes - )); - await screen.findByText('x86_64'); - }); - - test('x86_64 by default (invalid query parameter)', async () => { - ({ router } = await renderCustomRoutesWithReduxRouter( - 'imagewizard?arch=arm', - {}, - routes - )); - await screen.findByText('x86_64'); - }); - - test('aarch64 (query parameter provided)', async () => { - ({ router } = await renderCustomRoutesWithReduxRouter( - 'imagewizard?arch=aarch64', - {}, - routes - )); - await screen.findByText('aarch64'); - }); -});