Skip to content

Commit 58e7cde

Browse files
authored
Merge pull request #46 from oslabs-beta/staging-faast
Add Jest Testing by Fredo
2 parents 2b7ee7f + d725a41 commit 58e7cde

File tree

9 files changed

+219
-97
lines changed

9 files changed

+219
-97
lines changed

__tests__/componentReducer.test.ts

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
import reducer from '../app/src/reducers/componentReducer';
2+
import { State, Action, Component, ChildElement } from '../app/src/interfaces/InterfacesNew';
3+
4+
import initialState from '../app/src/context/initialState';
5+
6+
7+
describe('Testing componentReducer functionality', function () {
8+
let state: State = initialState;
9+
10+
11+
// TEST 'ADD COMPONENT'
12+
describe('ADD COMPONENT reducer', () => {
13+
it('should add new reuseable component to state', () => {
14+
const action = {
15+
type: 'ADD COMPONENT',
16+
payload: {
17+
componentName: "TestRegular",
18+
root: false
19+
}
20+
}
21+
state = reducer(state, action);
22+
// expect state.components array to have length 2
23+
const length = state.components.length;
24+
expect(length).toEqual(2);
25+
// expect new component name to match name of last elem in state.components array
26+
expect(state.components[length - 1].name).toEqual(action.payload.componentName);
27+
})
28+
})
29+
30+
// TEST 'ADD CHILD'
31+
describe('ADD CHILD reducer', () => {
32+
it('should add child component to top-level component', () => {
33+
const action = {
34+
type: 'ADD CHILD',
35+
payload: {
36+
type: 'Component',
37+
typeId: 2,
38+
childId: null
39+
}
40+
}
41+
// switch focus to very first root component
42+
state.canvasFocus = { componentId: 1, childId: null };
43+
console.log(state);
44+
state = reducer(state, action);
45+
const newParent = state.components[0];
46+
// expect new parent's children array to have length 1
47+
expect(newParent.children.length).toEqual(1);
48+
// expect new child to have type 'Component'
49+
console.log('new child ', newParent.children[0]);
50+
expect(newParent.children[0].type).toEqual('Component');
51+
const addedChild = state.components.find(comp => comp.id === newParent.children[0].typeId);
52+
// expect new child typeId to correspond to component with name 'TestRegular'
53+
expect(addedChild.name).toEqual('TestRegular');
54+
})
55+
})
56+
57+
// TEST 'CHANGE FOCUS'
58+
describe('CHANGE FOCUS reducer', () => {
59+
it('should change focus to specified component', () => {
60+
const action = {
61+
type: 'CHANGE FOCUS',
62+
payload: {
63+
componentId: 2,
64+
childId: null
65+
}
66+
}
67+
console.log('before change focus ', state.canvasFocus);
68+
state = reducer(state, action);
69+
console.log('after change focus ', state.canvasFocus);
70+
expect(state.canvasFocus.componentId).toEqual(2);
71+
expect(state.canvasFocus.childId).toEqual(null);
72+
})
73+
})
74+
75+
// TEST 'UPDATE CSS'
76+
77+
78+
// TEST 'RESET STATE'
79+
80+
})

