Skip to content

Commit de197c7

Browse files
committed
fix(test): stabilize scrollToComment WebKit behavior test
After scrolling to top, the DomPainter may re-render pages and temporarily remove comment highlight elements from the DOM. On WebKit this window is long enough to cause scrollToComment to return false. - Use behavior:'auto' (instant scroll) instead of smooth to avoid timing issues - Add waitForStable() after scrollToComment to wait for the DOM rebuild triggered by setActiveComment - Use assertCommentHighlightExists (poll-based) instead of a single toBeVisible check, since the re-render creates new elements - Increase poll timeout to 15s for the scrollToComment call
1 parent d06ff4e commit de197c7

1 file changed

Lines changed: 15 additions & 8 deletions

File tree

tests/behavior/tests/comments/scroll-to-comment.spec.ts

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,24 @@ test('scrollToComment scrolls to the comment and activates it', async ({ superdo
2727
});
2828
await superdoc.waitForStable();
2929

30-
// Call scrollToComment via the public API.
31-
// WebKit can lag on DOM attribute propagation, so poll until it succeeds.
30+
// Poll scrollToComment until it succeeds. After scrolling to top the
31+
// DomPainter may re-render pages, temporarily removing comment highlight
32+
// elements from the DOM. Use behavior:'auto' (instant) to avoid
33+
// smooth-scroll timing issues on WebKit.
3234
await expect
33-
.poll(async () => superdoc.page.evaluate((id) => (window as any).superdoc.scrollToComment(id), commentId), {
34-
timeout: 10_000,
35-
})
35+
.poll(
36+
async () =>
37+
superdoc.page.evaluate((id) => (window as any).superdoc.scrollToComment(id, { behavior: 'auto' }), commentId),
38+
{ timeout: 15_000 },
39+
)
3640
.toBe(true);
3741

38-
// Verify the comment highlight is now visible in the viewport
39-
const highlight = superdoc.page.locator('.superdoc-comment-highlight').filter({ hasText: 'target text' });
40-
await expect(highlight.first()).toBeVisible({ timeout: 5_000 });
42+
// scrollToComment calls setActiveComment which triggers a full DomPainter
43+
// re-render (removes and recreates all page elements). Wait for it to settle.
44+
await superdoc.waitForStable();
45+
46+
// Poll for the highlight since the re-render creates new DOM elements.
47+
await superdoc.assertCommentHighlightExists({ text: 'target text', timeoutMs: 10_000 });
4148
});
4249

4350
test('scrollToComment returns false for a nonexistent comment', async ({ superdoc }) => {

0 commit comments

Comments
 (0)