Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2018-present Open Networking Foundation |
| 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 { NoDeviceConnectedSvgComponent } from './nodeviceconnectedsvg.component'; |
| 19 | import { DebugElement } from '@angular/core'; |
| 20 | import { By } from '@angular/platform-browser'; |
| 21 | import { |
| 22 | FnService, |
| 23 | IconService, |
| 24 | LionService, |
| 25 | LogService, |
| 26 | UrlFnService, |
| 27 | TableFilterPipe, |
| 28 | IconComponent, |
Sean Condon | 9148182 | 2019-01-01 13:56:14 +0000 | [diff] [blame] | 29 | WebSocketService, SvgUtilService, PrefsService |
Sean Condon | 3b3fdab | 2020-04-14 09:25:00 +0100 | [diff] [blame] | 30 | } from 'org_onosproject_onos/web/gui2-fw-lib/public_api'; |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 31 | import { of } from 'rxjs'; |
| 32 | |
| 33 | class MockActivatedRoute extends ActivatedRoute { |
| 34 | constructor(params: Params) { |
| 35 | super(); |
| 36 | this.queryParams = of(params); |
| 37 | } |
| 38 | } |
| 39 | |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 40 | class MockWebSocketService { |
| 41 | createWebSocket() { } |
| 42 | isConnected() { return false; } |
| 43 | unbindHandlers() { } |
| 44 | bindHandlers() { } |
| 45 | } |
| 46 | |
Sean Condon | 9148182 | 2019-01-01 13:56:14 +0000 | [diff] [blame] | 47 | class MockSvgUtilService { |
| 48 | translate() {} |
| 49 | scale() {} |
| 50 | } |
| 51 | |
| 52 | class MockPrefsService { |
| 53 | } |
| 54 | |
| 55 | |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 56 | /** |
| 57 | * ONOS GUI -- Topology NoDevicesConnected -- Unit Tests |
| 58 | */ |
| 59 | describe('NoDeviceConnectedSvgComponent', () => { |
| 60 | let fs: FnService; |
| 61 | let ar: MockActivatedRoute; |
| 62 | let windowMock: Window; |
| 63 | let logServiceSpy: jasmine.SpyObj<LogService>; |
| 64 | let component: NoDeviceConnectedSvgComponent; |
| 65 | let fixture: ComponentFixture<NoDeviceConnectedSvgComponent>; |
| 66 | |
| 67 | |
| 68 | beforeEach(async(() => { |
| 69 | const logSpy = jasmine.createSpyObj('LogService', ['info', 'debug', 'warn', 'error']); |
| 70 | ar = new MockActivatedRoute({'debug': 'panel'}); |
| 71 | |
| 72 | windowMock = <any>{ |
Sean Condon | ff85fbe | 2019-03-16 14:28:46 +0000 | [diff] [blame] | 73 | innerWidth: 800, |
| 74 | innerHeight: 600, |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 75 | }; |
| 76 | fs = new FnService(ar, logSpy, windowMock); |
| 77 | |
Sean Condon | 64060ff | 2019-05-30 15:48:11 +0100 | [diff] [blame] | 78 | const bundleObj = { |
| 79 | 'core.view.Topo': { |
| 80 | test: 'test1' |
| 81 | } |
| 82 | }; |
| 83 | const mockLion = (key) => { |
| 84 | return bundleObj[key] || '%' + key + '%'; |
| 85 | }; |
| 86 | |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 87 | TestBed.configureTestingModule({ |
| 88 | declarations: [ NoDeviceConnectedSvgComponent ], |
| 89 | providers: [ |
| 90 | { provide: FnService, useValue: fs }, |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 91 | { provide: LogService, useValue: logSpy }, |
Sean Condon | 9148182 | 2019-01-01 13:56:14 +0000 | [diff] [blame] | 92 | { provide: SvgUtilService, useClass: MockSvgUtilService }, |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 93 | { provide: WebSocketService, useClass: MockWebSocketService }, |
Sean Condon | 9148182 | 2019-01-01 13:56:14 +0000 | [diff] [blame] | 94 | { provide: PrefsService, useClass: MockPrefsService }, |
Sean Condon | 64060ff | 2019-05-30 15:48:11 +0100 | [diff] [blame] | 95 | { |
| 96 | provide: LionService, useFactory: (() => { |
| 97 | return { |
| 98 | bundle: ((bundleId) => mockLion), |
| 99 | ubercache: new Array(), |
| 100 | loadCbs: new Map<string, () => void>([]) |
| 101 | }; |
| 102 | }) |
| 103 | }, |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 104 | { provide: 'Window', useValue: windowMock }, |
| 105 | ] |
| 106 | }).compileComponents(); |
| 107 | logServiceSpy = TestBed.get(LogService); |
| 108 | })); |
| 109 | |
| 110 | beforeEach(() => { |
| 111 | fixture = TestBed.createComponent(NoDeviceConnectedSvgComponent); |
| 112 | component = fixture.componentInstance; |
| 113 | fixture.detectChanges(); |
| 114 | }); |
| 115 | |
| 116 | it('should create', () => { |
| 117 | expect(component).toBeTruthy(); |
| 118 | }); |
| 119 | }); |