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

test("Blank linked-thread IDs show Page not found", WEB, async ({ t3, app, screen }) => {
  const project = await t3.project("server");
  const thread = await t3.thread({ project, title: "Example thread", messages: ["Hello"] });
  await t3.open(thread);
  await screen.getByRole("textbox", "Message Example thread").waitFor({ timeout: 60_000 });
  await app.screenshot("initial-thread-loaded");
  const failures: unknown[] = [];
  for (const [label, path] of [
    ["blank-via-environment", "/linked/%20/e/t"],
    ["blank-linked-environment", "/linked/v/%20/t"],
    ["blank-linked-thread", "/linked/v/e/%20"],
  ]) {
    await t3.open(path);
    try {
      await expect(screen.getByText("Page not found", { exact: true })).toBeVisible();
      await expect(screen.getByRole("link", "Go home")).toBeVisible();
    } catch (error) {
      failures.push(error);
    } finally {
      await app.screenshot(label);
    }
  }
  await t3.open("/linked/v/e/t");
  await screen.getByText("Connect to interact", { exact: false }).waitFor();
  await app.screenshot("nonblank-control");
  if (failures.length) throw failures[0];
});
