@@ -4,6 +4,12 @@ import { TEST_IDENTITIES, installMockBridge } from "../helpers/bridge";
44
55const SHOTS = "test-results/thread-unread" ;
66
7+ type MockMessageEvent = {
8+ id : string ;
9+ created_at : number ;
10+ pubkey : string ;
11+ } ;
12+
713async function waitForMockLiveSubscription (
814 page : import ( "@playwright/test" ) . Page ,
915 channelName : string ,
@@ -26,7 +32,7 @@ async function waitForMockLiveSubscription(
2632 . toBe ( true ) ;
2733}
2834
29- function emitMockMessage (
35+ async function emitMockMessage (
3036 page : import ( "@playwright/test" ) . Page ,
3137 channelName : string ,
3238 content : string ,
@@ -36,8 +42,8 @@ function emitMockMessage(
3642 createdAt ?: number ;
3743 mentionPubkeys ?: string [ ] ;
3844 } ,
39- ) {
40- return page . evaluate (
45+ ) : Promise < MockMessageEvent > {
46+ const event = await page . evaluate (
4147 ( { ch, msg, parentEventId, pubkey, ts, mentionPubkeys } ) => {
4248 return (
4349 window as Window & {
@@ -68,6 +74,10 @@ function emitMockMessage(
6874 mentionPubkeys : options ?. mentionPubkeys ,
6975 } ,
7076 ) ;
77+ if ( ! event ) {
78+ throw new Error ( "Mock message emitter is not installed" ) ;
79+ }
80+ return event ;
7181}
7282
7383// Unread thread replies must be dated strictly after the read frontier captured
@@ -231,7 +241,7 @@ test.describe("thread unread indicator screenshots", () => {
231241 const base = unreadTimestamp ( ) ;
232242 for ( let i = 0 ; i < 2 ; i ++ ) {
233243 await emitMockMessage ( page , "general" , `Bob chimes in ${ i + 1 } ` , {
234- parentEventId : rootEvent ! . id ,
244+ parentEventId : rootEvent . id ,
235245 pubkey : TEST_IDENTITIES . bob . pubkey ,
236246 createdAt : base + i ,
237247 } ) ;
@@ -278,19 +288,19 @@ test.describe("thread unread indicator screenshots", () => {
278288 "general" ,
279289 "Replying one level down" ,
280290 {
281- parentEventId : r1 ! . id ,
291+ parentEventId : r1 . id ,
282292 pubkey : TEST_IDENTITIES . bob . pubkey ,
283293 createdAt : past + 1 ,
284294 } ,
285295 ) ;
286296 // A sibling at r1's level so the tree reads as a branching discussion.
287297 await emitMockMessage ( page , "general" , "Separate angle on the same point" , {
288- parentEventId : r1 ! . id ,
298+ parentEventId : r1 . id ,
289299 pubkey : TEST_IDENTITIES . charlie . pubkey ,
290300 createdAt : past + 2 ,
291301 } ) ;
292302 const r3 = await emitMockMessage ( page , "general" , "Going deeper still" , {
293- parentEventId : r2 ! . id ,
303+ parentEventId : r2 . id ,
294304 pubkey : TEST_IDENTITIES . alice . pubkey ,
295305 createdAt : past + 3 ,
296306 } ) ;
@@ -302,8 +312,8 @@ test.describe("thread unread indicator screenshots", () => {
302312 await expect ( summary ) . toBeVisible ( ) ;
303313 await summary . click ( ) ;
304314 await expect ( page . getByTestId ( "message-thread-panel" ) ) . toBeVisible ( ) ;
305- await expandReply ( page , r1 ! . id ) ;
306- await expandReply ( page , r2 ! . id ) ;
315+ await expandReply ( page , r1 . id ) ;
316+ await expandReply ( page , r2 . id ) ;
307317 await page . getByTestId ( "message-thread-close" ) . click ( ) ;
308318 await expect ( page . getByTestId ( "message-thread-panel" ) ) . not . toBeVisible ( ) ;
309319
@@ -314,12 +324,12 @@ test.describe("thread unread indicator screenshots", () => {
314324
315325 const base = unreadTimestamp ( ) ;
316326 const r4 = await emitMockMessage ( page , "general" , "New nested follow-up" , {
317- parentEventId : r3 ! . id ,
327+ parentEventId : r3 . id ,
318328 pubkey : TEST_IDENTITIES . bob . pubkey ,
319329 createdAt : base ,
320330 } ) ;
321331 await emitMockMessage ( page , "general" , "Deepest unread reply" , {
322- parentEventId : r4 ! . id ,
332+ parentEventId : r4 . id ,
323333 pubkey : TEST_IDENTITIES . alice . pubkey ,
324334 createdAt : base + 1 ,
325335 } ) ;
@@ -331,10 +341,10 @@ test.describe("thread unread indicator screenshots", () => {
331341 await expect ( page . getByTestId ( "chat-title" ) ) . toHaveText ( "general" ) ;
332342 await page . getByTestId ( "message-thread-summary" ) . first ( ) . click ( ) ;
333343 await expect ( page . getByTestId ( "message-thread-panel" ) ) . toBeVisible ( ) ;
334- await expandReply ( page , r1 ! . id ) ;
335- await expandReply ( page , r2 ! . id ) ;
336- await expandReply ( page , r3 ! . id ) ;
337- await expandReply ( page , r4 ! . id ) ;
344+ await expandReply ( page , r1 . id ) ;
345+ await expandReply ( page , r2 . id ) ;
346+ await expandReply ( page , r3 . id ) ;
347+ await expandReply ( page , r4 . id ) ;
338348
339349 // Fully expanded: r1, r2, sibling, r3, r4, r5 — six rendered replies.
340350 const replies = page
@@ -371,7 +381,7 @@ test.describe("thread unread indicator screenshots", () => {
371381 createdAt : past ,
372382 } ) ;
373383 const c = await emitMockMessage ( page , "general" , "Child of branch parent" , {
374- parentEventId : p ! . id ,
384+ parentEventId : p . id ,
375385 pubkey : TEST_IDENTITIES . bob . pubkey ,
376386 createdAt : past + 1 ,
377387 } ) ;
@@ -402,13 +412,13 @@ test.describe("thread unread indicator screenshots", () => {
402412 "general" ,
403413 "Unread under the branch" ,
404414 {
405- parentEventId : c ! . id ,
415+ parentEventId : c . id ,
406416 pubkey : TEST_IDENTITIES . alice . pubkey ,
407417 createdAt : base ,
408418 } ,
409419 ) ;
410420 await emitMockMessage ( page , "general" , "Another unread under the branch" , {
411- parentEventId : c2 ! . id ,
421+ parentEventId : c2 . id ,
412422 pubkey : TEST_IDENTITIES . bob . pubkey ,
413423 createdAt : base + 1 ,
414424 } ) ;
@@ -444,7 +454,7 @@ test.describe("thread unread indicator screenshots", () => {
444454
445455 // Expanding p marks its whole subtree read; the descendant-inclusive gate
446456 // (Phase 2.5) drops the badge from p and every revealed row beneath it.
447- await expandReply ( page , p ! . id ) ;
457+ await expandReply ( page , p . id ) ;
448458 await expect ( inPanelBadge ) . toHaveCount ( 0 ) ;
449459
450460 await page . screenshot ( {
@@ -469,7 +479,7 @@ test.describe("thread unread indicator screenshots", () => {
469479 createdAt : past ,
470480 } ) ;
471481 const c = await emitMockMessage ( page , "general" , "Child of branch parent" , {
472- parentEventId : p ! . id ,
482+ parentEventId : p . id ,
473483 pubkey : TEST_IDENTITIES . bob . pubkey ,
474484 createdAt : past + 1 ,
475485 } ) ;
@@ -486,7 +496,7 @@ test.describe("thread unread indicator screenshots", () => {
486496
487497 const base = unreadTimestamp ( ) ;
488498 await emitMockMessage ( page , "general" , "First unread under branch" , {
489- parentEventId : c ! . id ,
499+ parentEventId : c . id ,
490500 pubkey : TEST_IDENTITIES . alice . pubkey ,
491501 createdAt : base ,
492502 } ) ;
@@ -508,7 +518,7 @@ test.describe("thread unread indicator screenshots", () => {
508518 // the badge must bump to 2 on the same tick — readStateVersion-driven
509519 // recompute is what makes this fire live rather than on a later re-render.
510520 await emitMockMessage ( page , "general" , "Second unread under branch" , {
511- parentEventId : c ! . id ,
521+ parentEventId : c . id ,
512522 pubkey : TEST_IDENTITIES . bob . pubkey ,
513523 createdAt : base + 1 ,
514524 } ) ;
@@ -538,7 +548,7 @@ test.describe("thread unread indicator screenshots", () => {
538548 createdAt : past ,
539549 } ) ;
540550 const oldChild = await emitMockMessage ( page , "general" , "Old child" , {
541- parentEventId : branchOld ! . id ,
551+ parentEventId : branchOld . id ,
542552 pubkey : TEST_IDENTITIES . bob . pubkey ,
543553 createdAt : past + 1 ,
544554 } ) ;
@@ -548,7 +558,7 @@ test.describe("thread unread indicator screenshots", () => {
548558 createdAt : past + 2 ,
549559 } ) ;
550560 const newChild = await emitMockMessage ( page , "general" , "New child" , {
551- parentEventId : branchNew ! . id ,
561+ parentEventId : branchNew . id ,
552562 pubkey : TEST_IDENTITIES . alice . pubkey ,
553563 createdAt : past + 3 ,
554564 } ) ;
@@ -570,12 +580,12 @@ test.describe("thread unread indicator screenshots", () => {
570580 // sibling's badge survives until that branch is expanded too.
571581 const base = unreadTimestamp ( ) ;
572582 await emitMockMessage ( page , "general" , "Unread in older branch" , {
573- parentEventId : oldChild ! . id ,
583+ parentEventId : oldChild . id ,
574584 pubkey : TEST_IDENTITIES . alice . pubkey ,
575585 createdAt : base ,
576586 } ) ;
577587 await emitMockMessage ( page , "general" , "Unread in newer branch" , {
578- parentEventId : newChild ! . id ,
588+ parentEventId : newChild . id ,
579589 pubkey : TEST_IDENTITIES . bob . pubkey ,
580590 createdAt : base + 30 ,
581591 } ) ;
@@ -599,15 +609,15 @@ test.describe("thread unread indicator screenshots", () => {
599609 // `expandedSubtreeReplyIds` gate against the frozen open-time frontier.
600610 // The older sibling's badge SURVIVES — the design does not sweep across
601611 // branches off a live marker.
602- await expandReply ( page , branchNew ! . id ) ;
612+ await expandReply ( page , branchNew . id ) ;
603613 await expect ( inPanelBadges ) . toHaveCount ( 1 ) ;
604614
605615 await page . screenshot ( {
606616 path : `${ SHOTS } /09-expand-clears-own-branch-sibling-survives.png` ,
607617 } ) ;
608618
609619 // Expanding the older branch clears the last remaining badge.
610- await expandReply ( page , branchOld ! . id ) ;
620+ await expandReply ( page , branchOld . id ) ;
611621 await expect ( inPanelBadges ) . toHaveCount ( 0 ) ;
612622
613623 await page . screenshot ( {
0 commit comments