mirror of
https://github.com/konvajs/konva.git
synced 2026-01-18 19:51:21 +08:00
migrated Canvas, DragAndDrop, Global, and Tween tests to mocha
This commit is contained in:
@@ -1,47 +0,0 @@
|
||||
Test.Modules.CANVAS = {
|
||||
'pixel ratio': function(containerId) {
|
||||
var stage = new Kinetic.Stage({
|
||||
container: containerId,
|
||||
width: 578,
|
||||
height: 200
|
||||
});
|
||||
|
||||
var layer = new Kinetic.Layer();
|
||||
|
||||
var circle = new Kinetic.Circle({
|
||||
x: 578/2,
|
||||
y: 100,
|
||||
radius: 70,
|
||||
fill: 'green',
|
||||
stroke: 'blue',
|
||||
strokeWidth: 4
|
||||
});
|
||||
|
||||
layer.add(circle);
|
||||
stage.add(layer);
|
||||
|
||||
|
||||
stage.setWidth(578/2);
|
||||
stage.setHeight(100);
|
||||
|
||||
stage.draw();
|
||||
|
||||
layer.getCanvas().setPixelRatio(1);
|
||||
test(layer.getCanvas().getPixelRatio() === 1, 'pixel ratio should be 1');
|
||||
test(layer.getCanvas().width === 289, 'canvas width should be 289');
|
||||
test(layer.getCanvas().height === 100, 'canvas height should be 100');
|
||||
|
||||
layer.getCanvas().setPixelRatio(2);
|
||||
test(layer.getCanvas().getPixelRatio() === 2, 'pixel ratio should be 2');
|
||||
test(layer.getCanvas().width === 578, 'canvas width should be 578');
|
||||
test(layer.getCanvas().height === 200, 'canvas height should be 200');
|
||||
|
||||
|
||||
|
||||
layer.draw();
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
};
|
||||
@@ -1,59 +0,0 @@
|
||||
Test.Modules.DD = {
|
||||
'test drag and drop properties and methods': function(containerId) {
|
||||
var stage = new Kinetic.Stage({
|
||||
container: containerId,
|
||||
width: 578,
|
||||
height: 200
|
||||
});
|
||||
var layer = new Kinetic.Layer();
|
||||
var circle = new Kinetic.Circle({
|
||||
x: stage.getWidth() / 2,
|
||||
y: stage.getHeight() / 2,
|
||||
radius: 70,
|
||||
fill: 'green',
|
||||
stroke: 'black',
|
||||
strokeWidth: 4,
|
||||
name: 'myCircle'
|
||||
});
|
||||
|
||||
stage.add(layer);
|
||||
layer.add(circle);
|
||||
layer.draw();
|
||||
|
||||
// test defaults
|
||||
test(circle.isDraggable() === false, 'draggable should be false');
|
||||
|
||||
//change properties
|
||||
circle.setDraggable(true);
|
||||
|
||||
// test new properties
|
||||
test(circle.getDraggable() === true, 'draggable should be true');
|
||||
},
|
||||
'DRAG AND DROP - multiple drag and drop sets with setDraggable()': function(containerId) {
|
||||
var stage = new Kinetic.Stage({
|
||||
container: containerId,
|
||||
width: 578,
|
||||
height: 200
|
||||
});
|
||||
var layer = new Kinetic.Layer();
|
||||
var circle = new Kinetic.Circle({
|
||||
x: 380,
|
||||
y: stage.getHeight() / 2,
|
||||
radius: 70,
|
||||
strokeWidth: 4,
|
||||
fill: 'red',
|
||||
stroke: 'black'
|
||||
});
|
||||
|
||||
circle.setDraggable(true);
|
||||
test(circle.getDraggable(), 'draggable should be true');
|
||||
circle.setDraggable(true);
|
||||
test(circle.getDraggable(), 'draggable should be true');
|
||||
circle.setDraggable(false);
|
||||
test(!circle.getDraggable(), 'draggable should be false');
|
||||
|
||||
layer.add(circle);
|
||||
stage.add(layer);
|
||||
|
||||
}
|
||||
};
|
||||
@@ -1,5 +0,0 @@
|
||||
Test.Modules.GLOBAL = {
|
||||
'test Kinetic version number': function(containerId) {
|
||||
test(Kinetic.version === 'dev', 'Kinetic.version should equal dev');
|
||||
}
|
||||
};
|
||||
@@ -1,108 +0,0 @@
|
||||
Test.Modules.TWEEN = {
|
||||
'tween node': function(containerId) {
|
||||
var stage = new Kinetic.Stage({
|
||||
container: containerId,
|
||||
width: 578,
|
||||
height: 200
|
||||
});
|
||||
|
||||
var layer = new Kinetic.Layer();
|
||||
|
||||
var circle = new Kinetic.Circle({
|
||||
x: 100,
|
||||
y: stage.getHeight() / 2,
|
||||
radius: 70,
|
||||
fill: 'green',
|
||||
stroke: 'blue',
|
||||
strokeWidth: 4
|
||||
});
|
||||
|
||||
layer.add(circle);
|
||||
stage.add(layer);
|
||||
|
||||
var finishCount = 0;
|
||||
var onFinish = function() {
|
||||
test(++finishCount <= 1, 'finishCount should not exceed 1');
|
||||
}
|
||||
|
||||
var tweens = 0;
|
||||
var attrs = 0;
|
||||
|
||||
for (var key in Kinetic.Tween.tweens) {
|
||||
tweens++;
|
||||
}
|
||||
for (var key in Kinetic.Tween.attrs) {
|
||||
attrs++;
|
||||
}
|
||||
|
||||
test(tweens === 0, 'should be no tweens');
|
||||
test(attrs === 0, 'should be no attrs');
|
||||
|
||||
var tween = new Kinetic.Tween({
|
||||
node: circle,
|
||||
duration: 0.2,
|
||||
x: 200,
|
||||
y: 100,
|
||||
onFinish: onFinish
|
||||
}).play();
|
||||
|
||||
var tweens = 0;
|
||||
var attrs = 0;
|
||||
for (var key in Kinetic.Tween.tweens) {
|
||||
tweens++;
|
||||
}
|
||||
for (var key in Kinetic.Tween.attrs[circle._id][tween._id]) {
|
||||
attrs++;
|
||||
}
|
||||
|
||||
test(tweens === 1, 'should one tween');
|
||||
test(attrs === 2, 'should two attrs');
|
||||
|
||||
test(Kinetic.Tween.attrs[circle._id][tween._id].x !== undefined, 'x should not be undefined');
|
||||
test(Kinetic.Tween.attrs[circle._id][tween._id].y !== undefined, 'y should not be undefined');
|
||||
|
||||
},
|
||||
'tween node': function(containerId) {
|
||||
var stage = new Kinetic.Stage({
|
||||
container: containerId,
|
||||
width: 578,
|
||||
height: 200
|
||||
});
|
||||
|
||||
var layer = new Kinetic.Layer();
|
||||
|
||||
var circle = new Kinetic.Circle({
|
||||
x: 100,
|
||||
y: stage.getHeight() / 2,
|
||||
radius: 70,
|
||||
fill: 'green',
|
||||
stroke: 'blue',
|
||||
strokeWidth: 4
|
||||
});
|
||||
|
||||
layer.add(circle);
|
||||
stage.add(layer);
|
||||
|
||||
|
||||
var tween = new Kinetic.Tween({
|
||||
node: circle,
|
||||
duration: 0.2,
|
||||
x: 200,
|
||||
y: 100
|
||||
}).play();
|
||||
|
||||
// start/diff object = attrs.nodeId.tweenId.attr
|
||||
// tweenId = tweens.nodeId.attr
|
||||
|
||||
test(tween._id !== undefined, 'tween.play should return an instance of the tween');
|
||||
test(Kinetic.Tween.tweens[circle._id].x === tween._id, 'circle should be in the tweens hash');
|
||||
test(Kinetic.Tween.attrs[circle._id][tween._id] !== undefined, 'tween should be in the attrs hash');
|
||||
|
||||
tween.destroy();
|
||||
|
||||
test(Kinetic.Tween.tweens[circle._id].x === undefined, 'circle should not be in the tweens hash');
|
||||
test(Kinetic.Tween.attrs[circle._id][tween._id] === undefined, 'tween should not be in the attrs hash');
|
||||
|
||||
|
||||
}
|
||||
};
|
||||
@@ -1,9 +0,0 @@
|
||||
Test.Modules.UTIL = {
|
||||
'util get()': function(containerId) {
|
||||
var get = Kinetic.Util.get;
|
||||
|
||||
test(get(1, 2) === 1, 'get() should return 1');
|
||||
test(get(0, 2) === 0, 'get() should return 0');
|
||||
test(get(undefined, {foo:'bar'}).foo === 'bar', 'get() should return bar');
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user