/// <reference lib="dom" />
import { expect } from "e2e";
import { test, WEB } from "./t3.ts";

test("Saved notebook redraw retains an earlier leading combining mark", WEB, async ({t3, app, screen, browser}) => {
  const notebook = {nbformat:4, nbformat_minor:5, metadata:{language_info:{name:"python"}}, cells:[{id:"results", cell_type:"code", source:["print('saved redraw')"], metadata:{}, execution_count:1, outputs:[{output_type:"stream",name:"stdout",text:"a\r\u0301\ra done"}]}]};
  const project = await t3.project("demo", {"results.ipynb":JSON.stringify(notebook)});
  const thread = await t3.thread({project,title:"Review results",messages:['See :codex-file-citation{path="results.ipynb"}']});
  await browser.setViewport({width:1440,height:1000});
  await t3.open(thread);
  await screen.getByRole("button", /^Agent See/).tap();
  await screen.getByRole("link", /^results\.ipynb/).tap();
  await screen.getByText("Saved outputs only", {exact:false}).waitFor();
  await browser.locator('section[aria-label="Cell 1"] pre').waitFor();
  await screen.getByText("\'saved redraw\'", {exact:true}).waitFor();
  await app.screenshot("saved-notebook-leading-mark");
  const output = await browser.evaluate(() => document.querySelector('section[aria-label="Cell 1"] pre')?.textContent);
  expect(output).toBe("\u0301a done");
});
