blob: a9c619413c4aaead76e3bbbca4ff39e4bdcbfdbf [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';
Sean Condonaa4366d2018-11-02 14:29:01 +000023import {
24 Instance,
25 InstanceComponent
26} from '../panel/instance/instance.component';
Sean Condonf4f54a12018-10-10 23:25:46 +010027import { SummaryComponent } from '../panel/summary/summary.component';
28import { ToolbarComponent } from '../panel/toolbar/toolbar.component';
29import { DetailsComponent } from '../panel/details/details.component';
Sean Condonaa4366d2018-11-02 14:29:01 +000030import { TopologyService } from '../topology.service';
Sean Condonf4f54a12018-10-10 23:25:46 +010031
32import {
33 FlashComponent,
34 FnService,
35 LogService
36} from 'gui2-fw-lib';
Sean Condon0c577f62018-11-18 22:40:05 +000037import {ZoomableDirective} from '../layer/zoomable.directive';
Sean Condonf4f54a12018-10-10 23:25:46 +010038
39
40class MockActivatedRoute extends ActivatedRoute {
41 constructor(params: Params) {
42 super();
43 this.queryParams = of(params);
44 }
45}
46
47class MockHttpClient {}
48
Sean Condonaa4366d2018-11-02 14:29:01 +000049class MockTopologyService {
50 init(instance: InstanceComponent) {
51 instance.onosInstances = [
52 <Instance>{
53 'id': 'inst1',
54 'ip': '127.0.0.1',
55 'reachable': true,
56 'online': true,
57 'ready': true,
58 'switches': 4,
59 'uiAttached': true
60 },
61 <Instance>{
62 'id': 'inst1',
63 'ip': '127.0.0.2',
64 'reachable': true,
65 'online': true,
66 'ready': true,
67 'switches': 3,
68 'uiAttached': false
69 }
70 ];
71 }
72 destroy() {}
73}
74
Sean Condonf4f54a12018-10-10 23:25:46 +010075/**
76 * ONOS GUI -- Topology View -- Unit Tests
77 */
78describe('TopologyComponent', () => {
79 let fs: FnService;
80 let ar: MockActivatedRoute;
81 let windowMock: Window;
82 let logServiceSpy: jasmine.SpyObj<LogService>;
83 let component: TopologyComponent;
84 let fixture: ComponentFixture<TopologyComponent>;
85
86 beforeEach(async(() => {
87 const logSpy = jasmine.createSpyObj('LogService', ['info', 'debug', 'warn', 'error']);
88 ar = new MockActivatedRoute({ 'debug': 'txrx' });
89
90 windowMock = <any>{
91 location: <any>{
92 hostname: 'foo',
93 host: 'foo',
94 port: '80',
95 protocol: 'http',
96 search: { debug: 'true' },
97 href: 'ws://foo:123/onos/ui/websock/path',
98 absUrl: 'ws://foo:123/onos/ui/websock/path'
99 }
100 };
101 fs = new FnService(ar, logSpy, windowMock);
102
103 TestBed.configureTestingModule({
104 imports: [ BrowserAnimationsModule ],
105 declarations: [
106 TopologyComponent,
107 InstanceComponent,
108 SummaryComponent,
109 ToolbarComponent,
110 DetailsComponent,
Sean Condon0c577f62018-11-18 22:40:05 +0000111 FlashComponent,
112 ZoomableDirective
Sean Condonf4f54a12018-10-10 23:25:46 +0100113 ],
114 providers: [
115 { provide: FnService, useValue: fs },
116 { provide: LogService, useValue: logSpy },
117 { provide: 'Window', useValue: windowMock },
118 { provide: HttpClient, useClass: MockHttpClient },
Sean Condon0c577f62018-11-18 22:40:05 +0000119 { provide: TopologyService, useClass: MockTopologyService },
Sean Condonf4f54a12018-10-10 23:25:46 +0100120 ]
121 }).compileComponents();
122 logServiceSpy = TestBed.get(LogService);
123 }));
124
125 beforeEach(() => {
126 fixture = TestBed.createComponent(TopologyComponent);
127 component = fixture.componentInstance;
128 fixture.detectChanges();
129 });
130
131 it('should create', () => {
132 expect(component).toBeTruthy();
133 });
134});