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";
|
2016-11-16 16:58:25 +00:00
|
|
|
|
2022-12-14 18:56:56 +00:00
|
|
|
import { renderWithSetup } from "test/test-utils";
|
2021-04-12 13:32:25 +00:00
|
|
|
import OrgDetails from "components/forms/RegistrationForm/OrgDetails";
|
2016-11-16 16:58:25 +00:00
|
|
|
|
2021-04-12 13:32:25 +00:00
|
|
|
describe("OrgDetails - form", () => {
|
2022-04-08 14:35:57 +00:00
|
|
|
const handleSubmitSpy = jest.fn();
|
|
|
|
|
it("renders", () => {
|
|
|
|
|
render(<OrgDetails handleSubmit={handleSubmitSpy} />);
|
|
|
|
|
|
|
|
|
|
expect(
|
|
|
|
|
screen.getByRole("textbox", { name: "Organization name" })
|
|
|
|
|
).toBeInTheDocument();
|
|
|
|
|
expect(screen.getByRole("button", { name: "Next" })).toBeInTheDocument();
|
2016-11-16 16:58:25 +00:00
|
|
|
});
|
|
|
|
|
|
2022-09-12 15:10:10 +00:00
|
|
|
it("validates presence of org_name field", async () => {
|
|
|
|
|
const { user } = renderWithSetup(
|
|
|
|
|
<OrgDetails handleSubmit={handleSubmitSpy} currentPage />
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
await user.click(screen.getByRole("button", { name: "Next" }));
|
|
|
|
|
|
2022-04-08 14:35:57 +00:00
|
|
|
expect(handleSubmitSpy).not.toHaveBeenCalled();
|
|
|
|
|
expect(
|
|
|
|
|
screen.getByText("Organization name must be present")
|
|
|
|
|
).toBeInTheDocument();
|
2016-11-16 16:58:25 +00:00
|
|
|
});
|
|
|
|
|
|
2022-09-12 15:10:10 +00:00
|
|
|
it("validates the logo url field starts with https://", async () => {
|
|
|
|
|
const { user } = renderWithSetup(
|
|
|
|
|
<OrgDetails handleSubmit={handleSubmitSpy} currentPage />
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
await user.type(
|
2022-04-08 14:35:57 +00:00
|
|
|
screen.getByRole("textbox", { name: "Organization logo URL (optional)" }),
|
|
|
|
|
"http://www.thegnar.co/logo.png"
|
|
|
|
|
);
|
2022-09-12 15:10:10 +00:00
|
|
|
await user.click(screen.getByRole("button", { name: "Next" }));
|
|
|
|
|
|
2022-04-08 14:35:57 +00:00
|
|
|
expect(handleSubmitSpy).not.toHaveBeenCalled();
|
|
|
|
|
expect(
|
|
|
|
|
screen.getByText("Organization logo URL must start with https://")
|
|
|
|
|
).toBeInTheDocument();
|
|
|
|
|
});
|
2016-11-16 16:58:25 +00:00
|
|
|
|
2022-09-12 15:10:10 +00:00
|
|
|
it("submits the form when valid", async () => {
|
|
|
|
|
const { user } = renderWithSetup(
|
|
|
|
|
<OrgDetails handleSubmit={handleSubmitSpy} currentPage />
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
await user.type(
|
2022-04-08 14:35:57 +00:00
|
|
|
screen.getByRole("textbox", { name: "Organization logo URL (optional)" }),
|
|
|
|
|
"https://www.thegnar.co/logo.png"
|
|
|
|
|
);
|
2022-09-12 15:10:10 +00:00
|
|
|
await user.type(
|
2022-04-08 14:35:57 +00:00
|
|
|
screen.getByRole("textbox", { name: "Organization name" }),
|
|
|
|
|
"The Gnar Co"
|
|
|
|
|
);
|
2022-09-12 15:10:10 +00:00
|
|
|
await user.click(screen.getByRole("button", { name: "Next" }));
|
|
|
|
|
|
2022-04-08 14:35:57 +00:00
|
|
|
expect(handleSubmitSpy).toHaveBeenCalledWith({
|
|
|
|
|
org_logo_url: "https://www.thegnar.co/logo.png",
|
|
|
|
|
org_name: "The Gnar Co",
|
2016-11-16 16:58:25 +00:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|