import { render, fireEvent } from "@testing-library/react"; import { expect, it, describe, vi } from "vitest"; import { DismissableBanner, ErrorBanner, WarningBanner, } from "./DismissableBanner.component"; describe("DismissableBanner", () => { describe("Snapshots", () => { it("should match snapshot", () => { const res = render(); expect(res).toMatchSnapshot(); }); it("should match snapshot with icon", () => { const res = render(); expect(res).toMatchSnapshot(); }); it("should match snapshot with dismiss button", () => { const res = render( {}} />); expect(res).toMatchSnapshot(); }); }); describe("Functionality", () => { it("should call onDismiss when dismiss button is clicked", () => { const onDismiss = vi.fn(); const { getByLabelText } = render( ); fireEvent.click(getByLabelText("dismiss")); expect(onDismiss).toHaveBeenCalledTimes(1); }); }); }); describe("ErrorBanner", () => { describe("Snapshots", () => { it("should match snapshot", () => { const res = render(); expect(res).toMatchSnapshot(); }); }); describe("Functionality", () => { it("should call onDismiss when dismiss button is clicked", () => { const onDismiss = vi.fn(); const { getByLabelText } = render(); fireEvent.click(getByLabelText("dismiss")); expect(onDismiss).toHaveBeenCalledTimes(1); }); }); }); describe("WarningBanner", () => { describe("Snapshots", () => { it("should match snapshot", () => { const res = render(); expect(res).toMatchSnapshot(); }); }); describe("Functionality", () => { it("should call onDismiss when dismiss button is clicked", () => { const onDismiss = vi.fn(); const { getByLabelText } = render( ); fireEvent.click(getByLabelText("dismiss")); expect(onDismiss).toHaveBeenCalledTimes(1); }); }); });