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

test("Importing alpha keeps beta available", WEB, async ({ t3, app, screen, browser }) => {
  const project = await t3.project("mcp-import-demo");
  await t3.thread({ project, title: "MCP import proof", messages: ["Hello"] });
  await t3.open("/settings/labs");
  await screen.getByRole("switch", "MCP gateway", { exact: true }).tap();
  await t3.open("/settings/tools");
  const filter = screen.getByRole("combobox", "Show servers from", { exact: true });
  if (await filter.count()) {
    await filter.tap();
    await screen.getByRole("option", "Claude", { exact: true }).tap();
  }
  const capture = async (label: string) => {
    await browser.evaluate(async () => {
      await Promise.all(document.getAnimations().map((animation) => animation.finished.catch(() => {})));
    });
    await app.screenshot(label);
  };
  const add = screen.getByRole("button", "Add workspace to T3 Code", { exact: true });
  await add.nth(1).waitFor();
  await capture("two-project-configurations");
  await add.first().tap();
  await capture("import-alpha-configuration");
  await screen.getByRole("button", "Add server", { exact: true }).tap();
  await screen.getByText("Added workspace", { exact: true }).waitFor();
  await capture("beta-after-importing-alpha");
  await expect(add).toBeVisible();
  await add.tap();
  await capture("beta-offered-with-separate-name");
  await expect(screen.getByRole("textbox", "Name", { exact: true })).toHaveValue("workspace-2");
});
