2011-07-01 06:17:45 -04:00
|
|
|
/*
|
2013-01-28 21:03:27 -05:00
|
|
|
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
|
2011-07-01 06:17:45 -04:00
|
|
|
* http://paperjs.org/
|
|
|
|
*
|
2013-01-28 21:03:27 -05:00
|
|
|
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
|
2011-07-01 06:17:45 -04:00
|
|
|
* http://lehni.org/ & http://jonathanpuckey.com/
|
|
|
|
*
|
|
|
|
* Distributed under the MIT license. See LICENSE file for details.
|
|
|
|
*
|
|
|
|
* All rights reserved.
|
|
|
|
*/
|
|
|
|
|
2011-02-11 12:50:26 -05:00
|
|
|
module('Item');
|
|
|
|
|
2011-05-16 08:33:15 -04:00
|
|
|
test('copyTo(project)', function() {
|
2011-05-20 09:08:17 -04:00
|
|
|
var project = paper.project;
|
2011-02-12 11:43:51 -05:00
|
|
|
var path = new Path();
|
2011-05-16 08:33:15 -04:00
|
|
|
var secondDoc = new Project();
|
2011-02-12 11:43:51 -05:00
|
|
|
var copy = path.copyTo(secondDoc);
|
2011-05-07 12:46:06 -04:00
|
|
|
equals(function() {
|
|
|
|
return secondDoc.activeLayer.children.indexOf(copy) != -1;
|
|
|
|
}, true);
|
|
|
|
equals(function() {
|
2011-05-20 09:08:17 -04:00
|
|
|
return project.activeLayer.children.indexOf(copy) == -1;
|
2011-05-07 12:46:06 -04:00
|
|
|
}, true);
|
|
|
|
equals(function() {
|
|
|
|
return copy != path;
|
|
|
|
}, true);
|
2011-02-12 11:43:51 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
test('copyTo(layer)', function() {
|
2011-05-20 09:08:17 -04:00
|
|
|
var project = paper.project;
|
2011-02-12 11:43:51 -05:00
|
|
|
var path = new Path();
|
|
|
|
|
|
|
|
var layer = new Layer();
|
|
|
|
var copy = path.copyTo(layer);
|
2011-05-07 12:46:06 -04:00
|
|
|
equals(function() {
|
|
|
|
return layer.children.indexOf(copy) != -1;
|
|
|
|
}, true);
|
|
|
|
equals(function() {
|
2011-05-20 09:08:17 -04:00
|
|
|
return project.layers[0].children.indexOf(copy) == -1;
|
2011-05-07 12:46:06 -04:00
|
|
|
}, true);
|
2011-02-12 11:43:51 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
test('clone()', function() {
|
2011-05-20 09:08:17 -04:00
|
|
|
var project = paper.project;
|
2011-02-12 11:43:51 -05:00
|
|
|
var path = new Path();
|
|
|
|
var copy = path.clone();
|
2011-05-07 12:46:06 -04:00
|
|
|
equals(function() {
|
2011-05-20 09:08:17 -04:00
|
|
|
return project.activeLayer.children.length;
|
2011-05-14 13:59:04 -04:00
|
|
|
}, 2);
|
2011-05-07 12:46:06 -04:00
|
|
|
equals(function() {
|
|
|
|
return path != copy;
|
|
|
|
}, true);
|
2011-02-12 11:43:51 -05:00
|
|
|
});
|
|
|
|
|
2011-06-17 10:58:22 -04:00
|
|
|
test('addChild(item)', function() {
|
2011-05-20 09:08:17 -04:00
|
|
|
var project = paper.project;
|
2011-02-11 12:50:26 -05:00
|
|
|
var path = new Path();
|
2011-06-17 10:58:22 -04:00
|
|
|
project.activeLayer.addChild(path);
|
2011-05-07 12:46:06 -04:00
|
|
|
equals(function() {
|
2011-05-20 09:08:17 -04:00
|
|
|
return project.activeLayer.children.length;
|
2011-05-07 12:46:06 -04:00
|
|
|
}, 1);
|
2011-02-11 12:50:26 -05:00
|
|
|
});
|
|
|
|
|
2011-09-18 04:38:16 -04:00
|
|
|
test('item.parent / item.isChild / item.isParent / item.layer', function() {
|
2011-05-20 09:08:17 -04:00
|
|
|
var project = paper.project;
|
2011-05-16 08:33:15 -04:00
|
|
|
var secondDoc = new Project();
|
2011-02-11 12:50:26 -05:00
|
|
|
var path = new Path();
|
2011-06-17 10:58:22 -04:00
|
|
|
project.activeLayer.addChild(path);
|
2011-05-07 12:46:06 -04:00
|
|
|
equals(function() {
|
2011-05-20 09:08:17 -04:00
|
|
|
return project.activeLayer.children.indexOf(path) != -1;
|
2011-09-18 04:38:16 -04:00
|
|
|
}, true);
|
|
|
|
equals(function() {
|
|
|
|
return path.layer == project.activeLayer;
|
2011-05-07 12:46:06 -04:00
|
|
|
}, true);
|
2011-06-17 10:58:22 -04:00
|
|
|
secondDoc.activeLayer.addChild(path);
|
2011-05-07 12:46:06 -04:00
|
|
|
equals(function() {
|
2011-05-20 09:08:17 -04:00
|
|
|
return project.activeLayer.isChild(path);
|
2011-05-07 12:46:06 -04:00
|
|
|
}, false);
|
2011-09-18 04:38:16 -04:00
|
|
|
equals(function() {
|
|
|
|
return path.layer == secondDoc.activeLayer;
|
|
|
|
}, true);
|
2011-05-07 12:46:06 -04:00
|
|
|
equals(function() {
|
2011-05-20 09:08:17 -04:00
|
|
|
return path.isParent(project.activeLayer);
|
2011-05-07 12:46:06 -04:00
|
|
|
}, false);
|
|
|
|
equals(function() {
|
|
|
|
return secondDoc.activeLayer.isChild(path);
|
|
|
|
}, true);
|
|
|
|
equals(function() {
|
|
|
|
return path.isParent(secondDoc.activeLayer);
|
|
|
|
}, true);
|
|
|
|
equals(function() {
|
2011-05-20 09:08:17 -04:00
|
|
|
return project.activeLayer.children.indexOf(path) == -1;
|
2011-05-07 12:46:06 -04:00
|
|
|
}, true);
|
|
|
|
equals(function() {
|
|
|
|
return secondDoc.activeLayer.children.indexOf(path) == 0;
|
|
|
|
}, true);
|
2011-02-11 12:50:26 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
test('item.lastChild / item.firstChild', function() {
|
2011-05-20 09:08:17 -04:00
|
|
|
var project = paper.project;
|
2011-02-11 12:50:26 -05:00
|
|
|
var path = new Path();
|
|
|
|
var secondPath = new Path();
|
2011-05-07 12:46:06 -04:00
|
|
|
equals(function() {
|
2011-05-20 09:08:17 -04:00
|
|
|
return project.activeLayer.firstChild == path;
|
2011-05-07 12:46:06 -04:00
|
|
|
}, true);
|
|
|
|
equals(function() {
|
2011-05-20 09:08:17 -04:00
|
|
|
return project.activeLayer.lastChild == secondPath;
|
2011-05-07 12:46:06 -04:00
|
|
|
}, true);
|
2011-02-11 12:50:26 -05:00
|
|
|
});
|
|
|
|
|
2011-06-17 10:58:22 -04:00
|
|
|
test('insertChild(0, item)', function() {
|
2011-05-20 09:08:17 -04:00
|
|
|
var project = paper.project;
|
2011-02-11 12:50:26 -05:00
|
|
|
var path = new Path();
|
|
|
|
var secondPath = new Path();
|
2011-06-17 10:58:22 -04:00
|
|
|
project.activeLayer.insertChild(0, secondPath);
|
2011-05-07 12:46:06 -04:00
|
|
|
equals(function() {
|
|
|
|
return secondPath.index < path.index;
|
|
|
|
}, true);
|
2011-02-11 12:50:26 -05:00
|
|
|
});
|
|
|
|
|
2011-06-17 10:58:22 -04:00
|
|
|
test('insertAbove(item)', function() {
|
2011-05-20 09:08:17 -04:00
|
|
|
var project = paper.project;
|
2011-02-11 12:50:26 -05:00
|
|
|
var path = new Path();
|
|
|
|
var secondPath = new Path();
|
2011-06-17 10:58:22 -04:00
|
|
|
path.insertAbove(secondPath);
|
2011-05-07 12:46:06 -04:00
|
|
|
equals(function() {
|
2011-05-20 09:08:17 -04:00
|
|
|
return project.activeLayer.lastChild == path;
|
2011-05-07 12:46:06 -04:00
|
|
|
}, true);
|
2011-02-11 12:50:26 -05:00
|
|
|
});
|
|
|
|
|
2011-06-17 10:58:22 -04:00
|
|
|
test('insertBelow(item)', function() {
|
2011-05-20 09:08:17 -04:00
|
|
|
var project = paper.project;
|
2011-02-11 12:50:26 -05:00
|
|
|
var firstPath = new Path();
|
|
|
|
var secondPath = new Path();
|
2011-05-07 12:46:06 -04:00
|
|
|
equals(function() {
|
|
|
|
return secondPath.index > firstPath.index;
|
|
|
|
}, true);
|
2011-06-17 10:58:22 -04:00
|
|
|
secondPath.insertBelow(firstPath);
|
2011-05-07 12:46:06 -04:00
|
|
|
equals(function() {
|
|
|
|
return secondPath.index < firstPath.index;
|
|
|
|
}, true);
|
2011-02-11 12:50:26 -05:00
|
|
|
});
|
|
|
|
|
2013-03-03 14:08:49 -05:00
|
|
|
test('sendToBack()', function() {
|
|
|
|
var project = paper.project;
|
|
|
|
var firstPath = new Path();
|
|
|
|
var secondPath = new Path();
|
|
|
|
secondPath.sendToBack();
|
|
|
|
equals(function() {
|
|
|
|
return secondPath.index == 0;
|
|
|
|
}, true);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('bringToFront()', function() {
|
|
|
|
var project = paper.project;
|
|
|
|
var firstPath = new Path();
|
|
|
|
var secondPath = new Path();
|
|
|
|
firstPath.bringToFront();
|
|
|
|
equals(function() {
|
|
|
|
return firstPath.index == 1;
|
|
|
|
}, true);
|
|
|
|
});
|
|
|
|
|
2011-02-12 10:41:57 -05:00
|
|
|
test('isDescendant(item) / isAncestor(item)', function() {
|
2011-05-20 09:08:17 -04:00
|
|
|
var project = paper.project;
|
2011-02-11 12:50:26 -05:00
|
|
|
var path = new Path();
|
2011-05-07 12:46:06 -04:00
|
|
|
equals(function() {
|
2011-05-20 09:08:17 -04:00
|
|
|
return path.isDescendant(project.activeLayer);
|
2011-05-07 12:46:06 -04:00
|
|
|
}, true);
|
|
|
|
equals(function() {
|
2011-05-20 09:08:17 -04:00
|
|
|
return project.activeLayer.isDescendant(path);
|
2011-05-07 12:46:06 -04:00
|
|
|
}, false);
|
|
|
|
equals(function() {
|
2011-05-20 09:08:17 -04:00
|
|
|
return path.isAncestor(project.activeLayer);
|
2011-05-07 12:46:06 -04:00
|
|
|
}, false);
|
|
|
|
equals(function() {
|
2011-05-20 09:08:17 -04:00
|
|
|
return project.activeLayer.isAncestor(path);
|
2011-05-07 12:46:06 -04:00
|
|
|
}, true);
|
2011-07-07 10:09:02 -04:00
|
|
|
|
2011-02-24 12:09:48 -05:00
|
|
|
// an item can't be its own descendant:
|
2011-05-07 12:46:06 -04:00
|
|
|
equals(function() {
|
2011-05-20 09:08:17 -04:00
|
|
|
return project.activeLayer.isDescendant(project.activeLayer);
|
2011-05-07 12:46:06 -04:00
|
|
|
}, false);
|
2011-02-24 12:09:48 -05:00
|
|
|
// an item can't be its own ancestor:
|
2011-05-07 12:46:06 -04:00
|
|
|
equals(function() {
|
2011-05-20 09:08:17 -04:00
|
|
|
return project.activeLayer.isAncestor(project.activeLayer);
|
2011-05-07 12:46:06 -04:00
|
|
|
}, false);
|
2011-02-24 12:09:48 -05:00
|
|
|
});
|
|
|
|
|
2013-03-02 01:41:58 -05:00
|
|
|
test('addChildren(items)', function() {
|
|
|
|
var project = paper.project;
|
|
|
|
var path1 = new Path(),
|
|
|
|
path2 = new Path(),
|
|
|
|
path3 = new Path(),
|
|
|
|
group = new Group([path1, path2, path3]);
|
|
|
|
|
|
|
|
function check(i1, i2, i3) {
|
|
|
|
equals(function() {
|
|
|
|
return group.children.length;
|
|
|
|
}, 3);
|
|
|
|
equals(function() {
|
|
|
|
return path1.index;
|
|
|
|
}, i1);
|
|
|
|
equals(function() {
|
|
|
|
return path2.index;
|
|
|
|
}, i2);
|
|
|
|
equals(function() {
|
|
|
|
return path3.index;
|
|
|
|
}, i3);
|
|
|
|
}
|
|
|
|
check(0, 1, 2);
|
|
|
|
group.addChild(path1);
|
|
|
|
check(2, 0, 1);
|
|
|
|
group.addChild(path2);
|
|
|
|
check(1, 2, 0);
|
|
|
|
group.addChildren([path1, path2, path3]);
|
|
|
|
check(0, 1, 2);
|
|
|
|
});
|
|
|
|
|
2011-02-24 12:09:48 -05:00
|
|
|
test('isGroupedWith', function() {
|
2011-05-20 09:08:17 -04:00
|
|
|
var project = paper.project;
|
2011-02-24 12:09:48 -05:00
|
|
|
var path = new Path();
|
|
|
|
var secondPath = new Path();
|
|
|
|
var group = new Group([path]);
|
|
|
|
var secondGroup = new Group([secondPath]);
|
2011-07-07 10:09:02 -04:00
|
|
|
|
2011-05-07 12:46:06 -04:00
|
|
|
equals(function() {
|
|
|
|
return path.isGroupedWith(secondPath);
|
|
|
|
}, false);
|
2011-06-17 10:58:22 -04:00
|
|
|
secondGroup.addChild(path);
|
2011-05-07 12:46:06 -04:00
|
|
|
equals(function() {
|
|
|
|
return path.isGroupedWith(secondPath);
|
|
|
|
}, true);
|
|
|
|
equals(function() {
|
|
|
|
return path.isGroupedWith(group);
|
|
|
|
}, false);
|
|
|
|
equals(function() {
|
|
|
|
return path.isDescendant(secondGroup);
|
|
|
|
}, true);
|
|
|
|
equals(function() {
|
|
|
|
return secondGroup.isDescendant(path);
|
|
|
|
}, false);
|
|
|
|
equals(function() {
|
|
|
|
return secondGroup.isDescendant(secondGroup);
|
|
|
|
}, false);
|
|
|
|
equals(function() {
|
|
|
|
return path.isGroupedWith(secondGroup);
|
|
|
|
}, false);
|
2011-06-17 10:58:22 -04:00
|
|
|
paper.project.activeLayer.addChild(path);
|
2011-05-07 12:46:06 -04:00
|
|
|
equals(function() {
|
|
|
|
return path.isGroupedWith(secondPath);
|
|
|
|
}, false);
|
2011-06-17 10:58:22 -04:00
|
|
|
paper.project.activeLayer.addChild(secondPath);
|
2011-05-07 12:46:06 -04:00
|
|
|
equals(function() {
|
|
|
|
return path.isGroupedWith(secondPath);
|
|
|
|
}, false);
|
2011-02-11 12:50:26 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
test('getPreviousSibling() / getNextSibling()', function() {
|
|
|
|
var firstPath = new Path();
|
|
|
|
var secondPath = new Path();
|
2011-05-07 12:46:06 -04:00
|
|
|
equals(function() {
|
|
|
|
return firstPath.nextSibling == secondPath;
|
|
|
|
}, true);
|
|
|
|
equals(function() {
|
|
|
|
return secondPath.previousSibling == firstPath;
|
|
|
|
}, true);
|
|
|
|
equals(function() {
|
|
|
|
return secondPath.nextSibling == null;
|
|
|
|
}, true);
|
2011-02-11 12:50:26 -05:00
|
|
|
});
|
|
|
|
|
2011-02-24 13:31:07 -05:00
|
|
|
test('reverseChildren()', function() {
|
2011-05-20 09:08:17 -04:00
|
|
|
var project = paper.project;
|
2011-02-24 13:31:07 -05:00
|
|
|
var path = new Path();
|
|
|
|
var secondPath = new Path();
|
|
|
|
var thirdPath = new Path();
|
2011-05-07 12:46:06 -04:00
|
|
|
equals(function() {
|
2011-05-20 09:08:17 -04:00
|
|
|
return project.activeLayer.firstChild == path;
|
2011-05-07 12:46:06 -04:00
|
|
|
}, true);
|
2011-05-20 09:08:17 -04:00
|
|
|
project.activeLayer.reverseChildren();
|
2011-05-07 12:46:06 -04:00
|
|
|
equals(function() {
|
2011-05-20 09:08:17 -04:00
|
|
|
return project.activeLayer.firstChild == path;
|
2011-05-07 12:46:06 -04:00
|
|
|
}, false);
|
|
|
|
equals(function() {
|
2011-05-20 09:08:17 -04:00
|
|
|
return project.activeLayer.firstChild == thirdPath;
|
2011-05-07 12:46:06 -04:00
|
|
|
}, true);
|
|
|
|
equals(function() {
|
2011-05-20 09:08:17 -04:00
|
|
|
return project.activeLayer.lastChild == path;
|
2011-05-07 12:46:06 -04:00
|
|
|
}, true);
|
2011-04-21 09:57:19 -04:00
|
|
|
});
|
|
|
|
|
2011-05-16 08:33:15 -04:00
|
|
|
test('Check item#project when moving items across projects', function() {
|
2011-05-20 09:08:17 -04:00
|
|
|
var project = paper.project;
|
2011-05-16 08:33:15 -04:00
|
|
|
var doc1 = new Project();
|
2011-04-21 09:57:19 -04:00
|
|
|
var path = new Path();
|
|
|
|
var group = new Group();
|
2011-06-17 10:58:22 -04:00
|
|
|
group.addChild(new Path());
|
2011-07-07 10:09:02 -04:00
|
|
|
|
2011-05-07 12:46:06 -04:00
|
|
|
equals(function() {
|
2011-05-16 08:33:15 -04:00
|
|
|
return path.project == doc1;
|
2011-05-07 12:46:06 -04:00
|
|
|
}, true);
|
2011-05-16 08:33:15 -04:00
|
|
|
var doc2 = new Project();
|
2011-06-17 10:58:22 -04:00
|
|
|
doc2.activeLayer.addChild(path);
|
2011-05-07 12:46:06 -04:00
|
|
|
equals(function() {
|
2011-05-16 08:33:15 -04:00
|
|
|
return path.project == doc2;
|
2011-05-07 12:46:06 -04:00
|
|
|
}, true);
|
2011-07-07 10:09:02 -04:00
|
|
|
|
2011-06-17 10:58:22 -04:00
|
|
|
doc2.activeLayer.addChild(group);
|
2011-05-07 12:46:06 -04:00
|
|
|
equals(function() {
|
2011-05-16 08:33:15 -04:00
|
|
|
return group.children[0].project == doc2;
|
2011-05-07 12:46:06 -04:00
|
|
|
}, true);
|
2011-04-21 09:57:19 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
test('group.selected', function() {
|
2011-04-22 05:41:32 -04:00
|
|
|
var path = new Path([0, 0]);
|
|
|
|
var path2 = new Path([0, 0]);
|
2011-04-21 09:57:19 -04:00
|
|
|
var group = new Group([path, path2]);
|
|
|
|
path.selected = true;
|
2011-05-07 12:46:06 -04:00
|
|
|
equals(function() {
|
|
|
|
return group.selected;
|
|
|
|
}, true);
|
2011-07-07 10:09:02 -04:00
|
|
|
|
2011-04-21 09:57:19 -04:00
|
|
|
path.selected = false;
|
2011-05-07 12:46:06 -04:00
|
|
|
equals(function() {
|
|
|
|
return group.selected;
|
|
|
|
}, false);
|
2011-07-07 10:09:02 -04:00
|
|
|
|
2011-04-21 09:57:19 -04:00
|
|
|
group.selected = true;
|
2011-05-07 12:46:06 -04:00
|
|
|
equals(function() {
|
|
|
|
return path.selected;
|
|
|
|
}, true);
|
|
|
|
equals(function() {
|
|
|
|
return path2.selected;
|
|
|
|
}, true);
|
2011-07-07 10:09:02 -04:00
|
|
|
|
2011-04-21 09:57:19 -04:00
|
|
|
group.selected = false;
|
2011-05-07 12:46:06 -04:00
|
|
|
equals(function() {
|
|
|
|
return path.selected;
|
|
|
|
}, false);
|
|
|
|
equals(function() {
|
|
|
|
return path2.selected;
|
2011-05-15 13:13:55 -04:00
|
|
|
}, false);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('Check parent children object for named item', function() {
|
|
|
|
var path = new Path();
|
|
|
|
path.name = 'test';
|
|
|
|
equals(function() {
|
2011-05-16 08:33:15 -04:00
|
|
|
return paper.project.activeLayer.children['test'] == path;
|
2011-05-15 13:13:55 -04:00
|
|
|
}, true);
|
2011-07-07 10:09:02 -04:00
|
|
|
|
2011-05-15 13:13:55 -04:00
|
|
|
var path2 = new Path();
|
|
|
|
path2.name = 'test';
|
2011-07-07 10:09:02 -04:00
|
|
|
|
2011-05-15 13:13:55 -04:00
|
|
|
equals(function() {
|
2011-05-16 08:33:15 -04:00
|
|
|
return paper.project.activeLayer.children['test'] == path2;
|
2011-05-15 13:13:55 -04:00
|
|
|
}, true);
|
2011-07-07 10:09:02 -04:00
|
|
|
|
2011-05-15 13:13:55 -04:00
|
|
|
path2.remove();
|
2011-07-07 10:09:02 -04:00
|
|
|
|
2011-05-15 13:13:55 -04:00
|
|
|
equals(function() {
|
2011-05-16 08:33:15 -04:00
|
|
|
return paper.project.activeLayer.children['test'] == path;
|
2011-05-15 13:13:55 -04:00
|
|
|
}, true);
|
2011-07-07 10:09:02 -04:00
|
|
|
|
2011-05-15 13:13:55 -04:00
|
|
|
path.remove();
|
2011-07-07 10:09:02 -04:00
|
|
|
|
2011-05-15 13:13:55 -04:00
|
|
|
equals(function() {
|
2011-05-16 08:33:15 -04:00
|
|
|
return !paper.project.activeLayer.children['test'];
|
2011-05-15 13:13:55 -04:00
|
|
|
}, true);
|
|
|
|
});
|
|
|
|
|
2011-06-17 11:33:25 -04:00
|
|
|
test('Named child access 1', function() {
|
2011-05-15 13:13:55 -04:00
|
|
|
var path = new Path();
|
|
|
|
path.name = 'test';
|
|
|
|
|
|
|
|
var path2 = new Path();
|
|
|
|
path2.name = 'test';
|
2011-07-07 10:09:02 -04:00
|
|
|
|
2011-05-15 13:13:55 -04:00
|
|
|
path.remove();
|
2011-07-07 10:09:02 -04:00
|
|
|
|
2011-05-15 13:13:55 -04:00
|
|
|
equals(function() {
|
2011-05-16 08:33:15 -04:00
|
|
|
return paper.project.activeLayer.children['test'] == path2;
|
2011-05-15 13:13:55 -04:00
|
|
|
}, true);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('Named child access 2', function() {
|
|
|
|
var path = new Path();
|
|
|
|
path.name = 'test';
|
|
|
|
|
|
|
|
var path2 = new Path();
|
|
|
|
path2.name = 'test';
|
2011-07-07 10:09:02 -04:00
|
|
|
|
2011-05-15 13:13:55 -04:00
|
|
|
path.remove();
|
2011-07-07 10:09:02 -04:00
|
|
|
|
2011-05-15 13:13:55 -04:00
|
|
|
equals(function() {
|
2011-05-16 08:33:15 -04:00
|
|
|
return paper.project.activeLayer.children['test'] == path2;
|
2011-05-15 13:13:55 -04:00
|
|
|
}, true);
|
2011-07-07 10:09:02 -04:00
|
|
|
|
2011-05-15 13:13:55 -04:00
|
|
|
equals(function() {
|
2011-05-16 08:33:15 -04:00
|
|
|
return paper.project.activeLayer._namedChildren['test'].length == 1;
|
2011-05-15 13:13:55 -04:00
|
|
|
}, true);
|
2011-07-07 10:09:02 -04:00
|
|
|
|
2011-05-15 13:13:55 -04:00
|
|
|
path2.remove();
|
|
|
|
|
|
|
|
equals(function() {
|
2011-05-16 08:33:15 -04:00
|
|
|
return !paper.project.activeLayer._namedChildren['test'];
|
2011-05-15 13:13:55 -04:00
|
|
|
}, true);
|
2011-07-07 10:09:02 -04:00
|
|
|
|
2011-05-15 13:13:55 -04:00
|
|
|
equals(function() {
|
2011-05-16 08:33:15 -04:00
|
|
|
return paper.project.activeLayer.children['test'] === undefined;
|
2011-05-15 13:13:55 -04:00
|
|
|
}, true);
|
|
|
|
});
|
|
|
|
|
2011-06-17 11:33:25 -04:00
|
|
|
test('Named child access 3', function() {
|
2011-05-15 13:13:55 -04:00
|
|
|
var path = new Path();
|
|
|
|
path.name = 'test';
|
|
|
|
|
|
|
|
var path2 = new Path();
|
|
|
|
path2.name = 'test';
|
2011-07-07 10:09:02 -04:00
|
|
|
|
2011-05-15 13:13:55 -04:00
|
|
|
var group = new Group();
|
2011-07-07 10:09:02 -04:00
|
|
|
|
2011-06-17 10:58:22 -04:00
|
|
|
group.addChild(path2);
|
2011-07-07 10:09:02 -04:00
|
|
|
|
2011-05-15 13:13:55 -04:00
|
|
|
equals(function() {
|
2011-05-16 08:33:15 -04:00
|
|
|
return paper.project.activeLayer.children['test'] == path;
|
2011-05-15 13:13:55 -04:00
|
|
|
}, true);
|
2011-06-17 11:33:25 -04:00
|
|
|
|
|
|
|
// TODO: Tests should not access internal properties
|
2011-05-15 13:13:55 -04:00
|
|
|
equals(function() {
|
2011-06-17 11:33:25 -04:00
|
|
|
return paper.project.activeLayer._namedChildren['test'].length;
|
|
|
|
}, 1);
|
2011-05-15 13:13:55 -04:00
|
|
|
|
|
|
|
equals(function() {
|
|
|
|
return group.children['test'] == path2;
|
|
|
|
}, true);
|
2011-06-17 11:33:25 -04:00
|
|
|
|
2011-05-15 13:13:55 -04:00
|
|
|
equals(function() {
|
|
|
|
return group._namedChildren['test'].length == 1;
|
|
|
|
}, true);
|
2011-06-17 11:33:25 -04:00
|
|
|
|
|
|
|
equals(function() {
|
|
|
|
return paper.project.activeLayer._namedChildren['test'][0] == path;
|
|
|
|
}, true);
|
|
|
|
|
2011-05-16 08:33:15 -04:00
|
|
|
paper.project.activeLayer.appendTop(path2);
|
2011-05-15 13:13:55 -04:00
|
|
|
|
2011-06-17 11:33:25 -04:00
|
|
|
equals(function() {
|
|
|
|
return group.children['test'] == null;
|
|
|
|
}, true);
|
|
|
|
|
2011-05-15 13:13:55 -04:00
|
|
|
equals(function() {
|
|
|
|
return group._namedChildren['test'] === undefined;
|
|
|
|
}, true);
|
2011-06-17 11:33:25 -04:00
|
|
|
|
2011-05-15 13:13:55 -04:00
|
|
|
equals(function() {
|
2011-06-17 11:33:25 -04:00
|
|
|
return paper.project.activeLayer.children['test'] == path2;
|
2011-05-15 13:13:55 -04:00
|
|
|
}, true);
|
2011-06-17 11:33:25 -04:00
|
|
|
|
|
|
|
equals(function() {
|
|
|
|
return paper.project.activeLayer._namedChildren['test'].length;
|
|
|
|
}, 2);
|
2011-05-15 13:13:55 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
test('Setting name of child back to null', function() {
|
|
|
|
var path = new Path();
|
|
|
|
path.name = 'test';
|
2011-05-15 13:53:22 -04:00
|
|
|
|
2011-05-15 13:13:55 -04:00
|
|
|
var path2 = new Path();
|
|
|
|
path2.name = 'test';
|
2011-05-15 13:53:22 -04:00
|
|
|
|
|
|
|
equals(function() {
|
2011-05-16 08:33:15 -04:00
|
|
|
return paper.project.activeLayer.children['test'] == path2;
|
2011-05-15 13:53:22 -04:00
|
|
|
}, true);
|
|
|
|
|
2011-05-15 13:13:55 -04:00
|
|
|
path2.name = null;
|
|
|
|
|
|
|
|
equals(function() {
|
2011-05-16 08:33:15 -04:00
|
|
|
return paper.project.activeLayer.children['test'] == path;
|
2011-05-15 13:13:55 -04:00
|
|
|
}, true);
|
2011-07-07 10:09:02 -04:00
|
|
|
|
2011-05-15 13:13:55 -04:00
|
|
|
path.name = null;
|
2011-07-07 10:09:02 -04:00
|
|
|
|
2011-05-15 13:13:55 -04:00
|
|
|
equals(function() {
|
2011-05-16 08:33:15 -04:00
|
|
|
return paper.project.activeLayer.children['test'] === undefined;
|
2011-05-15 13:13:55 -04:00
|
|
|
}, true);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('Renaming item', function() {
|
|
|
|
var path = new Path();
|
|
|
|
path.name = 'test';
|
2011-07-07 10:09:02 -04:00
|
|
|
|
2011-05-15 13:13:55 -04:00
|
|
|
path.name = 'test2';
|
2011-07-07 10:09:02 -04:00
|
|
|
|
2011-05-15 13:13:55 -04:00
|
|
|
equals(function() {
|
2011-05-16 08:33:15 -04:00
|
|
|
return paper.project.activeLayer.children['test'] === undefined;
|
2011-05-15 13:13:55 -04:00
|
|
|
}, true);
|
2011-07-07 10:09:02 -04:00
|
|
|
|
2011-05-15 13:13:55 -04:00
|
|
|
equals(function() {
|
2011-05-16 08:33:15 -04:00
|
|
|
return paper.project.activeLayer.children['test2'] == path;
|
2011-05-15 13:13:55 -04:00
|
|
|
}, true);
|
|
|
|
});
|
2011-05-30 19:46:49 -04:00
|
|
|
|
|
|
|
test('Changing item#position.x', function() {
|
|
|
|
var path = new Path.Circle(new Point(50, 50), 50);
|
|
|
|
path.position.x += 5;
|
|
|
|
equals(path.position.toString(), '{ x: 55, y: 50 }', 'path.position.x += 5');
|
2011-06-21 12:42:53 -04:00
|
|
|
});
|
|
|
|
|
2012-03-01 10:39:00 -05:00
|
|
|
test('Naming a removed item', function() {
|
|
|
|
var path = new Path();
|
|
|
|
path.remove();
|
|
|
|
path.name = 'test';
|
|
|
|
});
|
|
|
|
|
|
|
|
test('Naming a layer', function() {
|
|
|
|
var layer = new Layer();
|
|
|
|
layer.name = 'test';
|
|
|
|
});
|
|
|
|
|
2011-06-21 12:42:53 -04:00
|
|
|
test('Cloning a linked size', function() {
|
|
|
|
var path = new Path([40, 75], [140, 75]);
|
|
|
|
var error = null;
|
|
|
|
try {
|
|
|
|
var cloneSize = path.bounds.size.clone();
|
|
|
|
} catch (e) {
|
|
|
|
error = e;
|
|
|
|
}
|
|
|
|
var description = 'Cloning a linked size should not throw an error';
|
|
|
|
if (error)
|
|
|
|
description += ': ' + error;
|
|
|
|
equals(error == null, true, description);
|
2013-03-03 08:40:37 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
test('Item#type', function() {
|
2013-03-03 17:22:31 -05:00
|
|
|
equals(new Group().type, 'Group');
|
|
|
|
equals(new Path().type, 'Path');
|
|
|
|
equals(new CompoundPath().type, 'CompoundPath');
|
2013-03-03 14:14:13 -05:00
|
|
|
|
|
|
|
var canvas = document.createElement('canvas');
|
2013-03-03 17:22:31 -05:00
|
|
|
equals(new Raster(canvas).type, 'Raster');
|
|
|
|
equals(new PlacedSymbol().type, 'PlacedSymbol');
|
|
|
|
equals(new PointText().type, 'PointText');
|
2013-03-03 08:40:37 -05:00
|
|
|
});
|
2013-03-03 10:59:27 -05:00
|
|
|
|
|
|
|
test('Item#isInserted', function() {
|
|
|
|
var item = new Path();
|
|
|
|
equals(item.isInserted(), true);
|
|
|
|
item.remove();
|
|
|
|
equals(item.isInserted(), false);
|
|
|
|
|
|
|
|
var group = new Group(item);
|
|
|
|
equals(item.isInserted(), true);
|
|
|
|
group.remove();
|
|
|
|
equals(item.isInserted(), false);
|
|
|
|
});
|