blob: e049fcf500d6502a8ed20bb570df8cb9779e093a [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 */
16import { async, ComponentFixture, TestBed } from '@angular/core/testing';
17
18import { FlowComponent } from './flow.component';
19import { ActivatedRoute, Params } from '@angular/router';
20import { of } from 'rxjs/index';
Sean Condon5ca00262018-09-06 17:55:25 +010021import {
22 FnService,
23 IconService,
24 GlyphService,
25 IconComponent,
26 LionService,
27 LoadingService,
28 LogService,
29 NavService,
30 MastService,
31 TableFilterPipe,
32 ThemeService,
33 WebSocketService
34} from 'gui2-fw-lib';
35
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';
Bhavesh72ead492018-07-19 16:29:18 +053041import { FlowDetailsComponent } from '../flowdetails/flowdetails/flowdetails.component';
42
43class MockActivatedRoute extends ActivatedRoute {
44 constructor(params: Params) {
45 super();
46 this.queryParams = of(params);
47 }
48}
49
50class MockIconService {
51 loadIconDef() { }
52}
53
54class MockGlyphService { }
55
Bhavesh72ead492018-07-19 16:29:18 +053056class MockLoadingService {
57 startAnim() { }
58 stop() { }
59}
60
61class MockNavService { }
62
63class MockMastService { }
64
65class MockThemeService { }
66
67class MockWebSocketService {
68 createWebSocket() { }
69 isConnected() { return false; }
70 unbindHandlers() { }
71 bindHandlers() { }
72}
73
74/**
75 * ONOS GUI -- Flow View Module - Unit Tests
76 */
77
78describe('FlowComponent', () => {
79 let fs: FnService;
80 let ar: MockActivatedRoute;
81 let windowMock: Window;
82 let logServiceSpy: jasmine.SpyObj<LogService>;
83 let component: FlowComponent;
84 let fixture: ComponentFixture<FlowComponent>;
85
86 const bundleObj = {
87 'core.view.Flow': {
88 test: 'test1'
89 }
90 };
91 const mockLion = (key) => {
92 return bundleObj[key] || '%' + key + '%';
93 };
94
95 beforeEach(async(() => {
96 const logSpy = jasmine.createSpyObj('LogService', ['info', 'debug', 'warn', 'error']);
97 ar = new MockActivatedRoute({ 'debug': 'txrx' });
98
99 windowMock = <any>{
100 location: <any>{
101 hostname: 'foo',
102 host: 'foo',
103 port: '80',
104 protocol: 'http',
105 search: { debug: 'true' },
106 href: 'ws://foo:123/onos/ui/websock/path',
107 absUrl: 'ws://foo:123/onos/ui/websock/path'
108 }
109 };
110 fs = new FnService(ar, logSpy, windowMock);
111
112 TestBed.configureTestingModule({
113 imports: [BrowserAnimationsModule, FormsModule, RouterTestingModule],
114 declarations: [FlowComponent, IconComponent, TableFilterPipe, FlowDetailsComponent],
115 providers: [
116 { provide: FnService, useValue: fs },
117 { provide: IconService, useClass: MockIconService },
118 { provide: GlyphService, useClass: MockGlyphService },
Bhavesh72ead492018-07-19 16:29:18 +0530119 {
120 provide: LionService, useFactory: (() => {
121 return {
122 bundle: ((bundleId) => mockLion),
123 ubercache: new Array(),
124 loadCbs: new Map<string, () => void>([])
125 };
126 })
127 },
128 { provide: LoadingService, useClass: MockLoadingService },
129 { provide: MastService, useClass: MockMastService },
130 { provide: NavService, useClass: MockNavService },
131 { provide: LogService, useValue: logSpy },
132 { provide: ThemeService, useClass: MockThemeService },
133 { provide: WebSocketService, useClass: MockWebSocketService },
134 { provide: 'Window', useValue: windowMock },
135 ]
136 }).compileComponents();
137 logServiceSpy = TestBed.get(LogService);
138 }));
139
140 beforeEach(() => {
141 fixture = TestBed.createComponent(FlowComponent);
142 component = fixture.componentInstance;
143 fixture.detectChanges();
144 });
145
146 it('should create', () => {
147 expect(component).toBeTruthy();
148 });
149
150 it('should have a div.tabular-header inside a div#ov-flow', () => {
151 const flowDe: DebugElement = fixture.debugElement;
152 const divDe = flowDe.query(By.css('div#ov-flow div.tabular-header'));
153 expect(divDe).toBeTruthy();
154 });
155
156 it('should have a h2 inside the div.tabular-header', () => {
157 const flowDe: DebugElement = fixture.debugElement;
158 const divDe = flowDe.query(By.css('div#ov-flow div.tabular-header h2'));
159 const div: HTMLElement = divDe.nativeElement;
160 expect(div.textContent).toEqual(' %title_flows% (0 %total%) ');
161 });
162
163 it('should have .table-header with "State..."', () => {
164 const flowDe: DebugElement = fixture.debugElement;
165 const divDe = flowDe.query(By.css('div#ov-flow div.table-header'));
166 const div: HTMLElement = divDe.nativeElement;
167 expect(div.textContent).toEqual('%state% %packets% %duration% %priority% %tableName% %selector% %treatment% %appName% ');
168 });
169
170 it('should have a refresh button inside the div.tabular-header', () => {
171 const flowDe: DebugElement = fixture.debugElement;
172 const divDe = flowDe.query(By.css('div#ov-flow div.tabular-header div.ctrl-btns div.refresh'));
173 expect(divDe).toBeTruthy();
174 });
175
176
177 it('should have a div.table-body ', () => {
178 const flowDe: DebugElement = fixture.debugElement;
179 const divDe = flowDe.query(By.css('div#ov-flow div.table-body'));
180 expect(divDe).toBeTruthy();
181 });
182});