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

test("Draft cards fit the same two-line layout as threads", WEB, async ({t3, app, browser, screen}) => {
  const project = await t3.project("Sample Project");
  const thread = await t3.thread({project, title: "First Sample Thread", messages: ["Hello"]});
  await browser.setViewport({width:1280,height:800});
  await t3.open("/settings/appearance");
  await screen.getByRole("button", "Customize", {exact:true}).tap();
  for (let i=0;i<8;i++) {
    const bottom = browser.locator('[data-layout-item-line="bottom"]');
    const count = await browser.evaluate(() => document.querySelectorAll('[data-layout-item-line="bottom"]').length);
    if (!count) break;
    await bottom.first().press("ArrowDown");
  }
  await screen.getByRole("button", "Done", {exact:true}).tap();
  await t3.open(thread);
  await screen.getByRole("button", "New thread", {exact:true}).tap();
  await screen.getByRole("textbox").fill("Unsent draft text");
  await screen.getByRole("button", "First Sample Thread", {exact:false}).tap();
  await app.screenshot("two-line-draft-card");
  const heights = await browser.evaluate(() => ({
    draft: document.querySelector('[data-testid="sidebar-draft-row"]')!.getBoundingClientRect().height,
    thread: document.querySelector('[data-testid="sidebar-row-card"]')!.getBoundingClientRect().height,
  }));
  expect(heights.draft).toBe(heights.thread);
});
