blob: 23fb257c01ee3979c10a673abc7be48b69a8d591 [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,
Sean Condon91481822019-01-01 13:56:14 +000035 LogService,
36 IconService, IconComponent
Sean Condonf4f54a12018-10-10 23:25:46 +010037} from 'gui2-fw-lib';
Sean Condon0c577f62018-11-18 22:40:05 +000038import {ZoomableDirective} from '../layer/zoomable.directive';
Sean Condon91481822019-01-01 13:56:14 +000039import {RouterTestingModule} from '@angular/router/testing';
Sean Condonf4f54a12018-10-10 23:25:46 +010040
41
42class MockActivatedRoute extends ActivatedRoute {
43 constructor(params: Params) {
44 super();
45 this.queryParams = of(params);
46 }
47}
48
49class MockHttpClient {}
50
Sean Condonaa4366d2018-11-02 14:29:01 +000051class MockTopologyService {
52 init(instance: InstanceComponent) {
53 instance.onosInstances = [
54 <Instance>{
55 'id': 'inst1',
56 'ip': '127.0.0.1',
57 'reachable': true,
58 'online': true,
59 'ready': true,
60 'switches': 4,
61 'uiAttached': true
62 },
63 <Instance>{
64 'id': 'inst1',
65 'ip': '127.0.0.2',
66 'reachable': true,
67 'online': true,
68 'ready': true,
69 'switches': 3,
70 'uiAttached': false
71 }
72 ];
73 }
74 destroy() {}
75}
76
Sean Condon91481822019-01-01 13:56:14 +000077class MockIconService {
78 loadIconDef() { }
79}
80
Sean Condonf4f54a12018-10-10 23:25:46 +010081/**
82 * ONOS GUI -- Topology View -- Unit Tests
83 */
84describe('TopologyComponent', () => {
85 let fs: FnService;
86 let ar: MockActivatedRoute;
87 let windowMock: Window;
88 let logServiceSpy: jasmine.SpyObj<LogService>;
89 let component: TopologyComponent;
90 let fixture: ComponentFixture<TopologyComponent>;
91
92 beforeEach(async(() => {
93 const logSpy = jasmine.createSpyObj('LogService', ['info', 'debug', 'warn', 'error']);
94 ar = new MockActivatedRoute({ 'debug': 'txrx' });
95
96 windowMock = <any>{
97 location: <any>{
98 hostname: 'foo',
99 host: 'foo',
100 port: '80',
101 protocol: 'http',
102 search: { debug: 'true' },
103 href: 'ws://foo:123/onos/ui/websock/path',
104 absUrl: 'ws://foo:123/onos/ui/websock/path'
105 }
106 };
107 fs = new FnService(ar, logSpy, windowMock);
108
109 TestBed.configureTestingModule({
Sean Condon91481822019-01-01 13:56:14 +0000110 imports: [ BrowserAnimationsModule, RouterTestingModule ],
Sean Condonf4f54a12018-10-10 23:25:46 +0100111 declarations: [
112 TopologyComponent,
113 InstanceComponent,
114 SummaryComponent,
115 ToolbarComponent,
116 DetailsComponent,
Sean Condon0c577f62018-11-18 22:40:05 +0000117 FlashComponent,
Sean Condon91481822019-01-01 13:56:14 +0000118 ZoomableDirective,
119 IconComponent
Sean Condonf4f54a12018-10-10 23:25:46 +0100120 ],
121 providers: [
122 { provide: FnService, useValue: fs },
123 { provide: LogService, useValue: logSpy },
124 { provide: 'Window', useValue: windowMock },
125 { provide: HttpClient, useClass: MockHttpClient },
Sean Condon0c577f62018-11-18 22:40:05 +0000126 { provide: TopologyService, useClass: MockTopologyService },
Sean Condon91481822019-01-01 13:56:14 +0000127 { provide: IconService, useClass: MockIconService },
Sean Condonf4f54a12018-10-10 23:25:46 +0100128 ]
129 }).compileComponents();
130 logServiceSpy = TestBed.get(LogService);
131 }));
132
133 beforeEach(() => {
134 fixture = TestBed.createComponent(TopologyComponent);
135 component = fixture.componentInstance;
136 fixture.detectChanges();
137 });
138
139 it('should create', () => {
140 expect(component).toBeTruthy();
141 });
142});