Adding keyboard shortcut to toggle notifications [S]

Change-Id: I5d69cb14141f4c484738920efee96f6c117527bc
diff --git a/src/app/core/debug/debug-summary.html b/src/app/core/debug/debug-summary.html
index 9807ac9..7e185da 100644
--- a/src/app/core/debug/debug-summary.html
+++ b/src/app/core/debug/debug-summary.html
@@ -41,5 +41,12 @@
                 <i class="fa fa-remove text-danger" ng-hide="vm.debugStatus.modelsTab"></i>
             </td>
         </tr>
+        <tr>
+            <td>Notifications</td>
+            <td class="text-right">
+                <i class="fa fa-check text-success" ng-show="vm.debugStatus.notifications"></i>
+                <i class="fa fa-remove text-danger" ng-hide="vm.debugStatus.notifications"></i>
+            </td>
+        </tr>
     </tbody>
 </table>
\ No newline at end of file
diff --git a/src/app/core/debug/debug.service.spec.ts b/src/app/core/debug/debug.service.spec.ts
index a26d8cc..99f9484 100644
--- a/src/app/core/debug/debug.service.spec.ts
+++ b/src/app/core/debug/debug.service.spec.ts
@@ -53,6 +53,13 @@
     expect(service.status.events).toBeTruthy();
   });
 
+  it('should read the notification status from localStorage', () => {
+    spyOn(window.localStorage, 'getItem')
+      .and.returnValue(null);
+    service = new XosDebugService($log, $scope, XosKeyboardShortcut);
+    expect(service.status.notifications).toBeTruthy();
+  });
+
   it('should disable the global debug status', () => {
     spyOn(window.localStorage, 'getItem')
       .and.returnValue('true');
diff --git a/src/app/core/debug/debug.service.ts b/src/app/core/debug/debug.service.ts
index f23fa06..aee1064 100644
--- a/src/app/core/debug/debug.service.ts
+++ b/src/app/core/debug/debug.service.ts
@@ -20,12 +20,13 @@
   global: boolean;
   events: boolean;
   modelsTab: boolean;
+  notifications: boolean;
 }
 
 export interface IXosDebugService {
   status: IXosDebugStatus;
   setupShortcuts(): void;
-  toggleDebug(type: 'global' | 'events' | 'modelsTab'): void;
+  toggleDebug(type: 'global' | 'events' | 'modelsTab' | 'notifications'): void;
 }
 
 export class XosDebugService implements IXosDebugService {
@@ -35,7 +36,8 @@
   public status: IXosDebugStatus = {
     global: false,
     events: false,
-    modelsTab: false
+    modelsTab: false,
+    notifications: true
   };
 
   constructor (
@@ -51,6 +53,9 @@
 
     const debugModelsTab = window.localStorage.getItem('debug-modelsTab');
     this.status.modelsTab = (debugModelsTab === 'true');
+
+    const notifications = window.localStorage.getItem('debug-notifications');
+    this.status.notifications = (notifications !== null ? notifications === 'true' : true);
   }
 
   public setupShortcuts(): void {
@@ -65,9 +70,15 @@
       cb: () => this.toggleDebug('events'),
       description: 'Toggle debug messages for WS events in browser console'
     }, 'global');
+
+    this.XosKeyboardShortcut.registerKeyBinding({
+        key: 'S',
+        cb: () => this.toggleDebug('notifications'),
+        description: 'Toggle notifications'
+    }, 'global');
   }
 
-  public toggleDebug(type: 'global' | 'events' | 'modelsTab'): void {
+  public toggleDebug(type: 'global' | 'events' | 'modelsTab' | 'notifications'): void {
     if (window.localStorage.getItem(`debug-${type}`) === 'true') {
       this.$log.info(`[XosDebug] Disabling ${type} debug`);
       window.localStorage.setItem(`debug-${type}`, 'false');
diff --git a/src/app/core/header/header.spec.ts b/src/app/core/header/header.spec.ts
index eb236b1..a4a7d90 100644
--- a/src/app/core/header/header.spec.ts
+++ b/src/app/core/header/header.spec.ts
@@ -24,6 +24,7 @@
 import 'angular-mocks';
 import {xosHeader, INotification} from './header';
 import {Subject} from 'rxjs';
+import {IXosDebugService} from '../debug/debug.service';
 
 let element, scope: angular.IRootScopeService, compile: ng.ICompileService, isolatedScope;
 const events = new Subject();
@@ -79,6 +80,17 @@
   registerKeyBinding: jasmine.createSpy('registerKeyBinding')
 };
 
+const MockXosDebug: IXosDebugService = {
+  status: {
+    global: false,
+    events: false,
+    modelsTab: false,
+    notifications: true
+  },
+  setupShortcuts: jasmine.createSpy('debug.createShortcuts'),
+  toggleDebug: jasmine.createSpy('debug.toggleDebug')
+};
+
 describe('header component', () => {
   beforeEach(() => {
     angular
@@ -96,7 +108,8 @@
       .value('StyleConfig', {
         logo: 'cord-logo.png',
       })
-      .value('SearchService', {});
+      .value('SearchService', {})
+      .value('XosDebug', MockXosDebug);
 
     angular.mock.module('xosHeader');
   });
@@ -146,7 +159,16 @@
     });
   });
 
-  it('should display a toastr for a new notification', () => {
+  it('should not display a toastr for a new notification (if notifications are disabled)', () => {
+      MockXosDebug.status.notifications = false;
+      sendEvent(infoNotification);
+      scope.$digest();
+
+      expect(MockToastr.info).not.toHaveBeenCalled();
+  });
+
+  it('should display a toastr for a new notification (if notifications are enabled)', () => {
+    MockXosDebug.status.notifications = true;
     sendEvent(infoNotification);
     scope.$digest();
 
diff --git a/src/app/core/header/header.ts b/src/app/core/header/header.ts
index a465f8f..26f6fd0 100644
--- a/src/app/core/header/header.ts
+++ b/src/app/core/header/header.ts
@@ -28,6 +28,7 @@
 import {IXosKeyboardShortcutService} from '../services/keyboard-shortcut';
 import {Subscription} from 'rxjs';
 import {IXosConfigHelpersService} from '../services/helpers/config.helpers';
+import {IXosDebugService} from '../debug/debug.service';
 
 export interface INotification extends IWSEvent {
   viewed?: boolean;
@@ -47,7 +48,8 @@
     'StyleConfig',
     'SearchService',
     'XosKeyboardShortcut',
-    'ConfigHelpers'
+    'ConfigHelpers',
+    'XosDebug'
   ];
   public notifications: INotification[] = [];
   public newNotifications: INotification[] = [];
@@ -73,7 +75,8 @@
     private StyleConfig: IXosStyleConfig,
     private SearchService: IXosSearchService,
     private XosKeyboardShortcut: IXosKeyboardShortcutService,
-    private ConfigHelpers: IXosConfigHelpersService
+    private ConfigHelpers: IXosConfigHelpersService,
+    private XosDebugService: IXosDebugService
   ) {
 
   }
@@ -123,6 +126,12 @@
         (event: IWSEvent) => {
           this.$scope.$evalAsync(() => {
 
+            if (!this.XosDebugService.status.notifications) {
+              // NOTE: notifications can be disabled
+              return;
+            }
+
+
             if (event.model === 'Diag') {
               // NOTE skip notifications for Diag model
               return;