Skip to content

Commit 8c12033

Browse files
committed
In Progress Testing UNDO Functionality
1 parent 2682a69 commit 8c12033

File tree

1 file changed

+38
-31
lines changed

1 file changed

+38
-31
lines changed

__tests__/componentReducer.test.ts

Lines changed: 38 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -163,42 +163,36 @@ describe('Testing componentReducer functionality', () => {
163163
// TEST 'UNDO'
164164
describe('UNDO reducer', () => {
165165
// problem: past array up to this point is empty because snapshot function is responsible for populating it- not invoked in testing
166-
// other ideas: take a snapshot in each of the tests in order to populate the past array
167-
it('should move the last element in past array to the future array, both nested within state.components', () => {
166+
// undo is not deleting the children because it relies on Canvas.tsx's function Canvas and snapShotFunc inside it
167+
it('should remove the last 2 elements in the children array', () => {
168168
const focusIndex = state.canvasFocus.componentId - 1;
169-
state.components[focusIndex].past.push({
170-
type: "HTML Element", typeId: 1000, name: "separator", childId: 1001, style: { border: "none" }, children: []
171-
},
172-
{
173-
type: "HTML Element", typeId: 4, name: "button", childId: 2, style: { border: "none" }, children: []
174-
});
175-
state.components[focusIndex].children.push({
176-
type: "HTML Element", typeId: 1000, name: "separator", childId: 1001, style: { border: "none" }, children: []
177-
},
178-
{
179-
type: "HTML Element", typeId: 4, name: "button", childId: 2, style: { border: "none" }, children: []
169+
const actionHTML: Action = {
170+
type: 'ADD CHILD',
171+
payload: {
172+
type: 'HTML Element',
173+
typeId: 9,
174+
childId: null,
175+
}
180176
}
181-
);
182-
// const actionHTML: Action = {
183-
// type: 'ADD CHILD',
184-
// payload: {
185-
// type: 'HTML Element',
186-
// typeId: 9,
187-
// childId: null,
188-
// },
189-
// };
190-
// state = reducer(state, actionHTML);
177+
console.log('focusIndex before UNDO', focusIndex);
178+
console.log('before add child', state.components[focusIndex]);
179+
state = reducer(state, actionHTML);
180+
console.log('after add kid', state.components[focusIndex]);
191181
const actionUndo: Action = {
192182
type: 'UNDO',
193-
payload: {},
194-
}
195-
console.log('state 1', state)
183+
payload: {},
184+
};
185+
196186
state = reducer(state, actionUndo);
197-
console.log('state 2', state);
198-
//const undidEl = state.components[focusIndex].past.pop();
199-
//const undidEl = state.components[focusIndex].past.pop()
200-
expect(state.components[focusIndex].future.length).toEqual(1);
201-
//expect(state.components[focusIndex].past
187+
console.log('focusIndex after UNDO', focusIndex);
188+
189+
const undoParent = state.components.find(comp => comp.id === state.canvasFocus.componentId);
190+
191+
expect(undoParent.children.length).toEqual(0);
192+
193+
console.log('after undo', state.components[focusIndex]);
194+
195+
//expect(state.components[focusIndex].children.length).toEqual(0);
202196
})
203197
});
204198

@@ -221,3 +215,16 @@ describe('Testing componentReducer functionality', () => {
221215

222216
});
223217

218+
// state.components[focusIndex].past.push({
219+
// type: "HTML Element", typeId: 1000, name: "separator", childId: 1001, style: { border: "none" }, children: []
220+
// },
221+
// {
222+
// type: "HTML Element", typeId: 4, name: "button", childId: 2, style: { border: "none" }, children: []
223+
// });
224+
// state.components[focusIndex].children.push({
225+
// type: "HTML Element", typeId: 1000, name: "separator", childId: 1001, style: { border: "none" }, children: []
226+
// },
227+
// {
228+
// type: "HTML Element", typeId: 4, name: "button", childId: 2, style: { border: "none" }, children: []
229+
// }
230+
// );

0 commit comments

Comments
 (0)