Skip to content

Commit 97208fc

Browse files
committed
jest & spectron test
1 parent f1b8246 commit 97208fc

File tree

8 files changed

+170
-69
lines changed

8 files changed

+170
-69
lines changed

__tests__/componentReducer.test.ts

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
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+
const path = require('path');
7+
const Application = require('spectron').Application;
8+
const baseDir = path.join(__dirname, '..');
9+
const electronPath = path.join(baseDir, 'node_modules', '.bin', 'electron');
10+
11+
const app = new Application({
12+
path: electronPath,
13+
args: ['../app/electron/main.js']
14+
})
15+
// const testComponent: Component = {
16+
// id: 2,
17+
// name: "Test",
18+
// nextChildId: 1,
19+
// style: {},
20+
// code: '',
21+
// children: []
22+
// }
23+
24+
describe('Testing componentReducer functionality', () => {
25+
let state: State = initialState;
26+
27+
beforeAll(() => {
28+
return app.start();
29+
})
30+
31+
afterAll(() => {
32+
if (app && app.isRunning()) {
33+
return app.stop();
34+
}
35+
})
36+
37+
// TEST 'ADD COMPONENT'
38+
describe('ADD COMPONENT reducer', () => {
39+
it('should add new reuseable component to state', () => {
40+
const action = {
41+
type: 'ADD COMPONENT',
42+
payload: {
43+
componentName: "TestRegular",
44+
root: false
45+
}
46+
}
47+
state = reducer(state, action);
48+
// expect state.components array to have length 2
49+
const length = state.components.length;
50+
expect(length).toEqual(2);
51+
// expect new component name to match name of last elem in state.components array
52+
expect(state.components[length - 1].name).toEqual(action.payload.componentName);
53+
})
54+
})
55+
56+
// TEST 'ADD CHILD'
57+
describe('ADD CHILD reducer', () => {
58+
it('should add child component to top-level component', () => {
59+
const action = {
60+
type: 'ADD CHILD',
61+
payload: {
62+
type: 'Component',
63+
typeId: 2,
64+
childId: null
65+
}
66+
}
67+
state.canvasFocus = { componentId: 1, childId: null };
68+
console.log(state);
69+
const newState = reducer(state, action);
70+
const newParent = newState.components[0];
71+
// expect newParent's children array to have length 1
72+
expect(newParent.children.length).toEqual(1);
73+
// expect child to have type 'Component' and name 'TestRegular'
74+
expect(newParent.children[0].type).toEqual('Component');
75+
expect(newParent.children[0].name).toEqual('TestRegular');
76+
})
77+
})
78+
// TEST 'CHANGE FOCUS'
79+
80+
// TEST 'UPDATE CSS'
81+
82+
// TEST 'SET INITIAL STATE'
83+
84+
})

app/electron/main.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const path = require('path');
2424
// const fs = require('fs');
2525

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

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, { useState, 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/components/main/CanvasContainer.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import Canvas from './Canvas';
44
// The CanvasContainer sets the boundaries on the width/height of the canvas
55
function CanvasContainer() {
66
const canvasContainerStyle = {
7-
height: '950px',
87
width: '100%',
98
backgroundColor: 'lightgrey',
109
border: '2px Solid grey',

app/src/public/styles/style.css

Lines changed: 60 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ h1 {
168168
background: #fff;
169169
flex: 1;
170170
width: 100%;
171-
/* overflow: hidden; */
171+
overflow: auto;
172172
display: flex;
173173
background-color: #e4e4e4;
174174
/* justify-content: center;
@@ -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;
@@ -315,4 +309,63 @@ a.nav_link {
315309
a.nav_link:hover {
316310
color: #3EC1AC;
317311
text-decoration: underline;
312+
}
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;
318371
}

app/src/public/styles/styleNew.css

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

app/src/reducers/componentReducer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ const reducer = (state: State, action: Action) => {
113113

114114
// update the focus to the new component
115115
const canvasFocus = {
116-
...canvasFocus,
116+
...state.canvasFocus,
117117
componentId: newComponent.id,
118118
childId: null
119119
};

package.json

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"Andrew Cho"
2525
],
2626
"scripts": {
27-
"postinstall": "electron-builder install-app-deps",
27+
"postinstall": "ELECTRON_BUILDER_ALLOW_UNRESOLVED_DEPENDENCIES=true electron-builder install-app-deps",
2828
"dev-server": "cross-env NODE_ENV=development webpack-dev-server --config ./webpack.development.js",
2929
"dev": "concurrently --success first \"npm run dev-server\" \"cross-env NODE_ENV=development electron .\" -k",
3030
"prod-build": "cross-env NODE_ENV=production npx webpack --mode=production --config ./webpack.production.js",
@@ -34,7 +34,8 @@
3434
"dist-mac": "npm run prod-build && electron-builder --mac",
3535
"dist-linux": "npm run prod-build && electron-builder --linux",
3636
"dist-windows": "npm run prod-build && electron-builder --windows",
37-
"dist-all": "npm run prod-build && electron-builder --mac --linux --windows"
37+
"dist-all": "npm run prod-build && electron-builder --mac --linux --windows",
38+
"test": "cross-env NODE_ENV=test jest --verbose"
3839
},
3940
"build": {
4041
"productName": "ReacType",
@@ -72,6 +73,26 @@
7273
"boilerplate"
7374
],
7475
"license": "MIT",
76+
"jest": {
77+
"moduleNameMapper": {
78+
"^.+\\.(css|scss|styl|less|sass|scss|png|jpg|ttf|woff|woff2)$": "identity-obj-proxy",
79+
"electron": "<rootDir>/__mocks__/electron.ts"
80+
},
81+
"moduleFileExtensions": [
82+
"ts",
83+
"tsx",
84+
"js"
85+
],
86+
"transform": {
87+
"\\.(ts|tsx)$": "<rootDir>/node_modules/ts-jest"
88+
},
89+
"testRegex": "/__tests__/.*\\.(ts|tsx|js)$",
90+
"globals": {
91+
"ts-jest": {
92+
"diagnostics": false
93+
}
94+
}
95+
},
7596
"bugs": {
7697
"url": "https://github.com/open-source-labs/ReacType/issues"
7798
},
@@ -194,6 +215,7 @@
194215
"postcss-loader": "^2.1.6",
195216
"redux-mock-store": "^1.5.4",
196217
"sass-loader": "^7.0.3",
218+
"spectron": "^11.1.0",
197219
"style-loader": "^0.20.3",
198220
"ts-jest": "^25.3.0",
199221
"ts-node": "^8.10.2",

0 commit comments

Comments
 (0)