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 { SettingsDetailsComponent } from './settingsdetails.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 { BrowserAnimationsModule } from '@angular/platform-browser/animations'; |
| 24 | import { IconComponent } from '../../../fw/svg/icon/icon.component'; |
| 25 | import { IconService } from '../../../fw/svg/icon.service'; |
| 26 | import { WebSocketService } from '../../../fw/remote/websocket.service'; |
| 27 | import { DebugElement } from '@angular/core'; |
| 28 | import { By } from '@angular/platform-browser'; |
| 29 | |
| 30 | class MockActivatedRoute extends ActivatedRoute { |
| 31 | constructor(params: Params) { |
| 32 | super(); |
| 33 | this.queryParams = of(params); |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | class MockIconService { |
| 38 | loadIconDef() { } |
| 39 | } |
| 40 | |
| 41 | class MockWebSocketService { |
| 42 | createWebSocket() { } |
| 43 | isConnected() { return false; } |
| 44 | unbindHandlers() { } |
| 45 | bindHandlers() { } |
| 46 | } |
| 47 | |
| 48 | /** |
| 49 | * ONOS GUI -- Settings Detail Panel View -- Unit Tests |
| 50 | */ |
| 51 | describe('SettingsdetailsComponent', () => { |
| 52 | let component: SettingsDetailsComponent; |
| 53 | let fixture: ComponentFixture<SettingsDetailsComponent>; |
| 54 | let fs: FnService; |
| 55 | let ar: MockActivatedRoute; |
| 56 | let windowMock: Window; |
| 57 | let logServiceSpy: jasmine.SpyObj<LogService>; |
| 58 | |
| 59 | beforeEach(async(() => { |
| 60 | const logSpy = jasmine.createSpyObj('LogService', ['info', 'debug', 'warn', 'error']); |
| 61 | ar = new MockActivatedRoute({ 'debug': 'panel' }); |
| 62 | windowMock = <any>{ |
| 63 | location: <any>{ |
| 64 | settingsname: 'foo', |
| 65 | settings: 'foo', |
| 66 | port: '80', |
| 67 | protocol: 'http', |
| 68 | search: { debug: 'true' }, |
| 69 | href: 'ws://foo:123/onos/ui/websock/path', |
| 70 | absUrl: 'ws://foo:123/onos/ui/websock/path' |
| 71 | } |
| 72 | }; |
| 73 | fs = new FnService(ar, logSpy, windowMock); |
| 74 | TestBed.configureTestingModule({ |
| 75 | imports: [BrowserAnimationsModule], |
| 76 | declarations: [SettingsDetailsComponent, IconComponent], |
| 77 | providers: [ |
| 78 | { provide: FnService, useValue: fs }, |
| 79 | { provide: IconService, useClass: MockIconService }, |
| 80 | { provide: LogService, useValue: logSpy }, |
| 81 | { provide: WebSocketService, useClass: MockWebSocketService }, |
| 82 | { provide: 'Window', useValue: windowMock }, |
| 83 | ] |
| 84 | }) |
| 85 | .compileComponents(); |
| 86 | logServiceSpy = TestBed.get(LogService); |
| 87 | })); |
| 88 | |
| 89 | beforeEach(() => { |
| 90 | fixture = TestBed.createComponent(SettingsDetailsComponent); |
| 91 | component = fixture.componentInstance; |
| 92 | fixture.detectChanges(); |
| 93 | }); |
| 94 | |
| 95 | it('should create', () => { |
| 96 | expect(component).toBeTruthy(); |
| 97 | }); |
| 98 | |
| 99 | it('should have an onos-icon.close-btn inside a div.top inside a div.container', () => { |
| 100 | const settingsDe: DebugElement = fixture.debugElement; |
| 101 | const divDe = settingsDe.query(By.css('div.container div.top onos-icon.close-btn')); |
| 102 | expect(divDe).toBeTruthy(); |
| 103 | }); |
| 104 | |
| 105 | it('should have a div.top-content inside a div.container', () => { |
| 106 | const settingsDe: DebugElement = fixture.debugElement; |
| 107 | const divDe = settingsDe.query(By.css('div.container div.top-content')); |
| 108 | expect(divDe).toBeTruthy(); |
| 109 | }); |
| 110 | |
| 111 | it('should have a div.settings-title-1 inside a div.top-content inside a div.container', () => { |
| 112 | const settingsDe: DebugElement = fixture.debugElement; |
| 113 | const divDe = settingsDe.query(By.css('div.container div.top-content div.settings-title-1')); |
| 114 | expect(divDe).toBeTruthy(); |
| 115 | }); |
| 116 | |
| 117 | it('should have a div.settings-title-2 inside a div.top-content inside a div.container', () => { |
| 118 | const settingsDe: DebugElement = fixture.debugElement; |
| 119 | const divDe = settingsDe.query(By.css('div.container div.top-content div.settings-title-2')); |
| 120 | expect(divDe).toBeTruthy(); |
| 121 | }); |
| 122 | |
| 123 | it('should have a div.settings-props inside a div.top-content inside a div.container', () => { |
| 124 | const settingsDe: DebugElement = fixture.debugElement; |
| 125 | const divDe = settingsDe.query(By.css('div.container div.top-content div.settings-props')); |
| 126 | expect(divDe).toBeTruthy(); |
| 127 | }); |
| 128 | }); |