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

test("Japanese section headings find Source control settings", WEB, async ({ t3, app, screen, browser }) => {
  const project = await t3.project("demo");
  await t3.thread({ project, title: "Settings demo", messages: ["Start"] });
  await t3.open("/settings/general");
  await screen.getByLabel("Language", { exact: true }).tap();
  await screen.getByText("日本語", { exact: true }).tap();
  await screen.getByLabel("言語", { exact: true }).waitFor();
  const found: boolean[] = [];
  for (const [query, label] of [["バージョン管理", "version-control-heading"], ["サーバー環境", "server-environment-heading"], ["version control", "english-control"]]) {
    await screen.getByLabel("設定を検索", { exact: true }).first().fill(query);
    await app.screenshot(label);
    const present = await browser.evaluate(() => document.querySelector('#settings-search-result-source-control')?.textContent?.includes("ソース管理") ?? false);
    if (present) {
      await browser.locator("#settings-search-result-source-control").tap();
      await screen.getByText("バージョン管理", { exact: true }).waitFor();
      found.push(await browser.evaluate(() => location.pathname === "/settings/source-control"));
      await t3.open("/settings/general");
    } else found.push(false);
  }
  await screen.getByLabel("設定を検索", { exact: true }).first().fill("");
  await t3.open("/settings/source-control");
  await screen.getByText("バージョン管理", { exact: true }).waitFor();
  await screen.getByText("Git", { exact: true }).first().waitFor({ timeout: 60_000 });
  await app.screenshot("visible-section-heading");
  await expect(found).toEqual([true, true, true]);
});
