blob: 3faa7f104e947c169111c048c95d0a1e4129abe2 [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 Condonf4f54a12018-10-10 23:25:46 +010018import { LogService } from './log.service';
19import { ConsoleLoggerService } from './consolelogger.service';
20import { DetectBrowserDirective } from './detectbrowser.directive';
Sean Condon49e15be2018-05-16 16:58:29 +010021import { ActivatedRoute, Params } from '@angular/router';
Sean Condonf4f54a12018-10-10 23:25:46 +010022import { FnService } from './util/fn.service';
23import { OnosService } from './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});