Skip to content

Commit b2b2c34

Browse files
cdervclaude
andcommitted
Add test verifying search highlight listeners register after delay
Complements the persistence test by confirming that quarto-hrChanged does clear marks after the 1000ms registration delay elapses. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 16361d0 commit b2b2c34

1 file changed

Lines changed: 38 additions & 0 deletions

File tree

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { test, expect } from "@playwright/test";
2+
3+
test('Search highlights persist after page load', async ({ page }) => {
4+
await page.goto('./html/search-highlight/_site/index.html?q=special');
5+
const marks = page.locator('mark');
6+
7+
// Marks should exist after page load
8+
await expect(marks.first()).toBeVisible({ timeout: 5000 });
9+
10+
// Simulate the layout-triggered quarto-hrChanged event that clears marks
11+
// prematurely without the fix (#14047). With the fix, the listener is
12+
// registered after a delay, so early events like this are ignored.
13+
await page.evaluate(() => {
14+
window.dispatchEvent(new CustomEvent('quarto-hrChanged'));
15+
});
16+
17+
// Marks should still be visible after the simulated layout event
18+
await expect(marks.first()).toBeVisible();
19+
await expect(marks.first()).toContainText(/special/i);
20+
});
21+
22+
test('Search highlights are cleared by scroll after delay', async ({ page }) => {
23+
await page.goto('./html/search-highlight/_site/index.html?q=special');
24+
const marks = page.locator('mark');
25+
26+
// Marks should exist after page load
27+
await expect(marks.first()).toBeVisible({ timeout: 5000 });
28+
29+
// Wait for the delayed listener registration (1000ms in quarto-search.js)
30+
await page.waitForTimeout(1500);
31+
32+
// Now quarto-hrChanged should clear marks (listener is registered)
33+
await page.evaluate(() => {
34+
window.dispatchEvent(new CustomEvent('quarto-hrChanged'));
35+
});
36+
37+
await expect(marks).toHaveCount(0);
38+
});

0 commit comments

Comments
 (0)