blob: 8bbf482445f5fecebcaf2d8e93300c74481ea363 [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 { FlowDetailsComponent } from './flowdetails.component';
19import { ActivatedRoute, Params } from '@angular/router';
20import { of } from 'rxjs';
21import { FnService } from '../../../../fw/util/fn.service';
22import { LogService } from '../../../../log.service';
23import { IconService } from '../../../../fw/svg/icon.service';
24import { WebSocketService } from '../../../../fw/remote/websocket.service';
25import { IconComponent } from '../../../../fw/svg/icon/icon.component';
26import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
27import { DebugElement } from '@angular/core';
28import { By } from '@angular/platform-browser';
29
30class MockActivatedRoute extends ActivatedRoute {
31 constructor(params: Params) {
32 super();
33 this.queryParams = of(params);
34 }
35}
36
37class MockIconService {
38 classes = 'active-close';
39 loadIconDef() { }
40}
41
42class MockWebSocketService {
43 createWebSocket() { }
44 isConnected() { return false; }
45 unbindHandlers() { }
46 bindHandlers() { }
47}
48
49describe('FlowDetailsComponent', () => {
50 let fs: FnService;
51 let ar: MockActivatedRoute;
52 let windowMock: Window;
53 let logServiceSpy: jasmine.SpyObj<LogService>;
54 let component: FlowDetailsComponent;
55 let fixture: ComponentFixture<FlowDetailsComponent>;
56
57 beforeEach(async(() => {
58 const logSpy = jasmine.createSpyObj('LogService', ['info', 'debug', 'warn', 'error']);
59 ar = new MockActivatedRoute({ 'debug': 'panel' });
60 windowMock = <any>{
61 location: <any>{
62 hostname: 'foo',
63 host: 'foo',
64 port: '80',
65 protocol: 'http',
66 search: { debug: 'true' },
67 href: 'ws://foo:123/onos/ui/websock/path',
68 absUrl: 'ws://foo:123/onos/ui/websock/path'
69 }
70 };
71 fs = new FnService(ar, logSpy, windowMock);
72
73 TestBed.configureTestingModule({
74 imports: [BrowserAnimationsModule],
75 declarations: [FlowDetailsComponent, IconComponent],
76 providers: [
77 { provide: FnService, useValue: fs },
78 { provide: IconService, useClass: MockIconService },
79 { provide: LogService, useValue: logSpy },
80 { provide: WebSocketService, useClass: MockWebSocketService },
81 { provide: 'Window', useValue: windowMock },
82 ]
83 })
84 .compileComponents();
85 logServiceSpy = TestBed.get(LogService);
86 }));
87
88 beforeEach(() => {
89 fixture = TestBed.createComponent(FlowDetailsComponent);
90 component = fixture.componentInstance;
91 fixture.detectChanges();
92 });
93
94 it('should create', () => {
95 expect(component).toBeTruthy();
96 });
97
98 it('should have an div.close-btn div.top inside a div.container', () => {
99 const flowDe: DebugElement = fixture.debugElement;
100 const divDe = flowDe.query(By.css('div.container div.top div.close-btn'));
101 expect(divDe).toBeTruthy();
102 });
103
104 it('should have a div.flow-icon inside a div.top inside a div.container', () => {
105 const flowDe: DebugElement = fixture.debugElement;
106 const divDe = flowDe.query(By.css('div.container div.top div.flow-icon'));
107 const div: HTMLElement = divDe.nativeElement;
108 expect(div.textContent).toEqual('');
109 });
110
111 it('should have a div.top-content inside a div.top inside a div.container', () => {
112 const flowDe: DebugElement = fixture.debugElement;
113 const divDe = flowDe.query(By.css('div.container div.top div.top-content'));
114 expect(divDe).toBeTruthy();
115 });
116
117 it('should have a div.scroll inside a div.container', () => {
118 const flowDe: DebugElement = fixture.debugElement;
119 const divDe = flowDe.query(By.css('div.container div.scroll'));
120 expect(divDe).toBeTruthy();
121 });
122
123 it('should have a h2 inside a div.top inside a div.container', () => {
124 const flowDe: DebugElement = fixture.debugElement;
125 const divDe = flowDe.query(By.css('div.container div.top h2'));
126 expect(divDe).toBeTruthy();
127 });
128
129 it('should have a h3 inside a div.scroll inside a div.top inside a div.container', () => {
130 const flowDe: DebugElement = fixture.debugElement;
131 const divDe = flowDe.query(By.css('div.container div.top div.scroll h3'));
132 expect(divDe).toBeTruthy();
133 });
134
135 it('should have a hr inside a div.scroll inside a div.top inside a div.container', () => {
136 const flowDe: DebugElement = fixture.debugElement;
137 const divDe = flowDe.query(By.css('div.container div.top div.scroll hr'));
138 expect(divDe).toBeTruthy();
139 });
140});