import { render, screen } from "@testing-library/react";
import { describe, expect, it } from "vitest";

import { AdminFlash } from "@/components/admin/admin-flash";

describe("AdminFlash", () => {
  it("renders nothing when there are no messages", () => {
    const { container } = render(<AdminFlash />);
    expect(container.firstChild).toBeNull();
  });

  it("renders a success message with a status role", () => {
    render(<AdminFlash success="Saved." />);
    const status = screen.getByRole("status");
    expect(status).toHaveTextContent("Saved.");
    expect(screen.queryByRole("alert")).toBeNull();
  });

  it("renders an error message with an alert role", () => {
    render(<AdminFlash error="Failed." />);
    const alert = screen.getByRole("alert");
    expect(alert).toHaveTextContent("Failed.");
    expect(screen.queryByRole("status")).toBeNull();
  });

  it("renders both a success and error message together", () => {
    render(<AdminFlash success="Yes" error="No" />);
    expect(screen.getByRole("status")).toHaveTextContent("Yes");
    expect(screen.getByRole("alert")).toHaveTextContent("No");
  });

  it("applies a custom className to the wrapper", () => {
    const { container } = render(<AdminFlash success="Yes" className="mb-4" />);
    expect(container.firstChild).toHaveClass("mb-4");
  });
});
