Skip to content

Commit

Permalink
simplify pay error and add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
RODO94 committed Nov 15, 2024
1 parent b3af894 commit a68bfc2
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 7 deletions.
6 changes: 1 addition & 5 deletions editor.planx.uk/src/@planx/components/Pay/Editor.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import DataObjectIcon from "@mui/icons-material/DataObject";
import Box from "@mui/material/Box";
import FormControlLabel from "@mui/material/FormControlLabel";
import Link from "@mui/material/Link";
import Typography from "@mui/material/Typography";
import {
Expand Down Expand Up @@ -352,10 +351,7 @@ const Component: React.FC<Props> = (props: Props) => {
<Switch
checked={values.allowInviteToPay}
onChange={() =>
setFieldValue(
"allowInviteToPay",
!values.allowInviteToPay,
)
setFieldValue("allowInviteToPay", !values.allowInviteToPay)
}
label="Allow applicants to invite someone else to pay"
/>
Expand Down
28 changes: 28 additions & 0 deletions editor.planx.uk/src/@planx/components/Pay/Public/Pay.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -450,3 +450,31 @@ describe("Confirm component in information-only mode", () => {
expect(results).toHaveNoViolations();
});
});

describe("the demo user view", () => {
beforeEach(() => {
act(() =>
setState({
teamSlug: "demo",
}),
);
});
it.only("should render an error when teamSlug is demo", async () => {
const handleSubmit = vi.fn();
const { queryByText } = setup(
<Pay
title="Pay for your application"
fn="application.fee.typo"
handleSubmit={handleSubmit}
govPayMetadata={[]}
/>,
);
const errorHeader = queryByText("GOV.UK Pay is not enabled for demo users");
const errorGuidance = queryByText(
"Click continue to skip payment and proceed with your application for testing.",
);

expect(errorGuidance).toBeInTheDocument();
expect(errorHeader).toBeInTheDocument();
});
});
7 changes: 5 additions & 2 deletions editor.planx.uk/src/@planx/components/Pay/Public/Pay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ function Component(props: Props) {
const errorMessage =
teamSlug !== "demo"
? "GOV.UK Pay is not enabled for this local authority"
: "GOV.UK Pay is not enabled demo users";
: "GOV.UK Pay is not enabled for demo users";

// Handles UI states
const reducer = (_state: ComponentState, action: Action): ComponentState => {
Expand Down Expand Up @@ -302,7 +302,10 @@ function Component(props: Props) {
: "Retry payment"
}
error={
(state.status === "unsupported_team" && errorMessage) ||
(teamSlug === "demo" &&
"GOV.UK Pay is not enabled for demo users") ||
(state.status === "unsupported_team" &&
"GOV.UK Pay is not enabled for this local authority") ||
(state.status === "undefined_fee" &&
"We are unable to calculate your fee right now") ||
undefined
Expand Down

0 comments on commit a68bfc2

Please sign in to comment.