blob: af96483d9cfb377e3dd6ca58d9158169c8373b46 [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 Condon98b6ddb2019-12-24 08:07:40 +000037 IconService, IconComponent, PrefsService, KeysService, LionService, ZoomableDirective
Sean Condona3ad7792020-01-04 19:26:34 +000038} from 'gui2-fw-lib/public_api';
Sean Condon91481822019-01-01 13:56:14 +000039import {RouterTestingModule} from '@angular/router/testing';
Sean Condonb2c483c2019-01-16 20:28:55 +000040import {TrafficService} from '../traffic.service';
41import {ForceSvgComponent} from '../layer/forcesvg/forcesvg.component';
Sean Condonb2c483c2019-01-16 20:28:55 +000042import {DraggableDirective} from '../layer/forcesvg/draggable/draggable.directive';
Sean Condon0d064ec2019-02-04 21:53:53 +000043import {MapSelectorComponent} from '../panel/mapselector/mapselector.component';
44import {BackgroundSvgComponent} from '../layer/backgroundsvg/backgroundsvg.component';
45import {FormsModule, ReactiveFormsModule} from '@angular/forms';
46import {MapSvgComponent} from '../layer/mapsvg/mapsvg.component';
Sean Condon71910542019-02-16 18:16:42 +000047import {GridsvgComponent} from '../layer/gridsvg/gridsvg.component';
Sean Condonff85fbe2019-03-16 14:28:46 +000048import {LinkSvgComponent} from '../layer/forcesvg/visuals/linksvg/linksvg.component';
49import {DeviceNodeSvgComponent} from '../layer/forcesvg/visuals/devicenodesvg/devicenodesvg.component';
50import {SubRegionNodeSvgComponent} from '../layer/forcesvg/visuals/subregionnodesvg/subregionnodesvg.component';
51import {HostNodeSvgComponent} from '../layer/forcesvg/visuals/hostnodesvg/hostnodesvg.component';
Sean Condon28884332019-03-21 14:07:00 +000052import {LayoutService} from '../layout.service';
Sean Condon590b34b2019-12-04 18:44:37 +000053import {BadgeSvgComponent} from '../layer/forcesvg/visuals/badgesvg/badgesvg.component';
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() {}
Sean Condon4e55c802019-12-03 22:13:34 +000089 setSelectedIntent(selectedIntent: Intent): void {}
90 selectRelatedIntent(ids: string[]): void {}
91 cancelHighlights(): void {}
Sean Condonaa4366d2018-11-02 14:29:01 +000092}
93
Sean Condon91481822019-01-01 13:56:14 +000094class MockIconService {
95 loadIconDef() { }
96}
97
Sean Condonb2c483c2019-01-16 20:28:55 +000098class MockKeysService {
99 quickHelpShown: boolean = true;
100
Sean Condonbed2e032019-04-17 22:22:49 +0100101 keyHandler: {
102 viewKeys: any[],
103 globalKeys: any[]
104 };
105
106 mockViewKeys: Object[];
107 constructor() {
108 this.mockViewKeys = [];
109 this.keyHandler = {
110 viewKeys: this.mockViewKeys,
111 globalKeys: this.mockViewKeys
112 };
113 }
114
Sean Condonb2c483c2019-01-16 20:28:55 +0000115 keyBindings(x) {
116 return {};
117 }
118
119 gestureNotes() {
120 return {};
121 }
122}
123
Sean Condon19e83672019-04-13 16:21:52 +0100124class MockTrafficService {
125 init(force: ForceSvgComponent) {}
Sean Condonc13d9562019-04-18 13:24:42 +0100126 destroy() {}
Sean Condon19e83672019-04-13 16:21:52 +0100127}
Sean Condonb2c483c2019-01-16 20:28:55 +0000128
Sean Condon28884332019-03-21 14:07:00 +0000129class MockLayoutService {}
130
Sean Condonb2c483c2019-01-16 20:28:55 +0000131class MockPrefsService {
132 listeners: ((data) => void)[] = [];
133
134 getPrefs() {
135 return { 'topo2_prefs': ''};
136 }
137
138 addListener(listener: (data) => void): void {
139 this.listeners.push(listener);
140 }
141
142 removeListener(listener: (data) => void) {
143 this.listeners = this.listeners.filter((obj) => obj !== listener);
144 }
145
Sean Condon71910542019-02-16 18:16:42 +0000146 setPrefs(name: string, obj: Object) {
147
148 }
149
Sean Condonb2c483c2019-01-16 20:28:55 +0000150}
151
Sean Condonf4f54a12018-10-10 23:25:46 +0100152/**
153 * ONOS GUI -- Topology View -- Unit Tests
154 */
Sean Condon0a884ad2019-10-28 17:57:21 +0000155// Skipping temporarily
Sean Condonf4f54a12018-10-10 23:25:46 +0100156describe('TopologyComponent', () => {
157 let fs: FnService;
158 let ar: MockActivatedRoute;
159 let windowMock: Window;
160 let logServiceSpy: jasmine.SpyObj<LogService>;
161 let component: TopologyComponent;
162 let fixture: ComponentFixture<TopologyComponent>;
163
Sean Condonb2c483c2019-01-16 20:28:55 +0000164 const bundleObj = {
165 'core.fw.QuickHelp': {
166 test: 'test1',
167 tt_help: 'Help!'
168 }
169 };
170 const mockLion = (key) => {
171 return bundleObj[key] || '%' + key + '%';
172 };
173
Sean Condon64060ff2019-05-30 15:48:11 +0100174 beforeEach(() => {
Sean Condonf4f54a12018-10-10 23:25:46 +0100175 const logSpy = jasmine.createSpyObj('LogService', ['info', 'debug', 'warn', 'error']);
176 ar = new MockActivatedRoute({ 'debug': 'txrx' });
177
178 windowMock = <any>{
179 location: <any>{
180 hostname: 'foo',
181 host: 'foo',
182 port: '80',
183 protocol: 'http',
184 search: { debug: 'true' },
185 href: 'ws://foo:123/onos/ui/websock/path',
186 absUrl: 'ws://foo:123/onos/ui/websock/path'
187 }
188 };
189 fs = new FnService(ar, logSpy, windowMock);
190
191 TestBed.configureTestingModule({
Sean Condon0d064ec2019-02-04 21:53:53 +0000192 imports: [
193 BrowserAnimationsModule,
194 RouterTestingModule,
195 FormsModule,
196 ReactiveFormsModule
197 ],
Sean Condonf4f54a12018-10-10 23:25:46 +0100198 declarations: [
199 TopologyComponent,
200 InstanceComponent,
201 SummaryComponent,
202 ToolbarComponent,
203 DetailsComponent,
Sean Condon0c577f62018-11-18 22:40:05 +0000204 FlashComponent,
Sean Condonb2c483c2019-01-16 20:28:55 +0000205 IconComponent,
206 QuickhelpComponent,
207 ForceSvgComponent,
208 LinkSvgComponent,
209 DeviceNodeSvgComponent,
210 HostNodeSvgComponent,
211 DraggableDirective,
212 ZoomableDirective,
Sean Condon0d064ec2019-02-04 21:53:53 +0000213 SubRegionNodeSvgComponent,
214 MapSelectorComponent,
215 BackgroundSvgComponent,
Sean Condon71910542019-02-16 18:16:42 +0000216 MapSvgComponent,
Sean Condon590b34b2019-12-04 18:44:37 +0000217 GridsvgComponent,
218 BadgeSvgComponent
Sean Condonf4f54a12018-10-10 23:25:46 +0100219 ],
220 providers: [
221 { provide: FnService, useValue: fs },
222 { provide: LogService, useValue: logSpy },
223 { provide: 'Window', useValue: windowMock },
224 { provide: HttpClient, useClass: MockHttpClient },
Sean Condon0c577f62018-11-18 22:40:05 +0000225 { provide: TopologyService, useClass: MockTopologyService },
Sean Condonb2c483c2019-01-16 20:28:55 +0000226 { provide: TrafficService, useClass: MockTrafficService },
Sean Condon28884332019-03-21 14:07:00 +0000227 { provide: LayoutService, useClass: MockLayoutService },
Sean Condon91481822019-01-01 13:56:14 +0000228 { provide: IconService, useClass: MockIconService },
Sean Condonb2c483c2019-01-16 20:28:55 +0000229 { provide: PrefsService, useClass: MockPrefsService },
230 { provide: KeysService, useClass: MockKeysService },
231 { provide: LionService, useFactory: (() => {
232 return {
233 bundle: ((bundleId) => mockLion),
234 ubercache: new Array(),
235 loadCbs: new Map<string, () => void>([])
236 };
237 })
238 },
Sean Condonf4f54a12018-10-10 23:25:46 +0100239 ]
240 }).compileComponents();
241 logServiceSpy = TestBed.get(LogService);
Sean Condon64060ff2019-05-30 15:48:11 +0100242 });
Sean Condonf4f54a12018-10-10 23:25:46 +0100243
244 beforeEach(() => {
245 fixture = TestBed.createComponent(TopologyComponent);
246 component = fixture.componentInstance;
Sean Condon0d064ec2019-02-04 21:53:53 +0000247
Sean Condonf4f54a12018-10-10 23:25:46 +0100248 fixture.detectChanges();
249 });
250
251 it('should create', () => {
252 expect(component).toBeTruthy();
253 });
254});