From 3ea4a4ad95dc38e07e7264c021d03fd2abeb58f1 Mon Sep 17 00:00:00 2001 From: kangax Date: Wed, 11 May 2011 18:17:21 -0400 Subject: [PATCH] Fix majority of failing unit tests. --- dist/all.js | 2 +- src/element.class.js | 2 +- test/unit/circle.js | 3 +- test/unit/element.js | 9 +++--- test/unit/ellipse.js | 3 +- test/unit/group.js | 5 ++- test/unit/image.js | 3 +- test/unit/line.js | 3 +- test/unit/object.js | 2 +- test/unit/path.js | 3 +- test/unit/path_group.js | 1 + test/unit/polygon.js | 3 +- test/unit/polyline.js | 3 +- test/unit/rect.js | 7 ++-- test/unit/text.js | 71 ++++++++++++++++++++++++----------------- 15 files changed, 72 insertions(+), 48 deletions(-) diff --git a/dist/all.js b/dist/all.js index 95fcf4eb..f0bceadc 100644 --- a/dist/all.js +++ b/dist/all.js @@ -6082,7 +6082,7 @@ fabric.util.animate = animate; data = imageData.data, iLen = imageData.width, jLen = imageData.height, - index, average; + index, average, i, j; for (i = 0; i < iLen; i++) { for (j = 0; j < jLen; j++) { diff --git a/src/element.class.js b/src/element.class.js index b96eacac..62fe3586 100644 --- a/src/element.class.js +++ b/src/element.class.js @@ -2318,7 +2318,7 @@ data = imageData.data, iLen = imageData.width, jLen = imageData.height, - index, average; + index, average, i, j; for (i = 0; i < iLen; i++) { for (j = 0; j < jLen; j++) { diff --git a/test/unit/circle.js b/test/unit/circle.js index da9a4f2d..1fd0c45d 100644 --- a/test/unit/circle.js +++ b/test/unit/circle.js @@ -62,7 +62,8 @@ 'flipX': false, 'flipY': false, 'opacity': 1, - 'radius': 0 + 'radius': 0, + 'selectable': true }; ok(typeof circle.toObject == 'function'); same(circle.toObject(), defaultProperties); diff --git a/test/unit/element.js b/test/unit/element.js index 2fee7675..f48c2f3d 100644 --- a/test/unit/element.js +++ b/test/unit/element.js @@ -21,10 +21,10 @@ var PATH_DATALESS_JSON = '{"objects":[{"type":"path","left":100,"top":100,"width":200,"height":200,"fill":"rgb(0,0,0)",'+ '"overlayFill":null,"stroke":null,"strokeWidth":1,"scaleX":1,"scaleY":1,"angle":0,"flipX":false,'+ - '"flipY":false,"opacity":1,"path":"http://example.com/"}],"background":"rgba(0, 0, 0, 0)"}'; + '"flipY":false,"opacity":1,"selectable":true,"path":"http://example.com/"}],"background":"rgba(0, 0, 0, 0)"}'; var RECT_JSON = '{"objects":[{"type":"rect","left":0,"top":0,"width":10,"height":10,"fill":"rgb(0,0,0)","overlayFill":null,'+ - '"stroke":null,"strokeWidth":1,"scaleX":1,"scaleY":1,"angle":0,"flipX":false,"flipY":false,"opacity":1}],'+ + '"stroke":null,"strokeWidth":1,"scaleX":1,"scaleY":1,"angle":0,"flipX":false,"flipY":false,"opacity":1,"selectable":true}],'+ '"background":"#ff5555"}'; var canvas = this.canvas = new fabric.Element('test'); @@ -713,7 +713,7 @@ ok(imgEl.width < ORIGINAL_WIDTH); start(); - }, 2000); + }, 1000); }); asyncTest('cache', function() { @@ -763,7 +763,7 @@ ok(/fixtures\/very_large_image\.jpg$/.test(objectPassedToCallback.getSrc()), 'image should have correct src'); start(); - }, 2000); + }, 1000); }); asyncTest('fxRemove', function() { @@ -783,7 +783,6 @@ setTimeout(function() { equals(canvas.item(0), undefined); ok(callbackFired); - start(); }, 1000); }); diff --git a/test/unit/ellipse.js b/test/unit/ellipse.js index fa7bfc7c..792da280 100644 --- a/test/unit/ellipse.js +++ b/test/unit/ellipse.js @@ -38,7 +38,8 @@ 'flipY': false, 'opacity': 1, 'rx': 0, - 'ry': 0 + 'ry': 0, + 'selectable': true }; ok(typeof ellipse.toObject == 'function'); same(defaultProperties, ellipse.toObject()); diff --git a/test/unit/group.js b/test/unit/group.js index 07597f95..d0cd5528 100644 --- a/test/unit/group.js +++ b/test/unit/group.js @@ -114,6 +114,7 @@ ok(typeof group.toObject == 'function'); var clone = group.toObject(); + var expectedObject = { 'type': 'group', 'left': 80, @@ -126,6 +127,7 @@ 'strokeWidth': 1, 'scaleX': 1, 'scaleY': 1, + 'selectable': true, 'angle': 0, 'flipX': false, 'flipY': false, @@ -133,7 +135,8 @@ 'objects': clone.objects }; - same(expectedObject, clone); + console.log(clone, expectedObject); + same(clone, expectedObject); ok(group !== clone, 'should produce different object'); ok(group.getObjects() !== clone.objects, 'should produce different object array'); diff --git a/test/unit/image.js b/test/unit/image.js index fa2e50da..f9395f57 100644 --- a/test/unit/image.js +++ b/test/unit/image.js @@ -30,7 +30,8 @@ 'flipX': false, 'flipY': false, 'opacity': 1, - 'src': IMG_SRC + 'src': IMG_SRC, + 'selectable': true } function _createImageObject(width, height) { diff --git a/test/unit/line.js b/test/unit/line.js index beaa3846..3fde65b1 100644 --- a/test/unit/line.js +++ b/test/unit/line.js @@ -19,7 +19,8 @@ 'x1': 11, 'y1': 12, 'x2': 13, - 'y2': 14 + 'y2': 14, + 'selectable': true }; module('fabric.Line'); diff --git a/test/unit/object.js b/test/unit/object.js index 182ba442..96345e66 100644 --- a/test/unit/object.js +++ b/test/unit/object.js @@ -364,7 +364,7 @@ ok(image); ok(image instanceof fabric.Image); start(); - }, 1000); + }, 500); cObj.cloneAsImage(function(i) { image = i; diff --git a/test/unit/path.js b/test/unit/path.js index 8c93eebb..fb39e34a 100644 --- a/test/unit/path.js +++ b/test/unit/path.js @@ -16,7 +16,8 @@ 'flipX': false, 'flipY': false, 'opacity': 1, - 'path': [['M', 100, 100], ['L', 300, 100], ['L', 200, 300], ['z', NaN]] + 'path': [['M', 100, 100], ['L', 300, 100], ['L', 200, 300], ['z', NaN]], + 'selectable': true }; function getPathElement(path) { diff --git a/test/unit/path_group.js b/test/unit/path_group.js index a13075d6..6a50b1b2 100644 --- a/test/unit/path_group.js +++ b/test/unit/path_group.js @@ -16,6 +16,7 @@ 'flipX': false, 'flipY': false, 'opacity': 1, + 'selectable': true, 'paths': getPathObjects() }; diff --git a/test/unit/polygon.js b/test/unit/polygon.js index 6139f848..79354f45 100644 --- a/test/unit/polygon.js +++ b/test/unit/polygon.js @@ -23,7 +23,8 @@ 'flipX': false, 'flipY': false, 'opacity': 1, - 'points': getPoints() + 'points': getPoints(), + 'selectable': true }; module('fabric.Polygon'); diff --git a/test/unit/polyline.js b/test/unit/polyline.js index 35880f2c..482db916 100644 --- a/test/unit/polyline.js +++ b/test/unit/polyline.js @@ -23,7 +23,8 @@ 'flipX': false, 'flipY': false, 'opacity': 1, - 'points': getPoints() + 'points': getPoints(), + 'selectable': true }; module('fabric.Polyline'); diff --git a/test/unit/rect.js b/test/unit/rect.js index e5c5e061..8cc305ea 100644 --- a/test/unit/rect.js +++ b/test/unit/rect.js @@ -4,8 +4,8 @@ 'type': 'rect', 'left': 0, 'top': 0, - 'width': 100, - 'height': 100, + 'width': 0, + 'height': 0, 'fill': 'rgb(0,0,0)', 'overlayFill': null, 'stroke': null, @@ -15,7 +15,8 @@ 'angle': 0, 'flipX': false, 'flipY': false, - 'opacity': 1 + 'opacity': 1, + 'selectable': true }; module('fabric.Rect'); diff --git a/test/unit/text.js b/test/unit/text.js index 2775e0ff..6f0a91f1 100644 --- a/test/unit/text.js +++ b/test/unit/text.js @@ -1,34 +1,47 @@ (function() { + function createTextObject() { + return new fabric.Text('foo', { + fontfamily: 'Modernist_One_400' + }); + } + var REFERENCE_TEXT_OBJECT = { - 'type': 'text', - 'left': 10, - 'top': 10, - 'width': 100, - 'height': 100, - 'fill': 'rgb(0,0,0)', - 'overlayFill': null, - 'stroke': null, - 'strokeWidth': 1, - 'scaleX': 1, - 'scaleY': 1, - 'angle': 0, - 'flipX': false, - 'flipY': false, - 'opacity': 1, - 'text': 'foo', - 'fontsize': 20, - 'fontweight': 100, - 'fontfamily': 'Modernist_One_400', - 'path': null + 'type': 'text', + 'left': 0, + 'top': 0, + 'width': 0, + 'height': 0, + 'fill': 'rgb(0,0,0)', + 'overlayFill': null, + 'stroke': null, + 'strokeWidth': 1, + 'scaleX': 1, + 'scaleY': 1, + 'angle': 0, + 'flipX': false, + 'flipY': false, + 'opacity': 1, + 'selectable': true, + 'text': 'foo', + 'fontsize': 20, + 'fontweight': 100, + 'fontfamily': 'Modernist_One_400', + "lineHeight": 1, + "textDecoration": '', + "textShadow": null, + "strokeStyle": '', + "fontStyle": '', + "path": null }; module('fabric.Text'); test('constructor', function() { ok(fabric.Text); - var text = new fabric.Text('foo'); + var text = createTextObject(); + ok(text); ok(text instanceof fabric.Text); ok(text instanceof fabric.Object); @@ -37,51 +50,51 @@ }); test('toString', function() { - var text = new fabric.Text('foo'); + var text = createTextObject(); ok(typeof text.toString == 'function'); equals(text.toString(), '#'); }); test('toObject', function() { - var text = new fabric.Text('foo'); + var text = createTextObject(); ok(typeof text.toObject == 'function'); same(text.toObject(), REFERENCE_TEXT_OBJECT); }); test('complexity', function(){ - var text = new fabric.Text('foo'); + var text = createTextObject(); ok(typeof text.complexity == 'function'); }); test('set', function() { - var text = new fabric.Text('foo'); + var text = createTextObject(); ok(typeof text.set == 'function'); equals(text.set('text', 'bar'), text, 'should be chainable'); }); test('setColor', function(){ - var text = new fabric.Text('foo'); + var text = createTextObject(); ok(typeof text.setColor == 'function'); equals(text.setColor('123456'), text, 'should be chainable'); equals(text.get('fill'), '123456'); }); test('setFontsize', function(){ - var text = new fabric.Text('foo'); + var text = createTextObject(); ok(typeof text.setFontsize == 'function'); equals(text.setFontsize(12), text); equals(text.get('fontsize'), 12); }); test('getText', function(){ - var text = new fabric.Text('foo'); + var text = createTextObject(); ok(typeof text.getText == 'function'); equals(text.getText(), 'foo'); equals(text.getText(), text.get('text')); }); test('setText', function(){ - var text = new fabric.Text('foo'); + var text = createTextObject(); ok(typeof text.setText == 'function'); equals(text.setText('bar'), text, 'should be chainable'); equals(text.getText(), 'bar');