Skip to content

Commit

Permalink
drop mocha and chai for jest with coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
bruno12mota committed Dec 15, 2016
1 parent 6293414 commit d5c6a56
Show file tree
Hide file tree
Showing 35 changed files with 1,500 additions and 789 deletions.
4 changes: 4 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"presets": ["react", "es2015", "stage-0"],
"plugins": ["transform-decorators-legacy"]
}
1 change: 1 addition & 0 deletions __mocks__/file-mock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = 'test-file-stub';
1 change: 1 addition & 0 deletions __mocks__/style-mock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = {};
23 changes: 13 additions & 10 deletions lib/shared/elements/index.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
const requireContext = require.context('.', true, /^\.\/[a-z\-]+?\/index\.(js|jsx)$/);
const elements = {};

requireContext.keys().forEach((path) => {
const splitted = path.split('/');
const name = splitted[1]
.replace('custom-', '')
.replace('-', ' ')
.replace(/\b\w/g, l => l.toUpperCase())
.replace(' ', '');
if (process.env.NODE_ENV !== 'test') {
const requireContext = require.context('.', true, /^\.\/[a-z\-]+?\/index\.(js|jsx)$/);

elements[name] = requireContext(path).default;
});
requireContext.keys().forEach((path) => {
const splitted = path.split('/');
const name = splitted[1]
.replace('custom-', '')
.replace('-', ' ')
.replace(/\b\w/g, l => l.toUpperCase())
.replace(' ', '');

elements[name] = requireContext(path).default;
});
}

