Skip to content

Commit

Permalink
test: Move feature flag check due to rule of conditional hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
DafyddLlyr committed Nov 27, 2024
1 parent 9eb735c commit 595d8dd
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
6 changes: 5 additions & 1 deletion editor.planx.uk/src/@planx/components/Pay/Public/Confirm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import Typography from "@mui/material/Typography";
import { PaymentStatus } from "@opensystemslab/planx-core/types";
import Card from "@planx/components/shared/Preview/Card";
import SaveResumeButton from "@planx/components/shared/Preview/SaveResumeButton";
import { hasFeatureFlag } from "lib/featureFlags";
import { useStore } from "pages/FlowEditor/lib/store";
import React, { useState } from "react";
import { ApplicationPath } from "types";
Expand Down Expand Up @@ -140,6 +141,9 @@ export default function Confirm(props: Props) {
changePage,
};

const showFeeBreakdown =
props.showFeeBreakdown && hasFeatureFlag("FEE_BREAKDOWN");

return (
<Box textAlign="left" width="100%">
<>
Expand Down Expand Up @@ -181,7 +185,7 @@ export default function Confirm(props: Props) {
/>
</Typography>
</FormWrapper>
{props.showFeeBreakdown && <FeeBreakdown />}
{showFeeBreakdown && <FeeBreakdown />}
</Banner>
)}
{page === "Pay" ? (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import TableContainer from "@mui/material/TableContainer";
import TableHead from "@mui/material/TableHead";
import TableRow from "@mui/material/TableRow";
import Typography from "@mui/material/Typography";
import { hasFeatureFlag } from "lib/featureFlags";
import React from "react";
import { FONT_WEIGHT_SEMI_BOLD } from "theme";

Expand Down Expand Up @@ -91,8 +90,6 @@ export const FeeBreakdown: React.FC = () => {
const breakdown = useFeeBreakdown();
if (!breakdown) return null;

if (!hasFeatureFlag("FEE_BREAKDOWN")) return null;

return (
<Box mt={3}>
<Typography variant="h3" mb={1}>
Expand Down
15 changes: 14 additions & 1 deletion editor.planx.uk/src/@planx/components/Pay/Public/Pay.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,20 @@ describe("the demo user view", () => {
});

describe("Displaying the fee breakdown", () => {
beforeAll(() => (initialState = getState()));
beforeAll(() => {
initialState = getState();
// Valid passport data is required to display the breakdown
setState({
computePassport: vi.fn().mockReturnValue({
data: {
"application.fee.calculated": 1000,
"application.fee.payable": 800,
"application.fee.payable.vat": 160,
},
}),
});
});

afterEach(() => act(() => setState(initialState)));

test("if the showFeeBreakdown prop is set, the breakdown is displayed to the user", () => {
Expand Down

0 comments on commit 595d8dd

Please sign in to comment.