Bhavesh Kumar | d0b8bae | 2018-07-31 16:56: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'; |
Bhavesh Kumar | d0b8bae | 2018-07-31 16:56:43 +0530 | [diff] [blame] | 27 | import { of } from 'rxjs'; |
| 28 | import { } from 'jasmine'; |
| 29 | import { RouterTestingModule } from '@angular/router/testing'; |
| 30 | import { PartitionComponent } from './partition.component'; |
Sean Condon | 95fb574 | 2019-04-02 12:16:55 +0100 | [diff] [blame^] | 31 | import {BrowserAnimationsModule} from '@angular/platform-browser/animations'; |
Bhavesh Kumar | d0b8bae | 2018-07-31 16:56:43 +0530 | [diff] [blame] | 32 | |
| 33 | class MockActivatedRoute extends ActivatedRoute { |
| 34 | constructor(params: Params) { |
| 35 | super(); |
| 36 | this.queryParams = of(params); |
| 37 | } |
| 38 | } |
| 39 | |
| 40 | class MockIconService { |
| 41 | loadIconDef() { } |
| 42 | } |
| 43 | |
Bhavesh Kumar | d0b8bae | 2018-07-31 16:56:43 +0530 | [diff] [blame] | 44 | class MockWebSocketService { |
| 45 | createWebSocket() { } |
| 46 | isConnected() { return false; } |
| 47 | unbindHandlers() { } |
| 48 | bindHandlers() { } |
| 49 | } |
| 50 | |
| 51 | /** |
| 52 | * ONOS GUI -- Partition View Module - Unit Tests |
| 53 | */ |
| 54 | describe('PartitionComponent', () => { |
| 55 | let fs: FnService; |
| 56 | let ar: MockActivatedRoute; |
| 57 | let windowMock: Window; |
| 58 | let logServiceSpy: jasmine.SpyObj<LogService>; |
| 59 | let component: PartitionComponent; |
| 60 | let fixture: ComponentFixture<PartitionComponent>; |
| 61 | |
| 62 | beforeEach(async(() => { |
| 63 | const logSpy = jasmine.createSpyObj('LogService', ['info', 'debug', 'warn', 'error']); |
| 64 | ar = new MockActivatedRoute({ 'debug': 'txrx' }); |
| 65 | |
| 66 | windowMock = <any>{ |
| 67 | location: <any>{ |
| 68 | partitionname: 'foo', |
| 69 | partition: '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 | fs = new FnService(ar, logSpy, windowMock); |
| 78 | |
| 79 | TestBed.configureTestingModule({ |
Sean Condon | 95fb574 | 2019-04-02 12:16:55 +0100 | [diff] [blame^] | 80 | imports: [BrowserAnimationsModule, RouterTestingModule], |
| 81 | declarations: [ |
| 82 | PartitionComponent, |
| 83 | IconComponent, |
| 84 | LoadingComponent |
| 85 | ], |
Bhavesh Kumar | d0b8bae | 2018-07-31 16:56:43 +0530 | [diff] [blame] | 86 | providers: [ |
| 87 | { provide: FnService, useValue: fs }, |
Bhavesh Kumar | d0b8bae | 2018-07-31 16:56:43 +0530 | [diff] [blame] | 88 | { provide: IconService, useClass: MockIconService }, |
| 89 | { provide: LogService, useValue: logSpy }, |
| 90 | { provide: WebSocketService, useClass: MockWebSocketService }, |
| 91 | ] |
| 92 | }) |
| 93 | .compileComponents(); |
| 94 | logServiceSpy = TestBed.get(LogService); |
| 95 | })); |
| 96 | |
| 97 | beforeEach(() => { |
| 98 | fixture = TestBed.createComponent(PartitionComponent); |
| 99 | component = fixture.componentInstance; |
| 100 | fixture.detectChanges(); |
| 101 | }); |
| 102 | |
| 103 | it('should create', () => { |
| 104 | expect(component).toBeTruthy(); |
| 105 | }); |
| 106 | |
| 107 | it('should have a div.tabular-header inside a div#ov-partition', () => { |
| 108 | const metDe: DebugElement = fixture.debugElement; |
| 109 | const divDe = metDe.query(By.css('div#ov-partition div.tabular-header')); |
| 110 | expect(divDe).toBeTruthy(); |
| 111 | }); |
| 112 | |
| 113 | it('should have a h2 inside the div.tabular-header', () => { |
| 114 | const metDe: DebugElement = fixture.debugElement; |
| 115 | const divDe = metDe.query(By.css('div#ov-partition div.tabular-header h2')); |
| 116 | const div: HTMLElement = divDe.nativeElement; |
| 117 | expect(div.textContent).toEqual('Partitions (0 total)'); |
| 118 | }); |
| 119 | |
| 120 | it('should have a refresh button inside the div.tabular-header', () => { |
| 121 | const metDe: DebugElement = fixture.debugElement; |
| 122 | const divDe = metDe.query(By.css('div#ov-partition div.tabular-header div.ctrl-btns div.refresh')); |
| 123 | expect(divDe).toBeTruthy(); |
| 124 | }); |
| 125 | |
| 126 | |
| 127 | it('should have a div.summary-list inside a div#ov-partition', () => { |
| 128 | const partDe: DebugElement = fixture.debugElement; |
| 129 | const divDe = partDe.query(By.css('div#ov-partition div.summary-list')); |
| 130 | expect(divDe).toBeTruthy(); |
| 131 | }); |
| 132 | |
| 133 | it('should have a div.table-header inside a div.summary-list inside a div#ov-partition', () => { |
| 134 | const partDe: DebugElement = fixture.debugElement; |
| 135 | const divDe = partDe.query(By.css('div#ov-partition div.summary-list div.table-header')); |
| 136 | expect(divDe).toBeTruthy(); |
| 137 | }); |
| 138 | |
| 139 | it('should have a div.table-body inside a div.summary-list inside a div#ov-partition', () => { |
| 140 | const partDe: DebugElement = fixture.debugElement; |
| 141 | const divDe = partDe.query(By.css('div#ov-partition div.summary-list div.table-body')); |
| 142 | expect(divDe).toBeTruthy(); |
| 143 | }); |
| 144 | }); |