Implement Item#isParent and add tests for it.

This commit is contained in:
Jonathan Puckey 2011-04-11 19:42:03 +02:00
parent 594c11fedd
commit d02885cba7
2 changed files with 7 additions and 5 deletions

View file

@ -309,10 +309,9 @@ var Item = this.Item = Base.extend({
*/
// TODO: isBelow
// TODO: this is confusing the beans
// isParent: function(item) {
// return this.parent == item;
// },
isParent: function(item) {
return this.parent == item;
},
isChild: function(item) {
return item.parent == this;

View file

@ -35,7 +35,7 @@ test('appendChild(item)', function() {
equals(doc.activeLayer.children.length, 1);
});
test('item.parent / item.isChild', function() {
test('item.parent / item.isChild / item.isParent', function() {
var doc = new Document();
var secondDoc = new Document();
var path = new Path();
@ -43,7 +43,10 @@ test('item.parent / item.isChild', function() {
equals(doc.activeLayer.children.indexOf(path) != -1, true);
secondDoc.activeLayer.appendTop(path);
equals(doc.activeLayer.isChild(path), false);
equals(path.isParent(doc.activeLayer), false);
equals(secondDoc.activeLayer.isChild(path), true);
equals(path.isParent(secondDoc.activeLayer), true);
equals(doc.activeLayer.children.indexOf(path) == -1, true);
equals(secondDoc.activeLayer.children.indexOf(path) == 0, true);
});