Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +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 { ComponentFixture, TestBed, async } from '@angular/core/testing'; |
| 17 | import { ActivatedRoute, Params } from '@angular/router'; |
| 18 | import { RouterTestingModule } from '@angular/router/testing'; |
| 19 | import { BrowserModule } from '@angular/platform-browser'; |
| 20 | import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; |
| 21 | import { FormsModule } from '@angular/forms'; |
| 22 | import { of } from 'rxjs'; |
| 23 | |
| 24 | import { NavComponent } from './nav/nav.component'; |
| 25 | import { OnosComponent } from './onos.component'; |
| 26 | |
| 27 | import { |
| 28 | LogService, ConsoleLoggerService, |
| 29 | ConfirmComponent, |
| 30 | IconComponent, |
| 31 | MastComponent, |
| 32 | VeilComponent, |
| 33 | FnService, |
| 34 | GlyphService, |
| 35 | IconService, |
| 36 | LionService, |
| 37 | NavService, UiView, |
| 38 | OnosService, |
| 39 | SvgUtilService, |
| 40 | ThemeService, |
| 41 | WebSocketService, |
| 42 | WsOptions |
Sean Condon | a3ad779 | 2020-01-04 19:26:34 +0000 | [diff] [blame] | 43 | } from 'gui2-fw-lib/public_api'; |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 44 | |
| 45 | class MockActivatedRoute extends ActivatedRoute { |
| 46 | constructor(params: Params) { |
| 47 | super(); |
| 48 | this.queryParams = of(params); |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | class MockDialogService {} |
| 53 | |
| 54 | class MockGlyphService {} |
| 55 | |
| 56 | class MockIconService {} |
| 57 | |
| 58 | class MockLionService {} |
| 59 | |
| 60 | class MockNavService { |
| 61 | uiPlatformViews = new Array<UiView>(); |
| 62 | uiNetworkViews = new Array<UiView>(); |
| 63 | uiOtherViews = new Array<UiView>(); |
| 64 | uiHiddenViews = new Array<UiView>(); |
| 65 | } |
| 66 | |
| 67 | class MockOnosService {} |
| 68 | |
| 69 | class MockThemeService {} |
| 70 | |
| 71 | class MockVeilComponent {} |
| 72 | |
| 73 | class MockWebSocketService { |
| 74 | createWebSocket() { } |
| 75 | isConnected() { return false; } |
| 76 | unbindHandlers() { } |
| 77 | bindHandlers() { } |
| 78 | } |
| 79 | |
| 80 | /** |
| 81 | * ONOS GUI -- Onos Component - Unit Tests |
| 82 | */ |
| 83 | describe('OnosComponent', () => { |
| 84 | let logServiceSpy: jasmine.SpyObj<LogService>; |
| 85 | let fs: FnService; |
| 86 | let ar: MockActivatedRoute; |
| 87 | let windowMock: Window; |
| 88 | let component: OnosComponent; |
| 89 | let fixture: ComponentFixture<OnosComponent>; |
| 90 | |
| 91 | beforeEach(async(() => { |
| 92 | const logSpy = jasmine.createSpyObj('LogService', ['info', 'debug', 'warn', 'error']); |
| 93 | ar = new MockActivatedRoute({'debug': 'TestService'}); |
| 94 | |
| 95 | windowMock = <any>{ |
| 96 | location: <any>{ |
| 97 | hostname: 'foo', |
| 98 | host: 'foo', |
| 99 | port: '80', |
| 100 | protocol: 'http', |
| 101 | search: { debug: 'true' }, |
| 102 | href: 'ws://foo:123/onos/ui/websock/path', |
| 103 | absUrl: 'ws://foo:123/onos/ui/websock/path' |
| 104 | }, |
| 105 | innerHeight: 240, |
| 106 | innerWidth: 320 |
| 107 | }; |
| 108 | fs = new FnService(ar, logSpy, windowMock); |
| 109 | |
| 110 | TestBed.configureTestingModule({ |
| 111 | imports: [ |
| 112 | RouterTestingModule, |
| 113 | BrowserModule, |
| 114 | BrowserAnimationsModule, |
| 115 | FormsModule |
| 116 | ], |
| 117 | declarations: [ |
| 118 | ConfirmComponent, |
| 119 | IconComponent, |
| 120 | MastComponent, |
| 121 | NavComponent, |
| 122 | OnosComponent, |
| 123 | VeilComponent, |
| 124 | ], |
| 125 | providers: [ |
| 126 | { provide: FnService, useValue: fs }, |
| 127 | { provide: GlyphService, useClass: MockGlyphService }, |
| 128 | { provide: IconService, useClass: MockIconService }, |
| 129 | { provide: LionService, useClass: MockLionService }, |
| 130 | { provide: LogService, useValue: logSpy }, |
| 131 | { provide: NavService, useClass: MockNavService }, |
| 132 | { provide: OnosService, useClass: MockOnosService }, |
| 133 | { provide: ThemeService, useClass: MockThemeService }, |
| 134 | { provide: WebSocketService, useClass: MockWebSocketService }, |
| 135 | { provide: Window, useFactory: (() => windowMock ) }, |
| 136 | ] |
| 137 | }).compileComponents(); |
| 138 | logServiceSpy = TestBed.get(LogService); |
| 139 | })); |
| 140 | |
| 141 | beforeEach(() => { |
| 142 | fixture = TestBed.createComponent(OnosComponent); |
| 143 | component = fixture.debugElement.componentInstance; |
| 144 | fixture.detectChanges(); |
| 145 | }); |
| 146 | |
| 147 | // TODO: Reimplemt this - it's compaining about "no provider for Window" |
| 148 | // it('should create the component', () => { |
| 149 | // expect(component).toBeTruthy(); |
| 150 | // }); |
| 151 | |
| 152 | // it(`should have as title 'onos'`, async(() => { |
| 153 | // const fixture = TestBed.createComponent(OnosComponent); |
| 154 | // const app = fixture.componentInstance; |
| 155 | // expect(app.title).toEqual('onos'); |
| 156 | // })); |
| 157 | }); |