@@ -94,17 +94,55 @@ export default function (){
9494 } ) ;
9595
9696 } ) ;
97- // Input output for bool, string, object and number
98- // write/read (getter/setter test) proper value, write read proper type,
99- // throws when corrupted
100-
101- // Update_handler
102- // it does lock the callback, it throws
103- // it updates the variable, updates only once
104- // it runs the callbacks, set ad hoc, passes the right modified value
105- // that unlocks
106-
107- // Set_auto value willbe tested in Transitions
97+ describe ( 'Update Handler' , ( ) => {
98+ it ( 'It locks' , ( ) => {
99+ let test_string = new StateVariable ( "test_string" , 'string' , "ciao" ) ;
100+ let test_number = new StateVariable ( "test_number" , 'number' , 7 ) ;
101+ let double_mod = ( ) => { let pippo = new CustomEvent ( "bordello" , { bubbles :true , detail :{ 'value' :872 } } ) ; test_number . updateHandler ( pippo ) } ;
102+ test_string . callbackMap . set ( document . body , double_mod ) ;
103+
104+ let throw_lock = ( ) => { let pippo = new CustomEvent ( "bordello" , { bubbles :true , detail :{ 'value' :"ggg" } } ) ; test_string . updateHandler ( pippo ) } ;
105+
106+ chai . assert . Throw ( throw_lock ) ;
107+ } ) ;
108+
109+ it ( 'It updates all values and only once and unlocks' , ( ) => {
110+ let test_string = new StateVariable ( "test_string" , 'string' , "ciao" ) ;
111+ let test_number = new StateVariable ( "test_number" , 'number' , 7 ) ;
112+ let test_object = new StateVariable ( "test_object" , 'object' , { ciao :"bella" , hey :67 , poz :[ "cool" , 9 ] } ) ;
113+ let test_bool = new StateVariable ( "test_bool" , 'boolean' , true ) ;
114+
115+ test_string . value = "hey" ;
116+ test_number . value = 123 ;
117+ test_object . value = { bla :67 , ca :"ca" } ;
118+ test_bool . value = false ;
119+
120+ let counter = 0 ;
121+ let counter_func = ( ) => { counter ++ ; } ;
122+ test_string . callbackMap . set ( document . body , counter_func ) ;
123+ test_number . callbackMap . set ( document . body , counter_func ) ;
124+ test_object . callbackMap . set ( document . body , counter_func ) ;
125+ test_bool . callbackMap . set ( document . body , counter_func ) ;
126+
127+ let ev_n = new CustomEvent ( "bordello" , { bubbles :true , detail :{ 'value' :321 } } ) ;
128+ let ev_s = new CustomEvent ( "bordello" , { bubbles :true , detail :{ 'value' :"qwerty" } } ) ;
129+ let ev_o = new CustomEvent ( "bordello" , { bubbles :true , detail :{ 'value' :{ a :1 , b :2 } } } ) ;
130+ let ev_b = new CustomEvent ( "bordello" , { bubbles :true , detail :{ 'value' :true } } ) ;
131+
132+ test_string . updateHandler ( ev_s ) ;
133+ chai . assert . equal ( test_string . value , "qwerty" , "String " ) ;
134+ chai . assert . equal ( counter , 1 , "Called once " ) ;
135+ test_number . updateHandler ( ev_n ) ;
136+ chai . assert . equal ( test_number . value , 321 , "number " ) ;
137+ chai . assert . equal ( counter , 2 , "Called once " ) ;
138+ test_object . updateHandler ( ev_o ) ;
139+ chai . assert . deepEqual ( test_object . value , { a :1 , b :2 } , "Object " ) ;
140+ chai . assert . equal ( counter , 3 , "Called once " ) ;
141+ test_bool . updateHandler ( ev_b ) ;
142+ chai . assert . equal ( test_bool . value , true , "bool " ) ;
143+ chai . assert . equal ( counter , 4 , "Called once " ) ;
144+ } ) ;
145+ } ) ;
108146
109147 } ) ;
110148}
0 commit comments