export default elements;
2 changes: 1 addition & 1 deletion lib/shared/reducers/__tests__/.eslintrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"env": {
"mocha": true
"jest": true
},
"rules": {
"no-unused-expressions": 0
Expand Down
10 changes: 5 additions & 5 deletions lib/shared/reducers/__tests__/admin-menu.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
import actionTypes from 'actions';
import chai from 'chai';


import adminMenuReducer, {defaultState} from '../admin-menu';

const expect = chai.expect;


describe('Admin menu Reducer', () => {
it('should return the initial state', () => {
const state = '';
const action = {};
const newState = adminMenuReducer(state, action);
expect(newState).to.equal(state);
expect(newState).toBe(state);
});

it('should return true if OPENING the admin menu', () => {
const state = defaultState;
const action = {type: actionTypes.openAdminMenu};
const newState = adminMenuReducer(state, action);
// Using equal(true) instead of .true to avoid JSLint error
expect(newState).to.be.true;
expect(newState).toBeTruthy();
});

it('show return false if CLOSING the admin menu', () => {
const state = defaultState;
const action = {type: actionTypes.closeAdminMenu};
const newState = adminMenuReducer(state, action);
// Using equal(true) instead of .true to avoid JSLint error
expect(newState).to.be.false;
expect(newState).toBeFalsy();
});
});
74 changes: 40 additions & 34 deletions lib/shared/reducers/__tests__/color.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
import actionTypes from 'actions';
import chai from 'chai';


import colorReducer, {defaultState} from '../color';

const expect = chai.expect;


describe('Color Reducer', () => {
const color = '#ffffff';

it('should return the initial state as default', () => {
expect(
colorReducer(undefined, {})
).to.deep.equal(defaultState);
).toEqual(defaultState);
});

it('should return state with opened true appended to state when OPENING new color', () => {
const action = {
type: actionTypes.openNewColor
};
// check if it has opened property
expect(colorReducer(defaultState, action)).to.be.an('object');
expect(colorReducer(defaultState, action)).toBeInstanceOf(Object);

// check if the the property opened is set to false
expect(Object.getOwnPropertyDescriptor(colorReducer(defaultState, {}), 'opened').value).
Expand All @@ -30,33 +30,29 @@ describe('Color Reducer', () => {
const action = {
type: actionTypes.closeNewColor
};

// check if it has opened property
expect(colorReducer(defaultState, action)).to.have.property('opened');
const result = colorReducer(defaultState, action);

// check if the the property opened is set to false
expect(colorReducer(defaultState, action)).to.have.property('opened').to.be.false;

// expect(colorReducer(defaultState, action)).ownPropertyDescriptor('editing').to.be.false;
expect(colorReducer(defaultState, action)).to.have.property('label').to.equal('');
expect(colorReducer(defaultState, action))
.to.have.property('value')
.to.have.property('value')
.to.equal('#000000');
expect(result.opened).toBeFalsy();

// expect(colorReducer(defaultState, action)).ownPropertyDescriptor('editing').toBeFalsy();
expect(result.label).toBe('');
expect(result.value.value).toBe('#000000');
});

it('should handle OPEN_EDIT_COLOR', () => {
const action = {
type: actionTypes.openEditColor,
color: {value: color, _id: 5, label: 'Test'}
};
expect(colorReducer(defaultState, action)).to.be.an('object');
expect(colorReducer(defaultState, action)).to.have.property('opened').to.be.true;
expect(colorReducer(defaultState, action)).to.have.property('editing').to.be.true;
expect(colorReducer(defaultState, action)).to.have.property('editingId').to.equal(5);
expect(colorReducer(defaultState, action)).to.have.property('label').to.equal('Test');
expect(colorReducer(defaultState, action)).to.have.property('value')
.to.have.property('value').to.equal(color);
const result = colorReducer(defaultState, action);

expect(result).toBeInstanceOf(Object);
expect(result.opened).toBeTruthy();
expect(result.editing).toBeTruthy();
expect(result.editingId).toBe(5);
expect(result.label).toBe('Test');
expect(result.value.value).toBe(color);
});

it('should handle CHANGE_COLOR_PROPERTY', () => {
Expand All @@ -65,43 +61,53 @@ describe('Color Reducer', () => {
property: 'default',
value: 'default_value'
};
expect(colorReducer(defaultState, action)).to.be.an('object');
expect(colorReducer(defaultState, action)).to.have.property(action.property).to.equal(action.value);
const result = colorReducer(defaultState, action);

expect(result).toBeInstanceOf(Object);
expect(result[action.property]).toBe(action.value);
});

it('should handle COLOR_LOADING', () => {
const action = {
type: actionTypes.colorLoading
};
expect(colorReducer(defaultState, action)).to.be.an('object');
expect(colorReducer(defaultState, action)).to.have.property('loading').to.be.true;
const result = colorReducer(defaultState, action);

expect(result).toBeInstanceOf(Object);
expect(result.loading).toBeTruthy();
});

it('should handle COLOR_SUCCESS', () => {
const action = {
type: actionTypes.colorSuccess
};
expect(colorReducer(defaultState, action)).to.be.an('object');
expect(colorReducer(defaultState, action)).to.deep.equal(defaultState);
const result = colorReducer(defaultState, action);

expect(result).toBeInstanceOf(Object);
expect(result).toEqual(defaultState);
});

it('should handle OPEN_REMOVE_COLOR', () => {
const action = {
type: actionTypes.openRemoveColor,
id: 5
};
expect(colorReducer(defaultState, action)).to.be.an('object');
expect(colorReducer(defaultState, action)).to.have.property('removeOpened').to.be.true;
expect(colorReducer(defaultState, action)).to.have.property('removeId').to.equal(5);
const result = colorReducer(defaultState, action);

expect(result).toBeInstanceOf(Object);
expect(result.removeOpened).toBeTruthy();
expect(result.removeId).toBe(5);
});

it('should handle CLOSE_REMOVE_COLOR', () => {
const action = {
type: actionTypes.closeRemoveColor,
id: 5
};
expect(colorReducer(defaultState, action)).to.be.an('object');
expect(colorReducer(defaultState, action)).to.have.property('removeOpened').to.be.false;
expect(colorReducer(defaultState, action)).to.have.property('removeId').to.be.null;
const result = colorReducer(defaultState, action);

expect(result).toBeInstanceOf(Object);
expect(result.removeOpened).toBeFalsy();
expect(result.removeId).toBeNull();
});
});
8 changes: 4 additions & 4 deletions lib/shared/reducers/__tests__/display.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import actionTypes from 'actions';
import chai from 'chai';


import displayReducer, {defaultState} from '../display';

const expect = chai.expect;


describe('Display reducer', () => {
it('should return the default state for other actions', () => {
expect(displayReducer()).to.equal(defaultState);
expect(displayReducer()).toBe(defaultState);
});
it('should return action value for action type change display', () => {
const action = {type: actionTypes.changeDisplay, value: 'test'};
expect(displayReducer(defaultState, action)).to.equal(action.value);
expect(displayReducer(defaultState, action)).toBe(action.value);
});
});
26 changes: 14 additions & 12 deletions lib/shared/reducers/__tests__/dnd.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import actionTypes from 'actions';
import chai from 'chai';


import dndReducer, {defaultState} from '../dnd';

const expect = chai.expect;


describe('DND Reducer', () => {
it('should return the initial state', () => {
expect(dndReducer(defaultState, {})).to.equal(defaultState);
expect(dndReducer(defaultState, {})).toBe(defaultState);
});

it('should handle START_DRAGGING', () => {
Expand All @@ -16,21 +16,23 @@ describe('DND Reducer', () => {
draggingData: 'Test',
dragInfo: 'Test2'
};
const result = dndReducer(defaultState, action);

expect(dndReducer(defaultState, action)).to.be.an('object');
expect(dndReducer(defaultState, action)).to.have.property('dragging').to.be.true;
expect(dndReducer(defaultState, action)).to.have.property('draggingData').to.equal('Test');
expect(dndReducer(defaultState, action)).to.have.property('dragInfo').to.equal('Test2');
expect(result).toBeInstanceOf(Object);
expect(result.dragging).toBeTruthy();
expect(result.draggingData).toBe('Test');
expect(result.dragInfo).toBe('Test2');
});

it('should handle ON_DROPPABLE', () => {
const action = {
type: actionTypes.onDroppable,
dropInfo: 'Test2'
};
const result = dndReducer(defaultState, action);

expect(dndReducer(defaultState, action)).to.be.an('object');
expect(dndReducer(defaultState, action)).to.have.property('dropInfo').to.equal(action.dropInfo);
expect(result).toBeInstanceOf(Object);
expect(result.dropInfo).toBe(action.dropInfo);
});

it('should handle OUT_DROPPABLE', () => {
Expand All @@ -45,11 +47,11 @@ describe('DND Reducer', () => {
theState.dropInfo = {};
theState.dropInfo.id = 5;

expect(dndReducer(theState, {})).to.equal(theState);
expect(dndReducer(theState, action)).to.have.property('dropInfo').to.be.false;
expect(dndReducer(theState, {})).toBe(theState);
expect(dndReducer(theState, action).dropInfo).toBeFalsy();
});

it('should handle STOP_DRAGGING', () => {
expect(dndReducer(defaultState, {})).to.equal(defaultState);
expect(dndReducer(defaultState, {})).toBe(defaultState);
});
});
Loading

0 comments on commit d5c6a56

Please sign in to comment.