Skip to content

Commit

Permalink
Wizard: Add Hostname expandable to Review step
Browse files Browse the repository at this point in the history
This adds a new expandable to the Review step.
  • Loading branch information
regexowl committed Dec 12, 2024
1 parent b4932d6 commit 295090d
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 2 deletions.
22 changes: 22 additions & 0 deletions src/Components/CreateImageWizard/steps/Review/ReviewStep.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {
TargetEnvOtherList,
TimezoneList,
LocaleList,
HostnameList,
} from './ReviewStepTextLists';

import isRhel from '../../../../../src/Utilities/isRhel';
Expand Down Expand Up @@ -70,10 +71,12 @@ const Review = ({ snapshottingEnabled }: { snapshottingEnabled: boolean }) => {
useState(true);
const [isExpandedTimezone, setIsExpandedTimezone] = useState(true);
const [isExpandedLocale, setIsExpandedLocale] = useState(true);
const [isExpandedHostname, setIsExpandedHostname] = useState(true);
const [isExpandableFirstBoot, setIsExpandedFirstBoot] = useState(true);

const isTimezoneEnabled = useFlag('image-builder.timezone.enabled');
const isLocaleEnabled = useFlag('image-builder.locale.enabled');
const isHostnameEnabled = useFlag('image-builder.hostname.enabled');

const onToggleImageOutput = (isExpandedImageOutput: boolean) =>
setIsExpandedImageOutput(isExpandedImageOutput);
Expand All @@ -95,6 +98,8 @@ const Review = ({ snapshottingEnabled }: { snapshottingEnabled: boolean }) => {
setIsExpandedTimezone(isExpandedTimezone);
const onToggleLocale = (isExpandedLocale: boolean) =>
setIsExpandedLocale(isExpandedLocale);
const onToggleHostname = (isExpandedHostname: boolean) =>
setIsExpandedHostname(isExpandedHostname);
const onToggleFirstBoot = (isExpandableFirstBoot: boolean) =>
setIsExpandedFirstBoot(isExpandableFirstBoot);

Expand Down Expand Up @@ -343,6 +348,23 @@ const Review = ({ snapshottingEnabled }: { snapshottingEnabled: boolean }) => {
<LocaleList />
</ExpandableSection>
)}
{isHostnameEnabled && (
<ExpandableSection
toggleContent={composeExpandable(
'Hostname',
'revisit-hostname',
'wizard-hostname'
)}
onToggle={(_event, isExpandedHostname) =>
onToggleHostname(isExpandedHostname)
}
isExpanded={isExpandedHostname}
isIndented
data-testid="hostname-expandable"
>
<HostnameList />
</ExpandableSection>
)}
{isFirstBootEnabled && (
<ExpandableSection
toggleContent={composeExpandable(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ import {
selectNtpServers,
selectLanguages,
selectKeyboard,
selectHostname,
} from '../../../../store/wizardSlice';
import { toMonthAndYear, yyyyMMddFormat } from '../../../../Utilities/time';
import {
Expand Down Expand Up @@ -803,6 +804,26 @@ export const LocaleList = () => {
);
};

export const HostnameList = () => {
const hostname = useAppSelector(selectHostname);

return (
<TextContent>
<TextList component={TextListVariants.dl}>
<TextListItem
component={TextListItemVariants.dt}
className="pf-v5-u-min-width"
>
Hostname
</TextListItem>
<TextListItem component={TextListItemVariants.dd}>
{hostname ? hostname : 'None'}
</TextListItem>
</TextList>
</TextContent>
);
};

export const FirstBootList = () => {
const isFirstbootEnabled = !!useAppSelector(selectFirstBootScript);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Router as RemixRouter } from '@remix-run/router';
import { screen, waitFor } from '@testing-library/react';
import { screen, waitFor, within } from '@testing-library/react';
import { userEvent } from '@testing-library/user-event';

import { CREATE_BLUEPRINT } from '../../../../../constants';
Expand Down Expand Up @@ -55,6 +55,15 @@ const clearHostname = async () => {
await waitFor(() => user.clear(hostnameInput));
};

const clickRevisitButton = async () => {
const user = userEvent.setup();
const expandable = await screen.findByTestId('hostname-expandable');
const revisitButton = await within(expandable).findByTestId(
'revisit-hostname'
);
await waitFor(() => user.click(revisitButton));
};

describe('Step Hostname', () => {
beforeEach(() => {
vi.clearAllMocks();
Expand Down Expand Up @@ -103,6 +112,15 @@ describe('Step Hostname', () => {
expect(nextButton).toBeEnabled();
expect(screen.queryByText(/Invalid hostname/)).not.toBeInTheDocument();
});

test('revisit step button on Review works', async () => {
await renderCreateMode();
await goToHostnameStep();
await enterHostname('hostname');
await goToReviewStep();
await clickRevisitButton();
await screen.findByRole('heading', { name: /Hostname/ });
});
});

describe('Hostname request generated correctly', () => {
Expand Down Expand Up @@ -133,5 +151,4 @@ describe('Hostname request generated correctly', () => {
});
});

// TO DO 'Step Hostname' -> 'revisit step button on Review works'
// TO DO 'Hostname edit mode'

0 comments on commit 295090d

Please sign in to comment.