mirror of
https://github.com/scratchfoundation/scratch-paint.git
synced 2024-12-22 13:32:28 -05:00
Add tests
This commit is contained in:
parent
a622d0d3e9
commit
34ce004a14
3 changed files with 61 additions and 0 deletions
15
test/unit/components/eraser-mode.test.jsx
Normal file
15
test/unit/components/eraser-mode.test.jsx
Normal 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();
|
||||
});
|
||||
});
|
15
test/unit/components/line-mode.test.jsx
Normal file
15
test/unit/components/line-mode.test.jsx
Normal 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();
|
||||
});
|
||||
});
|
31
test/unit/line-mode-reducer.test.js
Normal file
31
test/unit/line-mode-reducer.test.js
Normal 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);
|
||||
});
|
Loading…
Reference in a new issue