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

test("Non-Latin provider labels keep an available ID and advance to Config", WEB, async ({ t3, app, screen }) => {
  await t3.project("provider-label-demo");
  const failures: unknown[] = [];
  for (const [name, label] of [["cyrillic", "Работа"], ["japanese", "仕事用"], ["emoji", "🚀"], ["latin-control", "Work"]]) {
    await t3.open("/settings/providers");
    await screen.getByRole("button", "Add provider", { exact: true }).first().tap();
    const dialog = screen.getByRole("dialog", "Add provider", { exact: true });
    await dialog.getByRole("button", "Configure manually", { exact: true }).tap();
    await dialog.getByLabel("Label", { exact: true }).fill(label);
    await app.screenshot(`${name}-identity`);
    await dialog.getByRole("button", "Next", { exact: true }).tap();
    try {
      await expect(dialog.getByRole("button", "Add instance", { exact: true })).toBeVisible({ timeout: 1500 });
    } catch (error) {
      failures.push(error);
    } finally {
      await app.screenshot(`${name}-after-next`);
    }
  }
  if (failures.length > 0) throw failures[0];
});
