1
- import containerListReducer from '../src/redux/reducers/containerListReducer' ; // import containerList reducer
2
- import imageListReducer from '../src/redux/reducers/imageListReducer' ; // import imageListReducer reducer
3
- import { describe , beforeEach , expect , test } from '@jest/globals' ;
1
+ import containerListReducer from '../src/redux/reducers/containerListReducer' // import containerList reducer
2
+ import imageListReducer from '../src/redux/reducers/imageListReducer' // import imageListReducer reducer
3
+ import { describe , beforeEach , expect , test } from '@jest/globals'
4
4
5
5
describe ( 'Dockeeter reducer' , ( ) => {
6
- let state ;
6
+ let state
7
7
8
8
beforeEach ( ( ) => {
9
9
state = {
10
10
imagesList : [ ] ,
11
11
runningList : [ ] ,
12
- stoppedList : [ ]
13
- } ;
14
- } ) ;
12
+ stoppedList : [ ] ,
13
+ hostStats : { } ,
14
+ }
15
+ } )
15
16
16
17
describe ( 'Action Types' , ( ) => {
17
18
test ( 'Should return initial state if type is invalid' , ( ) => {
18
- expect ( containerListReducer ( state , { type : 'FakeActionType' } ) ) . toBe ( state ) ;
19
- } ) ;
20
- } ) ;
19
+ expect ( containerListReducer ( state , { type : 'FakeActionType' } ) ) . toBe (
20
+ state ,
21
+ )
22
+ } )
23
+ } )
24
+ // REFRESH_HOST_DATA
25
+ describe ( 'REFRESH_HOST_DATA' , ( ) => {
26
+ test ( 'Should refresh host data' , ( ) => {
27
+ expect ( state . hostStats ) . toEqual ( { } )
28
+ let action = {
29
+ type : 'REFRESH_HOST_DATA' ,
30
+ payload : { cpuPerc : 24.45 , memPerc : 95.08 } ,
31
+ }
32
+ } )
33
+ } )
21
34
22
35
describe ( 'REFRESH_RUNNING_CONTAINERS' , ( ) => {
23
36
test ( 'Should return a different state with each reducer invocation' , ( ) => {
24
- expect ( state . runningList . length ) . toEqual ( 0 ) ;
37
+ expect ( state . runningList . length ) . toEqual ( 0 )
25
38
let action = {
26
39
type : 'REFRESH_RUNNING_CONTAINERS' ,
27
- payload : [ { cid : '123' } , { cid : '456' } ]
28
- } ;
29
- let newState = containerListReducer ( state , action ) ;
30
- expect ( newState . runningList . length ) . toEqual ( 2 ) ;
40
+ payload : [ { cid : '123' } , { cid : '456' } ] ,
41
+ }
42
+ let newState = containerListReducer ( state , action )
43
+ expect ( newState . runningList . length ) . toEqual ( 2 )
31
44
32
45
action = {
33
46
type : 'REFRESH_RUNNING_CONTAINERS' ,
34
- payload : [ { cid : '789' } ]
35
- } ;
36
- newState = containerListReducer ( state , action ) ;
37
- expect ( newState . runningList . length ) . toEqual ( 1 ) ;
38
- expect ( newState . runningList [ 0 ] . cid ) . toEqual (
39
- '789'
40
- ) ;
41
- } ) ;
42
- } ) ;
47
+ payload : [ { cid : '789' } ] ,
48
+ }
49
+ newState = containerListReducer ( state , action )
50
+ expect ( newState . runningList . length ) . toEqual ( 1 )
51
+ expect ( newState . runningList [ 0 ] . cid ) . toEqual ( '789' )
52
+ } )
53
+ } )
43
54
44
55
describe ( 'REFRESH_STOPPED_CONTAINERS' , ( ) => {
45
56
test ( 'should overwrite the stoppedList array in the state to update it' , ( ) => {
46
- expect ( state . stoppedList . length ) . toEqual ( 0 ) ;
57
+ expect ( state . stoppedList . length ) . toEqual ( 0 )
47
58
let action = {
48
59
type : 'REFRESH_STOPPED_CONTAINERS' ,
49
- payload : [ { cid : '123' } , { cid : '456' } ]
50
- } ;
51
- let newState = containerListReducer ( state , action ) ;
52
- expect ( newState . stoppedList . length ) . toEqual ( 2 ) ;
60
+ payload : [ { cid : '123' } , { cid : '456' } ] ,
61
+ }
62
+ let newState = containerListReducer ( state , action )
63
+ expect ( newState . stoppedList . length ) . toEqual ( 2 )
53
64
54
65
action = {
55
66
type : 'REFRESH_STOPPED_CONTAINERS' ,
56
- payload : [ { cid : '789' } ]
57
- } ;
58
- newState = containerListReducer ( state , action ) ;
59
- expect ( newState . stoppedList . length ) . toEqual ( 1 ) ;
60
- expect ( newState . stoppedList [ 0 ] . cid ) . toEqual (
61
- '789'
62
- ) ;
63
- } ) ;
64
- } ) ;
67
+ payload : [ { cid : '789' } ] ,
68
+ }
69
+ newState = containerListReducer ( state , action )
70
+ expect ( newState . stoppedList . length ) . toEqual ( 1 )
71
+ expect ( newState . stoppedList [ 0 ] . cid ) . toEqual ( '789' )
72
+ } )
73
+ } )
65
74
66
75
describe ( 'REFRESH_IMAGES' , ( ) => {
67
76
test ( 'should overwrite the imagesList array in the state to update it' , ( ) => {
68
- expect ( state . imagesList . length ) . toEqual ( 0 ) ;
77
+ expect ( state . imagesList . length ) . toEqual ( 0 )
69
78
let action = {
70
79
type : 'REFRESH_IMAGES' ,
71
- payload : [ { imgid : '123' } , { imgid : '456' } ]
72
- } ;
73
- expect ( imageListReducer ( state , action ) . imagesList . length ) . toEqual ( 2 ) ;
74
- action = { type : 'REFRESH_IMAGES' , payload : [ { imgid : '789' } ] } ;
75
- expect ( imageListReducer ( state , action ) . imagesList . length ) . toEqual ( 1 ) ;
76
- expect ( imageListReducer ( state , action ) . imagesList [ 0 ] . imgid ) . toEqual ( '789' ) ;
77
- } ) ;
78
- } ) ;
80
+ payload : [ { imgid : '123' } , { imgid : '456' } ] ,
81
+ }
82
+ expect ( imageListReducer ( state , action ) . imagesList . length ) . toEqual ( 2 )
83
+ action = { type : 'REFRESH_IMAGES' , payload : [ { imgid : '789' } ] }
84
+ expect ( imageListReducer ( state , action ) . imagesList . length ) . toEqual ( 1 )
85
+ expect ( imageListReducer ( state , action ) . imagesList [ 0 ] . imgid ) . toEqual ( '789' )
86
+ } )
87
+ } )
79
88
80
89
describe ( 'REMOVE_CONTAINER' , ( ) => {
81
90
test ( 'should remove the specified container from the stoppedList array in the state' , ( ) => {
82
91
const newState = {
83
- stoppedList : [ { ID : '123' } , { ID : '456' } ]
84
- } ;
85
- const action = { type : 'REMOVE_CONTAINER' , payload : '123' } ;
86
- const storedValue = containerListReducer ( newState , action ) ;
87
- expect ( storedValue . stoppedList [ 0 ] . ID ) . toEqual (
88
- '456'
89
- ) ;
90
- } ) ;
91
- } ) ;
92
+ stoppedList : [ { ID : '123' } , { ID : '456' } ] ,
93
+ }
94
+ const action = { type : 'REMOVE_CONTAINER' , payload : '123' }
95
+ const storedValue = containerListReducer ( newState , action )
96
+ expect ( storedValue . stoppedList [ 0 ] . ID ) . toEqual ( '456' )
97
+ } )
98
+ } )
92
99
93
100
describe ( 'STOP_RUNNING_CONTAINER' , ( ) => {
94
101
test ( 'should remove a specified container from the runningList and add it to the stoppedList' , ( ) => {
95
102
let newState = {
96
103
runningList : [ { ID : '123' } , { ID : '456' } ] ,
97
- stoppedList : [ ]
98
- } ;
99
- const action = { type : 'STOP_RUNNING_CONTAINER' , payload : '123' } ;
100
- newState = containerListReducer ( newState , action ) ;
101
- expect ( newState . runningList [ 0 ] . ID ) . toEqual ( '456' ) ;
102
- } ) ;
103
- } ) ;
104
+ stoppedList : [ ] ,
105
+ }
106
+ const action = { type : 'STOP_RUNNING_CONTAINER' , payload : '123' }
107
+ newState = containerListReducer ( newState , action )
108
+ expect ( newState . runningList [ 0 ] . ID ) . toEqual ( '456' )
109
+ } )
110
+ } )
104
111
105
112
describe ( 'RUN_STOPPED_CONTAINER' , ( ) => {
106
113
test ( 'should remove a specified container from the stoppedList' , ( ) => {
107
114
const newState = {
108
115
runningList : [ ] ,
109
- stoppedList : [ { ID : '123' } , { ID : '456' } ]
110
- } ;
111
- const action = { type : 'RUN_STOPPED_CONTAINER' , payload : '123' } ;
116
+ stoppedList : [ { ID : '123' } , { ID : '456' } ] ,
117
+ }
118
+ const action = { type : 'RUN_STOPPED_CONTAINER' , payload : '123' }
112
119
expect ( containerListReducer ( newState , action ) . stoppedList [ 0 ] . ID ) . toEqual (
113
- '456'
114
- ) ;
115
- } ) ;
116
- } ) ;
120
+ '456' ,
121
+ )
122
+ } )
123
+ } )
117
124
118
125
describe ( 'REMOVE_IMAGE' , ( ) => {
119
126
test ( 'should remove a specified image from the imagesList' , ( ) => {
120
127
const newState = {
121
- imagesList : [ { id : '123' } , { id : '456' } ]
122
- } ;
123
- const action = { type : 'REMOVE_IMAGE' , payload : '123' } ;
124
- expect ( imageListReducer ( newState , action ) . imagesList [ 0 ] . id ) . toEqual ( '456' ) ;
125
- } ) ;
126
- } ) ;
127
- } ) ;
128
+ imagesList : [ { id : '123' } , { id : '456' } ] ,
129
+ }
130
+ const action = { type : 'REMOVE_IMAGE' , payload : '123' }
131
+ expect ( imageListReducer ( newState , action ) . imagesList [ 0 ] . id ) . toEqual ( '456' )
132
+ } )
133
+ } )
134
+ } )
0 commit comments