@@ -163,15 +163,47 @@ describe('processPresence', () => {
163163 expect ( result . values ) . toStrictEqual ( { } ) ;
164164 } ) ;
165165
166- test ( 'should apply higher priority over external and save external as previousState ' , ( ) => {
166+ test ( 'should apply manual over external without stashing the displaced claim ' , ( ) => {
167167 const result = processPresence (
168168 user ( { statusSource : 'external' , statusDefault : UserStatus . BUSY , statusText : 'In a meeting' } ) ,
169169 [ session ( ) ] ,
170170 { type : 'setActive' , newState : { statusDefault : UserStatus . BUSY , statusText : 'Focusing' , statusSource : 'manual' } } ,
171171 ) ;
172172 expect ( result . values . statusSource ) . toBe ( 'manual' ) ;
173173 expect ( result . values . statusText ) . toBe ( 'Focusing' ) ;
174- expect ( result . values . previousState ) . toMatchObject ( { statusSource : 'external' , statusText : 'In a meeting' } ) ;
174+ expect ( result . values . previousState ) . toBeUndefined ( ) ;
175+ expect ( result . clear ) . toContain ( 'previousState' ) ;
176+ } ) ;
177+
178+ test ( 'should drop a queued previousState when a manual claim wins' , ( ) => {
179+ const result = processPresence (
180+ user ( {
181+ statusSource : 'external' ,
182+ statusDefault : UserStatus . BUSY ,
183+ statusText : 'In a meeting' ,
184+ previousState : { statusDefault : UserStatus . AWAY , statusText : 'Lunch' , statusSource : 'manual' } ,
185+ } ) ,
186+ [ session ( ) ] ,
187+ { type : 'setActive' , newState : { statusDefault : UserStatus . BUSY , statusText : 'Focusing' , statusSource : 'manual' } } ,
188+ ) ;
189+ expect ( result . values . statusSource ) . toBe ( 'manual' ) ;
190+ expect ( result . values . previousState ) . toBeUndefined ( ) ;
191+ expect ( result . clear ) . toContain ( 'previousState' ) ;
192+ } ) ;
193+
194+ test ( 'should clear a queued previousState when overwriting a same-source manual claim' , ( ) => {
195+ const result = processPresence (
196+ user ( {
197+ statusSource : 'manual' ,
198+ statusDefault : UserStatus . BUSY ,
199+ statusText : 'Focusing' ,
200+ previousState : { statusDefault : UserStatus . AWAY , statusText : 'Lunch' , statusSource : 'external' } ,
201+ } ) ,
202+ [ session ( ) ] ,
203+ { type : 'setActive' , newState : { statusDefault : UserStatus . AWAY , statusText : 'Heads down' , statusSource : 'manual' } } ,
204+ ) ;
205+ expect ( result . values . statusText ) . toBe ( 'Heads down' ) ;
206+ expect ( result . clear ) . toContain ( 'previousState' ) ;
175207 } ) ;
176208 } ) ;
177209
0 commit comments