XosConfirm tests

Change-Id: Ia7a8259d3905859d7eaeaa61fd09108238817ae9
(cherry picked from commit 7d32b1e082ba4b346c279b75f16440743560981d)
diff --git a/src/app/core/confirm/confirm.service.spec.ts b/src/app/core/confirm/confirm.service.spec.ts
index 84a61de..d05899d 100644
--- a/src/app/core/confirm/confirm.service.spec.ts
+++ b/src/app/core/confirm/confirm.service.spec.ts
@@ -23,6 +23,8 @@
 let service: IXosConfirm;
 let modal;
 let modalInstance;
+let q;
+let scope;
 
 describe('The XosConfirm service', () => {
 
@@ -33,10 +35,14 @@
 
     angular.mock.inject((
       XosConfirm: IXosConfirm,
-      $uibModal: any
+      $uibModal: any,
+      $q: ng.IQService,
+      $rootScope: ng.IScope
     ) => {
       service = XosConfirm;
       modal = $uibModal;
+      q = $q;
+      scope = $rootScope;
     });
   });
 
@@ -54,19 +60,31 @@
         }]
       };
 
-    it('should open a modal', () => {
-      spyOn(modal, 'open');
+    it('should open the modal', () => {
+      spyOn(modal, 'open').and.returnValue('fake');
       modalInstance = service.open(test1);
       expect(modal.open).toHaveBeenCalled();
+      expect(modalInstance).toEqual('fake');
+      expect(service.modalInstance).toEqual('fake');
     });
-  });
 
-  // describe('the close method', () => {
-  //
-  // });
-  //
-  // describe('the dismiss method', () => {
-  //
-  // });
+    it('should close the modal', (done) => {
+      const p = q.defer();
+      const cb = jasmine.createSpy('cb').and.returnValue(p.promise);
+      service.modalInstance = {
+        close: jasmine.createSpy('close')
+      };
+
+      service.close(cb);
+      expect(cb).toHaveBeenCalled();
+      p.resolve();
+      scope.$apply();
+      expect(service.modalInstance.close).toHaveBeenCalled();
+      done();
+    });
+
+
+
+  });
 
 });
diff --git a/src/app/core/confirm/confirm.service.ts b/src/app/core/confirm/confirm.service.ts
index a8e802e..39336e3 100644
--- a/src/app/core/confirm/confirm.service.ts
+++ b/src/app/core/confirm/confirm.service.ts
@@ -18,36 +18,44 @@
 import {IXosConfirmConfig} from './confirm';
 
 export interface IXosConfirm {
+  modalInstance: any;
   open(config: IXosConfirmConfig) : void;
-  close(cb: Function) : void;
+  close(cb: any) : void;
   dismiss() : void;
 }
 
 export class XosConfirm implements IXosConfirm {
 
-  static $inject = ['$uibModal'];
+  static $inject = ['$uibModal', '$log'];
   public modalInstance;
 
   constructor(
     private $uibModal : any,
+    private $log: ng.ILogService,
   ) {
 
   }
 
   public open(config: IXosConfirmConfig) {
-
+    this.$log.debug('[XosConfirm] called open');
     this.modalInstance = this.$uibModal.open({
-      keyboard: false,
+      keyboard: true,
       component: 'xosConfirm',
       backdrop: 'static',
       resolve: {
         config: () => config
       }
     });
+
     return this.modalInstance;
   }
 
-  public close(cb: Function) {
+  public close(cb: any) {
+    // check if model instance exists
+    if (angular.isUndefined(this.modalInstance)) {
+      this.$log.debug('[XosConfirm] called close without a modalInstance');
+      return;
+    }
     cb()
       .then(() => {
         this.modalInstance.close();