Skip to content

Commit c6974a0

Browse files
author
john lim
committed
testing
1 parent 310b85d commit c6974a0

File tree

7 files changed

+141
-24
lines changed

7 files changed

+141
-24
lines changed

__tests__/__snapshots__/enzyme.test.tsx.snap

Lines changed: 89 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3+
exports[`Test All 10 default HTML elements have rendered Matches snapshot 1`] = `<HTMLPanel />`;
4+
35
exports[`Test the BottomTabs component Matches snapshot 1`] = `
46
<div
57
className="makeStyles-root-1"
8+
style={null}
69
>
710
<Styled(MuiBox)
811
display="flex"
@@ -28,9 +31,94 @@ exports[`Test the BottomTabs component Matches snapshot 1`] = `
2831
disableRipple={true}
2932
label="Code Preview"
3033
/>
34+
<WithStyles(ForwardRef(Tab))
35+
classes={
36+
Object {
37+
"root": "makeStyles-tabRoot-5",
38+
"selected": "makeStyles-tabSelected-6",
39+
}
40+
}
41+
disableRipple={true}
42+
label="Component Tree"
43+
/>
3144
</WithStyles(ForwardRef(Tabs))>
45+
<WithStyles(ForwardRef(FormControl))>
46+
<div
47+
className="flex-container"
48+
>
49+
<div
50+
className="flex1"
51+
>
52+
Change Theme:
53+
</div>
54+
<WithStyles(ForwardRef(NativeSelect))
55+
className="flex2"
56+
onChange={[Function]}
57+
style={
58+
Object {
59+
"color": "white",
60+
}
61+
}
62+
value="monokai"
63+
>
64+
<option
65+
style={
66+
Object {
67+
"backgroundColor": "#252526",
68+
}
69+
}
70+
value="monokai"
71+
>
72+
Monokai
73+
</option>
74+
<option
75+
style={
76+
Object {
77+
"backgroundColor": "#252526",
78+
}
79+
}
80+
value="github"
81+
>
82+
Github
83+
</option>
84+
<option
85+
style={
86+
Object {
87+
"backgroundColor": "#252526",
88+
}
89+
}
90+
value="solarized_dark"
91+
>
92+
Solarized Dark
93+
</option>
94+
<option
95+
style={
96+
Object {
97+
"backgroundColor": "#252526",
98+
}
99+
}
100+
value="terminal"
101+
>
102+
Terminal
103+
</option>
104+
<option
105+
style={
106+
Object {
107+
"backgroundColor": "#252526",
108+
}
109+
}
110+
value="solarized_light"
111+
>
112+
Solarized Light
113+
</option>
114+
</WithStyles(ForwardRef(NativeSelect))>
115+
</div>
116+
</WithStyles(ForwardRef(FormControl))>
32117
</Styled(MuiBox)>
33-
<CodePreview />
118+
<CodePreview
119+
setTheme={[Function]}
120+
theme="monokai"
121+
/>
34122
</div>
35123
`;
36124

__tests__/componentReducer.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import { State, Action, Component, ChildElement } from '../app/src/interfaces/In
44
import initialState from '../app/src/context/initialState';
55

66

7-
describe('Testing componentReducer functionality', function () {
7+
xdescribe('Testing componentReducer functionality', function () {
88
let state: State = initialState;
9-
9+
1010

1111
// TEST 'ADD COMPONENT'
1212
describe('ADD COMPONENT reducer', () => {
@@ -44,7 +44,7 @@ describe('Testing componentReducer functionality', function () {
4444
const newParent = state.components[0];
4545
// expect new parent's children array to have length 1
4646
expect(newParent.children.length).toEqual(1);
47-
// expect new child to have type 'Component'
47+
// expect new child to have type 'Component'
4848
expect(newParent.children[0].type).toEqual('Component');
4949
const addedChild = state.components.find(comp => comp.id === newParent.children[0].typeId);
5050
// expect new child typeId to correspond to component with name 'TestRegular'
@@ -68,7 +68,7 @@ describe('Testing componentReducer functionality', function () {
6868
type: 'CHANGE POSITION',
6969
payload: {
7070
currentChildId: 1,
71-
newParentChildId: null
71+
newParentChildId: null
7272
}
7373
}
7474
state = reducer(state, actionChangePos);
@@ -175,4 +175,4 @@ describe('Testing componentReducer functionality', function () {
175175
})
176176
})
177177

178-
})
178+
})

__tests__/enzyme.test.tsx

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
import { shallow, mount } from 'enzyme';
2-
import React from 'react';
2+
import React, { useState, useContext } from 'react';
33

4+
import { StateContext } from '../app/src/context/context';
5+
import initialState from '../app/src/context/initialState';
46
import MainContainer from '../app/src/containers/MainContainer';
57
import BottomPanel from '../app/src/components/bottom/BottomPanel';
68
import BottomTabs from '../app/src/components/bottom/BottomTabs';
79
import CodePreview from '../app/src/components/bottom/CodePreview';
810
import CanvasContainer from '../app/src/components/main/CanvasContainer';
911
import Canvas from '../app/src/components/main/Canvas';
10-
12+
import HTMLPanel from '../app/src/components/left/HTMLPanel';
13+
import HTMLItem from '../app/src/components/left/HTMLItem';
14+
import LeftContainer from '../app/src/containers/LeftContainer';
1115

1216
describe('Test the CanvasContainer component', () => {
1317
const target = shallow(<CanvasContainer />);
@@ -39,3 +43,25 @@ describe('Test the BottomTabs component', () => {
3943
})
4044
})
4145

46+
describe('Test All 10 default HTML elements have rendered', () => {
47+
48+
const target = shallow(
49+
<StateContext.Provider value={initialState} >
50+
<HTMLPanel />
51+
</StateContext.Provider>
52+
);
53+
54+
it('Matches snapshot', () => {
55+
expect(target).toMatchSnapshot();
56+
})
57+
it('Contains 10 HTMLItem component', () => {
58+
expect(target.contains(<HTMLItem/>)).toBe(true);
59+
expect(target.find(HTMLItem)).toHaveLength(10);
60+
})
61+
// it('Contains custom HTML form', () => {
62+
// expect(target.find('form')).toBe(true)
63+
// })
64+
// it('Contains 10 HTML Items', () => {
65+
// expect(target.contains(<HTMLItem />)).toBe(true)
66+
// })
67+
})

__tests__/userAuth.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import { sessionIsCreated, newUserIsCreated } from '../app/src/helperFunctions/auth';
22

3-
describe('Login Tests', () => {
3+
xdescribe('Login Tests', () => {
44
jest.setTimeout(10000);
55
let username;
6-
let password;
6+
let password;
77

88
// Called under SignIn.tsx
9-
describe('sessionIsCreated', async () => {
9+
describe('sessionIsCreated', () => {
1010
it('returns the message \'No Username Input\' when no username is entered', async () => {
1111
username = '';
1212
password = 'codesmith1!'
@@ -37,7 +37,7 @@ describe('Login Tests', () => {
3737

3838
it('returns the message \'Success\' when the user passes all auth checks', async () => {
3939
username = 'reactyp3test';
40-
password = 'codesmith1!';
40+
password = 'codesmith1!';
4141
const result = await sessionIsCreated(username, password).then((loginStatus) => loginStatus);
4242
expect(result).toEqual('Success');
4343
})

__tests__/users.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ if (isDev) {
66
}
77

88
// tests user signup and login routes
9-
describe('User authentication tests', () => {
9+
xdescribe('User authentication tests', () => {
1010
let num = Math.floor(Math.random() * 1000);
1111

1212
describe('/signup', () => {

app/src/components/bottom/CodePreview.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,12 @@ import 'ace-builds/src-noconflict/theme-solarized_light';
99
import 'ace-builds/src-noconflict/theme-terminal';
1010
import { Component } from '../../interfaces/Interfaces';
1111
import useResizeObserver from '../../tree/useResizeObserver';
12+
import { string } from 'prop-types';
1213

13-
const CodePreview = ({ theme, setTheme }) => {
14+
const CodePreview: React.FC<{
15+
theme: string | null;
16+
setTheme: any | null;
17+
}> = ({ theme, setTheme }) => {
1418
const wrapper = useRef();
1519
const dimensions = useResizeObserver(wrapper);
1620
const { width, height } =

app/src/components/left/HTMLPanel.tsx

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,23 @@ import Grid from '@material-ui/core/Grid';
33
import { StateContext } from '../../context/context';
44
import HTMLItem from './HTMLItem';
55
import { makeStyles } from '@material-ui/core/styles';
6+
import initialState from '../../context/initialState';
67

78
const HTMLPanel = (): JSX.Element => {
89
const classes = useStyles();
10+
const [tag, setTag] = useState('');
11+
const [name, setName] = useState('');
12+
const [errorMsg, setErrorMsg] = useState('');
13+
const [errorStatus, setErrorStatus] = useState(false);
914
const [state, dispatch] = useContext(StateContext);
10-
1115
let startingID = 0;
12-
for (let i = 0; i < state.HTMLTypes.length; i+=1) {
13-
if (state.HTMLTypes[i].id >= startingID) {
14-
startingID = state.HTMLTypes[i].id;
16+
state.HTMLTypes.forEach((el) => {
17+
if (el.id >= startingID) {
18+
startingID = el.id;
1519
}
16-
}
20+
})
1721
startingID += 1;
18-
19-
const [tag, setTag] = useState('');
20-
const [name, setName] = useState('');
2122
const [currentID, setCurrentID] = useState(startingID);
22-
const [errorMsg, setErrorMsg] = useState('');
23-
const [errorStatus, setErrorStatus] = useState(false);
2423

2524
const buttonClasses =
2625
'MuiButtonBase-root MuiButton-root MuiButton-text makeStyles-button-12 MuiButton-textPrimary';

0 commit comments

Comments
 (0)