blob: f8060fefcf323eab3e675755c335d056a2f099f3 [file] [log] [blame]
Bhavesh Kumard0b8bae2018-07-31 16:56:43 +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 { SettingsDetailsComponent } from './settingsdetails.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';
Bhavesh Kumard0b8bae2018-07-31 16:56:43 +053028import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
Bhavesh Kumard0b8bae2018-07-31 16:56:43 +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 loadIconDef() { }
41}
42
43class MockWebSocketService {
44 createWebSocket() { }
45 isConnected() { return false; }
46 unbindHandlers() { }
47 bindHandlers() { }
48}
49
50/**
51* ONOS GUI -- Settings Detail Panel View -- Unit Tests
52*/
53describe('SettingsdetailsComponent', () => {
54 let component: SettingsDetailsComponent;
55 let fixture: ComponentFixture<SettingsDetailsComponent>;
56 let fs: FnService;
57 let ar: MockActivatedRoute;
58 let windowMock: Window;
59 let logServiceSpy: jasmine.SpyObj<LogService>;
60
61 beforeEach(async(() => {
62 const logSpy = jasmine.createSpyObj('LogService', ['info', 'debug', 'warn', 'error']);
63 ar = new MockActivatedRoute({ 'debug': 'panel' });
64 windowMock = <any>{
65 location: <any>{
66 settingsname: 'foo',
67 settings: 'foo',
68 port: '80',
69 protocol: 'http',
70 search: { debug: 'true' },
71 href: 'ws://foo:123/onos/ui/websock/path',
72 absUrl: 'ws://foo:123/onos/ui/websock/path'
73 }
74 };
75 fs = new FnService(ar, logSpy, windowMock);
76 TestBed.configureTestingModule({
77 imports: [BrowserAnimationsModule],
78 declarations: [SettingsDetailsComponent, 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(SettingsDetailsComponent);
93 component = fixture.componentInstance;
94 fixture.detectChanges();
95 });
96
97 it('should create', () => {
98 expect(component).toBeTruthy();
99 });
100
101 it('should have an onos-icon.close-btn inside a div.top inside a div.container', () => {
102 const settingsDe: DebugElement = fixture.debugElement;
103 const divDe = settingsDe.query(By.css('div.container div.top onos-icon.close-btn'));
104 expect(divDe).toBeTruthy();
105 });
106
107 it('should have a div.top-content inside a div.container', () => {
108 const settingsDe: DebugElement = fixture.debugElement;
109 const divDe = settingsDe.query(By.css('div.container div.top-content'));
110 expect(divDe).toBeTruthy();
111 });
112
113 it('should have a div.settings-title-1 inside a div.top-content inside a div.container', () => {
114 const settingsDe: DebugElement = fixture.debugElement;
115 const divDe = settingsDe.query(By.css('div.container div.top-content div.settings-title-1'));
116 expect(divDe).toBeTruthy();
117 });
118
119 it('should have a div.settings-title-2 inside a div.top-content inside a div.container', () => {
120 const settingsDe: DebugElement = fixture.debugElement;
121 const divDe = settingsDe.query(By.css('div.container div.top-content div.settings-title-2'));
122 expect(divDe).toBeTruthy();
123 });
124
125 it('should have a div.settings-props inside a div.top-content inside a div.container', () => {
126 const settingsDe: DebugElement = fixture.debugElement;
127 const divDe = settingsDe.query(By.css('div.container div.top-content div.settings-props'));
128 expect(divDe).toBeTruthy();
129 });
130});