Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015-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'; |
Sean Condon | 2bd11b7 | 2018-06-15 08:00:48 +0100 | [diff] [blame] | 17 | import { ActivatedRoute, Params } from '@angular/router'; |
| 18 | import { DebugElement } from '@angular/core'; |
| 19 | import { By } from '@angular/platform-browser'; |
Sean Condon | 28ecc5f | 2018-06-25 12:50:16 +0100 | [diff] [blame] | 20 | import { LogService } from '../../log.service'; |
| 21 | import { DeviceComponent } from './device.component'; |
Sean Condon | fd6d11b | 2018-06-02 20:29:49 +0100 | [diff] [blame] | 22 | |
Sean Condon | 28ecc5f | 2018-06-25 12:50:16 +0100 | [diff] [blame] | 23 | import { FnService, WindowSize } from '../../fw/util/fn.service'; |
| 24 | import { IconService } from '../../fw/svg/icon.service'; |
| 25 | import { GlyphService } from '../../fw/svg/glyph.service'; |
| 26 | import { IconComponent } from '../../fw/svg/icon/icon.component'; |
| 27 | import { KeyService } from '../../fw/util/key.service'; |
| 28 | import { LoadingService } from '../../fw/layer/loading.service'; |
| 29 | import { NavService } from '../../fw/nav/nav.service'; |
| 30 | import { MastService } from '../../fw/mast/mast.service'; |
| 31 | import { SvgUtilService } from '../../fw/svg/svgutil.service'; |
| 32 | import { ThemeService } from '../../fw/util/theme.service'; |
| 33 | import { WebSocketService } from '../../fw/remote/websocket.service'; |
Sean Condon | 2bd11b7 | 2018-06-15 08:00:48 +0100 | [diff] [blame] | 34 | import { of } from 'rxjs'; |
Sean Condon | 49e15be | 2018-05-16 16:58:29 +0100 | [diff] [blame] | 35 | |
Sean Condon | 2bd11b7 | 2018-06-15 08:00:48 +0100 | [diff] [blame] | 36 | class MockActivatedRoute extends ActivatedRoute { |
| 37 | constructor(params: Params) { |
| 38 | super(); |
| 39 | this.queryParams = of(params); |
Sean Condon | fd6d11b | 2018-06-02 20:29:49 +0100 | [diff] [blame] | 40 | } |
| 41 | } |
Sean Condon | 49e15be | 2018-05-16 16:58:29 +0100 | [diff] [blame] | 42 | |
Sean Condon | 2bd11b7 | 2018-06-15 08:00:48 +0100 | [diff] [blame] | 43 | class MockDetailsPanelService {} |
| 44 | |
| 45 | class MockFnService {} |
| 46 | |
| 47 | class MockIconService { |
| 48 | loadIconDef() {} |
| 49 | } |
Sean Condon | 49e15be | 2018-05-16 16:58:29 +0100 | [diff] [blame] | 50 | |
Sean Condon | fd6d11b | 2018-06-02 20:29:49 +0100 | [diff] [blame] | 51 | class MockGlyphService {} |
| 52 | |
Sean Condon | 49e15be | 2018-05-16 16:58:29 +0100 | [diff] [blame] | 53 | class MockKeyService {} |
| 54 | |
| 55 | class MockLoadingService { |
Sean Condon | 2bd11b7 | 2018-06-15 08:00:48 +0100 | [diff] [blame] | 56 | startAnim() {} |
| 57 | stop() {} |
Sean Condon | 49e15be | 2018-05-16 16:58:29 +0100 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | class MockNavService {} |
| 61 | |
| 62 | class MockMastService {} |
| 63 | |
Sean Condon | 49e15be | 2018-05-16 16:58:29 +0100 | [diff] [blame] | 64 | class MockTableBuilderService {} |
| 65 | |
| 66 | class MockTableDetailService {} |
| 67 | |
Sean Condon | 2bd11b7 | 2018-06-15 08:00:48 +0100 | [diff] [blame] | 68 | class MockThemeService {} |
| 69 | |
| 70 | class MockWebSocketService { |
| 71 | createWebSocket() {} |
| 72 | isConnected() { return false; } |
| 73 | unbindHandlers() {} |
| 74 | bindHandlers() {} |
| 75 | } |
Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 76 | |
| 77 | /** |
| 78 | * ONOS GUI -- Device View Module - Unit Tests |
| 79 | */ |
| 80 | describe('DeviceComponent', () => { |
Sean Condon | 2bd11b7 | 2018-06-15 08:00:48 +0100 | [diff] [blame] | 81 | let fs: FnService; |
| 82 | let ar: MockActivatedRoute; |
| 83 | let windowMock: Window; |
| 84 | let logServiceSpy: jasmine.SpyObj<LogService>; |
Sean Condon | 49e15be | 2018-05-16 16:58:29 +0100 | [diff] [blame] | 85 | let component: DeviceComponent; |
| 86 | let fixture: ComponentFixture<DeviceComponent>; |
Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 87 | |
Sean Condon | 49e15be | 2018-05-16 16:58:29 +0100 | [diff] [blame] | 88 | beforeEach(async(() => { |
Sean Condon | 2bd11b7 | 2018-06-15 08:00:48 +0100 | [diff] [blame] | 89 | const logSpy = jasmine.createSpyObj('LogService', ['info', 'debug', 'warn', 'error']); |
| 90 | ar = new MockActivatedRoute({'debug': 'txrx'}); |
| 91 | |
| 92 | windowMock = <any>{ |
| 93 | location: <any> { |
| 94 | hostname: 'foo', |
| 95 | host: 'foo', |
| 96 | port: '80', |
| 97 | protocol: 'http', |
| 98 | search: { debug: 'true'}, |
| 99 | href: 'ws://foo:123/onos/ui/websock/path', |
| 100 | absUrl: 'ws://foo:123/onos/ui/websock/path' |
| 101 | } |
| 102 | }; |
| 103 | fs = new FnService(ar, logSpy, windowMock); |
| 104 | |
Sean Condon | 49e15be | 2018-05-16 16:58:29 +0100 | [diff] [blame] | 105 | TestBed.configureTestingModule({ |
Sean Condon | 2bd11b7 | 2018-06-15 08:00:48 +0100 | [diff] [blame] | 106 | declarations: [ DeviceComponent, IconComponent ], |
Sean Condon | 49e15be | 2018-05-16 16:58:29 +0100 | [diff] [blame] | 107 | providers: [ |
Sean Condon | 2bd11b7 | 2018-06-15 08:00:48 +0100 | [diff] [blame] | 108 | { provide: FnService, useValue: fs }, |
Sean Condon | 49e15be | 2018-05-16 16:58:29 +0100 | [diff] [blame] | 109 | { provide: IconService, useClass: MockIconService }, |
Sean Condon | fd6d11b | 2018-06-02 20:29:49 +0100 | [diff] [blame] | 110 | { provide: GlyphService, useClass: MockGlyphService }, |
Sean Condon | 49e15be | 2018-05-16 16:58:29 +0100 | [diff] [blame] | 111 | { provide: KeyService, useClass: MockKeyService }, |
| 112 | { provide: LoadingService, useClass: MockLoadingService }, |
| 113 | { provide: MastService, useClass: MockMastService }, |
| 114 | { provide: NavService, useClass: MockNavService }, |
Sean Condon | 2bd11b7 | 2018-06-15 08:00:48 +0100 | [diff] [blame] | 115 | { provide: LogService, useValue: logSpy }, |
Sean Condon | 2bd11b7 | 2018-06-15 08:00:48 +0100 | [diff] [blame] | 116 | { provide: ThemeService, useClass: MockThemeService }, |
Sean Condon | 49e15be | 2018-05-16 16:58:29 +0100 | [diff] [blame] | 117 | { provide: WebSocketService, useClass: MockWebSocketService }, |
Sean Condon | a00bf38 | 2018-06-23 07:54:01 +0100 | [diff] [blame] | 118 | { provide: 'Window', useValue: windowMock }, |
Sean Condon | 49e15be | 2018-05-16 16:58:29 +0100 | [diff] [blame] | 119 | ] |
| 120 | }) |
| 121 | .compileComponents(); |
Sean Condon | 2bd11b7 | 2018-06-15 08:00:48 +0100 | [diff] [blame] | 122 | logServiceSpy = TestBed.get(LogService); |
Sean Condon | 49e15be | 2018-05-16 16:58:29 +0100 | [diff] [blame] | 123 | })); |
Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 124 | |
Sean Condon | 49e15be | 2018-05-16 16:58:29 +0100 | [diff] [blame] | 125 | beforeEach(() => { |
| 126 | fixture = TestBed.createComponent(DeviceComponent); |
Sean Condon | 2bd11b7 | 2018-06-15 08:00:48 +0100 | [diff] [blame] | 127 | component = fixture.debugElement.componentInstance; |
Sean Condon | 49e15be | 2018-05-16 16:58:29 +0100 | [diff] [blame] | 128 | fixture.detectChanges(); |
| 129 | }); |
| 130 | |
| 131 | it('should create', () => { |
| 132 | expect(component).toBeTruthy(); |
| 133 | }); |
Sean Condon | 2bd11b7 | 2018-06-15 08:00:48 +0100 | [diff] [blame] | 134 | |
| 135 | it('should have .table-header with "Friendly Name..."', () => { |
| 136 | const appDe: DebugElement = fixture.debugElement; |
| 137 | const divDe = appDe.query(By.css('.table-header')); |
| 138 | const div: HTMLElement = divDe.nativeElement; |
| 139 | expect(div.textContent).toEqual('Friendly Name Device ID Master Ports Vendor H/W Version S/W Version Protocol '); |
| 140 | }); |
Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 141 | }); |