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