|
1
|
|
|
'use strict'; |
|
2
|
|
|
|
|
3
|
|
|
var test = require( 'tape' ), |
|
4
|
|
|
deepFreeze = require( 'deep-freeze' ), |
|
5
|
|
|
asyncRequests = require( '../../lib/reducers/async_requests' ); |
|
6
|
|
|
|
|
7
|
|
|
test( 'there are no asynchronous processes when starting out', function ( t ) { |
|
8
|
|
|
var expectedState = { isValidating: false, runningValidations: 0 }, |
|
9
|
|
|
action = { type: 'DUMMY_ACTION' }; |
|
10
|
|
|
|
|
11
|
|
|
t.deepEqual( asyncRequests( undefined, action ), expectedState ); |
|
12
|
|
|
t.end(); |
|
13
|
|
|
} ); |
|
14
|
|
|
|
|
15
|
|
|
test( 'BEGIN_XXX_VALIDATION actions increase counter and change isValidating ', function ( t ) { |
|
16
|
|
|
|
|
17
|
|
|
var stateBefore = { isValidating: false, runningValidations: 0 }, |
|
18
|
|
|
expectedStateAfterFirstAction = { isValidating: true, runningValidations: 1 }, |
|
19
|
|
|
expectedStateAfterSecondAction = { isValidating: true, runningValidations: 2 }, |
|
20
|
|
|
action = { type: 'BEGIN_PAYMENT_DATA_VALIDATION', payload: { amount: '25,00', paymentType: 'BEZ' } }; |
|
21
|
|
|
|
|
22
|
|
|
deepFreeze( stateBefore ); |
|
23
|
|
|
t.deepEqual( asyncRequests( stateBefore, action ), expectedStateAfterFirstAction ); |
|
24
|
|
|
deepFreeze( expectedStateAfterFirstAction ); |
|
25
|
|
|
t.deepEqual( asyncRequests( expectedStateAfterFirstAction, action ), expectedStateAfterSecondAction ); |
|
26
|
|
|
t.end(); |
|
27
|
|
|
|
|
28
|
|
|
} ); |
|
29
|
|
|
|
|
30
|
|
|
test( 'FINISH_XXX_VALIDATION actions decrease counter and change isValidating ', function ( t ) { |
|
31
|
|
|
|
|
32
|
|
|
var initialState = { isValidating: false, runningValidations: 0 }, |
|
33
|
|
|
expectedStateAfterFirstAction = { isValidating: true, runningValidations: 1 }, |
|
34
|
|
|
expectedStateAfterSecondAction = { isValidating: false, runningValidations: 0 }, |
|
35
|
|
|
beginAction = { type: 'BEGIN_PAYMENT_DATA_VALIDATION', payload: { amount: '25,00', paymentType: 'BEZ' } }, |
|
36
|
|
|
finishAction = { type: 'FINISH_PAYMENT_DATA_VALIDATION', payload: { status: 'OK' } }, |
|
37
|
|
|
stateBefore, stateAfterOneFinishAction; |
|
38
|
|
|
|
|
39
|
|
|
stateBefore = asyncRequests( asyncRequests( initialState, beginAction ), beginAction ); |
|
40
|
|
|
deepFreeze( stateBefore ); |
|
41
|
|
|
|
|
42
|
|
|
stateAfterOneFinishAction = asyncRequests( stateBefore, finishAction ); |
|
43
|
|
|
t.deepEqual( stateAfterOneFinishAction, expectedStateAfterFirstAction ); |
|
44
|
|
|
deepFreeze( expectedStateAfterFirstAction ); |
|
45
|
|
|
t.deepEqual( asyncRequests( expectedStateAfterFirstAction, finishAction ), expectedStateAfterSecondAction ); |
|
46
|
|
|
t.end(); |
|
47
|
|
|
|
|
48
|
|
|
} ); |
|
49
|
|
|
|
|
50
|
|
|
test( 'Additional FINISH_XXX_VALIDATION actions do not modify state', function ( t ) { |
|
51
|
|
|
|
|
52
|
|
|
var initialState = { isValidating: false, runningValidations: 0 }, |
|
53
|
|
|
action = { type: 'FINISH_PAYMENT_DATA_VALIDATION', payload: { status: 'OK' } }; |
|
54
|
|
|
|
|
55
|
|
|
deepFreeze( initialState ); |
|
56
|
|
|
|
|
57
|
|
|
t.equal( asyncRequests( initialState, action ), initialState ); |
|
58
|
|
|
|
|
59
|
|
|
t.end(); |
|
60
|
|
|
|
|
61
|
|
|
} ); |
|
62
|
|
|
|