Sean Condon | 49e15be | 2018-05-16 16:58:29 +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 | */ |
Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 16 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; |
Sean Condon | 2bd11b7 | 2018-06-15 08:00:48 +0100 | [diff] [blame] | 17 | import { ActivatedRoute, Params } from '@angular/router'; |
Sean Condon | 49e15be | 2018-05-16 16:58:29 +0100 | [diff] [blame] | 18 | import { LogService } from '../../../../app/log.service'; |
Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 19 | import { AppsComponent } from '../../../../app/view/apps/apps.component'; |
Sean Condon | 49e15be | 2018-05-16 16:58:29 +0100 | [diff] [blame] | 20 | import { DialogService } from '../../../../app/fw/layer/dialog.service'; |
| 21 | import { FnService } from '../../../../app/fw/util/fn.service'; |
Sean Condon | 2bd11b7 | 2018-06-15 08:00:48 +0100 | [diff] [blame] | 22 | import { IconComponent } from '../../../../app/fw/svg/icon/icon.component'; |
Sean Condon | 49e15be | 2018-05-16 16:58:29 +0100 | [diff] [blame] | 23 | import { IconService } from '../../../../app/fw/svg/icon.service'; |
| 24 | import { KeyService } from '../../../../app/fw/util/key.service'; |
| 25 | import { LionService } from '../../../../app/fw/util/lion.service'; |
Sean Condon | 2bd11b7 | 2018-06-15 08:00:48 +0100 | [diff] [blame] | 26 | import { LoadingService } from '../../../../app/fw/layer/loading.service'; |
Sean Condon | 49e15be | 2018-05-16 16:58:29 +0100 | [diff] [blame] | 27 | import { PanelService } from '../../../../app/fw/layer/panel.service'; |
Sean Condon | 2bd11b7 | 2018-06-15 08:00:48 +0100 | [diff] [blame] | 28 | import { ThemeService } from '../../../../app/fw/util/theme.service'; |
Sean Condon | 49e15be | 2018-05-16 16:58:29 +0100 | [diff] [blame] | 29 | import { UrlFnService } from '../../../../app/fw/remote/urlfn.service'; |
| 30 | import { WebSocketService } from '../../../../app/fw/remote/websocket.service'; |
Sean Condon | 2bd11b7 | 2018-06-15 08:00:48 +0100 | [diff] [blame] | 31 | import { of } from 'rxjs'; |
| 32 | |
| 33 | class MockActivatedRoute extends ActivatedRoute { |
| 34 | constructor(params: Params) { |
| 35 | super(); |
| 36 | this.queryParams = of(params); |
| 37 | } |
| 38 | } |
Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 39 | |
Sean Condon | 49e15be | 2018-05-16 16:58:29 +0100 | [diff] [blame] | 40 | class MockDialogService {} |
| 41 | |
| 42 | class MockFnService {} |
| 43 | |
Sean Condon | 2bd11b7 | 2018-06-15 08:00:48 +0100 | [diff] [blame] | 44 | class MockIconService { |
| 45 | loadIconDef() {} |
| 46 | } |
Sean Condon | 49e15be | 2018-05-16 16:58:29 +0100 | [diff] [blame] | 47 | |
| 48 | class MockKeyService {} |
| 49 | |
Sean Condon | 2bd11b7 | 2018-06-15 08:00:48 +0100 | [diff] [blame] | 50 | class MockLoadingService { |
| 51 | startAnim() {} |
| 52 | stop() {} |
| 53 | waiting() {} |
| 54 | } |
Sean Condon | 49e15be | 2018-05-16 16:58:29 +0100 | [diff] [blame] | 55 | |
| 56 | class MockPanelService {} |
| 57 | |
| 58 | class MockTableBuilderService {} |
| 59 | |
Sean Condon | 2bd11b7 | 2018-06-15 08:00:48 +0100 | [diff] [blame] | 60 | class MockThemeService {} |
| 61 | |
Sean Condon | 49e15be | 2018-05-16 16:58:29 +0100 | [diff] [blame] | 62 | class MockUrlFnService {} |
| 63 | |
Sean Condon | 2bd11b7 | 2018-06-15 08:00:48 +0100 | [diff] [blame] | 64 | class MockWebSocketService { |
| 65 | createWebSocket() {} |
| 66 | isConnected() { return false; } |
| 67 | unbindHandlers() {} |
| 68 | bindHandlers() {} |
| 69 | } |
Sean Condon | 49e15be | 2018-05-16 16:58:29 +0100 | [diff] [blame] | 70 | |
| 71 | /** |
| 72 | * ONOS GUI -- Apps View -- Unit Tests |
| 73 | */ |
Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 74 | describe('AppsComponent', () => { |
Sean Condon | 2bd11b7 | 2018-06-15 08:00:48 +0100 | [diff] [blame] | 75 | let fs: FnService; |
| 76 | let ar: MockActivatedRoute; |
| 77 | let windowMock: Window; |
| 78 | let logServiceSpy: jasmine.SpyObj<LogService>; |
Sean Condon | 49e15be | 2018-05-16 16:58:29 +0100 | [diff] [blame] | 79 | let component: AppsComponent; |
| 80 | let fixture: ComponentFixture<AppsComponent>; |
Sean Condon | 2bd11b7 | 2018-06-15 08:00:48 +0100 | [diff] [blame] | 81 | const bundleObj = { |
| 82 | 'core.view.App': { |
| 83 | test: 'test1' |
| 84 | } |
| 85 | }; |
| 86 | const mockLion = (key) => { |
| 87 | return bundleObj[key] || '%' + key + '%'; |
| 88 | }; |
Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 89 | |
Sean Condon | 49e15be | 2018-05-16 16:58:29 +0100 | [diff] [blame] | 90 | beforeEach(async(() => { |
Sean Condon | 2bd11b7 | 2018-06-15 08:00:48 +0100 | [diff] [blame] | 91 | const logSpy = jasmine.createSpyObj('LogService', ['info', 'debug', 'warn', 'error']); |
| 92 | ar = new MockActivatedRoute({'debug': 'txrx'}); |
| 93 | |
| 94 | windowMock = <any>{ |
| 95 | location: <any> { |
| 96 | hostname: 'foo', |
| 97 | host: 'foo', |
| 98 | port: '80', |
| 99 | protocol: 'http', |
| 100 | search: { debug: 'true'}, |
| 101 | href: 'ws://foo:123/onos/ui/websock/path', |
| 102 | absUrl: 'ws://foo:123/onos/ui/websock/path' |
| 103 | } |
| 104 | }; |
| 105 | fs = new FnService(ar, logSpy, windowMock); |
Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 106 | |
Sean Condon | 49e15be | 2018-05-16 16:58:29 +0100 | [diff] [blame] | 107 | TestBed.configureTestingModule({ |
Sean Condon | 2bd11b7 | 2018-06-15 08:00:48 +0100 | [diff] [blame] | 108 | declarations: [ AppsComponent, IconComponent ], |
Sean Condon | 49e15be | 2018-05-16 16:58:29 +0100 | [diff] [blame] | 109 | providers: [ |
| 110 | { provide: DialogService, useClass: MockDialogService }, |
Sean Condon | 2bd11b7 | 2018-06-15 08:00:48 +0100 | [diff] [blame] | 111 | { provide: FnService, useValue: fs }, |
Sean Condon | 49e15be | 2018-05-16 16:58:29 +0100 | [diff] [blame] | 112 | { provide: IconService, useClass: MockIconService }, |
| 113 | { provide: KeyService, useClass: MockKeyService }, |
Sean Condon | 2bd11b7 | 2018-06-15 08:00:48 +0100 | [diff] [blame] | 114 | { provide: LionService, useFactory: (() => { |
| 115 | return { |
| 116 | bundle: ((bundleId) => mockLion), |
| 117 | ubercache: new Array() |
| 118 | }; |
| 119 | }) |
| 120 | }, |
| 121 | { provide: LoadingService, useClass: MockLoadingService }, |
| 122 | { provide: LogService, useValue: logSpy }, |
Sean Condon | 49e15be | 2018-05-16 16:58:29 +0100 | [diff] [blame] | 123 | { provide: PanelService, useClass: MockPanelService }, |
Sean Condon | 2bd11b7 | 2018-06-15 08:00:48 +0100 | [diff] [blame] | 124 | { provide: ThemeService, useClass: MockThemeService }, |
Sean Condon | 49e15be | 2018-05-16 16:58:29 +0100 | [diff] [blame] | 125 | { provide: UrlFnService, useClass: MockUrlFnService }, |
| 126 | { provide: WebSocketService, useClass: MockWebSocketService }, |
Sean Condon | a00bf38 | 2018-06-23 07:54:01 +0100 | [diff] [blame] | 127 | { provide: 'Window', useValue: windowMock }, |
Sean Condon | 49e15be | 2018-05-16 16:58:29 +0100 | [diff] [blame] | 128 | ] |
| 129 | }) |
| 130 | .compileComponents(); |
Sean Condon | 2bd11b7 | 2018-06-15 08:00:48 +0100 | [diff] [blame] | 131 | logServiceSpy = TestBed.get(LogService); |
Sean Condon | 49e15be | 2018-05-16 16:58:29 +0100 | [diff] [blame] | 132 | })); |
Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 133 | |
Sean Condon | 49e15be | 2018-05-16 16:58:29 +0100 | [diff] [blame] | 134 | beforeEach(() => { |
| 135 | fixture = TestBed.createComponent(AppsComponent); |
Sean Condon | 2bd11b7 | 2018-06-15 08:00:48 +0100 | [diff] [blame] | 136 | component = fixture.debugElement.componentInstance; |
Sean Condon | 49e15be | 2018-05-16 16:58:29 +0100 | [diff] [blame] | 137 | fixture.detectChanges(); |
| 138 | }); |
| 139 | |
| 140 | it('should create', () => { |
| 141 | expect(component).toBeTruthy(); |
| 142 | }); |
Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 143 | }); |