import { render, screen } from "@testing-library/react";
import CoverageNotice from "./CoverageNotice";
import { formatTime } from "./format";

const WATERMARK = 1_700_000_000;

test("a window the log covers in full says nothing", () => {
	const { container } = render(<CoverageNotice coverage={{ complete: true, available_since: WATERMARK }} />);
	expect(container.textContent).toBe("");
});

test("a window reaching past the watermark names the instant history starts", () => {
	render(<CoverageNotice coverage={{ complete: false, available_since: WATERMARK }} />);
	const notice = screen.getByRole("status");
	expect(notice.textContent).toContain("Query history is available from");
	expect(notice.textContent).toContain(formatTime(WATERMARK));
});

/**
 * The server judges completeness, not the page: an unbounded request is
 * incomplete whatever the watermark reads, and the notice must follow that
 * verdict rather than compare timestamps itself.
 */
test("the server's verdict decides, not the numbers beside it", () => {
	const { rerender, container } = render(
		<CoverageNotice coverage={{ complete: true, available_since: WATERMARK }} />,
	);
	expect(container.textContent).toBe("");
	rerender(<CoverageNotice coverage={{ complete: false, available_since: 0 }} />);
	expect(screen.getByRole("status").textContent).toContain(formatTime(0));
});
