/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/
import React from "react";
import { render, fireEvent, waitFor } from "@testing-library/react";
import TextField from "../TextField";
test("renders a text input", async () => {
const wrapper = render();
expect(wrapper.container).toMatchSnapshot();
});
test("renders a text input with hint", async () => {
const wrapper = render();
expect(wrapper.container).toMatchSnapshot();
});
test("registers the input to the provided function", async () => {
const register = jest.fn();
render();
expect(register).toBeCalled();
});
test("registers the input as required", async () => {
const register = jest.fn();
render();
expect(register).toBeCalledWith({ required: true });
});
test("sets the default value", async () => {
const { getByRole } = render();
expect(getByRole("textbox")).toHaveValue("Banana");
});
test("check onChange event is invoked", async () => {
const onChange = jest.fn();
const { getByLabelText } = render(
,
);
fireEvent.input(getByLabelText("Hello"), {
target: {
value: "Test",
},
});
await waitFor(() => expect(onChange).toHaveBeenCalled());
});
test("shows an error message", async () => {
const wrapper = render(
,
);
expect(wrapper.container).toMatchSnapshot();
});
test("renders a multiline textarea", async () => {
const wrapper = render();
expect(wrapper.container).toMatchSnapshot();
});