@@ -234,6 +234,29 @@ describe('Player listen ranges', function () {
234234 assert . equal ( player . getListenDuration ( ) , 7 ) ;
235235 } ) ;
236236
237+ it ( 'Listened for is track duration invariant' , function ( ) {
238+ const player = new TestPositionalPlayerState ( logger , [ NO_DEVICE , NO_USER ] ) ;
239+
240+ const positioned = clone ( newPlay ) ;
241+ positioned . data . duration = 0 ;
242+
243+ player . update ( testState ( { play : positioned , position : 3 , status : REPORTED_PLAYER_STATUSES . playing } ) ) ;
244+
245+ player . currentListenRange . rtPlayer . setPosition ( 10000 ) ;
246+ player . update ( testState ( { play : positioned , position : 10 , status : REPORTED_PLAYER_STATUSES . playing } ) , dayjs ( ) . add ( 10 , 'seconds' ) ) ;
247+
248+ player . currentListenRange . rtPlayer . setPosition ( 20000 ) ;
249+ player . update ( testState ( { play : positioned , position : 20 , status : REPORTED_PLAYER_STATUSES . playing } ) , dayjs ( ) . add ( 20 , 'seconds' ) ) ;
250+
251+ const otherPlay = clone ( positioned ) ;
252+ otherPlay . data . track = "A New Track" ;
253+ player . currentListenRange . rtPlayer . setPosition ( 30000 ) ;
254+ const [ currPlay , prevPlay ] = player . update ( testState ( { play : otherPlay , position : 2 , status : REPORTED_PLAYER_STATUSES . playing } ) , dayjs ( ) . add ( 30 , 'seconds' ) ) ;
255+
256+ assert . isDefined ( prevPlay ) ;
257+ assert . equal ( prevPlay . data . listenedFor , 17 ) ;
258+ } ) ;
259+
237260 it ( 'Range ends if position over drifts' , function ( ) {
238261 const player = new TestPositionalPlayerState ( logger , [ NO_DEVICE , NO_USER ] ) ;
239262
0 commit comments