1
- import reducer from '../app/src/reducers/componentReducer' ; //does not exist
2
- //
3
- import initialState from '../app/src/context/initialState' ; //does not exist
1
+ import reducer from '../app/src/redux/reducers/slice/appStateSlice' ;
2
+ import { initialState } from '../app/src/redux/reducers/slice/appStateSlice' ;
4
3
5
- xdescribe ( 'Testing componentReducer functionality for stateManagement tab' , ( ) => {
4
+ let state = JSON . parse ( JSON . stringify ( initialState ) ) ;
5
+ state . components = [
6
+ {
7
+ id : 1 ,
8
+ name : 'App' ,
9
+ style : { } ,
10
+ code : "import React, { useState, useEffect, useContext} from 'react';\n\n\n\nimport C1 from './C1'\nconst App = (props) => {\n\n\n const [appState, setAppState] = useState<number | undefined>(1);\n\n return(\n <>\n<C1 id = \"1\" />\n </>\n );\n}\n\nexport default App\n" ,
11
+ children : [
12
+ {
13
+ type : 'HTML Element' ,
14
+ typeId : 1000 ,
15
+ name : 'separator' ,
16
+ childId : 1000 ,
17
+ style : { border : 'none' } ,
18
+ attributes : { } ,
19
+ children : [ ]
20
+ } ,
21
+ {
22
+ type : 'Component' ,
23
+ typeId : 2 ,
24
+ name : 'C1' ,
25
+ childId : 1 ,
26
+ style : { } ,
27
+ attributes : { } ,
28
+ children : [ ] ,
29
+ stateProps : [ ] ,
30
+ passedInProps : [ ]
31
+ }
32
+ ] ,
33
+ isPage : true ,
34
+ past : [ [ ] ] ,
35
+ future : [ ] ,
36
+ stateProps : [ ] ,
37
+ useStateCodes : [
38
+ 'const [appState, setAppState] = useState<number | undefined>(1)'
39
+ ]
40
+ } ,
41
+ {
42
+ id : 2 ,
43
+ name : 'C1' ,
44
+ nextChildId : 1 ,
45
+ style : { } ,
46
+ attributes : { } ,
47
+ code : "import React, { useState, useEffect, useContext} from 'react';\n\n\n\n\nconst C1 = (props) => {\n\n\n\n return(\n <>\n\n </>\n );\n}\n\nexport default C1\n" ,
48
+ children : [ ] ,
49
+ isPage : false ,
50
+ past : [ ] ,
51
+ future : [ ] ,
52
+ stateProps : [ ] ,
53
+ useStateCodes : [ ] ,
54
+ passedInProps : [ ]
55
+ }
56
+ ] ;
57
+
58
+ describe ( 'Testing componentReducer functionality for stateManagement tab' , ( ) => {
6
59
const findComponent = ( components , componentId ) => {
7
60
return components . find ( ( elem ) => elem . id === componentId ) ;
8
61
} ;
9
62
10
- let state = initialState ;
11
-
12
- // setting up initial state
13
- state . components = [
14
- {
15
- id : 1 ,
16
- name : 'App' ,
17
- style : { } ,
18
- code : "import React, { useState, useEffect, useContext} from 'react';\n\n\n\nimport C1 from './C1'\nconst App = (props) => {\n\n\n const [appState, setAppState] = useState<number | undefined>(1);\n\n return(\n <>\n<C1 id = \"1\" />\n </>\n );\n}\n\nexport default App\n" ,
19
- children : [
20
- {
21
- type : 'HTML Element' ,
22
- typeId : 1000 ,
23
- name : 'separator' ,
24
- childId : 1000 ,
25
- style : { border : 'none' } ,
26
- attributes : { } ,
27
- children : [ ]
28
- } ,
29
- {
30
- type : 'Component' ,
31
- typeId : 2 ,
32
- name : 'C1' ,
33
- childId : 1 ,
34
- style : { } ,
35
- attributes : { } ,
36
- children : [ ] ,
37
- stateProps : [ ] ,
38
- passedInProps : [ ]
39
- }
40
- ] ,
41
- isPage : true ,
42
- past : [ [ ] ] ,
43
- future : [ ] ,
44
- stateProps : [ ] ,
45
- useStateCodes : [
46
- 'const [appState, setAppState] = useState<number | undefined>(1)'
47
- ]
48
- } ,
49
- {
50
- id : 2 ,
51
- name : 'C1' ,
52
- nextChildId : 1 ,
53
- style : { } ,
54
- attributes : { } ,
55
- code : "import React, { useState, useEffect, useContext} from 'react';\n\n\n\n\nconst C1 = (props) => {\n\n\n\n return(\n <>\n\n </>\n );\n}\n\nexport default C1\n" ,
56
- children : [ ] ,
57
- isPage : false ,
58
- past : [ ] ,
59
- future : [ ] ,
60
- stateProps : [ ] ,
61
- useStateCodes : [ ] ,
62
- passedInProps : [ ]
63
- }
64
- ] ;
65
-
66
63
// TEST 'ADD STATE'
67
- describe ( 'ADD STATE test' , ( ) => {
64
+ describe ( 'addState test' , ( ) => {
68
65
// setting canvas focus to root component (App)
69
- state . canvasFocus . componentId = 1 ;
70
-
66
+ // state.canvasFocus.componentId = 1;
71
67
// action dispatched to be tested
72
68
const action = {
73
- type : 'ADD STATE ' ,
69
+ type : 'appState/addState ' ,
74
70
payload : {
75
71
newState : {
76
72
id : 'App-testAppState' ,
@@ -83,6 +79,9 @@ xdescribe('Testing componentReducer functionality for stateManagement tab', () =
83
79
key : 'setTestAppState' ,
84
80
type : 'func' ,
85
81
value : ''
82
+ } ,
83
+ contextParam : {
84
+ allContext : [ ]
86
85
}
87
86
}
88
87
} ;
@@ -123,23 +122,28 @@ xdescribe('Testing componentReducer functionality for stateManagement tab', () =
123
122
// TEST 'ADD PASSEDINPROPS'
124
123
describe ( 'ADD PASSEDINPROPS test' , ( ) => {
125
124
// setting canvas focus to the child component
125
+ state = JSON . parse ( JSON . stringify ( state ) ) ;
126
126
state . canvasFocus . componentId = 2 ;
127
127
128
128
// action dispatched to be tested
129
129
const action = {
130
- type : 'ADD PASSEDINPROPS ' ,
130
+ type : 'appState/addPassedInProps ' ,
131
131
payload : {
132
132
passedInProps : {
133
133
id : 'App-testAppState' ,
134
134
key : 'testAppState' ,
135
135
type : 'number' ,
136
136
value : 1
137
+ } ,
138
+ contextParam : {
139
+ allContext : [ ]
137
140
}
138
141
}
139
142
} ;
140
143
141
144
// setting test state
142
145
state = reducer ( state , action ) ;
146
+ console . log ( 'state.components' , state . components ) ;
143
147
const currComponent = findComponent ( state . components , 2 ) ;
144
148
const parentComponent = findComponent ( state . components , 1 ) ;
145
149
@@ -184,12 +188,18 @@ xdescribe('Testing componentReducer functionality for stateManagement tab', () =
184
188
describe ( 'DELETE PASSEDINPROPS test' , ( ) => {
185
189
it ( 'should delete the state passed down from parent component in the child component' , ( ) => {
186
190
// setting canvas focus to the child component
191
+ state = JSON . parse ( JSON . stringify ( state ) ) ;
187
192
state . canvasFocus . componentId = 2 ;
188
193
189
194
// action dispatched to be tested
190
195
const action = {
191
- type : 'DELETE PASSEDINPROPS' ,
192
- payload : { rowId : 'App-testAppState' }
196
+ type : 'appState/deletePassedInProps' ,
197
+ payload : {
198
+ rowId : 'App-testAppState' ,
199
+ contextParam : {
200
+ allContext : [ ]
201
+ }
202
+ }
193
203
} ;
194
204
195
205
// setting test state
@@ -206,15 +216,19 @@ xdescribe('Testing componentReducer functionality for stateManagement tab', () =
206
216
describe ( 'DELETE STATE test' , ( ) => {
207
217
it ( 'should delete all instances of state from stateProps and passedInProps' , ( ) => {
208
218
// setting canvas focus to root component
219
+ state = JSON . parse ( JSON . stringify ( state ) ) ;
209
220
state . canvasFocus . componentId = 1 ;
210
221
211
222
// action dispatched to be tested
212
223
const action = {
213
- type : 'DELETE STATE ' ,
224
+ type : 'appState/deleteState ' ,
214
225
payload : {
215
226
stateProps : [ ] ,
216
227
rowId : 'App-appState' ,
217
- otherId : 'App-setAppState'
228
+ otherId : 'App-setAppState' ,
229
+ contextParam : {
230
+ allContext : [ ]
231
+ }
218
232
}
219
233
} ;
220
234
0 commit comments