2018-07-15 14:04:27 +00:00
|
|
|
import { tap, expect } from '@pushrocks/tapbundle';
|
|
|
|
import * as lik from '../ts/index';
|
2017-11-20 08:26:13 +00:00
|
|
|
|
|
|
|
class TestClass {
|
2018-07-15 14:04:27 +00:00
|
|
|
constructor(public hey: string) {
|
2017-11-20 08:26:13 +00:00
|
|
|
// nothing here
|
|
|
|
}
|
|
|
|
}
|
2018-08-31 15:24:35 +00:00
|
|
|
|
|
|
|
let testTree = new lik.Tree<TestClass>();
|
|
|
|
|
2018-07-15 14:04:27 +00:00
|
|
|
let testInstance = new TestClass('first');
|
2018-08-31 15:24:35 +00:00
|
|
|
let testInstance2 = new TestClass('second');
|
|
|
|
let testInstance3 = new TestClass('third');
|
|
|
|
let testInstance4 = new TestClass('fourth');
|
|
|
|
let testInstance5 = new TestClass('fifth');
|
|
|
|
let testInstance6 = new TestClass('sixth');
|
2017-11-20 08:26:13 +00:00
|
|
|
|
|
|
|
tap.test('create a valid tree instance', async () => {
|
2018-07-15 14:04:27 +00:00
|
|
|
testTree = new lik.Tree();
|
|
|
|
expect(testTree).to.be.instanceOf(lik.Tree);
|
|
|
|
});
|
2017-11-20 08:26:13 +00:00
|
|
|
|
|
|
|
tap.test('should insert an object', async () => {
|
2018-07-15 14:04:27 +00:00
|
|
|
testTree.initialize(testInstance);
|
|
|
|
let resultArray = testTree.treeToArray(testInstance, {});
|
|
|
|
expect(resultArray).to.contain(testInstance);
|
|
|
|
});
|
2017-11-20 08:26:13 +00:00
|
|
|
|
2018-08-31 15:24:35 +00:00
|
|
|
tap.test('should add other objects in a hierachy', async () => {
|
|
|
|
testTree.appendChild(testInstance, testInstance2);
|
|
|
|
testTree.appendChild(testInstance, testInstance3);
|
|
|
|
testTree.appendChild(testInstance, testInstance4);
|
2018-11-23 19:33:44 +00:00
|
|
|
});
|
2018-08-31 15:24:35 +00:00
|
|
|
|
2018-11-23 19:33:44 +00:00
|
|
|
tap.test("should create a JSON object that reflects a tree's hierachy", async () => {
|
2018-08-31 15:24:35 +00:00
|
|
|
const jsonTreet = testTree.toJsonWithHierachy(testInstance);
|
|
|
|
});
|
|
|
|
|
2018-07-15 14:04:27 +00:00
|
|
|
tap.start();
|