Add tests

This commit is contained in:
DD 2017-08-25 10:45:22 -04:00
parent a622d0d3e9
commit 34ce004a14
3 changed files with 61 additions and 0 deletions

View file

@ -0,0 +1,15 @@
/* eslint-env jest */
import React from 'react'; // eslint-disable-line no-unused-vars
import {shallow} from 'enzyme';
import EraserModeComponent from '../../../src/components/eraser-mode.jsx'; // eslint-disable-line no-unused-vars
describe('EraserModeComponent', () => {
test('triggers callback when clicked', () => {
const onClick = jest.fn();
const componentShallowWrapper = shallow(
<EraserModeComponent onMouseDown={onClick}/>
);
componentShallowWrapper.simulate('click');
expect(onClick).toHaveBeenCalled();
});
});

View file

@ -0,0 +1,15 @@
/* eslint-env jest */
import React from 'react'; // eslint-disable-line no-unused-vars
import {shallow} from 'enzyme';
import LineModeComponent from '../../../src/components/line-mode.jsx'; // eslint-disable-line no-unused-vars
describe('LineModeComponent', () => {
test('triggers callback when clicked', () => {
const onClick = jest.fn();
const componentShallowWrapper = shallow(
<LineModeComponent onMouseDown={onClick}/>
);
componentShallowWrapper.simulate('click');
expect(onClick).toHaveBeenCalled();
});
});

View file

@ -0,0 +1,31 @@
/* eslint-env jest */
import lineReducer from '../../src/reducers/line-mode';
import {changeLineWidth} from '../../src/reducers/line-mode';
test('initialState', () => {
let defaultState;
expect(lineReducer(defaultState /* state */, {type: 'anything'} /* action */)).toBeDefined();
expect(lineReducer(defaultState /* state */, {type: 'anything'} /* action */).lineWidth).toBeGreaterThan(0);
});
test('changeLineWidth', () => {
let defaultState;
const newLineWidth = 8078;
expect(lineReducer(defaultState /* state */, changeLineWidth(newLineWidth) /* action */))
.toEqual({lineWidth: newLineWidth});
expect(lineReducer(2 /* state */, changeLineWidth(newLineWidth) /* action */))
.toEqual({lineWidth: newLineWidth});
expect(lineReducer(2 /* state */, changeLineWidth(-1) /* action */))
.toEqual({lineWidth: 1});
});
test('invalidChangeLineWidth', () => {
const origState = {lineWidth: 2};
expect(lineReducer(origState /* state */, changeLineWidth('invalid argument') /* action */))
.toBe(origState);
expect(lineReducer(origState /* state */, changeLineWidth() /* action */))
.toBe(origState);
});