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

test("Resume sends a usable continuation to an older server", WEB, async ({ t3, app, screen }) => {
  await t3.project("resume-demo");
  await t3.open();
  const composer = screen.getByRole("textbox");
  await composer.fill("Write numbers 1-500 with a word each");
  await composer.press("Enter");
  const stop = screen.getByRole("button", "Stop generation");
  await screen.getByText("The project has a single math module", { exact: false }).waitFor();
  await app.screenshot("streaming-before-stop");
  await stop.tap();
  await screen.getByRole("button", "Resume thread").waitFor();
  await app.screenshot("interrupted-empty-composer");
  // The button ignores clicks for 500 ms after Stop lands.
  await new Promise((resolve) => setTimeout(resolve, 650));
  await screen.getByRole("button", "Resume thread").tap();
  await screen.getByText("The project has a single math module", { exact: false }).nth(1).waitFor();
  await stop.tap();
  await screen.getByRole("button", "Resume thread").waitFor();
  await app.screenshot("resumed-older-server");
  await expect(screen.getByText("Continue where you left off.", { exact: true })).toBeVisible();
  await app.screenshot("continuation-visible");
});
