import { expect } from "e2e";
import { test, WEB } from "./t3.ts";

test("A failed HTTP quota source does not add usage-limits to Replay", WEB, async ({ t3, app, browser, screen }) => {
  await browser.emulateMedia({ colorScheme: "dark" });
  const project = await t3.project("quota-demo");
  const thread = await t3.thread({ project, title: "Replay quota coverage", messages: ["Start"], model: "showcase" });
  await t3.open(thread);
  await screen.getByRole("textbox").fill("");
  await screen.getByRole("textbox").fill("/");
  await screen.getByText("/model", { exact: true }).waitFor();
  await app.screenshot("before-adding-source");
  await t3.open("/settings/providers");
  await screen.getByRole("button", "Add HTTP source", { exact: true }).tap();
  await screen.getByRole("textbox", "Endpoint URL", { exact: true }).fill("http://127.0.0.1:18799/quota");
  await screen.getByRole("button", "Add source", { exact: true }).tap();
  await screen.getByText("http://127.0.0.1:18799/quota", { exact: true }).waitFor();
  await screen.getByRole("button", /Refresh provider status/).tap();
  await t3.open(thread);
  await screen.getByRole("textbox").fill("");
  await screen.getByRole("textbox").fill("/");
  await screen.getByText("/model", { exact: true }).waitFor();
  await app.screenshot("failed-http-source-command-menu");
  await expect(screen.getByText("/usage-limits", { exact: true })).toBeHidden();
});
