From 5944342aefa557f6a2b3bc677085bfa19222447d Mon Sep 17 00:00:00 2001 From: Galen Charlton Date: Wed, 7 Mar 2018 14:27:44 -0500 Subject: [PATCH] LP#1721807: regression test 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 Signed-off-by: Chris Sharp Signed-off-by: Kathy Lussier --- .../ui/default/staff/reporter/template/app.js | 4 +- .../js/ui/default/staff/test/karma.conf.js | 1 + .../ui/default/staff/test/unit/egReporter.js | 185 ++++++++++++++++++ 3 files changed, 189 insertions(+), 1 deletion(-) create mode 100644 Open-ILS/web/js/ui/default/staff/test/unit/egReporter.js diff --git a/Open-ILS/web/js/ui/default/staff/reporter/template/app.js b/Open-ILS/web/js/ui/default/staff/reporter/template/app.js index 69c433f896..9ea625ed75 100644 --- a/Open-ILS/web/js/ui/default/staff/reporter/template/app.js +++ b/Open-ILS/web/js/ui/default/staff/reporter/template/app.js @@ -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; diff --git a/Open-ILS/web/js/ui/default/staff/test/karma.conf.js b/Open-ILS/web/js/ui/default/staff/test/karma.conf.js index 531ac85adc..987d216602 100644 --- a/Open-ILS/web/js/ui/default/staff/test/karma.conf.js +++ b/Open-ILS/web/js/ui/default/staff/test/karma.conf.js @@ -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 index 0000000000..743483e0e9 --- /dev/null +++ b/Open-ILS/web/js/ui/default/staff/test/unit/egReporter.js @@ -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'); + }); + + }); + +}); -- 2.43.2