2021-04-12 13:32:25 +00:00
|
|
|
import React from "react";
|
2022-09-12 15:10:10 +00:00
|
|
|
import { render, screen } from "@testing-library/react";
|
|
|
|
|
|
2022-12-14 18:56:56 +00:00
|
|
|
import { renderWithSetup } from "test/test-utils";
|
2016-12-29 20:27:43 +00:00
|
|
|
|
2021-04-12 13:32:25 +00:00
|
|
|
import ConfirmInviteForm from "components/forms/ConfirmInviteForm";
|
2016-12-29 20:27:43 +00:00
|
|
|
|
2021-04-12 13:32:25 +00:00
|
|
|
describe("ConfirmInviteForm - component", () => {
|
2020-12-01 18:15:12 +00:00
|
|
|
const handleSubmitSpy = jest.fn();
|
2025-01-24 18:55:39 +00:00
|
|
|
const defaultFormData = { name: "Test User" };
|
2021-04-12 13:32:25 +00:00
|
|
|
|
|
|
|
|
it("renders", () => {
|
2022-03-21 16:27:50 +00:00
|
|
|
render(
|
2025-01-24 18:55:39 +00:00
|
|
|
<ConfirmInviteForm
|
|
|
|
|
defaultFormData={defaultFormData}
|
|
|
|
|
handleSubmit={handleSubmitSpy}
|
|
|
|
|
/>
|
2022-03-21 16:27:50 +00:00
|
|
|
);
|
|
|
|
|
expect(
|
|
|
|
|
screen.getByRole("textbox", { name: "Full name" })
|
|
|
|
|
).toBeInTheDocument();
|
|
|
|
|
expect(screen.getByLabelText("Password")).toBeInTheDocument();
|
|
|
|
|
expect(screen.getByLabelText("Confirm password")).toBeInTheDocument();
|
|
|
|
|
expect(screen.getByRole("button", { name: "Submit" })).toBeInTheDocument();
|
2016-12-29 20:27:43 +00:00
|
|
|
});
|
|
|
|
|
|
2021-04-12 13:32:25 +00:00
|
|
|
it("renders the base error", () => {
|
|
|
|
|
const baseError = "Unable to authenticate the current user";
|
2022-03-21 16:27:50 +00:00
|
|
|
render(
|
2021-04-12 13:32:25 +00:00
|
|
|
<ConfirmInviteForm
|
2025-01-24 18:55:39 +00:00
|
|
|
ancestorError={baseError}
|
2022-03-21 16:27:50 +00:00
|
|
|
handleSubmit={handleSubmitSpy}
|
2021-04-12 13:32:25 +00:00
|
|
|
/>
|
|
|
|
|
);
|
2017-01-06 00:01:17 +00:00
|
|
|
|
2022-03-21 16:27:50 +00:00
|
|
|
expect(screen.getByText(baseError)).toBeInTheDocument();
|
2017-01-06 00:01:17 +00:00
|
|
|
});
|
|
|
|
|
|
2025-01-24 18:55:39 +00:00
|
|
|
it("calls the handleSubmit prop when valid", async () => {
|
2022-09-12 15:10:10 +00:00
|
|
|
const { user } = renderWithSetup(
|
2025-01-24 18:55:39 +00:00
|
|
|
<ConfirmInviteForm
|
|
|
|
|
defaultFormData={defaultFormData}
|
|
|
|
|
handleSubmit={handleSubmitSpy}
|
|
|
|
|
/>
|
2022-03-21 16:27:50 +00:00
|
|
|
);
|
2022-09-12 15:10:10 +00:00
|
|
|
|
|
|
|
|
await user.type(screen.getByLabelText("Password"), "p@ssw0rd");
|
|
|
|
|
await user.type(screen.getByLabelText("Confirm password"), "p@ssw0rd");
|
|
|
|
|
await user.click(screen.getByRole("button", { name: "Submit" }));
|
|
|
|
|
|
2016-12-29 20:27:43 +00:00
|
|
|
expect(handleSubmitSpy).toHaveBeenCalledWith({
|
2025-01-24 18:55:39 +00:00
|
|
|
...defaultFormData,
|
2021-04-12 13:32:25 +00:00
|
|
|
password: "p@ssw0rd",
|
|
|
|
|
password_confirmation: "p@ssw0rd",
|
2016-12-29 20:27:43 +00:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2021-04-12 13:32:25 +00:00
|
|
|
describe("name input", () => {
|
2022-03-21 16:27:50 +00:00
|
|
|
it("validates the field must be present", async () => {
|
2022-09-12 15:10:10 +00:00
|
|
|
const { user } = renderWithSetup(
|
2025-01-24 18:55:39 +00:00
|
|
|
<ConfirmInviteForm
|
|
|
|
|
defaultFormData={{ ...defaultFormData, ...{ name: "" } }}
|
|
|
|
|
handleSubmit={handleSubmitSpy}
|
|
|
|
|
/>
|
2022-03-21 16:27:50 +00:00
|
|
|
);
|
2022-09-12 15:10:10 +00:00
|
|
|
|
|
|
|
|
await user.click(screen.getByRole("button", { name: "Submit" }));
|
|
|
|
|
|
2022-03-21 16:27:50 +00:00
|
|
|
expect(
|
|
|
|
|
await screen.findByText("Full name must be present")
|
|
|
|
|
).toBeInTheDocument();
|
2016-12-29 20:27:43 +00:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2021-04-12 13:32:25 +00:00
|
|
|
describe("password input", () => {
|
2022-03-21 16:27:50 +00:00
|
|
|
it("validates the field must be present", async () => {
|
2022-09-12 15:10:10 +00:00
|
|
|
const { user } = renderWithSetup(
|
2025-01-24 18:55:39 +00:00
|
|
|
<ConfirmInviteForm
|
|
|
|
|
defaultFormData={defaultFormData}
|
|
|
|
|
handleSubmit={handleSubmitSpy}
|
|
|
|
|
/>
|
2022-03-21 16:27:50 +00:00
|
|
|
);
|
2022-09-12 15:10:10 +00:00
|
|
|
|
|
|
|
|
await user.click(screen.getByRole("button", { name: "Submit" }));
|
|
|
|
|
|
2022-03-21 16:27:50 +00:00
|
|
|
expect(
|
|
|
|
|
await screen.findByText("Password must be present")
|
|
|
|
|
).toBeInTheDocument();
|
2016-12-29 20:27:43 +00:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2021-04-12 13:32:25 +00:00
|
|
|
describe("password_confirmation input", () => {
|
2022-03-21 16:27:50 +00:00
|
|
|
it("validates the password_confirmation matches the password", async () => {
|
2022-09-12 15:10:10 +00:00
|
|
|
const { user } = renderWithSetup(
|
2025-01-24 18:55:39 +00:00
|
|
|
<ConfirmInviteForm
|
|
|
|
|
defaultFormData={defaultFormData}
|
|
|
|
|
handleSubmit={handleSubmitSpy}
|
|
|
|
|
/>
|
2022-03-21 16:27:50 +00:00
|
|
|
);
|
|
|
|
|
|
2022-09-12 15:10:10 +00:00
|
|
|
await user.type(screen.getByLabelText("Password"), "p@ssw0rd");
|
|
|
|
|
await user.type(
|
2022-03-21 16:27:50 +00:00
|
|
|
screen.getByLabelText("Confirm password"),
|
|
|
|
|
"another password"
|
|
|
|
|
);
|
2022-09-12 15:10:10 +00:00
|
|
|
await user.click(screen.getByRole("button", { name: "Submit" }));
|
|
|
|
|
|
|
|
|
|
const passwordError = screen.getByText(
|
|
|
|
|
"Password confirmation does not match password"
|
|
|
|
|
);
|
|
|
|
|
expect(passwordError).toBeInTheDocument();
|
2016-12-29 20:27:43 +00:00
|
|
|
});
|
|
|
|
|
|
2022-03-21 16:27:50 +00:00
|
|
|
it("validates the field must be present", async () => {
|
2022-09-12 15:10:10 +00:00
|
|
|
const { user } = renderWithSetup(
|
2025-01-24 18:55:39 +00:00
|
|
|
<ConfirmInviteForm
|
|
|
|
|
defaultFormData={defaultFormData}
|
|
|
|
|
handleSubmit={handleSubmitSpy}
|
|
|
|
|
/>
|
2022-03-21 16:27:50 +00:00
|
|
|
);
|
2022-09-12 15:10:10 +00:00
|
|
|
|
|
|
|
|
await user.click(screen.getByRole("button", { name: "Submit" }));
|
|
|
|
|
|
|
|
|
|
const passwordError = screen.getByText(
|
|
|
|
|
"Password confirmation must be present"
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
expect(passwordError).toBeInTheDocument();
|
2016-12-29 20:27:43 +00:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|