Skip to content

Commit 9084bc7

Browse files
AnthonytorreroAnthonytorrero
authored andcommitted
comments and styling done
2 parents b73a0e4 + 0ca1b0c commit 9084bc7

File tree

7 files changed

+117
-99
lines changed

7 files changed

+117
-99
lines changed

__tests__/componentReducer.test.ts

Lines changed: 80 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import reducer from '../app/src/reducers/componentReducer';
2-
import { State, Action } from '../app/src/interfaces/InterfacesNew';
2+
import { State, Action } from '../app/src/interfaces/Interfaces';
33

44
import initialState from '../app/src/context/initialState';
5+
import { iterate } from 'localforage';
56

67
describe('Testing componentReducer functionality', () => {
78
let state: State = initialState;
@@ -25,6 +26,27 @@ describe('Testing componentReducer functionality', () => {
2526
});
2627
});
2728

29+
// TEST 'ADD COMPONENT' with new root
30+
describe('ADD COMPONENT reducer', () => {
31+
it('should add new reuseable component to state as the new root', () => {
32+
const action: Action = {
33+
type: 'ADD COMPONENT',
34+
payload: {
35+
componentName: 'TestRootChange',
36+
id: 3,
37+
root: true,
38+
},
39+
};
40+
state = reducer(state, action);
41+
42+
// expect state.components array to have length 3
43+
const length = state.components.length;
44+
expect(length).toEqual(3);
45+
// expect new root to match id of component id of TestRootChange (rootComponents is an array of component ID numbers)
46+
expect(state.rootComponents[state.rootComponents.length - 1]).toEqual(action.payload.id);
47+
});
48+
});
49+
2850
// TEST 'ADD CHILD'
2951
describe('ADD CHILD reducer', () => {
3052
it('should add child component and separator to top-level component', () => {
@@ -158,6 +180,62 @@ describe('Testing componentReducer functionality', () => {
158180
expect(state.projectType).toEqual(action.payload.projectType);
159181
});
160182
});
183+
184+
185+
// TEST 'UNDO'
186+
describe('UNDO reducer', () => {
187+
it('should remove the last element from the past array and push it to the future array', () => {
188+
const focusIndex = state.canvasFocus.componentId - 1;
189+
state.components[focusIndex].past = [];
190+
191+
// snapShotFunc taken from src/components/main/canvas.tsx to test undo functionality
192+
// snapShotFunc takes a snapshot of state to be used in UNDO/REDO functionality
193+
const snapShotFuncCopy = () => {
194+
const deepCopiedState = JSON.parse(JSON.stringify(state));
195+
// pushes the last user action on the canvas into the past array of Component
196+
state.components[focusIndex].past.push(deepCopiedState.components[focusIndex].children);
197+
}
198+
199+
const actionHTML2: Action = {
200+
type: 'ADD CHILD',
201+
payload: {
202+
type: 'HTML Element',
203+
typeId: 4,
204+
childId: null,
205+
}
206+
}
207+
state = reducer(state, actionHTML2);
208+
// invoking snapShotFunc is necessary to push actions into the past array, referenced in the UNDO functionality to define children
209+
snapShotFuncCopy();
210+
211+
const actionUndo: Action = {
212+
type: 'UNDO',
213+
payload: {},
214+
};
215+
state = reducer(state, actionUndo);
216+
217+
expect(state.components[focusIndex].past.length).toEqual(0);
218+
expect(state.components[focusIndex].future.length).toEqual(1);
219+
})
220+
});
221+
222+
223+
// TEST 'REDO'
224+
describe('REDO reducer', () => {
225+
it('should remove the last element from the future array and push it to the past array', () => {
226+
const focusIndex = state.canvasFocus.componentId - 1;
227+
228+
const actionRedo: Action = {
229+
type: 'REDO',
230+
payload: {},
231+
};
232+
state = reducer(state, actionRedo);
233+
234+
expect(state.components[focusIndex].future.length).toEqual(0);
235+
expect(state.components[focusIndex].past.length).toEqual(1);
236+
})
237+
});
238+
161239

162240
// TEST 'RESET STATE'
163241
describe('RESET STATE reducer', () => {
@@ -176,3 +254,4 @@ describe('Testing componentReducer functionality', () => {
176254
});
177255
});
178256
});
257+

