import { expect } from "e2e";
import { IOS, test } from "./t3-mobile.ts";

const comment = (file: string, text: string, diff: string) =>
  `<review_comment sectionId="git:working-tree" filePath="${file}" startIndex="0" endIndex="2">\n${text}\n\n\`\`\`diff\n${diff}\n\`\`\`\n</review_comment>`;

test("Headerless review snippets preserve deleted -- and added ++ content", IOS, async ({ t3, app, screen }) => {
  const project = await t3.project("snippet-proof");
  await t3.thread({
    project,
    title: "Review snippet proof",
    messages: [
      comment("example.sql", "Keep SQL comments", " select 1;\n--- note\n+-- new note"),
      comment("counter.c", "Keep increment lines", "+++ counter\n-x") + "\n\n" +
        comment("control.sql", "Ordinary diff control", " select 1;\n-- note\n+- new note"),
    ],
  });
  await t3.open();
  await screen.getByText("Review snippet proof", { exact: false }).first().waitFor({ timeout: 120_000 });
  await screen.getByText("Review snippet proof", { exact: false }).first().tap();
  await screen.getByText("counter.c", { exact: true }).waitFor({ timeout: 60_000 });
  await app.screenshot("added-plus-and-control");
  await expect(screen.getByText("+++ counter", { exact: false })).not.toBeVisible();
});
