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