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

describe("Queue", () => {
    it("shows the count and links every row to the work", () => {
        render(
            <Queue
                title="Failed injections"
                tone="expired"
                count={2}
                items={[
                    { label: "Acme Production", href: "/staff/instances/i1", meta: "4h ago" },
                    { label: "Globex EU", href: "/staff/instances/i2", meta: "26m ago" },
                ]}
            />,
        );
        expect(screen.getByText("Failed injections")).toBeInTheDocument();
        expect(screen.getByText("2")).toBeInTheDocument();
        expect(screen.getByRole("link", { name: "Acme Production" })).toHaveAttribute(
            "href",
            "/staff/instances/i1",
        );
    });

    it("says so plainly when there is nothing to do", () => {
        render(<Queue title="Past due" tone="expired" count={0} items={[]} />);
        expect(screen.getByText(/nothing to do/i)).toBeInTheDocument();
    });
});
