blob: 3e541bb17640f0c528c82e8a3e0d3ef98787869d [file] [log] [blame]
Sean Condon28ecc5f2018-06-25 12:50:16 +01001/*
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 { ActivatedRoute, Params } from '@angular/router';
18import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
19import { FormsModule } from '@angular/forms';
20import { DebugElement } from '@angular/core';
21import { By } from '@angular/platform-browser';
Sean Condon2aa86092018-07-16 09:04:05 +010022import { HttpClient, HttpErrorResponse } from '@angular/common/http';
Sean Condon28ecc5f2018-06-25 12:50:16 +010023
Sean Condon5ca00262018-09-06 17:55:25 +010024import {
25 FnService,
26 IconService,
27 LionService,
Sean Condon5ca00262018-09-06 17:55:25 +010028 LogService,
Sean Condon5ca00262018-09-06 17:55:25 +010029 UrlFnService,
30 WebSocketService,
31 TableFilterPipe,
32 ConfirmComponent,
33 FlashComponent,
34 IconComponent,
Sean Condon95fb5742019-04-02 12:16:55 +010035 ThemeService, LoadingComponent,
Sean Condon5ca00262018-09-06 17:55:25 +010036} from 'gui2-fw-lib';
37
Sean Condon28ecc5f2018-06-25 12:50:16 +010038import { AppsComponent } from './apps.component';
39import { AppsDetailsComponent } from '../appsdetails/appsdetails.component';
Sean Condon28ecc5f2018-06-25 12:50:16 +010040import { of } from 'rxjs';
Bhavesh72ead492018-07-19 16:29:18 +053041import { } from 'jasmine';
Sean Condon28ecc5f2018-06-25 12:50:16 +010042
43class MockActivatedRoute extends ActivatedRoute {
44 constructor(params: Params) {
45 super();
46 this.queryParams = of(params);
47 }
48}
49
Bhavesh72ead492018-07-19 16:29:18 +053050class MockFnService { }
Sean Condon28ecc5f2018-06-25 12:50:16 +010051
Sean Condon2aa86092018-07-16 09:04:05 +010052class MockHttpClient {}
53
Sean Condon28ecc5f2018-06-25 12:50:16 +010054class MockIconService {
Bhavesh72ead492018-07-19 16:29:18 +053055 loadIconDef() { }
Sean Condon28ecc5f2018-06-25 12:50:16 +010056}
57
Bhavesh72ead492018-07-19 16:29:18 +053058class MockThemeService { }
Sean Condon28ecc5f2018-06-25 12:50:16 +010059
Bhavesh72ead492018-07-19 16:29:18 +053060class MockUrlFnService { }
Sean Condon28ecc5f2018-06-25 12:50:16 +010061
62class MockWebSocketService {
Bhavesh72ead492018-07-19 16:29:18 +053063 createWebSocket() { }
Sean Condon28ecc5f2018-06-25 12:50:16 +010064 isConnected() { return false; }
Bhavesh72ead492018-07-19 16:29:18 +053065 unbindHandlers() { }
66 bindHandlers() { }
Sean Condon28ecc5f2018-06-25 12:50:16 +010067}
68
69/**
70 * ONOS GUI -- Apps View -- Unit Tests
71 */
72describe('AppsComponent', () => {
73 let fs: FnService;
74 let ar: MockActivatedRoute;
75 let windowMock: Window;
76 let logServiceSpy: jasmine.SpyObj<LogService>;
77 let component: AppsComponent;
78 let fixture: ComponentFixture<AppsComponent>;
79 const bundleObj = {
80 'core.view.App': {
81 test: 'test1'
82 }
83 };
Bhavesh72ead492018-07-19 16:29:18 +053084 const mockLion = (key) => {
Sean Condon28ecc5f2018-06-25 12:50:16 +010085 return bundleObj[key] || '%' + key + '%';
86 };
87
88 beforeEach(async(() => {
89 const logSpy = jasmine.createSpyObj('LogService', ['info', 'debug', 'warn', 'error']);
Bhavesh72ead492018-07-19 16:29:18 +053090 ar = new MockActivatedRoute({ 'debug': 'txrx' });
Sean Condon28ecc5f2018-06-25 12:50:16 +010091
92 windowMock = <any>{
Bhavesh72ead492018-07-19 16:29:18 +053093 location: <any>{
Sean Condon28ecc5f2018-06-25 12:50:16 +010094 hostname: 'foo',
95 host: 'foo',
96 port: '80',
97 protocol: 'http',
Bhavesh72ead492018-07-19 16:29:18 +053098 search: { debug: 'true' },
Sean Condon28ecc5f2018-06-25 12:50:16 +010099 href: 'ws://foo:123/onos/ui/websock/path',
100 absUrl: 'ws://foo:123/onos/ui/websock/path'
101 }
102 };
103 fs = new FnService(ar, logSpy, windowMock);
104
105 TestBed.configureTestingModule({
106 imports: [ BrowserAnimationsModule, FormsModule ],
Sean Condon2aa86092018-07-16 09:04:05 +0100107 declarations: [
108 AppsComponent,
109 ConfirmComponent,
110 IconComponent,
111 AppsDetailsComponent,
112 TableFilterPipe,
Sean Condon95fb5742019-04-02 12:16:55 +0100113 FlashComponent,
114 LoadingComponent
Sean Condon2aa86092018-07-16 09:04:05 +0100115 ],
Sean Condon28ecc5f2018-06-25 12:50:16 +0100116 providers: [
Sean Condon28ecc5f2018-06-25 12:50:16 +0100117 { provide: FnService, useValue: fs },
Sean Condon2aa86092018-07-16 09:04:05 +0100118 { provide: HttpClient, useClass: MockHttpClient },
Sean Condon28ecc5f2018-06-25 12:50:16 +0100119 { provide: IconService, useClass: MockIconService },
Bhavesh72ead492018-07-19 16:29:18 +0530120 {
121 provide: LionService, useFactory: (() => {
Sean Condon28ecc5f2018-06-25 12:50:16 +0100122 return {
123 bundle: ((bundleId) => mockLion),
124 ubercache: new Array(),
125 loadCbs: new Map<string, () => void>([])
126 };
127 })
128 },
Sean Condon28ecc5f2018-06-25 12:50:16 +0100129 { provide: LogService, useValue: logSpy },
130 { provide: ThemeService, useClass: MockThemeService },
131 { provide: UrlFnService, useClass: MockUrlFnService },
132 { provide: WebSocketService, useClass: MockWebSocketService },
133 { provide: 'Window', useValue: windowMock },
134 ]
Sean Condonf4f54a12018-10-10 23:25:46 +0100135 }).compileComponents();
Sean Condon28ecc5f2018-06-25 12:50:16 +0100136 logServiceSpy = TestBed.get(LogService);
137 }));
138
139 beforeEach(() => {
140 fixture = TestBed.createComponent(AppsComponent);
141 component = fixture.debugElement.componentInstance;
142 fixture.detectChanges();
143 });
144
145 it('should create', () => {
146 expect(component).toBeTruthy();
147 });
148
149 it('should have a div.tabular-header inside a div#ov-app', () => {
150 const appDe: DebugElement = fixture.debugElement;
151 const divDe = appDe.query(By.css('div#ov-app div.tabular-header'));
152 expect(divDe).toBeTruthy();
153 });
154
155 it('should have a h2 inside the div.tabular-header', () => {
156 const appDe: DebugElement = fixture.debugElement;
157 const divDe = appDe.query(By.css('div#ov-app div.tabular-header h2'));
158 const div: HTMLElement = divDe.nativeElement;
159 expect(div.textContent).toEqual(' %title_apps% (0 %total%) ');
160 });
161
162 it('should have a refresh button inside the div.tabular-header', () => {
163 const appDe: DebugElement = fixture.debugElement;
164 const divDe = appDe.query(By.css('div#ov-app div.tabular-header div.ctrl-btns div.refresh'));
165 expect(divDe).toBeTruthy();
166 });
167
168 it('should have an active button inside the div.tabular-header', () => {
169 const appDe: DebugElement = fixture.debugElement;
170 const divDe = appDe.query(By.css('div#ov-app div.tabular-header div.ctrl-btns div.active'));
171 expect(divDe).toBeTruthy();
172 });
173
174 it('should have a div.summary-list inside a div#ov-app', () => {
175 const appDe: DebugElement = fixture.debugElement;
176 const divDe = appDe.query(By.css('div#ov-app div.summary-list'));
177 expect(divDe).toBeTruthy();
178 });
179});