Skip to content

Commit

Permalink
refactor: update to move from fireEvent to user
Browse files Browse the repository at this point in the history
- As per: #2815 (comment)
  • Loading branch information
Mike-Heneghan committed Feb 26, 2024
1 parent c4c57f1 commit 70e5e81
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions editor.planx.uk/src/components/Feedback/MoreInfoFeedback.test.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { fireEvent, waitFor } from "@testing-library/react";
import { waitFor } from "@testing-library/react";
import {
getInternalFeedbackMetadata,
insertFeedbackMutation,
Expand Down Expand Up @@ -37,8 +37,8 @@ describe("MoreInfoFeedbackComponent presentation and functionality", () => {

// Sentiment selection
test("Clicking Yes input form scrolls into view", async () => {
const { getByText } = setup(<MoreInfoFeedbackComponent />);
fireEvent.click(getByText("Yes"));
const { getByText, user } = setup(<MoreInfoFeedbackComponent />);
await user.click(getByText("Yes"));
expect(scrollIntoView).toBeCalled();
await waitFor(() => {
expect(
Expand All @@ -48,8 +48,9 @@ describe("MoreInfoFeedbackComponent presentation and functionality", () => {
});

test("Clicking No input form scrolls into view", async () => {
const { getByText } = setup(<MoreInfoFeedbackComponent />);
fireEvent.click(getByText("No"));
const { getByText, user } = setup(<MoreInfoFeedbackComponent />);

await user.click(getByText("No"));
expect(scrollIntoView).toBeCalled();
await waitFor(() => {
expect(
Expand All @@ -64,14 +65,14 @@ describe("MoreInfoFeedbackComponent presentation and functionality", () => {
<MoreInfoFeedbackComponent />,
);

fireEvent.click(getByText("Yes"));
user.click(getByText("Yes"));
await waitFor(() => {
expect(getByTestId("userCommentTextarea")).toBeInTheDocument();
});

await user.type(getByTestId("userCommentTextarea"), "Great help, thanks!");

fireEvent.click(getByText("Send feedback"));
user.click(getByText("Send feedback"));
await waitFor(() => {
expect(getInternalFeedbackMetadata).toBeCalled();
expect(insertFeedbackMutation).toBeCalled();
Expand All @@ -93,9 +94,11 @@ describe("MoreInfoFeedbackComponent presentation and functionality", () => {
validation.
*/
test("Feedback form requires a comment before submitting", async () => {
const { getByTestId, getByText } = setup(<MoreInfoFeedbackComponent />);
const { getByTestId, getByText, user } = setup(
<MoreInfoFeedbackComponent />,
);

fireEvent.click(getByText("Yes"));
user.click(getByText("Yes"));
await waitFor(() => {
expect(getByTestId("userCommentTextarea")).toBeInTheDocument();
});
Expand All @@ -116,8 +119,8 @@ describe("MoreInfoFeedbackComponent accessibility", () => {
});

test("Form view should have no accessability violations", async () => {
const { container, getByText } = setup(<MoreInfoFeedbackComponent />);
fireEvent.click(getByText("Yes"));
const { container, getByText, user } = setup(<MoreInfoFeedbackComponent />);
user.click(getByText("Yes"));

const results = await axe(container);
expect(results).toHaveNoViolations();
Expand All @@ -128,14 +131,14 @@ describe("MoreInfoFeedbackComponent accessibility", () => {
<MoreInfoFeedbackComponent />,
);

fireEvent.click(getByText("Yes"));
user.click(getByText("Yes"));
await waitFor(() => {
expect(getByTestId("userCommentTextarea")).toBeInTheDocument();
});

await user.type(getByTestId("userCommentTextarea"), "Great help, thanks!");

fireEvent.click(getByText("Send feedback"));
user.click(getByText("Send feedback"));

await waitFor(() => {
expect(getByText("Thank you for your feedback.")).toBeInTheDocument();
Expand Down

0 comments on commit 70e5e81

Please sign in to comment.