blob: 5933d370ec6626f30165719414338b4ab233558d [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 { HttpClient } from '@angular/common/http';
20import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
21
22import { TopologyComponent } from './topology.component';
23import { InstanceComponent } from '../panel/instance/instance.component';
24import { SummaryComponent } from '../panel/summary/summary.component';
25import { ToolbarComponent } from '../panel/toolbar/toolbar.component';
26import { DetailsComponent } from '../panel/details/details.component';
27
28import {
29 FlashComponent,
30 FnService,
31 LogService
32} from 'gui2-fw-lib';
33
34
35class MockActivatedRoute extends ActivatedRoute {
36 constructor(params: Params) {
37 super();
38 this.queryParams = of(params);
39 }
40}
41
42class MockHttpClient {}
43
44/**
45 * ONOS GUI -- Topology View -- Unit Tests
46 */
47describe('TopologyComponent', () => {
48 let fs: FnService;
49 let ar: MockActivatedRoute;
50 let windowMock: Window;
51 let logServiceSpy: jasmine.SpyObj<LogService>;
52 let component: TopologyComponent;
53 let fixture: ComponentFixture<TopologyComponent>;
54
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({
73 imports: [ BrowserAnimationsModule ],
74 declarations: [
75 TopologyComponent,
76 InstanceComponent,
77 SummaryComponent,
78 ToolbarComponent,
79 DetailsComponent,
80 FlashComponent
81 ],
82 providers: [
83 { provide: FnService, useValue: fs },
84 { provide: LogService, useValue: logSpy },
85 { provide: 'Window', useValue: windowMock },
86 { provide: HttpClient, useClass: MockHttpClient },
87 ]
88 }).compileComponents();
89 logServiceSpy = TestBed.get(LogService);
90 }));
91
92 beforeEach(() => {
93 fixture = TestBed.createComponent(TopologyComponent);
94 component = fixture.componentInstance;
95 fixture.detectChanges();
96 });
97
98 it('should create', () => {
99 expect(component).toBeTruthy();
100 });
101});