2024-04-25 12:26:26 +00:00
|
|
|
import React from "react";
|
|
|
|
|
import { renderWithSetup } from "test/test-utils";
|
|
|
|
|
import { screen, render } from "@testing-library/react";
|
|
|
|
|
import { noop } from "lodash";
|
|
|
|
|
|
|
|
|
|
// @ts-ignore
|
|
|
|
|
import InputField from "components/forms/fields/InputField";
|
|
|
|
|
|
|
|
|
|
import LabelForm from "./LabelForm";
|
|
|
|
|
|
|
|
|
|
describe("LabelForm", () => {
|
|
|
|
|
it("should validate the name to be required", async () => {
|
|
|
|
|
const { user } = renderWithSetup(
|
2025-12-30 03:28:45 +00:00
|
|
|
<LabelForm
|
|
|
|
|
onSave={noop}
|
|
|
|
|
onCancel={noop}
|
|
|
|
|
immutableFields={[]}
|
|
|
|
|
teamName={null}
|
|
|
|
|
/>
|
2024-04-25 12:26:26 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const nameInput = screen.getByLabelText("Name");
|
|
|
|
|
|
|
|
|
|
await user.click(screen.getByRole("button", { name: "Save" }));
|
|
|
|
|
expect(screen.getByText("Label name must be present")).toBeInTheDocument();
|
|
|
|
|
|
|
|
|
|
await user.type(nameInput, "Label name");
|
|
|
|
|
expect(
|
|
|
|
|
screen.queryByText("Label name must be present")
|
|
|
|
|
).not.toBeInTheDocument();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("should render any additional field the user provides", () => {
|
|
|
|
|
render(
|
|
|
|
|
<LabelForm
|
|
|
|
|
onSave={noop}
|
|
|
|
|
onCancel={noop}
|
2025-12-30 03:28:45 +00:00
|
|
|
teamName={null}
|
|
|
|
|
immutableFields={[]}
|
2024-04-25 12:26:26 +00:00
|
|
|
additionalFields={<InputField name="test field" label="test field" />}
|
|
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
expect(screen.getByLabelText("test field")).toBeInTheDocument();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("should pass up the form data when the form is submitted and valid", async () => {
|
|
|
|
|
const onSave = jest.fn();
|
|
|
|
|
const { user } = renderWithSetup(
|
2025-12-30 03:28:45 +00:00
|
|
|
<LabelForm
|
|
|
|
|
onSave={onSave}
|
|
|
|
|
onCancel={jest.fn()}
|
|
|
|
|
teamName={null}
|
|
|
|
|
immutableFields={[]}
|
|
|
|
|
/>
|
2024-04-25 12:26:26 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const nameValue = "Test Name";
|
|
|
|
|
const descriptionValue = "Test Description";
|
|
|
|
|
await user.type(screen.getByLabelText("Name"), nameValue);
|
|
|
|
|
await user.type(screen.getByLabelText("Description"), descriptionValue);
|
|
|
|
|
await user.click(screen.getByRole("button", { name: "Save" }));
|
|
|
|
|
|
|
|
|
|
expect(onSave).toHaveBeenCalledWith(
|
|
|
|
|
{ name: nameValue, description: descriptionValue },
|
|
|
|
|
true
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
});
|