Skip to content

Commit 5ab6d67

Browse files
atvanekrachelk585sophia-buiMatteoDiter
committed
10/12 componentReducer tests pass
Co-authored-by: rachelk585 <[email protected]> Co-authored-by: Sophia Bui <[email protected]> Co-authored-by: Matteo <[email protected]>
1 parent 0f34623 commit 5ab6d67

File tree

5 files changed

+306
-200
lines changed

5 files changed

+306
-200
lines changed

__tests__/componentReducer.test.ts

Lines changed: 62 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { State, Action } from '../app/src/interfaces/Interfaces';
33

44
import { initialState } from '../app/src/redux/reducers/slice/appStateSlice'; //does not exist
55
import { iterate } from 'localforage';
6+
import { ConstructionOutlined } from '@mui/icons-material';
67

78
describe('Testing componentReducer functionality', () => {
89
let state: State = initialState;
@@ -14,7 +15,10 @@ describe('Testing componentReducer functionality', () => {
1415
type: 'appState/addComponent',
1516
payload: {
1617
componentName: 'TestRegular',
17-
root: false
18+
root: false,
19+
contextParam: {
20+
allContext: []
21+
}
1822
}
1923
};
2024
state = reducer(state, action);
@@ -29,14 +33,17 @@ describe('Testing componentReducer functionality', () => {
2933
});
3034

3135
// TEST 'ADD COMPONENT' with new root
32-
describe('ADD COMPONENT reducer', () => {
36+
describe('addComponent reducer', () => {
3337
it('should add new reuseable component to state as the new root', () => {
3438
const action: Action = {
3539
type: 'appState/addComponent',
3640
payload: {
3741
componentName: 'TestRootChange',
3842
id: 3,
39-
root: true
43+
root: true,
44+
contextParam: {
45+
allContext: []
46+
}
4047
}
4148
};
4249
state = reducer(state, action);
@@ -52,18 +59,21 @@ describe('Testing componentReducer functionality', () => {
5259
});
5360

5461
// TEST 'ADD CHILD'
55-
xdescribe('ADD CHILD reducer', () => {
62+
describe('addChild reducer', () => {
5663
it('should add child component and separator to top-level component', () => {
5764
const action: Action = {
58-
type: 'ADD CHILD',
65+
type: 'appState/addChild',
5966
payload: {
6067
type: 'Component',
6168
typeId: 2,
62-
childId: null
69+
childId: null,
70+
contextParam: {
71+
allContext: []
72+
}
6373
}
6474
};
6575
// switch focus to very first root component
66-
state.canvasFocus = { componentId: 1, childId: null };
76+
// state.canvasFocus = { componentId: 1, childId: null };
6777
state = reducer(state, action);
6878
const newParent = state.components[0];
6979
// expect new parent's children array to have length 2 (component + separator)
@@ -81,25 +91,35 @@ describe('Testing componentReducer functionality', () => {
8191
});
8292

8393
// TEST 'CHANGE POSITION'
84-
xdescribe('CHANGE POSITION reducer ', () => {
94+
describe('CHANGE POSITION reducer ', () => {
8595
it('should move position of an instance', () => {
8696
const actionHtml: Action = {
87-
type: 'ADD CHILD',
97+
type: 'appState/addChild',
8898
payload: {
8999
type: 'HTML Element',
90100
typeId: 9,
91-
childId: null
101+
childId: null,
102+
contextParam: {
103+
allContext: []
104+
}
92105
}
93106
};
94107
state = reducer(state, actionHtml);
95108
const actionChangePos: Action = {
96-
type: 'CHANGE POSITION',
109+
type: 'appState/changePosition',
97110
payload: {
98111
currentChildId: 1,
99-
newParentChildId: null
112+
newParentChildId: null,
113+
contextParam: {
114+
allContext: []
115+
}
100116
}
101117
};
118+
119+
console.log('state.components', state.components);
102120
state = reducer(state, actionChangePos);
121+
console.log('state.canvasfocus after reducer', state.canvasFocus);
122+
console.log('state.components', state.components);
103123
const changeParent = state.components.find(
104124
(comp) => comp.id === state.canvasFocus.componentId
105125
);
@@ -116,11 +136,17 @@ describe('Testing componentReducer functionality', () => {
116136
});
117137

118138
// TEST 'DELETE CHILD'
119-
xdescribe('DELETE CHILD reducer', () => {
139+
describe('DELETE CHILD reducer', () => {
120140
it('should delete child of focused top-level component', () => {
121141
// canvas still focused on childId: 2, which is an HTML element
122142
const action: Action = {
123-
type: 'DELETE CHILD'
143+
type: 'appState/deleteChild',
144+
payload: {
145+
id: 2,
146+
contextParam: {
147+
allContext: []
148+
}
149+
}
124150
};
125151
state = reducer(state, action);
126152
// expect only one remaining child
@@ -139,10 +165,10 @@ describe('Testing componentReducer functionality', () => {
139165
});
140166

141167
// TEST 'CHANGE FOCUS'
142-
xdescribe('CHANGE FOCUS reducer', () => {
168+
describe('CHANGE FOCUS reducer', () => {
143169
it('should change focus to specified component', () => {
144170
const action: Action = {
145-
type: 'CHANGE FOCUS',
171+
type: 'appState/changeFocus',
146172
payload: {
147173
componentId: 2,
148174
childId: null
@@ -155,13 +181,16 @@ describe('Testing componentReducer functionality', () => {
155181
});
156182

157183
// TEST 'UPDATE CSS'
158-
xdescribe('UPDATE CSS reducer', () => {
184+
describe('updateCss reducer', () => {
159185
it('should add style to focused component', () => {
160186
const action: Action = {
161-
type: 'UPDATE CSS',
187+
type: 'appState/updateCss',
162188
payload: {
163189
style: {
164190
backgroundColor: 'gray'
191+
},
192+
contextParam: {
193+
allContext: []
165194
}
166195
}
167196
};
@@ -177,10 +206,10 @@ describe('Testing componentReducer functionality', () => {
177206
});
178207

179208
// TEST 'UPDATE PROJECT NAME'
180-
xdescribe('UPDATE PROJECT NAME reducer', () => {
209+
describe('updateProjectName reducer', () => {
181210
it('should update project with specified name', () => {
182211
const action: Action = {
183-
type: 'UPDATE PROJECT NAME',
212+
type: 'appState/updateProjectName',
184213
payload: 'TESTNAME'
185214
};
186215
state = reducer(state, action);
@@ -190,12 +219,15 @@ describe('Testing componentReducer functionality', () => {
190219
});
191220

192221
// TEST 'CHANGE PROJECT TYPE'
193-
xdescribe('CHANGE PROJECT TYPE reducer', () => {
222+
describe('changeProjectType reducer', () => {
194223
it('should change project type to specified type', () => {
195224
const action: Action = {
196-
type: 'CHANGE PROJECT TYPE',
225+
type: 'appState/changeProjectType',
197226
payload: {
198-
projectType: 'Classic React'
227+
projectType: 'Classic React',
228+
contextParam: {
229+
allContext: []
230+
}
199231
}
200232
};
201233
state = reducer(state, action);
@@ -204,7 +236,7 @@ describe('Testing componentReducer functionality', () => {
204236
});
205237

206238
// TEST 'UNDO'
207-
xdescribe('UNDO reducer', () => {
239+
describe('undo reducer', () => {
208240
it('should remove the last element from the past array and push it to the future array', () => {
209241
const focusIndex = state.canvasFocus.componentId - 1;
210242
state.components[focusIndex].past = [];
@@ -220,7 +252,7 @@ describe('Testing componentReducer functionality', () => {
220252
};
221253

222254
const actionHTML2: Action = {
223-
type: 'ADD CHILD',
255+
type: 'appState/addChild',
224256
payload: {
225257
type: 'HTML Element',
226258
typeId: 4,
@@ -232,7 +264,7 @@ describe('Testing componentReducer functionality', () => {
232264
snapShotFuncCopy();
233265

234266
const actionUndo: Action = {
235-
type: 'UNDO',
267+
type: 'appState/undo',
236268
payload: {}
237269
};
238270
state = reducer(state, actionUndo);
@@ -242,11 +274,11 @@ describe('Testing componentReducer functionality', () => {
242274
});
243275
});
244276
// TEST 'REDO'
245-
xdescribe('REDO reducer', () => {
277+
describe('redo reducer', () => {
246278
it('should remove the last element from the future array and push it to the past array', () => {
247279
const focusIndex = state.canvasFocus.componentId - 1;
248280
const actionRedo: Action = {
249-
type: 'REDO',
281+
type: 'appState/redo',
250282
payload: {}
251283
};
252284
state = reducer(state, actionRedo);
@@ -255,10 +287,10 @@ describe('Testing componentReducer functionality', () => {
255287
});
256288
});
257289
// TEST 'RESET STATE'
258-
xdescribe('RESET STATE reducer', () => {
290+
describe('resetState reducer', () => {
259291
it('should reset project to initial state', () => {
260292
const action: Action = {
261-
type: 'RESET STATE',
293+
type: 'appState/resetState',
262294
payload: ''
263295
};
264296
state = reducer(state, action);

__tests__/contextReducer.test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ describe('Context Reducer', () => {
5050
});
5151

5252
//OLD ADD CONTEX TEST
53+
5354
// describe('ADD_CONTEXT', () => {
5455
// const action = {
5556
// type: 'ADD_CONTEXT',

0 commit comments

Comments
 (0)