blob: f0b4908cfb9a4ef293350a179e0ec715037d25cc [file] [log] [blame]
Priyanka H Mfa5b77a2018-07-27 12:43:44 +05301/*
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';
17
18import {ClusterComponent} from './cluster.component';
19import {FnService} from '../../../fw/util/fn.service';
20import {LogService} from '../../../log.service';
21import {ActivatedRoute, Params} from '@angular/router';
22import {of} from 'rxjs/index';
23import {BrowserAnimationsModule} from '@angular/platform-browser/animations';
24import {FormsModule} from '@angular/forms';
25import {RouterTestingModule} from '@angular/router/testing';
26import {IconComponent} from '../../../fw/svg/icon/icon.component';
27import {IconService} from '../../../fw/svg/icon.service';
28import {GlyphService} from '../../../fw/svg/glyph.service';
29import {KeyService} from '../../../fw/util/key.service';
30import {LoadingService} from '../../../fw/layer/loading.service';
31import {MastService} from '../../../fw/mast/mast.service';
32import {NavService} from '../../../fw/nav/nav.service';
33import {WebSocketService} from '../../../fw/remote/websocket.service';
34import {ThemeService} from '../../../fw/util/theme.service';
35import {DebugElement} from '@angular/core';
36import {By} from '@angular/platform-browser';
37
38class MockActivatedRoute extends ActivatedRoute {
39 constructor(params: Params) {
40 super();
41 this.queryParams = of(params);
42 }
43}
44
45class MockIconService {
46 loadIconDef() {
47 }
48}
49
50class MockGlyphService {
51}
52
53class MockKeyService {
54}
55
56class MockLoadingService {
57 startAnim() {
58 }
59
60 stop() {
61 }
62}
63
64class MockNavService {
65}
66
67class MockMastService {
68}
69
70class MockThemeService {
71}
72
73class MockWebSocketService {
74 createWebSocket() {
75 }
76
77 isConnected() {
78 return false;
79 }
80
81 unbindHandlers() {
82 }
83
84 bindHandlers() {
85 }
86}
87
88/**
89 * ONOS GUI -- Cluster View Module - Unit Tests
90 */
91
92describe('ClusterComponent', () => {
93 let fs: FnService;
94 let ar: MockActivatedRoute;
95 let windowMock: Window;
96 let logServiceSpy: jasmine.SpyObj<LogService>;
97 let component: ClusterComponent;
98 let fixture: ComponentFixture<ClusterComponent>;
99
100 beforeEach(async(() => {
101 const logSpy = jasmine.createSpyObj('LogService', ['info', 'debug', 'warn', 'error']);
102 ar = new MockActivatedRoute({'debug': 'txrx'});
103 windowMock = <any>{
104 location: <any>{
105 hostname: 'foo',
106 host: 'foo',
107 port: '80',
108 protocol: 'http',
109 search: {debug: 'true'},
110 href: 'ws://foo:123/onos/ui/websock/path',
111 absUrl: 'ws://foo:123/onos/ui/websock/path'
112 }
113 };
114 fs = new FnService(ar, logSpy, windowMock);
115
116 TestBed.configureTestingModule({
117 imports: [BrowserAnimationsModule, FormsModule, RouterTestingModule],
118 declarations: [ClusterComponent, IconComponent],
119 providers: [
120 {provide: FnService, useValue: fs},
121 {provide: IconService, useClass: MockIconService},
122 {provide: GlyphService, useClass: MockGlyphService},
123 {provide: KeyService, useClass: MockKeyService},
124 {provide: LoadingService, useClass: MockLoadingService},
125 {provide: MastService, useClass: MockMastService},
126 {provide: NavService, useClass: MockNavService},
127 {provide: LogService, useValue: logSpy},
128 {provide: ThemeService, useClass: MockThemeService},
129 {provide: WebSocketService, useClass: MockWebSocketService},
130 {provide: 'Window', useValue: windowMock},
131 ]
132 }).compileComponents();
133 logServiceSpy = TestBed.get(LogService);
134 }));
135
136 beforeEach(() => {
137 fixture = TestBed.createComponent(ClusterComponent);
138 component = fixture.componentInstance;
139 fixture.detectChanges();
140 });
141
142 it('should create', () => {
143 expect(component).toBeTruthy();
144 });
145
146 it('should have a div.tabular-header inside a div#ov-cluster', () => {
147 const appDe: DebugElement = fixture.debugElement;
148 const divDe = appDe.query(By.css('div#ov-cluster div.tabular-header'));
149 expect(divDe).toBeTruthy();
150 });
151
152 it('should have a refresh button inside the div.tabular-header', () => {
153 const appDe: DebugElement = fixture.debugElement;
154 const divDe = appDe.query(By.css('div#ov-cluster div.tabular-header div.ctrl-btns div.refresh'));
155 expect(divDe).toBeTruthy();
156 });
157
158 it('should have a div.summary-list inside a div#ov-cluster', () => {
159 const appDe: DebugElement = fixture.debugElement;
160 const divDe = appDe.query(By.css('div#ov-cluster div.summary-list'));
161 expect(divDe).toBeTruthy();
162 });
163
164 it('should have a div.table-body ', () => {
165 const appDe: DebugElement = fixture.debugElement;
166 const divDe = appDe.query(By.css('div#ov-cluster div.summary-list div.table-body'));
167 expect(divDe).toBeTruthy();
168 });
169});