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

describe("LicenceDelivery", () => {
    it("offers the file and always shows the blob as a fallback", () => {
        render(
            <LicenceDelivery
                instanceId="6a0fe3f0-49d2-4aa1-967c-a3094b200b5d"
                blob="VANTAGE-LIC abc123"
                downloadUrl="https://admin.example.com/api/instances/x/license/download"
            />,
        );
        const link = screen.getByRole("link", { name: /download licence/i });
        expect(link).toHaveAttribute("href", expect.stringContaining("/license/download"));
        // A blocked download must never leave a paying customer stuck.
        expect(screen.getByText(/VANTAGE-LIC abc123/)).toBeInTheDocument();
        expect(screen.getByText(/Settings → Licence/)).toBeInTheDocument();
    });
});
