Skip to content

Commit deb8ed0

Browse files
committed
finished component reducer test cases
1 parent d8f4008 commit deb8ed0

File tree

2 files changed

+47
-19
lines changed

2 files changed

+47
-19
lines changed

__mocks__/electron.ts

Lines changed: 0 additions & 6 deletions
This file was deleted.

__tests__/componentReducer.test.ts

Lines changed: 47 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ describe('Testing componentReducer functionality', function () {
1111
// TEST 'ADD COMPONENT'
1212
describe('ADD COMPONENT reducer', () => {
1313
it('should add new reuseable component to state', () => {
14-
const action = {
14+
const action: Action = {
1515
type: 'ADD COMPONENT',
1616
payload: {
1717
componentName: "TestRegular",
@@ -30,7 +30,7 @@ describe('Testing componentReducer functionality', function () {
3030
// TEST 'ADD CHILD'
3131
describe('ADD CHILD reducer', () => {
3232
it('should add child component to top-level component', () => {
33-
const action = {
33+
const action: Action = {
3434
type: 'ADD CHILD',
3535
payload: {
3636
type: 'Component',
@@ -40,40 +40,74 @@ describe('Testing componentReducer functionality', function () {
4040
}
4141
// switch focus to very first root component
4242
state.canvasFocus = { componentId: 1, childId: null };
43-
console.log(state);
4443
state = reducer(state, action);
4544
const newParent = state.components[0];
4645
// expect new parent's children array to have length 1
4746
expect(newParent.children.length).toEqual(1);
4847
// expect new child to have type 'Component'
49-
console.log('new child ', newParent.children[0]);
5048
expect(newParent.children[0].type).toEqual('Component');
5149
const addedChild = state.components.find(comp => comp.id === newParent.children[0].typeId);
5250
// expect new child typeId to correspond to component with name 'TestRegular'
5351
expect(addedChild.name).toEqual('TestRegular');
5452
})
5553
})
56-
54+
55+
// TEST 'CHANGE POSITION'
56+
describe('CHANGE POSITION reducer ', () => {
57+
it('should move position of an instance', () => {
58+
const actionHtml: Action = {
59+
type: 'ADD CHILD',
60+
payload: {
61+
type: 'HTML Element',
62+
typeId: 9,
63+
childId: null
64+
}
65+
}
66+
state = reducer(state, actionHtml);
67+
const actionChangePos: Action = {
68+
type: 'CHANGE POSITION',
69+
payload: {
70+
currentChildId: 1,
71+
newParentChildId: null
72+
}
73+
}
74+
state = reducer(state, actionChangePos);
75+
const changeParent = state.components.find(comp => comp.id === state.canvasFocus.componentId);
76+
const changeParentChildLength = changeParent.children.length;
77+
// expect last child of parent to be moved Component element
78+
expect(changeParent.children[changeParentChildLength-1].type).toEqual('Component');
79+
// expect last child of parent to have current child ID of payload
80+
expect(changeParent.children[changeParentChildLength-1].childId).toEqual(1);
81+
})
82+
})
83+
5784
// TEST 'DELETE CHILD'
5885
describe('DELETE CHILD reducer', () => {
5986
it('should delete child of focused top-level component', () => {
60-
console.log('state before delete child ', state);
87+
// canvas still focused on childId: 2, which is an HTML element
88+
const action: Action = {
89+
type: 'DELETE CHILD'
90+
}
91+
state = reducer(state, action);
92+
// expect only one remaining child
93+
const delParent = state.components.find(comp => comp.id === state.canvasFocus.componentId);
94+
// expect remaining child to have type 'Component'
95+
expect(delParent.children.length).toEqual(1);
96+
expect(delParent.children[delParent.children.length -1].type).toEqual('Component');
6197
})
6298
})
6399

64100
// TEST 'CHANGE FOCUS'
65101
describe('CHANGE FOCUS reducer', () => {
66102
it('should change focus to specified component', () => {
67-
const action = {
103+
const action: Action = {
68104
type: 'CHANGE FOCUS',
69105
payload: {
70106
componentId: 2,
71107
childId: null
72108
}
73109
}
74-
console.log('before change focus ', state.canvasFocus);
75110
state = reducer(state, action);
76-
console.log('after change focus ', state.canvasFocus);
77111
expect(state.canvasFocus.componentId).toEqual(2);
78112
expect(state.canvasFocus.childId).toEqual(null);
79113
})
@@ -82,7 +116,7 @@ describe('Testing componentReducer functionality', function () {
82116
// TEST 'UPDATE CSS'
83117
describe('UPDATE CSS reducer', () => {
84118
it('should add style to focused component', () => {
85-
const action = {
119+
const action: Action = {
86120
type: 'UPDATE CSS',
87121
payload: {
88122
style: {
@@ -100,7 +134,7 @@ describe('Testing componentReducer functionality', function () {
100134
// TEST 'UPDATE PROJECT NAME'
101135
describe('UPDATE PROJECT NAME reducer', () => {
102136
it('should update project with specified name', () => {
103-
const action = {
137+
const action: Action = {
104138
type: 'UPDATE PROJECT NAME',
105139
payload: 'TESTNAME'
106140
}
@@ -113,7 +147,7 @@ describe('Testing componentReducer functionality', function () {
113147
// TEST 'CHANGE PROJECT TYPE'
114148
describe('CHANGE PROJECT TYPE reducer', () => {
115149
it('should change project type to specified type', () => {
116-
const action = {
150+
const action: Action = {
117151
type: 'CHANGE PROJECT TYPE',
118152
payload: {
119153
projectType: 'Classic React'
@@ -127,7 +161,7 @@ describe('Testing componentReducer functionality', function () {
127161
// TEST 'RESET STATE'
128162
describe('RESET STATE reducer', () => {
129163
it('should reset project to initial state', () => {
130-
const action = {
164+
const action: Action = {
131165
type: 'RESET STATE'
132166
}
133167
state = reducer(state, action);

0 commit comments

Comments
 (0)