Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [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 { of } from 'rxjs'; |
| 19 | import { HttpClient } from '@angular/common/http'; |
| 20 | import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; |
| 21 | |
| 22 | import { TopologyComponent } from './topology.component'; |
Sean Condon | aa4366d | 2018-11-02 14:29:01 +0000 | [diff] [blame] | 23 | import { |
| 24 | Instance, |
| 25 | InstanceComponent |
| 26 | } from '../panel/instance/instance.component'; |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 27 | import { SummaryComponent } from '../panel/summary/summary.component'; |
| 28 | import { ToolbarComponent } from '../panel/toolbar/toolbar.component'; |
| 29 | import { DetailsComponent } from '../panel/details/details.component'; |
Sean Condon | aa4366d | 2018-11-02 14:29:01 +0000 | [diff] [blame] | 30 | import { TopologyService } from '../topology.service'; |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 31 | |
| 32 | import { |
| 33 | FlashComponent, |
| 34 | FnService, |
| 35 | LogService |
| 36 | } from 'gui2-fw-lib'; |
Sean Condon | 0c577f6 | 2018-11-18 22:40:05 +0000 | [diff] [blame^] | 37 | import {ZoomableDirective} from '../layer/zoomable.directive'; |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 38 | |
| 39 | |
| 40 | class MockActivatedRoute extends ActivatedRoute { |
| 41 | constructor(params: Params) { |
| 42 | super(); |
| 43 | this.queryParams = of(params); |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | class MockHttpClient {} |
| 48 | |
Sean Condon | aa4366d | 2018-11-02 14:29:01 +0000 | [diff] [blame] | 49 | class MockTopologyService { |
| 50 | init(instance: InstanceComponent) { |
| 51 | instance.onosInstances = [ |
| 52 | <Instance>{ |
| 53 | 'id': 'inst1', |
| 54 | 'ip': '127.0.0.1', |
| 55 | 'reachable': true, |
| 56 | 'online': true, |
| 57 | 'ready': true, |
| 58 | 'switches': 4, |
| 59 | 'uiAttached': true |
| 60 | }, |
| 61 | <Instance>{ |
| 62 | 'id': 'inst1', |
| 63 | 'ip': '127.0.0.2', |
| 64 | 'reachable': true, |
| 65 | 'online': true, |
| 66 | 'ready': true, |
| 67 | 'switches': 3, |
| 68 | 'uiAttached': false |
| 69 | } |
| 70 | ]; |
| 71 | } |
| 72 | destroy() {} |
| 73 | } |
| 74 | |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 75 | /** |
| 76 | * ONOS GUI -- Topology View -- Unit Tests |
| 77 | */ |
| 78 | describe('TopologyComponent', () => { |
| 79 | let fs: FnService; |
| 80 | let ar: MockActivatedRoute; |
| 81 | let windowMock: Window; |
| 82 | let logServiceSpy: jasmine.SpyObj<LogService>; |
| 83 | let component: TopologyComponent; |
| 84 | let fixture: ComponentFixture<TopologyComponent>; |
| 85 | |
| 86 | beforeEach(async(() => { |
| 87 | const logSpy = jasmine.createSpyObj('LogService', ['info', 'debug', 'warn', 'error']); |
| 88 | ar = new MockActivatedRoute({ 'debug': 'txrx' }); |
| 89 | |
| 90 | windowMock = <any>{ |
| 91 | location: <any>{ |
| 92 | hostname: 'foo', |
| 93 | host: 'foo', |
| 94 | port: '80', |
| 95 | protocol: 'http', |
| 96 | search: { debug: 'true' }, |
| 97 | href: 'ws://foo:123/onos/ui/websock/path', |
| 98 | absUrl: 'ws://foo:123/onos/ui/websock/path' |
| 99 | } |
| 100 | }; |
| 101 | fs = new FnService(ar, logSpy, windowMock); |
| 102 | |
| 103 | TestBed.configureTestingModule({ |
| 104 | imports: [ BrowserAnimationsModule ], |
| 105 | declarations: [ |
| 106 | TopologyComponent, |
| 107 | InstanceComponent, |
| 108 | SummaryComponent, |
| 109 | ToolbarComponent, |
| 110 | DetailsComponent, |
Sean Condon | 0c577f6 | 2018-11-18 22:40:05 +0000 | [diff] [blame^] | 111 | FlashComponent, |
| 112 | ZoomableDirective |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 113 | ], |
| 114 | providers: [ |
| 115 | { provide: FnService, useValue: fs }, |
| 116 | { provide: LogService, useValue: logSpy }, |
| 117 | { provide: 'Window', useValue: windowMock }, |
| 118 | { provide: HttpClient, useClass: MockHttpClient }, |
Sean Condon | 0c577f6 | 2018-11-18 22:40:05 +0000 | [diff] [blame^] | 119 | { provide: TopologyService, useClass: MockTopologyService }, |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 120 | ] |
| 121 | }).compileComponents(); |
| 122 | logServiceSpy = TestBed.get(LogService); |
| 123 | })); |
| 124 | |
| 125 | beforeEach(() => { |
| 126 | fixture = TestBed.createComponent(TopologyComponent); |
| 127 | component = fixture.componentInstance; |
| 128 | fixture.detectChanges(); |
| 129 | }); |
| 130 | |
| 131 | it('should create', () => { |
| 132 | expect(component).toBeTruthy(); |
| 133 | }); |
| 134 | }); |