blob: 7e0d8de39d9e23610b034780a904f4f8478a4c67 [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 { SettingsComponent } from './settings.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,
25 LoadingService,
26 LogService,
27 WebSocketService
28} from 'gui2-fw-lib';
Bhavesh Kumard0b8bae2018-07-31 16:56:43 +053029import { DebugElement } from '@angular/core';
30import { By } from '@angular/platform-browser';
31import { SettingsDetailsComponent } from '../settingsdetails/settingsdetails.component';
32import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
33
34class MockActivatedRoute extends ActivatedRoute {
35 constructor(params: Params) {
36 super();
37 this.queryParams = of(params);
38 }
39}
40
41class MockIconService {
42 loadIconDef() { }
43}
44
45class MockLoadingService {
46 startAnim() { }
47 stop() { }
48 waiting() { }
49}
50
51class MockWebSocketService {
52 createWebSocket() { }
53 isConnected() { return false; }
54 unbindHandlers() { }
55 bindHandlers() { }
56}
57
58/**
59 * ONOS GUI -- Settings View Module - Unit Tests
60 */
61describe('SettingsComponent', () => {
62 let fs: FnService;
63 let ar: MockActivatedRoute;
64 let windowMock: Window;
65 let logServiceSpy: jasmine.SpyObj<LogService>;
66 let component: SettingsComponent;
67 let fixture: ComponentFixture<SettingsComponent>;
68
69 const logSpy = jasmine.createSpyObj('LogService', ['info', 'debug', 'warn', 'error']);
70 ar = new MockActivatedRoute({ 'debug': 'txrx' });
71
72 windowMock = <any>{
73 location: <any>{
74 settingsname: 'foo',
75 settings: 'foo',
76 port: '80',
77 protocol: 'http',
78 search: { debug: 'true' },
79 href: 'ws://foo:123/onos/ui/websock/path',
80 absUrl: 'ws://foo:123/onos/ui/websock/path'
81 }
82 };
83 fs = new FnService(ar, logSpy, windowMock);
84
85 beforeEach(async(() => {
86 TestBed.configureTestingModule({
87 imports: [BrowserAnimationsModule],
88 declarations: [SettingsComponent, IconComponent, SettingsDetailsComponent],
89 providers: [
90 { provide: FnService, useValue: fs },
91 { provide: IconService, useClass: MockIconService },
92 { provide: LoadingService, useClass: MockLoadingService },
93 { provide: LogService, useValue: logSpy },
94 { provide: WebSocketService, useClass: MockWebSocketService },
95 ]
96 })
97 .compileComponents();
98 logServiceSpy = TestBed.get(LogService);
99 }));
100
101 beforeEach(() => {
102 fixture = TestBed.createComponent(SettingsComponent);
103 component = fixture.componentInstance;
104 fixture.detectChanges();
105 });
106
107 it('should create', () => {
108 expect(component).toBeTruthy();
109 });
110
111 it('should have a div.tabular-header inside a div#ov-settings', () => {
112 const settingsDe: DebugElement = fixture.debugElement;
113 const divDe = settingsDe.query(By.css('div#ov-settings div.tabular-header'));
114 expect(divDe).toBeTruthy();
115 });
116
117 it('should have a h2 inside the div.tabular-header', () => {
118 const settingsDe: DebugElement = fixture.debugElement;
119 const divDe = settingsDe.query(By.css('div#ov-settings div.tabular-header h2'));
120 const div: HTMLElement = divDe.nativeElement;
121 expect(div.textContent).toEqual('Component Settings (0 total)');
122 });
123
124 it('should have a refresh button inside the div.tabular-header', () => {
125 const settingsDe: DebugElement = fixture.debugElement;
126 const divDe = settingsDe.query(By.css('div#ov-settings div.tabular-header div.ctrl-btns div.refresh'));
127 expect(divDe).toBeTruthy();
128 });
129
130 it('should have a div.summary-list inside a div#ov-settings', () => {
131 const settingsDe: DebugElement = fixture.debugElement;
132 const divDe = settingsDe.query(By.css('div#ov-settings div.summary-list'));
133 expect(divDe).toBeTruthy();
134 });
135
136 it('should have a div.table-header inside a div.summary-list inside a div#ov-settings', () => {
137 const settingsDe: DebugElement = fixture.debugElement;
138 const divDe = settingsDe.query(By.css('div#ov-settings div.summary-list div.table-header'));
139 expect(divDe).toBeTruthy();
140 });
141
142 it('should have a div.table-body inside a div.summary-list inside a div#ov-settings', () => {
143 const settingsDe: DebugElement = fixture.debugElement;
144 const divDe = settingsDe.query(By.css('div#ov-settings div.summary-list div.table-body'));
145 expect(divDe).toBeTruthy();
146 });
147});