|
| 1 | +import { injectHtmlRenderBootstrap } from "@t3tools/shared/htmlRender"; |
| 2 | +import { HtmlRenderDocument } from "../files/BrowserDocumentFrame"; |
1 | 3 | import { flushSync } from "react-dom"; |
2 | 4 | import { AudioPreview } from "../files/AudioPreview"; |
3 | 5 | import { cdp, page } from "vite-plus/test/browser"; |
@@ -217,6 +219,66 @@ const TASK_ID = ScheduledTaskId.make("task-1"); |
217 | 219 | const AUTOMATION_PROMPT = "Triage the inbox\n\nLabel every new issue and close duplicates."; |
218 | 220 |
|
219 | 221 | describe("MessagesTimeline work rows", () => { |
| 222 | + it("keeps a tall HTML preview in place when its last accordion opens at the bottom", async () => { |
| 223 | + const props = baseProps(); |
| 224 | + const html = injectHtmlRenderBootstrap(`<div style="height:1400px">Earlier preview content</div> |
| 225 | + <details><summary>More rows</summary><div style="height:900px">More rows</div></details> |
| 226 | + <script>addEventListener('message', e => { if(e.data === 'toggle') document.querySelector('details').open = !document.querySelector('details').open; });</script>`); |
| 227 | + const src = URL.createObjectURL(new Blob([html], { type: "text/html" })); |
| 228 | + using _url = { [Symbol.dispose]: () => URL.revokeObjectURL(src) }; |
| 229 | + function Preview() { |
| 230 | + const [height, setHeight] = useState(1437); |
| 231 | + return ( |
| 232 | + <div style={{ height }}> |
| 233 | + <HtmlRenderDocument |
| 234 | + src={src} |
| 235 | + title="Tall preview" |
| 236 | + className="size-full" |
| 237 | + onContentHeight={setHeight} |
| 238 | + /> |
| 239 | + </div> |
| 240 | + ); |
| 241 | + } |
| 242 | + const container = document.createElement("div"); |
| 243 | + container.style.cssText = "height:600px;width:900px;display:flex;flex-direction:column"; |
| 244 | + await using screen = await render( |
| 245 | + <MessagesTimeline |
| 246 | + {...props} |
| 247 | + renderHtmlRender={() => <Preview />} |
| 248 | + timelineEntries={[ |
| 249 | + { |
| 250 | + id: "preview", |
| 251 | + kind: "html-render", |
| 252 | + createdAt: CREATED_AT, |
| 253 | + runId: RunId.make("preview-run"), |
| 254 | + htmlRender: { attachmentId: "preview", title: "Tall preview", height: 1450 }, |
| 255 | + }, |
| 256 | + message("Done", { role: "assistant" }, "preview-done"), |
| 257 | + ]} |
| 258 | + />, |
| 259 | + { container }, |
| 260 | + ); |
| 261 | + const viewport = props.listRef.current!.getScrollableNode()!; |
| 262 | + const frame = screen.getByTitle("Tall preview").element() as HTMLIFrameElement; |
| 263 | + await vi.waitFor(() => { |
| 264 | + expect(frame.clientHeight).toBe(1437); |
| 265 | + expect(viewport.scrollTop).toBeGreaterThan(0); |
| 266 | + expect(viewport.scrollHeight - viewport.clientHeight - viewport.scrollTop).toBeLessThan(2); |
| 267 | + }); |
| 268 | + const top = frame.getBoundingClientRect().top; |
| 269 | + frame.focus(); |
| 270 | + frame.contentWindow!.postMessage("toggle", "*"); |
| 271 | + await vi.waitFor(() => { |
| 272 | + expect(frame.clientHeight).toBe(2337); |
| 273 | + expect(frame.getBoundingClientRect().top).toBeCloseTo(top, 0); |
| 274 | + }); |
| 275 | + frame.contentWindow!.postMessage("toggle", "*"); |
| 276 | + await vi.waitFor(() => { |
| 277 | + expect(frame.clientHeight).toBe(1437); |
| 278 | + expect(frame.getBoundingClientRect().top).toBeCloseTo(top, 0); |
| 279 | + }); |
| 280 | + }); |
| 281 | + |
220 | 282 | it("keeps the worked-for heading in place when expanded at the bottom", async () => { |
221 | 283 | const props = baseProps(); |
222 | 284 | const runId = RunId.make("completed-run"); |
|
0 commit comments