Matteo Scandolo | c3804aa | 2017-08-09 16:00:43 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017-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 | */ |
| 16 | |
| 17 | import * as angular from 'angular'; |
| 18 | import 'angular-mocks'; |
| 19 | import {XosDebugService, IXosDebugService} from './debug.service'; |
| 20 | |
| 21 | const MockShortcut = {}; |
| 22 | |
| 23 | describe('The XOS Debug service', () => { |
| 24 | let service, $log, $scope, XosKeyboardShortcut; |
| 25 | |
| 26 | beforeEach(() => { |
| 27 | angular.module('testDebug', []) |
| 28 | .service('XosDebug', XosDebugService) |
| 29 | .value('XosKeyboardShortcut', MockShortcut); |
| 30 | |
| 31 | angular.mock.module('testDebug'); |
| 32 | }); |
| 33 | |
| 34 | beforeEach(angular.mock.inject(( |
| 35 | XosDebug: IXosDebugService, |
| 36 | _$log_: ng.ILogService, |
| 37 | _$rootScope_: ng.IScope, |
| 38 | _XosKeyboardShortcut_: any |
| 39 | ) => { |
| 40 | service = XosDebug; |
| 41 | $log = _$log_; |
| 42 | $scope = _$rootScope_; |
| 43 | XosKeyboardShortcut = _XosKeyboardShortcut_; |
| 44 | spyOn(window.localStorage, 'setItem'); |
| 45 | spyOn($scope, '$broadcast'); |
| 46 | })); |
| 47 | |
| 48 | it('should read the debug status from localStorage', () => { |
| 49 | spyOn(window.localStorage, 'getItem') |
| 50 | .and.returnValue('true'); |
| 51 | service = new XosDebugService($log, $scope, XosKeyboardShortcut); |
| 52 | expect(service.status.global).toBeTruthy(); |
| 53 | expect(service.status.events).toBeTruthy(); |
| 54 | }); |
| 55 | |
Matteo Scandolo | f371725 | 2017-10-11 15:38:54 -0700 | [diff] [blame] | 56 | it('should read the notification status from localStorage', () => { |
| 57 | spyOn(window.localStorage, 'getItem') |
| 58 | .and.returnValue(null); |
| 59 | service = new XosDebugService($log, $scope, XosKeyboardShortcut); |
| 60 | expect(service.status.notifications).toBeTruthy(); |
| 61 | }); |
| 62 | |
Matteo Scandolo | c3804aa | 2017-08-09 16:00:43 -0700 | [diff] [blame] | 63 | it('should disable the global debug status', () => { |
| 64 | spyOn(window.localStorage, 'getItem') |
| 65 | .and.returnValue('true'); |
Matteo Scandolo | c8a58c8 | 2017-08-17 17:14:38 -0700 | [diff] [blame] | 66 | service.toggleDebug('global'); |
| 67 | expect(window.localStorage.setItem).toHaveBeenCalledWith('debug-global', 'false'); |
Matteo Scandolo | c3804aa | 2017-08-09 16:00:43 -0700 | [diff] [blame] | 68 | expect(service.status.global).toBeFalsy(); |
| 69 | expect($scope.$broadcast).toHaveBeenCalledWith('xos.debug.status', service.status); |
| 70 | }); |
| 71 | it('should enable the global debug status', () => { |
| 72 | spyOn(window.localStorage, 'getItem') |
| 73 | .and.returnValue('false'); |
Matteo Scandolo | c8a58c8 | 2017-08-17 17:14:38 -0700 | [diff] [blame] | 74 | service.toggleDebug('global'); |
| 75 | expect(window.localStorage.setItem).toHaveBeenCalledWith('debug-global', 'true'); |
Matteo Scandolo | c3804aa | 2017-08-09 16:00:43 -0700 | [diff] [blame] | 76 | expect(service.status.global).toBeTruthy(); |
| 77 | expect($scope.$broadcast).toHaveBeenCalledWith('xos.debug.status', service.status); |
| 78 | }); |
| 79 | }); |