blob: 767e094463af20a9048a25ae3a415a9c47433dbb [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';
19
20export class TestNode extends Node {
21 constructor(id: string) {
22 super(id);
23 }
24}
25
26export class TestLink extends Link {
27 constructor(source: Node, target: Node) {
28 super(source, target);
29 }
30}
31
32/**
33 * ONOS GUI -- ForceDirectedGraph - Unit Tests
34 */
35describe('ForceDirectedGraph', () => {
36 let fdg: ForceDirectedGraph;
37 const options: Options = {width: 1000, height: 1000};
38
39 beforeEach(() => {
40 const nodes: Node[] = [];
41 const links: Link[] = [];
42 fdg = new ForceDirectedGraph(options);
43
44 for (let i = 0; i < 10; i++) {
45 const newNode: TestNode = new TestNode('id' + i);
46 nodes.push(newNode);
47 }
48 for (let j = 1; j < 10; j++) {
49 const newLink = new TestLink(nodes[0], nodes[j]);
50 links.push(newLink);
51 }
52 fdg.nodes = nodes;
53 fdg.links = links;
54 fdg.initSimulation(options);
55 fdg.initNodes();
56
57 });
58
59 afterEach(() => {
60 fdg.stopSimulation();
61 fdg.nodes = [];
62 fdg.links = [];
63 fdg.initSimulation(options);
64 });
65
66 it('should be created', () => {
67 expect(fdg).toBeTruthy();
68 });
69
70 it('should have simulation', () => {
71 expect(fdg.simulation).toBeTruthy();
72 });
73
74 it('should have 10 nodes', () => {
75 expect(fdg.nodes.length).toEqual(10);
76 });
77
78 it('should have 10 links', () => {
79 expect(fdg.links.length).toEqual(9);
80 });
81
82 // TODO fix these up to listen for tick
83 // it('nodes should not be at zero', () => {
84 // expect(nodes[0].x).toBeGreaterThan(0);
85 // });
86 // it('ticker should emit', () => {
87 // let tickMe = jasmine.createSpy("tickMe() spy");
88 // fdg.ticker.subscribe((simulation) => tickMe());
89 // expect(tickMe).toHaveBeenCalled();
90 // });
91
92 // it('init links chould be called ', () => {
93 // spyOn(fdg, 'initLinks');
94 // // expect(fdg).toBeTruthy();
95 // fdg.initSimulation(options);
96 // expect(fdg.initLinks).toHaveBeenCalled();
97 // });
98
99 it ('throws error on no options', () => {
100 expect(fdg.initSimulation).toThrowError('missing options when initializing simulation');
101 });
102
103
104
105});