blob: 14ad396fcf7fbfd78688a2c8f9fd232cdc397e28 [file] [log] [blame]
Sean Condon28884332019-03-21 14:07:00 +00001/*
2 * Copyright 2019-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 { LayoutService } from './layout.service';
19import {ActivatedRoute, Params} from '@angular/router';
20import {of} from 'rxjs';
Sean Condon3b3fdab2020-04-14 09:25:00 +010021import {FnService, LogService} from 'org_onosproject_onos/web/gui2-fw-lib/public_api';
Sean Condon28884332019-03-21 14:07:00 +000022
23class MockActivatedRoute extends ActivatedRoute {
24 constructor(params: Params) {
25 super();
26 this.queryParams = of(params);
27 }
28}
29
30describe('LayoutService', () => {
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({
58 providers: [LayoutService,
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: LayoutService = TestBed.get(LayoutService);
70 expect(service).toBeTruthy();
71 });
72});