Sean Condon | 28ecc5f | 2018-06-25 12:50:16 +0100 | [diff] [blame] | 1 | /* |
| 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 | */ |
| 16 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; |
| 17 | import { ActivatedRoute, Params } from '@angular/router'; |
| 18 | import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; |
| 19 | import { DebugElement } from '@angular/core'; |
| 20 | import { By } from '@angular/platform-browser'; |
| 21 | |
| 22 | import { LogService } from '../../../log.service'; |
| 23 | import { AppsDetailsComponent } from './appsdetails.component'; |
| 24 | import { FnService } from '../../../../app/fw/util/fn.service'; |
| 25 | import { IconComponent } from '../../../../app/fw/svg/icon/icon.component'; |
| 26 | import { IconService } from '../../../../app/fw/svg/icon.service'; |
| 27 | import { LionService } from '../../../../app/fw/util/lion.service'; |
| 28 | import { UrlFnService } from '../../../fw/remote/urlfn.service'; |
| 29 | import { WebSocketService } from '../../../fw/remote/websocket.service'; |
| 30 | import { of } from 'rxjs'; |
| 31 | |
| 32 | class MockActivatedRoute extends ActivatedRoute { |
| 33 | constructor(params: Params) { |
| 34 | super(); |
| 35 | this.queryParams = of(params); |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | class MockFnService {} |
| 40 | |
| 41 | class MockIconService { |
| 42 | loadIconDef() {} |
| 43 | } |
| 44 | |
| 45 | class MockUrlFnService {} |
| 46 | |
| 47 | class MockWebSocketService { |
| 48 | createWebSocket() {} |
| 49 | isConnected() { return false; } |
| 50 | unbindHandlers() {} |
| 51 | bindHandlers() {} |
| 52 | } |
| 53 | |
| 54 | /** |
| 55 | * ONOS GUI -- Apps Detail Panel View -- Unit Tests |
| 56 | */ |
| 57 | describe('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 | }); |