mirror of
https://github.com/scratchfoundation/scratch-paint.git
synced 2024-12-22 13:32:28 -05:00
make modes independent of tool. Fix tests
This commit is contained in:
parent
087a6264a0
commit
33a01c1396
9 changed files with 50 additions and 48 deletions
|
@ -41,9 +41,7 @@ class BrushMode extends React.Component {
|
|||
activateTool () {
|
||||
// TODO: This is temporary until a component that provides the brush size is hooked up
|
||||
this.props.canvas.addEventListener('mousewheel', this.onScroll);
|
||||
|
||||
this.tool = new paper.Tool();
|
||||
this.blob.activateTool(false /* isEraser */, this.tool, this.props.brushModeState);
|
||||
this.blob.activateTool(false /* isEraser */, this.props.brushModeState);
|
||||
|
||||
// TODO Make sure a fill color is set on the brush
|
||||
// if(!pg.stylebar.getFillColor()) {
|
||||
|
@ -53,8 +51,6 @@ class BrushMode extends React.Component {
|
|||
|
||||
// TODO setup floating tool options panel in the editor
|
||||
// pg.toolOptionPanel.setup(options, components, function() {});
|
||||
|
||||
this.tool.activate();
|
||||
}
|
||||
deactivateTool () {
|
||||
this.props.canvas.removeEventListener('mousewheel', this.onScroll);
|
||||
|
|
|
@ -40,9 +40,7 @@ class EraserMode extends React.Component {
|
|||
activateTool () {
|
||||
this.props.canvas.addEventListener('mousewheel', this.onScroll);
|
||||
|
||||
this.tool = new paper.Tool();
|
||||
this.blob.activateTool(true /* isEraser */, this.tool, this.props.eraserModeState);
|
||||
this.tool.activate();
|
||||
this.blob.activateTool(true /* isEraser */, this.props.eraserModeState);
|
||||
}
|
||||
deactivateTool () {
|
||||
this.props.canvas.removeEventListener('mousewheel', this.onScroll);
|
||||
|
|
|
@ -31,8 +31,8 @@ class Blobbiness {
|
|||
}
|
||||
}
|
||||
|
||||
activateTool (isEraser, tool, options) {
|
||||
this.tool = tool;
|
||||
activateTool (isEraser, options) {
|
||||
this.tool = new paper.Tool();
|
||||
|
||||
tool.cursorPreviewLastPoint = new paper.Point(-10000, -10000);
|
||||
tool.resizeCursorIfNeeded = function (point) {
|
||||
|
|
|
@ -77,7 +77,6 @@ const segmentBrushHelper = function (tool) {
|
|||
|
||||
// Smooth the path.
|
||||
finalPath.simplify(2);
|
||||
// console.log(finalPath.segments);
|
||||
return finalPath;
|
||||
};
|
||||
};
|
||||
|
|
|
@ -18,11 +18,14 @@ const reducer = function (state, action) {
|
|||
};
|
||||
|
||||
// Action creators ==================================
|
||||
reducer.changeBrushSize = function (brushSize) {
|
||||
const changeBrushSize = function (brushSize) {
|
||||
return {
|
||||
type: CHANGE_ERASER_SIZE,
|
||||
brushSize: brushSize
|
||||
};
|
||||
};
|
||||
|
||||
export default reducer;
|
||||
export {
|
||||
reducer as default,
|
||||
changeBrushSize
|
||||
};
|
|
@ -19,11 +19,14 @@ const reducer = function (state, action) {
|
|||
};
|
||||
|
||||
// Action creators ==================================
|
||||
reducer.changeMode = function (mode) {
|
||||
const changeMode = function (mode) {
|
||||
return {
|
||||
type: CHANGE_MODE,
|
||||
mode: mode
|
||||
};
|
||||
};
|
||||
|
||||
export default reducer;
|
||||
export {
|
||||
reducer as default,
|
||||
changeMode
|
||||
};
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
/* eslint-env jest */
|
||||
import brushReducer from '../../src/reducers/brush-tool';
|
||||
import eraserReducer from '../../src/reducers/eraser-tool';
|
||||
import brushReducer from '../../src/reducers/brush-mode';
|
||||
import {changeBrushSize} from '../../src/reducers/brush-mode';
|
||||
import eraserReducer from '../../src/reducers/eraser-mode';
|
||||
import {changeBrushSize as changeEraserSize} from '../../src/reducers/eraser-mode';
|
||||
|
||||
test('initialState', () => {
|
||||
let defaultState;
|
||||
|
@ -16,27 +18,27 @@ test('changeBrushSize', () => {
|
|||
let defaultState;
|
||||
const newBrushSize = 8078;
|
||||
|
||||
expect(brushReducer(defaultState /* state */, brushReducer.changeBrushSize(newBrushSize) /* action */))
|
||||
expect(brushReducer(defaultState /* state */, changeBrushSize(newBrushSize) /* action */))
|
||||
.toEqual({brushSize: newBrushSize});
|
||||
expect(brushReducer(1 /* state */, brushReducer.changeBrushSize(newBrushSize) /* action */))
|
||||
expect(brushReducer(1 /* state */, changeBrushSize(newBrushSize) /* action */))
|
||||
.toEqual({brushSize: newBrushSize});
|
||||
|
||||
expect(eraserReducer(defaultState /* state */, eraserReducer.changeBrushSize(newBrushSize) /* action */))
|
||||
expect(eraserReducer(defaultState /* state */, changeEraserSize(newBrushSize) /* action */))
|
||||
.toEqual({brushSize: newBrushSize});
|
||||
expect(eraserReducer(1 /* state */, eraserReducer.changeBrushSize(newBrushSize) /* action */))
|
||||
expect(eraserReducer(1 /* state */, changeEraserSize(newBrushSize) /* action */))
|
||||
.toEqual({brushSize: newBrushSize});
|
||||
});
|
||||
|
||||
test('invalidChangeBrushSize', () => {
|
||||
const origState = {brushSize: 1};
|
||||
|
||||
expect(brushReducer(origState /* state */, brushReducer.changeBrushSize('invalid argument') /* action */))
|
||||
expect(brushReducer(origState /* state */, changeBrushSize('invalid argument') /* action */))
|
||||
.toBe(origState);
|
||||
expect(brushReducer(origState /* state */, brushReducer.changeBrushSize() /* action */))
|
||||
expect(brushReducer(origState /* state */, changeBrushSize() /* action */))
|
||||
.toBe(origState);
|
||||
|
||||
expect(eraserReducer(origState /* state */, eraserReducer.changeBrushSize('invalid argument') /* action */))
|
||||
expect(eraserReducer(origState /* state */, changeEraserSize('invalid argument') /* action */))
|
||||
.toBe(origState);
|
||||
expect(eraserReducer(origState /* state */, eraserReducer.changeBrushSize() /* action */))
|
||||
expect(eraserReducer(origState /* state */, changeEraserSize() /* action */))
|
||||
.toBe(origState);
|
||||
});
|
24
test/unit/modes-reducer.test.js
Normal file
24
test/unit/modes-reducer.test.js
Normal file
|
@ -0,0 +1,24 @@
|
|||
/* eslint-env jest */
|
||||
import Modes from '../../src/modes/modes';
|
||||
import reducer from '../../src/reducers/modes';
|
||||
import {changeMode} from '../../src/reducers/modes';
|
||||
|
||||
test('initialState', () => {
|
||||
let defaultState;
|
||||
expect(reducer(defaultState /* state */, {type: 'anything'} /* action */) in Modes).toBeTruthy();
|
||||
});
|
||||
|
||||
test('changeMode', () => {
|
||||
let defaultState;
|
||||
expect(reducer(defaultState /* state */, changeMode(Modes.ERASER) /* action */)).toBe(Modes.ERASER);
|
||||
expect(reducer(Modes.ERASER /* state */, changeMode(Modes.ERASER) /* action */))
|
||||
.toBe(Modes.ERASER);
|
||||
expect(reducer(Modes.BRUSH /* state */, changeMode(Modes.ERASER) /* action */))
|
||||
.toBe(Modes.ERASER);
|
||||
});
|
||||
|
||||
test('invalidChangeMode', () => {
|
||||
expect(reducer(Modes.BRUSH /* state */, changeMode('non-existant mode') /* action */))
|
||||
.toBe(Modes.BRUSH);
|
||||
expect(reducer(Modes.BRUSH /* state */, changeMode() /* action */)).toBe(Modes.BRUSH);
|
||||
});
|
|
@ -1,23 +0,0 @@
|
|||
/* eslint-env jest */
|
||||
import ToolTypes from '../../src/tools/tool-types';
|
||||
import reducer from '../../src/reducers/tools';
|
||||
|
||||
test('initialState', () => {
|
||||
let defaultState;
|
||||
expect(reducer(defaultState /* state */, {type: 'anything'} /* action */) in ToolTypes).toBeTruthy();
|
||||
});
|
||||
|
||||
test('changeTool', () => {
|
||||
let defaultState;
|
||||
expect(reducer(defaultState /* state */, reducer.changeTool(ToolTypes.ERASER) /* action */)).toBe(ToolTypes.ERASER);
|
||||
expect(reducer(ToolTypes.ERASER /* state */, reducer.changeTool(ToolTypes.ERASER) /* action */))
|
||||
.toBe(ToolTypes.ERASER);
|
||||
expect(reducer(ToolTypes.BRUSH /* state */, reducer.changeTool(ToolTypes.ERASER) /* action */))
|
||||
.toBe(ToolTypes.ERASER);
|
||||
});
|
||||
|
||||
test('invalidChangeTool', () => {
|
||||
expect(reducer(ToolTypes.BRUSH /* state */, reducer.changeTool('non-existant tool') /* action */))
|
||||
.toBe(ToolTypes.BRUSH);
|
||||
expect(reducer(ToolTypes.BRUSH /* state */, reducer.changeTool() /* action */)).toBe(ToolTypes.BRUSH);
|
||||
});
|
Loading…
Reference in a new issue