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