diff --git a/__mocks__/fileMock.js b/__mocks__/fileMock.js new file mode 100644 index 0000000..fd566b2 --- /dev/null +++ b/__mocks__/fileMock.js @@ -0,0 +1,5 @@ +/** + * Created by invader on 18.10.16. + */ + +module.exports = 'test-file-stub'; \ No newline at end of file diff --git a/__mocks__/styleMock.js b/__mocks__/styleMock.js new file mode 100644 index 0000000..5b21cff --- /dev/null +++ b/__mocks__/styleMock.js @@ -0,0 +1,5 @@ +/** + * Created by invader on 18.10.16. + */ + +module.exports = {}; \ No newline at end of file diff --git a/package.json b/package.json index cf81fde..7bd4dd3 100644 --- a/package.json +++ b/package.json @@ -31,6 +31,13 @@ "author": "Stdio.Digital", "license": "MIT", "homepage": "https://github.com/hex22a/post3ree-boilerplate#post3ree-boilerplate", + "jest": { + "verbose": true, + "moduleNameMapper": { + "^.+\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": "/__mocks__/fileMock.js", + "^.+\\.(css|less|pcss)$": "identity-obj-proxy" + } + }, "devDependencies": { "autoprefixer": "^6.3.6", "babel": "^6.5.2", @@ -56,8 +63,8 @@ "cookie-parser": "^1.4.1", "css-loader": "^0.25.0", "css-modules-require-hook": "^4.0.2", - "enzyme": "^2.4.1", "cucumber": "^1.3.1", + "enzyme": "^2.4.1", "eslint": "^3.3.1", "eslint-config-airbnb-base": "^8.0.0", "eslint-loader": "^1.3.0", @@ -70,6 +77,7 @@ "file-loader": "^0.9.0", "history": "^4.3.0", "http": "0.0.0", + "identity-obj-proxy": "^3.0.0", "image-webpack-loader": "^2.0.0", "immutable": "^3.7.6", "jest": "^16.0.1", @@ -89,6 +97,7 @@ "pug": "^2.0.0-beta5", "pug-html-loader": "^1.0.8", "react": "^15.3.1", + "react-addons-test-utils": "^15.3.2", "react-datepicker": "^0.30.0", "react-dom": "^15.3.1", "react-hot-loader": "^3.0.0-beta.5", @@ -100,6 +109,7 @@ "redux-devtools-dock-monitor": "^1.1.0", "redux-devtools-log-monitor": "^1.0.4", "redux-logger": "^2.6.0", + "redux-mock-store": "^1.2.1", "redux-thunk": "^2.1.0", "rethinkdb": "^2.2.2", "style-loader": "^0.13.0", @@ -115,4 +125,4 @@ "dependencies": { "forever": "^0.15.2" } -} \ No newline at end of file +} diff --git a/universal/containers/ContainerWrapper.js b/universal/containers/ContainerWrapperHOC.js similarity index 100% rename from universal/containers/ContainerWrapper.js rename to universal/containers/ContainerWrapperHOC.js diff --git a/universal/containers/Main.js b/universal/containers/Main.js index 12f43a0..2107493 100644 --- a/universal/containers/Main.js +++ b/universal/containers/Main.js @@ -3,11 +3,11 @@ import { connect } from 'react-redux' import './common/main.pcss' -import ContainerWrapperHOC from './ContainerWrapper' +import ContainerWrapperHOC from './ContainerWrapperHOC' import Container from '../components/Container/Container' import Menu from '../components/Menu/Menu' -class Main extends Component { +export class Main extends Component { render() { return ( diff --git a/universal/containers/SignIn.js b/universal/containers/SignIn.js index 1a89c9b..a365562 100644 --- a/universal/containers/SignIn.js +++ b/universal/containers/SignIn.js @@ -1,7 +1,7 @@ import React, { Component } from 'react' import { connect } from 'react-redux' -import ContainerWrapperHOC from './ContainerWrapper' +import ContainerWrapperHOC from './ContainerWrapperHOC' import Container from '../components/Container/Container' import Menu from '../components/Menu/Menu' import SignInForm from '../components/SignInForm/SignInForm' diff --git a/universal/containers/SignUp.js b/universal/containers/SignUp.js index 0dbc174..6a9a118 100644 --- a/universal/containers/SignUp.js +++ b/universal/containers/SignUp.js @@ -1,7 +1,7 @@ import React, { Component } from 'react' import { connect } from 'react-redux' -import ContainerWrapperHOC from './ContainerWrapper' +import ContainerWrapperHOC from './ContainerWrapperHOC' import Container from '../components/Container/Container' import Menu from '../components/Menu/Menu' import SignUpForm from '../components/SignUpForm/SignUpForm' diff --git a/universal/containers/__tests__/Main.test.js b/universal/containers/__tests__/Main.test.js new file mode 100644 index 0000000..48e3e0c --- /dev/null +++ b/universal/containers/__tests__/Main.test.js @@ -0,0 +1,35 @@ +/** + * Created by invader on 18.10.16. + */ + +import React from 'react' +import configureStore from 'redux-mock-store' +import jest from 'jest' +import { mount, shallow, ShallowWrapper } from 'enzyme' +import ConnectedMain, { Main } from '../Main' + +const mockStore = configureStore(); + +function setup() { + const props = { + isAuthenticated: false, + payload: { + sub: '', + role: '' + } + }; + + const enzymeWrapper = shallow(
); + + return { props, enzymeWrapper } +} + +describe('Main container', () => { + describe('descr', () => { + const { enzymeWrapper } = setup(); + + it('Should render self and subcomponents', () => { + expect(enzymeWrapper.find('div').isEmpty()).toBe(false) + }); + }); +}); \ No newline at end of file diff --git a/universal/reducers/__tests__/auth.test.js b/universal/reducers/__tests__/auth.test.js index 5f66fc3..96fe22d 100644 --- a/universal/reducers/__tests__/auth.test.js +++ b/universal/reducers/__tests__/auth.test.js @@ -1,41 +1,45 @@ import reducer from '../auth' import * as constants from '../../actions/constants' +const PAYLOAD = { + uuid: 'jest@example.com', + role: 'user' +}; + describe('Auth reducers', () => { describe('Auth', () => { it('Should return the initial state', () => { expect(reducer.auth(undefined, {})).toEqual({ isAuthenticated: false, - role: '' + payload: { + sub: '', + role: '' + } }); }); it('Should handle LOGIN_SUCCESS from user', () => { expect(reducer.auth({}, { type: constants.LOGIN_SUCCESS, - role: 'user' + payload: PAYLOAD })).toEqual({ isAuthenticated: true, - role: 'user' + payload: { + uuid: 'jest@example.com', + role: 'user' + } }); }); - it('Should handle LOGIN_SUCCESS from admin', () => { - expect(reducer.auth({}, { - type: constants.LOGIN_SUCCESS, - role: 'admin' - })).toEqual({ - isAuthenticated: true, - role: 'admin' - }) - }); - it('Should handle LOGOUT_SUCCESS from any user', () => { expect(reducer.auth({}, { type: constants.LOGOUT_SUCCESS })).toEqual({ isAuthenticated: false, - role: '' + payload: { + sub: '', + role: '' + } }) }) });