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 | |
| 18 | import { PortDetailsComponent } from './portdetails.component'; |
| 19 | import { ActivatedRoute, Params } from '@angular/router'; |
| 20 | import { of } from 'rxjs/index'; |
| 21 | import { LogService } from '../../../log.service'; |
| 22 | import { FnService } from '../../../fw/util/fn.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 | classes = 'active-close'; |
| 39 | loadIconDef() { } |
| 40 | } |
| 41 | |
| 42 | class MockWebSocketService { |
| 43 | createWebSocket() { } |
| 44 | isConnected() { return false; } |
| 45 | unbindHandlers() { } |
| 46 | bindHandlers() { } |
| 47 | } |
| 48 | |
| 49 | describe('PortdetailsComponent', () => { |
| 50 | let fs: FnService; |
| 51 | let ar: MockActivatedRoute; |
| 52 | let windowMock: Window; |
| 53 | let logServiceSpy: jasmine.SpyObj<LogService>; |
| 54 | let component: PortDetailsComponent; |
| 55 | let fixture: ComponentFixture<PortDetailsComponent>; |
| 56 | |
| 57 | beforeEach(async(() => { |
| 58 | const logSpy = jasmine.createSpyObj('LogService', ['info', 'debug', 'warn', 'error']); |
| 59 | ar = new MockActivatedRoute({ 'debug': 'panel' }); |
| 60 | windowMock = <any>{ |
| 61 | location: <any>{ |
| 62 | hostname: 'foo', |
| 63 | host: 'foo', |
| 64 | port: '80', |
| 65 | protocol: 'http', |
| 66 | search: { debug: 'true' }, |
| 67 | href: 'ws://foo:123/onos/ui/websock/path', |
| 68 | absUrl: 'ws://foo:123/onos/ui/websock/path' |
| 69 | } |
| 70 | }; |
| 71 | fs = new FnService(ar, logSpy, windowMock); |
| 72 | |
| 73 | TestBed.configureTestingModule({ |
| 74 | imports: [BrowserAnimationsModule], |
| 75 | declarations: [PortDetailsComponent, IconComponent], |
| 76 | providers: [ |
| 77 | { provide: FnService, useValue: fs }, |
| 78 | { provide: IconService, useClass: MockIconService }, |
| 79 | { provide: LogService, useValue: logSpy }, |
| 80 | { provide: WebSocketService, useClass: MockWebSocketService }, |
| 81 | { provide: 'Window', useValue: windowMock }, |
| 82 | ] |
| 83 | |
| 84 | }).compileComponents(); |
| 85 | logServiceSpy = TestBed.get(LogService); |
| 86 | })); |
| 87 | |
| 88 | beforeEach(() => { |
| 89 | fixture = TestBed.createComponent(PortDetailsComponent); |
| 90 | component = fixture.componentInstance; |
| 91 | fixture.detectChanges(); |
| 92 | }); |
| 93 | |
| 94 | it('should create', () => { |
| 95 | expect(component).toBeTruthy(); |
| 96 | }); |
| 97 | |
| 98 | it('should have an div.close-btn div.top inside a div.container', () => { |
| 99 | const portDe: DebugElement = fixture.debugElement; |
| 100 | const divDe = portDe.query(By.css('div.container div.top div.close-btn')); |
| 101 | expect(divDe).toBeTruthy(); |
| 102 | }); |
| 103 | |
| 104 | it('should have a div.port-icon inside a div.top inside a div.container', () => { |
| 105 | const portDe: DebugElement = fixture.debugElement; |
| 106 | const divDe = portDe.query(By.css('div.container div.top div.port-icon')); |
| 107 | const div: HTMLElement = divDe.nativeElement; |
| 108 | expect(div.textContent).toEqual(''); |
| 109 | }); |
| 110 | |
| 111 | it('should have a div.top-content inside a div.top inside a div.container', () => { |
| 112 | const portDe: DebugElement = fixture.debugElement; |
| 113 | const divDe = portDe.query(By.css('div.container div.top div.top-content')); |
| 114 | expect(divDe).toBeTruthy(); |
| 115 | }); |
| 116 | |
| 117 | it('should have a dev.left inside a div.top-tables inside a div.top-content', () => { |
| 118 | const portDe: DebugElement = fixture.debugElement; |
| 119 | const divDe = portDe.query(By.css('div.top-content div.top-tables div.left')); |
| 120 | const div: HTMLElement = divDe.nativeElement; |
| 121 | expect(div.textContent).toEqual('ID :Device :Type :Speed :Enabled :'); |
| 122 | }); |
| 123 | }); |