import { ComponentFixture, TestBed } from '@angular/core/testing'; import { Node, Link } from '@creedinteractive/onguard-models'; import { NetworkGraphComponent } from './network-graph.component'; import { NetworkModule } from './network-graph.module'; import { NetworkGraph } from './network-graph.model'; describe('NetworkGraphComponent', () => { let component: NetworkGraphComponent; let fixture: ComponentFixture; beforeEach(async () => { await TestBed.configureTestingModule({ imports: [NetworkModule], }).compileComponents(); }); beforeEach(() => { fixture = TestBed.createComponent(NetworkGraphComponent); component = fixture.componentInstance; component.links = primaryLinks; component.nodes = primaryNodes; component.networkGraphModel = new NetworkGraph(primaryNodes, primaryLinks); fixture.detectChanges(); }); it('should create', () => { expect(component).toBeTruthy(); }); }); const checkExists = (links: Link[], testLink: Link): boolean => { const filtered = links.filter((l) => { if ( (l.source === testLink.source && l.target === testLink.target) || (l.target === testLink.source && l.source === testLink.target) ) { return true; } return false; }); return filtered?.length > 0; }; const getNodes = (n: number, name = 'Node ', codec = 'G.711MU,G.729'): Node[] => { const nodes: Node[] = []; for (let i = 0; i < n; i++) { // @ts-ignore nodes.push(new Node(i, name + i, codec)); } return nodes; }; const linkNodes = (nodes: Node[], connectionCount = 1): Link[] => { const links: Link[] = []; for (let i = 0; i < nodes.length - 1; i++) { nodes[i].linkCount++; for (let j = 0; j < connectionCount; j++) { const linkedNode = Math.floor(Math.random() * (nodes.length - 1)); nodes[linkedNode].linkCount++; const potentialLink = new Link(i, linkedNode); if (!checkExists(links, potentialLink)) { links.push(potentialLink); } } } return links; }; const primaryNodes = getNodes(100); const primaryLinks = linkNodes(primaryNodes, 1);