Sean Condon | 28ecc5f | 2018-06-25 12:50:16 +0100 | [diff] [blame] | 1 | /* |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 2 | * Copyright 2018-present Open Networking Foundation |
Sean Condon | 28ecc5f | 2018-06-25 12:50:16 +0100 | [diff] [blame] | 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'; |
Sean Condon | 87b7850 | 2018-09-17 20:53:24 +0100 | [diff] [blame] | 17 | import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; |
| 18 | import { RouterTestingModule } from '@angular/router/testing'; |
Sean Condon | 28ecc5f | 2018-06-25 12:50:16 +0100 | [diff] [blame] | 19 | import { DebugElement } from '@angular/core'; |
| 20 | import { By } from '@angular/platform-browser'; |
| 21 | |
Sean Condon | 5ca0026 | 2018-09-06 17:55:25 +0100 | [diff] [blame] | 22 | import { LogService } from '../../log.service'; |
| 23 | import { ConsoleLoggerService } from '../../consolelogger.service'; |
Sean Condon | 28ecc5f | 2018-06-25 12:50:16 +0100 | [diff] [blame] | 24 | import { MastComponent } from './mast.component'; |
| 25 | import { IconComponent } from '../../svg/icon/icon.component'; |
Sean Condon | 87b7850 | 2018-09-17 20:53:24 +0100 | [diff] [blame] | 26 | import { ConfirmComponent } from '../../layer/confirm/confirm.component'; |
Sean Condon | 28ecc5f | 2018-06-25 12:50:16 +0100 | [diff] [blame] | 27 | import { LionService } from '../../util/lion.service'; |
| 28 | import { IconService } from '../../svg/icon.service'; |
| 29 | import { NavService } from '../../nav/nav.service'; |
| 30 | import { WebSocketService } from '../../remote/websocket.service'; |
| 31 | |
| 32 | class MockNavService {} |
| 33 | |
| 34 | class MockIconService { |
| 35 | loadIconDef() {} |
| 36 | } |
| 37 | |
| 38 | class MockWebSocketService { |
| 39 | createWebSocket() {} |
| 40 | isConnected() { return false; } |
| 41 | unbindHandlers() {} |
| 42 | bindHandlers() {} |
| 43 | } |
| 44 | |
| 45 | /** |
| 46 | * ONOS GUI -- Masthead Controller - Unit Tests |
| 47 | */ |
| 48 | describe('MastComponent', () => { |
| 49 | let log: LogService; |
| 50 | let windowMock: Window; |
| 51 | let component: MastComponent; |
| 52 | let fixture: ComponentFixture<MastComponent>; |
| 53 | const bundleObj = { |
| 54 | 'core.view.App': { |
| 55 | test: 'test1', |
| 56 | tt_help: 'Help!' |
| 57 | } |
| 58 | }; |
| 59 | const mockLion = (key) => { |
| 60 | return bundleObj[key] || '%' + key + '%'; |
| 61 | }; |
| 62 | |
| 63 | beforeEach(async(() => { |
| 64 | log = new ConsoleLoggerService(); |
| 65 | windowMock = <any>{ |
| 66 | location: <any> { |
| 67 | hostname: 'foo', |
| 68 | pathname: 'apps', |
| 69 | host: 'foo', |
| 70 | port: '80', |
| 71 | protocol: 'http', |
| 72 | search: { debug: 'true'}, |
| 73 | href: 'ws://foo:123/onos/ui/websock/path', |
| 74 | absUrl: 'ws://foo:123/onos/ui/websock/path' |
| 75 | } |
| 76 | }; |
| 77 | |
| 78 | TestBed.configureTestingModule({ |
Sean Condon | 87b7850 | 2018-09-17 20:53:24 +0100 | [diff] [blame] | 79 | imports: [ BrowserAnimationsModule, RouterTestingModule ], |
| 80 | declarations: [ MastComponent, IconComponent, ConfirmComponent ], |
Sean Condon | 28ecc5f | 2018-06-25 12:50:16 +0100 | [diff] [blame] | 81 | providers: [ |
| 82 | { provide: LogService, useValue: log }, |
| 83 | { provide: NavService, useClass: MockNavService }, |
| 84 | { provide: LionService, useFactory: (() => { |
| 85 | return { |
| 86 | bundle: ((bundleId) => mockLion), |
| 87 | ubercache: new Array(), |
| 88 | loadCbs: new Map<string, () => void>([]) |
| 89 | }; |
| 90 | }) |
| 91 | }, |
| 92 | { provide: IconService, useClass: MockIconService }, |
| 93 | { provide: WebSocketService, useClass: MockWebSocketService }, |
| 94 | { provide: 'Window', useValue: windowMock } |
| 95 | ] |
| 96 | }) |
| 97 | .compileComponents(); |
| 98 | })); |
| 99 | |
| 100 | beforeEach(() => { |
| 101 | fixture = TestBed.createComponent(MastComponent); |
| 102 | component = fixture.debugElement.componentInstance; |
| 103 | fixture.detectChanges(); |
| 104 | }); |
| 105 | |
| 106 | it('should create', () => { |
| 107 | expect(component).toBeTruthy(); |
| 108 | }); |
| 109 | |
| 110 | it('should have a div#mast-top-block', () => { |
| 111 | const appDe: DebugElement = fixture.debugElement; |
| 112 | const divDe = appDe.query(By.css('div#mast-top-block')); |
| 113 | expect(divDe).toBeTruthy(); |
| 114 | }); |
| 115 | |
| 116 | it('should have a span.nav-menu-button inside a div#mast', () => { |
| 117 | const appDe: DebugElement = fixture.debugElement; |
| 118 | const divDe = appDe.query(By.css('div#mast span.nav-menu-button')); |
| 119 | expect(divDe).toBeTruthy(); |
| 120 | }); |
| 121 | |
| 122 | it('should have a div.dropdown-parent inside a div#mast-right inside a div#mast', () => { |
| 123 | const appDe: DebugElement = fixture.debugElement; |
| 124 | const divDe = appDe.query(By.css('div#mast div#mast-right div.dropdown-parent')); |
| 125 | const div: HTMLElement = divDe.nativeElement; |
| 126 | expect(div.textContent).toEqual(' %logout% '); |
| 127 | }); |
| 128 | |
| 129 | it('should have an onos-icon inside a div#mast-right inside a div#mast', () => { |
| 130 | const appDe: DebugElement = fixture.debugElement; |
| 131 | const divDe = appDe.query(By.css('div#mast div#mast-right div.ctrl-btns div.active onos-icon')); |
| 132 | expect(divDe).toBeTruthy(); |
| 133 | }); |
| 134 | |
| 135 | }); |