blob: 33953b51dfea06804947fd02f54275452801c7ee [file] [log] [blame]
Nils Diewald6ac292b2015-01-15 21:33:21 +00001/*
Nils Diewald7c8ced22015-04-15 19:21:00 +00002 * Todo: In demoSpec: Create "and" on the last element of the top "or"-Group
3 */
Akrondd5c6d32018-08-17 14:12:58 +02004define([
5 'vc',
6 'vc/doc',
7 'vc/menu',
8 'vc/prefix',
9 'vc/docgroup',
10 'vc/docgroupref',
11 'vc/unspecified',
12 'vc/operators',
13 'vc/rewrite',
14 'vc/stringval'
15], function (vcClass,
16 docClass,
17 menuClass,
18 prefixClass,
19 docGroupClass,
20 docGroupRefClass,
21 unspecifiedClass,
22 operatorsClass,
23 rewriteClass,
24 stringValClass) {
Nils Diewald6ac292b2015-01-15 21:33:21 +000025
Akrondd5c6d32018-08-17 14:12:58 +020026 KorAP._vcKeyMenu = undefined;
27
Nils Diewald6ac292b2015-01-15 21:33:21 +000028
Nils Diewald7c8ced22015-04-15 19:21:00 +000029 // Helper method for building factories
30 buildFactory = function (objClass, defaults) {
31 return {
32 create : function (overwrites) {
Akron712733a2018-04-05 18:17:47 +020033 var newObj = {};
34 for (var prop in defaults) {
35 newObj[prop] = defaults[prop];
36 };
37 for (var prop in overwrites) {
38 newObj[prop] = overwrites[prop];
39 };
40 return objClass.create().fromJson(newObj);
Nils Diewald7c8ced22015-04-15 19:21:00 +000041 }
Nils Diewald0b6c0412014-12-19 03:55:57 +000042 }
Nils Diewald7c8ced22015-04-15 19:21:00 +000043 };
Nils Diewald0b6c0412014-12-19 03:55:57 +000044
Nils Diewald7c8ced22015-04-15 19:21:00 +000045 function _andOn (obj) {
Akrond141a362018-07-10 18:12:13 +020046 KorAP._and.apply(obj);
Nils Diewald7c8ced22015-04-15 19:21:00 +000047 };
Nils Diewald52f7eb12015-01-12 17:30:04 +000048
Nils Diewald7c8ced22015-04-15 19:21:00 +000049 function _orOn (obj) {
Akrond141a362018-07-10 18:12:13 +020050 KorAP._or.apply(obj);
Nils Diewald7c8ced22015-04-15 19:21:00 +000051 };
Nils Diewald52f7eb12015-01-12 17:30:04 +000052
Nils Diewald7c8ced22015-04-15 19:21:00 +000053 function _delOn (obj) {
Akrond141a362018-07-10 18:12:13 +020054 KorAP._delete.apply(obj);
Nils Diewald7c8ced22015-04-15 19:21:00 +000055 };
Nils Diewald52f7eb12015-01-12 17:30:04 +000056
Nils Diewald7c8ced22015-04-15 19:21:00 +000057 var demoFactory = buildFactory(vcClass, {
58 "@type":"koral:docGroup",
59 "operation":"operation:or",
60 "operands":[
Nils Diewaldf219eb82015-01-07 20:15:42 +000061 {
Akron712733a2018-04-05 18:17:47 +020062 "@type":"koral:docGroup",
63 "operation":"operation:and",
64 "operands":[
Nils Diewald7c8ced22015-04-15 19:21:00 +000065 {
66 "@type":"koral:doc",
67 "key":"Titel",
68 "value":"Baum",
69 "match":"match:eq"
70 },
71 {
72 "@type":"koral:doc",
73 "key":"Veröffentlichungsort",
74 "value":"hihi",
75 "match":"match:eq"
76 },
77 {
78 "@type":"koral:docGroup",
79 "operation":"operation:or",
80 "operands":[
81 {
Akron712733a2018-04-05 18:17:47 +020082 "@type":"koral:doc",
83 "key":"Titel",
84 "value":"Baum",
85 "match":"match:eq"
Nils Diewald7c8ced22015-04-15 19:21:00 +000086 },
87 {
Akron712733a2018-04-05 18:17:47 +020088 "@type":"koral:doc",
89 "key":"Veröffentlichungsort",
90 "value":"hihi",
91 "match":"match:eq"
Nils Diewald7c8ced22015-04-15 19:21:00 +000092 }
93 ]
94 }
Akron712733a2018-04-05 18:17:47 +020095 ]
Nils Diewaldf219eb82015-01-07 20:15:42 +000096 },
97 {
Akron712733a2018-04-05 18:17:47 +020098 "@type":"koral:doc",
99 "key":"Untertitel",
100 "value":"huhu",
101 "match":"match:contains"
Nils Diewaldf219eb82015-01-07 20:15:42 +0000102 }
103 ]
104 });
105
Nils Diewald7c8ced22015-04-15 19:21:00 +0000106 describe('KorAP.Doc', function () {
107 // Create example factories
108 var stringFactory = buildFactory(docClass, {
109 "key" : "author",
110 "value" : "Max Birkendale",
Akron31d89942018-04-06 16:44:51 +0200111 "type" : "type:string",
Nils Diewald7c8ced22015-04-15 19:21:00 +0000112 "@type" : "koral:doc"
113 });
114
115 // Create example factories
Akron712733a2018-04-05 18:17:47 +0200116 var textFactory = buildFactory(docClass, {
117 "key" : "author",
118 "value" : "Birkendale",
Akron31d89942018-04-06 16:44:51 +0200119 "type" : "type:string",
Akron712733a2018-04-05 18:17:47 +0200120 "match" : "match:contains",
121 "@type" : "koral:doc"
122 });
123
124 // Create example factories
Nils Diewald7c8ced22015-04-15 19:21:00 +0000125 var dateFactory = buildFactory(docClass, {
126 "key" : "pubDate",
127 "type" : "type:date",
128 "match" : "match:eq",
129 "value" : "2014-11-05",
130 "@type" : "koral:doc"
131 });
132
133 // Create example factories
134 var regexFactory = buildFactory(docClass, {
135 "key" : "title",
136 "type" : "type:regex",
137 "value" : "[^b]ee.+?",
138 "@type" : "koral:doc"
139 });
140
141 it('should be initializable', function () {
142 var doc = docClass.create();
143 expect(doc.matchop()).toEqual('eq');
144 expect(doc.key()).toBeUndefined();
145 expect(doc.value()).toBeUndefined();
146 expect(doc.type()).toEqual("string");
147 });
148
149 it('should be definable', function () {
150
151 // Empty doc
152 var doc = docClass.create();
153
154 // Set values
155 doc.key("title");
Akron8db5e3a2018-05-28 19:25:26 +0200156
Nils Diewald7c8ced22015-04-15 19:21:00 +0000157 doc.value("Der alte Mann");
158 expect(doc.matchop()).toEqual('eq');
159 expect(doc.key()).toEqual("title");
160 expect(doc.type()).toEqual("string");
161 expect(doc.value()).toEqual("Der alte Mann");
162 });
163
164
165 it('should deserialize JSON-LD string', function () {
166 var doc;
167
168 // String default
169 doc = stringFactory.create();
170 expect(doc.matchop()).toEqual('eq');
171 expect(doc.key()).toEqual("author");
172 expect(doc.type()).toEqual("string");
173 expect(doc.value()).toEqual("Max Birkendale");
174
175 // No valid string
176 doc = stringFactory.create({
Akron712733a2018-04-05 18:17:47 +0200177 value : undefined
Nils Diewald7c8ced22015-04-15 19:21:00 +0000178 });
179 expect(doc).toBeUndefined();
180
181 // No valid string
182 doc = stringFactory.create({
Akron712733a2018-04-05 18:17:47 +0200183 value : { "foo" : "bar" }
Nils Diewald7c8ced22015-04-15 19:21:00 +0000184 });
185 expect(doc).toBeUndefined();
186
187 // Change match type
188 doc = stringFactory.create({
Akron712733a2018-04-05 18:17:47 +0200189 "match" : "match:ne"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000190 });
191
192 expect(doc.matchop()).toEqual('ne');
193 expect(doc.key()).toEqual("author");
194 expect(doc.type()).toEqual("string");
195 expect(doc.value()).toEqual("Max Birkendale");
196
197 // Invalid match type
198 doc = stringFactory.create({
Akron712733a2018-04-05 18:17:47 +0200199 "match" : { "foo" : "bar" }
Nils Diewald7c8ced22015-04-15 19:21:00 +0000200 });
201 expect(doc).toBeUndefined();
202 });
203
204 it('should deserialize JSON-LD regex', function () {
205 var doc = regexFactory.create();
206 expect(doc.key()).toEqual("title");
207 expect(doc.type()).toEqual("regex");
208 expect(doc.value()).toEqual("[^b]ee.+?");
209 expect(doc.matchop()).toEqual('eq');
210
211 // change matcher
212 doc = regexFactory.create({
Akron712733a2018-04-05 18:17:47 +0200213 match : "match:ne"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000214 });
215 expect(doc.matchop()).toEqual('ne');
Akronea4e9052017-07-06 16:12:05 +0200216 expect(doc.rewrites()).toBeUndefined();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000217
218 // Invalid matcher
219 doc = regexFactory.create({
Akron712733a2018-04-05 18:17:47 +0200220 match : "match:chook"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000221 });
Akronea4e9052017-07-06 16:12:05 +0200222 expect(doc.matchop()).toEqual('eq');
223 expect(doc.rewrites()).toBeDefined();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000224
225 // Invalid regex
226 doc = regexFactory.create({
Akron712733a2018-04-05 18:17:47 +0200227 value : "[^b"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000228 });
229 expect(doc).toBeUndefined();
230 });
231
232 it('should deserialize JSON-LD date', function () {
233
234 // Normal date
235 doc = dateFactory.create({});
236
237 expect(doc.matchop()).toEqual('eq');
238 expect(doc.key()).toEqual("pubDate");
239 expect(doc.type()).toEqual("date");
240 expect(doc.value()).toEqual("2014-11-05");
241
242 // Short date 1
243 doc = dateFactory.create({
Akron712733a2018-04-05 18:17:47 +0200244 "value" : "2014-11"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000245 });
246
247 expect(doc.matchop()).toEqual('eq');
248 expect(doc.key()).toEqual("pubDate");
249 expect(doc.type()).toEqual("date");
250 expect(doc.value()).toEqual("2014-11");
251
252 // Short date 2
253 doc = dateFactory.create({
Akron712733a2018-04-05 18:17:47 +0200254 "value" : "2014"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000255 });
256
257 expect(doc.matchop()).toEqual('eq');
258 expect(doc.key()).toEqual("pubDate");
259 expect(doc.type()).toEqual("date");
260 expect(doc.value()).toEqual("2014");
261
262 // Invalid date!
263 doc = dateFactory.create({
Akron712733a2018-04-05 18:17:47 +0200264 "value" : "2014-11-050"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000265 });
266 expect(doc).toBeUndefined();
267
268 // Invalid matcher!
269 doc = dateFactory.create({
Akron31d89942018-04-06 16:44:51 +0200270 "match" : "match:contains",
Nils Diewald7c8ced22015-04-15 19:21:00 +0000271 });
Akronea4e9052017-07-06 16:12:05 +0200272 expect(doc).toBeDefined();
273 expect(doc.rewrites()).toBeDefined();
274 expect(doc.matchop()).toEqual('eq');
Nils Diewald7c8ced22015-04-15 19:21:00 +0000275 });
276
277 it('should be serializale to JSON', function () {
278
279 // Empty doc
280 var doc = docClass.create();
281 expect(doc.toJson()).toEqual(jasmine.any(Object));
282
283 // Serialize string
284 doc = stringFactory.create();
285 expect(doc.toJson()).toEqual(jasmine.objectContaining({
Akron712733a2018-04-05 18:17:47 +0200286 "@type" : "koral:doc",
287 "type" : "type:string",
288 "key" : "author",
289 "value" : "Max Birkendale",
290 "match" : "match:eq"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000291 }));
292
293 // Serialize regex
294 doc = regexFactory.create();
295 expect(doc.toJson()).toEqual(jasmine.objectContaining({
Akron712733a2018-04-05 18:17:47 +0200296 "@type" : "koral:doc",
297 "type" : "type:regex",
298 "value" : "[^b]ee.+?",
299 "match" : "match:eq",
300 "key" : 'title'
Nils Diewald7c8ced22015-04-15 19:21:00 +0000301 }));
302
303 doc = regexFactory.create({
Akron712733a2018-04-05 18:17:47 +0200304 match: "match:ne"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000305 });
306 expect(doc.toJson()).toEqual(jasmine.objectContaining({
Akron712733a2018-04-05 18:17:47 +0200307 "@type" : "koral:doc",
308 "type" : "type:regex",
309 "value" : "[^b]ee.+?",
310 "match" : "match:ne",
311 "key" : 'title'
Nils Diewald7c8ced22015-04-15 19:21:00 +0000312 }));
313
314 doc = dateFactory.create();
315 expect(doc.toJson()).toEqual(jasmine.objectContaining({
Akron712733a2018-04-05 18:17:47 +0200316 "@type" : "koral:doc",
317 "type" : "type:date",
318 "value" : "2014-11-05",
319 "match" : "match:eq",
320 "key" : 'pubDate'
Nils Diewald7c8ced22015-04-15 19:21:00 +0000321 }));
322
323 doc = dateFactory.create({
Akron712733a2018-04-05 18:17:47 +0200324 value : "2014"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000325 });
326 expect(doc.toJson()).toEqual(jasmine.objectContaining({
Akron712733a2018-04-05 18:17:47 +0200327 "@type" : "koral:doc",
328 "type" : "type:date",
329 "value" : "2014",
330 "match" : "match:eq",
331 "key" : 'pubDate'
Nils Diewald7c8ced22015-04-15 19:21:00 +0000332 }));
333 });
334
335
336 it('should be serializale to String', function () {
337 // Empty doc
338 var doc = docClass.create();
Akronebc96662018-08-29 17:36:20 +0200339
Nils Diewald7c8ced22015-04-15 19:21:00 +0000340 expect(doc.toQuery()).toEqual("");
341
342 // Serialize string
343 doc = stringFactory.create();
344 expect(doc.toQuery()).toEqual('author = "Max Birkendale"');
345
346 // Serialize string with quotes
347 doc = stringFactory.create({ "value" : 'Max "Der Coole" Birkendate'});
348 expect(doc.toQuery()).toEqual('author = "Max \\"Der Coole\\" Birkendate"');
349
350 // Serialize regex
351 doc = regexFactory.create();
352 expect(doc.toQuery()).toEqual('title = /[^b]ee.+?/');
353
354 doc = regexFactory.create({
Akron712733a2018-04-05 18:17:47 +0200355 match: "match:ne"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000356 });
357 expect(doc.toQuery()).toEqual('title != /[^b]ee.+?/');
358
Akron8778f5d2017-06-30 21:25:55 +0200359 doc = regexFactory.create({
Akron712733a2018-04-05 18:17:47 +0200360 value: "WPD/AAA/00001"
Akron8778f5d2017-06-30 21:25:55 +0200361 });
362 expect(doc.toQuery()).toEqual('title = /WPD\\/AAA\\/00001/');
363
Nils Diewald7c8ced22015-04-15 19:21:00 +0000364 doc = dateFactory.create();
365 expect(doc.toQuery()).toEqual('pubDate in 2014-11-05');
366
367 doc = dateFactory.create({
Akron712733a2018-04-05 18:17:47 +0200368 value : "2014"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000369 });
370 expect(doc.toQuery()).toEqual('pubDate in 2014');
371 });
372 });
373
374
375 describe('KorAP.DocGroup', function () {
376 // Create example factories
377 var docFactory = buildFactory(
378 docClass,
Nils Diewaldf219eb82015-01-07 20:15:42 +0000379 {
Akron712733a2018-04-05 18:17:47 +0200380 "@type" : "koral:doc",
381 "match":"match:eq",
382 "key" : "author",
383 "value" : "Max Birkendale"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000384 }
385 );
386
387 var docGroupFactory = buildFactory(
388 docGroupClass, {
Akron712733a2018-04-05 18:17:47 +0200389 "@type" : "koral:docGroup",
390 "operation" : "operation:and",
391 "operands" : [
392 docFactory.create().toJson(),
393 docFactory.create({
394 "key" : "pubDate",
395 "type" : "type:date",
396 "value" : "2014-12-05"
397 }).toJson()
398 ]
Nils Diewald7c8ced22015-04-15 19:21:00 +0000399 });
400
401 it('should be initializable', function () {
402 // Create empty group
403 var docGroup = docGroupClass.create();
404 expect(docGroup.operation()).toEqual('and');
405
406 // Create empty group
407 docGroup = docGroupClass.create();
408 docGroup.operation('or');
409 expect(docGroup.operation()).toEqual('or');
410 });
411
412 it('should be definable', function () {
413
414 // Empty group
415 var docGroup = docGroupClass.create();
416 expect(docGroup.operation()).toEqual('and');
417
418 // Set values
419 docGroup.operation("or");
420 expect(docGroup.operation()).toEqual('or');
421
422 // Set invalid values
423 docGroup.operation("hui");
424 expect(docGroup.operation()).toEqual('or');
425 });
426
427 it('should be deserializable', function () {
Akronadab5e52018-08-20 13:50:53 +0200428
429 // Reset list
430 KorAP._vcKeyMenu = menuClass.create([['referTo','ref']]);
431
Nils Diewald7c8ced22015-04-15 19:21:00 +0000432 var docGroup = docGroupFactory.create();
433 expect(docGroup.operation()).toEqual("and");
434 expect(docGroup.operands().length).toEqual(2);
435
436 var op1 = docGroup.getOperand(0);
437 expect(op1.type()).toEqual("string");
438 expect(op1.key()).toEqual("author");
439 expect(op1.value()).toEqual("Max Birkendale");
440 expect(op1.matchop()).toEqual("eq");
441
442 var op2 = docGroup.getOperand(1);
443 expect(op2.type()).toEqual("date");
444 expect(op2.key()).toEqual("pubDate");
445 expect(op2.value()).toEqual("2014-12-05");
446 expect(op2.matchop()).toEqual("eq");
447
448 // Append empty group
449 var newGroup = docGroup.append(docGroupClass.create());
450 newGroup.operation('or');
451 newGroup.append(docFactory.create());
452 newGroup.append(docFactory.create({
Akron712733a2018-04-05 18:17:47 +0200453 "type" : "type:regex",
454 "key" : "title",
455 "value" : "^e.+?$",
456 "match" : "match:ne"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000457 }));
458
459 expect(docGroup.operation()).toEqual("and");
460 expect(docGroup.operands().length).toEqual(3);
461
462 var op1 = docGroup.getOperand(0);
463 expect(op1.ldType()).toEqual("doc");
464 expect(op1.type()).toEqual("string");
465 expect(op1.key()).toEqual("author");
466 expect(op1.value()).toEqual("Max Birkendale");
467 expect(op1.matchop()).toEqual("eq");
468
469 var op2 = docGroup.getOperand(1);
470 expect(op2.ldType()).toEqual("doc");
471 expect(op2.type()).toEqual("date");
472 expect(op2.key()).toEqual("pubDate");
473 expect(op2.value()).toEqual("2014-12-05");
474 expect(op2.matchop()).toEqual("eq");
475
476 var op3 = docGroup.getOperand(2);
477 expect(op3.ldType()).toEqual("docGroup");
478 expect(op3.operation()).toEqual("or");
Akronadab5e52018-08-20 13:50:53 +0200479
Nils Diewald7c8ced22015-04-15 19:21:00 +0000480 var op4 = op3.getOperand(0);
481 expect(op4.ldType()).toEqual("doc");
482 expect(op4.type()).toEqual("string");
483 expect(op4.key()).toEqual("author");
484 expect(op4.value()).toEqual("Max Birkendale");
485 expect(op4.matchop()).toEqual("eq");
486
487 var op5 = op3.getOperand(1);
488 expect(op5.ldType()).toEqual("doc");
489 expect(op5.type()).toEqual("regex");
490 expect(op5.key()).toEqual("title");
491 expect(op5.value()).toEqual("^e.+?$");
492 expect(op5.matchop()).toEqual("ne");
493 });
494
495 it('should be serializable to JSON', function () {
496 var docGroup = docGroupFactory.create();
497
498 expect(docGroup.toJson()).toEqual(jasmine.objectContaining({
Akron712733a2018-04-05 18:17:47 +0200499 "@type" : "koral:docGroup",
500 "operation" : "operation:and",
501 "operands" : [
502 {
503 "@type": 'koral:doc',
504 "key" : 'author',
505 "match": 'match:eq',
506 "value": 'Max Birkendale',
507 "type": 'type:string'
508 },
509 {
510 "@type": 'koral:doc',
511 "key": 'pubDate',
512 "match": 'match:eq',
513 "value": '2014-12-05',
514 "type": 'type:date'
515 }
516 ]
Nils Diewald7c8ced22015-04-15 19:21:00 +0000517 }));
518 });
Nils Diewalde15b7a22015-01-09 21:50:21 +0000519
Nils Diewald7c8ced22015-04-15 19:21:00 +0000520 it('should be serializable to String', function () {
521 var docGroup = docGroupFactory.create();
522 expect(docGroup.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +0200523 'author = "Max Birkendale" & pubDate in 2014-12-05'
Nils Diewald7c8ced22015-04-15 19:21:00 +0000524 );
Nils Diewald52f7eb12015-01-12 17:30:04 +0000525
Nils Diewald7c8ced22015-04-15 19:21:00 +0000526 docGroup = docGroupFactory.create({
Akron712733a2018-04-05 18:17:47 +0200527 "@type" : "koral:docGroup",
528 "operation" : "operation:or",
529 "operands" : [
530 {
531 "@type": 'koral:doc',
532 "key" : 'author',
533 "match": 'match:eq',
534 "value": 'Max Birkendale',
535 "type": 'type:string'
536 },
537 {
538 "@type" : "koral:docGroup",
539 "operation" : "operation:and",
540 "operands" : [
541 {
542 "@type": 'koral:doc',
543 "key": 'pubDate',
544 "match": 'match:geq',
545 "value": '2014-05-12',
546 "type": 'type:date'
547 },
548 {
549 "@type": 'koral:doc',
550 "key": 'pubDate',
551 "match": 'match:leq',
552 "value": '2014-12-05',
553 "type": 'type:date'
554 },
555 {
556 "@type": 'koral:doc',
557 "key": 'foo',
558 "match": 'match:ne',
559 "value": '[a]?bar',
560 "type": 'type:regex'
561 }
562 ]
563 }
564 ]
Nils Diewald7c8ced22015-04-15 19:21:00 +0000565 });
566 expect(docGroup.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +0200567 'author = "Max Birkendale" | ' +
568 '(pubDate since 2014-05-12 & ' +
569 'pubDate until 2014-12-05 & foo != /[a]?bar/)'
Nils Diewald7c8ced22015-04-15 19:21:00 +0000570 );
571 });
572 });
573
Akronb19803c2018-08-16 16:39:42 +0200574 describe('KorAP.DocGroupRef', function () {
575 // Create example factories
576 var docRefFactory = buildFactory(
577 docGroupRefClass,
578 {
579 "@type" : "koral:docGroupRef",
580 "ref" : "@max/myCorpus"
581 }
582 );
583
584 it('should be initializable', function () {
585 var vcRef = docGroupRefClass.create();
586 expect(vcRef.ref()).toBeUndefined();
587 });
588
589 it('should be definable', function () {
590 var vcRef = docGroupRefClass.create();
591 vcRef.ref("@peter/mycorpus");
592 expect(vcRef.ref()).toEqual("@peter/mycorpus");
593 vcRef.ref("@peter/mycorpus2");
594 expect(vcRef.ref()).toEqual("@peter/mycorpus2");
595 });
596
597 it('should deserialize JSON-LD string', function () {
598 var vcRef = docRefFactory.create();
599 expect(vcRef.ref()).toEqual("@max/myCorpus");
600 });
601
602 it('should serialize to JSON-LD', function () {
603 var vcRef = docRefFactory.create();
604 expect(vcRef.toJson()).toEqual(jasmine.objectContaining({
605 "@type" : "koral:docGroupRef",
606 "ref":"@max/myCorpus"
607 }));
608
609 vcRef.ref("@peter/myCorpus2");
610 expect(vcRef.toJson()).toEqual(jasmine.objectContaining({
611 "@type" : "koral:docGroupRef",
612 "ref":"@peter/myCorpus2"
613 }));
614 });
615
616 it('should serialize to a query', function () {
617 var vcRef = docRefFactory.create();
618 expect(vcRef.toQuery()).toEqual(
619 "referTo \"@max/myCorpus\""
620 );
621
622 vcRef.ref("@peter/myCorpus2");
623 expect(vcRef.toQuery()).toEqual(
624 "referTo \"@peter/myCorpus2\""
625 );
626 });
627 });
628
629
Nils Diewald7c8ced22015-04-15 19:21:00 +0000630 describe('KorAP.UnspecifiedDoc', function () {
631 it('should be initializable', function () {
632 var doc = unspecifiedClass.create();
633 var docElement = doc.element();
634 expect(docElement.getAttribute('class')).toEqual('doc unspecified');
Akronebc96662018-08-29 17:36:20 +0200635 expect(docElement.firstChild.firstChild.data).toEqual(KorAP.Locale.EMPTY);
636 expect(docElement.lastChild.lastChild.data).toEqual(KorAP.Locale.EMPTY);
Nils Diewald7c8ced22015-04-15 19:21:00 +0000637 expect(doc.toQuery()).toEqual('');
638
639 // Only removable
640 expect(docElement.lastChild.children.length).toEqual(0);
641 });
642
Akrond141a362018-07-10 18:12:13 +0200643 it('should be removable, when no root', function () {
Nils Diewald7c8ced22015-04-15 19:21:00 +0000644 var docGroup = docGroupClass.create();
645 docGroup.operation('or');
646 expect(docGroup.operation()).toEqual('or');
647
648 docGroup.append({
Akron712733a2018-04-05 18:17:47 +0200649 "@type": 'koral:doc',
650 "key": 'pubDate',
651 "match": 'match:eq',
652 "value": '2014-12-05',
653 "type": 'type:date'
Nils Diewald7c8ced22015-04-15 19:21:00 +0000654 });
655
656 // Add unspecified object
657 docGroup.append();
658
Akrond141a362018-07-10 18:12:13 +0200659 var parent = document.createElement('div');
660 parent.appendChild(docGroup.element());
661
Nils Diewald7c8ced22015-04-15 19:21:00 +0000662 expect(docGroup.element().getAttribute('class')).toEqual('docGroup');
663 expect(docGroup.element().children[0].getAttribute('class')).toEqual('doc');
664
665 var unspec = docGroup.element().children[1];
666 expect(unspec.getAttribute('class')).toEqual('doc unspecified');
667
Akronb19803c2018-08-16 16:39:42 +0200668 // Only unspec and delete
669 expect(unspec.children.length).toEqual(2);
670
Nils Diewald7c8ced22015-04-15 19:21:00 +0000671 // Removable
672 expect(unspec.lastChild.children.length).toEqual(1);
673 expect(unspec.lastChild.children[0].getAttribute('class')).toEqual('delete');
674 });
675
Akrond141a362018-07-10 18:12:13 +0200676
Nils Diewald7c8ced22015-04-15 19:21:00 +0000677 it('should be replaceable by a doc', function () {
678 var doc = unspecifiedClass.create();
679 expect(doc.ldType()).toEqual("non");
680 // No parent, therefor not updateable
681 expect(doc.key("baum")).toBeNull();
682
683 var docGroup = docGroupClass.create();
684 docGroup.operation('or');
685 expect(docGroup.operation()).toEqual('or');
686
687 docGroup.append({
Akron712733a2018-04-05 18:17:47 +0200688 "@type": 'koral:doc',
689 "key": 'pubDate',
690 "match": 'match:eq',
691 "value": '2014-12-05',
692 "type": 'type:date'
Nils Diewald7c8ced22015-04-15 19:21:00 +0000693 });
694
695 expect(docGroup.toQuery()).toEqual("pubDate in 2014-12-05");
696 docGroup.append();
697
698 expect(docGroup.getOperand(0).ldType()).toEqual("doc");
699 expect(docGroup.getOperand(1).ldType()).toEqual("non");
700
701 var op = docGroup.getOperand(1).element().lastChild;
Akron0b489ad2018-02-02 16:49:32 +0100702 expect(op.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +0000703 expect(op.children[0].getAttribute('class')).toEqual('delete');
704 expect(op.children.length).toEqual(1);
705
706 // Replace unspecified doc
707 expect(docGroup.getOperand(1).key("name")).not.toBeNull();
708 expect(docGroup.getOperand(1).ldType()).toEqual("doc");
709 expect(docGroup.getOperand(1).key()).toEqual("name");
Akron55a343b2018-04-06 19:57:36 +0200710 expect(docGroup.getOperand(1).value()).toBeUndefined();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000711
Akronb19803c2018-08-16 16:39:42 +0200712 expect(docGroup.getOperand(1).element().children.length).toEqual(4);
713
Nils Diewald7c8ced22015-04-15 19:21:00 +0000714 op = docGroup.getOperand(1).element().lastChild;
Akron0b489ad2018-02-02 16:49:32 +0100715 expect(op.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +0000716 expect(op.children[0].getAttribute('class')).toEqual('and');
717 expect(op.children[1].getAttribute('class')).toEqual('or');
718 expect(op.children[2].getAttribute('class')).toEqual('delete');
Akronb19803c2018-08-16 16:39:42 +0200719
Nils Diewald7c8ced22015-04-15 19:21:00 +0000720 expect(op.children.length).toEqual(3);
721
722 docGroup.getOperand(1).value("Pachelbel");
723 expect(docGroup.getOperand(1).value()).toEqual("Pachelbel");
724 expect(docGroup.getOperand(1).type()).toEqual("string");
725 expect(docGroup.getOperand(1).matchop()).toEqual("eq");
726
727 // Specified!
728 expect(docGroup.toQuery()).toEqual('pubDate in 2014-12-05 | name = "Pachelbel"');
729 });
Akronb19803c2018-08-16 16:39:42 +0200730
Nils Diewald7c8ced22015-04-15 19:21:00 +0000731 it('should be replaceable on root', function () {
Nils Diewald6283d692015-04-23 20:32:53 +0000732 var vc = vcClass.create();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000733 expect(vc.toQuery()).toEqual("");
734
735 expect(vc.root().ldType()).toEqual("non");
736
737 // No operators on root
738 op = vc.root().element().lastChild;
Akronebc96662018-08-29 17:36:20 +0200739 expect(op.lastChild.textContent).toEqual(KorAP.Locale.EMPTY);
Nils Diewald7c8ced22015-04-15 19:21:00 +0000740
741 // Replace
742 expect(vc.root().key("baum")).not.toBeNull();
743 expect(vc.root().ldType()).toEqual("doc");
744
745 op = vc.root().element().lastChild;
Akron0b489ad2018-02-02 16:49:32 +0100746 expect(op.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +0000747 expect(op.children[0].getAttribute('class')).toEqual('and');
748 expect(op.children[1].getAttribute('class')).toEqual('or');
749 expect(op.children[2].getAttribute('class')).toEqual('delete');
750 expect(op.children.length).toEqual(3);
751 });
Akron55a343b2018-04-06 19:57:36 +0200752
753 it('should be clickable', function () {
754 var vc = vcClass.create([
755 ["pubDate", "date"]
756 ]);
757 expect(vc.toQuery()).toEqual("");
Akronebc96662018-08-29 17:36:20 +0200758 expect(vc.builder().firstChild.textContent).toEqual(KorAP.Locale.EMPTY);
759 expect(vc.builder().firstChild.classList.contains('unspecified')).toEqual(true);
Akronadab5e52018-08-20 13:50:53 +0200760 vc.builder().firstChild.firstChild.click();
Akron55a343b2018-04-06 19:57:36 +0200761
762 // Click on pubDate
Akron3ad46942018-08-22 16:47:14 +0200763 vc.element().firstChild.getElementsByTagName("LI")[1].click();
Akronadab5e52018-08-20 13:50:53 +0200764 expect(vc.builder().firstChild.firstChild.textContent).toEqual("pubDate");
765 expect(vc.builder().firstChild.children[1].getAttribute("data-type")).toEqual("date");
Akron55a343b2018-04-06 19:57:36 +0200766 });
Nils Diewald7c8ced22015-04-15 19:21:00 +0000767 });
768
769 describe('KorAP.Doc element', function () {
770 it('should be initializable', function () {
771 var docElement = docClass.create(undefined, {
Akron712733a2018-04-05 18:17:47 +0200772 "@type" : "koral:doc",
773 "key":"Titel",
774 "value":"Baum",
775 "match":"match:eq"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000776 });
777 expect(docElement.key()).toEqual('Titel');
778 expect(docElement.matchop()).toEqual('eq');
779 expect(docElement.value()).toEqual('Baum');
780
781 var docE = docElement.element();
782 expect(docE.children[0].firstChild.data).toEqual('Titel');
783 expect(docE.children[1].firstChild.data).toEqual('eq');
784 expect(docE.children[1].getAttribute('data-type')).toEqual('string');
785 expect(docE.children[2].firstChild.data).toEqual('Baum');
786 expect(docE.children[2].getAttribute('data-type')).toEqual('string');
787
788 expect(docElement.toJson()).toEqual(jasmine.objectContaining({
Akron712733a2018-04-05 18:17:47 +0200789 "@type" : "koral:doc",
790 "key":"Titel",
791 "value":"Baum",
792 "match":"match:eq"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000793 }));
794 });
Akronb19803c2018-08-16 16:39:42 +0200795
796
797 it('should be replacable by unspecified', function () {
798 var vc = vcClass.create([
799 ["pubDate", "date"]
800 ]).fromJson({
801 "@type" : "koral:doc",
802 "key":"Titel",
803 "value":"Baum",
804 "match":"match:eq"
805 });
806 expect(vc.toQuery()).toEqual("Titel = \"Baum\"");
807
Akronadab5e52018-08-20 13:50:53 +0200808 var vcE = vc.builder();
Akronb19803c2018-08-16 16:39:42 +0200809 expect(vcE.firstChild.children.length).toEqual(4);
810
811 // Click to delete
812 vcE.firstChild.lastChild.lastChild.click();
813
814 expect(vcE.firstChild.children.length).toEqual(1);
815
Akronebc96662018-08-29 17:36:20 +0200816 expect(vcE.firstChild.textContent).toEqual(KorAP.Locale.EMPTY);
817 expect(vcE.firstChild.classList.contains("unspecified")).toBeTruthy();
Akronb19803c2018-08-16 16:39:42 +0200818 vcE.firstChild.firstChild.click();
819
820 // Click on pubDate
Akron3ad46942018-08-22 16:47:14 +0200821 vcE.firstChild.getElementsByTagName("LI")[1].click();
Akronb19803c2018-08-16 16:39:42 +0200822
823 expect(vcE.firstChild.firstChild.textContent).toEqual("pubDate");
824 expect(vcE.firstChild.children[1].getAttribute("data-type")).toEqual("date");
825
826 expect(vcE.firstChild.children.length).toEqual(4);
827 });
828
829
Akron587e4d92018-08-31 12:44:26 +0200830 it('should be replaceable by docGroupRef with deletion', function () {
Akron3ad46942018-08-22 16:47:14 +0200831 var vc = vcClass.create().fromJson({
Akronb19803c2018-08-16 16:39:42 +0200832 "@type" : "koral:doc",
833 "key":"Titel",
834 "value":"Baum",
835 "match":"match:eq"
836 });
837
838 expect(vc.toQuery()).toEqual("Titel = \"Baum\"");
839
Akronadab5e52018-08-20 13:50:53 +0200840 var vcE = vc.builder();
Akronb19803c2018-08-16 16:39:42 +0200841 expect(vcE.firstChild.children.length).toEqual(4);
842
843 // Click to delete
844 vcE.firstChild.lastChild.lastChild.click();
845
846 expect(vcE.firstChild.children.length).toEqual(1);
847
Akronebc96662018-08-29 17:36:20 +0200848 expect(vcE.firstChild.textContent).toEqual(KorAP.Locale.EMPTY);
849 expect(vcE.firstChild.classList.contains('unspecified')).toEqual(true);
Akronb19803c2018-08-16 16:39:42 +0200850 vcE.firstChild.firstChild.click();
851
Akron3ad46942018-08-22 16:47:14 +0200852 // Click on referTo
Akronb19803c2018-08-16 16:39:42 +0200853 vcE.firstChild.getElementsByTagName("LI")[0].click();
854
Akron3ad46942018-08-22 16:47:14 +0200855 expect(vcE.firstChild.firstChild.textContent).toEqual("referTo");
Akronb19803c2018-08-16 16:39:42 +0200856 expect(vcE.firstChild.children[1].getAttribute("data-type")).toEqual("string");
Akron587e4d92018-08-31 12:44:26 +0200857
Akronb19803c2018-08-16 16:39:42 +0200858 expect(vcE.firstChild.children.length).toEqual(3);
Akron62ac95b2018-08-30 18:08:25 +0200859 expect(vcE.firstChild.children[1].classList.contains("unspecified")).toBeTruthy();
Akronb19803c2018-08-16 16:39:42 +0200860 });
Akron587e4d92018-08-31 12:44:26 +0200861
862
863 it('should be replaceable by docGroupRef on root', function () {
864 var vc = vcClass.create().fromJson({
865 "@type" : "koral:doc",
866 "key":"Titel",
867 "value":"Baum",
868 "match":"match:eq"
869 });
870
871 expect(vc.toQuery()).toEqual("Titel = \"Baum\"");
872
873 var vcE = vc.builder();
874 expect(vcE.firstChild.children.length).toEqual(4);
875
876 // Click on the key
877 vcE.firstChild.firstChild.click();
878
879 expect(vcE.firstChild.getElementsByTagName("LI")[0].textContent).toEqual("referTo");
880
881 // Click on referTo
882 vcE.firstChild.getElementsByTagName("LI")[0].click();
883
884 // Now it's a referTo element
885 expect(vcE.firstChild.firstChild.textContent).toEqual("referTo");
886 expect(vcE.firstChild.children.length).toEqual(3);
887 expect(vcE.firstChild.children[1].classList.contains("unspecified")).toBeTruthy();
888 });
889
890 it('should be replaceable by docGroupRef nested', function () {
891 var vc = vcClass.create().fromJson({
892 "@type" : "koral:docGroup",
893 "operation" : "operation:and",
894 "operands" : [
895 {
896 "@type": 'koral:doc',
897 "key" : 'author',
898 "match": 'match:eq',
899 "value": 'Max Birkendale',
900 "type": 'type:string'
901 },
902 {
903 "@type": 'koral:doc',
904 "key": 'pubDate',
905 "match": 'match:eq',
906 "value": '2014-12-05',
907 "type": 'type:date'
908 }
909 ]
910 });
911
912 expect(vc.toQuery()).toEqual("author = \"Max Birkendale\" & pubDate in 2014-12-05");
913
914 var vcE = vc.builder();
915
916 // First doc
917 var doc = vcE.firstChild.firstChild;
918 expect(doc.children.length).toEqual(4);
919
920 // Click on the key
921 doc.firstChild.click();
922
923 expect(doc.getElementsByTagName("LI")[0].textContent).toEqual("referTo");
924
925 // Click on referTo
926 vcE.firstChild.getElementsByTagName("LI")[0].click();
927
928 // Now it's a referTo element
929 expect(vcE.firstChild.firstChild.firstChild.textContent).toEqual("referTo");
930 expect(vcE.firstChild.firstChild.children.length).toEqual(3);
931 expect(vcE.firstChild.firstChild.children[1].classList.contains("unspecified")).toBeTruthy();
932 });
Nils Diewald7c8ced22015-04-15 19:21:00 +0000933 });
934
935 describe('KorAP.DocGroup element', function () {
936 it('should be initializable', function () {
937
938 var docGroup = docGroupClass.create(undefined, {
Akron712733a2018-04-05 18:17:47 +0200939 "@type" : "koral:docGroup",
940 "operation" : "operation:and",
941 "operands" : [
942 {
943 "@type": 'koral:doc',
944 "key" : 'author',
945 "match": 'match:eq',
946 "value": 'Max Birkendale',
947 "type": 'type:string'
948 },
949 {
950 "@type": 'koral:doc',
951 "key": 'pubDate',
952 "match": 'match:eq',
953 "value": '2014-12-05',
954 "type": 'type:date'
955 }
956 ]
Nils Diewald7c8ced22015-04-15 19:21:00 +0000957 });
958
959 expect(docGroup.operation()).toEqual('and');
960 var e = docGroup.element();
961 expect(e.getAttribute('class')).toEqual('docGroup');
962 expect(e.getAttribute('data-operation')).toEqual('and');
963
964 var first = e.children[0];
965 expect(first.getAttribute('class')).toEqual('doc');
966 expect(first.children[0].getAttribute('class')).toEqual('key');
967 expect(first.children[1].getAttribute('class')).toEqual('match');
968 expect(first.children[2].getAttribute('class')).toEqual('value');
969 expect(first.children[2].getAttribute('data-type')).toEqual('string');
970 expect(first.children[0].firstChild.data).toEqual('author');
971 expect(first.children[1].firstChild.data).toEqual('eq');
972 expect(first.children[2].firstChild.data).toEqual('Max Birkendale');
973
974 var second = e.children[1];
975 expect(second.getAttribute('class')).toEqual('doc');
976 expect(second.children[0].getAttribute('class')).toEqual('key');
977 expect(second.children[1].getAttribute('class')).toEqual('match');
978 expect(second.children[2].getAttribute('class')).toEqual('value');
979 expect(second.children[2].getAttribute('data-type')).toEqual('date');
980 expect(second.children[0].firstChild.data).toEqual('pubDate');
981 expect(second.children[1].firstChild.data).toEqual('eq');
982 expect(second.children[2].firstChild.data).toEqual('2014-12-05');
983 });
984
985 it('should be deserializable with nested groups', function () {
986 var docGroup = docGroupClass.create(undefined, {
Akron712733a2018-04-05 18:17:47 +0200987 "@type" : "koral:docGroup",
988 "operation" : "operation:or",
989 "operands" : [
990 {
991 "@type": 'koral:doc',
992 "key" : 'author',
993 "match": 'match:eq',
994 "value": 'Max Birkendale',
995 "type": 'type:string'
996 },
997 {
998 "@type" : "koral:docGroup",
999 "operation" : "operation:and",
1000 "operands" : [
1001 {
1002 "@type": 'koral:doc',
1003 "key": 'pubDate',
1004 "match": 'match:geq',
1005 "value": '2014-05-12',
1006 "type": 'type:date'
1007 },
1008 {
1009 "@type": 'koral:doc',
1010 "key": 'pubDate',
1011 "match": 'match:leq',
1012 "value": '2014-12-05',
1013 "type": 'type:date'
1014 }
1015 ]
1016 }
1017 ]
Nils Diewald7c8ced22015-04-15 19:21:00 +00001018 });
1019
1020 expect(docGroup.operation()).toEqual('or');
1021 var e = docGroup.element();
1022 expect(e.getAttribute('class')).toEqual('docGroup');
1023 expect(e.getAttribute('data-operation')).toEqual('or');
1024
1025 expect(e.children[0].getAttribute('class')).toEqual('doc');
1026 var docop = e.children[0].lastChild;
Akron0b489ad2018-02-02 16:49:32 +01001027 expect(docop.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001028 expect(docop.children[0].getAttribute('class')).toEqual('and');
1029 expect(docop.children[1].getAttribute('class')).toEqual('or');
1030 expect(docop.children[2].getAttribute('class')).toEqual('delete');
1031
1032 expect(e.children[1].getAttribute('class')).toEqual('docGroup');
1033 expect(e.children[1].getAttribute('data-operation')).toEqual('and');
1034
1035 // This and-operation can be "or"ed or "delete"d
1036 var secop = e.children[1].children[2];
Akron0b489ad2018-02-02 16:49:32 +01001037 expect(secop.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001038 expect(secop.children[0].getAttribute('class')).toEqual('or');
1039 expect(secop.children[1].getAttribute('class')).toEqual('delete');
1040
1041 // This or-operation can be "and"ed or "delete"d
Akron0b489ad2018-02-02 16:49:32 +01001042 expect(e.children[2].getAttribute('class')).toEqual('operators button-group');
1043 expect(e.lastChild.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001044 expect(e.lastChild.children[0].getAttribute('class')).toEqual('and');
1045 expect(e.lastChild.children[1].getAttribute('class')).toEqual('delete');
1046 });
1047 });
1048
Akronb19803c2018-08-16 16:39:42 +02001049 describe('KorAP.DocGroupRef element', function () {
1050 it('should be initializable', function () {
1051 var docGroupRef = docGroupRefClass.create(undefined, {
1052 "@type" : "koral:docGroupRef",
1053 "ref" : "@franz/myVC1"
1054 });
1055 expect(docGroupRef.ref()).toEqual("@franz/myVC1");
1056 var dgrE = docGroupRef.element();
1057
Akron3ad46942018-08-22 16:47:14 +02001058 expect(dgrE.children[0].firstChild.data).toEqual("referTo");
Akronb19803c2018-08-16 16:39:42 +02001059 expect(dgrE.children[0].tagName).toEqual("SPAN");
1060 expect(dgrE.children[0].classList.contains("key")).toBeTruthy();
1061 expect(dgrE.children[0].classList.contains("fixed")).toBeTruthy();
1062 expect(dgrE.children[1].firstChild.data).toEqual("@franz/myVC1");
1063 expect(dgrE.children[1].tagName).toEqual("SPAN");
1064 expect(dgrE.children[1].classList.contains("value")).toBeTruthy();
1065 expect(dgrE.children[1].getAttribute("data-type")).toEqual("string");
1066 });
1067
1068 it('should be modifiable on reference', function () {
1069 var docGroupRef = docGroupRefClass.create(undefined, {
1070 "@type" : "koral:docGroupRef",
1071 "ref" : "@franz/myVC1"
1072 });
1073 var dgrE = docGroupRef.element();
1074 expect(docGroupRef.toQuery()).toEqual("referTo \"@franz/myVC1\"");
1075 dgrE.children[1].click();
1076
1077 var input = dgrE.children[1].firstChild;
1078 expect(input.tagName).toEqual("INPUT");
1079 input.value = "Versuch";
1080
1081 var event = new KeyboardEvent("keypress", {
1082 "key" : "[Enter]",
1083 "keyCode" : 13
1084 });
1085
1086 input.dispatchEvent(event);
1087 expect(docGroupRef.toQuery()).toEqual("referTo \"Versuch\"");
1088 });
1089 });
1090
1091
Akrone4961b12017-05-10 21:04:46 +02001092 describe('KorAP.VirtualCorpus', function () {
Nils Diewald7c8ced22015-04-15 19:21:00 +00001093 var simpleGroupFactory = buildFactory(docGroupClass, {
1094 "@type" : "koral:docGroup",
1095 "operation" : "operation:and",
1096 "operands" : [
Akron712733a2018-04-05 18:17:47 +02001097 {
1098 "@type": 'koral:doc',
1099 "key" : 'author',
1100 "match": 'match:eq',
1101 "value": 'Max Birkendale',
1102 "type": 'type:string'
1103 },
1104 {
1105 "@type": 'koral:doc',
1106 "key": 'pubDate',
1107 "match": 'match:eq',
1108 "value": '2014-12-05',
1109 "type": 'type:date'
1110 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00001111 ]
1112 });
1113
1114 var nestedGroupFactory = buildFactory(vcClass, {
1115 "@type" : "koral:docGroup",
1116 "operation" : "operation:or",
1117 "operands" : [
Akron712733a2018-04-05 18:17:47 +02001118 {
1119 "@type": 'koral:doc',
1120 "key" : 'author',
1121 "match": 'match:eq',
1122 "value": 'Max Birkendale',
1123 "type": 'type:string'
1124 },
1125 {
1126 "@type" : "koral:docGroup",
1127 "operation" : "operation:and",
1128 "operands" : [
1129 {
1130 "@type": 'koral:doc',
1131 "key": 'pubDate',
1132 "match": 'match:geq',
1133 "value": '2014-05-12',
1134 "type": 'type:date'
1135 },
1136 {
1137 "@type": 'koral:doc',
1138 "key": 'pubDate',
1139 "match": 'match:leq',
1140 "value": '2014-12-05',
1141 "type": 'type:date'
1142 }
1143 ]
1144 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00001145 ]
1146 });
1147
1148 var flatGroupFactory = buildFactory(vcClass, {
1149 "@type" : "koral:docGroup",
1150 "operation" : "operation:and",
1151 "operands" : [
Akron712733a2018-04-05 18:17:47 +02001152 {
1153 "@type": 'koral:doc',
1154 "key": 'pubDate',
1155 "match": 'match:geq',
1156 "value": '2014-05-12',
1157 "type": 'type:date'
1158 },
1159 {
1160 "@type": 'koral:doc',
1161 "key": 'pubDate',
1162 "match": 'match:leq',
1163 "value": '2014-12-05',
1164 "type": 'type:date'
1165 },
1166 {
1167 "@type": 'koral:doc',
1168 "key": 'foo',
1169 "match": 'match:eq',
1170 "value": 'bar',
1171 "type": 'type:string'
1172 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00001173 ]
1174 });
1175
1176 it('should be initializable', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00001177 var vc = vcClass.create();
Nils Diewald7c8ced22015-04-15 19:21:00 +00001178 expect(vc.element().getAttribute('class')).toEqual('vc');
1179 expect(vc.root().element().getAttribute('class')).toEqual('doc unspecified');
1180
1181 // Not removable
1182 expect(vc.root().element().lastChild.children.length).toEqual(0);
1183 });
1184
1185 it('should be based on a doc', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00001186 var vc = vcClass.create().fromJson({
Akron712733a2018-04-05 18:17:47 +02001187 "@type" : "koral:doc",
1188 "key":"Titel",
1189 "value":"Baum",
1190 "match":"match:eq"
Nils Diewald7c8ced22015-04-15 19:21:00 +00001191 });
1192
1193 expect(vc.element().getAttribute('class')).toEqual('vc');
1194 expect(vc.root().element().getAttribute('class')).toEqual('doc');
1195 expect(vc.root().key()).toEqual('Titel');
1196 expect(vc.root().value()).toEqual('Baum');
1197 expect(vc.root().matchop()).toEqual('eq');
1198
1199 var docE = vc.root().element();
1200 expect(docE.children[0].firstChild.data).toEqual('Titel');
1201 expect(docE.children[1].firstChild.data).toEqual('eq');
1202 expect(docE.children[1].getAttribute('data-type')).toEqual('string');
1203 expect(docE.children[2].firstChild.data).toEqual('Baum');
1204 expect(docE.children[2].getAttribute('data-type')).toEqual('string');
1205 });
1206
1207 it('should be based on a docGroup', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00001208 var vc = vcClass.create().fromJson(simpleGroupFactory.create().toJson());
Nils Diewald7c8ced22015-04-15 19:21:00 +00001209
1210 expect(vc.element().getAttribute('class')).toEqual('vc');
1211 expect(vc.root().element().getAttribute('class')).toEqual('docGroup');
1212 expect(vc.root().operation()).toEqual('and');
1213
1214 var docGroup = vc.root();
1215
1216 var first = docGroup.getOperand(0);
1217 expect(first.key()).toEqual('author');
1218 expect(first.value()).toEqual('Max Birkendale');
1219 expect(first.matchop()).toEqual('eq');
1220
1221 var second = docGroup.getOperand(1);
1222 expect(second.key()).toEqual('pubDate');
1223 expect(second.value()).toEqual('2014-12-05');
1224 expect(second.matchop()).toEqual('eq');
1225 });
1226
Akronb19803c2018-08-16 16:39:42 +02001227 it('should be based on a docGroupRef', function () {
1228 var vc = vcClass.create().fromJson({
1229 "@type" : "koral:docGroupRef",
1230 "ref":"myCorpus"
1231 });
1232
Akronadab5e52018-08-20 13:50:53 +02001233 // iv class="doc groupref"><span class="key fixed">@referTo</span><span data-type="string" class="value">myCorpus</span>
1234 var vcE = vc.builder();
1235 expect(vcE.getAttribute('class')).toEqual('builder');
Akronb19803c2018-08-16 16:39:42 +02001236 expect(vcE.firstChild.tagName).toEqual('DIV');
1237 expect(vcE.firstChild.classList.contains('groupref')).toBeTruthy();
1238
1239 expect(vcE.firstChild.firstChild.tagName).toEqual('SPAN');
1240 expect(vcE.firstChild.firstChild.classList.contains('key')).toBeTruthy();
1241 expect(vcE.firstChild.firstChild.classList.contains('fixed')).toBeTruthy();
1242
Akron3ad46942018-08-22 16:47:14 +02001243 expect(vcE.firstChild.firstChild.textContent).toEqual("referTo");
Akronb19803c2018-08-16 16:39:42 +02001244
1245 expect(vcE.firstChild.children[1].tagName).toEqual('SPAN');
1246 expect(vcE.firstChild.children[1].classList.contains('value')).toBeTruthy();
1247 expect(vcE.firstChild.children[1].getAttribute('data-type')).toEqual('string');
1248 expect(vcE.firstChild.children[1].textContent).toEqual("myCorpus");
1249 });
Nils Diewald7c8ced22015-04-15 19:21:00 +00001250
1251 it('should be based on a nested docGroup', function () {
1252 var vc = nestedGroupFactory.create();
1253
Akronadab5e52018-08-20 13:50:53 +02001254 expect(vc.builder().getAttribute('class')).toEqual('builder');
1255 expect(vc.builder().firstChild.getAttribute('class')).toEqual('docGroup');
1256 expect(vc.builder().firstChild.children[0].getAttribute('class')).toEqual('doc');
1257 var dg = vc.builder().firstChild.children[1];
Nils Diewald7c8ced22015-04-15 19:21:00 +00001258 expect(dg.getAttribute('class')).toEqual('docGroup');
1259 expect(dg.children[0].getAttribute('class')).toEqual('doc');
1260 expect(dg.children[1].getAttribute('class')).toEqual('doc');
Akron0b489ad2018-02-02 16:49:32 +01001261 expect(dg.children[2].getAttribute('class')).toEqual('operators button-group');
Akronadab5e52018-08-20 13:50:53 +02001262 expect(vc.builder().firstChild.children[2].getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001263 });
1264
Akronb19803c2018-08-16 16:39:42 +02001265 it('should be based on a nested docGroupRef', function () {
1266 var vc = vcClass.create().fromJson({
1267 "@type" : "koral:docGroup",
1268 "operation" : "operation:and",
1269 "operands" : [{
1270 "@type" : "koral:docGroupRef",
1271 "ref":"myCorpus"
1272 },{
1273 "@type" : "koral:doc",
1274 "key":"Titel",
1275 "value":"Baum",
1276 "match":"match:eq"
1277 }]
1278 });
1279
1280 expect(vc._root.ldType()).toEqual("docGroup");
1281
1282 expect(vc.toQuery()).toEqual('referTo "myCorpus" & Titel = "Baum"');
1283 });
1284
1285
Nils Diewald7c8ced22015-04-15 19:21:00 +00001286 it('should be modifiable by deletion in flat docGroups', function () {
1287 var vc = flatGroupFactory.create();
1288 var docGroup = vc.root();
1289
1290 expect(docGroup.element().getAttribute('class')).toEqual('docGroup');
1291
1292 var doc = docGroup.getOperand(1);
1293 expect(doc.key()).toEqual("pubDate");
1294 expect(doc.value()).toEqual("2014-12-05");
1295
1296 // Remove operand 1
1297 expect(docGroup.delOperand(doc).update()).not.toBeUndefined();
1298 expect(doc._element).toEqual(undefined);
1299
1300 doc = docGroup.getOperand(1);
1301 expect(doc.key()).toEqual("foo");
1302
1303 // Remove operand 1
1304 expect(docGroup.delOperand(doc).update()).not.toBeUndefined();
1305 expect(doc._element).toEqual(undefined);
1306
1307 // Only one operand left ...
1308 expect(docGroup.getOperand(1)).toBeUndefined();
1309 // ... but there shouldn't be a group anymore at all!
1310 expect(docGroup.getOperand(0)).toBeUndefined();
1311
1312 var obj = vc.root();
1313 expect(obj.ldType()).toEqual("doc");
1314 expect(obj.key()).toEqual("pubDate");
1315 expect(obj.value()).toEqual("2014-05-12");
1316
1317 expect(obj.element().getAttribute('class')).toEqual('doc');
1318 });
1319
1320
1321 it('should be modifiable by deletion in nested docGroups (root case)', function () {
1322 var vc = nestedGroupFactory.create();
1323
1324 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001325 'author = "Max Birkendale" | (pubDate since 2014-05-12 & pubDate until 2014-12-05)'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001326 );
1327
1328 var docGroup = vc.root();
1329 expect(docGroup.ldType()).toEqual("docGroup");
1330 expect(docGroup.operation()).toEqual("or");
1331
1332 var doc = docGroup.getOperand(0);
1333 expect(doc.key()).toEqual("author");
1334 expect(doc.value()).toEqual("Max Birkendale");
1335
1336 docGroup = docGroup.getOperand(1);
1337 expect(docGroup.operation()).toEqual("and");
1338
1339 doc = docGroup.getOperand(0);
1340 expect(doc.key()).toEqual("pubDate");
1341 expect(doc.matchop()).toEqual("geq");
1342 expect(doc.value()).toEqual("2014-05-12");
1343 expect(doc.type()).toEqual("date");
1344
1345 doc = docGroup.getOperand(1);
1346 expect(doc.key()).toEqual("pubDate");
1347 expect(doc.matchop()).toEqual("leq");
1348 expect(doc.value()).toEqual("2014-12-05");
1349 expect(doc.type()).toEqual("date");
1350
1351 // Remove first operand so everything becomes root
1352 expect(
Akron712733a2018-04-05 18:17:47 +02001353 vc.root().delOperand(
1354 vc.root().getOperand(0)
1355 ).update().ldType()
Nils Diewald7c8ced22015-04-15 19:21:00 +00001356 ).toEqual("docGroup");
1357
1358 expect(vc.root().ldType()).toEqual("docGroup");
1359 expect(vc.root().operation()).toEqual("and");
1360 expect(vc.root().getOperand(0).ldType()).toEqual("doc");
1361
1362 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001363 'pubDate since 2014-05-12 & pubDate until 2014-12-05'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001364 );
1365 });
1366
1367 it('should be modifiable by deletion in nested docGroups (resolve group case)', function () {
1368 var vc = nestedGroupFactory.create();
1369
1370 // Get nested group
1371 var firstGroup = vc.root().getOperand(1);
1372 firstGroup.append(simpleGroupFactory.create({ "operation" : "operation:or" }));
1373
1374 // Structur is now:
1375 // or(doc, and(doc, doc, or(doc, doc)))
1376
1377 // Get nested or in and
1378 var orGroup = vc.root().getOperand(1).getOperand(2);
1379 expect(orGroup.ldType()).toEqual("docGroup");
1380 expect(orGroup.operation()).toEqual("or");
1381
1382 // Remove
1383 // Structur is now:
1384 // or(doc, and(doc, doc, doc)))
1385 expect(orGroup.delOperand(orGroup.getOperand(0)).update().operation()).toEqual("and");
1386 expect(vc.root().getOperand(1).operands().length).toEqual(3);
1387 });
1388
1389 it('should be modifiable by deletion in nested docGroups (identical group case)', function () {
1390 var vc = nestedGroupFactory.create();
1391
1392 // Get nested group
1393 var firstGroup = vc.root().getOperand(1);
1394 firstGroup.append(simpleGroupFactory.create({
Akron712733a2018-04-05 18:17:47 +02001395 "operation" : "operation:or"
Nils Diewald7c8ced22015-04-15 19:21:00 +00001396 }));
1397 var oldAuthor = firstGroup.getOperand(2).getOperand(0);
1398 oldAuthor.key("title");
1399 oldAuthor.value("Der Birnbaum");
1400
1401 // Structur is now:
1402 // or(doc, and(doc, doc, or(doc, doc)))
1403 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001404 'author = "Max Birkendale" | ' +
1405 '(pubDate since 2014-05-12 & ' +
1406 'pubDate until 2014-12-05 & ' +
1407 '(title = "Der Birnbaum" | ' +
1408 'pubDate in 2014-12-05))'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001409 );
1410
1411 var andGroup = vc.root().getOperand(1);
1412
1413 // Get leading docs in and
1414 var doc1 = andGroup.getOperand(0);
1415 expect(doc1.ldType()).toEqual("doc");
1416 expect(doc1.value()).toEqual("2014-05-12");
1417 var doc2 = andGroup.getOperand(1);
1418 expect(doc2.ldType()).toEqual("doc");
1419 expect(doc2.value()).toEqual("2014-12-05");
1420
1421 // Remove 2
1422 expect(
Akron712733a2018-04-05 18:17:47 +02001423 andGroup.delOperand(doc2).update().operation()
Nils Diewald7c8ced22015-04-15 19:21:00 +00001424 ).toEqual("and");
1425 // Structur is now:
1426 // or(doc, and(doc, or(doc, doc)))
1427
1428 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001429 'author = "Max Birkendale"' +
1430 ' | (pubDate since 2014-05-12 & ' +
1431 '(title = "Der Birnbaum" | pubDate in 2014-12-05))'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001432 );
1433
1434
1435 // Remove 1
1436 expect(andGroup.delOperand(doc1).update().operation()).toEqual("or");
1437 // Structur is now:
1438 // or(doc, doc, doc)
1439
1440 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001441 'author = "Max Birkendale" | title = "Der Birnbaum" | pubDate in 2014-12-05'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001442 );
1443 });
1444
1445 it('should be reducible to unspecification', function () {
1446 var vc = demoFactory.create();
1447
1448 expect(vc.toQuery()).toEqual(vc.root().toQuery());
1449 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001450 '(Titel = "Baum" & Veröffentlichungsort = "hihi" & ' +
1451 '(Titel = "Baum" | Veröffentlichungsort = "hihi")) ' +
1452 '| Untertitel ~ "huhu"');
Akrond141a362018-07-10 18:12:13 +02001453 expect(vc.root().element().lastChild.children[0].innerText).toEqual('and');
1454 expect(vc.root().element().lastChild.children[1].innerText).toEqual('×');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001455 expect(vc.root().delOperand(vc.root().getOperand(0)).update()).not.toBeUndefined();
Akron712733a2018-04-05 18:17:47 +02001456 expect(vc.toQuery()).toEqual('Untertitel ~ "huhu"');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001457
1458 var lc = vc.root().element().lastChild;
Akrond141a362018-07-10 18:12:13 +02001459 expect(lc.children[0].innerText).toEqual('and');
1460 expect(lc.children[1].innerText).toEqual('or');
1461 expect(lc.children[2].innerText).toEqual('×');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001462
1463 // Clean everything
1464 vc.clean();
1465 expect(vc.toQuery()).toEqual('');
1466 });
1467
1468 it('should flatten on import', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00001469 var vc = vcClass.create().fromJson({
Akron712733a2018-04-05 18:17:47 +02001470 "@type":"koral:docGroup",
1471 "operation":"operation:or",
1472 "operands":[
1473 {
1474 "@type":"koral:docGroup",
1475 "operation":"operation:or",
1476 "operands":[
Nils Diewald7c8ced22015-04-15 19:21:00 +00001477 {
Akron712733a2018-04-05 18:17:47 +02001478 "@type":"koral:doc",
1479 "key":"Titel",
1480 "value":"Baum",
1481 "match":"match:eq"
Nils Diewald7c8ced22015-04-15 19:21:00 +00001482 },
1483 {
Akron712733a2018-04-05 18:17:47 +02001484 "@type":"koral:doc",
1485 "key":"Veröffentlichungsort",
1486 "value":"hihi",
1487 "match":"match:eq"
Nils Diewald7c8ced22015-04-15 19:21:00 +00001488 },
1489 {
Akron712733a2018-04-05 18:17:47 +02001490 "@type":"koral:docGroup",
1491 "operation":"operation:or",
1492 "operands":[
1493 {
1494 "@type":"koral:doc",
1495 "key":"Titel",
1496 "value":"Baum",
1497 "match":"match:eq"
1498 },
1499 {
1500 "@type":"koral:doc",
1501 "key":"Veröffentlichungsort",
1502 "value":"hihi",
1503 "match":"match:eq"
1504 }
1505 ]
Nils Diewald7c8ced22015-04-15 19:21:00 +00001506 }
Akron712733a2018-04-05 18:17:47 +02001507 ]
1508 },
1509 {
1510 "@type":"koral:doc",
1511 "key":"Untertitel",
1512 "value":"huhu",
1513 "match":"match:contains"
1514 }
1515 ]
Nils Diewald7c8ced22015-04-15 19:21:00 +00001516 });
Nils Diewaldfda29d92015-01-22 17:28:01 +00001517
Nils Diewald7c8ced22015-04-15 19:21:00 +00001518 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001519 'Titel = "Baum" | Veröffentlichungsort = "hihi" | Untertitel ~ "huhu"'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001520 );
Nils Diewald86dad5b2015-01-28 15:09:07 +00001521 });
Akron1bdf5272018-07-24 18:51:30 +02001522
1523 it('should be deserializable from collection 1', function () {
1524 var kq = {
1525 "matches":["..."],
1526 "collection":{
1527 "@type": "koral:docGroup",
1528 "operation": "operation:or",
1529 "operands": [{
1530 "@type": "koral:docGroup",
1531 "operation": "operation:and",
1532 "operands": [
1533 {
1534 "@type": "koral:doc",
1535 "key": "title",
1536 "match": "match:eq",
1537 "value": "Der Birnbaum",
1538 "type": "type:string"
1539 },
1540 {
1541 "@type": "koral:doc",
1542 "key": "pubPlace",
1543 "match": "match:eq",
1544 "value": "Mannheim",
1545 "type": "type:string"
1546 },
1547 {
1548 "@type": "koral:docGroup",
1549 "operation": "operation:or",
1550 "operands": [
1551 {
1552 "@type": "koral:doc",
1553 "key": "subTitle",
1554 "match": "match:eq",
1555 "value": "Aufzucht und Pflege",
1556 "type": "type:string"
1557 },
1558 {
1559 "@type": "koral:doc",
1560 "key": "subTitle",
1561 "match": "match:eq",
1562 "value": "Gedichte",
1563 "type": "type:string"
1564 }
1565 ]
1566 }
1567 ]
1568 },{
1569 "@type": "koral:doc",
1570 "key": "pubDate",
1571 "match": "match:geq",
1572 "value": "2015-03-05",
1573 "type": "type:date",
1574 "rewrites" : [{
1575 "@type" : "koral:rewrite",
1576 "operation" : "operation:modification",
1577 "src" : "querySerializer",
1578 "scope" : "tree"
1579 }]
1580 }]
1581 }
1582 };
1583
1584 var vc = vcClass.create().fromJson(kq["collection"]);
1585 expect(vc.toQuery()).toEqual('(title = "Der Birnbaum" & pubPlace = "Mannheim" & (subTitle = "Aufzucht und Pflege" | subTitle = "Gedichte")) | pubDate since 2015-03-05');
1586 });
1587
1588 it('should be deserializable from collection 2', function () {
1589 var kq = {
1590 "@context": "http://korap.ids-mannheim.de/ns/KoralQuery/v0.3/context.jsonld",
1591 "meta": {},
1592 "query": {
1593 "@type": "koral:token",
1594 "wrap": {
1595 "@type": "koral:term",
1596 "match": "match:eq",
1597 "layer": "orth",
1598 "key": "Baum",
1599 "foundry": "opennlp",
1600 "rewrites": [
1601 {
1602 "@type": "koral:rewrite",
1603 "src": "Kustvakt",
1604 "operation": "operation:injection",
1605 "scope": "foundry"
1606 }
1607 ]
1608 },
1609 "idn": "Baum_2227",
1610 "rewrites": [
1611 {
1612 "@type": "koral:rewrite",
1613 "src": "Kustvakt",
1614 "operation": "operation:injection",
1615 "scope": "idn"
1616 }
1617 ]
1618 },
1619 "collection": {
1620 "@type": "koral:docGroup",
1621 "operation": "operation:and",
1622 "operands": [
1623 {
1624 "@type": "koral:doc",
1625 "match": "match:eq",
1626 "type": "type:regex",
1627 "value": "CC-BY.*",
1628 "key": "availability"
1629 },
1630 {
1631 "@type": "koral:doc",
1632 "match": "match:eq",
1633 "type":"type:text",
1634 "value": "Goethe",
1635 "key": "author"
1636 }
1637 ],
1638 "rewrites": [
1639 {
1640 "@type": "koral:rewrite",
1641 "src": "Kustvakt",
1642 "operation": "operation:insertion",
1643 "scope": "availability(FREE)"
1644 }
1645 ]
1646 },
1647 "matches": []
1648 };
1649
1650 var vc = vcClass.create().fromJson(kq["collection"]);
1651 expect(vc.toQuery()).toEqual('availability = /CC-BY.*/ & author = "Goethe"');
1652 });
Nils Diewald86dad5b2015-01-28 15:09:07 +00001653
Akron8a670162018-08-28 10:09:13 +02001654 it('shouldn\'t be deserializable from collection with unknown type', function () {
1655 var kq = {
1656 "@type" : "koral:doc",
1657 "match": "match:eq",
1658 "type":"type:failure",
1659 "value": "Goethe",
1660 "key": "author"
1661 };
Akron1bdf5272018-07-24 18:51:30 +02001662
Akron8a670162018-08-28 10:09:13 +02001663 expect(function () {
1664 vcClass.create().fromJson(kq)
1665 }).toThrow(new Error("Unknown value type: string"));
1666 });
1667
1668 it('should return a name', function () {
1669 var vc = vcClass.create();
1670 expect(vc.getName()).toEqual(KorAP.Locale.VC_allCorpora);
1671
1672 vc = vcClass.create().fromJson({"@type" : "koral:docGroupRef", "ref" : "DeReKo"});
1673 expect(vc.getName()).toEqual("DeReKo");
1674
1675 vc = vcClass.create().fromJson({"@type" : "koral:doc", "key" : "author", "value" : "Peter"});
1676 expect(vc.getName()).toEqual(KorAP.Locale.VC_oneCollection);
1677 });
Akrond2474aa2018-08-28 12:06:27 +02001678
1679 it('should check for rewrites', function () {
1680
1681 var vc = vcClass.create().fromJson({
1682 "@type" : "koral:doc",
1683 "key" : "author",
1684 "value" : "Goethe",
1685 "rewrites" : [{
1686 "@type" : "koral:rewrite",
1687 "operation" : "operation:modification",
1688 "src" : "querySerializer",
1689 "scope" : "value"
1690 }]
1691 });
1692 expect(vc.wasRewritten()).toBeTruthy();
1693
1694 var nested = {
1695 "@type" : "koral:docGroup",
1696 "operation" : "operation:or",
1697 "operands" : [
1698 {
1699 "@type" : "koral:doc",
1700 "key" : "author",
1701 "value" : "Goethe"
1702 },
1703 {
1704 "@type" : "koral:docGroup",
1705 "operation" : "operation:and",
1706 "operands" : [
1707 {
1708 "@type": "koral:doc",
1709 "key" : "author",
1710 "value" : "Schiller"
1711 },
1712 {
1713 "@type": "koral:doc",
1714 "key" : "author",
1715 "value" : "Fontane"
1716 }
1717 ]
1718 }
1719 ]
1720 };
1721 vc = vcClass.create().fromJson(nested);
1722 expect(vc.wasRewritten()).toBe(false);
1723
1724 nested["operands"][1]["operands"][1]["rewrites"] = [{
1725 "@type" : "koral:rewrite",
1726 "operation" : "operation:modification",
1727 "src" : "querySerializer",
1728 "scope" : "tree"
1729 }];
1730 vc = vcClass.create().fromJson(nested);
1731 expect(vc.wasRewritten()).toBeTruthy();
1732 });
Akron1bdf5272018-07-24 18:51:30 +02001733 });
1734
1735
Nils Diewald7c8ced22015-04-15 19:21:00 +00001736 describe('KorAP.Operators', function () {
1737 it('should be initializable', function () {
1738 var op = operatorsClass.create(true, false, false);
1739 expect(op.and()).toBeTruthy();
1740 expect(op.or()).not.toBeTruthy();
1741 expect(op.del()).not.toBeTruthy();
1742
1743 op.and(false);
1744 expect(op.and()).not.toBeTruthy();
1745 expect(op.or()).not.toBeTruthy();
1746 expect(op.del()).not.toBeTruthy();
1747
1748 op.or(true);
1749 op.del(true);
1750 expect(op.and()).not.toBeTruthy();
1751 expect(op.or()).toBeTruthy();
1752 expect(op.del()).toBeTruthy();
1753
Akrond141a362018-07-10 18:12:13 +02001754 var e = op.update();
Akron0b489ad2018-02-02 16:49:32 +01001755 expect(e.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001756 expect(e.children[0].getAttribute('class')).toEqual('or');
Akrond141a362018-07-10 18:12:13 +02001757 expect(e.children[0].innerText).toEqual('or');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001758 expect(e.children[1].getAttribute('class')).toEqual('delete');
Akrond141a362018-07-10 18:12:13 +02001759 expect(e.children[1].innerText).toEqual('×');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001760
1761 op.and(true);
1762 op.del(false);
Akrond141a362018-07-10 18:12:13 +02001763 e = op.update();
Nils Diewald7c8ced22015-04-15 19:21:00 +00001764
Akron0b489ad2018-02-02 16:49:32 +01001765 expect(e.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001766 expect(e.children[0].getAttribute('class')).toEqual('and');
Akrond141a362018-07-10 18:12:13 +02001767 expect(e.children[0].innerText).toEqual('and');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001768 expect(e.children[1].getAttribute('class')).toEqual('or');
Akrond141a362018-07-10 18:12:13 +02001769 expect(e.children[1].innerText).toEqual('or');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001770 });
1771 });
1772
1773 describe('KorAP._delete (event)', function () {
1774 var complexVCFactory = buildFactory(vcClass,{
1775 "@type": 'koral:docGroup',
1776 'operation' : 'operation:and',
1777 'operands' : [
Akron712733a2018-04-05 18:17:47 +02001778 {
1779 "@type": 'koral:doc',
1780 "key": 'pubDate',
1781 "match": 'match:eq',
1782 "value": '2014-12-05',
1783 "type": 'type:date'
1784 },
1785 {
1786 "@type" : 'koral:docGroup',
1787 'operation' : 'operation:or',
1788 'operands' : [
1789 {
1790 '@type' : 'koral:doc',
1791 'key' : 'title',
1792 'value' : 'Hello World!'
1793 },
1794 {
1795 '@type' : 'koral:doc',
1796 'key' : 'foo',
1797 'value' : 'bar'
1798 }
1799 ]
1800 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00001801 ]
1802 });
1803
1804 it('should clean on root docs', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00001805 var vc = vcClass.create().fromJson({
Akron712733a2018-04-05 18:17:47 +02001806 "@type": 'koral:doc',
1807 "key": 'pubDate',
1808 "match": 'match:eq',
1809 "value": '2014-12-05',
1810 "type": 'type:date'
Nils Diewald86dad5b2015-01-28 15:09:07 +00001811 });
Nils Diewald7c8ced22015-04-15 19:21:00 +00001812 expect(vc.root().toQuery()).toEqual('pubDate in 2014-12-05');
Akron0b489ad2018-02-02 16:49:32 +01001813 expect(vc.root().element().lastChild.getAttribute('class')).toEqual('operators button-group');
Nils Diewald86dad5b2015-01-28 15:09:07 +00001814
Nils Diewald7c8ced22015-04-15 19:21:00 +00001815 // Clean with delete from root
1816 expect(vc.root().element().lastChild.lastChild.getAttribute('class')).toEqual('delete');
1817 _delOn(vc.root());
1818 expect(vc.root().toQuery()).toEqual('');
Akronebc96662018-08-29 17:36:20 +02001819 expect(vc.root().element().lastChild.lastChild.data).toEqual(KorAP.Locale.EMPTY);
1820 expect(vc.root().element().classList.contains('unspecified')).toEqual(true);
Nils Diewald7c8ced22015-04-15 19:21:00 +00001821 });
Nils Diewald86dad5b2015-01-28 15:09:07 +00001822
Nils Diewald7c8ced22015-04-15 19:21:00 +00001823 it('should remove on nested docs', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00001824 var vc = vcClass.create().fromJson(
Akron712733a2018-04-05 18:17:47 +02001825 {
1826 "@type": 'koral:docGroup',
1827 'operation' : 'operation:and',
1828 'operands' : [
1829 {
1830 "@type": 'koral:doc',
1831 "key": 'pubDate',
1832 "match": 'match:eq',
1833 "value": '2014-12-05',
1834 "type": 'type:date'
1835 },
1836 {
1837 "@type" : 'koral:doc',
1838 'key' : 'foo',
1839 'value' : 'bar'
1840 }
1841 ]
1842 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00001843 );
1844
1845 // Delete with direct element access
1846 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar"');
1847 _delOn(vc.root().getOperand(0));
1848
1849 expect(vc.toQuery()).toEqual('foo = "bar"');
1850 expect(vc.root().ldType()).toEqual('doc');
1851 });
1852
1853 it('should clean on doc groups', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00001854 var vc = vcClass.create().fromJson(
Akron712733a2018-04-05 18:17:47 +02001855 {
1856 "@type": 'koral:docGroup',
1857 'operation' : 'operation:and',
1858 'operands' : [
1859 {
1860 "@type": 'koral:doc',
1861 "key": 'pubDate',
1862 "match": 'match:eq',
1863 "value": '2014-12-05',
1864 "type": 'type:date'
1865 },
1866 {
1867 "@type" : 'koral:doc',
1868 'key' : 'foo',
1869 'value' : 'bar'
1870 }
1871 ]
1872 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00001873 );
1874
1875 // Cleanwith direct element access
1876 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar"');
1877 _delOn(vc.root());
1878 expect(vc.toQuery()).toEqual('');
1879 expect(vc.root().ldType()).toEqual('non');
1880 });
1881
1882 it('should remove on nested doc groups (case of ungrouping 1)', function () {
1883 var vc = complexVCFactory.create();
1884
1885 // Delete with direct element access
1886 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001887 'pubDate in 2014-12-05 & (title = "Hello World!" | foo = "bar")'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001888 );
1889
1890 // Remove hello world:
1891 _delOn(vc.root().getOperand(1).getOperand(0));
1892 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar"');
1893 expect(vc.root().ldType()).toEqual('docGroup');
1894 });
1895
1896 it('should remove on nested doc groups (case of ungrouping 2)', function () {
1897 var vc = complexVCFactory.create();
1898
1899 // Delete with direct element access
1900 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001901 'pubDate in 2014-12-05 & (title = "Hello World!" | foo = "bar")'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001902 );
1903
1904 // Remove bar
1905 _delOn(vc.root().getOperand(1).getOperand(1));
1906 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & title = "Hello World!"');
1907 expect(vc.root().ldType()).toEqual('docGroup');
1908 expect(vc.root().operation()).toEqual('and');
1909 });
1910
1911 it('should remove on nested doc groups (case of root changing)', function () {
1912 var vc = complexVCFactory.create();
1913
1914 // Delete with direct element access
1915 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001916 'pubDate in 2014-12-05 & ' +
1917 '(title = "Hello World!" | foo = "bar")'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001918 );
1919
1920 // Remove bar
1921 _delOn(vc.root().getOperand(0));
1922 expect(vc.toQuery()).toEqual('title = "Hello World!" | foo = "bar"');
1923 expect(vc.root().ldType()).toEqual('docGroup');
1924 expect(vc.root().operation()).toEqual('or');
1925 });
1926
1927 it('should remove on nested doc groups (list flattening)', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00001928 var vc = vcClass.create().fromJson(
Akron712733a2018-04-05 18:17:47 +02001929 {
1930 "@type": 'koral:docGroup',
1931 'operation' : 'operation:or',
1932 'operands' : [
1933 {
1934 "@type": 'koral:doc',
1935 "key": 'pubDate',
1936 "match": 'match:eq',
1937 "value": '2014-12-05',
1938 "type": 'type:date'
1939 },
1940 {
1941 "@type" : 'koral:doc',
1942 'key' : 'foo',
1943 'value' : 'bar'
1944 },
1945 {
1946 "@type": 'koral:docGroup',
1947 'operation' : 'operation:and',
1948 'operands' : [
1949 {
1950 "@type": 'koral:doc',
1951 "key": 'pubDate',
1952 "match": 'match:eq',
1953 "value": '2014-12-05',
1954 "type": 'type:date'
1955 },
1956 {
1957 "@type" : 'koral:docGroup',
1958 'operation' : 'operation:or',
1959 'operands' : [
1960 {
1961 '@type' : 'koral:doc',
1962 'key' : 'title',
1963 'value' : 'Hello World!'
1964 },
1965 {
1966 '@type' : 'koral:doc',
1967 'key' : 'yeah',
1968 'value' : 'juhu'
1969 }
1970 ]
1971 }
1972 ]
1973 }
1974 ]
1975 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00001976 );
1977
1978 // Delete with direct element access
1979 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001980 'pubDate in 2014-12-05 | foo = "bar" | ' +
1981 '(pubDate in 2014-12-05 & ' +
1982 '(title = "Hello World!" | yeah = "juhu"))'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001983 );
1984
1985 expect(vc.root().ldType()).toEqual('docGroup');
1986 expect(vc.root().operation()).toEqual('or');
1987
1988 // Operands and operators
Akronadab5e52018-08-20 13:50:53 +02001989 expect(vc.builder().firstChild.children.length).toEqual(4);
1990 expect(vc.builder().firstChild.lastChild.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001991
1992 // Remove inner group and flatten
1993 _delOn(vc.root().getOperand(2).getOperand(0));
1994
1995 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001996 'pubDate in 2014-12-05 | foo = "bar" | title = "Hello World!" | yeah = "juhu"'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001997 );
1998 expect(vc.root().ldType()).toEqual('docGroup');
1999 expect(vc.root().operation()).toEqual('or');
2000
2001 // Operands and operators
Akronadab5e52018-08-20 13:50:53 +02002002 expect(vc.builder().firstChild.children.length).toEqual(5);
2003 expect(vc.builder().firstChild.lastChild.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +00002004 });
2005 });
2006
2007 describe('KorAP._add (event)', function () {
2008 var complexVCFactory = buildFactory(vcClass,{
2009 "@type": 'koral:docGroup',
2010 'operation' : 'operation:and',
2011 'operands' : [
Akron712733a2018-04-05 18:17:47 +02002012 {
2013 "@type": 'koral:doc',
2014 "key": 'pubDate',
2015 "match": 'match:eq',
2016 "value": '2014-12-05',
2017 "type": 'type:date'
2018 },
2019 {
2020 "@type" : 'koral:docGroup',
2021 'operation' : 'operation:or',
2022 'operands' : [
2023 {
2024 '@type' : 'koral:doc',
2025 'key' : 'title',
2026 'value' : 'Hello World!'
2027 },
2028 {
2029 '@type' : 'koral:doc',
2030 'key' : 'foo',
2031 'value' : 'bar'
2032 }
2033 ]
2034 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00002035 ]
2036 });
2037
2038 it('should add new unspecified doc with "and"', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00002039 var vc = vcClass.create().fromJson(
Akron712733a2018-04-05 18:17:47 +02002040 {
2041 "@type": 'koral:docGroup',
2042 'operation' : 'operation:and',
2043 'operands' : [
2044 {
2045 "@type": 'koral:doc',
2046 "key": 'pubDate',
2047 "match": 'match:eq',
2048 "value": '2014-12-05',
2049 "type": 'type:date'
2050 },
2051 {
2052 "@type" : 'koral:doc',
2053 'key' : 'foo',
2054 'value' : 'bar'
Akronb19803c2018-08-16 16:39:42 +02002055 },
2056 {
2057 "@type" : "koral:docGroupRef",
2058 "ref" : "myCorpus"
Akron712733a2018-04-05 18:17:47 +02002059 }
2060 ]
2061 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00002062 );
2063
Akronb19803c2018-08-16 16:39:42 +02002064 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar" & referTo "myCorpus"');
Nils Diewald7c8ced22015-04-15 19:21:00 +00002065
Akronadab5e52018-08-20 13:50:53 +02002066 var fc = vc.builder().firstChild;
Nils Diewald7c8ced22015-04-15 19:21:00 +00002067 expect(fc.getAttribute('data-operation')).toEqual('and');
Akronb19803c2018-08-16 16:39:42 +02002068 expect(fc.children.length).toEqual(4);
Akron0b489ad2018-02-02 16:49:32 +01002069 expect(fc.lastChild.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +00002070 expect(fc.children[0].getAttribute('class')).toEqual('doc');
2071 expect(fc.children[1].getAttribute('class')).toEqual('doc');
Akronb19803c2018-08-16 16:39:42 +02002072 expect(fc.children[2].getAttribute('class')).toEqual('doc groupref');
Nils Diewald7c8ced22015-04-15 19:21:00 +00002073
2074 // add with 'and' in the middle
2075 _andOn(vc.root().getOperand(0));
Akronb19803c2018-08-16 16:39:42 +02002076 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar" & referTo "myCorpus"');
Nils Diewald7c8ced22015-04-15 19:21:00 +00002077
Akronadab5e52018-08-20 13:50:53 +02002078 fc = vc.builder().firstChild;
Nils Diewald7c8ced22015-04-15 19:21:00 +00002079 expect(fc.getAttribute('data-operation')).toEqual('and');
Akronb19803c2018-08-16 16:39:42 +02002080 expect(fc.children.length).toEqual(5);
Akron0b489ad2018-02-02 16:49:32 +01002081 expect(fc.lastChild.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +00002082
2083 expect(fc.children[0].getAttribute('class')).toEqual('doc');
2084 expect(fc.children[1].getAttribute('class')).toEqual('doc unspecified');
2085 expect(fc.children[2].getAttribute('class')).toEqual('doc');
Akronb19803c2018-08-16 16:39:42 +02002086 expect(fc.children[3].getAttribute('class')).toEqual('doc groupref');
2087 expect(fc.children[4].classList.contains('button-group')).toBeTruthy();
2088 expect(fc.children.length).toEqual(5);
2089
2090 _andOn(vc.root().getOperand(3));
2091 expect(fc.children[0].getAttribute('class')).toEqual('doc');
2092 expect(fc.children[1].getAttribute('class')).toEqual('doc unspecified');
2093 expect(fc.children[2].getAttribute('class')).toEqual('doc');
2094 expect(fc.children[3].getAttribute('class')).toEqual('doc groupref');
2095 expect(fc.children[4].getAttribute('class')).toEqual('doc unspecified');
2096 expect(fc.children[5].classList.contains('button-group')).toBeTruthy();
2097 expect(fc.children.length).toEqual(6);
2098
Nils Diewald7c8ced22015-04-15 19:21:00 +00002099 });
2100
Akronb19803c2018-08-16 16:39:42 +02002101
Nils Diewald7c8ced22015-04-15 19:21:00 +00002102 it('should add new unspecified doc with "or"', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00002103 var vc = vcClass.create().fromJson(
Akron712733a2018-04-05 18:17:47 +02002104 {
2105 "@type": 'koral:docGroup',
2106 'operation' : 'operation:and',
2107 'operands' : [
2108 {
2109 "@type": 'koral:doc',
2110 "key": 'pubDate',
2111 "match": 'match:eq',
2112 "value": '2014-12-05',
2113 "type": 'type:date'
2114 },
2115 {
2116 "@type" : 'koral:doc',
2117 'key' : 'foo',
2118 'value' : 'bar'
Akronb19803c2018-08-16 16:39:42 +02002119 },
2120 {
2121 "@type" : "koral:docGroupRef",
2122 "ref" : "myCorpus"
Akron712733a2018-04-05 18:17:47 +02002123 }
2124 ]
2125 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00002126 );
2127
Akronb19803c2018-08-16 16:39:42 +02002128 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar" & referTo "myCorpus"');
Nils Diewald7c8ced22015-04-15 19:21:00 +00002129
Akronadab5e52018-08-20 13:50:53 +02002130 var fc = vc.builder().firstChild;
Akronb19803c2018-08-16 16:39:42 +02002131 expect(fc.children.length).toEqual(4);
Akron0b489ad2018-02-02 16:49:32 +01002132 expect(fc.lastChild.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +00002133 expect(fc.children[0].getAttribute('class')).toEqual('doc');
2134 expect(fc.children[1].getAttribute('class')).toEqual('doc');
Akronb19803c2018-08-16 16:39:42 +02002135 expect(fc.children[2].getAttribute('class')).toEqual('doc groupref');
Nils Diewald7c8ced22015-04-15 19:21:00 +00002136
2137 // add with 'or' in the middle
2138 _orOn(vc.root().getOperand(0));
Akronb19803c2018-08-16 16:39:42 +02002139 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar" & referTo "myCorpus"');
Akronadab5e52018-08-20 13:50:53 +02002140 fc = vc.builder().firstChild;
Nils Diewald7c8ced22015-04-15 19:21:00 +00002141
2142 expect(fc.getAttribute('data-operation')).toEqual('and');
Akronb19803c2018-08-16 16:39:42 +02002143 expect(fc.children.length).toEqual(4);
Nils Diewald7c8ced22015-04-15 19:21:00 +00002144 expect(fc.children[0].getAttribute('class')).toEqual('docGroup');
2145 expect(fc.children[0].getAttribute('data-operation')).toEqual('or');
2146 expect(fc.children[1].getAttribute('class')).toEqual('doc');
Akronb19803c2018-08-16 16:39:42 +02002147 expect(fc.children[2].getAttribute('class')).toEqual('doc groupref');
2148 expect(fc.children[3].getAttribute('class')).toEqual('operators button-group');
Akron0b489ad2018-02-02 16:49:32 +01002149 expect(fc.lastChild.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +00002150
Akronadab5e52018-08-20 13:50:53 +02002151 fc = vc.builder().firstChild.firstChild;
Nils Diewald7c8ced22015-04-15 19:21:00 +00002152 expect(fc.children.length).toEqual(3);
2153 expect(fc.children[0].getAttribute('class')).toEqual('doc');
2154 expect(fc.children[1].getAttribute('class')).toEqual('doc unspecified');
Akron0b489ad2018-02-02 16:49:32 +01002155 expect(fc.children[2].getAttribute('class')).toEqual('operators button-group');
2156 expect(fc.lastChild.getAttribute('class')).toEqual('operators button-group');
Akronb19803c2018-08-16 16:39:42 +02002157
2158 _orOn(vc.root().getOperand(2));
Akronadab5e52018-08-20 13:50:53 +02002159 fc = vc.builder().firstChild;
Akronb19803c2018-08-16 16:39:42 +02002160 expect(fc.children.length).toEqual(4);
2161
2162 expect(fc.children[0].getAttribute('class')).toEqual('docGroup');
2163 expect(fc.children[1].getAttribute('class')).toEqual('doc');
2164 expect(fc.children[2].getAttribute('class')).toEqual('docGroup');
2165 expect(fc.children[3].getAttribute('class')).toEqual('operators button-group');
2166
Akronadab5e52018-08-20 13:50:53 +02002167 fc = vc.builder().firstChild.children[2];
Akronb19803c2018-08-16 16:39:42 +02002168 expect(fc.children[0].getAttribute('class')).toEqual('doc groupref');
2169 expect(fc.children[1].getAttribute('class')).toEqual('doc unspecified');
2170 expect(fc.children[2].getAttribute('class')).toEqual('operators button-group');
2171 expect(fc.lastChild.getAttribute('class')).toEqual('operators button-group');
2172
Nils Diewald7c8ced22015-04-15 19:21:00 +00002173 });
2174
2175 it('should add new unspecified doc with "and" before group', function () {
2176 var vc = demoFactory.create();
2177
2178 // Wrap with direct element access
2179 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02002180 '(Titel = "Baum" & ' +
2181 'Veröffentlichungsort = "hihi" & ' +
2182 '(Titel = "Baum" | ' +
2183 'Veröffentlichungsort = "hihi")) | ' +
2184 'Untertitel ~ "huhu"'
Nils Diewald7c8ced22015-04-15 19:21:00 +00002185 );
2186
2187 expect(vc.root().getOperand(0).ldType()).toEqual('docGroup');
2188 expect(vc.root().getOperand(0).operation()).toEqual('and');
2189 expect(vc.root().getOperand(0).operands().length).toEqual(3);
2190
2191 // Add unspecified on the second doc
2192 var secDoc = vc.root().getOperand(0).getOperand(1);
2193 expect(secDoc.value()).toEqual('hihi');
2194
2195 // Add
2196 _andOn(secDoc);
2197
2198 var fo = vc.root().getOperand(0);
2199
2200 expect(fo.ldType()).toEqual('docGroup');
2201 expect(fo.operation()).toEqual('and');
2202 expect(fo.operands().length).toEqual(4);
2203
2204 expect(fo.getOperand(0).ldType()).toEqual('doc');
2205 expect(fo.getOperand(1).ldType()).toEqual('doc');
2206 expect(fo.getOperand(2).ldType()).toEqual('non');
2207 expect(fo.getOperand(3).ldType()).toEqual('docGroup');
2208 });
2209
2210
2211 it('should remove a doc with an unspecified doc in a nested group', function () {
2212 var vc = demoFactory.create();
2213
2214 // Wrap with direct element access
2215 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02002216 '(Titel = "Baum" & Veröffentlichungsort = "hihi" & (Titel = "Baum" | Veröffentlichungsort = "hihi")) | Untertitel ~ "huhu"'
Nils Diewald7c8ced22015-04-15 19:21:00 +00002217 );
2218
2219 var fo = vc.root().getOperand(0).getOperand(0);
2220 expect(fo.key()).toEqual('Titel');
2221 expect(fo.value()).toEqual('Baum');
2222
2223 // Add unspecified on the root group
2224 _orOn(fo);
2225
2226 fo = vc.root().getOperand(0).getOperand(0);
2227
2228 expect(fo.operation()).toEqual('or');
2229 expect(fo.getOperand(0).ldType()).toEqual('doc');
2230 expect(fo.getOperand(1).ldType()).toEqual('non');
2231
2232 // Delete document
2233 _delOn(fo.getOperand(0));
2234
2235 // The operand is now non
2236 expect(vc.root().getOperand(0).getOperand(0).ldType()).toEqual('non');
2237 expect(vc.root().getOperand(0).getOperand(1).ldType()).toEqual('doc');
2238 expect(vc.root().getOperand(0).getOperand(2).ldType()).toEqual('docGroup');
2239 });
2240
2241
Akron712733a2018-04-05 18:17:47 +02002242 it('should remove an unspecified doc with a doc in a nested group', function () {
Nils Diewald7c8ced22015-04-15 19:21:00 +00002243 var vc = demoFactory.create();
2244
2245 // Wrap with direct element access
2246 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02002247 '(Titel = "Baum" & ' +
2248 'Veröffentlichungsort = "hihi" & ' +
2249 '(Titel = "Baum" ' +
2250 '| Veröffentlichungsort = "hihi")) | ' +
2251 'Untertitel ~ "huhu"'
Nils Diewald7c8ced22015-04-15 19:21:00 +00002252 );
2253
2254 var fo = vc.root().getOperand(0).getOperand(0);
2255 expect(fo.key()).toEqual('Titel');
2256 expect(fo.value()).toEqual('Baum');
2257
2258 // Add unspecified on the root group
2259 _orOn(fo);
2260
2261 fo = vc.root().getOperand(0).getOperand(0);
2262
2263 expect(fo.operation()).toEqual('or');
2264 expect(fo.getOperand(0).ldType()).toEqual('doc');
2265 expect(fo.getOperand(1).ldType()).toEqual('non');
2266
2267 // Delete unspecified doc
2268 _delOn(fo.getOperand(1));
2269
2270 // The operand is now non
2271 fo = vc.root().getOperand(0);
2272 expect(fo.getOperand(0).ldType()).toEqual('doc');
2273 expect(fo.getOperand(0).key()).toEqual('Titel');
2274 expect(fo.getOperand(0).value()).toEqual('Baum');
2275 expect(fo.getOperand(1).ldType()).toEqual('doc');
2276 expect(fo.getOperand(2).ldType()).toEqual('docGroup');
2277 });
2278
2279
2280 it('should add on parent group (case "and")', function () {
2281 var vc = complexVCFactory.create();
2282
2283 // Wrap with direct element access
2284 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02002285 'pubDate in 2014-12-05 & (title = "Hello World!" | foo = "bar")'
Nils Diewald7c8ced22015-04-15 19:21:00 +00002286 );
2287
2288 expect(vc.root().operands().length).toEqual(2);
2289
2290 // Add unspecified on the root group
2291 _andOn(vc.root().getOperand(1));
2292 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02002293 'pubDate in 2014-12-05 & (title = "Hello World!" | foo = "bar")'
Nils Diewald7c8ced22015-04-15 19:21:00 +00002294 );
2295
2296 expect(vc.root().ldType()).toEqual('docGroup');
2297 expect(vc.root().operands().length).toEqual(3);
2298 expect(vc.root().getOperand(0).ldType()).toEqual('doc');
2299 expect(vc.root().getOperand(1).ldType()).toEqual('docGroup');
2300 expect(vc.root().getOperand(1).operation()).toEqual('or');
2301 expect(vc.root().getOperand(2).ldType()).toEqual('non');
2302
2303 // Add another unspecified on the root group
2304 _andOn(vc.root().getOperand(1));
2305
2306 expect(vc.root().operands().length).toEqual(4);
2307 expect(vc.root().getOperand(0).ldType()).toEqual('doc');
2308 expect(vc.root().getOperand(1).ldType()).toEqual('docGroup');
2309 expect(vc.root().getOperand(2).ldType()).toEqual('non');
2310 expect(vc.root().getOperand(3).ldType()).toEqual('non');
2311
2312 // Add another unspecified after the first doc
2313 _andOn(vc.root().getOperand(0));
2314
2315 expect(vc.root().operands().length).toEqual(5);
2316 expect(vc.root().getOperand(0).ldType()).toEqual('doc');
2317 expect(vc.root().getOperand(1).ldType()).toEqual('non');
2318 expect(vc.root().getOperand(2).ldType()).toEqual('docGroup');
2319 expect(vc.root().getOperand(3).ldType()).toEqual('non');
2320 expect(vc.root().getOperand(4).ldType()).toEqual('non');
2321 });
2322
2323 it('should wrap on root', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00002324 var vc = vcClass.create().fromJson(
Akron712733a2018-04-05 18:17:47 +02002325 {
2326 "@type": 'koral:docGroup',
2327 'operation' : 'operation:and',
2328 'operands' : [
2329 {
2330 "@type": 'koral:doc',
2331 "key": 'pubDate',
2332 "match": 'match:eq',
2333 "value": '2014-12-05',
2334 "type": 'type:date'
2335 },
2336 {
2337 "@type" : 'koral:doc',
2338 'key' : 'foo',
2339 'value' : 'bar'
2340 }
2341 ]
2342 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00002343 );
2344
2345 // Wrap on root
2346 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar"');
2347 expect(vc.root().ldType()).toEqual('docGroup');
2348 expect(vc.root().operation()).toEqual('and');
2349 _orOn(vc.root());
2350 expect(vc.root().ldType()).toEqual('docGroup');
2351 expect(vc.root().operation()).toEqual('or');
2352
2353 expect(vc.root().getOperand(0).ldType()).toEqual('docGroup');
2354 expect(vc.root().getOperand(0).operation()).toEqual('and');
2355 });
2356
2357 it('should add on root (case "and")', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00002358 var vc = vcClass.create().fromJson(
Akron712733a2018-04-05 18:17:47 +02002359 {
2360 "@type": 'koral:doc',
2361 "key": 'pubDate',
2362 "match": 'match:eq',
2363 "value": '2014-12-05',
2364 "type": 'type:date'
2365 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00002366 );
2367
2368 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05');
2369 expect(vc.root().ldType()).toEqual('doc');
2370 expect(vc.root().key()).toEqual('pubDate');
2371 expect(vc.root().value()).toEqual('2014-12-05');
2372
2373 // Wrap on root
2374 _andOn(vc.root());
2375 expect(vc.root().ldType()).toEqual('docGroup');
2376 expect(vc.root().operation()).toEqual('and');
2377 });
2378
2379 it('should add on root (case "or")', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00002380 var vc = vcClass.create().fromJson(
Akron712733a2018-04-05 18:17:47 +02002381 {
2382 "@type": 'koral:doc',
2383 "key": 'pubDate',
2384 "match": 'match:eq',
2385 "value": '2014-12-05',
2386 "type": 'type:date'
2387 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00002388 );
2389
2390 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05');
2391 expect(vc.root().key()).toEqual('pubDate');
2392 expect(vc.root().value()).toEqual('2014-12-05');
2393
2394 // Wrap on root
2395 _orOn(vc.root());
2396 expect(vc.root().ldType()).toEqual('docGroup');
2397 expect(vc.root().operation()).toEqual('or');
2398 });
2399
2400 it('should support multiple sub groups per group', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00002401 var vc = vcClass.create().fromJson(
Akron712733a2018-04-05 18:17:47 +02002402 {
2403 "@type": 'koral:docGroup',
2404 'operation' : 'operation:or',
2405 'operands' : [
2406 {
2407 "@type": 'koral:docGroup',
2408 'operation' : 'operation:and',
2409 'operands' : [
2410 {
2411 "@type": 'koral:doc',
2412 "key": 'title',
2413 "value": 't1',
2414 },
2415 {
2416 "@type" : 'koral:doc',
2417 'key' : 'title',
2418 'value' : 't2'
2419 }
2420 ]
2421 },
2422 {
2423 "@type": 'koral:docGroup',
2424 'operation' : 'operation:and',
2425 'operands' : [
2426 {
2427 "@type": 'koral:doc',
2428 "key": 'title',
2429 "value": 't3',
2430 },
2431 {
2432 "@type" : 'koral:doc',
2433 'key' : 'title',
2434 'value' : 't4'
2435 }
2436 ]
2437 }
2438 ]
2439 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00002440 );
2441 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02002442 '(title = "t1" & title = "t2") | ' +
2443 '(title = "t3" & title = "t4")'
Nils Diewald7c8ced22015-04-15 19:21:00 +00002444 );
2445 expect(vc.root().operation()).toEqual('or');
2446 expect(vc.root().getOperand(0).toQuery()).toEqual('title = "t1" & title = "t2"');
2447 expect(vc.root().getOperand(1).toQuery()).toEqual('title = "t3" & title = "t4"');
2448
2449 _andOn(vc.root());
2450
2451 expect(vc.root().operation()).toEqual('and');
2452 expect(vc.root().getOperand(0).ldType()).toEqual('docGroup');
2453 expect(vc.root().getOperand(1).ldType()).toEqual('non');
2454 });
2455 });
2456
Nils Diewald6283d692015-04-23 20:32:53 +00002457
2458 describe('KorAP.Rewrite', function () {
Nils Diewald7c8ced22015-04-15 19:21:00 +00002459 it('should be initializable', function () {
2460 var rewrite = rewriteClass.create({
Akron712733a2018-04-05 18:17:47 +02002461 "@type" : "koral:rewrite",
2462 "operation" : "operation:modification",
2463 "src" : "querySerializer",
2464 "scope" : "tree"
Nils Diewald86dad5b2015-01-28 15:09:07 +00002465 });
Nils Diewald7c8ced22015-04-15 19:21:00 +00002466 expect(rewrite.toString()).toEqual('Modification of "tree" by "querySerializer"');
2467 });
Nils Diewald86dad5b2015-01-28 15:09:07 +00002468
Nils Diewald7c8ced22015-04-15 19:21:00 +00002469 it('should be deserialized by docs', function () {
2470 var doc = docClass.create(
Akron712733a2018-04-05 18:17:47 +02002471 undefined,
2472 {
2473 "@type":"koral:doc",
2474 "key":"Titel",
2475 "value":"Baum",
2476 "match":"match:eq"
2477 });
Nils Diewald7c8ced22015-04-15 19:21:00 +00002478
2479 expect(doc.element().classList.contains('doc')).toBeTruthy();
2480 expect(doc.element().classList.contains('rewritten')).toBe(false);
2481
2482 doc = docClass.create(
Akron712733a2018-04-05 18:17:47 +02002483 undefined,
2484 {
2485 "@type":"koral:doc",
2486 "key":"Titel",
2487 "value":"Baum",
2488 "match":"match:eq",
2489 "rewrites" : [
2490 {
2491 "@type" : "koral:rewrite",
2492 "operation" : "operation:modification",
2493 "src" : "querySerializer",
2494 "scope" : "tree"
2495 }
2496 ]
2497 });
Nils Diewald7c8ced22015-04-15 19:21:00 +00002498
2499 expect(doc.element().classList.contains('doc')).toBeTruthy();
2500 expect(doc.element().classList.contains('rewritten')).toBeTruthy();
2501 });
Nils Diewald6283d692015-04-23 20:32:53 +00002502
Akron76c3dd62018-05-29 20:58:27 +02002503 it('should be described in a title attribute', function () {
2504
2505 doc = docClass.create(
2506 undefined,
2507 {
2508 "@type":"koral:doc",
2509 "key":"Titel",
2510 "value":"Baum",
2511 "match":"match:eq",
2512 "rewrites" : [
2513 {
2514 "@type" : "koral:rewrite",
2515 "operation" : "operation:modification",
2516 "src" : "querySerializer",
2517 "scope" : "tree"
2518 },
2519 {
2520 "@type" : "koral:rewrite",
2521 "operation" : "operation:injection",
2522 "src" : "me"
2523 }
2524 ]
2525 });
2526
2527 expect(doc.element().classList.contains('doc')).toBeTruthy();
2528 expect(doc.element().classList.contains('rewritten')).toBeTruthy();
2529 expect(doc.element().lastChild.getAttribute("title")).toEqual("querySerializer: tree (modification)\nme (injection)");
2530 });
2531
2532
Nils Diewald6283d692015-04-23 20:32:53 +00002533 xit('should be deserialized by docGroups', function () {
2534 var docGroup = docGroupClass.create(
Akron712733a2018-04-05 18:17:47 +02002535 undefined,
2536 {
2537 "@type" : "koral:docGroup",
2538 "operation" : "operation:or",
2539 "operands" : [
2540 {
2541 "@type" : "doc",
2542 "key" : "pubDate",
2543 "type" : "type:date",
2544 "value" : "2014-12-05"
2545 },
2546 {
2547 "@type" : "doc",
2548 "key" : "pubDate",
2549 "type" : "type:date",
2550 "value" : "2014-12-06"
2551 }
2552 ],
2553 "rewrites" : [
2554 {
2555 "@type" : "koral:rewrite",
2556 "operation" : "operation:modification",
2557 "src" : "querySerializer",
2558 "scope" : "tree"
2559 }
2560 ]
2561 }
Nils Diewald6283d692015-04-23 20:32:53 +00002562 );
2563
2564 expect(doc.element().classList.contains('docgroup')).toBeTruthy();
2565 expect(doc.element().classList.contains('rewritten')).toBe(false);
2566 });
Nils Diewald86dad5b2015-01-28 15:09:07 +00002567 });
Nils Diewaldf0c4f112015-05-05 12:56:59 +00002568
2569 describe('KorAP.stringValue', function () {
2570 it('should be initializable', function () {
2571 var sv = stringValClass.create();
2572 expect(sv.regex()).toBe(false);
2573 expect(sv.value()).toBe('');
Nils Diewaldc4c4b832015-05-05 16:00:08 +00002574
2575 sv = stringValClass.create('Baum');
2576 expect(sv.regex()).toBe(false);
2577 expect(sv.value()).toBe('Baum');
2578
2579 sv = stringValClass.create('Baum', false);
2580 expect(sv.regex()).toBe(false);
2581 expect(sv.value()).toBe('Baum');
2582
2583 sv = stringValClass.create('Baum', true);
2584 expect(sv.regex()).toBe(true);
2585 expect(sv.value()).toBe('Baum');
2586 });
2587
2588 it('should be modifiable', function () {
2589 var sv = stringValClass.create();
2590 expect(sv.regex()).toBe(false);
2591 expect(sv.value()).toBe('');
2592
2593 expect(sv.value('Baum')).toBe('Baum');
2594 expect(sv.value()).toBe('Baum');
2595
2596 expect(sv.regex(true)).toBe(true);
2597 expect(sv.regex()).toBe(true);
2598 });
2599
2600 it('should have a toggleble regex value', function () {
2601 var sv = stringValClass.create();
Nils Diewald7991a3f2015-05-19 14:12:37 +00002602
2603 expect(sv.element().firstChild.value).toBe('');
2604 sv.element().firstChild.value = 'der'
2605 expect(sv.element().firstChild.value).toBe('der');
2606
Nils Diewaldc4c4b832015-05-05 16:00:08 +00002607 expect(sv.regex()).toBe(false);
2608
2609 sv.toggleRegex();
Nils Diewald7991a3f2015-05-19 14:12:37 +00002610 expect(sv.element().firstChild.value).toBe('der');
Nils Diewaldc4c4b832015-05-05 16:00:08 +00002611 expect(sv.regex()).toBe(true);
Nils Diewald7991a3f2015-05-19 14:12:37 +00002612 sv.element().firstChild.value = 'derbe'
Nils Diewaldc4c4b832015-05-05 16:00:08 +00002613
2614 sv.toggleRegex();
2615 expect(sv.regex()).toBe(false);
Nils Diewald7991a3f2015-05-19 14:12:37 +00002616 expect(sv.element().firstChild.value).toBe('derbe');
Nils Diewaldc4c4b832015-05-05 16:00:08 +00002617 });
2618
2619 it('should have an element', function () {
2620 var sv = stringValClass.create('der');
2621 expect(sv.element().nodeName).toBe('DIV');
2622 expect(sv.element().firstChild.nodeName).toBe('INPUT');
2623 expect(sv.element().firstChild.value).toBe('der');
2624 });
2625
2626 it('should have a classed element', function () {
2627 var sv = stringValClass.create();
Nils Diewaldc4c4b832015-05-05 16:00:08 +00002628 expect(sv.element().classList.contains('regex')).toBe(false);
2629 expect(sv.regex()).toBe(false);
2630 sv.toggleRegex();
2631 expect(sv.element().classList.contains('regex')).toBe(true);
2632 });
2633
2634 it('should be storable', function () {
2635 var sv = stringValClass.create();
2636 var count = 1;
2637 sv.store = function (value, regex) {
Akron712733a2018-04-05 18:17:47 +02002638 expect(regex).toBe(true);
2639 expect(value).toBe('tree');
Nils Diewaldc4c4b832015-05-05 16:00:08 +00002640 };
2641 sv.regex(true);
2642 sv.value('tree');
2643 sv.element().lastChild.click();
Nils Diewaldf0c4f112015-05-05 12:56:59 +00002644 });
Akron712733a2018-04-05 18:17:47 +02002645
Akronb19803c2018-08-16 16:39:42 +02002646 it('should have a disableoption for regex', function () {
2647 var sv = stringValClass.create(undefined, undefined, true);
2648 var svE = sv.element();
2649 expect(svE.children.length).toEqual(2);
2650
2651 sv = stringValClass.create(undefined, undefined, false);
2652 svE = sv.element();
2653 expect(svE.children.length).toEqual(1);
2654 });
2655
Nils Diewaldf0c4f112015-05-05 12:56:59 +00002656 });
Akrone4961b12017-05-10 21:04:46 +02002657
Akron712733a2018-04-05 18:17:47 +02002658 describe('KorAP.VC.Menu', function () {
Akrone65a88a2018-04-05 19:14:20 +02002659
2660 var vc;
2661
Akron712733a2018-04-05 18:17:47 +02002662 it('should be initializable', function () {
2663
Akrone65a88a2018-04-05 19:14:20 +02002664 vc = vcClass.create([
Akron712733a2018-04-05 18:17:47 +02002665 ['a', 'text'],
2666 ['b', 'string'],
2667 ['c', 'date']
2668 ]).fromJson();
Akronadab5e52018-08-20 13:50:53 +02002669 expect(vc.builder().firstChild.classList.contains('unspecified')).toBeTruthy();
2670 expect(vc.builder().firstChild.firstChild.tagName).toEqual('SPAN');
Akron712733a2018-04-05 18:17:47 +02002671
2672 // Click on unspecified
Akronadab5e52018-08-20 13:50:53 +02002673 vc.builder().firstChild.firstChild.click();
2674 expect(vc.builder().firstChild.firstChild.tagName).toEqual('UL');
Akron712733a2018-04-05 18:17:47 +02002675
Akronadab5e52018-08-20 13:50:53 +02002676 var list = vc.builder().firstChild.firstChild;
Akron3ad46942018-08-22 16:47:14 +02002677 expect(list.getElementsByTagName("LI")[0].innerText).toEqual('referTo');
2678 expect(list.getElementsByTagName("LI")[1].innerText).toEqual('a');
2679 expect(list.getElementsByTagName("LI")[2].innerText).toEqual('b');
2680 expect(list.getElementsByTagName("LI")[3].innerText).toEqual('c');
Akron712733a2018-04-05 18:17:47 +02002681
2682 vc = vcClass.create([
2683 ['d', 'text'],
2684 ['e', 'string'],
2685 ['f', 'date']
2686 ]).fromJson();
Akronadab5e52018-08-20 13:50:53 +02002687 expect(vc.builder().firstChild.classList.contains('unspecified')).toBeTruthy();
2688 expect(vc.builder().firstChild.firstChild.tagName).toEqual('SPAN');
Akron712733a2018-04-05 18:17:47 +02002689
2690 // Click on unspecified
Akronadab5e52018-08-20 13:50:53 +02002691 vc.builder().firstChild.firstChild.click();
2692 expect(vc.builder().firstChild.firstChild.tagName).toEqual('UL');
Akron712733a2018-04-05 18:17:47 +02002693
Akronadab5e52018-08-20 13:50:53 +02002694 list = vc.builder().firstChild.firstChild;
Akron3ad46942018-08-22 16:47:14 +02002695 expect(list.getElementsByTagName("LI")[0].innerText).toEqual('referTo');
2696 expect(list.getElementsByTagName("LI")[1].innerText).toEqual('d');
2697 expect(list.getElementsByTagName("LI")[2].innerText).toEqual('e');
2698 expect(list.getElementsByTagName("LI")[3].innerText).toEqual('f');
Akron31d89942018-04-06 16:44:51 +02002699 // blur
2700 document.body.click();
Akron712733a2018-04-05 18:17:47 +02002701 });
Akrone65a88a2018-04-05 19:14:20 +02002702
2703 // Reinitialize to make tests stable
2704 vc = vcClass.create([
2705 ['d', 'text'],
2706 ['e', 'string'],
2707 ['f', 'date']
2708 ]).fromJson();
2709
2710 it('should be clickable on key', function () {
Akron31d89942018-04-06 16:44:51 +02002711 // Click on unspecified
Akronadab5e52018-08-20 13:50:53 +02002712 vc.builder().firstChild.firstChild.click();
Akrone65a88a2018-04-05 19:14:20 +02002713 // Click on "d"
Akronadab5e52018-08-20 13:50:53 +02002714 vc.builder().firstChild.firstChild.getElementsByTagName("LI")[1].click();
2715 expect(vc.builder().firstChild.firstChild.tagName).toEqual('SPAN');
2716 expect(vc.builder().firstChild.firstChild.innerText).toEqual('d');
2717 expect(vc.builder().firstChild.children[1].innerText).toEqual('eq');
2718 expect(vc.builder().firstChild.children[1].getAttribute('data-type')).toEqual('text');
Akron31d89942018-04-06 16:44:51 +02002719 // blur
2720 document.body.click();
Akrone65a88a2018-04-05 19:14:20 +02002721 });
2722
Akron31d89942018-04-06 16:44:51 +02002723 it('should be clickable on operation for text', function () {
2724 // Click on "d" (or unspecified)
Akronadab5e52018-08-20 13:50:53 +02002725 vc.builder().firstChild.firstChild.click();
Akron31d89942018-04-06 16:44:51 +02002726
2727 // Choose "d"
Akronadab5e52018-08-20 13:50:53 +02002728 vc.builder().firstChild.firstChild.getElementsByTagName("LI")[1].click();
Akron31d89942018-04-06 16:44:51 +02002729
2730 // Click on matchop
Akronadab5e52018-08-20 13:50:53 +02002731 vc.builder().firstChild.children[1].click();
Akron31d89942018-04-06 16:44:51 +02002732
Akronadab5e52018-08-20 13:50:53 +02002733 expect(vc.builder().firstChild.children[1].tagName).toEqual('UL');
Akron31d89942018-04-06 16:44:51 +02002734
Akronadab5e52018-08-20 13:50:53 +02002735 var ul = vc.builder().firstChild.children[1];
Akrone65a88a2018-04-05 19:14:20 +02002736 expect(ul.getElementsByTagName('li')[0].innerText).toEqual("eq");
2737 expect(ul.getElementsByTagName('li')[1].innerText).toEqual("ne");
2738 expect(ul.getElementsByTagName('li')[2].innerText).toEqual("contains");
2739 expect(ul.getElementsByTagName('li')[3].innerText).toEqual("containsnot");
2740 expect(ul.getElementsByTagName('li')[4]).toBeUndefined();
Akron31d89942018-04-06 16:44:51 +02002741
2742 // Choose "contains"
2743 ul.getElementsByTagName('li')[2].click();
Akronadab5e52018-08-20 13:50:53 +02002744 expect(vc.builder().firstChild.children[1].tagName).toEqual("SPAN");
2745 expect(vc.builder().firstChild.children[1].innerText).toEqual("contains");
Akron31d89942018-04-06 16:44:51 +02002746 // blur
2747 document.body.click();
Akrone65a88a2018-04-05 19:14:20 +02002748 })
Akron31d89942018-04-06 16:44:51 +02002749
2750 it('should be clickable on operation for string', function () {
2751 // Click on "d" (or unspecified)
Akronadab5e52018-08-20 13:50:53 +02002752 vc.builder().firstChild.firstChild.click();
Akron31d89942018-04-06 16:44:51 +02002753
2754 // Choose "e"
Akronadab5e52018-08-20 13:50:53 +02002755 vc.builder().firstChild.firstChild.getElementsByTagName("LI")[2].click();
2756
Akron31d89942018-04-06 16:44:51 +02002757 // As a consequence the matchoperator may no longer
2758 // be valid and needs to be re-evaluated
Akronadab5e52018-08-20 13:50:53 +02002759 var fc = vc.builder().firstChild;
Akron31d89942018-04-06 16:44:51 +02002760 expect(fc.firstChild.tagName).toEqual('SPAN');
2761 expect(fc.firstChild.innerText).toEqual('e');
2762 expect(fc.children[1].innerText).toEqual('eq');
2763 expect(fc.children[1].getAttribute('data-type')).toEqual('string');
2764
Akronadab5e52018-08-20 13:50:53 +02002765 vc.builder().firstChild.children[1].click();
Akron31d89942018-04-06 16:44:51 +02002766
Akronadab5e52018-08-20 13:50:53 +02002767 expect(vc.builder().firstChild.children[1].tagName).toEqual('UL');
Akron31d89942018-04-06 16:44:51 +02002768
Akronadab5e52018-08-20 13:50:53 +02002769 var ul = vc.builder().firstChild.children[1];
Akron31d89942018-04-06 16:44:51 +02002770 expect(ul.getElementsByTagName('li')[0].innerText).toEqual("eq");
2771 expect(ul.getElementsByTagName('li')[1].innerText).toEqual("ne");
2772 expect(ul.getElementsByTagName('li')[2]).toBeUndefined();
2773
2774 // Choose "ne"
2775 ul.getElementsByTagName('li')[1].click();
Akronadab5e52018-08-20 13:50:53 +02002776 expect(vc.builder().firstChild.children[1].tagName).toEqual("SPAN");
2777 expect(vc.builder().firstChild.children[1].innerText).toEqual("ne");
Akron8db5e3a2018-05-28 19:25:26 +02002778
2779 // Click on text
Akronebc96662018-08-29 17:36:20 +02002780 expect(vc.builder().firstChild.children[2].innerText).toEqual(KorAP.Locale.EMPTY);
2781 expect(vc.builder().firstChild.children[2].classList.contains('unspecified')).toEqual(true);
Akronadab5e52018-08-20 13:50:53 +02002782 vc.builder().firstChild.children[2].click();
Akron8db5e3a2018-05-28 19:25:26 +02002783
2784 // Blur text element
Akronadab5e52018-08-20 13:50:53 +02002785 expect(vc.builder().firstChild.children[2].firstChild.value).toEqual('');
Akron8db5e3a2018-05-28 19:25:26 +02002786
Akron31d89942018-04-06 16:44:51 +02002787 // blur
2788 document.body.click();
2789 });
2790
2791 it('should be clickable on operation for date', function () {
2792
2793 // Replay matchop check - so it's guaranteed that "ne" is chosen
2794 // Click on "e" (or unspecified)
Akronadab5e52018-08-20 13:50:53 +02002795 vc.builder().firstChild.firstChild.click();
Akron31d89942018-04-06 16:44:51 +02002796 // Rechoose "e"
Akronadab5e52018-08-20 13:50:53 +02002797 vc.builder().firstChild.firstChild.getElementsByTagName("LI")[1].click();
Akron31d89942018-04-06 16:44:51 +02002798 // Click on matchop
Akronadab5e52018-08-20 13:50:53 +02002799 vc.builder().firstChild.children[1].click();
Akron31d89942018-04-06 16:44:51 +02002800 // Choose "ne"
Akronadab5e52018-08-20 13:50:53 +02002801 vc.builder().firstChild.children[1].getElementsByTagName('li')[1].click();
2802 expect(vc.builder().firstChild.children[1].innerText).toEqual("ne");
Akron31d89942018-04-06 16:44:51 +02002803
2804 // Click on "e"
Akronadab5e52018-08-20 13:50:53 +02002805 vc.builder().firstChild.firstChild.click();
Akron31d89942018-04-06 16:44:51 +02002806 // Choose "f"
Akronadab5e52018-08-20 13:50:53 +02002807 vc.builder().firstChild.firstChild.getElementsByTagName("LI")[3].click();
Akron31d89942018-04-06 16:44:51 +02002808
2809 // The matchoperator should still be "ne" as this is valid for dates as well (now)
Akronadab5e52018-08-20 13:50:53 +02002810 var fc = vc.builder().firstChild;
Akron31d89942018-04-06 16:44:51 +02002811 expect(fc.firstChild.tagName).toEqual('SPAN');
2812 expect(fc.firstChild.innerText).toEqual('f');
2813 expect(fc.children[1].innerText).toEqual('ne');
2814 // blur
2815 document.body.click();
2816 });
Akronddc98a72018-04-06 17:33:52 +02002817
2818
2819 // Check json deserialization
2820 it('should be initializable', function () {
2821 vc = vcClass.create([
2822 ['a', 'text'],
2823 ['b', 'string'],
2824 ['c', 'date']
2825 ]).fromJson({
2826 "@type" : "koral:doc",
2827 "key":"a",
2828 "value":"Baum"
2829 });
2830
Akronadab5e52018-08-20 13:50:53 +02002831 expect(vc.builder().firstChild.children[1].getAttribute('data-type')).toEqual('text');
Akronddc98a72018-04-06 17:33:52 +02002832 });
Akron712733a2018-04-05 18:17:47 +02002833 });
2834
2835
Akrone4961b12017-05-10 21:04:46 +02002836 // Check prefix
2837 describe('KorAP.VC.Prefix', function () {
2838
2839 it('should be initializable', function () {
2840 var p = prefixClass.create();
2841 expect(p.element().classList.contains('pref')).toBeTruthy();
2842 expect(p.isSet()).not.toBeTruthy();
2843 });
2844
2845
2846 it('should be clickable', function () {
2847 var vc = vcClass.create([
Akron712733a2018-04-05 18:17:47 +02002848 ['a', null],
2849 ['b', null],
2850 ['c', null]
2851 ]).fromJson();
Akronadab5e52018-08-20 13:50:53 +02002852 expect(vc.builder().firstChild.classList.contains('unspecified')).toBeTruthy();
Akrone4961b12017-05-10 21:04:46 +02002853
2854 // This should open up the menu
Akronadab5e52018-08-20 13:50:53 +02002855 vc.builder().firstChild.firstChild.click();
2856 expect(vc.builder().firstChild.firstChild.tagName).toEqual('UL');
Akrone4961b12017-05-10 21:04:46 +02002857
2858 KorAP._vcKeyMenu._prefix.clear();
2859 KorAP._vcKeyMenu._prefix.add('x');
2860
Akronadab5e52018-08-20 13:50:53 +02002861 var prefElement = vc.builder().querySelector('span.pref');
Akrone4961b12017-05-10 21:04:46 +02002862 expect(prefElement.innerText).toEqual('x');
2863
2864 // This should add key 'x' to VC
2865 prefElement.click();
2866
Akronadab5e52018-08-20 13:50:53 +02002867 expect(vc.builder().firstChild.classList.contains('doc')).toBeTruthy();
2868 expect(vc.builder().firstChild.firstChild.className).toEqual('key');
2869 expect(vc.builder().firstChild.firstChild.innerText).toEqual('x');
Akrone4961b12017-05-10 21:04:46 +02002870 });
2871 });
Nils Diewald2fe12e12015-03-06 16:47:06 +00002872});