import { fireEvent, render, screen } from "@testing-library/react"; import * as stylex from "@stylexjs/stylex"; import { ApiError } from "@/lib/api"; import { styles as shared } from "@/ui/styles"; import InlineError from "./InlineError"; test("no retry button without onRetry", () => { render(); expect(screen.getByRole("alert").textContent).toBe("already exists"); expect(screen.queryByRole("button", { name: "Retry" })).toBeNull(); }); test("onRetry renders a focusable retry button that calls back", () => { const onRetry = vi.fn(); render(); const button = screen.getByRole("button", { name: "Retry" }); // The accessibility floor: StyleX compiles the ring to opaque class names, so // the check is that every class `focusRing` produces landed on the button. const ring = (stylex.props(shared.focusRing).className ?? "").split(" "); expect(button.className.split(" ")).toEqual(expect.arrayContaining(ring)); fireEvent.click(button); expect(onRetry).toHaveBeenCalledTimes(1); }); test("a null error renders nothing even with onRetry", () => { const { container } = render( undefined} />); expect(container.innerHTML).toBe(""); });