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("Review includes ordinary untracked files beside an empty nested repository", WEB, async ({ t3, app, screen }) => {
  const project = await t3.project("demo-repo", { "README.md": "Original line\n" });
  const thread = await t3.thread({ project, title: "Review local changes", messages: ["first"] });
  await runPromise(Effect.flatMap(FileSystem.FileSystem, fs => Effect.all([
    fs.writeFileString(`${project}/README.md`, "Changed line\n"),
    fs.writeFileString(`${project}/notes.txt`, "Untracked note\n"),
  ])));
  await runPromise(run("git", ["init", "--quiet", "scaffold"], { cwd: project }));
  await t3.open(thread);
  await screen.getByRole("button", /^Changes/).tap();
  await screen.getByRole("button", "Refresh diff").tap();
  await app.screenshot("review-diff");
  await expect(screen.getByText("notes.txt", { exact: true }).first()).toBeVisible();
  await expect(screen.getByText("Showing tracked changes. Untracked changes could not be loaded. Refresh to retry.", { exact: true })).not.toBeVisible();
});
