Bhavesh Kumar | d0b8bae | 2018-07-31 16:56:43 +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 | |
| 18 | import { SettingsComponent } from './settings.component'; |
| 19 | import { ActivatedRoute, Params } from '@angular/router'; |
| 20 | import { of } from 'rxjs'; |
| 21 | import { FnService } from '../../../fw/util/fn.service'; |
| 22 | import { LogService } from '../../../log.service'; |
| 23 | import { IconComponent } from '../../../fw/svg/icon/icon.component'; |
| 24 | import { IconService } from '../../../fw/svg/icon.service'; |
| 25 | import { LoadingService } from '../../../fw/layer/loading.service'; |
| 26 | import { WebSocketService } from '../../../fw/remote/websocket.service'; |
| 27 | import { DebugElement } from '@angular/core'; |
| 28 | import { By } from '@angular/platform-browser'; |
| 29 | import { SettingsDetailsComponent } from '../settingsdetails/settingsdetails.component'; |
| 30 | import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; |
| 31 | |
| 32 | class MockActivatedRoute extends ActivatedRoute { |
| 33 | constructor(params: Params) { |
| 34 | super(); |
| 35 | this.queryParams = of(params); |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | class MockIconService { |
| 40 | loadIconDef() { } |
| 41 | } |
| 42 | |
| 43 | class MockLoadingService { |
| 44 | startAnim() { } |
| 45 | stop() { } |
| 46 | waiting() { } |
| 47 | } |
| 48 | |
| 49 | class MockWebSocketService { |
| 50 | createWebSocket() { } |
| 51 | isConnected() { return false; } |
| 52 | unbindHandlers() { } |
| 53 | bindHandlers() { } |
| 54 | } |
| 55 | |
| 56 | /** |
| 57 | * ONOS GUI -- Settings View Module - Unit Tests |
| 58 | */ |
| 59 | describe('SettingsComponent', () => { |
| 60 | let fs: FnService; |
| 61 | let ar: MockActivatedRoute; |
| 62 | let windowMock: Window; |
| 63 | let logServiceSpy: jasmine.SpyObj<LogService>; |
| 64 | let component: SettingsComponent; |
| 65 | let fixture: ComponentFixture<SettingsComponent>; |
| 66 | |
| 67 | const logSpy = jasmine.createSpyObj('LogService', ['info', 'debug', 'warn', 'error']); |
| 68 | ar = new MockActivatedRoute({ 'debug': 'txrx' }); |
| 69 | |
| 70 | windowMock = <any>{ |
| 71 | location: <any>{ |
| 72 | settingsname: 'foo', |
| 73 | settings: 'foo', |
| 74 | port: '80', |
| 75 | protocol: 'http', |
| 76 | search: { debug: 'true' }, |
| 77 | href: 'ws://foo:123/onos/ui/websock/path', |
| 78 | absUrl: 'ws://foo:123/onos/ui/websock/path' |
| 79 | } |
| 80 | }; |
| 81 | fs = new FnService(ar, logSpy, windowMock); |
| 82 | |
| 83 | beforeEach(async(() => { |
| 84 | TestBed.configureTestingModule({ |
| 85 | imports: [BrowserAnimationsModule], |
| 86 | declarations: [SettingsComponent, IconComponent, SettingsDetailsComponent], |
| 87 | providers: [ |
| 88 | { provide: FnService, useValue: fs }, |
| 89 | { provide: IconService, useClass: MockIconService }, |
| 90 | { provide: LoadingService, useClass: MockLoadingService }, |
| 91 | { provide: LogService, useValue: logSpy }, |
| 92 | { provide: WebSocketService, useClass: MockWebSocketService }, |
| 93 | ] |
| 94 | }) |
| 95 | .compileComponents(); |
| 96 | logServiceSpy = TestBed.get(LogService); |
| 97 | })); |
| 98 | |
| 99 | beforeEach(() => { |
| 100 | fixture = TestBed.createComponent(SettingsComponent); |
| 101 | component = fixture.componentInstance; |
| 102 | fixture.detectChanges(); |
| 103 | }); |
| 104 | |
| 105 | it('should create', () => { |
| 106 | expect(component).toBeTruthy(); |
| 107 | }); |
| 108 | |
| 109 | it('should have a div.tabular-header inside a div#ov-settings', () => { |
| 110 | const settingsDe: DebugElement = fixture.debugElement; |
| 111 | const divDe = settingsDe.query(By.css('div#ov-settings div.tabular-header')); |
| 112 | expect(divDe).toBeTruthy(); |
| 113 | }); |
| 114 | |
| 115 | it('should have a h2 inside the div.tabular-header', () => { |
| 116 | const settingsDe: DebugElement = fixture.debugElement; |
| 117 | const divDe = settingsDe.query(By.css('div#ov-settings div.tabular-header h2')); |
| 118 | const div: HTMLElement = divDe.nativeElement; |
| 119 | expect(div.textContent).toEqual('Component Settings (0 total)'); |
| 120 | }); |
| 121 | |
| 122 | it('should have a refresh button inside the div.tabular-header', () => { |
| 123 | const settingsDe: DebugElement = fixture.debugElement; |
| 124 | const divDe = settingsDe.query(By.css('div#ov-settings div.tabular-header div.ctrl-btns div.refresh')); |
| 125 | expect(divDe).toBeTruthy(); |
| 126 | }); |
| 127 | |
| 128 | it('should have a div.summary-list inside a div#ov-settings', () => { |
| 129 | const settingsDe: DebugElement = fixture.debugElement; |
| 130 | const divDe = settingsDe.query(By.css('div#ov-settings div.summary-list')); |
| 131 | expect(divDe).toBeTruthy(); |
| 132 | }); |
| 133 | |
| 134 | it('should have a div.table-header inside a div.summary-list inside a div#ov-settings', () => { |
| 135 | const settingsDe: DebugElement = fixture.debugElement; |
| 136 | const divDe = settingsDe.query(By.css('div#ov-settings div.summary-list div.table-header')); |
| 137 | expect(divDe).toBeTruthy(); |
| 138 | }); |
| 139 | |
| 140 | it('should have a div.table-body inside a div.summary-list inside a div#ov-settings', () => { |
| 141 | const settingsDe: DebugElement = fixture.debugElement; |
| 142 | const divDe = settingsDe.query(By.css('div#ov-settings div.summary-list div.table-body')); |
| 143 | expect(divDe).toBeTruthy(); |
| 144 | }); |
| 145 | }); |