more unit tests working, more refactoring

This commit is contained in:
Eric Rowell
2013-12-02 21:25:20 -08:00
parent 86686eb590
commit a57d6c6106
10 changed files with 124 additions and 136 deletions

View File

@@ -4,7 +4,7 @@ suite('Container', function() {
test('clip', function() {
var stage = addStage();
var layer = new Kinetic.Layer({
clip: [0, 0, stage.getWidth() / 2, 100]
clip: {x:0, y:0, width:stage.getWidth() / 2, height:100}
});
var group = new Kinetic.Group();
var circle = new Kinetic.Circle({

View File

@@ -68,7 +68,7 @@ suite('Node', function() {
assert.equal(circle.getFill(), 'red');
circle.setAttr('position', 5, 6);
circle.setAttr('position', {x: 5, y: 6});
assert.equal(circle.getX(), 5);
assert.equal(circle.getY(), 6);
@@ -574,7 +574,7 @@ suite('Node', function() {
width: 200,
height: 50,
fill: 'blue',
shadowOffset: [10, 10],
shadowOffset: {x: 10, y: 10},
});
var circle = new Kinetic.Circle({
@@ -608,9 +608,9 @@ suite('Node', function() {
radiusChanged++;
});
circle.setRadius(70, 20);
circle.setRadius(70);
rect.setSize(210);
rect.setSize({width: 210, height: 210});
rect.setShadowOffset({
x: 20
});
@@ -776,7 +776,7 @@ suite('Node', function() {
assert.equal(rect.getScale().y, 0.5);
assert.equal(rect.getRotation(), 20 * Math.PI / 180);
rect.setScale(2, 0.3);
rect.setScale({x:2, y:0.3});
assert.equal(rect.getScale().x, 2);
assert.equal(rect.getScale().y, 0.3);
@@ -1131,7 +1131,7 @@ suite('Node', function() {
assert.equal(rect.getOffset().x, 40);
assert.equal(rect.getOffset().y, 20);
rect.setOffset(80, 40);
rect.setOffset({x:80, y:40});
assert.equal(rect.getOffsetX(), 80);
assert.equal(rect.getOffsetY(), 40);
@@ -1203,7 +1203,7 @@ suite('Node', function() {
layer.add(rect);
stage.add(layer);
rect.setShadowOffset([1, 2]);
rect.setShadowOffset({x:1, y:2});
assert.equal(rect.getShadowOffset().x, 1);
assert.equal(rect.getShadowOffset().y, 2);
// make sure we still have the other properties
@@ -1218,16 +1218,12 @@ suite('Node', function() {
assert.equal(rect.getShadowOffset().y, 4);
// test partial setting
rect.setShadowOffset({
x: 5
});
rect.setShadowOffsetX(5);
assert.equal(rect.getShadowOffset().x, 5);
assert.equal(rect.getShadowOffset().y, 4);
// test partial setting
rect.setShadowOffset({
y: 6
});
rect.setShadowOffsetY(6);
assert.equal(rect.getShadowOffset().x, 5);
assert.equal(rect.getShadowOffset().y, 6);
@@ -1248,11 +1244,11 @@ suite('Node', function() {
layer.add(rect);
stage.add(layer);
rect.setOffset(1, 2);
rect.setOffset({x:1, y: 2});
assert.equal(rect.getOffset().x, 1);
assert.equal(rect.getOffset().y, 2);
rect.setOffset([3, 4]);
rect.setOffset({x:3, y:4});
assert.equal(rect.getOffset().x, 3);
assert.equal(rect.getOffset().y, 4);
@@ -1263,15 +1259,11 @@ suite('Node', function() {
assert.equal(rect.getOffset().x, 5);
assert.equal(rect.getOffset().y, 6);
rect.setOffset({
x: 7
});
rect.setOffsetX(7);
assert.equal(rect.getOffset().x, 7);
assert.equal(rect.getOffset().y, 6);
rect.setOffset({
y: 8
});
rect.setOffsetY(8);
assert.equal(rect.getOffset().x, 7);
assert.equal(rect.getOffset().y, 8);
@@ -1292,11 +1284,11 @@ suite('Node', function() {
layer.add(rect);
stage.add(layer);
rect.setPosition(1, 2);
rect.setPosition({x:1, y:2});
assert.equal(rect.getPosition().x, 1);
assert.equal(rect.getPosition().y, 2);
rect.setPosition([3, 4]);
rect.setPosition({x:3, y:4});
assert.equal(rect.getPosition().x, 3);
assert.equal(rect.getPosition().y, 4);
@@ -1307,19 +1299,15 @@ suite('Node', function() {
assert.equal(rect.getPosition().x, 5);
assert.equal(rect.getPosition().y, 6);
rect.setPosition({
x: 7
});
rect.setX(7);
assert.equal(rect.getPosition().x, 7);
assert.equal(rect.getPosition().y, 6);
rect.setPosition({
y: 8
});
rect.setY(8);
assert.equal(rect.getPosition().x, 7);
assert.equal(rect.getPosition().y, 8);
rect.move(10);
rect.move({x: 10, y: 10});
assert.equal(rect.getPosition().x, 17);
assert.equal(rect.getPosition().y, 18);

View File

@@ -91,10 +91,10 @@ suite('Stage', function() {
assert.equal(stage.getSize().width, 578);
assert.equal(stage.getSize().height, 200);
stage.setSize(1, 2);
stage.setSize({width:1, height:2});
assert.equal(stage.getSize().width, 1);
assert.equal(stage.getSize().height, 2);
stage.setSize(3);
stage.setSize({width: 3, height: 3});
assert.equal(stage.getSize().width, 3);
assert.equal(stage.getSize().height, 3);
stage.setSize({
@@ -103,27 +103,23 @@ suite('Stage', function() {
});
assert.equal(stage.getSize().width, 4);
assert.equal(stage.getSize().height, 5);
stage.setSize({
width: 6
});
stage.setWidth(6);
assert.equal(stage.getSize().width, 6);
assert.equal(stage.getSize().height, 5);
stage.setSize({
height: 7
});
stage.setHeight(7);
assert.equal(stage.getSize().width, 6);
assert.equal(stage.getSize().height, 7);
stage.setSize([8, 9]);
stage.setSize({width: 8, height: 9});
assert.equal(stage.getSize().width, 8);
assert.equal(stage.getSize().height, 9);
stage.setSize([1, 1, 10, 11]);
stage.setSize({width:10, height:11});
assert.equal(stage.getSize().width, 10);
assert.equal(stage.getSize().height, 11);
layer.add(circle);
stage.add(layer);
stage.setSize(333, 155);
stage.setSize({width:333, height:155});
assert.equal(stage.getSize().width, 333);
assert.equal(stage.getSize().height, 155);
@@ -169,9 +165,9 @@ suite('Stage', function() {
layer.add(greenCircle);
stage.add(layer);
assert.equal(stage.getIntersection(300, 100).getId(), 'greenCircle', 'shape should be greenCircle');
assert.equal(stage.getIntersection(380, 100).getId(), 'redCircle', 'shape should be redCircle');
assert.equal(stage.getIntersection(100, 100), null, 'shape should be null');
assert.equal(stage.getIntersection({x:300, y:100}).getId(), 'greenCircle', 'shape should be greenCircle');
assert.equal(stage.getIntersection({x:380, y:100}).getId(), 'redCircle', 'shape should be redCircle');
assert.equal(stage.getIntersection({x:100, y:100}), null, 'shape should be null');
});
@@ -213,10 +209,10 @@ suite('Stage', function() {
layer.add(greenCircle);
stage.add(layer);
assert.equal(stage.getIntersection(370, 93).getId(), 'greenCircle', 'shape should be greenCircle');
assert.equal(stage.getIntersection({x:370, y:93}).getId(), 'greenCircle', 'shape should be greenCircle');
// TODO: this passes in the browser but fails in phantomjs. no idea why.
//assert.equal(stage.getIntersection(371, 93).getId(), 'greenCircle', 'shape should be greenCircle');
assert.equal(stage.getIntersection(372, 93).getId(), 'redCircle', 'shape should be redCircle');
assert.equal(stage.getIntersection({x:372, y:93}).getId(), 'redCircle', 'shape should be redCircle');
//console.log(layer.hitCanvas.context._context.getImageData(1, 1, 1, 1).data)
@@ -253,50 +249,50 @@ suite('Stage', function() {
stage.add(layer);
// test individual shapes
assert.equal(stage.getAllIntersections(266, 114).length, 1, '17) getAllIntersections should return one shape');
assert.equal(stage.getAllIntersections(266, 114)[0].getId(), 'greenCircle', '19) first intersection should be greenCircle');
assert.equal(stage.getAllIntersections({x: 266, y:114}).length, 1, '17) getAllIntersections should return one shape');
assert.equal(stage.getAllIntersections({x: 266, y:114})[0].getId(), 'greenCircle', '19) first intersection should be greenCircle');
assert.equal(stage.getAllIntersections(414, 115).length, 1, '18) getAllIntersections should return one shape');
assert.equal(stage.getAllIntersections(414, 115)[0].getId(), 'redCircle', '20) first intersection should be redCircle');
assert.equal(stage.getAllIntersections({x: 414, y:115}).length, 1, '18) getAllIntersections should return one shape');
assert.equal(stage.getAllIntersections({x: 414, y:115})[0].getId(), 'redCircle', '20) first intersection should be redCircle');
assert.equal(stage.getAllIntersections(350, 118).length, 2, '1) getAllIntersections should return two shapes');
assert.equal(stage.getAllIntersections(350, 118)[0].getId(), 'redCircle', '2) first intersection should be redCircle');
assert.equal(stage.getAllIntersections(350, 118)[1].getId(), 'greenCircle', '3) second intersection should be greenCircle');
assert.equal(stage.getAllIntersections({x: 350, y:118}).length, 2, '1) getAllIntersections should return two shapes');
assert.equal(stage.getAllIntersections({x: 350, y:118})[0].getId(), 'redCircle', '2) first intersection should be redCircle');
assert.equal(stage.getAllIntersections({x: 350, y:118})[1].getId(), 'greenCircle', '3) second intersection should be greenCircle');
// hide green circle. make sure only red circle is in result set
greenCircle.hide();
layer.draw();
assert.equal(stage.getAllIntersections(350, 118).length, 1, '4) getAllIntersections should return one shape');
assert.equal(stage.getAllIntersections(350, 118)[0].getId(), 'redCircle', '5) first intersection should be redCircle');
assert.equal(stage.getAllIntersections({x: 350, y:118}).length, 1, '4) getAllIntersections should return one shape');
assert.equal(stage.getAllIntersections({x: 350, y:118})[0].getId(), 'redCircle', '5) first intersection should be redCircle');
// show green circle again. make sure both circles are in result set
greenCircle.show();
layer.draw();
assert.equal(stage.getAllIntersections(350, 118).length, 2, '6) getAllIntersections should return two shapes');
assert.equal(stage.getAllIntersections(350, 118)[0].getId(), 'redCircle', '7) first intersection should be redCircle');
assert.equal(stage.getAllIntersections(350, 118)[1].getId(), 'greenCircle', '8) second intersection should be greenCircle');
assert.equal(stage.getAllIntersections({x: 350, y:118}).length, 2, '6) getAllIntersections should return two shapes');
assert.equal(stage.getAllIntersections({x: 350, y:118})[0].getId(), 'redCircle', '7) first intersection should be redCircle');
assert.equal(stage.getAllIntersections({x: 350, y:118})[1].getId(), 'greenCircle', '8) second intersection should be greenCircle');
// hide red circle. make sure only green circle is in result set
redCircle.hide();
layer.draw();
assert.equal(stage.getAllIntersections(350, 118).length, 1, '9) getAllIntersections should return one shape');
assert.equal(stage.getAllIntersections(350, 118)[0].getId(), 'greenCircle', '10) first intersection should be greenCircle');
assert.equal(stage.getAllIntersections({x: 350, y:118}).length, 1, '9) getAllIntersections should return one shape');
assert.equal(stage.getAllIntersections({x: 350, y:118})[0].getId(), 'greenCircle', '10) first intersection should be greenCircle');
// show red circle again. make sure both circles are in result set
redCircle.show();
layer.draw();
assert.equal(stage.getAllIntersections(350, 118).length, 2, '11) getAllIntersections should return two shapes');
assert.equal(stage.getAllIntersections(350, 118)[0].getId(), 'redCircle', '12) first intersection should be redCircle');
assert.equal(stage.getAllIntersections(350, 118)[1].getId(), 'greenCircle', '13) second intersection should be greenCircle');
assert.equal(stage.getAllIntersections({x: 350, y:118}).length, 2, '11) getAllIntersections should return two shapes');
assert.equal(stage.getAllIntersections({x: 350, y:118})[0].getId(), 'redCircle', '12) first intersection should be redCircle');
assert.equal(stage.getAllIntersections({x: 350, y:118})[1].getId(), 'greenCircle', '13) second intersection should be greenCircle');
// test from layer
assert.equal(layer.getAllIntersections(350, 118).length, 2, '14) getAllIntersections should return two shapes');
assert.equal(layer.getAllIntersections(350, 118)[0].getId(), 'redCircle', '15) first intersection should be redCircle');
assert.equal(layer.getAllIntersections(350, 118)[1].getId(), 'greenCircle', '16) second intersection should be greenCircle');
assert.equal(layer.getAllIntersections({x: 350, y:118}).length, 2, '14) getAllIntersections should return two shapes');
assert.equal(layer.getAllIntersections({x: 350, y:118})[0].getId(), 'redCircle', '15) first intersection should be redCircle');
assert.equal(layer.getAllIntersections({x: 350, y:118})[1].getId(), 'greenCircle', '16) second intersection should be greenCircle');
});
@@ -316,7 +312,7 @@ suite('Stage', function() {
layer.add(circle);
stage.add(layer);
stage.setScale(0.5);
stage.setScale({x:0.5, y:0.5});
assert.equal(stage.getScale().x, 0.5, 'stage scale x should be 0.5');
assert.equal(stage.getScale().y, 0.5, 'stage scale y should be 0.5');
@@ -336,7 +332,7 @@ suite('Stage', function() {
strokeWidth: 4
});
stage.setScale(0.5);
stage.setScale({x:0.5, y:0.5});
assert.equal(stage.getScale().x, 0.5, 'stage scale x should be 0.5');
assert.equal(stage.getScale().y, 0.5, 'stage scale y should be 0.5');

View File

@@ -15,8 +15,6 @@ suite('Rect', function(){
stroke: 'blue'
});
console.log(rect)
layer.add(rect);
stage.add(layer);