blob: 83ee822c4c0ee79ad07c6b4a24471f7befc1f2db [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',
Akron68d28322018-08-27 15:02:42 +020014 'vc/stringval',
15 'vc/fragment'
Akrondd5c6d32018-08-17 14:12:58 +020016], function (vcClass,
17 docClass,
18 menuClass,
19 prefixClass,
20 docGroupClass,
21 docGroupRefClass,
22 unspecifiedClass,
23 operatorsClass,
24 rewriteClass,
Akron68d28322018-08-27 15:02:42 +020025 stringValClass,
26 fragmentClass) {
Nils Diewald6ac292b2015-01-15 21:33:21 +000027
Akrondd5c6d32018-08-17 14:12:58 +020028 KorAP._vcKeyMenu = undefined;
29
hebastaa0282be2018-12-05 16:58:00 +010030
Nils Diewald7c8ced22015-04-15 19:21:00 +000031 // Helper method for building factories
32 buildFactory = function (objClass, defaults) {
33 return {
34 create : function (overwrites) {
Akron712733a2018-04-05 18:17:47 +020035 var newObj = {};
36 for (var prop in defaults) {
37 newObj[prop] = defaults[prop];
38 };
39 for (var prop in overwrites) {
40 newObj[prop] = overwrites[prop];
41 };
42 return objClass.create().fromJson(newObj);
Nils Diewald7c8ced22015-04-15 19:21:00 +000043 }
Nils Diewald0b6c0412014-12-19 03:55:57 +000044 }
Nils Diewald7c8ced22015-04-15 19:21:00 +000045 };
Nils Diewald0b6c0412014-12-19 03:55:57 +000046
Nils Diewald7c8ced22015-04-15 19:21:00 +000047 function _andOn (obj) {
Akrond141a362018-07-10 18:12:13 +020048 KorAP._and.apply(obj);
Nils Diewald7c8ced22015-04-15 19:21:00 +000049 };
Nils Diewald52f7eb12015-01-12 17:30:04 +000050
Nils Diewald7c8ced22015-04-15 19:21:00 +000051 function _orOn (obj) {
Akrond141a362018-07-10 18:12:13 +020052 KorAP._or.apply(obj);
Nils Diewald7c8ced22015-04-15 19:21:00 +000053 };
Nils Diewald52f7eb12015-01-12 17:30:04 +000054
Nils Diewald7c8ced22015-04-15 19:21:00 +000055 function _delOn (obj) {
Akrond141a362018-07-10 18:12:13 +020056 KorAP._delete.apply(obj);
Nils Diewald7c8ced22015-04-15 19:21:00 +000057 };
Nils Diewald52f7eb12015-01-12 17:30:04 +000058
Nils Diewald7c8ced22015-04-15 19:21:00 +000059 var demoFactory = buildFactory(vcClass, {
60 "@type":"koral:docGroup",
61 "operation":"operation:or",
62 "operands":[
Nils Diewaldf219eb82015-01-07 20:15:42 +000063 {
Akron712733a2018-04-05 18:17:47 +020064 "@type":"koral:docGroup",
65 "operation":"operation:and",
66 "operands":[
Nils Diewald7c8ced22015-04-15 19:21:00 +000067 {
68 "@type":"koral:doc",
69 "key":"Titel",
70 "value":"Baum",
71 "match":"match:eq"
72 },
73 {
74 "@type":"koral:doc",
75 "key":"Veröffentlichungsort",
76 "value":"hihi",
77 "match":"match:eq"
78 },
79 {
80 "@type":"koral:docGroup",
81 "operation":"operation:or",
82 "operands":[
83 {
Akron712733a2018-04-05 18:17:47 +020084 "@type":"koral:doc",
85 "key":"Titel",
86 "value":"Baum",
87 "match":"match:eq"
Nils Diewald7c8ced22015-04-15 19:21:00 +000088 },
89 {
Akron712733a2018-04-05 18:17:47 +020090 "@type":"koral:doc",
91 "key":"Veröffentlichungsort",
92 "value":"hihi",
93 "match":"match:eq"
Nils Diewald7c8ced22015-04-15 19:21:00 +000094 }
95 ]
96 }
Akron712733a2018-04-05 18:17:47 +020097 ]
Nils Diewaldf219eb82015-01-07 20:15:42 +000098 },
99 {
Akron712733a2018-04-05 18:17:47 +0200100 "@type":"koral:doc",
101 "key":"Untertitel",
102 "value":"huhu",
103 "match":"match:contains"
Nils Diewaldf219eb82015-01-07 20:15:42 +0000104 }
105 ]
106 });
107
Akron88d237e2020-10-21 08:05:18 +0200108 describe('KorAP.VC.Doc', function () {
Nils Diewald7c8ced22015-04-15 19:21:00 +0000109 // Create example factories
110 var stringFactory = buildFactory(docClass, {
111 "key" : "author",
112 "value" : "Max Birkendale",
Akron31d89942018-04-06 16:44:51 +0200113 "type" : "type:string",
Nils Diewald7c8ced22015-04-15 19:21:00 +0000114 "@type" : "koral:doc"
115 });
116
117 // Create example factories
Akron712733a2018-04-05 18:17:47 +0200118 var textFactory = buildFactory(docClass, {
119 "key" : "author",
120 "value" : "Birkendale",
Akron31d89942018-04-06 16:44:51 +0200121 "type" : "type:string",
Akron712733a2018-04-05 18:17:47 +0200122 "match" : "match:contains",
123 "@type" : "koral:doc"
124 });
125
126 // Create example factories
Nils Diewald7c8ced22015-04-15 19:21:00 +0000127 var dateFactory = buildFactory(docClass, {
128 "key" : "pubDate",
129 "type" : "type:date",
130 "match" : "match:eq",
131 "value" : "2014-11-05",
132 "@type" : "koral:doc"
133 });
134
135 // Create example factories
136 var regexFactory = buildFactory(docClass, {
137 "key" : "title",
138 "type" : "type:regex",
139 "value" : "[^b]ee.+?",
140 "@type" : "koral:doc"
141 });
142
143 it('should be initializable', function () {
144 var doc = docClass.create();
145 expect(doc.matchop()).toEqual('eq');
146 expect(doc.key()).toBeUndefined();
147 expect(doc.value()).toBeUndefined();
148 expect(doc.type()).toEqual("string");
hebastaa0282be2018-12-05 16:58:00 +0100149 expect(doc.incomplete()).toBeTruthy();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000150 });
151
152 it('should be definable', function () {
153
154 // Empty doc
155 var doc = docClass.create();
156
157 // Set values
158 doc.key("title");
Akron8db5e3a2018-05-28 19:25:26 +0200159
Nils Diewald7c8ced22015-04-15 19:21:00 +0000160 doc.value("Der alte Mann");
161 expect(doc.matchop()).toEqual('eq');
162 expect(doc.key()).toEqual("title");
163 expect(doc.type()).toEqual("string");
164 expect(doc.value()).toEqual("Der alte Mann");
hebastaa0282be2018-12-05 16:58:00 +0100165 expect(doc.incomplete()).toBeFalsy();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000166 });
167
168
169 it('should deserialize JSON-LD string', function () {
170 var doc;
171
172 // String default
173 doc = stringFactory.create();
174 expect(doc.matchop()).toEqual('eq');
175 expect(doc.key()).toEqual("author");
176 expect(doc.type()).toEqual("string");
177 expect(doc.value()).toEqual("Max Birkendale");
hebastaa0282be2018-12-05 16:58:00 +0100178 expect(doc.incomplete()).toBeFalsy();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000179
180 // No valid string
181 doc = stringFactory.create({
Akron712733a2018-04-05 18:17:47 +0200182 value : undefined
Nils Diewald7c8ced22015-04-15 19:21:00 +0000183 });
184 expect(doc).toBeUndefined();
185
186 // No valid string
187 doc = stringFactory.create({
Akron712733a2018-04-05 18:17:47 +0200188 value : { "foo" : "bar" }
Nils Diewald7c8ced22015-04-15 19:21:00 +0000189 });
190 expect(doc).toBeUndefined();
191
192 // Change match type
193 doc = stringFactory.create({
Akron712733a2018-04-05 18:17:47 +0200194 "match" : "match:ne"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000195 });
196
197 expect(doc.matchop()).toEqual('ne');
198 expect(doc.key()).toEqual("author");
199 expect(doc.type()).toEqual("string");
200 expect(doc.value()).toEqual("Max Birkendale");
hebastaa0282be2018-12-05 16:58:00 +0100201 expect(doc.incomplete()).toBeFalsy();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000202
203 // Invalid match type
204 doc = stringFactory.create({
Akron712733a2018-04-05 18:17:47 +0200205 "match" : { "foo" : "bar" }
Nils Diewald7c8ced22015-04-15 19:21:00 +0000206 });
207 expect(doc).toBeUndefined();
208 });
209
210 it('should deserialize JSON-LD regex', function () {
211 var doc = regexFactory.create();
212 expect(doc.key()).toEqual("title");
213 expect(doc.type()).toEqual("regex");
214 expect(doc.value()).toEqual("[^b]ee.+?");
215 expect(doc.matchop()).toEqual('eq');
216
217 // change matcher
218 doc = regexFactory.create({
Akron712733a2018-04-05 18:17:47 +0200219 match : "match:ne"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000220 });
221 expect(doc.matchop()).toEqual('ne');
Akronea4e9052017-07-06 16:12:05 +0200222 expect(doc.rewrites()).toBeUndefined();
hebastaa0282be2018-12-05 16:58:00 +0100223 expect(doc.incomplete()).toBeFalsy();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000224
225 // Invalid matcher
226 doc = regexFactory.create({
Akron712733a2018-04-05 18:17:47 +0200227 match : "match:chook"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000228 });
Akronea4e9052017-07-06 16:12:05 +0200229 expect(doc.matchop()).toEqual('eq');
230 expect(doc.rewrites()).toBeDefined();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000231
232 // Invalid regex
233 doc = regexFactory.create({
Akron712733a2018-04-05 18:17:47 +0200234 value : "[^b"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000235 });
236 expect(doc).toBeUndefined();
237 });
238
239 it('should deserialize JSON-LD date', function () {
240
241 // Normal date
242 doc = dateFactory.create({});
243
244 expect(doc.matchop()).toEqual('eq');
245 expect(doc.key()).toEqual("pubDate");
246 expect(doc.type()).toEqual("date");
247 expect(doc.value()).toEqual("2014-11-05");
248
249 // Short date 1
250 doc = dateFactory.create({
Akron712733a2018-04-05 18:17:47 +0200251 "value" : "2014-11"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000252 });
253
254 expect(doc.matchop()).toEqual('eq');
255 expect(doc.key()).toEqual("pubDate");
256 expect(doc.type()).toEqual("date");
257 expect(doc.value()).toEqual("2014-11");
258
259 // Short date 2
260 doc = dateFactory.create({
Akron712733a2018-04-05 18:17:47 +0200261 "value" : "2014"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000262 });
263
264 expect(doc.matchop()).toEqual('eq');
265 expect(doc.key()).toEqual("pubDate");
266 expect(doc.type()).toEqual("date");
267 expect(doc.value()).toEqual("2014");
268
269 // Invalid date!
270 doc = dateFactory.create({
Akron712733a2018-04-05 18:17:47 +0200271 "value" : "2014-11-050"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000272 });
273 expect(doc).toBeUndefined();
274
275 // Invalid matcher!
276 doc = dateFactory.create({
Akron31d89942018-04-06 16:44:51 +0200277 "match" : "match:contains",
Nils Diewald7c8ced22015-04-15 19:21:00 +0000278 });
Akronea4e9052017-07-06 16:12:05 +0200279 expect(doc).toBeDefined();
280 expect(doc.rewrites()).toBeDefined();
281 expect(doc.matchop()).toEqual('eq');
Nils Diewald7c8ced22015-04-15 19:21:00 +0000282 });
283
284 it('should be serializale to JSON', function () {
285
286 // Empty doc
287 var doc = docClass.create();
288 expect(doc.toJson()).toEqual(jasmine.any(Object));
289
290 // Serialize string
291 doc = stringFactory.create();
292 expect(doc.toJson()).toEqual(jasmine.objectContaining({
Akron712733a2018-04-05 18:17:47 +0200293 "@type" : "koral:doc",
294 "type" : "type:string",
295 "key" : "author",
296 "value" : "Max Birkendale",
297 "match" : "match:eq"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000298 }));
299
300 // Serialize regex
301 doc = regexFactory.create();
302 expect(doc.toJson()).toEqual(jasmine.objectContaining({
Akron712733a2018-04-05 18:17:47 +0200303 "@type" : "koral:doc",
304 "type" : "type:regex",
305 "value" : "[^b]ee.+?",
306 "match" : "match:eq",
307 "key" : 'title'
Nils Diewald7c8ced22015-04-15 19:21:00 +0000308 }));
309
310 doc = regexFactory.create({
Akron712733a2018-04-05 18:17:47 +0200311 match: "match:ne"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000312 });
313 expect(doc.toJson()).toEqual(jasmine.objectContaining({
Akron712733a2018-04-05 18:17:47 +0200314 "@type" : "koral:doc",
315 "type" : "type:regex",
316 "value" : "[^b]ee.+?",
317 "match" : "match:ne",
318 "key" : 'title'
Nils Diewald7c8ced22015-04-15 19:21:00 +0000319 }));
320
321 doc = dateFactory.create();
322 expect(doc.toJson()).toEqual(jasmine.objectContaining({
Akron712733a2018-04-05 18:17:47 +0200323 "@type" : "koral:doc",
324 "type" : "type:date",
325 "value" : "2014-11-05",
326 "match" : "match:eq",
327 "key" : 'pubDate'
Nils Diewald7c8ced22015-04-15 19:21:00 +0000328 }));
329
330 doc = dateFactory.create({
Akron712733a2018-04-05 18:17:47 +0200331 value : "2014"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000332 });
333 expect(doc.toJson()).toEqual(jasmine.objectContaining({
Akron712733a2018-04-05 18:17:47 +0200334 "@type" : "koral:doc",
335 "type" : "type:date",
336 "value" : "2014",
337 "match" : "match:eq",
338 "key" : 'pubDate'
Nils Diewald7c8ced22015-04-15 19:21:00 +0000339 }));
340 });
341
342
343 it('should be serializale to String', function () {
344 // Empty doc
345 var doc = docClass.create();
Akronebc96662018-08-29 17:36:20 +0200346
Nils Diewald7c8ced22015-04-15 19:21:00 +0000347 expect(doc.toQuery()).toEqual("");
348
349 // Serialize string
350 doc = stringFactory.create();
351 expect(doc.toQuery()).toEqual('author = "Max Birkendale"');
352
hebastaa0282be2018-12-05 16:58:00 +0100353 // Check for incompletion
354 expect(doc.incomplete()).toBeFalsy();
355 doc.value("");
356 expect(doc.incomplete()).toBeTruthy();
357 expect(doc.toQuery()).toEqual('');
358
Nils Diewald7c8ced22015-04-15 19:21:00 +0000359 // Serialize string with quotes
360 doc = stringFactory.create({ "value" : 'Max "Der Coole" Birkendate'});
361 expect(doc.toQuery()).toEqual('author = "Max \\"Der Coole\\" Birkendate"');
362
363 // Serialize regex
364 doc = regexFactory.create();
365 expect(doc.toQuery()).toEqual('title = /[^b]ee.+?/');
366
367 doc = regexFactory.create({
Akron712733a2018-04-05 18:17:47 +0200368 match: "match:ne"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000369 });
370 expect(doc.toQuery()).toEqual('title != /[^b]ee.+?/');
371
Akron8778f5d2017-06-30 21:25:55 +0200372 doc = regexFactory.create({
Akron712733a2018-04-05 18:17:47 +0200373 value: "WPD/AAA/00001"
Akron8778f5d2017-06-30 21:25:55 +0200374 });
375 expect(doc.toQuery()).toEqual('title = /WPD\\/AAA\\/00001/');
376
Nils Diewald7c8ced22015-04-15 19:21:00 +0000377 doc = dateFactory.create();
378 expect(doc.toQuery()).toEqual('pubDate in 2014-11-05');
379
380 doc = dateFactory.create({
Akron712733a2018-04-05 18:17:47 +0200381 value : "2014"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000382 });
383 expect(doc.toQuery()).toEqual('pubDate in 2014');
384 });
385 });
386
387
Akron88d237e2020-10-21 08:05:18 +0200388 describe('KorAP.VC.DocGroup', function () {
Nils Diewald7c8ced22015-04-15 19:21:00 +0000389 // Create example factories
390 var docFactory = buildFactory(
391 docClass,
Nils Diewaldf219eb82015-01-07 20:15:42 +0000392 {
Akron712733a2018-04-05 18:17:47 +0200393 "@type" : "koral:doc",
394 "match":"match:eq",
395 "key" : "author",
396 "value" : "Max Birkendale"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000397 }
398 );
399
400 var docGroupFactory = buildFactory(
401 docGroupClass, {
Akron712733a2018-04-05 18:17:47 +0200402 "@type" : "koral:docGroup",
403 "operation" : "operation:and",
404 "operands" : [
405 docFactory.create().toJson(),
406 docFactory.create({
407 "key" : "pubDate",
408 "type" : "type:date",
409 "value" : "2014-12-05"
410 }).toJson()
411 ]
Nils Diewald7c8ced22015-04-15 19:21:00 +0000412 });
413
414 it('should be initializable', function () {
415 // Create empty group
416 var docGroup = docGroupClass.create();
417 expect(docGroup.operation()).toEqual('and');
418
419 // Create empty group
420 docGroup = docGroupClass.create();
421 docGroup.operation('or');
422 expect(docGroup.operation()).toEqual('or');
423 });
424
425 it('should be definable', function () {
426
427 // Empty group
428 var docGroup = docGroupClass.create();
429 expect(docGroup.operation()).toEqual('and');
430
431 // Set values
432 docGroup.operation("or");
433 expect(docGroup.operation()).toEqual('or');
434
435 // Set invalid values
436 docGroup.operation("hui");
437 expect(docGroup.operation()).toEqual('or');
438 });
439
440 it('should be deserializable', function () {
Akronadab5e52018-08-20 13:50:53 +0200441
442 // Reset list
443 KorAP._vcKeyMenu = menuClass.create([['referTo','ref']]);
444
Nils Diewald7c8ced22015-04-15 19:21:00 +0000445 var docGroup = docGroupFactory.create();
446 expect(docGroup.operation()).toEqual("and");
447 expect(docGroup.operands().length).toEqual(2);
448
449 var op1 = docGroup.getOperand(0);
450 expect(op1.type()).toEqual("string");
451 expect(op1.key()).toEqual("author");
452 expect(op1.value()).toEqual("Max Birkendale");
453 expect(op1.matchop()).toEqual("eq");
454
455 var op2 = docGroup.getOperand(1);
456 expect(op2.type()).toEqual("date");
457 expect(op2.key()).toEqual("pubDate");
458 expect(op2.value()).toEqual("2014-12-05");
459 expect(op2.matchop()).toEqual("eq");
460
461 // Append empty group
462 var newGroup = docGroup.append(docGroupClass.create());
463 newGroup.operation('or');
464 newGroup.append(docFactory.create());
465 newGroup.append(docFactory.create({
Akron712733a2018-04-05 18:17:47 +0200466 "type" : "type:regex",
467 "key" : "title",
468 "value" : "^e.+?$",
469 "match" : "match:ne"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000470 }));
471
472 expect(docGroup.operation()).toEqual("and");
473 expect(docGroup.operands().length).toEqual(3);
474
475 var op1 = docGroup.getOperand(0);
476 expect(op1.ldType()).toEqual("doc");
477 expect(op1.type()).toEqual("string");
478 expect(op1.key()).toEqual("author");
479 expect(op1.value()).toEqual("Max Birkendale");
480 expect(op1.matchop()).toEqual("eq");
481
482 var op2 = docGroup.getOperand(1);
483 expect(op2.ldType()).toEqual("doc");
484 expect(op2.type()).toEqual("date");
485 expect(op2.key()).toEqual("pubDate");
486 expect(op2.value()).toEqual("2014-12-05");
487 expect(op2.matchop()).toEqual("eq");
488
489 var op3 = docGroup.getOperand(2);
490 expect(op3.ldType()).toEqual("docGroup");
491 expect(op3.operation()).toEqual("or");
Akronadab5e52018-08-20 13:50:53 +0200492
Nils Diewald7c8ced22015-04-15 19:21:00 +0000493 var op4 = op3.getOperand(0);
494 expect(op4.ldType()).toEqual("doc");
495 expect(op4.type()).toEqual("string");
496 expect(op4.key()).toEqual("author");
497 expect(op4.value()).toEqual("Max Birkendale");
498 expect(op4.matchop()).toEqual("eq");
499
500 var op5 = op3.getOperand(1);
501 expect(op5.ldType()).toEqual("doc");
502 expect(op5.type()).toEqual("regex");
503 expect(op5.key()).toEqual("title");
504 expect(op5.value()).toEqual("^e.+?$");
505 expect(op5.matchop()).toEqual("ne");
506 });
507
508 it('should be serializable to JSON', function () {
509 var docGroup = docGroupFactory.create();
510
511 expect(docGroup.toJson()).toEqual(jasmine.objectContaining({
Akron712733a2018-04-05 18:17:47 +0200512 "@type" : "koral:docGroup",
513 "operation" : "operation:and",
514 "operands" : [
515 {
516 "@type": 'koral:doc',
517 "key" : 'author',
518 "match": 'match:eq',
519 "value": 'Max Birkendale',
520 "type": 'type:string'
521 },
522 {
523 "@type": 'koral:doc',
524 "key": 'pubDate',
525 "match": 'match:eq',
526 "value": '2014-12-05',
527 "type": 'type:date'
528 }
529 ]
Nils Diewald7c8ced22015-04-15 19:21:00 +0000530 }));
531 });
Nils Diewalde15b7a22015-01-09 21:50:21 +0000532
Nils Diewald7c8ced22015-04-15 19:21:00 +0000533 it('should be serializable to String', function () {
534 var docGroup = docGroupFactory.create();
535 expect(docGroup.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +0200536 'author = "Max Birkendale" & pubDate in 2014-12-05'
Nils Diewald7c8ced22015-04-15 19:21:00 +0000537 );
Nils Diewald52f7eb12015-01-12 17:30:04 +0000538
Nils Diewald7c8ced22015-04-15 19:21:00 +0000539 docGroup = docGroupFactory.create({
Akron712733a2018-04-05 18:17:47 +0200540 "@type" : "koral:docGroup",
541 "operation" : "operation:or",
542 "operands" : [
543 {
544 "@type": 'koral:doc',
545 "key" : 'author',
546 "match": 'match:eq',
547 "value": 'Max Birkendale',
548 "type": 'type:string'
549 },
550 {
551 "@type" : "koral:docGroup",
552 "operation" : "operation:and",
553 "operands" : [
554 {
555 "@type": 'koral:doc',
556 "key": 'pubDate',
557 "match": 'match:geq',
558 "value": '2014-05-12',
559 "type": 'type:date'
560 },
561 {
562 "@type": 'koral:doc',
563 "key": 'pubDate',
564 "match": 'match:leq',
565 "value": '2014-12-05',
566 "type": 'type:date'
567 },
568 {
569 "@type": 'koral:doc',
570 "key": 'foo',
571 "match": 'match:ne',
572 "value": '[a]?bar',
573 "type": 'type:regex'
574 }
575 ]
576 }
577 ]
Nils Diewald7c8ced22015-04-15 19:21:00 +0000578 });
579 expect(docGroup.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +0200580 'author = "Max Birkendale" | ' +
581 '(pubDate since 2014-05-12 & ' +
582 'pubDate until 2014-12-05 & foo != /[a]?bar/)'
Nils Diewald7c8ced22015-04-15 19:21:00 +0000583 );
hebastaa0282be2018-12-05 16:58:00 +0100584
585
586 // Check for incompletion and only serialize complete operands
587 expect(docGroup.incomplete()).toBeFalsy();
588 var op1 = docGroup.getOperand(0);
589 op1.value("");
590 expect(docGroup.incomplete()).toBeFalsy();
591 expect(docGroup.toQuery()).toEqual(
592 '(pubDate since 2014-05-12 & ' +
593 'pubDate until 2014-12-05 & foo != /[a]?bar/)'
594 );
Nils Diewald7c8ced22015-04-15 19:21:00 +0000595 });
596 });
597
Akron88d237e2020-10-21 08:05:18 +0200598 describe('KorAP.VC.DocGroupRef', function () {
Akronb19803c2018-08-16 16:39:42 +0200599 // Create example factories
600 var docRefFactory = buildFactory(
601 docGroupRefClass,
602 {
603 "@type" : "koral:docGroupRef",
604 "ref" : "@max/myCorpus"
605 }
606 );
607
608 it('should be initializable', function () {
609 var vcRef = docGroupRefClass.create();
610 expect(vcRef.ref()).toBeUndefined();
611 });
612
613 it('should be definable', function () {
614 var vcRef = docGroupRefClass.create();
615 vcRef.ref("@peter/mycorpus");
616 expect(vcRef.ref()).toEqual("@peter/mycorpus");
617 vcRef.ref("@peter/mycorpus2");
618 expect(vcRef.ref()).toEqual("@peter/mycorpus2");
619 });
620
621 it('should deserialize JSON-LD string', function () {
622 var vcRef = docRefFactory.create();
623 expect(vcRef.ref()).toEqual("@max/myCorpus");
624 });
625
626 it('should serialize to JSON-LD', function () {
627 var vcRef = docRefFactory.create();
628 expect(vcRef.toJson()).toEqual(jasmine.objectContaining({
629 "@type" : "koral:docGroupRef",
630 "ref":"@max/myCorpus"
631 }));
632
633 vcRef.ref("@peter/myCorpus2");
634 expect(vcRef.toJson()).toEqual(jasmine.objectContaining({
635 "@type" : "koral:docGroupRef",
636 "ref":"@peter/myCorpus2"
637 }));
638 });
639
640 it('should serialize to a query', function () {
641 var vcRef = docRefFactory.create();
642 expect(vcRef.toQuery()).toEqual(
643 "referTo \"@max/myCorpus\""
644 );
645
646 vcRef.ref("@peter/myCorpus2");
647 expect(vcRef.toQuery()).toEqual(
648 "referTo \"@peter/myCorpus2\""
649 );
hebastaa0282be2018-12-05 16:58:00 +0100650
651 // Check for incompletion and only serialize complete operands
652 expect(vcRef.incomplete()).toBeFalsy();
653 vcRef.ref("");
654 expect(vcRef.incomplete()).toBeTruthy();
655 expect(vcRef.toQuery()).toEqual("");
Akronb19803c2018-08-16 16:39:42 +0200656 });
657 });
658
659
Akron88d237e2020-10-21 08:05:18 +0200660 describe('KorAP.VC.UnspecifiedDoc', function () {
Akron0f00b772020-12-02 17:32:13 +0100661
662 KorAP.vc = undefined;
663
Nils Diewald7c8ced22015-04-15 19:21:00 +0000664 it('should be initializable', function () {
665 var doc = unspecifiedClass.create();
666 var docElement = doc.element();
667 expect(docElement.getAttribute('class')).toEqual('doc unspecified');
Akronebc96662018-08-29 17:36:20 +0200668 expect(docElement.firstChild.firstChild.data).toEqual(KorAP.Locale.EMPTY);
669 expect(docElement.lastChild.lastChild.data).toEqual(KorAP.Locale.EMPTY);
Nils Diewald7c8ced22015-04-15 19:21:00 +0000670 expect(doc.toQuery()).toEqual('');
hebastaa0282be2018-12-05 16:58:00 +0100671 expect(doc.incomplete()).toBeTruthy();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000672
673 // Only removable
674 expect(docElement.lastChild.children.length).toEqual(0);
675 });
676
hebastad7c03742019-07-11 12:48:50 +0200677 it('should be removable, when no root', function () {
678 var vc = vcClass.create();
679 KorAP.vc = vc;
Nils Diewald7c8ced22015-04-15 19:21:00 +0000680 var docGroup = docGroupClass.create();
681 docGroup.operation('or');
682 expect(docGroup.operation()).toEqual('or');
683
684 docGroup.append({
Akron712733a2018-04-05 18:17:47 +0200685 "@type": 'koral:doc',
686 "key": 'pubDate',
687 "match": 'match:eq',
688 "value": '2014-12-05',
689 "type": 'type:date'
Nils Diewald7c8ced22015-04-15 19:21:00 +0000690 });
691
692 // Add unspecified object
693 docGroup.append();
694
Akrond141a362018-07-10 18:12:13 +0200695 var parent = document.createElement('div');
696 parent.appendChild(docGroup.element());
697
Nils Diewald7c8ced22015-04-15 19:21:00 +0000698 expect(docGroup.element().getAttribute('class')).toEqual('docGroup');
699 expect(docGroup.element().children[0].getAttribute('class')).toEqual('doc');
700
701 var unspec = docGroup.element().children[1];
702 expect(unspec.getAttribute('class')).toEqual('doc unspecified');
703
Akronb19803c2018-08-16 16:39:42 +0200704 // Only unspec and delete
705 expect(unspec.children.length).toEqual(2);
706
Nils Diewald7c8ced22015-04-15 19:21:00 +0000707 // Removable
708 expect(unspec.lastChild.children.length).toEqual(1);
709 expect(unspec.lastChild.children[0].getAttribute('class')).toEqual('delete');
710 });
711
Akrond141a362018-07-10 18:12:13 +0200712
Nils Diewald7c8ced22015-04-15 19:21:00 +0000713 it('should be replaceable by a doc', function () {
714 var doc = unspecifiedClass.create();
715 expect(doc.ldType()).toEqual("non");
716 // No parent, therefor not updateable
717 expect(doc.key("baum")).toBeNull();
718
719 var docGroup = docGroupClass.create();
720 docGroup.operation('or');
721 expect(docGroup.operation()).toEqual('or');
722
723 docGroup.append({
Akron712733a2018-04-05 18:17:47 +0200724 "@type": 'koral:doc',
725 "key": 'pubDate',
726 "match": 'match:eq',
727 "value": '2014-12-05',
728 "type": 'type:date'
Nils Diewald7c8ced22015-04-15 19:21:00 +0000729 });
730
731 expect(docGroup.toQuery()).toEqual("pubDate in 2014-12-05");
732 docGroup.append();
733
734 expect(docGroup.getOperand(0).ldType()).toEqual("doc");
735 expect(docGroup.getOperand(1).ldType()).toEqual("non");
736
737 var op = docGroup.getOperand(1).element().lastChild;
Akron0b489ad2018-02-02 16:49:32 +0100738 expect(op.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +0000739 expect(op.children[0].getAttribute('class')).toEqual('delete');
740 expect(op.children.length).toEqual(1);
741
742 // Replace unspecified doc
743 expect(docGroup.getOperand(1).key("name")).not.toBeNull();
744 expect(docGroup.getOperand(1).ldType()).toEqual("doc");
745 expect(docGroup.getOperand(1).key()).toEqual("name");
Akron55a343b2018-04-06 19:57:36 +0200746 expect(docGroup.getOperand(1).value()).toBeUndefined();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000747
Akronb19803c2018-08-16 16:39:42 +0200748 expect(docGroup.getOperand(1).element().children.length).toEqual(4);
749
Nils Diewald7c8ced22015-04-15 19:21:00 +0000750 op = docGroup.getOperand(1).element().lastChild;
Akron0b489ad2018-02-02 16:49:32 +0100751 expect(op.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +0000752 expect(op.children[0].getAttribute('class')).toEqual('and');
753 expect(op.children[1].getAttribute('class')).toEqual('or');
754 expect(op.children[2].getAttribute('class')).toEqual('delete');
Akronb19803c2018-08-16 16:39:42 +0200755
Nils Diewald7c8ced22015-04-15 19:21:00 +0000756 expect(op.children.length).toEqual(3);
757
758 docGroup.getOperand(1).value("Pachelbel");
759 expect(docGroup.getOperand(1).value()).toEqual("Pachelbel");
760 expect(docGroup.getOperand(1).type()).toEqual("string");
761 expect(docGroup.getOperand(1).matchop()).toEqual("eq");
762
763 // Specified!
764 expect(docGroup.toQuery()).toEqual('pubDate in 2014-12-05 | name = "Pachelbel"');
765 });
Akronb19803c2018-08-16 16:39:42 +0200766
Nils Diewald7c8ced22015-04-15 19:21:00 +0000767 it('should be replaceable on root', function () {
hebastaa0282be2018-12-05 16:58:00 +0100768
Nils Diewald6283d692015-04-23 20:32:53 +0000769 var vc = vcClass.create();
hebastaa0282be2018-12-05 16:58:00 +0100770 KorAP.vc = vc;
Nils Diewald7c8ced22015-04-15 19:21:00 +0000771 expect(vc.toQuery()).toEqual("");
772
773 expect(vc.root().ldType()).toEqual("non");
774
775 // No operators on root
776 op = vc.root().element().lastChild;
Akronebc96662018-08-29 17:36:20 +0200777 expect(op.lastChild.textContent).toEqual(KorAP.Locale.EMPTY);
Nils Diewald7c8ced22015-04-15 19:21:00 +0000778
779 // Replace
780 expect(vc.root().key("baum")).not.toBeNull();
781 expect(vc.root().ldType()).toEqual("doc");
782
783 op = vc.root().element().lastChild;
Akron0b489ad2018-02-02 16:49:32 +0100784 expect(op.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +0000785 expect(op.children[0].getAttribute('class')).toEqual('and');
786 expect(op.children[1].getAttribute('class')).toEqual('or');
787 expect(op.children[2].getAttribute('class')).toEqual('delete');
788 expect(op.children.length).toEqual(3);
789 });
Akron55a343b2018-04-06 19:57:36 +0200790
791 it('should be clickable', function () {
792 var vc = vcClass.create([
793 ["pubDate", "date"]
794 ]);
hebastaa0282be2018-12-05 16:58:00 +0100795 KorAP.vc = vc;
796
Akron55a343b2018-04-06 19:57:36 +0200797 expect(vc.toQuery()).toEqual("");
Akronebc96662018-08-29 17:36:20 +0200798 expect(vc.builder().firstChild.textContent).toEqual(KorAP.Locale.EMPTY);
799 expect(vc.builder().firstChild.classList.contains('unspecified')).toEqual(true);
Akronadab5e52018-08-20 13:50:53 +0200800 vc.builder().firstChild.firstChild.click();
Akron55a343b2018-04-06 19:57:36 +0200801
802 // Click on pubDate
Akron3ad46942018-08-22 16:47:14 +0200803 vc.element().firstChild.getElementsByTagName("LI")[1].click();
Akronadab5e52018-08-20 13:50:53 +0200804 expect(vc.builder().firstChild.firstChild.textContent).toEqual("pubDate");
805 expect(vc.builder().firstChild.children[1].getAttribute("data-type")).toEqual("date");
Akron55a343b2018-04-06 19:57:36 +0200806 });
Nils Diewald7c8ced22015-04-15 19:21:00 +0000807 });
808
Akron88d237e2020-10-21 08:05:18 +0200809 describe('KorAP.VC.Doc element', function () {
Nils Diewald7c8ced22015-04-15 19:21:00 +0000810 it('should be initializable', function () {
811 var docElement = docClass.create(undefined, {
Akron712733a2018-04-05 18:17:47 +0200812 "@type" : "koral:doc",
813 "key":"Titel",
814 "value":"Baum",
815 "match":"match:eq"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000816 });
817 expect(docElement.key()).toEqual('Titel');
818 expect(docElement.matchop()).toEqual('eq');
819 expect(docElement.value()).toEqual('Baum');
820
821 var docE = docElement.element();
822 expect(docE.children[0].firstChild.data).toEqual('Titel');
823 expect(docE.children[1].firstChild.data).toEqual('eq');
824 expect(docE.children[1].getAttribute('data-type')).toEqual('string');
825 expect(docE.children[2].firstChild.data).toEqual('Baum');
826 expect(docE.children[2].getAttribute('data-type')).toEqual('string');
827
828 expect(docElement.toJson()).toEqual(jasmine.objectContaining({
Akron712733a2018-04-05 18:17:47 +0200829 "@type" : "koral:doc",
830 "key":"Titel",
831 "value":"Baum",
832 "match":"match:eq"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000833 }));
834 });
Akronb19803c2018-08-16 16:39:42 +0200835
836
837 it('should be replacable by unspecified', function () {
838 var vc = vcClass.create([
839 ["pubDate", "date"]
840 ]).fromJson({
841 "@type" : "koral:doc",
842 "key":"Titel",
843 "value":"Baum",
844 "match":"match:eq"
845 });
hebastaa0282be2018-12-05 16:58:00 +0100846 KorAP.vc = vc;
Akronb19803c2018-08-16 16:39:42 +0200847 expect(vc.toQuery()).toEqual("Titel = \"Baum\"");
848
Akronadab5e52018-08-20 13:50:53 +0200849 var vcE = vc.builder();
Akronb19803c2018-08-16 16:39:42 +0200850 expect(vcE.firstChild.children.length).toEqual(4);
851
852 // Click to delete
853 vcE.firstChild.lastChild.lastChild.click();
854
855 expect(vcE.firstChild.children.length).toEqual(1);
856
Akronebc96662018-08-29 17:36:20 +0200857 expect(vcE.firstChild.textContent).toEqual(KorAP.Locale.EMPTY);
858 expect(vcE.firstChild.classList.contains("unspecified")).toBeTruthy();
Akronb19803c2018-08-16 16:39:42 +0200859 vcE.firstChild.firstChild.click();
860
861 // Click on pubDate
Akron3ad46942018-08-22 16:47:14 +0200862 vcE.firstChild.getElementsByTagName("LI")[1].click();
Akronb19803c2018-08-16 16:39:42 +0200863
864 expect(vcE.firstChild.firstChild.textContent).toEqual("pubDate");
865 expect(vcE.firstChild.children[1].getAttribute("data-type")).toEqual("date");
866
867 expect(vcE.firstChild.children.length).toEqual(4);
868 });
869
870
Akron587e4d92018-08-31 12:44:26 +0200871 it('should be replaceable by docGroupRef with deletion', function () {
Akron3ad46942018-08-22 16:47:14 +0200872 var vc = vcClass.create().fromJson({
Akronb19803c2018-08-16 16:39:42 +0200873 "@type" : "koral:doc",
874 "key":"Titel",
875 "value":"Baum",
876 "match":"match:eq"
877 });
878
hebastaa0282be2018-12-05 16:58:00 +0100879 KorAP.vc = vc;
Akronb19803c2018-08-16 16:39:42 +0200880 expect(vc.toQuery()).toEqual("Titel = \"Baum\"");
881
Akronadab5e52018-08-20 13:50:53 +0200882 var vcE = vc.builder();
Akronb19803c2018-08-16 16:39:42 +0200883 expect(vcE.firstChild.children.length).toEqual(4);
884
885 // Click to delete
886 vcE.firstChild.lastChild.lastChild.click();
887
888 expect(vcE.firstChild.children.length).toEqual(1);
889
Akronebc96662018-08-29 17:36:20 +0200890 expect(vcE.firstChild.textContent).toEqual(KorAP.Locale.EMPTY);
891 expect(vcE.firstChild.classList.contains('unspecified')).toEqual(true);
Akronb19803c2018-08-16 16:39:42 +0200892 vcE.firstChild.firstChild.click();
893
Akron3ad46942018-08-22 16:47:14 +0200894 // Click on referTo
Akronb19803c2018-08-16 16:39:42 +0200895 vcE.firstChild.getElementsByTagName("LI")[0].click();
896
Akron3ad46942018-08-22 16:47:14 +0200897 expect(vcE.firstChild.firstChild.textContent).toEqual("referTo");
Akronb19803c2018-08-16 16:39:42 +0200898 expect(vcE.firstChild.children[1].getAttribute("data-type")).toEqual("string");
Akron587e4d92018-08-31 12:44:26 +0200899
Akronb19803c2018-08-16 16:39:42 +0200900 expect(vcE.firstChild.children.length).toEqual(3);
Akron62ac95b2018-08-30 18:08:25 +0200901 expect(vcE.firstChild.children[1].classList.contains("unspecified")).toBeTruthy();
Akronb19803c2018-08-16 16:39:42 +0200902 });
Akron587e4d92018-08-31 12:44:26 +0200903
904
905 it('should be replaceable by docGroupRef on root', function () {
906 var vc = vcClass.create().fromJson({
907 "@type" : "koral:doc",
908 "key":"Titel",
909 "value":"Baum",
910 "match":"match:eq"
911 });
912
hebastaa0282be2018-12-05 16:58:00 +0100913 KorAP.vc = vc;
Akron587e4d92018-08-31 12:44:26 +0200914 expect(vc.toQuery()).toEqual("Titel = \"Baum\"");
915
916 var vcE = vc.builder();
917 expect(vcE.firstChild.children.length).toEqual(4);
918
919 // Click on the key
920 vcE.firstChild.firstChild.click();
921
922 expect(vcE.firstChild.getElementsByTagName("LI")[0].textContent).toEqual("referTo");
923
924 // Click on referTo
925 vcE.firstChild.getElementsByTagName("LI")[0].click();
926
927 // Now it's a referTo element
928 expect(vcE.firstChild.firstChild.textContent).toEqual("referTo");
929 expect(vcE.firstChild.children.length).toEqual(3);
930 expect(vcE.firstChild.children[1].classList.contains("unspecified")).toBeTruthy();
931 });
932
933 it('should be replaceable by docGroupRef nested', function () {
934 var vc = vcClass.create().fromJson({
935 "@type" : "koral:docGroup",
936 "operation" : "operation:and",
937 "operands" : [
938 {
939 "@type": 'koral:doc',
940 "key" : 'author',
941 "match": 'match:eq',
942 "value": 'Max Birkendale',
943 "type": 'type:string'
944 },
945 {
946 "@type": 'koral:doc',
947 "key": 'pubDate',
948 "match": 'match:eq',
949 "value": '2014-12-05',
950 "type": 'type:date'
951 }
952 ]
953 });
954
hebastaa0282be2018-12-05 16:58:00 +0100955 KorAP.vc = vc;
Akron587e4d92018-08-31 12:44:26 +0200956 expect(vc.toQuery()).toEqual("author = \"Max Birkendale\" & pubDate in 2014-12-05");
957
958 var vcE = vc.builder();
959
960 // First doc
961 var doc = vcE.firstChild.firstChild;
962 expect(doc.children.length).toEqual(4);
963
964 // Click on the key
965 doc.firstChild.click();
966
967 expect(doc.getElementsByTagName("LI")[0].textContent).toEqual("referTo");
968
969 // Click on referTo
970 vcE.firstChild.getElementsByTagName("LI")[0].click();
971
972 // Now it's a referTo element
973 expect(vcE.firstChild.firstChild.firstChild.textContent).toEqual("referTo");
974 expect(vcE.firstChild.firstChild.children.length).toEqual(3);
975 expect(vcE.firstChild.firstChild.children[1].classList.contains("unspecified")).toBeTruthy();
976 });
Nils Diewald7c8ced22015-04-15 19:21:00 +0000977 });
978
Akron88d237e2020-10-21 08:05:18 +0200979 describe('KorAP.VC.DocGroup element', function () {
Nils Diewald7c8ced22015-04-15 19:21:00 +0000980 it('should be initializable', function () {
981
982 var docGroup = docGroupClass.create(undefined, {
Akron712733a2018-04-05 18:17:47 +0200983 "@type" : "koral:docGroup",
984 "operation" : "operation:and",
985 "operands" : [
986 {
987 "@type": 'koral:doc',
988 "key" : 'author',
989 "match": 'match:eq',
990 "value": 'Max Birkendale',
991 "type": 'type:string'
992 },
993 {
994 "@type": 'koral:doc',
995 "key": 'pubDate',
996 "match": 'match:eq',
997 "value": '2014-12-05',
998 "type": 'type:date'
999 }
1000 ]
Nils Diewald7c8ced22015-04-15 19:21:00 +00001001 });
1002
1003 expect(docGroup.operation()).toEqual('and');
1004 var e = docGroup.element();
1005 expect(e.getAttribute('class')).toEqual('docGroup');
1006 expect(e.getAttribute('data-operation')).toEqual('and');
1007
1008 var first = e.children[0];
1009 expect(first.getAttribute('class')).toEqual('doc');
1010 expect(first.children[0].getAttribute('class')).toEqual('key');
1011 expect(first.children[1].getAttribute('class')).toEqual('match');
1012 expect(first.children[2].getAttribute('class')).toEqual('value');
1013 expect(first.children[2].getAttribute('data-type')).toEqual('string');
1014 expect(first.children[0].firstChild.data).toEqual('author');
1015 expect(first.children[1].firstChild.data).toEqual('eq');
1016 expect(first.children[2].firstChild.data).toEqual('Max Birkendale');
1017
1018 var second = e.children[1];
1019 expect(second.getAttribute('class')).toEqual('doc');
1020 expect(second.children[0].getAttribute('class')).toEqual('key');
1021 expect(second.children[1].getAttribute('class')).toEqual('match');
1022 expect(second.children[2].getAttribute('class')).toEqual('value');
1023 expect(second.children[2].getAttribute('data-type')).toEqual('date');
1024 expect(second.children[0].firstChild.data).toEqual('pubDate');
1025 expect(second.children[1].firstChild.data).toEqual('eq');
1026 expect(second.children[2].firstChild.data).toEqual('2014-12-05');
1027 });
1028
1029 it('should be deserializable with nested groups', function () {
1030 var docGroup = docGroupClass.create(undefined, {
Akron712733a2018-04-05 18:17:47 +02001031 "@type" : "koral:docGroup",
1032 "operation" : "operation:or",
1033 "operands" : [
1034 {
1035 "@type": 'koral:doc',
1036 "key" : 'author',
1037 "match": 'match:eq',
1038 "value": 'Max Birkendale',
1039 "type": 'type:string'
1040 },
1041 {
1042 "@type" : "koral:docGroup",
1043 "operation" : "operation:and",
1044 "operands" : [
1045 {
1046 "@type": 'koral:doc',
1047 "key": 'pubDate',
1048 "match": 'match:geq',
1049 "value": '2014-05-12',
1050 "type": 'type:date'
1051 },
1052 {
1053 "@type": 'koral:doc',
1054 "key": 'pubDate',
1055 "match": 'match:leq',
1056 "value": '2014-12-05',
1057 "type": 'type:date'
1058 }
1059 ]
1060 }
1061 ]
Nils Diewald7c8ced22015-04-15 19:21:00 +00001062 });
1063
1064 expect(docGroup.operation()).toEqual('or');
1065 var e = docGroup.element();
1066 expect(e.getAttribute('class')).toEqual('docGroup');
1067 expect(e.getAttribute('data-operation')).toEqual('or');
1068
1069 expect(e.children[0].getAttribute('class')).toEqual('doc');
1070 var docop = e.children[0].lastChild;
Akron0b489ad2018-02-02 16:49:32 +01001071 expect(docop.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001072 expect(docop.children[0].getAttribute('class')).toEqual('and');
1073 expect(docop.children[1].getAttribute('class')).toEqual('or');
1074 expect(docop.children[2].getAttribute('class')).toEqual('delete');
1075
1076 expect(e.children[1].getAttribute('class')).toEqual('docGroup');
1077 expect(e.children[1].getAttribute('data-operation')).toEqual('and');
1078
1079 // This and-operation can be "or"ed or "delete"d
1080 var secop = e.children[1].children[2];
Akron0b489ad2018-02-02 16:49:32 +01001081 expect(secop.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001082 expect(secop.children[0].getAttribute('class')).toEqual('or');
1083 expect(secop.children[1].getAttribute('class')).toEqual('delete');
1084
1085 // This or-operation can be "and"ed or "delete"d
Akron0b489ad2018-02-02 16:49:32 +01001086 expect(e.children[2].getAttribute('class')).toEqual('operators button-group');
1087 expect(e.lastChild.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001088 expect(e.lastChild.children[0].getAttribute('class')).toEqual('and');
1089 expect(e.lastChild.children[1].getAttribute('class')).toEqual('delete');
1090 });
1091 });
1092
Akron88d237e2020-10-21 08:05:18 +02001093 describe('KorAP.VC.DocGroupRef element', function () {
Akronb19803c2018-08-16 16:39:42 +02001094 it('should be initializable', function () {
1095 var docGroupRef = docGroupRefClass.create(undefined, {
1096 "@type" : "koral:docGroupRef",
1097 "ref" : "@franz/myVC1"
1098 });
1099 expect(docGroupRef.ref()).toEqual("@franz/myVC1");
1100 var dgrE = docGroupRef.element();
1101
Akron3ad46942018-08-22 16:47:14 +02001102 expect(dgrE.children[0].firstChild.data).toEqual("referTo");
Akronb19803c2018-08-16 16:39:42 +02001103 expect(dgrE.children[0].tagName).toEqual("SPAN");
1104 expect(dgrE.children[0].classList.contains("key")).toBeTruthy();
1105 expect(dgrE.children[0].classList.contains("fixed")).toBeTruthy();
1106 expect(dgrE.children[1].firstChild.data).toEqual("@franz/myVC1");
1107 expect(dgrE.children[1].tagName).toEqual("SPAN");
1108 expect(dgrE.children[1].classList.contains("value")).toBeTruthy();
1109 expect(dgrE.children[1].getAttribute("data-type")).toEqual("string");
1110 });
1111
1112 it('should be modifiable on reference', function () {
1113 var docGroupRef = docGroupRefClass.create(undefined, {
1114 "@type" : "koral:docGroupRef",
1115 "ref" : "@franz/myVC1"
1116 });
1117 var dgrE = docGroupRef.element();
1118 expect(docGroupRef.toQuery()).toEqual("referTo \"@franz/myVC1\"");
1119 dgrE.children[1].click();
1120
1121 var input = dgrE.children[1].firstChild;
1122 expect(input.tagName).toEqual("INPUT");
1123 input.value = "Versuch";
1124
1125 var event = new KeyboardEvent("keypress", {
1126 "key" : "[Enter]",
1127 "keyCode" : 13
1128 });
1129
1130 input.dispatchEvent(event);
1131 expect(docGroupRef.toQuery()).toEqual("referTo \"Versuch\"");
1132 });
1133 });
1134
1135
Akron88d237e2020-10-21 08:05:18 +02001136 describe('KorAP.VC.VirtualCorpus', function () {
Nils Diewald7c8ced22015-04-15 19:21:00 +00001137 var simpleGroupFactory = buildFactory(docGroupClass, {
1138 "@type" : "koral:docGroup",
1139 "operation" : "operation:and",
1140 "operands" : [
Akron712733a2018-04-05 18:17:47 +02001141 {
1142 "@type": 'koral:doc',
1143 "key" : 'author',
1144 "match": 'match:eq',
1145 "value": 'Max Birkendale',
1146 "type": 'type:string'
1147 },
1148 {
1149 "@type": 'koral:doc',
1150 "key": 'pubDate',
1151 "match": 'match:eq',
1152 "value": '2014-12-05',
1153 "type": 'type:date'
1154 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00001155 ]
1156 });
1157
1158 var nestedGroupFactory = buildFactory(vcClass, {
1159 "@type" : "koral:docGroup",
1160 "operation" : "operation:or",
1161 "operands" : [
Akron712733a2018-04-05 18:17:47 +02001162 {
1163 "@type": 'koral:doc',
1164 "key" : 'author',
1165 "match": 'match:eq',
1166 "value": 'Max Birkendale',
1167 "type": 'type:string'
1168 },
1169 {
1170 "@type" : "koral:docGroup",
1171 "operation" : "operation:and",
1172 "operands" : [
1173 {
1174 "@type": 'koral:doc',
1175 "key": 'pubDate',
1176 "match": 'match:geq',
1177 "value": '2014-05-12',
1178 "type": 'type:date'
1179 },
1180 {
1181 "@type": 'koral:doc',
1182 "key": 'pubDate',
1183 "match": 'match:leq',
1184 "value": '2014-12-05',
1185 "type": 'type:date'
1186 }
1187 ]
1188 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00001189 ]
1190 });
1191
1192 var flatGroupFactory = buildFactory(vcClass, {
1193 "@type" : "koral:docGroup",
1194 "operation" : "operation:and",
1195 "operands" : [
Akron712733a2018-04-05 18:17:47 +02001196 {
1197 "@type": 'koral:doc',
1198 "key": 'pubDate',
1199 "match": 'match:geq',
1200 "value": '2014-05-12',
1201 "type": 'type:date'
1202 },
1203 {
1204 "@type": 'koral:doc',
1205 "key": 'pubDate',
1206 "match": 'match:leq',
1207 "value": '2014-12-05',
1208 "type": 'type:date'
1209 },
1210 {
1211 "@type": 'koral:doc',
1212 "key": 'foo',
1213 "match": 'match:eq',
1214 "value": 'bar',
1215 "type": 'type:string'
1216 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00001217 ]
1218 });
1219
1220 it('should be initializable', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00001221 var vc = vcClass.create();
Nils Diewald7c8ced22015-04-15 19:21:00 +00001222 expect(vc.element().getAttribute('class')).toEqual('vc');
1223 expect(vc.root().element().getAttribute('class')).toEqual('doc unspecified');
1224
1225 // Not removable
1226 expect(vc.root().element().lastChild.children.length).toEqual(0);
1227 });
1228
1229 it('should be based on a doc', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00001230 var vc = vcClass.create().fromJson({
Akron712733a2018-04-05 18:17:47 +02001231 "@type" : "koral:doc",
1232 "key":"Titel",
1233 "value":"Baum",
1234 "match":"match:eq"
Nils Diewald7c8ced22015-04-15 19:21:00 +00001235 });
1236
1237 expect(vc.element().getAttribute('class')).toEqual('vc');
1238 expect(vc.root().element().getAttribute('class')).toEqual('doc');
1239 expect(vc.root().key()).toEqual('Titel');
1240 expect(vc.root().value()).toEqual('Baum');
1241 expect(vc.root().matchop()).toEqual('eq');
1242
1243 var docE = vc.root().element();
1244 expect(docE.children[0].firstChild.data).toEqual('Titel');
1245 expect(docE.children[1].firstChild.data).toEqual('eq');
1246 expect(docE.children[1].getAttribute('data-type')).toEqual('string');
1247 expect(docE.children[2].firstChild.data).toEqual('Baum');
1248 expect(docE.children[2].getAttribute('data-type')).toEqual('string');
1249 });
1250
1251 it('should be based on a docGroup', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00001252 var vc = vcClass.create().fromJson(simpleGroupFactory.create().toJson());
Nils Diewald7c8ced22015-04-15 19:21:00 +00001253
1254 expect(vc.element().getAttribute('class')).toEqual('vc');
1255 expect(vc.root().element().getAttribute('class')).toEqual('docGroup');
1256 expect(vc.root().operation()).toEqual('and');
1257
1258 var docGroup = vc.root();
1259
1260 var first = docGroup.getOperand(0);
1261 expect(first.key()).toEqual('author');
1262 expect(first.value()).toEqual('Max Birkendale');
1263 expect(first.matchop()).toEqual('eq');
1264
1265 var second = docGroup.getOperand(1);
1266 expect(second.key()).toEqual('pubDate');
1267 expect(second.value()).toEqual('2014-12-05');
1268 expect(second.matchop()).toEqual('eq');
1269 });
1270
Akronb19803c2018-08-16 16:39:42 +02001271 it('should be based on a docGroupRef', function () {
1272 var vc = vcClass.create().fromJson({
1273 "@type" : "koral:docGroupRef",
1274 "ref":"myCorpus"
1275 });
1276
Akronadab5e52018-08-20 13:50:53 +02001277 // iv class="doc groupref"><span class="key fixed">@referTo</span><span data-type="string" class="value">myCorpus</span>
1278 var vcE = vc.builder();
1279 expect(vcE.getAttribute('class')).toEqual('builder');
Akronb19803c2018-08-16 16:39:42 +02001280 expect(vcE.firstChild.tagName).toEqual('DIV');
1281 expect(vcE.firstChild.classList.contains('groupref')).toBeTruthy();
1282
1283 expect(vcE.firstChild.firstChild.tagName).toEqual('SPAN');
1284 expect(vcE.firstChild.firstChild.classList.contains('key')).toBeTruthy();
1285 expect(vcE.firstChild.firstChild.classList.contains('fixed')).toBeTruthy();
1286
Akron3ad46942018-08-22 16:47:14 +02001287 expect(vcE.firstChild.firstChild.textContent).toEqual("referTo");
Akronb19803c2018-08-16 16:39:42 +02001288
1289 expect(vcE.firstChild.children[1].tagName).toEqual('SPAN');
1290 expect(vcE.firstChild.children[1].classList.contains('value')).toBeTruthy();
1291 expect(vcE.firstChild.children[1].getAttribute('data-type')).toEqual('string');
1292 expect(vcE.firstChild.children[1].textContent).toEqual("myCorpus");
1293 });
Akron0f00b772020-12-02 17:32:13 +01001294
Nils Diewald7c8ced22015-04-15 19:21:00 +00001295 it('should be based on a nested docGroup', function () {
1296 var vc = nestedGroupFactory.create();
1297
Akronadab5e52018-08-20 13:50:53 +02001298 expect(vc.builder().getAttribute('class')).toEqual('builder');
1299 expect(vc.builder().firstChild.getAttribute('class')).toEqual('docGroup');
1300 expect(vc.builder().firstChild.children[0].getAttribute('class')).toEqual('doc');
1301 var dg = vc.builder().firstChild.children[1];
Nils Diewald7c8ced22015-04-15 19:21:00 +00001302 expect(dg.getAttribute('class')).toEqual('docGroup');
1303 expect(dg.children[0].getAttribute('class')).toEqual('doc');
1304 expect(dg.children[1].getAttribute('class')).toEqual('doc');
Akron0b489ad2018-02-02 16:49:32 +01001305 expect(dg.children[2].getAttribute('class')).toEqual('operators button-group');
Akronadab5e52018-08-20 13:50:53 +02001306 expect(vc.builder().firstChild.children[2].getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001307 });
1308
Akronb19803c2018-08-16 16:39:42 +02001309 it('should be based on a nested docGroupRef', function () {
1310 var vc = vcClass.create().fromJson({
1311 "@type" : "koral:docGroup",
1312 "operation" : "operation:and",
1313 "operands" : [{
1314 "@type" : "koral:docGroupRef",
1315 "ref":"myCorpus"
1316 },{
1317 "@type" : "koral:doc",
1318 "key":"Titel",
1319 "value":"Baum",
1320 "match":"match:eq"
1321 }]
1322 });
1323
1324 expect(vc._root.ldType()).toEqual("docGroup");
1325
1326 expect(vc.toQuery()).toEqual('referTo "myCorpus" & Titel = "Baum"');
1327 });
1328
Akron0f00b772020-12-02 17:32:13 +01001329 it('should accept an undefined KorAP.vc', function () {
1330 let temp = KorAP.vc;
1331 KorAP.vc = undefined;
1332 const vc = vcClass.create().fromJson({
1333 "@type" : "koral:docGroup",
1334 "operation" : "operation:and",
1335 "operands" : [{
1336 "@type" : "koral:docGroupRef",
1337 "ref":"myCorpus"
1338 },{
1339 "@type" : "koral:doc",
1340 "key":"Titel",
1341 "value":"Baum",
1342 "match":"match:eq"
1343 }]
1344 });
1345
1346 expect(vc._root.ldType()).toEqual("docGroup");
1347 expect(vc.toQuery()).toEqual('referTo "myCorpus" & Titel = "Baum"');
1348
1349 KorAP.vc = temp;
1350 });
Akronb19803c2018-08-16 16:39:42 +02001351
Nils Diewald7c8ced22015-04-15 19:21:00 +00001352 it('should be modifiable by deletion in flat docGroups', function () {
1353 var vc = flatGroupFactory.create();
1354 var docGroup = vc.root();
1355
1356 expect(docGroup.element().getAttribute('class')).toEqual('docGroup');
1357
1358 var doc = docGroup.getOperand(1);
1359 expect(doc.key()).toEqual("pubDate");
1360 expect(doc.value()).toEqual("2014-12-05");
1361
1362 // Remove operand 1
1363 expect(docGroup.delOperand(doc).update()).not.toBeUndefined();
Akron24aa0052020-11-10 11:00:34 +01001364 expect(doc._el).toEqual(undefined);
Nils Diewald7c8ced22015-04-15 19:21:00 +00001365
1366 doc = docGroup.getOperand(1);
1367 expect(doc.key()).toEqual("foo");
1368
1369 // Remove operand 1
1370 expect(docGroup.delOperand(doc).update()).not.toBeUndefined();
Akron24aa0052020-11-10 11:00:34 +01001371 expect(doc._el).toEqual(undefined);
Nils Diewald7c8ced22015-04-15 19:21:00 +00001372
1373 // Only one operand left ...
1374 expect(docGroup.getOperand(1)).toBeUndefined();
1375 // ... but there shouldn't be a group anymore at all!
1376 expect(docGroup.getOperand(0)).toBeUndefined();
1377
1378 var obj = vc.root();
1379 expect(obj.ldType()).toEqual("doc");
1380 expect(obj.key()).toEqual("pubDate");
1381 expect(obj.value()).toEqual("2014-05-12");
1382
1383 expect(obj.element().getAttribute('class')).toEqual('doc');
1384 });
1385
1386
1387 it('should be modifiable by deletion in nested docGroups (root case)', function () {
1388 var vc = nestedGroupFactory.create();
1389
1390 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001391 'author = "Max Birkendale" | (pubDate since 2014-05-12 & pubDate until 2014-12-05)'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001392 );
1393
1394 var docGroup = vc.root();
1395 expect(docGroup.ldType()).toEqual("docGroup");
1396 expect(docGroup.operation()).toEqual("or");
1397
1398 var doc = docGroup.getOperand(0);
1399 expect(doc.key()).toEqual("author");
1400 expect(doc.value()).toEqual("Max Birkendale");
1401
1402 docGroup = docGroup.getOperand(1);
1403 expect(docGroup.operation()).toEqual("and");
1404
1405 doc = docGroup.getOperand(0);
1406 expect(doc.key()).toEqual("pubDate");
1407 expect(doc.matchop()).toEqual("geq");
1408 expect(doc.value()).toEqual("2014-05-12");
1409 expect(doc.type()).toEqual("date");
1410
1411 doc = docGroup.getOperand(1);
1412 expect(doc.key()).toEqual("pubDate");
1413 expect(doc.matchop()).toEqual("leq");
1414 expect(doc.value()).toEqual("2014-12-05");
1415 expect(doc.type()).toEqual("date");
1416
1417 // Remove first operand so everything becomes root
1418 expect(
Akron712733a2018-04-05 18:17:47 +02001419 vc.root().delOperand(
1420 vc.root().getOperand(0)
1421 ).update().ldType()
Nils Diewald7c8ced22015-04-15 19:21:00 +00001422 ).toEqual("docGroup");
1423
1424 expect(vc.root().ldType()).toEqual("docGroup");
1425 expect(vc.root().operation()).toEqual("and");
1426 expect(vc.root().getOperand(0).ldType()).toEqual("doc");
1427
1428 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001429 'pubDate since 2014-05-12 & pubDate until 2014-12-05'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001430 );
1431 });
1432
1433 it('should be modifiable by deletion in nested docGroups (resolve group case)', function () {
1434 var vc = nestedGroupFactory.create();
1435
1436 // Get nested group
1437 var firstGroup = vc.root().getOperand(1);
1438 firstGroup.append(simpleGroupFactory.create({ "operation" : "operation:or" }));
1439
1440 // Structur is now:
1441 // or(doc, and(doc, doc, or(doc, doc)))
1442
1443 // Get nested or in and
1444 var orGroup = vc.root().getOperand(1).getOperand(2);
1445 expect(orGroup.ldType()).toEqual("docGroup");
1446 expect(orGroup.operation()).toEqual("or");
1447
1448 // Remove
1449 // Structur is now:
1450 // or(doc, and(doc, doc, doc)))
1451 expect(orGroup.delOperand(orGroup.getOperand(0)).update().operation()).toEqual("and");
1452 expect(vc.root().getOperand(1).operands().length).toEqual(3);
1453 });
1454
1455 it('should be modifiable by deletion in nested docGroups (identical group case)', function () {
1456 var vc = nestedGroupFactory.create();
1457
1458 // Get nested group
1459 var firstGroup = vc.root().getOperand(1);
1460 firstGroup.append(simpleGroupFactory.create({
Akron712733a2018-04-05 18:17:47 +02001461 "operation" : "operation:or"
Nils Diewald7c8ced22015-04-15 19:21:00 +00001462 }));
1463 var oldAuthor = firstGroup.getOperand(2).getOperand(0);
1464 oldAuthor.key("title");
1465 oldAuthor.value("Der Birnbaum");
1466
1467 // Structur is now:
1468 // or(doc, and(doc, doc, or(doc, doc)))
1469 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001470 'author = "Max Birkendale" | ' +
1471 '(pubDate since 2014-05-12 & ' +
1472 'pubDate until 2014-12-05 & ' +
1473 '(title = "Der Birnbaum" | ' +
1474 'pubDate in 2014-12-05))'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001475 );
1476
1477 var andGroup = vc.root().getOperand(1);
1478
1479 // Get leading docs in and
1480 var doc1 = andGroup.getOperand(0);
1481 expect(doc1.ldType()).toEqual("doc");
1482 expect(doc1.value()).toEqual("2014-05-12");
1483 var doc2 = andGroup.getOperand(1);
1484 expect(doc2.ldType()).toEqual("doc");
1485 expect(doc2.value()).toEqual("2014-12-05");
1486
1487 // Remove 2
1488 expect(
Akron712733a2018-04-05 18:17:47 +02001489 andGroup.delOperand(doc2).update().operation()
Nils Diewald7c8ced22015-04-15 19:21:00 +00001490 ).toEqual("and");
1491 // Structur is now:
1492 // or(doc, and(doc, or(doc, doc)))
1493
1494 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001495 'author = "Max Birkendale"' +
1496 ' | (pubDate since 2014-05-12 & ' +
1497 '(title = "Der Birnbaum" | pubDate in 2014-12-05))'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001498 );
1499
1500
1501 // Remove 1
1502 expect(andGroup.delOperand(doc1).update().operation()).toEqual("or");
1503 // Structur is now:
1504 // or(doc, doc, doc)
1505
1506 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001507 'author = "Max Birkendale" | title = "Der Birnbaum" | pubDate in 2014-12-05'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001508 );
1509 });
1510
1511 it('should be reducible to unspecification', function () {
1512 var vc = demoFactory.create();
1513
1514 expect(vc.toQuery()).toEqual(vc.root().toQuery());
1515 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001516 '(Titel = "Baum" & Veröffentlichungsort = "hihi" & ' +
1517 '(Titel = "Baum" | Veröffentlichungsort = "hihi")) ' +
1518 '| Untertitel ~ "huhu"');
Akrond141a362018-07-10 18:12:13 +02001519 expect(vc.root().element().lastChild.children[0].innerText).toEqual('and');
1520 expect(vc.root().element().lastChild.children[1].innerText).toEqual('×');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001521 expect(vc.root().delOperand(vc.root().getOperand(0)).update()).not.toBeUndefined();
Akron712733a2018-04-05 18:17:47 +02001522 expect(vc.toQuery()).toEqual('Untertitel ~ "huhu"');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001523
1524 var lc = vc.root().element().lastChild;
Akrond141a362018-07-10 18:12:13 +02001525 expect(lc.children[0].innerText).toEqual('and');
1526 expect(lc.children[1].innerText).toEqual('or');
1527 expect(lc.children[2].innerText).toEqual('×');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001528
1529 // Clean everything
1530 vc.clean();
1531 expect(vc.toQuery()).toEqual('');
1532 });
1533
1534 it('should flatten on import', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00001535 var vc = vcClass.create().fromJson({
Akron712733a2018-04-05 18:17:47 +02001536 "@type":"koral:docGroup",
1537 "operation":"operation:or",
1538 "operands":[
1539 {
1540 "@type":"koral:docGroup",
1541 "operation":"operation:or",
1542 "operands":[
Nils Diewald7c8ced22015-04-15 19:21:00 +00001543 {
Akron712733a2018-04-05 18:17:47 +02001544 "@type":"koral:doc",
1545 "key":"Titel",
1546 "value":"Baum",
1547 "match":"match:eq"
Nils Diewald7c8ced22015-04-15 19:21:00 +00001548 },
1549 {
Akron712733a2018-04-05 18:17:47 +02001550 "@type":"koral:doc",
1551 "key":"Veröffentlichungsort",
1552 "value":"hihi",
1553 "match":"match:eq"
Nils Diewald7c8ced22015-04-15 19:21:00 +00001554 },
1555 {
Akron712733a2018-04-05 18:17:47 +02001556 "@type":"koral:docGroup",
1557 "operation":"operation:or",
1558 "operands":[
1559 {
1560 "@type":"koral:doc",
1561 "key":"Titel",
1562 "value":"Baum",
1563 "match":"match:eq"
1564 },
1565 {
1566 "@type":"koral:doc",
1567 "key":"Veröffentlichungsort",
1568 "value":"hihi",
1569 "match":"match:eq"
1570 }
1571 ]
Nils Diewald7c8ced22015-04-15 19:21:00 +00001572 }
Akron712733a2018-04-05 18:17:47 +02001573 ]
1574 },
1575 {
1576 "@type":"koral:doc",
1577 "key":"Untertitel",
1578 "value":"huhu",
1579 "match":"match:contains"
1580 }
1581 ]
Nils Diewald7c8ced22015-04-15 19:21:00 +00001582 });
Nils Diewaldfda29d92015-01-22 17:28:01 +00001583
Nils Diewald7c8ced22015-04-15 19:21:00 +00001584 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001585 'Titel = "Baum" | Veröffentlichungsort = "hihi" | Untertitel ~ "huhu"'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001586 );
Nils Diewald86dad5b2015-01-28 15:09:07 +00001587 });
Akron1bdf5272018-07-24 18:51:30 +02001588
Akroncd42a142019-07-12 18:55:37 +02001589 it('should be deserializable from collection/corpus 1', function () {
Akron1bdf5272018-07-24 18:51:30 +02001590 var kq = {
1591 "matches":["..."],
1592 "collection":{
1593 "@type": "koral:docGroup",
1594 "operation": "operation:or",
1595 "operands": [{
1596 "@type": "koral:docGroup",
1597 "operation": "operation:and",
1598 "operands": [
1599 {
1600 "@type": "koral:doc",
1601 "key": "title",
1602 "match": "match:eq",
1603 "value": "Der Birnbaum",
1604 "type": "type:string"
1605 },
1606 {
1607 "@type": "koral:doc",
1608 "key": "pubPlace",
1609 "match": "match:eq",
1610 "value": "Mannheim",
1611 "type": "type:string"
1612 },
1613 {
1614 "@type": "koral:docGroup",
1615 "operation": "operation:or",
1616 "operands": [
1617 {
1618 "@type": "koral:doc",
1619 "key": "subTitle",
1620 "match": "match:eq",
1621 "value": "Aufzucht und Pflege",
1622 "type": "type:string"
1623 },
1624 {
1625 "@type": "koral:doc",
1626 "key": "subTitle",
1627 "match": "match:eq",
1628 "value": "Gedichte",
1629 "type": "type:string"
1630 }
1631 ]
1632 }
1633 ]
1634 },{
1635 "@type": "koral:doc",
1636 "key": "pubDate",
1637 "match": "match:geq",
1638 "value": "2015-03-05",
1639 "type": "type:date",
1640 "rewrites" : [{
1641 "@type" : "koral:rewrite",
1642 "operation" : "operation:modification",
1643 "src" : "querySerializer",
1644 "scope" : "tree"
1645 }]
1646 }]
1647 }
1648 };
1649
1650 var vc = vcClass.create().fromJson(kq["collection"]);
1651 expect(vc.toQuery()).toEqual('(title = "Der Birnbaum" & pubPlace = "Mannheim" & (subTitle = "Aufzucht und Pflege" | subTitle = "Gedichte")) | pubDate since 2015-03-05');
Akroncd42a142019-07-12 18:55:37 +02001652
1653 kq["corpus"] = kq["collection"]
1654 delete kq["collection"]
1655
1656 vc = vcClass.create().fromJson(kq["corpus"]);
1657 expect(vc.toQuery()).toEqual('(title = "Der Birnbaum" & pubPlace = "Mannheim" & (subTitle = "Aufzucht und Pflege" | subTitle = "Gedichte")) | pubDate since 2015-03-05');
1658
Akron1bdf5272018-07-24 18:51:30 +02001659 });
1660
1661 it('should be deserializable from collection 2', function () {
1662 var kq = {
1663 "@context": "http://korap.ids-mannheim.de/ns/KoralQuery/v0.3/context.jsonld",
1664 "meta": {},
1665 "query": {
1666 "@type": "koral:token",
1667 "wrap": {
1668 "@type": "koral:term",
1669 "match": "match:eq",
1670 "layer": "orth",
1671 "key": "Baum",
1672 "foundry": "opennlp",
1673 "rewrites": [
1674 {
1675 "@type": "koral:rewrite",
1676 "src": "Kustvakt",
1677 "operation": "operation:injection",
1678 "scope": "foundry"
1679 }
1680 ]
1681 },
1682 "idn": "Baum_2227",
1683 "rewrites": [
1684 {
1685 "@type": "koral:rewrite",
1686 "src": "Kustvakt",
1687 "operation": "operation:injection",
1688 "scope": "idn"
1689 }
1690 ]
1691 },
1692 "collection": {
1693 "@type": "koral:docGroup",
1694 "operation": "operation:and",
1695 "operands": [
1696 {
1697 "@type": "koral:doc",
1698 "match": "match:eq",
1699 "type": "type:regex",
1700 "value": "CC-BY.*",
1701 "key": "availability"
1702 },
1703 {
1704 "@type": "koral:doc",
1705 "match": "match:eq",
1706 "type":"type:text",
1707 "value": "Goethe",
1708 "key": "author"
1709 }
1710 ],
1711 "rewrites": [
1712 {
1713 "@type": "koral:rewrite",
1714 "src": "Kustvakt",
1715 "operation": "operation:insertion",
1716 "scope": "availability(FREE)"
1717 }
1718 ]
1719 },
1720 "matches": []
1721 };
1722
1723 var vc = vcClass.create().fromJson(kq["collection"]);
1724 expect(vc.toQuery()).toEqual('availability = /CC-BY.*/ & author = "Goethe"');
1725 });
Nils Diewald86dad5b2015-01-28 15:09:07 +00001726
Akroncd42a142019-07-12 18:55:37 +02001727
Akron8a670162018-08-28 10:09:13 +02001728 it('shouldn\'t be deserializable from collection with unknown type', function () {
1729 var kq = {
1730 "@type" : "koral:doc",
1731 "match": "match:eq",
1732 "type":"type:failure",
1733 "value": "Goethe",
1734 "key": "author"
1735 };
Akron1bdf5272018-07-24 18:51:30 +02001736
Akron8a670162018-08-28 10:09:13 +02001737 expect(function () {
1738 vcClass.create().fromJson(kq)
1739 }).toThrow(new Error("Unknown value type: string"));
1740 });
1741
1742 it('should return a name', function () {
1743 var vc = vcClass.create();
1744 expect(vc.getName()).toEqual(KorAP.Locale.VC_allCorpora);
1745
1746 vc = vcClass.create().fromJson({"@type" : "koral:docGroupRef", "ref" : "DeReKo"});
1747 expect(vc.getName()).toEqual("DeReKo");
1748
1749 vc = vcClass.create().fromJson({"@type" : "koral:doc", "key" : "author", "value" : "Peter"});
1750 expect(vc.getName()).toEqual(KorAP.Locale.VC_oneCollection);
1751 });
Akrond2474aa2018-08-28 12:06:27 +02001752
1753 it('should check for rewrites', function () {
1754
1755 var vc = vcClass.create().fromJson({
1756 "@type" : "koral:doc",
1757 "key" : "author",
1758 "value" : "Goethe",
1759 "rewrites" : [{
1760 "@type" : "koral:rewrite",
1761 "operation" : "operation:modification",
1762 "src" : "querySerializer",
1763 "scope" : "value"
1764 }]
1765 });
1766 expect(vc.wasRewritten()).toBeTruthy();
1767
1768 var nested = {
1769 "@type" : "koral:docGroup",
1770 "operation" : "operation:or",
1771 "operands" : [
1772 {
1773 "@type" : "koral:doc",
1774 "key" : "author",
1775 "value" : "Goethe"
1776 },
1777 {
1778 "@type" : "koral:docGroup",
1779 "operation" : "operation:and",
1780 "operands" : [
1781 {
1782 "@type": "koral:doc",
1783 "key" : "author",
1784 "value" : "Schiller"
1785 },
1786 {
1787 "@type": "koral:doc",
1788 "key" : "author",
1789 "value" : "Fontane"
1790 }
1791 ]
1792 }
1793 ]
1794 };
1795 vc = vcClass.create().fromJson(nested);
1796 expect(vc.wasRewritten()).toBe(false);
1797
1798 nested["operands"][1]["operands"][1]["rewrites"] = [{
1799 "@type" : "koral:rewrite",
1800 "operation" : "operation:modification",
1801 "src" : "querySerializer",
1802 "scope" : "tree"
1803 }];
1804 vc = vcClass.create().fromJson(nested);
1805 expect(vc.wasRewritten()).toBeTruthy();
1806 });
Akron4feec9d2018-11-20 17:00:50 +01001807
1808 it('should add document at virtual corpus', function () {
1809 vc = vcClass.create();
1810 expect(vc.toQuery()).toEqual("");
1811
1812 let doc = docClass.create();
1813 doc.key("author");
1814 doc.type("string");
1815 doc.matchop("eq");
1816 doc.value("Goethe");
1817 expect(doc.toQuery()).toEqual('author = "Goethe"');
1818
1819 expect(vc.element().firstChild.children.length).toEqual(1);
1820 expect(vc.element().firstChild.firstChild.classList.contains("unspecified")).toBeTruthy();
1821
1822 vc.addRequired(doc);
1823 expect(vc.toQuery()).toEqual('author = "Goethe"');
1824
1825 expect(vc.element().firstChild.children.length).toEqual(1);
1826 expect(vc.element().firstChild.firstChild.classList.contains("doc")).toBeTruthy();
1827
1828 // Add as 'and' to doc
1829 let doc2 = docClass.create();
1830 doc2.key("author");
1831 doc2.type("string");
1832 doc2.matchop("eq");
1833 doc2.value("Schiller");
1834 vc.addRequired(doc2);
1835 expect(vc.toQuery()).toEqual('author = "Goethe" & author = "Schiller"');
1836
1837 expect(vc.element().firstChild.firstChild.classList.contains("docGroup")).toBeTruthy();
1838 expect(vc.element().firstChild.firstChild.children[0].classList.contains("doc")).toBeTruthy();
1839 expect(vc.element().firstChild.firstChild.children[1].classList.contains("doc")).toBeTruthy();
1840
1841
1842 // Add as 'and' to 'and'-docGroup
1843 let doc3 = docClass.create();
1844 doc3.key("author");
1845 doc3.type("string");
1846 doc3.matchop("eq");
1847 doc3.value("Fontane");
1848 vc.addRequired(doc3);
1849 expect(vc.toQuery()).toEqual('author = "Goethe" & author = "Schiller" & author = "Fontane"');
1850
1851 expect(vc.element().firstChild.firstChild.classList.contains("docGroup")).toBeTruthy();
1852 expect(vc.element().firstChild.firstChild.children[0].classList.contains("doc")).toBeTruthy();
1853 expect(vc.element().firstChild.firstChild.children[1].classList.contains("doc")).toBeTruthy();
1854 expect(vc.element().firstChild.firstChild.children[2].classList.contains("doc")).toBeTruthy();
1855
1856 // Add as 'and' to 'or'-docGroup
1857 vc = vcClass.create().fromJson({
1858 "@type" : 'koral:docGroup',
1859 'operation' : 'operation:or',
1860 'operands' : [
1861 {
1862 '@type' : 'koral:doc',
1863 'key' : 'title',
1864 'value' : 'Hello World!'
1865 },
1866 {
1867 '@type' : 'koral:doc',
1868 'key' : 'foo',
1869 'value' : 'bar'
1870 }
1871 ]
1872 });
1873 expect(vc.toQuery()).toEqual('title = "Hello World!" | foo = "bar"');
1874
1875 let doc4 = docClass.create();
1876 doc4.key("author");
1877 doc4.type("string");
1878 doc4.matchop("eq");
1879 doc4.value("Fontane");
1880 vc.addRequired(doc4);
1881 expect(vc.toQuery()).toEqual('(title = "Hello World!" | foo = "bar") & author = "Fontane"');
1882
1883 // Add as 'and' to 'or'-docGroup
1884 vc = vcClass.create().fromJson({
1885 "@type" : "koral:docGroupRef",
1886 "ref" : "@max/myCorpus"
1887 })
1888 let doc5 = docClass.create();
1889 doc5.key("author");
1890 doc5.type("string");
1891 doc5.matchop("eq");
1892 doc5.value("Goethe");
1893 expect(doc5.toQuery()).toEqual('author = "Goethe"');
1894 vc.addRequired(doc5);
1895 expect(vc.toQuery()).toEqual('referTo "@max/myCorpus" & author = "Goethe"');
1896 });
Akron13af2f42019-07-25 15:06:21 +02001897
1898 it('should be replaceble via JSON', function () {
1899 let vc = KorAP.vc = vcClass.create().fromJson({
1900 "@type" : 'koral:docGroup',
1901 'operation' : 'operation:or',
1902 'operands' : [
1903 {
1904 '@type' : 'koral:doc',
1905 'key' : 'title',
1906 'value' : 'Hello World!'
1907 },
1908 {
1909 '@type' : 'koral:doc',
1910 'key' : 'foo',
1911 'value' : 'bar'
1912 }
1913 ]
1914 });
1915
1916 expect(vc.toQuery()).toEqual('title = "Hello World!" | foo = "bar"')
1917
1918 let e = vc.element();
1919 expect(e.firstChild.firstChild.firstChild.children[0].textContent).toEqual("title");
1920 expect(e.firstChild.firstChild.firstChild.children[2].textContent).toEqual("Hello World!");
1921
1922 vc.fromJson({
1923 '@type' : 'koral:doc',
1924 'key' : 'foo',
1925 'value' : 'bar'
1926 });
1927
1928 expect(vc.toQuery()).toEqual('foo = "bar"');
1929 e = vc.element();
1930 expect(e.firstChild.firstChild.children[0].textContent).toEqual("foo");
1931 expect(e.firstChild.firstChild.children[2].textContent).toEqual("bar");
1932 })
Akron1bdf5272018-07-24 18:51:30 +02001933 });
1934
1935
Akron88d237e2020-10-21 08:05:18 +02001936 describe('KorAP.VC.Operators', function () {
Nils Diewald7c8ced22015-04-15 19:21:00 +00001937 it('should be initializable', function () {
1938 var op = operatorsClass.create(true, false, false);
1939 expect(op.and()).toBeTruthy();
1940 expect(op.or()).not.toBeTruthy();
1941 expect(op.del()).not.toBeTruthy();
1942
1943 op.and(false);
1944 expect(op.and()).not.toBeTruthy();
1945 expect(op.or()).not.toBeTruthy();
1946 expect(op.del()).not.toBeTruthy();
1947
1948 op.or(true);
1949 op.del(true);
1950 expect(op.and()).not.toBeTruthy();
1951 expect(op.or()).toBeTruthy();
1952 expect(op.del()).toBeTruthy();
1953
Akrond141a362018-07-10 18:12:13 +02001954 var e = op.update();
Akron0b489ad2018-02-02 16:49:32 +01001955 expect(e.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001956 expect(e.children[0].getAttribute('class')).toEqual('or');
Akrond141a362018-07-10 18:12:13 +02001957 expect(e.children[0].innerText).toEqual('or');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001958 expect(e.children[1].getAttribute('class')).toEqual('delete');
Akrond141a362018-07-10 18:12:13 +02001959 expect(e.children[1].innerText).toEqual('×');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001960
1961 op.and(true);
1962 op.del(false);
Akrond141a362018-07-10 18:12:13 +02001963 e = op.update();
Nils Diewald7c8ced22015-04-15 19:21:00 +00001964
Akron0b489ad2018-02-02 16:49:32 +01001965 expect(e.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001966 expect(e.children[0].getAttribute('class')).toEqual('and');
Akrond141a362018-07-10 18:12:13 +02001967 expect(e.children[0].innerText).toEqual('and');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001968 expect(e.children[1].getAttribute('class')).toEqual('or');
Akrond141a362018-07-10 18:12:13 +02001969 expect(e.children[1].innerText).toEqual('or');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001970 });
1971 });
1972
Akron88d237e2020-10-21 08:05:18 +02001973 describe('KorAP.VC._delete (event)', function () {
Nils Diewald7c8ced22015-04-15 19:21:00 +00001974 var complexVCFactory = buildFactory(vcClass,{
1975 "@type": 'koral:docGroup',
1976 'operation' : 'operation:and',
1977 'operands' : [
Akron712733a2018-04-05 18:17:47 +02001978 {
1979 "@type": 'koral:doc',
1980 "key": 'pubDate',
1981 "match": 'match:eq',
1982 "value": '2014-12-05',
1983 "type": 'type:date'
1984 },
1985 {
1986 "@type" : 'koral:docGroup',
1987 'operation' : 'operation:or',
1988 'operands' : [
1989 {
1990 '@type' : 'koral:doc',
1991 'key' : 'title',
1992 'value' : 'Hello World!'
1993 },
1994 {
1995 '@type' : 'koral:doc',
1996 'key' : 'foo',
1997 'value' : 'bar'
1998 }
1999 ]
2000 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00002001 ]
2002 });
2003
2004 it('should clean on root docs', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00002005 var vc = vcClass.create().fromJson({
Akron712733a2018-04-05 18:17:47 +02002006 "@type": 'koral:doc',
2007 "key": 'pubDate',
2008 "match": 'match:eq',
2009 "value": '2014-12-05',
2010 "type": 'type:date'
Nils Diewald86dad5b2015-01-28 15:09:07 +00002011 });
Nils Diewald7c8ced22015-04-15 19:21:00 +00002012 expect(vc.root().toQuery()).toEqual('pubDate in 2014-12-05');
Akron0b489ad2018-02-02 16:49:32 +01002013 expect(vc.root().element().lastChild.getAttribute('class')).toEqual('operators button-group');
Nils Diewald86dad5b2015-01-28 15:09:07 +00002014
Nils Diewald7c8ced22015-04-15 19:21:00 +00002015 // Clean with delete from root
2016 expect(vc.root().element().lastChild.lastChild.getAttribute('class')).toEqual('delete');
2017 _delOn(vc.root());
2018 expect(vc.root().toQuery()).toEqual('');
Akronebc96662018-08-29 17:36:20 +02002019 expect(vc.root().element().lastChild.lastChild.data).toEqual(KorAP.Locale.EMPTY);
2020 expect(vc.root().element().classList.contains('unspecified')).toEqual(true);
Nils Diewald7c8ced22015-04-15 19:21:00 +00002021 });
Nils Diewald86dad5b2015-01-28 15:09:07 +00002022
Nils Diewald7c8ced22015-04-15 19:21:00 +00002023 it('should remove on nested docs', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00002024 var vc = vcClass.create().fromJson(
Akron712733a2018-04-05 18:17:47 +02002025 {
2026 "@type": 'koral:docGroup',
2027 'operation' : 'operation:and',
2028 'operands' : [
2029 {
2030 "@type": 'koral:doc',
2031 "key": 'pubDate',
2032 "match": 'match:eq',
2033 "value": '2014-12-05',
2034 "type": 'type:date'
2035 },
2036 {
2037 "@type" : 'koral:doc',
2038 'key' : 'foo',
2039 'value' : 'bar'
2040 }
2041 ]
2042 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00002043 );
2044
2045 // Delete with direct element access
2046 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar"');
2047 _delOn(vc.root().getOperand(0));
2048
2049 expect(vc.toQuery()).toEqual('foo = "bar"');
2050 expect(vc.root().ldType()).toEqual('doc');
2051 });
2052
2053 it('should clean on doc groups', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00002054 var vc = vcClass.create().fromJson(
Akron712733a2018-04-05 18:17:47 +02002055 {
2056 "@type": 'koral:docGroup',
2057 'operation' : 'operation:and',
2058 'operands' : [
2059 {
2060 "@type": 'koral:doc',
2061 "key": 'pubDate',
2062 "match": 'match:eq',
2063 "value": '2014-12-05',
2064 "type": 'type:date'
2065 },
2066 {
2067 "@type" : 'koral:doc',
2068 'key' : 'foo',
2069 'value' : 'bar'
2070 }
2071 ]
2072 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00002073 );
2074
2075 // Cleanwith direct element access
2076 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar"');
2077 _delOn(vc.root());
2078 expect(vc.toQuery()).toEqual('');
2079 expect(vc.root().ldType()).toEqual('non');
2080 });
2081
2082 it('should remove on nested doc groups (case of ungrouping 1)', function () {
2083 var vc = complexVCFactory.create();
2084
2085 // Delete with direct element access
2086 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02002087 'pubDate in 2014-12-05 & (title = "Hello World!" | foo = "bar")'
Nils Diewald7c8ced22015-04-15 19:21:00 +00002088 );
2089
2090 // Remove hello world:
2091 _delOn(vc.root().getOperand(1).getOperand(0));
2092 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar"');
2093 expect(vc.root().ldType()).toEqual('docGroup');
2094 });
2095
2096 it('should remove on nested doc groups (case of ungrouping 2)', function () {
2097 var vc = complexVCFactory.create();
2098
2099 // Delete with direct element access
2100 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02002101 'pubDate in 2014-12-05 & (title = "Hello World!" | foo = "bar")'
Nils Diewald7c8ced22015-04-15 19:21:00 +00002102 );
2103
2104 // Remove bar
2105 _delOn(vc.root().getOperand(1).getOperand(1));
2106 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & title = "Hello World!"');
2107 expect(vc.root().ldType()).toEqual('docGroup');
2108 expect(vc.root().operation()).toEqual('and');
2109 });
2110
2111 it('should remove on nested doc groups (case of root changing)', function () {
2112 var vc = complexVCFactory.create();
2113
2114 // Delete with direct element access
2115 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02002116 'pubDate in 2014-12-05 & ' +
2117 '(title = "Hello World!" | foo = "bar")'
Nils Diewald7c8ced22015-04-15 19:21:00 +00002118 );
2119
2120 // Remove bar
2121 _delOn(vc.root().getOperand(0));
2122 expect(vc.toQuery()).toEqual('title = "Hello World!" | foo = "bar"');
2123 expect(vc.root().ldType()).toEqual('docGroup');
2124 expect(vc.root().operation()).toEqual('or');
2125 });
2126
2127 it('should remove on nested doc groups (list flattening)', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00002128 var vc = vcClass.create().fromJson(
Akron712733a2018-04-05 18:17:47 +02002129 {
2130 "@type": 'koral:docGroup',
2131 'operation' : 'operation:or',
2132 'operands' : [
2133 {
2134 "@type": 'koral:doc',
2135 "key": 'pubDate',
2136 "match": 'match:eq',
2137 "value": '2014-12-05',
2138 "type": 'type:date'
2139 },
2140 {
2141 "@type" : 'koral:doc',
2142 'key' : 'foo',
2143 'value' : 'bar'
2144 },
2145 {
2146 "@type": 'koral:docGroup',
2147 'operation' : 'operation:and',
2148 'operands' : [
2149 {
2150 "@type": 'koral:doc',
2151 "key": 'pubDate',
2152 "match": 'match:eq',
2153 "value": '2014-12-05',
2154 "type": 'type:date'
2155 },
2156 {
2157 "@type" : 'koral:docGroup',
2158 'operation' : 'operation:or',
2159 'operands' : [
2160 {
2161 '@type' : 'koral:doc',
2162 'key' : 'title',
2163 'value' : 'Hello World!'
2164 },
2165 {
2166 '@type' : 'koral:doc',
2167 'key' : 'yeah',
2168 'value' : 'juhu'
2169 }
2170 ]
2171 }
2172 ]
2173 }
2174 ]
2175 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00002176 );
2177
2178 // Delete with direct element access
2179 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02002180 'pubDate in 2014-12-05 | foo = "bar" | ' +
2181 '(pubDate in 2014-12-05 & ' +
2182 '(title = "Hello World!" | yeah = "juhu"))'
Nils Diewald7c8ced22015-04-15 19:21:00 +00002183 );
2184
2185 expect(vc.root().ldType()).toEqual('docGroup');
2186 expect(vc.root().operation()).toEqual('or');
2187
2188 // Operands and operators
Akronadab5e52018-08-20 13:50:53 +02002189 expect(vc.builder().firstChild.children.length).toEqual(4);
2190 expect(vc.builder().firstChild.lastChild.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +00002191
2192 // Remove inner group and flatten
2193 _delOn(vc.root().getOperand(2).getOperand(0));
2194
2195 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02002196 'pubDate in 2014-12-05 | foo = "bar" | title = "Hello World!" | yeah = "juhu"'
Nils Diewald7c8ced22015-04-15 19:21:00 +00002197 );
2198 expect(vc.root().ldType()).toEqual('docGroup');
2199 expect(vc.root().operation()).toEqual('or');
2200
2201 // Operands and operators
Akronadab5e52018-08-20 13:50:53 +02002202 expect(vc.builder().firstChild.children.length).toEqual(5);
2203 expect(vc.builder().firstChild.lastChild.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +00002204 });
2205 });
2206
Akron88d237e2020-10-21 08:05:18 +02002207 describe('KorAP.VC._add (event)', function () {
Nils Diewald7c8ced22015-04-15 19:21:00 +00002208 var complexVCFactory = buildFactory(vcClass,{
2209 "@type": 'koral:docGroup',
2210 'operation' : 'operation:and',
2211 'operands' : [
Akron712733a2018-04-05 18:17:47 +02002212 {
2213 "@type": 'koral:doc',
2214 "key": 'pubDate',
2215 "match": 'match:eq',
2216 "value": '2014-12-05',
2217 "type": 'type:date'
2218 },
2219 {
2220 "@type" : 'koral:docGroup',
2221 'operation' : 'operation:or',
2222 'operands' : [
2223 {
2224 '@type' : 'koral:doc',
2225 'key' : 'title',
2226 'value' : 'Hello World!'
2227 },
2228 {
2229 '@type' : 'koral:doc',
2230 'key' : 'foo',
2231 'value' : 'bar'
2232 }
2233 ]
2234 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00002235 ]
2236 });
2237
2238 it('should add new unspecified doc with "and"', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00002239 var vc = vcClass.create().fromJson(
Akron712733a2018-04-05 18:17:47 +02002240 {
2241 "@type": 'koral:docGroup',
2242 'operation' : 'operation:and',
2243 'operands' : [
2244 {
2245 "@type": 'koral:doc',
2246 "key": 'pubDate',
2247 "match": 'match:eq',
2248 "value": '2014-12-05',
2249 "type": 'type:date'
2250 },
2251 {
2252 "@type" : 'koral:doc',
2253 'key' : 'foo',
2254 'value' : 'bar'
Akronb19803c2018-08-16 16:39:42 +02002255 },
2256 {
2257 "@type" : "koral:docGroupRef",
2258 "ref" : "myCorpus"
Akron712733a2018-04-05 18:17:47 +02002259 }
2260 ]
2261 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00002262 );
2263
Akronb19803c2018-08-16 16:39:42 +02002264 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar" & referTo "myCorpus"');
Nils Diewald7c8ced22015-04-15 19:21:00 +00002265
Akronadab5e52018-08-20 13:50:53 +02002266 var fc = vc.builder().firstChild;
Nils Diewald7c8ced22015-04-15 19:21:00 +00002267 expect(fc.getAttribute('data-operation')).toEqual('and');
Akronb19803c2018-08-16 16:39:42 +02002268 expect(fc.children.length).toEqual(4);
Akron0b489ad2018-02-02 16:49:32 +01002269 expect(fc.lastChild.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +00002270 expect(fc.children[0].getAttribute('class')).toEqual('doc');
2271 expect(fc.children[1].getAttribute('class')).toEqual('doc');
Akronb19803c2018-08-16 16:39:42 +02002272 expect(fc.children[2].getAttribute('class')).toEqual('doc groupref');
Nils Diewald7c8ced22015-04-15 19:21:00 +00002273
2274 // add with 'and' in the middle
2275 _andOn(vc.root().getOperand(0));
Akronb19803c2018-08-16 16:39:42 +02002276 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar" & referTo "myCorpus"');
Nils Diewald7c8ced22015-04-15 19:21:00 +00002277
Akronadab5e52018-08-20 13:50:53 +02002278 fc = vc.builder().firstChild;
Nils Diewald7c8ced22015-04-15 19:21:00 +00002279 expect(fc.getAttribute('data-operation')).toEqual('and');
Akronb19803c2018-08-16 16:39:42 +02002280 expect(fc.children.length).toEqual(5);
Akron0b489ad2018-02-02 16:49:32 +01002281 expect(fc.lastChild.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +00002282
2283 expect(fc.children[0].getAttribute('class')).toEqual('doc');
2284 expect(fc.children[1].getAttribute('class')).toEqual('doc unspecified');
2285 expect(fc.children[2].getAttribute('class')).toEqual('doc');
Akronb19803c2018-08-16 16:39:42 +02002286 expect(fc.children[3].getAttribute('class')).toEqual('doc groupref');
2287 expect(fc.children[4].classList.contains('button-group')).toBeTruthy();
2288 expect(fc.children.length).toEqual(5);
2289
2290 _andOn(vc.root().getOperand(3));
2291 expect(fc.children[0].getAttribute('class')).toEqual('doc');
2292 expect(fc.children[1].getAttribute('class')).toEqual('doc unspecified');
2293 expect(fc.children[2].getAttribute('class')).toEqual('doc');
2294 expect(fc.children[3].getAttribute('class')).toEqual('doc groupref');
2295 expect(fc.children[4].getAttribute('class')).toEqual('doc unspecified');
2296 expect(fc.children[5].classList.contains('button-group')).toBeTruthy();
2297 expect(fc.children.length).toEqual(6);
2298
Nils Diewald7c8ced22015-04-15 19:21:00 +00002299 });
2300
Akronb19803c2018-08-16 16:39:42 +02002301
Nils Diewald7c8ced22015-04-15 19:21:00 +00002302 it('should add new unspecified doc with "or"', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00002303 var vc = vcClass.create().fromJson(
Akron712733a2018-04-05 18:17:47 +02002304 {
2305 "@type": 'koral:docGroup',
2306 'operation' : 'operation:and',
2307 'operands' : [
2308 {
2309 "@type": 'koral:doc',
2310 "key": 'pubDate',
2311 "match": 'match:eq',
2312 "value": '2014-12-05',
2313 "type": 'type:date'
2314 },
2315 {
2316 "@type" : 'koral:doc',
2317 'key' : 'foo',
2318 'value' : 'bar'
Akronb19803c2018-08-16 16:39:42 +02002319 },
2320 {
2321 "@type" : "koral:docGroupRef",
2322 "ref" : "myCorpus"
Akron712733a2018-04-05 18:17:47 +02002323 }
2324 ]
2325 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00002326 );
2327
Akronb19803c2018-08-16 16:39:42 +02002328 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar" & referTo "myCorpus"');
Nils Diewald7c8ced22015-04-15 19:21:00 +00002329
Akronadab5e52018-08-20 13:50:53 +02002330 var fc = vc.builder().firstChild;
Akronb19803c2018-08-16 16:39:42 +02002331 expect(fc.children.length).toEqual(4);
Akron0b489ad2018-02-02 16:49:32 +01002332 expect(fc.lastChild.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +00002333 expect(fc.children[0].getAttribute('class')).toEqual('doc');
2334 expect(fc.children[1].getAttribute('class')).toEqual('doc');
Akronb19803c2018-08-16 16:39:42 +02002335 expect(fc.children[2].getAttribute('class')).toEqual('doc groupref');
Nils Diewald7c8ced22015-04-15 19:21:00 +00002336
2337 // add with 'or' in the middle
2338 _orOn(vc.root().getOperand(0));
Akronb19803c2018-08-16 16:39:42 +02002339 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar" & referTo "myCorpus"');
Akronadab5e52018-08-20 13:50:53 +02002340 fc = vc.builder().firstChild;
Nils Diewald7c8ced22015-04-15 19:21:00 +00002341
2342 expect(fc.getAttribute('data-operation')).toEqual('and');
Akronb19803c2018-08-16 16:39:42 +02002343 expect(fc.children.length).toEqual(4);
Nils Diewald7c8ced22015-04-15 19:21:00 +00002344 expect(fc.children[0].getAttribute('class')).toEqual('docGroup');
2345 expect(fc.children[0].getAttribute('data-operation')).toEqual('or');
2346 expect(fc.children[1].getAttribute('class')).toEqual('doc');
Akronb19803c2018-08-16 16:39:42 +02002347 expect(fc.children[2].getAttribute('class')).toEqual('doc groupref');
2348 expect(fc.children[3].getAttribute('class')).toEqual('operators button-group');
Akron0b489ad2018-02-02 16:49:32 +01002349 expect(fc.lastChild.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +00002350
Akronadab5e52018-08-20 13:50:53 +02002351 fc = vc.builder().firstChild.firstChild;
Nils Diewald7c8ced22015-04-15 19:21:00 +00002352 expect(fc.children.length).toEqual(3);
2353 expect(fc.children[0].getAttribute('class')).toEqual('doc');
2354 expect(fc.children[1].getAttribute('class')).toEqual('doc unspecified');
Akron0b489ad2018-02-02 16:49:32 +01002355 expect(fc.children[2].getAttribute('class')).toEqual('operators button-group');
2356 expect(fc.lastChild.getAttribute('class')).toEqual('operators button-group');
Akronb19803c2018-08-16 16:39:42 +02002357
2358 _orOn(vc.root().getOperand(2));
Akronadab5e52018-08-20 13:50:53 +02002359 fc = vc.builder().firstChild;
Akronb19803c2018-08-16 16:39:42 +02002360 expect(fc.children.length).toEqual(4);
2361
2362 expect(fc.children[0].getAttribute('class')).toEqual('docGroup');
2363 expect(fc.children[1].getAttribute('class')).toEqual('doc');
2364 expect(fc.children[2].getAttribute('class')).toEqual('docGroup');
2365 expect(fc.children[3].getAttribute('class')).toEqual('operators button-group');
2366
Akronadab5e52018-08-20 13:50:53 +02002367 fc = vc.builder().firstChild.children[2];
Akronb19803c2018-08-16 16:39:42 +02002368 expect(fc.children[0].getAttribute('class')).toEqual('doc groupref');
2369 expect(fc.children[1].getAttribute('class')).toEqual('doc unspecified');
2370 expect(fc.children[2].getAttribute('class')).toEqual('operators button-group');
2371 expect(fc.lastChild.getAttribute('class')).toEqual('operators button-group');
2372
Nils Diewald7c8ced22015-04-15 19:21:00 +00002373 });
2374
2375 it('should add new unspecified doc with "and" before group', function () {
2376 var vc = demoFactory.create();
2377
2378 // Wrap with direct element access
2379 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02002380 '(Titel = "Baum" & ' +
2381 'Veröffentlichungsort = "hihi" & ' +
2382 '(Titel = "Baum" | ' +
2383 'Veröffentlichungsort = "hihi")) | ' +
2384 'Untertitel ~ "huhu"'
Nils Diewald7c8ced22015-04-15 19:21:00 +00002385 );
2386
2387 expect(vc.root().getOperand(0).ldType()).toEqual('docGroup');
2388 expect(vc.root().getOperand(0).operation()).toEqual('and');
2389 expect(vc.root().getOperand(0).operands().length).toEqual(3);
2390
2391 // Add unspecified on the second doc
2392 var secDoc = vc.root().getOperand(0).getOperand(1);
2393 expect(secDoc.value()).toEqual('hihi');
2394
2395 // Add
2396 _andOn(secDoc);
2397
2398 var fo = vc.root().getOperand(0);
2399
2400 expect(fo.ldType()).toEqual('docGroup');
2401 expect(fo.operation()).toEqual('and');
2402 expect(fo.operands().length).toEqual(4);
2403
2404 expect(fo.getOperand(0).ldType()).toEqual('doc');
2405 expect(fo.getOperand(1).ldType()).toEqual('doc');
2406 expect(fo.getOperand(2).ldType()).toEqual('non');
2407 expect(fo.getOperand(3).ldType()).toEqual('docGroup');
2408 });
2409
2410
2411 it('should remove a doc with an unspecified doc in a nested group', function () {
2412 var vc = demoFactory.create();
2413
2414 // Wrap with direct element access
2415 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02002416 '(Titel = "Baum" & Veröffentlichungsort = "hihi" & (Titel = "Baum" | Veröffentlichungsort = "hihi")) | Untertitel ~ "huhu"'
Nils Diewald7c8ced22015-04-15 19:21:00 +00002417 );
2418
2419 var fo = vc.root().getOperand(0).getOperand(0);
2420 expect(fo.key()).toEqual('Titel');
2421 expect(fo.value()).toEqual('Baum');
2422
2423 // Add unspecified on the root group
2424 _orOn(fo);
2425
2426 fo = vc.root().getOperand(0).getOperand(0);
2427
2428 expect(fo.operation()).toEqual('or');
2429 expect(fo.getOperand(0).ldType()).toEqual('doc');
2430 expect(fo.getOperand(1).ldType()).toEqual('non');
2431
2432 // Delete document
2433 _delOn(fo.getOperand(0));
2434
2435 // The operand is now non
2436 expect(vc.root().getOperand(0).getOperand(0).ldType()).toEqual('non');
2437 expect(vc.root().getOperand(0).getOperand(1).ldType()).toEqual('doc');
2438 expect(vc.root().getOperand(0).getOperand(2).ldType()).toEqual('docGroup');
2439 });
2440
2441
Akron712733a2018-04-05 18:17:47 +02002442 it('should remove an unspecified doc with a doc in a nested group', function () {
Nils Diewald7c8ced22015-04-15 19:21:00 +00002443 var vc = demoFactory.create();
2444
2445 // Wrap with direct element access
2446 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02002447 '(Titel = "Baum" & ' +
2448 'Veröffentlichungsort = "hihi" & ' +
2449 '(Titel = "Baum" ' +
2450 '| Veröffentlichungsort = "hihi")) | ' +
2451 'Untertitel ~ "huhu"'
Nils Diewald7c8ced22015-04-15 19:21:00 +00002452 );
2453
2454 var fo = vc.root().getOperand(0).getOperand(0);
2455 expect(fo.key()).toEqual('Titel');
2456 expect(fo.value()).toEqual('Baum');
2457
2458 // Add unspecified on the root group
2459 _orOn(fo);
2460
2461 fo = vc.root().getOperand(0).getOperand(0);
2462
2463 expect(fo.operation()).toEqual('or');
2464 expect(fo.getOperand(0).ldType()).toEqual('doc');
2465 expect(fo.getOperand(1).ldType()).toEqual('non');
2466
2467 // Delete unspecified doc
2468 _delOn(fo.getOperand(1));
2469
2470 // The operand is now non
2471 fo = vc.root().getOperand(0);
2472 expect(fo.getOperand(0).ldType()).toEqual('doc');
2473 expect(fo.getOperand(0).key()).toEqual('Titel');
2474 expect(fo.getOperand(0).value()).toEqual('Baum');
2475 expect(fo.getOperand(1).ldType()).toEqual('doc');
2476 expect(fo.getOperand(2).ldType()).toEqual('docGroup');
2477 });
2478
2479
2480 it('should add on parent group (case "and")', function () {
2481 var vc = complexVCFactory.create();
2482
2483 // Wrap with direct element access
2484 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02002485 'pubDate in 2014-12-05 & (title = "Hello World!" | foo = "bar")'
Nils Diewald7c8ced22015-04-15 19:21:00 +00002486 );
2487
2488 expect(vc.root().operands().length).toEqual(2);
2489
2490 // Add unspecified on the root group
2491 _andOn(vc.root().getOperand(1));
2492 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02002493 'pubDate in 2014-12-05 & (title = "Hello World!" | foo = "bar")'
Nils Diewald7c8ced22015-04-15 19:21:00 +00002494 );
2495
2496 expect(vc.root().ldType()).toEqual('docGroup');
2497 expect(vc.root().operands().length).toEqual(3);
2498 expect(vc.root().getOperand(0).ldType()).toEqual('doc');
2499 expect(vc.root().getOperand(1).ldType()).toEqual('docGroup');
2500 expect(vc.root().getOperand(1).operation()).toEqual('or');
2501 expect(vc.root().getOperand(2).ldType()).toEqual('non');
2502
2503 // Add another unspecified on the root group
2504 _andOn(vc.root().getOperand(1));
2505
2506 expect(vc.root().operands().length).toEqual(4);
2507 expect(vc.root().getOperand(0).ldType()).toEqual('doc');
2508 expect(vc.root().getOperand(1).ldType()).toEqual('docGroup');
2509 expect(vc.root().getOperand(2).ldType()).toEqual('non');
2510 expect(vc.root().getOperand(3).ldType()).toEqual('non');
2511
2512 // Add another unspecified after the first doc
2513 _andOn(vc.root().getOperand(0));
2514
2515 expect(vc.root().operands().length).toEqual(5);
2516 expect(vc.root().getOperand(0).ldType()).toEqual('doc');
2517 expect(vc.root().getOperand(1).ldType()).toEqual('non');
2518 expect(vc.root().getOperand(2).ldType()).toEqual('docGroup');
2519 expect(vc.root().getOperand(3).ldType()).toEqual('non');
2520 expect(vc.root().getOperand(4).ldType()).toEqual('non');
2521 });
2522
2523 it('should wrap on root', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00002524 var vc = vcClass.create().fromJson(
Akron712733a2018-04-05 18:17:47 +02002525 {
2526 "@type": 'koral:docGroup',
2527 'operation' : 'operation:and',
2528 'operands' : [
2529 {
2530 "@type": 'koral:doc',
2531 "key": 'pubDate',
2532 "match": 'match:eq',
2533 "value": '2014-12-05',
2534 "type": 'type:date'
2535 },
2536 {
2537 "@type" : 'koral:doc',
2538 'key' : 'foo',
2539 'value' : 'bar'
2540 }
2541 ]
2542 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00002543 );
2544
2545 // Wrap on root
2546 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar"');
2547 expect(vc.root().ldType()).toEqual('docGroup');
2548 expect(vc.root().operation()).toEqual('and');
2549 _orOn(vc.root());
2550 expect(vc.root().ldType()).toEqual('docGroup');
2551 expect(vc.root().operation()).toEqual('or');
2552
2553 expect(vc.root().getOperand(0).ldType()).toEqual('docGroup');
2554 expect(vc.root().getOperand(0).operation()).toEqual('and');
2555 });
2556
2557 it('should add on root (case "and")', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00002558 var vc = vcClass.create().fromJson(
Akron712733a2018-04-05 18:17:47 +02002559 {
2560 "@type": 'koral:doc',
2561 "key": 'pubDate',
2562 "match": 'match:eq',
2563 "value": '2014-12-05',
2564 "type": 'type:date'
2565 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00002566 );
2567
2568 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05');
2569 expect(vc.root().ldType()).toEqual('doc');
2570 expect(vc.root().key()).toEqual('pubDate');
2571 expect(vc.root().value()).toEqual('2014-12-05');
2572
2573 // Wrap on root
2574 _andOn(vc.root());
2575 expect(vc.root().ldType()).toEqual('docGroup');
2576 expect(vc.root().operation()).toEqual('and');
2577 });
2578
2579 it('should add on root (case "or")', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00002580 var vc = vcClass.create().fromJson(
Akron712733a2018-04-05 18:17:47 +02002581 {
2582 "@type": 'koral:doc',
2583 "key": 'pubDate',
2584 "match": 'match:eq',
2585 "value": '2014-12-05',
2586 "type": 'type:date'
2587 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00002588 );
2589
2590 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05');
2591 expect(vc.root().key()).toEqual('pubDate');
2592 expect(vc.root().value()).toEqual('2014-12-05');
2593
2594 // Wrap on root
2595 _orOn(vc.root());
2596 expect(vc.root().ldType()).toEqual('docGroup');
2597 expect(vc.root().operation()).toEqual('or');
2598 });
2599
2600 it('should support multiple sub groups per group', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00002601 var vc = vcClass.create().fromJson(
Akron712733a2018-04-05 18:17:47 +02002602 {
2603 "@type": 'koral:docGroup',
2604 'operation' : 'operation:or',
2605 'operands' : [
2606 {
2607 "@type": 'koral:docGroup',
2608 'operation' : 'operation:and',
2609 'operands' : [
2610 {
2611 "@type": 'koral:doc',
2612 "key": 'title',
2613 "value": 't1',
2614 },
2615 {
2616 "@type" : 'koral:doc',
2617 'key' : 'title',
2618 'value' : 't2'
2619 }
2620 ]
2621 },
2622 {
2623 "@type": 'koral:docGroup',
2624 'operation' : 'operation:and',
2625 'operands' : [
2626 {
2627 "@type": 'koral:doc',
2628 "key": 'title',
2629 "value": 't3',
2630 },
2631 {
2632 "@type" : 'koral:doc',
2633 'key' : 'title',
2634 'value' : 't4'
2635 }
2636 ]
2637 }
2638 ]
2639 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00002640 );
2641 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02002642 '(title = "t1" & title = "t2") | ' +
2643 '(title = "t3" & title = "t4")'
Nils Diewald7c8ced22015-04-15 19:21:00 +00002644 );
2645 expect(vc.root().operation()).toEqual('or');
2646 expect(vc.root().getOperand(0).toQuery()).toEqual('title = "t1" & title = "t2"');
2647 expect(vc.root().getOperand(1).toQuery()).toEqual('title = "t3" & title = "t4"');
2648
2649 _andOn(vc.root());
2650
2651 expect(vc.root().operation()).toEqual('and');
2652 expect(vc.root().getOperand(0).ldType()).toEqual('docGroup');
2653 expect(vc.root().getOperand(1).ldType()).toEqual('non');
2654 });
2655 });
2656
Nils Diewald6283d692015-04-23 20:32:53 +00002657
Akron88d237e2020-10-21 08:05:18 +02002658 describe('KorAP.VC.Rewrite', function () {
Nils Diewald7c8ced22015-04-15 19:21:00 +00002659 it('should be initializable', function () {
2660 var rewrite = rewriteClass.create({
Akron712733a2018-04-05 18:17:47 +02002661 "@type" : "koral:rewrite",
2662 "operation" : "operation:modification",
2663 "src" : "querySerializer",
2664 "scope" : "tree"
Nils Diewald86dad5b2015-01-28 15:09:07 +00002665 });
Nils Diewald7c8ced22015-04-15 19:21:00 +00002666 expect(rewrite.toString()).toEqual('Modification of "tree" by "querySerializer"');
2667 });
Nils Diewald86dad5b2015-01-28 15:09:07 +00002668
Nils Diewald7c8ced22015-04-15 19:21:00 +00002669 it('should be deserialized by docs', function () {
2670 var doc = docClass.create(
Akron712733a2018-04-05 18:17:47 +02002671 undefined,
2672 {
2673 "@type":"koral:doc",
2674 "key":"Titel",
2675 "value":"Baum",
2676 "match":"match:eq"
2677 });
Nils Diewald7c8ced22015-04-15 19:21:00 +00002678
2679 expect(doc.element().classList.contains('doc')).toBeTruthy();
2680 expect(doc.element().classList.contains('rewritten')).toBe(false);
2681
2682 doc = docClass.create(
Akron712733a2018-04-05 18:17:47 +02002683 undefined,
2684 {
2685 "@type":"koral:doc",
2686 "key":"Titel",
2687 "value":"Baum",
2688 "match":"match:eq",
2689 "rewrites" : [
2690 {
2691 "@type" : "koral:rewrite",
2692 "operation" : "operation:modification",
2693 "src" : "querySerializer",
2694 "scope" : "tree"
2695 }
2696 ]
2697 });
Nils Diewald7c8ced22015-04-15 19:21:00 +00002698
2699 expect(doc.element().classList.contains('doc')).toBeTruthy();
2700 expect(doc.element().classList.contains('rewritten')).toBeTruthy();
2701 });
Nils Diewald6283d692015-04-23 20:32:53 +00002702
Akron76c3dd62018-05-29 20:58:27 +02002703 it('should be described in a title attribute', function () {
2704
2705 doc = docClass.create(
2706 undefined,
2707 {
2708 "@type":"koral:doc",
2709 "key":"Titel",
2710 "value":"Baum",
2711 "match":"match:eq",
2712 "rewrites" : [
2713 {
2714 "@type" : "koral:rewrite",
2715 "operation" : "operation:modification",
2716 "src" : "querySerializer",
2717 "scope" : "tree"
2718 },
2719 {
2720 "@type" : "koral:rewrite",
2721 "operation" : "operation:injection",
2722 "src" : "me"
2723 }
2724 ]
2725 });
2726
2727 expect(doc.element().classList.contains('doc')).toBeTruthy();
2728 expect(doc.element().classList.contains('rewritten')).toBeTruthy();
2729 expect(doc.element().lastChild.getAttribute("title")).toEqual("querySerializer: tree (modification)\nme (injection)");
2730 });
2731
2732
Nils Diewald6283d692015-04-23 20:32:53 +00002733 xit('should be deserialized by docGroups', function () {
2734 var docGroup = docGroupClass.create(
Akron712733a2018-04-05 18:17:47 +02002735 undefined,
2736 {
2737 "@type" : "koral:docGroup",
2738 "operation" : "operation:or",
2739 "operands" : [
2740 {
2741 "@type" : "doc",
2742 "key" : "pubDate",
2743 "type" : "type:date",
2744 "value" : "2014-12-05"
2745 },
2746 {
2747 "@type" : "doc",
2748 "key" : "pubDate",
2749 "type" : "type:date",
2750 "value" : "2014-12-06"
2751 }
2752 ],
2753 "rewrites" : [
2754 {
2755 "@type" : "koral:rewrite",
2756 "operation" : "operation:modification",
2757 "src" : "querySerializer",
2758 "scope" : "tree"
2759 }
2760 ]
2761 }
Nils Diewald6283d692015-04-23 20:32:53 +00002762 );
2763
2764 expect(doc.element().classList.contains('docgroup')).toBeTruthy();
2765 expect(doc.element().classList.contains('rewritten')).toBe(false);
2766 });
Nils Diewald86dad5b2015-01-28 15:09:07 +00002767 });
Nils Diewaldf0c4f112015-05-05 12:56:59 +00002768
Akron88d237e2020-10-21 08:05:18 +02002769 describe('KorAP.VC.stringValue', function () {
Nils Diewaldf0c4f112015-05-05 12:56:59 +00002770 it('should be initializable', function () {
2771 var sv = stringValClass.create();
2772 expect(sv.regex()).toBe(false);
2773 expect(sv.value()).toBe('');
Nils Diewaldc4c4b832015-05-05 16:00:08 +00002774
2775 sv = stringValClass.create('Baum');
2776 expect(sv.regex()).toBe(false);
2777 expect(sv.value()).toBe('Baum');
2778
2779 sv = stringValClass.create('Baum', false);
2780 expect(sv.regex()).toBe(false);
2781 expect(sv.value()).toBe('Baum');
2782
2783 sv = stringValClass.create('Baum', true);
2784 expect(sv.regex()).toBe(true);
2785 expect(sv.value()).toBe('Baum');
2786 });
2787
2788 it('should be modifiable', function () {
2789 var sv = stringValClass.create();
2790 expect(sv.regex()).toBe(false);
2791 expect(sv.value()).toBe('');
2792
2793 expect(sv.value('Baum')).toBe('Baum');
2794 expect(sv.value()).toBe('Baum');
2795
2796 expect(sv.regex(true)).toBe(true);
2797 expect(sv.regex()).toBe(true);
2798 });
2799
2800 it('should have a toggleble regex value', function () {
2801 var sv = stringValClass.create();
Nils Diewald7991a3f2015-05-19 14:12:37 +00002802
2803 expect(sv.element().firstChild.value).toBe('');
2804 sv.element().firstChild.value = 'der'
2805 expect(sv.element().firstChild.value).toBe('der');
2806
Nils Diewaldc4c4b832015-05-05 16:00:08 +00002807 expect(sv.regex()).toBe(false);
2808
2809 sv.toggleRegex();
Nils Diewald7991a3f2015-05-19 14:12:37 +00002810 expect(sv.element().firstChild.value).toBe('der');
Nils Diewaldc4c4b832015-05-05 16:00:08 +00002811 expect(sv.regex()).toBe(true);
Nils Diewald7991a3f2015-05-19 14:12:37 +00002812 sv.element().firstChild.value = 'derbe'
Nils Diewaldc4c4b832015-05-05 16:00:08 +00002813
2814 sv.toggleRegex();
2815 expect(sv.regex()).toBe(false);
Nils Diewald7991a3f2015-05-19 14:12:37 +00002816 expect(sv.element().firstChild.value).toBe('derbe');
Nils Diewaldc4c4b832015-05-05 16:00:08 +00002817 });
2818
2819 it('should have an element', function () {
2820 var sv = stringValClass.create('der');
2821 expect(sv.element().nodeName).toBe('DIV');
2822 expect(sv.element().firstChild.nodeName).toBe('INPUT');
2823 expect(sv.element().firstChild.value).toBe('der');
2824 });
2825
2826 it('should have a classed element', function () {
2827 var sv = stringValClass.create();
Nils Diewaldc4c4b832015-05-05 16:00:08 +00002828 expect(sv.element().classList.contains('regex')).toBe(false);
2829 expect(sv.regex()).toBe(false);
2830 sv.toggleRegex();
2831 expect(sv.element().classList.contains('regex')).toBe(true);
2832 });
2833
2834 it('should be storable', function () {
2835 var sv = stringValClass.create();
2836 var count = 1;
2837 sv.store = function (value, regex) {
Akron712733a2018-04-05 18:17:47 +02002838 expect(regex).toBe(true);
2839 expect(value).toBe('tree');
Nils Diewaldc4c4b832015-05-05 16:00:08 +00002840 };
2841 sv.regex(true);
2842 sv.value('tree');
2843 sv.element().lastChild.click();
Nils Diewaldf0c4f112015-05-05 12:56:59 +00002844 });
Akron712733a2018-04-05 18:17:47 +02002845
Akronb19803c2018-08-16 16:39:42 +02002846 it('should have a disableoption for regex', function () {
2847 var sv = stringValClass.create(undefined, undefined, true);
2848 var svE = sv.element();
2849 expect(svE.children.length).toEqual(2);
2850
2851 sv = stringValClass.create(undefined, undefined, false);
2852 svE = sv.element();
2853 expect(svE.children.length).toEqual(1);
2854 });
2855
Nils Diewaldf0c4f112015-05-05 12:56:59 +00002856 });
Akrone4961b12017-05-10 21:04:46 +02002857
Akron712733a2018-04-05 18:17:47 +02002858 describe('KorAP.VC.Menu', function () {
Akrone65a88a2018-04-05 19:14:20 +02002859
2860 var vc;
2861
Akron712733a2018-04-05 18:17:47 +02002862 it('should be initializable', function () {
2863
Akrone65a88a2018-04-05 19:14:20 +02002864 vc = vcClass.create([
Akron712733a2018-04-05 18:17:47 +02002865 ['a', 'text'],
2866 ['b', 'string'],
2867 ['c', 'date']
2868 ]).fromJson();
Akronadab5e52018-08-20 13:50:53 +02002869 expect(vc.builder().firstChild.classList.contains('unspecified')).toBeTruthy();
2870 expect(vc.builder().firstChild.firstChild.tagName).toEqual('SPAN');
Akron712733a2018-04-05 18:17:47 +02002871
2872 // Click on unspecified
Akronadab5e52018-08-20 13:50:53 +02002873 vc.builder().firstChild.firstChild.click();
2874 expect(vc.builder().firstChild.firstChild.tagName).toEqual('UL');
Akron712733a2018-04-05 18:17:47 +02002875
Akronadab5e52018-08-20 13:50:53 +02002876 var list = vc.builder().firstChild.firstChild;
Akron3ad46942018-08-22 16:47:14 +02002877 expect(list.getElementsByTagName("LI")[0].innerText).toEqual('referTo');
2878 expect(list.getElementsByTagName("LI")[1].innerText).toEqual('a');
2879 expect(list.getElementsByTagName("LI")[2].innerText).toEqual('b');
2880 expect(list.getElementsByTagName("LI")[3].innerText).toEqual('c');
Akron712733a2018-04-05 18:17:47 +02002881
2882 vc = vcClass.create([
2883 ['d', 'text'],
2884 ['e', 'string'],
2885 ['f', 'date']
2886 ]).fromJson();
Akronadab5e52018-08-20 13:50:53 +02002887 expect(vc.builder().firstChild.classList.contains('unspecified')).toBeTruthy();
2888 expect(vc.builder().firstChild.firstChild.tagName).toEqual('SPAN');
Akron712733a2018-04-05 18:17:47 +02002889
2890 // Click on unspecified
Akronadab5e52018-08-20 13:50:53 +02002891 vc.builder().firstChild.firstChild.click();
2892 expect(vc.builder().firstChild.firstChild.tagName).toEqual('UL');
Akron712733a2018-04-05 18:17:47 +02002893
Akronadab5e52018-08-20 13:50:53 +02002894 list = vc.builder().firstChild.firstChild;
Akron3ad46942018-08-22 16:47:14 +02002895 expect(list.getElementsByTagName("LI")[0].innerText).toEqual('referTo');
2896 expect(list.getElementsByTagName("LI")[1].innerText).toEqual('d');
2897 expect(list.getElementsByTagName("LI")[2].innerText).toEqual('e');
2898 expect(list.getElementsByTagName("LI")[3].innerText).toEqual('f');
Akron31d89942018-04-06 16:44:51 +02002899 // blur
2900 document.body.click();
Akron712733a2018-04-05 18:17:47 +02002901 });
Akrone65a88a2018-04-05 19:14:20 +02002902
2903 // Reinitialize to make tests stable
2904 vc = vcClass.create([
2905 ['d', 'text'],
2906 ['e', 'string'],
2907 ['f', 'date']
2908 ]).fromJson();
2909
2910 it('should be clickable on key', function () {
Akron31d89942018-04-06 16:44:51 +02002911 // Click on unspecified
Akronadab5e52018-08-20 13:50:53 +02002912 vc.builder().firstChild.firstChild.click();
Akrone65a88a2018-04-05 19:14:20 +02002913 // Click on "d"
Akronadab5e52018-08-20 13:50:53 +02002914 vc.builder().firstChild.firstChild.getElementsByTagName("LI")[1].click();
2915 expect(vc.builder().firstChild.firstChild.tagName).toEqual('SPAN');
2916 expect(vc.builder().firstChild.firstChild.innerText).toEqual('d');
2917 expect(vc.builder().firstChild.children[1].innerText).toEqual('eq');
2918 expect(vc.builder().firstChild.children[1].getAttribute('data-type')).toEqual('text');
Akron31d89942018-04-06 16:44:51 +02002919 // blur
2920 document.body.click();
Akrone65a88a2018-04-05 19:14:20 +02002921 });
2922
Akron31d89942018-04-06 16:44:51 +02002923 it('should be clickable on operation for text', function () {
2924 // Click on "d" (or unspecified)
Akronadab5e52018-08-20 13:50:53 +02002925 vc.builder().firstChild.firstChild.click();
Akron31d89942018-04-06 16:44:51 +02002926
2927 // Choose "d"
Akronadab5e52018-08-20 13:50:53 +02002928 vc.builder().firstChild.firstChild.getElementsByTagName("LI")[1].click();
Akron31d89942018-04-06 16:44:51 +02002929
2930 // Click on matchop
Akronadab5e52018-08-20 13:50:53 +02002931 vc.builder().firstChild.children[1].click();
Akron31d89942018-04-06 16:44:51 +02002932
Akronadab5e52018-08-20 13:50:53 +02002933 expect(vc.builder().firstChild.children[1].tagName).toEqual('UL');
Akron31d89942018-04-06 16:44:51 +02002934
Akronadab5e52018-08-20 13:50:53 +02002935 var ul = vc.builder().firstChild.children[1];
Akrone65a88a2018-04-05 19:14:20 +02002936 expect(ul.getElementsByTagName('li')[0].innerText).toEqual("eq");
2937 expect(ul.getElementsByTagName('li')[1].innerText).toEqual("ne");
2938 expect(ul.getElementsByTagName('li')[2].innerText).toEqual("contains");
2939 expect(ul.getElementsByTagName('li')[3].innerText).toEqual("containsnot");
2940 expect(ul.getElementsByTagName('li')[4]).toBeUndefined();
Akron31d89942018-04-06 16:44:51 +02002941
2942 // Choose "contains"
2943 ul.getElementsByTagName('li')[2].click();
Akronadab5e52018-08-20 13:50:53 +02002944 expect(vc.builder().firstChild.children[1].tagName).toEqual("SPAN");
2945 expect(vc.builder().firstChild.children[1].innerText).toEqual("contains");
Akron31d89942018-04-06 16:44:51 +02002946 // blur
2947 document.body.click();
Akrone65a88a2018-04-05 19:14:20 +02002948 })
Akron31d89942018-04-06 16:44:51 +02002949
2950 it('should be clickable on operation for string', function () {
2951 // Click on "d" (or unspecified)
Akronadab5e52018-08-20 13:50:53 +02002952 vc.builder().firstChild.firstChild.click();
Akron31d89942018-04-06 16:44:51 +02002953
2954 // Choose "e"
Akronadab5e52018-08-20 13:50:53 +02002955 vc.builder().firstChild.firstChild.getElementsByTagName("LI")[2].click();
2956
Akron31d89942018-04-06 16:44:51 +02002957 // As a consequence the matchoperator may no longer
2958 // be valid and needs to be re-evaluated
Akronadab5e52018-08-20 13:50:53 +02002959 var fc = vc.builder().firstChild;
Akron31d89942018-04-06 16:44:51 +02002960 expect(fc.firstChild.tagName).toEqual('SPAN');
2961 expect(fc.firstChild.innerText).toEqual('e');
2962 expect(fc.children[1].innerText).toEqual('eq');
2963 expect(fc.children[1].getAttribute('data-type')).toEqual('string');
2964
Akronadab5e52018-08-20 13:50:53 +02002965 vc.builder().firstChild.children[1].click();
Akron31d89942018-04-06 16:44:51 +02002966
Akronadab5e52018-08-20 13:50:53 +02002967 expect(vc.builder().firstChild.children[1].tagName).toEqual('UL');
Akron31d89942018-04-06 16:44:51 +02002968
Akronadab5e52018-08-20 13:50:53 +02002969 var ul = vc.builder().firstChild.children[1];
Akron31d89942018-04-06 16:44:51 +02002970 expect(ul.getElementsByTagName('li')[0].innerText).toEqual("eq");
2971 expect(ul.getElementsByTagName('li')[1].innerText).toEqual("ne");
2972 expect(ul.getElementsByTagName('li')[2]).toBeUndefined();
2973
2974 // Choose "ne"
2975 ul.getElementsByTagName('li')[1].click();
Akronadab5e52018-08-20 13:50:53 +02002976 expect(vc.builder().firstChild.children[1].tagName).toEqual("SPAN");
2977 expect(vc.builder().firstChild.children[1].innerText).toEqual("ne");
Akron8db5e3a2018-05-28 19:25:26 +02002978
2979 // Click on text
Akronebc96662018-08-29 17:36:20 +02002980 expect(vc.builder().firstChild.children[2].innerText).toEqual(KorAP.Locale.EMPTY);
2981 expect(vc.builder().firstChild.children[2].classList.contains('unspecified')).toEqual(true);
Akronadab5e52018-08-20 13:50:53 +02002982 vc.builder().firstChild.children[2].click();
Akron8db5e3a2018-05-28 19:25:26 +02002983
2984 // Blur text element
Akronadab5e52018-08-20 13:50:53 +02002985 expect(vc.builder().firstChild.children[2].firstChild.value).toEqual('');
Akron8db5e3a2018-05-28 19:25:26 +02002986
Akron31d89942018-04-06 16:44:51 +02002987 // blur
2988 document.body.click();
2989 });
2990
2991 it('should be clickable on operation for date', function () {
2992
2993 // Replay matchop check - so it's guaranteed that "ne" is chosen
2994 // Click on "e" (or unspecified)
Akronadab5e52018-08-20 13:50:53 +02002995 vc.builder().firstChild.firstChild.click();
Akron31d89942018-04-06 16:44:51 +02002996 // Rechoose "e"
Akronadab5e52018-08-20 13:50:53 +02002997 vc.builder().firstChild.firstChild.getElementsByTagName("LI")[1].click();
Akron31d89942018-04-06 16:44:51 +02002998 // Click on matchop
Akronadab5e52018-08-20 13:50:53 +02002999 vc.builder().firstChild.children[1].click();
Akron31d89942018-04-06 16:44:51 +02003000 // Choose "ne"
Akronadab5e52018-08-20 13:50:53 +02003001 vc.builder().firstChild.children[1].getElementsByTagName('li')[1].click();
3002 expect(vc.builder().firstChild.children[1].innerText).toEqual("ne");
Akron31d89942018-04-06 16:44:51 +02003003
3004 // Click on "e"
Akronadab5e52018-08-20 13:50:53 +02003005 vc.builder().firstChild.firstChild.click();
Akron31d89942018-04-06 16:44:51 +02003006 // Choose "f"
Akronadab5e52018-08-20 13:50:53 +02003007 vc.builder().firstChild.firstChild.getElementsByTagName("LI")[3].click();
Akron31d89942018-04-06 16:44:51 +02003008
3009 // The matchoperator should still be "ne" as this is valid for dates as well (now)
Akronadab5e52018-08-20 13:50:53 +02003010 var fc = vc.builder().firstChild;
Akron31d89942018-04-06 16:44:51 +02003011 expect(fc.firstChild.tagName).toEqual('SPAN');
3012 expect(fc.firstChild.innerText).toEqual('f');
3013 expect(fc.children[1].innerText).toEqual('ne');
3014 // blur
3015 document.body.click();
3016 });
Akronddc98a72018-04-06 17:33:52 +02003017
3018
3019 // Check json deserialization
3020 it('should be initializable', function () {
3021 vc = vcClass.create([
3022 ['a', 'text'],
3023 ['b', 'string'],
3024 ['c', 'date']
3025 ]).fromJson({
3026 "@type" : "koral:doc",
3027 "key":"a",
3028 "value":"Baum"
3029 });
3030
Akronadab5e52018-08-20 13:50:53 +02003031 expect(vc.builder().firstChild.children[1].getAttribute('data-type')).toEqual('text');
Akronddc98a72018-04-06 17:33:52 +02003032 });
Akron712733a2018-04-05 18:17:47 +02003033 });
3034
3035
Akrone4961b12017-05-10 21:04:46 +02003036 // Check prefix
3037 describe('KorAP.VC.Prefix', function () {
3038
3039 it('should be initializable', function () {
3040 var p = prefixClass.create();
3041 expect(p.element().classList.contains('pref')).toBeTruthy();
3042 expect(p.isSet()).not.toBeTruthy();
3043 });
3044
3045
3046 it('should be clickable', function () {
hebastaa0282be2018-12-05 16:58:00 +01003047 KorAP.vc = vcClass.create([
Akron712733a2018-04-05 18:17:47 +02003048 ['a', null],
3049 ['b', null],
3050 ['c', null]
3051 ]).fromJson();
hebastaa0282be2018-12-05 16:58:00 +01003052
3053 //vc = KorAP.vc;
3054
3055 expect(KorAP.vc.builder().firstChild.classList.contains('unspecified')).toBeTruthy();
Akrone4961b12017-05-10 21:04:46 +02003056
3057 // This should open up the menu
hebastaa0282be2018-12-05 16:58:00 +01003058 KorAP.vc.builder().firstChild.firstChild.click();
3059 expect(KorAP.vc.builder().firstChild.firstChild.tagName).toEqual('UL');
Akrone4961b12017-05-10 21:04:46 +02003060
3061 KorAP._vcKeyMenu._prefix.clear();
3062 KorAP._vcKeyMenu._prefix.add('x');
3063
hebastaa0282be2018-12-05 16:58:00 +01003064 var prefElement = KorAP.vc.builder().querySelector('span.pref');
Akrone4961b12017-05-10 21:04:46 +02003065 expect(prefElement.innerText).toEqual('x');
3066
3067 // This should add key 'x' to VC
3068 prefElement.click();
3069
hebastaa0282be2018-12-05 16:58:00 +01003070 expect(KorAP.vc.builder().firstChild.classList.contains('doc')).toBeTruthy();
3071 expect(KorAP.vc.builder().firstChild.firstChild.className).toEqual('key');
3072 expect(KorAP.vc.builder().firstChild.firstChild.innerText).toEqual('x');
Akrone4961b12017-05-10 21:04:46 +02003073 });
3074 });
Akron68d28322018-08-27 15:02:42 +02003075
Akron889ec292018-11-19 17:56:01 +01003076 // Check fragment handling for corpusByMatch helper
Akron68d28322018-08-27 15:02:42 +02003077 describe('KorAP.VC.Fragment', function () {
3078 it('should be initializable', function () {
3079 var f = fragmentClass.create();
3080 var e = f.element();
3081 expect(e.classList.contains('vc')).toBeTruthy();
3082 expect(e.classList.contains('fragment')).toBeTruthy();
Akrond45a1702018-11-19 18:15:17 +01003083 expect(e.firstChild.children.length).toEqual(0);
Akron68d28322018-08-27 15:02:42 +02003084 });
3085
3086 it('should be expansable', function () {
3087 var f = fragmentClass.create();
3088 f.add("author", "Peter");
3089
Akrond45a1702018-11-19 18:15:17 +01003090 var root = f.element().lastChild.firstChild;
Akron68d28322018-08-27 15:02:42 +02003091
3092 expect(root.classList.contains("doc")).toBeTruthy();
3093 expect(root.children[0].tagName).toEqual("SPAN");
3094 expect(root.children[0].textContent).toEqual("author");
3095 expect(root.children[1].tagName).toEqual("SPAN");
3096 expect(root.children[1].textContent).toEqual("eq");
3097 expect(root.children[2].tagName).toEqual("SPAN");
3098 expect(root.children[2].textContent).toEqual("Peter");
3099
3100 f.add("title", "Example");
3101
Akrond45a1702018-11-19 18:15:17 +01003102 root = f.element().lastChild.firstChild;
Akron68d28322018-08-27 15:02:42 +02003103
3104 expect(root.classList.contains("docGroup")).toBeTruthy();
3105
3106 var doc = root.children[0];
3107
3108 expect(doc.children[0].tagName).toEqual("SPAN");
3109 expect(doc.children[0].textContent).toEqual("author");
3110 expect(doc.children[1].tagName).toEqual("SPAN");
3111 expect(doc.children[1].textContent).toEqual("eq");
3112 expect(doc.children[2].tagName).toEqual("SPAN");
3113 expect(doc.children[2].textContent).toEqual("Peter");
3114
3115 doc = root.children[1];
3116
3117 expect(doc.children[0].tagName).toEqual("SPAN");
3118 expect(doc.children[0].textContent).toEqual("title");
3119 expect(doc.children[1].tagName).toEqual("SPAN");
3120 expect(doc.children[1].textContent).toEqual("eq");
3121 expect(doc.children[2].tagName).toEqual("SPAN");
3122 expect(doc.children[2].textContent).toEqual("Example");
3123 });
3124
3125
3126 it('should be reducible', function () {
3127 var f = fragmentClass.create();
Akrond45a1702018-11-19 18:15:17 +01003128 expect(f.element().lastChild.children.length).toEqual(0);
Akron889ec292018-11-19 17:56:01 +01003129
Akron68d28322018-08-27 15:02:42 +02003130 f.add("author", "Peter");
3131 f.add("title", "Example");
3132
Akrond45a1702018-11-19 18:15:17 +01003133 expect(f.element().lastChild.children.length).toEqual(1);
Akron889ec292018-11-19 17:56:01 +01003134
Akrond45a1702018-11-19 18:15:17 +01003135 var root = f.element().lastChild.firstChild;
Akron889ec292018-11-19 17:56:01 +01003136
Akron68d28322018-08-27 15:02:42 +02003137 expect(root.classList.contains("docGroup")).toBeTruthy();
3138
3139 expect(root.children.length).toEqual(2);
3140
3141 f.remove("author","Peter");
3142
Akrond45a1702018-11-19 18:15:17 +01003143 root = f.element().lastChild.firstChild;
Akron68d28322018-08-27 15:02:42 +02003144 expect(root.classList.contains("doc")).toBeTruthy();
3145
3146 expect(root.children[0].tagName).toEqual("SPAN");
3147 expect(root.children[0].textContent).toEqual("title");
3148 expect(root.children[1].tagName).toEqual("SPAN");
3149 expect(root.children[1].textContent).toEqual("eq");
3150 expect(root.children[2].tagName).toEqual("SPAN");
3151 expect(root.children[2].textContent).toEqual("Example");
Akron889ec292018-11-19 17:56:01 +01003152
3153 f.remove("title","Example");
3154
Akrond45a1702018-11-19 18:15:17 +01003155 expect(f.element().lastChild.children.length).toEqual(0);
Akron68d28322018-08-27 15:02:42 +02003156 });
Akron2761d882020-10-13 10:35:09 +02003157
3158 it('should respect already set attributes', function () {
3159 var f = fragmentClass.create();
3160 expect(f.element().lastChild.children.length).toEqual(0);
3161
3162 expect(f.isEmpty()).toBeTruthy();
3163
3164 f.add("author", "Peter");
3165 f.add("title", "Example");
3166
3167 expect(f.isEmpty()).toBeFalsy();
3168
3169 expect(f.toQuery()).toEqual('author = "Peter" & title = "Example"');
3170
3171 f.add("author", "Peter");
3172
3173 expect(f.toQuery()).toEqual('title = "Example" & author = "Peter"');
3174 });
Akron68d28322018-08-27 15:02:42 +02003175 });
Nils Diewald2fe12e12015-03-06 16:47:06 +00003176});