Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 1 | /* |
| 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 Condon | 49e15be | 2018-05-16 16:58:29 +0100 | [diff] [blame] | 16 | import { TestBed, inject } from '@angular/core/testing'; |
| 17 | |
Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 18 | import { LogService } from '../../app/log.service'; |
Sean Condon | 49e15be | 2018-05-16 16:58:29 +0100 | [diff] [blame] | 19 | import { ConsoleLoggerService } from '../../app/consolelogger.service'; |
| 20 | import { DetectBrowserDirective } from '../../app/detectbrowser.directive'; |
| 21 | import { ActivatedRoute, Params } from '@angular/router'; |
Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 22 | import { FnService } from '../../app/fw/util/fn.service'; |
| 23 | import { OnosService } from '../../app/onos.service'; |
Sean Condon | 49e15be | 2018-05-16 16:58:29 +0100 | [diff] [blame] | 24 | import { of } from 'rxjs'; |
Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 25 | |
Sean Condon | 49e15be | 2018-05-16 16:58:29 +0100 | [diff] [blame] | 26 | class MockFnService extends FnService { |
Sean Condon | fd6d11b | 2018-06-02 20:29:49 +0100 | [diff] [blame] | 27 | constructor(ar: ActivatedRoute, log: LogService, w: Window) { |
| 28 | super(ar, log, w); |
Sean Condon | 49e15be | 2018-05-16 16:58:29 +0100 | [diff] [blame] | 29 | } |
Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 30 | } |
| 31 | |
Sean Condon | 49e15be | 2018-05-16 16:58:29 +0100 | [diff] [blame] | 32 | class MockOnosService {} |
| 33 | |
| 34 | class MockActivatedRoute extends ActivatedRoute { |
| 35 | constructor(params: Params) { |
| 36 | super(); |
| 37 | this.queryParams = of(params); |
| 38 | } |
Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 39 | } |
| 40 | |
| 41 | /** |
| 42 | * ONOS GUI -- Detect Browser Directive - Unit Tests |
| 43 | */ |
| 44 | describe('DetectBrowserDirective', () => { |
Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 45 | let log: LogService; |
| 46 | let ar: ActivatedRoute; |
Sean Condon | fd6d11b | 2018-06-02 20:29:49 +0100 | [diff] [blame] | 47 | let mockWindow: Window; |
Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 48 | |
| 49 | beforeEach(() => { |
Sean Condon | 49e15be | 2018-05-16 16:58:29 +0100 | [diff] [blame] | 50 | log = new ConsoleLoggerService(); |
| 51 | ar = new MockActivatedRoute(['debug', 'DetectBrowserDirective']); |
Sean Condon | fd6d11b | 2018-06-02 20:29:49 +0100 | [diff] [blame] | 52 | mockWindow = <any>{ |
| 53 | navigator: { |
| 54 | userAgent: 'HeadlessChrome', |
| 55 | vendor: 'Google Inc.' |
| 56 | } |
| 57 | }; |
Sean Condon | 49e15be | 2018-05-16 16:58:29 +0100 | [diff] [blame] | 58 | |
| 59 | TestBed.configureTestingModule({ |
| 60 | providers: [ DetectBrowserDirective, |
Sean Condon | fd6d11b | 2018-06-02 20:29:49 +0100 | [diff] [blame] | 61 | { provide: FnService, useValue: new MockFnService(ar, log, mockWindow) }, |
Sean Condon | 49e15be | 2018-05-16 16:58:29 +0100 | [diff] [blame] | 62 | { provide: LogService, useValue: log }, |
| 63 | { provide: OnosService, useClass: MockOnosService }, |
| 64 | { provide: Document, useValue: document }, |
Sean Condon | a00bf38 | 2018-06-23 07:54:01 +0100 | [diff] [blame] | 65 | { provide: 'Window', useFactory: (() => mockWindow ) } |
Sean Condon | 49e15be | 2018-05-16 16:58:29 +0100 | [diff] [blame] | 66 | ] |
| 67 | }); |
Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 68 | }); |
| 69 | |
| 70 | afterEach(() => { |
Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 71 | log = null; |
Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 72 | }); |
| 73 | |
Sean Condon | 49e15be | 2018-05-16 16:58:29 +0100 | [diff] [blame] | 74 | it('should create an instance', inject([DetectBrowserDirective], (directive: DetectBrowserDirective) => { |
Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 75 | expect(directive).toBeTruthy(); |
Sean Condon | 49e15be | 2018-05-16 16:58:29 +0100 | [diff] [blame] | 76 | })); |
Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 77 | }); |