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

test("Settings recognizes the documented composerEmpty condition", WEB, async ({t3, app, screen}) => {
  await t3.project("keybinding-demo");
  await t3.open("/settings/keybindings");
  await screen.getByRole("button", "Add keybinding", {exact:true}).tap();
  await screen.getByRole("combobox", "Search", {exact:true}).fill("Send First");
  await screen.getByRole("option", /Queue: Send First Queued Message/).tap();
  await screen.getByRole("button", "Edit when clause for Queue: Send First Queued Message", {exact:true}).first().tap();
  await screen.getByRole("textbox", "When expression").fill("composerFocus && turnRunning && composerEmpty");
  await app.screenshot("documented-expression");
  await screen.getByText("composerFocus", {exact:true}).last().tap();
  await app.screenshot("condition-picker");
  try {
    await expect(screen.getByRole("option", "composerEmpty", {exact:true})).toBeVisible();
  } finally {
    await screen.getByRole("textbox", "When expression").press("Escape");
    await screen.getByRole("button", "Edit when clause for Queue: Send First Queued Message", {exact:true}).first().tap();
    await app.screenshot("expression-recognition");
  }
  await expect(screen.getByLabel("Unknown condition: composerEmpty")).toHaveCount(0);
});
