import { expect } from "e2e";
import * as Effect from "effect/Effect";
import * as FileSystem from "effect/FileSystem";
import { run } from "./shell.ts";
import { runPromise, test, WEB } from "./t3.ts";

test("Hide test files hides PascalCase test doubles and preserves Mockup", WEB, async ({ t3, app, browser, screen }) => {
  const project = await t3.project("test-double-names");
  const names = ["app.ts", "FakeClock.ts", "fakeTimer.ts", "MockTransport.ts", "Mockup.ts", "Foo.Mock.ts"];
  await runPromise(Effect.gen(function* () {
    const fs = yield* FileSystem.FileSystem;
    yield* fs.makeDirectory(`${project}/src`, { recursive: true });
    for (const name of names) yield* fs.writeFileString(`${project}/src/${name}`, "export const value = 1;\n");
    yield* run("git", ["add", "--intent-to-add", "src"], { cwd: project });
  }));
  const thread = await t3.thread({ project, title: "Review test double names", messages: ["first"] });
  await browser.setViewport({ width: 1440, height: 1000 });
  await t3.open(thread);
  await screen.getByText("first fixture turn complete", { exact: false }).waitFor();
  await screen.getByRole("button", "Toggle right panel").tap();
  await screen.getByText("Diff", { exact: true }).tap();
  const row = (name: string) => screen.getByRole("button", `Expand src/${name}`, { exact: true });
  for (const name of names) await row(name).waitFor();
  await app.screenshot("all-six-files");
  await screen.getByRole("button", "Hide test files", { exact: true }).tap();
  await row("fakeTimer.ts").waitFor({ state: "hidden" });
  await app.screenshot("hide-test-files");
  await expect(row("FakeClock.ts")).not.toBeVisible();
  await expect(row("MockTransport.ts")).not.toBeVisible();
  await expect(row("Foo.Mock.ts")).not.toBeVisible();
  await expect(row("app.ts")).toBeVisible();
  await expect(row("Mockup.ts")).toBeVisible();
});
