feat: add hasChildren method to RoutesService

pull/4546/head
Arman Ozak 6 years ago
parent 135e8200a9
commit 58b2cae823

@ -151,6 +151,11 @@ export abstract class AbstractNavTreeService<T extends ABP.Nav> extends Abstract
return this.store.selectSnapshot(ConfigState.getGrantedPolicy(requiredPolicy));
}
hasChildren(identifier: string): boolean {
const node = this.find(item => item[this.id] === identifier);
return Boolean(node?.children?.length);
}
hasInvisibleChild(identifier: string): boolean {
const node = this.find(item => item[this.id] === identifier);
return node?.children?.some(child => child.invisible);

@ -68,6 +68,16 @@ describe('Routes Service', () => {
});
});
describe('#hasChildren', () => {
it('should return if node has invisible child', () => {
service.add(routes);
expect(service.hasChildren('foo')).toBe(true);
expect(service.hasChildren('bar')).toBe(true);
expect(service.hasChildren('baz')).toBe(false);
});
});
describe('#hasInvisibleChild', () => {
it('should return if node has invisible child', () => {
service.add(routes);

Loading…
Cancel
Save