blob: f5ab3d6fc527198ad7d72c2f56ceea6241f9aebe [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 { TunnelComponent } from './tunnel.component';
19import { ActivatedRoute, Params } from '@angular/router';
20import { of } from 'rxjs';
Sean Condon5ca00262018-09-06 17:55:25 +010021import {
22 FnService,
23 IconService,
24 IconComponent,
Sean Condon5ca00262018-09-06 17:55:25 +010025 LogService,
Sean Condon95fb5742019-04-02 12:16:55 +010026 WebSocketService, LoadingComponent
Sean Condon5ca00262018-09-06 17:55:25 +010027} from 'gui2-fw-lib';
Bhavesh72ead492018-07-19 16:29:18 +053028import { DebugElement } from '@angular/core';
29import { By } from '@angular/platform-browser';
Sean Condon95fb5742019-04-02 12:16:55 +010030import {BrowserAnimationsModule} from '@angular/platform-browser/animations';
Bhavesh72ead492018-07-19 16:29:18 +053031
32class MockActivatedRoute extends ActivatedRoute {
33 constructor(params: Params) {
34 super();
35 this.queryParams = of(params);
36 }
37}
38
39class MockIconService {
40 loadIconDef() { }
41}
42
Bhavesh72ead492018-07-19 16:29:18 +053043class MockWebSocketService {
44 createWebSocket() { }
45 isConnected() { return false; }
46 unbindHandlers() { }
47 bindHandlers() { }
48}
49
50/**
51 * ONOS GUI -- Tunnel View Module - Unit Tests
52 */
53describe('TunnelComponent', () => {
54
55 let fs: FnService;
56 let ar: MockActivatedRoute;
57 let windowMock: Window;
58 let logServiceSpy: jasmine.SpyObj<LogService>;
59 let component: TunnelComponent;
60 let fixture: ComponentFixture<TunnelComponent>;
61
62 beforeEach(async(() => {
63 const logSpy = jasmine.createSpyObj('LogService', ['info', 'debug', 'warn', 'error']);
64 ar = new MockActivatedRoute({ 'debug': 'txrx' });
65
66 windowMock = <any>{
67 location: <any>{
68 tunnelname: 'foo',
69 tunnel: 'foo',
70 port: '80',
71 protocol: 'http',
72 search: { debug: 'true' },
73 href: 'ws://foo:123/onos/ui/websock/path',
74 absUrl: 'ws://foo:123/onos/ui/websock/path'
75 }
76 };
77 fs = new FnService(ar, logSpy, windowMock);
78
79 TestBed.configureTestingModule({
Sean Condon95fb5742019-04-02 12:16:55 +010080 imports: [BrowserAnimationsModule],
81 declarations: [
82 TunnelComponent,
83 IconComponent,
84 LoadingComponent
85 ],
Bhavesh72ead492018-07-19 16:29:18 +053086 providers: [
87 { provide: FnService, useValue: fs },
88 { provide: IconService, useClass: MockIconService },
Bhavesh72ead492018-07-19 16:29:18 +053089 { provide: LogService, useValue: logSpy },
90 { provide: WebSocketService, useClass: MockWebSocketService },
91 ]
92 })
93 .compileComponents();
94 logServiceSpy = TestBed.get(LogService);
95 }));
96
97 beforeEach(() => {
98 fixture = TestBed.createComponent(TunnelComponent);
99 component = fixture.componentInstance;
100 fixture.detectChanges();
101 });
102
103 it('should create', () => {
104 expect(component).toBeTruthy();
105 });
106
107 it('should have a div.tabular-header inside a div#ov-tunnel', () => {
108 const tunnelDe: DebugElement = fixture.debugElement;
109 const divDe = tunnelDe.query(By.css('div#ov-tunnel div.tabular-header'));
110 expect(divDe).toBeTruthy();
111 });
112
113 it('should have a h2 inside the div.tabular-header', () => {
114 const tunnelDe: DebugElement = fixture.debugElement;
115 const divDe = tunnelDe.query(By.css('div#ov-tunnel div.tabular-header h2'));
116 const div: HTMLElement = divDe.nativeElement;
117 expect(div.textContent).toEqual('Tunnels (0 total)');
118 });
119
120 it('should have a refresh button inside the div.tabular-header', () => {
121 const tunnelDe: DebugElement = fixture.debugElement;
122 const divDe = tunnelDe.query(By.css('div#ov-tunnel div.tabular-header div.ctrl-btns div.refresh'));
123 expect(divDe).toBeTruthy();
124 });
125
126 it('should have a div.summary-list inside a div#ov-tunnel', () => {
127 const tunnelDe: DebugElement = fixture.debugElement;
128 const divDe = tunnelDe.query(By.css('div#ov-tunnel div.summary-list'));
129 expect(divDe).toBeTruthy();
130 });
131
132 it('should have a div.table-header inside a div.summary-list inside a div#ov-tunnel', () => {
133 const tunnelDe: DebugElement = fixture.debugElement;
134 const divDe = tunnelDe.query(By.css('div#ov-tunnel div.summary-list div.table-header'));
135 expect(divDe).toBeTruthy();
136 });
137
138 it('should have a div.table-body inside a div.summary-list inside a div#ov-tunnel', () => {
139 const tunnelDe: DebugElement = fixture.debugElement;
140 const divDe = tunnelDe.query(By.css('div#ov-tunnel div.summary-list div.table-body'));
141 expect(divDe).toBeTruthy();
142 });
143});