blob: 1889a44940cbed951a6fae900c3b1c20ac1d30c9 [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';
22
23import { LogService } from '../../../log.service';
24import { AppsComponent } from './apps.component';
25import { AppsDetailsComponent } from '../appsdetails/appsdetails.component';
26import { DialogService } from '../../../fw/layer/dialog.service';
27import { FnService } from '../../../fw/util/fn.service';
28import { IconComponent } from '../../../fw/svg/icon/icon.component';
29import { IconService } from '../../../fw/svg/icon.service';
30import { KeyService } from '../../../fw/util/key.service';
31import { LionService } from '../../../fw/util/lion.service';
32import { LoadingService } from '../../../fw/layer/loading.service';
33import { ThemeService } from '../../../fw/util/theme.service';
34import { TableFilterPipe } from '../../../fw/widget/tablefilter.pipe';
35import { UrlFnService } from '../../../fw/remote/urlfn.service';
36import { WebSocketService } from '../../../fw/remote/websocket.service';
37import { of } from 'rxjs';
38
39class MockActivatedRoute extends ActivatedRoute {
40 constructor(params: Params) {
41 super();
42 this.queryParams = of(params);
43 }
44}
45
46class MockDialogService {}
47
48class MockFnService {}
49
50class MockIconService {
51 loadIconDef() {}
52}
53
54class MockKeyService {}
55
56class MockLoadingService {
57 startAnim() {}
58 stop() {}
59 waiting() {}
60}
61
62class MockThemeService {}
63
64class MockUrlFnService {}
65
66class MockWebSocketService {
67 createWebSocket() {}
68 isConnected() { return false; }
69 unbindHandlers() {}
70 bindHandlers() {}
71}
72
73/**
74 * ONOS GUI -- Apps View -- Unit Tests
75 */
76describe('AppsComponent', () => {
77 let fs: FnService;
78 let ar: MockActivatedRoute;
79 let windowMock: Window;
80 let logServiceSpy: jasmine.SpyObj<LogService>;
81 let component: AppsComponent;
82 let fixture: ComponentFixture<AppsComponent>;
83 const bundleObj = {
84 'core.view.App': {
85 test: 'test1'
86 }
87 };
88 const mockLion = (key) => {
89 return bundleObj[key] || '%' + key + '%';
90 };
91
92 beforeEach(async(() => {
93 const logSpy = jasmine.createSpyObj('LogService', ['info', 'debug', 'warn', 'error']);
94 ar = new MockActivatedRoute({'debug': 'txrx'});
95
96 windowMock = <any>{
97 location: <any> {
98 hostname: 'foo',
99 host: 'foo',
100 port: '80',
101 protocol: 'http',
102 search: { debug: 'true'},
103 href: 'ws://foo:123/onos/ui/websock/path',
104 absUrl: 'ws://foo:123/onos/ui/websock/path'
105 }
106 };
107 fs = new FnService(ar, logSpy, windowMock);
108
109 TestBed.configureTestingModule({
110 imports: [ BrowserAnimationsModule, FormsModule ],
111 declarations: [ AppsComponent, IconComponent, AppsDetailsComponent, TableFilterPipe ],
112 providers: [
113 { provide: DialogService, useClass: MockDialogService },
114 { provide: FnService, useValue: fs },
115 { provide: IconService, useClass: MockIconService },
116 { provide: KeyService, useClass: MockKeyService },
117 { provide: LionService, useFactory: (() => {
118 return {
119 bundle: ((bundleId) => mockLion),
120 ubercache: new Array(),
121 loadCbs: new Map<string, () => void>([])
122 };
123 })
124 },
125 { provide: LoadingService, useClass: MockLoadingService },
126 { provide: LogService, useValue: logSpy },
127 { provide: ThemeService, useClass: MockThemeService },
128 { provide: UrlFnService, useClass: MockUrlFnService },
129 { provide: WebSocketService, useClass: MockWebSocketService },
130 { provide: 'Window', useValue: windowMock },
131 ]
132 })
133 .compileComponents();
134 logServiceSpy = TestBed.get(LogService);
135 }));
136
137 beforeEach(() => {
138 fixture = TestBed.createComponent(AppsComponent);
139 component = fixture.debugElement.componentInstance;
140 fixture.detectChanges();
141 });
142
143 it('should create', () => {
144 expect(component).toBeTruthy();
145 });
146
147 it('should have a div.tabular-header inside a div#ov-app', () => {
148 const appDe: DebugElement = fixture.debugElement;
149 const divDe = appDe.query(By.css('div#ov-app div.tabular-header'));
150 expect(divDe).toBeTruthy();
151 });
152
153 it('should have a h2 inside the div.tabular-header', () => {
154 const appDe: DebugElement = fixture.debugElement;
155 const divDe = appDe.query(By.css('div#ov-app div.tabular-header h2'));
156 const div: HTMLElement = divDe.nativeElement;
157 expect(div.textContent).toEqual(' %title_apps% (0 %total%) ');
158 });
159
160 it('should have a refresh button inside the div.tabular-header', () => {
161 const appDe: DebugElement = fixture.debugElement;
162 const divDe = appDe.query(By.css('div#ov-app div.tabular-header div.ctrl-btns div.refresh'));
163 expect(divDe).toBeTruthy();
164 });
165
166 it('should have an active button inside the div.tabular-header', () => {
167 const appDe: DebugElement = fixture.debugElement;
168 const divDe = appDe.query(By.css('div#ov-app div.tabular-header div.ctrl-btns div.active'));
169 expect(divDe).toBeTruthy();
170 });
171
172 it('should have a div.summary-list inside a div#ov-app', () => {
173 const appDe: DebugElement = fixture.debugElement;
174 const divDe = appDe.query(By.css('div#ov-app div.summary-list'));
175 expect(divDe).toBeTruthy();
176 });
177});