LP#1721807: regression test
authorGalen Charlton <gmc@equinoxinitiative.org>
Wed, 7 Mar 2018 19:27:44 +0000 (14:27 -0500)
committerKathy Lussier <klussier@masslnc.org>
Tue, 20 Mar 2018 18:24:27 +0000 (14:24 -0400)
This adds an automated regression test as well as some additional
unit tests for the web staff reporter app and template service.  This
patch could be applied by itself to verify that the regression
test (run using 'npm run test' for master or 'grunt test' for rel_3_0)
fails.

Signed-off-by: Galen Charlton <gmc@equinoxinitiative.org>
Signed-off-by: Chris Sharp <csharp@georgialibraries.org>
Signed-off-by: Kathy Lussier <klussier@masslnc.org>
Open-ILS/web/js/ui/default/staff/reporter/template/app.js
Open-ILS/web/js/ui/default/staff/test/karma.conf.js
Open-ILS/web/js/ui/default/staff/test/unit/egReporter.js [new file with mode: 0644]

index 69c433f..9ea625e 100644 (file)
@@ -155,7 +155,9 @@ function($scope , $q , $routeParams , $location , $timeout , $window,  egCore ,
         });
 
         return tree;
-    }
+    };
+    // expose for testing
+    $scope._mergePaths = mergePaths;
 
     $scope.constructTemplate = function () {
         var param_counter = 0;
index 531ac85..987d216 100644 (file)
@@ -31,6 +31,7 @@ module.exports = function(config){
       'app.js',
       'circ/**/*.js',
       'cat/**/*.js',
+      'reporter/**/*.js',
       'admin/**/*.js',
       'test/unit/egIDL.js', // order matters for some of these
       'test/unit/egOrg.js', 
diff --git a/Open-ILS/web/js/ui/default/staff/test/unit/egReporter.js b/Open-ILS/web/js/ui/default/staff/test/unit/egReporter.js
new file mode 100644 (file)
index 0000000..743483e
--- /dev/null
@@ -0,0 +1,185 @@
+'use strict';
+
+describe('egReporterTest', function() {
+    beforeEach(module('egCoreMod'));
+    beforeEach(module('egReportMod'));
+    beforeEach(module('egReporter'));
+
+    var reportEditCtrl, reportEditScope;
+    beforeEach(inject(function ($rootScope, $controller, $location, egIDL) {
+        egIDL.parseIDL();
+        reportEditScope = $rootScope.$new();
+        reportEditCtrl = $controller('ReporterTemplateEdit', {$scope: reportEditScope});
+    }));
+
+    /** egReportTemplateSvc tests **/
+    describe('egReportTemplateSvcTests', function() {
+
+        it('egReportTemplateSvc should start with empty lists', inject(function(egReportTemplateSvc) {
+            expect(egReportTemplateSvc.display_fields.length).toEqual(0);
+            expect(egReportTemplateSvc.filter_fields.length).toEqual(0);
+        }));
+
+    });
+
+    // test template
+    var display_fields = [{
+        "name": "family_name",
+        "label": "Last Name",
+        "datatype": "text",
+        "index": 0,
+        "path": [
+            {
+            "label": "ILS User",
+            "id": "au",
+            "jtype": "inner",
+            "classname": "au",
+            "struct": {
+                "name": "au",
+                "label": "ILS User",
+                "table": "actor.usr",
+                "core": true,
+                "pkey": "id",
+                "pkey_sequence": "actor.usr_id_seq",
+                "core_label": "Core sources",
+                "classname": "au"
+            },
+            "table": "actor.usr"
+            }
+        ],
+        "path_label": "ILS User",
+        "transform": {
+            "transform": "Bare",
+            "label": "Raw Data",
+            "aggregate": false
+        },
+        "doc_text": ""
+        }, {
+        "name": "first_given_name",
+        "label": "First Name",
+        "datatype": "text",
+        "index": 1,
+        "path": [
+            {
+            "label": "ILS User",
+            "id": "au",
+            "jtype": "inner",
+            "classname": "au",
+            "struct": {
+                "name": "au",
+                "label": "ILS User",
+                "table": "actor.usr",
+                "core": true,
+                "pkey": "id",
+                "pkey_sequence": "actor.usr_id_seq",
+                "core_label": "Core sources",
+                "classname": "au"
+            },
+            "table": "actor.usr"
+            }
+        ],
+        "path_label": "ILS User",
+        "transform": {
+            "transform": "Bare",
+            "label": "Raw Data",
+            "aggregate": false
+        },
+        "doc_text": ""
+        }, {
+        "name": "value",
+        "label": "Note Content",
+        "datatype": "text",
+        "index": 2,
+        "path": [
+            {
+            "label": "ILS User",
+            "id": "au",
+            "jtype": "inner",
+            "classname": "au",
+            "struct": {
+                "name": "au",
+                "label": "ILS User",
+                "table": "actor.usr",
+                "core": true,
+                "pkey": "id",
+                "pkey_sequence": "actor.usr_id_seq",
+                "core_label": "Core sources",
+                "classname": "au"
+            },
+            "table": "actor.usr"
+            },
+            {
+            "label": "User Notes",
+            "from": "au",
+            "link": {
+                "name": "notes",
+                "label": "User Notes",
+                "virtual": true,
+                "type": "link",
+                "key": "usr",
+                "class": "aun",
+                "reltype": "has_many",
+                "datatype": "link"
+            },
+            "id": "au.aun",
+            "jtype": "left",
+            "uplink": {
+                "name": "notes",
+                "label": "User Notes",
+                "virtual": true,
+                "type": "link",
+                "key": "usr",
+                "class": "aun",
+                "reltype": "has_many",
+                "datatype": "link"
+            },
+            "classname": "aun",
+            "struct": {
+                "name": "aun",
+                "label": "User Note",
+                "table": "actor.usr_note",
+                "pkey": "id",
+                "pkey_sequence": "actor.usr_note_id_seq",
+                "core_label": "Non-core sources",
+                "classname": "aun"
+            },
+            "table": "actor.usr_note"
+            }
+        ],
+        "path_label": "ILS User -> User Notes (left)",
+        "transform": {
+            "transform": "Bare",
+            "label": "Raw Data",
+            "aggregate": false
+        },
+        "doc_text": ""
+    }];
+
+    describe('egReporterTemplateEditTests', function() {
+        it('initialize and set core source for ReporterTemplateEdit', inject(function(egIDL, egCore) {
+            egIDL.parseIDL();
+
+            // initialize
+            expect(reportEditScope.class_tree.length).toEqual(0);
+            expect(reportEditScope.coreSourceChosen).toEqual(false);
+
+            // set core source
+            reportEditScope.changeCoreSource('au');
+            expect(reportEditScope.coreSourceChosen).toEqual(true);
+            expect(reportEditScope.class_tree.length).toEqual(1);
+
+        }));
+
+        it('LP#1721807: construct join key correctly when using virtual field', function() {
+            var tmpl = reportEditScope._mergePaths(display_fields);
+            expect(tmpl).toBeDefined();
+            expect(Object.keys(tmpl)).toContain('join');
+            expect(Object.keys(tmpl.join).length).toEqual(1);
+            var join_key = Object.keys(tmpl.join)[0];
+            var lcol = join_key.split(/-/)[0];
+            expect(lcol).toEqual('id');
+        });
+
+    });
+
+});