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

test("Hide test files recognizes plural test suffixes", WEB, async ({ t3, app, screen }) => {
  const files = {
    "native/hyprland-snap-shot/src/transport_tests.rs": "// Transport test module\n",
    "native/hyprland-snap-shot/src/capture.rs": "// Capture implementation\n",
    "packages/shared/src/changedFileKind.test.ts": "// Existing test control\n",
    "models_tests.py": "# Model tests\n",
    "latest_tests_helper.rs": "// Helper implementation\n",
  };
  const project = await t3.project("Test file filtering", files);
  await runPromise(Effect.gen(function* () {
    const fs = yield* FileSystem.FileSystem;
    for (const [path, content] of Object.entries(files)) {
      yield* fs.writeFileString(`${project}/${path}`, content + (path.endsWith(".py") ? "# Evidence change\n" : "// Evidence change\n"));
    }
  }));
  const thread = await t3.thread({ project, title: "Plural test suffix", messages: ["first"] });
  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 file = (path: string) => screen.getByRole("button", `Expand ${path}`, { exact: true });
  for (const path of Object.keys(files)) await file(path).waitFor();
  await app.screenshot("all-five-changed-files");
  await screen.getByRole("button", "Hide test files", { exact: true }).tap();
  await file("packages/shared/src/changedFileKind.test.ts").waitFor({ state: "hidden" });
  await app.screenshot("test-files-hidden");
  await expect(file("native/hyprland-snap-shot/src/transport_tests.rs")).not.toBeVisible();
  await expect(file("models_tests.py")).not.toBeVisible();
  await expect(file("native/hyprland-snap-shot/src/capture.rs")).toBeVisible();
  await expect(file("latest_tests_helper.rs")).toBeVisible();
});
