Skip to content

Commit c4d938e

Browse files
committed
Fixed issues with left reducers
1 parent 697eac6 commit c4d938e

File tree

1 file changed

+10
-20
lines changed

1 file changed

+10
-20
lines changed

src/reducers/__tests__/leftReducers.test.ts

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ describe('Left reducers', () => {
1010
// redefine the default state before each reducer test
1111
beforeEach(() => {
1212
state = initialApplicationState;
13+
// state.components.push(testComponent);
1314
});
1415

1516
// TEST CHANGE FOCUS COMPONENT: test component will add "look" for "test" after it's added
@@ -19,6 +20,8 @@ describe('Left reducers', () => {
1920
type: types.CHANGE_FOCUS_COMPONENT,
2021
payload: { title: 'TEST' }
2122
};
23+
24+
state.components.push(testComponent);
2225
const newState = reducers.changeFocusComponent(state, action.payload);
2326
// expecting new payload of "title" to the payload we just created
2427
expect(newState.focusComponent.title).toEqual(action.payload.title);
@@ -38,31 +41,14 @@ describe('Left reducers', () => {
3841
});
3942
});
4043

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-
6044
describe('editComponent', () => {
6145
it('should change the name of the component', () => {
6246
const test = {
6347
id: 19, //this id is established in the testComponent
6448
title: 'Edited'
6549
};
50+
51+
state.components.push(testComponent);
6652
const newState = reducers.editComponent(state, test);
6753

6854
// find the updated component in the state returned above
@@ -209,13 +195,15 @@ describe('Left reducers', () => {
209195
);
210196
});
211197
});
198+
212199
// TEST ADD COMPONENT: adds component to the global state components array
213200
describe('addComponent reducer', () => {
214201
it('return the state as it was if an empty title', () => {
215202
const action = {
216203
type: types.ADD_COMPONENT,
217204
payload: { title: '' }
218205
};
206+
219207
// grab initial copy of current state
220208
const prevState = cloneDeep(state);
221209

@@ -237,7 +225,9 @@ describe('Left reducers', () => {
237225
const newState = reducers.addComponent(prevState, action.payload);
238226

239227
// 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+
);
241231
});
242232
});
243233
// TEST ADD CHILD: adds child to the focus component's childrenArray

0 commit comments

Comments
 (0)