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