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