← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 21132: Added test for d2Enter directive

 

------------------------------------------------------------
revno: 21132
committer: Jiju K Jose <jijukjose@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2015-11-19 15:20:27 +0100
message:
  Added test for d2Enter directive
modified:
  dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/test/directives/d2SetFocus.test.js


--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk

Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/test/directives/d2SetFocus.test.js'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/test/directives/d2SetFocus.test.js	2015-11-19 13:31:51 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/javascripts/dhis2/test/directives/d2SetFocus.test.js	2015-11-19 14:20:27 +0000
@@ -7,7 +7,7 @@
     let $timeout;
     let render;
     beforeEach(module('d2Directives'));
-    beforeEach(inject(($injector) = > {
+    beforeEach(inject(($injector) => {
         const $compile = $injector.get('$compile');
         const $rootScope = $injector.get('$rootScope');
         $timeout = $injector.get('$timeout');
@@ -22,15 +22,51 @@
         };
     }));
 
-    it('should set the focus when the attribute property is set to true', () = > {
+    it('should set the focus when the attribute property is set to true', () => {
         var elm = angular.element('<input d2-set-focus="true" />');
         render(elm);
         expect(elm[0].focus).to.be.calledOnce;
     });
 
-    it('should not set focus when the attribute property is set to false', () = > {
+    it('should not set focus when the attribute property is set to false', () => {
         var elm = angular.element('<input d2-set-focus="false" />');
         render(elm);
         expect(elm[0].focus).to.not.be.called;
     });
+});
+
+
+describe('Directives: d2Enter', () => {
+    let mock$scope;
+    let element;
+    let $timeout;
+    let render;
+
+    beforeEach(module('d2Directives'));
+
+
+    beforeEach(inject(($injector) => {
+        const $compile = $injector.get('$compile');
+        const $rootScope = $injector.get('$rootScope');
+        $timeout = $injector.get('$timeout');
+        mock$scope = $rootScope.$new();
+        mock$scope.search = function() {
+            var a=100;
+        };
+        mock$scope.message="testMessage";
+        render = (elm) => {
+            mock$scope.search = spy();
+            $compile(elm)(mock$scope);
+            mock$scope.$digest();
+        };
+    }));
+
+    it('should call the resgistered function on key press event', () => {
+        var elm = angular.element('<input type="text" d2-enter="search(message)"/>');
+        render(elm);
+        var e = jQuery.Event("keydown");
+        e.which = 13; // # Some key code value
+        elm .trigger(e);
+        expect(mock$scope.search).to.be.calledOnce;
+    });
 });
\ No newline at end of file