fix(router): route.parent should work for secondary children
This commit is contained in:
parent
afcb3c0035
commit
5a99393355
|
@ -71,7 +71,7 @@ function findPath<T>(expected: T, c: TreeNode<T>, collected: TreeNode<T>[]): Tre
|
||||||
for (let cc of c.children) {
|
for (let cc of c.children) {
|
||||||
const cloned = collected.slice(0);
|
const cloned = collected.slice(0);
|
||||||
const r = findPath(expected, cc, cloned);
|
const r = findPath(expected, cc, cloned);
|
||||||
if (r) return r;
|
if (r.length > 0) return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
return [];
|
return [];
|
||||||
|
|
|
@ -20,6 +20,13 @@ describe('tree', () => {
|
||||||
expect(t.parent(2)).toEqual(1);
|
expect(t.parent(2)).toEqual(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should return the parent of a node (second child)', () => {
|
||||||
|
const t = new Tree<any>(
|
||||||
|
new TreeNode<number>(1, [new TreeNode<number>(2, []), new TreeNode<number>(3, [])]));
|
||||||
|
expect(t.parent(1)).toEqual(null);
|
||||||
|
expect(t.parent(3)).toEqual(1);
|
||||||
|
});
|
||||||
|
|
||||||
it('should return the children of a node', () => {
|
it('should return the children of a node', () => {
|
||||||
const t = new Tree<any>(new TreeNode<number>(1, [new TreeNode<number>(2, [])]));
|
const t = new Tree<any>(new TreeNode<number>(1, [new TreeNode<number>(2, [])]));
|
||||||
expect(t.children(1)).toEqual([2]);
|
expect(t.children(1)).toEqual([2]);
|
||||||
|
|
Loading…
Reference in New Issue