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:
@@ -38,8 +38,14 @@
|
|||||||
<script src="assets/worldMap.js"></script>
|
<script src="assets/worldMap.js"></script>
|
||||||
|
|
||||||
<!-- core -->
|
<!-- core -->
|
||||||
<script src="unit/Node-test.js"></script>
|
<script src="unit/Global-test.js"></script>
|
||||||
<script src="unit/Util-test.js"></script>
|
<script src="unit/Util-test.js"></script>
|
||||||
|
<script src="unit/Canvas-test.js"></script>
|
||||||
|
<script src="unit/Node-test.js"></script>
|
||||||
|
|
||||||
|
<!-- extensions -->
|
||||||
|
<script src="unit/DragAndDrop-test.js"></script>
|
||||||
|
<script src="unit/Tween-test.js"></script>
|
||||||
|
|
||||||
<!-- shapes -->
|
<!-- shapes -->
|
||||||
<script src="unit/shapes/Rect-test.js"></script>
|
<script src="unit/shapes/Rect-test.js"></script>
|
||||||
|
|||||||
39
test/unit/Canvas-test.js
Normal file
39
test/unit/Canvas-test.js
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
suite('Canvas', function() {
|
||||||
|
// ======================================================
|
||||||
|
test('pixel ratio', function() {
|
||||||
|
var stage = addStage();
|
||||||
|
|
||||||
|
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);
|
||||||
|
assert.equal(layer.getCanvas().getPixelRatio(), 1);
|
||||||
|
assert.equal(layer.getCanvas().width, 289);
|
||||||
|
assert.equal(layer.getCanvas().height, 100);
|
||||||
|
|
||||||
|
layer.getCanvas().setPixelRatio(2);
|
||||||
|
assert.equal(layer.getCanvas().getPixelRatio(), 2);
|
||||||
|
assert.equal(layer.getCanvas().width, 578);
|
||||||
|
assert.equal(layer.getCanvas().height, 200);
|
||||||
|
|
||||||
|
layer.draw();
|
||||||
|
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -1,10 +1,8 @@
|
|||||||
Test.Modules.DD = {
|
suite('DragAndDrop', function() {
|
||||||
'test drag and drop properties and methods': function(containerId) {
|
|
||||||
var stage = new Kinetic.Stage({
|
// ======================================================
|
||||||
container: containerId,
|
test('test drag and drop properties and methods', function() {
|
||||||
width: 578,
|
var stage = addStage();
|
||||||
height: 200
|
|
||||||
});
|
|
||||||
var layer = new Kinetic.Layer();
|
var layer = new Kinetic.Layer();
|
||||||
var circle = new Kinetic.Circle({
|
var circle = new Kinetic.Circle({
|
||||||
x: stage.getWidth() / 2,
|
x: stage.getWidth() / 2,
|
||||||
@@ -21,20 +19,18 @@ Test.Modules.DD = {
|
|||||||
layer.draw();
|
layer.draw();
|
||||||
|
|
||||||
// test defaults
|
// test defaults
|
||||||
test(circle.isDraggable() === false, 'draggable should be false');
|
assert.equal(circle.isDraggable(), false);
|
||||||
|
|
||||||
//change properties
|
//change properties
|
||||||
circle.setDraggable(true);
|
circle.setDraggable(true);
|
||||||
|
|
||||||
// test new properties
|
// test new properties
|
||||||
test(circle.getDraggable() === true, 'draggable should be true');
|
assert.equal(circle.getDraggable(), true);
|
||||||
},
|
});
|
||||||
'DRAG AND DROP - multiple drag and drop sets with setDraggable()': function(containerId) {
|
|
||||||
var stage = new Kinetic.Stage({
|
// ======================================================
|
||||||
container: containerId,
|
test('multiple drag and drop sets with setDraggable()', function() {
|
||||||
width: 578,
|
var stage = addStage();
|
||||||
height: 200
|
|
||||||
});
|
|
||||||
var layer = new Kinetic.Layer();
|
var layer = new Kinetic.Layer();
|
||||||
var circle = new Kinetic.Circle({
|
var circle = new Kinetic.Circle({
|
||||||
x: 380,
|
x: 380,
|
||||||
@@ -46,14 +42,14 @@ Test.Modules.DD = {
|
|||||||
});
|
});
|
||||||
|
|
||||||
circle.setDraggable(true);
|
circle.setDraggable(true);
|
||||||
test(circle.getDraggable(), 'draggable should be true');
|
assert.equal(circle.getDraggable(), true);
|
||||||
circle.setDraggable(true);
|
circle.setDraggable(true);
|
||||||
test(circle.getDraggable(), 'draggable should be true');
|
assert.equal(circle.getDraggable(), true);
|
||||||
circle.setDraggable(false);
|
circle.setDraggable(false);
|
||||||
test(!circle.getDraggable(), 'draggable should be false');
|
assert.equal(!circle.getDraggable(), true);
|
||||||
|
|
||||||
layer.add(circle);
|
layer.add(circle);
|
||||||
stage.add(layer);
|
stage.add(layer);
|
||||||
|
|
||||||
}
|
});
|
||||||
};
|
});
|
||||||
7
test/unit/Global-test.js
Normal file
7
test/unit/Global-test.js
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
suite('Global', function() {
|
||||||
|
|
||||||
|
// ======================================================
|
||||||
|
test('test Kinetic version number', function() {
|
||||||
|
assert.equal(Kinetic.version, 'dev');
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -1,10 +1,8 @@
|
|||||||
Test.Modules.TWEEN = {
|
suite('Tween', function() {
|
||||||
'tween node': function(containerId) {
|
|
||||||
var stage = new Kinetic.Stage({
|
// ======================================================
|
||||||
container: containerId,
|
test('tween node', function(done) {
|
||||||
width: 578,
|
var stage = addStage();
|
||||||
height: 200
|
|
||||||
});
|
|
||||||
|
|
||||||
var layer = new Kinetic.Layer();
|
var layer = new Kinetic.Layer();
|
||||||
|
|
||||||
@@ -22,7 +20,8 @@ Test.Modules.TWEEN = {
|
|||||||
|
|
||||||
var finishCount = 0;
|
var finishCount = 0;
|
||||||
var onFinish = function() {
|
var onFinish = function() {
|
||||||
test(++finishCount <= 1, 'finishCount should not exceed 1');
|
assert(++finishCount <= 1, 'finishCount should not exceed 1');
|
||||||
|
done();
|
||||||
}
|
}
|
||||||
|
|
||||||
var tweens = 0;
|
var tweens = 0;
|
||||||
@@ -35,8 +34,8 @@ Test.Modules.TWEEN = {
|
|||||||
attrs++;
|
attrs++;
|
||||||
}
|
}
|
||||||
|
|
||||||
test(tweens === 0, 'should be no tweens');
|
assert.equal(tweens, 0);
|
||||||
test(attrs === 0, 'should be no attrs');
|
assert.equal(attrs, 0);
|
||||||
|
|
||||||
var tween = new Kinetic.Tween({
|
var tween = new Kinetic.Tween({
|
||||||
node: circle,
|
node: circle,
|
||||||
@@ -55,19 +54,17 @@ Test.Modules.TWEEN = {
|
|||||||
attrs++;
|
attrs++;
|
||||||
}
|
}
|
||||||
|
|
||||||
test(tweens === 1, 'should one tween');
|
assert.equal(tweens, 1);
|
||||||
test(attrs === 2, 'should two attrs');
|
assert.equal(attrs, 2);
|
||||||
|
|
||||||
test(Kinetic.Tween.attrs[circle._id][tween._id].x !== undefined, 'x should not be undefined');
|
assert.notEqual(Kinetic.Tween.attrs[circle._id][tween._id].x, undefined);
|
||||||
test(Kinetic.Tween.attrs[circle._id][tween._id].y !== undefined, 'y should not be undefined');
|
assert.notEqual(Kinetic.Tween.attrs[circle._id][tween._id].y, undefined);
|
||||||
|
|
||||||
},
|
});
|
||||||
'tween node': function(containerId) {
|
|
||||||
var stage = new Kinetic.Stage({
|
// ======================================================
|
||||||
container: containerId,
|
test('tween node', function() {
|
||||||
width: 578,
|
var stage = addStage();
|
||||||
height: 200
|
|
||||||
});
|
|
||||||
|
|
||||||
var layer = new Kinetic.Layer();
|
var layer = new Kinetic.Layer();
|
||||||
|
|
||||||
@@ -94,15 +91,15 @@ Test.Modules.TWEEN = {
|
|||||||
// start/diff object = attrs.nodeId.tweenId.attr
|
// start/diff object = attrs.nodeId.tweenId.attr
|
||||||
// tweenId = tweens.nodeId.attr
|
// tweenId = tweens.nodeId.attr
|
||||||
|
|
||||||
test(tween._id !== undefined, 'tween.play should return an instance of the tween');
|
assert.notEqual(tween._id, undefined);
|
||||||
test(Kinetic.Tween.tweens[circle._id].x === tween._id, 'circle should be in the tweens hash');
|
assert.equal(Kinetic.Tween.tweens[circle._id].x, tween._id);
|
||||||
test(Kinetic.Tween.attrs[circle._id][tween._id] !== undefined, 'tween should be in the attrs hash');
|
assert.notEqual(Kinetic.Tween.attrs[circle._id][tween._id], undefined);
|
||||||
|
|
||||||
tween.destroy();
|
tween.destroy();
|
||||||
|
|
||||||
test(Kinetic.Tween.tweens[circle._id].x === undefined, 'circle should not be in the tweens hash');
|
assert.equal(Kinetic.Tween.tweens[circle._id].x, undefined);
|
||||||
test(Kinetic.Tween.attrs[circle._id][tween._id] === undefined, 'tween should not be in the attrs hash');
|
assert.equal(Kinetic.Tween.attrs[circle._id][tween._id], undefined);
|
||||||
|
|
||||||
|
|
||||||
}
|
});
|
||||||
};
|
});
|
||||||
@@ -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,5 +0,0 @@
|
|||||||
Test.Modules.GLOBAL = {
|
|
||||||
'test Kinetic version number': function(containerId) {
|
|
||||||
test(Kinetic.version === 'dev', 'Kinetic.version should equal dev');
|
|
||||||
}
|
|
||||||
};
|
|
||||||
@@ -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