From 655b0c479450c6c3ec734fc8f487de8ae5da89b4 Mon Sep 17 00:00:00 2001 From: Jessica McInchak Date: Thu, 11 Apr 2024 18:01:01 +0200 Subject: [PATCH] show help text if defined for Content components --- .../@planx/components/Content/Public.test.tsx | 18 +++++ .../src/@planx/components/Content/Public.tsx | 78 ++++++++++++++++++- 2 files changed, 92 insertions(+), 4 deletions(-) diff --git a/editor.planx.uk/src/@planx/components/Content/Public.test.tsx b/editor.planx.uk/src/@planx/components/Content/Public.test.tsx index f9e0adf665..4e9f018bf8 100644 --- a/editor.planx.uk/src/@planx/components/Content/Public.test.tsx +++ b/editor.planx.uk/src/@planx/components/Content/Public.test.tsx @@ -18,6 +18,7 @@ test("const { user } = setups correctly", async () => { background: "#fff", color: "#0B0C0C", }); + expect(screen.queryByTestId("more-info-button")).not.toBeInTheDocument(); await user.click(screen.getByTestId("continue-button")); @@ -37,3 +38,20 @@ it("should not have any accessibility violations", async () => { const results = await axe(container); expect(results).toHaveNoViolations(); }); + +test("should display and open more information link if help text is provided", async () => { + const handleSubmit = jest.fn(); + + const { user } = setup( + , + ); + + expect(screen.getByTestId("more-info-button")).toBeInTheDocument(); + + await user.click(screen.getByTestId("more-info-button")); + expect(screen.findByText("Why does it matter?")).toBeTruthy(); +}); diff --git a/editor.planx.uk/src/@planx/components/Content/Public.tsx b/editor.planx.uk/src/@planx/components/Content/Public.tsx index 4d2fa13c34..c177aebc79 100644 --- a/editor.planx.uk/src/@planx/components/Content/Public.tsx +++ b/editor.planx.uk/src/@planx/components/Content/Public.tsx @@ -1,13 +1,21 @@ import { mostReadable } from "@ctrl/tinycolor"; +import HelpIcon from "@mui/icons-material/Help"; import Box from "@mui/material/Box"; import { styled } from "@mui/material/styles"; +import Typography from "@mui/material/Typography"; import type { Content } from "@planx/components/Content/model"; import Card from "@planx/components/shared/Preview/Card"; import { PublicProps } from "@planx/components/ui"; +import { useAnalyticsTracking } from "pages/FlowEditor/lib/analytics/provider"; import React from "react"; import { getContrastTextColor } from "styleUtils"; +import { emptyContent } from "ui/editor/RichTextInput"; import ReactMarkdownOrHtml from "ui/shared/ReactMarkdownOrHtml"; +import MoreInfo from "../shared/Preview/MoreInfo"; +import MoreInfoSection from "../shared/Preview/MoreInfoSection"; +import { HelpButton, Image } from "../shared/Preview/QuestionHeader"; + export type Props = PublicProps; const Content = styled(Box, { @@ -32,19 +40,81 @@ Content.defaultProps = { }; const ContentComponent: React.FC = (props) => { + const { + handleSubmit, + color, + content, + info, + policyRef, + howMeasured, + definitionImg, + } = props; + + const [open, setOpen] = React.useState(false); + const { trackEvent } = useAnalyticsTracking(); + + const handleHelpClick = () => { + setOpen(true); + trackEvent({ event: "helpClick", metadata: {} }); // This returns a promise but we don't need to await for it + }; + return ( - + + {!!(info || policyRef || howMeasured) && ( + + + More information + + + )} + setOpen(false)}> + {info && info !== emptyContent ? ( + + + + ) : undefined} + {policyRef && policyRef !== emptyContent ? ( + + + + ) : undefined} + {howMeasured && howMeasured !== emptyContent ? ( + + <> + {definitionImg && ( + + )} + + + + ) : undefined} + ); };