blob: a53bd1c5759a6f9812761aebdeec65bdffc9f1cf [file] [log] [blame]
Bhavesh72ead492018-07-19 16:29:18 +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 */
16
17import { async, ComponentFixture, TestBed } from '@angular/core/testing';
18
19import { PortComponent } from './port.component';
20import { ActivatedRoute, Params } from '@angular/router';
21import { of } from 'rxjs/index';
Sean Condon5ca00262018-09-06 17:55:25 +010022import {
23 FnService,
24 IconService,
25 GlyphService,
26 IconComponent,
27 LoadingService,
28 LogService,
29 NavService,
30 MastService,
31 PrefsService,
32 TableFilterPipe,
33 ThemeService,
34 WebSocketService
35} from 'gui2-fw-lib';
Bhavesh72ead492018-07-19 16:29:18 +053036import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
37import { FormsModule } from '@angular/forms';
38import { RouterTestingModule } from '@angular/router/testing';
Bhavesh72ead492018-07-19 16:29:18 +053039import { DebugElement } from '@angular/core';
40import { By } from '@angular/platform-browser';
41import { PortDetailsComponent } from '../portdetails/portdetails.component';
Bhavesh72ead492018-07-19 16:29:18 +053042class MockActivatedRoute extends ActivatedRoute {
43 constructor(params: Params) {
44 super();
45 this.queryParams = of(params);
46 }
47}
48
49class MockIconService {
50 loadIconDef() { }
51}
52
53class MockPrefsService {
54 setPrefs() { }
55 getPrefs() { }
56 asNumbers() { }
57 updatePrefs() { }
58}
59
60class MockGlyphService { }
61
Bhavesh72ead492018-07-19 16:29:18 +053062class MockLoadingService {
63 startAnim() { }
64 stop() { }
65}
66
67class MockNavService { }
68
69class MockMastService { }
70
71class MockThemeService { }
72
73class MockWebSocketService {
74 createWebSocket() { }
75 isConnected() { return false; }
76 unbindHandlers() { }
77 bindHandlers() { }
78 sendEvent() { }
79}
80
81/**
82 * ONOS GUI -- Flow View Module - Unit Tests
83 */
84
85
86describe('PortComponent', () => {
87 let fs: FnService;
88 let ar: MockActivatedRoute;
89 let windowMock: Window;
90 let logServiceSpy: jasmine.SpyObj<LogService>;
91 let component: PortComponent;
92 let fixture: ComponentFixture<PortComponent>;
93
94 beforeEach(async(() => {
95 const logSpy = jasmine.createSpyObj('LogService', ['info', 'debug', 'warn', 'error']);
96 ar = new MockActivatedRoute({ 'debug': 'txrx' });
97
98 windowMock = <any>{
99 location: <any>{
100 hostname: 'foo',
101 host: 'foo',
102 port: '80',
103 protocol: 'http',
104 search: { debug: 'true' },
105 href: 'ws://foo:123/onos/ui/websock/path',
106 absUrl: 'ws://foo:123/onos/ui/websock/path'
107 }
108 };
109 fs = new FnService(ar, logSpy, windowMock);
110
111 TestBed.configureTestingModule({
112 imports: [BrowserAnimationsModule, FormsModule, RouterTestingModule],
113 declarations: [PortComponent, IconComponent, TableFilterPipe, PortDetailsComponent],
114 providers: [
115 { provide: FnService, useValue: fs },
116 { provide: IconService, useClass: MockIconService },
117 { provide: GlyphService, useClass: MockGlyphService },
Bhavesh72ead492018-07-19 16:29:18 +0530118 { provide: LoadingService, useClass: MockLoadingService },
119 { provide: MastService, useClass: MockMastService },
120 { provide: NavService, useClass: MockNavService },
121 { provide: PrefsService, useClass: MockPrefsService },
122 { provide: LogService, useValue: logSpy },
123 { provide: ThemeService, useClass: MockThemeService },
124 { provide: WebSocketService, useClass: MockWebSocketService },
125 { provide: 'Window', useValue: windowMock },
126 ]
127 }).compileComponents();
128 logServiceSpy = TestBed.get(LogService);
129 }));
130
131 beforeEach(() => {
132 fixture = TestBed.createComponent(PortComponent);
133 component = fixture.componentInstance;
134 fixture.detectChanges();
135 });
136
137 it('should create', () => {
138 expect(component).toBeTruthy();
139 });
140
141 it('should have a div.tabular-header inside a div#ov-port', () => {
142 const portDe: DebugElement = fixture.debugElement;
143 const divDe = portDe.query(By.css('div#ov-port div.tabular-header'));
144 expect(divDe).toBeTruthy();
145 });
146
147 it('should have a h2 inside the div.tabular-header', () => {
148 const portDe: DebugElement = fixture.debugElement;
149 const divDe = portDe.query(By.css('div#ov-port div.tabular-header h2'));
150 const div: HTMLElement = divDe.nativeElement;
151 expect(div.textContent).toEqual(' Ports for Device (0 Total) ');
152 });
153
154 it('should have .table-header with "Port ID..."', () => {
155 const portDe: DebugElement = fixture.debugElement;
156 const divDe = portDe.query(By.css('div#ov-port div.table-header'));
157 const div: HTMLElement = divDe.nativeElement;
158 expect(div.textContent).toEqual(
159 'Port ID Pkts Received Pkts Sent Bytes Received Bytes Sent Pkts RX Dropped Pkts TX Dropped Duration (sec) ');
160 });
161
162 it('should have a refresh button inside the div.tabular-header', () => {
163 const portDe: DebugElement = fixture.debugElement;
164 const divDe = portDe.query(By.css('div#ov-port div.tabular-header div.ctrl-btns div.refresh'));
165 expect(divDe).toBeTruthy();
166 });
167
168 it('should have a div.table-body ', () => {
169 const portDe: DebugElement = fixture.debugElement;
170 const divDe = portDe.query(By.css('div#ov-port div.table-body'));
171 expect(divDe).toBeTruthy();
172 });
173});