LP#1626157 Unit tests setup / ported EgEventService test
authorBill Erickson <berickxx@gmail.com>
Thu, 17 May 2018 18:01:59 +0000 (14:01 -0400)
committerBill Erickson <berickxx@gmail.com>
Thu, 17 May 2018 18:01:59 +0000 (14:01 -0400)
Signed-off-by: Bill Erickson <berickxx@gmail.com>
Open-ILS/src/eg2/karma.conf.js
Open-ILS/src/eg2/package.json
Open-ILS/src/eg2/src/app/core/event.spec.ts [new file with mode: 0644]
Open-ILS/src/eg2/src/polyfills.ts

index 84af9d1..bed8c6f 100644 (file)
@@ -8,6 +8,7 @@ module.exports = function (config) {
     plugins: [
       require('karma-jasmine'),
       require('karma-chrome-launcher'),
+      require('karma-phantomjs-launcher'),
       require('karma-jasmine-html-reporter'),
       require('karma-coverage-istanbul-reporter'),
       require('@angular-devkit/build-angular/plugins/karma')
@@ -27,7 +28,7 @@ module.exports = function (config) {
     colors: true,
     logLevel: config.LOG_INFO,
     autoWatch: true,
-    browsers: ['Chrome'],
-    singleRun: false
+    browsers: ['PhantomJS'],
+    singleRun: true
   });
 };
index 2816c9a..0955f5c 100644 (file)
@@ -30,7 +30,7 @@
   },
   "devDependencies": {
     "@angular-devkit/build-angular": "~0.6.1",
-    "@angular/cli": "6.0.1",
+    "@angular/cli": "^6.0.1",
     "@angular/compiler-cli": "6.0.1",
     "@angular/language-service": "6.0.1",
     "@types/jasmine": "~2.5.53",
@@ -45,6 +45,7 @@
     "karma-coverage-istanbul-reporter": "^1.2.1",
     "karma-jasmine": "~1.1.0",
     "karma-jasmine-html-reporter": "^0.2.2",
+    "karma-phantomjs-launcher": "^1.0.4",
     "protractor": "~5.1.2",
     "ts-node": "~3.2.0",
     "tslint": "~5.7.0",
diff --git a/Open-ILS/src/eg2/src/app/core/event.spec.ts b/Open-ILS/src/eg2/src/app/core/event.spec.ts
new file mode 100644 (file)
index 0000000..a14f89b
--- /dev/null
@@ -0,0 +1,45 @@
+import {EgEventService} from './event.service';
+
+describe('EgEventService', function(){
+    let service: EgEventService;
+    beforeEach(() => {service = new EgEventService();});
+
+    let 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', () => {
+        expect(service.parse(evt)).not.toBe(null);
+    });
+
+    it('should not parse a non-event', () => {
+        expect(service.parse({})).toBe(null);
+    });
+
+    it('should not parse a non-event', () => {
+        expect(service.parse({abc : '123'})).toBe(null);
+    });
+
+    it('should not parse a non-event', () => {
+        expect(service.parse([])).toBe(null);
+    });
+
+    it('should not parse a non-event', () => {
+        expect(service.parse('STRING')).toBe(null);
+    });
+
+    it('should not parse a non-event', () => {
+        expect(service.parse(true)).toBe(null);
+    });
+
+    it('should stringify an event', () => {
+        expect(service.parse(evt).toString()).toBe(
+            'Event: 12345:TEST_EVENT -> Test Event Description')
+    });
+
+});
index 20d4075..e073082 100644 (file)
 // import 'core-js/es6/weak-map';
 // import 'core-js/es6/set';
 
+// PhantomJS needs these
+import 'core-js/es6/array';
+import 'core-js/es6/string';
+
 /** IE10 and IE11 requires the following for NgClass support on SVG elements */
 // import 'classlist.js';  // Run `npm install --save classlist.js`.