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 { FlowComponent } from './flow.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 { FormsModule } from '@angular/forms'; |
| 25 | import { RouterTestingModule } from '@angular/router/testing'; |
| 26 | import { TableFilterPipe } from '../../../fw/widget/tablefilter.pipe'; |
| 27 | import { IconComponent } from '../../../fw/svg/icon/icon.component'; |
| 28 | import { IconService } from '../../../fw/svg/icon.service'; |
| 29 | import { GlyphService } from '../../../fw/svg/glyph.service'; |
| 30 | import { KeyService } from '../../../fw/util/key.service'; |
| 31 | import { LoadingService } from '../../../fw/layer/loading.service'; |
| 32 | import { MastService } from '../../../fw/mast/mast.service'; |
| 33 | import { NavService } from '../../../fw/nav/nav.service'; |
| 34 | import { ThemeService } from '../../../fw/util/theme.service'; |
| 35 | import { WebSocketService } from '../../../fw/remote/websocket.service'; |
| 36 | import { DebugElement } from '@angular/core'; |
| 37 | import { By } from '@angular/platform-browser'; |
| 38 | import { LionService } from '../../../fw/util/lion.service'; |
| 39 | import { FlowDetailsComponent } from '../flowdetails/flowdetails/flowdetails.component'; |
| 40 | |
| 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 MockGlyphService { } |
| 53 | |
| 54 | class MockKeyService { } |
| 55 | |
| 56 | class MockLoadingService { |
| 57 | startAnim() { } |
| 58 | stop() { } |
| 59 | } |
| 60 | |
| 61 | class MockNavService { } |
| 62 | |
| 63 | class MockMastService { } |
| 64 | |
| 65 | class MockThemeService { } |
| 66 | |
| 67 | class MockWebSocketService { |
| 68 | createWebSocket() { } |
| 69 | isConnected() { return false; } |
| 70 | unbindHandlers() { } |
| 71 | bindHandlers() { } |
| 72 | } |
| 73 | |
| 74 | /** |
| 75 | * ONOS GUI -- Flow View Module - Unit Tests |
| 76 | */ |
| 77 | |
| 78 | describe('FlowComponent', () => { |
| 79 | let fs: FnService; |
| 80 | let ar: MockActivatedRoute; |
| 81 | let windowMock: Window; |
| 82 | let logServiceSpy: jasmine.SpyObj<LogService>; |
| 83 | let component: FlowComponent; |
| 84 | let fixture: ComponentFixture<FlowComponent>; |
| 85 | |
| 86 | const bundleObj = { |
| 87 | 'core.view.Flow': { |
| 88 | test: 'test1' |
| 89 | } |
| 90 | }; |
| 91 | const mockLion = (key) => { |
| 92 | return bundleObj[key] || '%' + key + '%'; |
| 93 | }; |
| 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: [FlowComponent, IconComponent, TableFilterPipe, FlowDetailsComponent], |
| 115 | providers: [ |
| 116 | { provide: FnService, useValue: fs }, |
| 117 | { provide: IconService, useClass: MockIconService }, |
| 118 | { provide: GlyphService, useClass: MockGlyphService }, |
| 119 | { provide: KeyService, useClass: MockKeyService }, |
| 120 | { |
| 121 | provide: LionService, useFactory: (() => { |
| 122 | return { |
| 123 | bundle: ((bundleId) => mockLion), |
| 124 | ubercache: new Array(), |
| 125 | loadCbs: new Map<string, () => void>([]) |
| 126 | }; |
| 127 | }) |
| 128 | }, |
| 129 | { provide: LoadingService, useClass: MockLoadingService }, |
| 130 | { provide: MastService, useClass: MockMastService }, |
| 131 | { provide: NavService, useClass: MockNavService }, |
| 132 | { provide: LogService, useValue: logSpy }, |
| 133 | { provide: ThemeService, useClass: MockThemeService }, |
| 134 | { provide: WebSocketService, useClass: MockWebSocketService }, |
| 135 | { provide: 'Window', useValue: windowMock }, |
| 136 | ] |
| 137 | }).compileComponents(); |
| 138 | logServiceSpy = TestBed.get(LogService); |
| 139 | })); |
| 140 | |
| 141 | beforeEach(() => { |
| 142 | fixture = TestBed.createComponent(FlowComponent); |
| 143 | component = fixture.componentInstance; |
| 144 | fixture.detectChanges(); |
| 145 | }); |
| 146 | |
| 147 | it('should create', () => { |
| 148 | expect(component).toBeTruthy(); |
| 149 | }); |
| 150 | |
| 151 | it('should have a div.tabular-header inside a div#ov-flow', () => { |
| 152 | const flowDe: DebugElement = fixture.debugElement; |
| 153 | const divDe = flowDe.query(By.css('div#ov-flow div.tabular-header')); |
| 154 | expect(divDe).toBeTruthy(); |
| 155 | }); |
| 156 | |
| 157 | it('should have a h2 inside the div.tabular-header', () => { |
| 158 | const flowDe: DebugElement = fixture.debugElement; |
| 159 | const divDe = flowDe.query(By.css('div#ov-flow div.tabular-header h2')); |
| 160 | const div: HTMLElement = divDe.nativeElement; |
| 161 | expect(div.textContent).toEqual(' %title_flows% (0 %total%) '); |
| 162 | }); |
| 163 | |
| 164 | it('should have .table-header with "State..."', () => { |
| 165 | const flowDe: DebugElement = fixture.debugElement; |
| 166 | const divDe = flowDe.query(By.css('div#ov-flow div.table-header')); |
| 167 | const div: HTMLElement = divDe.nativeElement; |
| 168 | expect(div.textContent).toEqual('%state% %packets% %duration% %priority% %tableName% %selector% %treatment% %appName% '); |
| 169 | }); |
| 170 | |
| 171 | it('should have a refresh button inside the div.tabular-header', () => { |
| 172 | const flowDe: DebugElement = fixture.debugElement; |
| 173 | const divDe = flowDe.query(By.css('div#ov-flow div.tabular-header div.ctrl-btns div.refresh')); |
| 174 | expect(divDe).toBeTruthy(); |
| 175 | }); |
| 176 | |
| 177 | |
| 178 | it('should have a div.table-body ', () => { |
| 179 | const flowDe: DebugElement = fixture.debugElement; |
| 180 | const divDe = flowDe.query(By.css('div#ov-flow div.table-body')); |
| 181 | expect(divDe).toBeTruthy(); |
| 182 | }); |
| 183 | }); |