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