Skip to content

Commit

Permalink
enzyme & co
Browse files Browse the repository at this point in the history
  • Loading branch information
01dr committed Oct 19, 2016
1 parent d7bdd9a commit 8bec266
Show file tree
Hide file tree
Showing 9 changed files with 79 additions and 20 deletions.
5 changes: 5 additions & 0 deletions __mocks__/fileMock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/**
* Created by invader on 18.10.16.
*/

module.exports = 'test-file-stub';
5 changes: 5 additions & 0 deletions __mocks__/styleMock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/**
* Created by invader on 18.10.16.
*/

module.exports = {};
14 changes: 12 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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)$": "<rootDir>/__mocks__/fileMock.js",
"^.+\\.(css|less|pcss)$": "identity-obj-proxy"
}
},
"devDependencies": {
"autoprefixer": "^6.3.6",
"babel": "^6.5.2",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -115,4 +125,4 @@
"dependencies": {
"forever": "^0.15.2"
}
}
}
File renamed without changes.
4 changes: 2 additions & 2 deletions universal/containers/Main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<Container>
Expand Down
2 changes: 1 addition & 1 deletion universal/containers/SignIn.js
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
2 changes: 1 addition & 1 deletion universal/containers/#.js
Original file line number Diff line number Diff line change
@@ -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 #Form from '../components/#Form/#Form'
Expand Down
35 changes: 35 additions & 0 deletions universal/containers/__tests__/Main.test.js
Original file line number Diff line number Diff line change
@@ -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(<Main {...props} />);

return { props, enzymeWrapper }
}

describe('Main container', () => {
describe('descr', () => {
const { enzymeWrapper } = setup();

it('Should render self and subcomponents', () => {
expect(enzymeWrapper.find('div').isEmpty()).toBe(false)
});
});
});
32 changes: 18 additions & 14 deletions universal/reducers/__tests__/auth.test.js
Original file line number Diff line number Diff line change
@@ -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: ''
}
})
})
});
Expand Down

0 comments on commit 8bec266

Please # to comment.