@@ -8,16 +8,12 @@ import {
88 hasMultiplePresenceIdentities ,
99 hasSessionPresenceViewers ,
1010 projectOnlinePresenceViewers ,
11+ projectPresencePayload ,
1112 type PresenceViewer ,
1213} from "../lib/presence-users.ts" ;
1314import { renderChatAuthorAvatar } from "../pages/chat/components/chat-author-avatar.ts" ;
1415import "./viewer-facepile.ts" ;
1516
16- type ViewerAvatarElement = HTMLElement & {
17- user : PresenceViewer | null ;
18- updateComplete : Promise < boolean > ;
19- } ;
20-
2117afterEach ( ( ) => {
2218 document . body . replaceChildren ( ) ;
2319 setAvatarGatewayOrigin ( null ) ;
@@ -31,7 +27,7 @@ it("uses the same user initials and identity hue in the roster and attributed ch
31273228 watchedSessions : [ ] ,
3329 } ;
34- const viewerAvatar = document . createElement ( "openclaw-viewer-avatar" ) as ViewerAvatarElement ;
30+ const viewerAvatar = document . createElement ( "openclaw-viewer-avatar" ) ;
3531 viewerAvatar . user = user ;
3632 document . body . append ( viewerAvatar ) ;
3733
@@ -60,7 +56,7 @@ it("uses the same user initials and identity hue in the roster and attributed ch
6056} ) ;
6157
6258it ( "uses the shared resolver and rejects cross-origin presence avatar metadata" , async ( ) => {
63- const avatar = document . createElement ( "openclaw-viewer-avatar" ) as ViewerAvatarElement ;
59+ const avatar = document . createElement ( "openclaw-viewer-avatar" ) ;
6460 avatar . user = {
6561 id : "profile-mallory" ,
6662 name : "Mallory" ,
@@ -77,7 +73,7 @@ it("uses the shared resolver and rejects cross-origin presence avatar metadata",
7773} ) ;
7874
7975it ( "renders trusted presence avatar routes directly" , async ( ) => {
80- const avatar = document . createElement ( "openclaw-viewer-avatar" ) as ViewerAvatarElement ;
76+ const avatar = document . createElement ( "openclaw-viewer-avatar" ) ;
8177 avatar . user = {
8278 id : "profile-ada" ,
8379 name : "Ada Lovelace" ,
@@ -185,7 +181,7 @@ it("shares an authenticated avatar blob between the same user in the roster and
185181 watchedSessions : [ ] ,
186182 } ;
187183 const avatars = Array . from ( { length : 2 } , ( ) => {
188- const avatar = document . createElement ( "openclaw-viewer-avatar" ) as ViewerAvatarElement ;
184+ const avatar = document . createElement ( "openclaw-viewer-avatar" ) ;
189185 avatar . user = user ;
190186 document . body . append ( avatar ) ;
191187 return avatar ;
@@ -210,12 +206,25 @@ it("shares an authenticated avatar blob between the same user in the roster and
210206 }
211207} ) ;
212208
213- type ViewerFacepileElement = HTMLElementTagNameMap [ "openclaw-viewer-facepile" ] ;
209+ it . each ( [ "staticParticipants" , "staticUsers" ] as const ) (
210+ "renders an empty %s list without invalidating cached live presence" ,
211+ async ( source ) => {
212+ const payload = { presence : [ { user : { id : "live-viewer" } } ] } ;
213+ const projection = projectPresencePayload ( payload ) ;
214+ const facepile = document . createElement ( "openclaw-viewer-facepile" ) ;
215+ facepile [ source ] = [ ] ;
216+ document . body . append ( facepile ) ;
217+ await facepile . updateComplete ;
218+
219+ expect ( facepile . querySelector ( ".viewer-facepile" ) ) . toBeNull ( ) ;
220+ expect ( projectPresencePayload ( payload ) ) . toBe ( projection ) ;
221+ } ,
222+ ) ;
214223
215224it . each ( [ "first" , "second" ] ) (
216225 "merges device presence into one non-interactive face watching %s" ,
217226 async ( session ) => {
218- const facepile = document . createElement ( "openclaw-viewer-facepile" ) as ViewerFacepileElement ;
227+ const facepile = document . createElement ( "openclaw-viewer-facepile" ) ;
219228 facepile . sessionKey = `agent:main:${ session } ` ;
220229 facepile . presencePayload = {
221230 presence : [
@@ -243,8 +252,7 @@ it.each(["first", "second"])(
243252) ;
244253
245254it ( "renders ordered static participant actors without presence filtering" , async ( ) => {
246- // SAFETY: the registered custom element exposes the tested reactive properties.
247- const facepile = document . createElement ( "openclaw-viewer-facepile" ) as ViewerFacepileElement ;
255+ const facepile = document . createElement ( "openclaw-viewer-facepile" ) ;
248256 facepile . maxVisible = 2 ;
249257 facepile . staticParticipants = [
250258 { identity : { type : "profile" , id : "profile-ada" } , label : "Ada" } ,
@@ -265,7 +273,7 @@ it("renders ordered static participant actors without presence filtering", async
265273} ) ;
266274
267275it ( "excludes displayed owners and participants before choosing visible avatars and overflow" , async ( ) => {
268- const facepile = document . createElement ( "openclaw-viewer-facepile" ) as ViewerFacepileElement ;
276+ const facepile = document . createElement ( "openclaw-viewer-facepile" ) ;
269277 facepile . sessionKey = "agent:main:active" ;
270278 facepile . excludeIdentities = [
271279 { type : "profile" , id : "owner" } ,
@@ -352,7 +360,7 @@ it.each([
352360 ] ,
353361 } ,
354362] ) ( "excludes authenticated self from session facepiles when $name" , async ( fixture ) => {
355- const facepile = document . createElement ( "openclaw-viewer-facepile" ) as ViewerFacepileElement ;
363+ const facepile = document . createElement ( "openclaw-viewer-facepile" ) ;
356364 facepile . selfUser = { id : "self" } ;
357365 facepile . selfInstanceId = fixture . selfInstanceId ;
358366 facepile . sessionKey = "agent:main:active" ;
@@ -395,11 +403,7 @@ it("links faces only when the host opts in, so nested facepiles stay plain", asy
395403 { identity : { type : "profile" , id : "profile-mira" } , label : "Mira" } ,
396404 ] ;
397405 const mount = async ( personActivity ?: { basePath : string ; navigate : ( id : string ) => void } ) => {
398- const facepile = document . createElement ( "openclaw-viewer-facepile" ) as HTMLElement & {
399- staticParticipants : readonly SessionParticipant [ ] ;
400- personActivity ?: { basePath : string ; navigate : ( id : string ) => void } ;
401- updateComplete : Promise < boolean > ;
402- } ;
406+ const facepile = document . createElement ( "openclaw-viewer-facepile" ) ;
403407 facepile . staticParticipants = users ;
404408 if ( personActivity ) {
405409 facepile . personActivity = personActivity ;
0 commit comments