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

describe("NotConnectedPanel", () => {
    it("names the variable that is wrong and where it is set", () => {
        render(<NotConnectedPanel url="https://admin.example.com" />);

        expect(screen.getByRole("heading")).toHaveTextContent(
            /not connected to the licensing service/i,
        );
        expect(screen.getByText(/ADMIN_API_URL/)).toBeInTheDocument();
        expect(screen.getByText(/https:\/\/admin\.example\.com/)).toBeInTheDocument();
        // The two mistakes that actually cause this, both named.
        expect(screen.getByText(/reachable from your browser/i)).toBeInTheDocument();
        expect(screen.getByText(/ADMIN_ORIGIN/)).toBeInTheDocument();
    });

    it("says the value is missing when no URL was baked in", () => {
        render(<NotConnectedPanel url="" />);
        expect(screen.getByText(/was not set when this app was built/i)).toBeInTheDocument();
    });
});
