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