From ce6e37e269b062885c131bcf621e922d644f11bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dafydd=20Ll=C5=B7r=20Pearson?= Date: Fri, 17 May 2024 11:23:53 +0100 Subject: [PATCH] feat: Replace `Select` with `Autocomplete` in `FileUploadAndLabel` component (#2993) Co-authored-by: Ian Jones <51156018+ianjon3s@users.noreply.github.com> --- .../FileUploadAndLabel/Public.test.tsx | 243 +++++----- .../components/FileUploadAndLabel/Public.tsx | 7 +- .../FileUploadAndLabel/SelectMultiple.tsx | 416 +++++++++++------- .../PrivateFileUpload/UploadedFileCard.tsx | 4 +- editor.planx.uk/src/theme.ts | 8 + editor.planx.uk/src/ui/shared/Checkbox.tsx | 18 +- 6 files changed, 411 insertions(+), 285 deletions(-) diff --git a/editor.planx.uk/src/@planx/components/FileUploadAndLabel/Public.test.tsx b/editor.planx.uk/src/@planx/components/FileUploadAndLabel/Public.test.tsx index 0f69f50d9c..a8a8435fd8 100644 --- a/editor.planx.uk/src/@planx/components/FileUploadAndLabel/Public.test.tsx +++ b/editor.planx.uk/src/@planx/components/FileUploadAndLabel/Public.test.tsx @@ -1,10 +1,4 @@ -import { - act, - fireEvent, - screen, - waitFor, - within, -} from "@testing-library/react"; +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 { vanillaStore } from "pages/FlowEditor/lib/store"; @@ -27,7 +21,7 @@ window.URL.createObjectURL = jest.fn(); describe("Basic state and setup", () => { test("renders correctly", async () => { - setup( + const { getAllByRole, getByTestId, getByText } = setup( { />, ); - expect(screen.getAllByRole("heading")[0]).toHaveTextContent("Test title"); + expect(getAllByRole("heading")[0]).toHaveTextContent("Test title"); // Required file is listed - expect(screen.getByText("testKey")).toBeVisible(); + expect(getByText("testKey")).toBeVisible(); // Drop zone is available - expect(screen.getByTestId("upload-input")).toBeInTheDocument(); + expect(getByTestId("upload-input")).toBeInTheDocument(); }); it("should not have any accessibility violations", async () => { @@ -65,7 +59,7 @@ describe("Basic state and setup", () => { }); test("shows help buttons for header and applicable file", async () => { - setup( + const { getAllByTestId } = setup( { />, ); - const helpButtons = screen.getAllByTestId("more-info-button"); + const helpButtons = getAllByTestId("more-info-button"); expect(helpButtons).toHaveLength(1); }); it("does not show optional files if there are other types", () => { - setup( + const { queryByRole } = setup( { />, ); - expect( - screen.queryByRole("heading", { name: /Optional files/ }), - ).toBeNull(); + expect(queryByRole("heading", { name: /Optional files/ })).toBeNull(); }); it("shows optional files if there are no other types", () => { - setup( + const { getByRole } = setup( , ); - expect( - screen.getByRole("heading", { name: /Optional files/ }), - ).toBeVisible(); + expect(getByRole("heading", { name: /Optional files/ })).toBeVisible(); }); }); describe("Info-only mode with hidden drop zone", () => { test("renders correctly", async () => { - setup( + const { getAllByRole, queryByTestId, getByText } = setup(