app/electron/main.js

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,22 @@ const {
1010
// The splash screen is what appears while the app is loading
1111
const { initSplashScreen, OfficeTemplate } = require('electron-splashscreen');
1212
const { resolve } = require('app-root-path');
13-
const Protocol = require('./protocol');
14-
const MenuBuilder = require('./menu');
15-
const path = require('path');
1613

1714
const {
1815
default: installExtension,
1916
REACT_DEVELOPER_TOOLS
2017
} = require('electron-devtools-installer');
2118
const debug = require('electron-debug');
2219

23-
const isDev = process.env.NODE_ENV === 'development';
20+
const Protocol = require('./protocol');
21+
// menu from another file to modularize the code
22+
const MenuBuilder = require('./menu');
23+
24+
const path = require('path');
25+
// const fs = require('fs');
26+
27+
console.log('NODE ENV is ', process.env.NODE_ENV);
28+
const isDev = process.env.NODE_ENV === 'development' || process.env.NODE_ENV === 'test' ;
2429
const port = 8080;
2530
const selfHost = `http://localhost:${port}`;
2631

@@ -189,18 +194,19 @@ app.on('ready', createWindow);
189194
app.on('window-all-closed', () => {
190195
// On macOS it is common for applications and their menu bar
191196
// to stay active until the user quits explicitly with Cmd + Q
192-
if (process.platform !== 'darwin') {
193-
app.quit();
194-
} else {
195-
ContextMenu.clearMainBindings(ipcMain);
196-
}
197+
// if (process.platform !== 'darwin') {
198+
// app.quit();
199+
// } else {
200+
// ContextMenu.clearMainBindings(ipcMain);
201+
// }
202+
app.quit();
197203
});
198204

199-
app.on('activate', () => {
205+
app.on('activate', async () => {
200206
// On macOS it's common to re-create a window in the app when the
201207
// dock icon is clicked and there are no other windows open.
202208
if (win === null) {
203-
createWindow();
209+
await createWindow();
204210
}
205211
});
206212

app/src/components/App.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import React, { useReducer, useEffect } from 'react';
22
import '../public/styles/style.css';
3-
import '../public/styles/styleNew.css';
43
import { DndProvider } from 'react-dnd';
54
import { HTML5Backend } from 'react-dnd-html5-backend';
65
import AppContainer from '../containers/AppContainer';

app/src/helperFunctions/generateCode.ts

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
import { Component, State, ChildElement } from '../interfaces/InterfacesNew';
22
import HTMLTypes from '../context/HTMLTypes';
3+
const { format } = require('prettier');
4+
5+
declare global {
6+
interface Window {
7+
api: any;
8+
}
9+
}
310

411
// generate code based on the component heirarchy
512
const generateUnformattedCode = (
@@ -211,14 +218,20 @@ const generateUnformattedCode = (
211218

212219
// formats code with prettier linter
213220
const formatCode = (code: string) => {
214-
return window.api.formatCode(code);
215-
// return format(code, {
216-
// singleQuote: true,
217-
// trailingComma: 'es5',
218-
// bracketSpacing: true,
219-
// jsxBracketSameLine: true,
220-
// parser: 'babel'
221-
// });
221+
222+
// in test environment, window.api is not defined,
223+
// so we reference original prettier format function instead
224+
if (process.env.NODE_ENV === 'test') {
225+
return format(code, {
226+
singleQuote: true,
227+
trailingComma: 'es5',
228+
bracketSpacing: true,
229+
jsxBracketSameLine: true,
230+
parser: 'babel'
231+
});
232+
} else {
233+
return window.api.formatCode(code);
234+
}
222235
};
223236

224237
// generate code based on component heirarchy and then return the rendered code

app/src/public/styles/style.css

Lines changed: 59 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -301,12 +301,6 @@ div.rst__rowContents {
301301
cursor: pointer;
302302
}
303303

304-
/* @media only screen and (max-width: 560px) {
305-
.app-container {
306-
width: 80%;
307-
}
308-
} */
309-
310304
a.nav_link {
311305
color: rgba(0, 0, 0, 0.87);
312306
cursor: pointer;
@@ -316,3 +310,62 @@ a.nav_link:hover {
316310
color: #3ec1ac;
317311
text-decoration: underline;
318312
}
313+
314+
// Additional styling for ReacType X
315+
316+
.componentDefault {
317+
width: 100%;
318+
border: 2px solid gray;
319+
min-height: 150px;
320+
padding: 10px;
321+
background-color: lightgray;
322+
opacity: 0.75;
323+
}
324+
325+
.componentPanelWrapper {
326+
margin-top: 75px;
327+
width: 100%;
328+
}
329+
330+
.inputName {
331+
margin-bottom: 35px;
332+
text-align: center;
333+
}
334+
335+
.makeStyles-panelWrapperList-4::-webkit-scrollbar-track {
336+
background-color: rgba(25, 25, 25, 0.8);
337+
}
338+
339+
h4 {
340+
color: white;
341+
text-align: center;
342+
}
343+
344+
h3 {
345+
margin: 0;
346+
padding-left: 15px;
347+
padding-top: 15px;
348+
font-size: 1em;
349+
letter-spacing: 0.5px;
350+
}
351+
352+
.compPanelItem {
353+
height: 100%;
354+
position: relative;
355+
display: flex;
356+
}
357+
358+
.compPanelItem h3 {
359+
padding-top: 25px;
360+
font-size: 1.15em;
361+
letter-spacing: 0.75px;
362+
}
363+
364+
.compPanelItem:hover {
365+
cursor: pointer;
366+
}
367+
368+
.right {
369+
padding-top: 35px;
370+
width: 420px;
371+
}

app/src/public/styles/styleNew.css

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

app/src/reducers/componentReducer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ const reducer = (state: State, action: Action) => {
133133
type,
134134
typeId,
135135
childId
136-
}: { type: string; typeId: number; childId: number } = action.payload;
136+
}: { type: string; typeId: number; childId: any} = action.payload;
137137
// the parent of the new child is whichever component that is currently focused on
138138
const parentComponentId: number = state.canvasFocus.componentId;
139139

0 commit comments

Comments
 (0)