blob: f5a768074af9375c1f640cd7ffcab9f05857a45d [file] [log] [blame]
Sean Condon83fc39f2018-04-19 18:56:13 +01001/*
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, inject } from '@angular/core/testing';
Sean Condonaa4366d2018-11-02 14:29:01 +000017import { ActivatedRoute, Params } from '@angular/router';
18import {of} from 'rxjs';
19
Sean Condonf4f54a12018-10-10 23:25:46 +010020import { TopologyService } from './topology.service';
Sean Condonaa4366d2018-11-02 14:29:01 +000021import {
22 LogService,
23 FnService
Sean Condon3dd062f2020-04-14 09:25:00 +010024} from 'org_onosproject_onos/web/gui2-fw-lib/public_api';
Sean Condonaa4366d2018-11-02 14:29:01 +000025
26class MockActivatedRoute extends ActivatedRoute {
27 constructor(params: Params) {
28 super();
29 this.queryParams = of(params);
30 }
31}
Sean Condon83fc39f2018-04-19 18:56:13 +010032
33/**
Sean Condonf4f54a12018-10-10 23:25:46 +010034 * ONOS GUI -- Topology Service - Unit Tests
Sean Condon83fc39f2018-04-19 18:56:13 +010035 */
Sean Condonf4f54a12018-10-10 23:25:46 +010036describe('TopologyService', () => {
Sean Condonaa4366d2018-11-02 14:29:01 +000037 let logServiceSpy: jasmine.SpyObj<LogService>;
38 let ar: ActivatedRoute;
39 let fs: FnService;
40 let mockWindow: Window;
Sean Condon83fc39f2018-04-19 18:56:13 +010041
Sean Condon49e15be2018-05-16 16:58:29 +010042 beforeEach(() => {
Sean Condonaa4366d2018-11-02 14:29:01 +000043 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 Condon49e15be2018-05-16 16:58:29 +010062
63 TestBed.configureTestingModule({
Sean Condonf4f54a12018-10-10 23:25:46 +010064 providers: [TopologyService,
Sean Condonaa4366d2018-11-02 14:29:01 +000065 { provide: FnService, useValue: fs},
66 { provide: LogService, useValue: logSpy },
67 { provide: ActivatedRoute, useValue: ar },
68 { provide: 'Window', useFactory: (() => mockWindow ) }
Sean Condon49e15be2018-05-16 16:58:29 +010069 ]
70 });
Sean Condonaa4366d2018-11-02 14:29:01 +000071 logServiceSpy = TestBed.get(LogService);
Sean Condon49e15be2018-05-16 16:58:29 +010072 });
73
Sean Condonf4f54a12018-10-10 23:25:46 +010074 it('should be created', inject([TopologyService], (service: TopologyService) => {
Sean Condon49e15be2018-05-16 16:58:29 +010075 expect(service).toBeTruthy();
76 }));
Sean Condon83fc39f2018-04-19 18:56:13 +010077});