diff --git a/frontend/components/forms/LoginForm/LoginForm.tests.jsx b/frontend/components/forms/LoginForm/LoginForm.tests.jsx
index c74d437d16..d9ed673e0e 100644
--- a/frontend/components/forms/LoginForm/LoginForm.tests.jsx
+++ b/frontend/components/forms/LoginForm/LoginForm.tests.jsx
@@ -1,93 +1,64 @@
import React from "react";
-import { mount } from "enzyme";
-import { noop } from "lodash";
+import { fireEvent, render, screen } from "@testing-library/react";
+import userEvent from "@testing-library/user-event";
+
import LoginForm from "./LoginForm";
-import { fillInFormInput } from "../../../test/helpers";
describe("LoginForm - component", () => {
const settings = { sso_enabled: false };
+ const submitSpy = jest.fn();
+ const baseError = "Unable to authenticate the current user";
it("renders the base error", () => {
- const baseError = "Unable to authenticate the current user";
- const formWithError = mount(
+ render(
);
- const formWithoutError = mount(
-
- );
- expect(formWithError.text()).toContain(baseError);
- expect(formWithoutError.text()).not.toContain(baseError);
+ expect(screen.getByText(baseError)).toBeInTheDocument();
+ });
+
+ it("should not render the base error", () => {
+ render();
+
+ expect(screen.queryByText(baseError)).not.toBeInTheDocument();
});
it("renders 2 InputField components", () => {
- const form = mount(
-
- );
+ render();
- expect(form.find("InputFieldWithIcon").length).toEqual(2);
- });
-
- it("updates component state when the email field is changed", () => {
- const form = mount(
-
- );
- const email = "hi@thegnar.co";
-
- const emailField = form.find({ name: "email" });
- fillInFormInput(emailField, email);
-
- const { formData } = form.state();
- expect(formData).toMatchObject({ email });
- });
-
- it("updates component state when the password field is changed", () => {
- const form = mount(
-
- );
-
- const passwordField = form.find({ name: "password" });
- fillInFormInput(passwordField, "hello");
-
- const { formData } = form.state();
- expect(formData).toMatchObject({
- password: "hello",
- });
+ expect(screen.getByRole("textbox", { name: "Email" })).toBeInTheDocument();
+ expect(screen.getByPlaceholderText("Password")).toBeInTheDocument();
});
it("it does not submit the form when the form fields have not been filled out", () => {
- const submitSpy = jest.fn();
- const form = mount(
-
- );
- const submitBtn = form.find("button");
+ render();
- submitBtn.simulate("click");
+ // when
+ fireEvent.click(screen.getByRole("button", { name: "Login" }));
- expect(form.state().errors).toMatchObject({
- email: "Email field must be completed",
- });
+ // then
expect(submitSpy).not.toHaveBeenCalled();
+ expect(
+ screen.getByText("Email field must be completed")
+ ).toBeInTheDocument();
});
it("submits the form data when form is submitted", () => {
- const submitSpy = jest.fn();
+ render();
- const form = mount(
-
+ // when
+ userEvent.type(
+ screen.getByRole("textbox", { name: "Email" }),
+ "my@email.com"
);
- const emailField = form.find({ name: "email" });
- const passwordField = form.find({ name: "password" });
- const submitBtn = form.find("button");
-
- fillInFormInput(emailField, "my@email.com");
- fillInFormInput(passwordField, "p@ssw0rd");
- submitBtn.simulate("submit");
+ userEvent.type(screen.getByPlaceholderText("Password"), "p@ssw0rd");
+ fireEvent.click(screen.getByRole("button", { name: "Login" }));
+ // then
expect(submitSpy).toHaveBeenCalledWith({
email: "my@email.com",
password: "p@ssw0rd",