blob: b1e87e61a760018060154b270547db6de4b29c5f [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';
Sean Condon49e15be2018-05-16 16:58:29 +010017import { ActivatedRoute, Params } from '@angular/router';
Sean Condon49e15be2018-05-16 16:58:29 +010018import { of } from 'rxjs';
Sean Condonf4f54a12018-10-10 23:25:46 +010019import { TableResizeDirective } from './tableresize.directive';
20import { LogService } from '..//log.service';
21import { ConsoleLoggerService } from '../consolelogger.service';
22import { MastService } from '../mast/mast.service';
23import { FnService } from '../util/fn.service';
24
25class MockMastService {}
Sean Condon83fc39f2018-04-19 18:56:13 +010026
Sean Condon49e15be2018-05-16 16:58:29 +010027class MockFnService extends FnService {
Sean Condonfd6d11b2018-06-02 20:29:49 +010028 constructor(ar: ActivatedRoute, log: LogService, w: Window) {
29 super(ar, log, w);
Sean Condon49e15be2018-05-16 16:58:29 +010030 }
Sean Condon83fc39f2018-04-19 18:56:13 +010031}
32
Sean Condon49e15be2018-05-16 16:58:29 +010033class MockActivatedRoute extends ActivatedRoute {
34 constructor(params: Params) {
35 super();
36 this.queryParams = of(params);
37 }
Sean Condon83fc39f2018-04-19 18:56:13 +010038}
39
40/**
Sean Condonf4f54a12018-10-10 23:25:46 +010041 * ONOS GUI -- Widget -- Table Resize Directive - Unit Tests
Sean Condon83fc39f2018-04-19 18:56:13 +010042 */
Sean Condonf4f54a12018-10-10 23:25:46 +010043describe('TableResizeDirective', () => {
Sean Condon83fc39f2018-04-19 18:56:13 +010044 let log: LogService;
Sean Condonfd6d11b2018-06-02 20:29:49 +010045 let mockWindow: Window;
Sean Condonf4f54a12018-10-10 23:25:46 +010046 let ar: ActivatedRoute;
Sean Condon83fc39f2018-04-19 18:56:13 +010047
48 beforeEach(() => {
Sean Condon49e15be2018-05-16 16:58:29 +010049 log = new ConsoleLoggerService();
50 ar = new MockActivatedRoute(['debug', 'DetectBrowserDirective']);
Sean Condonfd6d11b2018-06-02 20:29:49 +010051 mockWindow = <any>{
52 navigator: {
53 userAgent: 'HeadlessChrome',
54 vendor: 'Google Inc.'
55 }
56 };
Sean Condon49e15be2018-05-16 16:58:29 +010057 TestBed.configureTestingModule({
Sean Condonf4f54a12018-10-10 23:25:46 +010058 providers: [ TableResizeDirective,
Sean Condonfd6d11b2018-06-02 20:29:49 +010059 { provide: FnService, useValue: new MockFnService(ar, log, mockWindow) },
Sean Condon49e15be2018-05-16 16:58:29 +010060 { provide: LogService, useValue: log },
Sean Condonf4f54a12018-10-10 23:25:46 +010061 { provide: MastService, useClass: MockMastService },
62 { provide: 'Window', useFactory: (() => mockWindow ) },
Sean Condon49e15be2018-05-16 16:58:29 +010063 ]
64 });
Sean Condon83fc39f2018-04-19 18:56:13 +010065 });
66
67 afterEach(() => {
Sean Condon83fc39f2018-04-19 18:56:13 +010068 log = null;
Sean Condon83fc39f2018-04-19 18:56:13 +010069 });
70
Sean Condonf4f54a12018-10-10 23:25:46 +010071 it('should create an instance', inject([TableResizeDirective], (directive: TableResizeDirective) => {
Sean Condon83fc39f2018-04-19 18:56:13 +010072 expect(directive).toBeTruthy();
Sean Condon49e15be2018-05-16 16:58:29 +010073 }));
Sean Condon83fc39f2018-04-19 18:56:13 +010074});