Skip to content

Commit eb58eda

Browse files
committed
added more reducer test cases
1 parent 6cd2b6a commit eb58eda

File tree

1 file changed

+59
-2
lines changed

1 file changed

+59
-2
lines changed

__tests__/componentReducer.test.ts

Lines changed: 59 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,13 @@ describe('Testing componentReducer functionality', function () {
5454
})
5555
})
5656

57+
// TEST 'DELETE CHILD'
58+
describe('DELETE CHILD reducer', () => {
59+
it('should delete child of focused top-level component', () => {
60+
console.log('state before delete child ', state);
61+
})
62+
})
63+
5764
// TEST 'CHANGE FOCUS'
5865
describe('CHANGE FOCUS reducer', () => {
5966
it('should change focus to specified component', () => {
@@ -74,11 +81,61 @@ describe('Testing componentReducer functionality', function () {
7481

7582
// TEST 'UPDATE CSS'
7683
describe('UPDATE CSS reducer', () => {
77-
it('should update background color of focused component', () => {
78-
84+
it('should add style to focused component', () => {
85+
const action = {
86+
type: 'UPDATE CSS',
87+
payload: {
88+
style: {
89+
backgroundColor: 'gray'
90+
}
91+
}
92+
}
93+
state = reducer(state, action);
94+
const styledComp = state.components.find(comp => comp.id === state.canvasFocus.componentId);
95+
// expect the style property on targeted comp to equal style property in payload
96+
expect(styledComp.style.backgroundColor).toEqual(action.payload.style.backgroundColor);
97+
})
98+
})
99+
100+
// TEST 'UPDATE PROJECT NAME'
101+
describe('UPDATE PROJECT NAME reducer', () => {
102+
it('should update project with specified name', () => {
103+
const action = {
104+
type: 'UPDATE PROJECT NAME',
105+
payload: 'TESTNAME'
106+
}
107+
state = reducer(state, action);
108+
// expect state name to equal payload
109+
expect(state.name).toEqual(action.payload);
110+
})
111+
})
112+
113+
// TEST 'CHANGE PROJECT TYPE'
114+
describe('CHANGE PROJECT TYPE reducer', () => {
115+
it('should change project type to specified type', () => {
116+
const action = {
117+
type: 'CHANGE PROJECT TYPE',
118+
payload: {
119+
projectType: 'Classic React'
120+
}
121+
};
122+
state = reducer(state, action);
123+
expect(state.projectType).toEqual(action.payload.projectType);
79124
})
80125
})
81126

82127
// TEST 'RESET STATE'
128+
describe('RESET STATE reducer', () => {
129+
it('should reset project to initial state', () => {
130+
const action = {
131+
type: 'RESET STATE'
132+
}
133+
state = reducer(state, action);
134+
// expect default project to have empty string as name
135+
expect(state.name).toEqual('');
136+
// expect default project to only have one component in components array
137+
expect(state.components.length).toEqual(1);
138+
})
139+
})
83140

84141
})

0 commit comments

Comments
 (0)