@@ -73,4 +73,126 @@ describe('console-accessible values on the window object', function () {
7373 1970-01-01 00:00:00.190000000 UTC - [Unknown Process 0: Empty]: D/nsJarProtocol nsJARChannel::nsJARChannel [this=0x87f1ec80]
7474 ` ) ;
7575 } ) ;
76+
77+ describe ( 'totalMarkerDuration' , function ( ) {
78+ function setup ( ) {
79+ jest . spyOn ( console , 'log' ) . mockImplementation ( ( ) => { } ) ;
80+
81+ const store = storeWithSimpleProfile ( ) ;
82+ const target = { } ;
83+ addDataToWindowObject ( store . getState , store . dispatch , target ) ;
84+
85+ return target ;
86+ }
87+ beforeEach ( function ( ) { } ) ;
88+
89+ it ( 'returns 0 for empty array' , function ( ) {
90+ const target = setup ( ) ;
91+ const result = target . totalMarkerDuration ( [ ] ) ;
92+ expect ( result ) . toBe ( 0 ) ;
93+ } ) ;
94+
95+ it ( 'returns 0 and logs error for non-array input' , function ( ) {
96+ const target = setup ( ) ;
97+ const consoleErrorSpy = jest
98+ . spyOn ( console , 'error' )
99+ . mockImplementation ( ( ) => { } ) ;
100+ const result = target . totalMarkerDuration ( 'not an array' ) ;
101+ expect ( result ) . toBe ( 0 ) ;
102+ expect ( consoleErrorSpy ) . toHaveBeenCalledWith (
103+ 'totalMarkerDuration expects an array of markers'
104+ ) ;
105+ consoleErrorSpy . mockRestore ( ) ;
106+ } ) ;
107+
108+ it ( 'calculates duration for interval markers' , function ( ) {
109+ const target = setup ( ) ;
110+ const markers = [
111+ {
112+ start : 100 ,
113+ end : 200 ,
114+ name : 'marker1' ,
115+ category : 0 ,
116+ data : null ,
117+ } ,
118+ {
119+ start : 150 ,
120+ end : 250 ,
121+ name : 'marker2' ,
122+ category : 0 ,
123+ data : null ,
124+ } ,
125+ ] ;
126+ const result = target . totalMarkerDuration ( markers ) ;
127+ expect ( result ) . toBe ( 200 ) ; // (200-100) + (250-150) = 100 + 100 = 200
128+
129+ // Make sure that we print a formatted log for the duration.
130+ expect ( console . log ) . toHaveBeenCalledWith ( 'Total marker duration: 200ms' ) ;
131+ } ) ;
132+
133+ it ( 'skips instant markers with null end times' , function ( ) {
134+ const target = setup ( ) ;
135+ const markers = [
136+ {
137+ start : 100 ,
138+ end : 200 ,
139+ name : 'interval' ,
140+ category : 0 ,
141+ threadId : null ,
142+ data : null ,
143+ } ,
144+ {
145+ start : 150 ,
146+ end : null ,
147+ name : 'instant' ,
148+ category : 0 ,
149+ threadId : null ,
150+ data : null ,
151+ } ,
152+ {
153+ start : 300 ,
154+ end : 400 ,
155+ name : 'interval2' ,
156+ category : 0 ,
157+ threadId : null ,
158+ data : null ,
159+ } ,
160+ ] ;
161+ const result = target . totalMarkerDuration ( markers ) ;
162+ expect ( result ) . toBe ( 200 ) ; // (200-100) + (400-300) = 100 + 100 = 200
163+ } ) ;
164+
165+ it ( 'handles mixed valid and invalid markers' , function ( ) {
166+ const target = setup ( ) ;
167+ const markers = [
168+ {
169+ start : 100 ,
170+ end : 200 ,
171+ name : 'valid' ,
172+ category : 0 ,
173+ threadId : null ,
174+ data : null ,
175+ } ,
176+ null ,
177+ {
178+ start : 'invalid' ,
179+ end : 300 ,
180+ name : 'invalid' ,
181+ category : 0 ,
182+ threadId : null ,
183+ data : null ,
184+ } ,
185+ {
186+ start : 400 ,
187+ end : 500 ,
188+ name : 'valid2' ,
189+ category : 0 ,
190+ threadId : null ,
191+ data : null ,
192+ } ,
193+ ] ;
194+ const result = target . totalMarkerDuration ( markers ) ;
195+ expect ( result ) . toBe ( 200 ) ; // (200-100) + (500-400) = 100 + 100 = 200
196+ } ) ;
197+ } ) ;
76198} ) ;
0 commit comments