blob: b4d579d6580c5cb0865c0eae6b91e0a6ef9630fe [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 Condonf4f54a12018-10-10 23:25:46 +010053
54
55class MockActivatedRoute extends ActivatedRoute {
56 constructor(params: Params) {
57 super();
58 this.queryParams = of(params);
59 }
60}
61
62class MockHttpClient {}
63
Sean Condonaa4366d2018-11-02 14:29:01 +000064class MockTopologyService {
65 init(instance: InstanceComponent) {
66 instance.onosInstances = [
67 <Instance>{
68 'id': 'inst1',
69 'ip': '127.0.0.1',
70 'reachable': true,
71 'online': true,
72 'ready': true,
73 'switches': 4,
74 'uiAttached': true
75 },
76 <Instance>{
77 'id': 'inst1',
78 'ip': '127.0.0.2',
79 'reachable': true,
80 'online': true,
81 'ready': true,
82 'switches': 3,
83 'uiAttached': false
84 }
85 ];
86 }
87 destroy() {}
88}
89
Sean Condon91481822019-01-01 13:56:14 +000090class MockIconService {
91 loadIconDef() { }
92}
93
Sean Condonb2c483c2019-01-16 20:28:55 +000094class MockKeysService {
95 quickHelpShown: boolean = true;
96
97 keyBindings(x) {
98 return {};
99 }
100
101 gestureNotes() {
102 return {};
103 }
104}
105
106class MockTrafficService {}
107
108class MockPrefsService {
109 listeners: ((data) => void)[] = [];
110
111 getPrefs() {
112 return { 'topo2_prefs': ''};
113 }
114
115 addListener(listener: (data) => void): void {
116 this.listeners.push(listener);
117 }
118
119 removeListener(listener: (data) => void) {
120 this.listeners = this.listeners.filter((obj) => obj !== listener);
121 }
122
Sean Condon71910542019-02-16 18:16:42 +0000123 setPrefs(name: string, obj: Object) {
124
125 }
126
Sean Condonb2c483c2019-01-16 20:28:55 +0000127}
128
Sean Condonf4f54a12018-10-10 23:25:46 +0100129/**
130 * ONOS GUI -- Topology View -- Unit Tests
131 */
132describe('TopologyComponent', () => {
133 let fs: FnService;
134 let ar: MockActivatedRoute;
135 let windowMock: Window;
136 let logServiceSpy: jasmine.SpyObj<LogService>;
137 let component: TopologyComponent;
138 let fixture: ComponentFixture<TopologyComponent>;
139
Sean Condonb2c483c2019-01-16 20:28:55 +0000140 const bundleObj = {
141 'core.fw.QuickHelp': {
142 test: 'test1',
143 tt_help: 'Help!'
144 }
145 };
146 const mockLion = (key) => {
147 return bundleObj[key] || '%' + key + '%';
148 };
149
Sean Condonf4f54a12018-10-10 23:25:46 +0100150 beforeEach(async(() => {
151 const logSpy = jasmine.createSpyObj('LogService', ['info', 'debug', 'warn', 'error']);
152 ar = new MockActivatedRoute({ 'debug': 'txrx' });
153
154 windowMock = <any>{
155 location: <any>{
156 hostname: 'foo',
157 host: 'foo',
158 port: '80',
159 protocol: 'http',
160 search: { debug: 'true' },
161 href: 'ws://foo:123/onos/ui/websock/path',
162 absUrl: 'ws://foo:123/onos/ui/websock/path'
163 }
164 };
165 fs = new FnService(ar, logSpy, windowMock);
166
167 TestBed.configureTestingModule({
Sean Condon0d064ec2019-02-04 21:53:53 +0000168 imports: [
169 BrowserAnimationsModule,
170 RouterTestingModule,
171 FormsModule,
172 ReactiveFormsModule
173 ],
Sean Condonf4f54a12018-10-10 23:25:46 +0100174 declarations: [
175 TopologyComponent,
176 InstanceComponent,
177 SummaryComponent,
178 ToolbarComponent,
179 DetailsComponent,
Sean Condon0c577f62018-11-18 22:40:05 +0000180 FlashComponent,
Sean Condon91481822019-01-01 13:56:14 +0000181 ZoomableDirective,
Sean Condonb2c483c2019-01-16 20:28:55 +0000182 IconComponent,
183 QuickhelpComponent,
184 ForceSvgComponent,
185 LinkSvgComponent,
186 DeviceNodeSvgComponent,
187 HostNodeSvgComponent,
188 DraggableDirective,
189 ZoomableDirective,
Sean Condon0d064ec2019-02-04 21:53:53 +0000190 SubRegionNodeSvgComponent,
191 MapSelectorComponent,
192 BackgroundSvgComponent,
Sean Condon71910542019-02-16 18:16:42 +0000193 MapSvgComponent,
194 GridsvgComponent
Sean Condonf4f54a12018-10-10 23:25:46 +0100195 ],
196 providers: [
197 { provide: FnService, useValue: fs },
198 { provide: LogService, useValue: logSpy },
199 { provide: 'Window', useValue: windowMock },
200 { provide: HttpClient, useClass: MockHttpClient },
Sean Condon0c577f62018-11-18 22:40:05 +0000201 { provide: TopologyService, useClass: MockTopologyService },
Sean Condonb2c483c2019-01-16 20:28:55 +0000202 { provide: TrafficService, useClass: MockTrafficService },
Sean Condon91481822019-01-01 13:56:14 +0000203 { provide: IconService, useClass: MockIconService },
Sean Condonb2c483c2019-01-16 20:28:55 +0000204 { provide: PrefsService, useClass: MockPrefsService },
205 { provide: KeysService, useClass: MockKeysService },
206 { provide: LionService, useFactory: (() => {
207 return {
208 bundle: ((bundleId) => mockLion),
209 ubercache: new Array(),
210 loadCbs: new Map<string, () => void>([])
211 };
212 })
213 },
Sean Condonf4f54a12018-10-10 23:25:46 +0100214 ]
215 }).compileComponents();
216 logServiceSpy = TestBed.get(LogService);
217 }));
218
219 beforeEach(() => {
220 fixture = TestBed.createComponent(TopologyComponent);
221 component = fixture.componentInstance;
Sean Condon0d064ec2019-02-04 21:53:53 +0000222
Sean Condonf4f54a12018-10-10 23:25:46 +0100223 fixture.detectChanges();
224 });
225
226 it('should create', () => {
227 expect(component).toBeTruthy();
228 });
229});