mirror of
https://github.com/konvajs/konva.git
synced 2025-04-05 20:48:28 +08:00
migrated Canvas, DragAndDrop, Global, and Tween tests to mocha
This commit is contained in:
parent
c40fc7cf38
commit
1ea9e68ff6
@ -38,8 +38,14 @@
|
||||
<script src="assets/worldMap.js"></script>
|
||||
|
||||
<!-- 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/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 -->
|
||||
<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 = {
|
||||
'test drag and drop properties and methods': function(containerId) {
|
||||
var stage = new Kinetic.Stage({
|
||||
container: containerId,
|
||||
width: 578,
|
||||
height: 200
|
||||
});
|
||||
suite('DragAndDrop', function() {
|
||||
|
||||
// ======================================================
|
||||
test('test drag and drop properties and methods', function() {
|
||||
var stage = addStage();
|
||||
var layer = new Kinetic.Layer();
|
||||
var circle = new Kinetic.Circle({
|
||||
x: stage.getWidth() / 2,
|
||||
@ -21,20 +19,18 @@ Test.Modules.DD = {
|
||||
layer.draw();
|
||||
|
||||
// test defaults
|
||||
test(circle.isDraggable() === false, 'draggable should be false');
|
||||
assert.equal(circle.isDraggable(), 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
|
||||
});
|
||||
assert.equal(circle.getDraggable(), true);
|
||||
});
|
||||
|
||||
// ======================================================
|
||||
test('multiple drag and drop sets with setDraggable()', function() {
|
||||
var stage = addStage();
|
||||
var layer = new Kinetic.Layer();
|
||||
var circle = new Kinetic.Circle({
|
||||
x: 380,
|
||||
@ -46,14 +42,14 @@ Test.Modules.DD = {
|
||||
});
|
||||
|
||||
circle.setDraggable(true);
|
||||
test(circle.getDraggable(), 'draggable should be true');
|
||||
assert.equal(circle.getDraggable(), true);
|
||||
circle.setDraggable(true);
|
||||
test(circle.getDraggable(), 'draggable should be true');
|
||||
assert.equal(circle.getDraggable(), true);
|
||||
circle.setDraggable(false);
|
||||
test(!circle.getDraggable(), 'draggable should be false');
|
||||
assert.equal(!circle.getDraggable(), true);
|
||||
|
||||
layer.add(circle);
|
||||
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 = {
|
||||
'tween node': function(containerId) {
|
||||
var stage = new Kinetic.Stage({
|
||||
container: containerId,
|
||||
width: 578,
|
||||
height: 200
|
||||
});
|
||||
suite('Tween', function() {
|
||||
|
||||
// ======================================================
|
||||
test('tween node', function(done) {
|
||||
var stage = addStage();
|
||||
|
||||
var layer = new Kinetic.Layer();
|
||||
|
||||
@ -22,7 +20,8 @@ Test.Modules.TWEEN = {
|
||||
|
||||
var finishCount = 0;
|
||||
var onFinish = function() {
|
||||
test(++finishCount <= 1, 'finishCount should not exceed 1');
|
||||
assert(++finishCount <= 1, 'finishCount should not exceed 1');
|
||||
done();
|
||||
}
|
||||
|
||||
var tweens = 0;
|
||||
@ -35,8 +34,8 @@ Test.Modules.TWEEN = {
|
||||
attrs++;
|
||||
}
|
||||
|
||||
test(tweens === 0, 'should be no tweens');
|
||||
test(attrs === 0, 'should be no attrs');
|
||||
assert.equal(tweens, 0);
|
||||
assert.equal(attrs, 0);
|
||||
|
||||
var tween = new Kinetic.Tween({
|
||||
node: circle,
|
||||
@ -55,19 +54,17 @@ Test.Modules.TWEEN = {
|
||||
attrs++;
|
||||
}
|
||||
|
||||
test(tweens === 1, 'should one tween');
|
||||
test(attrs === 2, 'should two attrs');
|
||||
assert.equal(tweens, 1);
|
||||
assert.equal(attrs, 2);
|
||||
|
||||
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');
|
||||
assert.notEqual(Kinetic.Tween.attrs[circle._id][tween._id].x, undefined);
|
||||
assert.notEqual(Kinetic.Tween.attrs[circle._id][tween._id].y, undefined);
|
||||
|
||||
},
|
||||
'tween node': function(containerId) {
|
||||
var stage = new Kinetic.Stage({
|
||||
container: containerId,
|
||||
width: 578,
|
||||
height: 200
|
||||
});
|
||||
});
|
||||
|
||||
// ======================================================
|
||||
test('tween node', function() {
|
||||
var stage = addStage();
|
||||
|
||||
var layer = new Kinetic.Layer();
|
||||
|
||||
@ -94,15 +91,15 @@ Test.Modules.TWEEN = {
|
||||
// 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');
|
||||
assert.notEqual(tween._id, undefined);
|
||||
assert.equal(Kinetic.Tween.tweens[circle._id].x, tween._id);
|
||||
assert.notEqual(Kinetic.Tween.attrs[circle._id][tween._id], undefined);
|
||||
|
||||
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');
|
||||
assert.equal(Kinetic.Tween.tweens[circle._id].x, undefined);
|
||||
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');
|
||||
}
|
||||
};
|
Loading…
Reference in New Issue
Block a user