Sean Condon | 83fc39f | 2018-04-19 18:56:13 +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 { TestBed, inject } from '@angular/core/testing'; |
Sean Condon | aa4366d | 2018-11-02 14:29:01 +0000 | [diff] [blame] | 17 | import { ActivatedRoute, Params } from '@angular/router'; |
| 18 | import {of} from 'rxjs'; |
| 19 | |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 20 | import { TopologyService } from './topology.service'; |
Sean Condon | aa4366d | 2018-11-02 14:29:01 +0000 | [diff] [blame] | 21 | import { |
| 22 | LogService, |
| 23 | FnService |
Sean Condon | 3dd062f | 2020-04-14 09:25:00 +0100 | [diff] [blame^] | 24 | } from 'org_onosproject_onos/web/gui2-fw-lib/public_api'; |
Sean Condon | aa4366d | 2018-11-02 14:29:01 +0000 | [diff] [blame] | 25 | |
| 26 | class MockActivatedRoute extends ActivatedRoute { |
| 27 | constructor(params: Params) { |
| 28 | super(); |
| 29 | this.queryParams = of(params); |
| 30 | } |
| 31 | } |
Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 32 | |
| 33 | /** |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 34 | * ONOS GUI -- Topology Service - Unit Tests |
Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 35 | */ |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 36 | describe('TopologyService', () => { |
Sean Condon | aa4366d | 2018-11-02 14:29:01 +0000 | [diff] [blame] | 37 | let logServiceSpy: jasmine.SpyObj<LogService>; |
| 38 | let ar: ActivatedRoute; |
| 39 | let fs: FnService; |
| 40 | let mockWindow: Window; |
Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 41 | |
Sean Condon | 49e15be | 2018-05-16 16:58:29 +0100 | [diff] [blame] | 42 | beforeEach(() => { |
Sean Condon | aa4366d | 2018-11-02 14:29:01 +0000 | [diff] [blame] | 43 | const logSpy = jasmine.createSpyObj('LogService', ['debug', 'warn', 'info']); |
| 44 | ar = new MockActivatedRoute({'debug': 'TestService'}); |
| 45 | mockWindow = <any>{ |
| 46 | innerWidth: 400, |
| 47 | innerHeight: 200, |
| 48 | navigator: { |
| 49 | userAgent: 'defaultUA' |
| 50 | }, |
| 51 | location: <any>{ |
| 52 | hostname: 'foo', |
| 53 | host: 'foo', |
| 54 | port: '80', |
| 55 | protocol: 'http', |
| 56 | search: { debug: 'true' }, |
| 57 | href: 'ws://foo:123/onos/ui/websock/path', |
| 58 | absUrl: 'ws://foo:123/onos/ui/websock/path' |
| 59 | } |
| 60 | }; |
| 61 | fs = new FnService(ar, logSpy, mockWindow); |
Sean Condon | 49e15be | 2018-05-16 16:58:29 +0100 | [diff] [blame] | 62 | |
| 63 | TestBed.configureTestingModule({ |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 64 | providers: [TopologyService, |
Sean Condon | aa4366d | 2018-11-02 14:29:01 +0000 | [diff] [blame] | 65 | { provide: FnService, useValue: fs}, |
| 66 | { provide: LogService, useValue: logSpy }, |
| 67 | { provide: ActivatedRoute, useValue: ar }, |
| 68 | { provide: 'Window', useFactory: (() => mockWindow ) } |
Sean Condon | 49e15be | 2018-05-16 16:58:29 +0100 | [diff] [blame] | 69 | ] |
| 70 | }); |
Sean Condon | aa4366d | 2018-11-02 14:29:01 +0000 | [diff] [blame] | 71 | logServiceSpy = TestBed.get(LogService); |
Sean Condon | 49e15be | 2018-05-16 16:58:29 +0100 | [diff] [blame] | 72 | }); |
| 73 | |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 74 | it('should be created', inject([TopologyService], (service: TopologyService) => { |
Sean Condon | 49e15be | 2018-05-16 16:58:29 +0100 | [diff] [blame] | 75 | expect(service).toBeTruthy(); |
| 76 | })); |
Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 77 | }); |