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

test("Returning to a scrolled-up thread shows Scroll to end", WEB, async ({ t3, app, screen, browser }) => {
  const project = await t3.project("scroll-demo");
  const thread = await t3.thread({ project, title: "go", messages: ["Showcase one", "Showcase two"], model: "showcase" });
  await t3.open(thread);
  await screen.getByRole("textbox").click();
  await browser.keyboard.press("PageDown");
  await browser.keyboard.press("PageUp");
  await screen.getByRole("button", "Scroll to end", { exact: true }).waitFor();
  await app.screenshot("scrolled-up-before-leaving");
  await screen.getByRole("button", "Pull requests", { exact: true }).click();
  await screen.getByRole("button", "Back", { exact: true }).waitFor();
  await screen.getByRole("textbox").waitFor({ state: "hidden" });
  await browser.locator(`[data-sidebar-row$=":${thread.threadId}"]`).click();
  await screen.getByRole("textbox").waitFor();
  await app.screenshot("returned-scrolled-up-thread");
  await expect(screen.getByRole("button", "Scroll to end", { exact: true })).toBeVisible();
  await screen.getByRole("button", "Scroll to end", { exact: true }).click();
  await expect(screen.getByRole("button", "Scroll to end", { exact: true })).toBeHidden();
  await app.screenshot("reached-end");
});
