1
+ import * as types from 'constants/action-types' ;
2
+
3
+ import path from 'reducers/path' ;
4
+
5
+ describe ( 'path.js reducers' , ( ) => {
6
+ let initialState ;
7
+ const DECREASE_PENDING_ACTIONS = [
8
+ types . RECEIVE_UNGIT_CONFIG ,
9
+ types . RECEIVE_USER_CONFIG ,
10
+ types . RECEIVE_GIT_VERSION ,
11
+ types . RECEIVE_LATEST_VERSION
12
+ ] ;
13
+
14
+ beforeEach ( ( ) => {
15
+ initialState = {
16
+ pending : null ,
17
+ errMessage : [ ]
18
+ } ;
19
+ } ) ;
20
+
21
+ it ( 'should return original state if action doesn\'t match any case' , function ( ) {
22
+ const state = path ( initialState , { type : 'no-op' } ) ;
23
+ expect ( state . pending ) . toEqual ( initialState . pending ) ;
24
+ expect ( state . errMessage . length ) . toEqual ( initialState . errMessage . length ) ;
25
+ } ) ;
26
+
27
+ describe ( 'when PATH_PAGE_PENDING action dispatch' , ( ) => {
28
+ it ( 'pending state should be calculated correctly' , function ( ) {
29
+ const action1 = { type : types . PATH_PAGE_PENDING , payload : 1 } ;
30
+ const action2 = { type : types . PATH_PAGE_PENDING , payload : 3 } ;
31
+
32
+ const state1 = path ( initialState , action1 ) ;
33
+ expect ( state1 . pending ) . toEqual ( initialState . pending + action1 . payload ) ;
34
+
35
+ const state2 = path ( state1 , action2 ) ;
36
+ expect ( state2 . pending ) . toEqual ( state1 . pending + action2 . payload ) ;
37
+ } ) ;
38
+ } ) ;
39
+
40
+ DECREASE_PENDING_ACTIONS . forEach ( actionName => {
41
+ describe ( `when ${ actionName } action dispatch` , ( ) => {
42
+ beforeEach ( ( ) => {
43
+ initialState = {
44
+ pending : 1 ,
45
+ errMessage : [ ]
46
+ } ;
47
+ } ) ;
48
+ it ( 'pending state should be minused one' , ( ) => {
49
+ const action = { type : actionName } ;
50
+
51
+ const state = path ( initialState , action ) ;
52
+ expect ( state . pending ) . toEqual ( initialState . pending - 1 ) ;
53
+ } ) ;
54
+ } ) ;
55
+ } ) ;
56
+
57
+ describe ( 'when PATH_PAGE_API_ERR action dispatch' , ( ) => {
58
+ it ( 'pending state should be minused one' , function ( ) {
59
+ const action = { type : types . PATH_PAGE_API_ERR , payload : 'error message' } ;
60
+
61
+ const state = path ( initialState , action ) ;
62
+ expect ( state . pending ) . toEqual ( initialState . pending - 1 ) ;
63
+ } ) ;
64
+
65
+ it ( 'errMessage state should correct content' , function ( ) {
66
+ const action = { type : types . PATH_PAGE_API_ERR , payload : 'error message' } ;
67
+
68
+ const state = path ( initialState , action ) ;
69
+ expect ( state . errMessage . length ) . toEqual ( initialState . errMessage . length + 1 ) ;
70
+ expect ( state . errMessage [ 0 ] ) . toEqual ( action . payload ) ;
71
+ } ) ;
72
+ } ) ;
73
+ } ) ;
0 commit comments