unit tests for egCore, egEvent, and egStrings
authorBill Erickson <berick@esilibrary.com>
Tue, 6 May 2014 18:19:44 +0000 (14:19 -0400)
committerBill Erickson <berick@esilibrary.com>
Tue, 6 May 2014 18:19:44 +0000 (14:19 -0400)
Signed-off-by: Bill Erickson <berick@esilibrary.com>
Open-ILS/web/js/ui/default/staff/test/unit/egCore.js [new file with mode: 0644]
Open-ILS/web/js/ui/default/staff/test/unit/egEvent.js [new file with mode: 0644]
Open-ILS/web/js/ui/default/staff/test/unit/egStrings.js [new file with mode: 0644]

diff --git a/Open-ILS/web/js/ui/default/staff/test/unit/egCore.js b/Open-ILS/web/js/ui/default/staff/test/unit/egCore.js
new file mode 100644 (file)
index 0000000..d19a371
--- /dev/null
@@ -0,0 +1,18 @@
+'use strict';
+
+describe('egCore', function(){
+    beforeEach(module('egCoreMod'));
+
+    it('should wrap services', inject(function(egCore, egIDL) {
+        expect(egCore.idl).toBe(egIDL);
+    }));
+
+    it('should wrap services', inject(function(egCore, egIDL) {
+        expect(egCore.auth).not.toBe(egIDL);
+    }));
+
+    it('should not wrap non-services', inject(function(egCore) {
+        expect(egCore.junk).not.toBeDefined();
+    }));
+
+});
diff --git a/Open-ILS/web/js/ui/default/staff/test/unit/egEvent.js b/Open-ILS/web/js/ui/default/staff/test/unit/egEvent.js
new file mode 100644 (file)
index 0000000..7b17653
--- /dev/null
@@ -0,0 +1,44 @@
+'use strict';
+
+describe('egEvent', function(){
+    beforeEach(module('egCoreMod'));
+
+    var evt = {                                                                           
+        ilsevent: "12345",                                                         
+        pid: "12345",                                                             
+        desc: "Test Event Description",
+        payload: {test : 'xyz'},                                                             
+        textcode: "TEST_EVENT",
+        servertime: "Wed Nov 6 16:05:50 2013"                                     
+    };
+
+    it('should parse an event object', inject(function(egEvent) {
+        expect(egEvent.parse(evt)).not.toBe(null);
+    }));
+
+    it('should not parse a non-event', inject(function(egEvent) {
+        expect(egEvent.parse({})).toBe(null);
+    }));
+
+    it('should not parse a non-event', inject(function(egEvent) {
+        expect(egEvent.parse({abc : '123'})).toBe(null);
+    }));
+
+    it('should not parse a non-event', inject(function(egEvent) {
+        expect(egEvent.parse([])).toBe(null);
+    }));
+
+    it('should not parse a non-event', inject(function(egEvent) {
+        expect(egEvent.parse('STRING')).toBe(null);
+    }));
+
+    it('should not parse a non-event', inject(function(egEvent) {
+        expect(egEvent.parse(true)).toBe(null);
+    }));
+
+    it('should stringify an event', inject(function(egEvent) {
+        expect(egEvent.parse(evt).toString()).toBe(
+            'Event: 12345:TEST_EVENT -> Test Event Description')
+    }));
+
+});
diff --git a/Open-ILS/web/js/ui/default/staff/test/unit/egStrings.js b/Open-ILS/web/js/ui/default/staff/test/unit/egStrings.js
new file mode 100644 (file)
index 0000000..fe81e08
--- /dev/null
@@ -0,0 +1,14 @@
+'use strict';
+
+describe('egStrings', function(){
+    beforeEach(module('egCoreMod'));
+
+    it('should interpolate values', inject(function(egStrings) {
+
+        egStrings.FOO = 'Hello, {{planet}}';
+
+        expect(egStrings.$replace(egStrings.FOO, {planet : 'Earth'}))
+       .toBe('Hello, Earth');
+    }));
+
+});