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

test("Saved notebook redraws preserve terminal columns", WEB, async ({ t3, app, screen }) => {
  const project = await t3.project("notebook-demo", {
    "progress.ipynb": JSON.stringify({
      nbformat: 4, nbformat_minor: 5,
      metadata: { kernelspec: { display_name: "Python 3", language: "python", name: "python3" }, language_info: { name: "python" } },
      cells: [{ cell_type: "code", id: "progress", metadata: {}, execution_count: 1,
        source: ["print('12345\\r进度', end='')"],
        outputs: [{ output_type: "stream", name: "stdout", text: "12345\r进度" }] }],
    }),
  });
  const thread = await t3.thread({ project, title: "Notebook progress", messages: ["Start"] });
  await t3.open(thread);
  await screen.getByRole("button", "Toggle right panel").tap();
  await screen.getByRole("button", "Files F").tap();
  await screen.getByRole("treeitem", "progress.ipynb").tap();
  await screen.getByText("Saved outputs only. Code is never executed.").waitFor({ timeout: 60_000 });
  await screen.getByText("Loading code...").waitFor({ state: "hidden", timeout: 60_000 });
  await app.screenshot("saved-notebook-redraw");
  await expect(screen.getByText("进度5", { exact: true })).toBeVisible();
});
