blob: 99f9484d3d1781c4f92213042478d04abc2a1fad [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
Matteo Scandolo71d74a42017-10-11 15:38:54 -070056 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 Scandoloc3804aa2017-08-09 16:00:43 -070063 it('should disable the global debug status', () => {
64 spyOn(window.localStorage, 'getItem')
65 .and.returnValue('true');
Matteo Scandoloc8a58c82017-08-17 17:14:38 -070066 service.toggleDebug('global');
67 expect(window.localStorage.setItem).toHaveBeenCalledWith('debug-global', 'false');
Matteo Scandoloc3804aa2017-08-09 16:00:43 -070068 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 Scandoloc8a58c82017-08-17 17:14:38 -070074 service.toggleDebug('global');
75 expect(window.localStorage.setItem).toHaveBeenCalledWith('debug-global', 'true');
Matteo Scandoloc3804aa2017-08-09 16:00:43 -070076 expect(service.status.global).toBeTruthy();
77 expect($scope.$broadcast).toHaveBeenCalledWith('xos.debug.status', service.status);
78 });
79});