Skip to content

Commit

Permalink
ensure canBeSwapped can only be true when a style prop has actually b…
Browse files Browse the repository at this point in the history
…een set to a value (#4751)
  • Loading branch information
stefanhayden authored and asturur committed Feb 20, 2018
1 parent d569407 commit d1e5337
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/mixins/text_style.mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
style = obj[p1][p2][property];
foundStyle = true;
}
else if (obj[p1][p2][property] !== style) {
else if (obj[p1][p2][property] !== style || !obj[p1][p2].hasOwnProperty(property)) {
canBeSwapped = false;
}
if (obj[p1][p2][property] === this[property]) {
Expand Down
34 changes: 34 additions & 0 deletions test/unit/text.js
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,26 @@
assert.equal(text.styles[1][0].stroke, 'blue', 'nothing to clean, style untouched');
});

QUnit.test('text cleanStyle with different sub styles styles', function(assert) {
var text = new fabric.Text('xxxxxx\nx y');
text.styles = { 1: { 0: { fill: 'red' }, 1: { stroke: 'red' }}};
text.stroke = 'red';
text.cleanStyle('stroke');
assert.equal(text.stroke, 'red', 'the stroke stays red');
assert.equal(text.styles[1][0].fill, 'red', 'the style has not been changed since it\'s a different property');
assert.equal(text.styles[1][0].stroke, undefined, 'the style has been cleaned since stroke was equal to text property');
assert.equal(text.styles[1][1], undefined, 'the style remains undefined');
});

QUnit.test('text cleanStyle with undefined and set styles', function(assert) {
var text = new fabric.Text('xxxxxx\nx y');
text.styles = { 1: { 1: { stroke: 'red' }, 3: { stroke: 'red' }}};
text.stroke = 'red';
text.cleanStyle('stroke');
assert.equal(text.stroke, 'red', 'the stroke stays red');
assert.equal(text.styles[1], undefined, 'the style has been cleaned since stroke was equal to text property');
});

QUnit.test('text cleanStyle with empty styles', function(assert) {
var text = new fabric.Text('xxxxxx\nx y');
text.styles = { 1: { 0: { }, 1: { }}, 2: { }, 3: { 4: { }}};
Expand All @@ -354,6 +374,20 @@
assert.equal(text.styles[0], undefined, 'all the style has been removed');
});

QUnit.test('text cleanStyle with no relevant style', function(assert) {
var text = new fabric.Text('xxx');
text.styles = { 0: { 0: { other: 'value1' }, 1: { other: 'value2' }, 2: { other: 'value3' }}};
text.fill = 'black';
text.cleanStyle('fill');
assert.equal(text.fill, 'black', 'the fill remains black');
assert.equal(text.styles[0][0].other, 'value1', 'style remains the same');
assert.equal(text.styles[0][0].full, undefined, 'style remains undefined');
assert.equal(text.styles[0][1].other, 'value2', 'style remains the same');
assert.equal(text.styles[0][1].full, undefined, 'style remains undefined');
assert.equal(text.styles[0][2].other, 'value3', 'style remains the same');
assert.equal(text.styles[0][2].full, undefined, 'style remains undefined');
});

QUnit.test('text removeStyle with some style', function(assert) {
var text = new fabric.Text('xxx');
text.styles = { 0: { 0: { stroke: 'black', fill: 'blue' }, 1: { fill: 'blue' }, 2: { fill: 'blue' }}};
Expand Down

0 comments on commit d1e5337

Please sign in to comment.