diff mrjunejune/test/latex_editor_test.js @ 245:3843bb6253ac

[tools] Debounce live LaTeX preview Co-authored-by: Copilot <[email protected]>
author MrJuneJune <me@mrjunejune.com>
date Mon, 03 Aug 2026 18:23:36 -0700
parents b8aa08503378
children 4f2b50bc78e7
line wrap: on
line diff
--- a/mrjunejune/test/latex_editor_test.js	Mon Aug 03 16:56:25 2026 -0700
+++ b/mrjunejune/test/latex_editor_test.js	Mon Aug 03 18:23:36 2026 -0700
@@ -236,6 +236,25 @@
       'document.pdf',
     );
 
+    let livePreviewRequests = 0;
+    const countLivePreviewRequest = request => {
+      if (request.url().endsWith('/api/latex/render')) livePreviewRequests++;
+    };
+    page.on('request', countLivePreviewRequest);
+    const livePreviewResponse = page.waitForResponse(response =>
+      response.url().endsWith('/api/latex/render') &&
+      response.status() === 200
+    );
+    await page.locator('#latexSource').fill(valid.replace('API.', 'API change one.'));
+    await page.waitForTimeout(100);
+    await page.locator('#latexSource').fill(valid.replace('API.', 'API change two.'));
+    await page.waitForTimeout(100);
+    await page.locator('#latexSource').fill(valid.replace('API.', 'API final change.'));
+    await livePreviewResponse;
+    await page.locator('#latexStatus[data-state="ready"]').waitFor();
+    page.off('request', countLivePreviewRequest);
+    assert.equal(livePreviewRequests, 1);
+
     await page.locator('#autoCompile').uncheck();
     await page.locator('#latexSource').fill(
       String.raw`\documentclass{article}\begin{document}\badcommand\end{document}`,