blob: 76630cc5f014164e45c88d3e4486bb933c99e7aa [file] [log] [blame]
Sean Condon0c577f62018-11-18 22:40:05 +00001/*
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 */
16import {ForceDirectedGraph, Options} from './force-directed-graph';
17import {Node} from './node';
18import {Link} from './link';
Sean Condon3dd062f2020-04-14 09:25:00 +010019import {LogService} from 'org_onosproject_onos/web/gui2-fw-lib/public_api';
Sean Condon50855cf2018-12-23 15:37:42 +000020import {TestBed} from '@angular/core/testing';
Sean Condon0c577f62018-11-18 22:40:05 +000021
22export class TestNode extends Node {
23 constructor(id: string) {
24 super(id);
25 }
26}
27
28export 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 */
37describe('ForceDirectedGraph', () => {
Sean Condon50855cf2018-12-23 15:37:42 +000038 let logServiceSpy: jasmine.SpyObj<LogService>;
Sean Condon0c577f62018-11-18 22:40:05 +000039 let fdg: ForceDirectedGraph;
40 const options: Options = {width: 1000, height: 1000};
41
42 beforeEach(() => {
Sean Condon50855cf2018-12-23 15:37:42 +000043 const logSpy = jasmine.createSpyObj('LogService', ['info', 'debug', 'warn', 'error']);
Sean Condon0c577f62018-11-18 22:40:05 +000044 const nodes: Node[] = [];
45 const links: Link[] = [];
Sean Condon50855cf2018-12-23 15:37:42 +000046 fdg = new ForceDirectedGraph(options, logSpy);
Sean Condon0c577f62018-11-18 22:40:05 +000047
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 Condon28884332019-03-21 14:07:00 +000058 fdg.reinitSimulation();
Sean Condon50855cf2018-12-23 15:37:42 +000059 logServiceSpy = TestBed.get(LogService);
Sean Condon0c577f62018-11-18 22:40:05 +000060 });
61
62 afterEach(() => {
63 fdg.stopSimulation();
64 fdg.nodes = [];
65 fdg.links = [];
Sean Condon28884332019-03-21 14:07:00 +000066 fdg.reinitSimulation();
Sean Condon0c577f62018-11-18 22:40:05 +000067 });
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 Condon28884332019-03-21 14:07:00 +000098 // fdg.reinitSimulation(options);
Sean Condon0c577f62018-11-18 22:40:05 +000099 // expect(fdg.initLinks).toHaveBeenCalled();
100 // });
Sean Condon0c577f62018-11-18 22:40:05 +0000101});