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