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

test("Russian removal warning covers all 21 checkouts and their threads", WEB, async ({ t3, app, browser, screen }) => {
  for (let index = 1; index <= 21; index++) {
    await t3.project(`demo-${String(index).padStart(2, "0")}`, {
      ".git/config": '[core]\nrepositoryformatversion = 0\nbare = false\n[remote "origin"]\nurl = https://github.com/example-org/demo-app.git\nfetch = +refs/heads/*:refs/remotes/origin/*\n',
    });
  }
  await t3.open("/settings/general");
  await screen.getByLabel("Language", { exact: true }).tap();
  await screen.getByText("Русский", { exact: true }).tap();
  await screen.getByLabel("Язык", { exact: true }).waitFor();
  await t3.open("/settings/projects");
  await screen.getByText("example-org/demo-app", { exact: true }).tap();
  await screen.getByText("Удалить этот проект везде", { exact: true }).waitFor();
  await browser.evaluate(() => {
    const title = [...document.querySelectorAll("*")].find((el) => el.textContent === "Удалить этот проект везде");
    for (const el of document.querySelectorAll("*")) {
      if (el.children.length === 0 && el.textContent?.includes("/workspaces/")) {
        el.textContent = `/demo-checkouts/${el.textContent.split("/").at(-1)}`;
      }
    }
    title?.scrollIntoView({ block: "center" });
  });
  await app.screenshot("russian-21-checkout-removal-warning");
  await expect(screen.getByText("Удаляет все записи копий (21) и их треды на всех машинах. Файлы на диске не затрагиваются.", { exact: true })).toBeVisible();
});
