| Total Complexity | 2 |
| Complexity/F | 1 |
| Lines of Code | 34 |
| Function Count | 2 |
| Duplicated Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | 'use strict'; |
||
| 2 | |||
| 3 | var test = require( 'tape' ), |
||
| 4 | sinon = require( 'sinon' ), |
||
| 5 | createValidationDispatcherCollection = require( '../lib/validation_dispatcher_collection' ).createValidationDispatcherCollection; |
||
| 6 | |||
| 7 | test( 'ValidationDispatcherCollection listens to store updates', function ( t ) { |
||
| 8 | var storeSpy = { |
||
| 9 | subscribe: sinon.spy() |
||
| 10 | }; |
||
| 11 | |||
| 12 | createValidationDispatcherCollection( storeSpy, [], 'dummy' ); |
||
| 13 | |||
| 14 | t.ok( storeSpy.subscribe.calledOnce, 'mapper subscribes to store updates' ); |
||
| 15 | t.end(); |
||
| 16 | } ); |
||
| 17 | |||
| 18 | test( 'ValidationDispatcherCollection update method calls dispatchers', function ( t ) { |
||
| 19 | var formContent = { amount: 42 }, |
||
| 20 | state = { donationForm: formContent }, |
||
| 21 | storeSpy = { |
||
| 22 | subscribe: sinon.spy(), |
||
| 23 | getState: sinon.stub().returns( state ) |
||
| 24 | }, |
||
| 25 | validatorSpy = { dispatchIfChanged: sinon.spy() }, |
||
| 26 | collection = createValidationDispatcherCollection( storeSpy, [ validatorSpy ], 'donationForm' ); |
||
| 27 | |||
| 28 | collection.onUpdate(); |
||
| 29 | |||
| 30 | t.ok( storeSpy.getState.calledOnce, 'onUpdate gets state from the store' ); |
||
| 31 | t.ok( validatorSpy.dispatchIfChanged.calledOnce, 'dispatchers are called' ); |
||
| 32 | t.ok( validatorSpy.dispatchIfChanged.calledWith( formContent, storeSpy ), 'dispatchers are called' ); |
||
| 33 | t.end(); |
||
| 34 | } ); |
||
| 35 | |||
| 36 |