@@ -10,7 +10,6 @@ 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 ) ;
14
13
} ) ;
15
14
16
15
describe ( 'toggleComponentClass' , ( ) => {
@@ -70,6 +69,7 @@ describe('Left reducers', () => {
70
69
type : types . CHANGE_FOCUS_COMPONENT ,
71
70
payload : { title : 'TEST' }
72
71
} ;
72
+ state . components . push ( testComponent ) ;
73
73
const newState = reducers . changeFocusComponent ( state , action . payload ) ;
74
74
// expecting new payload of "title" to the payload we just created
75
75
expect ( newState . focusComponent . title ) . toEqual ( action . payload . title ) ;
@@ -90,22 +90,87 @@ describe('Left reducers', () => {
90
90
} ) ;
91
91
92
92
// TEST DELETE CHILD: test child should be deleted from local state components array
93
- // describe('deleteChild reducer', () => {
94
- // it('should delete test component', () => {
95
- // // CHANGE FOCUS COMPONENT FIRST
96
- // // const action = {
97
- // // type: types.CHANGE_FOCUS_COMPONENT,
98
- // // payload: { title: 'TEST' }
99
- // // };
100
- // // const newState = reducers.changeFocusComponent(state, action.payload);
101
- // const prevState = cloneDeep(state);
102
- // console.log('this is prevState', prevState)
103
- // const newState = reducers.deleteChild(state, {});
104
- // // expecting new payload of "title" to the payload we just created
105
- // expect(prevState.focusComponent.childrenArray).not.toEqual(
106
- // newState.focusComponent.childrenArray
107
- // );
108
- // });
109
- } ) ;
93
+ describe ( 'deleteChild reducer' , ( ) => {
94
+ it ( 'should delete test component' , ( ) => {
95
+ // grab initial copy of current state
96
+ const prevState = cloneDeep ( state ) ;
97
+ // push into it the test component
98
+ prevState . focusComponent . childrenArray . push ( testComponent ) ;
99
+
100
+ //take new state and delete from it the testComponent
101
+ const newState = reducers . deleteChild ( state , { } ) ;
102
+
103
+ // expecting previous state not to equal new state after deletion of test component
104
+ expect ( prevState . focusComponent . childrenArray ) . not . toEqual (
105
+ newState . focusComponent . childrenArray
106
+ ) ;
107
+ } ) ;
108
+ } ) ;
109
+ // TEST ADD COMPONENT: adds component to the global state components array
110
+ describe ( 'addComponent reducer' , ( ) => {
111
+ it ( 'return the state as it was if an empty title' , ( ) => {
112
+ const action = {
113
+ type : types . ADD_COMPONENT ,
114
+ payload : { title : '' }
115
+ } ;
116
+ // grab initial copy of current state
117
+ const prevState = cloneDeep ( state ) ;
110
118
111
- // NEXT TEST
119
+ //take new state and add testComponent
120
+ const newState = reducers . addComponent ( state , action . payload ) ;
121
+ // expecting previous state not to equal new state after deletion of test component
122
+ expect ( prevState . components [ 2 ] ) . toEqual ( newState . components [ 2 ] ) ;
123
+ } ) ;
124
+
125
+ it ( 'should add test component' , ( ) => {
126
+ const action = {
127
+ type : types . ADD_COMPONENT ,
128
+ payload : { title : 'TESTCOMPONENT' }
129
+ } ;
130
+ // grab initial copy of current state
131
+ const prevState = cloneDeep ( state ) ;
132
+
133
+ //take new state and add testComponent
134
+ const newState = reducers . addComponent ( prevState , action . payload ) ;
135
+
136
+ // expecting previous state not to equal new state after deletion of test component
137
+ expect ( prevState . components [ 2 ] ) . not . toEqual ( newState . components [ 2 ] ) ;
138
+ } ) ;
139
+ } ) ;
140
+ // TEST ADD CHILD: adds child to the focus component's childrenArray
141
+ describe ( 'addChild reducer' , ( ) => {
142
+ it ( 'return focus component childrenarray with test react component' , ( ) => {
143
+ const actionReact = {
144
+ type : types . ADD_CHILD ,
145
+ payload : {
146
+ title : 'TestREACTComponent' ,
147
+ childType : 'COMP'
148
+ }
149
+ } ;
150
+
151
+ state = reducers . addComponent ( state , { title : 'TestREACTComponent' } ) ;
152
+ const newState = reducers . addChild ( state , actionReact . payload ) ;
153
+
154
+ expect ( state . focusComponent . childrenArray ) . not . toEqual (
155
+ newState . focusComponent . childrenArray
156
+ ) ;
157
+ } ) ;
158
+
159
+ it ( 'return focus component childrenarray with test HTML component' , ( ) => {
160
+ const actionHTML = {
161
+ type : types . ADD_CHILD ,
162
+ payload : {
163
+ title : 'TestHTMLComponent' ,
164
+ childType : 'HTML'
165
+ }
166
+ } ;
167
+
168
+ state = reducers . addComponent ( state , { title : 'TestHTMLComponent' } ) ;
169
+ const newState = reducers . addChild ( state , actionHTML . payload ) ;
170
+
171
+ expect ( state . focusComponent . childrenArray ) . not . toEqual (
172
+ newState . focusComponent . childrenArray
173
+ ) ;
174
+ } ) ;
175
+ } ) ;
176
+ } ) ;
0 commit comments