Sean Condon | 0c577f6 | 2018-11-18 22:40:05 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2018-present Open Networking Foundation |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the 'License'); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an 'AS IS' BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | import {ForceDirectedGraph, Options} from './force-directed-graph'; |
| 17 | import {Node} from './node'; |
| 18 | import {Link} from './link'; |
Sean Condon | a3ad779 | 2020-01-04 19:26:34 +0000 | [diff] [blame] | 19 | import {LogService} from 'gui2-fw-lib/public_api'; |
Sean Condon | 50855cf | 2018-12-23 15:37:42 +0000 | [diff] [blame] | 20 | import {TestBed} from '@angular/core/testing'; |
Sean Condon | 0c577f6 | 2018-11-18 22:40:05 +0000 | [diff] [blame] | 21 | |
| 22 | export class TestNode extends Node { |
| 23 | constructor(id: string) { |
| 24 | super(id); |
| 25 | } |
| 26 | } |
| 27 | |
| 28 | export class TestLink extends Link { |
| 29 | constructor(source: Node, target: Node) { |
| 30 | super(source, target); |
| 31 | } |
| 32 | } |
| 33 | |
| 34 | /** |
| 35 | * ONOS GUI -- ForceDirectedGraph - Unit Tests |
| 36 | */ |
| 37 | describe('ForceDirectedGraph', () => { |
Sean Condon | 50855cf | 2018-12-23 15:37:42 +0000 | [diff] [blame] | 38 | let logServiceSpy: jasmine.SpyObj<LogService>; |
Sean Condon | 0c577f6 | 2018-11-18 22:40:05 +0000 | [diff] [blame] | 39 | let fdg: ForceDirectedGraph; |
| 40 | const options: Options = {width: 1000, height: 1000}; |
| 41 | |
| 42 | beforeEach(() => { |
Sean Condon | 50855cf | 2018-12-23 15:37:42 +0000 | [diff] [blame] | 43 | const logSpy = jasmine.createSpyObj('LogService', ['info', 'debug', 'warn', 'error']); |
Sean Condon | 0c577f6 | 2018-11-18 22:40:05 +0000 | [diff] [blame] | 44 | const nodes: Node[] = []; |
| 45 | const links: Link[] = []; |
Sean Condon | 50855cf | 2018-12-23 15:37:42 +0000 | [diff] [blame] | 46 | fdg = new ForceDirectedGraph(options, logSpy); |
Sean Condon | 0c577f6 | 2018-11-18 22:40:05 +0000 | [diff] [blame] | 47 | |
| 48 | for (let i = 0; i < 10; i++) { |
| 49 | const newNode: TestNode = new TestNode('id' + i); |
| 50 | nodes.push(newNode); |
| 51 | } |
| 52 | for (let j = 1; j < 10; j++) { |
| 53 | const newLink = new TestLink(nodes[0], nodes[j]); |
| 54 | links.push(newLink); |
| 55 | } |
| 56 | fdg.nodes = nodes; |
| 57 | fdg.links = links; |
Sean Condon | 2888433 | 2019-03-21 14:07:00 +0000 | [diff] [blame] | 58 | fdg.reinitSimulation(); |
Sean Condon | 50855cf | 2018-12-23 15:37:42 +0000 | [diff] [blame] | 59 | logServiceSpy = TestBed.get(LogService); |
Sean Condon | 0c577f6 | 2018-11-18 22:40:05 +0000 | [diff] [blame] | 60 | }); |
| 61 | |
| 62 | afterEach(() => { |
| 63 | fdg.stopSimulation(); |
| 64 | fdg.nodes = []; |
| 65 | fdg.links = []; |
Sean Condon | 2888433 | 2019-03-21 14:07:00 +0000 | [diff] [blame] | 66 | fdg.reinitSimulation(); |
Sean Condon | 0c577f6 | 2018-11-18 22:40:05 +0000 | [diff] [blame] | 67 | }); |
| 68 | |
| 69 | it('should be created', () => { |
| 70 | expect(fdg).toBeTruthy(); |
| 71 | }); |
| 72 | |
| 73 | it('should have simulation', () => { |
| 74 | expect(fdg.simulation).toBeTruthy(); |
| 75 | }); |
| 76 | |
| 77 | it('should have 10 nodes', () => { |
| 78 | expect(fdg.nodes.length).toEqual(10); |
| 79 | }); |
| 80 | |
| 81 | it('should have 10 links', () => { |
| 82 | expect(fdg.links.length).toEqual(9); |
| 83 | }); |
| 84 | |
| 85 | // TODO fix these up to listen for tick |
| 86 | // it('nodes should not be at zero', () => { |
| 87 | // expect(nodes[0].x).toBeGreaterThan(0); |
| 88 | // }); |
| 89 | // it('ticker should emit', () => { |
| 90 | // let tickMe = jasmine.createSpy("tickMe() spy"); |
| 91 | // fdg.ticker.subscribe((simulation) => tickMe()); |
| 92 | // expect(tickMe).toHaveBeenCalled(); |
| 93 | // }); |
| 94 | |
| 95 | // it('init links chould be called ', () => { |
| 96 | // spyOn(fdg, 'initLinks'); |
| 97 | // // expect(fdg).toBeTruthy(); |
Sean Condon | 2888433 | 2019-03-21 14:07:00 +0000 | [diff] [blame] | 98 | // fdg.reinitSimulation(options); |
Sean Condon | 0c577f6 | 2018-11-18 22:40:05 +0000 | [diff] [blame] | 99 | // expect(fdg.initLinks).toHaveBeenCalled(); |
| 100 | // }); |
Sean Condon | 0c577f6 | 2018-11-18 22:40:05 +0000 | [diff] [blame] | 101 | }); |