/// <reference lib="dom" />
import { expect } from "e2e";
import { test, WEB } from "./t3.ts";

test("French slash descriptions match decomposed accents", WEB, async ({ t3, app, browser, screen }) => {
  const project = await t3.project("demo");
  const thread = await t3.thread({ project, title: "French slash commands", messages: ["Bonjour"], model: "multi-turn" });
  await t3.open("/settings/general");
  await screen.getByLabel("Language", { exact: true }).tap();
  await screen.getByText("Français", { exact: true }).tap();
  await screen.getByLabel("Langue", { exact: true }).waitFor();
  await t3.open(thread);
  const composer = screen.getByRole("textbox");
  const results: boolean[] = [];
  for (const [query, command, label] of [
    ["/modèle", "/model", "composed-model-control"],
    ["/mode\u0300le", "/model", "decomposed-model"],
    ["/démarrer", "/clear", "composed-clear-control"],
    ["/de\u0301marrer", "/clear", "decomposed-clear"],
  ]) {
    await composer.fill("");
    await composer.tap();
    await browser.evaluate((text) => {
      const editor = document.activeElement!;
      const clipboardData = new DataTransfer();
      clipboardData.setData("text/plain", text);
      editor.dispatchEvent(new ClipboardEvent("paste", { clipboardData, bubbles: true, cancelable: true }));
      return null;
    }, query);
    await screen.getByText(/Changer le modèle de réponse de ce fil|Démarrer une nouvelle session|Aucune commande correspondante/).first().waitFor();
    await app.screenshot(label);
    results.push(await screen.getByRole("option").filter({ hasText: command }).count() > 0);
  }
  expect(results).toEqual([true, true, true, true]);
});
