import * as React from "react";
import {render, screen} from "@testing-library/react";
import userEvent, {UserEvent} from "@testing-library/user-event";
import {addToast, ToastProvider} from "../src";
const title = "Testing Title";
const description = "Testing Description";
describe("Toast", () => {
let user: UserEvent;
beforeEach(() => {
user = userEvent.setup();
});
it("should render correctly", () => {
const wrapper = render(
<>
>,
);
expect(() => wrapper.unmount()).not.toThrow();
});
it("ref should be forwarded", async () => {
const ref = React.createRef();
const wrapper = render(
<>
>,
);
const button = wrapper.getByTestId("button");
await user.click(button);
expect(ref.current).not.toBeNull();
});
it("should display title and description when component is rendered", async () => {
const wrapper = render(
<>
>,
);
const button = wrapper.getByTestId("button");
await user.click(button);
const region = screen.getByRole("region");
expect(region).toContainHTML(title);
expect(region).toContainHTML(description);
await user.click(wrapper.getAllByRole("button")[0]);
});
it("should close", async () => {
const wrapper = render(
<>
>,
);
const button = wrapper.getByTestId("button");
await user.click(button);
const initialCloseButtons = wrapper.getAllByRole("button");
const initialButtonLength = initialCloseButtons.length;
await user.click(initialCloseButtons[0]);
const finalCloseButtons = wrapper.getAllByRole("button");
const finalButtonLength = finalCloseButtons.length;
expect(initialButtonLength).toEqual(finalButtonLength + 1);
});
it("should work with placement", async () => {
const wrapper = render(
<>
>,
);
const region = wrapper.getByRole("region");
expect(region).toHaveAttribute("data-placement", "bottom-left");
});
it("should have loading-icon when promise prop is passed.", async () => {
const wrapper = render(
<>
>,
);
const button = wrapper.getByTestId("button");
await user.click(button);
const loadingIcon = wrapper.getByLabelText("loadingIcon");
expect(loadingIcon).toBeTruthy();
});
});