1+ import { fromJS } from 'immutable' ;
12import issues from './issues' ;
23import * as constants from '../actionCreators/constants' ;
34
45describe ( 'Issue' , ( ) => {
5- const initState = {
6+ const initState = fromJS ( {
67 didInvalidate : true ,
78 isFetching : false ,
89 isRequestFailed : false ,
@@ -11,8 +12,9 @@ describe('Issue', () => {
1112 paging : {
1213 issuesCountOptions : [ '10' , '20' , '30' , '50' , '100' ] ,
1314 defaultIssuesCountOption : '20' ,
15+ issuesPagesCount : null ,
1416 } ,
15- } ;
17+ } ) ;
1618
1719 it ( 'should return the init state' , ( ) => {
1820 expect ( issues ( undefined , { } ) ) . toEqual ( initState ) ;
@@ -22,39 +24,25 @@ describe('Issue', () => {
2224 expect ( issues ( undefined , { type : 'NOT_EXISTING' } ) ) . toEqual ( initState ) ;
2325 } ) ;
2426
25- it ( 'should handle INVALIDATE_ISSUES' , ( ) => {
26- const originalState = {
27- ...initState ,
28- didInvalidate : false ,
29- data : [ { id : 1 } , { id : 2 } , { id : 5 } ] ,
30- } ;
27+ it ( 'should handle INVALIDATE_ISSUES action' , ( ) => {
28+ const originalState = initState . set ( 'didInvalidate' , false ) . set ( 'data' , fromJS ( [ { id : 1 } , { id : 2 } , { id : 5 } ] ) ) ;
3129 const expectedState = initState ;
32- expect ( issues ( originalState , { type : constants . INVALIDATE_ISSUES } ) ) . toEqual ( expectedState ) ;
30+ expect ( issues ( originalState , { type : constants . INVALIDATE_ISSUES } ) ) . toEqual ( fromJS ( expectedState ) ) ;
3331 } ) ;
3432
35- it ( 'should handle REQUEST_ISSUES' , ( ) => {
33+ it ( 'should handle REQUEST_ISSUES action ' , ( ) => {
3634 const originalState = initState ;
37- const expectedState = {
38- ...initState ,
39- didInvalidate : false ,
40- isFetching : true ,
41- } ;
35+ const expectedState = initState . set ( 'didInvalidate' , false ) . set ( 'isFetching' , true ) ;
4236 expect ( issues ( originalState , { type : constants . REQUEST_ISSUES } ) ) . toEqual ( expectedState ) ;
4337 } ) ;
4438
45- it ( 'should handle RECEIVE_ISSUES' , ( ) => {
46- const originalState = {
47- ...initState ,
48- data : [ { id : 1 } , { id : 2 } , { id : 5 } ] ,
49- isFetching : true ,
50- didInvalidate : false ,
51- } ;
39+ it ( 'should handle RECEIVE_ISSUES action' , ( ) => {
40+ const originalState = initState
41+ . set ( 'data' , fromJS ( [ { id : 1 } , { id : 2 } , { id : 5 } ] ) )
42+ . set ( 'isFetching' , true )
43+ . set ( 'didInvalidate' , false ) ;
5244 const newIssues = [ { id : 7 } , { id : 8 } , { id : 9 } ] ;
53- const expectedState = {
54- ...originalState ,
55- isFetching : false ,
56- data : [ ...originalState . data , ...newIssues ] ,
57- } ;
45+ const expectedState = originalState . set ( 'isFetching' , false ) . set ( 'data' , fromJS ( newIssues ) ) ;
5846 expect (
5947 issues ( originalState , {
6048 type : constants . RECEIVE_ISSUES ,
@@ -63,20 +51,16 @@ describe('Issue', () => {
6351 ) . toEqual ( expectedState ) ;
6452 } ) ;
6553
66- it ( 'should handle RECEIVE_ISSUES_ERROR' , ( ) => {
67- const originalState = {
68- ...initState ,
69- data : [ { id : 1 } , { id : 2 } , { id : 5 } ] ,
70- isFetching : true ,
71- didInvalidate : false ,
72- } ;
54+ it ( 'should handle RECEIVE_ISSUES_ERROR action' , ( ) => {
55+ const originalState = initState
56+ . set ( 'data' , [ { id : 1 } , { id : 2 } , { id : 5 } ] )
57+ . set ( 'isFetching' , true )
58+ . set ( 'didInvalidate' , false ) ;
7359 const errorMessage = 'Message' ;
74- const expectedState = {
75- ...originalState ,
76- isFetching : false ,
77- isRequestFailed : true ,
78- errorMessage,
79- } ;
60+ const expectedState = originalState
61+ . set ( 'isFetching' , false )
62+ . set ( 'isRequestFailed' , true )
63+ . set ( 'errorMessage' , errorMessage ) ;
8064 expect (
8165 issues ( originalState , {
8266 type : constants . RECEIVE_ISSUES_ERROR ,
@@ -85,13 +69,10 @@ describe('Issue', () => {
8569 ) . toEqual ( expectedState ) ;
8670 } ) ;
8771
88- it ( 'should handle RECEIVE_ISSUES_PAGES_COUNT' , ( ) => {
72+ it ( 'should handle RECEIVE_ISSUES_PAGES_COUNT action ' , ( ) => {
8973 const originalState = initState ;
9074 const issuesPagesCount = 5 ;
91- const expectedState = {
92- ...initState ,
93- paging : { ...originalState . paging , issuesPagesCount } ,
94- } ;
75+ const expectedState = originalState . setIn ( [ 'paging' , 'issuesPagesCount' ] , issuesPagesCount ) ;
9576 expect (
9677 issues ( originalState , {
9778 type : constants . RECEIVE_ISSUES_PAGES_COUNT ,
0 commit comments