66 lines
1.4 KiB
JavaScript
66 lines
1.4 KiB
JavaScript
|
var Tree = require('../src/util/tree');
|
||
|
|
||
|
var TreeSuite = module.exports = {};
|
||
|
|
||
|
TreeSuite.getPropertyByPath = function(test) {
|
||
|
var tree = new Tree(this.treeState);
|
||
|
var label = tree.get(['items', 1, 'label']);
|
||
|
test.ok(label === 'root.child2', 'The property value should be "root.child2" !');
|
||
|
test.done();
|
||
|
};
|
||
|
|
||
|
TreeSuite.updatePropertyByPath = function(test) {
|
||
|
var tree = new Tree(this.treeState);
|
||
|
var path = ['items', 1, 'label'];
|
||
|
tree.update(path, {$set: 'foo'});
|
||
|
var label = tree.get(path);
|
||
|
test.ok(label === 'foo', 'The property value should be "foo" !');
|
||
|
test.done();
|
||
|
};
|
||
|
|
||
|
TreeSuite.findItem = function(test) {
|
||
|
var tree = new Tree(this.treeState);
|
||
|
var result = tree.find(this.treeItem);
|
||
|
test.ok(result.path.join('.') === 'items.1.items.0.items.0', 'The result should have a path equal to "items.1.items.0.items.0" !');
|
||
|
test.done();
|
||
|
};
|
||
|
|
||
|
TreeSuite.setUp = function(done) {
|
||
|
|
||
|
this.treeItem = {
|
||
|
label: "root.child2.child1.child1",
|
||
|
items: []
|
||
|
};
|
||
|
|
||
|
this.treeState = {
|
||
|
label: "root",
|
||
|
items: [
|
||
|
{
|
||
|
label: "root.child1",
|
||
|
items: [
|
||
|
{
|
||
|
label: "root.child1.child1",
|
||
|
items: [
|
||
|
|
||
|
]
|
||
|
}
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
label: "root.child2",
|
||
|
items: [
|
||
|
{
|
||
|
label: "root.child2.child1",
|
||
|
items: [
|
||
|
this.treeItem
|
||
|
]
|
||
|
}
|
||
|
]
|
||
|
}
|
||
|
]
|
||
|
};
|
||
|
|
||
|
done();
|
||
|
|
||
|
};
|