blob: f38604f9e1ba96dad64b36c77be2ee9af9c4f0e8 [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
98 keyBindings(x) {
99 return {};
100 }
101
102 gestureNotes() {
103 return {};
104 }
105}
106
Sean Condon19e83672019-04-13 16:21:52 +0100107class MockTrafficService {
108 init(force: ForceSvgComponent) {}
109}
Sean Condonb2c483c2019-01-16 20:28:55 +0000110
Sean Condon28884332019-03-21 14:07:00 +0000111class MockLayoutService {}
112
Sean Condonb2c483c2019-01-16 20:28:55 +0000113class MockPrefsService {
114 listeners: ((data) => void)[] = [];
115
116 getPrefs() {
117 return { 'topo2_prefs': ''};
118 }
119
120 addListener(listener: (data) => void): void {
121 this.listeners.push(listener);
122 }
123
124 removeListener(listener: (data) => void) {
125 this.listeners = this.listeners.filter((obj) => obj !== listener);
126 }
127
Sean Condon71910542019-02-16 18:16:42 +0000128 setPrefs(name: string, obj: Object) {
129
130 }
131
Sean Condonb2c483c2019-01-16 20:28:55 +0000132}
133
Sean Condonf4f54a12018-10-10 23:25:46 +0100134/**
135 * ONOS GUI -- Topology View -- Unit Tests
136 */
137describe('TopologyComponent', () => {
138 let fs: FnService;
139 let ar: MockActivatedRoute;
140 let windowMock: Window;
141 let logServiceSpy: jasmine.SpyObj<LogService>;
142 let component: TopologyComponent;
143 let fixture: ComponentFixture<TopologyComponent>;
144
Sean Condonb2c483c2019-01-16 20:28:55 +0000145 const bundleObj = {
146 'core.fw.QuickHelp': {
147 test: 'test1',
148 tt_help: 'Help!'
149 }
150 };
151 const mockLion = (key) => {
152 return bundleObj[key] || '%' + key + '%';
153 };
154
Sean Condonf4f54a12018-10-10 23:25:46 +0100155 beforeEach(async(() => {
156 const logSpy = jasmine.createSpyObj('LogService', ['info', 'debug', 'warn', 'error']);
157 ar = new MockActivatedRoute({ 'debug': 'txrx' });
158
159 windowMock = <any>{
160 location: <any>{
161 hostname: 'foo',
162 host: 'foo',
163 port: '80',
164 protocol: 'http',
165 search: { debug: 'true' },
166 href: 'ws://foo:123/onos/ui/websock/path',
167 absUrl: 'ws://foo:123/onos/ui/websock/path'
168 }
169 };
170 fs = new FnService(ar, logSpy, windowMock);
171
172 TestBed.configureTestingModule({
Sean Condon0d064ec2019-02-04 21:53:53 +0000173 imports: [
174 BrowserAnimationsModule,
175 RouterTestingModule,
176 FormsModule,
177 ReactiveFormsModule
178 ],
Sean Condonf4f54a12018-10-10 23:25:46 +0100179 declarations: [
180 TopologyComponent,
181 InstanceComponent,
182 SummaryComponent,
183 ToolbarComponent,
184 DetailsComponent,
Sean Condon0c577f62018-11-18 22:40:05 +0000185 FlashComponent,
Sean Condon91481822019-01-01 13:56:14 +0000186 ZoomableDirective,
Sean Condonb2c483c2019-01-16 20:28:55 +0000187 IconComponent,
188 QuickhelpComponent,
189 ForceSvgComponent,
190 LinkSvgComponent,
191 DeviceNodeSvgComponent,
192 HostNodeSvgComponent,
193 DraggableDirective,
194 ZoomableDirective,
Sean Condon0d064ec2019-02-04 21:53:53 +0000195 SubRegionNodeSvgComponent,
196 MapSelectorComponent,
197 BackgroundSvgComponent,
Sean Condon71910542019-02-16 18:16:42 +0000198 MapSvgComponent,
199 GridsvgComponent
Sean Condonf4f54a12018-10-10 23:25:46 +0100200 ],
201 providers: [
202 { provide: FnService, useValue: fs },
203 { provide: LogService, useValue: logSpy },
204 { provide: 'Window', useValue: windowMock },
205 { provide: HttpClient, useClass: MockHttpClient },
Sean Condon0c577f62018-11-18 22:40:05 +0000206 { provide: TopologyService, useClass: MockTopologyService },
Sean Condonb2c483c2019-01-16 20:28:55 +0000207 { provide: TrafficService, useClass: MockTrafficService },
Sean Condon28884332019-03-21 14:07:00 +0000208 { provide: LayoutService, useClass: MockLayoutService },
Sean Condon91481822019-01-01 13:56:14 +0000209 { provide: IconService, useClass: MockIconService },
Sean Condonb2c483c2019-01-16 20:28:55 +0000210 { provide: PrefsService, useClass: MockPrefsService },
211 { provide: KeysService, useClass: MockKeysService },
212 { provide: LionService, useFactory: (() => {
213 return {
214 bundle: ((bundleId) => mockLion),
215 ubercache: new Array(),
216 loadCbs: new Map<string, () => void>([])
217 };
218 })
219 },
Sean Condonf4f54a12018-10-10 23:25:46 +0100220 ]
221 }).compileComponents();
222 logServiceSpy = TestBed.get(LogService);
223 }));
224
225 beforeEach(() => {
226 fixture = TestBed.createComponent(TopologyComponent);
227 component = fixture.componentInstance;
Sean Condon0d064ec2019-02-04 21:53:53 +0000228
Sean Condonf4f54a12018-10-10 23:25:46 +0100229 fixture.detectChanges();
230 });
231
232 it('should create', () => {
233 expect(component).toBeTruthy();
234 });
235});