blob: 15c2bd13a46920a6d7ed48476707effb880ce5b9 [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 Condon4e55c802019-12-03 22:13:34 +000030import {Intent, 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 Condon590b34b2019-12-04 18:44:37 +000054import {BadgeSvgComponent} from '../layer/forcesvg/visuals/badgesvg/badgesvg.component';
Sean Condonf4f54a12018-10-10 23:25:46 +010055
56
57class MockActivatedRoute extends ActivatedRoute {
58 constructor(params: Params) {
59 super();
60 this.queryParams = of(params);
61 }
62}
63
64class MockHttpClient {}
65
Sean Condonaa4366d2018-11-02 14:29:01 +000066class MockTopologyService {
67 init(instance: InstanceComponent) {
68 instance.onosInstances = [
69 <Instance>{
70 'id': 'inst1',
71 'ip': '127.0.0.1',
72 'reachable': true,
73 'online': true,
74 'ready': true,
75 'switches': 4,
76 'uiAttached': true
77 },
78 <Instance>{
79 'id': 'inst1',
80 'ip': '127.0.0.2',
81 'reachable': true,
82 'online': true,
83 'ready': true,
84 'switches': 3,
85 'uiAttached': false
86 }
87 ];
88 }
89 destroy() {}
Sean Condon4e55c802019-12-03 22:13:34 +000090 setSelectedIntent(selectedIntent: Intent): void {}
91 selectRelatedIntent(ids: string[]): void {}
92 cancelHighlights(): void {}
Sean Condonaa4366d2018-11-02 14:29:01 +000093}
94
Sean Condon91481822019-01-01 13:56:14 +000095class MockIconService {
96 loadIconDef() { }
97}
98
Sean Condonb2c483c2019-01-16 20:28:55 +000099class MockKeysService {
100 quickHelpShown: boolean = true;
101
Sean Condonbed2e032019-04-17 22:22:49 +0100102 keyHandler: {
103 viewKeys: any[],
104 globalKeys: any[]
105 };
106
107 mockViewKeys: Object[];
108 constructor() {
109 this.mockViewKeys = [];
110 this.keyHandler = {
111 viewKeys: this.mockViewKeys,
112 globalKeys: this.mockViewKeys
113 };
114 }
115
Sean Condonb2c483c2019-01-16 20:28:55 +0000116 keyBindings(x) {
117 return {};
118 }
119
120 gestureNotes() {
121 return {};
122 }
123}
124
Sean Condon19e83672019-04-13 16:21:52 +0100125class MockTrafficService {
126 init(force: ForceSvgComponent) {}
Sean Condonc13d9562019-04-18 13:24:42 +0100127 destroy() {}
Sean Condon19e83672019-04-13 16:21:52 +0100128}
Sean Condonb2c483c2019-01-16 20:28:55 +0000129
Sean Condon28884332019-03-21 14:07:00 +0000130class MockLayoutService {}
131
Sean Condonb2c483c2019-01-16 20:28:55 +0000132class MockPrefsService {
133 listeners: ((data) => void)[] = [];
134
135 getPrefs() {
136 return { 'topo2_prefs': ''};
137 }
138
139 addListener(listener: (data) => void): void {
140 this.listeners.push(listener);
141 }
142
143 removeListener(listener: (data) => void) {
144 this.listeners = this.listeners.filter((obj) => obj !== listener);
145 }
146
Sean Condon71910542019-02-16 18:16:42 +0000147 setPrefs(name: string, obj: Object) {
148
149 }
150
Sean Condonb2c483c2019-01-16 20:28:55 +0000151}
152
Sean Condonf4f54a12018-10-10 23:25:46 +0100153/**
154 * ONOS GUI -- Topology View -- Unit Tests
155 */
Sean Condon0a884ad2019-10-28 17:57:21 +0000156// Skipping temporarily
Sean Condonf4f54a12018-10-10 23:25:46 +0100157describe('TopologyComponent', () => {
158 let fs: FnService;
159 let ar: MockActivatedRoute;
160 let windowMock: Window;
161 let logServiceSpy: jasmine.SpyObj<LogService>;
162 let component: TopologyComponent;
163 let fixture: ComponentFixture<TopologyComponent>;
164
Sean Condonb2c483c2019-01-16 20:28:55 +0000165 const bundleObj = {
166 'core.fw.QuickHelp': {
167 test: 'test1',
168 tt_help: 'Help!'
169 }
170 };
171 const mockLion = (key) => {
172 return bundleObj[key] || '%' + key + '%';
173 };
174
Sean Condon64060ff2019-05-30 15:48:11 +0100175 beforeEach(() => {
Sean Condonf4f54a12018-10-10 23:25:46 +0100176 const logSpy = jasmine.createSpyObj('LogService', ['info', 'debug', 'warn', 'error']);
177 ar = new MockActivatedRoute({ 'debug': 'txrx' });
178
179 windowMock = <any>{
180 location: <any>{
181 hostname: 'foo',
182 host: 'foo',
183 port: '80',
184 protocol: 'http',
185 search: { debug: 'true' },
186 href: 'ws://foo:123/onos/ui/websock/path',
187 absUrl: 'ws://foo:123/onos/ui/websock/path'
188 }
189 };
190 fs = new FnService(ar, logSpy, windowMock);
191
192 TestBed.configureTestingModule({
Sean Condon0d064ec2019-02-04 21:53:53 +0000193 imports: [
194 BrowserAnimationsModule,
195 RouterTestingModule,
196 FormsModule,
197 ReactiveFormsModule
198 ],
Sean Condonf4f54a12018-10-10 23:25:46 +0100199 declarations: [
200 TopologyComponent,
201 InstanceComponent,
202 SummaryComponent,
203 ToolbarComponent,
204 DetailsComponent,
Sean Condon0c577f62018-11-18 22:40:05 +0000205 FlashComponent,
Sean Condon91481822019-01-01 13:56:14 +0000206 ZoomableDirective,
Sean Condonb2c483c2019-01-16 20:28:55 +0000207 IconComponent,
208 QuickhelpComponent,
209 ForceSvgComponent,
210 LinkSvgComponent,
211 DeviceNodeSvgComponent,
212 HostNodeSvgComponent,
213 DraggableDirective,
214 ZoomableDirective,
Sean Condon0d064ec2019-02-04 21:53:53 +0000215 SubRegionNodeSvgComponent,
216 MapSelectorComponent,
217 BackgroundSvgComponent,
Sean Condon71910542019-02-16 18:16:42 +0000218 MapSvgComponent,
Sean Condon590b34b2019-12-04 18:44:37 +0000219 GridsvgComponent,
220 BadgeSvgComponent
Sean Condonf4f54a12018-10-10 23:25:46 +0100221 ],
222 providers: [
223 { provide: FnService, useValue: fs },
224 { provide: LogService, useValue: logSpy },
225 { provide: 'Window', useValue: windowMock },
226 { provide: HttpClient, useClass: MockHttpClient },
Sean Condon0c577f62018-11-18 22:40:05 +0000227 { provide: TopologyService, useClass: MockTopologyService },
Sean Condonb2c483c2019-01-16 20:28:55 +0000228 { provide: TrafficService, useClass: MockTrafficService },
Sean Condon28884332019-03-21 14:07:00 +0000229 { provide: LayoutService, useClass: MockLayoutService },
Sean Condon91481822019-01-01 13:56:14 +0000230 { provide: IconService, useClass: MockIconService },
Sean Condonb2c483c2019-01-16 20:28:55 +0000231 { provide: PrefsService, useClass: MockPrefsService },
232 { provide: KeysService, useClass: MockKeysService },
233 { provide: LionService, useFactory: (() => {
234 return {
235 bundle: ((bundleId) => mockLion),
236 ubercache: new Array(),
237 loadCbs: new Map<string, () => void>([])
238 };
239 })
240 },
Sean Condonf4f54a12018-10-10 23:25:46 +0100241 ]
242 }).compileComponents();
243 logServiceSpy = TestBed.get(LogService);
Sean Condon64060ff2019-05-30 15:48:11 +0100244 });
Sean Condonf4f54a12018-10-10 23:25:46 +0100245
246 beforeEach(() => {
247 fixture = TestBed.createComponent(TopologyComponent);
248 component = fixture.componentInstance;
Sean Condon0d064ec2019-02-04 21:53:53 +0000249
Sean Condonf4f54a12018-10-10 23:25:46 +0100250 fixture.detectChanges();
251 });
252
253 it('should create', () => {
254 expect(component).toBeTruthy();
255 });
256});