blob: 32a50e92e5aab9272f67b6ca8d02910c196e704b [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 { PortDetailsComponent } from './portdetails.component';
19import { ActivatedRoute, Params } from '@angular/router';
20import { of } from 'rxjs/index';
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';
Bhavesh72ead492018-07-19 16:29:18 +053029import { 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('PortdetailsComponent', () => {
52 let fs: FnService;
53 let ar: MockActivatedRoute;
54 let windowMock: Window;
55 let logServiceSpy: jasmine.SpyObj<LogService>;
56 let component: PortDetailsComponent;
57 let fixture: ComponentFixture<PortDetailsComponent>;
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: [PortDetailsComponent, 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(PortDetailsComponent);
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 portDe: DebugElement = fixture.debugElement;
102 const divDe = portDe.query(By.css('div.container div.top div.close-btn'));
103 expect(divDe).toBeTruthy();
104 });
105
106 it('should have a div.port-icon inside a div.top inside a div.container', () => {
107 const portDe: DebugElement = fixture.debugElement;
108 const divDe = portDe.query(By.css('div.container div.top div.port-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 portDe: DebugElement = fixture.debugElement;
115 const divDe = portDe.query(By.css('div.container div.top div.top-content'));
116 expect(divDe).toBeTruthy();
117 });
118
119 it('should have a dev.left inside a div.top-tables inside a div.top-content', () => {
120 const portDe: DebugElement = fixture.debugElement;
121 const divDe = portDe.query(By.css('div.top-content div.top-tables div.left'));
122 const div: HTMLElement = divDe.nativeElement;
Sean Condonff5bb452020-05-27 08:30:48 +0100123 expect(div.textContent).toEqual('IDDeviceTypeSpeedEnabled');
Bhavesh72ead492018-07-19 16:29:18 +0530124 });
125});