blob: 0f230c44962b382ab18a7881419bf4c5fbaa03d0 [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,
Sean Condon5ca00262018-09-06 17:55:25 +010027 LogService,
28 NavService,
29 MastService,
30 PrefsService,
31 TableFilterPipe,
32 ThemeService,
Sean Condon95fb5742019-04-02 12:16:55 +010033 WebSocketService, LoadingComponent
Sean Condon5ca00262018-09-06 17:55:25 +010034} from 'gui2-fw-lib';
Bhavesh72ead492018-07-19 16:29:18 +053035import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
36import { FormsModule } from '@angular/forms';
37import { RouterTestingModule } from '@angular/router/testing';
Bhavesh72ead492018-07-19 16:29:18 +053038import { DebugElement } from '@angular/core';
39import { By } from '@angular/platform-browser';
40import { PortDetailsComponent } from '../portdetails/portdetails.component';
Sean Condon95fb5742019-04-02 12:16:55 +010041
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 MockNavService { }
63
64class MockMastService { }
65
66class MockThemeService { }
67
68class MockWebSocketService {
69 createWebSocket() { }
70 isConnected() { return false; }
71 unbindHandlers() { }
72 bindHandlers() { }
73 sendEvent() { }
74}
75
76/**
77 * ONOS GUI -- Flow View Module - Unit Tests
78 */
79
80
81describe('PortComponent', () => {
82 let fs: FnService;
83 let ar: MockActivatedRoute;
84 let windowMock: Window;
85 let logServiceSpy: jasmine.SpyObj<LogService>;
86 let component: PortComponent;
87 let fixture: ComponentFixture<PortComponent>;
88
89 beforeEach(async(() => {
90 const logSpy = jasmine.createSpyObj('LogService', ['info', 'debug', 'warn', 'error']);
91 ar = new MockActivatedRoute({ 'debug': 'txrx' });
92
93 windowMock = <any>{
94 location: <any>{
95 hostname: 'foo',
96 host: 'foo',
97 port: '80',
98 protocol: 'http',
99 search: { debug: 'true' },
100 href: 'ws://foo:123/onos/ui/websock/path',
101 absUrl: 'ws://foo:123/onos/ui/websock/path'
102 }
103 };
104 fs = new FnService(ar, logSpy, windowMock);
105
106 TestBed.configureTestingModule({
107 imports: [BrowserAnimationsModule, FormsModule, RouterTestingModule],
Sean Condon95fb5742019-04-02 12:16:55 +0100108 declarations: [
109 PortComponent,
110 IconComponent,
111 TableFilterPipe,
112 PortDetailsComponent,
113 LoadingComponent
114 ],
Bhavesh72ead492018-07-19 16:29:18 +0530115 providers: [
116 { provide: FnService, useValue: fs },
117 { provide: IconService, useClass: MockIconService },
118 { provide: GlyphService, useClass: MockGlyphService },
Bhavesh72ead492018-07-19 16:29:18 +0530119 { 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});