Skip to content

Commit

Permalink
feat: add export/print button to Upload+Label and Review components (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
jamdelion authored Oct 8, 2024
1 parent dc85fa8 commit e0c7b5a
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { act, screen, waitFor, within } from "@testing-library/react";
import { UserEvent } from "@testing-library/user-event/dist/types/setup/setup";
import axios from "axios";
import { useStore } from "pages/FlowEditor/lib/store";
import { FullStore } from "pages/FlowEditor/lib/store";
import { FullStore, useStore } from "pages/FlowEditor/lib/store";
import React from "react";
import { setup } from "testUtils";
import { Breadcrumbs } from "types";
Expand Down Expand Up @@ -60,6 +59,18 @@ describe("Basic state and setup", () => {
expect(results).toHaveNoViolations();
});

it("does not show a print button if hideDropZone is false", async () => {
const { queryByText } = setup(
<FileUploadAndLabelComponent
title="Test title"
fileTypes={[mockFileTypes.AlwaysRequired, mockFileTypes.NotRequired]}
// hideDropZone is false by default
/>,
);
const printButton = queryByText("Print this page");
expect(printButton).toBeNull();
});

test("shows help buttons for header and applicable file", async () => {
const { getAllByTestId } = setup(
<FileUploadAndLabelComponent
Expand Down Expand Up @@ -141,6 +152,17 @@ describe("Info-only mode with hidden drop zone", () => {
expect(results).toHaveNoViolations();
});

it("shows a print button", async () => {
const { getByText } = setup(
<FileUploadAndLabelComponent
title="Test title"
fileTypes={[mockFileTypes.AlwaysRequired, mockFileTypes.NotRequired]}
hideDropZone={true}
/>,
);
expect(getByText("Print this page")).toBeVisible();
});

test("shows help buttons for header and applicable file", async () => {
const { getAllByTestId } = setup(
<FileUploadAndLabelComponent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import ListSubheader from "@mui/material/ListSubheader";
import { styled } from "@mui/material/styles";
import Typography from "@mui/material/Typography";
import { PublicProps } from "@planx/components/ui";
import { PrintButton } from "components/PrintButton";
import capitalize from "lodash/capitalize";
import { useAnalyticsTracking } from "pages/FlowEditor/lib/analytics/provider";
import { HelpClickMetadata } from "pages/FlowEditor/lib/analytics/types";
Expand Down Expand Up @@ -271,6 +272,7 @@ function Component(props: Props) {
</Box>
</ErrorWrapper>
</FullWidthWrapper>
{props.hideDropZone && <PrintButton />}
</Card>
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { NodeId } from "@opensystemslab/planx-core/types";
import Card from "@planx/components/shared/Preview/Card";
import CardHeader from "@planx/components/shared/Preview/CardHeader";
import SummaryListsBySections from "@planx/components/shared/Preview/SummaryList";
import { PrintButton } from "components/PrintButton";
import { Store } from "pages/FlowEditor/lib/store";
import { sortBreadcrumbs } from "pages/FlowEditor/lib/store/preview";
import type { HandleSubmit } from "pages/Preview/Node";
Expand Down Expand Up @@ -38,6 +39,7 @@ function Component(props: Props) {
showChangeButton={props.showChangeButton}
sectionComponent="h2"
/>
<PrintButton />
</Card>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ describe("Simple flow", () => {
const handleSubmit = vi.fn();
const changeAnswer = vi.fn();

const { user } = setup(
const { user, getByText } = setup(
<Review
title="Review"
description="Check your answers before submitting"
Expand All @@ -52,6 +52,7 @@ describe("Simple flow", () => {
);

expect(screen.getByRole("heading")).toHaveTextContent("Review");
expect(getByText("Print this page")).toBeVisible();

await user.click(screen.getByTestId("continue-button"));

Expand Down
17 changes: 17 additions & 0 deletions editor.planx.uk/src/components/PrintButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import PrintIcon from "@mui/icons-material/Print";
import Button from "@mui/material/Button";
import React from "react";

export const PrintButton = () => {
return (
<Button
variant="contained"
color="secondary"
startIcon={<PrintIcon />}
size="large"
onClick={() => window.print()}
>
Print this page
</Button>
);
};

0 comments on commit e0c7b5a

Please sign in to comment.