Skip to content

Commit 4166033

Browse files
committed
Merge branch 'dev' into Hernan/alerts
2 parents 1fe35ea + 1e6fe53 commit 4166033

26 files changed

+670
-223
lines changed

__tests__/projects.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const http = require('http')
1111
const {state, projectToSave } = mockData
1212

1313
// save and get projects endpoint testing
14-
xdescribe('Project endpoints tests', () => {
14+
describe('Project endpoints tests', () => {
1515
let server;
1616
beforeAll((done) => {
1717
server = http.createServer(app);
@@ -22,7 +22,7 @@ xdescribe('Project endpoints tests', () => {
2222
server.close(done);
2323
});
2424
// test saveProject endpoint
25-
xdescribe('/saveProject', () => {
25+
describe('/saveProject', () => {
2626
describe('/POST', () => {
2727
it('responds with a status of 200 and json object equal to project sent', () => {
2828
return request(server)
@@ -36,7 +36,7 @@ xdescribe('Project endpoints tests', () => {
3636
});
3737
});
3838
// test getProjects endpoint
39-
xdescribe('/getProjects', () => {
39+
describe('/getProjects', () => {
4040
describe('POST', () => {
4141
it('responds with status of 200 and json object equal to an array of user projects', () => {
4242
return request(server)
@@ -53,7 +53,7 @@ xdescribe('Project endpoints tests', () => {
5353
});
5454
});
5555
// test deleteProject endpoint
56-
xdescribe('/deleteProject', () => {
56+
describe('/deleteProject', () => {
5757
describe('DELETE', () => {
5858
const { name, userId } = projectToSave;
5959
it('responds with status of 200 and json object equal to deleted project', () => {

__tests__/server.test.tsx

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
import marketplaceController from '../server/controllers/marketplaceController';
2+
import app from '../server/server';
3+
import mockData from '../mockData';
4+
const request = require('supertest');
5+
const mongoose = require('mongoose');
6+
const mockNext = jest.fn(); // Mock nextFunction
7+
const MONGO_DB = process.env.MONGO_DB_TEST;
8+
const { state, projectToSave, user } = mockData
9+
const PORT = 8080;
10+
11+
beforeAll(async () => {
12+
await mongoose.connect(MONGO_DB, {
13+
useNewUrlParser: true,
14+
useUnifiedTopology: true,
15+
});
16+
});
17+
18+
afterAll(async () => {
19+
await mongoose.connection.close();
20+
});
21+
22+
describe('Server endpoint tests', () => {
23+
it('should pass this test request', async () => {
24+
const response = await request(app).get('/test');
25+
expect(response.status).toBe(200);
26+
expect(response.text).toBe('test request is working');
27+
});
28+
describe('Marketplace endpoint testing', () => {
29+
it('get requests to /getMarketplaceProjects should return an array of projects', async () => {
30+
const response = await request(app).get('/getMarketplaceProjects');
31+
expect(response.status).toBe(200);
32+
expect(Array.isArray(response.body)).toBe(true);
33+
});
34+
it('the return array should be populated with project objects', async () => {
35+
const response = await request(app).get('/getMarketplaceProjects');
36+
expect(response.status).toBe(200);
37+
expect(Array.isArray(response.body)).toBe(true);
38+
});
39+
});
40+
// test saveProject endpoint
41+
describe('/saveProject', () => {
42+
describe('/POST', () => {
43+
it('responds with a status of 200 and json object equal to project sent', async () => {
44+
// const response = await request(app).post('/saveProject').set('Accept', 'application/json').send(projectToSave);
45+
// console.log(response);
46+
// console.log(response.body);
47+
// expect(response.status).toBe(200);
48+
return request(app)
49+
.post('/saveProject')
50+
.set('Accept', 'application/json')
51+
.send(projectToSave)
52+
.expect(200)
53+
.expect('Content-Type', /application\/json/)
54+
.then((res) => expect(res.body.name).toBe(projectToSave.name));
55+
});
56+
// });
57+
});
58+
// test getProjects endpoint
59+
describe('/getProjects', () => {
60+
describe('POST', () => {
61+
it('responds with status of 200 and json object equal to an array of user projects', () => {
62+
return request(app)
63+
.post('/getProjects')
64+
.set('Accept', 'application/json')
65+
.send({ userId: projectToSave.userId })
66+
.expect(200)
67+
.expect('Content-Type', /json/)
68+
.then((res) => {
69+
expect(Array.isArray(res.body)).toBeTruthy;
70+
expect(res.body[0].name).toBe(state.name);
71+
});
72+
});
73+
});
74+
});
75+
// test deleteProject endpoint
76+
describe('/deleteProject', () => {
77+
describe('DELETE', () => {
78+
it('responds with status of 200 and json object equal to deleted project', async () => {
79+
const response: Response = await request(app).post('/getProjects').set('Accept', 'application/json').send({ userId: projectToSave.userId });
80+
const _id: String = response.body[0]._id;
81+
const userId: String = user.username;
82+
console.log(_id, userId);
83+
return request(app)
84+
.delete('/deleteProject')
85+
.set('Content-Type', 'application/json')
86+
.send({ _id, userId })
87+
.expect(200)
88+
.then((res) => expect(res.body.name).toBe(projectToSave.name)); // @Denton might want to check more of these fields
89+
});
90+
});
91+
});
92+
});
93+
});
94+
95+
96+
97+
98+
99+
100+
101+
// describe('marketplaceController Middleware', () => {
102+
// describe('getProjects tests', () => {
103+
// it('should add the projects as an array to res.locals', () => {
104+
// const req = {};
105+
// const res = { locals: {} };
106+
// console.log(marketplaceController.getPublishedProjects);
107+
// console.log(typeof marketplaceController.getPublishedProjects);
108+
// marketplaceController.getPublishedProjects(req, res, mockNext);
109+
// expect(Array.isArray(res.locals.publishedProjects)).toBe(true);
110+
// expect(mockNext).toHaveBeenCalled();
111+
// });
112+
// });
113+
114+
115+
// it('should send an error response if there is an error in the middleware', () => {
116+
// const req = { user: { isAuthenticated: false } };
117+
// const res = mockResponse();
118+
119+
// marketplaceController.authenticateMiddleware(req, res, mockNext);
120+
121+
// expect(res.status).toHaveBeenCalledWith(500);
122+
// expect(res.json).toHaveBeenCalledWith({ err: 'Error in marketplaceController.getPublishedProjects, check server logs for details' });
123+
// });
124+
// });

app/src/components/App.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { saveProject } from '../helperFunctions/projectGetSaveDel';
1919
// Intermediary component to wrap main App component with higher order provider components
2020
export const App = (): JSX.Element => {
2121
const state = useSelector((store: RootState) => store.appState);
22+
2223
const [toggleAttempt, setToggleAttempt] = useState(false);
2324
const dispatch = useDispatch();
2425
// checks if user is signed in as guest or actual user and changes loggedIn boolean accordingly
@@ -34,11 +35,15 @@ export const App = (): JSX.Element => {
3435
console.log('state.isLoggedIn', state.isLoggedIn)
3536
// console.log('cookies.get in App', Cookies.get())
3637
// if user is a guest, see if a project exists in localforage and retrieve it
38+
// v17 May not currently work yet
3739
if (!state.isLoggedIn) {
40+
console.log('not state.islogged in')
3841
localforage.getItem('guestProject').then((project) => {
3942
// if project exists, use dispatch to set initial state to that project
43+
console.log('guestProject', project)
4044
if (project) {
4145
dispatch(setInitialState(project));
46+
console.log('project', project)
4247
}
4348
});
4449
} else {

app/src/components/left/ComponentDrag.tsx

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import React from 'react';
2-
import Grid from '@mui/material/Grid';
31
import ComponentPanelItem from '../right/ComponentPanelItem';
2+
import Grid from '@mui/material/Grid';
3+
import React from 'react';
4+
import { RootState } from '../../redux/store';
45
import makeStyles from '@mui/styles/makeStyles';
56
import { useSelector } from 'react-redux';
6-
import { RootState } from '../../redux/store';
77
// The component panel section of the left panel displays all components and has the ability to add new components
88
const ComponentDrag = ({ isThemeLight }): JSX.Element => {
99
const classes = useStyles();
@@ -37,6 +37,7 @@ const ComponentDrag = ({ isThemeLight }): JSX.Element => {
3737
direction="row"
3838
justifyContent="center"
3939
alignItems="center"
40+
4041
>
4142
{state.components
4243
.filter((comp) => state.rootComponents.includes(comp.id))
@@ -54,7 +55,7 @@ const ComponentDrag = ({ isThemeLight }): JSX.Element => {
5455
})}
5556
</Grid>
5657
{/* Display all reusable components */}
57-
<h4
58+
{/* <h4
5859
className={
5960
!isDarkMode
6061
? classes.lightThemeFontColor
@@ -83,7 +84,7 @@ const ComponentDrag = ({ isThemeLight }): JSX.Element => {
8384
/>
8485
);
8586
})}
86-
</Grid>
87+
</Grid> */}
8788
</div>
8889
</div>
8990
);
@@ -99,16 +100,9 @@ const useStyles = makeStyles({
99100
},
100101
panelWrapperList: {
101102
minHeight: '120px',
102-
marginLeft: '-15px',
103-
marginRight: '-15px',
104-
width: '100%',
105-
display: 'flex',
106-
flexDirection: 'column',
107-
alignItems: 'center',
108-
wordWrap: 'break-word'
109103
},
110104
lightThemeFontColor: {
111-
color: '#155084'
105+
color: '#fff'
112106
},
113107
darkThemeFontColor: {
114108
color: '#fff'
Lines changed: 68 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,74 @@
1+
import ComponentPanelItem from '../right/ComponentPanelItem';
2+
import Grid from '@mui/material/Grid';
13
import React from 'react';
4+
import { RootState } from '../../redux/store';
5+
import makeStyles from '@mui/styles/makeStyles';
6+
import { useSelector } from 'react-redux';
27

38
const ComponentsContainer = () => {
4-
return <div>ComponentsContainer</div>;
9+
const classes = useStyles();
10+
const state = useSelector((store: RootState) => store.appState);
11+
const isDarkMode = useSelector(
12+
(store: RootState) => store.darkMode.isDarkMode
13+
);
14+
const isFocus = (targetId: Number) => {
15+
return state.canvasFocus.componentId === targetId ? true : false;
16+
};
17+
return (
18+
<div>
19+
<div className={classes.panelWrapper}>
20+
<div className={classes.panelWrapperList}>
21+
<h4
22+
className={
23+
!isDarkMode
24+
? classes.lightThemeFontColor
25+
: classes.darkThemeFontColor
26+
}
27+
>
28+
Reusable Components
29+
</h4>
30+
<Grid
31+
container
32+
direction="column"
33+
alignContent={"center"}
34+
>
35+
{state.components
36+
.filter((comp) => !state.rootComponents.includes(comp.id))
37+
.map((comp) => {
38+
return (
39+
<ComponentPanelItem
40+
isFocus={isFocus(comp.id)}
41+
key={`comp-${comp.id}`}
42+
name={comp.name}
43+
id={comp.id}
44+
root={false}
45+
/>
46+
);
47+
})}
48+
</Grid>
49+
</div>
50+
</div>
51+
</div>
52+
);
553
};
654

55+
const useStyles = makeStyles({
56+
panelWrapper: {
57+
display: 'flex',
58+
flexDirection: 'column',
59+
alignItems: 'center',
60+
flexGrow: 1,
61+
overflow: 'auto'
62+
},
63+
panelWrapperList: {
64+
minHeight: '120px',
65+
},
66+
lightThemeFontColor: {
67+
color: '#fff'
68+
},
69+
darkThemeFontColor: {
70+
color: '#fff'
71+
}
72+
});
73+
774
export default ComponentsContainer;

app/src/components/left/ContentArea.tsx

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,35 +5,38 @@ import React from 'react';
55
import RoomsContainer from './RoomsContainer';
66
import TreeContainer from './TreeContainer';
77

8-
interface TabPanelProps {
9-
value: number;
10-
index: number;
8+
interface ContentAreaProps {
9+
activeTab: number | null;
10+
isVisible: boolean;
1111
}
1212

13-
const TabPanel: React.FC<TabPanelProps> = ({ children, value, index }) => {
14-
return <Box hidden={value !== index}>{value === index && children}</Box>;
13+
const TabPanel: React.FC<{
14+
children: React.ReactNode;
15+
activeTab: number | null;
16+
index: number;
17+
}> = ({ children, activeTab, index }) => {
18+
return (
19+
<Box hidden={activeTab !== index}>{activeTab === index && children}</Box>
20+
);
1521
};
1622

17-
const ContentArea: React.FC<{ value: number | null }> = ({ value }) => {
18-
if (value === null) {
19-
return null;
20-
}
21-
23+
const panels = [
24+
<ElementsContainer />,
25+
<ComponentsContainer />,
26+
<RoomsContainer />
27+
];
28+
const ContentArea: React.FC<ContentAreaProps> = ({ activeTab, isVisible }) => {
2229
return (
23-
<div className="left-container">
30+
<div
31+
className="left-container"
32+
style={{ display: isVisible ? 'block' : 'none' }} // Visibility based on activeTab
33+
>
2434
<div className="column left">
25-
<TabPanel value={value} index={0}>
26-
<ElementsContainer />
27-
</TabPanel>
28-
<TabPanel value={value} index={1}>
29-
<ComponentsContainer />
30-
</TabPanel>
31-
<TabPanel value={value} index={2}>
32-
<TreeContainer />
33-
</TabPanel>
34-
<TabPanel value={value} index={3}>
35-
<RoomsContainer />
36-
</TabPanel>
35+
{panels.map((panel, idx) => (
36+
<TabPanel activeTab={activeTab} index={idx} key={idx}>
37+
{panel}
38+
</TabPanel>
39+
))}
3740
</div>
3841
</div>
3942
);

app/src/components/left/DragDropPanel.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ const DragDropPanel = (props): JSX.Element => {
8686
state.projectType === 'Classic React'
8787
) {
8888
return (
89-
<Grid item xs={2} sm={2} md={2}>
89+
<Grid item xs={2} sm={2} md={2} key={option.name}>
9090
<HTMLItem
9191
name={option.name}
9292
key={`html-${option.name}`}

app/src/components/left/ElementsContainer.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ const ElementsContainer = (props): JSX.Element => {
4848
textAlign: 'center'
4949
}}
5050
>
51-
<h4>Drag and Drop</h4>
51+
{' '}
5252
<DragDropPanel />
5353
<div id={'CompBottomHalf'}>
5454
<ComponentDrag isThemeLight={props.isThemeLight} />

0 commit comments

Comments
 (0)