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

test("Imported VS Code theme names omit an emoji crossing the name limit", WEB, async ({ t3, app, screen, browser }) => {
  await t3.project("demo");
  await t3.open("/settings/appearance");
  await screen.getByRole("button", "Add theme", { exact: true }).tap();
  const dialog = screen.getByRole("dialog", "Add a theme");
  await dialog.getByRole("textbox", "Theme JSON").fill('{"name":"Midnight Harbor Theme with Soft Blue Highlights🌙","type":"dark","colors":{"editor.background":"#14161f","editor.foreground":"#d8dee9"}}');
  await dialog.getByRole("button", "Add theme", { exact: true }).tap();
  await dialog.waitFor({ state: "hidden" });
  await screen.getByRole("button", /^Edit Midnight Harbor Theme with Soft Blue Highlights/).tap();
  const name = screen.getByRole("textbox", "Theme name", { exact: true });
  await name.waitFor();
  await browser.evaluate(() => {
    const input = [...document.querySelectorAll<HTMLInputElement>('input')].find(el => el.value.startsWith('Midnight Harbor'))!;
    input.focus();
    input.setSelectionRange(input.value.length, input.value.length);
    input.scrollLeft = input.scrollWidth;
    return null;
  });
  await app.screenshot("imported-theme-name-in-editor");
  await expect(name).toHaveValue("Midnight Harbor Theme with Soft Blue Highlights");
});
