11import type { Duration } from '@datadog/browser-core'
2- import { mockClock , type Clock } from '@datadog/browser-core/test'
3- import { clocksNow } from '@datadog/browser-core'
2+ import { mockClock , mockExperimentalFeatures , type Clock } from '@datadog/browser-core/test'
3+ import { clocksNow , ExperimentalFeature } from '@datadog/browser-core'
44import { collectAndValidateRawRumEvents , mockPageStateHistory } from '../../../test'
55import type { RawRumEvent , RawRumVitalEvent } from '../../rawRumEvent.types'
66import { VitalType , RumEventType } from '../../rawRumEvent.types'
@@ -229,7 +229,34 @@ describe('vitalCollection', () => {
229229 expect ( rawRumEvents [ 0 ] . domainContext ) . toEqual ( { } )
230230 } )
231231
232- it ( 'should create a vital from add API' , ( ) => {
232+ it ( 'should collect raw rum event from operation step vital' , ( ) => {
233+ mockExperimentalFeatures ( [ ExperimentalFeature . FEATURE_OPERATION_VITAL ] )
234+ vitalCollection . addOperationStepVital ( 'foo' , 'start' )
235+
236+ expect ( rawRumEvents [ 0 ] . startTime ) . toEqual ( jasmine . any ( Number ) )
237+ expect ( rawRumEvents [ 0 ] . rawRumEvent ) . toEqual ( {
238+ date : jasmine . any ( Number ) ,
239+ vital : {
240+ id : jasmine . any ( String ) ,
241+ type : VitalType . OPERATION_STEP ,
242+ name : 'foo' ,
243+ step_type : 'start' ,
244+ operation_key : undefined ,
245+ failure_reason : undefined ,
246+ description : undefined ,
247+ } ,
248+ context : undefined ,
249+ type : RumEventType . VITAL ,
250+ _dd : {
251+ vital : {
252+ computed_value : true ,
253+ } ,
254+ } ,
255+ } )
256+ expect ( rawRumEvents [ 0 ] . domainContext ) . toEqual ( { } )
257+ } )
258+
259+ it ( 'should create a duration vital from add API' , ( ) => {
233260 vitalCollection . addDurationVital ( {
234261 name : 'foo' ,
235262 type : VitalType . DURATION ,
@@ -244,6 +271,23 @@ describe('vitalCollection', () => {
244271 expect ( ( rawRumEvents [ 0 ] . rawRumEvent as RawRumVitalEvent ) . vital . description ) . toBe ( 'baz' )
245272 expect ( ( rawRumEvents [ 0 ] . rawRumEvent as RawRumVitalEvent ) . context ) . toEqual ( { foo : 'bar' } )
246273 } )
274+
275+ it ( 'should create a operation step vital from add API' , ( ) => {
276+ mockExperimentalFeatures ( [ ExperimentalFeature . FEATURE_OPERATION_VITAL ] )
277+ vitalCollection . addOperationStepVital ( 'foo' , 'end' , '00000000-0000-0000-0000-000000000000' , 'error' , {
278+ context : { foo : 'bar' } ,
279+ description : 'baz' ,
280+ } )
281+
282+ expect ( rawRumEvents . length ) . toBe ( 1 )
283+ expect ( ( rawRumEvents [ 0 ] . rawRumEvent as RawRumVitalEvent ) . vital . step_type ) . toBe ( 'end' )
284+ expect ( ( rawRumEvents [ 0 ] . rawRumEvent as RawRumVitalEvent ) . vital . operation_key ) . toBe (
285+ '00000000-0000-0000-0000-000000000000'
286+ )
287+ expect ( ( rawRumEvents [ 0 ] . rawRumEvent as RawRumVitalEvent ) . vital . failure_reason ) . toBe ( 'error' )
288+ expect ( ( rawRumEvents [ 0 ] . rawRumEvent as RawRumVitalEvent ) . vital . description ) . toBe ( 'baz' )
289+ expect ( ( rawRumEvents [ 0 ] . rawRumEvent as RawRumVitalEvent ) . context ) . toEqual ( { foo : 'bar' } )
290+ } )
247291 } )
248292 } )
249293} )
0 commit comments