/**
 * Utilities for testing.
 */ /**
 * Regex that matches a UUID v4 as used in Coaty framework.
 */ export const UUID_REGEX_STRING = "[a-f0-9]{8}-[a-f0-9]{4}-4[a-f0-9]{3}-[89aAbB][a-f0-9]{3}-[a-f0-9]{12}" ; export const UUID_REGEX = new RegExp ( UUID_REGEX_STRING ) ; export function delayAction ( delay , done , action ? ) { setTimeout ( ( ) => { action && action ( ) ; done && done ( ) ; } , delay ) ; } export function skipTestIf ( condition , reason ? ) { if ( condition ) { pending ( reason ) ; } } export function failTest ( error , done ? ) { fail ( error ) ; done && done ( ) ; } export class Spy { static NO_VALUE = { noValue : true } ; private static _spies = { } ; static add ( name ) { Spy . _spies [ name ] = jasmine . createSpyObj ( name , [ "value1" , "value2" , "value3" , "value4" , "value5" ] ) ; } static get ( name ) { return Spy . _spies [ name ] ; } static set ( name , value1 = Spy . NO_VALUE , value2 = Spy . NO_VALUE , value3 = Spy . NO_VALUE , value4 = Spy . NO_VALUE , value5 = Spy . NO_VALUE ) { let spyObj = Spy . _spies [ name ] ; if ( ! spyObj ) { Spy . add ( name ) ; spyObj = Spy . _spies [ name ] ; } value1 === Spy . NO_VALUE || spyObj . value1 ( value1 ) ; value2 === Spy . NO_VALUE || spyObj . value2 ( value2 ) ; value3 === Spy . NO_VALUE || spyObj . value3 ( value3 ) ; value4 === Spy . NO_VALUE || spyObj . value4 ( value4 ) ; value5 === Spy . NO_VALUE || spyObj . value5 ( value5 ) ; } static reset ( ) { Object . keys ( Spy . _spies ) . forEach ( prop => { Spy . _spies [ prop ] . calls && Spy . _spies [ prop ] . calls . reset ( ) ; } ) ; } }