lik/test/test.tree.both.ts

41 lines
1.2 KiB
TypeScript
Raw Normal View History

2024-04-18 21:55:33 +02:00
import { tap, expect } from '@push.rocks/tapbundle';
2022-05-27 17:53:02 +02:00
import * as lik from '../ts/index.js';
2017-11-20 09:26:13 +01:00
class TestClass {
2018-07-15 16:04:27 +02:00
constructor(public hey: string) {
2017-11-20 09:26:13 +01:00
// nothing here
}
}
2018-08-31 17:24:35 +02:00
let testTree = new lik.Tree<TestClass>();
2018-07-15 16:04:27 +02:00
let testInstance = new TestClass('first');
2018-08-31 17:24:35 +02: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 09:26:13 +01:00
tap.test('create a valid tree instance', async () => {
2018-07-15 16:04:27 +02:00
testTree = new lik.Tree();
2022-01-24 05:22:49 +01:00
expect(testTree).toBeInstanceOf(lik.Tree);
2018-07-15 16:04:27 +02:00
});
2017-11-20 09:26:13 +01:00
tap.test('should insert an object', async () => {
2018-07-15 16:04:27 +02:00
testTree.initialize(testInstance);
let resultArray = testTree.treeToArray(testInstance, {});
2022-05-27 17:53:02 +02:00
expect(resultArray).toContain(testInstance);
2018-07-15 16:04:27 +02:00
});
2017-11-20 09:26:13 +01:00
2018-08-31 17:24:35 +02: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 20:33:44 +01:00
});
2018-08-31 17:24:35 +02:00
2018-11-23 20:33:44 +01:00
tap.test("should create a JSON object that reflects a tree's hierachy", async () => {
2018-08-31 17:24:35 +02:00
const jsonTreet = testTree.toJsonWithHierachy(testInstance);
});
2024-04-18 21:55:33 +02:00
export default tap.start();