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 { async, ComponentFixture, TestBed } from '@angular/core/testing'; |
| 17 | import { ActivatedRoute, Params } from '@angular/router'; |
| 18 | import { of } from 'rxjs'; |
| 19 | import { ToolbarComponent } from './toolbar.component'; |
| 20 | |
| 21 | import { |
Sean Condon | 9148182 | 2019-01-01 13:56:14 +0000 | [diff] [blame] | 22 | FnService, LionService, |
| 23 | LogService, IconComponent |
Sean Condon | 3dd062f | 2020-04-14 09:25:00 +0100 | [diff] [blame] | 24 | } from 'org_onosproject_onos/web/gui2-fw-lib/public_api'; |
Sean Condon | 50855cf | 2018-12-23 15:37:42 +0000 | [diff] [blame] | 25 | import {BrowserAnimationsModule} from '@angular/platform-browser/animations'; |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 26 | |
| 27 | class MockActivatedRoute extends ActivatedRoute { |
| 28 | constructor(params: Params) { |
| 29 | super(); |
| 30 | this.queryParams = of(params); |
| 31 | } |
| 32 | } |
| 33 | |
| 34 | /** |
| 35 | * ONOS GUI -- Topology View Topology Panel-- Unit Tests |
| 36 | */ |
| 37 | describe('ToolbarComponent', () => { |
| 38 | let fs: FnService; |
| 39 | let ar: MockActivatedRoute; |
| 40 | let windowMock: Window; |
| 41 | let logServiceSpy: jasmine.SpyObj<LogService>; |
| 42 | let component: ToolbarComponent; |
| 43 | let fixture: ComponentFixture<ToolbarComponent>; |
| 44 | |
Sean Condon | 9148182 | 2019-01-01 13:56:14 +0000 | [diff] [blame] | 45 | const bundleObj = { |
| 46 | 'core.view.Topo': { |
| 47 | test: 'test1' |
| 48 | } |
| 49 | }; |
| 50 | const mockLion = (key) => { |
| 51 | return bundleObj[key] || '%' + key + '%'; |
| 52 | }; |
| 53 | |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 54 | beforeEach(async(() => { |
| 55 | const logSpy = jasmine.createSpyObj('LogService', ['info', 'debug', 'warn', 'error']); |
| 56 | ar = new MockActivatedRoute({ 'debug': 'txrx' }); |
| 57 | |
| 58 | windowMock = <any>{ |
| 59 | location: <any>{ |
| 60 | hostname: 'foo', |
| 61 | host: 'foo', |
| 62 | port: '80', |
| 63 | protocol: 'http', |
| 64 | search: { debug: 'true' }, |
| 65 | href: 'ws://foo:123/onos/ui/websock/path', |
| 66 | absUrl: 'ws://foo:123/onos/ui/websock/path' |
| 67 | } |
| 68 | }; |
| 69 | fs = new FnService(ar, logSpy, windowMock); |
| 70 | TestBed.configureTestingModule({ |
Sean Condon | 50855cf | 2018-12-23 15:37:42 +0000 | [diff] [blame] | 71 | imports: [ BrowserAnimationsModule ], |
Sean Condon | 9148182 | 2019-01-01 13:56:14 +0000 | [diff] [blame] | 72 | declarations: [ ToolbarComponent, IconComponent ], |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 73 | providers: [ |
| 74 | { provide: FnService, useValue: fs }, |
| 75 | { provide: LogService, useValue: logSpy }, |
Sean Condon | 9148182 | 2019-01-01 13:56:14 +0000 | [diff] [blame] | 76 | { |
| 77 | provide: LionService, useFactory: (() => { |
| 78 | return { |
| 79 | bundle: ((bundleId) => mockLion), |
| 80 | ubercache: new Array(), |
| 81 | loadCbs: new Map<string, () => void>([]) |
| 82 | }; |
| 83 | }) |
| 84 | }, |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 85 | { provide: 'Window', useValue: windowMock }, |
| 86 | ] |
| 87 | }) |
| 88 | .compileComponents(); |
| 89 | logServiceSpy = TestBed.get(LogService); |
| 90 | })); |
| 91 | |
| 92 | beforeEach(() => { |
| 93 | fixture = TestBed.createComponent(ToolbarComponent); |
| 94 | component = fixture.componentInstance; |
| 95 | fixture.detectChanges(); |
| 96 | }); |
| 97 | |
| 98 | it('should create', () => { |
| 99 | expect(component).toBeTruthy(); |
| 100 | }); |
| 101 | }); |