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 { FormsModule } from '@angular/forms'; |
| 20 | import { DebugElement } from '@angular/core'; |
| 21 | import { By } from '@angular/platform-browser'; |
| 22 | |
| 23 | import { LogService } from '../../../log.service'; |
| 24 | import { HostComponent } from './host.component'; |
| 25 | import { HostDetailsComponent } from '../hostdetails/hostdetails.component'; |
| 26 | import { DialogService } from '../../../fw/layer/dialog.service'; |
| 27 | import { FnService } from '../../../fw/util/fn.service'; |
| 28 | import { IconComponent } from '../../../fw/svg/icon/icon.component'; |
| 29 | import { IconService } from '../../../fw/svg/icon.service'; |
| 30 | import { KeyService } from '../../../fw/util/key.service'; |
| 31 | import { LoadingService } from '../../../fw/layer/loading.service'; |
| 32 | import { ThemeService } from '../../../fw/util/theme.service'; |
| 33 | import { TableFilterPipe } from '../../../fw/widget/tablefilter.pipe'; |
| 34 | import { UrlFnService } from '../../../fw/remote/urlfn.service'; |
| 35 | import { WebSocketService } from '../../../fw/remote/websocket.service'; |
| 36 | import { of } from 'rxjs'; |
| 37 | import { } from 'jasmine'; |
| 38 | |
| 39 | class MockActivatedRoute extends ActivatedRoute { |
| 40 | constructor(params: Params) { |
| 41 | super(); |
| 42 | this.queryParams = of(params); |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | class MockDialogService { } |
| 47 | |
| 48 | class MockFnService { } |
| 49 | |
| 50 | class MockIconService { |
| 51 | loadIconDef() { } |
| 52 | } |
| 53 | |
| 54 | class MockKeyService { } |
| 55 | |
| 56 | class MockLoadingService { |
| 57 | startAnim() { } |
| 58 | stop() { } |
| 59 | waiting() { } |
| 60 | } |
| 61 | |
| 62 | class MockThemeService { } |
| 63 | |
| 64 | class MockUrlFnService { } |
| 65 | |
| 66 | class MockWebSocketService { |
| 67 | createWebSocket() { } |
| 68 | isConnected() { return false; } |
| 69 | unbindHandlers() { } |
| 70 | bindHandlers() { } |
| 71 | } |
| 72 | |
| 73 | |
| 74 | describe('HostComponent', () => { |
| 75 | |
| 76 | let fs: FnService; |
| 77 | let ar: MockActivatedRoute; |
| 78 | let windowMock: Window; |
| 79 | let logServiceSpy: jasmine.SpyObj<LogService>; |
| 80 | let component: HostComponent; |
| 81 | let fixture: ComponentFixture<HostComponent>; |
| 82 | const bundleObj = { |
| 83 | 'core.view.Host': { |
| 84 | test: 'test1' |
| 85 | } |
| 86 | }; |
| 87 | const mockLion = (key) => { |
| 88 | return bundleObj[key] || '%' + key + '%'; |
| 89 | }; |
| 90 | |
| 91 | |
| 92 | beforeEach(async(() => { |
| 93 | const logSpy = jasmine.createSpyObj('LogService', ['info', 'debug', 'warn', 'error']); |
| 94 | ar = new MockActivatedRoute({ 'debug': 'txrx' }); |
| 95 | |
| 96 | windowMock = <any>{ |
| 97 | location: <any>{ |
| 98 | hostname: 'foo', |
| 99 | host: 'foo', |
| 100 | port: '80', |
| 101 | protocol: 'http', |
| 102 | search: { debug: 'true' }, |
| 103 | href: 'ws://foo:123/onos/ui/websock/path', |
| 104 | absUrl: 'ws://foo:123/onos/ui/websock/path' |
| 105 | } |
| 106 | }; |
| 107 | fs = new FnService(ar, logSpy, windowMock); |
| 108 | |
| 109 | TestBed.configureTestingModule({ |
| 110 | imports: [BrowserAnimationsModule, FormsModule], |
| 111 | declarations: [HostComponent, HostDetailsComponent, IconComponent, TableFilterPipe], |
| 112 | providers: [ |
| 113 | { provide: DialogService, useClass: MockDialogService }, |
| 114 | { provide: FnService, useValue: fs }, |
| 115 | { provide: IconService, useClass: MockIconService }, |
| 116 | { provide: KeyService, useClass: MockKeyService }, |
| 117 | { provide: LoadingService, useClass: MockLoadingService }, |
| 118 | { provide: LogService, useValue: logSpy }, |
| 119 | { provide: ThemeService, useClass: MockThemeService }, |
| 120 | { provide: UrlFnService, useClass: MockUrlFnService }, |
| 121 | { provide: WebSocketService, useClass: MockWebSocketService }, |
| 122 | { provide: 'Window', useValue: windowMock }, |
| 123 | ] |
| 124 | }) |
| 125 | .compileComponents(); |
| 126 | logServiceSpy = TestBed.get(LogService); |
| 127 | })); |
| 128 | |
| 129 | beforeEach(() => { |
| 130 | fixture = TestBed.createComponent(HostComponent); |
| 131 | component = fixture.componentInstance; |
| 132 | fixture.detectChanges(); |
| 133 | }); |
| 134 | |
| 135 | it('should create', () => { |
| 136 | expect(component).toBeTruthy(); |
| 137 | }); |
| 138 | |
| 139 | it('should have a div.tabular-header inside a div#ov-host', () => { |
| 140 | const hostDe: DebugElement = fixture.debugElement; |
| 141 | const divDe = hostDe.query(By.css('div#ov-host div.tabular-header')); |
| 142 | expect(divDe).toBeTruthy(); |
| 143 | }); |
| 144 | |
| 145 | it('should have a h2 inside the div.tabular-header', () => { |
| 146 | const hostDe: DebugElement = fixture.debugElement; |
| 147 | const divDe = hostDe.query(By.css('div#ov-host div.tabular-header h2')); |
| 148 | const div: HTMLElement = divDe.nativeElement; |
| 149 | expect(div.textContent).toEqual('Hosts (0 total)'); |
| 150 | }); |
| 151 | |
| 152 | it('should have a refresh button inside the div.tabular-header', () => { |
| 153 | const hostDe: DebugElement = fixture.debugElement; |
| 154 | const divDe = hostDe.query(By.css('div#ov-host div.tabular-header div.ctrl-btns div.refresh')); |
| 155 | expect(divDe).toBeTruthy(); |
| 156 | }); |
| 157 | |
| 158 | it('should have a div.summary-list inside a div#ov-host', () => { |
| 159 | const hostDe: DebugElement = fixture.debugElement; |
| 160 | const divDe = hostDe.query(By.css('div#ov-host div.summary-list')); |
| 161 | expect(divDe).toBeTruthy(); |
| 162 | }); |
| 163 | |
| 164 | it('should have a div.table-header inside a div.summary-list inside a div#ov-host', () => { |
| 165 | const hostDe: DebugElement = fixture.debugElement; |
| 166 | const divDe = hostDe.query(By.css('div#ov-host div.summary-list div.table-header')); |
| 167 | expect(divDe).toBeTruthy(); |
| 168 | }); |
| 169 | |
| 170 | it('should have a div.table-body inside a div.summary-list inside a div#ov-host', () => { |
| 171 | const hostDe: DebugElement = fixture.debugElement; |
| 172 | const divDe = hostDe.query(By.css('div#ov-host div.summary-list div.table-body')); |
| 173 | expect(divDe).toBeTruthy(); |
| 174 | }); |
| 175 | |
| 176 | }); |