import React from "react"; import { fireEvent, render, TestWrapper } from "@test"; import { RefreshButton } from "./"; describe("Refresh Button", () => { const refresh = jest.fn(); it("should render button successfuly", () => { const { container, getByText } = render( refresh()} />, { wrapper: TestWrapper({ resources: [{ name: "posts" }], }), }, ); expect(container).toBeTruthy(); getByText("Refresh"); }); it("should render text by children", () => { const { container, getByText } = render( refine, { wrapper: TestWrapper({ resources: [{ name: "posts" }], }), }, ); expect(container).toBeTruthy(); getByText("refine"); }); it("should render without text show only icon", () => { const { container, queryByText } = render(, { wrapper: TestWrapper({ resources: [{ name: "posts" }], }), }); expect(container).toBeTruthy(); expect(queryByText("Refresh")).not.toBeInTheDocument(); }); it("should render called function successfully if click the button", () => { const { getByText } = render( refresh()} />, { wrapper: TestWrapper({ resources: [{ name: "posts" }], }), }, ); fireEvent.click(getByText("Refresh")); expect(refresh).toHaveBeenCalledTimes(1); }); });