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