UNPKG

@neo4j-nvl/layout-workers

Version:

Layout workers for the Neo4j Visualization Library

37 lines (36 loc) 2.02 kB
import { layout } from './dagre-layout-impl.js'; describe('Dagre-layout-impl', () => { test('is defined', () => { expect(layout).toBeDefined(); }); test('the waypoints are defined by the first relationship', () => { const nodes = [ { id: '1', color: '#000000', caption: 'Thing1', pinned: false, activated: false, selected: false }, { id: '2', color: '#000000', caption: 'Thing2', pinned: false, activated: false, selected: false }, { id: '3', color: '#000000', caption: 'Thing3', pinned: false, activated: false, selected: false } ]; const nodeIds = { 1: { id: '1', color: '#000000', caption: 'Thing1', pinned: false, activated: false, selected: false }, 2: { id: '2', color: '#000000', caption: 'Thing2', pinned: false, activated: false, selected: false }, 3: { id: '3', color: '#000000', caption: 'Thing3', pinned: false, activated: false, selected: false } }; const rels = [ { id: '1000', from: '1', to: '2', type: 'CONNECTED_TO', properties: {} }, { id: '1002', from: '2', to: '3', type: 'CONNECTED_TO', properties: {} }, { id: '1004', from: '1', to: '3', type: 'CONNECTED_TO', properties: {} }, { id: '1005', from: '3', to: '1', type: 'CONNECTED_TO', properties: {} } ]; const idToPosition = { 1: { id: '1' }, 2: { id: '2' }, 3: { id: '3' } }; const result = layout(nodes, nodeIds, idToPosition, rels, 'right', 2); expect(result).toBeDefined(); expect(result.positions).toBeDefined(); expect(result.parents).toBeDefined(); expect(result.waypoints).toBeDefined(); expect(result.waypoints['1-3']).toBeDefined(); const wpObject = result.waypoints['1-3']; const xs = [wpObject.from.x, ...wpObject.points.map((p) => p.x), wpObject.to.x]; for (let i = 1; i < xs.length; i++) { expect(xs[i]).toBeGreaterThan(xs[i - 1]); } }); });