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