Skip to content

Commit

Permalink
Implement unit tests for paperjs#991
Browse files Browse the repository at this point in the history
Tests for item.addChildren()/removeChildren(), some currently failing.
  • Loading branch information
lehni committed Feb 23, 2016
1 parent 50bd5be commit 1cb2916
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions test/tests/Item.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,40 @@ test('item.remove()', function() {
}, 0);
});


test('item.addChildren() / item.removeChildren()', function() {
var project = paper.project,
layer = project.activeLayer,
path1 = new Path({ insert: false }),
path2 = new Path({ insert: false, name: 'path2' });

layer.addChildren([path1, path2]);
equals(function() { return path1.index; }, 0);
equals(function() { return path2.index; }, 1);
equals(function() { return path1.parent === layer; }, true);
equals(function() { return path2.parent === layer; }, true);
equals(function() { return layer.children['path2'] === path2; }, true);
layer.removeChildren();
equals(function() { return path1.index; }, undefined);
equals(function() { return path2.index; }, undefined);
equals(function() { return path1.parent; }, null);
equals(function() { return path2.parent; }, null);
equals(function() { return layer.children['path2'] === undefined; }, true);

layer.children = [path1, path2];
equals(function() { return path1.index; }, 0);
equals(function() { return path2.index; }, 1);
equals(function() { return path1.parent === layer; }, true);
equals(function() { return path2.parent === layer; }, true);
equals(function() { return layer.children['path2'] === path2; }, true);
layer.children = [];
equals(function() { return path1.index; }, undefined);
equals(function() { return path2.index; }, undefined);
equals(function() { return path1.parent; }, null);
equals(function() { return path2.parent; }, null);
equals(function() { return layer.children['path2'] === undefined; }, true);
});

test('item.lastChild / item.firstChild', function() {
var project = paper.project;
var path = new Path();
Expand Down

0 comments on commit 1cb2916

Please sign in to comment.