@@ -73,4 +73,138 @@ 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+ let target ;
79+ let consoleLogSpy ;
80+
81+ beforeEach ( function ( ) {
82+ const store = storeWithSimpleProfile ( ) ;
83+ target = { } ;
84+ addDataToWindowObject ( store . getState , store . dispatch , target ) ;
85+ consoleLogSpy = jest . spyOn ( console , 'log' ) . mockImplementation ( ( ) => { } ) ;
86+ } ) ;
87+
88+ afterEach ( function ( ) {
89+ consoleLogSpy . mockRestore ( ) ;
90+ } ) ;
91+
92+ it ( 'returns 0 for empty array' , function ( ) {
93+ const result = target . totalMarkerDuration ( [ ] ) ;
94+ expect ( result ) . toBe ( 0 ) ;
95+ } ) ;
96+
97+ it ( 'returns 0 and logs error for non-array input' , function ( ) {
98+ const consoleErrorSpy = jest
99+ . spyOn ( console , 'error' )
100+ . mockImplementation ( ( ) => { } ) ;
101+ const result = target . totalMarkerDuration ( 'not an array' ) ;
102+ expect ( result ) . toBe ( 0 ) ;
103+ expect ( consoleErrorSpy ) . toHaveBeenCalledWith (
104+ 'totalMarkerDuration expects an array of markers'
105+ ) ;
106+ consoleErrorSpy . mockRestore ( ) ;
107+ } ) ;
108+
109+ it ( 'calculates duration for interval markers' , function ( ) {
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+
130+ it ( 'skips instant markers with null end times' , function ( ) {
131+ const markers = [
132+ {
133+ start : 100 ,
134+ end : 200 ,
135+ name : 'interval' ,
136+ category : 0 ,
137+ threadId : null ,
138+ data : null ,
139+ } ,
140+ {
141+ start : 150 ,
142+ end : null ,
143+ name : 'instant' ,
144+ category : 0 ,
145+ threadId : null ,
146+ data : null ,
147+ } ,
148+ {
149+ start : 300 ,
150+ end : 400 ,
151+ name : 'interval2' ,
152+ category : 0 ,
153+ threadId : null ,
154+ data : null ,
155+ } ,
156+ ] ;
157+ const result = target . totalMarkerDuration ( markers ) ;
158+ expect ( result ) . toBe ( 200 ) ; // (200-100) + (400-300) = 100 + 100 = 200
159+ } ) ;
160+
161+ it ( 'handles mixed valid and invalid markers' , function ( ) {
162+ const markers = [
163+ {
164+ start : 100 ,
165+ end : 200 ,
166+ name : 'valid' ,
167+ category : 0 ,
168+ threadId : null ,
169+ data : null ,
170+ } ,
171+ null ,
172+ {
173+ start : 'invalid' ,
174+ end : 300 ,
175+ name : 'invalid' ,
176+ category : 0 ,
177+ threadId : null ,
178+ data : null ,
179+ } ,
180+ {
181+ start : 400 ,
182+ end : 500 ,
183+ name : 'valid2' ,
184+ category : 0 ,
185+ threadId : null ,
186+ data : null ,
187+ } ,
188+ ] ;
189+ const result = target . totalMarkerDuration ( markers ) ;
190+ expect ( result ) . toBe ( 200 ) ; // (200-100) + (500-400) = 100 + 100 = 200
191+ } ) ;
192+
193+ it ( 'logs formatted duration to console' , function ( ) {
194+ const markers = [
195+ {
196+ start : 100 ,
197+ end : 350 ,
198+ name : 'marker' ,
199+ category : 0 ,
200+ threadId : null ,
201+ data : null ,
202+ } ,
203+ ] ;
204+ target . totalMarkerDuration ( markers ) ;
205+ expect ( consoleLogSpy ) . toHaveBeenCalledWith (
206+ 'Total marker duration: 250ms'
207+ ) ;
208+ } ) ;
209+ } ) ;
76210} ) ;
0 commit comments