Skip to content
This repository was archived by the owner on Sep 16, 2021. It is now read-only.

Commit 50a8024

Browse files
author
Rizchel Dayao
committed
Add tests
1 parent e4852c1 commit 50a8024

File tree

14 files changed

+217
-48
lines changed

14 files changed

+217
-48
lines changed

.babelrc

Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,3 @@
11
{
2-
"plugins": [
3-
["transform-es2015-template-literals", { "loose": true }],
4-
"transform-es2015-literals",
5-
"transform-es2015-function-name",
6-
"transform-es2015-arrow-functions",
7-
"transform-es2015-block-scoped-functions",
8-
["transform-es2015-classes", { "loose": true }],
9-
"transform-es2015-object-super",
10-
"transform-es2015-shorthand-properties",
11-
["transform-es2015-computed-properties", { "loose": true }],
12-
["transform-es2015-for-of", { "loose": true }],
13-
"transform-es2015-sticky-regex",
14-
"transform-es2015-unicode-regex",
15-
"check-es2015-constants",
16-
["transform-es2015-spread", { "loose": true }],
17-
"transform-es2015-parameters",
18-
["transform-es2015-destructuring", { "loose": true }],
19-
"transform-es2015-block-scoping",
20-
"transform-object-rest-spread",
21-
"transform-es3-member-expression-literals",
22-
"transform-es3-property-literals"
23-
],
24-
"env": {
25-
"commonjs": {
26-
"plugins": [
27-
["transform-es2015-modules-commonjs", { "loose": true }]
28-
]
29-
},
30-
"es": {
31-
"plugins": [
32-
"./build/use-lodash-es"
33-
]
34-
}
35-
}
2+
"presets": ["env", "react", "stage-2"]
363
}

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ install:
66
- npm install
77
script:
88
- npm run eslint
9-
# - npm run test
9+
- npm run test
1010
cache:
1111
directories:
1212
- node_modules

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ When the reader has completed this Code Pattern, they will understand how to:
3535

