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