Implement additional unit tests for dealing with sibling items with the same name.

This commit is contained in:
Jürg Lehni 2016-01-08 16:41:33 +01:00
parent 74c1f54bb3
commit c064cb6c43

View file

@ -130,7 +130,7 @@ test('item.parent / item.isChild / item.isParent / item.layer', function() {
return project.activeLayer.children.indexOf(path) == -1; return project.activeLayer.children.indexOf(path) == -1;
}, true); }, true);
equals(function() { equals(function() {
return secondDoc.activeLayer.children.indexOf(path) == 0; return secondDoc.activeLayer.children.indexOf(path) === 0;
}, true); }, true);
}); });
@ -245,7 +245,7 @@ test('item.sendToBack()', function() {
var secondPath = new Path(); var secondPath = new Path();
secondPath.sendToBack(); secondPath.sendToBack();
equals(function() { equals(function() {
return secondPath.index == 0; return secondPath.index === 0;
}, true); }, true);
}); });
@ -428,161 +428,144 @@ test('group.selected', function() {
}); });
test('Check parent children object for named item', function() { test('Check parent children object for named item', function() {
var path = new Path(); var path1 = new Path({ name: 'test' });
path.name = 'test'; var layer = paper.project.activeLayer;
equals(function() { equals(function() {
return paper.project.activeLayer.children['test'] == path; return layer.children['test'] === path1;
}, true); }, true);
var path2 = new Path(); var path2 = new Path({ name: 'test' });
path2.name = 'test';
equals(function() { equals(function() {
return paper.project.activeLayer.children['test'] == path2; return layer.children['test'] === path1;
}, true); }, true);
path2.remove(); path2.remove();
equals(function() { equals(function() {
return paper.project.activeLayer.children['test'] == path; return layer.children['test'] === path1;
}, true); }, true);
path.remove(); path1.remove();
equals(function() { equals(function() {
return !paper.project.activeLayer.children['test']; return !layer.children['test'];
}, true); }, true);
}); });
test('Named child access 1', function() { test('Named child access 1', function() {
var path = new Path(); var path1 = new Path({ name: 'test' });
path.name = 'test'; var path2 = new Path({ name: 'test' });
var layer = paper.project.activeLayer;
var path2 = new Path();
path2.name = 'test';
path.remove();
equals(function() { equals(function() {
return paper.project.activeLayer.children['test'] == path2; return layer.children['test'] === path1;
}, true);
});
test('Named child access 2', function() {
var path = new Path();
path.name = 'test';
var path2 = new Path();
path2.name = 'test';
path.remove();
equals(function() {
return paper.project.activeLayer.children['test'] == path2;
}, true); }, true);
path1.remove();
equals(function() { equals(function() {
return paper.project.activeLayer._namedChildren['test'].length == 1; return layer.children['test'] === path2;
}, true); }, true);
path2.remove(); path2.remove();
equals(function() { equals(function() {
return !paper.project.activeLayer._namedChildren['test']; return layer.children['test'] === undefined;
}, true);
equals(function() {
return paper.project.activeLayer.children['test'] === undefined;
}, true); }, true);
}); });
test('Named child access 3', function() { test('Named child access 2', function() {
var path = new Path(); var path1 = new Path({ name: 'test' });
path.name = 'test'; var path2 = new Path({ name: 'test' });
var layer = paper.project.activeLayer;
var path2 = new Path();
path2.name = 'test';
var group = new Group(); var group = new Group();
group.addChild(path2); group.addChild(path2);
equals(function() { equals(function() {
return paper.project.activeLayer.children['test'] == path; return layer.children['test'] === path1;
}, true); }, true);
// TODO: Tests should not access internal properties path1.remove();
equals(function() {
return paper.project.activeLayer._namedChildren['test'].length;
}, 1);
equals(function() { equals(function() {
return group.children['test'] == path2; return layer.children['test'] === undefined;
}, true); }, true);
equals(function() { equals(function() {
return group._namedChildren['test'].length == 1; return group.children['test'] === path2;
}, true);
path2.remove();
equals(function() {
return group.children['test'] === undefined;
}, true);
group.addChild(path2);
equals(function() {
return group.children['test'] === path2;
}, true);
layer.appendTop(path2);
equals(function() {
return group.children['test'] === undefined;
}, true); }, true);
equals(function() { equals(function() {
return paper.project.activeLayer._namedChildren['test'][0] == path; return layer.children['test'] === path2;
}, true); }, true);
paper.project.activeLayer.appendTop(path2); layer.addChild(path1);
equals(function() { equals(function() {
return group.children['test'] == null; return layer.children['test'] === path2;
}, true); }, true);
equals(function() { path2.remove();
return group._namedChildren['test'] === undefined;
}, true);
equals(function() { equals(function() {
return paper.project.activeLayer.children['test'] == path2; return layer.children['test'] === path1;
}, true); }, true);
equals(function() {
return paper.project.activeLayer._namedChildren['test'].length;
}, 2);
}); });
test('Setting name of child back to null', function() { test('Setting name of child back to null', function() {
var path = new Path(); var path1 = new Path({ name: 'test' });
path.name = 'test'; var path2 = new Path({ name: 'test' });
var layer = paper.project.activeLayer;
var path2 = new Path();
path2.name = 'test';
equals(function() { equals(function() {
return paper.project.activeLayer.children['test'] == path2; return layer.children['test'] == path1;
}, true);
path1.name = null;
equals(function() {
return layer.children['test'] == path2;
}, true); }, true);
path2.name = null; path2.name = null;
equals(function() { equals(function() {
return paper.project.activeLayer.children['test'] == path; return layer.children['test'] === undefined;
}, true);
path.name = null;
equals(function() {
return paper.project.activeLayer.children['test'] === undefined;
}, true); }, true);
}); });
test('Renaming item', function() { test('Renaming item', function() {
var path = new Path(); var path = new Path({ name: 'test' });
path.name = 'test';
path.name = 'test2'; path.name = 'test2';
var layer = paper.project.activeLayer;
equals(function() { equals(function() {
return paper.project.activeLayer.children['test'] === undefined; return layer.children['test'] === undefined;
}, true); }, true);
equals(function() { equals(function() {
return paper.project.activeLayer.children['test2'] == path; return layer.children['test2'] == path;
}, true); }, true);
}); });
@ -662,7 +645,7 @@ test('Item#data', function() {
var item = new Path(); var item = new Path();
item.data = { item.data = {
testing: true testing: true
} };
equals(item.data.testing, true, 'we can set data using an object literal'); equals(item.data.testing, true, 'we can set data using an object literal');
var item = new Path({ var item = new Path({