blob: 7beede7cbfe208c073ef4b737a328c6e6531cd6d [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 () {
Nils Diewald7c8ced22015-04-15 19:21:00 +0000661 it('should be initializable', function () {
662 var doc = unspecifiedClass.create();
663 var docElement = doc.element();
664 expect(docElement.getAttribute('class')).toEqual('doc unspecified');
Akronebc96662018-08-29 17:36:20 +0200665 expect(docElement.firstChild.firstChild.data).toEqual(KorAP.Locale.EMPTY);
666 expect(docElement.lastChild.lastChild.data).toEqual(KorAP.Locale.EMPTY);
Nils Diewald7c8ced22015-04-15 19:21:00 +0000667 expect(doc.toQuery()).toEqual('');
hebastaa0282be2018-12-05 16:58:00 +0100668 expect(doc.incomplete()).toBeTruthy();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000669
670 // Only removable
671 expect(docElement.lastChild.children.length).toEqual(0);
672 });
673
hebastad7c03742019-07-11 12:48:50 +0200674 it('should be removable, when no root', function () {
675 var vc = vcClass.create();
676 KorAP.vc = vc;
Nils Diewald7c8ced22015-04-15 19:21:00 +0000677 var docGroup = docGroupClass.create();
678 docGroup.operation('or');
679 expect(docGroup.operation()).toEqual('or');
680
681 docGroup.append({
Akron712733a2018-04-05 18:17:47 +0200682 "@type": 'koral:doc',
683 "key": 'pubDate',
684 "match": 'match:eq',
685 "value": '2014-12-05',
686 "type": 'type:date'
Nils Diewald7c8ced22015-04-15 19:21:00 +0000687 });
688
689 // Add unspecified object
690 docGroup.append();
691
Akrond141a362018-07-10 18:12:13 +0200692 var parent = document.createElement('div');
693 parent.appendChild(docGroup.element());
694
Nils Diewald7c8ced22015-04-15 19:21:00 +0000695 expect(docGroup.element().getAttribute('class')).toEqual('docGroup');
696 expect(docGroup.element().children[0].getAttribute('class')).toEqual('doc');
697
698 var unspec = docGroup.element().children[1];
699 expect(unspec.getAttribute('class')).toEqual('doc unspecified');
700
Akronb19803c2018-08-16 16:39:42 +0200701 // Only unspec and delete
702 expect(unspec.children.length).toEqual(2);
703
Nils Diewald7c8ced22015-04-15 19:21:00 +0000704 // Removable
705 expect(unspec.lastChild.children.length).toEqual(1);
706 expect(unspec.lastChild.children[0].getAttribute('class')).toEqual('delete');
707 });
708
Akrond141a362018-07-10 18:12:13 +0200709
Nils Diewald7c8ced22015-04-15 19:21:00 +0000710 it('should be replaceable by a doc', function () {
711 var doc = unspecifiedClass.create();
712 expect(doc.ldType()).toEqual("non");
713 // No parent, therefor not updateable
714 expect(doc.key("baum")).toBeNull();
715
716 var docGroup = docGroupClass.create();
717 docGroup.operation('or');
718 expect(docGroup.operation()).toEqual('or');
719
720 docGroup.append({
Akron712733a2018-04-05 18:17:47 +0200721 "@type": 'koral:doc',
722 "key": 'pubDate',
723 "match": 'match:eq',
724 "value": '2014-12-05',
725 "type": 'type:date'
Nils Diewald7c8ced22015-04-15 19:21:00 +0000726 });
727
728 expect(docGroup.toQuery()).toEqual("pubDate in 2014-12-05");
729 docGroup.append();
730
731 expect(docGroup.getOperand(0).ldType()).toEqual("doc");
732 expect(docGroup.getOperand(1).ldType()).toEqual("non");
733
734 var op = docGroup.getOperand(1).element().lastChild;
Akron0b489ad2018-02-02 16:49:32 +0100735 expect(op.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +0000736 expect(op.children[0].getAttribute('class')).toEqual('delete');
737 expect(op.children.length).toEqual(1);
738
739 // Replace unspecified doc
740 expect(docGroup.getOperand(1).key("name")).not.toBeNull();
741 expect(docGroup.getOperand(1).ldType()).toEqual("doc");
742 expect(docGroup.getOperand(1).key()).toEqual("name");
Akron55a343b2018-04-06 19:57:36 +0200743 expect(docGroup.getOperand(1).value()).toBeUndefined();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000744
Akronb19803c2018-08-16 16:39:42 +0200745 expect(docGroup.getOperand(1).element().children.length).toEqual(4);
746
Nils Diewald7c8ced22015-04-15 19:21:00 +0000747 op = docGroup.getOperand(1).element().lastChild;
Akron0b489ad2018-02-02 16:49:32 +0100748 expect(op.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +0000749 expect(op.children[0].getAttribute('class')).toEqual('and');
750 expect(op.children[1].getAttribute('class')).toEqual('or');
751 expect(op.children[2].getAttribute('class')).toEqual('delete');
Akronb19803c2018-08-16 16:39:42 +0200752
Nils Diewald7c8ced22015-04-15 19:21:00 +0000753 expect(op.children.length).toEqual(3);
754
755 docGroup.getOperand(1).value("Pachelbel");
756 expect(docGroup.getOperand(1).value()).toEqual("Pachelbel");
757 expect(docGroup.getOperand(1).type()).toEqual("string");
758 expect(docGroup.getOperand(1).matchop()).toEqual("eq");
759
760 // Specified!
761 expect(docGroup.toQuery()).toEqual('pubDate in 2014-12-05 | name = "Pachelbel"');
762 });
Akronb19803c2018-08-16 16:39:42 +0200763
Nils Diewald7c8ced22015-04-15 19:21:00 +0000764 it('should be replaceable on root', function () {
hebastaa0282be2018-12-05 16:58:00 +0100765
Nils Diewald6283d692015-04-23 20:32:53 +0000766 var vc = vcClass.create();
hebastaa0282be2018-12-05 16:58:00 +0100767 KorAP.vc = vc;
Nils Diewald7c8ced22015-04-15 19:21:00 +0000768 expect(vc.toQuery()).toEqual("");
769
770 expect(vc.root().ldType()).toEqual("non");
771
772 // No operators on root
773 op = vc.root().element().lastChild;
Akronebc96662018-08-29 17:36:20 +0200774 expect(op.lastChild.textContent).toEqual(KorAP.Locale.EMPTY);
Nils Diewald7c8ced22015-04-15 19:21:00 +0000775
776 // Replace
777 expect(vc.root().key("baum")).not.toBeNull();
778 expect(vc.root().ldType()).toEqual("doc");
779
780 op = vc.root().element().lastChild;
Akron0b489ad2018-02-02 16:49:32 +0100781 expect(op.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +0000782 expect(op.children[0].getAttribute('class')).toEqual('and');
783 expect(op.children[1].getAttribute('class')).toEqual('or');
784 expect(op.children[2].getAttribute('class')).toEqual('delete');
785 expect(op.children.length).toEqual(3);
786 });
Akron55a343b2018-04-06 19:57:36 +0200787
788 it('should be clickable', function () {
789 var vc = vcClass.create([
790 ["pubDate", "date"]
791 ]);
hebastaa0282be2018-12-05 16:58:00 +0100792 KorAP.vc = vc;
793
Akron55a343b2018-04-06 19:57:36 +0200794 expect(vc.toQuery()).toEqual("");
Akronebc96662018-08-29 17:36:20 +0200795 expect(vc.builder().firstChild.textContent).toEqual(KorAP.Locale.EMPTY);
796 expect(vc.builder().firstChild.classList.contains('unspecified')).toEqual(true);
Akronadab5e52018-08-20 13:50:53 +0200797 vc.builder().firstChild.firstChild.click();
Akron55a343b2018-04-06 19:57:36 +0200798
799 // Click on pubDate
Akron3ad46942018-08-22 16:47:14 +0200800 vc.element().firstChild.getElementsByTagName("LI")[1].click();
Akronadab5e52018-08-20 13:50:53 +0200801 expect(vc.builder().firstChild.firstChild.textContent).toEqual("pubDate");
802 expect(vc.builder().firstChild.children[1].getAttribute("data-type")).toEqual("date");
Akron55a343b2018-04-06 19:57:36 +0200803 });
Nils Diewald7c8ced22015-04-15 19:21:00 +0000804 });
805
Akron88d237e2020-10-21 08:05:18 +0200806 describe('KorAP.VC.Doc element', function () {
Nils Diewald7c8ced22015-04-15 19:21:00 +0000807 it('should be initializable', function () {
808 var docElement = docClass.create(undefined, {
Akron712733a2018-04-05 18:17:47 +0200809 "@type" : "koral:doc",
810 "key":"Titel",
811 "value":"Baum",
812 "match":"match:eq"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000813 });
814 expect(docElement.key()).toEqual('Titel');
815 expect(docElement.matchop()).toEqual('eq');
816 expect(docElement.value()).toEqual('Baum');
817
818 var docE = docElement.element();
819 expect(docE.children[0].firstChild.data).toEqual('Titel');
820 expect(docE.children[1].firstChild.data).toEqual('eq');
821 expect(docE.children[1].getAttribute('data-type')).toEqual('string');
822 expect(docE.children[2].firstChild.data).toEqual('Baum');
823 expect(docE.children[2].getAttribute('data-type')).toEqual('string');
824
825 expect(docElement.toJson()).toEqual(jasmine.objectContaining({
Akron712733a2018-04-05 18:17:47 +0200826 "@type" : "koral:doc",
827 "key":"Titel",
828 "value":"Baum",
829 "match":"match:eq"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000830 }));
831 });
Akronb19803c2018-08-16 16:39:42 +0200832
833
834 it('should be replacable by unspecified', function () {
835 var vc = vcClass.create([
836 ["pubDate", "date"]
837 ]).fromJson({
838 "@type" : "koral:doc",
839 "key":"Titel",
840 "value":"Baum",
841 "match":"match:eq"
842 });
hebastaa0282be2018-12-05 16:58:00 +0100843 KorAP.vc = vc;
Akronb19803c2018-08-16 16:39:42 +0200844 expect(vc.toQuery()).toEqual("Titel = \"Baum\"");
845
Akronadab5e52018-08-20 13:50:53 +0200846 var vcE = vc.builder();
Akronb19803c2018-08-16 16:39:42 +0200847 expect(vcE.firstChild.children.length).toEqual(4);
848
849 // Click to delete
850 vcE.firstChild.lastChild.lastChild.click();
851
852 expect(vcE.firstChild.children.length).toEqual(1);
853
Akronebc96662018-08-29 17:36:20 +0200854 expect(vcE.firstChild.textContent).toEqual(KorAP.Locale.EMPTY);
855 expect(vcE.firstChild.classList.contains("unspecified")).toBeTruthy();
Akronb19803c2018-08-16 16:39:42 +0200856 vcE.firstChild.firstChild.click();
857
858 // Click on pubDate
Akron3ad46942018-08-22 16:47:14 +0200859 vcE.firstChild.getElementsByTagName("LI")[1].click();
Akronb19803c2018-08-16 16:39:42 +0200860
861 expect(vcE.firstChild.firstChild.textContent).toEqual("pubDate");
862 expect(vcE.firstChild.children[1].getAttribute("data-type")).toEqual("date");
863
864 expect(vcE.firstChild.children.length).toEqual(4);
865 });
866
867
Akron587e4d92018-08-31 12:44:26 +0200868 it('should be replaceable by docGroupRef with deletion', function () {
Akron3ad46942018-08-22 16:47:14 +0200869 var vc = vcClass.create().fromJson({
Akronb19803c2018-08-16 16:39:42 +0200870 "@type" : "koral:doc",
871 "key":"Titel",
872 "value":"Baum",
873 "match":"match:eq"
874 });
875
hebastaa0282be2018-12-05 16:58:00 +0100876 KorAP.vc = vc;
Akronb19803c2018-08-16 16:39:42 +0200877 expect(vc.toQuery()).toEqual("Titel = \"Baum\"");
878
Akronadab5e52018-08-20 13:50:53 +0200879 var vcE = vc.builder();
Akronb19803c2018-08-16 16:39:42 +0200880 expect(vcE.firstChild.children.length).toEqual(4);
881
882 // Click to delete
883 vcE.firstChild.lastChild.lastChild.click();
884
885 expect(vcE.firstChild.children.length).toEqual(1);
886
Akronebc96662018-08-29 17:36:20 +0200887 expect(vcE.firstChild.textContent).toEqual(KorAP.Locale.EMPTY);
888 expect(vcE.firstChild.classList.contains('unspecified')).toEqual(true);
Akronb19803c2018-08-16 16:39:42 +0200889 vcE.firstChild.firstChild.click();
890
Akron3ad46942018-08-22 16:47:14 +0200891 // Click on referTo
Akronb19803c2018-08-16 16:39:42 +0200892 vcE.firstChild.getElementsByTagName("LI")[0].click();
893
Akron3ad46942018-08-22 16:47:14 +0200894 expect(vcE.firstChild.firstChild.textContent).toEqual("referTo");
Akronb19803c2018-08-16 16:39:42 +0200895 expect(vcE.firstChild.children[1].getAttribute("data-type")).toEqual("string");
Akron587e4d92018-08-31 12:44:26 +0200896
Akronb19803c2018-08-16 16:39:42 +0200897 expect(vcE.firstChild.children.length).toEqual(3);
Akron62ac95b2018-08-30 18:08:25 +0200898 expect(vcE.firstChild.children[1].classList.contains("unspecified")).toBeTruthy();
Akronb19803c2018-08-16 16:39:42 +0200899 });
Akron587e4d92018-08-31 12:44:26 +0200900
901
902 it('should be replaceable by docGroupRef on root', function () {
903 var vc = vcClass.create().fromJson({
904 "@type" : "koral:doc",
905 "key":"Titel",
906 "value":"Baum",
907 "match":"match:eq"
908 });
909
hebastaa0282be2018-12-05 16:58:00 +0100910 KorAP.vc = vc;
Akron587e4d92018-08-31 12:44:26 +0200911 expect(vc.toQuery()).toEqual("Titel = \"Baum\"");
912
913 var vcE = vc.builder();
914 expect(vcE.firstChild.children.length).toEqual(4);
915
916 // Click on the key
917 vcE.firstChild.firstChild.click();
918
919 expect(vcE.firstChild.getElementsByTagName("LI")[0].textContent).toEqual("referTo");
920
921 // Click on referTo
922 vcE.firstChild.getElementsByTagName("LI")[0].click();
923
924 // Now it's a referTo element
925 expect(vcE.firstChild.firstChild.textContent).toEqual("referTo");
926 expect(vcE.firstChild.children.length).toEqual(3);
927 expect(vcE.firstChild.children[1].classList.contains("unspecified")).toBeTruthy();
928 });
929
930 it('should be replaceable by docGroupRef nested', function () {
931 var vc = vcClass.create().fromJson({
932 "@type" : "koral:docGroup",
933 "operation" : "operation:and",
934 "operands" : [
935 {
936 "@type": 'koral:doc',
937 "key" : 'author',
938 "match": 'match:eq',
939 "value": 'Max Birkendale',
940 "type": 'type:string'
941 },
942 {
943 "@type": 'koral:doc',
944 "key": 'pubDate',
945 "match": 'match:eq',
946 "value": '2014-12-05',
947 "type": 'type:date'
948 }
949 ]
950 });
951
hebastaa0282be2018-12-05 16:58:00 +0100952 KorAP.vc = vc;
Akron587e4d92018-08-31 12:44:26 +0200953 expect(vc.toQuery()).toEqual("author = \"Max Birkendale\" & pubDate in 2014-12-05");
954
955 var vcE = vc.builder();
956
957 // First doc
958 var doc = vcE.firstChild.firstChild;
959 expect(doc.children.length).toEqual(4);
960
961 // Click on the key
962 doc.firstChild.click();
963
964 expect(doc.getElementsByTagName("LI")[0].textContent).toEqual("referTo");
965
966 // Click on referTo
967 vcE.firstChild.getElementsByTagName("LI")[0].click();
968
969 // Now it's a referTo element
970 expect(vcE.firstChild.firstChild.firstChild.textContent).toEqual("referTo");
971 expect(vcE.firstChild.firstChild.children.length).toEqual(3);
972 expect(vcE.firstChild.firstChild.children[1].classList.contains("unspecified")).toBeTruthy();
973 });
Nils Diewald7c8ced22015-04-15 19:21:00 +0000974 });
975
Akron88d237e2020-10-21 08:05:18 +0200976 describe('KorAP.VC.DocGroup element', function () {
Nils Diewald7c8ced22015-04-15 19:21:00 +0000977 it('should be initializable', function () {
978
979 var docGroup = docGroupClass.create(undefined, {
Akron712733a2018-04-05 18:17:47 +0200980 "@type" : "koral:docGroup",
981 "operation" : "operation:and",
982 "operands" : [
983 {
984 "@type": 'koral:doc',
985 "key" : 'author',
986 "match": 'match:eq',
987 "value": 'Max Birkendale',
988 "type": 'type:string'
989 },
990 {
991 "@type": 'koral:doc',
992 "key": 'pubDate',
993 "match": 'match:eq',
994 "value": '2014-12-05',
995 "type": 'type:date'
996 }
997 ]
Nils Diewald7c8ced22015-04-15 19:21:00 +0000998 });
999
1000 expect(docGroup.operation()).toEqual('and');
1001 var e = docGroup.element();
1002 expect(e.getAttribute('class')).toEqual('docGroup');
1003 expect(e.getAttribute('data-operation')).toEqual('and');
1004
1005 var first = e.children[0];
1006 expect(first.getAttribute('class')).toEqual('doc');
1007 expect(first.children[0].getAttribute('class')).toEqual('key');
1008 expect(first.children[1].getAttribute('class')).toEqual('match');
1009 expect(first.children[2].getAttribute('class')).toEqual('value');
1010 expect(first.children[2].getAttribute('data-type')).toEqual('string');
1011 expect(first.children[0].firstChild.data).toEqual('author');
1012 expect(first.children[1].firstChild.data).toEqual('eq');
1013 expect(first.children[2].firstChild.data).toEqual('Max Birkendale');
1014
1015 var second = e.children[1];
1016 expect(second.getAttribute('class')).toEqual('doc');
1017 expect(second.children[0].getAttribute('class')).toEqual('key');
1018 expect(second.children[1].getAttribute('class')).toEqual('match');
1019 expect(second.children[2].getAttribute('class')).toEqual('value');
1020 expect(second.children[2].getAttribute('data-type')).toEqual('date');
1021 expect(second.children[0].firstChild.data).toEqual('pubDate');
1022 expect(second.children[1].firstChild.data).toEqual('eq');
1023 expect(second.children[2].firstChild.data).toEqual('2014-12-05');
1024 });
1025
1026 it('should be deserializable with nested groups', function () {
1027 var docGroup = docGroupClass.create(undefined, {
Akron712733a2018-04-05 18:17:47 +02001028 "@type" : "koral:docGroup",
1029 "operation" : "operation:or",
1030 "operands" : [
1031 {
1032 "@type": 'koral:doc',
1033 "key" : 'author',
1034 "match": 'match:eq',
1035 "value": 'Max Birkendale',
1036 "type": 'type:string'
1037 },
1038 {
1039 "@type" : "koral:docGroup",
1040 "operation" : "operation:and",
1041 "operands" : [
1042 {
1043 "@type": 'koral:doc',
1044 "key": 'pubDate',
1045 "match": 'match:geq',
1046 "value": '2014-05-12',
1047 "type": 'type:date'
1048 },
1049 {
1050 "@type": 'koral:doc',
1051 "key": 'pubDate',
1052 "match": 'match:leq',
1053 "value": '2014-12-05',
1054 "type": 'type:date'
1055 }
1056 ]
1057 }
1058 ]
Nils Diewald7c8ced22015-04-15 19:21:00 +00001059 });
1060
1061 expect(docGroup.operation()).toEqual('or');
1062 var e = docGroup.element();
1063 expect(e.getAttribute('class')).toEqual('docGroup');
1064 expect(e.getAttribute('data-operation')).toEqual('or');
1065
1066 expect(e.children[0].getAttribute('class')).toEqual('doc');
1067 var docop = e.children[0].lastChild;
Akron0b489ad2018-02-02 16:49:32 +01001068 expect(docop.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001069 expect(docop.children[0].getAttribute('class')).toEqual('and');
1070 expect(docop.children[1].getAttribute('class')).toEqual('or');
1071 expect(docop.children[2].getAttribute('class')).toEqual('delete');
1072
1073 expect(e.children[1].getAttribute('class')).toEqual('docGroup');
1074 expect(e.children[1].getAttribute('data-operation')).toEqual('and');
1075
1076 // This and-operation can be "or"ed or "delete"d
1077 var secop = e.children[1].children[2];
Akron0b489ad2018-02-02 16:49:32 +01001078 expect(secop.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001079 expect(secop.children[0].getAttribute('class')).toEqual('or');
1080 expect(secop.children[1].getAttribute('class')).toEqual('delete');
1081
1082 // This or-operation can be "and"ed or "delete"d
Akron0b489ad2018-02-02 16:49:32 +01001083 expect(e.children[2].getAttribute('class')).toEqual('operators button-group');
1084 expect(e.lastChild.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001085 expect(e.lastChild.children[0].getAttribute('class')).toEqual('and');
1086 expect(e.lastChild.children[1].getAttribute('class')).toEqual('delete');
1087 });
1088 });
1089
Akron88d237e2020-10-21 08:05:18 +02001090 describe('KorAP.VC.DocGroupRef element', function () {
Akronb19803c2018-08-16 16:39:42 +02001091 it('should be initializable', function () {
1092 var docGroupRef = docGroupRefClass.create(undefined, {
1093 "@type" : "koral:docGroupRef",
1094 "ref" : "@franz/myVC1"
1095 });
1096 expect(docGroupRef.ref()).toEqual("@franz/myVC1");
1097 var dgrE = docGroupRef.element();
1098
Akron3ad46942018-08-22 16:47:14 +02001099 expect(dgrE.children[0].firstChild.data).toEqual("referTo");
Akronb19803c2018-08-16 16:39:42 +02001100 expect(dgrE.children[0].tagName).toEqual("SPAN");
1101 expect(dgrE.children[0].classList.contains("key")).toBeTruthy();
1102 expect(dgrE.children[0].classList.contains("fixed")).toBeTruthy();
1103 expect(dgrE.children[1].firstChild.data).toEqual("@franz/myVC1");
1104 expect(dgrE.children[1].tagName).toEqual("SPAN");
1105 expect(dgrE.children[1].classList.contains("value")).toBeTruthy();
1106 expect(dgrE.children[1].getAttribute("data-type")).toEqual("string");
1107 });
1108
1109 it('should be modifiable on reference', function () {
1110 var docGroupRef = docGroupRefClass.create(undefined, {
1111 "@type" : "koral:docGroupRef",
1112 "ref" : "@franz/myVC1"
1113 });
1114 var dgrE = docGroupRef.element();
1115 expect(docGroupRef.toQuery()).toEqual("referTo \"@franz/myVC1\"");
1116 dgrE.children[1].click();
1117
1118 var input = dgrE.children[1].firstChild;
1119 expect(input.tagName).toEqual("INPUT");
1120 input.value = "Versuch";
1121
1122 var event = new KeyboardEvent("keypress", {
1123 "key" : "[Enter]",
1124 "keyCode" : 13
1125 });
1126
1127 input.dispatchEvent(event);
1128 expect(docGroupRef.toQuery()).toEqual("referTo \"Versuch\"");
1129 });
1130 });
1131
1132
Akron88d237e2020-10-21 08:05:18 +02001133 describe('KorAP.VC.VirtualCorpus', function () {
Nils Diewald7c8ced22015-04-15 19:21:00 +00001134 var simpleGroupFactory = buildFactory(docGroupClass, {
1135 "@type" : "koral:docGroup",
1136 "operation" : "operation:and",
1137 "operands" : [
Akron712733a2018-04-05 18:17:47 +02001138 {
1139 "@type": 'koral:doc',
1140 "key" : 'author',
1141 "match": 'match:eq',
1142 "value": 'Max Birkendale',
1143 "type": 'type:string'
1144 },
1145 {
1146 "@type": 'koral:doc',
1147 "key": 'pubDate',
1148 "match": 'match:eq',
1149 "value": '2014-12-05',
1150 "type": 'type:date'
1151 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00001152 ]
1153 });
1154
1155 var nestedGroupFactory = buildFactory(vcClass, {
1156 "@type" : "koral:docGroup",
1157 "operation" : "operation:or",
1158 "operands" : [
Akron712733a2018-04-05 18:17:47 +02001159 {
1160 "@type": 'koral:doc',
1161 "key" : 'author',
1162 "match": 'match:eq',
1163 "value": 'Max Birkendale',
1164 "type": 'type:string'
1165 },
1166 {
1167 "@type" : "koral:docGroup",
1168 "operation" : "operation:and",
1169 "operands" : [
1170 {
1171 "@type": 'koral:doc',
1172 "key": 'pubDate',
1173 "match": 'match:geq',
1174 "value": '2014-05-12',
1175 "type": 'type:date'
1176 },
1177 {
1178 "@type": 'koral:doc',
1179 "key": 'pubDate',
1180 "match": 'match:leq',
1181 "value": '2014-12-05',
1182 "type": 'type:date'
1183 }
1184 ]
1185 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00001186 ]
1187 });
1188
1189 var flatGroupFactory = buildFactory(vcClass, {
1190 "@type" : "koral:docGroup",
1191 "operation" : "operation:and",
1192 "operands" : [
Akron712733a2018-04-05 18:17:47 +02001193 {
1194 "@type": 'koral:doc',
1195 "key": 'pubDate',
1196 "match": 'match:geq',
1197 "value": '2014-05-12',
1198 "type": 'type:date'
1199 },
1200 {
1201 "@type": 'koral:doc',
1202 "key": 'pubDate',
1203 "match": 'match:leq',
1204 "value": '2014-12-05',
1205 "type": 'type:date'
1206 },
1207 {
1208 "@type": 'koral:doc',
1209 "key": 'foo',
1210 "match": 'match:eq',
1211 "value": 'bar',
1212 "type": 'type:string'
1213 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00001214 ]
1215 });
1216
1217 it('should be initializable', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00001218 var vc = vcClass.create();
Nils Diewald7c8ced22015-04-15 19:21:00 +00001219 expect(vc.element().getAttribute('class')).toEqual('vc');
1220 expect(vc.root().element().getAttribute('class')).toEqual('doc unspecified');
1221
1222 // Not removable
1223 expect(vc.root().element().lastChild.children.length).toEqual(0);
1224 });
1225
1226 it('should be based on a doc', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00001227 var vc = vcClass.create().fromJson({
Akron712733a2018-04-05 18:17:47 +02001228 "@type" : "koral:doc",
1229 "key":"Titel",
1230 "value":"Baum",
1231 "match":"match:eq"
Nils Diewald7c8ced22015-04-15 19:21:00 +00001232 });
1233
1234 expect(vc.element().getAttribute('class')).toEqual('vc');
1235 expect(vc.root().element().getAttribute('class')).toEqual('doc');
1236 expect(vc.root().key()).toEqual('Titel');
1237 expect(vc.root().value()).toEqual('Baum');
1238 expect(vc.root().matchop()).toEqual('eq');
1239
1240 var docE = vc.root().element();
1241 expect(docE.children[0].firstChild.data).toEqual('Titel');
1242 expect(docE.children[1].firstChild.data).toEqual('eq');
1243 expect(docE.children[1].getAttribute('data-type')).toEqual('string');
1244 expect(docE.children[2].firstChild.data).toEqual('Baum');
1245 expect(docE.children[2].getAttribute('data-type')).toEqual('string');
1246 });
1247
1248 it('should be based on a docGroup', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00001249 var vc = vcClass.create().fromJson(simpleGroupFactory.create().toJson());
Nils Diewald7c8ced22015-04-15 19:21:00 +00001250
1251 expect(vc.element().getAttribute('class')).toEqual('vc');
1252 expect(vc.root().element().getAttribute('class')).toEqual('docGroup');
1253 expect(vc.root().operation()).toEqual('and');
1254
1255 var docGroup = vc.root();
1256
1257 var first = docGroup.getOperand(0);
1258 expect(first.key()).toEqual('author');
1259 expect(first.value()).toEqual('Max Birkendale');
1260 expect(first.matchop()).toEqual('eq');
1261
1262 var second = docGroup.getOperand(1);
1263 expect(second.key()).toEqual('pubDate');
1264 expect(second.value()).toEqual('2014-12-05');
1265 expect(second.matchop()).toEqual('eq');
1266 });
1267
Akronb19803c2018-08-16 16:39:42 +02001268 it('should be based on a docGroupRef', function () {
1269 var vc = vcClass.create().fromJson({
1270 "@type" : "koral:docGroupRef",
1271 "ref":"myCorpus"
1272 });
1273
Akronadab5e52018-08-20 13:50:53 +02001274 // iv class="doc groupref"><span class="key fixed">@referTo</span><span data-type="string" class="value">myCorpus</span>
1275 var vcE = vc.builder();
1276 expect(vcE.getAttribute('class')).toEqual('builder');
Akronb19803c2018-08-16 16:39:42 +02001277 expect(vcE.firstChild.tagName).toEqual('DIV');
1278 expect(vcE.firstChild.classList.contains('groupref')).toBeTruthy();
1279
1280 expect(vcE.firstChild.firstChild.tagName).toEqual('SPAN');
1281 expect(vcE.firstChild.firstChild.classList.contains('key')).toBeTruthy();
1282 expect(vcE.firstChild.firstChild.classList.contains('fixed')).toBeTruthy();
1283
Akron3ad46942018-08-22 16:47:14 +02001284 expect(vcE.firstChild.firstChild.textContent).toEqual("referTo");
Akronb19803c2018-08-16 16:39:42 +02001285
1286 expect(vcE.firstChild.children[1].tagName).toEqual('SPAN');
1287 expect(vcE.firstChild.children[1].classList.contains('value')).toBeTruthy();
1288 expect(vcE.firstChild.children[1].getAttribute('data-type')).toEqual('string');
1289 expect(vcE.firstChild.children[1].textContent).toEqual("myCorpus");
1290 });
Nils Diewald7c8ced22015-04-15 19:21:00 +00001291
1292 it('should be based on a nested docGroup', function () {
1293 var vc = nestedGroupFactory.create();
1294
Akronadab5e52018-08-20 13:50:53 +02001295 expect(vc.builder().getAttribute('class')).toEqual('builder');
1296 expect(vc.builder().firstChild.getAttribute('class')).toEqual('docGroup');
1297 expect(vc.builder().firstChild.children[0].getAttribute('class')).toEqual('doc');
1298 var dg = vc.builder().firstChild.children[1];
Nils Diewald7c8ced22015-04-15 19:21:00 +00001299 expect(dg.getAttribute('class')).toEqual('docGroup');
1300 expect(dg.children[0].getAttribute('class')).toEqual('doc');
1301 expect(dg.children[1].getAttribute('class')).toEqual('doc');
Akron0b489ad2018-02-02 16:49:32 +01001302 expect(dg.children[2].getAttribute('class')).toEqual('operators button-group');
Akronadab5e52018-08-20 13:50:53 +02001303 expect(vc.builder().firstChild.children[2].getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001304 });
1305
Akronb19803c2018-08-16 16:39:42 +02001306 it('should be based on a nested docGroupRef', function () {
1307 var vc = vcClass.create().fromJson({
1308 "@type" : "koral:docGroup",
1309 "operation" : "operation:and",
1310 "operands" : [{
1311 "@type" : "koral:docGroupRef",
1312 "ref":"myCorpus"
1313 },{
1314 "@type" : "koral:doc",
1315 "key":"Titel",
1316 "value":"Baum",
1317 "match":"match:eq"
1318 }]
1319 });
1320
1321 expect(vc._root.ldType()).toEqual("docGroup");
1322
1323 expect(vc.toQuery()).toEqual('referTo "myCorpus" & Titel = "Baum"');
1324 });
1325
1326
Nils Diewald7c8ced22015-04-15 19:21:00 +00001327 it('should be modifiable by deletion in flat docGroups', function () {
1328 var vc = flatGroupFactory.create();
1329 var docGroup = vc.root();
1330
1331 expect(docGroup.element().getAttribute('class')).toEqual('docGroup');
1332
1333 var doc = docGroup.getOperand(1);
1334 expect(doc.key()).toEqual("pubDate");
1335 expect(doc.value()).toEqual("2014-12-05");
1336
1337 // Remove operand 1
1338 expect(docGroup.delOperand(doc).update()).not.toBeUndefined();
Akron24aa0052020-11-10 11:00:34 +01001339 expect(doc._el).toEqual(undefined);
Nils Diewald7c8ced22015-04-15 19:21:00 +00001340
1341 doc = docGroup.getOperand(1);
1342 expect(doc.key()).toEqual("foo");
1343
1344 // Remove operand 1
1345 expect(docGroup.delOperand(doc).update()).not.toBeUndefined();
Akron24aa0052020-11-10 11:00:34 +01001346 expect(doc._el).toEqual(undefined);
Nils Diewald7c8ced22015-04-15 19:21:00 +00001347
1348 // Only one operand left ...
1349 expect(docGroup.getOperand(1)).toBeUndefined();
1350 // ... but there shouldn't be a group anymore at all!
1351 expect(docGroup.getOperand(0)).toBeUndefined();
1352
1353 var obj = vc.root();
1354 expect(obj.ldType()).toEqual("doc");
1355 expect(obj.key()).toEqual("pubDate");
1356 expect(obj.value()).toEqual("2014-05-12");
1357
1358 expect(obj.element().getAttribute('class')).toEqual('doc');
1359 });
1360
1361
1362 it('should be modifiable by deletion in nested docGroups (root case)', function () {
1363 var vc = nestedGroupFactory.create();
1364
1365 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001366 'author = "Max Birkendale" | (pubDate since 2014-05-12 & pubDate until 2014-12-05)'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001367 );
1368
1369 var docGroup = vc.root();
1370 expect(docGroup.ldType()).toEqual("docGroup");
1371 expect(docGroup.operation()).toEqual("or");
1372
1373 var doc = docGroup.getOperand(0);
1374 expect(doc.key()).toEqual("author");
1375 expect(doc.value()).toEqual("Max Birkendale");
1376
1377 docGroup = docGroup.getOperand(1);
1378 expect(docGroup.operation()).toEqual("and");
1379
1380 doc = docGroup.getOperand(0);
1381 expect(doc.key()).toEqual("pubDate");
1382 expect(doc.matchop()).toEqual("geq");
1383 expect(doc.value()).toEqual("2014-05-12");
1384 expect(doc.type()).toEqual("date");
1385
1386 doc = docGroup.getOperand(1);
1387 expect(doc.key()).toEqual("pubDate");
1388 expect(doc.matchop()).toEqual("leq");
1389 expect(doc.value()).toEqual("2014-12-05");
1390 expect(doc.type()).toEqual("date");
1391
1392 // Remove first operand so everything becomes root
1393 expect(
Akron712733a2018-04-05 18:17:47 +02001394 vc.root().delOperand(
1395 vc.root().getOperand(0)
1396 ).update().ldType()
Nils Diewald7c8ced22015-04-15 19:21:00 +00001397 ).toEqual("docGroup");
1398
1399 expect(vc.root().ldType()).toEqual("docGroup");
1400 expect(vc.root().operation()).toEqual("and");
1401 expect(vc.root().getOperand(0).ldType()).toEqual("doc");
1402
1403 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001404 'pubDate since 2014-05-12 & pubDate until 2014-12-05'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001405 );
1406 });
1407
1408 it('should be modifiable by deletion in nested docGroups (resolve group case)', function () {
1409 var vc = nestedGroupFactory.create();
1410
1411 // Get nested group
1412 var firstGroup = vc.root().getOperand(1);
1413 firstGroup.append(simpleGroupFactory.create({ "operation" : "operation:or" }));
1414
1415 // Structur is now:
1416 // or(doc, and(doc, doc, or(doc, doc)))
1417
1418 // Get nested or in and
1419 var orGroup = vc.root().getOperand(1).getOperand(2);
1420 expect(orGroup.ldType()).toEqual("docGroup");
1421 expect(orGroup.operation()).toEqual("or");
1422
1423 // Remove
1424 // Structur is now:
1425 // or(doc, and(doc, doc, doc)))
1426 expect(orGroup.delOperand(orGroup.getOperand(0)).update().operation()).toEqual("and");
1427 expect(vc.root().getOperand(1).operands().length).toEqual(3);
1428 });
1429
1430 it('should be modifiable by deletion in nested docGroups (identical group case)', function () {
1431 var vc = nestedGroupFactory.create();
1432
1433 // Get nested group
1434 var firstGroup = vc.root().getOperand(1);
1435 firstGroup.append(simpleGroupFactory.create({
Akron712733a2018-04-05 18:17:47 +02001436 "operation" : "operation:or"
Nils Diewald7c8ced22015-04-15 19:21:00 +00001437 }));
1438 var oldAuthor = firstGroup.getOperand(2).getOperand(0);
1439 oldAuthor.key("title");
1440 oldAuthor.value("Der Birnbaum");
1441
1442 // Structur is now:
1443 // or(doc, and(doc, doc, or(doc, doc)))
1444 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001445 'author = "Max Birkendale" | ' +
1446 '(pubDate since 2014-05-12 & ' +
1447 'pubDate until 2014-12-05 & ' +
1448 '(title = "Der Birnbaum" | ' +
1449 'pubDate in 2014-12-05))'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001450 );
1451
1452 var andGroup = vc.root().getOperand(1);
1453
1454 // Get leading docs in and
1455 var doc1 = andGroup.getOperand(0);
1456 expect(doc1.ldType()).toEqual("doc");
1457 expect(doc1.value()).toEqual("2014-05-12");
1458 var doc2 = andGroup.getOperand(1);
1459 expect(doc2.ldType()).toEqual("doc");
1460 expect(doc2.value()).toEqual("2014-12-05");
1461
1462 // Remove 2
1463 expect(
Akron712733a2018-04-05 18:17:47 +02001464 andGroup.delOperand(doc2).update().operation()
Nils Diewald7c8ced22015-04-15 19:21:00 +00001465 ).toEqual("and");
1466 // Structur is now:
1467 // or(doc, and(doc, or(doc, doc)))
1468
1469 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001470 'author = "Max Birkendale"' +
1471 ' | (pubDate since 2014-05-12 & ' +
1472 '(title = "Der Birnbaum" | pubDate in 2014-12-05))'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001473 );
1474
1475
1476 // Remove 1
1477 expect(andGroup.delOperand(doc1).update().operation()).toEqual("or");
1478 // Structur is now:
1479 // or(doc, doc, doc)
1480
1481 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001482 'author = "Max Birkendale" | title = "Der Birnbaum" | pubDate in 2014-12-05'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001483 );
1484 });
1485
1486 it('should be reducible to unspecification', function () {
1487 var vc = demoFactory.create();
1488
1489 expect(vc.toQuery()).toEqual(vc.root().toQuery());
1490 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001491 '(Titel = "Baum" & Veröffentlichungsort = "hihi" & ' +
1492 '(Titel = "Baum" | Veröffentlichungsort = "hihi")) ' +
1493 '| Untertitel ~ "huhu"');
Akrond141a362018-07-10 18:12:13 +02001494 expect(vc.root().element().lastChild.children[0].innerText).toEqual('and');
1495 expect(vc.root().element().lastChild.children[1].innerText).toEqual('×');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001496 expect(vc.root().delOperand(vc.root().getOperand(0)).update()).not.toBeUndefined();
Akron712733a2018-04-05 18:17:47 +02001497 expect(vc.toQuery()).toEqual('Untertitel ~ "huhu"');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001498
1499 var lc = vc.root().element().lastChild;
Akrond141a362018-07-10 18:12:13 +02001500 expect(lc.children[0].innerText).toEqual('and');
1501 expect(lc.children[1].innerText).toEqual('or');
1502 expect(lc.children[2].innerText).toEqual('×');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001503
1504 // Clean everything
1505 vc.clean();
1506 expect(vc.toQuery()).toEqual('');
1507 });
1508
1509 it('should flatten on import', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00001510 var vc = vcClass.create().fromJson({
Akron712733a2018-04-05 18:17:47 +02001511 "@type":"koral:docGroup",
1512 "operation":"operation:or",
1513 "operands":[
1514 {
1515 "@type":"koral:docGroup",
1516 "operation":"operation:or",
1517 "operands":[
Nils Diewald7c8ced22015-04-15 19:21:00 +00001518 {
Akron712733a2018-04-05 18:17:47 +02001519 "@type":"koral:doc",
1520 "key":"Titel",
1521 "value":"Baum",
1522 "match":"match:eq"
Nils Diewald7c8ced22015-04-15 19:21:00 +00001523 },
1524 {
Akron712733a2018-04-05 18:17:47 +02001525 "@type":"koral:doc",
1526 "key":"Veröffentlichungsort",
1527 "value":"hihi",
1528 "match":"match:eq"
Nils Diewald7c8ced22015-04-15 19:21:00 +00001529 },
1530 {
Akron712733a2018-04-05 18:17:47 +02001531 "@type":"koral:docGroup",
1532 "operation":"operation:or",
1533 "operands":[
1534 {
1535 "@type":"koral:doc",
1536 "key":"Titel",
1537 "value":"Baum",
1538 "match":"match:eq"
1539 },
1540 {
1541 "@type":"koral:doc",
1542 "key":"Veröffentlichungsort",
1543 "value":"hihi",
1544 "match":"match:eq"
1545 }
1546 ]
Nils Diewald7c8ced22015-04-15 19:21:00 +00001547 }
Akron712733a2018-04-05 18:17:47 +02001548 ]
1549 },
1550 {
1551 "@type":"koral:doc",
1552 "key":"Untertitel",
1553 "value":"huhu",
1554 "match":"match:contains"
1555 }
1556 ]
Nils Diewald7c8ced22015-04-15 19:21:00 +00001557 });
Nils Diewaldfda29d92015-01-22 17:28:01 +00001558
Nils Diewald7c8ced22015-04-15 19:21:00 +00001559 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001560 'Titel = "Baum" | Veröffentlichungsort = "hihi" | Untertitel ~ "huhu"'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001561 );
Nils Diewald86dad5b2015-01-28 15:09:07 +00001562 });
Akron1bdf5272018-07-24 18:51:30 +02001563
Akroncd42a142019-07-12 18:55:37 +02001564 it('should be deserializable from collection/corpus 1', function () {
Akron1bdf5272018-07-24 18:51:30 +02001565 var kq = {
1566 "matches":["..."],
1567 "collection":{
1568 "@type": "koral:docGroup",
1569 "operation": "operation:or",
1570 "operands": [{
1571 "@type": "koral:docGroup",
1572 "operation": "operation:and",
1573 "operands": [
1574 {
1575 "@type": "koral:doc",
1576 "key": "title",
1577 "match": "match:eq",
1578 "value": "Der Birnbaum",
1579 "type": "type:string"
1580 },
1581 {
1582 "@type": "koral:doc",
1583 "key": "pubPlace",
1584 "match": "match:eq",
1585 "value": "Mannheim",
1586 "type": "type:string"
1587 },
1588 {
1589 "@type": "koral:docGroup",
1590 "operation": "operation:or",
1591 "operands": [
1592 {
1593 "@type": "koral:doc",
1594 "key": "subTitle",
1595 "match": "match:eq",
1596 "value": "Aufzucht und Pflege",
1597 "type": "type:string"
1598 },
1599 {
1600 "@type": "koral:doc",
1601 "key": "subTitle",
1602 "match": "match:eq",
1603 "value": "Gedichte",
1604 "type": "type:string"
1605 }
1606 ]
1607 }
1608 ]
1609 },{
1610 "@type": "koral:doc",
1611 "key": "pubDate",
1612 "match": "match:geq",
1613 "value": "2015-03-05",
1614 "type": "type:date",
1615 "rewrites" : [{
1616 "@type" : "koral:rewrite",
1617 "operation" : "operation:modification",
1618 "src" : "querySerializer",
1619 "scope" : "tree"
1620 }]
1621 }]
1622 }
1623 };
1624
1625 var vc = vcClass.create().fromJson(kq["collection"]);
1626 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 +02001627
1628 kq["corpus"] = kq["collection"]
1629 delete kq["collection"]
1630
1631 vc = vcClass.create().fromJson(kq["corpus"]);
1632 expect(vc.toQuery()).toEqual('(title = "Der Birnbaum" & pubPlace = "Mannheim" & (subTitle = "Aufzucht und Pflege" | subTitle = "Gedichte")) | pubDate since 2015-03-05');
1633
Akron1bdf5272018-07-24 18:51:30 +02001634 });
1635
1636 it('should be deserializable from collection 2', function () {
1637 var kq = {
1638 "@context": "http://korap.ids-mannheim.de/ns/KoralQuery/v0.3/context.jsonld",
1639 "meta": {},
1640 "query": {
1641 "@type": "koral:token",
1642 "wrap": {
1643 "@type": "koral:term",
1644 "match": "match:eq",
1645 "layer": "orth",
1646 "key": "Baum",
1647 "foundry": "opennlp",
1648 "rewrites": [
1649 {
1650 "@type": "koral:rewrite",
1651 "src": "Kustvakt",
1652 "operation": "operation:injection",
1653 "scope": "foundry"
1654 }
1655 ]
1656 },
1657 "idn": "Baum_2227",
1658 "rewrites": [
1659 {
1660 "@type": "koral:rewrite",
1661 "src": "Kustvakt",
1662 "operation": "operation:injection",
1663 "scope": "idn"
1664 }
1665 ]
1666 },
1667 "collection": {
1668 "@type": "koral:docGroup",
1669 "operation": "operation:and",
1670 "operands": [
1671 {
1672 "@type": "koral:doc",
1673 "match": "match:eq",
1674 "type": "type:regex",
1675 "value": "CC-BY.*",
1676 "key": "availability"
1677 },
1678 {
1679 "@type": "koral:doc",
1680 "match": "match:eq",
1681 "type":"type:text",
1682 "value": "Goethe",
1683 "key": "author"
1684 }
1685 ],
1686 "rewrites": [
1687 {
1688 "@type": "koral:rewrite",
1689 "src": "Kustvakt",
1690 "operation": "operation:insertion",
1691 "scope": "availability(FREE)"
1692 }
1693 ]
1694 },
1695 "matches": []
1696 };
1697
1698 var vc = vcClass.create().fromJson(kq["collection"]);
1699 expect(vc.toQuery()).toEqual('availability = /CC-BY.*/ & author = "Goethe"');
1700 });
Nils Diewald86dad5b2015-01-28 15:09:07 +00001701
Akroncd42a142019-07-12 18:55:37 +02001702
Akron8a670162018-08-28 10:09:13 +02001703 it('shouldn\'t be deserializable from collection with unknown type', function () {
1704 var kq = {
1705 "@type" : "koral:doc",
1706 "match": "match:eq",
1707 "type":"type:failure",
1708 "value": "Goethe",
1709 "key": "author"
1710 };
Akron1bdf5272018-07-24 18:51:30 +02001711
Akron8a670162018-08-28 10:09:13 +02001712 expect(function () {
1713 vcClass.create().fromJson(kq)
1714 }).toThrow(new Error("Unknown value type: string"));
1715 });
1716
1717 it('should return a name', function () {
1718 var vc = vcClass.create();
1719 expect(vc.getName()).toEqual(KorAP.Locale.VC_allCorpora);
1720
1721 vc = vcClass.create().fromJson({"@type" : "koral:docGroupRef", "ref" : "DeReKo"});
1722 expect(vc.getName()).toEqual("DeReKo");
1723
1724 vc = vcClass.create().fromJson({"@type" : "koral:doc", "key" : "author", "value" : "Peter"});
1725 expect(vc.getName()).toEqual(KorAP.Locale.VC_oneCollection);
1726 });
Akrond2474aa2018-08-28 12:06:27 +02001727
1728 it('should check for rewrites', function () {
1729
1730 var vc = vcClass.create().fromJson({
1731 "@type" : "koral:doc",
1732 "key" : "author",
1733 "value" : "Goethe",
1734 "rewrites" : [{
1735 "@type" : "koral:rewrite",
1736 "operation" : "operation:modification",
1737 "src" : "querySerializer",
1738 "scope" : "value"
1739 }]
1740 });
1741 expect(vc.wasRewritten()).toBeTruthy();
1742
1743 var nested = {
1744 "@type" : "koral:docGroup",
1745 "operation" : "operation:or",
1746 "operands" : [
1747 {
1748 "@type" : "koral:doc",
1749 "key" : "author",
1750 "value" : "Goethe"
1751 },
1752 {
1753 "@type" : "koral:docGroup",
1754 "operation" : "operation:and",
1755 "operands" : [
1756 {
1757 "@type": "koral:doc",
1758 "key" : "author",
1759 "value" : "Schiller"
1760 },
1761 {
1762 "@type": "koral:doc",
1763 "key" : "author",
1764 "value" : "Fontane"
1765 }
1766 ]
1767 }
1768 ]
1769 };
1770 vc = vcClass.create().fromJson(nested);
1771 expect(vc.wasRewritten()).toBe(false);
1772
1773 nested["operands"][1]["operands"][1]["rewrites"] = [{
1774 "@type" : "koral:rewrite",
1775 "operation" : "operation:modification",
1776 "src" : "querySerializer",
1777 "scope" : "tree"
1778 }];
1779 vc = vcClass.create().fromJson(nested);
1780 expect(vc.wasRewritten()).toBeTruthy();
1781 });
Akron4feec9d2018-11-20 17:00:50 +01001782
1783 it('should add document at virtual corpus', function () {
1784 vc = vcClass.create();
1785 expect(vc.toQuery()).toEqual("");
1786
1787 let doc = docClass.create();
1788 doc.key("author");
1789 doc.type("string");
1790 doc.matchop("eq");
1791 doc.value("Goethe");
1792 expect(doc.toQuery()).toEqual('author = "Goethe"');
1793
1794 expect(vc.element().firstChild.children.length).toEqual(1);
1795 expect(vc.element().firstChild.firstChild.classList.contains("unspecified")).toBeTruthy();
1796
1797 vc.addRequired(doc);
1798 expect(vc.toQuery()).toEqual('author = "Goethe"');
1799
1800 expect(vc.element().firstChild.children.length).toEqual(1);
1801 expect(vc.element().firstChild.firstChild.classList.contains("doc")).toBeTruthy();
1802
1803 // Add as 'and' to doc
1804 let doc2 = docClass.create();
1805 doc2.key("author");
1806 doc2.type("string");
1807 doc2.matchop("eq");
1808 doc2.value("Schiller");
1809 vc.addRequired(doc2);
1810 expect(vc.toQuery()).toEqual('author = "Goethe" & author = "Schiller"');
1811
1812 expect(vc.element().firstChild.firstChild.classList.contains("docGroup")).toBeTruthy();
1813 expect(vc.element().firstChild.firstChild.children[0].classList.contains("doc")).toBeTruthy();
1814 expect(vc.element().firstChild.firstChild.children[1].classList.contains("doc")).toBeTruthy();
1815
1816
1817 // Add as 'and' to 'and'-docGroup
1818 let doc3 = docClass.create();
1819 doc3.key("author");
1820 doc3.type("string");
1821 doc3.matchop("eq");
1822 doc3.value("Fontane");
1823 vc.addRequired(doc3);
1824 expect(vc.toQuery()).toEqual('author = "Goethe" & author = "Schiller" & author = "Fontane"');
1825
1826 expect(vc.element().firstChild.firstChild.classList.contains("docGroup")).toBeTruthy();
1827 expect(vc.element().firstChild.firstChild.children[0].classList.contains("doc")).toBeTruthy();
1828 expect(vc.element().firstChild.firstChild.children[1].classList.contains("doc")).toBeTruthy();
1829 expect(vc.element().firstChild.firstChild.children[2].classList.contains("doc")).toBeTruthy();
1830
1831 // Add as 'and' to 'or'-docGroup
1832 vc = vcClass.create().fromJson({
1833 "@type" : 'koral:docGroup',
1834 'operation' : 'operation:or',
1835 'operands' : [
1836 {
1837 '@type' : 'koral:doc',
1838 'key' : 'title',
1839 'value' : 'Hello World!'
1840 },
1841 {
1842 '@type' : 'koral:doc',
1843 'key' : 'foo',
1844 'value' : 'bar'
1845 }
1846 ]
1847 });
1848 expect(vc.toQuery()).toEqual('title = "Hello World!" | foo = "bar"');
1849
1850 let doc4 = docClass.create();
1851 doc4.key("author");
1852 doc4.type("string");
1853 doc4.matchop("eq");
1854 doc4.value("Fontane");
1855 vc.addRequired(doc4);
1856 expect(vc.toQuery()).toEqual('(title = "Hello World!" | foo = "bar") & author = "Fontane"');
1857
1858 // Add as 'and' to 'or'-docGroup
1859 vc = vcClass.create().fromJson({
1860 "@type" : "koral:docGroupRef",
1861 "ref" : "@max/myCorpus"
1862 })
1863 let doc5 = docClass.create();
1864 doc5.key("author");
1865 doc5.type("string");
1866 doc5.matchop("eq");
1867 doc5.value("Goethe");
1868 expect(doc5.toQuery()).toEqual('author = "Goethe"');
1869 vc.addRequired(doc5);
1870 expect(vc.toQuery()).toEqual('referTo "@max/myCorpus" & author = "Goethe"');
1871 });
Akron13af2f42019-07-25 15:06:21 +02001872
1873 it('should be replaceble via JSON', function () {
1874 let vc = KorAP.vc = vcClass.create().fromJson({
1875 "@type" : 'koral:docGroup',
1876 'operation' : 'operation:or',
1877 'operands' : [
1878 {
1879 '@type' : 'koral:doc',
1880 'key' : 'title',
1881 'value' : 'Hello World!'
1882 },
1883 {
1884 '@type' : 'koral:doc',
1885 'key' : 'foo',
1886 'value' : 'bar'
1887 }
1888 ]
1889 });
1890
1891 expect(vc.toQuery()).toEqual('title = "Hello World!" | foo = "bar"')
1892
1893 let e = vc.element();
1894 expect(e.firstChild.firstChild.firstChild.children[0].textContent).toEqual("title");
1895 expect(e.firstChild.firstChild.firstChild.children[2].textContent).toEqual("Hello World!");
1896
1897 vc.fromJson({
1898 '@type' : 'koral:doc',
1899 'key' : 'foo',
1900 'value' : 'bar'
1901 });
1902
1903 expect(vc.toQuery()).toEqual('foo = "bar"');
1904 e = vc.element();
1905 expect(e.firstChild.firstChild.children[0].textContent).toEqual("foo");
1906 expect(e.firstChild.firstChild.children[2].textContent).toEqual("bar");
1907 })
Akron1bdf5272018-07-24 18:51:30 +02001908 });
1909
1910
Akron88d237e2020-10-21 08:05:18 +02001911 describe('KorAP.VC.Operators', function () {
Nils Diewald7c8ced22015-04-15 19:21:00 +00001912 it('should be initializable', function () {
1913 var op = operatorsClass.create(true, false, false);
1914 expect(op.and()).toBeTruthy();
1915 expect(op.or()).not.toBeTruthy();
1916 expect(op.del()).not.toBeTruthy();
1917
1918 op.and(false);
1919 expect(op.and()).not.toBeTruthy();
1920 expect(op.or()).not.toBeTruthy();
1921 expect(op.del()).not.toBeTruthy();
1922
1923 op.or(true);
1924 op.del(true);
1925 expect(op.and()).not.toBeTruthy();
1926 expect(op.or()).toBeTruthy();
1927 expect(op.del()).toBeTruthy();
1928
Akrond141a362018-07-10 18:12:13 +02001929 var e = op.update();
Akron0b489ad2018-02-02 16:49:32 +01001930 expect(e.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001931 expect(e.children[0].getAttribute('class')).toEqual('or');
Akrond141a362018-07-10 18:12:13 +02001932 expect(e.children[0].innerText).toEqual('or');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001933 expect(e.children[1].getAttribute('class')).toEqual('delete');
Akrond141a362018-07-10 18:12:13 +02001934 expect(e.children[1].innerText).toEqual('×');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001935
1936 op.and(true);
1937 op.del(false);
Akrond141a362018-07-10 18:12:13 +02001938 e = op.update();
Nils Diewald7c8ced22015-04-15 19:21:00 +00001939
Akron0b489ad2018-02-02 16:49:32 +01001940 expect(e.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001941 expect(e.children[0].getAttribute('class')).toEqual('and');
Akrond141a362018-07-10 18:12:13 +02001942 expect(e.children[0].innerText).toEqual('and');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001943 expect(e.children[1].getAttribute('class')).toEqual('or');
Akrond141a362018-07-10 18:12:13 +02001944 expect(e.children[1].innerText).toEqual('or');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001945 });
1946 });
1947
Akron88d237e2020-10-21 08:05:18 +02001948 describe('KorAP.VC._delete (event)', function () {
Nils Diewald7c8ced22015-04-15 19:21:00 +00001949 var complexVCFactory = buildFactory(vcClass,{
1950 "@type": 'koral:docGroup',
1951 'operation' : 'operation:and',
1952 'operands' : [
Akron712733a2018-04-05 18:17:47 +02001953 {
1954 "@type": 'koral:doc',
1955 "key": 'pubDate',
1956 "match": 'match:eq',
1957 "value": '2014-12-05',
1958 "type": 'type:date'
1959 },
1960 {
1961 "@type" : 'koral:docGroup',
1962 'operation' : 'operation:or',
1963 'operands' : [
1964 {
1965 '@type' : 'koral:doc',
1966 'key' : 'title',
1967 'value' : 'Hello World!'
1968 },
1969 {
1970 '@type' : 'koral:doc',
1971 'key' : 'foo',
1972 'value' : 'bar'
1973 }
1974 ]
1975 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00001976 ]
1977 });
1978
1979 it('should clean on root docs', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00001980 var vc = vcClass.create().fromJson({
Akron712733a2018-04-05 18:17:47 +02001981 "@type": 'koral:doc',
1982 "key": 'pubDate',
1983 "match": 'match:eq',
1984 "value": '2014-12-05',
1985 "type": 'type:date'
Nils Diewald86dad5b2015-01-28 15:09:07 +00001986 });
Nils Diewald7c8ced22015-04-15 19:21:00 +00001987 expect(vc.root().toQuery()).toEqual('pubDate in 2014-12-05');
Akron0b489ad2018-02-02 16:49:32 +01001988 expect(vc.root().element().lastChild.getAttribute('class')).toEqual('operators button-group');
Nils Diewald86dad5b2015-01-28 15:09:07 +00001989
Nils Diewald7c8ced22015-04-15 19:21:00 +00001990 // Clean with delete from root
1991 expect(vc.root().element().lastChild.lastChild.getAttribute('class')).toEqual('delete');
1992 _delOn(vc.root());
1993 expect(vc.root().toQuery()).toEqual('');
Akronebc96662018-08-29 17:36:20 +02001994 expect(vc.root().element().lastChild.lastChild.data).toEqual(KorAP.Locale.EMPTY);
1995 expect(vc.root().element().classList.contains('unspecified')).toEqual(true);
Nils Diewald7c8ced22015-04-15 19:21:00 +00001996 });
Nils Diewald86dad5b2015-01-28 15:09:07 +00001997
Nils Diewald7c8ced22015-04-15 19:21:00 +00001998 it('should remove on nested docs', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00001999 var vc = vcClass.create().fromJson(
Akron712733a2018-04-05 18:17:47 +02002000 {
2001 "@type": 'koral:docGroup',
2002 'operation' : 'operation:and',
2003 'operands' : [
2004 {
2005 "@type": 'koral:doc',
2006 "key": 'pubDate',
2007 "match": 'match:eq',
2008 "value": '2014-12-05',
2009 "type": 'type:date'
2010 },
2011 {
2012 "@type" : 'koral:doc',
2013 'key' : 'foo',
2014 'value' : 'bar'
2015 }
2016 ]
2017 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00002018 );
2019
2020 // Delete with direct element access
2021 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar"');
2022 _delOn(vc.root().getOperand(0));
2023
2024 expect(vc.toQuery()).toEqual('foo = "bar"');
2025 expect(vc.root().ldType()).toEqual('doc');
2026 });
2027
2028 it('should clean on doc groups', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00002029 var vc = vcClass.create().fromJson(
Akron712733a2018-04-05 18:17:47 +02002030 {
2031 "@type": 'koral:docGroup',
2032 'operation' : 'operation:and',
2033 'operands' : [
2034 {
2035 "@type": 'koral:doc',
2036 "key": 'pubDate',
2037 "match": 'match:eq',
2038 "value": '2014-12-05',
2039 "type": 'type:date'
2040 },
2041 {
2042 "@type" : 'koral:doc',
2043 'key' : 'foo',
2044 'value' : 'bar'
2045 }
2046 ]
2047 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00002048 );
2049
2050 // Cleanwith direct element access
2051 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar"');
2052 _delOn(vc.root());
2053 expect(vc.toQuery()).toEqual('');
2054 expect(vc.root().ldType()).toEqual('non');
2055 });
2056
2057 it('should remove on nested doc groups (case of ungrouping 1)', function () {
2058 var vc = complexVCFactory.create();
2059
2060 // Delete with direct element access
2061 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02002062 'pubDate in 2014-12-05 & (title = "Hello World!" | foo = "bar")'
Nils Diewald7c8ced22015-04-15 19:21:00 +00002063 );
2064
2065 // Remove hello world:
2066 _delOn(vc.root().getOperand(1).getOperand(0));
2067 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar"');
2068 expect(vc.root().ldType()).toEqual('docGroup');
2069 });
2070
2071 it('should remove on nested doc groups (case of ungrouping 2)', function () {
2072 var vc = complexVCFactory.create();
2073
2074 // Delete with direct element access
2075 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02002076 'pubDate in 2014-12-05 & (title = "Hello World!" | foo = "bar")'
Nils Diewald7c8ced22015-04-15 19:21:00 +00002077 );
2078
2079 // Remove bar
2080 _delOn(vc.root().getOperand(1).getOperand(1));
2081 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & title = "Hello World!"');
2082 expect(vc.root().ldType()).toEqual('docGroup');
2083 expect(vc.root().operation()).toEqual('and');
2084 });
2085
2086 it('should remove on nested doc groups (case of root changing)', function () {
2087 var vc = complexVCFactory.create();
2088
2089 // Delete with direct element access
2090 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02002091 'pubDate in 2014-12-05 & ' +
2092 '(title = "Hello World!" | foo = "bar")'
Nils Diewald7c8ced22015-04-15 19:21:00 +00002093 );
2094
2095 // Remove bar
2096 _delOn(vc.root().getOperand(0));
2097 expect(vc.toQuery()).toEqual('title = "Hello World!" | foo = "bar"');
2098 expect(vc.root().ldType()).toEqual('docGroup');
2099 expect(vc.root().operation()).toEqual('or');
2100 });
2101
2102 it('should remove on nested doc groups (list flattening)', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00002103 var vc = vcClass.create().fromJson(
Akron712733a2018-04-05 18:17:47 +02002104 {
2105 "@type": 'koral:docGroup',
2106 'operation' : 'operation:or',
2107 'operands' : [
2108 {
2109 "@type": 'koral:doc',
2110 "key": 'pubDate',
2111 "match": 'match:eq',
2112 "value": '2014-12-05',
2113 "type": 'type:date'
2114 },
2115 {
2116 "@type" : 'koral:doc',
2117 'key' : 'foo',
2118 'value' : 'bar'
2119 },
2120 {
2121 "@type": 'koral:docGroup',
2122 'operation' : 'operation:and',
2123 'operands' : [
2124 {
2125 "@type": 'koral:doc',
2126 "key": 'pubDate',
2127 "match": 'match:eq',
2128 "value": '2014-12-05',
2129 "type": 'type:date'
2130 },
2131 {
2132 "@type" : 'koral:docGroup',
2133 'operation' : 'operation:or',
2134 'operands' : [
2135 {
2136 '@type' : 'koral:doc',
2137 'key' : 'title',
2138 'value' : 'Hello World!'
2139 },
2140 {
2141 '@type' : 'koral:doc',
2142 'key' : 'yeah',
2143 'value' : 'juhu'
2144 }
2145 ]
2146 }
2147 ]
2148 }
2149 ]
2150 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00002151 );
2152
2153 // Delete with direct element access
2154 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02002155 'pubDate in 2014-12-05 | foo = "bar" | ' +
2156 '(pubDate in 2014-12-05 & ' +
2157 '(title = "Hello World!" | yeah = "juhu"))'
Nils Diewald7c8ced22015-04-15 19:21:00 +00002158 );
2159
2160 expect(vc.root().ldType()).toEqual('docGroup');
2161 expect(vc.root().operation()).toEqual('or');
2162
2163 // Operands and operators
Akronadab5e52018-08-20 13:50:53 +02002164 expect(vc.builder().firstChild.children.length).toEqual(4);
2165 expect(vc.builder().firstChild.lastChild.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +00002166
2167 // Remove inner group and flatten
2168 _delOn(vc.root().getOperand(2).getOperand(0));
2169
2170 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02002171 'pubDate in 2014-12-05 | foo = "bar" | title = "Hello World!" | yeah = "juhu"'
Nils Diewald7c8ced22015-04-15 19:21:00 +00002172 );
2173 expect(vc.root().ldType()).toEqual('docGroup');
2174 expect(vc.root().operation()).toEqual('or');
2175
2176 // Operands and operators
Akronadab5e52018-08-20 13:50:53 +02002177 expect(vc.builder().firstChild.children.length).toEqual(5);
2178 expect(vc.builder().firstChild.lastChild.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +00002179 });
2180 });
2181
Akron88d237e2020-10-21 08:05:18 +02002182 describe('KorAP.VC._add (event)', function () {
Nils Diewald7c8ced22015-04-15 19:21:00 +00002183 var complexVCFactory = buildFactory(vcClass,{
2184 "@type": 'koral:docGroup',
2185 'operation' : 'operation:and',
2186 'operands' : [
Akron712733a2018-04-05 18:17:47 +02002187 {
2188 "@type": 'koral:doc',
2189 "key": 'pubDate',
2190 "match": 'match:eq',
2191 "value": '2014-12-05',
2192 "type": 'type:date'
2193 },
2194 {
2195 "@type" : 'koral:docGroup',
2196 'operation' : 'operation:or',
2197 'operands' : [
2198 {
2199 '@type' : 'koral:doc',
2200 'key' : 'title',
2201 'value' : 'Hello World!'
2202 },
2203 {
2204 '@type' : 'koral:doc',
2205 'key' : 'foo',
2206 'value' : 'bar'
2207 }
2208 ]
2209 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00002210 ]
2211 });
2212
2213 it('should add new unspecified doc with "and"', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00002214 var vc = vcClass.create().fromJson(
Akron712733a2018-04-05 18:17:47 +02002215 {
2216 "@type": 'koral:docGroup',
2217 'operation' : 'operation:and',
2218 'operands' : [
2219 {
2220 "@type": 'koral:doc',
2221 "key": 'pubDate',
2222 "match": 'match:eq',
2223 "value": '2014-12-05',
2224 "type": 'type:date'
2225 },
2226 {
2227 "@type" : 'koral:doc',
2228 'key' : 'foo',
2229 'value' : 'bar'
Akronb19803c2018-08-16 16:39:42 +02002230 },
2231 {
2232 "@type" : "koral:docGroupRef",
2233 "ref" : "myCorpus"
Akron712733a2018-04-05 18:17:47 +02002234 }
2235 ]
2236 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00002237 );
2238
Akronb19803c2018-08-16 16:39:42 +02002239 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar" & referTo "myCorpus"');
Nils Diewald7c8ced22015-04-15 19:21:00 +00002240
Akronadab5e52018-08-20 13:50:53 +02002241 var fc = vc.builder().firstChild;
Nils Diewald7c8ced22015-04-15 19:21:00 +00002242 expect(fc.getAttribute('data-operation')).toEqual('and');
Akronb19803c2018-08-16 16:39:42 +02002243 expect(fc.children.length).toEqual(4);
Akron0b489ad2018-02-02 16:49:32 +01002244 expect(fc.lastChild.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +00002245 expect(fc.children[0].getAttribute('class')).toEqual('doc');
2246 expect(fc.children[1].getAttribute('class')).toEqual('doc');
Akronb19803c2018-08-16 16:39:42 +02002247 expect(fc.children[2].getAttribute('class')).toEqual('doc groupref');
Nils Diewald7c8ced22015-04-15 19:21:00 +00002248
2249 // add with 'and' in the middle
2250 _andOn(vc.root().getOperand(0));
Akronb19803c2018-08-16 16:39:42 +02002251 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar" & referTo "myCorpus"');
Nils Diewald7c8ced22015-04-15 19:21:00 +00002252
Akronadab5e52018-08-20 13:50:53 +02002253 fc = vc.builder().firstChild;
Nils Diewald7c8ced22015-04-15 19:21:00 +00002254 expect(fc.getAttribute('data-operation')).toEqual('and');
Akronb19803c2018-08-16 16:39:42 +02002255 expect(fc.children.length).toEqual(5);
Akron0b489ad2018-02-02 16:49:32 +01002256 expect(fc.lastChild.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +00002257
2258 expect(fc.children[0].getAttribute('class')).toEqual('doc');
2259 expect(fc.children[1].getAttribute('class')).toEqual('doc unspecified');
2260 expect(fc.children[2].getAttribute('class')).toEqual('doc');
Akronb19803c2018-08-16 16:39:42 +02002261 expect(fc.children[3].getAttribute('class')).toEqual('doc groupref');
2262 expect(fc.children[4].classList.contains('button-group')).toBeTruthy();
2263 expect(fc.children.length).toEqual(5);
2264
2265 _andOn(vc.root().getOperand(3));
2266 expect(fc.children[0].getAttribute('class')).toEqual('doc');
2267 expect(fc.children[1].getAttribute('class')).toEqual('doc unspecified');
2268 expect(fc.children[2].getAttribute('class')).toEqual('doc');
2269 expect(fc.children[3].getAttribute('class')).toEqual('doc groupref');
2270 expect(fc.children[4].getAttribute('class')).toEqual('doc unspecified');
2271 expect(fc.children[5].classList.contains('button-group')).toBeTruthy();
2272 expect(fc.children.length).toEqual(6);
2273
Nils Diewald7c8ced22015-04-15 19:21:00 +00002274 });
2275
Akronb19803c2018-08-16 16:39:42 +02002276
Nils Diewald7c8ced22015-04-15 19:21:00 +00002277 it('should add new unspecified doc with "or"', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00002278 var vc = vcClass.create().fromJson(
Akron712733a2018-04-05 18:17:47 +02002279 {
2280 "@type": 'koral:docGroup',
2281 'operation' : 'operation:and',
2282 'operands' : [
2283 {
2284 "@type": 'koral:doc',
2285 "key": 'pubDate',
2286 "match": 'match:eq',
2287 "value": '2014-12-05',
2288 "type": 'type:date'
2289 },
2290 {
2291 "@type" : 'koral:doc',
2292 'key' : 'foo',
2293 'value' : 'bar'
Akronb19803c2018-08-16 16:39:42 +02002294 },
2295 {
2296 "@type" : "koral:docGroupRef",
2297 "ref" : "myCorpus"
Akron712733a2018-04-05 18:17:47 +02002298 }
2299 ]
2300 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00002301 );
2302
Akronb19803c2018-08-16 16:39:42 +02002303 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar" & referTo "myCorpus"');
Nils Diewald7c8ced22015-04-15 19:21:00 +00002304
Akronadab5e52018-08-20 13:50:53 +02002305 var fc = vc.builder().firstChild;
Akronb19803c2018-08-16 16:39:42 +02002306 expect(fc.children.length).toEqual(4);
Akron0b489ad2018-02-02 16:49:32 +01002307 expect(fc.lastChild.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +00002308 expect(fc.children[0].getAttribute('class')).toEqual('doc');
2309 expect(fc.children[1].getAttribute('class')).toEqual('doc');
Akronb19803c2018-08-16 16:39:42 +02002310 expect(fc.children[2].getAttribute('class')).toEqual('doc groupref');
Nils Diewald7c8ced22015-04-15 19:21:00 +00002311
2312 // add with 'or' in the middle
2313 _orOn(vc.root().getOperand(0));
Akronb19803c2018-08-16 16:39:42 +02002314 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar" & referTo "myCorpus"');
Akronadab5e52018-08-20 13:50:53 +02002315 fc = vc.builder().firstChild;
Nils Diewald7c8ced22015-04-15 19:21:00 +00002316
2317 expect(fc.getAttribute('data-operation')).toEqual('and');
Akronb19803c2018-08-16 16:39:42 +02002318 expect(fc.children.length).toEqual(4);
Nils Diewald7c8ced22015-04-15 19:21:00 +00002319 expect(fc.children[0].getAttribute('class')).toEqual('docGroup');
2320 expect(fc.children[0].getAttribute('data-operation')).toEqual('or');
2321 expect(fc.children[1].getAttribute('class')).toEqual('doc');
Akronb19803c2018-08-16 16:39:42 +02002322 expect(fc.children[2].getAttribute('class')).toEqual('doc groupref');
2323 expect(fc.children[3].getAttribute('class')).toEqual('operators button-group');
Akron0b489ad2018-02-02 16:49:32 +01002324 expect(fc.lastChild.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +00002325
Akronadab5e52018-08-20 13:50:53 +02002326 fc = vc.builder().firstChild.firstChild;
Nils Diewald7c8ced22015-04-15 19:21:00 +00002327 expect(fc.children.length).toEqual(3);
2328 expect(fc.children[0].getAttribute('class')).toEqual('doc');
2329 expect(fc.children[1].getAttribute('class')).toEqual('doc unspecified');
Akron0b489ad2018-02-02 16:49:32 +01002330 expect(fc.children[2].getAttribute('class')).toEqual('operators button-group');
2331 expect(fc.lastChild.getAttribute('class')).toEqual('operators button-group');
Akronb19803c2018-08-16 16:39:42 +02002332
2333 _orOn(vc.root().getOperand(2));
Akronadab5e52018-08-20 13:50:53 +02002334 fc = vc.builder().firstChild;
Akronb19803c2018-08-16 16:39:42 +02002335 expect(fc.children.length).toEqual(4);
2336
2337 expect(fc.children[0].getAttribute('class')).toEqual('docGroup');
2338 expect(fc.children[1].getAttribute('class')).toEqual('doc');
2339 expect(fc.children[2].getAttribute('class')).toEqual('docGroup');
2340 expect(fc.children[3].getAttribute('class')).toEqual('operators button-group');
2341
Akronadab5e52018-08-20 13:50:53 +02002342 fc = vc.builder().firstChild.children[2];
Akronb19803c2018-08-16 16:39:42 +02002343 expect(fc.children[0].getAttribute('class')).toEqual('doc groupref');
2344 expect(fc.children[1].getAttribute('class')).toEqual('doc unspecified');
2345 expect(fc.children[2].getAttribute('class')).toEqual('operators button-group');
2346 expect(fc.lastChild.getAttribute('class')).toEqual('operators button-group');
2347
Nils Diewald7c8ced22015-04-15 19:21:00 +00002348 });
2349
2350 it('should add new unspecified doc with "and" before group', function () {
2351 var vc = demoFactory.create();
2352
2353 // Wrap with direct element access
2354 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02002355 '(Titel = "Baum" & ' +
2356 'Veröffentlichungsort = "hihi" & ' +
2357 '(Titel = "Baum" | ' +
2358 'Veröffentlichungsort = "hihi")) | ' +
2359 'Untertitel ~ "huhu"'
Nils Diewald7c8ced22015-04-15 19:21:00 +00002360 );
2361
2362 expect(vc.root().getOperand(0).ldType()).toEqual('docGroup');
2363 expect(vc.root().getOperand(0).operation()).toEqual('and');
2364 expect(vc.root().getOperand(0).operands().length).toEqual(3);
2365
2366 // Add unspecified on the second doc
2367 var secDoc = vc.root().getOperand(0).getOperand(1);
2368 expect(secDoc.value()).toEqual('hihi');
2369
2370 // Add
2371 _andOn(secDoc);
2372
2373 var fo = vc.root().getOperand(0);
2374
2375 expect(fo.ldType()).toEqual('docGroup');
2376 expect(fo.operation()).toEqual('and');
2377 expect(fo.operands().length).toEqual(4);
2378
2379 expect(fo.getOperand(0).ldType()).toEqual('doc');
2380 expect(fo.getOperand(1).ldType()).toEqual('doc');
2381 expect(fo.getOperand(2).ldType()).toEqual('non');
2382 expect(fo.getOperand(3).ldType()).toEqual('docGroup');
2383 });
2384
2385
2386 it('should remove a doc with an unspecified doc in a nested group', function () {
2387 var vc = demoFactory.create();
2388
2389 // Wrap with direct element access
2390 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02002391 '(Titel = "Baum" & Veröffentlichungsort = "hihi" & (Titel = "Baum" | Veröffentlichungsort = "hihi")) | Untertitel ~ "huhu"'
Nils Diewald7c8ced22015-04-15 19:21:00 +00002392 );
2393
2394 var fo = vc.root().getOperand(0).getOperand(0);
2395 expect(fo.key()).toEqual('Titel');
2396 expect(fo.value()).toEqual('Baum');
2397
2398 // Add unspecified on the root group
2399 _orOn(fo);
2400
2401 fo = vc.root().getOperand(0).getOperand(0);
2402
2403 expect(fo.operation()).toEqual('or');
2404 expect(fo.getOperand(0).ldType()).toEqual('doc');
2405 expect(fo.getOperand(1).ldType()).toEqual('non');
2406
2407 // Delete document
2408 _delOn(fo.getOperand(0));
2409
2410 // The operand is now non
2411 expect(vc.root().getOperand(0).getOperand(0).ldType()).toEqual('non');
2412 expect(vc.root().getOperand(0).getOperand(1).ldType()).toEqual('doc');
2413 expect(vc.root().getOperand(0).getOperand(2).ldType()).toEqual('docGroup');
2414 });
2415
2416
Akron712733a2018-04-05 18:17:47 +02002417 it('should remove an unspecified doc with a doc in a nested group', function () {
Nils Diewald7c8ced22015-04-15 19:21:00 +00002418 var vc = demoFactory.create();
2419
2420 // Wrap with direct element access
2421 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02002422 '(Titel = "Baum" & ' +
2423 'Veröffentlichungsort = "hihi" & ' +
2424 '(Titel = "Baum" ' +
2425 '| Veröffentlichungsort = "hihi")) | ' +
2426 'Untertitel ~ "huhu"'
Nils Diewald7c8ced22015-04-15 19:21:00 +00002427 );
2428
2429 var fo = vc.root().getOperand(0).getOperand(0);
2430 expect(fo.key()).toEqual('Titel');
2431 expect(fo.value()).toEqual('Baum');
2432
2433 // Add unspecified on the root group
2434 _orOn(fo);
2435
2436 fo = vc.root().getOperand(0).getOperand(0);
2437
2438 expect(fo.operation()).toEqual('or');
2439 expect(fo.getOperand(0).ldType()).toEqual('doc');
2440 expect(fo.getOperand(1).ldType()).toEqual('non');
2441
2442 // Delete unspecified doc
2443 _delOn(fo.getOperand(1));
2444
2445 // The operand is now non
2446 fo = vc.root().getOperand(0);
2447 expect(fo.getOperand(0).ldType()).toEqual('doc');
2448 expect(fo.getOperand(0).key()).toEqual('Titel');
2449 expect(fo.getOperand(0).value()).toEqual('Baum');
2450 expect(fo.getOperand(1).ldType()).toEqual('doc');
2451 expect(fo.getOperand(2).ldType()).toEqual('docGroup');
2452 });
2453
2454
2455 it('should add on parent group (case "and")', function () {
2456 var vc = complexVCFactory.create();
2457
2458 // Wrap with direct element access
2459 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02002460 'pubDate in 2014-12-05 & (title = "Hello World!" | foo = "bar")'
Nils Diewald7c8ced22015-04-15 19:21:00 +00002461 );
2462
2463 expect(vc.root().operands().length).toEqual(2);
2464
2465 // Add unspecified on the root group
2466 _andOn(vc.root().getOperand(1));
2467 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02002468 'pubDate in 2014-12-05 & (title = "Hello World!" | foo = "bar")'
Nils Diewald7c8ced22015-04-15 19:21:00 +00002469 );
2470
2471 expect(vc.root().ldType()).toEqual('docGroup');
2472 expect(vc.root().operands().length).toEqual(3);
2473 expect(vc.root().getOperand(0).ldType()).toEqual('doc');
2474 expect(vc.root().getOperand(1).ldType()).toEqual('docGroup');
2475 expect(vc.root().getOperand(1).operation()).toEqual('or');
2476 expect(vc.root().getOperand(2).ldType()).toEqual('non');
2477
2478 // Add another unspecified on the root group
2479 _andOn(vc.root().getOperand(1));
2480
2481 expect(vc.root().operands().length).toEqual(4);
2482 expect(vc.root().getOperand(0).ldType()).toEqual('doc');
2483 expect(vc.root().getOperand(1).ldType()).toEqual('docGroup');
2484 expect(vc.root().getOperand(2).ldType()).toEqual('non');
2485 expect(vc.root().getOperand(3).ldType()).toEqual('non');
2486
2487 // Add another unspecified after the first doc
2488 _andOn(vc.root().getOperand(0));
2489
2490 expect(vc.root().operands().length).toEqual(5);
2491 expect(vc.root().getOperand(0).ldType()).toEqual('doc');
2492 expect(vc.root().getOperand(1).ldType()).toEqual('non');
2493 expect(vc.root().getOperand(2).ldType()).toEqual('docGroup');
2494 expect(vc.root().getOperand(3).ldType()).toEqual('non');
2495 expect(vc.root().getOperand(4).ldType()).toEqual('non');
2496 });
2497
2498 it('should wrap on root', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00002499 var vc = vcClass.create().fromJson(
Akron712733a2018-04-05 18:17:47 +02002500 {
2501 "@type": 'koral:docGroup',
2502 'operation' : 'operation:and',
2503 'operands' : [
2504 {
2505 "@type": 'koral:doc',
2506 "key": 'pubDate',
2507 "match": 'match:eq',
2508 "value": '2014-12-05',
2509 "type": 'type:date'
2510 },
2511 {
2512 "@type" : 'koral:doc',
2513 'key' : 'foo',
2514 'value' : 'bar'
2515 }
2516 ]
2517 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00002518 );
2519
2520 // Wrap on root
2521 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar"');
2522 expect(vc.root().ldType()).toEqual('docGroup');
2523 expect(vc.root().operation()).toEqual('and');
2524 _orOn(vc.root());
2525 expect(vc.root().ldType()).toEqual('docGroup');
2526 expect(vc.root().operation()).toEqual('or');
2527
2528 expect(vc.root().getOperand(0).ldType()).toEqual('docGroup');
2529 expect(vc.root().getOperand(0).operation()).toEqual('and');
2530 });
2531
2532 it('should add on root (case "and")', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00002533 var vc = vcClass.create().fromJson(
Akron712733a2018-04-05 18:17:47 +02002534 {
2535 "@type": 'koral:doc',
2536 "key": 'pubDate',
2537 "match": 'match:eq',
2538 "value": '2014-12-05',
2539 "type": 'type:date'
2540 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00002541 );
2542
2543 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05');
2544 expect(vc.root().ldType()).toEqual('doc');
2545 expect(vc.root().key()).toEqual('pubDate');
2546 expect(vc.root().value()).toEqual('2014-12-05');
2547
2548 // Wrap on root
2549 _andOn(vc.root());
2550 expect(vc.root().ldType()).toEqual('docGroup');
2551 expect(vc.root().operation()).toEqual('and');
2552 });
2553
2554 it('should add on root (case "or")', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00002555 var vc = vcClass.create().fromJson(
Akron712733a2018-04-05 18:17:47 +02002556 {
2557 "@type": 'koral:doc',
2558 "key": 'pubDate',
2559 "match": 'match:eq',
2560 "value": '2014-12-05',
2561 "type": 'type:date'
2562 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00002563 );
2564
2565 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05');
2566 expect(vc.root().key()).toEqual('pubDate');
2567 expect(vc.root().value()).toEqual('2014-12-05');
2568
2569 // Wrap on root
2570 _orOn(vc.root());
2571 expect(vc.root().ldType()).toEqual('docGroup');
2572 expect(vc.root().operation()).toEqual('or');
2573 });
2574
2575 it('should support multiple sub groups per group', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00002576 var vc = vcClass.create().fromJson(
Akron712733a2018-04-05 18:17:47 +02002577 {
2578 "@type": 'koral:docGroup',
2579 'operation' : 'operation:or',
2580 'operands' : [
2581 {
2582 "@type": 'koral:docGroup',
2583 'operation' : 'operation:and',
2584 'operands' : [
2585 {
2586 "@type": 'koral:doc',
2587 "key": 'title',
2588 "value": 't1',
2589 },
2590 {
2591 "@type" : 'koral:doc',
2592 'key' : 'title',
2593 'value' : 't2'
2594 }
2595 ]
2596 },
2597 {
2598 "@type": 'koral:docGroup',
2599 'operation' : 'operation:and',
2600 'operands' : [
2601 {
2602 "@type": 'koral:doc',
2603 "key": 'title',
2604 "value": 't3',
2605 },
2606 {
2607 "@type" : 'koral:doc',
2608 'key' : 'title',
2609 'value' : 't4'
2610 }
2611 ]
2612 }
2613 ]
2614 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00002615 );
2616 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02002617 '(title = "t1" & title = "t2") | ' +
2618 '(title = "t3" & title = "t4")'
Nils Diewald7c8ced22015-04-15 19:21:00 +00002619 );
2620 expect(vc.root().operation()).toEqual('or');
2621 expect(vc.root().getOperand(0).toQuery()).toEqual('title = "t1" & title = "t2"');
2622 expect(vc.root().getOperand(1).toQuery()).toEqual('title = "t3" & title = "t4"');
2623
2624 _andOn(vc.root());
2625
2626 expect(vc.root().operation()).toEqual('and');
2627 expect(vc.root().getOperand(0).ldType()).toEqual('docGroup');
2628 expect(vc.root().getOperand(1).ldType()).toEqual('non');
2629 });
2630 });
2631
Nils Diewald6283d692015-04-23 20:32:53 +00002632
Akron88d237e2020-10-21 08:05:18 +02002633 describe('KorAP.VC.Rewrite', function () {
Nils Diewald7c8ced22015-04-15 19:21:00 +00002634 it('should be initializable', function () {
2635 var rewrite = rewriteClass.create({
Akron712733a2018-04-05 18:17:47 +02002636 "@type" : "koral:rewrite",
2637 "operation" : "operation:modification",
2638 "src" : "querySerializer",
2639 "scope" : "tree"
Nils Diewald86dad5b2015-01-28 15:09:07 +00002640 });
Nils Diewald7c8ced22015-04-15 19:21:00 +00002641 expect(rewrite.toString()).toEqual('Modification of "tree" by "querySerializer"');
2642 });
Nils Diewald86dad5b2015-01-28 15:09:07 +00002643
Nils Diewald7c8ced22015-04-15 19:21:00 +00002644 it('should be deserialized by docs', function () {
2645 var doc = docClass.create(
Akron712733a2018-04-05 18:17:47 +02002646 undefined,
2647 {
2648 "@type":"koral:doc",
2649 "key":"Titel",
2650 "value":"Baum",
2651 "match":"match:eq"
2652 });
Nils Diewald7c8ced22015-04-15 19:21:00 +00002653
2654 expect(doc.element().classList.contains('doc')).toBeTruthy();
2655 expect(doc.element().classList.contains('rewritten')).toBe(false);
2656
2657 doc = docClass.create(
Akron712733a2018-04-05 18:17:47 +02002658 undefined,
2659 {
2660 "@type":"koral:doc",
2661 "key":"Titel",
2662 "value":"Baum",
2663 "match":"match:eq",
2664 "rewrites" : [
2665 {
2666 "@type" : "koral:rewrite",
2667 "operation" : "operation:modification",
2668 "src" : "querySerializer",
2669 "scope" : "tree"
2670 }
2671 ]
2672 });
Nils Diewald7c8ced22015-04-15 19:21:00 +00002673
2674 expect(doc.element().classList.contains('doc')).toBeTruthy();
2675 expect(doc.element().classList.contains('rewritten')).toBeTruthy();
2676 });
Nils Diewald6283d692015-04-23 20:32:53 +00002677
Akron76c3dd62018-05-29 20:58:27 +02002678 it('should be described in a title attribute', function () {
2679
2680 doc = docClass.create(
2681 undefined,
2682 {
2683 "@type":"koral:doc",
2684 "key":"Titel",
2685 "value":"Baum",
2686 "match":"match:eq",
2687 "rewrites" : [
2688 {
2689 "@type" : "koral:rewrite",
2690 "operation" : "operation:modification",
2691 "src" : "querySerializer",
2692 "scope" : "tree"
2693 },
2694 {
2695 "@type" : "koral:rewrite",
2696 "operation" : "operation:injection",
2697 "src" : "me"
2698 }
2699 ]
2700 });
2701
2702 expect(doc.element().classList.contains('doc')).toBeTruthy();
2703 expect(doc.element().classList.contains('rewritten')).toBeTruthy();
2704 expect(doc.element().lastChild.getAttribute("title")).toEqual("querySerializer: tree (modification)\nme (injection)");
2705 });
2706
2707
Nils Diewald6283d692015-04-23 20:32:53 +00002708 xit('should be deserialized by docGroups', function () {
2709 var docGroup = docGroupClass.create(
Akron712733a2018-04-05 18:17:47 +02002710 undefined,
2711 {
2712 "@type" : "koral:docGroup",
2713 "operation" : "operation:or",
2714 "operands" : [
2715 {
2716 "@type" : "doc",
2717 "key" : "pubDate",
2718 "type" : "type:date",
2719 "value" : "2014-12-05"
2720 },
2721 {
2722 "@type" : "doc",
2723 "key" : "pubDate",
2724 "type" : "type:date",
2725 "value" : "2014-12-06"
2726 }
2727 ],
2728 "rewrites" : [
2729 {
2730 "@type" : "koral:rewrite",
2731 "operation" : "operation:modification",
2732 "src" : "querySerializer",
2733 "scope" : "tree"
2734 }
2735 ]
2736 }
Nils Diewald6283d692015-04-23 20:32:53 +00002737 );
2738
2739 expect(doc.element().classList.contains('docgroup')).toBeTruthy();
2740 expect(doc.element().classList.contains('rewritten')).toBe(false);
2741 });
Nils Diewald86dad5b2015-01-28 15:09:07 +00002742 });
Nils Diewaldf0c4f112015-05-05 12:56:59 +00002743
Akron88d237e2020-10-21 08:05:18 +02002744 describe('KorAP.VC.stringValue', function () {
Nils Diewaldf0c4f112015-05-05 12:56:59 +00002745 it('should be initializable', function () {
2746 var sv = stringValClass.create();
2747 expect(sv.regex()).toBe(false);
2748 expect(sv.value()).toBe('');
Nils Diewaldc4c4b832015-05-05 16:00:08 +00002749
2750 sv = stringValClass.create('Baum');
2751 expect(sv.regex()).toBe(false);
2752 expect(sv.value()).toBe('Baum');
2753
2754 sv = stringValClass.create('Baum', false);
2755 expect(sv.regex()).toBe(false);
2756 expect(sv.value()).toBe('Baum');
2757
2758 sv = stringValClass.create('Baum', true);
2759 expect(sv.regex()).toBe(true);
2760 expect(sv.value()).toBe('Baum');
2761 });
2762
2763 it('should be modifiable', function () {
2764 var sv = stringValClass.create();
2765 expect(sv.regex()).toBe(false);
2766 expect(sv.value()).toBe('');
2767
2768 expect(sv.value('Baum')).toBe('Baum');
2769 expect(sv.value()).toBe('Baum');
2770
2771 expect(sv.regex(true)).toBe(true);
2772 expect(sv.regex()).toBe(true);
2773 });
2774
2775 it('should have a toggleble regex value', function () {
2776 var sv = stringValClass.create();
Nils Diewald7991a3f2015-05-19 14:12:37 +00002777
2778 expect(sv.element().firstChild.value).toBe('');
2779 sv.element().firstChild.value = 'der'
2780 expect(sv.element().firstChild.value).toBe('der');
2781
Nils Diewaldc4c4b832015-05-05 16:00:08 +00002782 expect(sv.regex()).toBe(false);
2783
2784 sv.toggleRegex();
Nils Diewald7991a3f2015-05-19 14:12:37 +00002785 expect(sv.element().firstChild.value).toBe('der');
Nils Diewaldc4c4b832015-05-05 16:00:08 +00002786 expect(sv.regex()).toBe(true);
Nils Diewald7991a3f2015-05-19 14:12:37 +00002787 sv.element().firstChild.value = 'derbe'
Nils Diewaldc4c4b832015-05-05 16:00:08 +00002788
2789 sv.toggleRegex();
2790 expect(sv.regex()).toBe(false);
Nils Diewald7991a3f2015-05-19 14:12:37 +00002791 expect(sv.element().firstChild.value).toBe('derbe');
Nils Diewaldc4c4b832015-05-05 16:00:08 +00002792 });
2793
2794 it('should have an element', function () {
2795 var sv = stringValClass.create('der');
2796 expect(sv.element().nodeName).toBe('DIV');
2797 expect(sv.element().firstChild.nodeName).toBe('INPUT');
2798 expect(sv.element().firstChild.value).toBe('der');
2799 });
2800
2801 it('should have a classed element', function () {
2802 var sv = stringValClass.create();
Nils Diewaldc4c4b832015-05-05 16:00:08 +00002803 expect(sv.element().classList.contains('regex')).toBe(false);
2804 expect(sv.regex()).toBe(false);
2805 sv.toggleRegex();
2806 expect(sv.element().classList.contains('regex')).toBe(true);
2807 });
2808
2809 it('should be storable', function () {
2810 var sv = stringValClass.create();
2811 var count = 1;
2812 sv.store = function (value, regex) {
Akron712733a2018-04-05 18:17:47 +02002813 expect(regex).toBe(true);
2814 expect(value).toBe('tree');
Nils Diewaldc4c4b832015-05-05 16:00:08 +00002815 };
2816 sv.regex(true);
2817 sv.value('tree');
2818 sv.element().lastChild.click();
Nils Diewaldf0c4f112015-05-05 12:56:59 +00002819 });
Akron712733a2018-04-05 18:17:47 +02002820
Akronb19803c2018-08-16 16:39:42 +02002821 it('should have a disableoption for regex', function () {
2822 var sv = stringValClass.create(undefined, undefined, true);
2823 var svE = sv.element();
2824 expect(svE.children.length).toEqual(2);
2825
2826 sv = stringValClass.create(undefined, undefined, false);
2827 svE = sv.element();
2828 expect(svE.children.length).toEqual(1);
2829 });
2830
Nils Diewaldf0c4f112015-05-05 12:56:59 +00002831 });
Akrone4961b12017-05-10 21:04:46 +02002832
Akron712733a2018-04-05 18:17:47 +02002833 describe('KorAP.VC.Menu', function () {
Akrone65a88a2018-04-05 19:14:20 +02002834
2835 var vc;
2836
Akron712733a2018-04-05 18:17:47 +02002837 it('should be initializable', function () {
2838
Akrone65a88a2018-04-05 19:14:20 +02002839 vc = vcClass.create([
Akron712733a2018-04-05 18:17:47 +02002840 ['a', 'text'],
2841 ['b', 'string'],
2842 ['c', 'date']
2843 ]).fromJson();
Akronadab5e52018-08-20 13:50:53 +02002844 expect(vc.builder().firstChild.classList.contains('unspecified')).toBeTruthy();
2845 expect(vc.builder().firstChild.firstChild.tagName).toEqual('SPAN');
Akron712733a2018-04-05 18:17:47 +02002846
2847 // Click on unspecified
Akronadab5e52018-08-20 13:50:53 +02002848 vc.builder().firstChild.firstChild.click();
2849 expect(vc.builder().firstChild.firstChild.tagName).toEqual('UL');
Akron712733a2018-04-05 18:17:47 +02002850
Akronadab5e52018-08-20 13:50:53 +02002851 var list = vc.builder().firstChild.firstChild;
Akron3ad46942018-08-22 16:47:14 +02002852 expect(list.getElementsByTagName("LI")[0].innerText).toEqual('referTo');
2853 expect(list.getElementsByTagName("LI")[1].innerText).toEqual('a');
2854 expect(list.getElementsByTagName("LI")[2].innerText).toEqual('b');
2855 expect(list.getElementsByTagName("LI")[3].innerText).toEqual('c');
Akron712733a2018-04-05 18:17:47 +02002856
2857 vc = vcClass.create([
2858 ['d', 'text'],
2859 ['e', 'string'],
2860 ['f', 'date']
2861 ]).fromJson();
Akronadab5e52018-08-20 13:50:53 +02002862 expect(vc.builder().firstChild.classList.contains('unspecified')).toBeTruthy();
2863 expect(vc.builder().firstChild.firstChild.tagName).toEqual('SPAN');
Akron712733a2018-04-05 18:17:47 +02002864
2865 // Click on unspecified
Akronadab5e52018-08-20 13:50:53 +02002866 vc.builder().firstChild.firstChild.click();
2867 expect(vc.builder().firstChild.firstChild.tagName).toEqual('UL');
Akron712733a2018-04-05 18:17:47 +02002868
Akronadab5e52018-08-20 13:50:53 +02002869 list = vc.builder().firstChild.firstChild;
Akron3ad46942018-08-22 16:47:14 +02002870 expect(list.getElementsByTagName("LI")[0].innerText).toEqual('referTo');
2871 expect(list.getElementsByTagName("LI")[1].innerText).toEqual('d');
2872 expect(list.getElementsByTagName("LI")[2].innerText).toEqual('e');
2873 expect(list.getElementsByTagName("LI")[3].innerText).toEqual('f');
Akron31d89942018-04-06 16:44:51 +02002874 // blur
2875 document.body.click();
Akron712733a2018-04-05 18:17:47 +02002876 });
Akrone65a88a2018-04-05 19:14:20 +02002877
2878 // Reinitialize to make tests stable
2879 vc = vcClass.create([
2880 ['d', 'text'],
2881 ['e', 'string'],
2882 ['f', 'date']
2883 ]).fromJson();
2884
2885 it('should be clickable on key', function () {
Akron31d89942018-04-06 16:44:51 +02002886 // Click on unspecified
Akronadab5e52018-08-20 13:50:53 +02002887 vc.builder().firstChild.firstChild.click();
Akrone65a88a2018-04-05 19:14:20 +02002888 // Click on "d"
Akronadab5e52018-08-20 13:50:53 +02002889 vc.builder().firstChild.firstChild.getElementsByTagName("LI")[1].click();
2890 expect(vc.builder().firstChild.firstChild.tagName).toEqual('SPAN');
2891 expect(vc.builder().firstChild.firstChild.innerText).toEqual('d');
2892 expect(vc.builder().firstChild.children[1].innerText).toEqual('eq');
2893 expect(vc.builder().firstChild.children[1].getAttribute('data-type')).toEqual('text');
Akron31d89942018-04-06 16:44:51 +02002894 // blur
2895 document.body.click();
Akrone65a88a2018-04-05 19:14:20 +02002896 });
2897
Akron31d89942018-04-06 16:44:51 +02002898 it('should be clickable on operation for text', function () {
2899 // Click on "d" (or unspecified)
Akronadab5e52018-08-20 13:50:53 +02002900 vc.builder().firstChild.firstChild.click();
Akron31d89942018-04-06 16:44:51 +02002901
2902 // Choose "d"
Akronadab5e52018-08-20 13:50:53 +02002903 vc.builder().firstChild.firstChild.getElementsByTagName("LI")[1].click();
Akron31d89942018-04-06 16:44:51 +02002904
2905 // Click on matchop
Akronadab5e52018-08-20 13:50:53 +02002906 vc.builder().firstChild.children[1].click();
Akron31d89942018-04-06 16:44:51 +02002907
Akronadab5e52018-08-20 13:50:53 +02002908 expect(vc.builder().firstChild.children[1].tagName).toEqual('UL');
Akron31d89942018-04-06 16:44:51 +02002909
Akronadab5e52018-08-20 13:50:53 +02002910 var ul = vc.builder().firstChild.children[1];
Akrone65a88a2018-04-05 19:14:20 +02002911 expect(ul.getElementsByTagName('li')[0].innerText).toEqual("eq");
2912 expect(ul.getElementsByTagName('li')[1].innerText).toEqual("ne");
2913 expect(ul.getElementsByTagName('li')[2].innerText).toEqual("contains");
2914 expect(ul.getElementsByTagName('li')[3].innerText).toEqual("containsnot");
2915 expect(ul.getElementsByTagName('li')[4]).toBeUndefined();
Akron31d89942018-04-06 16:44:51 +02002916
2917 // Choose "contains"
2918 ul.getElementsByTagName('li')[2].click();
Akronadab5e52018-08-20 13:50:53 +02002919 expect(vc.builder().firstChild.children[1].tagName).toEqual("SPAN");
2920 expect(vc.builder().firstChild.children[1].innerText).toEqual("contains");
Akron31d89942018-04-06 16:44:51 +02002921 // blur
2922 document.body.click();
Akrone65a88a2018-04-05 19:14:20 +02002923 })
Akron31d89942018-04-06 16:44:51 +02002924
2925 it('should be clickable on operation for string', function () {
2926 // Click on "d" (or unspecified)
Akronadab5e52018-08-20 13:50:53 +02002927 vc.builder().firstChild.firstChild.click();
Akron31d89942018-04-06 16:44:51 +02002928
2929 // Choose "e"
Akronadab5e52018-08-20 13:50:53 +02002930 vc.builder().firstChild.firstChild.getElementsByTagName("LI")[2].click();
2931
Akron31d89942018-04-06 16:44:51 +02002932 // As a consequence the matchoperator may no longer
2933 // be valid and needs to be re-evaluated
Akronadab5e52018-08-20 13:50:53 +02002934 var fc = vc.builder().firstChild;
Akron31d89942018-04-06 16:44:51 +02002935 expect(fc.firstChild.tagName).toEqual('SPAN');
2936 expect(fc.firstChild.innerText).toEqual('e');
2937 expect(fc.children[1].innerText).toEqual('eq');
2938 expect(fc.children[1].getAttribute('data-type')).toEqual('string');
2939
Akronadab5e52018-08-20 13:50:53 +02002940 vc.builder().firstChild.children[1].click();
Akron31d89942018-04-06 16:44:51 +02002941
Akronadab5e52018-08-20 13:50:53 +02002942 expect(vc.builder().firstChild.children[1].tagName).toEqual('UL');
Akron31d89942018-04-06 16:44:51 +02002943
Akronadab5e52018-08-20 13:50:53 +02002944 var ul = vc.builder().firstChild.children[1];
Akron31d89942018-04-06 16:44:51 +02002945 expect(ul.getElementsByTagName('li')[0].innerText).toEqual("eq");
2946 expect(ul.getElementsByTagName('li')[1].innerText).toEqual("ne");
2947 expect(ul.getElementsByTagName('li')[2]).toBeUndefined();
2948
2949 // Choose "ne"
2950 ul.getElementsByTagName('li')[1].click();
Akronadab5e52018-08-20 13:50:53 +02002951 expect(vc.builder().firstChild.children[1].tagName).toEqual("SPAN");
2952 expect(vc.builder().firstChild.children[1].innerText).toEqual("ne");
Akron8db5e3a2018-05-28 19:25:26 +02002953
2954 // Click on text
Akronebc96662018-08-29 17:36:20 +02002955 expect(vc.builder().firstChild.children[2].innerText).toEqual(KorAP.Locale.EMPTY);
2956 expect(vc.builder().firstChild.children[2].classList.contains('unspecified')).toEqual(true);
Akronadab5e52018-08-20 13:50:53 +02002957 vc.builder().firstChild.children[2].click();
Akron8db5e3a2018-05-28 19:25:26 +02002958
2959 // Blur text element
Akronadab5e52018-08-20 13:50:53 +02002960 expect(vc.builder().firstChild.children[2].firstChild.value).toEqual('');
Akron8db5e3a2018-05-28 19:25:26 +02002961
Akron31d89942018-04-06 16:44:51 +02002962 // blur
2963 document.body.click();
2964 });
2965
2966 it('should be clickable on operation for date', function () {
2967
2968 // Replay matchop check - so it's guaranteed that "ne" is chosen
2969 // Click on "e" (or unspecified)
Akronadab5e52018-08-20 13:50:53 +02002970 vc.builder().firstChild.firstChild.click();
Akron31d89942018-04-06 16:44:51 +02002971 // Rechoose "e"
Akronadab5e52018-08-20 13:50:53 +02002972 vc.builder().firstChild.firstChild.getElementsByTagName("LI")[1].click();
Akron31d89942018-04-06 16:44:51 +02002973 // Click on matchop
Akronadab5e52018-08-20 13:50:53 +02002974 vc.builder().firstChild.children[1].click();
Akron31d89942018-04-06 16:44:51 +02002975 // Choose "ne"
Akronadab5e52018-08-20 13:50:53 +02002976 vc.builder().firstChild.children[1].getElementsByTagName('li')[1].click();
2977 expect(vc.builder().firstChild.children[1].innerText).toEqual("ne");
Akron31d89942018-04-06 16:44:51 +02002978
2979 // Click on "e"
Akronadab5e52018-08-20 13:50:53 +02002980 vc.builder().firstChild.firstChild.click();
Akron31d89942018-04-06 16:44:51 +02002981 // Choose "f"
Akronadab5e52018-08-20 13:50:53 +02002982 vc.builder().firstChild.firstChild.getElementsByTagName("LI")[3].click();
Akron31d89942018-04-06 16:44:51 +02002983
2984 // The matchoperator should still be "ne" as this is valid for dates as well (now)
Akronadab5e52018-08-20 13:50:53 +02002985 var fc = vc.builder().firstChild;
Akron31d89942018-04-06 16:44:51 +02002986 expect(fc.firstChild.tagName).toEqual('SPAN');
2987 expect(fc.firstChild.innerText).toEqual('f');
2988 expect(fc.children[1].innerText).toEqual('ne');
2989 // blur
2990 document.body.click();
2991 });
Akronddc98a72018-04-06 17:33:52 +02002992
2993
2994 // Check json deserialization
2995 it('should be initializable', function () {
2996 vc = vcClass.create([
2997 ['a', 'text'],
2998 ['b', 'string'],
2999 ['c', 'date']
3000 ]).fromJson({
3001 "@type" : "koral:doc",
3002 "key":"a",
3003 "value":"Baum"
3004 });
3005
Akronadab5e52018-08-20 13:50:53 +02003006 expect(vc.builder().firstChild.children[1].getAttribute('data-type')).toEqual('text');
Akronddc98a72018-04-06 17:33:52 +02003007 });
Akron712733a2018-04-05 18:17:47 +02003008 });
3009
3010
Akrone4961b12017-05-10 21:04:46 +02003011 // Check prefix
3012 describe('KorAP.VC.Prefix', function () {
3013
3014 it('should be initializable', function () {
3015 var p = prefixClass.create();
3016 expect(p.element().classList.contains('pref')).toBeTruthy();
3017 expect(p.isSet()).not.toBeTruthy();
3018 });
3019
3020
3021 it('should be clickable', function () {
hebastaa0282be2018-12-05 16:58:00 +01003022 KorAP.vc = vcClass.create([
Akron712733a2018-04-05 18:17:47 +02003023 ['a', null],
3024 ['b', null],
3025 ['c', null]
3026 ]).fromJson();
hebastaa0282be2018-12-05 16:58:00 +01003027
3028 //vc = KorAP.vc;
3029
3030 expect(KorAP.vc.builder().firstChild.classList.contains('unspecified')).toBeTruthy();
Akrone4961b12017-05-10 21:04:46 +02003031
3032 // This should open up the menu
hebastaa0282be2018-12-05 16:58:00 +01003033 KorAP.vc.builder().firstChild.firstChild.click();
3034 expect(KorAP.vc.builder().firstChild.firstChild.tagName).toEqual('UL');
Akrone4961b12017-05-10 21:04:46 +02003035
3036 KorAP._vcKeyMenu._prefix.clear();
3037 KorAP._vcKeyMenu._prefix.add('x');
3038
hebastaa0282be2018-12-05 16:58:00 +01003039 var prefElement = KorAP.vc.builder().querySelector('span.pref');
Akrone4961b12017-05-10 21:04:46 +02003040 expect(prefElement.innerText).toEqual('x');
3041
3042 // This should add key 'x' to VC
3043 prefElement.click();
3044
hebastaa0282be2018-12-05 16:58:00 +01003045 expect(KorAP.vc.builder().firstChild.classList.contains('doc')).toBeTruthy();
3046 expect(KorAP.vc.builder().firstChild.firstChild.className).toEqual('key');
3047 expect(KorAP.vc.builder().firstChild.firstChild.innerText).toEqual('x');
Akrone4961b12017-05-10 21:04:46 +02003048 });
3049 });
Akron68d28322018-08-27 15:02:42 +02003050
Akron889ec292018-11-19 17:56:01 +01003051 // Check fragment handling for corpusByMatch helper
Akron68d28322018-08-27 15:02:42 +02003052 describe('KorAP.VC.Fragment', function () {
3053 it('should be initializable', function () {
3054 var f = fragmentClass.create();
3055 var e = f.element();
3056 expect(e.classList.contains('vc')).toBeTruthy();
3057 expect(e.classList.contains('fragment')).toBeTruthy();
Akrond45a1702018-11-19 18:15:17 +01003058 expect(e.firstChild.children.length).toEqual(0);
Akron68d28322018-08-27 15:02:42 +02003059 });
3060
3061 it('should be expansable', function () {
3062 var f = fragmentClass.create();
3063 f.add("author", "Peter");
3064
Akrond45a1702018-11-19 18:15:17 +01003065 var root = f.element().lastChild.firstChild;
Akron68d28322018-08-27 15:02:42 +02003066
3067 expect(root.classList.contains("doc")).toBeTruthy();
3068 expect(root.children[0].tagName).toEqual("SPAN");
3069 expect(root.children[0].textContent).toEqual("author");
3070 expect(root.children[1].tagName).toEqual("SPAN");
3071 expect(root.children[1].textContent).toEqual("eq");
3072 expect(root.children[2].tagName).toEqual("SPAN");
3073 expect(root.children[2].textContent).toEqual("Peter");
3074
3075 f.add("title", "Example");
3076
Akrond45a1702018-11-19 18:15:17 +01003077 root = f.element().lastChild.firstChild;
Akron68d28322018-08-27 15:02:42 +02003078
3079 expect(root.classList.contains("docGroup")).toBeTruthy();
3080
3081 var doc = root.children[0];
3082
3083 expect(doc.children[0].tagName).toEqual("SPAN");
3084 expect(doc.children[0].textContent).toEqual("author");
3085 expect(doc.children[1].tagName).toEqual("SPAN");
3086 expect(doc.children[1].textContent).toEqual("eq");
3087 expect(doc.children[2].tagName).toEqual("SPAN");
3088 expect(doc.children[2].textContent).toEqual("Peter");
3089
3090 doc = root.children[1];
3091
3092 expect(doc.children[0].tagName).toEqual("SPAN");
3093 expect(doc.children[0].textContent).toEqual("title");
3094 expect(doc.children[1].tagName).toEqual("SPAN");
3095 expect(doc.children[1].textContent).toEqual("eq");
3096 expect(doc.children[2].tagName).toEqual("SPAN");
3097 expect(doc.children[2].textContent).toEqual("Example");
3098 });
3099
3100
3101 it('should be reducible', function () {
3102 var f = fragmentClass.create();
Akrond45a1702018-11-19 18:15:17 +01003103 expect(f.element().lastChild.children.length).toEqual(0);
Akron889ec292018-11-19 17:56:01 +01003104
Akron68d28322018-08-27 15:02:42 +02003105 f.add("author", "Peter");
3106 f.add("title", "Example");
3107
Akrond45a1702018-11-19 18:15:17 +01003108 expect(f.element().lastChild.children.length).toEqual(1);
Akron889ec292018-11-19 17:56:01 +01003109
Akrond45a1702018-11-19 18:15:17 +01003110 var root = f.element().lastChild.firstChild;
Akron889ec292018-11-19 17:56:01 +01003111
Akron68d28322018-08-27 15:02:42 +02003112 expect(root.classList.contains("docGroup")).toBeTruthy();
3113
3114 expect(root.children.length).toEqual(2);
3115
3116 f.remove("author","Peter");
3117
Akrond45a1702018-11-19 18:15:17 +01003118 root = f.element().lastChild.firstChild;
Akron68d28322018-08-27 15:02:42 +02003119 expect(root.classList.contains("doc")).toBeTruthy();
3120
3121 expect(root.children[0].tagName).toEqual("SPAN");
3122 expect(root.children[0].textContent).toEqual("title");
3123 expect(root.children[1].tagName).toEqual("SPAN");
3124 expect(root.children[1].textContent).toEqual("eq");
3125 expect(root.children[2].tagName).toEqual("SPAN");
3126 expect(root.children[2].textContent).toEqual("Example");
Akron889ec292018-11-19 17:56:01 +01003127
3128 f.remove("title","Example");
3129
Akrond45a1702018-11-19 18:15:17 +01003130 expect(f.element().lastChild.children.length).toEqual(0);
Akron68d28322018-08-27 15:02:42 +02003131 });
Akron2761d882020-10-13 10:35:09 +02003132
3133 it('should respect already set attributes', function () {
3134 var f = fragmentClass.create();
3135 expect(f.element().lastChild.children.length).toEqual(0);
3136
3137 expect(f.isEmpty()).toBeTruthy();
3138
3139 f.add("author", "Peter");
3140 f.add("title", "Example");
3141
3142 expect(f.isEmpty()).toBeFalsy();
3143
3144 expect(f.toQuery()).toEqual('author = "Peter" & title = "Example"');
3145
3146 f.add("author", "Peter");
3147
3148 expect(f.toQuery()).toEqual('title = "Example" & author = "Peter"');
3149 });
Akron68d28322018-08-27 15:02:42 +02003150 });
Nils Diewald2fe12e12015-03-06 16:47:06 +00003151});