Sean Condon | 28ecc5f | 2018-06-25 12:50:16 +0100 | [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 | import { ActivatedRoute, Params } from '@angular/router'; |
| 18 | import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; |
| 19 | import { FormsModule } from '@angular/forms'; |
| 20 | import { DebugElement } from '@angular/core'; |
| 21 | import { By } from '@angular/platform-browser'; |
| 22 | |
| 23 | import { LogService } from '../../../log.service'; |
| 24 | import { AppsComponent } from './apps.component'; |
| 25 | import { AppsDetailsComponent } from '../appsdetails/appsdetails.component'; |
| 26 | import { DialogService } from '../../../fw/layer/dialog.service'; |
| 27 | import { FnService } from '../../../fw/util/fn.service'; |
| 28 | import { IconComponent } from '../../../fw/svg/icon/icon.component'; |
| 29 | import { IconService } from '../../../fw/svg/icon.service'; |
| 30 | import { KeyService } from '../../../fw/util/key.service'; |
| 31 | import { LionService } from '../../../fw/util/lion.service'; |
| 32 | import { LoadingService } from '../../../fw/layer/loading.service'; |
| 33 | import { ThemeService } from '../../../fw/util/theme.service'; |
| 34 | import { TableFilterPipe } from '../../../fw/widget/tablefilter.pipe'; |
| 35 | import { UrlFnService } from '../../../fw/remote/urlfn.service'; |
| 36 | import { WebSocketService } from '../../../fw/remote/websocket.service'; |
| 37 | import { of } from 'rxjs'; |
| 38 | |
| 39 | class MockActivatedRoute extends ActivatedRoute { |
| 40 | constructor(params: Params) { |
| 41 | super(); |
| 42 | this.queryParams = of(params); |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | class MockDialogService {} |
| 47 | |
| 48 | class MockFnService {} |
| 49 | |
| 50 | class MockIconService { |
| 51 | loadIconDef() {} |
| 52 | } |
| 53 | |
| 54 | class MockKeyService {} |
| 55 | |
| 56 | class MockLoadingService { |
| 57 | startAnim() {} |
| 58 | stop() {} |
| 59 | waiting() {} |
| 60 | } |
| 61 | |
| 62 | class MockThemeService {} |
| 63 | |
| 64 | class MockUrlFnService {} |
| 65 | |
| 66 | class MockWebSocketService { |
| 67 | createWebSocket() {} |
| 68 | isConnected() { return false; } |
| 69 | unbindHandlers() {} |
| 70 | bindHandlers() {} |
| 71 | } |
| 72 | |
| 73 | /** |
| 74 | * ONOS GUI -- Apps View -- Unit Tests |
| 75 | */ |
| 76 | describe('AppsComponent', () => { |
| 77 | let fs: FnService; |
| 78 | let ar: MockActivatedRoute; |
| 79 | let windowMock: Window; |
| 80 | let logServiceSpy: jasmine.SpyObj<LogService>; |
| 81 | let component: AppsComponent; |
| 82 | let fixture: ComponentFixture<AppsComponent>; |
| 83 | const bundleObj = { |
| 84 | 'core.view.App': { |
| 85 | test: 'test1' |
| 86 | } |
| 87 | }; |
| 88 | const mockLion = (key) => { |
| 89 | return bundleObj[key] || '%' + key + '%'; |
| 90 | }; |
| 91 | |
| 92 | beforeEach(async(() => { |
| 93 | const logSpy = jasmine.createSpyObj('LogService', ['info', 'debug', 'warn', 'error']); |
| 94 | ar = new MockActivatedRoute({'debug': 'txrx'}); |
| 95 | |
| 96 | windowMock = <any>{ |
| 97 | location: <any> { |
| 98 | hostname: 'foo', |
| 99 | host: 'foo', |
| 100 | port: '80', |
| 101 | protocol: 'http', |
| 102 | search: { debug: 'true'}, |
| 103 | href: 'ws://foo:123/onos/ui/websock/path', |
| 104 | absUrl: 'ws://foo:123/onos/ui/websock/path' |
| 105 | } |
| 106 | }; |
| 107 | fs = new FnService(ar, logSpy, windowMock); |
| 108 | |
| 109 | TestBed.configureTestingModule({ |
| 110 | imports: [ BrowserAnimationsModule, FormsModule ], |
| 111 | declarations: [ AppsComponent, IconComponent, AppsDetailsComponent, TableFilterPipe ], |
| 112 | providers: [ |
| 113 | { provide: DialogService, useClass: MockDialogService }, |
| 114 | { provide: FnService, useValue: fs }, |
| 115 | { provide: IconService, useClass: MockIconService }, |
| 116 | { provide: KeyService, useClass: MockKeyService }, |
| 117 | { provide: LionService, useFactory: (() => { |
| 118 | return { |
| 119 | bundle: ((bundleId) => mockLion), |
| 120 | ubercache: new Array(), |
| 121 | loadCbs: new Map<string, () => void>([]) |
| 122 | }; |
| 123 | }) |
| 124 | }, |
| 125 | { provide: LoadingService, useClass: MockLoadingService }, |
| 126 | { provide: LogService, useValue: logSpy }, |
| 127 | { provide: ThemeService, useClass: MockThemeService }, |
| 128 | { provide: UrlFnService, useClass: MockUrlFnService }, |
| 129 | { provide: WebSocketService, useClass: MockWebSocketService }, |
| 130 | { provide: 'Window', useValue: windowMock }, |
| 131 | ] |
| 132 | }) |
| 133 | .compileComponents(); |
| 134 | logServiceSpy = TestBed.get(LogService); |
| 135 | })); |
| 136 | |
| 137 | beforeEach(() => { |
| 138 | fixture = TestBed.createComponent(AppsComponent); |
| 139 | component = fixture.debugElement.componentInstance; |
| 140 | fixture.detectChanges(); |
| 141 | }); |
| 142 | |
| 143 | it('should create', () => { |
| 144 | expect(component).toBeTruthy(); |
| 145 | }); |
| 146 | |
| 147 | it('should have a div.tabular-header inside a div#ov-app', () => { |
| 148 | const appDe: DebugElement = fixture.debugElement; |
| 149 | const divDe = appDe.query(By.css('div#ov-app div.tabular-header')); |
| 150 | expect(divDe).toBeTruthy(); |
| 151 | }); |
| 152 | |
| 153 | it('should have a h2 inside the div.tabular-header', () => { |
| 154 | const appDe: DebugElement = fixture.debugElement; |
| 155 | const divDe = appDe.query(By.css('div#ov-app div.tabular-header h2')); |
| 156 | const div: HTMLElement = divDe.nativeElement; |
| 157 | expect(div.textContent).toEqual(' %title_apps% (0 %total%) '); |
| 158 | }); |
| 159 | |
| 160 | it('should have a refresh button inside the div.tabular-header', () => { |
| 161 | const appDe: DebugElement = fixture.debugElement; |
| 162 | const divDe = appDe.query(By.css('div#ov-app div.tabular-header div.ctrl-btns div.refresh')); |
| 163 | expect(divDe).toBeTruthy(); |
| 164 | }); |
| 165 | |
| 166 | it('should have an active button inside the div.tabular-header', () => { |
| 167 | const appDe: DebugElement = fixture.debugElement; |
| 168 | const divDe = appDe.query(By.css('div#ov-app div.tabular-header div.ctrl-btns div.active')); |
| 169 | expect(divDe).toBeTruthy(); |
| 170 | }); |
| 171 | |
| 172 | it('should have a div.summary-list inside a div#ov-app', () => { |
| 173 | const appDe: DebugElement = fixture.debugElement; |
| 174 | const divDe = appDe.query(By.css('div#ov-app div.summary-list')); |
| 175 | expect(divDe).toBeTruthy(); |
| 176 | }); |
| 177 | }); |