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

test("Missing Git is explained after a regular-file PATH entry", WEB, async ({ t3, app, browser, screen }) => {
  await browser.emulateMedia({ colorScheme: "dark" });
  await t3.open();
  await screen.getByRole("button", "Start", { exact: true }).tap();
  await browser.keyboard.press("Control+k");
  const palette = screen.getByRole("dialog", "Command palette");
  await palette.getByRole("combobox").fill("> New project");
  await palette.getByText("New project", { exact: true }).tap();
  await palette.getByRole("combobox").fill("Repro Demo");
  await browser.keyboard.press("Enter");
  await screen.getByText("Could not create the project", { exact: true }).waitFor();
  await browser.keyboard.press("Escape");
  await palette.waitFor({ state: "hidden" });
  await browser.evaluate(async () => {
    for (const animation of document.getAnimations()) {
      if (Number.isFinite(animation.effect?.getComputedTiming().endTime)) animation.finish();
    }
    await new Promise((resolve) => setTimeout(resolve, 1200));
    return null;
  });
  await app.screenshot("missing-git-project-creation-stable-1");
  await browser.evaluate(async () => {
    await new Promise((resolve) => setTimeout(resolve, 500));
    return null;
  });
  await app.screenshot("missing-git-project-creation-stable-2");
  await expect(screen.getByText("Git isn't installed on this machine. Install Git to create a project.", { exact: true })).toBeVisible();
});
