blob: cb9d713a31adeb7204f452fbe44fe714bcba1a96 [file] [log] [blame]
hebasta5e4d7542018-06-19 16:57:36 +02001/**
2 * Test suite for corpus statistic
3 *
4 * @author Helge Stallkamp
Akron18a99c02018-08-20 12:55:14 +02005 * @author Nils Diewald
hebasta5e4d7542018-06-19 16:57:36 +02006 */
7
8
hebasta6c8f09d2018-07-24 13:21:36 +02009define(['vc', 'vc/statistic', 'view/corpstatv'], function(vcClass, statClass, corpStatVClass){
hebasta47d03a42018-06-25 10:31:58 +020010
11 var json = {
Akron18a99c02018-08-20 12:55:14 +020012 "@type":"koral:docGroup",
13 "operation":"operation:or",
14 "operands":[
15 {
16 "@type":"koral:docGroup",
17 "operation":"operation:and",
18 "operands":[
19 {
20 "@type":"koral:doc",
21 "key":"title",
22 "value":"Der Birnbaum",
23 "match":"match:eq"
24 },
25 {
26 "@type":"koral:doc",
27 "key":"pubPlace",
28 "value":"Mannheim",
29 "type" : "type:regex",
30 "match":"match:contains"
31 },
32 {
33 "@type":"koral:docGroup",
34 "operation":"operation:or",
35 "operands":[
36 {
37 "@type":"koral:doc",
38 "key":"subTitle",
39 "value":"Aufzucht und Pflege",
40 "match":"match:eq"
41 },
42 {
43 "@type":"koral:doc",
44 "key":"subTitle",
45 "value":"Gedichte",
46 "match":"match:eq",
47 "rewrites" : [
48 {
49 "@type": "koral:rewrite",
50 "src" : "policy",
51 "operation" : "operation:injection",
52 }
53 ]
54 }
55 ]
56 }
57 ]
58 },
59 {
60 "@type":"koral:doc",
61 "key":"pubDate",
62 "type":"type:date",
63 "value":"2015-03-05",
64 "match":"match:geq"
65 }
66 ]
67 };
hebasta5e4d7542018-06-19 16:57:36 +020068
hebasta47d03a42018-06-25 10:31:58 +020069 var preDefinedStat={
Akron18a99c02018-08-20 12:55:14 +020070 "documents":12,
71 "tokens":2323,
72 "sentences":343434,
73 "paragraphs":45454545
hebasta47d03a42018-06-25 10:31:58 +020074 };
75
76 KorAP.API.getCorpStat = function(collQu, cb){
77 return cb(preDefinedStat);
Akron18a99c02018-08-20 12:55:14 +020078 };
79
hebasta4c92eec2018-06-29 10:11:15 +020080
hebasta47d03a42018-06-25 10:31:58 +020081 describe('KorAP.CorpusStat', function(){
hebasta47d03a42018-06-25 10:31:58 +020082
hebasta5e4d7542018-06-19 16:57:36 +020083 it('should be initiable', function(){
Akron18a99c02018-08-20 12:55:14 +020084 var stat = statClass.create(preDefinedStat);
hebasta5e4d7542018-06-19 16:57:36 +020085 expect( function() { statClass.create() }).toThrow(new Error("Missing parameter"));
86 });
87
88
Akron18a99c02018-08-20 12:55:14 +020089 it('should be parsed in a statistic view and displayed as HTML Description List', function(){
90 var stat = statClass.create(preDefinedStat);
91 var descL = stat.element();
hebasta5e4d7542018-06-19 16:57:36 +020092 expect(descL.tagName).toEqual('DL');
93 expect(descL.children[0].tagName).toEqual('DIV');
94 expect(descL.children[0].children[0].tagName).toEqual('DT');
95 expect(descL.children[0].children[0].attributes[0].name).toEqual('title');
96 expect(descL.children[0].children[1].tagName).toEqual('DD');
Akron18a99c02018-08-20 12:55:14 +020097
hebasta5e4d7542018-06-19 16:57:36 +020098 expect(descL.children[0].children[0].firstChild.nodeValue).toEqual('documents');
99 expect(descL.children[0].children[1].firstChild.nodeValue).toEqual('12');
100 expect(descL.children[0].children[0].attributes[0].value).toEqual('documents');
Akron2f979122018-07-25 17:00:23 +0200101
102 expect(descL.children[1].children[0].firstChild.nodeValue).toEqual('tokens');
103 expect(descL.children[1].children[1].firstChild.nodeValue).toEqual(new Number(2323).toLocaleString());
104 expect(descL.children[1].children[0].attributes[0].value).toEqual('tokens');
105 });
hebasta5e4d7542018-06-19 16:57:36 +0200106
hebasta47d03a42018-06-25 10:31:58 +0200107
hebasta6c8f09d2018-07-24 13:21:36 +0200108 it('should display corpus statistic after creating a corpus statistic view', function(){
Akron18a99c02018-08-20 12:55:14 +0200109 var vc = vcClass.create([
110 ['title', 'string'],
111 ['subTitle', 'string'],
112 ['pubDate', 'date'],
113 ['author', 'text']
114 ]).fromJson(json);
115
116 statView = corpStatVClass.create(vc);
117 //corpStatVClass.show(vc);
118
hebasta47d03a42018-06-25 10:31:58 +0200119 var testDiv = document.createElement('div');
hebasta6c8f09d2018-07-24 13:21:36 +0200120 testDiv.appendChild(statView.show());
121 //statClass.showCorpStat(testDiv, vc);
hebasta47d03a42018-06-25 10:31:58 +0200122
123 expect(testDiv.children[0].tagName).toEqual('DIV');
124 expect(testDiv.children[0].getAttribute("class")).toEqual('stattable');
125 expect(testDiv.children[0].children[0].tagName).toEqual('DL');
126 expect(testDiv.children[0].children[0].children[0].children[0].firstChild.nodeValue).toEqual('documents');
127 expect(testDiv.children[0].children[0].children[0].children[1].firstChild.nodeValue).toEqual('12');
hebasta47d03a42018-06-25 10:31:58 +0200128 });
Akron18a99c02018-08-20 12:55:14 +0200129
130 it('should display the statistics button in a panel', function () {
131 var vc = vcClass.create([
132 ['title', 'string'],
133 ['subTitle', 'string'],
134 ['pubDate', 'date'],
135 ['author', 'text']
136 ]).fromJson(json);
137
138 var show = document.createElement('div');
139
140 show.appendChild(vc.element());
141
142 var panel = show.firstChild.lastChild.firstChild;
143 expect(panel.classList.contains('panel')).toBeTruthy();
144 expect(panel.classList.contains('vcinfo')).toBeTruthy();
145 expect(panel.lastChild.classList.contains('button-group')).toBeTruthy();
146 expect(panel.lastChild.classList.contains('vcinfo')).toBeTruthy();
147 expect(panel.lastChild.children[0].tagName).toEqual('SPAN');
148 expect(panel.lastChild.children[0].textContent).toEqual('Statistics');
149 });
150
151
152 it('should display the statistics button in a panel after VC modification', function () {
153
154 var vc = vcClass.create([
155 ['title', 'string'],
156 ['subTitle', 'string'],
157 ['pubDate', 'date'],
158 ['author', 'text']
159 ]).fromJson(json);
160
161 var show = document.createElement('div');
162
163 show.appendChild(vc.element());
164
165 expect(show.querySelector(".statistic").tagName).toEqual("SPAN");
166
Akronadab5e52018-08-20 13:50:53 +0200167 var and = vc.builder().lastChild.firstChild;
Akron18a99c02018-08-20 12:55:14 +0200168
169 // Click on and() in VC
170 and.click();
171
172 // Check that statistics is there
173 expect(show.querySelector(".statistic").tagName).toEqual("SPAN");
174 });
175
176
177 it('should display and hide corpus statistics view in the panel', function () {
178
179 var vc = vcClass.create([
180 ['title', 'string'],
181 ['subTitle', 'string'],
182 ['pubDate', 'date'],
183 ['author', 'text']
184 ]).fromJson(json);
185
186 var show = document.createElement('div');
187
188 show.appendChild(vc.element());
189
190 var panel = show.firstChild.lastChild.firstChild;
191
192 // Show statistics
193 panel.lastChild.children[0].click();
194
195 // Statistics view
196 var viewE = panel.firstChild.firstChild;
197
198 expect(viewE.tagName).toEqual("DIV");
199 expect(viewE.classList.contains("view")).toBeTruthy();
200 expect(viewE.classList.contains("vcstatistic")).toBeTruthy();
201
202 expect(viewE.firstChild.classList.contains("stattable")).toBeTruthy();
203 expect(viewE.firstChild.firstChild.tagName).toEqual("DL");
204
205 // List of statistic values
206 var dl = viewE.firstChild.firstChild.firstChild;
207 expect(dl.firstChild.tagName).toEqual("DT");
208 expect(dl.firstChild.textContent).toEqual("documents");
209 expect(dl.lastChild.tagName).toEqual("DD");
210 expect(dl.lastChild.textContent).toEqual("12");
211
212 expect(viewE.children.length).toEqual(2);
213
214 expect(viewE.lastChild.classList.contains("button-group")).toBeTruthy();
215 expect(viewE.lastChild.children.length).toEqual(1);
216 expect(viewE.lastChild.firstChild.tagName).toEqual("SPAN");
217 expect(viewE.lastChild.firstChild.textContent).toEqual("Close");
218
219 // Close view
220 viewE.lastChild.firstChild.firstChild.click();
221
222 // Is gone
223 expect(panel.firstChild.children.length).toEqual(0);
224
225 // Show statistics
226 panel.lastChild.children[0].click();
227
228 // Is there
229 expect(panel.firstChild.children.length).toEqual(1);
230
231 // Only show once
232 panel.lastChild.children[0].click();
233 expect(panel.firstChild.children.length).toEqual(1);
234 });
235 });
hebasta5e4d7542018-06-19 16:57:36 +0200236});