@@ -3,6 +3,8 @@ import test from "node:test";
33
44import { computeChannelUnreadMarker } from "../messages/lib/unreadMarker.ts" ;
55import {
6+ countUnreadAppBadgeObservedEvents ,
7+ countUnreadBadgeObservedEvents ,
68 countUnreadHighPriorityObservedEvents ,
79 countUnreadObservedEvents ,
810 observedUnreadEventReadAt ,
@@ -136,8 +138,22 @@ test("observedUnreadEventReadAt_nullChannelMarkerThreadMarkerCanClear", () => {
136138
137139// --- Fix 2b: sidebar badge evaluates all observed events, not a single aggregate frontier ---
138140
139- function observed ( id , createdAt , rootId = null , highPriority = false ) {
140- return { id, createdAt, rootId, highPriority } ;
141+ function observed (
142+ id ,
143+ createdAt ,
144+ rootId = null ,
145+ highPriority = false ,
146+ countsTowardBadge = true ,
147+ countsTowardAppBadge = countsTowardBadge ,
148+ ) {
149+ return {
150+ id,
151+ createdAt,
152+ rootId,
153+ highPriority,
154+ countsTowardBadge,
155+ countsTowardAppBadge,
156+ } ;
141157}
142158
143159function readAtFor ( channelMarker , threadMarkers ) {
@@ -219,6 +235,51 @@ test("countUnreadObservedEvents_topLevelUsesChannelMarker", () => {
219235 assert . equal ( countUnreadObservedEvents ( events , readAtFor ( 300 , new Map ( ) ) ) , 1 ) ;
220236} ) ;
221237
238+ test ( "countUnreadBadgeObservedEvents_skipsBoldOnlyGeneralChannelItems" , ( ) => {
239+ const events = new Map ( [
240+ [ "plain" , observed ( "plain" , 500 , null , false , false ) ] ,
241+ [ "thread" , observed ( "thread" , 600 , "root-1" ) ] ,
242+ ] ) ;
243+
244+ assert . equal ( countUnreadObservedEvents ( events , readAtFor ( 300 , new Map ( ) ) ) , 2 ) ;
245+ assert . equal (
246+ countUnreadBadgeObservedEvents ( events , readAtFor ( 300 , new Map ( ) ) ) ,
247+ 1 ,
248+ ) ;
249+ assert . equal (
250+ countUnreadAppBadgeObservedEvents ( events , readAtFor ( 300 , new Map ( ) ) ) ,
251+ 1 ,
252+ ) ;
253+ } ) ;
254+
255+ test ( "countUnreadObservedEvents_countsThreadRepliesForChannelUnread" , ( ) => {
256+ const events = new Map ( [
257+ [ "reply" , observed ( "reply" , 500 , "root-1" , false , true , false ) ] ,
258+ ] ) ;
259+
260+ assert . equal ( countUnreadObservedEvents ( events , readAtFor ( 300 , new Map ( ) ) ) , 1 ) ;
261+ assert . equal (
262+ countUnreadBadgeObservedEvents ( events , readAtFor ( 300 , new Map ( ) ) ) ,
263+ 1 ,
264+ ) ;
265+ assert . equal (
266+ countUnreadAppBadgeObservedEvents ( events , readAtFor ( 300 , new Map ( ) ) ) ,
267+ 0 ,
268+ ) ;
269+ } ) ;
270+
271+ test ( "highPriorityObservedEvents_countsMentionBadgeForGeneralMessage" , ( ) => {
272+ const events = new Map ( [
273+ [ "mention" , observed ( "mention" , 500 , null , true , true ) ] ,
274+ ] ) ;
275+ const getReadAt = readAtFor ( 300 , new Map ( ) ) ;
276+
277+ assert . equal ( countUnreadObservedEvents ( events , getReadAt ) , 1 ) ;
278+ assert . equal ( countUnreadBadgeObservedEvents ( events , getReadAt ) , 1 ) ;
279+ assert . equal ( countUnreadAppBadgeObservedEvents ( events , getReadAt ) , 1 ) ;
280+ assert . equal ( countUnreadHighPriorityObservedEvents ( events , getReadAt ) , 1 ) ;
281+ } ) ;
282+
222283test ( "recordObservedUnreadEvent_reportsOutOfOrderInsertForInvalidation" , ( ) => {
223284 const channelId = "chan" ;
224285 const observedByChannel = new Map ( ) ;
0 commit comments