Sean Condon | 28ecc5f | 2018-06-25 12:50:16 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015-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 | import { of } from 'rxjs'; |
| 22 | |
| 23 | import { ConsoleLoggerService } from '../../../consolelogger.service'; |
Bhavesh | 72ead49 | 2018-07-19 16:29:18 +0530 | [diff] [blame^] | 24 | import { FnService } from '../../util/fn.service'; |
Sean Condon | 28ecc5f | 2018-06-25 12:50:16 +0100 | [diff] [blame] | 25 | import { IconComponent } from '../../svg/icon/icon.component'; |
| 26 | import { IconService } from '../../svg/icon.service'; |
| 27 | import { LionService } from '../../util/lion.service'; |
| 28 | import { LogService } from '../../../log.service'; |
| 29 | import { NavComponent } from './nav.component'; |
| 30 | import { NavService } from '../nav.service'; |
| 31 | |
| 32 | class MockActivatedRoute extends ActivatedRoute { |
| 33 | constructor(params: Params) { |
| 34 | super(); |
| 35 | this.queryParams = of(params); |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | class MockNavService {} |
| 40 | |
| 41 | class MockIconService { |
| 42 | loadIconDef() {} |
| 43 | } |
| 44 | |
| 45 | /** |
| 46 | * ONOS GUI -- Util -- Navigation Component - Unit Tests |
| 47 | */ |
| 48 | describe('NavComponent', () => { |
| 49 | let log: LogService; |
| 50 | let fs: FnService; |
| 51 | let ar: MockActivatedRoute; |
| 52 | let windowMock: Window; |
| 53 | let component: NavComponent; |
| 54 | let fixture: ComponentFixture<NavComponent>; |
| 55 | const bundleObj = { |
| 56 | 'core.view.App': { |
| 57 | test: 'test1' |
| 58 | } |
| 59 | }; |
| 60 | const mockLion = (key) => { |
| 61 | return bundleObj[key] || '%' + key + '%'; |
| 62 | }; |
| 63 | |
| 64 | beforeEach(async(() => { |
| 65 | log = new ConsoleLoggerService(); |
| 66 | ar = new MockActivatedRoute({'debug': 'txrx'}); |
| 67 | |
| 68 | windowMock = <any>{ |
| 69 | location: <any> { |
| 70 | hostname: 'foo', |
| 71 | host: 'foo', |
| 72 | port: '80', |
| 73 | protocol: 'http', |
| 74 | search: { debug: 'true'}, |
| 75 | href: 'ws://foo:123/onos/ui/websock/path', |
| 76 | absUrl: 'ws://foo:123/onos/ui/websock/path' |
| 77 | } |
| 78 | }; |
| 79 | fs = new FnService(ar, log, windowMock); |
| 80 | |
| 81 | TestBed.configureTestingModule({ |
| 82 | imports: [ BrowserAnimationsModule ], |
| 83 | declarations: [ NavComponent, IconComponent ], |
| 84 | providers: [ |
| 85 | { provide: FnService, useValue: fs }, |
| 86 | { provide: IconService, useClass: MockIconService }, |
| 87 | { provide: LionService, useFactory: (() => { |
| 88 | return { |
| 89 | bundle: ((bundleId) => mockLion), |
| 90 | ubercache: new Array(), |
| 91 | loadCbs: new Map<string, () => void>([]) |
| 92 | }; |
| 93 | }) |
| 94 | }, |
| 95 | { provide: LogService, useValue: log }, |
| 96 | { provide: NavService, useClass: MockNavService }, |
| 97 | { provide: 'Window', useValue: windowMock }, |
| 98 | ] |
| 99 | }) |
| 100 | .compileComponents(); |
| 101 | })); |
| 102 | |
| 103 | beforeEach(() => { |
| 104 | fixture = TestBed.createComponent(NavComponent); |
| 105 | component = fixture.debugElement.componentInstance; |
| 106 | fixture.detectChanges(); |
| 107 | }); |
| 108 | |
| 109 | it('should create', () => { |
| 110 | expect(component).toBeTruthy(); |
| 111 | }); |
| 112 | |
| 113 | it('should have a nav#nav', () => { |
| 114 | const appDe: DebugElement = fixture.debugElement; |
| 115 | const divDe = appDe.query(By.css('nav#nav')); |
| 116 | expect(divDe).toBeTruthy(); |
| 117 | }); |
| 118 | |
| 119 | it('should have a platform div.nav-hdr inside a nav#nav', () => { |
| 120 | const appDe: DebugElement = fixture.debugElement; |
| 121 | const divDe = appDe.query(By.css('nav#nav div.nav-hdr')); |
| 122 | const div: HTMLElement = divDe.nativeElement; |
| 123 | expect(div.textContent).toEqual('%cat_platform%'); |
| 124 | }); |
| 125 | |
| 126 | it('should have an apps link inside a nav#nav', () => { |
| 127 | const appDe: DebugElement = fixture.debugElement; |
| 128 | const divDe = appDe.query(By.css('nav#nav a')); |
| 129 | const div: HTMLElement = divDe.nativeElement; |
Bhavesh | 72ead49 | 2018-07-19 16:29:18 +0530 | [diff] [blame^] | 130 | expect(div.textContent).toEqual(' Apps'); |
Sean Condon | 28ecc5f | 2018-06-25 12:50:16 +0100 | [diff] [blame] | 131 | }); |
| 132 | }); |