blob: a7585536ad54f7cd6db1a789e86e8ddc45133617 [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,
Sean Condon5ca00262018-09-06 17:55:25 +010027 LogService,
28 NavService,
29 MastService,
30 TableFilterPipe,
31 ThemeService,
Sean Condon95fb5742019-04-02 12:16:55 +010032 WebSocketService, LoadingComponent
Sean Condon5ca00262018-09-06 17:55:25 +010033} from 'gui2-fw-lib';
34
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';
Bhavesh72ead492018-07-19 16:29:18 +053040import { FlowDetailsComponent } from '../flowdetails/flowdetails/flowdetails.component';
41
42class MockActivatedRoute extends ActivatedRoute {
43 constructor(params: Params) {
44 super();
45 this.queryParams = of(params);
46 }
47}
48
49class MockIconService {
50 loadIconDef() { }
51}
52
53class MockGlyphService { }
54
Bhavesh72ead492018-07-19 16:29:18 +053055class MockNavService { }
56
57class MockMastService { }
58
59class MockThemeService { }
60
61class MockWebSocketService {
62 createWebSocket() { }
63 isConnected() { return false; }
64 unbindHandlers() { }
65 bindHandlers() { }
66}
67
68/**
69 * ONOS GUI -- Flow View Module - Unit Tests
70 */
71
72describe('FlowComponent', () => {
73 let fs: FnService;
74 let ar: MockActivatedRoute;
75 let windowMock: Window;
76 let logServiceSpy: jasmine.SpyObj<LogService>;
77 let component: FlowComponent;
78 let fixture: ComponentFixture<FlowComponent>;
79
80 const bundleObj = {
81 'core.view.Flow': {
82 test: 'test1'
83 }
84 };
85 const mockLion = (key) => {
86 return bundleObj[key] || '%' + key + '%';
87 };
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 FlowComponent,
110 IconComponent,
111 TableFilterPipe,
112 FlowDetailsComponent,
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 {
120 provide: LionService, useFactory: (() => {
121 return {
122 bundle: ((bundleId) => mockLion),
123 ubercache: new Array(),
124 loadCbs: new Map<string, () => void>([])
125 };
126 })
127 },
Bhavesh72ead492018-07-19 16:29:18 +0530128 { provide: MastService, useClass: MockMastService },
129 { provide: NavService, useClass: MockNavService },
130 { provide: LogService, useValue: logSpy },
131 { provide: ThemeService, useClass: MockThemeService },
132 { provide: WebSocketService, useClass: MockWebSocketService },
133 { provide: 'Window', useValue: windowMock },
134 ]
135 }).compileComponents();
136 logServiceSpy = TestBed.get(LogService);
137 }));
138
139 beforeEach(() => {
140 fixture = TestBed.createComponent(FlowComponent);
141 component = fixture.componentInstance;
142 fixture.detectChanges();
143 });
144
145 it('should create', () => {
146 expect(component).toBeTruthy();
147 });
148
149 it('should have a div.tabular-header inside a div#ov-flow', () => {
150 const flowDe: DebugElement = fixture.debugElement;
151 const divDe = flowDe.query(By.css('div#ov-flow div.tabular-header'));
152 expect(divDe).toBeTruthy();
153 });
154
155 it('should have a h2 inside the div.tabular-header', () => {
156 const flowDe: DebugElement = fixture.debugElement;
157 const divDe = flowDe.query(By.css('div#ov-flow div.tabular-header h2'));
158 const div: HTMLElement = divDe.nativeElement;
159 expect(div.textContent).toEqual(' %title_flows% (0 %total%) ');
160 });
161
162 it('should have .table-header with "State..."', () => {
163 const flowDe: DebugElement = fixture.debugElement;
164 const divDe = flowDe.query(By.css('div#ov-flow div.table-header'));
165 const div: HTMLElement = divDe.nativeElement;
166 expect(div.textContent).toEqual('%state% %packets% %duration% %priority% %tableName% %selector% %treatment% %appName% ');
167 });
168
169 it('should have a refresh button inside the div.tabular-header', () => {
170 const flowDe: DebugElement = fixture.debugElement;
171 const divDe = flowDe.query(By.css('div#ov-flow div.tabular-header div.ctrl-btns div.refresh'));
172 expect(divDe).toBeTruthy();
173 });
174
175
176 it('should have a div.table-body ', () => {
177 const flowDe: DebugElement = fixture.debugElement;
178 const divDe = flowDe.query(By.css('div#ov-flow div.table-body'));
179 expect(divDe).toBeTruthy();
180 });
181});