mirror of
https://github.com/konvajs/konva.git
synced 2025-09-18 18:27:58 +08:00
all methods are now copied to Collection prototype so that you don't have to use the each() method all the time
This commit is contained in:
@@ -50,6 +50,7 @@
|
||||
<script src="unit/Stage-test.js"></script>
|
||||
<script src="unit/Layer-test.js"></script>
|
||||
<script src="unit/Shape-test.js"></script>
|
||||
<script src="unit/Collection-test.js"></script>
|
||||
|
||||
<!-- shapes -->
|
||||
<script src="unit/shapes/Rect-test.js"></script>
|
||||
|
57
test/unit/Collection-test.js
Normal file
57
test/unit/Collection-test.js
Normal file
@@ -0,0 +1,57 @@
|
||||
suite('Collection', function(){
|
||||
var util;
|
||||
|
||||
test('test collection method mapping', function(){
|
||||
// Node method
|
||||
assert.notEqual(Kinetic.Collection.prototype.on, undefined);
|
||||
|
||||
// Layer method
|
||||
assert.notEqual(Kinetic.Collection.prototype.getContext, undefined);
|
||||
|
||||
// Container method
|
||||
assert.notEqual(Kinetic.Collection.prototype.hasChildren, undefined);
|
||||
|
||||
// Shape method
|
||||
assert.notEqual(Kinetic.Collection.prototype.strokeWidth, undefined);
|
||||
});
|
||||
|
||||
test('add circle to stage', function(){
|
||||
var stage = addStage();
|
||||
var layer = new Kinetic.Layer();
|
||||
var circle1 = new Kinetic.Circle({
|
||||
x: 100,
|
||||
y: 100,
|
||||
radius: 70,
|
||||
fill: 'green',
|
||||
stroke: 'black',
|
||||
strokeWidth: 4,
|
||||
name: 'myCircle',
|
||||
draggable: true
|
||||
});
|
||||
|
||||
|
||||
var circle2 = new Kinetic.Circle({
|
||||
x:300,
|
||||
y: 100,
|
||||
radius: 70,
|
||||
fill: 'red',
|
||||
stroke: 'black',
|
||||
strokeWidth: 4,
|
||||
name: 'myCircle',
|
||||
draggable: true
|
||||
});
|
||||
|
||||
|
||||
layer.add(circle1).add(circle2);
|
||||
stage.add(layer);
|
||||
|
||||
layer.find('Circle').fill('blue');
|
||||
layer.draw();
|
||||
|
||||
//console.log(layer.getContext().getTrace());
|
||||
|
||||
assert.equal(layer.getContext().getTrace(),'clearRect(0,0,578,200);save();transform(1,0,0,1,100,100);beginPath();arc(0,0,70,0,6.283,false);closePath();fillStyle=green;fill();lineWidth=4;strokeStyle=black;stroke();restore();save();transform(1,0,0,1,300,100);beginPath();arc(0,0,70,0,6.283,false);closePath();fillStyle=red;fill();lineWidth=4;strokeStyle=black;stroke();restore();clearRect(0,0,578,200);save();transform(1,0,0,1,100,100);beginPath();arc(0,0,70,0,6.283,false);closePath();fillStyle=blue;fill();lineWidth=4;strokeStyle=black;stroke();restore();save();transform(1,0,0,1,300,100);beginPath();arc(0,0,70,0,6.283,false);closePath();fillStyle=blue;fill();lineWidth=4;strokeStyle=black;stroke();restore();');
|
||||
|
||||
|
||||
});
|
||||
});
|
@@ -279,17 +279,17 @@ suite('Layer', function() {
|
||||
layer.add(circle);
|
||||
stage.add(layer);
|
||||
|
||||
assert.equal(layer.isHitGraphEnabled(), true);
|
||||
assert.equal(layer.hitGraphEnabled(), true);
|
||||
assert.equal(layer.shouldDrawHit(), true);
|
||||
|
||||
layer.disableHitGraph();
|
||||
|
||||
assert.equal(layer.isHitGraphEnabled(), false);
|
||||
assert.equal(layer.hitGraphEnabled(), false);
|
||||
assert.equal(layer.shouldDrawHit(), false);
|
||||
|
||||
layer.enableHitGraph();
|
||||
|
||||
assert.equal(layer.isHitGraphEnabled(), true);
|
||||
assert.equal(layer.hitGraphEnabled(), true);
|
||||
assert.equal(layer.shouldDrawHit(), true);
|
||||
});
|
||||
});
|
Reference in New Issue
Block a user