blob: e15f8a513dfa6bba5b737591b1662783e5c7d887 [file] [log] [blame]
Sean Condon50855cf2018-12-23 15:37:42 +00001/*
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 */
16import { TestBed } from '@angular/core/testing';
17
18import { TrafficService } from './traffic.service';
Sean Condona3ad7792020-01-04 19:26:34 +000019import {FnService, LogService} from 'gui2-fw-lib/public_api';
Sean Condon50855cf2018-12-23 15:37:42 +000020import {ActivatedRoute, Params} from '@angular/router';
21import {of} from 'rxjs';
Sean Condon50855cf2018-12-23 15:37:42 +000022
23class MockActivatedRoute extends ActivatedRoute {
24 constructor(params: Params) {
25 super();
26 this.queryParams = of(params);
27 }
28}
29
30describe('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 Condon28884332019-03-21 14:07:00 +000058 providers: [TrafficService,
Sean Condon50855cf2018-12-23 15:37:42 +000059 { 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});