Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Johanna/small clean up frontend tests #5950

Merged
merged 3 commits into from
Jun 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions frontend/src/app/ReportingApp.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Provider } from "react-redux";
import createMockStore, { MockStoreEnhanced } from "redux-mock-store";
import { MockedProvider, MockedResponse } from "@apollo/client/testing";
import {
act,
render,
screen,
waitFor,
Expand Down Expand Up @@ -252,8 +253,11 @@ describe("App", () => {
await waitForElementToBeRemoved(() =>
screen.queryByText("Loading account information...")
);
await userEvent.click(
screen.getAllByText("Testing Site", { exact: false })[0]
await act(
async () =>
await userEvent.click(
screen.getAllByText("Testing Site", { exact: false })[0]
)
);
expect(
await screen.findByText("COVID-19 testing data")
Expand All @@ -280,7 +284,10 @@ describe("App", () => {
exact: false,
});
expect(trainingWelcome).toBeInTheDocument();
await userEvent.click(screen.getByText("Got it", { exact: false }));
await act(
async () =>
await userEvent.click(screen.getByText("Got it", { exact: false }))
);
expect(trainingWelcome).not.toBeInTheDocument();
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useState } from "react";
import {
act,
fireEvent,
render,
screen,
Expand Down Expand Up @@ -105,8 +106,11 @@ describe("ManageDevices", () => {
const deviceInput = screen.getByTestId("multi-select-toggle");
const deviceList = screen.getByTestId("multi-select-option-list");

await userEvent.click(deviceInput);
await userEvent.click(within(deviceList).getByText("Device C"));
await act(async () => await userEvent.click(deviceInput));
await act(
async () =>
await userEvent.click(within(deviceList).getByText("Device C"))
);

expect(await screen.findByTestId("pill-container"));
expect(
Expand Down
16 changes: 13 additions & 3 deletions frontend/src/app/Settings/Facility/FacilityFormContainer.test.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
act,
render,
screen,
waitForElementToBeRemoved,
Expand Down Expand Up @@ -226,7 +227,10 @@ describe("FacilityFormContainer", () => {

it("redirects on successful facility update", async () => {
await waitForElementToBeRemoved(() => screen.queryByText("Loading..."));
await userEvent.click(screen.getByRole("button", { name: /submit/i }));
await act(
async () =>
await userEvent.click(screen.getByRole("button", { name: /submit/i }))
);
expect(await screen.findByText("Redirected")).toBeInTheDocument();
});

Expand All @@ -235,7 +239,10 @@ describe("FacilityFormContainer", () => {
trackEvent: trackEventMock,
}));
await waitForElementToBeRemoved(() => screen.queryByText("Loading..."));
await userEvent.click(screen.getByRole("button", { name: /submit/i }));
await act(
async () =>
await userEvent.click(screen.getByRole("button", { name: /submit/i }))
);
expect(trackEventMock).toBeCalledWith({ name: "Save Settings" });
});
});
Expand All @@ -247,7 +254,10 @@ describe("FacilityFormContainer", () => {

it("creates a new facility", async () => {
expect(await screen.findByRole("button", { name: /submit/i }));
await userEvent.click(screen.getByRole("button", { name: /submit/i }));
await act(
async () =>
await userEvent.click(screen.getByRole("button", { name: /submit/i }))
);
expect(await screen.findByText("Redirected")).toBeInTheDocument();
});
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { MockedProvider } from "@apollo/client/testing";
import { render, screen, waitFor } from "@testing-library/react";
import { act, render, screen, waitFor } from "@testing-library/react";
import userEvent from "@testing-library/user-event";

import {
Expand Down Expand Up @@ -64,15 +64,15 @@ describe("ManageSelfRegistrationLinks", () => {
it("copies the org link", async () => {
const orgUrl = `${process.env.REACT_APP_BASE_URL}/register/${expectedOrgSlug}`;
const [orgBtn] = screen.getAllByRole("button");
await userEvent.click(orgBtn);
await act(async () => await userEvent.click(orgBtn));
await waitFor(async () => expect(orgBtn).toBeEnabled());
expect(navigator.clipboard.writeText).toBeCalledWith(orgUrl);
});

it("copies a facility link", async () => {
const facilityUrl = `${process.env.REACT_APP_BASE_URL}/register/${expectedFacilitySlug}`;
const btns = screen.getAllByRole("button");
await userEvent.click(btns[2]);
await act(async () => await userEvent.click(btns[2]));
await waitFor(async () => expect(btns[2]).toBeEnabled());
expect(navigator.clipboard.writeText).toBeCalledWith(facilityUrl);
});
Expand Down
9 changes: 6 additions & 3 deletions frontend/src/app/VersionEnforcer.test.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { render, screen } from "@testing-library/react";
import { act, render, screen } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import { Link, MemoryRouter, Outlet, Route, Routes } from "react-router-dom";

Expand Down Expand Up @@ -61,8 +61,11 @@ describe("VersionEnforcer", () => {
expect(await screen.findByText("This is the first page", { exact: false }));

// WHEN
await userEvent.click(
screen.getByText("Go to a new page", { exact: false })
await act(
async () =>
await userEvent.click(
screen.getByText("Go to a new page", { exact: false })
)
);

// THEN
Expand Down
34 changes: 25 additions & 9 deletions frontend/src/app/accountCreation/MfaPhone/MfaPhone.test.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
act,
render,
screen,
waitForElementToBeRemoved,
Expand Down Expand Up @@ -39,11 +40,17 @@ describe("Phone call MFA", () => {
});

it("can enter a valid phone number", async () => {
await userEvent.type(
screen.getByLabelText("Phone number", { exact: false }),
"(910) 867-5309"
await act(
async () =>
await userEvent.type(
screen.getByLabelText("Phone number", { exact: false }),
"(910) 867-5309"
)
);
await act(
async () =>
await userEvent.click(screen.getByText("Send code", { exact: false }))
);
await userEvent.click(screen.getByText("Send code", { exact: false }));
await waitForElementToBeRemoved(() =>
screen.queryByText("Validating phone number …")
);
Expand All @@ -53,18 +60,27 @@ describe("Phone call MFA", () => {
});

it("requires a phone number", async () => {
await userEvent.click(screen.getByText("Send code", { exact: false }));
await act(
async () =>
await userEvent.click(screen.getByText("Send code", { exact: false }))
);
expect(
await screen.findByText("Enter your phone number", { exact: false })
);
});

it("requires a valid phone number", async () => {
await userEvent.type(
screen.getByLabelText("Phone number", { exact: false }),
"(555) 555-5555"
await act(
async () =>
await userEvent.type(
screen.getByLabelText("Phone number", { exact: false }),
"(555) 555-5555"
)
);
await act(
async () =>
await userEvent.click(screen.getByText("Send code", { exact: false }))
);
await userEvent.click(screen.getByText("Send code", { exact: false }));
expect(
await screen.findByText("Enter a valid phone number", { exact: false })
);
Expand Down
32 changes: 16 additions & 16 deletions frontend/src/app/accountCreation/MfaSelect/MfaSelect.test.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { render, screen, waitFor } from "@testing-library/react";
import { act, render, screen, waitFor } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import { MemoryRouter, Route, Routes } from "react-router-dom";

Expand Down Expand Up @@ -34,20 +34,20 @@ jest.mock("../AccountCreationApiService", () => ({
}));

describe("MfaSelect", () => {
beforeEach(() => {
beforeEach(async () => {
render(<MfaSelect />);
});

it("can choose an mfa option", async () => {
const smsRadio = screen.getByLabelText("Text message (SMS)", {
exact: false,
});
await userEvent.click(smsRadio);
await act(async () => await userEvent.click(smsRadio));
expect(smsRadio).toBeChecked();
});

it("requires an mfa option", async () => {
await userEvent.click(screen.getByText("Continue"));
await act(async () => await userEvent.click(screen.getByText("Continue")));
expect(
screen.getByText("Select an authentication option")
).toBeInTheDocument();
Expand Down Expand Up @@ -95,9 +95,9 @@ describe("MfaSelect routing", () => {
const smsRadio = screen.getByLabelText("Text message (SMS)", {
exact: false,
});
await userEvent.click(smsRadio);
await act(async () => await userEvent.click(smsRadio));
expect(smsRadio).toBeChecked();
await userEvent.click(continueButton);
await act(async () => await userEvent.click(continueButton));
await waitFor(() => {
expect(
screen.getByText("Get your security code via text message (SMS).")
Expand All @@ -109,9 +109,9 @@ describe("MfaSelect routing", () => {
const googleRadio = screen.getByLabelText("Google Authenticator", {
exact: false,
});
await userEvent.click(googleRadio);
await act(async () => await userEvent.click(googleRadio));
expect(googleRadio).toBeChecked();
await userEvent.click(continueButton);
await act(async () => await userEvent.click(continueButton));
expect(
await screen.findByText(
"Get your security code via the Google Authenticator application."
Expand All @@ -123,9 +123,9 @@ describe("MfaSelect routing", () => {
const oktaRadio = screen.getByLabelText("Okta Verify", {
exact: false,
});
await userEvent.click(oktaRadio);
await act(async () => await userEvent.click(oktaRadio));
expect(oktaRadio).toBeChecked();
await userEvent.click(continueButton);
await act(async () => await userEvent.click(continueButton));
expect(
await screen.findByText(
"Get your security code via the Okta Verify application."
Expand All @@ -141,9 +141,9 @@ describe("MfaSelect routing", () => {
}
);

await userEvent.click(securityKeyRadio);
await act(async () => await userEvent.click(securityKeyRadio));
expect(securityKeyRadio).toBeChecked();
await userEvent.click(continueButton);
await act(async () => await userEvent.click(continueButton));

await waitFor(() => {
expect(
Expand All @@ -158,9 +158,9 @@ describe("MfaSelect routing", () => {
const emailRadio = screen.getByLabelText("Email", {
exact: false,
});
await userEvent.click(emailRadio);
await act(async () => await userEvent.click(emailRadio));
expect(emailRadio).toBeChecked();
await userEvent.click(continueButton);
await act(async () => await userEvent.click(continueButton));
await waitFor(() => {
expect(
screen.getByText(
Expand All @@ -175,9 +175,9 @@ describe("MfaSelect routing", () => {
const phoneRadio = screen.getByLabelText("Phone call", {
exact: false,
});
await userEvent.click(phoneRadio);
await act(async () => await userEvent.click(phoneRadio));
expect(phoneRadio).toBeChecked();
await userEvent.click(continueButton);
await act(async () => await userEvent.click(continueButton));
await waitFor(() => {
expect(
screen.getByText("Get your security code via a phone call")
Expand Down
25 changes: 16 additions & 9 deletions frontend/src/app/accountCreation/MfaSms/MfaSms.test.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
act,
render,
screen,
waitForElementToBeRemoved,
Expand Down Expand Up @@ -39,11 +40,14 @@ describe("SMS MFA", () => {
});

it("can enter a valid phone number", async () => {
await userEvent.type(
screen.getByLabelText("Phone number", { exact: false }),
"(910) 867-5309"
await act(
async () =>
await userEvent.type(
screen.getByLabelText("Phone number", { exact: false }),
"(910) 867-5309"
)
);
await userEvent.click(screen.getByText("Send code"));
await act(async () => await userEvent.click(screen.getByText("Send code")));
await waitForElementToBeRemoved(() =>
screen.queryByText("Validating phone number …")
);
Expand All @@ -54,16 +58,19 @@ describe("SMS MFA", () => {
});

it("requires a phone number", async () => {
await userEvent.click(screen.getByText("Send code"));
await act(async () => await userEvent.click(screen.getByText("Send code")));
expect(screen.getByText("Enter your phone number")).toBeInTheDocument();
});

it("requires a valid phone number", async () => {
await userEvent.type(
screen.getByLabelText("Phone number", { exact: false }),
"(555) 555-5555"
await act(
async () =>
await userEvent.type(
screen.getByLabelText("Phone number", { exact: false }),
"(555) 555-5555"
)
);
await userEvent.click(screen.getByText("Send code"));
await act(async () => await userEvent.click(screen.getByText("Send code")));
expect(screen.getByText("Enter a valid phone number")).toBeInTheDocument();
});
});
Loading