Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 1 | /* |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 2 | * Copyright 2018-present Open Networking Foundation |
Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 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 | */ |
| 16 | import { TestBed, inject } from '@angular/core/testing'; |
| 17 | |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 18 | import { LogService } from '../log.service'; |
| 19 | import { ConsoleLoggerService } from '../consolelogger.service'; |
| 20 | import { PrefsService } from '../util/prefs.service'; |
| 21 | import { FnService } from '../util/fn.service'; |
| 22 | import { WebSocketService } from '../remote/websocket.service'; |
Sean Condon | 49e15be | 2018-05-16 16:58:29 +0100 | [diff] [blame] | 23 | |
| 24 | class MockFnService {} |
| 25 | |
Sean Condon | f4f54a1 | 2018-10-10 23:25:46 +0100 | [diff] [blame] | 26 | class MockWebSocketService { |
| 27 | createWebSocket() {} |
| 28 | isConnected() { return false; } |
| 29 | unbindHandlers() {} |
| 30 | bindHandlers() {} |
| 31 | } |
Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 32 | |
| 33 | /** |
Sean Condon | 49e15be | 2018-05-16 16:58:29 +0100 | [diff] [blame] | 34 | * ONOS GUI -- Util -- User Preference Service - Unit Tests |
Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 35 | */ |
| 36 | describe('PrefsService', () => { |
Sean Condon | 49e15be | 2018-05-16 16:58:29 +0100 | [diff] [blame] | 37 | let log: LogService; |
Sean Condon | b2c483c | 2019-01-16 20:28:55 +0000 | [diff] [blame] | 38 | let windowMock: Window; |
| 39 | |
| 40 | windowMock = <any>{ |
| 41 | location: <any> { |
| 42 | hostname: 'foo', |
| 43 | host: 'foo', |
| 44 | port: '80', |
| 45 | protocol: 'http', |
| 46 | search: { debug: 'true'}, |
| 47 | href: 'ws://foo:123/onos/ui/websock/path', |
| 48 | absUrl: 'ws://foo:123/onos/ui/websock/path' |
| 49 | } |
| 50 | }; |
Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 51 | |
Sean Condon | 49e15be | 2018-05-16 16:58:29 +0100 | [diff] [blame] | 52 | beforeEach(() => { |
| 53 | log = new ConsoleLoggerService(); |
| 54 | |
| 55 | TestBed.configureTestingModule({ |
| 56 | providers: [PrefsService, |
| 57 | { provide: LogService, useValue: log }, |
| 58 | { provide: FnService, useClass: MockFnService }, |
Sean Condon | b2c483c | 2019-01-16 20:28:55 +0000 | [diff] [blame] | 59 | { provide: 'Window', useFactory: (() => windowMock ) }, |
Sean Condon | 49e15be | 2018-05-16 16:58:29 +0100 | [diff] [blame] | 60 | { provide: WebSocketService, useClass: MockWebSocketService }, |
| 61 | ] |
| 62 | }); |
| 63 | }); |
| 64 | |
| 65 | it('should be created', inject([PrefsService], (service: PrefsService) => { |
| 66 | expect(service).toBeTruthy(); |
| 67 | })); |
Sean Condon | 83fc39f | 2018-04-19 18:56:13 +0100 | [diff] [blame] | 68 | }); |