blob: f890cde44f69a9da94073f66b9a980c7a92f25ae [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 { DebugElement } from '@angular/core';
20import { By } from '@angular/platform-browser';
21
22import { LogService } from '../../../log.service';
23import { AppsDetailsComponent } from './appsdetails.component';
24import { FnService } from '../../../../app/fw/util/fn.service';
25import { IconComponent } from '../../../../app/fw/svg/icon/icon.component';
26import { IconService } from '../../../../app/fw/svg/icon.service';
27import { LionService } from '../../../../app/fw/util/lion.service';
28import { UrlFnService } from '../../../fw/remote/urlfn.service';
29import { WebSocketService } from '../../../fw/remote/websocket.service';
30import { of } from 'rxjs';
31
32class MockActivatedRoute extends ActivatedRoute {
33 constructor(params: Params) {
34 super();
35 this.queryParams = of(params);
36 }
37}
38
39class MockFnService {}
40
41class MockIconService {
42 loadIconDef() {}
43}
44
45class MockUrlFnService {}
46
47class MockWebSocketService {
48 createWebSocket() {}
49 isConnected() { return false; }
50 unbindHandlers() {}
51 bindHandlers() {}
52}
53
54/**
55 * ONOS GUI -- Apps Detail Panel View -- Unit Tests
56 */
57describe('AppsDetailsComponent', () => {
58 let fs: FnService;
59 let ar: MockActivatedRoute;
60 let windowMock: Window;
61 let logServiceSpy: jasmine.SpyObj<LogService>;
62 let component: AppsDetailsComponent;
63 let fixture: ComponentFixture<AppsDetailsComponent>;
64 const bundleObj = {
65 'core.view.App': {
66 }
67 };
68 const mockLion = (key) => {
69 return bundleObj[key] || '%' + key + '%';
70 };
71
72 beforeEach(async(() => {
73 const logSpy = jasmine.createSpyObj('LogService', ['info', 'debug', 'warn', 'error']);
74 ar = new MockActivatedRoute({'debug': 'panel'});
75
76 windowMock = <any>{
77 location: <any> {
78 hostname: 'foo',
79 host: 'foo',
80 port: '80',
81 protocol: 'http',
82 search: { debug: 'true'},
83 href: 'ws://foo:123/onos/ui/websock/path',
84 absUrl: 'ws://foo:123/onos/ui/websock/path'
85 }
86 };
87 fs = new FnService(ar, logSpy, windowMock);
88
89 TestBed.configureTestingModule({
90 imports: [ BrowserAnimationsModule ],
91 declarations: [ AppsDetailsComponent, IconComponent ],
92 providers: [
93 { provide: FnService, useValue: fs },
94 { provide: IconService, useClass: MockIconService },
95 { provide: LionService, useFactory: (() => {
96 return {
97 bundle: ((bundleId) => mockLion),
98 ubercache: new Array(),
99 loadCbs: new Map<string, () => void>([])
100 };
101 })
102 },
103 { provide: LogService, useValue: logSpy },
104 { provide: UrlFnService, useClass: MockUrlFnService },
105 { provide: WebSocketService, useClass: MockWebSocketService },
106 { provide: 'Window', useValue: windowMock },
107 ]
108 })
109 .compileComponents();
110 logServiceSpy = TestBed.get(LogService);
111 }));
112
113 beforeEach(() => {
114 fixture = TestBed.createComponent(AppsDetailsComponent);
115 component = fixture.debugElement.componentInstance;
116 fixture.detectChanges();
117 });
118
119 it('should create', () => {
120 expect(component).toBeTruthy();
121 });
122
123 it('should have an onos-icon.close-btn inside a div.top inside a div.container', () => {
124 const appDe: DebugElement = fixture.debugElement;
125 const divDe = appDe.query(By.css('div.container div.top onos-icon.close-btn'));
126 expect(divDe).toBeTruthy();
127 });
128
129 it('should have a div.top-content inside a div.top inside a div.container', () => {
130 const appDe: DebugElement = fixture.debugElement;
131 const divDe = appDe.query(By.css('div.container div.top div.top-content'));
132 expect(divDe).toBeTruthy();
133 });
134
135 it('should have a div.app-title inside a div.top-content', () => {
136 const appDe: DebugElement = fixture.debugElement;
137 const divDe = appDe.query(By.css('div.top-content div.app-title'));
138 const div: HTMLElement = divDe.nativeElement;
139 expect(div.textContent).toEqual('');
140 });
141
142 it('should have an img inside a div.left div.top-content', () => {
143 const appDe: DebugElement = fixture.debugElement;
144 const divDe = appDe.query(By.css('div.top-content div.left.app-icon img'));
145 expect(divDe).toBeTruthy();
146 });
147
148 it('should have a table.app-props inside a div.right inside a div.top-content', () => {
149 const appDe: DebugElement = fixture.debugElement;
150 const divDe = appDe.query(By.css('div.top-content div.right table.app-props'));
151 const div: HTMLElement = divDe.nativeElement;
152 expect(div.textContent).toEqual('%app_id%:%state%:%category%:%version%:%origin%:%role%:');
153 });
154
155 it('should have an a inside an div.app-url inside a div.top-content', () => {
156 const appDe: DebugElement = fixture.debugElement;
157 const divDe = appDe.query(By.css('div.top-content div.app-url a'));
158 expect(divDe).toBeTruthy();
159 });
160
161 it('should have a div.app-readme inside a div.middle inside a div.container', () => {
162 const appDe: DebugElement = fixture.debugElement;
163 const divDe = appDe.query(By.css('div.container div.middle div.app-readme'));
164 expect(divDe).toBeTruthy();
165 });
166
167 it('should have a div.features inside a div.bottom inside a div.container', () => {
168 const appDe: DebugElement = fixture.debugElement;
169 const divDe = appDe.query(By.css('div.container div.bottom div.features'));
170 expect(divDe).toBeTruthy();
171 });
172});