@@ -17,6 +17,21 @@ async function doubleClickElement(element: Element) {
1717 await clickAt ( x + width / 2 , y + height / 2 , 2 ) ;
1818}
1919
20+ /**
21+ * Clicks the comment mark near its left edge. ProseMirror counts a click within
22+ * 500ms and 10px of the previous one in the editor as a double/triple click
23+ * (which skips `handleClick`, so no thread opens). The clicks on the comment
24+ * UI in between happen outside the editor and don't reset that count, so
25+ * clicking the centre right after double-clicking the word to select it is
26+ * flaky.
27+ */
28+ async function clickThreadMark ( ) {
29+ const { x, y, height } = getRect (
30+ await waitForSelector ( "span.bn-thread-mark" ) ,
31+ ) ;
32+ await clickAt ( x + 2 , y + height / 2 ) ;
33+ }
34+
2035/** Resolves once exactly `count` elements match `selector`. */
2136function expectSelectorCount ( selector : string , count : number ) {
2237 return vi . waitFor ( ( ) => {
@@ -90,7 +105,7 @@ describe("Check Comments functionality", () => {
90105
91106 await userEvent . keyboard ( "{Enter}" ) ;
92107 await expectSelectorCount ( ".bn-thread" , 0 ) ;
93- await userEvent . click ( await waitForSelector ( "span.bn-thread-mark" ) ) ;
108+ await clickThreadMark ( ) ;
94109 await expectSelectorCount ( ".bn-thread-comment" , 1 ) ;
95110 expect ( document . querySelector ( ".bn-thread-comment" ) ?. textContent ) . toContain (
96111 "second line" ,
@@ -131,7 +146,7 @@ describe("Check Comments functionality", () => {
131146 // Wait for comment composer to close.
132147 await expectSelectorCount ( ".bn-thread" , 0 ) ;
133148
134- await userEvent . click ( await waitForSelector ( "span.bn-thread-mark" ) ) ;
149+ await clickThreadMark ( ) ;
135150 await expectElement (
136151 await waitForSelector ( ".bn-thread-comment" ) ,
137152 ) . toBeVisible ( ) ;
0 commit comments