From 7a1b854a120f0288974c4252a4cd44d99d752078 Mon Sep 17 00:00:00 2001 From: Eric Rowell Date: Wed, 24 Jul 2013 21:57:45 -0700 Subject: [PATCH] #291 added unit test for creating a blob via json who has the tension defined before the points array --- tests/js/unit/shapes/blobTests.js | 51 ++++++++++++++++++++++++++--- tests/js/unit/shapes/splineTests.js | 12 +++---- 2 files changed, 53 insertions(+), 10 deletions(-) diff --git a/tests/js/unit/shapes/blobTests.js b/tests/js/unit/shapes/blobTests.js index 9254d58e..e486ca43 100644 --- a/tests/js/unit/shapes/blobTests.js +++ b/tests/js/unit/shapes/blobTests.js @@ -27,7 +27,7 @@ Test.Modules.BLOB = { fill: '#aaf', tension: 0.8 }); - + var blob2 = new Kinetic.Blob({ points: [{ x: 73, @@ -48,7 +48,7 @@ Test.Modules.BLOB = { x: 100, y: 50 }); - + layer.add(blob1); layer.add(blob2); @@ -56,11 +56,54 @@ Test.Modules.BLOB = { test(blob1.getTension() === 0.8, 'blob1 tension should be 0.8'); test(blob2.getTension() === 1.2, 'blob2 tension should be 1.2'); - + test(blob1.getClassName() === 'Blob', 'getClassName should be Blob'); //console.log(blob1.getPoints()) - + + + }, + 'add blob and define tension first': function(containerId) { + var stage = new Kinetic.Stage({ + container: containerId, + width: 578, + height: 200 + }); + var layer = new Kinetic.Layer(); + + /* + var blob = new Kinetic.Blob({ + tension: 0.8, + points: [{ + x: 73, + y: 140 + }, { + x: 340, + y: 23 + }, { + x: 500, + y: 109 + }, { + x: 300, + y: 170 + }], + stroke: 'blue', + strokeWidth: 10, + draggable: true, + fill: '#aaf' + + }); + */ + + var json = '{"attrs":{"tension":0.8,"points":[{"x":73,"y":140},{"x":340,"y":23},{"x":500,"y":109},{"x":300,"y":170}],"stroke":"blue","strokeWidth":10,"draggable":true,"fill":"#aaf"},"className":"Blob"}'; + var blob = Kinetic.Node.create(json); + + layer.add(blob); + stage.add(layer); + + //console.log(blob.toJSON()); + + test(stage.get('Blob')[0].getPoints().length === 4, 'created blob should have 4 points'); } }; diff --git a/tests/js/unit/shapes/splineTests.js b/tests/js/unit/shapes/splineTests.js index 7aa1fe2d..cd0803f0 100644 --- a/tests/js/unit/shapes/splineTests.js +++ b/tests/js/unit/shapes/splineTests.js @@ -28,7 +28,7 @@ Test.Modules.SPLINE = { draggable: true, tension: 1 }); - + var line2 = new Kinetic.Spline({ points: [{ x: 73, @@ -47,7 +47,7 @@ Test.Modules.SPLINE = { draggable: true, tension: 1 }); - + var line3 = new Kinetic.Spline({ points: [{ x: 73, @@ -68,7 +68,7 @@ Test.Modules.SPLINE = { layer.add(line2); layer.add(line3); stage.add(layer); - + test(line1.getClassName() === 'Spline', 'getClassName should be Spline'); @@ -102,7 +102,7 @@ Test.Modules.SPLINE = { draggable: true, tension: 1 }); - + layer.add(spline); stage.add(layer); @@ -123,7 +123,7 @@ Test.Modules.SPLINE = { test(spline.allPoints.length === 3, 'spline all points should have 3 points'); layer.draw(); - + }, 'add point to spline points': function(containerId) { @@ -155,7 +155,7 @@ Test.Modules.SPLINE = { draggable: true, tension: 1 }); - + layer.add(spline); stage.add(layer);