@@ -3,6 +3,7 @@ import { State, Action } from '../app/src/interfaces/Interfaces';
3
3
4
4
import { initialState } from '../app/src/redux/reducers/slice/appStateSlice' ; //does not exist
5
5
import { iterate } from 'localforage' ;
6
+ import { ConstructionOutlined } from '@mui/icons-material' ;
6
7
7
8
describe ( 'Testing componentReducer functionality' , ( ) => {
8
9
let state : State = initialState ;
@@ -14,7 +15,10 @@ describe('Testing componentReducer functionality', () => {
14
15
type : 'appState/addComponent' ,
15
16
payload : {
16
17
componentName : 'TestRegular' ,
17
- root : false
18
+ root : false ,
19
+ contextParam : {
20
+ allContext : [ ]
21
+ }
18
22
}
19
23
} ;
20
24
state = reducer ( state , action ) ;
@@ -29,14 +33,17 @@ describe('Testing componentReducer functionality', () => {
29
33
} ) ;
30
34
31
35
// TEST 'ADD COMPONENT' with new root
32
- describe ( 'ADD COMPONENT reducer' , ( ) => {
36
+ describe ( 'addComponent reducer' , ( ) => {
33
37
it ( 'should add new reuseable component to state as the new root' , ( ) => {
34
38
const action : Action = {
35
39
type : 'appState/addComponent' ,
36
40
payload : {
37
41
componentName : 'TestRootChange' ,
38
42
id : 3 ,
39
- root : true
43
+ root : true ,
44
+ contextParam : {
45
+ allContext : [ ]
46
+ }
40
47
}
41
48
} ;
42
49
state = reducer ( state , action ) ;
@@ -52,18 +59,21 @@ describe('Testing componentReducer functionality', () => {
52
59
} ) ;
53
60
54
61
// TEST 'ADD CHILD'
55
- xdescribe ( 'ADD CHILD reducer', ( ) => {
62
+ describe ( 'addChild reducer', ( ) => {
56
63
it ( 'should add child component and separator to top-level component' , ( ) => {
57
64
const action : Action = {
58
- type : 'ADD CHILD ' ,
65
+ type : 'appState/addChild ' ,
59
66
payload : {
60
67
type : 'Component' ,
61
68
typeId : 2 ,
62
- childId : null
69
+ childId : null ,
70
+ contextParam : {
71
+ allContext : [ ]
72
+ }
63
73
}
64
74
} ;
65
75
// switch focus to very first root component
66
- state . canvasFocus = { componentId : 1 , childId : null } ;
76
+ // state.canvasFocus = { componentId: 1, childId: null };
67
77
state = reducer ( state , action ) ;
68
78
const newParent = state . components [ 0 ] ;
69
79
// expect new parent's children array to have length 2 (component + separator)
@@ -81,25 +91,35 @@ describe('Testing componentReducer functionality', () => {
81
91
} ) ;
82
92
83
93
// TEST 'CHANGE POSITION'
84
- xdescribe ( 'CHANGE POSITION reducer ' , ( ) => {
94
+ describe ( 'CHANGE POSITION reducer ' , ( ) => {
85
95
it ( 'should move position of an instance' , ( ) => {
86
96
const actionHtml : Action = {
87
- type : 'ADD CHILD ' ,
97
+ type : 'appState/addChild ' ,
88
98
payload : {
89
99
type : 'HTML Element' ,
90
100
typeId : 9 ,
91
- childId : null
101
+ childId : null ,
102
+ contextParam : {
103
+ allContext : [ ]
104
+ }
92
105
}
93
106
} ;
94
107
state = reducer ( state , actionHtml ) ;
95
108
const actionChangePos : Action = {
96
- type : 'CHANGE POSITION ' ,
109
+ type : 'appState/changePosition ' ,
97
110
payload : {
98
111
currentChildId : 1 ,
99
- newParentChildId : null
112
+ newParentChildId : null ,
113
+ contextParam : {
114
+ allContext : [ ]
115
+ }
100
116
}
101
117
} ;
118
+
119
+ console . log ( 'state.components' , state . components ) ;
102
120
state = reducer ( state , actionChangePos ) ;
121
+ console . log ( 'state.canvasfocus after reducer' , state . canvasFocus ) ;
122
+ console . log ( 'state.components' , state . components ) ;
103
123
const changeParent = state . components . find (
104
124
( comp ) => comp . id === state . canvasFocus . componentId
105
125
) ;
@@ -116,11 +136,17 @@ describe('Testing componentReducer functionality', () => {
116
136
} ) ;
117
137
118
138
// TEST 'DELETE CHILD'
119
- xdescribe ( 'DELETE CHILD reducer' , ( ) => {
139
+ describe ( 'DELETE CHILD reducer' , ( ) => {
120
140
it ( 'should delete child of focused top-level component' , ( ) => {
121
141
// canvas still focused on childId: 2, which is an HTML element
122
142
const action : Action = {
123
- type : 'DELETE CHILD'
143
+ type : 'appState/deleteChild' ,
144
+ payload : {
145
+ id : 2 ,
146
+ contextParam : {
147
+ allContext : [ ]
148
+ }
149
+ }
124
150
} ;
125
151
state = reducer ( state , action ) ;
126
152
// expect only one remaining child
@@ -139,10 +165,10 @@ describe('Testing componentReducer functionality', () => {
139
165
} ) ;
140
166
141
167
// TEST 'CHANGE FOCUS'
142
- xdescribe ( 'CHANGE FOCUS reducer' , ( ) => {
168
+ describe ( 'CHANGE FOCUS reducer' , ( ) => {
143
169
it ( 'should change focus to specified component' , ( ) => {
144
170
const action : Action = {
145
- type : 'CHANGE FOCUS ' ,
171
+ type : 'appState/changeFocus ' ,
146
172
payload : {
147
173
componentId : 2 ,
148
174
childId : null
@@ -155,13 +181,16 @@ describe('Testing componentReducer functionality', () => {
155
181
} ) ;
156
182
157
183
// TEST 'UPDATE CSS'
158
- xdescribe ( 'UPDATE CSS reducer', ( ) => {
184
+ describe ( 'updateCss reducer', ( ) => {
159
185
it ( 'should add style to focused component' , ( ) => {
160
186
const action : Action = {
161
- type : 'UPDATE CSS ' ,
187
+ type : 'appState/updateCss ' ,
162
188
payload : {
163
189
style : {
164
190
backgroundColor : 'gray'
191
+ } ,
192
+ contextParam : {
193
+ allContext : [ ]
165
194
}
166
195
}
167
196
} ;
@@ -177,10 +206,10 @@ describe('Testing componentReducer functionality', () => {
177
206
} ) ;
178
207
179
208
// TEST 'UPDATE PROJECT NAME'
180
- xdescribe ( 'UPDATE PROJECT NAME reducer', ( ) => {
209
+ describe ( 'updateProjectName reducer', ( ) => {
181
210
it ( 'should update project with specified name' , ( ) => {
182
211
const action : Action = {
183
- type : 'UPDATE PROJECT NAME ' ,
212
+ type : 'appState/updateProjectName ' ,
184
213
payload : 'TESTNAME'
185
214
} ;
186
215
state = reducer ( state , action ) ;
@@ -190,12 +219,15 @@ describe('Testing componentReducer functionality', () => {
190
219
} ) ;
191
220
192
221
// TEST 'CHANGE PROJECT TYPE'
193
- xdescribe ( 'CHANGE PROJECT TYPE reducer', ( ) => {
222
+ describe ( 'changeProjectType reducer', ( ) => {
194
223
it ( 'should change project type to specified type' , ( ) => {
195
224
const action : Action = {
196
- type : 'CHANGE PROJECT TYPE ' ,
225
+ type : 'appState/changeProjectType ' ,
197
226
payload : {
198
- projectType : 'Classic React'
227
+ projectType : 'Classic React' ,
228
+ contextParam : {
229
+ allContext : [ ]
230
+ }
199
231
}
200
232
} ;
201
233
state = reducer ( state , action ) ;
@@ -204,7 +236,7 @@ describe('Testing componentReducer functionality', () => {
204
236
} ) ;
205
237
206
238
// TEST 'UNDO'
207
- xdescribe ( 'UNDO reducer', ( ) => {
239
+ describe ( 'undo reducer', ( ) => {
208
240
it ( 'should remove the last element from the past array and push it to the future array' , ( ) => {
209
241
const focusIndex = state . canvasFocus . componentId - 1 ;
210
242
state . components [ focusIndex ] . past = [ ] ;
@@ -220,7 +252,7 @@ describe('Testing componentReducer functionality', () => {
220
252
} ;
221
253
222
254
const actionHTML2 : Action = {
223
- type : 'ADD CHILD ' ,
255
+ type : 'appState/addChild ' ,
224
256
payload : {
225
257
type : 'HTML Element' ,
226
258
typeId : 4 ,
@@ -232,7 +264,7 @@ describe('Testing componentReducer functionality', () => {
232
264
snapShotFuncCopy ( ) ;
233
265
234
266
const actionUndo : Action = {
235
- type : 'UNDO ' ,
267
+ type : 'appState/undo ' ,
236
268
payload : { }
237
269
} ;
238
270
state = reducer ( state , actionUndo ) ;
@@ -242,11 +274,11 @@ describe('Testing componentReducer functionality', () => {
242
274
} ) ;
243
275
} ) ;
244
276
// TEST 'REDO'
245
- xdescribe ( 'REDO reducer', ( ) => {
277
+ describe ( 'redo reducer', ( ) => {
246
278
it ( 'should remove the last element from the future array and push it to the past array' , ( ) => {
247
279
const focusIndex = state . canvasFocus . componentId - 1 ;
248
280
const actionRedo : Action = {
249
- type : 'REDO ' ,
281
+ type : 'appState/redo ' ,
250
282
payload : { }
251
283
} ;
252
284
state = reducer ( state , actionRedo ) ;
@@ -255,10 +287,10 @@ describe('Testing componentReducer functionality', () => {
255
287
} ) ;
256
288
} ) ;
257
289
// TEST 'RESET STATE'
258
- xdescribe ( 'RESET STATE reducer', ( ) => {
290
+ describe ( 'resetState reducer', ( ) => {
259
291
it ( 'should reset project to initial state' , ( ) => {
260
292
const action : Action = {
261
- type : 'RESET STATE ' ,
293
+ type : 'appState/resetState ' ,
262
294
payload : ''
263
295
} ;
264
296
state = reducer ( state , action ) ;
0 commit comments