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

test("Send receives the first tap after Scroll to end", IOS, async ({ t3, app, screen, device }) => {
  const project = await t3.project("Scroll proof");
  const { threadId } = await t3.thread({ project, title: "Long conversation", messages: Array.from({ length: 8 }, (_, i) => `Review section ${i + 1}`), model: "multi-turn" });
  await t3.open();
  await screen.getByText("Long conversation", { exact: false }).first().waitFor({ timeout: 120_000 });
  const environment = await runPromise(environmentId(`http://${MOBILE.host}:${MOBILE.serverPort}`));
  await device.openLink(`t3code-dev://threads/${environment}/${threadId}`, { app: "com.t3tools.t3code.dev" });
  await device.alert("accept").catch(() => {});
  const composer = screen.getByRole("textbox", "Ask anything");
  await composer.fill("First tap delivery proof");
  await screen.swipe({ from: { x: 200, y: 220 }, to: { x: 200, y: 440 }, duration: 600 });
  await screen.getByRole("button", "Scroll to end").tap();
  await screen.getByRole("button", "Send", { exact: true }).tap();
  await app.screenshot("after-first-send-tap");
  await expect(composer).toHaveValue("");
});
