blob: c7b6c1514e79c2f76ef0e33658043a2621d847c5 [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
107class MockTrafficService {}
108
Sean Condon28884332019-03-21 14:07:00 +0000109class MockLayoutService {}
110
Sean Condonb2c483c2019-01-16 20:28:55 +0000111class MockPrefsService {
112 listeners: ((data) => void)[] = [];
113
114 getPrefs() {
115 return { 'topo2_prefs': ''};
116 }
117
118 addListener(listener: (data) => void): void {
119 this.listeners.push(listener);
120 }
121
122 removeListener(listener: (data) => void) {
123 this.listeners = this.listeners.filter((obj) => obj !== listener);
124 }
125
Sean Condon71910542019-02-16 18:16:42 +0000126 setPrefs(name: string, obj: Object) {
127
128 }
129
Sean Condonb2c483c2019-01-16 20:28:55 +0000130}
131
Sean Condonf4f54a12018-10-10 23:25:46 +0100132/**
133 * ONOS GUI -- Topology View -- Unit Tests
134 */
135describe('TopologyComponent', () => {
136 let fs: FnService;
137 let ar: MockActivatedRoute;
138 let windowMock: Window;
139 let logServiceSpy: jasmine.SpyObj<LogService>;
140 let component: TopologyComponent;
141 let fixture: ComponentFixture<TopologyComponent>;
142
Sean Condonb2c483c2019-01-16 20:28:55 +0000143 const bundleObj = {
144 'core.fw.QuickHelp': {
145 test: 'test1',
146 tt_help: 'Help!'
147 }
148 };
149 const mockLion = (key) => {
150 return bundleObj[key] || '%' + key + '%';
151 };
152
Sean Condonf4f54a12018-10-10 23:25:46 +0100153 beforeEach(async(() => {
154 const logSpy = jasmine.createSpyObj('LogService', ['info', 'debug', 'warn', 'error']);
155 ar = new MockActivatedRoute({ 'debug': 'txrx' });
156
157 windowMock = <any>{
158 location: <any>{
159 hostname: 'foo',
160 host: 'foo',
161 port: '80',
162 protocol: 'http',
163 search: { debug: 'true' },
164 href: 'ws://foo:123/onos/ui/websock/path',
165 absUrl: 'ws://foo:123/onos/ui/websock/path'
166 }
167 };
168 fs = new FnService(ar, logSpy, windowMock);
169
170 TestBed.configureTestingModule({
Sean Condon0d064ec2019-02-04 21:53:53 +0000171 imports: [
172 BrowserAnimationsModule,
173 RouterTestingModule,
174 FormsModule,
175 ReactiveFormsModule
176 ],
Sean Condonf4f54a12018-10-10 23:25:46 +0100177 declarations: [
178 TopologyComponent,
179 InstanceComponent,
180 SummaryComponent,
181 ToolbarComponent,
182 DetailsComponent,
Sean Condon0c577f62018-11-18 22:40:05 +0000183 FlashComponent,
Sean Condon91481822019-01-01 13:56:14 +0000184 ZoomableDirective,
Sean Condonb2c483c2019-01-16 20:28:55 +0000185 IconComponent,
186 QuickhelpComponent,
187 ForceSvgComponent,
188 LinkSvgComponent,
189 DeviceNodeSvgComponent,
190 HostNodeSvgComponent,
191 DraggableDirective,
192 ZoomableDirective,
Sean Condon0d064ec2019-02-04 21:53:53 +0000193 SubRegionNodeSvgComponent,
194 MapSelectorComponent,
195 BackgroundSvgComponent,
Sean Condon71910542019-02-16 18:16:42 +0000196 MapSvgComponent,
197 GridsvgComponent
Sean Condonf4f54a12018-10-10 23:25:46 +0100198 ],
199 providers: [
200 { provide: FnService, useValue: fs },
201 { provide: LogService, useValue: logSpy },
202 { provide: 'Window', useValue: windowMock },
203 { provide: HttpClient, useClass: MockHttpClient },
Sean Condon0c577f62018-11-18 22:40:05 +0000204 { provide: TopologyService, useClass: MockTopologyService },
Sean Condonb2c483c2019-01-16 20:28:55 +0000205 { provide: TrafficService, useClass: MockTrafficService },
Sean Condon28884332019-03-21 14:07:00 +0000206 { provide: LayoutService, useClass: MockLayoutService },
Sean Condon91481822019-01-01 13:56:14 +0000207 { provide: IconService, useClass: MockIconService },
Sean Condonb2c483c2019-01-16 20:28:55 +0000208 { provide: PrefsService, useClass: MockPrefsService },
209 { provide: KeysService, useClass: MockKeysService },
210 { provide: LionService, useFactory: (() => {
211 return {
212 bundle: ((bundleId) => mockLion),
213 ubercache: new Array(),
214 loadCbs: new Map<string, () => void>([])
215 };
216 })
217 },
Sean Condonf4f54a12018-10-10 23:25:46 +0100218 ]
219 }).compileComponents();
220 logServiceSpy = TestBed.get(LogService);
221 }));
222
223 beforeEach(() => {
224 fixture = TestBed.createComponent(TopologyComponent);
225 component = fixture.componentInstance;
Sean Condon0d064ec2019-02-04 21:53:53 +0000226
Sean Condonf4f54a12018-10-10 23:25:46 +0100227 fixture.detectChanges();
228 });
229
230 it('should create', () => {
231 expect(component).toBeTruthy();
232 });
233});