2011-02-11 12:50:26 -05:00
|
|
|
module('Item');
|
|
|
|
|
2011-02-12 11:43:51 -05:00
|
|
|
test('copyTo(document)', function() {
|
2011-05-14 13:59:04 -04:00
|
|
|
var doc = paper.document;
|
2011-02-12 11:43:51 -05:00
|
|
|
var path = new Path();
|
2011-03-03 12:23:27 -05:00
|
|
|
var secondDoc = new Document();
|
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() {
|
|
|
|
return doc.activeLayer.children.indexOf(copy) == -1;
|
|
|
|
}, true);
|
|
|
|
equals(function() {
|
|
|
|
return copy != path;
|
|
|
|
}, true);
|
2011-02-12 11:43:51 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
test('copyTo(layer)', function() {
|
2011-05-14 13:59:04 -04:00
|
|
|
var doc = paper.document;
|
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() {
|
|
|
|
return doc.layers[0].children.indexOf(copy) == -1;
|
|
|
|
}, true);
|
2011-02-12 11:43:51 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
test('clone()', function() {
|
2011-05-14 13:59:04 -04:00
|
|
|
var doc = paper.document;
|
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-14 13:59:04 -04:00
|
|
|
return doc.activeLayer.children.length;
|
|
|
|
}, 2);
|
2011-05-07 12:46:06 -04:00
|
|
|
equals(function() {
|
|
|
|
return path != copy;
|
|
|
|
}, true);
|
2011-02-12 11:43:51 -05:00
|
|
|
});
|
|
|
|
|
2011-02-11 12:50:26 -05:00
|
|
|
test('appendChild(item)', function() {
|
2011-05-14 13:59:04 -04:00
|
|
|
var doc = paper.document;
|
2011-02-11 12:50:26 -05:00
|
|
|
var path = new Path();
|
2011-02-12 10:20:10 -05:00
|
|
|
doc.activeLayer.appendChild(path);
|
2011-05-07 12:46:06 -04:00
|
|
|
equals(function() {
|
|
|
|
return doc.activeLayer.children.length;
|
|
|
|
}, 1);
|
2011-02-11 12:50:26 -05:00
|
|
|
});
|
|
|
|
|
2011-04-11 13:42:03 -04:00
|
|
|
test('item.parent / item.isChild / item.isParent', function() {
|
2011-05-14 13:59:04 -04:00
|
|
|
var doc = paper.document;
|
2011-03-03 12:23:27 -05:00
|
|
|
var secondDoc = new Document();
|
2011-02-11 12:50:26 -05:00
|
|
|
var path = new Path();
|
|
|
|
doc.activeLayer.appendChild(path);
|
2011-05-07 12:46:06 -04:00
|
|
|
equals(function() {
|
|
|
|
return doc.activeLayer.children.indexOf(path) != -1;
|
|
|
|
}, true);
|
2011-02-11 12:50:26 -05:00
|
|
|
secondDoc.activeLayer.appendTop(path);
|
2011-05-07 12:46:06 -04:00
|
|
|
equals(function() {
|
|
|
|
return doc.activeLayer.isChild(path);
|
|
|
|
}, false);
|
|
|
|
equals(function() {
|
|
|
|
return path.isParent(doc.activeLayer);
|
|
|
|
}, false);
|
|
|
|
equals(function() {
|
|
|
|
return secondDoc.activeLayer.isChild(path);
|
|
|
|
}, true);
|
|
|
|
equals(function() {
|
|
|
|
return path.isParent(secondDoc.activeLayer);
|
|
|
|
}, true);
|
|
|
|
equals(function() {
|
|
|
|
return doc.activeLayer.children.indexOf(path) == -1;
|
|
|
|
}, 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-14 13:59:04 -04:00
|
|
|
var doc = paper.document;
|
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() {
|
|
|
|
return doc.activeLayer.firstChild == path;
|
|
|
|
}, true);
|
|
|
|
equals(function() {
|
|
|
|
return doc.activeLayer.lastChild == secondPath;
|
|
|
|
}, true);
|
2011-02-11 12:50:26 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
test('appendBottom(item)', function() {
|
2011-05-14 13:59:04 -04:00
|
|
|
var doc = paper.document;
|
2011-02-11 12:50:26 -05:00
|
|
|
var path = new Path();
|
|
|
|
var secondPath = new Path();
|
|
|
|
doc.activeLayer.appendBottom(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
|
|
|
});
|
|
|
|
|
|
|
|
test('moveAbove(item)', function() {
|
2011-05-14 13:59:04 -04:00
|
|
|
var doc = paper.document;
|
2011-02-11 12:50:26 -05:00
|
|
|
var path = new Path();
|
|
|
|
var secondPath = new Path();
|
|
|
|
path.moveAbove(secondPath);
|
2011-05-07 12:46:06 -04:00
|
|
|
equals(function() {
|
|
|
|
return doc.activeLayer.lastChild == path;
|
|
|
|
}, true);
|
2011-02-11 12:50:26 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
test('moveBelow(item)', function() {
|
2011-05-14 13:59:04 -04:00
|
|
|
var doc = paper.document;
|
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-02-11 12:50:26 -05:00
|
|
|
secondPath.moveBelow(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
|
|
|
});
|
|
|
|
|
2011-02-12 10:41:57 -05:00
|
|
|
test('isDescendant(item) / isAncestor(item)', function() {
|
2011-05-14 13:59:04 -04:00
|
|
|
var doc = paper.document;
|
2011-02-11 12:50:26 -05:00
|
|
|
var path = new Path();
|
2011-05-07 12:46:06 -04:00
|
|
|
equals(function() {
|
|
|
|
return path.isDescendant(doc.activeLayer);
|
|
|
|
}, true);
|
|
|
|
equals(function() {
|
|
|
|
return doc.activeLayer.isDescendant(path);
|
|
|
|
}, false);
|
|
|
|
equals(function() {
|
|
|
|
return path.isAncestor(doc.activeLayer);
|
|
|
|
}, false);
|
|
|
|
equals(function() {
|
|
|
|
return doc.activeLayer.isAncestor(path);
|
|
|
|
}, true);
|
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() {
|
|
|
|
return doc.activeLayer.isDescendant(doc.activeLayer);
|
|
|
|
}, 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() {
|
|
|
|
return doc.activeLayer.isAncestor(doc.activeLayer);
|
|
|
|
}, false);
|
2011-02-24 12:09:48 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
test('isGroupedWith', function() {
|
2011-05-14 13:59:04 -04:00
|
|
|
var doc = paper.document;
|
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-05-07 12:46:06 -04:00
|
|
|
equals(function() {
|
|
|
|
return path.isGroupedWith(secondPath);
|
|
|
|
}, false);
|
2011-02-24 12:09:48 -05:00
|
|
|
secondGroup.appendTop(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-03-03 11:21:17 -05:00
|
|
|
paper.document.activeLayer.appendTop(path);
|
2011-05-07 12:46:06 -04:00
|
|
|
equals(function() {
|
|
|
|
return path.isGroupedWith(secondPath);
|
|
|
|
}, false);
|
2011-03-03 11:21:17 -05:00
|
|
|
paper.document.activeLayer.appendTop(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-14 13:59:04 -04:00
|
|
|
var doc = paper.document;
|
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() {
|
|
|
|
return doc.activeLayer.firstChild == path;
|
|
|
|
}, true);
|
2011-02-24 13:31:07 -05:00
|
|
|
doc.activeLayer.reverseChildren();
|
2011-05-07 12:46:06 -04:00
|
|
|
equals(function() {
|
|
|
|
return doc.activeLayer.firstChild == path;
|
|
|
|
}, false);
|
|
|
|
equals(function() {
|
|
|
|
return doc.activeLayer.firstChild == thirdPath;
|
|
|
|
}, true);
|
|
|
|
equals(function() {
|
|
|
|
return doc.activeLayer.lastChild == path;
|
|
|
|
}, true);
|
2011-04-21 09:57:19 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
test('Check item#document when moving items across documents', function() {
|
2011-05-14 13:59:04 -04:00
|
|
|
var doc = paper.document;
|
2011-04-21 09:57:19 -04:00
|
|
|
var doc1 = new Document();
|
|
|
|
var path = new Path();
|
|
|
|
var group = new Group();
|
|
|
|
group.appendTop(new Path());
|
|
|
|
|
2011-05-07 12:46:06 -04:00
|
|
|
equals(function() {
|
|
|
|
return path.document == doc1;
|
|
|
|
}, true);
|
2011-04-21 09:57:19 -04:00
|
|
|
var doc2 = new Document();
|
|
|
|
doc2.activeLayer.appendTop(path);
|
2011-05-07 12:46:06 -04:00
|
|
|
equals(function() {
|
|
|
|
return path.document == doc2;
|
|
|
|
}, true);
|
2011-04-21 09:57:19 -04:00
|
|
|
|
|
|
|
doc2.activeLayer.appendTop(group);
|
2011-05-07 12:46:06 -04:00
|
|
|
equals(function() {
|
|
|
|
return group.children[0].document == doc2;
|
|
|
|
}, 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-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-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-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;
|
|
|
|
}, false);});
|