Skip to content

wizard: add Users to review step (HMS-4906) #2633

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

Merged
merged 1 commit into from
Jan 6, 2025
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
20 changes: 20 additions & 0 deletions src/Components/CreateImageWizard/steps/Review/ReviewStep.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
TargetEnvGCPList,
TargetEnvOciList,
TargetEnvOtherList,
UsersList,
TimezoneList,
LocaleList,
HostnameList,
Expand Down Expand Up @@ -73,6 +74,7 @@ const Review = ({ snapshottingEnabled }: { snapshottingEnabled: boolean }) => {
const [isExpandedLocale, setIsExpandedLocale] = useState(true);
const [isExpandedHostname, setIsExpandedHostname] = useState(true);
const [isExpandableFirstBoot, setIsExpandedFirstBoot] = useState(true);
const [isExpandedUsers, setIsExpandedUsers] = useState(true);

const isTimezoneEnabled = useFlag('image-builder.timezone.enabled');
const isLocaleEnabled = useFlag('image-builder.locale.enabled');
Expand Down Expand Up @@ -102,6 +104,8 @@ const Review = ({ snapshottingEnabled }: { snapshottingEnabled: boolean }) => {
setIsExpandedHostname(isExpandedHostname);
const onToggleFirstBoot = (isExpandableFirstBoot: boolean) =>
setIsExpandedFirstBoot(isExpandableFirstBoot);
const onToggleUsers = (isExpandedUsers: boolean) =>
setIsExpandedUsers(isExpandedUsers);

type RevisitStepButtonProps = {
ariaLabel: string;
Expand Down Expand Up @@ -158,6 +162,7 @@ const Review = ({ snapshottingEnabled }: { snapshottingEnabled: boolean }) => {
};

const isFirstBootEnabled = useFlag('image-builder.firstboot.enabled');
const isUsersEnabled = useFlag('image-builder.users.enabled');
return (
<>
<ExpandableSection
Expand Down Expand Up @@ -314,6 +319,21 @@ const Review = ({ snapshottingEnabled }: { snapshottingEnabled: boolean }) => {
{/* Intentional prop drilling for simplicity - To be removed */}
<ContentList snapshottingEnabled={snapshottingEnabled} />
</ExpandableSection>
{isUsersEnabled && (
<ExpandableSection
toggleContent={composeExpandable(
'Users',
'revisit-users',
'wizard-users'
)}
onToggle={(_event, isExpandedUsers) => onToggleUsers(isExpandedUsers)}
isExpanded={isExpandedUsers}
isIndented
data-testid="users-expandable"
>
<UsersList />
</ExpandableSection>
)}
{isTimezoneEnabled && (
<ExpandableSection
toggleContent={composeExpandable(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ import {
selectLanguages,
selectKeyboard,
selectHostname,
selectUserNameByIndex,
selectUserPasswordByIndex,
} from '../../../../store/wizardSlice';
import { toMonthAndYear, yyyyMMddFormat } from '../../../../Utilities/time';
import {
Expand Down Expand Up @@ -774,6 +776,41 @@ export const TimezoneList = () => {
);
};

export const UsersList = () => {
const index = 0;
const userNameSelector = selectUserNameByIndex(index);
const userName = useAppSelector(userNameSelector);
const userPasswordSelector = selectUserPasswordByIndex(index);
const userPassword = useAppSelector(userPasswordSelector);

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

export const LocaleList = () => {
const languages = useAppSelector(selectLanguages);
const keyboard = useAppSelector(selectKeyboard);
Expand Down
20 changes: 19 additions & 1 deletion src/test/Components/CreateImageWizard/steps/Users/Users.test.tsx
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, EDIT_BLUEPRINT } from '../../../../../constants';
Expand Down Expand Up @@ -45,6 +45,13 @@ const goToReviewStep = async () => {
await clickNext(); // Review
};

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

const addValidUser = async () => {
const user = userEvent.setup();
const addUser = await screen.findByRole('button', { name: /add a user/i });
Expand Down Expand Up @@ -92,6 +99,17 @@ describe('Step Users', () => {
await verifyCancelButton(router);
});

test('revisit step button on Review works', async () => {
await renderCreateMode();
await goToRegistrationStep();
await clickRegisterLater();
await goToUsersStep();
await addValidUser();
await goToReviewStep();
await clickRevisitButton();
await screen.findByRole('heading', { name: /Users/ });
});

describe('User request generated correctly', () => {
test('with valid name and password', async () => {
await renderCreateMode();
Expand Down
Loading