Skip to content

Commit 097bb9c

Browse files
committed
All stateManagementReducer tests pass
1 parent 912134b commit 097bb9c

File tree

3 files changed

+93
-78
lines changed

3 files changed

+93
-78
lines changed

__tests__/enzyme.test.tsx renamed to __tests__/enzyme.tsx

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,13 @@ import LoginButton from '../app/src/components/right/LoginButton';
2323
import customizationPanel from '../app/src/containers/CustomizationPanel';
2424
import configureMockStore from 'redux-mock-store';
2525

26+
2627
const mockStore = configureMockStore();
2728
const store = mockStore({});
2829

2930
configure({ adapter: new Adapter() });
3031

31-
/* If there is an error with unmatched snapshots because of intentionally modified codes, delete the contents in enzyme.test.tsx.snap to record new codes as blueprints */
32+
// /* If there is an error with unmatched snapshots because of intentionally modified codes, delete the contents in enzyme.test.tsx.snap to record new codes as blueprints */
3233

3334
xdescribe('Test the CanvasContainer component', () => {
3435
const target = shallow(
@@ -40,13 +41,13 @@ xdescribe('Test the CanvasContainer component', () => {
4041
expect(target).toMatchSnapshot();
4142
});
4243
// test if Canvas component is rendered
43-
// it('Contains Canvas component', () => {
44-
// expect(
45-
// target.contains(
46-
// <Canvas />
47-
// )
48-
// ).toBe(true);
49-
// });
44+
it('Contains Canvas component', () => {
45+
expect(
46+
target.contains(
47+
<Canvas />
48+
)
49+
).toBe(true);
50+
});
5051
});
5152

5253
xdescribe('Test the MainContainer component', () => {

__tests__/stateManagementReducer.test.js

Lines changed: 83 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,76 +1,72 @@
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';
43

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', () => {
659
const findComponent = (components, componentId) => {
760
return components.find((elem) => elem.id === componentId);
861
};
962

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-
6663
// TEST 'ADD STATE'
67-
describe('ADD STATE test', () => {
64+
describe('addState test', () => {
6865
// setting canvas focus to root component (App)
69-
state.canvasFocus.componentId = 1;
70-
66+
// state.canvasFocus.componentId = 1;
7167
// action dispatched to be tested
7268
const action = {
73-
type: 'ADD STATE',
69+
type: 'appState/addState',
7470
payload: {
7571
newState: {
7672
id: 'App-testAppState',
@@ -83,6 +79,9 @@ xdescribe('Testing componentReducer functionality for stateManagement tab', () =
8379
key: 'setTestAppState',
8480
type: 'func',
8581
value: ''
82+
},
83+
contextParam: {
84+
allContext: []
8685
}
8786
}
8887
};
@@ -123,23 +122,28 @@ xdescribe('Testing componentReducer functionality for stateManagement tab', () =
123122
// TEST 'ADD PASSEDINPROPS'
124123
describe('ADD PASSEDINPROPS test', () => {
125124
// setting canvas focus to the child component
125+
state = JSON.parse(JSON.stringify(state));
126126
state.canvasFocus.componentId = 2;
127127

128128
// action dispatched to be tested
129129
const action = {
130-
type: 'ADD PASSEDINPROPS',
130+
type: 'appState/addPassedInProps',
131131
payload: {
132132
passedInProps: {
133133
id: 'App-testAppState',
134134
key: 'testAppState',
135135
type: 'number',
136136
value: 1
137+
},
138+
contextParam: {
139+
allContext: []
137140
}
138141
}
139142
};
140143

141144
// setting test state
142145
state = reducer(state, action);
146+
console.log('state.components', state.components);
143147
const currComponent = findComponent(state.components, 2);
144148
const parentComponent = findComponent(state.components, 1);
145149

@@ -184,12 +188,18 @@ xdescribe('Testing componentReducer functionality for stateManagement tab', () =
184188
describe('DELETE PASSEDINPROPS test', () => {
185189
it('should delete the state passed down from parent component in the child component', () => {
186190
// setting canvas focus to the child component
191+
state = JSON.parse(JSON.stringify(state));
187192
state.canvasFocus.componentId = 2;
188193

189194
// action dispatched to be tested
190195
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+
}
193203
};
194204

195205
// setting test state
@@ -206,15 +216,19 @@ xdescribe('Testing componentReducer functionality for stateManagement tab', () =
206216
describe('DELETE STATE test', () => {
207217
it('should delete all instances of state from stateProps and passedInProps', () => {
208218
// setting canvas focus to root component
219+
state = JSON.parse(JSON.stringify(state));
209220
state.canvasFocus.componentId = 1;
210221

211222
// action dispatched to be tested
212223
const action = {
213-
type: 'DELETE STATE',
224+
type: 'appState/deleteState',
214225
payload: {
215226
stateProps: [],
216227
rowId: 'App-appState',
217-
otherId: 'App-setAppState'
228+
otherId: 'App-setAppState',
229+
contextParam: {
230+
allContext: []
231+
}
218232
}
219233
};
220234

app/src/components/top/NavBarButtons.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ function handleUserEnteredRoom(roomCode) {
8383
initSocketConnection(roomCode);
8484
}
8585

86-
console.log(store.getState());
86+
// console.log(store.getState());
8787
let previousState = store.getState();
8888

8989
// sending info to backend whenever the redux store changes

0 commit comments

Comments
 (0)