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