scratch-paint/test/unit/blob-mode-reducer.test.js

44 lines
1.8 KiB
JavaScript
Raw Normal View History

2017-07-27 22:58:31 -04:00
/* eslint-env jest */
import brushReducer, {changeBrushSize} from '../../src/reducers/brush-mode';
import eraserReducer, {changeBrushSize as changeEraserSize} from '../../src/reducers/eraser-mode';
2017-07-27 22:58:31 -04:00
test('initialState', () => {
let defaultState;
expect(brushReducer(defaultState /* state */, {type: 'anything'} /* action */)).toBeDefined();
expect(brushReducer(defaultState /* state */, {type: 'anything'} /* action */).brushSize).toBeGreaterThan(0);
expect(eraserReducer(defaultState /* state */, {type: 'anything'} /* action */)).toBeTruthy();
expect(eraserReducer(defaultState /* state */, {type: 'anything'} /* action */).brushSize).toBeGreaterThan(0);
});
test('changeBrushSize', () => {
let defaultState;
2017-07-27 22:58:31 -04:00
const newBrushSize = 8078;
expect(brushReducer(defaultState /* state */, changeBrushSize(newBrushSize) /* action */))
2017-07-27 22:58:31 -04:00
.toEqual({brushSize: newBrushSize});
expect(brushReducer(1 /* state */, changeBrushSize(newBrushSize) /* action */))
2017-07-27 22:58:31 -04:00
.toEqual({brushSize: newBrushSize});
expect(eraserReducer(defaultState /* state */, changeEraserSize(newBrushSize) /* action */))
2017-07-27 22:58:31 -04:00
.toEqual({brushSize: newBrushSize});
expect(eraserReducer(1 /* state */, changeEraserSize(newBrushSize) /* action */))
2017-07-27 22:58:31 -04:00
.toEqual({brushSize: newBrushSize});
});
test('invalidChangeBrushSize', () => {
const origState = {brushSize: 1};
expect(brushReducer(origState /* state */, changeBrushSize('invalid argument') /* action */))
2017-07-27 22:58:31 -04:00
.toBe(origState);
expect(brushReducer(origState /* state */, changeBrushSize() /* action */))
2017-07-27 22:58:31 -04:00
.toBe(origState);
expect(eraserReducer(origState /* state */, changeEraserSize('invalid argument') /* action */))
2017-07-27 22:58:31 -04:00
.toBe(origState);
expect(eraserReducer(origState /* state */, changeEraserSize() /* action */))
2017-07-27 22:58:31 -04:00
.toBe(origState);
});