Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 1 | /* |
Sean Condon | b2c483c | 2019-01-16 20:28:55 +0000 | [diff] [blame] | 2 | * Copyright 2019-present Open Networking Foundation |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 3 | * |
| 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 | */ |
| 16 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; |
| 17 | import { ActivatedRoute, Params } from '@angular/router'; |
| 18 | import { of } from 'rxjs'; |
| 19 | import { HttpClient } from '@angular/common/http'; |
| 20 | import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; |
Sean Condon | 0d064ec | 2019-02-04 21:53:53 +0000 | [diff] [blame] | 21 | import * as d3 from 'd3'; |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 22 | import { TopologyComponent } from './topology.component'; |
Sean Condon | aa4366d | 2018-11-02 14:29:01 +0000 | [diff] [blame] | 23 | import { |
| 24 | Instance, |
| 25 | InstanceComponent |
| 26 | } from '../panel/instance/instance.component'; |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 27 | import { SummaryComponent } from '../panel/summary/summary.component'; |
| 28 | import { ToolbarComponent } from '../panel/toolbar/toolbar.component'; |
| 29 | import { DetailsComponent } from '../panel/details/details.component'; |
Sean Condon | 4e55c80 | 2019-12-03 22:13:34 +0000 | [diff] [blame] | 30 | import {Intent, TopologyService} from '../topology.service'; |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 31 | |
| 32 | import { |
| 33 | FlashComponent, |
Sean Condon | b2c483c | 2019-01-16 20:28:55 +0000 | [diff] [blame] | 34 | QuickhelpComponent, |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 35 | FnService, |
Sean Condon | 9148182 | 2019-01-01 13:56:14 +0000 | [diff] [blame] | 36 | LogService, |
Sean Condon | 98b6ddb | 2019-12-24 08:07:40 +0000 | [diff] [blame] | 37 | IconService, IconComponent, PrefsService, KeysService, LionService, ZoomableDirective |
Sean Condon | a3ad779 | 2020-01-04 19:26:34 +0000 | [diff] [blame] | 38 | } from 'gui2-fw-lib/public_api'; |
Sean Condon | 9148182 | 2019-01-01 13:56:14 +0000 | [diff] [blame] | 39 | import {RouterTestingModule} from '@angular/router/testing'; |
Sean Condon | b2c483c | 2019-01-16 20:28:55 +0000 | [diff] [blame] | 40 | import {TrafficService} from '../traffic.service'; |
| 41 | import {ForceSvgComponent} from '../layer/forcesvg/forcesvg.component'; |
Sean Condon | b2c483c | 2019-01-16 20:28:55 +0000 | [diff] [blame] | 42 | import {DraggableDirective} from '../layer/forcesvg/draggable/draggable.directive'; |
Sean Condon | 0d064ec | 2019-02-04 21:53:53 +0000 | [diff] [blame] | 43 | import {MapSelectorComponent} from '../panel/mapselector/mapselector.component'; |
| 44 | import {BackgroundSvgComponent} from '../layer/backgroundsvg/backgroundsvg.component'; |
| 45 | import {FormsModule, ReactiveFormsModule} from '@angular/forms'; |
| 46 | import {MapSvgComponent} from '../layer/mapsvg/mapsvg.component'; |
Sean Condon | 7191054 | 2019-02-16 18:16:42 +0000 | [diff] [blame] | 47 | import {GridsvgComponent} from '../layer/gridsvg/gridsvg.component'; |
Sean Condon | ff85fbe | 2019-03-16 14:28:46 +0000 | [diff] [blame] | 48 | import {LinkSvgComponent} from '../layer/forcesvg/visuals/linksvg/linksvg.component'; |
| 49 | import {DeviceNodeSvgComponent} from '../layer/forcesvg/visuals/devicenodesvg/devicenodesvg.component'; |
| 50 | import {SubRegionNodeSvgComponent} from '../layer/forcesvg/visuals/subregionnodesvg/subregionnodesvg.component'; |
| 51 | import {HostNodeSvgComponent} from '../layer/forcesvg/visuals/hostnodesvg/hostnodesvg.component'; |
Sean Condon | 2888433 | 2019-03-21 14:07:00 +0000 | [diff] [blame] | 52 | import {LayoutService} from '../layout.service'; |
Sean Condon | 590b34b | 2019-12-04 18:44:37 +0000 | [diff] [blame] | 53 | import {BadgeSvgComponent} from '../layer/forcesvg/visuals/badgesvg/badgesvg.component'; |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 54 | |
| 55 | |
| 56 | class MockActivatedRoute extends ActivatedRoute { |
| 57 | constructor(params: Params) { |
| 58 | super(); |
| 59 | this.queryParams = of(params); |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | class MockHttpClient {} |
| 64 | |
Sean Condon | aa4366d | 2018-11-02 14:29:01 +0000 | [diff] [blame] | 65 | class 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 Condon | 4e55c80 | 2019-12-03 22:13:34 +0000 | [diff] [blame] | 89 | setSelectedIntent(selectedIntent: Intent): void {} |
| 90 | selectRelatedIntent(ids: string[]): void {} |
| 91 | cancelHighlights(): void {} |
Sean Condon | aa4366d | 2018-11-02 14:29:01 +0000 | [diff] [blame] | 92 | } |
| 93 | |
Sean Condon | 9148182 | 2019-01-01 13:56:14 +0000 | [diff] [blame] | 94 | class MockIconService { |
| 95 | loadIconDef() { } |
| 96 | } |
| 97 | |
Sean Condon | b2c483c | 2019-01-16 20:28:55 +0000 | [diff] [blame] | 98 | class MockKeysService { |
| 99 | quickHelpShown: boolean = true; |
| 100 | |
Sean Condon | bed2e03 | 2019-04-17 22:22:49 +0100 | [diff] [blame] | 101 | 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 Condon | b2c483c | 2019-01-16 20:28:55 +0000 | [diff] [blame] | 115 | keyBindings(x) { |
| 116 | return {}; |
| 117 | } |
| 118 | |
| 119 | gestureNotes() { |
| 120 | return {}; |
| 121 | } |
| 122 | } |
| 123 | |
Sean Condon | 19e8367 | 2019-04-13 16:21:52 +0100 | [diff] [blame] | 124 | class MockTrafficService { |
| 125 | init(force: ForceSvgComponent) {} |
Sean Condon | c13d956 | 2019-04-18 13:24:42 +0100 | [diff] [blame] | 126 | destroy() {} |
Sean Condon | 19e8367 | 2019-04-13 16:21:52 +0100 | [diff] [blame] | 127 | } |
Sean Condon | b2c483c | 2019-01-16 20:28:55 +0000 | [diff] [blame] | 128 | |
Sean Condon | 2888433 | 2019-03-21 14:07:00 +0000 | [diff] [blame] | 129 | class MockLayoutService {} |
| 130 | |
Sean Condon | b2c483c | 2019-01-16 20:28:55 +0000 | [diff] [blame] | 131 | class 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 Condon | 7191054 | 2019-02-16 18:16:42 +0000 | [diff] [blame] | 146 | setPrefs(name: string, obj: Object) { |
| 147 | |
| 148 | } |
| 149 | |
Sean Condon | b2c483c | 2019-01-16 20:28:55 +0000 | [diff] [blame] | 150 | } |
| 151 | |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 152 | /** |
| 153 | * ONOS GUI -- Topology View -- Unit Tests |
| 154 | */ |
Sean Condon | 0a884ad | 2019-10-28 17:57:21 +0000 | [diff] [blame] | 155 | // Skipping temporarily |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 156 | describe('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 Condon | b2c483c | 2019-01-16 20:28:55 +0000 | [diff] [blame] | 164 | 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 Condon | 64060ff | 2019-05-30 15:48:11 +0100 | [diff] [blame] | 174 | beforeEach(() => { |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 175 | 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 Condon | 0d064ec | 2019-02-04 21:53:53 +0000 | [diff] [blame] | 192 | imports: [ |
| 193 | BrowserAnimationsModule, |
| 194 | RouterTestingModule, |
| 195 | FormsModule, |
| 196 | ReactiveFormsModule |
| 197 | ], |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 198 | declarations: [ |
| 199 | TopologyComponent, |
| 200 | InstanceComponent, |
| 201 | SummaryComponent, |
| 202 | ToolbarComponent, |
| 203 | DetailsComponent, |
Sean Condon | 0c577f6 | 2018-11-18 22:40:05 +0000 | [diff] [blame] | 204 | FlashComponent, |
Sean Condon | b2c483c | 2019-01-16 20:28:55 +0000 | [diff] [blame] | 205 | IconComponent, |
| 206 | QuickhelpComponent, |
| 207 | ForceSvgComponent, |
| 208 | LinkSvgComponent, |
| 209 | DeviceNodeSvgComponent, |
| 210 | HostNodeSvgComponent, |
| 211 | DraggableDirective, |
| 212 | ZoomableDirective, |
Sean Condon | 0d064ec | 2019-02-04 21:53:53 +0000 | [diff] [blame] | 213 | SubRegionNodeSvgComponent, |
| 214 | MapSelectorComponent, |
| 215 | BackgroundSvgComponent, |
Sean Condon | 7191054 | 2019-02-16 18:16:42 +0000 | [diff] [blame] | 216 | MapSvgComponent, |
Sean Condon | 590b34b | 2019-12-04 18:44:37 +0000 | [diff] [blame] | 217 | GridsvgComponent, |
| 218 | BadgeSvgComponent |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 219 | ], |
| 220 | providers: [ |
| 221 | { provide: FnService, useValue: fs }, |
| 222 | { provide: LogService, useValue: logSpy }, |
| 223 | { provide: 'Window', useValue: windowMock }, |
| 224 | { provide: HttpClient, useClass: MockHttpClient }, |
Sean Condon | 0c577f6 | 2018-11-18 22:40:05 +0000 | [diff] [blame] | 225 | { provide: TopologyService, useClass: MockTopologyService }, |
Sean Condon | b2c483c | 2019-01-16 20:28:55 +0000 | [diff] [blame] | 226 | { provide: TrafficService, useClass: MockTrafficService }, |
Sean Condon | 2888433 | 2019-03-21 14:07:00 +0000 | [diff] [blame] | 227 | { provide: LayoutService, useClass: MockLayoutService }, |
Sean Condon | 9148182 | 2019-01-01 13:56:14 +0000 | [diff] [blame] | 228 | { provide: IconService, useClass: MockIconService }, |
Sean Condon | b2c483c | 2019-01-16 20:28:55 +0000 | [diff] [blame] | 229 | { 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 Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 239 | ] |
| 240 | }).compileComponents(); |
| 241 | logServiceSpy = TestBed.get(LogService); |
Sean Condon | 64060ff | 2019-05-30 15:48:11 +0100 | [diff] [blame] | 242 | }); |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 243 | |
| 244 | beforeEach(() => { |
| 245 | fixture = TestBed.createComponent(TopologyComponent); |
| 246 | component = fixture.componentInstance; |
Sean Condon | 0d064ec | 2019-02-04 21:53:53 +0000 | [diff] [blame] | 247 | |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 248 | fixture.detectChanges(); |
| 249 | }); |
| 250 | |
| 251 | it('should create', () => { |
| 252 | expect(component).toBeTruthy(); |
| 253 | }); |
| 254 | }); |