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

describe("RelinkPanel", () => {
    it("shows the remaining allowance", () => {
        render(<RelinkPanel instanceId="i1" used={1} max={3} onRelink={vi.fn()} />);
        expect(screen.getByText("2 of 3 relinks left this term")).toBeInTheDocument();
        expect(screen.getByRole("button", { name: /relink/i })).toBeEnabled();
    });

    it("disables at zero and says what to do instead", () => {
        render(<RelinkPanel instanceId="i1" used={3} max={3} onRelink={vi.fn()} />);
        expect(screen.getByRole("button", { name: /relink/i })).toBeDisabled();
        expect(screen.getByText(/contact support/i)).toBeInTheDocument();
    });
});
