lik/test/test.tree.both.ts

41 lines
1.2 KiB
TypeScript
Raw Permalink Normal View History

2024-04-18 19:55:33 +00:00
import { tap, expect } from '@push.rocks/tapbundle';
2022-05-27 15:53:02 +00:00
import * as lik from '../ts/index.js';
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();
2022-01-24 04:22:49 +00:00
expect(testTree).toBeInstanceOf(lik.Tree);
2018-07-15 14:04:27 +00:00
});
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, {});
2022-05-27 15:53:02 +00:00
expect(resultArray).toContain(testInstance);
2018-07-15 14:04:27 +00:00
});
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);
});
2024-04-18 19:55:33 +00:00
export default tap.start();