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