Merge pull request #879 from paulkaplan/drag-mode-block

Add setDragMode primitive and unit test
This commit is contained in:
Paul Kaplan authored and GitHub committed 2017-12-29 09:38:37 -05:00
commit 8366a02513
2 files changed
+12 -8

No files matched your search

+1 -1
View File
@@ -164,7 +164,7 @@ class Scratch3SensingBlocks {
}
setDragMode (args, util) {
util.target.draggable = args.DRAG_MODE === 'draggable';
util.target.setDraggable(args.DRAG_MODE === 'draggable');
}
getTimer (args, util) {
+11 -7
View File
@@ -1,6 +1,8 @@
const test = require('tap').test;
const Sensing = require('../../src/blocks/scratch3_sensing');
const Runtime = require('../../src/engine/runtime');
const Sprite = require('../../src/sprites/sprite');
const RenderedTarget = require('../../src/sprites/rendered-target');
test('getPrimitives', t => {
const rt = new Runtime();
@@ -67,15 +69,17 @@ test('ask and answer with a visible target', t => {
});
test('set drag mode', t => {
const rt = new Runtime();
const s = new Sensing(rt);
const util = {target: {draggable: true}};
const runtime = new Runtime();
runtime.requestTargetsUpdate = () => {}; // noop for testing
const sensing = new Sensing(runtime);
const s = new Sprite();
const rt = new RenderedTarget(s, runtime);
s.setDragMode({DRAG_MODE: 'not draggable'}, util);
t.strictEqual(util.target.draggable, false);
sensing.setDragMode({DRAG_MODE: 'not draggable'}, {target: rt});
t.strictEqual(rt.draggable, false);
s.setDragMode({DRAG_MODE: 'draggable'}, util);
t.strictEqual(util.target.draggable, true);
sensing.setDragMode({DRAG_MODE: 'draggable'}, {target: rt});
t.strictEqual(rt.draggable, true);
t.end();
});