blob: 29dab54937379feee715d8d7f592800bb03d773f [file] [log] [blame]
Sean Condonf4f54a12018-10-10 23:25:46 +01001/*
Sean Condonb2c483c2019-01-16 20:28:55 +00002 * Copyright 2019-present Open Networking Foundation
Sean Condonf4f54a12018-10-10 23:25:46 +01003 *
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 { async, ComponentFixture, TestBed } from '@angular/core/testing';
17import { ActivatedRoute, Params } from '@angular/router';
18import { of } from 'rxjs';
19import { HttpClient } from '@angular/common/http';
20import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
Sean Condon0d064ec2019-02-04 21:53:53 +000021import * as d3 from 'd3';
Sean Condonf4f54a12018-10-10 23:25:46 +010022import { TopologyComponent } from './topology.component';
Sean Condonaa4366d2018-11-02 14:29:01 +000023import {
24 Instance,
25 InstanceComponent
26} from '../panel/instance/instance.component';
Sean Condonf4f54a12018-10-10 23:25:46 +010027import { SummaryComponent } from '../panel/summary/summary.component';
28import { ToolbarComponent } from '../panel/toolbar/toolbar.component';
29import { DetailsComponent } from '../panel/details/details.component';
Sean Condonaa4366d2018-11-02 14:29:01 +000030import { TopologyService } from '../topology.service';
Sean Condonf4f54a12018-10-10 23:25:46 +010031
32import {
33 FlashComponent,
Sean Condonb2c483c2019-01-16 20:28:55 +000034 QuickhelpComponent,
Sean Condonf4f54a12018-10-10 23:25:46 +010035 FnService,
Sean Condon91481822019-01-01 13:56:14 +000036 LogService,
Sean Condonb2c483c2019-01-16 20:28:55 +000037 IconService, IconComponent, PrefsService, KeysService, LionService
Sean Condonf4f54a12018-10-10 23:25:46 +010038} from 'gui2-fw-lib';
Sean Condon0c577f62018-11-18 22:40:05 +000039import {ZoomableDirective} from '../layer/zoomable.directive';
Sean Condon91481822019-01-01 13:56:14 +000040import {RouterTestingModule} from '@angular/router/testing';
Sean Condonb2c483c2019-01-16 20:28:55 +000041import {TrafficService} from '../traffic.service';
42import {ForceSvgComponent} from '../layer/forcesvg/forcesvg.component';
Sean Condonb2c483c2019-01-16 20:28:55 +000043import {DraggableDirective} from '../layer/forcesvg/draggable/draggable.directive';
Sean Condon0d064ec2019-02-04 21:53:53 +000044import {MapSelectorComponent} from '../panel/mapselector/mapselector.component';
45import {BackgroundSvgComponent} from '../layer/backgroundsvg/backgroundsvg.component';
46import {FormsModule, ReactiveFormsModule} from '@angular/forms';
47import {MapSvgComponent} from '../layer/mapsvg/mapsvg.component';
Sean Condon71910542019-02-16 18:16:42 +000048import {GridsvgComponent} from '../layer/gridsvg/gridsvg.component';
Sean Condonff85fbe2019-03-16 14:28:46 +000049import {LinkSvgComponent} from '../layer/forcesvg/visuals/linksvg/linksvg.component';
50import {DeviceNodeSvgComponent} from '../layer/forcesvg/visuals/devicenodesvg/devicenodesvg.component';
51import {SubRegionNodeSvgComponent} from '../layer/forcesvg/visuals/subregionnodesvg/subregionnodesvg.component';
52import {HostNodeSvgComponent} from '../layer/forcesvg/visuals/hostnodesvg/hostnodesvg.component';
Sean Condon28884332019-03-21 14:07:00 +000053import {LayoutService} from '../layout.service';
Sean Condonf4f54a12018-10-10 23:25:46 +010054
55
56class MockActivatedRoute extends ActivatedRoute {
57 constructor(params: Params) {
58 super();
59 this.queryParams = of(params);
60 }
61}
62
63class MockHttpClient {}
64
Sean Condonaa4366d2018-11-02 14:29:01 +000065class MockTopologyService {
66 init(instance: InstanceComponent) {
67 instance.onosInstances = [
68 <Instance>{
69 'id': 'inst1',
70 'ip': '127.0.0.1',
71 'reachable': true,
72 'online': true,
73 'ready': true,
74 'switches': 4,
75 'uiAttached': true
76 },
77 <Instance>{
78 'id': 'inst1',
79 'ip': '127.0.0.2',
80 'reachable': true,
81 'online': true,
82 'ready': true,
83 'switches': 3,
84 'uiAttached': false
85 }
86 ];
87 }
88 destroy() {}
89}
90
Sean Condon91481822019-01-01 13:56:14 +000091class MockIconService {
92 loadIconDef() { }
93}
94
Sean Condonb2c483c2019-01-16 20:28:55 +000095class MockKeysService {
96 quickHelpShown: boolean = true;
97
Sean Condonbed2e032019-04-17 22:22:49 +010098 keyHandler: {
99 viewKeys: any[],
100 globalKeys: any[]
101 };
102
103 mockViewKeys: Object[];
104 constructor() {
105 this.mockViewKeys = [];
106 this.keyHandler = {
107 viewKeys: this.mockViewKeys,
108 globalKeys: this.mockViewKeys
109 };
110 }
111
Sean Condonb2c483c2019-01-16 20:28:55 +0000112 keyBindings(x) {
113 return {};
114 }
115
116 gestureNotes() {
117 return {};
118 }
119}
120
Sean Condon19e83672019-04-13 16:21:52 +0100121class MockTrafficService {
122 init(force: ForceSvgComponent) {}
Sean Condonc13d9562019-04-18 13:24:42 +0100123 destroy() {}
Sean Condon19e83672019-04-13 16:21:52 +0100124}
Sean Condonb2c483c2019-01-16 20:28:55 +0000125
Sean Condon28884332019-03-21 14:07:00 +0000126class MockLayoutService {}
127
Sean Condonb2c483c2019-01-16 20:28:55 +0000128class MockPrefsService {
129 listeners: ((data) => void)[] = [];
130
131 getPrefs() {
132 return { 'topo2_prefs': ''};
133 }
134
135 addListener(listener: (data) => void): void {
136 this.listeners.push(listener);
137 }
138
139 removeListener(listener: (data) => void) {
140 this.listeners = this.listeners.filter((obj) => obj !== listener);
141 }
142
Sean Condon71910542019-02-16 18:16:42 +0000143 setPrefs(name: string, obj: Object) {
144
145 }
146
Sean Condonb2c483c2019-01-16 20:28:55 +0000147}
148
Sean Condonf4f54a12018-10-10 23:25:46 +0100149/**
150 * ONOS GUI -- Topology View -- Unit Tests
151 */
Sean Condon0a884ad2019-10-28 17:57:21 +0000152// Skipping temporarily
Sean Condonf4f54a12018-10-10 23:25:46 +0100153describe('TopologyComponent', () => {
154 let fs: FnService;
155 let ar: MockActivatedRoute;
156 let windowMock: Window;
157 let logServiceSpy: jasmine.SpyObj<LogService>;
158 let component: TopologyComponent;
159 let fixture: ComponentFixture<TopologyComponent>;
160
Sean Condonb2c483c2019-01-16 20:28:55 +0000161 const bundleObj = {
162 'core.fw.QuickHelp': {
163 test: 'test1',
164 tt_help: 'Help!'
165 }
166 };
167 const mockLion = (key) => {
168 return bundleObj[key] || '%' + key + '%';
169 };
170
Sean Condon64060ff2019-05-30 15:48:11 +0100171 beforeEach(() => {
Sean Condonf4f54a12018-10-10 23:25:46 +0100172 const logSpy = jasmine.createSpyObj('LogService', ['info', 'debug', 'warn', 'error']);
173 ar = new MockActivatedRoute({ 'debug': 'txrx' });
174
175 windowMock = <any>{
176 location: <any>{
177 hostname: 'foo',
178 host: 'foo',
179 port: '80',
180 protocol: 'http',
181 search: { debug: 'true' },
182 href: 'ws://foo:123/onos/ui/websock/path',
183 absUrl: 'ws://foo:123/onos/ui/websock/path'
184 }
185 };
186 fs = new FnService(ar, logSpy, windowMock);
187
188 TestBed.configureTestingModule({
Sean Condon0d064ec2019-02-04 21:53:53 +0000189 imports: [
190 BrowserAnimationsModule,
191 RouterTestingModule,
192 FormsModule,
193 ReactiveFormsModule
194 ],
Sean Condonf4f54a12018-10-10 23:25:46 +0100195 declarations: [
196 TopologyComponent,
197 InstanceComponent,
198 SummaryComponent,
199 ToolbarComponent,
200 DetailsComponent,
Sean Condon0c577f62018-11-18 22:40:05 +0000201 FlashComponent,
Sean Condon91481822019-01-01 13:56:14 +0000202 ZoomableDirective,
Sean Condonb2c483c2019-01-16 20:28:55 +0000203 IconComponent,
204 QuickhelpComponent,
205 ForceSvgComponent,
206 LinkSvgComponent,
207 DeviceNodeSvgComponent,
208 HostNodeSvgComponent,
209 DraggableDirective,
210 ZoomableDirective,
Sean Condon0d064ec2019-02-04 21:53:53 +0000211 SubRegionNodeSvgComponent,
212 MapSelectorComponent,
213 BackgroundSvgComponent,
Sean Condon71910542019-02-16 18:16:42 +0000214 MapSvgComponent,
215 GridsvgComponent
Sean Condonf4f54a12018-10-10 23:25:46 +0100216 ],
217 providers: [
218 { provide: FnService, useValue: fs },
219 { provide: LogService, useValue: logSpy },
220 { provide: 'Window', useValue: windowMock },
221 { provide: HttpClient, useClass: MockHttpClient },
Sean Condon0c577f62018-11-18 22:40:05 +0000222 { provide: TopologyService, useClass: MockTopologyService },
Sean Condonb2c483c2019-01-16 20:28:55 +0000223 { provide: TrafficService, useClass: MockTrafficService },
Sean Condon28884332019-03-21 14:07:00 +0000224 { provide: LayoutService, useClass: MockLayoutService },
Sean Condon91481822019-01-01 13:56:14 +0000225 { provide: IconService, useClass: MockIconService },
Sean Condonb2c483c2019-01-16 20:28:55 +0000226 { provide: PrefsService, useClass: MockPrefsService },
227 { provide: KeysService, useClass: MockKeysService },
228 { provide: LionService, useFactory: (() => {
229 return {
230 bundle: ((bundleId) => mockLion),
231 ubercache: new Array(),
232 loadCbs: new Map<string, () => void>([])
233 };
234 })
235 },
Sean Condonf4f54a12018-10-10 23:25:46 +0100236 ]
237 }).compileComponents();
238 logServiceSpy = TestBed.get(LogService);
Sean Condon64060ff2019-05-30 15:48:11 +0100239 });
Sean Condonf4f54a12018-10-10 23:25:46 +0100240
241 beforeEach(() => {
242 fixture = TestBed.createComponent(TopologyComponent);
243 component = fixture.componentInstance;
Sean Condon0d064ec2019-02-04 21:53:53 +0000244
Sean Condonf4f54a12018-10-10 23:25:46 +0100245 fixture.detectChanges();
246 });
247
248 it('should create', () => {
249 expect(component).toBeTruthy();
250 });
251});