@@ -21,32 +21,6 @@ var CONFIG_DELAYED_HELLO_WORLD = [{
2121 ] ,
2222} ] ;
2323
24- var CONFIG_HELLO_STATES = [ {
25- name : 'hello!' ,
26- provides : 'hello' ,
27- sequence : [
28- [ 'say' , 'hello' ] ,
29- ] ,
30- } , {
31- name : 'world!' ,
32- requires : 'hello' ,
33- sequence : [
34- [ 'say' , 'world' ] ,
35- ] ,
36- } , {
37- name : 'goodbye!' ,
38- resets : 'hello' ,
39- sequence : [
40- [ 'say' , 'goodbye' ] ,
41- ] ,
42- } , {
43- name : 'something' ,
44- resets : 'world' ,
45- sequence : [
46- [ 'say' , 'goodbye' ] ,
47- ] ,
48- } ] ;
49-
5024var CONFIG_HELLO = [
5125 {
5226 name : 'hello' ,
@@ -350,6 +324,32 @@ describe('macros', function () {
350324 } ) ;
351325
352326 describe ( 'state' , function ( ) {
327+ var CONFIG_STATES = [ {
328+ name : 'hello!' ,
329+ provides : 'hello' ,
330+ sequence : [
331+ [ 'say' , 'hello' ] ,
332+ ] ,
333+ } , {
334+ name : 'world!' ,
335+ requires : 'hello' ,
336+ sequence : [
337+ [ 'say' , 'world' ] ,
338+ ] ,
339+ } , {
340+ name : 'goodbye!' ,
341+ resets : 'hello' ,
342+ sequence : [
343+ [ 'say' , 'goodbye' ] ,
344+ ] ,
345+ } , {
346+ name : 'something' ,
347+ resets : 'world' ,
348+ sequence : [
349+ [ 'say' , 'goodbye' ] ,
350+ ] ,
351+ } ] ;
352+
353353 describe ( 'set, reset and query' , function ( ) {
354354 beforeEach ( function ( ) {
355355 resetMockAndFixture ( ) ;
@@ -361,27 +361,27 @@ describe('macros', function () {
361361 } ) ;
362362
363363 it ( 'should deliver current states as key value map' , function ( ) {
364- macros . init ( CONFIG_HELLO_STATES ) ;
364+ macros . init ( CONFIG_STATES ) ;
365365 assert . deepEqual ( macros . getCurrentStates ( ) , { hello : 'clear' , world : 'clear' } ) ;
366366 } ) ;
367367
368368 it ( 'should set state after execution' , function ( ) {
369- macros . init ( CONFIG_HELLO_STATES ) ;
369+ macros . init ( CONFIG_STATES ) ;
370370 assert . deepEqual ( macros . getCurrentStates ( ) ,
371371 { hello : 'clear' , world : 'clear' } , 'not called' ) ;
372- macros . execute ( CONFIG_HELLO_STATES [ 0 ] . name ) ;
372+ macros . execute ( CONFIG_STATES [ 0 ] . name ) ;
373373 clock . tick ( 51 ) ;
374374 assert . deepEqual ( macros . getCurrentStates ( ) ,
375375 { hello : 'set' , world : 'clear' } , 'macro called' ) ;
376376 } ) ;
377377
378378 it ( 'should reset state after execution' , function ( ) {
379- macros . init ( CONFIG_HELLO_STATES ) ;
380- macros . execute ( CONFIG_HELLO_STATES [ 0 ] . name ) ;
379+ macros . init ( CONFIG_STATES ) ;
380+ macros . execute ( CONFIG_STATES [ 0 ] . name ) ;
381381 clock . tick ( 51 ) ;
382382 assert . deepEqual ( macros . getCurrentStates ( ) , { hello : 'set' , world : 'clear' } ,
383383 'state set called' ) ;
384- macros . execute ( CONFIG_HELLO_STATES [ 2 ] . name ) ;
384+ macros . execute ( CONFIG_STATES [ 2 ] . name ) ;
385385 clock . tick ( 51 ) ;
386386 assert . deepEqual ( macros . getCurrentStates ( ) , { hello : 'clear' , world : 'clear' } ,
387387 'state reset called' ) ;
@@ -396,7 +396,30 @@ describe('macros', function () {
396396 } ) ;
397397 } ) ;
398398
399+ // TODO validation of providers, requesters, resetters and deniers:
400+ // providers and deniers need match!
401+
399402 describe ( 'dependency call' , function ( ) {
403+ var CONFIG_MULTI_STATES = [ {
404+ name : 'Lamp' ,
405+ provides : 'light' ,
406+ sequence : [
407+ [ 'say' , 'shiny' ] ,
408+ ] ,
409+ } , {
410+ name : 'he' ,
411+ requires : 'light' ,
412+ sequence : [
413+ [ 'say' , 'uh' ] ,
414+ ] ,
415+ } , {
416+ name : 'she' ,
417+ requires : 'light' ,
418+ sequence : [
419+ [ 'say' , 'ah' ] ,
420+ ] ,
421+ } ] ;
422+
400423 beforeEach ( function ( ) {
401424 resetMockAndFixture ( ) ;
402425 clock = sinon . useFakeTimers ( ) ;
@@ -407,14 +430,35 @@ describe('macros', function () {
407430 } ) ;
408431
409432 it . skip ( 'should call macro if state is requested' , function ( ) {
410- macros . init ( CONFIG_HELLO_STATES ) ;
411- macros . execute ( CONFIG_HELLO_STATES [ 1 ] . name ) ;
433+ macros . init ( CONFIG_STATES ) ;
434+ macros . execute ( CONFIG_STATES [ 1 ] . name ) ;
412435 clock . tick ( 51 ) ;
413436 assert . deepEqual ( deviceMock . operations ,
414437 [ [ 'say' , 'hello' ] , [ 'say' , 'world' ] ] , 'calls are not done as expected' ) ;
415438 assert . deepEqual ( macros . getCurrentStates ( ) , { hello : true , world : false } ,
416439 'states are not set as required' ) ;
417440 } ) ;
441+
442+ it . skip ( 'should call a macro only once, if two triggered macros request it simultaneously' ,
443+ function ( ) {
444+ macros . init ( CONFIG_MULTI_STATES ) ;
445+ macros . execute ( CONFIG_MULTI_STATES [ 1 ] . name ) ;
446+ clock . tick ( 20 ) ;
447+ macros . execute ( CONFIG_MULTI_STATES [ 2 ] . name ) ;
448+ clock . tick ( 131 ) ;
449+ assert . deepEqual ( deviceMock . operations ,
450+ [ [ 'say' , 'shiny' ] , [ 'say' , 'uh' ] , [ 'say' , 'ah' ] ] , 'calls are not done as expected' ) ;
451+ assert . deepEqual ( macros . getCurrentStates ( ) , { hello : true , world : false } ,
452+ 'states are not set as required' ) ;
453+ }
454+ ) ;
455+
456+ it . skip ( 'should call multiple macros if multiple states are requested' , function ( ) {
457+ macros . init ( CONFIG_MULTI_STATES ) ;
458+ macros . execute ( CONFIG_MULTI_STATES [ 1 ] . name ) ;
459+ clock . tick ( 51 ) ;
460+ // TODO
461+ } ) ;
418462 } ) ;
419463 } ) ;
420464} ) ;
0 commit comments