From 78d67b13d446fc06158cf52641aa76adaac3aaa2 Mon Sep 17 00:00:00 2001 From: Andrea Bogazzi Date: Mon, 12 Nov 2018 00:28:49 +0100 Subject: [PATCH 1/3] added test --- src/shapes/object.class.js | 4 +++- test/unit/object.js | 12 ++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/shapes/object.class.js b/src/shapes/object.class.js index ffd55eccc0c..e307b1cdb12 100644 --- a/src/shapes/object.class.js +++ b/src/shapes/object.class.js @@ -1031,7 +1031,9 @@ * @return {Boolean} */ isNotVisible: function() { - return this.opacity === 0 || (this.width === 0 && this.height === 0) || !this.visible; + return this.opacity === 0 || + (this.width === 0 && this.height === 0 && this.strokeWidth === 0) || + !this.visible; }, /** diff --git a/test/unit/object.js b/test/unit/object.js index 28b9c47aff8..6bfd19f6363 100644 --- a/test/unit/object.js +++ b/test/unit/object.js @@ -1249,4 +1249,16 @@ object._set('fill', 'blue'); assert.equal(object.dirty, false, 'dirty is not rised'); }); + QUnit.test('isNotVisible', function(assert) { + var object = new fabric.Object({ fill: 'blue', width: 100, height: 100 }); + assert.equal(object.isNotVisible(), false, 'object is default visilbe'); + object = new fabric.Object({ fill: 'blue', width: 0, height: 0, strokeWidth: 1 }); + assert.equal(object.isNotVisible(), false, 'object is visilbe with width and height equal 0, but strokeWidth 1'); + object = new fabric.Object({ opacity: 0, fill: 'blue' }); + assert.equal(object.isNotVisible(), true, 'object is not visilbe with opacity 0'); + object = new fabric.Object({ fill: 'blue', visible: false }); + assert.equal(object.isNotVisible(), true, 'object is not visilbe with visible false'); + object = new fabric.Object({ fill: 'blue', width: 0, height: 0, strokeWidth: 0 }); + assert.equal(object.isNotVisible(), true, 'object is not visilbe with also strokeWidth equal 0'); + }); })(); From 83d89867e916e72db2a46cb6aa378420a7be3e82 Mon Sep 17 00:00:00 2001 From: Andrea Bogazzi Date: Mon, 12 Nov 2018 00:42:51 +0100 Subject: [PATCH 2/3] fixed ellipse test --- test/unit/ellipse.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/test/unit/ellipse.js b/test/unit/ellipse.js index 03c8d6ce36f..9e67e386f5b 100644 --- a/test/unit/ellipse.js +++ b/test/unit/ellipse.js @@ -83,18 +83,18 @@ assert.deepEqual(ellipse.getRx(), ellipse.rx * ellipse.scaleX); }); - QUnit.test('render', function(assert) { + QUnit.test('isNotVisible', function(assert) { var ellipse = new fabric.Ellipse(); ellipse.set('rx', 0).set('ry', 0); var wasRenderCalled = false; - ellipse._render = function(){ - wasRenderCalled = true; - }; - ellipse.render({}); + assert.equal(ellipse.isNotVisible(), false, 'isNotVisible false when rx/ry are 0 because strokeWidth is > 0'); + + ellipse.set('strokeWidth', 0); + + assert.equal(ellipse.isNotVisible(), true, 'should not render anymore with also strokeWidth 0'); - assert.equal(wasRenderCalled, false, 'should not render when rx/ry are 0'); }); QUnit.test('toSVG', function(assert) { From d5608bdeeb2d4ee4aaeba2fe3b129a5c8e23eff2 Mon Sep 17 00:00:00 2001 From: Andrea Bogazzi Date: Mon, 12 Nov 2018 00:49:14 +0100 Subject: [PATCH 3/3] fixed ellipse lint --- test/unit/ellipse.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/test/unit/ellipse.js b/test/unit/ellipse.js index 9e67e386f5b..63b0031e15c 100644 --- a/test/unit/ellipse.js +++ b/test/unit/ellipse.js @@ -87,8 +87,6 @@ var ellipse = new fabric.Ellipse(); ellipse.set('rx', 0).set('ry', 0); - var wasRenderCalled = false; - assert.equal(ellipse.isNotVisible(), false, 'isNotVisible false when rx/ry are 0 because strokeWidth is > 0'); ellipse.set('strokeWidth', 0);