blob: a26d8ccf24f6f84976e0e43f83e580a0bb524fea [file] [log] [blame]
Matteo Scandoloc3804aa2017-08-09 16:00:43 -07001/*
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
17import * as angular from 'angular';
18import 'angular-mocks';
19import {XosDebugService, IXosDebugService} from './debug.service';
20
21const MockShortcut = {};
22
23describe('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
56 it('should disable the global debug status', () => {
57 spyOn(window.localStorage, 'getItem')
58 .and.returnValue('true');
Matteo Scandoloc8a58c82017-08-17 17:14:38 -070059 service.toggleDebug('global');
60 expect(window.localStorage.setItem).toHaveBeenCalledWith('debug-global', 'false');
Matteo Scandoloc3804aa2017-08-09 16:00:43 -070061 expect(service.status.global).toBeFalsy();
62 expect($scope.$broadcast).toHaveBeenCalledWith('xos.debug.status', service.status);
63 });
64 it('should enable the global debug status', () => {
65 spyOn(window.localStorage, 'getItem')
66 .and.returnValue('false');
Matteo Scandoloc8a58c82017-08-17 17:14:38 -070067 service.toggleDebug('global');
68 expect(window.localStorage.setItem).toHaveBeenCalledWith('debug-global', 'true');
Matteo Scandoloc3804aa2017-08-09 16:00:43 -070069 expect(service.status.global).toBeTruthy();
70 expect($scope.$broadcast).toHaveBeenCalledWith('xos.debug.status', service.status);
71 });
72});