blob: 6abded15ec96a0fca9e22502fa07a22bfb0bfce9 [file] [log] [blame]
prai9d445962018-07-27 13:27:43 +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';
17import { ActivatedRoute, Params } from '@angular/router';
18import { DebugElement } from '@angular/core';
19import { By } from '@angular/platform-browser';
20import { LogService } from '../../../log.service';
21import { FnService } from '../../../fw/util/fn.service';
22import { IconComponent } from '../../../fw/svg/icon/icon.component';
23import { IconService } from '../../../fw/svg/icon.service';
24import { LoadingService } from '../../../fw/layer/loading.service';
25import { WebSocketService } from '../../../fw/remote/websocket.service';
26import { of } from 'rxjs';
27import { } from 'jasmine';
28import { RouterTestingModule } from '@angular/router/testing';
29
30import { ProcessorComponent } from './processor.component';
31
32class MockActivatedRoute extends ActivatedRoute {
33 constructor(params: Params) {
34 super();
35 this.queryParams = of(params);
36 }
37}
38
39
40class MockIconService {
41 loadIconDef() { }
42}
43
44class MockLoadingService {
45 startAnim() { }
46 stop() { }
47 waiting() { }
48}
49
50class MockWebSocketService {
51 createWebSocket() { }
52 isConnected() { return false; }
53 unbindHandlers() { }
54 bindHandlers() { }
55}
56
57describe('ProcessorComponent', () => {
58 let fs: FnService;
59 let ar: MockActivatedRoute;
60 let windowMock: Window;
61 let logServiceSpy: jasmine.SpyObj<LogService>;
62 let component: ProcessorComponent;
63 let fixture: ComponentFixture<ProcessorComponent>;
64
65 const bundleObj = {
66 'core.view.Processor': {
67 test: 'test1'
68 }
69 };
70
71 beforeEach(async(() => {
72 const logSpy = jasmine.createSpyObj('LogService', ['info', 'debug', 'warn', 'error']);
73 ar = new MockActivatedRoute({ 'debug': 'txrx' });
74
75 windowMock = <any>{
76 location: <any>{
77 hostname: 'foo',
78 host: 'foo',
79 port: '80',
80 protocol: 'http',
81 search: { debug: 'true' },
82 href: 'ws://foo:123/onos/ui/websock/path',
83 absUrl: 'ws://foo:123/onos/ui/websock/path'
84 }
85 };
86 fs = new FnService(ar, logSpy, windowMock);
87
88 TestBed.configureTestingModule({
89 imports: [RouterTestingModule],
90 declarations: [ProcessorComponent, IconComponent],
91 providers: [
92 { provide: FnService, useValue: fs },
93 { provide: LoadingService, useClass: MockLoadingService },
94 { provide: IconService, useClass: MockIconService },
95 { provide: LogService, useValue: logSpy },
96 { provide: WebSocketService, useClass: MockWebSocketService },
97 ]
98 })
99 .compileComponents();
100 logServiceSpy = TestBed.get(LogService);
101 }));
102
103 beforeEach(() => {
104 fixture = TestBed.createComponent(ProcessorComponent);
105 component = fixture.componentInstance;
106 fixture.detectChanges();
107 });
108
109 it('should create', () => {
110 expect(component).toBeTruthy();
111 });
112
113
114 it('should have a div.tabular-header inside a div#ov-processor', () => {
115 const metDe: DebugElement = fixture.debugElement;
116 const divDe = metDe.query(By.css('div#ov-processor div.tabular-header'));
117 expect(divDe).toBeTruthy();
118 });
119
120 it('should have a h2 inside the div.tabular-header', () => {
121 const metDe: DebugElement = fixture.debugElement;
122 const divDe = metDe.query(By.css('div#ov-processor div.tabular-header h2'));
123 const div: HTMLElement = divDe.nativeElement;
124 expect(div.textContent).toEqual(' Packet Processors (0 Processors total) ');
125 });
126
127 it('should have a refresh button inside the div.tabular-header', () => {
128 const metDe: DebugElement = fixture.debugElement;
129 const divDe = metDe.query(By.css('div#ov-processor div.tabular-header div.ctrl-btns div.refresh'));
130 expect(divDe).toBeTruthy();
131 });
132
133
134 it('should have a div.summary-list inside a div#ov-processor', () => {
135 const hostDe: DebugElement = fixture.debugElement;
136 const divDe = hostDe.query(By.css('div#ov-processor div.summary-list'));
137 expect(divDe).toBeTruthy();
138 });
139
140 it('should have a div.table-header inside a div.summary-list inside a div#ov-processor', () => {
141 const hostDe: DebugElement = fixture.debugElement;
142 const divDe = hostDe.query(By.css('div#ov-processor div.summary-list div.table-header'));
143 expect(divDe).toBeTruthy();
144 });
145
146 it('should have a div.table-body inside a div.summary-list inside a div#ov-processor', () => {
147 const hostDe: DebugElement = fixture.debugElement;
148 const divDe = hostDe.query(By.css('div#ov-processor div.summary-list div.table-body'));
149 expect(divDe).toBeTruthy();
150 });
151});