import { buildParentLookup } from './parent-lookup' describe('parent-lookup', () => { describe('buildParentLookup', () => { let result: ReturnType beforeEach(() => { result = buildParentLookup({ ids: ['1', '2', '3'], entities: new Map([ ['1', { id: '1' }], ['2', { id: '2' }], ['3', { id: '3' }], ['11', { id: '11' }], ['12', { id: '12' }], ['121', { id: '121' }], ['122', { id: '122' }], ['21', { id: '21' }], ['22', { id: '22' }], ]), meta: new Map([ ['1', { type: 'tree', children: ['11', '12'] }], ['2', { type: 'tree', children: ['21', '22'] }], ['12', { type: 'tree', children: ['121', '122'] }], ]), }) }) it('should provide the parent lookup', () => { expect(result.parentLookup.get('122')).toEqual('12') expect(result.parentLookup.get('2')).toBeUndefined() }) it('should return all parents for a item', () => { expect(result.getAllParents('122')).toEqual(['12', '1']) }) it('should return an empty array for a null id', () => { expect(result.getAllParents(null)).toEqual([]) }) it('should return an empty array for root level items', () => { expect(result.getAllParents('2')).toEqual([]) }) }) })