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