blob: 0c0a6dd6723825268bf406694961bb7d8f081d2e [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';
43import {
44 DeviceNodeSvgComponent, HostNodeSvgComponent,
45 LinkSvgComponent, SubRegionNodeSvgComponent
46} from '../layer/forcesvg/visuals';
47import {DraggableDirective} from '../layer/forcesvg/draggable/draggable.directive';
Sean Condon0d064ec2019-02-04 21:53:53 +000048import {MapSelectorComponent} from '../panel/mapselector/mapselector.component';
49import {BackgroundSvgComponent} from '../layer/backgroundsvg/backgroundsvg.component';
50import {FormsModule, ReactiveFormsModule} from '@angular/forms';
51import {MapSvgComponent} from '../layer/mapsvg/mapsvg.component';
Sean Condonf4f54a12018-10-10 23:25:46 +010052
53
54class MockActivatedRoute extends ActivatedRoute {
55 constructor(params: Params) {
56 super();
57 this.queryParams = of(params);
58 }
59}
60
61class MockHttpClient {}
62
Sean Condonaa4366d2018-11-02 14:29:01 +000063class MockTopologyService {
64 init(instance: InstanceComponent) {
65 instance.onosInstances = [
66 <Instance>{
67 'id': 'inst1',
68 'ip': '127.0.0.1',
69 'reachable': true,
70 'online': true,
71 'ready': true,
72 'switches': 4,
73 'uiAttached': true
74 },
75 <Instance>{
76 'id': 'inst1',
77 'ip': '127.0.0.2',
78 'reachable': true,
79 'online': true,
80 'ready': true,
81 'switches': 3,
82 'uiAttached': false
83 }
84 ];
85 }
86 destroy() {}
87}
88
Sean Condon91481822019-01-01 13:56:14 +000089class MockIconService {
90 loadIconDef() { }
91}
92
Sean Condonb2c483c2019-01-16 20:28:55 +000093class MockKeysService {
94 quickHelpShown: boolean = true;
95
96 keyBindings(x) {
97 return {};
98 }
99
100 gestureNotes() {
101 return {};
102 }
103}
104
105class MockTrafficService {}
106
107class MockPrefsService {
108 listeners: ((data) => void)[] = [];
109
110 getPrefs() {
111 return { 'topo2_prefs': ''};
112 }
113
114 addListener(listener: (data) => void): void {
115 this.listeners.push(listener);
116 }
117
118 removeListener(listener: (data) => void) {
119 this.listeners = this.listeners.filter((obj) => obj !== listener);
120 }
121
122}
123
Sean Condonf4f54a12018-10-10 23:25:46 +0100124/**
125 * ONOS GUI -- Topology View -- Unit Tests
126 */
127describe('TopologyComponent', () => {
128 let fs: FnService;
129 let ar: MockActivatedRoute;
130 let windowMock: Window;
131 let logServiceSpy: jasmine.SpyObj<LogService>;
132 let component: TopologyComponent;
133 let fixture: ComponentFixture<TopologyComponent>;
134
Sean Condonb2c483c2019-01-16 20:28:55 +0000135 const bundleObj = {
136 'core.fw.QuickHelp': {
137 test: 'test1',
138 tt_help: 'Help!'
139 }
140 };
141 const mockLion = (key) => {
142 return bundleObj[key] || '%' + key + '%';
143 };
144
Sean Condonf4f54a12018-10-10 23:25:46 +0100145 beforeEach(async(() => {
146 const logSpy = jasmine.createSpyObj('LogService', ['info', 'debug', 'warn', 'error']);
147 ar = new MockActivatedRoute({ 'debug': 'txrx' });
148
149 windowMock = <any>{
150 location: <any>{
151 hostname: 'foo',
152 host: 'foo',
153 port: '80',
154 protocol: 'http',
155 search: { debug: 'true' },
156 href: 'ws://foo:123/onos/ui/websock/path',
157 absUrl: 'ws://foo:123/onos/ui/websock/path'
158 }
159 };
160 fs = new FnService(ar, logSpy, windowMock);
161
162 TestBed.configureTestingModule({
Sean Condon0d064ec2019-02-04 21:53:53 +0000163 imports: [
164 BrowserAnimationsModule,
165 RouterTestingModule,
166 FormsModule,
167 ReactiveFormsModule
168 ],
Sean Condonf4f54a12018-10-10 23:25:46 +0100169 declarations: [
170 TopologyComponent,
171 InstanceComponent,
172 SummaryComponent,
173 ToolbarComponent,
174 DetailsComponent,
Sean Condon0c577f62018-11-18 22:40:05 +0000175 FlashComponent,
Sean Condon91481822019-01-01 13:56:14 +0000176 ZoomableDirective,
Sean Condonb2c483c2019-01-16 20:28:55 +0000177 IconComponent,
178 QuickhelpComponent,
179 ForceSvgComponent,
180 LinkSvgComponent,
181 DeviceNodeSvgComponent,
182 HostNodeSvgComponent,
183 DraggableDirective,
184 ZoomableDirective,
Sean Condon0d064ec2019-02-04 21:53:53 +0000185 SubRegionNodeSvgComponent,
186 MapSelectorComponent,
187 BackgroundSvgComponent,
188 MapSvgComponent
Sean Condonf4f54a12018-10-10 23:25:46 +0100189 ],
190 providers: [
191 { provide: FnService, useValue: fs },
192 { provide: LogService, useValue: logSpy },
193 { provide: 'Window', useValue: windowMock },
194 { provide: HttpClient, useClass: MockHttpClient },
Sean Condon0c577f62018-11-18 22:40:05 +0000195 { provide: TopologyService, useClass: MockTopologyService },
Sean Condonb2c483c2019-01-16 20:28:55 +0000196 { provide: TrafficService, useClass: MockTrafficService },
Sean Condon91481822019-01-01 13:56:14 +0000197 { provide: IconService, useClass: MockIconService },
Sean Condonb2c483c2019-01-16 20:28:55 +0000198 { provide: PrefsService, useClass: MockPrefsService },
199 { provide: KeysService, useClass: MockKeysService },
200 { provide: LionService, useFactory: (() => {
201 return {
202 bundle: ((bundleId) => mockLion),
203 ubercache: new Array(),
204 loadCbs: new Map<string, () => void>([])
205 };
206 })
207 },
Sean Condonf4f54a12018-10-10 23:25:46 +0100208 ]
209 }).compileComponents();
210 logServiceSpy = TestBed.get(LogService);
211 }));
212
213 beforeEach(() => {
214 fixture = TestBed.createComponent(TopologyComponent);
215 component = fixture.componentInstance;
Sean Condon0d064ec2019-02-04 21:53:53 +0000216
Sean Condonf4f54a12018-10-10 23:25:46 +0100217 fixture.detectChanges();
218 });
219
220 it('should create', () => {
221 expect(component).toBeTruthy();
222 });
223});