Sean Condon | 83fc39f | 2018-04-19 18:56:13 +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 { TestBed, async } from '@angular/core/testing'; |
Sean Condon | fd6d11b | 2018-06-02 20:29:49 +0100 | [diff] [blame] | 17 | import { RouterModule, RouterOutlet, ChildrenOutletContexts, ActivatedRoute, Params } from '@angular/router'; |
| 18 | import { of } from 'rxjs'; |
| 19 | |
Sean Condon | 49e15be | 2018-05-16 16:58:29 +0100 | [diff] [blame] | 20 | import { LogService } from '../../app/log.service'; |
| 21 | import { ConsoleLoggerService } from '../../app/consolelogger.service'; |
Sean Condon | fd6d11b | 2018-06-02 20:29:49 +0100 | [diff] [blame] | 22 | |
Sean Condon | 49e15be | 2018-05-16 16:58:29 +0100 | [diff] [blame] | 23 | import { IconComponent } from '../../app/fw/svg/icon/icon.component'; |
| 24 | import { MastComponent } from '../../app/fw/mast/mast/mast.component'; |
| 25 | import { NavComponent } from '../../app/fw/nav/nav/nav.component'; |
Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 26 | import { OnosComponent } from '../../app/onos.component'; |
Sean Condon | fd6d11b | 2018-06-02 20:29:49 +0100 | [diff] [blame] | 27 | import { VeilComponent } from '../../app/fw/layer/veil/veil.component'; |
| 28 | |
Sean Condon | 49e15be | 2018-05-16 16:58:29 +0100 | [diff] [blame] | 29 | import { DialogService } from '../../app/fw/layer/dialog.service'; |
| 30 | import { EeService } from '../../app/fw/util/ee.service'; |
Sean Condon | fd6d11b | 2018-06-02 20:29:49 +0100 | [diff] [blame] | 31 | import { FnService } from '../../app/fw/util/fn.service'; |
Sean Condon | 49e15be | 2018-05-16 16:58:29 +0100 | [diff] [blame] | 32 | import { GlyphService } from '../../app/fw/svg/glyph.service'; |
| 33 | import { IconService } from '../../app/fw/svg/icon.service'; |
| 34 | import { KeyService } from '../../app/fw/util/key.service'; |
| 35 | import { LionService } from '../../app/fw/util/lion.service'; |
| 36 | import { NavService } from '../../app/fw/nav/nav.service'; |
| 37 | import { OnosService } from '../../app/onos.service'; |
Sean Condon | 49e15be | 2018-05-16 16:58:29 +0100 | [diff] [blame] | 38 | import { QuickHelpService } from '../../app/fw/layer/quickhelp.service'; |
Sean Condon | fd6d11b | 2018-06-02 20:29:49 +0100 | [diff] [blame] | 39 | import { SvgUtilService } from '../../app/fw/svg/svgutil.service'; |
Sean Condon | 49e15be | 2018-05-16 16:58:29 +0100 | [diff] [blame] | 40 | import { ThemeService } from '../../app/fw/util/theme.service'; |
| 41 | import { SpriteService } from '../../app/fw/svg/sprite.service'; |
Sean Condon | fd6d11b | 2018-06-02 20:29:49 +0100 | [diff] [blame] | 42 | import { WebSocketService, WsOptions } from '../../app/fw/remote/websocket.service'; |
| 43 | |
| 44 | class MockActivatedRoute extends ActivatedRoute { |
| 45 | constructor(params: Params) { |
| 46 | super(); |
| 47 | this.queryParams = of(params); |
| 48 | } |
| 49 | } |
Sean Condon | 49e15be | 2018-05-16 16:58:29 +0100 | [diff] [blame] | 50 | |
| 51 | class MockDialogService {} |
| 52 | |
| 53 | class MockEeService {} |
| 54 | |
Sean Condon | 49e15be | 2018-05-16 16:58:29 +0100 | [diff] [blame] | 55 | class MockGlyphService {} |
| 56 | |
| 57 | class MockIconService {} |
| 58 | |
| 59 | class MockKeyService {} |
| 60 | |
Sean Condon | 2bd11b7 | 2018-06-15 08:00:48 +0100 | [diff] [blame] | 61 | class MockLionService {} |
| 62 | |
Sean Condon | 49e15be | 2018-05-16 16:58:29 +0100 | [diff] [blame] | 63 | class MockNavService {} |
| 64 | |
| 65 | class MockOnosService {} |
| 66 | |
Sean Condon | 49e15be | 2018-05-16 16:58:29 +0100 | [diff] [blame] | 67 | class MockQuickHelpService {} |
| 68 | |
| 69 | class MockSpriteService {} |
| 70 | |
| 71 | class MockThemeService {} |
| 72 | |
Sean Condon | fd6d11b | 2018-06-02 20:29:49 +0100 | [diff] [blame] | 73 | class MockVeilComponent {} |
Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 74 | |
Sean Condon | 2bd11b7 | 2018-06-15 08:00:48 +0100 | [diff] [blame] | 75 | class MockWebSocketService { |
| 76 | createWebSocket() {} |
| 77 | isConnected() { return false; } |
| 78 | } |
| 79 | |
Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 80 | /** |
| 81 | * ONOS GUI -- Onos Component - Unit Tests |
| 82 | */ |
| 83 | describe('OnosComponent', () => { |
Sean Condon | 49e15be | 2018-05-16 16:58:29 +0100 | [diff] [blame] | 84 | let log: LogService; |
Sean Condon | fd6d11b | 2018-06-02 20:29:49 +0100 | [diff] [blame] | 85 | let fs: FnService; |
| 86 | let ar: MockActivatedRoute; |
| 87 | let windowMock: Window; |
Sean Condon | 2bd11b7 | 2018-06-15 08:00:48 +0100 | [diff] [blame] | 88 | let fixture; |
| 89 | let app; |
Sean Condon | 49e15be | 2018-05-16 16:58:29 +0100 | [diff] [blame] | 90 | |
| 91 | beforeEach(async(() => { |
| 92 | log = new ConsoleLoggerService(); |
Sean Condon | fd6d11b | 2018-06-02 20:29:49 +0100 | [diff] [blame] | 93 | ar = new MockActivatedRoute({'debug': 'TestService'}); |
| 94 | |
| 95 | windowMock = <any>{ |
| 96 | location: <any> { |
| 97 | hostname: '', |
| 98 | host: '', |
| 99 | port: '', |
| 100 | protocol: '', |
| 101 | search: { debug: 'true'}, |
| 102 | href: '' |
| 103 | }, |
| 104 | innerHeight: 240, |
| 105 | innerWidth: 320 |
| 106 | }; |
| 107 | fs = new FnService(ar, log, windowMock); |
Sean Condon | 49e15be | 2018-05-16 16:58:29 +0100 | [diff] [blame] | 108 | |
| 109 | TestBed.configureTestingModule({ |
| 110 | declarations: [ |
| 111 | IconComponent, |
| 112 | MastComponent, |
| 113 | NavComponent, |
| 114 | OnosComponent, |
Sean Condon | fd6d11b | 2018-06-02 20:29:49 +0100 | [diff] [blame] | 115 | VeilComponent, |
Sean Condon | 49e15be | 2018-05-16 16:58:29 +0100 | [diff] [blame] | 116 | RouterOutlet |
| 117 | ], |
| 118 | providers: [ |
| 119 | { provide: ChildrenOutletContexts, useClass: ChildrenOutletContexts }, |
| 120 | { provide: DialogService, useClass: MockDialogService }, |
| 121 | { provide: EeService, useClass: MockEeService }, |
Sean Condon | fd6d11b | 2018-06-02 20:29:49 +0100 | [diff] [blame] | 122 | { provide: FnService, useValue: fs }, |
Sean Condon | 49e15be | 2018-05-16 16:58:29 +0100 | [diff] [blame] | 123 | { provide: GlyphService, useClass: MockGlyphService }, |
| 124 | { provide: IconService, useClass: MockIconService }, |
| 125 | { provide: KeyService, useClass: MockKeyService }, |
Sean Condon | 2bd11b7 | 2018-06-15 08:00:48 +0100 | [diff] [blame] | 126 | { provide: LionService, useClass: MockLionService }, |
Sean Condon | 49e15be | 2018-05-16 16:58:29 +0100 | [diff] [blame] | 127 | { provide: LogService, useValue: log }, |
| 128 | { provide: NavService, useClass: MockNavService }, |
| 129 | { provide: OnosService, useClass: MockOnosService }, |
| 130 | { provide: QuickHelpService, useClass: MockQuickHelpService }, |
Sean Condon | 49e15be | 2018-05-16 16:58:29 +0100 | [diff] [blame] | 131 | { provide: SpriteService, useClass: MockSpriteService }, |
| 132 | { provide: ThemeService, useClass: MockThemeService }, |
Sean Condon | 2bd11b7 | 2018-06-15 08:00:48 +0100 | [diff] [blame] | 133 | { provide: WebSocketService, useClass: MockWebSocketService }, |
Sean Condon | fd6d11b | 2018-06-02 20:29:49 +0100 | [diff] [blame] | 134 | { provide: Window, useFactory: (() => windowMock ) }, |
Sean Condon | 49e15be | 2018-05-16 16:58:29 +0100 | [diff] [blame] | 135 | ] |
| 136 | }).compileComponents(); |
Sean Condon | 2bd11b7 | 2018-06-15 08:00:48 +0100 | [diff] [blame] | 137 | |
| 138 | fixture = TestBed.createComponent(OnosComponent); |
| 139 | app = fixture.componentInstance; |
Sean Condon | 49e15be | 2018-05-16 16:58:29 +0100 | [diff] [blame] | 140 | })); |
| 141 | |
| 142 | it('should create the app', async(() => { |
Sean Condon | 49e15be | 2018-05-16 16:58:29 +0100 | [diff] [blame] | 143 | expect(app).toBeTruthy(); |
| 144 | })); |
| 145 | |
Sean Condon | 2bd11b7 | 2018-06-15 08:00:48 +0100 | [diff] [blame] | 146 | // it(`should have as title 'onos'`, async(() => { |
| 147 | // const fixture = TestBed.createComponent(OnosComponent); |
| 148 | // const app = fixture.componentInstance; |
| 149 | // expect(app.title).toEqual('onos'); |
| 150 | // })); |
Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 151 | }); |