blob: 37f4a8ec641df4c1a5a93c87a7bc879f434bc9a4 [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 */
Sean Condon49e15be2018-05-16 16:58:29 +010016import { TestBed, inject } from '@angular/core/testing';
17
Sean Condon83fc39f2018-04-19 18:56:13 +010018import { LogService } from '../../app/log.service';
Sean Condon49e15be2018-05-16 16:58:29 +010019import { ConsoleLoggerService } from '../../app/consolelogger.service';
20import { DetectBrowserDirective } from '../../app/detectbrowser.directive';
21import { ActivatedRoute, Params } from '@angular/router';
Sean Condon83fc39f2018-04-19 18:56:13 +010022import { FnService } from '../../app/fw/util/fn.service';
23import { OnosService } from '../../app/onos.service';
Sean Condon49e15be2018-05-16 16:58:29 +010024import { of } from 'rxjs';
Sean Condon83fc39f2018-04-19 18:56:13 +010025
Sean Condon49e15be2018-05-16 16:58:29 +010026class MockFnService extends FnService {
Sean Condonfd6d11b2018-06-02 20:29:49 +010027 constructor(ar: ActivatedRoute, log: LogService, w: Window) {
28 super(ar, log, w);
Sean Condon49e15be2018-05-16 16:58:29 +010029 }
Sean Condon83fc39f2018-04-19 18:56:13 +010030}
31
Sean Condon49e15be2018-05-16 16:58:29 +010032class MockOnosService {}
33
34class MockActivatedRoute extends ActivatedRoute {
35 constructor(params: Params) {
36 super();
37 this.queryParams = of(params);
38 }
Sean Condon83fc39f2018-04-19 18:56:13 +010039}
40
41/**
42 * ONOS GUI -- Detect Browser Directive - Unit Tests
43 */
44describe('DetectBrowserDirective', () => {
Sean Condon83fc39f2018-04-19 18:56:13 +010045 let log: LogService;
46 let ar: ActivatedRoute;
Sean Condonfd6d11b2018-06-02 20:29:49 +010047 let mockWindow: Window;
Sean Condon83fc39f2018-04-19 18:56:13 +010048
49 beforeEach(() => {
Sean Condon49e15be2018-05-16 16:58:29 +010050 log = new ConsoleLoggerService();
51 ar = new MockActivatedRoute(['debug', 'DetectBrowserDirective']);
Sean Condonfd6d11b2018-06-02 20:29:49 +010052 mockWindow = <any>{
53 navigator: {
54 userAgent: 'HeadlessChrome',
55 vendor: 'Google Inc.'
56 }
57 };
Sean Condon49e15be2018-05-16 16:58:29 +010058
59 TestBed.configureTestingModule({
60 providers: [ DetectBrowserDirective,
Sean Condonfd6d11b2018-06-02 20:29:49 +010061 { provide: FnService, useValue: new MockFnService(ar, log, mockWindow) },
Sean Condon49e15be2018-05-16 16:58:29 +010062 { provide: LogService, useValue: log },
63 { provide: OnosService, useClass: MockOnosService },
64 { provide: Document, useValue: document },
Sean Condona00bf382018-06-23 07:54:01 +010065 { provide: 'Window', useFactory: (() => mockWindow ) }
Sean Condon49e15be2018-05-16 16:58:29 +010066 ]
67 });
Sean Condon83fc39f2018-04-19 18:56:13 +010068 });
69
70 afterEach(() => {
Sean Condon83fc39f2018-04-19 18:56:13 +010071 log = null;
Sean Condon83fc39f2018-04-19 18:56:13 +010072 });
73
Sean Condon49e15be2018-05-16 16:58:29 +010074 it('should create an instance', inject([DetectBrowserDirective], (directive: DetectBrowserDirective) => {
Sean Condon83fc39f2018-04-19 18:56:13 +010075 expect(directive).toBeTruthy();
Sean Condon49e15be2018-05-16 16:58:29 +010076 }));
Sean Condon83fc39f2018-04-19 18:56:13 +010077});