Skip to content

Commit

Permalink
added test (#5344)
Browse files Browse the repository at this point in the history
  • Loading branch information
asturur authored Oct 27, 2018
1 parent 40de484 commit 0a76ff3
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/shapes/group.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -558,9 +558,12 @@
*/
fabric.Group.fromObject = function(object, callback) {
fabric.util.enlivenObjects(object.objects, function(enlivenedObjects) {
var options = fabric.util.object.clone(object, true);
delete options.objects;
callback && callback(new fabric.Group(enlivenedObjects, options, true));
fabric.util.enlivenObjects([object.clipPath], function(enlivedClipPath) {
var options = fabric.util.object.clone(object, true);
options.clipPath = enlivedClipPath[0];
delete options.objects;
callback && callback(new fabric.Group(enlivenedObjects, options, true));
});
});
};

Expand Down
32 changes: 32 additions & 0 deletions test/unit/group.js
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,38 @@
});
});

QUnit.test('fromObject with clipPath', function(assert) {
var done = assert.async();
var clipPath = new fabric.Rect({
width: 500,
height: 250,
top: 0,
left: 0,
absolutePositioned: true
});

var groupObject = new fabric.Group([
new fabric.Rect({ width: 100, height: 100, fill: 'red' }),
new fabric.Rect({ width: 100, height: 100, fill: 'yellow', left: 100 }),
new fabric.Rect({ width: 100, height: 100, fill: 'blue', top: 100 }),
new fabric.Rect({ width: 100, height: 100, fill: 'green', left: 100, top: 100 })
]);
groupObject.clipPath = clipPath;

var groupToObject = groupObject.toObject();

fabric.Group.fromObject(groupToObject, function(newGroupFromObject) {

var objectFromNewGroup = newGroupFromObject.toObject();

assert.ok(newGroupFromObject instanceof fabric.Group);
assert.ok(newGroupFromObject.clipPath instanceof fabric.Rect, 'clipPath has been restored');
assert.deepEqual(objectFromNewGroup, groupToObject, 'double serialization gives same results');

done();
});
});

QUnit.test('fromObject restores oCoords', function(assert) {
var done = assert.async();
var group = makeGroupWith2ObjectsWithOpacity();
Expand Down

0 comments on commit 0a76ff3

Please sign in to comment.