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