import { expect } from "e2e";
import { IOS, test } from "./t3-mobile.ts";

test("Project filter puts the most recently active projects first", IOS, async ({ t3, app, screen }) => {
  const server = await t3.project("server");
  await t3.thread({ project: server, title: "Older work", messages: ["Start"] });
  await t3.project("alpha");
  const bravo = await t3.project("bravo");
  const charlie = await t3.project("charlie");
  await t3.project("delta");
  await t3.project("echo");
  await t3.thread({ project: bravo, title: "Bravo work", messages: ["Start"] });
  await t3.thread({ project: charlie, title: "Charlie work", messages: ["Start"] });
  await t3.open();
  await screen.getByRole("button", "Filter threads by project").tap({ timeout: 120_000 });
  await app.screenshot("project-filter");
  const charlieBox = await screen.getByRole("button", "charlie").boundingBox();
  const bravoBox = await screen.getByRole("button", "bravo").boundingBox();
  const serverBox = await screen.getByRole("button", "server").boundingBox();
  expect(charlieBox!.y).toBeLessThan(bravoBox!.y);
  expect(bravoBox!.y).toBeLessThan(serverBox!.y);
});
