/// <reference lib="dom" />
import { expect } from "e2e";
import { test, WEB } from "./t3.ts";

test("Claude Fable 5.2 advertises Fast Mode while older Fable models do not", WEB, async ({ t3, app, browser, screen }) => {
  await browser.emulateMedia({ colorScheme: "dark" });
  const project = await t3.project("demo");
  const thread = await t3.thread({ project, title: "Fast Mode proof", messages: ["hello"] });
  await t3.open("/settings/providers?instanceId=claudeAgent");
  await screen.getByRole("textbox", "Filter models").fill("Fable");
  await screen.getByText("Claude Fable 5.2", { exact: true }).first().tap();
  await browser.evaluate(() => {
    for (const animation of document.getAnimations()) {
      if (Number.isFinite(animation.effect?.getComputedTiming().endTime)) animation.finish();
    }
    return null;
  });
  await app.screenshot("fable-model-capabilities");
  const capabilities = await browser.evaluate(() => Object.fromEntries(
    [...document.querySelectorAll("[data-model-slug]")].map(row => [row.getAttribute("data-model-slug"), row.textContent ?? ""])
  ));
  await screen.getByRole("switch", "Enable Claude", { exact: true }).tap();
  await t3.open(thread);
  await screen.getByRole("button", "Multi turn", { exact: true }).tap();
  await screen.getByRole("button", "Claude", { exact: true }).tap();
  await screen.getByRole("option", /Fable 5.2/).tap();
  await browser.evaluate(() => { const picker = document.querySelector("[data-model-picker-content]"); if (!picker) (document.querySelector("[data-chat-provider-model-picker]") as HTMLElement)?.click(); return null; });
  await app.screenshot("fable-composer-fast-mode");
  const fastControl = await browser.evaluate(() => !!document.querySelector('[role="radiogroup"][aria-label="Fast Mode"]'));
  expect(fastControl).toBe(true);
  expect(capabilities["claude-fable-5-2"]).toContain("Fast mode");
  expect(capabilities["claude-fable-5-1"]).not.toContain("Fast mode");
  expect(capabilities["claude-fable-5"]).not.toContain("Fast mode");
});
