Skip to content

Commit 3e25ac3

Browse files
committed
chore: fix tests
1 parent 3e8934a commit 3e25ac3

2 files changed

Lines changed: 22 additions & 12 deletions

File tree

tests/behavior/helpers/comments.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,18 +69,21 @@ export async function activateCommentDialog(
6969
await superdoc.waitForStable();
7070
}
7171

72+
const activeDialog = superdoc.page.locator('.comment-placeholder .comments-dialog.is-active').last();
7273
const dialog = activeCommentDialog(superdoc.page);
73-
const isActive = await dialog.isVisible({ timeout: 2_000 }).catch(() => false);
74+
const hasActiveDialog = (await activeDialog.count()) > 0;
7475

75-
if (!isActive) {
76+
if (!hasActiveDialog) {
7677
// Fallback: click the floating dialog directly to trigger setFocus → is-active
7778
const floatingDialog = superdoc.page.locator('.comment-placeholder .comments-dialog').last();
7879
await expect(floatingDialog).toBeVisible({ timeout: timeoutMs });
79-
await floatingDialog.click();
80+
// Click near the top-left to avoid accidentally hitting interactive controls
81+
// such as the "N more replies" collapse/expand pill in the middle of the card.
82+
await floatingDialog.click({ position: { x: 12, y: 12 } });
8083
await superdoc.waitForStable();
8184

82-
const isActiveNow = await dialog.isVisible({ timeout: 2_000 }).catch(() => false);
83-
if (!isActiveNow) {
85+
const hasActiveDialogNow = (await activeDialog.count()) > 0;
86+
if (!hasActiveDialogNow) {
8487
// Last resort: set activeComment directly on the Pinia store. This is
8588
// needed when click events don't propagate to activate the dialog
8689
// (Firefox/WebKit) or replyToComment calls set it to a child ID.
@@ -99,6 +102,11 @@ export async function activateCommentDialog(
99102
}
100103
}
101104

105+
if ((await activeDialog.count()) > 0) {
106+
await expect(activeDialog).toBeVisible({ timeout: timeoutMs });
107+
return activeDialog;
108+
}
109+
102110
await expect(dialog).toBeVisible({ timeout: timeoutMs });
103111
return dialog;
104112
}

tests/behavior/tests/comments/comment-thread-collapse.spec.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { test, expect } from '../../fixtures/superdoc.js';
2-
import { addCommentViaUIWithId, activateCommentDialog } from '../../helpers/comments.js';
2+
import { addCommentViaUIWithId } from '../../helpers/comments.js';
33
import { assertDocumentApiReady, replyToComment } from '../../helpers/document-api.js';
44

55
test.use({ config: { toolbar: 'full', comments: 'on' } });
@@ -42,13 +42,15 @@ test('thread with 2+ replies collapses and expands on click', async ({ superdoc
4242
});
4343
await superdoc.waitForStable();
4444

45-
// Wait for dialog to lose active state before re-activating — Firefox needs
46-
// this gap so the component fully unmounts its expanded state.
47-
const activeDialog = superdoc.page.locator('.comment-placeholder .comments-dialog.is-active');
48-
await expect(activeDialog).toHaveCount(0, { timeout: 5_000 });
45+
// Activate parent thread deterministically (avoid click-path races in Firefox).
46+
await superdoc.page.evaluate((id: string) => {
47+
const sd = (window as any).superdoc;
48+
sd.commentsStore.$patch({ activeComment: id });
49+
}, commentId);
50+
await superdoc.waitForStable();
4951

50-
// Activate the comment dialog
51-
const dialog = await activateCommentDialog(superdoc, 'collapse');
52+
const dialog = superdoc.page.locator(`.comment-placeholder[data-comment-id="${commentId}"] .comments-dialog`).first();
53+
await expect(dialog).toBeVisible({ timeout: 10_000 });
5254

5355
// The collapsed-replies pill should be visible with "more replies" text
5456
const collapsedPill = dialog.locator('.collapsed-replies');

0 commit comments

Comments
 (0)