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

CRDCDH-2199 Show Review and Submit in Progress Bar when submit button is visible #585

Merged
merged 3 commits into from
Jan 8, 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
47 changes: 44 additions & 3 deletions src/components/ProgressBar/ProgressBar.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ import { ContextState, Context as AuthCtx, Status as AuthStatus } from "../Conte

type Props = {
section: string;
userRole?: UserRole;
data: object;
};

const BaseComponent: FC<Props> = ({ section, data = {} }: Props) => {
const BaseComponent: FC<Props> = ({ section, userRole = "Submitter", data = {} }: Props) => {
const formValue = useMemo<FormCtxState>(
() => ({
status: FormStatus.LOADED,
Expand All @@ -28,10 +29,10 @@ const BaseComponent: FC<Props> = ({ section, data = {} }: Props) => {
const authValue = useMemo<ContextState>(
() => ({
status: AuthStatus.LOADED,
user: null,
user: { role: userRole } as User,
isLoggedIn: true,
}),
[]
[userRole]
);

return (
Expand Down Expand Up @@ -224,4 +225,44 @@ describe("ProgressBar General Tests", () => {
);
}
);

it.each<ApplicationStatus>(["In Progress", "Inquired"])(
"shows the default review section title (from config) when submit button is visible and status is %s",
(status) => {
const data = {
status,
questionnaireData: {
sections: keys.map((s) => ({ name: s, status: "Completed" })),
},
};

const { getByTestId } = render(
<BaseComponent section={config.REVIEW.title} data={data} userRole="Federal Lead" />
);

const reviewSection = getByTestId(`progress-bar-section-${keys.length - 1}`);

expect(reviewSection.textContent).toBe("Review and Submit");
}
);

it.each<ApplicationStatus>(["In Progress", "Inquired"])(
"shows the review section title as 'Review' when submit button is not visible and status is %s",
(status) => {
const data = {
status,
questionnaireData: {
sections: keys.map((s) => ({ name: s, status: "Completed" })),
},
};

const { getByTestId } = render(
<BaseComponent section={config.REVIEW.title} data={data} userRole="Admin" />
);

const reviewSection = getByTestId(`progress-bar-section-${keys.length - 1}`);

expect(reviewSection.textContent).toBe("Review");
}
);
});
16 changes: 14 additions & 2 deletions src/components/ProgressBar/ProgressBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import config from "../../config/SectionConfig";
import { Status, useFormContext } from "../Contexts/FormContext";
import StatusAdornment from "./StatusAdornment";
import useFormMode from "../../hooks/useFormMode";
import { useAuthContext } from "../Contexts/AuthContext";
import { CanSubmitSubmissionRequestRoles } from "../../config/AuthRoles";

type Props = {
section: string;
Expand Down Expand Up @@ -77,6 +79,8 @@ const StyledButton = styled(ListItemButton)({
* @returns {JSX.Element}
*/
const ProgressBar: FC<Props> = ({ section }) => {
const { user } = useAuthContext();

const sectionKeys = Object.keys(config);

const { data, status: formStatus } = useFormContext();
Expand Down Expand Up @@ -112,7 +116,15 @@ const ProgressBar: FC<Props> = ({ section }) => {
const reviewSection = newSections.find((s) => s.id === "review");
const reviewUnlocked = completedSections === sectionKeys.length - 1;
if (reviewSection) {
const showReviewTitle = formMode === "View Only" || formMode === "Review";
const meetsReviewCriteria = formMode === "View Only" || formMode === "Review";

const canSeeSubmitButton =
CanSubmitSubmissionRequestRoles.includes(user?.role) &&
(data?.status === "In Progress" ||
Alejandro-Vega marked this conversation as resolved.
Show resolved Hide resolved
(data?.status === "Inquired" && user?.role === "Federal Lead"));
Alejandro-Vega marked this conversation as resolved.
Show resolved Hide resolved

const showReviewTitle = meetsReviewCriteria && !canSeeSubmitButton;

const reviewIcon = reviewUnlocked ? "Review" : "ReviewDisabled";
reviewSection.icon =
["Approved"].includes(status) && reviewUnlocked ? "Completed" : reviewIcon;
Expand All @@ -121,7 +133,7 @@ const ProgressBar: FC<Props> = ({ section }) => {
}

setSections(newSections);
}, [section, sectionStatuses, formMode, formStatus]);
}, [section, sectionStatuses, formMode, formStatus, data?.status, user?.role]);

return (
<StyledList>
Expand Down
Loading