prai | 9d44596 | 2018-07-27 13:27:43 +0530 | [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 { DebugElement } from '@angular/core'; |
| 19 | import { By } from '@angular/platform-browser'; |
Sean Condon | 5ca0026 | 2018-09-06 17:55:25 +0100 | [diff] [blame] | 20 | import { |
| 21 | FnService, |
| 22 | IconService, |
| 23 | IconComponent, |
Sean Condon | 5ca0026 | 2018-09-06 17:55:25 +0100 | [diff] [blame] | 24 | LogService, |
Sean Condon | 95fb574 | 2019-04-02 12:16:55 +0100 | [diff] [blame^] | 25 | WebSocketService, LoadingComponent |
Sean Condon | 5ca0026 | 2018-09-06 17:55:25 +0100 | [diff] [blame] | 26 | } from 'gui2-fw-lib'; |
prai | 9d44596 | 2018-07-27 13:27:43 +0530 | [diff] [blame] | 27 | import { of } from 'rxjs'; |
| 28 | import { } from 'jasmine'; |
| 29 | import { RouterTestingModule } from '@angular/router/testing'; |
| 30 | |
| 31 | import { ProcessorComponent } from './processor.component'; |
Sean Condon | 95fb574 | 2019-04-02 12:16:55 +0100 | [diff] [blame^] | 32 | import {BrowserAnimationsModule} from '@angular/platform-browser/animations'; |
prai | 9d44596 | 2018-07-27 13:27:43 +0530 | [diff] [blame] | 33 | |
| 34 | class MockActivatedRoute extends ActivatedRoute { |
| 35 | constructor(params: Params) { |
| 36 | super(); |
| 37 | this.queryParams = of(params); |
| 38 | } |
| 39 | } |
| 40 | |
| 41 | |
| 42 | class MockIconService { |
| 43 | loadIconDef() { } |
| 44 | } |
| 45 | |
prai | 9d44596 | 2018-07-27 13:27:43 +0530 | [diff] [blame] | 46 | class MockWebSocketService { |
| 47 | createWebSocket() { } |
| 48 | isConnected() { return false; } |
| 49 | unbindHandlers() { } |
| 50 | bindHandlers() { } |
| 51 | } |
| 52 | |
| 53 | describe('ProcessorComponent', () => { |
| 54 | let fs: FnService; |
| 55 | let ar: MockActivatedRoute; |
| 56 | let windowMock: Window; |
| 57 | let logServiceSpy: jasmine.SpyObj<LogService>; |
| 58 | let component: ProcessorComponent; |
| 59 | let fixture: ComponentFixture<ProcessorComponent>; |
| 60 | |
| 61 | const bundleObj = { |
| 62 | 'core.view.Processor': { |
| 63 | test: 'test1' |
| 64 | } |
| 65 | }; |
| 66 | |
| 67 | beforeEach(async(() => { |
| 68 | const logSpy = jasmine.createSpyObj('LogService', ['info', 'debug', 'warn', 'error']); |
| 69 | ar = new MockActivatedRoute({ 'debug': 'txrx' }); |
| 70 | |
| 71 | windowMock = <any>{ |
| 72 | location: <any>{ |
| 73 | hostname: 'foo', |
| 74 | host: 'foo', |
| 75 | port: '80', |
| 76 | protocol: 'http', |
| 77 | search: { debug: 'true' }, |
| 78 | href: 'ws://foo:123/onos/ui/websock/path', |
| 79 | absUrl: 'ws://foo:123/onos/ui/websock/path' |
| 80 | } |
| 81 | }; |
| 82 | fs = new FnService(ar, logSpy, windowMock); |
| 83 | |
| 84 | TestBed.configureTestingModule({ |
Sean Condon | 95fb574 | 2019-04-02 12:16:55 +0100 | [diff] [blame^] | 85 | imports: [BrowserAnimationsModule, RouterTestingModule], |
| 86 | declarations: [ |
| 87 | ProcessorComponent, |
| 88 | IconComponent, |
| 89 | LoadingComponent |
| 90 | ], |
prai | 9d44596 | 2018-07-27 13:27:43 +0530 | [diff] [blame] | 91 | providers: [ |
| 92 | { provide: FnService, useValue: fs }, |
prai | 9d44596 | 2018-07-27 13:27:43 +0530 | [diff] [blame] | 93 | { provide: IconService, useClass: MockIconService }, |
| 94 | { provide: LogService, useValue: logSpy }, |
| 95 | { provide: WebSocketService, useClass: MockWebSocketService }, |
| 96 | ] |
| 97 | }) |
| 98 | .compileComponents(); |
| 99 | logServiceSpy = TestBed.get(LogService); |
| 100 | })); |
| 101 | |
| 102 | beforeEach(() => { |
| 103 | fixture = TestBed.createComponent(ProcessorComponent); |
| 104 | component = fixture.componentInstance; |
| 105 | fixture.detectChanges(); |
| 106 | }); |
| 107 | |
| 108 | it('should create', () => { |
| 109 | expect(component).toBeTruthy(); |
| 110 | }); |
| 111 | |
| 112 | |
| 113 | it('should have a div.tabular-header inside a div#ov-processor', () => { |
| 114 | const metDe: DebugElement = fixture.debugElement; |
| 115 | const divDe = metDe.query(By.css('div#ov-processor div.tabular-header')); |
| 116 | expect(divDe).toBeTruthy(); |
| 117 | }); |
| 118 | |
| 119 | it('should have a h2 inside the div.tabular-header', () => { |
| 120 | const metDe: DebugElement = fixture.debugElement; |
| 121 | const divDe = metDe.query(By.css('div#ov-processor div.tabular-header h2')); |
| 122 | const div: HTMLElement = divDe.nativeElement; |
| 123 | expect(div.textContent).toEqual(' Packet Processors (0 Processors total) '); |
| 124 | }); |
| 125 | |
| 126 | it('should have a refresh button inside the div.tabular-header', () => { |
| 127 | const metDe: DebugElement = fixture.debugElement; |
| 128 | const divDe = metDe.query(By.css('div#ov-processor div.tabular-header div.ctrl-btns div.refresh')); |
| 129 | expect(divDe).toBeTruthy(); |
| 130 | }); |
| 131 | |
| 132 | |
| 133 | it('should have a div.summary-list inside a div#ov-processor', () => { |
| 134 | const hostDe: DebugElement = fixture.debugElement; |
| 135 | const divDe = hostDe.query(By.css('div#ov-processor div.summary-list')); |
| 136 | expect(divDe).toBeTruthy(); |
| 137 | }); |
| 138 | |
| 139 | it('should have a div.table-header inside a div.summary-list inside a div#ov-processor', () => { |
| 140 | const hostDe: DebugElement = fixture.debugElement; |
| 141 | const divDe = hostDe.query(By.css('div#ov-processor div.summary-list div.table-header')); |
| 142 | expect(divDe).toBeTruthy(); |
| 143 | }); |
| 144 | |
| 145 | it('should have a div.table-body inside a div.summary-list inside a div#ov-processor', () => { |
| 146 | const hostDe: DebugElement = fixture.debugElement; |
| 147 | const divDe = hostDe.query(By.css('div#ov-processor div.summary-list div.table-body')); |
| 148 | expect(divDe).toBeTruthy(); |
| 149 | }); |
| 150 | }); |