From 76040f8cd86acc511db0ce0ccd1aa52386b7ae1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dafydd=20Ll=C5=B7r=20Pearson?= Date: Wed, 27 Mar 2024 11:50:23 +0000 Subject: [PATCH] test: Add tests for inaccuracy, add missing test for comment --- .../src/components/Feedback/index.test.tsx | 39 ++++++++++++++++++- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/editor.planx.uk/src/components/Feedback/index.test.tsx b/editor.planx.uk/src/components/Feedback/index.test.tsx index 15be73e5c0..181d6e09d9 100644 --- a/editor.planx.uk/src/components/Feedback/index.test.tsx +++ b/editor.planx.uk/src/components/Feedback/index.test.tsx @@ -143,11 +143,46 @@ describe("Feedback component triage journey", () => { await user.click(getByText("feedback")); await user.click(getByRole("button", { name: "Comment" })); + await waitFor(() => {}); + expect(getByText("Share a comment")).toBeInTheDocument(); + + await user.type(getByTestId("userCommentTextarea"), "What about 3D maps"); + + await user.click(getByText("Send feedback")); + await waitFor(() => { - expect(getByText("Share a comment")).toBeInTheDocument(); + expect(getInternalFeedbackMetadata).toBeCalledTimes(1); + expect(insertFeedbackMutation).toBeCalledTimes(1); + expect(getByText("Thank you for your feedback.")).toBeInTheDocument(); }); + }); + + test("Selecting 'Inaccuracy' from triage scrolls the comment form into view", async () => { + const { getByText, getByRole, user } = setup(); + + await user.click(getByText("feedback")); + await user.click(getByRole("button", { name: "Inaccuracy" })); - await user.type(getByTestId("userCommentTextarea"), "This page is great"); + expect(scrollIntoViewMock).toBeCalledTimes(2); + + await waitFor(() => { + expect(getByText("Report an inaccuracy")).toBeInTheDocument(); + }); + }); + + test("Submitting 'Inaccuracy' form changes view to thank you message", async () => { + const { getByText, getByTestId, getByRole, user } = setup(); + + await user.click(getByText("feedback")); + await user.click(getByRole("button", { name: "Inaccuracy" })); + + await waitFor(() => {}); + expect(getByText("Report an inaccuracy")).toBeInTheDocument(); + + await user.type( + getByTestId("userCommentTextarea"), + "This information is wrong", + ); await user.click(getByText("Send feedback"));