Skip to content

Commit d676cf6

Browse files
authored
Merge pull request #61 from fredosauce/working
Finished Enzyme test cases
2 parents 806c394 + 1f5f9c6 commit d676cf6

File tree

7 files changed

+155
-20
lines changed

7 files changed

+155
-20
lines changed

.travis.yml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
11
language: node_js
22
node_js:
3-
- 10
3+
- "10"
4+
dist: trusty
5+
cache:
6+
directories:
7+
- node_modules
8+
install:
9+
- npm install
10+
- npm run prod-build
11+
script:
12+
- npm run test
13+
Lines changed: 45 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,49 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3-
exports[`Enzyme testing suite renders snapshots, too 1`] = `
4-
<div>
5-
<h1>
6-
Hello, Enzyme!
7-
</h1>
3+
exports[`Test the BottomTabs component Matches snapshot 1`] = `
4+
<div
5+
className="makeStyles-root-1"
6+
>
7+
<Styled(MuiBox)
8+
display="flex"
9+
justifyContent="space-between"
10+
>
11+
<WithStyles(ForwardRef(Tabs))
12+
classes={
13+
Object {
14+
"indicator": "makeStyles-tabsIndicator-4",
15+
"root": "makeStyles-tabsRoot-3",
16+
}
17+
}
18+
onChange={[Function]}
19+
value={0}
20+
>
21+
<WithStyles(ForwardRef(Tab))
22+
classes={
23+
Object {
24+
"root": "makeStyles-tabRoot-5",
25+
"selected": "makeStyles-tabSelected-6",
26+
}
27+
}
28+
disableRipple={true}
29+
label="Code Preview"
30+
/>
31+
</WithStyles(ForwardRef(Tabs))>
32+
</Styled(MuiBox)>
33+
<CodePreview />
34+
</div>
35+
`;
36+
37+
exports[`Test the CanvasContainer component Matches snapshot 1`] = `
38+
<div
39+
style={
40+
Object {
41+
"backgroundColor": "lightgrey",
42+
"border": "2px Solid grey",
43+
"width": "100%",
44+
}
45+
}
46+
>
47+
<Canvas />
848
</div>
949
`;

__tests__/componentReducer.test.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,13 +162,16 @@ describe('Testing componentReducer functionality', function () {
162162
describe('RESET STATE reducer', () => {
163163
it('should reset project to initial state', () => {
164164
const action: Action = {
165-
type: 'RESET STATE'
165+
type: 'RESET STATE',
166+
payload: ''
166167
}
167168
state = reducer(state, action);
168169
// expect default project to have empty string as name
169-
expect(state.name).toEqual('');
170+
expect(state.name).toEqual('TESTNAME');
170171
// expect default project to only have one component in components array
171172
expect(state.components.length).toEqual(1);
173+
// expect lone component to have no children :(
174+
expect(state.components[0].children.length).toEqual(0);
172175
})
173176
})
174177

__tests__/enzyme.test.tsx

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,41 @@
1-
import { shallow } from 'enzyme';
1+
import { shallow, mount } from 'enzyme';
22
import React from 'react';
33

4-
describe('Enzyme testing suite', () => {
4+
import MainContainer from '../app/src/containers/MainContainer';
5+
import BottomPanel from '../app/src/components/bottom/BottomPanel';
6+
import BottomTabs from '../app/src/components/bottom/BottomTabs';
7+
import CodePreview from '../app/src/components/bottom/CodePreview';
8+
import CanvasContainer from '../app/src/components/main/CanvasContainer';
9+
import Canvas from '../app/src/components/main/Canvas';
510

6-
it('renders snapshots, too', () => {
7-
const wrapper = shallow(<div>
8-
<h1>Hello, Enzyme!</h1>
9-
</div>)
10-
expect(wrapper).toMatchSnapshot()
11+
12+
describe('Test the CanvasContainer component', () => {
13+
const target = shallow(<CanvasContainer />);
14+
it('Matches snapshot', () => {
15+
expect(target).toMatchSnapshot()
16+
})
17+
it('Contains Canvas component', () => {
18+
expect(target.contains(<Canvas />)).toBe(true);
19+
})
20+
})
21+
22+
describe('Test the MainContainer component', () => {
23+
const target = shallow(<MainContainer />);
24+
it('Contains CanvasContainer component', () => {
25+
expect(target.contains(<CanvasContainer />)).toBe(true);
26+
})
27+
it('Contains BottomPanel component', () => {
28+
expect(target.contains(<BottomPanel />)).toBe(true);
1129
})
12-
})
30+
})
31+
32+
describe('Test the BottomTabs component', () => {
33+
const target = shallow(<BottomTabs />);
34+
it('Matches snapshot', () => {
35+
expect(target).toMatchSnapshot()
36+
})
37+
it('Contains a CodePreview component', () => {
38+
expect(target.contains(<CodePreview />)).toBe(true);
39+
})
40+
})
41+

__tests__/userAuth.test.ts

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import { sessionIsCreated, newUserIsCreated } from '../app/src/helperFunctions/auth';
2+
3+
describe('Login Tests', () => {
4+
jest.setTimeout(10000);
5+
let username;
6+
let password;
7+
8+
// Called under SignIn.tsx
9+
describe('sessionIsCreated', async () => {
10+
it('returns the message \'No Username Input\' when no username is entered', async () => {
11+
username = '';
12+
password = 'codesmith1!'
13+
const result = await sessionIsCreated(username, password).then((loginStatus) => loginStatus);
14+
expect(result).toEqual('No Username Input');
15+
})
16+
17+
it('returns the message \'No Password Input\' when no password is entered', async () => {
18+
username = 'reactyp3test';
19+
password = ''
20+
const result = await sessionIsCreated(username, password).then((loginStatus) => loginStatus);
21+
expect(result).toEqual('No Password Input');
22+
})
23+
24+
it('returns the message \'Invalid Username\' when username does not exist', async () => {
25+
username = 'l!b'; //breaks the 4 character minimum and no special characters
26+
password = 'test';
27+
const result = await sessionIsCreated(username, password).then((loginStatus) => loginStatus);
28+
expect(result).toEqual('Invalid Username');
29+
})
30+
31+
it('returns the message \'Incorrect Password\' when password does not match', async () => {
32+
username = 'reactyp3test';
33+
password = 'incorrect';
34+
const result = await sessionIsCreated(username, password).then((loginStatus) => loginStatus);
35+
expect(result).toEqual('Incorrect Password');
36+
})
37+
38+
it('returns the message \'Success\' when the user passes all auth checks', async () => {
39+
username = 'reactyp3test';
40+
password = 'codesmith1!';
41+
const result = await sessionIsCreated(username, password).then((loginStatus) => loginStatus);
42+
expect(result).toEqual('Success');
43+
})
44+
})
45+
46+
})
47+

app/src/helperFunctions/auth.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
const fetch = require("node-fetch");
2+
13
const isDev = process.env.NODE_ENV === 'development';
24
let serverURL = 'https://reactype.herokuapp.com';
35
if (isDev) {
@@ -33,7 +35,6 @@ export const sessionIsCreated = (
3335
}
3436
})
3537
.catch(err => {
36-
console.log('Error while trying to login', err);
3738
return 'Error';
3839
});
3940
return result;
@@ -69,7 +70,6 @@ export const newUserIsCreated = (
6970
return data; // response is either Email Taken or Username Taken, refer to userController.createUser
7071
})
7172
.catch(err => {
72-
console.log(err);
7373
return 'Error';
7474
});
7575
return result;

package.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,12 @@
7272
"diagnostics": false
7373
}
7474
},
75-
"setupFilesAfterEnv": ["<rootDir>/app/setupTests.ts"],
76-
"snapshotSerializers": ["enzyme-to-json/serializer"]
75+
"setupFilesAfterEnv": [
76+
"<rootDir>/app/setupTests.ts"
77+
],
78+
"snapshotSerializers": [
79+
"enzyme-to-json/serializer"
80+
]
7781
},
7882
"bugs": {
7983
"url": "https://github.com/open-source-labs/ReacType/issues"
@@ -106,6 +110,7 @@
106110
"immutable": "^4.0.0-rc.12",
107111
"js-cookie": "^2.2.1",
108112
"localforage": "^1.7.2",
113+
"node-fetch": "^2.6.0",
109114
"prettier": "^1.19.1",
110115
"prop-types": "^15.6.2",
111116
"react": "^16.13.0",
@@ -123,6 +128,7 @@
123128
"@babel/preset-env": "^7.10.4",
124129
"@babel/preset-react": "^7.10.4",
125130
"@babel/preset-typescript": "^7.10.4",
131+
"@testing-library/react": "^10.4.6",
126132
"@types/chai": "^4.2.11",
127133
"@types/enzyme": "^3.10.5",
128134
"@types/enzyme-adapter-react-16": "^1.0.6",

0 commit comments

Comments
 (0)