Bhavesh | 72ead49 | 2018-07-19 16:29:18 +0530 | [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 { BrowserAnimationsModule } from '@angular/platform-browser/animations'; |
| 19 | import { DebugElement } from '@angular/core'; |
| 20 | import { By } from '@angular/platform-browser'; |
| 21 | |
| 22 | import { LogService } from '../../../log.service'; |
| 23 | import { FnService } from '../../../../app/fw/util/fn.service'; |
| 24 | import { IconComponent } from '../../../../app/fw/svg/icon/icon.component'; |
| 25 | import { IconService } from '../../../../app/fw/svg/icon.service'; |
| 26 | import { UrlFnService } from '../../../fw/remote/urlfn.service'; |
| 27 | import { WebSocketService } from '../../../fw/remote/websocket.service'; |
| 28 | import { of } from 'rxjs'; |
| 29 | import { } from 'jasmine'; |
| 30 | |
| 31 | import { HostDetailsComponent } from './hostdetails.component'; |
| 32 | |
| 33 | class MockActivatedRoute extends ActivatedRoute { |
| 34 | constructor(params: Params) { |
| 35 | super(); |
| 36 | this.queryParams = of(params); |
| 37 | } |
| 38 | } |
| 39 | |
| 40 | class MockFnService { } |
| 41 | |
| 42 | class MockIconService { |
| 43 | loadIconDef() { } |
| 44 | } |
| 45 | |
| 46 | class MockUrlFnService { } |
| 47 | |
| 48 | class MockWebSocketService { |
| 49 | createWebSocket() { } |
| 50 | isConnected() { return false; } |
| 51 | unbindHandlers() { } |
| 52 | bindHandlers() { } |
| 53 | } |
| 54 | |
| 55 | /** |
| 56 | * ONOS GUI -- Host Detail Panel View -- Unit Tests |
| 57 | */ |
| 58 | |
| 59 | describe('HostdetailsComponent', () => { |
| 60 | let fs: FnService; |
| 61 | let ar: MockActivatedRoute; |
| 62 | let windowMock: Window; |
| 63 | let logServiceSpy: jasmine.SpyObj<LogService>; |
| 64 | let component: HostDetailsComponent; |
| 65 | let fixture: ComponentFixture<HostDetailsComponent>; |
| 66 | |
| 67 | const bundleObj = { |
| 68 | 'core.view.Hosts': { |
| 69 | } |
| 70 | }; |
| 71 | |
| 72 | const mockLion = (key) => { |
| 73 | return bundleObj[key] || '%' + key + '%'; |
| 74 | }; |
| 75 | |
| 76 | beforeEach(async(() => { |
| 77 | |
| 78 | const logSpy = jasmine.createSpyObj('LogService', ['info', 'debug', 'warn', 'error']); |
| 79 | ar = new MockActivatedRoute({ 'debug': 'panel' }); |
| 80 | |
| 81 | windowMock = <any>{ |
| 82 | location: <any>{ |
| 83 | hostname: 'foo', |
| 84 | host: 'foo', |
| 85 | port: '80', |
| 86 | protocol: 'http', |
| 87 | search: { debug: 'true' }, |
| 88 | href: 'ws://foo:123/onos/ui/websock/path', |
| 89 | absUrl: 'ws://foo:123/onos/ui/websock/path' |
| 90 | } |
| 91 | }; |
| 92 | fs = new FnService(ar, logSpy, windowMock); |
| 93 | TestBed.configureTestingModule({ |
| 94 | imports: [BrowserAnimationsModule], |
| 95 | declarations: [HostDetailsComponent, IconComponent], |
| 96 | providers: [ |
| 97 | { provide: FnService, useValue: fs }, |
| 98 | { provide: IconService, useClass: MockIconService }, |
| 99 | { provide: LogService, useValue: logSpy }, |
| 100 | { provide: UrlFnService, useClass: MockUrlFnService }, |
| 101 | { provide: WebSocketService, useClass: MockWebSocketService }, |
| 102 | { provide: 'Window', useValue: windowMock }, |
| 103 | ] |
| 104 | }) |
| 105 | .compileComponents(); |
| 106 | logServiceSpy = TestBed.get(LogService); |
| 107 | })); |
| 108 | |
| 109 | beforeEach(() => { |
| 110 | fixture = TestBed.createComponent(HostDetailsComponent); |
| 111 | component = fixture.componentInstance; |
| 112 | fixture.detectChanges(); |
| 113 | }); |
| 114 | |
| 115 | it('should create', () => { |
| 116 | expect(component).toBeTruthy(); |
| 117 | }); |
| 118 | |
| 119 | it('should have an onos-icon.close-btn inside a div.top inside a div.container', () => { |
| 120 | const hostDe: DebugElement = fixture.debugElement; |
| 121 | const divDe = hostDe.query(By.css('div.container div.top onos-icon.close-btn')); |
| 122 | expect(divDe).toBeTruthy(); |
| 123 | }); |
| 124 | |
| 125 | it('should have a div.host-icon inside a div.container', () => { |
| 126 | const hostDe: DebugElement = fixture.debugElement; |
| 127 | const divDe = hostDe.query(By.css('div.container div.host-icon')); |
| 128 | expect(divDe).toBeTruthy(); |
| 129 | }); |
| 130 | |
| 131 | it('should have a h2 inside the div.container', () => { |
| 132 | const hostDe: DebugElement = fixture.debugElement; |
| 133 | const divDe = hostDe.query(By.css('div#host-details-panel div.container h2')); |
| 134 | const div: HTMLElement = divDe.nativeElement; |
| 135 | expect(div.textContent).toEqual(''); |
| 136 | }); |
| 137 | |
| 138 | it('should have a div.top-content inside a div.container', () => { |
| 139 | const hostDe: DebugElement = fixture.debugElement; |
| 140 | const divDe = hostDe.query(By.css('div.container div.top-content')); |
| 141 | expect(divDe).toBeTruthy(); |
| 142 | }); |
| 143 | |
| 144 | it('should have a div.top-tables inside a div.top-content inside a div.container', () => { |
| 145 | const hostDe: DebugElement = fixture.debugElement; |
| 146 | const divDe = hostDe.query(By.css('div.container div.top-content div.top-tables')); |
| 147 | expect(divDe).toBeTruthy(); |
| 148 | }); |
| 149 | |
| 150 | it('should have a div.left inside a div.top-tables inside a div.top-content inside a div.container', () => { |
| 151 | const hostDe: DebugElement = fixture.debugElement; |
| 152 | const divDe = hostDe.query(By.css('div.container div.top-content div.top-tables div.left')); |
| 153 | expect(divDe).toBeTruthy(); |
| 154 | }); |
| 155 | |
| 156 | it('should have a div.right inside a div.top-tables inside a div.top-content inside a div.container', () => { |
| 157 | const hostDe: DebugElement = fixture.debugElement; |
| 158 | const divDe = hostDe.query(By.css('div.container div.top-content div.top-tables div.right')); |
| 159 | expect(divDe).toBeTruthy(); |
| 160 | }); |
| 161 | |
| 162 | it('should have a div.bottom inside a div.container', () => { |
| 163 | const hostDe: DebugElement = fixture.debugElement; |
| 164 | const divDe = hostDe.query(By.css('div.container div.bottom')); |
| 165 | expect(divDe).toBeTruthy(); |
| 166 | }); |
| 167 | }); |