Skip to content

Commit 22fdf52

Browse files
committed
commit to switch branch
2 parents dc7f0a7 + 251938c commit 22fdf52

File tree

27 files changed

+477
-320
lines changed

27 files changed

+477
-320
lines changed

Dockerfile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
FROM node:10.1
2+
WORKDIR /usr/src/app
3+
COPY . /usr/src/app
4+
RUN npm install
5+
RUN npm run prod-build
6+
EXPOSE 5000
7+
CMD npm run server

__tests__/__snapshots__/enzyme.test.tsx.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -336,19 +336,19 @@ exports[`Test HTMLPanel Component Matches snapshot 1`] = `
336336
Object {
337337
"children": Array [],
338338
"code": "<div>Drag in a component or HTML element into the canvas!</div>",
339+
"future": Array [],
339340
"id": 1,
340341
"isPage": true,
341342
"name": "App",
343+
"past": Array [],
342344
"style": Object {},
343345
},
344346
],
345-
"future": Array [],
346347
"isLoggedIn": false,
347348
"name": "",
348349
"nextChildId": 1,
349350
"nextComponentId": 2,
350351
"nextTopSeparatorId": 1000,
351-
"past": Array [],
352352
"projectType": "Classic React",
353353
"rootComponents": Array [
354354
1,

__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__/gql.projects.test.js

Lines changed: 73 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,17 @@ const request = require('supertest');
33
const http = require('http');
44
const app = require('../server/server.js');
55

6-
const { GET_PROJECTS, ADD_LIKE } = require('../mockData');
7-
const { projectToSave, state } = require('../mockData');
6+
const mock = require('../mockData');
87

98
// tests user signup and login routes
109
describe('GraphQL tests', () => {
1110
let server;
12-
let projectId = "6052b90a6287fb36e96a2bfe";
11+
// Mutation test variables
12+
const projectId = '6053a36b6287fb36e92fab59'; // Must use a valid projectId from the database. NOTE: This should be revised for each Production Project Team since the database store different projectId
13+
const testNum = 100;
14+
const makeCopyUserIdTest = '604333d10004ad51c899e250';
15+
const makeCopyUsernameTest = 'test1';
16+
let makeCopyProjId = '';
1317

1418
beforeAll((done) => {
1519
server = http.createServer(app);
@@ -27,7 +31,7 @@ describe('GraphQL tests', () => {
2731
.post('/graphql')
2832
.set('Content-Type', 'application/json')
2933
.send({
30-
query: GET_PROJECTS,
34+
query: mock.GET_PROJECTS,
3135
})
3236
.expect(200)
3337
.then(res => expect(res.body.data.getAllProjects.length).toBeGreaterThanOrEqual(1)));
@@ -36,52 +40,91 @@ describe('GraphQL tests', () => {
3640
.post('/graphql')
3741
.set('Content-Type', 'application/json')
3842
.send({
39-
query: GET_PROJECTS,
43+
query: mock.GET_PROJECTS,
4044
variables: {
41-
userId: '603ac3454625489e492abe16',
45+
userId: '604d21b2b61a1c95f2dc9105',
4246
},
4347
})
4448
.expect(200)
45-
.then(res => expect(res.body.data.getAllProjects[0].userId).toBe('603ac3454625489e492abe16')));
49+
.then(res => expect(res.body.data.getAllProjects[0].userId).toBe('604d21b2b61a1c95f2dc9105')));
4650
});
4751

4852
// GraphQL Mutation
4953
describe('Testing GraphQL mutation', () => {
5054
// Add likes
51-
it('Increment likes by 1', () => request(server)
55+
it('addLike should update the "likes" field of the project document', () => request(server)
5256
.post('/graphql')
5357
.set('Content-Type', 'application/json')
5458
.send({
55-
mutation: ADD_LIKE,
59+
query: mock.ADD_LIKE,
5660
variables: {
5761
projId: projectId,
58-
likes: 100,
62+
likes: testNum,
5963
},
6064
})
6165
.expect(200)
62-
.then(res => expect(res.body.data.likes).toBe(1)));
63-
});
64-
65-
66-
// Publish project
66+
.then(res => expect(res.body.data.addLike.likes).toBe(testNum)));
6767

68-
// Make copy
68+
// Publish project
69+
it('Should set the "published" on the project document to TRUE', () => request(server)
70+
.post('/graphql')
71+
.set('Content-Type', 'application/json')
72+
.send({
73+
query: mock.PUBLISH_PROJECT,
74+
variables: {
75+
projId: projectId,
76+
published: true,
77+
},
78+
})
79+
.expect(200)
80+
.then(res => expect(res.body.data.publishProject.published).toBe(true)));
6981

70-
// Delete copy
82+
it('Should set the "published" on the project document to FALSE', () => request(server)
83+
.post('/graphql')
84+
.set('Content-Type', 'application/json')
85+
.send({
86+
query: mock.PUBLISH_PROJECT,
87+
variables: {
88+
projId: projectId,
89+
published: false,
90+
},
91+
})
92+
.expect(200)
93+
.then(res => expect(res.body.data.publishProject.published).toBe(false)));
7194

72-
// Delete project
95+
// Make copy
96+
it('Should make a copy of an existing project and change the userId and userName', () => request(server)
97+
.post('/graphql')
98+
.set('Content-Type', 'application/json')
99+
.send({
100+
query: mock.MAKE_COPY,
101+
variables: {
102+
projId: projectId,
103+
userId: makeCopyUserIdTest,
104+
username: makeCopyUsernameTest,
105+
},
106+
})
107+
.expect(200)
108+
.then((res) => {
109+
expect(res.body.data.makeCopy.userId).toBe(makeCopyUserIdTest);
110+
expect(res.body.data.makeCopy.username).toBe(makeCopyUsernameTest);
111+
makeCopyProjId = res.body.data.makeCopy.id;
112+
}));
73113

114+
// Delete copy
115+
it('Should make a copy of an existing project and change the userId and userName', () => request(server)
116+
.post('/graphql')
117+
.set('Content-Type', 'application/json')
118+
.send({
119+
query: mock.DELETE_PROJECT,
120+
variables: {
121+
projId: makeCopyProjId,
122+
},
123+
})
124+
.expect(200)
125+
.then((res) => {
126+
expect(res.body.data.deleteProject.id).toBe(makeCopyProjId);
127+
}));
128+
});
74129

75-
// it('getAllProjects should return projects that matches the provided userId', () => request(server)
76-
// .post('/graphql')
77-
// .set('Content-Type', 'application/json')
78-
// .send({
79-
// query: GET_PROJECTS,
80-
// variables: {
81-
// userId: '603ac3454625489e492abe16',
82-
// }
83-
// })
84-
// .expect(200)
85-
// .then(res => expect(res.body.data.getAllProjects[0].userId).toBe('603ac3454625489e492abe16')),
86-
// );
87130
});

__tests__/projects.test.js

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,20 @@
1+
const { Mongoose } = require('mongoose');
12
const request = require('supertest');
2-
const app = require('../server/server');
3-
4-
let server = 'https://reactype.herokuapp.com';
5-
const isDev = process.env.NODE_ENV === 'development';
6-
if (isDev) {
7-
// server = 'http://localhost:5000';
8-
server = require('..server/server');
9-
}
10-
3+
// initializes the project to be sent to server/DB
4+
const { projectToSave, state } = require('../mockData');
5+
const app = require('../server/server.js');
6+
const http = require('http');
7+
let server;
118
// save and get projects endpoint testing
129
describe('Project endpoints tests', () => {
1310
beforeAll((done) => {
1411
server = http.createServer(app);
1512
server.listen(done);
1613
});
17-
1814
afterAll((done) => {
1915
Mongoose.disconnect();
2016
server.close(done);
2117
});
22-
2318
// test saveProject endpoint
2419
describe('/saveProject', () => {
2520
describe('/POST', () => {
@@ -29,11 +24,11 @@ describe('Project endpoints tests', () => {
2924
.set('Accept', 'application/json')
3025
.send(projectToSave)
3126
.expect(200)
32-
.then(res => expect(res.body.project.name).toBe('test'));
27+
.expect('Content-Type', /application\/json/)
28+
.then((res) => expect(res.body.name).toBe(projectToSave.name));
3329
});
3430
});
3531
});
36-
3732
// test getProjects endpoint
3833
describe('/getProjects', () => {
3934
describe('POST', () => {
@@ -51,7 +46,6 @@ describe('Project endpoints tests', () => {
5146
});
5247
});
5348
});
54-
5549
// test deleteProject endpoint
5650
describe('/deleteProject', () => {
5751
describe('DELETE', () => {
@@ -62,8 +56,7 @@ describe('Project endpoints tests', () => {
6256
.set('Accept', 'application/json')
6357
.send({ name, userId })
6458
.expect(200)
65-
.expect('Content-Type', /json/)
66-
.then(res => expect(res.body.name).toBe('test'));
59+
.then((res) => expect(res.body.name).toBe(projectToSave.name));
6760
});
6861
});
6962
});

__tests__/users.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const app = require('../server/server.js');
55

66
const browser = 'http://localhost:8080'; // for checking endpoints accessed with hash router
77

8-
const { user } = require('../app/mockData');
8+
const { user } = require('../mockData');
99

1010
// tests user signup and login routes
1111
describe('User authentication tests', () => {

app/src/Dashboard/FormsContainer.tsx

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

0 commit comments

Comments
 (0)