From 1cb291690d599a4ee9b3c907dc27bcc8a6ed7358 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Tue, 23 Feb 2016 11:55:03 +0100 Subject: [PATCH] Implement unit tests for #991 Tests for item.addChildren()/removeChildren(), some currently failing. --- test/tests/Item.js | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/test/tests/Item.js b/test/tests/Item.js index dc1f1a1b..b9c6b455 100644 --- a/test/tests/Item.js +++ b/test/tests/Item.js @@ -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();