Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wizard: Add Hostname expandable to Review step (HMS-5177) #2674

Merged
merged 1 commit into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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'
Loading