@@ -10,6 +10,7 @@ describe('Left reducers', () => {
10
10
// redefine the default state before each reducer test
11
11
beforeEach ( ( ) => {
12
12
state = initialApplicationState ;
13
+ // state.components.push(testComponent);
13
14
} ) ;
14
15
15
16
// TEST CHANGE FOCUS COMPONENT: test component will add "look" for "test" after it's added
@@ -19,6 +20,8 @@ describe('Left reducers', () => {
19
20
type : types . CHANGE_FOCUS_COMPONENT ,
20
21
payload : { title : 'TEST' }
21
22
} ;
23
+
24
+ state . components . push ( testComponent ) ;
22
25
const newState = reducers . changeFocusComponent ( state , action . payload ) ;
23
26
// expecting new payload of "title" to the payload we just created
24
27
expect ( newState . focusComponent . title ) . toEqual ( action . payload . title ) ;
@@ -38,31 +41,14 @@ describe('Left reducers', () => {
38
41
} ) ;
39
42
} ) ;
40
43
41
- // TEST DELETE CHILD: test child should be deleted from local state components array
42
- // describe('deleteChild reducer', () => {
43
- // it('should delete test component', () => {
44
- // // const action = {
45
- // // type: types.CHANGE_IMAGE_SOURCE,
46
- // // payload: { imageSource: 'www.test.com/test.img' }
47
- // // };
48
- // const model = {
49
- // parentId = state.focusComponent.id,
50
- // childId = state.focusChild.childId,
51
- // calledFromDeleteComponent = false
52
- // };
53
- // const newState = reducers.deleteChild();
54
- // // expecting new payload of "title" to the payload we just created
55
- // expect(newState.imageSource).toEqual(action.payload.imageSource);
56
- // });
57
- // });
58
- // NEXT TEST
59
-
60
44
describe ( 'editComponent' , ( ) => {
61
45
it ( 'should change the name of the component' , ( ) => {
62
46
const test = {
63
47
id : 19 , //this id is established in the testComponent
64
48
title : 'Edited'
65
49
} ;
50
+
51
+ state . components . push ( testComponent ) ;
66
52
const newState = reducers . editComponent ( state , test ) ;
67
53
68
54
// find the updated component in the state returned above
@@ -209,13 +195,15 @@ describe('Left reducers', () => {
209
195
) ;
210
196
} ) ;
211
197
} ) ;
198
+
212
199
// TEST ADD COMPONENT: adds component to the global state components array
213
200
describe ( 'addComponent reducer' , ( ) => {
214
201
it ( 'return the state as it was if an empty title' , ( ) => {
215
202
const action = {
216
203
type : types . ADD_COMPONENT ,
217
204
payload : { title : '' }
218
205
} ;
206
+
219
207
// grab initial copy of current state
220
208
const prevState = cloneDeep ( state ) ;
221
209
@@ -237,7 +225,9 @@ describe('Left reducers', () => {
237
225
const newState = reducers . addComponent ( prevState , action . payload ) ;
238
226
239
227
// expecting previous state not to equal new state after deletion of test component
240
- expect ( prevState . components [ 2 ] ) . not . toEqual ( newState . components [ 2 ] ) ;
228
+ expect ( prevState . components [ prevState . components . length - 1 ] ) . not . toEqual (
229
+ newState . components [ newState . components . length - 1 ]
230
+ ) ;
241
231
} ) ;
242
232
} ) ;
243
233
// TEST ADD CHILD: adds child to the focus component's childrenArray
0 commit comments