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

test("env uses the Node program for the file chip icon", WEB, async ({ t3, app, screen, browser }) => {
  const project = await t3.project("proj", {
    run: "#!/usr/bin/env -S node --conditions=python\nconsole.log('hello')\n",
    "run-plain": "#!/usr/bin/env node\nconsole.log('hello')\n",
  });
  const thread = await t3.thread({ project, title: "Env shebang icons", messages: ["Ready to review scripts"] });
  await t3.open(thread);
  const composer = screen.getByRole("textbox");
  await composer.pressSequentially("@run");
  await screen.getByRole("option", "run", { exact: true }).tap();
  await screen.getByRole("listbox", "Files and folders").waitFor({ state: "hidden" });
  await browser.keyboard.type(" @run-plain");
  await screen.getByRole("option", "run", { exact: true }).waitFor({ state: "hidden" });
  await screen.getByRole("option", "run-plain", { exact: true }).tap();
  await screen.getByRole("button", "Preview run-plain", { exact: true }).waitFor();
  const icon = (name: string) => browser.evaluate((file) =>
    document.querySelector(`[aria-label="Preview ${file}"] [data-pierre-icon]`)?.getAttribute("data-icon-token"), name);
  try {
    await expect.poll(() => icon("run")).toBe("javascript");
  } finally {
    await app.screenshot("env-shebang-icons");
  }
});
