blob: 78a186e57bb9e2a0a6efe823eebf03a1ae6c535f [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',
Akron5d4f2e42024-12-16 09:10:27 +010015 'vc/intval',
Akron68d28322018-08-27 15:02:42 +020016 'vc/fragment'
Akrondd5c6d32018-08-17 14:12:58 +020017], function (vcClass,
18 docClass,
19 menuClass,
20 prefixClass,
21 docGroupClass,
22 docGroupRefClass,
23 unspecifiedClass,
24 operatorsClass,
25 rewriteClass,
Akron68d28322018-08-27 15:02:42 +020026 stringValClass,
Akron5d4f2e42024-12-16 09:10:27 +010027 intValClass,
Akron68d28322018-08-27 15:02:42 +020028 fragmentClass) {
Nils Diewald6ac292b2015-01-15 21:33:21 +000029
Akrondd5c6d32018-08-17 14:12:58 +020030 KorAP._vcKeyMenu = undefined;
31
hebastaa0282be2018-12-05 16:58:00 +010032
Nils Diewald7c8ced22015-04-15 19:21:00 +000033 // Helper method for building factories
34 buildFactory = function (objClass, defaults) {
35 return {
36 create : function (overwrites) {
Akron712733a2018-04-05 18:17:47 +020037 var newObj = {};
38 for (var prop in defaults) {
39 newObj[prop] = defaults[prop];
40 };
41 for (var prop in overwrites) {
42 newObj[prop] = overwrites[prop];
43 };
44 return objClass.create().fromJson(newObj);
Nils Diewald7c8ced22015-04-15 19:21:00 +000045 }
Nils Diewald0b6c0412014-12-19 03:55:57 +000046 }
Nils Diewald7c8ced22015-04-15 19:21:00 +000047 };
Nils Diewald0b6c0412014-12-19 03:55:57 +000048
Nils Diewald7c8ced22015-04-15 19:21:00 +000049 function _andOn (obj) {
Akrond141a362018-07-10 18:12:13 +020050 KorAP._and.apply(obj);
Nils Diewald7c8ced22015-04-15 19:21:00 +000051 };
Nils Diewald52f7eb12015-01-12 17:30:04 +000052
Nils Diewald7c8ced22015-04-15 19:21:00 +000053 function _orOn (obj) {
Akrond141a362018-07-10 18:12:13 +020054 KorAP._or.apply(obj);
Nils Diewald7c8ced22015-04-15 19:21:00 +000055 };
Nils Diewald52f7eb12015-01-12 17:30:04 +000056
Nils Diewald7c8ced22015-04-15 19:21:00 +000057 function _delOn (obj) {
Akrond141a362018-07-10 18:12:13 +020058 KorAP._delete.apply(obj);
Nils Diewald7c8ced22015-04-15 19:21:00 +000059 };
Nils Diewald52f7eb12015-01-12 17:30:04 +000060
Nils Diewald7c8ced22015-04-15 19:21:00 +000061 var demoFactory = buildFactory(vcClass, {
62 "@type":"koral:docGroup",
63 "operation":"operation:or",
64 "operands":[
Nils Diewaldf219eb82015-01-07 20:15:42 +000065 {
Akron712733a2018-04-05 18:17:47 +020066 "@type":"koral:docGroup",
67 "operation":"operation:and",
68 "operands":[
Nils Diewald7c8ced22015-04-15 19:21:00 +000069 {
70 "@type":"koral:doc",
71 "key":"Titel",
72 "value":"Baum",
73 "match":"match:eq"
74 },
75 {
76 "@type":"koral:doc",
77 "key":"Veröffentlichungsort",
78 "value":"hihi",
79 "match":"match:eq"
80 },
81 {
82 "@type":"koral:docGroup",
83 "operation":"operation:or",
84 "operands":[
85 {
Akron712733a2018-04-05 18:17:47 +020086 "@type":"koral:doc",
87 "key":"Titel",
88 "value":"Baum",
89 "match":"match:eq"
Nils Diewald7c8ced22015-04-15 19:21:00 +000090 },
91 {
Akron712733a2018-04-05 18:17:47 +020092 "@type":"koral:doc",
93 "key":"Veröffentlichungsort",
94 "value":"hihi",
95 "match":"match:eq"
Nils Diewald7c8ced22015-04-15 19:21:00 +000096 }
97 ]
98 }
Akron712733a2018-04-05 18:17:47 +020099 ]
Nils Diewaldf219eb82015-01-07 20:15:42 +0000100 },
101 {
Akron712733a2018-04-05 18:17:47 +0200102 "@type":"koral:doc",
103 "key":"Untertitel",
104 "value":"huhu",
105 "match":"match:contains"
Nils Diewaldf219eb82015-01-07 20:15:42 +0000106 }
107 ]
108 });
109
Akron88d237e2020-10-21 08:05:18 +0200110 describe('KorAP.VC.Doc', function () {
Nils Diewald7c8ced22015-04-15 19:21:00 +0000111 // Create example factories
112 var stringFactory = buildFactory(docClass, {
113 "key" : "author",
114 "value" : "Max Birkendale",
Akron31d89942018-04-06 16:44:51 +0200115 "type" : "type:string",
Nils Diewald7c8ced22015-04-15 19:21:00 +0000116 "@type" : "koral:doc"
117 });
118
119 // Create example factories
Akron712733a2018-04-05 18:17:47 +0200120 var textFactory = buildFactory(docClass, {
121 "key" : "author",
122 "value" : "Birkendale",
Akron31d89942018-04-06 16:44:51 +0200123 "type" : "type:string",
Akron712733a2018-04-05 18:17:47 +0200124 "match" : "match:contains",
125 "@type" : "koral:doc"
126 });
127
128 // Create example factories
Nils Diewald7c8ced22015-04-15 19:21:00 +0000129 var dateFactory = buildFactory(docClass, {
130 "key" : "pubDate",
131 "type" : "type:date",
132 "match" : "match:eq",
133 "value" : "2014-11-05",
134 "@type" : "koral:doc"
135 });
136
Akron5d4f2e42024-12-16 09:10:27 +0100137 var integerFactory = buildFactory(docClass, {
138 "key" : "KED.nToks",
139 "type" : "type:integer",
140 "match" : "match:eq",
141 "value" : "200",
142 "@type" : "koral:doc"
143 });
144
Nils Diewald7c8ced22015-04-15 19:21:00 +0000145 // Create example factories
146 var regexFactory = buildFactory(docClass, {
147 "key" : "title",
148 "type" : "type:regex",
149 "value" : "[^b]ee.+?",
150 "@type" : "koral:doc"
151 });
152
153 it('should be initializable', function () {
154 var doc = docClass.create();
155 expect(doc.matchop()).toEqual('eq');
156 expect(doc.key()).toBeUndefined();
157 expect(doc.value()).toBeUndefined();
158 expect(doc.type()).toEqual("string");
hebastaa0282be2018-12-05 16:58:00 +0100159 expect(doc.incomplete()).toBeTruthy();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000160 });
161
162 it('should be definable', function () {
163
164 // Empty doc
165 var doc = docClass.create();
166
167 // Set values
168 doc.key("title");
Akron8db5e3a2018-05-28 19:25:26 +0200169
Nils Diewald7c8ced22015-04-15 19:21:00 +0000170 doc.value("Der alte Mann");
171 expect(doc.matchop()).toEqual('eq');
172 expect(doc.key()).toEqual("title");
173 expect(doc.type()).toEqual("string");
174 expect(doc.value()).toEqual("Der alte Mann");
hebastaa0282be2018-12-05 16:58:00 +0100175 expect(doc.incomplete()).toBeFalsy();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000176 });
177
178
179 it('should deserialize JSON-LD string', function () {
180 var doc;
181
182 // String default
183 doc = stringFactory.create();
184 expect(doc.matchop()).toEqual('eq');
185 expect(doc.key()).toEqual("author");
186 expect(doc.type()).toEqual("string");
187 expect(doc.value()).toEqual("Max Birkendale");
hebastaa0282be2018-12-05 16:58:00 +0100188 expect(doc.incomplete()).toBeFalsy();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000189
190 // No valid string
191 doc = stringFactory.create({
Akron712733a2018-04-05 18:17:47 +0200192 value : undefined
Nils Diewald7c8ced22015-04-15 19:21:00 +0000193 });
194 expect(doc).toBeUndefined();
195
196 // No valid string
197 doc = stringFactory.create({
Akron712733a2018-04-05 18:17:47 +0200198 value : { "foo" : "bar" }
Nils Diewald7c8ced22015-04-15 19:21:00 +0000199 });
200 expect(doc).toBeUndefined();
201
202 // Change match type
203 doc = stringFactory.create({
Akron712733a2018-04-05 18:17:47 +0200204 "match" : "match:ne"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000205 });
206
207 expect(doc.matchop()).toEqual('ne');
208 expect(doc.key()).toEqual("author");
209 expect(doc.type()).toEqual("string");
210 expect(doc.value()).toEqual("Max Birkendale");
hebastaa0282be2018-12-05 16:58:00 +0100211 expect(doc.incomplete()).toBeFalsy();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000212
213 // Invalid match type
214 doc = stringFactory.create({
Akron712733a2018-04-05 18:17:47 +0200215 "match" : { "foo" : "bar" }
Nils Diewald7c8ced22015-04-15 19:21:00 +0000216 });
217 expect(doc).toBeUndefined();
218 });
219
220 it('should deserialize JSON-LD regex', function () {
221 var doc = regexFactory.create();
222 expect(doc.key()).toEqual("title");
223 expect(doc.type()).toEqual("regex");
224 expect(doc.value()).toEqual("[^b]ee.+?");
225 expect(doc.matchop()).toEqual('eq');
226
227 // change matcher
228 doc = regexFactory.create({
Akron712733a2018-04-05 18:17:47 +0200229 match : "match:ne"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000230 });
231 expect(doc.matchop()).toEqual('ne');
Akronea4e9052017-07-06 16:12:05 +0200232 expect(doc.rewrites()).toBeUndefined();
hebastaa0282be2018-12-05 16:58:00 +0100233 expect(doc.incomplete()).toBeFalsy();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000234
235 // Invalid matcher
236 doc = regexFactory.create({
Akron712733a2018-04-05 18:17:47 +0200237 match : "match:chook"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000238 });
Akronea4e9052017-07-06 16:12:05 +0200239 expect(doc.matchop()).toEqual('eq');
240 expect(doc.rewrites()).toBeDefined();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000241
242 // Invalid regex
243 doc = regexFactory.create({
Akron712733a2018-04-05 18:17:47 +0200244 value : "[^b"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000245 });
246 expect(doc).toBeUndefined();
247 });
248
249 it('should deserialize JSON-LD date', function () {
250
251 // Normal date
252 doc = dateFactory.create({});
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-05");
258
259 // Short date 1
260 doc = dateFactory.create({
Akron712733a2018-04-05 18:17:47 +0200261 "value" : "2014-11"
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-11");
268
269 // Short date 2
270 doc = dateFactory.create({
Akron712733a2018-04-05 18:17:47 +0200271 "value" : "2014"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000272 });
273
274 expect(doc.matchop()).toEqual('eq');
275 expect(doc.key()).toEqual("pubDate");
276 expect(doc.type()).toEqual("date");
277 expect(doc.value()).toEqual("2014");
278
279 // Invalid date!
280 doc = dateFactory.create({
Akron712733a2018-04-05 18:17:47 +0200281 "value" : "2014-11-050"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000282 });
283 expect(doc).toBeUndefined();
284
285 // Invalid matcher!
286 doc = dateFactory.create({
Akron31d89942018-04-06 16:44:51 +0200287 "match" : "match:contains",
Nils Diewald7c8ced22015-04-15 19:21:00 +0000288 });
Akronea4e9052017-07-06 16:12:05 +0200289 expect(doc).toBeDefined();
290 expect(doc.rewrites()).toBeDefined();
291 expect(doc.matchop()).toEqual('eq');
Nils Diewald7c8ced22015-04-15 19:21:00 +0000292 });
293
Akron5d4f2e42024-12-16 09:10:27 +0100294 it('should deserialize JSON-LD integer', function () {
295 doc = integerFactory.create({});
296
297 expect(doc.matchop()).toEqual('eq');
298 expect(doc.key()).toEqual("KED.nToks");
299 expect(doc.type()).toEqual("integer");
300 expect(doc.value()).toEqual("200");
301 });
302
Nils Diewald7c8ced22015-04-15 19:21:00 +0000303 it('should be serializale to JSON', function () {
304
305 // Empty doc
306 var doc = docClass.create();
307 expect(doc.toJson()).toEqual(jasmine.any(Object));
308
309 // Serialize string
310 doc = stringFactory.create();
311 expect(doc.toJson()).toEqual(jasmine.objectContaining({
Akron712733a2018-04-05 18:17:47 +0200312 "@type" : "koral:doc",
313 "type" : "type:string",
314 "key" : "author",
315 "value" : "Max Birkendale",
316 "match" : "match:eq"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000317 }));
318
319 // Serialize regex
320 doc = regexFactory.create();
321 expect(doc.toJson()).toEqual(jasmine.objectContaining({
Akron712733a2018-04-05 18:17:47 +0200322 "@type" : "koral:doc",
323 "type" : "type:regex",
324 "value" : "[^b]ee.+?",
325 "match" : "match:eq",
326 "key" : 'title'
Nils Diewald7c8ced22015-04-15 19:21:00 +0000327 }));
328
329 doc = regexFactory.create({
Akron712733a2018-04-05 18:17:47 +0200330 match: "match:ne"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000331 });
332 expect(doc.toJson()).toEqual(jasmine.objectContaining({
Akron712733a2018-04-05 18:17:47 +0200333 "@type" : "koral:doc",
334 "type" : "type:regex",
335 "value" : "[^b]ee.+?",
336 "match" : "match:ne",
337 "key" : 'title'
Nils Diewald7c8ced22015-04-15 19:21:00 +0000338 }));
339
340 doc = dateFactory.create();
341 expect(doc.toJson()).toEqual(jasmine.objectContaining({
Akron712733a2018-04-05 18:17:47 +0200342 "@type" : "koral:doc",
343 "type" : "type:date",
344 "value" : "2014-11-05",
345 "match" : "match:eq",
346 "key" : 'pubDate'
Nils Diewald7c8ced22015-04-15 19:21:00 +0000347 }));
348
349 doc = dateFactory.create({
Akron712733a2018-04-05 18:17:47 +0200350 value : "2014"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000351 });
352 expect(doc.toJson()).toEqual(jasmine.objectContaining({
Akron712733a2018-04-05 18:17:47 +0200353 "@type" : "koral:doc",
354 "type" : "type:date",
355 "value" : "2014",
356 "match" : "match:eq",
357 "key" : 'pubDate'
Nils Diewald7c8ced22015-04-15 19:21:00 +0000358 }));
359 });
360
361
362 it('should be serializale to String', function () {
363 // Empty doc
364 var doc = docClass.create();
Akronebc96662018-08-29 17:36:20 +0200365
Nils Diewald7c8ced22015-04-15 19:21:00 +0000366 expect(doc.toQuery()).toEqual("");
367
368 // Serialize string
369 doc = stringFactory.create();
370 expect(doc.toQuery()).toEqual('author = "Max Birkendale"');
371
hebastaa0282be2018-12-05 16:58:00 +0100372 // Check for incompletion
373 expect(doc.incomplete()).toBeFalsy();
374 doc.value("");
375 expect(doc.incomplete()).toBeTruthy();
376 expect(doc.toQuery()).toEqual('');
377
Nils Diewald7c8ced22015-04-15 19:21:00 +0000378 // Serialize string with quotes
379 doc = stringFactory.create({ "value" : 'Max "Der Coole" Birkendate'});
380 expect(doc.toQuery()).toEqual('author = "Max \\"Der Coole\\" Birkendate"');
381
382 // Serialize regex
383 doc = regexFactory.create();
384 expect(doc.toQuery()).toEqual('title = /[^b]ee.+?/');
385
386 doc = regexFactory.create({
Akron712733a2018-04-05 18:17:47 +0200387 match: "match:ne"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000388 });
389 expect(doc.toQuery()).toEqual('title != /[^b]ee.+?/');
390
Akron8778f5d2017-06-30 21:25:55 +0200391 doc = regexFactory.create({
Akron712733a2018-04-05 18:17:47 +0200392 value: "WPD/AAA/00001"
Akron8778f5d2017-06-30 21:25:55 +0200393 });
394 expect(doc.toQuery()).toEqual('title = /WPD\\/AAA\\/00001/');
395
Nils Diewald7c8ced22015-04-15 19:21:00 +0000396 doc = dateFactory.create();
397 expect(doc.toQuery()).toEqual('pubDate in 2014-11-05');
398
399 doc = dateFactory.create({
Akron712733a2018-04-05 18:17:47 +0200400 value : "2014"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000401 });
402 expect(doc.toQuery()).toEqual('pubDate in 2014');
Akron5d4f2e42024-12-16 09:10:27 +0100403
Marc Kupietza5f79e62024-12-17 07:15:46 +0100404 // Checks for integer values
Akron5d4f2e42024-12-16 09:10:27 +0100405 doc = integerFactory.create();
406 expect(doc.toQuery()).toEqual('KED.nToks = 200');
407
408 doc = integerFactory.create({
409 value : "100"
410 });
411 expect(doc.toQuery()).toEqual('KED.nToks = 100');
412
413 doc = integerFactory.create({
414 value : "100",
415 match : "match:geq"
416 });
417 expect(doc.toQuery()).toEqual('KED.nToks >= 100');
418
419 doc = integerFactory.create({
420 value : "100",
421 match : "match:leq"
422 });
423 expect(doc.toQuery()).toEqual('KED.nToks <= 100');
424
Marc Kupietza5f79e62024-12-17 07:15:46 +0100425 doc = integerFactory.create({
426 value : "100",
427 match : "match:gt"
428 });
429 expect(doc.toQuery()).toEqual('KED.nToks > 100');
430
431 doc = integerFactory.create({
432 value : "100",
433 match : "match:lt"
434 });
435 expect(doc.toQuery()).toEqual('KED.nToks < 100');
436
Akron5d4f2e42024-12-16 09:10:27 +0100437 doc = integerFactory.create({
438 value : 100,
439 });
440 expect(doc.toQuery()).toEqual('KED.nToks = 100');
441
Nils Diewald7c8ced22015-04-15 19:21:00 +0000442 });
443 });
444
445
Akron88d237e2020-10-21 08:05:18 +0200446 describe('KorAP.VC.DocGroup', function () {
Nils Diewald7c8ced22015-04-15 19:21:00 +0000447 // Create example factories
448 var docFactory = buildFactory(
449 docClass,
Nils Diewaldf219eb82015-01-07 20:15:42 +0000450 {
Akron712733a2018-04-05 18:17:47 +0200451 "@type" : "koral:doc",
452 "match":"match:eq",
453 "key" : "author",
454 "value" : "Max Birkendale"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000455 }
456 );
457
458 var docGroupFactory = buildFactory(
459 docGroupClass, {
Akron712733a2018-04-05 18:17:47 +0200460 "@type" : "koral:docGroup",
461 "operation" : "operation:and",
462 "operands" : [
463 docFactory.create().toJson(),
464 docFactory.create({
465 "key" : "pubDate",
466 "type" : "type:date",
467 "value" : "2014-12-05"
468 }).toJson()
469 ]
Nils Diewald7c8ced22015-04-15 19:21:00 +0000470 });
471
472 it('should be initializable', function () {
473 // Create empty group
474 var docGroup = docGroupClass.create();
475 expect(docGroup.operation()).toEqual('and');
476
477 // Create empty group
478 docGroup = docGroupClass.create();
479 docGroup.operation('or');
480 expect(docGroup.operation()).toEqual('or');
481 });
482
483 it('should be definable', function () {
484
485 // Empty group
486 var docGroup = docGroupClass.create();
487 expect(docGroup.operation()).toEqual('and');
488
489 // Set values
490 docGroup.operation("or");
491 expect(docGroup.operation()).toEqual('or');
492
493 // Set invalid values
494 docGroup.operation("hui");
495 expect(docGroup.operation()).toEqual('or');
496 });
497
498 it('should be deserializable', function () {
Akronadab5e52018-08-20 13:50:53 +0200499
500 // Reset list
501 KorAP._vcKeyMenu = menuClass.create([['referTo','ref']]);
502
Nils Diewald7c8ced22015-04-15 19:21:00 +0000503 var docGroup = docGroupFactory.create();
504 expect(docGroup.operation()).toEqual("and");
505 expect(docGroup.operands().length).toEqual(2);
506
507 var op1 = docGroup.getOperand(0);
508 expect(op1.type()).toEqual("string");
509 expect(op1.key()).toEqual("author");
510 expect(op1.value()).toEqual("Max Birkendale");
511 expect(op1.matchop()).toEqual("eq");
512
513 var op2 = docGroup.getOperand(1);
514 expect(op2.type()).toEqual("date");
515 expect(op2.key()).toEqual("pubDate");
516 expect(op2.value()).toEqual("2014-12-05");
517 expect(op2.matchop()).toEqual("eq");
518
519 // Append empty group
520 var newGroup = docGroup.append(docGroupClass.create());
521 newGroup.operation('or');
522 newGroup.append(docFactory.create());
523 newGroup.append(docFactory.create({
Akron712733a2018-04-05 18:17:47 +0200524 "type" : "type:regex",
525 "key" : "title",
526 "value" : "^e.+?$",
527 "match" : "match:ne"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000528 }));
529
530 expect(docGroup.operation()).toEqual("and");
531 expect(docGroup.operands().length).toEqual(3);
532
533 var op1 = docGroup.getOperand(0);
534 expect(op1.ldType()).toEqual("doc");
535 expect(op1.type()).toEqual("string");
536 expect(op1.key()).toEqual("author");
537 expect(op1.value()).toEqual("Max Birkendale");
538 expect(op1.matchop()).toEqual("eq");
539
540 var op2 = docGroup.getOperand(1);
541 expect(op2.ldType()).toEqual("doc");
542 expect(op2.type()).toEqual("date");
543 expect(op2.key()).toEqual("pubDate");
544 expect(op2.value()).toEqual("2014-12-05");
545 expect(op2.matchop()).toEqual("eq");
546
547 var op3 = docGroup.getOperand(2);
548 expect(op3.ldType()).toEqual("docGroup");
549 expect(op3.operation()).toEqual("or");
Akronadab5e52018-08-20 13:50:53 +0200550
Nils Diewald7c8ced22015-04-15 19:21:00 +0000551 var op4 = op3.getOperand(0);
552 expect(op4.ldType()).toEqual("doc");
553 expect(op4.type()).toEqual("string");
554 expect(op4.key()).toEqual("author");
555 expect(op4.value()).toEqual("Max Birkendale");
556 expect(op4.matchop()).toEqual("eq");
557
558 var op5 = op3.getOperand(1);
559 expect(op5.ldType()).toEqual("doc");
560 expect(op5.type()).toEqual("regex");
561 expect(op5.key()).toEqual("title");
562 expect(op5.value()).toEqual("^e.+?$");
563 expect(op5.matchop()).toEqual("ne");
564 });
565
566 it('should be serializable to JSON', function () {
567 var docGroup = docGroupFactory.create();
568
569 expect(docGroup.toJson()).toEqual(jasmine.objectContaining({
Akron712733a2018-04-05 18:17:47 +0200570 "@type" : "koral:docGroup",
571 "operation" : "operation:and",
572 "operands" : [
573 {
574 "@type": 'koral:doc',
575 "key" : 'author',
576 "match": 'match:eq',
577 "value": 'Max Birkendale',
578 "type": 'type:string'
579 },
580 {
581 "@type": 'koral:doc',
582 "key": 'pubDate',
583 "match": 'match:eq',
584 "value": '2014-12-05',
585 "type": 'type:date'
586 }
587 ]
Nils Diewald7c8ced22015-04-15 19:21:00 +0000588 }));
589 });
Nils Diewalde15b7a22015-01-09 21:50:21 +0000590
Nils Diewald7c8ced22015-04-15 19:21:00 +0000591 it('should be serializable to String', function () {
592 var docGroup = docGroupFactory.create();
593 expect(docGroup.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +0200594 'author = "Max Birkendale" & pubDate in 2014-12-05'
Nils Diewald7c8ced22015-04-15 19:21:00 +0000595 );
Nils Diewald52f7eb12015-01-12 17:30:04 +0000596
Nils Diewald7c8ced22015-04-15 19:21:00 +0000597 docGroup = docGroupFactory.create({
Akron712733a2018-04-05 18:17:47 +0200598 "@type" : "koral:docGroup",
599 "operation" : "operation:or",
600 "operands" : [
601 {
602 "@type": 'koral:doc',
603 "key" : 'author',
604 "match": 'match:eq',
605 "value": 'Max Birkendale',
606 "type": 'type:string'
607 },
608 {
609 "@type" : "koral:docGroup",
610 "operation" : "operation:and",
611 "operands" : [
612 {
613 "@type": 'koral:doc',
614 "key": 'pubDate',
615 "match": 'match:geq',
616 "value": '2014-05-12',
617 "type": 'type:date'
618 },
619 {
620 "@type": 'koral:doc',
621 "key": 'pubDate',
622 "match": 'match:leq',
623 "value": '2014-12-05',
624 "type": 'type:date'
625 },
626 {
627 "@type": 'koral:doc',
628 "key": 'foo',
629 "match": 'match:ne',
630 "value": '[a]?bar',
631 "type": 'type:regex'
Akron5d4f2e42024-12-16 09:10:27 +0100632 },
633 {
634 "@type": 'koral:doc',
635 "key": 'KED.nToks',
636 "match": 'match:leq',
637 "value": '300',
638 "type": 'type:integer'
Akron712733a2018-04-05 18:17:47 +0200639 }
Akron5d4f2e42024-12-16 09:10:27 +0100640
Akron712733a2018-04-05 18:17:47 +0200641 ]
642 }
643 ]
Nils Diewald7c8ced22015-04-15 19:21:00 +0000644 });
645 expect(docGroup.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +0200646 'author = "Max Birkendale" | ' +
647 '(pubDate since 2014-05-12 & ' +
Akron5d4f2e42024-12-16 09:10:27 +0100648 'pubDate until 2014-12-05 & foo != /[a]?bar/ & ' +
649 'KED.nToks <= 300)'
Nils Diewald7c8ced22015-04-15 19:21:00 +0000650 );
hebastaa0282be2018-12-05 16:58:00 +0100651
652
653 // Check for incompletion and only serialize complete operands
654 expect(docGroup.incomplete()).toBeFalsy();
655 var op1 = docGroup.getOperand(0);
656 op1.value("");
657 expect(docGroup.incomplete()).toBeFalsy();
658 expect(docGroup.toQuery()).toEqual(
659 '(pubDate since 2014-05-12 & ' +
Akron5d4f2e42024-12-16 09:10:27 +0100660 'pubDate until 2014-12-05 & foo != /[a]?bar/ & ' +
661 'KED.nToks <= 300)'
hebastaa0282be2018-12-05 16:58:00 +0100662 );
Nils Diewald7c8ced22015-04-15 19:21:00 +0000663 });
664 });
665
Akron88d237e2020-10-21 08:05:18 +0200666 describe('KorAP.VC.DocGroupRef', function () {
Akronb19803c2018-08-16 16:39:42 +0200667 // Create example factories
668 var docRefFactory = buildFactory(
669 docGroupRefClass,
670 {
671 "@type" : "koral:docGroupRef",
672 "ref" : "@max/myCorpus"
673 }
674 );
675
676 it('should be initializable', function () {
677 var vcRef = docGroupRefClass.create();
678 expect(vcRef.ref()).toBeUndefined();
679 });
680
681 it('should be definable', function () {
682 var vcRef = docGroupRefClass.create();
683 vcRef.ref("@peter/mycorpus");
684 expect(vcRef.ref()).toEqual("@peter/mycorpus");
685 vcRef.ref("@peter/mycorpus2");
686 expect(vcRef.ref()).toEqual("@peter/mycorpus2");
687 });
688
689 it('should deserialize JSON-LD string', function () {
690 var vcRef = docRefFactory.create();
691 expect(vcRef.ref()).toEqual("@max/myCorpus");
692 });
693
694 it('should serialize to JSON-LD', function () {
695 var vcRef = docRefFactory.create();
696 expect(vcRef.toJson()).toEqual(jasmine.objectContaining({
697 "@type" : "koral:docGroupRef",
698 "ref":"@max/myCorpus"
699 }));
700
701 vcRef.ref("@peter/myCorpus2");
702 expect(vcRef.toJson()).toEqual(jasmine.objectContaining({
703 "@type" : "koral:docGroupRef",
704 "ref":"@peter/myCorpus2"
705 }));
706 });
707
708 it('should serialize to a query', function () {
709 var vcRef = docRefFactory.create();
710 expect(vcRef.toQuery()).toEqual(
711 "referTo \"@max/myCorpus\""
712 );
713
714 vcRef.ref("@peter/myCorpus2");
715 expect(vcRef.toQuery()).toEqual(
716 "referTo \"@peter/myCorpus2\""
717 );
hebastaa0282be2018-12-05 16:58:00 +0100718
719 // Check for incompletion and only serialize complete operands
720 expect(vcRef.incomplete()).toBeFalsy();
721 vcRef.ref("");
722 expect(vcRef.incomplete()).toBeTruthy();
723 expect(vcRef.toQuery()).toEqual("");
Akronb19803c2018-08-16 16:39:42 +0200724 });
725 });
726
727
Akron88d237e2020-10-21 08:05:18 +0200728 describe('KorAP.VC.UnspecifiedDoc', function () {
Akron0f00b772020-12-02 17:32:13 +0100729
730 KorAP.vc = undefined;
731
Nils Diewald7c8ced22015-04-15 19:21:00 +0000732 it('should be initializable', function () {
733 var doc = unspecifiedClass.create();
734 var docElement = doc.element();
735 expect(docElement.getAttribute('class')).toEqual('doc unspecified');
Akronebc96662018-08-29 17:36:20 +0200736 expect(docElement.firstChild.firstChild.data).toEqual(KorAP.Locale.EMPTY);
737 expect(docElement.lastChild.lastChild.data).toEqual(KorAP.Locale.EMPTY);
Nils Diewald7c8ced22015-04-15 19:21:00 +0000738 expect(doc.toQuery()).toEqual('');
hebastaa0282be2018-12-05 16:58:00 +0100739 expect(doc.incomplete()).toBeTruthy();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000740
741 // Only removable
742 expect(docElement.lastChild.children.length).toEqual(0);
743 });
744
hebastad7c03742019-07-11 12:48:50 +0200745 it('should be removable, when no root', function () {
746 var vc = vcClass.create();
747 KorAP.vc = vc;
Nils Diewald7c8ced22015-04-15 19:21:00 +0000748 var docGroup = docGroupClass.create();
749 docGroup.operation('or');
750 expect(docGroup.operation()).toEqual('or');
751
752 docGroup.append({
Akron712733a2018-04-05 18:17:47 +0200753 "@type": 'koral:doc',
754 "key": 'pubDate',
755 "match": 'match:eq',
756 "value": '2014-12-05',
757 "type": 'type:date'
Nils Diewald7c8ced22015-04-15 19:21:00 +0000758 });
759
760 // Add unspecified object
761 docGroup.append();
762
Akrond141a362018-07-10 18:12:13 +0200763 var parent = document.createElement('div');
764 parent.appendChild(docGroup.element());
765
Nils Diewald7c8ced22015-04-15 19:21:00 +0000766 expect(docGroup.element().getAttribute('class')).toEqual('docGroup');
767 expect(docGroup.element().children[0].getAttribute('class')).toEqual('doc');
768
769 var unspec = docGroup.element().children[1];
770 expect(unspec.getAttribute('class')).toEqual('doc unspecified');
771
Akronb19803c2018-08-16 16:39:42 +0200772 // Only unspec and delete
773 expect(unspec.children.length).toEqual(2);
774
Nils Diewald7c8ced22015-04-15 19:21:00 +0000775 // Removable
776 expect(unspec.lastChild.children.length).toEqual(1);
777 expect(unspec.lastChild.children[0].getAttribute('class')).toEqual('delete');
778 });
779
Akrond141a362018-07-10 18:12:13 +0200780
Nils Diewald7c8ced22015-04-15 19:21:00 +0000781 it('should be replaceable by a doc', function () {
782 var doc = unspecifiedClass.create();
783 expect(doc.ldType()).toEqual("non");
784 // No parent, therefor not updateable
785 expect(doc.key("baum")).toBeNull();
786
787 var docGroup = docGroupClass.create();
788 docGroup.operation('or');
789 expect(docGroup.operation()).toEqual('or');
790
791 docGroup.append({
Akron712733a2018-04-05 18:17:47 +0200792 "@type": 'koral:doc',
793 "key": 'pubDate',
794 "match": 'match:eq',
795 "value": '2014-12-05',
796 "type": 'type:date'
Nils Diewald7c8ced22015-04-15 19:21:00 +0000797 });
798
799 expect(docGroup.toQuery()).toEqual("pubDate in 2014-12-05");
800 docGroup.append();
801
802 expect(docGroup.getOperand(0).ldType()).toEqual("doc");
803 expect(docGroup.getOperand(1).ldType()).toEqual("non");
804
805 var op = docGroup.getOperand(1).element().lastChild;
Akron0b489ad2018-02-02 16:49:32 +0100806 expect(op.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +0000807 expect(op.children[0].getAttribute('class')).toEqual('delete');
808 expect(op.children.length).toEqual(1);
809
810 // Replace unspecified doc
811 expect(docGroup.getOperand(1).key("name")).not.toBeNull();
812 expect(docGroup.getOperand(1).ldType()).toEqual("doc");
813 expect(docGroup.getOperand(1).key()).toEqual("name");
Akron55a343b2018-04-06 19:57:36 +0200814 expect(docGroup.getOperand(1).value()).toBeUndefined();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000815
Akronb19803c2018-08-16 16:39:42 +0200816 expect(docGroup.getOperand(1).element().children.length).toEqual(4);
817
Nils Diewald7c8ced22015-04-15 19:21:00 +0000818 op = docGroup.getOperand(1).element().lastChild;
Akron0b489ad2018-02-02 16:49:32 +0100819 expect(op.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +0000820 expect(op.children[0].getAttribute('class')).toEqual('and');
821 expect(op.children[1].getAttribute('class')).toEqual('or');
822 expect(op.children[2].getAttribute('class')).toEqual('delete');
Akronb19803c2018-08-16 16:39:42 +0200823
Nils Diewald7c8ced22015-04-15 19:21:00 +0000824 expect(op.children.length).toEqual(3);
825
826 docGroup.getOperand(1).value("Pachelbel");
827 expect(docGroup.getOperand(1).value()).toEqual("Pachelbel");
828 expect(docGroup.getOperand(1).type()).toEqual("string");
829 expect(docGroup.getOperand(1).matchop()).toEqual("eq");
830
831 // Specified!
832 expect(docGroup.toQuery()).toEqual('pubDate in 2014-12-05 | name = "Pachelbel"');
833 });
Akronb19803c2018-08-16 16:39:42 +0200834
Nils Diewald7c8ced22015-04-15 19:21:00 +0000835 it('should be replaceable on root', function () {
hebastaa0282be2018-12-05 16:58:00 +0100836
Nils Diewald6283d692015-04-23 20:32:53 +0000837 var vc = vcClass.create();
hebastaa0282be2018-12-05 16:58:00 +0100838 KorAP.vc = vc;
Nils Diewald7c8ced22015-04-15 19:21:00 +0000839 expect(vc.toQuery()).toEqual("");
840
841 expect(vc.root().ldType()).toEqual("non");
842
843 // No operators on root
844 op = vc.root().element().lastChild;
Akronebc96662018-08-29 17:36:20 +0200845 expect(op.lastChild.textContent).toEqual(KorAP.Locale.EMPTY);
Nils Diewald7c8ced22015-04-15 19:21:00 +0000846
847 // Replace
848 expect(vc.root().key("baum")).not.toBeNull();
849 expect(vc.root().ldType()).toEqual("doc");
850
851 op = vc.root().element().lastChild;
Akron0b489ad2018-02-02 16:49:32 +0100852 expect(op.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +0000853 expect(op.children[0].getAttribute('class')).toEqual('and');
854 expect(op.children[1].getAttribute('class')).toEqual('or');
855 expect(op.children[2].getAttribute('class')).toEqual('delete');
856 expect(op.children.length).toEqual(3);
857 });
Akron55a343b2018-04-06 19:57:36 +0200858
859 it('should be clickable', function () {
860 var vc = vcClass.create([
861 ["pubDate", "date"]
862 ]);
hebastaa0282be2018-12-05 16:58:00 +0100863 KorAP.vc = vc;
864
Akron55a343b2018-04-06 19:57:36 +0200865 expect(vc.toQuery()).toEqual("");
Akronebc96662018-08-29 17:36:20 +0200866 expect(vc.builder().firstChild.textContent).toEqual(KorAP.Locale.EMPTY);
867 expect(vc.builder().firstChild.classList.contains('unspecified')).toEqual(true);
Akronadab5e52018-08-20 13:50:53 +0200868 vc.builder().firstChild.firstChild.click();
Akron55a343b2018-04-06 19:57:36 +0200869
870 // Click on pubDate
Akron3ad46942018-08-22 16:47:14 +0200871 vc.element().firstChild.getElementsByTagName("LI")[1].click();
Akronadab5e52018-08-20 13:50:53 +0200872 expect(vc.builder().firstChild.firstChild.textContent).toEqual("pubDate");
873 expect(vc.builder().firstChild.children[1].getAttribute("data-type")).toEqual("date");
Akron55a343b2018-04-06 19:57:36 +0200874 });
Nils Diewald7c8ced22015-04-15 19:21:00 +0000875 });
876
Akron88d237e2020-10-21 08:05:18 +0200877 describe('KorAP.VC.Doc element', function () {
Nils Diewald7c8ced22015-04-15 19:21:00 +0000878 it('should be initializable', function () {
879 var docElement = docClass.create(undefined, {
Akron712733a2018-04-05 18:17:47 +0200880 "@type" : "koral:doc",
881 "key":"Titel",
882 "value":"Baum",
883 "match":"match:eq"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000884 });
885 expect(docElement.key()).toEqual('Titel');
886 expect(docElement.matchop()).toEqual('eq');
887 expect(docElement.value()).toEqual('Baum');
888
889 var docE = docElement.element();
890 expect(docE.children[0].firstChild.data).toEqual('Titel');
891 expect(docE.children[1].firstChild.data).toEqual('eq');
892 expect(docE.children[1].getAttribute('data-type')).toEqual('string');
893 expect(docE.children[2].firstChild.data).toEqual('Baum');
894 expect(docE.children[2].getAttribute('data-type')).toEqual('string');
895
896 expect(docElement.toJson()).toEqual(jasmine.objectContaining({
Akron712733a2018-04-05 18:17:47 +0200897 "@type" : "koral:doc",
898 "key":"Titel",
899 "value":"Baum",
900 "match":"match:eq"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000901 }));
902 });
Akronb19803c2018-08-16 16:39:42 +0200903
904
905 it('should be replacable by unspecified', function () {
906 var vc = vcClass.create([
907 ["pubDate", "date"]
908 ]).fromJson({
909 "@type" : "koral:doc",
910 "key":"Titel",
911 "value":"Baum",
912 "match":"match:eq"
913 });
hebastaa0282be2018-12-05 16:58:00 +0100914 KorAP.vc = vc;
Akronb19803c2018-08-16 16:39:42 +0200915 expect(vc.toQuery()).toEqual("Titel = \"Baum\"");
916
Akronadab5e52018-08-20 13:50:53 +0200917 var vcE = vc.builder();
Akronb19803c2018-08-16 16:39:42 +0200918 expect(vcE.firstChild.children.length).toEqual(4);
919
920 // Click to delete
921 vcE.firstChild.lastChild.lastChild.click();
922
923 expect(vcE.firstChild.children.length).toEqual(1);
924
Akronebc96662018-08-29 17:36:20 +0200925 expect(vcE.firstChild.textContent).toEqual(KorAP.Locale.EMPTY);
926 expect(vcE.firstChild.classList.contains("unspecified")).toBeTruthy();
Akronb19803c2018-08-16 16:39:42 +0200927 vcE.firstChild.firstChild.click();
928
929 // Click on pubDate
Akron3ad46942018-08-22 16:47:14 +0200930 vcE.firstChild.getElementsByTagName("LI")[1].click();
Akronb19803c2018-08-16 16:39:42 +0200931
932 expect(vcE.firstChild.firstChild.textContent).toEqual("pubDate");
933 expect(vcE.firstChild.children[1].getAttribute("data-type")).toEqual("date");
934
935 expect(vcE.firstChild.children.length).toEqual(4);
936 });
937
938
Akron587e4d92018-08-31 12:44:26 +0200939 it('should be replaceable by docGroupRef with deletion', function () {
Akron3ad46942018-08-22 16:47:14 +0200940 var vc = vcClass.create().fromJson({
Akronb19803c2018-08-16 16:39:42 +0200941 "@type" : "koral:doc",
942 "key":"Titel",
943 "value":"Baum",
944 "match":"match:eq"
945 });
946
hebastaa0282be2018-12-05 16:58:00 +0100947 KorAP.vc = vc;
Akronb19803c2018-08-16 16:39:42 +0200948 expect(vc.toQuery()).toEqual("Titel = \"Baum\"");
949
Akronadab5e52018-08-20 13:50:53 +0200950 var vcE = vc.builder();
Akronb19803c2018-08-16 16:39:42 +0200951 expect(vcE.firstChild.children.length).toEqual(4);
952
953 // Click to delete
954 vcE.firstChild.lastChild.lastChild.click();
955
956 expect(vcE.firstChild.children.length).toEqual(1);
957
Akronebc96662018-08-29 17:36:20 +0200958 expect(vcE.firstChild.textContent).toEqual(KorAP.Locale.EMPTY);
959 expect(vcE.firstChild.classList.contains('unspecified')).toEqual(true);
Akronb19803c2018-08-16 16:39:42 +0200960 vcE.firstChild.firstChild.click();
961
Akron3ad46942018-08-22 16:47:14 +0200962 // Click on referTo
Akronb19803c2018-08-16 16:39:42 +0200963 vcE.firstChild.getElementsByTagName("LI")[0].click();
964
Akron3ad46942018-08-22 16:47:14 +0200965 expect(vcE.firstChild.firstChild.textContent).toEqual("referTo");
Akronb19803c2018-08-16 16:39:42 +0200966 expect(vcE.firstChild.children[1].getAttribute("data-type")).toEqual("string");
Akron587e4d92018-08-31 12:44:26 +0200967
Akronb19803c2018-08-16 16:39:42 +0200968 expect(vcE.firstChild.children.length).toEqual(3);
Akron62ac95b2018-08-30 18:08:25 +0200969 expect(vcE.firstChild.children[1].classList.contains("unspecified")).toBeTruthy();
Akronb19803c2018-08-16 16:39:42 +0200970 });
Akron587e4d92018-08-31 12:44:26 +0200971
972
973 it('should be replaceable by docGroupRef on root', function () {
974 var vc = vcClass.create().fromJson({
975 "@type" : "koral:doc",
976 "key":"Titel",
977 "value":"Baum",
978 "match":"match:eq"
979 });
980
hebastaa0282be2018-12-05 16:58:00 +0100981 KorAP.vc = vc;
Akron587e4d92018-08-31 12:44:26 +0200982 expect(vc.toQuery()).toEqual("Titel = \"Baum\"");
983
984 var vcE = vc.builder();
985 expect(vcE.firstChild.children.length).toEqual(4);
986
987 // Click on the key
988 vcE.firstChild.firstChild.click();
989
990 expect(vcE.firstChild.getElementsByTagName("LI")[0].textContent).toEqual("referTo");
991
992 // Click on referTo
993 vcE.firstChild.getElementsByTagName("LI")[0].click();
994
995 // Now it's a referTo element
996 expect(vcE.firstChild.firstChild.textContent).toEqual("referTo");
997 expect(vcE.firstChild.children.length).toEqual(3);
998 expect(vcE.firstChild.children[1].classList.contains("unspecified")).toBeTruthy();
999 });
1000
1001 it('should be replaceable by docGroupRef nested', function () {
1002 var vc = vcClass.create().fromJson({
1003 "@type" : "koral:docGroup",
1004 "operation" : "operation:and",
1005 "operands" : [
1006 {
1007 "@type": 'koral:doc',
1008 "key" : 'author',
1009 "match": 'match:eq',
1010 "value": 'Max Birkendale',
1011 "type": 'type:string'
1012 },
1013 {
1014 "@type": 'koral:doc',
1015 "key": 'pubDate',
1016 "match": 'match:eq',
1017 "value": '2014-12-05',
1018 "type": 'type:date'
1019 }
1020 ]
1021 });
1022
hebastaa0282be2018-12-05 16:58:00 +01001023 KorAP.vc = vc;
Akron587e4d92018-08-31 12:44:26 +02001024 expect(vc.toQuery()).toEqual("author = \"Max Birkendale\" & pubDate in 2014-12-05");
1025
1026 var vcE = vc.builder();
1027
1028 // First doc
1029 var doc = vcE.firstChild.firstChild;
1030 expect(doc.children.length).toEqual(4);
1031
1032 // Click on the key
1033 doc.firstChild.click();
1034
1035 expect(doc.getElementsByTagName("LI")[0].textContent).toEqual("referTo");
1036
1037 // Click on referTo
1038 vcE.firstChild.getElementsByTagName("LI")[0].click();
1039
1040 // Now it's a referTo element
1041 expect(vcE.firstChild.firstChild.firstChild.textContent).toEqual("referTo");
1042 expect(vcE.firstChild.firstChild.children.length).toEqual(3);
1043 expect(vcE.firstChild.firstChild.children[1].classList.contains("unspecified")).toBeTruthy();
1044 });
Nils Diewald7c8ced22015-04-15 19:21:00 +00001045 });
1046
Akron88d237e2020-10-21 08:05:18 +02001047 describe('KorAP.VC.DocGroup element', function () {
Nils Diewald7c8ced22015-04-15 19:21:00 +00001048 it('should be initializable', function () {
1049
1050 var docGroup = docGroupClass.create(undefined, {
Akron712733a2018-04-05 18:17:47 +02001051 "@type" : "koral:docGroup",
1052 "operation" : "operation:and",
1053 "operands" : [
1054 {
1055 "@type": 'koral:doc',
1056 "key" : 'author',
1057 "match": 'match:eq',
1058 "value": 'Max Birkendale',
1059 "type": 'type:string'
1060 },
1061 {
1062 "@type": 'koral:doc',
1063 "key": 'pubDate',
1064 "match": 'match:eq',
1065 "value": '2014-12-05',
1066 "type": 'type:date'
1067 }
1068 ]
Nils Diewald7c8ced22015-04-15 19:21:00 +00001069 });
1070
1071 expect(docGroup.operation()).toEqual('and');
1072 var e = docGroup.element();
1073 expect(e.getAttribute('class')).toEqual('docGroup');
1074 expect(e.getAttribute('data-operation')).toEqual('and');
1075
1076 var first = e.children[0];
1077 expect(first.getAttribute('class')).toEqual('doc');
1078 expect(first.children[0].getAttribute('class')).toEqual('key');
1079 expect(first.children[1].getAttribute('class')).toEqual('match');
1080 expect(first.children[2].getAttribute('class')).toEqual('value');
1081 expect(first.children[2].getAttribute('data-type')).toEqual('string');
1082 expect(first.children[0].firstChild.data).toEqual('author');
1083 expect(first.children[1].firstChild.data).toEqual('eq');
1084 expect(first.children[2].firstChild.data).toEqual('Max Birkendale');
1085
1086 var second = e.children[1];
1087 expect(second.getAttribute('class')).toEqual('doc');
1088 expect(second.children[0].getAttribute('class')).toEqual('key');
1089 expect(second.children[1].getAttribute('class')).toEqual('match');
1090 expect(second.children[2].getAttribute('class')).toEqual('value');
1091 expect(second.children[2].getAttribute('data-type')).toEqual('date');
1092 expect(second.children[0].firstChild.data).toEqual('pubDate');
1093 expect(second.children[1].firstChild.data).toEqual('eq');
1094 expect(second.children[2].firstChild.data).toEqual('2014-12-05');
1095 });
1096
1097 it('should be deserializable with nested groups', function () {
1098 var docGroup = docGroupClass.create(undefined, {
Akron712733a2018-04-05 18:17:47 +02001099 "@type" : "koral:docGroup",
1100 "operation" : "operation:or",
1101 "operands" : [
1102 {
1103 "@type": 'koral:doc',
1104 "key" : 'author',
1105 "match": 'match:eq',
1106 "value": 'Max Birkendale',
1107 "type": 'type:string'
1108 },
1109 {
1110 "@type" : "koral:docGroup",
1111 "operation" : "operation:and",
1112 "operands" : [
1113 {
1114 "@type": 'koral:doc',
1115 "key": 'pubDate',
1116 "match": 'match:geq',
1117 "value": '2014-05-12',
1118 "type": 'type:date'
1119 },
1120 {
1121 "@type": 'koral:doc',
1122 "key": 'pubDate',
1123 "match": 'match:leq',
1124 "value": '2014-12-05',
1125 "type": 'type:date'
1126 }
1127 ]
1128 }
1129 ]
Nils Diewald7c8ced22015-04-15 19:21:00 +00001130 });
1131
1132 expect(docGroup.operation()).toEqual('or');
1133 var e = docGroup.element();
1134 expect(e.getAttribute('class')).toEqual('docGroup');
1135 expect(e.getAttribute('data-operation')).toEqual('or');
1136
1137 expect(e.children[0].getAttribute('class')).toEqual('doc');
1138 var docop = e.children[0].lastChild;
Akron0b489ad2018-02-02 16:49:32 +01001139 expect(docop.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001140 expect(docop.children[0].getAttribute('class')).toEqual('and');
1141 expect(docop.children[1].getAttribute('class')).toEqual('or');
1142 expect(docop.children[2].getAttribute('class')).toEqual('delete');
1143
1144 expect(e.children[1].getAttribute('class')).toEqual('docGroup');
1145 expect(e.children[1].getAttribute('data-operation')).toEqual('and');
1146
1147 // This and-operation can be "or"ed or "delete"d
1148 var secop = e.children[1].children[2];
Akron0b489ad2018-02-02 16:49:32 +01001149 expect(secop.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001150 expect(secop.children[0].getAttribute('class')).toEqual('or');
1151 expect(secop.children[1].getAttribute('class')).toEqual('delete');
1152
1153 // This or-operation can be "and"ed or "delete"d
Akron0b489ad2018-02-02 16:49:32 +01001154 expect(e.children[2].getAttribute('class')).toEqual('operators button-group');
1155 expect(e.lastChild.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001156 expect(e.lastChild.children[0].getAttribute('class')).toEqual('and');
1157 expect(e.lastChild.children[1].getAttribute('class')).toEqual('delete');
1158 });
1159 });
1160
Akron88d237e2020-10-21 08:05:18 +02001161 describe('KorAP.VC.DocGroupRef element', function () {
Akronb19803c2018-08-16 16:39:42 +02001162 it('should be initializable', function () {
1163 var docGroupRef = docGroupRefClass.create(undefined, {
1164 "@type" : "koral:docGroupRef",
1165 "ref" : "@franz/myVC1"
1166 });
1167 expect(docGroupRef.ref()).toEqual("@franz/myVC1");
1168 var dgrE = docGroupRef.element();
1169
Akron3ad46942018-08-22 16:47:14 +02001170 expect(dgrE.children[0].firstChild.data).toEqual("referTo");
Akronb19803c2018-08-16 16:39:42 +02001171 expect(dgrE.children[0].tagName).toEqual("SPAN");
1172 expect(dgrE.children[0].classList.contains("key")).toBeTruthy();
1173 expect(dgrE.children[0].classList.contains("fixed")).toBeTruthy();
1174 expect(dgrE.children[1].firstChild.data).toEqual("@franz/myVC1");
1175 expect(dgrE.children[1].tagName).toEqual("SPAN");
1176 expect(dgrE.children[1].classList.contains("value")).toBeTruthy();
1177 expect(dgrE.children[1].getAttribute("data-type")).toEqual("string");
1178 });
1179
1180 it('should be modifiable on reference', function () {
1181 var docGroupRef = docGroupRefClass.create(undefined, {
1182 "@type" : "koral:docGroupRef",
1183 "ref" : "@franz/myVC1"
1184 });
1185 var dgrE = docGroupRef.element();
1186 expect(docGroupRef.toQuery()).toEqual("referTo \"@franz/myVC1\"");
1187 dgrE.children[1].click();
1188
1189 var input = dgrE.children[1].firstChild;
1190 expect(input.tagName).toEqual("INPUT");
1191 input.value = "Versuch";
1192
1193 var event = new KeyboardEvent("keypress", {
1194 "key" : "[Enter]",
1195 "keyCode" : 13
1196 });
1197
1198 input.dispatchEvent(event);
1199 expect(docGroupRef.toQuery()).toEqual("referTo \"Versuch\"");
1200 });
1201 });
1202
1203
Akron88d237e2020-10-21 08:05:18 +02001204 describe('KorAP.VC.VirtualCorpus', function () {
Nils Diewald7c8ced22015-04-15 19:21:00 +00001205 var simpleGroupFactory = buildFactory(docGroupClass, {
1206 "@type" : "koral:docGroup",
1207 "operation" : "operation:and",
1208 "operands" : [
Akron712733a2018-04-05 18:17:47 +02001209 {
1210 "@type": 'koral:doc',
1211 "key" : 'author',
1212 "match": 'match:eq',
1213 "value": 'Max Birkendale',
1214 "type": 'type:string'
1215 },
1216 {
1217 "@type": 'koral:doc',
1218 "key": 'pubDate',
1219 "match": 'match:eq',
1220 "value": '2014-12-05',
1221 "type": 'type:date'
1222 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00001223 ]
1224 });
1225
1226 var nestedGroupFactory = buildFactory(vcClass, {
1227 "@type" : "koral:docGroup",
1228 "operation" : "operation:or",
1229 "operands" : [
Akron712733a2018-04-05 18:17:47 +02001230 {
1231 "@type": 'koral:doc',
1232 "key" : 'author',
1233 "match": 'match:eq',
1234 "value": 'Max Birkendale',
1235 "type": 'type:string'
1236 },
1237 {
1238 "@type" : "koral:docGroup",
1239 "operation" : "operation:and",
1240 "operands" : [
1241 {
1242 "@type": 'koral:doc',
1243 "key": 'pubDate',
1244 "match": 'match:geq',
1245 "value": '2014-05-12',
1246 "type": 'type:date'
1247 },
1248 {
1249 "@type": 'koral:doc',
1250 "key": 'pubDate',
1251 "match": 'match:leq',
1252 "value": '2014-12-05',
1253 "type": 'type:date'
1254 }
1255 ]
1256 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00001257 ]
1258 });
1259
1260 var flatGroupFactory = buildFactory(vcClass, {
1261 "@type" : "koral:docGroup",
1262 "operation" : "operation:and",
1263 "operands" : [
Akron712733a2018-04-05 18:17:47 +02001264 {
1265 "@type": 'koral:doc',
1266 "key": 'pubDate',
1267 "match": 'match:geq',
1268 "value": '2014-05-12',
1269 "type": 'type:date'
1270 },
1271 {
1272 "@type": 'koral:doc',
1273 "key": 'pubDate',
1274 "match": 'match:leq',
1275 "value": '2014-12-05',
1276 "type": 'type:date'
1277 },
1278 {
1279 "@type": 'koral:doc',
1280 "key": 'foo',
1281 "match": 'match:eq',
1282 "value": 'bar',
1283 "type": 'type:string'
1284 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00001285 ]
1286 });
1287
1288 it('should be initializable', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00001289 var vc = vcClass.create();
Nils Diewald7c8ced22015-04-15 19:21:00 +00001290 expect(vc.element().getAttribute('class')).toEqual('vc');
1291 expect(vc.root().element().getAttribute('class')).toEqual('doc unspecified');
1292
1293 // Not removable
1294 expect(vc.root().element().lastChild.children.length).toEqual(0);
1295 });
1296
1297 it('should be based on a doc', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00001298 var vc = vcClass.create().fromJson({
Akron712733a2018-04-05 18:17:47 +02001299 "@type" : "koral:doc",
1300 "key":"Titel",
1301 "value":"Baum",
1302 "match":"match:eq"
Nils Diewald7c8ced22015-04-15 19:21:00 +00001303 });
1304
1305 expect(vc.element().getAttribute('class')).toEqual('vc');
1306 expect(vc.root().element().getAttribute('class')).toEqual('doc');
1307 expect(vc.root().key()).toEqual('Titel');
1308 expect(vc.root().value()).toEqual('Baum');
1309 expect(vc.root().matchop()).toEqual('eq');
1310
1311 var docE = vc.root().element();
1312 expect(docE.children[0].firstChild.data).toEqual('Titel');
1313 expect(docE.children[1].firstChild.data).toEqual('eq');
1314 expect(docE.children[1].getAttribute('data-type')).toEqual('string');
1315 expect(docE.children[2].firstChild.data).toEqual('Baum');
1316 expect(docE.children[2].getAttribute('data-type')).toEqual('string');
1317 });
1318
1319 it('should be based on a docGroup', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00001320 var vc = vcClass.create().fromJson(simpleGroupFactory.create().toJson());
Nils Diewald7c8ced22015-04-15 19:21:00 +00001321
1322 expect(vc.element().getAttribute('class')).toEqual('vc');
1323 expect(vc.root().element().getAttribute('class')).toEqual('docGroup');
1324 expect(vc.root().operation()).toEqual('and');
1325
1326 var docGroup = vc.root();
1327
1328 var first = docGroup.getOperand(0);
1329 expect(first.key()).toEqual('author');
1330 expect(first.value()).toEqual('Max Birkendale');
1331 expect(first.matchop()).toEqual('eq');
1332
1333 var second = docGroup.getOperand(1);
1334 expect(second.key()).toEqual('pubDate');
1335 expect(second.value()).toEqual('2014-12-05');
1336 expect(second.matchop()).toEqual('eq');
1337 });
1338
Akronb19803c2018-08-16 16:39:42 +02001339 it('should be based on a docGroupRef', function () {
1340 var vc = vcClass.create().fromJson({
1341 "@type" : "koral:docGroupRef",
1342 "ref":"myCorpus"
1343 });
1344
Akronadab5e52018-08-20 13:50:53 +02001345 // iv class="doc groupref"><span class="key fixed">@referTo</span><span data-type="string" class="value">myCorpus</span>
1346 var vcE = vc.builder();
1347 expect(vcE.getAttribute('class')).toEqual('builder');
Akronb19803c2018-08-16 16:39:42 +02001348 expect(vcE.firstChild.tagName).toEqual('DIV');
1349 expect(vcE.firstChild.classList.contains('groupref')).toBeTruthy();
1350
1351 expect(vcE.firstChild.firstChild.tagName).toEqual('SPAN');
1352 expect(vcE.firstChild.firstChild.classList.contains('key')).toBeTruthy();
1353 expect(vcE.firstChild.firstChild.classList.contains('fixed')).toBeTruthy();
1354
Akron3ad46942018-08-22 16:47:14 +02001355 expect(vcE.firstChild.firstChild.textContent).toEqual("referTo");
Akronb19803c2018-08-16 16:39:42 +02001356
1357 expect(vcE.firstChild.children[1].tagName).toEqual('SPAN');
1358 expect(vcE.firstChild.children[1].classList.contains('value')).toBeTruthy();
1359 expect(vcE.firstChild.children[1].getAttribute('data-type')).toEqual('string');
1360 expect(vcE.firstChild.children[1].textContent).toEqual("myCorpus");
1361 });
Akron0f00b772020-12-02 17:32:13 +01001362
Nils Diewald7c8ced22015-04-15 19:21:00 +00001363 it('should be based on a nested docGroup', function () {
1364 var vc = nestedGroupFactory.create();
1365
Akronadab5e52018-08-20 13:50:53 +02001366 expect(vc.builder().getAttribute('class')).toEqual('builder');
1367 expect(vc.builder().firstChild.getAttribute('class')).toEqual('docGroup');
1368 expect(vc.builder().firstChild.children[0].getAttribute('class')).toEqual('doc');
1369 var dg = vc.builder().firstChild.children[1];
Nils Diewald7c8ced22015-04-15 19:21:00 +00001370 expect(dg.getAttribute('class')).toEqual('docGroup');
1371 expect(dg.children[0].getAttribute('class')).toEqual('doc');
1372 expect(dg.children[1].getAttribute('class')).toEqual('doc');
Akron0b489ad2018-02-02 16:49:32 +01001373 expect(dg.children[2].getAttribute('class')).toEqual('operators button-group');
Akronadab5e52018-08-20 13:50:53 +02001374 expect(vc.builder().firstChild.children[2].getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001375 });
1376
Akronb19803c2018-08-16 16:39:42 +02001377 it('should be based on a nested docGroupRef', function () {
1378 var vc = vcClass.create().fromJson({
1379 "@type" : "koral:docGroup",
1380 "operation" : "operation:and",
1381 "operands" : [{
1382 "@type" : "koral:docGroupRef",
1383 "ref":"myCorpus"
1384 },{
1385 "@type" : "koral:doc",
1386 "key":"Titel",
1387 "value":"Baum",
1388 "match":"match:eq"
1389 }]
1390 });
1391
1392 expect(vc._root.ldType()).toEqual("docGroup");
1393
1394 expect(vc.toQuery()).toEqual('referTo "myCorpus" & Titel = "Baum"');
1395 });
1396
Akron0f00b772020-12-02 17:32:13 +01001397 it('should accept an undefined KorAP.vc', function () {
1398 let temp = KorAP.vc;
1399 KorAP.vc = undefined;
1400 const vc = vcClass.create().fromJson({
1401 "@type" : "koral:docGroup",
1402 "operation" : "operation:and",
1403 "operands" : [{
1404 "@type" : "koral:docGroupRef",
1405 "ref":"myCorpus"
1406 },{
1407 "@type" : "koral:doc",
1408 "key":"Titel",
1409 "value":"Baum",
1410 "match":"match:eq"
1411 }]
1412 });
1413
1414 expect(vc._root.ldType()).toEqual("docGroup");
1415 expect(vc.toQuery()).toEqual('referTo "myCorpus" & Titel = "Baum"');
1416
1417 KorAP.vc = temp;
1418 });
Akronb19803c2018-08-16 16:39:42 +02001419
Nils Diewald7c8ced22015-04-15 19:21:00 +00001420 it('should be modifiable by deletion in flat docGroups', function () {
1421 var vc = flatGroupFactory.create();
1422 var docGroup = vc.root();
1423
1424 expect(docGroup.element().getAttribute('class')).toEqual('docGroup');
1425
1426 var doc = docGroup.getOperand(1);
1427 expect(doc.key()).toEqual("pubDate");
1428 expect(doc.value()).toEqual("2014-12-05");
1429
1430 // Remove operand 1
1431 expect(docGroup.delOperand(doc).update()).not.toBeUndefined();
Akron24aa0052020-11-10 11:00:34 +01001432 expect(doc._el).toEqual(undefined);
Nils Diewald7c8ced22015-04-15 19:21:00 +00001433
1434 doc = docGroup.getOperand(1);
1435 expect(doc.key()).toEqual("foo");
1436
1437 // Remove operand 1
1438 expect(docGroup.delOperand(doc).update()).not.toBeUndefined();
Akron24aa0052020-11-10 11:00:34 +01001439 expect(doc._el).toEqual(undefined);
Nils Diewald7c8ced22015-04-15 19:21:00 +00001440
1441 // Only one operand left ...
1442 expect(docGroup.getOperand(1)).toBeUndefined();
1443 // ... but there shouldn't be a group anymore at all!
1444 expect(docGroup.getOperand(0)).toBeUndefined();
1445
1446 var obj = vc.root();
1447 expect(obj.ldType()).toEqual("doc");
1448 expect(obj.key()).toEqual("pubDate");
1449 expect(obj.value()).toEqual("2014-05-12");
1450
1451 expect(obj.element().getAttribute('class')).toEqual('doc');
1452 });
1453
1454
1455 it('should be modifiable by deletion in nested docGroups (root case)', function () {
1456 var vc = nestedGroupFactory.create();
1457
1458 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001459 'author = "Max Birkendale" | (pubDate since 2014-05-12 & pubDate until 2014-12-05)'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001460 );
1461
1462 var docGroup = vc.root();
1463 expect(docGroup.ldType()).toEqual("docGroup");
1464 expect(docGroup.operation()).toEqual("or");
1465
1466 var doc = docGroup.getOperand(0);
1467 expect(doc.key()).toEqual("author");
1468 expect(doc.value()).toEqual("Max Birkendale");
1469
1470 docGroup = docGroup.getOperand(1);
1471 expect(docGroup.operation()).toEqual("and");
1472
1473 doc = docGroup.getOperand(0);
1474 expect(doc.key()).toEqual("pubDate");
1475 expect(doc.matchop()).toEqual("geq");
1476 expect(doc.value()).toEqual("2014-05-12");
1477 expect(doc.type()).toEqual("date");
1478
1479 doc = docGroup.getOperand(1);
1480 expect(doc.key()).toEqual("pubDate");
1481 expect(doc.matchop()).toEqual("leq");
1482 expect(doc.value()).toEqual("2014-12-05");
1483 expect(doc.type()).toEqual("date");
1484
1485 // Remove first operand so everything becomes root
1486 expect(
Akron712733a2018-04-05 18:17:47 +02001487 vc.root().delOperand(
1488 vc.root().getOperand(0)
1489 ).update().ldType()
Nils Diewald7c8ced22015-04-15 19:21:00 +00001490 ).toEqual("docGroup");
1491
1492 expect(vc.root().ldType()).toEqual("docGroup");
1493 expect(vc.root().operation()).toEqual("and");
1494 expect(vc.root().getOperand(0).ldType()).toEqual("doc");
1495
1496 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001497 'pubDate since 2014-05-12 & pubDate until 2014-12-05'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001498 );
1499 });
1500
1501 it('should be modifiable by deletion in nested docGroups (resolve group case)', function () {
1502 var vc = nestedGroupFactory.create();
1503
1504 // Get nested group
1505 var firstGroup = vc.root().getOperand(1);
1506 firstGroup.append(simpleGroupFactory.create({ "operation" : "operation:or" }));
1507
1508 // Structur is now:
1509 // or(doc, and(doc, doc, or(doc, doc)))
1510
1511 // Get nested or in and
1512 var orGroup = vc.root().getOperand(1).getOperand(2);
1513 expect(orGroup.ldType()).toEqual("docGroup");
1514 expect(orGroup.operation()).toEqual("or");
1515
1516 // Remove
1517 // Structur is now:
1518 // or(doc, and(doc, doc, doc)))
1519 expect(orGroup.delOperand(orGroup.getOperand(0)).update().operation()).toEqual("and");
1520 expect(vc.root().getOperand(1).operands().length).toEqual(3);
1521 });
1522
1523 it('should be modifiable by deletion in nested docGroups (identical group case)', function () {
1524 var vc = nestedGroupFactory.create();
1525
1526 // Get nested group
1527 var firstGroup = vc.root().getOperand(1);
1528 firstGroup.append(simpleGroupFactory.create({
Akron712733a2018-04-05 18:17:47 +02001529 "operation" : "operation:or"
Nils Diewald7c8ced22015-04-15 19:21:00 +00001530 }));
1531 var oldAuthor = firstGroup.getOperand(2).getOperand(0);
1532 oldAuthor.key("title");
1533 oldAuthor.value("Der Birnbaum");
1534
1535 // Structur is now:
1536 // or(doc, and(doc, doc, or(doc, doc)))
1537 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001538 'author = "Max Birkendale" | ' +
1539 '(pubDate since 2014-05-12 & ' +
1540 'pubDate until 2014-12-05 & ' +
1541 '(title = "Der Birnbaum" | ' +
1542 'pubDate in 2014-12-05))'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001543 );
1544
1545 var andGroup = vc.root().getOperand(1);
1546
1547 // Get leading docs in and
1548 var doc1 = andGroup.getOperand(0);
1549 expect(doc1.ldType()).toEqual("doc");
1550 expect(doc1.value()).toEqual("2014-05-12");
1551 var doc2 = andGroup.getOperand(1);
1552 expect(doc2.ldType()).toEqual("doc");
1553 expect(doc2.value()).toEqual("2014-12-05");
1554
1555 // Remove 2
1556 expect(
Akron712733a2018-04-05 18:17:47 +02001557 andGroup.delOperand(doc2).update().operation()
Nils Diewald7c8ced22015-04-15 19:21:00 +00001558 ).toEqual("and");
1559 // Structur is now:
1560 // or(doc, and(doc, or(doc, doc)))
1561
1562 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001563 'author = "Max Birkendale"' +
1564 ' | (pubDate since 2014-05-12 & ' +
1565 '(title = "Der Birnbaum" | pubDate in 2014-12-05))'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001566 );
1567
1568
1569 // Remove 1
1570 expect(andGroup.delOperand(doc1).update().operation()).toEqual("or");
1571 // Structur is now:
1572 // or(doc, doc, doc)
1573
1574 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001575 'author = "Max Birkendale" | title = "Der Birnbaum" | pubDate in 2014-12-05'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001576 );
1577 });
1578
1579 it('should be reducible to unspecification', function () {
1580 var vc = demoFactory.create();
1581
1582 expect(vc.toQuery()).toEqual(vc.root().toQuery());
1583 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001584 '(Titel = "Baum" & Veröffentlichungsort = "hihi" & ' +
1585 '(Titel = "Baum" | Veröffentlichungsort = "hihi")) ' +
1586 '| Untertitel ~ "huhu"');
Akrond141a362018-07-10 18:12:13 +02001587 expect(vc.root().element().lastChild.children[0].innerText).toEqual('and');
1588 expect(vc.root().element().lastChild.children[1].innerText).toEqual('×');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001589 expect(vc.root().delOperand(vc.root().getOperand(0)).update()).not.toBeUndefined();
Akron712733a2018-04-05 18:17:47 +02001590 expect(vc.toQuery()).toEqual('Untertitel ~ "huhu"');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001591
1592 var lc = vc.root().element().lastChild;
Akrond141a362018-07-10 18:12:13 +02001593 expect(lc.children[0].innerText).toEqual('and');
1594 expect(lc.children[1].innerText).toEqual('or');
1595 expect(lc.children[2].innerText).toEqual('×');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001596
1597 // Clean everything
1598 vc.clean();
1599 expect(vc.toQuery()).toEqual('');
1600 });
1601
1602 it('should flatten on import', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00001603 var vc = vcClass.create().fromJson({
Akron712733a2018-04-05 18:17:47 +02001604 "@type":"koral:docGroup",
1605 "operation":"operation:or",
1606 "operands":[
1607 {
1608 "@type":"koral:docGroup",
1609 "operation":"operation:or",
1610 "operands":[
Nils Diewald7c8ced22015-04-15 19:21:00 +00001611 {
Akron712733a2018-04-05 18:17:47 +02001612 "@type":"koral:doc",
1613 "key":"Titel",
1614 "value":"Baum",
1615 "match":"match:eq"
Nils Diewald7c8ced22015-04-15 19:21:00 +00001616 },
1617 {
Akron712733a2018-04-05 18:17:47 +02001618 "@type":"koral:doc",
1619 "key":"Veröffentlichungsort",
1620 "value":"hihi",
1621 "match":"match:eq"
Nils Diewald7c8ced22015-04-15 19:21:00 +00001622 },
1623 {
Akron712733a2018-04-05 18:17:47 +02001624 "@type":"koral:docGroup",
1625 "operation":"operation:or",
1626 "operands":[
1627 {
1628 "@type":"koral:doc",
1629 "key":"Titel",
1630 "value":"Baum",
1631 "match":"match:eq"
1632 },
1633 {
1634 "@type":"koral:doc",
1635 "key":"Veröffentlichungsort",
1636 "value":"hihi",
1637 "match":"match:eq"
1638 }
1639 ]
Nils Diewald7c8ced22015-04-15 19:21:00 +00001640 }
Akron712733a2018-04-05 18:17:47 +02001641 ]
1642 },
1643 {
1644 "@type":"koral:doc",
1645 "key":"Untertitel",
1646 "value":"huhu",
1647 "match":"match:contains"
1648 }
1649 ]
Nils Diewald7c8ced22015-04-15 19:21:00 +00001650 });
Nils Diewaldfda29d92015-01-22 17:28:01 +00001651
Nils Diewald7c8ced22015-04-15 19:21:00 +00001652 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001653 'Titel = "Baum" | Veröffentlichungsort = "hihi" | Untertitel ~ "huhu"'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001654 );
Nils Diewald86dad5b2015-01-28 15:09:07 +00001655 });
Akron1bdf5272018-07-24 18:51:30 +02001656
Akroncd42a142019-07-12 18:55:37 +02001657 it('should be deserializable from collection/corpus 1', function () {
Akron1bdf5272018-07-24 18:51:30 +02001658 var kq = {
1659 "matches":["..."],
1660 "collection":{
1661 "@type": "koral:docGroup",
1662 "operation": "operation:or",
1663 "operands": [{
1664 "@type": "koral:docGroup",
1665 "operation": "operation:and",
1666 "operands": [
1667 {
1668 "@type": "koral:doc",
1669 "key": "title",
1670 "match": "match:eq",
1671 "value": "Der Birnbaum",
1672 "type": "type:string"
1673 },
1674 {
1675 "@type": "koral:doc",
1676 "key": "pubPlace",
1677 "match": "match:eq",
1678 "value": "Mannheim",
1679 "type": "type:string"
1680 },
1681 {
1682 "@type": "koral:docGroup",
1683 "operation": "operation:or",
1684 "operands": [
1685 {
1686 "@type": "koral:doc",
1687 "key": "subTitle",
1688 "match": "match:eq",
1689 "value": "Aufzucht und Pflege",
1690 "type": "type:string"
1691 },
1692 {
1693 "@type": "koral:doc",
1694 "key": "subTitle",
1695 "match": "match:eq",
1696 "value": "Gedichte",
1697 "type": "type:string"
1698 }
1699 ]
1700 }
1701 ]
1702 },{
1703 "@type": "koral:doc",
1704 "key": "pubDate",
1705 "match": "match:geq",
1706 "value": "2015-03-05",
1707 "type": "type:date",
1708 "rewrites" : [{
1709 "@type" : "koral:rewrite",
1710 "operation" : "operation:modification",
1711 "src" : "querySerializer",
1712 "scope" : "tree"
1713 }]
1714 }]
1715 }
1716 };
1717
1718 var vc = vcClass.create().fromJson(kq["collection"]);
1719 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 +02001720
1721 kq["corpus"] = kq["collection"]
1722 delete kq["collection"]
1723
1724 vc = vcClass.create().fromJson(kq["corpus"]);
1725 expect(vc.toQuery()).toEqual('(title = "Der Birnbaum" & pubPlace = "Mannheim" & (subTitle = "Aufzucht und Pflege" | subTitle = "Gedichte")) | pubDate since 2015-03-05');
1726
Akron1bdf5272018-07-24 18:51:30 +02001727 });
1728
1729 it('should be deserializable from collection 2', function () {
1730 var kq = {
1731 "@context": "http://korap.ids-mannheim.de/ns/KoralQuery/v0.3/context.jsonld",
1732 "meta": {},
1733 "query": {
1734 "@type": "koral:token",
1735 "wrap": {
1736 "@type": "koral:term",
1737 "match": "match:eq",
1738 "layer": "orth",
1739 "key": "Baum",
1740 "foundry": "opennlp",
1741 "rewrites": [
1742 {
1743 "@type": "koral:rewrite",
1744 "src": "Kustvakt",
1745 "operation": "operation:injection",
1746 "scope": "foundry"
1747 }
1748 ]
1749 },
1750 "idn": "Baum_2227",
1751 "rewrites": [
1752 {
1753 "@type": "koral:rewrite",
1754 "src": "Kustvakt",
1755 "operation": "operation:injection",
1756 "scope": "idn"
1757 }
1758 ]
1759 },
1760 "collection": {
1761 "@type": "koral:docGroup",
1762 "operation": "operation:and",
1763 "operands": [
1764 {
1765 "@type": "koral:doc",
1766 "match": "match:eq",
1767 "type": "type:regex",
1768 "value": "CC-BY.*",
1769 "key": "availability"
1770 },
1771 {
1772 "@type": "koral:doc",
1773 "match": "match:eq",
1774 "type":"type:text",
1775 "value": "Goethe",
1776 "key": "author"
1777 }
1778 ],
1779 "rewrites": [
1780 {
1781 "@type": "koral:rewrite",
1782 "src": "Kustvakt",
1783 "operation": "operation:insertion",
1784 "scope": "availability(FREE)"
1785 }
1786 ]
1787 },
1788 "matches": []
1789 };
1790
1791 var vc = vcClass.create().fromJson(kq["collection"]);
1792 expect(vc.toQuery()).toEqual('availability = /CC-BY.*/ & author = "Goethe"');
1793 });
Nils Diewald86dad5b2015-01-28 15:09:07 +00001794
Akroncd42a142019-07-12 18:55:37 +02001795
Akron8a670162018-08-28 10:09:13 +02001796 it('shouldn\'t be deserializable from collection with unknown type', function () {
1797 var kq = {
1798 "@type" : "koral:doc",
1799 "match": "match:eq",
1800 "type":"type:failure",
1801 "value": "Goethe",
1802 "key": "author"
1803 };
Akron1bdf5272018-07-24 18:51:30 +02001804
Akron8a670162018-08-28 10:09:13 +02001805 expect(function () {
1806 vcClass.create().fromJson(kq)
1807 }).toThrow(new Error("Unknown value type: string"));
1808 });
1809
1810 it('should return a name', function () {
1811 var vc = vcClass.create();
1812 expect(vc.getName()).toEqual(KorAP.Locale.VC_allCorpora);
1813
1814 vc = vcClass.create().fromJson({"@type" : "koral:docGroupRef", "ref" : "DeReKo"});
1815 expect(vc.getName()).toEqual("DeReKo");
1816
1817 vc = vcClass.create().fromJson({"@type" : "koral:doc", "key" : "author", "value" : "Peter"});
1818 expect(vc.getName()).toEqual(KorAP.Locale.VC_oneCollection);
1819 });
Akrond2474aa2018-08-28 12:06:27 +02001820
1821 it('should check for rewrites', function () {
1822
1823 var vc = vcClass.create().fromJson({
1824 "@type" : "koral:doc",
1825 "key" : "author",
1826 "value" : "Goethe",
1827 "rewrites" : [{
1828 "@type" : "koral:rewrite",
1829 "operation" : "operation:modification",
1830 "src" : "querySerializer",
1831 "scope" : "value"
1832 }]
1833 });
1834 expect(vc.wasRewritten()).toBeTruthy();
1835
1836 var nested = {
1837 "@type" : "koral:docGroup",
1838 "operation" : "operation:or",
1839 "operands" : [
1840 {
1841 "@type" : "koral:doc",
1842 "key" : "author",
1843 "value" : "Goethe"
1844 },
1845 {
1846 "@type" : "koral:docGroup",
1847 "operation" : "operation:and",
1848 "operands" : [
1849 {
1850 "@type": "koral:doc",
1851 "key" : "author",
1852 "value" : "Schiller"
1853 },
1854 {
1855 "@type": "koral:doc",
1856 "key" : "author",
1857 "value" : "Fontane"
1858 }
1859 ]
1860 }
1861 ]
1862 };
1863 vc = vcClass.create().fromJson(nested);
1864 expect(vc.wasRewritten()).toBe(false);
1865
1866 nested["operands"][1]["operands"][1]["rewrites"] = [{
1867 "@type" : "koral:rewrite",
1868 "operation" : "operation:modification",
1869 "src" : "querySerializer",
1870 "scope" : "tree"
1871 }];
1872 vc = vcClass.create().fromJson(nested);
1873 expect(vc.wasRewritten()).toBeTruthy();
1874 });
Akron4feec9d2018-11-20 17:00:50 +01001875
1876 it('should add document at virtual corpus', function () {
1877 vc = vcClass.create();
1878 expect(vc.toQuery()).toEqual("");
1879
1880 let doc = docClass.create();
1881 doc.key("author");
1882 doc.type("string");
1883 doc.matchop("eq");
1884 doc.value("Goethe");
1885 expect(doc.toQuery()).toEqual('author = "Goethe"');
1886
1887 expect(vc.element().firstChild.children.length).toEqual(1);
1888 expect(vc.element().firstChild.firstChild.classList.contains("unspecified")).toBeTruthy();
1889
1890 vc.addRequired(doc);
1891 expect(vc.toQuery()).toEqual('author = "Goethe"');
1892
1893 expect(vc.element().firstChild.children.length).toEqual(1);
1894 expect(vc.element().firstChild.firstChild.classList.contains("doc")).toBeTruthy();
1895
1896 // Add as 'and' to doc
1897 let doc2 = docClass.create();
1898 doc2.key("author");
1899 doc2.type("string");
1900 doc2.matchop("eq");
1901 doc2.value("Schiller");
1902 vc.addRequired(doc2);
1903 expect(vc.toQuery()).toEqual('author = "Goethe" & author = "Schiller"');
1904
1905 expect(vc.element().firstChild.firstChild.classList.contains("docGroup")).toBeTruthy();
1906 expect(vc.element().firstChild.firstChild.children[0].classList.contains("doc")).toBeTruthy();
1907 expect(vc.element().firstChild.firstChild.children[1].classList.contains("doc")).toBeTruthy();
1908
1909
1910 // Add as 'and' to 'and'-docGroup
1911 let doc3 = docClass.create();
1912 doc3.key("author");
1913 doc3.type("string");
1914 doc3.matchop("eq");
1915 doc3.value("Fontane");
1916 vc.addRequired(doc3);
1917 expect(vc.toQuery()).toEqual('author = "Goethe" & author = "Schiller" & author = "Fontane"');
1918
1919 expect(vc.element().firstChild.firstChild.classList.contains("docGroup")).toBeTruthy();
1920 expect(vc.element().firstChild.firstChild.children[0].classList.contains("doc")).toBeTruthy();
1921 expect(vc.element().firstChild.firstChild.children[1].classList.contains("doc")).toBeTruthy();
1922 expect(vc.element().firstChild.firstChild.children[2].classList.contains("doc")).toBeTruthy();
1923
1924 // Add as 'and' to 'or'-docGroup
1925 vc = vcClass.create().fromJson({
1926 "@type" : 'koral:docGroup',
1927 'operation' : 'operation:or',
1928 'operands' : [
1929 {
1930 '@type' : 'koral:doc',
1931 'key' : 'title',
1932 'value' : 'Hello World!'
1933 },
1934 {
1935 '@type' : 'koral:doc',
1936 'key' : 'foo',
1937 'value' : 'bar'
1938 }
1939 ]
1940 });
1941 expect(vc.toQuery()).toEqual('title = "Hello World!" | foo = "bar"');
1942
1943 let doc4 = docClass.create();
1944 doc4.key("author");
1945 doc4.type("string");
1946 doc4.matchop("eq");
1947 doc4.value("Fontane");
1948 vc.addRequired(doc4);
1949 expect(vc.toQuery()).toEqual('(title = "Hello World!" | foo = "bar") & author = "Fontane"');
1950
1951 // Add as 'and' to 'or'-docGroup
1952 vc = vcClass.create().fromJson({
1953 "@type" : "koral:docGroupRef",
1954 "ref" : "@max/myCorpus"
1955 })
1956 let doc5 = docClass.create();
1957 doc5.key("author");
1958 doc5.type("string");
1959 doc5.matchop("eq");
1960 doc5.value("Goethe");
1961 expect(doc5.toQuery()).toEqual('author = "Goethe"');
1962 vc.addRequired(doc5);
1963 expect(vc.toQuery()).toEqual('referTo "@max/myCorpus" & author = "Goethe"');
1964 });
Akron13af2f42019-07-25 15:06:21 +02001965
1966 it('should be replaceble via JSON', function () {
1967 let vc = KorAP.vc = vcClass.create().fromJson({
1968 "@type" : 'koral:docGroup',
1969 'operation' : 'operation:or',
1970 'operands' : [
1971 {
1972 '@type' : 'koral:doc',
1973 'key' : 'title',
1974 'value' : 'Hello World!'
1975 },
1976 {
1977 '@type' : 'koral:doc',
1978 'key' : 'foo',
1979 'value' : 'bar'
1980 }
1981 ]
1982 });
1983
1984 expect(vc.toQuery()).toEqual('title = "Hello World!" | foo = "bar"')
1985
1986 let e = vc.element();
1987 expect(e.firstChild.firstChild.firstChild.children[0].textContent).toEqual("title");
1988 expect(e.firstChild.firstChild.firstChild.children[2].textContent).toEqual("Hello World!");
1989
1990 vc.fromJson({
1991 '@type' : 'koral:doc',
1992 'key' : 'foo',
1993 'value' : 'bar'
1994 });
1995
1996 expect(vc.toQuery()).toEqual('foo = "bar"');
1997 e = vc.element();
1998 expect(e.firstChild.firstChild.children[0].textContent).toEqual("foo");
1999 expect(e.firstChild.firstChild.children[2].textContent).toEqual("bar");
2000 })
Akron1bdf5272018-07-24 18:51:30 +02002001 });
2002
2003
Akron88d237e2020-10-21 08:05:18 +02002004 describe('KorAP.VC.Operators', function () {
Nils Diewald7c8ced22015-04-15 19:21:00 +00002005 it('should be initializable', function () {
2006 var op = operatorsClass.create(true, false, false);
2007 expect(op.and()).toBeTruthy();
2008 expect(op.or()).not.toBeTruthy();
2009 expect(op.del()).not.toBeTruthy();
2010
2011 op.and(false);
2012 expect(op.and()).not.toBeTruthy();
2013 expect(op.or()).not.toBeTruthy();
2014 expect(op.del()).not.toBeTruthy();
2015
2016 op.or(true);
2017 op.del(true);
2018 expect(op.and()).not.toBeTruthy();
2019 expect(op.or()).toBeTruthy();
2020 expect(op.del()).toBeTruthy();
2021
Akrond141a362018-07-10 18:12:13 +02002022 var e = op.update();
Akron0b489ad2018-02-02 16:49:32 +01002023 expect(e.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +00002024 expect(e.children[0].getAttribute('class')).toEqual('or');
Akrond141a362018-07-10 18:12:13 +02002025 expect(e.children[0].innerText).toEqual('or');
Nils Diewald7c8ced22015-04-15 19:21:00 +00002026 expect(e.children[1].getAttribute('class')).toEqual('delete');
Akrond141a362018-07-10 18:12:13 +02002027 expect(e.children[1].innerText).toEqual('×');
Nils Diewald7c8ced22015-04-15 19:21:00 +00002028
2029 op.and(true);
2030 op.del(false);
Akrond141a362018-07-10 18:12:13 +02002031 e = op.update();
Nils Diewald7c8ced22015-04-15 19:21:00 +00002032
Akron0b489ad2018-02-02 16:49:32 +01002033 expect(e.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +00002034 expect(e.children[0].getAttribute('class')).toEqual('and');
Akrond141a362018-07-10 18:12:13 +02002035 expect(e.children[0].innerText).toEqual('and');
Nils Diewald7c8ced22015-04-15 19:21:00 +00002036 expect(e.children[1].getAttribute('class')).toEqual('or');
Akrond141a362018-07-10 18:12:13 +02002037 expect(e.children[1].innerText).toEqual('or');
Nils Diewald7c8ced22015-04-15 19:21:00 +00002038 });
2039 });
2040
Akron88d237e2020-10-21 08:05:18 +02002041 describe('KorAP.VC._delete (event)', function () {
Nils Diewald7c8ced22015-04-15 19:21:00 +00002042 var complexVCFactory = buildFactory(vcClass,{
2043 "@type": 'koral:docGroup',
2044 'operation' : 'operation:and',
2045 'operands' : [
Akron712733a2018-04-05 18:17:47 +02002046 {
2047 "@type": 'koral:doc',
2048 "key": 'pubDate',
2049 "match": 'match:eq',
2050 "value": '2014-12-05',
2051 "type": 'type:date'
2052 },
2053 {
2054 "@type" : 'koral:docGroup',
2055 'operation' : 'operation:or',
2056 'operands' : [
2057 {
2058 '@type' : 'koral:doc',
2059 'key' : 'title',
2060 'value' : 'Hello World!'
2061 },
2062 {
2063 '@type' : 'koral:doc',
2064 'key' : 'foo',
2065 'value' : 'bar'
2066 }
2067 ]
2068 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00002069 ]
2070 });
2071
2072 it('should clean on root docs', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00002073 var vc = vcClass.create().fromJson({
Akron712733a2018-04-05 18:17:47 +02002074 "@type": 'koral:doc',
2075 "key": 'pubDate',
2076 "match": 'match:eq',
2077 "value": '2014-12-05',
2078 "type": 'type:date'
Nils Diewald86dad5b2015-01-28 15:09:07 +00002079 });
Nils Diewald7c8ced22015-04-15 19:21:00 +00002080 expect(vc.root().toQuery()).toEqual('pubDate in 2014-12-05');
Akron0b489ad2018-02-02 16:49:32 +01002081 expect(vc.root().element().lastChild.getAttribute('class')).toEqual('operators button-group');
Nils Diewald86dad5b2015-01-28 15:09:07 +00002082
Nils Diewald7c8ced22015-04-15 19:21:00 +00002083 // Clean with delete from root
2084 expect(vc.root().element().lastChild.lastChild.getAttribute('class')).toEqual('delete');
2085 _delOn(vc.root());
2086 expect(vc.root().toQuery()).toEqual('');
Akronebc96662018-08-29 17:36:20 +02002087 expect(vc.root().element().lastChild.lastChild.data).toEqual(KorAP.Locale.EMPTY);
2088 expect(vc.root().element().classList.contains('unspecified')).toEqual(true);
Nils Diewald7c8ced22015-04-15 19:21:00 +00002089 });
Nils Diewald86dad5b2015-01-28 15:09:07 +00002090
Nils Diewald7c8ced22015-04-15 19:21:00 +00002091 it('should remove on nested docs', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00002092 var vc = vcClass.create().fromJson(
Akron712733a2018-04-05 18:17:47 +02002093 {
2094 "@type": 'koral:docGroup',
2095 'operation' : 'operation:and',
2096 'operands' : [
2097 {
2098 "@type": 'koral:doc',
2099 "key": 'pubDate',
2100 "match": 'match:eq',
2101 "value": '2014-12-05',
2102 "type": 'type:date'
2103 },
2104 {
2105 "@type" : 'koral:doc',
2106 'key' : 'foo',
2107 'value' : 'bar'
2108 }
2109 ]
2110 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00002111 );
2112
2113 // Delete with direct element access
2114 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar"');
2115 _delOn(vc.root().getOperand(0));
2116
2117 expect(vc.toQuery()).toEqual('foo = "bar"');
2118 expect(vc.root().ldType()).toEqual('doc');
2119 });
2120
2121 it('should clean on doc groups', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00002122 var vc = vcClass.create().fromJson(
Akron712733a2018-04-05 18:17:47 +02002123 {
2124 "@type": 'koral:docGroup',
2125 'operation' : 'operation:and',
2126 'operands' : [
2127 {
2128 "@type": 'koral:doc',
2129 "key": 'pubDate',
2130 "match": 'match:eq',
2131 "value": '2014-12-05',
2132 "type": 'type:date'
2133 },
2134 {
2135 "@type" : 'koral:doc',
2136 'key' : 'foo',
2137 'value' : 'bar'
2138 }
2139 ]
2140 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00002141 );
2142
2143 // Cleanwith direct element access
2144 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar"');
2145 _delOn(vc.root());
2146 expect(vc.toQuery()).toEqual('');
2147 expect(vc.root().ldType()).toEqual('non');
2148 });
2149
2150 it('should remove on nested doc groups (case of ungrouping 1)', function () {
2151 var vc = complexVCFactory.create();
2152
2153 // Delete with direct element access
2154 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02002155 'pubDate in 2014-12-05 & (title = "Hello World!" | foo = "bar")'
Nils Diewald7c8ced22015-04-15 19:21:00 +00002156 );
2157
2158 // Remove hello world:
2159 _delOn(vc.root().getOperand(1).getOperand(0));
2160 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar"');
2161 expect(vc.root().ldType()).toEqual('docGroup');
2162 });
2163
2164 it('should remove on nested doc groups (case of ungrouping 2)', function () {
2165 var vc = complexVCFactory.create();
2166
2167 // Delete with direct element access
2168 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02002169 'pubDate in 2014-12-05 & (title = "Hello World!" | foo = "bar")'
Nils Diewald7c8ced22015-04-15 19:21:00 +00002170 );
2171
2172 // Remove bar
2173 _delOn(vc.root().getOperand(1).getOperand(1));
2174 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & title = "Hello World!"');
2175 expect(vc.root().ldType()).toEqual('docGroup');
2176 expect(vc.root().operation()).toEqual('and');
2177 });
2178
2179 it('should remove on nested doc groups (case of root changing)', function () {
2180 var vc = complexVCFactory.create();
2181
2182 // Delete with direct element access
2183 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02002184 'pubDate in 2014-12-05 & ' +
2185 '(title = "Hello World!" | foo = "bar")'
Nils Diewald7c8ced22015-04-15 19:21:00 +00002186 );
2187
2188 // Remove bar
2189 _delOn(vc.root().getOperand(0));
2190 expect(vc.toQuery()).toEqual('title = "Hello World!" | foo = "bar"');
2191 expect(vc.root().ldType()).toEqual('docGroup');
2192 expect(vc.root().operation()).toEqual('or');
2193 });
2194
2195 it('should remove on nested doc groups (list flattening)', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00002196 var vc = vcClass.create().fromJson(
Akron712733a2018-04-05 18:17:47 +02002197 {
2198 "@type": 'koral:docGroup',
2199 'operation' : 'operation:or',
2200 'operands' : [
2201 {
2202 "@type": 'koral:doc',
2203 "key": 'pubDate',
2204 "match": 'match:eq',
2205 "value": '2014-12-05',
2206 "type": 'type:date'
2207 },
2208 {
2209 "@type" : 'koral:doc',
2210 'key' : 'foo',
2211 'value' : 'bar'
2212 },
2213 {
2214 "@type": 'koral:docGroup',
2215 'operation' : 'operation:and',
2216 'operands' : [
2217 {
2218 "@type": 'koral:doc',
2219 "key": 'pubDate',
2220 "match": 'match:eq',
2221 "value": '2014-12-05',
2222 "type": 'type:date'
2223 },
2224 {
2225 "@type" : 'koral:docGroup',
2226 'operation' : 'operation:or',
2227 'operands' : [
2228 {
2229 '@type' : 'koral:doc',
2230 'key' : 'title',
2231 'value' : 'Hello World!'
2232 },
2233 {
2234 '@type' : 'koral:doc',
2235 'key' : 'yeah',
2236 'value' : 'juhu'
2237 }
2238 ]
2239 }
2240 ]
2241 }
2242 ]
2243 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00002244 );
2245
2246 // Delete with direct element access
2247 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02002248 'pubDate in 2014-12-05 | foo = "bar" | ' +
2249 '(pubDate in 2014-12-05 & ' +
2250 '(title = "Hello World!" | yeah = "juhu"))'
Nils Diewald7c8ced22015-04-15 19:21:00 +00002251 );
2252
2253 expect(vc.root().ldType()).toEqual('docGroup');
2254 expect(vc.root().operation()).toEqual('or');
2255
2256 // Operands and operators
Akronadab5e52018-08-20 13:50:53 +02002257 expect(vc.builder().firstChild.children.length).toEqual(4);
2258 expect(vc.builder().firstChild.lastChild.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +00002259
2260 // Remove inner group and flatten
2261 _delOn(vc.root().getOperand(2).getOperand(0));
2262
2263 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02002264 'pubDate in 2014-12-05 | foo = "bar" | title = "Hello World!" | yeah = "juhu"'
Nils Diewald7c8ced22015-04-15 19:21:00 +00002265 );
2266 expect(vc.root().ldType()).toEqual('docGroup');
2267 expect(vc.root().operation()).toEqual('or');
2268
2269 // Operands and operators
Akronadab5e52018-08-20 13:50:53 +02002270 expect(vc.builder().firstChild.children.length).toEqual(5);
2271 expect(vc.builder().firstChild.lastChild.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +00002272 });
2273 });
2274
Akron88d237e2020-10-21 08:05:18 +02002275 describe('KorAP.VC._add (event)', function () {
Nils Diewald7c8ced22015-04-15 19:21:00 +00002276 var complexVCFactory = buildFactory(vcClass,{
2277 "@type": 'koral:docGroup',
2278 'operation' : 'operation:and',
2279 'operands' : [
Akron712733a2018-04-05 18:17:47 +02002280 {
2281 "@type": 'koral:doc',
2282 "key": 'pubDate',
2283 "match": 'match:eq',
2284 "value": '2014-12-05',
2285 "type": 'type:date'
2286 },
2287 {
2288 "@type" : 'koral:docGroup',
2289 'operation' : 'operation:or',
2290 'operands' : [
2291 {
2292 '@type' : 'koral:doc',
2293 'key' : 'title',
2294 'value' : 'Hello World!'
2295 },
2296 {
2297 '@type' : 'koral:doc',
2298 'key' : 'foo',
2299 'value' : 'bar'
2300 }
2301 ]
2302 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00002303 ]
2304 });
2305
2306 it('should add new unspecified doc with "and"', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00002307 var vc = vcClass.create().fromJson(
Akron712733a2018-04-05 18:17:47 +02002308 {
2309 "@type": 'koral:docGroup',
2310 'operation' : 'operation:and',
2311 'operands' : [
2312 {
2313 "@type": 'koral:doc',
2314 "key": 'pubDate',
2315 "match": 'match:eq',
2316 "value": '2014-12-05',
2317 "type": 'type:date'
2318 },
2319 {
2320 "@type" : 'koral:doc',
2321 'key' : 'foo',
2322 'value' : 'bar'
Akronb19803c2018-08-16 16:39:42 +02002323 },
2324 {
2325 "@type" : "koral:docGroupRef",
2326 "ref" : "myCorpus"
Akron712733a2018-04-05 18:17:47 +02002327 }
2328 ]
2329 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00002330 );
2331
Akronb19803c2018-08-16 16:39:42 +02002332 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar" & referTo "myCorpus"');
Nils Diewald7c8ced22015-04-15 19:21:00 +00002333
Akronadab5e52018-08-20 13:50:53 +02002334 var fc = vc.builder().firstChild;
Nils Diewald7c8ced22015-04-15 19:21:00 +00002335 expect(fc.getAttribute('data-operation')).toEqual('and');
Akronb19803c2018-08-16 16:39:42 +02002336 expect(fc.children.length).toEqual(4);
Akron0b489ad2018-02-02 16:49:32 +01002337 expect(fc.lastChild.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +00002338 expect(fc.children[0].getAttribute('class')).toEqual('doc');
2339 expect(fc.children[1].getAttribute('class')).toEqual('doc');
Akronb19803c2018-08-16 16:39:42 +02002340 expect(fc.children[2].getAttribute('class')).toEqual('doc groupref');
Nils Diewald7c8ced22015-04-15 19:21:00 +00002341
2342 // add with 'and' in the middle
2343 _andOn(vc.root().getOperand(0));
Akronb19803c2018-08-16 16:39:42 +02002344 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar" & referTo "myCorpus"');
Nils Diewald7c8ced22015-04-15 19:21:00 +00002345
Akronadab5e52018-08-20 13:50:53 +02002346 fc = vc.builder().firstChild;
Nils Diewald7c8ced22015-04-15 19:21:00 +00002347 expect(fc.getAttribute('data-operation')).toEqual('and');
Akronb19803c2018-08-16 16:39:42 +02002348 expect(fc.children.length).toEqual(5);
Akron0b489ad2018-02-02 16:49:32 +01002349 expect(fc.lastChild.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +00002350
2351 expect(fc.children[0].getAttribute('class')).toEqual('doc');
2352 expect(fc.children[1].getAttribute('class')).toEqual('doc unspecified');
2353 expect(fc.children[2].getAttribute('class')).toEqual('doc');
Akronb19803c2018-08-16 16:39:42 +02002354 expect(fc.children[3].getAttribute('class')).toEqual('doc groupref');
2355 expect(fc.children[4].classList.contains('button-group')).toBeTruthy();
2356 expect(fc.children.length).toEqual(5);
2357
2358 _andOn(vc.root().getOperand(3));
2359 expect(fc.children[0].getAttribute('class')).toEqual('doc');
2360 expect(fc.children[1].getAttribute('class')).toEqual('doc unspecified');
2361 expect(fc.children[2].getAttribute('class')).toEqual('doc');
2362 expect(fc.children[3].getAttribute('class')).toEqual('doc groupref');
2363 expect(fc.children[4].getAttribute('class')).toEqual('doc unspecified');
2364 expect(fc.children[5].classList.contains('button-group')).toBeTruthy();
2365 expect(fc.children.length).toEqual(6);
2366
Nils Diewald7c8ced22015-04-15 19:21:00 +00002367 });
2368
Akronb19803c2018-08-16 16:39:42 +02002369
Nils Diewald7c8ced22015-04-15 19:21:00 +00002370 it('should add new unspecified doc with "or"', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00002371 var vc = vcClass.create().fromJson(
Akron712733a2018-04-05 18:17:47 +02002372 {
2373 "@type": 'koral:docGroup',
2374 'operation' : 'operation:and',
2375 'operands' : [
2376 {
2377 "@type": 'koral:doc',
2378 "key": 'pubDate',
2379 "match": 'match:eq',
2380 "value": '2014-12-05',
2381 "type": 'type:date'
2382 },
2383 {
2384 "@type" : 'koral:doc',
2385 'key' : 'foo',
2386 'value' : 'bar'
Akronb19803c2018-08-16 16:39:42 +02002387 },
2388 {
2389 "@type" : "koral:docGroupRef",
2390 "ref" : "myCorpus"
Akron712733a2018-04-05 18:17:47 +02002391 }
2392 ]
2393 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00002394 );
2395
Akronb19803c2018-08-16 16:39:42 +02002396 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar" & referTo "myCorpus"');
Nils Diewald7c8ced22015-04-15 19:21:00 +00002397
Akronadab5e52018-08-20 13:50:53 +02002398 var fc = vc.builder().firstChild;
Akronb19803c2018-08-16 16:39:42 +02002399 expect(fc.children.length).toEqual(4);
Akron0b489ad2018-02-02 16:49:32 +01002400 expect(fc.lastChild.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +00002401 expect(fc.children[0].getAttribute('class')).toEqual('doc');
2402 expect(fc.children[1].getAttribute('class')).toEqual('doc');
Akronb19803c2018-08-16 16:39:42 +02002403 expect(fc.children[2].getAttribute('class')).toEqual('doc groupref');
Nils Diewald7c8ced22015-04-15 19:21:00 +00002404
2405 // add with 'or' in the middle
2406 _orOn(vc.root().getOperand(0));
Akronb19803c2018-08-16 16:39:42 +02002407 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar" & referTo "myCorpus"');
Akronadab5e52018-08-20 13:50:53 +02002408 fc = vc.builder().firstChild;
Nils Diewald7c8ced22015-04-15 19:21:00 +00002409
2410 expect(fc.getAttribute('data-operation')).toEqual('and');
Akronb19803c2018-08-16 16:39:42 +02002411 expect(fc.children.length).toEqual(4);
Nils Diewald7c8ced22015-04-15 19:21:00 +00002412 expect(fc.children[0].getAttribute('class')).toEqual('docGroup');
2413 expect(fc.children[0].getAttribute('data-operation')).toEqual('or');
2414 expect(fc.children[1].getAttribute('class')).toEqual('doc');
Akronb19803c2018-08-16 16:39:42 +02002415 expect(fc.children[2].getAttribute('class')).toEqual('doc groupref');
2416 expect(fc.children[3].getAttribute('class')).toEqual('operators button-group');
Akron0b489ad2018-02-02 16:49:32 +01002417 expect(fc.lastChild.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +00002418
Akronadab5e52018-08-20 13:50:53 +02002419 fc = vc.builder().firstChild.firstChild;
Nils Diewald7c8ced22015-04-15 19:21:00 +00002420 expect(fc.children.length).toEqual(3);
2421 expect(fc.children[0].getAttribute('class')).toEqual('doc');
2422 expect(fc.children[1].getAttribute('class')).toEqual('doc unspecified');
Akron0b489ad2018-02-02 16:49:32 +01002423 expect(fc.children[2].getAttribute('class')).toEqual('operators button-group');
2424 expect(fc.lastChild.getAttribute('class')).toEqual('operators button-group');
Akronb19803c2018-08-16 16:39:42 +02002425
2426 _orOn(vc.root().getOperand(2));
Akronadab5e52018-08-20 13:50:53 +02002427 fc = vc.builder().firstChild;
Akronb19803c2018-08-16 16:39:42 +02002428 expect(fc.children.length).toEqual(4);
2429
2430 expect(fc.children[0].getAttribute('class')).toEqual('docGroup');
2431 expect(fc.children[1].getAttribute('class')).toEqual('doc');
2432 expect(fc.children[2].getAttribute('class')).toEqual('docGroup');
2433 expect(fc.children[3].getAttribute('class')).toEqual('operators button-group');
2434
Akronadab5e52018-08-20 13:50:53 +02002435 fc = vc.builder().firstChild.children[2];
Akronb19803c2018-08-16 16:39:42 +02002436 expect(fc.children[0].getAttribute('class')).toEqual('doc groupref');
2437 expect(fc.children[1].getAttribute('class')).toEqual('doc unspecified');
2438 expect(fc.children[2].getAttribute('class')).toEqual('operators button-group');
2439 expect(fc.lastChild.getAttribute('class')).toEqual('operators button-group');
2440
Nils Diewald7c8ced22015-04-15 19:21:00 +00002441 });
2442
2443 it('should add new unspecified doc with "and" before group', function () {
2444 var vc = demoFactory.create();
2445
2446 // Wrap with direct element access
2447 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02002448 '(Titel = "Baum" & ' +
2449 'Veröffentlichungsort = "hihi" & ' +
2450 '(Titel = "Baum" | ' +
2451 'Veröffentlichungsort = "hihi")) | ' +
2452 'Untertitel ~ "huhu"'
Nils Diewald7c8ced22015-04-15 19:21:00 +00002453 );
2454
2455 expect(vc.root().getOperand(0).ldType()).toEqual('docGroup');
2456 expect(vc.root().getOperand(0).operation()).toEqual('and');
2457 expect(vc.root().getOperand(0).operands().length).toEqual(3);
2458
2459 // Add unspecified on the second doc
2460 var secDoc = vc.root().getOperand(0).getOperand(1);
2461 expect(secDoc.value()).toEqual('hihi');
2462
2463 // Add
2464 _andOn(secDoc);
2465
2466 var fo = vc.root().getOperand(0);
2467
2468 expect(fo.ldType()).toEqual('docGroup');
2469 expect(fo.operation()).toEqual('and');
2470 expect(fo.operands().length).toEqual(4);
2471
2472 expect(fo.getOperand(0).ldType()).toEqual('doc');
2473 expect(fo.getOperand(1).ldType()).toEqual('doc');
2474 expect(fo.getOperand(2).ldType()).toEqual('non');
2475 expect(fo.getOperand(3).ldType()).toEqual('docGroup');
2476 });
2477
2478
2479 it('should remove a doc with an unspecified doc in a nested group', function () {
2480 var vc = demoFactory.create();
2481
2482 // Wrap with direct element access
2483 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02002484 '(Titel = "Baum" & Veröffentlichungsort = "hihi" & (Titel = "Baum" | Veröffentlichungsort = "hihi")) | Untertitel ~ "huhu"'
Nils Diewald7c8ced22015-04-15 19:21:00 +00002485 );
2486
2487 var fo = vc.root().getOperand(0).getOperand(0);
2488 expect(fo.key()).toEqual('Titel');
2489 expect(fo.value()).toEqual('Baum');
2490
2491 // Add unspecified on the root group
2492 _orOn(fo);
2493
2494 fo = vc.root().getOperand(0).getOperand(0);
2495
2496 expect(fo.operation()).toEqual('or');
2497 expect(fo.getOperand(0).ldType()).toEqual('doc');
2498 expect(fo.getOperand(1).ldType()).toEqual('non');
2499
2500 // Delete document
2501 _delOn(fo.getOperand(0));
2502
2503 // The operand is now non
2504 expect(vc.root().getOperand(0).getOperand(0).ldType()).toEqual('non');
2505 expect(vc.root().getOperand(0).getOperand(1).ldType()).toEqual('doc');
2506 expect(vc.root().getOperand(0).getOperand(2).ldType()).toEqual('docGroup');
2507 });
2508
2509
Akron712733a2018-04-05 18:17:47 +02002510 it('should remove an unspecified doc with a doc in a nested group', function () {
Nils Diewald7c8ced22015-04-15 19:21:00 +00002511 var vc = demoFactory.create();
2512
2513 // Wrap with direct element access
2514 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02002515 '(Titel = "Baum" & ' +
2516 'Veröffentlichungsort = "hihi" & ' +
2517 '(Titel = "Baum" ' +
2518 '| Veröffentlichungsort = "hihi")) | ' +
2519 'Untertitel ~ "huhu"'
Nils Diewald7c8ced22015-04-15 19:21:00 +00002520 );
2521
2522 var fo = vc.root().getOperand(0).getOperand(0);
2523 expect(fo.key()).toEqual('Titel');
2524 expect(fo.value()).toEqual('Baum');
2525
2526 // Add unspecified on the root group
2527 _orOn(fo);
2528
2529 fo = vc.root().getOperand(0).getOperand(0);
2530
2531 expect(fo.operation()).toEqual('or');
2532 expect(fo.getOperand(0).ldType()).toEqual('doc');
2533 expect(fo.getOperand(1).ldType()).toEqual('non');
2534
2535 // Delete unspecified doc
2536 _delOn(fo.getOperand(1));
2537
2538 // The operand is now non
2539 fo = vc.root().getOperand(0);
2540 expect(fo.getOperand(0).ldType()).toEqual('doc');
2541 expect(fo.getOperand(0).key()).toEqual('Titel');
2542 expect(fo.getOperand(0).value()).toEqual('Baum');
2543 expect(fo.getOperand(1).ldType()).toEqual('doc');
2544 expect(fo.getOperand(2).ldType()).toEqual('docGroup');
2545 });
2546
2547
2548 it('should add on parent group (case "and")', function () {
2549 var vc = complexVCFactory.create();
2550
2551 // Wrap with direct element access
2552 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02002553 'pubDate in 2014-12-05 & (title = "Hello World!" | foo = "bar")'
Nils Diewald7c8ced22015-04-15 19:21:00 +00002554 );
2555
2556 expect(vc.root().operands().length).toEqual(2);
2557
2558 // Add unspecified on the root group
2559 _andOn(vc.root().getOperand(1));
2560 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02002561 'pubDate in 2014-12-05 & (title = "Hello World!" | foo = "bar")'
Nils Diewald7c8ced22015-04-15 19:21:00 +00002562 );
2563
2564 expect(vc.root().ldType()).toEqual('docGroup');
2565 expect(vc.root().operands().length).toEqual(3);
2566 expect(vc.root().getOperand(0).ldType()).toEqual('doc');
2567 expect(vc.root().getOperand(1).ldType()).toEqual('docGroup');
2568 expect(vc.root().getOperand(1).operation()).toEqual('or');
2569 expect(vc.root().getOperand(2).ldType()).toEqual('non');
2570
2571 // Add another unspecified on the root group
2572 _andOn(vc.root().getOperand(1));
2573
2574 expect(vc.root().operands().length).toEqual(4);
2575 expect(vc.root().getOperand(0).ldType()).toEqual('doc');
2576 expect(vc.root().getOperand(1).ldType()).toEqual('docGroup');
2577 expect(vc.root().getOperand(2).ldType()).toEqual('non');
2578 expect(vc.root().getOperand(3).ldType()).toEqual('non');
2579
2580 // Add another unspecified after the first doc
2581 _andOn(vc.root().getOperand(0));
2582
2583 expect(vc.root().operands().length).toEqual(5);
2584 expect(vc.root().getOperand(0).ldType()).toEqual('doc');
2585 expect(vc.root().getOperand(1).ldType()).toEqual('non');
2586 expect(vc.root().getOperand(2).ldType()).toEqual('docGroup');
2587 expect(vc.root().getOperand(3).ldType()).toEqual('non');
2588 expect(vc.root().getOperand(4).ldType()).toEqual('non');
2589 });
2590
2591 it('should wrap on root', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00002592 var vc = vcClass.create().fromJson(
Akron712733a2018-04-05 18:17:47 +02002593 {
2594 "@type": 'koral:docGroup',
2595 'operation' : 'operation:and',
2596 'operands' : [
2597 {
2598 "@type": 'koral:doc',
2599 "key": 'pubDate',
2600 "match": 'match:eq',
2601 "value": '2014-12-05',
2602 "type": 'type:date'
2603 },
2604 {
2605 "@type" : 'koral:doc',
2606 'key' : 'foo',
2607 'value' : 'bar'
2608 }
2609 ]
2610 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00002611 );
2612
2613 // Wrap on root
2614 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar"');
2615 expect(vc.root().ldType()).toEqual('docGroup');
2616 expect(vc.root().operation()).toEqual('and');
2617 _orOn(vc.root());
2618 expect(vc.root().ldType()).toEqual('docGroup');
2619 expect(vc.root().operation()).toEqual('or');
2620
2621 expect(vc.root().getOperand(0).ldType()).toEqual('docGroup');
2622 expect(vc.root().getOperand(0).operation()).toEqual('and');
2623 });
2624
2625 it('should add on root (case "and")', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00002626 var vc = vcClass.create().fromJson(
Akron712733a2018-04-05 18:17:47 +02002627 {
2628 "@type": 'koral:doc',
2629 "key": 'pubDate',
2630 "match": 'match:eq',
2631 "value": '2014-12-05',
2632 "type": 'type:date'
2633 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00002634 );
2635
2636 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05');
2637 expect(vc.root().ldType()).toEqual('doc');
2638 expect(vc.root().key()).toEqual('pubDate');
2639 expect(vc.root().value()).toEqual('2014-12-05');
2640
2641 // Wrap on root
2642 _andOn(vc.root());
2643 expect(vc.root().ldType()).toEqual('docGroup');
2644 expect(vc.root().operation()).toEqual('and');
2645 });
2646
2647 it('should add on root (case "or")', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00002648 var vc = vcClass.create().fromJson(
Akron712733a2018-04-05 18:17:47 +02002649 {
2650 "@type": 'koral:doc',
2651 "key": 'pubDate',
2652 "match": 'match:eq',
2653 "value": '2014-12-05',
2654 "type": 'type:date'
2655 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00002656 );
2657
2658 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05');
2659 expect(vc.root().key()).toEqual('pubDate');
2660 expect(vc.root().value()).toEqual('2014-12-05');
2661
2662 // Wrap on root
2663 _orOn(vc.root());
2664 expect(vc.root().ldType()).toEqual('docGroup');
2665 expect(vc.root().operation()).toEqual('or');
2666 });
2667
2668 it('should support multiple sub groups per group', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00002669 var vc = vcClass.create().fromJson(
Akron712733a2018-04-05 18:17:47 +02002670 {
2671 "@type": 'koral:docGroup',
2672 'operation' : 'operation:or',
2673 'operands' : [
2674 {
2675 "@type": 'koral:docGroup',
2676 'operation' : 'operation:and',
2677 'operands' : [
2678 {
2679 "@type": 'koral:doc',
2680 "key": 'title',
2681 "value": 't1',
2682 },
2683 {
2684 "@type" : 'koral:doc',
2685 'key' : 'title',
2686 'value' : 't2'
2687 }
2688 ]
2689 },
2690 {
2691 "@type": 'koral:docGroup',
2692 'operation' : 'operation:and',
2693 'operands' : [
2694 {
2695 "@type": 'koral:doc',
2696 "key": 'title',
2697 "value": 't3',
2698 },
2699 {
2700 "@type" : 'koral:doc',
2701 'key' : 'title',
2702 'value' : 't4'
2703 }
2704 ]
2705 }
2706 ]
2707 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00002708 );
2709 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02002710 '(title = "t1" & title = "t2") | ' +
2711 '(title = "t3" & title = "t4")'
Nils Diewald7c8ced22015-04-15 19:21:00 +00002712 );
2713 expect(vc.root().operation()).toEqual('or');
2714 expect(vc.root().getOperand(0).toQuery()).toEqual('title = "t1" & title = "t2"');
2715 expect(vc.root().getOperand(1).toQuery()).toEqual('title = "t3" & title = "t4"');
2716
2717 _andOn(vc.root());
2718
2719 expect(vc.root().operation()).toEqual('and');
2720 expect(vc.root().getOperand(0).ldType()).toEqual('docGroup');
2721 expect(vc.root().getOperand(1).ldType()).toEqual('non');
2722 });
2723 });
2724
Nils Diewald6283d692015-04-23 20:32:53 +00002725
Akron88d237e2020-10-21 08:05:18 +02002726 describe('KorAP.VC.Rewrite', function () {
Nils Diewald7c8ced22015-04-15 19:21:00 +00002727 it('should be initializable', function () {
2728 var rewrite = rewriteClass.create({
Akron712733a2018-04-05 18:17:47 +02002729 "@type" : "koral:rewrite",
2730 "operation" : "operation:modification",
2731 "src" : "querySerializer",
2732 "scope" : "tree"
Nils Diewald86dad5b2015-01-28 15:09:07 +00002733 });
Nils Diewald7c8ced22015-04-15 19:21:00 +00002734 expect(rewrite.toString()).toEqual('Modification of "tree" by "querySerializer"');
2735 });
Nils Diewald86dad5b2015-01-28 15:09:07 +00002736
Nils Diewald7c8ced22015-04-15 19:21:00 +00002737 it('should be deserialized by docs', function () {
2738 var doc = docClass.create(
Akron712733a2018-04-05 18:17:47 +02002739 undefined,
2740 {
2741 "@type":"koral:doc",
2742 "key":"Titel",
2743 "value":"Baum",
2744 "match":"match:eq"
2745 });
Nils Diewald7c8ced22015-04-15 19:21:00 +00002746
2747 expect(doc.element().classList.contains('doc')).toBeTruthy();
2748 expect(doc.element().classList.contains('rewritten')).toBe(false);
2749
2750 doc = docClass.create(
Akron712733a2018-04-05 18:17:47 +02002751 undefined,
2752 {
2753 "@type":"koral:doc",
2754 "key":"Titel",
2755 "value":"Baum",
2756 "match":"match:eq",
2757 "rewrites" : [
2758 {
2759 "@type" : "koral:rewrite",
2760 "operation" : "operation:modification",
2761 "src" : "querySerializer",
2762 "scope" : "tree"
2763 }
2764 ]
2765 });
Nils Diewald7c8ced22015-04-15 19:21:00 +00002766
2767 expect(doc.element().classList.contains('doc')).toBeTruthy();
2768 expect(doc.element().classList.contains('rewritten')).toBeTruthy();
2769 });
Nils Diewald6283d692015-04-23 20:32:53 +00002770
Akron76c3dd62018-05-29 20:58:27 +02002771 it('should be described in a title attribute', function () {
2772
2773 doc = docClass.create(
2774 undefined,
2775 {
2776 "@type":"koral:doc",
2777 "key":"Titel",
2778 "value":"Baum",
2779 "match":"match:eq",
2780 "rewrites" : [
2781 {
2782 "@type" : "koral:rewrite",
2783 "operation" : "operation:modification",
2784 "src" : "querySerializer",
2785 "scope" : "tree"
2786 },
2787 {
2788 "@type" : "koral:rewrite",
2789 "operation" : "operation:injection",
2790 "src" : "me"
2791 }
2792 ]
2793 });
2794
2795 expect(doc.element().classList.contains('doc')).toBeTruthy();
2796 expect(doc.element().classList.contains('rewritten')).toBeTruthy();
2797 expect(doc.element().lastChild.getAttribute("title")).toEqual("querySerializer: tree (modification)\nme (injection)");
2798 });
2799
2800
Nils Diewald6283d692015-04-23 20:32:53 +00002801 xit('should be deserialized by docGroups', function () {
2802 var docGroup = docGroupClass.create(
Akron712733a2018-04-05 18:17:47 +02002803 undefined,
2804 {
2805 "@type" : "koral:docGroup",
2806 "operation" : "operation:or",
2807 "operands" : [
2808 {
2809 "@type" : "doc",
2810 "key" : "pubDate",
2811 "type" : "type:date",
2812 "value" : "2014-12-05"
2813 },
2814 {
2815 "@type" : "doc",
2816 "key" : "pubDate",
2817 "type" : "type:date",
2818 "value" : "2014-12-06"
2819 }
2820 ],
2821 "rewrites" : [
2822 {
2823 "@type" : "koral:rewrite",
2824 "operation" : "operation:modification",
2825 "src" : "querySerializer",
2826 "scope" : "tree"
2827 }
2828 ]
2829 }
Nils Diewald6283d692015-04-23 20:32:53 +00002830 );
2831
2832 expect(doc.element().classList.contains('docgroup')).toBeTruthy();
2833 expect(doc.element().classList.contains('rewritten')).toBe(false);
2834 });
Nils Diewald86dad5b2015-01-28 15:09:07 +00002835 });
Nils Diewaldf0c4f112015-05-05 12:56:59 +00002836
Akron88d237e2020-10-21 08:05:18 +02002837 describe('KorAP.VC.stringValue', function () {
Nils Diewaldf0c4f112015-05-05 12:56:59 +00002838 it('should be initializable', function () {
2839 var sv = stringValClass.create();
2840 expect(sv.regex()).toBe(false);
2841 expect(sv.value()).toBe('');
Nils Diewaldc4c4b832015-05-05 16:00:08 +00002842
2843 sv = stringValClass.create('Baum');
2844 expect(sv.regex()).toBe(false);
2845 expect(sv.value()).toBe('Baum');
2846
2847 sv = stringValClass.create('Baum', false);
2848 expect(sv.regex()).toBe(false);
2849 expect(sv.value()).toBe('Baum');
2850
2851 sv = stringValClass.create('Baum', true);
2852 expect(sv.regex()).toBe(true);
2853 expect(sv.value()).toBe('Baum');
2854 });
2855
2856 it('should be modifiable', function () {
2857 var sv = stringValClass.create();
2858 expect(sv.regex()).toBe(false);
2859 expect(sv.value()).toBe('');
2860
2861 expect(sv.value('Baum')).toBe('Baum');
2862 expect(sv.value()).toBe('Baum');
2863
2864 expect(sv.regex(true)).toBe(true);
2865 expect(sv.regex()).toBe(true);
2866 });
2867
2868 it('should have a toggleble regex value', function () {
2869 var sv = stringValClass.create();
Nils Diewald7991a3f2015-05-19 14:12:37 +00002870
2871 expect(sv.element().firstChild.value).toBe('');
2872 sv.element().firstChild.value = 'der'
2873 expect(sv.element().firstChild.value).toBe('der');
2874
Nils Diewaldc4c4b832015-05-05 16:00:08 +00002875 expect(sv.regex()).toBe(false);
2876
2877 sv.toggleRegex();
Nils Diewald7991a3f2015-05-19 14:12:37 +00002878 expect(sv.element().firstChild.value).toBe('der');
Nils Diewaldc4c4b832015-05-05 16:00:08 +00002879 expect(sv.regex()).toBe(true);
Nils Diewald7991a3f2015-05-19 14:12:37 +00002880 sv.element().firstChild.value = 'derbe'
Nils Diewaldc4c4b832015-05-05 16:00:08 +00002881
2882 sv.toggleRegex();
2883 expect(sv.regex()).toBe(false);
Nils Diewald7991a3f2015-05-19 14:12:37 +00002884 expect(sv.element().firstChild.value).toBe('derbe');
Nils Diewaldc4c4b832015-05-05 16:00:08 +00002885 });
2886
2887 it('should have an element', function () {
2888 var sv = stringValClass.create('der');
2889 expect(sv.element().nodeName).toBe('DIV');
2890 expect(sv.element().firstChild.nodeName).toBe('INPUT');
Akron5d4f2e42024-12-16 09:10:27 +01002891 expect(sv.element().firstChild.getAttribute('type')).toBeNull();
Nils Diewaldc4c4b832015-05-05 16:00:08 +00002892 expect(sv.element().firstChild.value).toBe('der');
2893 });
2894
2895 it('should have a classed element', function () {
Akrondbbe5ee2020-12-03 12:39:46 +01002896 const sv = stringValClass.create();
Nils Diewaldc4c4b832015-05-05 16:00:08 +00002897 expect(sv.element().classList.contains('regex')).toBe(false);
2898 expect(sv.regex()).toBe(false);
Akrondbbe5ee2020-12-03 12:39:46 +01002899
2900 const re = sv.element().children[1];
2901 expect(re.textContent).toEqual('RegEx');
2902 expect(re.getAttribute("title")).toEqual('Use as regular expression');
2903
2904 // Run event instead toggleRegex()
2905 re.click();
2906
Nils Diewaldc4c4b832015-05-05 16:00:08 +00002907 expect(sv.element().classList.contains('regex')).toBe(true);
2908 });
2909
2910 it('should be storable', function () {
2911 var sv = stringValClass.create();
2912 var count = 1;
2913 sv.store = function (value, regex) {
Akron712733a2018-04-05 18:17:47 +02002914 expect(regex).toBe(true);
2915 expect(value).toBe('tree');
Nils Diewaldc4c4b832015-05-05 16:00:08 +00002916 };
2917 sv.regex(true);
2918 sv.value('tree');
2919 sv.element().lastChild.click();
Nils Diewaldf0c4f112015-05-05 12:56:59 +00002920 });
Akron712733a2018-04-05 18:17:47 +02002921
Akronb19803c2018-08-16 16:39:42 +02002922 it('should have a disableoption for regex', function () {
2923 var sv = stringValClass.create(undefined, undefined, true);
2924 var svE = sv.element();
2925 expect(svE.children.length).toEqual(2);
2926
2927 sv = stringValClass.create(undefined, undefined, false);
2928 svE = sv.element();
2929 expect(svE.children.length).toEqual(1);
2930 });
2931
Nils Diewaldf0c4f112015-05-05 12:56:59 +00002932 });
Akrone4961b12017-05-10 21:04:46 +02002933
Akron5d4f2e42024-12-16 09:10:27 +01002934
2935 describe('KorAP.VC.intValue', function () {
2936 it('should be initializable', function () {
2937 var iv = intValClass.create();
2938 expect(iv.value()).toBe(0);
2939
2940 iv = intValClass.create('400');
2941 expect(iv.value()).toBe(400);
2942
2943 iv = intValClass.create(400);
2944 expect(iv.value()).toBe(400);
2945
2946 iv = intValClass.create('Baum');
2947 expect(iv.value()).toBe(0);
2948 });
2949
2950 it('should be modifiable', function () {
2951 var iv = intValClass.create();
2952 expect(iv.value()).toBe(0);
2953
2954 expect(iv.value('33')).toBe(33);
2955 expect(iv.value()).toBe(33);
2956 });
2957
2958 it('should have an element', function () {
2959 var iv = intValClass.create(22);
2960 expect(iv.element().nodeName).toBe('DIV');
2961 expect(iv.element().firstChild.nodeName).toBe('INPUT');
2962 expect(iv.element().firstChild.getAttribute('type')).toBe('number');
2963 expect(iv.element().firstChild.value).toBe('22');
2964 });
2965
2966 it('should be storable', function () {
2967 var iv = intValClass.create();
2968 var count = 1;
2969 iv.store = function (value) {
2970 expect(value).toBe(80);
2971 };
2972 iv.value('80');
2973 iv.element().lastChild.click();
2974 });
2975 });
2976
2977
Akron712733a2018-04-05 18:17:47 +02002978 describe('KorAP.VC.Menu', function () {
Akrone65a88a2018-04-05 19:14:20 +02002979
2980 var vc;
2981
Akron712733a2018-04-05 18:17:47 +02002982 it('should be initializable', function () {
2983
Akrone65a88a2018-04-05 19:14:20 +02002984 vc = vcClass.create([
Akron712733a2018-04-05 18:17:47 +02002985 ['a', 'text'],
2986 ['b', 'string'],
2987 ['c', 'date']
2988 ]).fromJson();
Akronadab5e52018-08-20 13:50:53 +02002989 expect(vc.builder().firstChild.classList.contains('unspecified')).toBeTruthy();
2990 expect(vc.builder().firstChild.firstChild.tagName).toEqual('SPAN');
Akron712733a2018-04-05 18:17:47 +02002991
2992 // Click on unspecified
Akronadab5e52018-08-20 13:50:53 +02002993 vc.builder().firstChild.firstChild.click();
2994 expect(vc.builder().firstChild.firstChild.tagName).toEqual('UL');
Akron712733a2018-04-05 18:17:47 +02002995
Akronadab5e52018-08-20 13:50:53 +02002996 var list = vc.builder().firstChild.firstChild;
Akron3ad46942018-08-22 16:47:14 +02002997 expect(list.getElementsByTagName("LI")[0].innerText).toEqual('referTo');
2998 expect(list.getElementsByTagName("LI")[1].innerText).toEqual('a');
2999 expect(list.getElementsByTagName("LI")[2].innerText).toEqual('b');
3000 expect(list.getElementsByTagName("LI")[3].innerText).toEqual('c');
Akron712733a2018-04-05 18:17:47 +02003001
3002 vc = vcClass.create([
3003 ['d', 'text'],
3004 ['e', 'string'],
Akron5d4f2e42024-12-16 09:10:27 +01003005 ['f', 'date'],
3006 ['g', 'integer']
Akron712733a2018-04-05 18:17:47 +02003007 ]).fromJson();
Akronadab5e52018-08-20 13:50:53 +02003008 expect(vc.builder().firstChild.classList.contains('unspecified')).toBeTruthy();
3009 expect(vc.builder().firstChild.firstChild.tagName).toEqual('SPAN');
Akron712733a2018-04-05 18:17:47 +02003010
3011 // Click on unspecified
Akronadab5e52018-08-20 13:50:53 +02003012 vc.builder().firstChild.firstChild.click();
3013 expect(vc.builder().firstChild.firstChild.tagName).toEqual('UL');
Akron712733a2018-04-05 18:17:47 +02003014
Akronadab5e52018-08-20 13:50:53 +02003015 list = vc.builder().firstChild.firstChild;
Akron3ad46942018-08-22 16:47:14 +02003016 expect(list.getElementsByTagName("LI")[0].innerText).toEqual('referTo');
3017 expect(list.getElementsByTagName("LI")[1].innerText).toEqual('d');
3018 expect(list.getElementsByTagName("LI")[2].innerText).toEqual('e');
3019 expect(list.getElementsByTagName("LI")[3].innerText).toEqual('f');
Akron5d4f2e42024-12-16 09:10:27 +01003020 expect(list.getElementsByTagName("LI")[4].innerText).toEqual('g');
Akron31d89942018-04-06 16:44:51 +02003021 // blur
3022 document.body.click();
Akron712733a2018-04-05 18:17:47 +02003023 });
Akrone65a88a2018-04-05 19:14:20 +02003024
3025 // Reinitialize to make tests stable
3026 vc = vcClass.create([
3027 ['d', 'text'],
3028 ['e', 'string'],
3029 ['f', 'date']
3030 ]).fromJson();
3031
3032 it('should be clickable on key', function () {
Akron31d89942018-04-06 16:44:51 +02003033 // Click on unspecified
Akronadab5e52018-08-20 13:50:53 +02003034 vc.builder().firstChild.firstChild.click();
Akrone65a88a2018-04-05 19:14:20 +02003035 // Click on "d"
Akronadab5e52018-08-20 13:50:53 +02003036 vc.builder().firstChild.firstChild.getElementsByTagName("LI")[1].click();
3037 expect(vc.builder().firstChild.firstChild.tagName).toEqual('SPAN');
3038 expect(vc.builder().firstChild.firstChild.innerText).toEqual('d');
3039 expect(vc.builder().firstChild.children[1].innerText).toEqual('eq');
3040 expect(vc.builder().firstChild.children[1].getAttribute('data-type')).toEqual('text');
Akron31d89942018-04-06 16:44:51 +02003041 // blur
3042 document.body.click();
Akrone65a88a2018-04-05 19:14:20 +02003043 });
3044
Akron31d89942018-04-06 16:44:51 +02003045 it('should be clickable on operation for text', function () {
3046 // Click on "d" (or unspecified)
Akronadab5e52018-08-20 13:50:53 +02003047 vc.builder().firstChild.firstChild.click();
Akron31d89942018-04-06 16:44:51 +02003048
3049 // Choose "d"
Akronadab5e52018-08-20 13:50:53 +02003050 vc.builder().firstChild.firstChild.getElementsByTagName("LI")[1].click();
Akron31d89942018-04-06 16:44:51 +02003051
3052 // Click on matchop
Akronadab5e52018-08-20 13:50:53 +02003053 vc.builder().firstChild.children[1].click();
Akron31d89942018-04-06 16:44:51 +02003054
Akronadab5e52018-08-20 13:50:53 +02003055 expect(vc.builder().firstChild.children[1].tagName).toEqual('UL');
Akron31d89942018-04-06 16:44:51 +02003056
Akronadab5e52018-08-20 13:50:53 +02003057 var ul = vc.builder().firstChild.children[1];
Akrone65a88a2018-04-05 19:14:20 +02003058 expect(ul.getElementsByTagName('li')[0].innerText).toEqual("eq");
3059 expect(ul.getElementsByTagName('li')[1].innerText).toEqual("ne");
3060 expect(ul.getElementsByTagName('li')[2].innerText).toEqual("contains");
3061 expect(ul.getElementsByTagName('li')[3].innerText).toEqual("containsnot");
3062 expect(ul.getElementsByTagName('li')[4]).toBeUndefined();
Akron31d89942018-04-06 16:44:51 +02003063
3064 // Choose "contains"
3065 ul.getElementsByTagName('li')[2].click();
Akronadab5e52018-08-20 13:50:53 +02003066 expect(vc.builder().firstChild.children[1].tagName).toEqual("SPAN");
3067 expect(vc.builder().firstChild.children[1].innerText).toEqual("contains");
Akron31d89942018-04-06 16:44:51 +02003068 // blur
3069 document.body.click();
Akrone65a88a2018-04-05 19:14:20 +02003070 })
Akron31d89942018-04-06 16:44:51 +02003071
3072 it('should be clickable on operation for string', function () {
3073 // Click on "d" (or unspecified)
Akronadab5e52018-08-20 13:50:53 +02003074 vc.builder().firstChild.firstChild.click();
Akron31d89942018-04-06 16:44:51 +02003075
3076 // Choose "e"
Akronadab5e52018-08-20 13:50:53 +02003077 vc.builder().firstChild.firstChild.getElementsByTagName("LI")[2].click();
3078
Akron31d89942018-04-06 16:44:51 +02003079 // As a consequence the matchoperator may no longer
3080 // be valid and needs to be re-evaluated
Akronadab5e52018-08-20 13:50:53 +02003081 var fc = vc.builder().firstChild;
Akron31d89942018-04-06 16:44:51 +02003082 expect(fc.firstChild.tagName).toEqual('SPAN');
3083 expect(fc.firstChild.innerText).toEqual('e');
3084 expect(fc.children[1].innerText).toEqual('eq');
3085 expect(fc.children[1].getAttribute('data-type')).toEqual('string');
3086
Akronadab5e52018-08-20 13:50:53 +02003087 vc.builder().firstChild.children[1].click();
Akron31d89942018-04-06 16:44:51 +02003088
Akronadab5e52018-08-20 13:50:53 +02003089 expect(vc.builder().firstChild.children[1].tagName).toEqual('UL');
Akron31d89942018-04-06 16:44:51 +02003090
Akronadab5e52018-08-20 13:50:53 +02003091 var ul = vc.builder().firstChild.children[1];
Akron31d89942018-04-06 16:44:51 +02003092 expect(ul.getElementsByTagName('li')[0].innerText).toEqual("eq");
3093 expect(ul.getElementsByTagName('li')[1].innerText).toEqual("ne");
3094 expect(ul.getElementsByTagName('li')[2]).toBeUndefined();
3095
3096 // Choose "ne"
3097 ul.getElementsByTagName('li')[1].click();
Akronadab5e52018-08-20 13:50:53 +02003098 expect(vc.builder().firstChild.children[1].tagName).toEqual("SPAN");
3099 expect(vc.builder().firstChild.children[1].innerText).toEqual("ne");
Akron8db5e3a2018-05-28 19:25:26 +02003100
3101 // Click on text
Akronebc96662018-08-29 17:36:20 +02003102 expect(vc.builder().firstChild.children[2].innerText).toEqual(KorAP.Locale.EMPTY);
3103 expect(vc.builder().firstChild.children[2].classList.contains('unspecified')).toEqual(true);
Akronadab5e52018-08-20 13:50:53 +02003104 vc.builder().firstChild.children[2].click();
Akron8db5e3a2018-05-28 19:25:26 +02003105
3106 // Blur text element
Akronadab5e52018-08-20 13:50:53 +02003107 expect(vc.builder().firstChild.children[2].firstChild.value).toEqual('');
Akron8db5e3a2018-05-28 19:25:26 +02003108
Akron31d89942018-04-06 16:44:51 +02003109 // blur
3110 document.body.click();
3111 });
3112
3113 it('should be clickable on operation for date', function () {
3114
3115 // Replay matchop check - so it's guaranteed that "ne" is chosen
3116 // Click on "e" (or unspecified)
Akronadab5e52018-08-20 13:50:53 +02003117 vc.builder().firstChild.firstChild.click();
Akron31d89942018-04-06 16:44:51 +02003118 // Rechoose "e"
Akronadab5e52018-08-20 13:50:53 +02003119 vc.builder().firstChild.firstChild.getElementsByTagName("LI")[1].click();
Akron31d89942018-04-06 16:44:51 +02003120 // Click on matchop
Akronadab5e52018-08-20 13:50:53 +02003121 vc.builder().firstChild.children[1].click();
Akron31d89942018-04-06 16:44:51 +02003122 // Choose "ne"
Akronadab5e52018-08-20 13:50:53 +02003123 vc.builder().firstChild.children[1].getElementsByTagName('li')[1].click();
3124 expect(vc.builder().firstChild.children[1].innerText).toEqual("ne");
Akron31d89942018-04-06 16:44:51 +02003125
3126 // Click on "e"
Akronadab5e52018-08-20 13:50:53 +02003127 vc.builder().firstChild.firstChild.click();
Akron31d89942018-04-06 16:44:51 +02003128 // Choose "f"
Akronadab5e52018-08-20 13:50:53 +02003129 vc.builder().firstChild.firstChild.getElementsByTagName("LI")[3].click();
Akron31d89942018-04-06 16:44:51 +02003130
3131 // The matchoperator should still be "ne" as this is valid for dates as well (now)
Akronadab5e52018-08-20 13:50:53 +02003132 var fc = vc.builder().firstChild;
Akron31d89942018-04-06 16:44:51 +02003133 expect(fc.firstChild.tagName).toEqual('SPAN');
3134 expect(fc.firstChild.innerText).toEqual('f');
3135 expect(fc.children[1].innerText).toEqual('ne');
3136 // blur
3137 document.body.click();
3138 });
Akronddc98a72018-04-06 17:33:52 +02003139
Akron5d4f2e42024-12-16 09:10:27 +01003140 it('should be clickable on operation for integer', function () {
3141
3142 vc.builder().firstChild.firstChild.click();// Choose "g"
3143 vc.builder().firstChild.firstChild.getElementsByTagName("LI")[4].click()
3144 // Click on "g" (or unspecified)
3145 vc.builder().firstChild.firstChild.click();
3146 // Rechoose "g"
3147 vc.builder().firstChild.firstChild.getElementsByTagName("LI")[4].click();
3148 // Click on matchop
3149 vc.builder().firstChild.children[1].click();
3150 // Choose "geq"
3151 vc.builder().firstChild.children[1].getElementsByTagName('li')[2].click();
3152 expect(vc.builder().firstChild.children[1].innerText).toEqual("geq");
3153
3154 // Click on "e"
3155 vc.builder().firstChild.firstChild.click();
3156 // Choose "f"
3157 vc.builder().firstChild.firstChild.getElementsByTagName("LI")[3].click();
3158
3159 // The matchoperator should still be "geq" as this is valid for dates as well (now)
3160 var fc = vc.builder().firstChild;
3161 expect(fc.firstChild.tagName).toEqual('SPAN');
3162 expect(fc.firstChild.innerText).toEqual('f');
3163 expect(fc.children[1].innerText).toEqual('geq');
3164 // blur
3165 document.body.click();
3166 });
Akronddc98a72018-04-06 17:33:52 +02003167
3168 // Check json deserialization
3169 it('should be initializable', function () {
3170 vc = vcClass.create([
3171 ['a', 'text'],
3172 ['b', 'string'],
3173 ['c', 'date']
3174 ]).fromJson({
3175 "@type" : "koral:doc",
3176 "key":"a",
3177 "value":"Baum"
3178 });
3179
Akronadab5e52018-08-20 13:50:53 +02003180 expect(vc.builder().firstChild.children[1].getAttribute('data-type')).toEqual('text');
Akronddc98a72018-04-06 17:33:52 +02003181 });
Akron712733a2018-04-05 18:17:47 +02003182 });
3183
3184
Akrone4961b12017-05-10 21:04:46 +02003185 // Check prefix
3186 describe('KorAP.VC.Prefix', function () {
3187
3188 it('should be initializable', function () {
3189 var p = prefixClass.create();
3190 expect(p.element().classList.contains('pref')).toBeTruthy();
3191 expect(p.isSet()).not.toBeTruthy();
3192 });
3193
3194
3195 it('should be clickable', function () {
hebastaa0282be2018-12-05 16:58:00 +01003196 KorAP.vc = vcClass.create([
Akron712733a2018-04-05 18:17:47 +02003197 ['a', null],
3198 ['b', null],
3199 ['c', null]
3200 ]).fromJson();
hebastaa0282be2018-12-05 16:58:00 +01003201
3202 //vc = KorAP.vc;
3203
3204 expect(KorAP.vc.builder().firstChild.classList.contains('unspecified')).toBeTruthy();
Akrone4961b12017-05-10 21:04:46 +02003205
3206 // This should open up the menu
hebastaa0282be2018-12-05 16:58:00 +01003207 KorAP.vc.builder().firstChild.firstChild.click();
3208 expect(KorAP.vc.builder().firstChild.firstChild.tagName).toEqual('UL');
Akrone4961b12017-05-10 21:04:46 +02003209
3210 KorAP._vcKeyMenu._prefix.clear();
3211 KorAP._vcKeyMenu._prefix.add('x');
3212
hebastaa0282be2018-12-05 16:58:00 +01003213 var prefElement = KorAP.vc.builder().querySelector('span.pref');
Akrone4961b12017-05-10 21:04:46 +02003214 expect(prefElement.innerText).toEqual('x');
3215
3216 // This should add key 'x' to VC
3217 prefElement.click();
3218
hebastaa0282be2018-12-05 16:58:00 +01003219 expect(KorAP.vc.builder().firstChild.classList.contains('doc')).toBeTruthy();
3220 expect(KorAP.vc.builder().firstChild.firstChild.className).toEqual('key');
3221 expect(KorAP.vc.builder().firstChild.firstChild.innerText).toEqual('x');
Akrone4961b12017-05-10 21:04:46 +02003222 });
3223 });
Akron68d28322018-08-27 15:02:42 +02003224
Akron889ec292018-11-19 17:56:01 +01003225 // Check fragment handling for corpusByMatch helper
Akron68d28322018-08-27 15:02:42 +02003226 describe('KorAP.VC.Fragment', function () {
3227 it('should be initializable', function () {
3228 var f = fragmentClass.create();
3229 var e = f.element();
3230 expect(e.classList.contains('vc')).toBeTruthy();
3231 expect(e.classList.contains('fragment')).toBeTruthy();
Akrond45a1702018-11-19 18:15:17 +01003232 expect(e.firstChild.children.length).toEqual(0);
Akron68d28322018-08-27 15:02:42 +02003233 });
3234
3235 it('should be expansable', function () {
3236 var f = fragmentClass.create();
3237 f.add("author", "Peter");
3238
Akrond45a1702018-11-19 18:15:17 +01003239 var root = f.element().lastChild.firstChild;
Akron68d28322018-08-27 15:02:42 +02003240
3241 expect(root.classList.contains("doc")).toBeTruthy();
3242 expect(root.children[0].tagName).toEqual("SPAN");
3243 expect(root.children[0].textContent).toEqual("author");
3244 expect(root.children[1].tagName).toEqual("SPAN");
3245 expect(root.children[1].textContent).toEqual("eq");
3246 expect(root.children[2].tagName).toEqual("SPAN");
3247 expect(root.children[2].textContent).toEqual("Peter");
3248
3249 f.add("title", "Example");
3250
Akrond45a1702018-11-19 18:15:17 +01003251 root = f.element().lastChild.firstChild;
Akron68d28322018-08-27 15:02:42 +02003252
3253 expect(root.classList.contains("docGroup")).toBeTruthy();
3254
3255 var doc = root.children[0];
3256
3257 expect(doc.children[0].tagName).toEqual("SPAN");
3258 expect(doc.children[0].textContent).toEqual("author");
3259 expect(doc.children[1].tagName).toEqual("SPAN");
3260 expect(doc.children[1].textContent).toEqual("eq");
3261 expect(doc.children[2].tagName).toEqual("SPAN");
3262 expect(doc.children[2].textContent).toEqual("Peter");
3263
3264 doc = root.children[1];
3265
3266 expect(doc.children[0].tagName).toEqual("SPAN");
3267 expect(doc.children[0].textContent).toEqual("title");
3268 expect(doc.children[1].tagName).toEqual("SPAN");
3269 expect(doc.children[1].textContent).toEqual("eq");
3270 expect(doc.children[2].tagName).toEqual("SPAN");
3271 expect(doc.children[2].textContent).toEqual("Example");
3272 });
3273
3274
3275 it('should be reducible', function () {
3276 var f = fragmentClass.create();
Akrond45a1702018-11-19 18:15:17 +01003277 expect(f.element().lastChild.children.length).toEqual(0);
Akron889ec292018-11-19 17:56:01 +01003278
Akron68d28322018-08-27 15:02:42 +02003279 f.add("author", "Peter");
3280 f.add("title", "Example");
3281
Akrond45a1702018-11-19 18:15:17 +01003282 expect(f.element().lastChild.children.length).toEqual(1);
Akron889ec292018-11-19 17:56:01 +01003283
Akrond45a1702018-11-19 18:15:17 +01003284 var root = f.element().lastChild.firstChild;
Akron889ec292018-11-19 17:56:01 +01003285
Akron68d28322018-08-27 15:02:42 +02003286 expect(root.classList.contains("docGroup")).toBeTruthy();
3287
3288 expect(root.children.length).toEqual(2);
3289
3290 f.remove("author","Peter");
3291
Akrond45a1702018-11-19 18:15:17 +01003292 root = f.element().lastChild.firstChild;
Akron68d28322018-08-27 15:02:42 +02003293 expect(root.classList.contains("doc")).toBeTruthy();
3294
3295 expect(root.children[0].tagName).toEqual("SPAN");
3296 expect(root.children[0].textContent).toEqual("title");
3297 expect(root.children[1].tagName).toEqual("SPAN");
3298 expect(root.children[1].textContent).toEqual("eq");
3299 expect(root.children[2].tagName).toEqual("SPAN");
3300 expect(root.children[2].textContent).toEqual("Example");
Akron889ec292018-11-19 17:56:01 +01003301
3302 f.remove("title","Example");
3303
Akrond45a1702018-11-19 18:15:17 +01003304 expect(f.element().lastChild.children.length).toEqual(0);
Akron68d28322018-08-27 15:02:42 +02003305 });
Akron2761d882020-10-13 10:35:09 +02003306
3307 it('should respect already set attributes', function () {
3308 var f = fragmentClass.create();
3309 expect(f.element().lastChild.children.length).toEqual(0);
3310
3311 expect(f.isEmpty()).toBeTruthy();
3312
3313 f.add("author", "Peter");
3314 f.add("title", "Example");
3315
3316 expect(f.isEmpty()).toBeFalsy();
3317
3318 expect(f.toQuery()).toEqual('author = "Peter" & title = "Example"');
3319
3320 f.add("author", "Peter");
3321
3322 expect(f.toQuery()).toEqual('title = "Example" & author = "Peter"');
3323 });
Akron68d28322018-08-27 15:02:42 +02003324 });
Nils Diewald2fe12e12015-03-06 16:47:06 +00003325});