]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/web/js/ui/default/staff/test/unit/egReporter.js
743483e0e916d53fa8fcb015e54b0192a8bdd911
[Evergreen.git] / Open-ILS / web / js / ui / default / staff / test / unit / egReporter.js
1 'use strict';
2
3 describe('egReporterTest', function() {
4     beforeEach(module('egCoreMod'));
5     beforeEach(module('egReportMod'));
6     beforeEach(module('egReporter'));
7
8     var reportEditCtrl, reportEditScope;
9     beforeEach(inject(function ($rootScope, $controller, $location, egIDL) {
10         egIDL.parseIDL();
11         reportEditScope = $rootScope.$new();
12         reportEditCtrl = $controller('ReporterTemplateEdit', {$scope: reportEditScope});
13     }));
14
15     /** egReportTemplateSvc tests **/
16     describe('egReportTemplateSvcTests', function() {
17
18         it('egReportTemplateSvc should start with empty lists', inject(function(egReportTemplateSvc) {
19             expect(egReportTemplateSvc.display_fields.length).toEqual(0);
20             expect(egReportTemplateSvc.filter_fields.length).toEqual(0);
21         }));
22
23     });
24
25     // test template
26     var display_fields = [{
27         "name": "family_name",
28         "label": "Last Name",
29         "datatype": "text",
30         "index": 0,
31         "path": [
32             {
33             "label": "ILS User",
34             "id": "au",
35             "jtype": "inner",
36             "classname": "au",
37             "struct": {
38                 "name": "au",
39                 "label": "ILS User",
40                 "table": "actor.usr",
41                 "core": true,
42                 "pkey": "id",
43                 "pkey_sequence": "actor.usr_id_seq",
44                 "core_label": "Core sources",
45                 "classname": "au"
46             },
47             "table": "actor.usr"
48             }
49         ],
50         "path_label": "ILS User",
51         "transform": {
52             "transform": "Bare",
53             "label": "Raw Data",
54             "aggregate": false
55         },
56         "doc_text": ""
57         }, {
58         "name": "first_given_name",
59         "label": "First Name",
60         "datatype": "text",
61         "index": 1,
62         "path": [
63             {
64             "label": "ILS User",
65             "id": "au",
66             "jtype": "inner",
67             "classname": "au",
68             "struct": {
69                 "name": "au",
70                 "label": "ILS User",
71                 "table": "actor.usr",
72                 "core": true,
73                 "pkey": "id",
74                 "pkey_sequence": "actor.usr_id_seq",
75                 "core_label": "Core sources",
76                 "classname": "au"
77             },
78             "table": "actor.usr"
79             }
80         ],
81         "path_label": "ILS User",
82         "transform": {
83             "transform": "Bare",
84             "label": "Raw Data",
85             "aggregate": false
86         },
87         "doc_text": ""
88         }, {
89         "name": "value",
90         "label": "Note Content",
91         "datatype": "text",
92         "index": 2,
93         "path": [
94             {
95             "label": "ILS User",
96             "id": "au",
97             "jtype": "inner",
98             "classname": "au",
99             "struct": {
100                 "name": "au",
101                 "label": "ILS User",
102                 "table": "actor.usr",
103                 "core": true,
104                 "pkey": "id",
105                 "pkey_sequence": "actor.usr_id_seq",
106                 "core_label": "Core sources",
107                 "classname": "au"
108             },
109             "table": "actor.usr"
110             },
111             {
112             "label": "User Notes",
113             "from": "au",
114             "link": {
115                 "name": "notes",
116                 "label": "User Notes",
117                 "virtual": true,
118                 "type": "link",
119                 "key": "usr",
120                 "class": "aun",
121                 "reltype": "has_many",
122                 "datatype": "link"
123             },
124             "id": "au.aun",
125             "jtype": "left",
126             "uplink": {
127                 "name": "notes",
128                 "label": "User Notes",
129                 "virtual": true,
130                 "type": "link",
131                 "key": "usr",
132                 "class": "aun",
133                 "reltype": "has_many",
134                 "datatype": "link"
135             },
136             "classname": "aun",
137             "struct": {
138                 "name": "aun",
139                 "label": "User Note",
140                 "table": "actor.usr_note",
141                 "pkey": "id",
142                 "pkey_sequence": "actor.usr_note_id_seq",
143                 "core_label": "Non-core sources",
144                 "classname": "aun"
145             },
146             "table": "actor.usr_note"
147             }
148         ],
149         "path_label": "ILS User -> User Notes (left)",
150         "transform": {
151             "transform": "Bare",
152             "label": "Raw Data",
153             "aggregate": false
154         },
155         "doc_text": ""
156     }];
157
158     describe('egReporterTemplateEditTests', function() {
159         it('initialize and set core source for ReporterTemplateEdit', inject(function(egIDL, egCore) {
160             egIDL.parseIDL();
161
162             // initialize
163             expect(reportEditScope.class_tree.length).toEqual(0);
164             expect(reportEditScope.coreSourceChosen).toEqual(false);
165
166             // set core source
167             reportEditScope.changeCoreSource('au');
168             expect(reportEditScope.coreSourceChosen).toEqual(true);
169             expect(reportEditScope.class_tree.length).toEqual(1);
170
171         }));
172
173         it('LP#1721807: construct join key correctly when using virtual field', function() {
174             var tmpl = reportEditScope._mergePaths(display_fields);
175             expect(tmpl).toBeDefined();
176             expect(Object.keys(tmpl)).toContain('join');
177             expect(Object.keys(tmpl.join).length).toEqual(1);
178             var join_key = Object.keys(tmpl.join)[0];
179             var lcol = join_key.split(/-/)[0];
180             expect(lcol).toEqual('id');
181         });
182
183     });
184
185 });