__tests__/projects.test.js

Lines changed: 0 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,20 @@
1-
<<<<<<< HEAD
2-
<<<<<<< HEAD
3-
<<<<<<< HEAD
4-
=======
5-
>>>>>>> master
61
const { Mongoose } = require('mongoose');
72
const request = require('supertest');
8-
9-
103
// initializes the project to be sent to server/DB
114
const { projectToSave, state } = require('../mockData');
12-
135
const app = require('../server/server.js');
146
const http = require('http');
157
let server;
16-
<<<<<<< HEAD
17-
=======
18-
=======
19-
const request = require('supertest');
20-
>>>>>>> 88cc3e590da1bd5641e96dc39eb4a7863d71dbfc
21-
const app = require('../server/server');
22-
23-
let server = 'https://reactype.herokuapp.com';
24-
const isDev = process.env.NODE_ENV === 'development';
25-
if (isDev) {
26-
// server = 'http://localhost:5000';
27-
server = require('..server/server');
28-
}
29-
<<<<<<< HEAD
30-
>>>>>>> d93eb6bfcae6f1452b6e7451c95370b5d9e558f5
31-
=======
32-
>>>>>>> master
33-
=======
34-
>>>>>>> 88cc3e590da1bd5641e96dc39eb4a7863d71dbfc
35-
368
// save and get projects endpoint testing
379
describe('Project endpoints tests', () => {
3810
beforeAll((done) => {
3911
server = http.createServer(app);
4012
server.listen(done);
4113
});
42-
4314
afterAll((done) => {
4415
Mongoose.disconnect();
4516
server.close(done);
4617
});
47-
4818
// test saveProject endpoint
4919
describe('/saveProject', () => {
5020
describe('/POST', () => {
@@ -54,25 +24,11 @@ describe('Project endpoints tests', () => {
5424
.set('Accept', 'application/json')
5525
.send(projectToSave)
5626
.expect(200)
57-
<<<<<<< HEAD
58-
<<<<<<< HEAD
59-
<<<<<<< HEAD
60-
.expect('Content-Type', /application\/json/)
61-
.then((res) => expect(res.body.name).toBe(projectToSave.name));
62-
=======
63-
.then(res => expect(res.body.project.name).toBe('test'));
64-
>>>>>>> d93eb6bfcae6f1452b6e7451c95370b5d9e558f5
65-
=======
6627
.expect('Content-Type', /application\/json/)
6728
.then((res) => expect(res.body.name).toBe(projectToSave.name));
68-
>>>>>>> master
69-
=======
70-
.then(res => expect(res.body.project.name).toBe('test'));
71-
>>>>>>> 88cc3e590da1bd5641e96dc39eb4a7863d71dbfc
7229
});
7330
});
7431
});
75-
7632
// test getProjects endpoint
7733
describe('/getProjects', () => {
7834
describe('POST', () => {
@@ -90,7 +46,6 @@ describe('Project endpoints tests', () => {
9046
});
9147
});
9248
});
93-
9449
// test deleteProject endpoint
9550
describe('/deleteProject', () => {
9651
describe('DELETE', () => {
@@ -101,21 +56,7 @@ describe('Project endpoints tests', () => {
10156
.set('Accept', 'application/json')
10257
.send({ name, userId })
10358
.expect(200)
104-
<<<<<<< HEAD
105-
<<<<<<< HEAD
106-
<<<<<<< HEAD
10759
.then((res) => expect(res.body.name).toBe(projectToSave.name));
108-
=======
109-
.expect('Content-Type', /json/)
110-
.then(res => expect(res.body.name).toBe('test'));
111-
>>>>>>> d93eb6bfcae6f1452b6e7451c95370b5d9e558f5
112-
=======
113-
.then((res) => expect(res.body.name).toBe(projectToSave.name));
114-
>>>>>>> master
115-
=======
116-
.expect('Content-Type', /json/)
117-
.then(res => expect(res.body.name).toBe('test'));
118-
>>>>>>> 88cc3e590da1bd5641e96dc39eb4a7863d71dbfc
11960
});
12061
});
12162
});

app/src/components/login/SignIn.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ const SignIn: React.FC<LoginInt & RouteComponentProps> = props => {
7575
window.api.setCookie();
7676
window.api.getCookie(cookie => {
7777
// if a cookie exists, set localstorage item with cookie data, clear interval, go back to '/' route to load app
78-
console.log(cookie);
7978
if (cookie[0]) {
8079
window.localStorage.setItem('ssid', cookie[0].value);
8180
clearInterval(githubCookie);

app/src/components/main/Canvas.tsx

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import React, { useState, useCallback, useContext, useEffect } from 'react';
22
import { useDrop, DropTargetMonitor } from 'react-dnd';
3-
import _ from 'lodash';
43
import { ItemTypes } from '../../constants/ItemTypes';
54
import StateContext from '../../context/context';
65
import { Component, DragItem } from '../../interfaces/Interfaces';
@@ -14,25 +13,25 @@ function Canvas() {
1413
const currentComponent: Component = state.components.find(
1514
(elem: Component) => elem.id === state.canvasFocus.componentId
1615
);
17-
18-
// changes focus of the canvas to a new component / child
19-
const changeFocus = (componentId?: number, childId?: number | null, e?: string) => {
20-
dispatch({ type: 'CHANGE FOCUS', payload: { componentId, childId, e, /*state*/ } });
21-
};
22-
// onClickHandler is responsible for changing the focused component and child component
23-
function onClickHandler(event) {
24-
event.stopPropagation();
25-
// note: a null value for the child id means that we are focusing on the top-level component rather than any child
26-
changeFocus(state.canvasFocus.componentId, null);
27-
};
28-
29-
// stores a snapshot of state into the past array for UNDO
30-
const snapShotFunc = () => {
31-
// make a deep clone of state
32-
const deepCopiedState = JSON.parse(JSON.stringify(state));
33-
const focusIndex = state.canvasFocus.componentId - 1;
34-
//pushes the last user action on the canvas into the past array of Component
35-
state.components[focusIndex].past.push(deepCopiedState.components[focusIndex].children);
16+
17+
// changes focus of the canvas to a new component / child
18+
const changeFocus = (componentId?: number, childId?: number | null) => {
19+
dispatch({ type: 'CHANGE FOCUS', payload: { componentId, childId } });
20+
};
21+
// onClickHandler is responsible for changing the focused component and child component
22+
function onClickHandler(event) {
23+
event.stopPropagation();
24+
// note: a null value for the child id means that we are focusing on the top-level component rather than any child
25+
changeFocus(state.canvasFocus.componentId, null);
26+
};
27+
28+
// stores a snapshot of state into the past array for UNDO
29+
const snapShotFunc = () => {
30+
// make a deep clone of state
31+
const deepCopiedState = JSON.parse(JSON.stringify(state));
32+
const focusIndex = state.canvasFocus.componentId - 1;
33+
//pushes the last user action on the canvas into the past array of Component
34+
state.components[focusIndex].past.push(deepCopiedState.components[focusIndex].children);
3635
};
3736

3837
// This hook will allow the user to drag items from the left panel on to the canvas
@@ -95,6 +94,5 @@ function Canvas() {
9594
</div>
9695
);
9796
}
98-
// export { snapStateArr };
99-
export default Canvas;
10097

98+
export default Canvas;

app/src/reducers/componentReducer.ts

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -215,10 +215,11 @@ const reducer = (state: State, action: Action) => {
215215
};
216216
components.push(newComponent);
217217

218+
// functionality if the new component will become the root component
218219
const rootComponents = [...state.rootComponents];
219220
if (action.payload.root) rootComponents.push(newComponent.id);
220221

221-
// update the focus to the new component
222+
// updates the focus to the new component, which redirects to the new blank canvas of said new component
222223
const canvasFocus = {
223224
...state.canvasFocus,
224225
componentId: newComponent.id,
@@ -344,7 +345,7 @@ const reducer = (state: State, action: Action) => {
344345
case 'CHANGE POSITION': {
345346
const { currentChildId, newParentChildId } = action.payload;
346347

347-
// if the currentChild Id is the same as the newParentId (i.e. a component is trying to drop itself into itself), don't update sate
348+
// if the currentChild Id is the same as the newParentId (i.e. a component is trying to drop itself into itself), don't update state
348349
if (currentChildId === newParentChildId) return state;
349350

350351
// find the current component in focus
@@ -618,15 +619,17 @@ const reducer = (state: State, action: Action) => {
618619
HTMLTypes
619620
};
620621
}
622+
621623
case 'UNDO': {
622624
const focusIndex = state.canvasFocus.componentId - 1;
623-
//if the past array is empty, return state
625+
// if the past array is empty, return state
624626
if(state.components[focusIndex].past.length === 0) return {...state};
625-
//the children array of the focused component will equal the last element of the past array
626-
state.components[focusIndex].children = state.components[focusIndex].past[state.components[focusIndex].past.length - 1]
627-
//the last element of the past array gets pushed into the future
628-
//the last element of the past array gets popped out
629-
state.components[focusIndex].future.push(state.components[focusIndex].past.pop())
627+
// the children array of the focused component will equal the last element of the past array
628+
state.components[focusIndex].children = state.components[focusIndex].past[state.components[focusIndex].past.length - 1];
629+
// the last element of the past array gets popped off
630+
const poppedEl = state.components[focusIndex].past.pop();
631+
// the last element of the past array gets popped off and pushed into the future array
632+
state.components[focusIndex].future.push(poppedEl);
630633

631634
//generate code for the Code Preview
632635
state.components.forEach((el, i) => {
@@ -642,17 +645,18 @@ const reducer = (state: State, action: Action) => {
642645
...state
643646
};
644647
}
648+
645649
case 'REDO': {
646650
const focusIndex = state.canvasFocus.componentId - 1;
647651
//if future array is empty, return state
648652
if(state.components[focusIndex].future.length === 0) return {...state};
649653
//the children array of the focused component will equal the last element of the future array
650654
state.components[focusIndex].children = state.components[focusIndex].future[state.components[focusIndex].future.length - 1]
651655
//the last element of the future array gets pushed into the past
652-
//the last element of the future array gets popped out
656+
//the last element of the future array gets popped out
653657
state.components[focusIndex].past.push(state.components[focusIndex].future.pop())
654658

655-
// //generate code for the Code Preview
659+
// generate code for the Code Preview
656660
state.components.forEach((el, i) => {
657661
el.code = generateCode(
658662
state.components,
@@ -666,8 +670,6 @@ const reducer = (state: State, action: Action) => {
666670
...state
667671
};
668672
}
669-
case 'CHANGEDVALUE': {}
670-
671673
default:
672674
return state;
673675
}

app/src/utils/createApplication.util.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,7 @@ export const createPackage = (path, appName) => {
136136
"express": "^4.17.1",
137137
"react": "^16.13.1",
138138
"react-dom": "^16.13.1",
139-
"webpack": "^4.29.6",
140-
"react-native": "^0.62.1"
139+
"webpack": "^4.29.6"
141140
},
142141
"devDependencies": {
143142
"@babel/core": "^7.4.3",

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@
175175
"@types/chai": "^4.2.11",
176176
"@types/enzyme": "^3.10.5",
177177
"@types/enzyme-adapter-react-16": "^1.0.6",
178-
"@types/jest": "^25.1.5",
178+
"@types/jest": "^25.2.3",
179179
"apollo": "^2.32.5",
180180
"babel-eslint": "^8.2.6",
181181
"babel-jest": "^25.2.4",
@@ -207,7 +207,7 @@
207207
"sass-loader": "^7.0.3",
208208
"style-loader": "^0.20.3",
209209
"supertest": "^4.0.2",
210-
"ts-jest": "^25.3.0",
210+
"ts-jest": "^25.5.1",
211211
"ts-node": "^8.10.2",
212212
"typescript": "^3.9.6",
213213
"url-loader": "^4.1.0",

0 commit comments

Comments
 (0)