blob: d98a55c1c2048803255e1472f1cf52e749416cb8 [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';
37
38
39class MockActivatedRoute extends ActivatedRoute {
40 constructor(params: Params) {
41 super();
42 this.queryParams = of(params);
43 }
44}
45
46class MockHttpClient {}
47
Sean Condonaa4366d2018-11-02 14:29:01 +000048class MockTopologyService {
49 init(instance: InstanceComponent) {
50 instance.onosInstances = [
51 <Instance>{
52 'id': 'inst1',
53 'ip': '127.0.0.1',
54 'reachable': true,
55 'online': true,
56 'ready': true,
57 'switches': 4,
58 'uiAttached': true
59 },
60 <Instance>{
61 'id': 'inst1',
62 'ip': '127.0.0.2',
63 'reachable': true,
64 'online': true,
65 'ready': true,
66 'switches': 3,
67 'uiAttached': false
68 }
69 ];
70 }
71 destroy() {}
72}
73
Sean Condonf4f54a12018-10-10 23:25:46 +010074/**
75 * ONOS GUI -- Topology View -- Unit Tests
76 */
77describe('TopologyComponent', () => {
78 let fs: FnService;
79 let ar: MockActivatedRoute;
80 let windowMock: Window;
81 let logServiceSpy: jasmine.SpyObj<LogService>;
82 let component: TopologyComponent;
83 let fixture: ComponentFixture<TopologyComponent>;
84
85 beforeEach(async(() => {
86 const logSpy = jasmine.createSpyObj('LogService', ['info', 'debug', 'warn', 'error']);
87 ar = new MockActivatedRoute({ 'debug': 'txrx' });
88
89 windowMock = <any>{
90 location: <any>{
91 hostname: 'foo',
92 host: 'foo',
93 port: '80',
94 protocol: 'http',
95 search: { debug: 'true' },
96 href: 'ws://foo:123/onos/ui/websock/path',
97 absUrl: 'ws://foo:123/onos/ui/websock/path'
98 }
99 };
100 fs = new FnService(ar, logSpy, windowMock);
101
102 TestBed.configureTestingModule({
103 imports: [ BrowserAnimationsModule ],
104 declarations: [
105 TopologyComponent,
106 InstanceComponent,
107 SummaryComponent,
108 ToolbarComponent,
109 DetailsComponent,
110 FlashComponent
111 ],
112 providers: [
113 { provide: FnService, useValue: fs },
114 { provide: LogService, useValue: logSpy },
115 { provide: 'Window', useValue: windowMock },
116 { provide: HttpClient, useClass: MockHttpClient },
Sean Condonaa4366d2018-11-02 14:29:01 +0000117 { provide: TopologyService, useClass: MockTopologyService }
Sean Condonf4f54a12018-10-10 23:25:46 +0100118 ]
119 }).compileComponents();
120 logServiceSpy = TestBed.get(LogService);
121 }));
122
123 beforeEach(() => {
124 fixture = TestBed.createComponent(TopologyComponent);
125 component = fixture.componentInstance;
126 fixture.detectChanges();
127 });
128
129 it('should create', () => {
130 expect(component).toBeTruthy();
131 });
132});