blob: 699e535015ffd07ee5740ab22441671038a9850f [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 { LinkComponent } from './link.component';
19import { ActivatedRoute, Params } from '@angular/router';
20import { of } from 'rxjs';
21import { FnService } from '../../../fw/util/fn.service';
22import { LogService } from '../../../log.service';
23import { IconComponent } from '../../../fw/svg/icon/icon.component';
24import { IconService } from '../../../fw/svg/icon.service';
25import { LoadingService } from '../../../fw/layer/loading.service';
26import { WebSocketService } from '../../../fw/remote/websocket.service';
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 loadIconDef() { }
39}
40
41class MockLoadingService {
42 startAnim() { }
43 stop() { }
44 waiting() { }
45}
46
47class MockWebSocketService {
48 createWebSocket() { }
49 isConnected() { return false; }
50 unbindHandlers() { }
51 bindHandlers() { }
52}
53
54/**
55 * ONOS GUI -- Link View Module - Unit Tests
56 */
57describe('LinkComponent', () => {
58
59 let fs: FnService;
60 let ar: MockActivatedRoute;
61 let windowMock: Window;
62 let logServiceSpy: jasmine.SpyObj<LogService>;
63 let component: LinkComponent;
64 let fixture: ComponentFixture<LinkComponent>;
65
66 beforeEach(async(() => {
67 const logSpy = jasmine.createSpyObj('LogService', ['info', 'debug', 'warn', 'error']);
68 ar = new MockActivatedRoute({ 'debug': 'txrx' });
69
70 windowMock = <any>{
71 location: <any>{
72 linkname: 'foo',
73 link: 'foo',
74 port: '80',
75 protocol: 'http',
76 search: { debug: 'true' },
77 href: 'ws://foo:123/onos/ui/websock/path',
78 absUrl: 'ws://foo:123/onos/ui/websock/path'
79 }
80 };
81 fs = new FnService(ar, logSpy, windowMock);
82
83 TestBed.configureTestingModule({
84 declarations: [LinkComponent, IconComponent],
85 providers: [
86 { provide: FnService, useValue: fs },
87 { provide: IconService, useClass: MockIconService },
88 { provide: LoadingService, useClass: MockLoadingService },
89 { 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(LinkComponent);
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-link', () => {
108 const linkDe: DebugElement = fixture.debugElement;
109 const divDe = linkDe.query(By.css('div#ov-link div.tabular-header'));
110 expect(divDe).toBeTruthy();
111 });
112
113 it('should have a h2 inside the div.tabular-header', () => {
114 const linkDe: DebugElement = fixture.debugElement;
115 const divDe = linkDe.query(By.css('div#ov-link div.tabular-header h2'));
116 const div: HTMLElement = divDe.nativeElement;
117 expect(div.textContent).toEqual('Links (0 total)');
118 });
119
120 it('should have a refresh button inside the div.tabular-header', () => {
121 const linkDe: DebugElement = fixture.debugElement;
122 const divDe = linkDe.query(By.css('div#ov-link 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-link', () => {
127 const linkDe: DebugElement = fixture.debugElement;
128 const divDe = linkDe.query(By.css('div#ov-link 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-link', () => {
133 const linkDe: DebugElement = fixture.debugElement;
134 const divDe = linkDe.query(By.css('div#ov-link 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-link', () => {
139 const linkDe: DebugElement = fixture.debugElement;
140 const divDe = linkDe.query(By.css('div#ov-link div.summary-list div.table-body'));
141 expect(divDe).toBeTruthy();
142 });
143});