blob: 91c1de4842a9109f6a90dc6facadd516c18237f6 [file] [log] [blame]
Sean Condonf4f54a12018-10-10 23:25:46 +01001/*
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 */
16import { async, ComponentFixture, TestBed } from '@angular/core/testing';
17import { ActivatedRoute, Params } from '@angular/router';
18import { of } from 'rxjs';
19import { ToolbarComponent } from './toolbar.component';
20
21import {
Sean Condon91481822019-01-01 13:56:14 +000022 FnService, LionService,
23 LogService, IconComponent
Sean Condonf4f54a12018-10-10 23:25:46 +010024} from 'gui2-fw-lib';
Sean Condon50855cf2018-12-23 15:37:42 +000025import {BrowserAnimationsModule} from '@angular/platform-browser/animations';
Sean Condonf4f54a12018-10-10 23:25:46 +010026
27class 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 */
37describe('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 Condon91481822019-01-01 13:56:14 +000045 const bundleObj = {
46 'core.view.Topo': {
47 test: 'test1'
48 }
49 };
50 const mockLion = (key) => {
51 return bundleObj[key] || '%' + key + '%';
52 };
53
Sean Condonf4f54a12018-10-10 23:25:46 +010054 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 Condon50855cf2018-12-23 15:37:42 +000071 imports: [ BrowserAnimationsModule ],
Sean Condon91481822019-01-01 13:56:14 +000072 declarations: [ ToolbarComponent, IconComponent ],
Sean Condonf4f54a12018-10-10 23:25:46 +010073 providers: [
74 { provide: FnService, useValue: fs },
75 { provide: LogService, useValue: logSpy },
Sean Condon91481822019-01-01 13:56:14 +000076 {
77 provide: LionService, useFactory: (() => {
78 return {
79 bundle: ((bundleId) => mockLion),
80 ubercache: new Array(),
81 loadCbs: new Map<string, () => void>([])
82 };
83 })
84 },
Sean Condonf4f54a12018-10-10 23:25:46 +010085 { 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});