Skip to content

Commit 8e8ec47

Browse files
committed
Merge branch 'master' into auth-testing
2 parents db6a373 + 22880c3 commit 8e8ec47

25 files changed

+193
-77
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Download for [MacOS](https://github.com/team-reactype/ReacType/releases), [Windo
2929

3030
- **Linux users**: run the application as a super user in order to read and write files.
3131

32-
![Gif of adding](https://i.imgur.com/hdVTFcP.gif)
32+
![Gif of adding](https://i.imgur.com/nOeuuU6.gif)
3333

3434
### How to use
3535

__mocks__/electron.ts

Lines changed: 0 additions & 6 deletions
This file was deleted.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`Enzyme testing suite renders snapshots, too 1`] = `
4+
<div>
5+
<h1>
6+
Hello, Enzyme!
7+
</h1>
8+
</div>
9+
`;

__tests__/componentReducer.test.ts

Lines changed: 101 additions & 10 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,45 +40,136 @@ 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+
84+
// TEST 'DELETE CHILD'
85+
describe('DELETE CHILD reducer', () => {
86+
it('should delete child of focused top-level component', () => {
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');
97+
})
98+
})
99+
57100
// TEST 'CHANGE FOCUS'
58101
describe('CHANGE FOCUS reducer', () => {
59102
it('should change focus to specified component', () => {
60-
const action = {
103+
const action: Action = {
61104
type: 'CHANGE FOCUS',
62105
payload: {
63106
componentId: 2,
64107
childId: null
65108
}
66109
}
67-
console.log('before change focus ', state.canvasFocus);
68110
state = reducer(state, action);
69-
console.log('after change focus ', state.canvasFocus);
70111
expect(state.canvasFocus.componentId).toEqual(2);
71112
expect(state.canvasFocus.childId).toEqual(null);
72113
})
73114
})
74115

75116
// TEST 'UPDATE CSS'
76117
describe('UPDATE CSS reducer', () => {
77-
it('should update background color of focused component', () => {
78-
118+
it('should add style to focused component', () => {
119+
const action: Action = {
120+
type: 'UPDATE CSS',
121+
payload: {
122+
style: {
123+
backgroundColor: 'gray'
124+
}
125+
}
126+
}
127+
state = reducer(state, action);
128+
const styledComp = state.components.find(comp => comp.id === state.canvasFocus.componentId);
129+
// expect the style property on targeted comp to equal style property in payload
130+
expect(styledComp.style.backgroundColor).toEqual(action.payload.style.backgroundColor);
131+
})
132+
})
133+
134+
// TEST 'UPDATE PROJECT NAME'
135+
describe('UPDATE PROJECT NAME reducer', () => {
136+
it('should update project with specified name', () => {
137+
const action: Action = {
138+
type: 'UPDATE PROJECT NAME',
139+
payload: 'TESTNAME'
140+
}
141+
state = reducer(state, action);
142+
// expect state name to equal payload
143+
expect(state.name).toEqual(action.payload);
144+
})
145+
})
146+
147+
// TEST 'CHANGE PROJECT TYPE'
148+
describe('CHANGE PROJECT TYPE reducer', () => {
149+
it('should change project type to specified type', () => {
150+
const action: Action = {
151+
type: 'CHANGE PROJECT TYPE',
152+
payload: {
153+
projectType: 'Classic React'
154+
}
155+
};
156+
state = reducer(state, action);
157+
expect(state.projectType).toEqual(action.payload.projectType);
79158
})
80159
})
81160

82161
// TEST 'RESET STATE'
162+
describe('RESET STATE reducer', () => {
163+
it('should reset project to initial state', () => {
164+
const action: Action = {
165+
type: 'RESET STATE'
166+
}
167+
state = reducer(state, action);
168+
// expect default project to have empty string as name
169+
expect(state.name).toEqual('');
170+
// expect default project to only have one component in components array
171+
expect(state.components.length).toEqual(1);
172+
})
173+
})
83174

84175
})

__tests__/enzyme.test.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { shallow } from 'enzyme';
2+
import React from 'react';
3+
4+
describe('Enzyme testing suite', () => {
5+
6+
it('renders snapshots, too', () => {
7+
const wrapper = shallow(<div>
8+
<h1>Hello, Enzyme!</h1>
9+
</div>)
10+
expect(wrapper).toMatchSnapshot()
11+
})
12+
})

app/electron/main.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ const MenuBuilder = require('./menu');
2424
const path = require('path');
2525
// const fs = require('fs');
2626

27-
console.log('NODE ENV is ', process.env.NODE_ENV);
28-
const isDev = process.env.NODE_ENV === 'development' || process.env.NODE_ENV === 'test' ;
27+
const isDev =
28+
process.env.NODE_ENV === 'development' || process.env.NODE_ENV === 'test';
2929
const port = 8080;
3030
const selfHost = `http://localhost:${port}`;
3131

@@ -237,8 +237,6 @@ app.on('web-contents-created', (event, contents) => {
237237

238238
contents.on('will-redirect', (event, navigationUrl) => {
239239
const parsedUrl = new URL(navigationUrl);
240-
//console.log('parsedUrl is', parsedUrl);
241-
//console.log('parsedUrl.origin is', parsedUrl.origin);
242240
const validOrigins = [
243241
selfHost,
244242
'http://localhost:5000',
@@ -339,8 +337,12 @@ ipcMain.on('set_cookie', event => {
339337
session.defaultSession.cookies
340338
.get({ url: serverUrl })
341339
.then(cookie => {
342-
console.log(cookie);
343-
event.reply('give_cookie', cookie);
340+
// this if statement is necessary or the setInterval on main app will constantly run and will emit this event.reply, causing a memory leak
341+
// checking for a cookie inside array will only emit reply when a cookie exists
342+
if (cookie[0]) {
343+
console.log(cookie);
344+
event.reply('give_cookie', cookie);
345+
}
344346
})
345347
.catch(error => {
346348
console.log('Error giving cookies in set_cookie:', error);

app/setupTests.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { configure } from 'enzyme'
2+
import Adapter from 'enzyme-adapter-react-16'
3+
4+
configure({
5+
adapter: new Adapter(),
6+
})

app/src/components/App.tsx

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,6 @@ export const App = (): JSX.Element => {
3636
});
3737
} else {
3838
// otherwise if a user is logged in, use a fetch request to load user's projects from DB
39-
// getProjects().then(projects =>
40-
// console.log('UseEffect in App getprojects() returns', projects)
41-
// );
4239
let userId;
4340
if (Cookies.get('ssid')) {
4441
userId = Cookies.get('ssid');
@@ -69,10 +66,8 @@ export const App = (): JSX.Element => {
6966
userId = window.localStorage.getItem('ssid');
7067
}
7168
if (state.isLoggedIn === false) {
72-
//console.log('Saving guest project as', state);
7369
localforage.setItem('guestProject', state);
7470
} else if (state.name !== '') {
75-
//console.log('Saving user project as', state);
7671
saveProject(state.name, state);
7772
localforage.setItem(userId, state);
7873
}

app/src/components/login/SignIn.tsx

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -121,13 +121,11 @@ const SignIn: React.FC<LoginInt & RouteComponentProps> = props => {
121121
*/
122122
const handleLogin = (e: React.MouseEvent<HTMLButtonElement, MouseEvent>) => {
123123
e.preventDefault();
124-
console.log('click fired on handleLogin');
125124
setInvalidUser(false);
126125
setInvalidUserMsg('');
127126
setInvalidPass(false);
128127
setInvalidPassMsg('');
129128
sessionIsCreated(username, password).then(loginStatus => {
130-
console.log('login fetch', loginStatus);
131129
if (loginStatus === 'Success') {
132130
props.history.push('/');
133131
} else {
@@ -157,7 +155,6 @@ const SignIn: React.FC<LoginInt & RouteComponentProps> = props => {
157155
const handleLoginGuest = (
158156
e: React.MouseEvent<HTMLButtonElement, MouseEvent>
159157
) => {
160-
console.log('Handle login guest fired');
161158
e.preventDefault();
162159
// generate "cookie" in localStorage for guest users
163160
window.localStorage.setItem('ssid', 'guest');
@@ -247,9 +244,6 @@ const SignIn: React.FC<LoginInt & RouteComponentProps> = props => {
247244

248245
<Grid container>
249246
<Grid item xs>
250-
{/* <Link href="#" variant="body2">
251-
Forgot password?
252-
</Link> */}
253247
<RouteLink to={`/signup`} className="nav_link">
254248
Forgot password?
255249
</RouteLink>

app/src/components/login/SignUp.tsx

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -182,14 +182,9 @@ const SignUp: React.FC<LoginInt & RouteComponentProps> = props => {
182182
setInvalidVerifyPassword(false);
183183
}
184184

185-
console.log('invalidUsername', invalidUsername);
186-
console.log('invalidPassword', invalidPassword);
187-
console.log('invalidEmail', invalidEmail);
188-
console.log('invalidVerifyPassword', invalidVerifyPassword);
189185
// if(!invalidUsername && !invalidPassword && !invalidEmail && !invalidVerifyPassword) {
190186
newUserIsCreated(username, email, password).then(userCreated => {
191187
if (userCreated === 'Success') {
192-
console.log('user created');
193188

194189
props.history.push('/');
195190
} else {

app/src/components/main/Canvas.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import renderChildren from '../../helperFunctions/renderChildren';
99
function Canvas() {
1010
const [state, dispatch] = useContext(stateContext);
1111

12-
console.log('state is ', state);
1312
// find the current component to render on the canvas
1413
const currentComponent: Component = state.components.find(
1514
(elem: Component) => elem.id === state.canvasFocus.componentId

app/src/components/main/DirectChildComponent.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ function DirectChildComponent({ childId, type, typeId, style }: ChildElement) {
5757
boxShadow:
5858
state.canvasFocus.childId === childId ? '1px 1px 3px rgb(11,212,112)' : ''
5959
};
60+
6061
const combinedStyle = combineStyles(
6162
combineStyles(
6263
combineStyles(globalDefaultStyle, referencedComponent.style),
@@ -109,7 +110,13 @@ function DirectChildComponent({ childId, type, typeId, style }: ChildElement) {
109110
const HTMLDefaultPlacholder = HTMLType.placeHolderShort;
110111
const combinedStyle = combineStyles(HTMLDefaultStyle, child.style);
111112
return (
112-
<React.Fragment>
113+
<React.Fragment
114+
key={
115+
'indChildFrag' +
116+
child.childId.toString() +
117+
child.typeId.toString()
118+
}
119+
>
113120
{child.children.length === 0 ? (
114121
<IndirectChild
115122
style={combinedStyle}
@@ -161,7 +168,7 @@ function DirectChildComponent({ childId, type, typeId, style }: ChildElement) {
161168
return (
162169
<div
163170
onClick={onClickHandler}
164-
key={'childComp' + childId}
171+
// key={'childComp' + childId}
165172
style={combinedStyle}
166173
ref={drag}
167174
>

app/src/components/main/IndirectChild.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ function IndirectChild({ style, children, placeHolder, linkId }) {
2525
combinedStyle = combineStyles(combinedStyle, { color: 'blue' });
2626
}
2727

28-
//console.log('children are ', children);
29-
//console.log('place holder is ', placeHolder);
3028
return (
3129
<div style={combinedStyle}>
3230
{linkId ? (

app/src/components/right/ProjectsFolder.tsx

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,6 @@ function ProjectsDialog(props: ProjectDialogProps) {
2727
const { onClose, open, projects } = props;
2828
const [_, dispatch] = useContext(stateContext);
2929

30-
useEffect(() => {
31-
console.log('state is', _);
32-
}, [_]);
33-
3430
// If no projects selected, keep the name of the current displayed
3531
const handleClose = () => {
3632
// onClose(selectedValue);

0 commit comments

Comments
 (0)