blob: e1db5fd46c0b7794ab30520af091ccc24d3cdba6 [file] [log] [blame]
Sean Condonf4f54a12018-10-10 23:25:46 +01001/*
Sean Condon91481822019-01-01 13:56:14 +00002 * Copyright 2019-present Open Networking Foundation
Sean Condonf4f54a12018-10-10 23:25:46 +01003 *
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 */
16import { async, ComponentFixture, TestBed } from '@angular/core/testing';
17import { ActivatedRoute, Params } from '@angular/router';
18import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
19import { of } from 'rxjs';
20import { DetailsComponent } from './details.component';
21
22import {
Sean Condon91481822019-01-01 13:56:14 +000023 FnService, LionService,
24 LogService, IconComponent
Sean Condona3ad7792020-01-04 19:26:34 +000025} from 'gui2-fw-lib/public_api';
Sean Condon91481822019-01-01 13:56:14 +000026import {RouterTestingModule} from '@angular/router/testing';
Sean Condonf4f54a12018-10-10 23:25:46 +010027
28class 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 */
38describe('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 Condon91481822019-01-01 13:56:14 +000046 const bundleObj = {
47 'core.view.Flow': {
48 test: 'test1'
49 }
50 };
51 const mockLion = (key) => {
52 return bundleObj[key] || '%' + key + '%';
53 };
54
Sean Condonf4f54a12018-10-10 23:25:46 +010055 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 Condon91481822019-01-01 13:56:14 +000073 imports: [ BrowserAnimationsModule, RouterTestingModule ],
74 declarations: [ DetailsComponent, IconComponent ],
Sean Condonf4f54a12018-10-10 23:25:46 +010075 providers: [
76 { provide: FnService, useValue: fs },
77 { provide: LogService, useValue: logSpy },
Sean Condon91481822019-01-01 13:56:14 +000078 {
79 provide: LionService, useFactory: (() => {
80 return {
81 bundle: ((bundleId) => mockLion),
82 ubercache: new Array(),
83 loadCbs: new Map<string, () => void>([])
84 };
85 })
86 },
Sean Condonf4f54a12018-10-10 23:25:46 +010087 { 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});