3636
## Prerequisites
3737
1. You must get an API key from [OMDb API](http://www.omdbapi.com/) in order to get a response from the API. You will insert your API key in /src/actions/index.js on line 42
38+
[OMDb API](http://www.omdbapi.com/) by Brian Fitz is licensed under [CC BY-NC 4.0](https://creativecommons.org/licenses/by-nc/4.0/)
3839

3940
2. Create an environment variable for your docker username
4041
```
@@ -58,7 +59,7 @@ $ git clone https://github.com/IBM/deploy-react-kubernetes
5859
2. Run the following commands in a terminal:
5960

6061
```
61-
$ npm install`
62+
$ npm install
6263
6364
$ npm run build-css
6465
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
2+
import {
3+
retrieveMoviesStart,
4+
retrieveMoviesError,
5+
retrieveMoviesSuccess,
6+
} from '../../../src/actions'
7+
import ActionTypes from '../../../src/constants'
8+
9+
const testObject = {
10+
title: 'Finding Nemo',
11+
year: '2002',
12+
plot: 'testing'
13+
}
14+
15+
describe('actions', () => {
16+
it('should start retrieving movies', () => {
17+
const retrieveMoviesStartAction = {
18+
type: ActionTypes.RETRIEVE_MOVIES_START
19+
}
20+
expect(retrieveMoviesStart()).toEqual(retrieveMoviesStartAction)
21+
})
22+
it('should give an error', () => {
23+
const retrieveMoviesErrorAction = {
24+
type: ActionTypes.RETRIEVE_MOVIES_ERROR,
25+
payload: 'error'
26+
}
27+
expect(retrieveMoviesError('error')).toEqual(retrieveMoviesErrorAction)
28+
})
29+
it('should give a successful response', () => {
30+
const retrieveMoviesSuccessAction = {
31+
type: ActionTypes.RETRIEVE_MOVIES_SUCCESS,
32+
payload: testObject
33+
}
34+
expect(retrieveMoviesSuccess(testObject)).toEqual(retrieveMoviesSuccessAction)
35+
})
36+
})
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import React from 'react'
2+
import { mount } from 'enzyme'
3+
import Input from '../../../src/components/Input'
4+
5+
describe('<Input />', () => {
6+
it('Basic render', () => {
7+
const wrapper = mount(<Input input='Finding Nemo' handleChange={jest.fn()} handleKeyPress={jest.fn()} handleResponse={jest.fn()} />);
8+
expect(wrapper.find('.set').length).toEqual(1);
9+
expect(wrapper.find('input').length).toEqual(1);
10+
expect(wrapper.find('button').length).toEqual(1);
11+
expect(wrapper.instance().props.input).toEqual('Finding Nemo');
12+
})
13+
})
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import React from 'react'
2+
import { mount } from 'enzyme'
3+
import ListItem from '../../../src/components/ListItem'
4+
5+
const testArray = [ 'Title: Finding Nemo', 'Year: 2002', 'Plot: testing']
6+
7+
describe('<ListItem />', () => {
8+
it('Basic render with empty list', () => {
9+
const wrapper = mount(<ListItem list={[]} />);
10+
expect(wrapper.find('.list-item').length).toEqual(1);
11+
expect(wrapper.find('ul').length).toEqual(1);
12+
expect(wrapper.find('li').length).toEqual(0);
13+
expect(wrapper.instance().props.list).toEqual([]);
14+
})
15+
it('Basic render with one item', () => {
16+
const wrapper = mount(<ListItem list={testArray} />);
17+
expect(wrapper.find('.list-item').length).toEqual(1);
18+
expect(wrapper.find('ul').length).toEqual(1);
19+
expect(wrapper.instance().props.list).toEqual(testArray);
20+
})
21+
})
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import React from 'react'
2+
import { mount } from 'enzyme'
3+
import InputSet from '../../../src/containers/InputSet'
4+
import configureStore from 'redux-mock-store'
5+
import { Provider } from 'react-redux'
6+
7+
const testObject = {
8+
title: 'Finding Nemo',
9+
year: 2002,
10+
plot: 'testing'
11+
}
12+
13+
const initialState = {
14+
movies: testObject
15+
}
16+
17+
const mockStore = configureStore()
18+
let wrapper
19+
let store
20+
21+
beforeEach(() => {
22+
store = mockStore(initialState)
23+
wrapper = mount(<Provider store={store}><InputSet movies={testObject} retrieveMovies={jest.fn()} /></Provider>)
24+
})
25+
26+
describe('<InputSet />', () => {
27+
it('Basic render', () => {
28+
expect(wrapper.find('.input-set').length).toEqual(1);
29+
})
30+
})
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import React from 'react'
2+
import { mount } from 'enzyme'
3+
import List from '../../../src/containers/List'
4+
import configureStore from 'redux-mock-store'
5+
import { Provider } from 'react-redux'
6+
7+
const testObject = [{
8+
title: 'Finding Nemo',
9+
year: 2002,
10+
plot: 'testing'
11+
}]
12+
13+
const initialState = {
14+
movies: testObject
15+
}
16+
17+
const mockStore = configureStore()
18+
let wrapper
19+
let store
20+
21+
beforeEach(() => {
22+
store = mockStore(initialState)
23+
wrapper = mount(<Provider store={store} movies={testObject}><List /></Provider>)
24+
})
25+
26+
describe('<List />', () => {
27+
it('Basic render with a movie', () => {
28+
expect(wrapper.find('.list').length).toEqual(1);
29+
expect(wrapper.instance().props.movies).toEqual(testObject);
30+
})
31+
it('Basic render without a movie', () => {
32+
const emptyWrapper = mount(<Provider store={store} movies={[]}><List /></Provider>)
33+
expect(emptyWrapper.find('.list').length).toEqual(1);
34+
expect(emptyWrapper.instance().props.movies).toEqual([]);
35+
})
36+
})
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import { movies } from '../../../src/reducers'
2+
import ActionTypes from '../../../src/constants'
3+
4+
const testObject = {
5+
title: 'Finding Nemo',
6+
year: '2002',
7+
plot: 'testing'
8+
}
9+
10+
describe('movies reducer', () => {
11+
it('should return the initial state', () => {
12+
expect(movies(undefined, {})).toEqual(
13+
{
14+
isFetching: false,
15+
items: [],
16+
errorDetails: ''
17+
}
18+
)
19+
})
20+
it('should handle RETRIEVE_MOVIES_START', () => {
21+
expect(
22+
movies([], {
23+
type: ActionTypes.RETRIEVE_MOVIES_START,
24+
})
25+
).toEqual(
26+
{
27+
isFetching: true
28+
}
29+
)
30+
})
31+
it('should handle RETRIEVE_MOVIES_ERROR', () => {
32+
expect(
33+
movies([], {
34+
type: ActionTypes.RETRIEVE_MOVIES_ERROR,
35+
payload: 'error',
36+
})
37+
).toEqual(
38+
{
39+
isFetching: false,
40+
errorDetails: 'Error'
41+
}
42+
)
43+
})
44+
it('should handle RETRIEVE_MOVIES_SUCCESS', () => {
45+
expect(
46+
movies([], {
47+
type: ActionTypes.RETRIEVE_MOVIES_SUCCESS,
48+
payload: testObject,
49+
})
50+
).toEqual(
51+
{
52+
isFetching: false,
53+
items: testObject
54+
}
55+
)
56+
})
57+
})

package.json

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,26 @@
33
"version": "0.0.1",
44
"description": "React Redux application that calls the OMDb api to get information on a specific movie",
55
"repository": "git+https://github.com/IBM/deploy-react-kubernetes",
6+
"license": "Apache-2.0",
67
"devDependencies": {
8+
"babel-cli": "^6.26.0",
79
"babel-eslint": "^7.2.3",
8-
"enzyme": "^2.4.1",
10+
"babel-jest": "^23.0.0-alpha.0",
11+
"babel-preset-env": "^1.6.1",
12+
"babel-preset-react": "^6.24.1",
13+
"babel-preset-stage-2": "^6.24.1",
14+
"enzyme": "^2.9.1",
915
"eslint": "^4.18.2",
1016
"eslint-config-react-app": "^2.1.0",
1117
"eslint-plugin-flowtype": "^2.46.1",
1218
"eslint-plugin-import": "^2.9.0",
1319
"eslint-plugin-jsx-a11y": "^5.1.1",
1420
"eslint-plugin-react": "^7.7.0",
21+
"jest": "^22.4.2",
1522
"node-sass": "^4.5.0",
1623
"react-scripts": "^1.1.1",
1724
"redux-logger": "^2.8.1",
25+
"redux-mock-store": "^1.5.1",
1826
"redux-router": "^2.1.2",
1927
"redux-thunk": "^2.2.0",
2028
"sass-loader": "^6.0.2"
@@ -34,7 +42,8 @@
3442
"start": "react-scripts start",
3543
"build": "react-scripts build",
3644
"eject": "react-scripts eject",
37-
"test": "react-scripts test",
38-
"eslint": "eslint . --ext .js"
45+
"eslint": "eslint . --ext .js",
46+
"test": "jest",
47+
"test:watch": "npm test -- --watch"
3948
}
4049
}

0 commit comments

Comments
 (0)