blob: 656a827b6359c3bbfcdce3f5438fda6ea806640d [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
404 doc = integerFactory.create();
405 expect(doc.toQuery()).toEqual('KED.nToks = 200');
406
407 doc = integerFactory.create({
408 value : "100"
409 });
410 expect(doc.toQuery()).toEqual('KED.nToks = 100');
411
412 doc = integerFactory.create({
413 value : "100",
414 match : "match:geq"
415 });
416 expect(doc.toQuery()).toEqual('KED.nToks >= 100');
417
418 doc = integerFactory.create({
419 value : "100",
420 match : "match:leq"
421 });
422 expect(doc.toQuery()).toEqual('KED.nToks <= 100');
423
424 // Check for numeric values
425 doc = integerFactory.create({
426 value : 100,
427 });
428 expect(doc.toQuery()).toEqual('KED.nToks = 100');
429
Nils Diewald7c8ced22015-04-15 19:21:00 +0000430 });
431 });
432
433
Akron88d237e2020-10-21 08:05:18 +0200434 describe('KorAP.VC.DocGroup', function () {
Nils Diewald7c8ced22015-04-15 19:21:00 +0000435 // Create example factories
436 var docFactory = buildFactory(
437 docClass,
Nils Diewaldf219eb82015-01-07 20:15:42 +0000438 {
Akron712733a2018-04-05 18:17:47 +0200439 "@type" : "koral:doc",
440 "match":"match:eq",
441 "key" : "author",
442 "value" : "Max Birkendale"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000443 }
444 );
445
446 var docGroupFactory = buildFactory(
447 docGroupClass, {
Akron712733a2018-04-05 18:17:47 +0200448 "@type" : "koral:docGroup",
449 "operation" : "operation:and",
450 "operands" : [
451 docFactory.create().toJson(),
452 docFactory.create({
453 "key" : "pubDate",
454 "type" : "type:date",
455 "value" : "2014-12-05"
456 }).toJson()
457 ]
Nils Diewald7c8ced22015-04-15 19:21:00 +0000458 });
459
460 it('should be initializable', function () {
461 // Create empty group
462 var docGroup = docGroupClass.create();
463 expect(docGroup.operation()).toEqual('and');
464
465 // Create empty group
466 docGroup = docGroupClass.create();
467 docGroup.operation('or');
468 expect(docGroup.operation()).toEqual('or');
469 });
470
471 it('should be definable', function () {
472
473 // Empty group
474 var docGroup = docGroupClass.create();
475 expect(docGroup.operation()).toEqual('and');
476
477 // Set values
478 docGroup.operation("or");
479 expect(docGroup.operation()).toEqual('or');
480
481 // Set invalid values
482 docGroup.operation("hui");
483 expect(docGroup.operation()).toEqual('or');
484 });
485
486 it('should be deserializable', function () {
Akronadab5e52018-08-20 13:50:53 +0200487
488 // Reset list
489 KorAP._vcKeyMenu = menuClass.create([['referTo','ref']]);
490
Nils Diewald7c8ced22015-04-15 19:21:00 +0000491 var docGroup = docGroupFactory.create();
492 expect(docGroup.operation()).toEqual("and");
493 expect(docGroup.operands().length).toEqual(2);
494
495 var op1 = docGroup.getOperand(0);
496 expect(op1.type()).toEqual("string");
497 expect(op1.key()).toEqual("author");
498 expect(op1.value()).toEqual("Max Birkendale");
499 expect(op1.matchop()).toEqual("eq");
500
501 var op2 = docGroup.getOperand(1);
502 expect(op2.type()).toEqual("date");
503 expect(op2.key()).toEqual("pubDate");
504 expect(op2.value()).toEqual("2014-12-05");
505 expect(op2.matchop()).toEqual("eq");
506
507 // Append empty group
508 var newGroup = docGroup.append(docGroupClass.create());
509 newGroup.operation('or');
510 newGroup.append(docFactory.create());
511 newGroup.append(docFactory.create({
Akron712733a2018-04-05 18:17:47 +0200512 "type" : "type:regex",
513 "key" : "title",
514 "value" : "^e.+?$",
515 "match" : "match:ne"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000516 }));
517
518 expect(docGroup.operation()).toEqual("and");
519 expect(docGroup.operands().length).toEqual(3);
520
521 var op1 = docGroup.getOperand(0);
522 expect(op1.ldType()).toEqual("doc");
523 expect(op1.type()).toEqual("string");
524 expect(op1.key()).toEqual("author");
525 expect(op1.value()).toEqual("Max Birkendale");
526 expect(op1.matchop()).toEqual("eq");
527
528 var op2 = docGroup.getOperand(1);
529 expect(op2.ldType()).toEqual("doc");
530 expect(op2.type()).toEqual("date");
531 expect(op2.key()).toEqual("pubDate");
532 expect(op2.value()).toEqual("2014-12-05");
533 expect(op2.matchop()).toEqual("eq");
534
535 var op3 = docGroup.getOperand(2);
536 expect(op3.ldType()).toEqual("docGroup");
537 expect(op3.operation()).toEqual("or");
Akronadab5e52018-08-20 13:50:53 +0200538
Nils Diewald7c8ced22015-04-15 19:21:00 +0000539 var op4 = op3.getOperand(0);
540 expect(op4.ldType()).toEqual("doc");
541 expect(op4.type()).toEqual("string");
542 expect(op4.key()).toEqual("author");
543 expect(op4.value()).toEqual("Max Birkendale");
544 expect(op4.matchop()).toEqual("eq");
545
546 var op5 = op3.getOperand(1);
547 expect(op5.ldType()).toEqual("doc");
548 expect(op5.type()).toEqual("regex");
549 expect(op5.key()).toEqual("title");
550 expect(op5.value()).toEqual("^e.+?$");
551 expect(op5.matchop()).toEqual("ne");
552 });
553
554 it('should be serializable to JSON', function () {
555 var docGroup = docGroupFactory.create();
556
557 expect(docGroup.toJson()).toEqual(jasmine.objectContaining({
Akron712733a2018-04-05 18:17:47 +0200558 "@type" : "koral:docGroup",
559 "operation" : "operation:and",
560 "operands" : [
561 {
562 "@type": 'koral:doc',
563 "key" : 'author',
564 "match": 'match:eq',
565 "value": 'Max Birkendale',
566 "type": 'type:string'
567 },
568 {
569 "@type": 'koral:doc',
570 "key": 'pubDate',
571 "match": 'match:eq',
572 "value": '2014-12-05',
573 "type": 'type:date'
574 }
575 ]
Nils Diewald7c8ced22015-04-15 19:21:00 +0000576 }));
577 });
Nils Diewalde15b7a22015-01-09 21:50:21 +0000578
Nils Diewald7c8ced22015-04-15 19:21:00 +0000579 it('should be serializable to String', function () {
580 var docGroup = docGroupFactory.create();
581 expect(docGroup.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +0200582 'author = "Max Birkendale" & pubDate in 2014-12-05'
Nils Diewald7c8ced22015-04-15 19:21:00 +0000583 );
Nils Diewald52f7eb12015-01-12 17:30:04 +0000584
Nils Diewald7c8ced22015-04-15 19:21:00 +0000585 docGroup = docGroupFactory.create({
Akron712733a2018-04-05 18:17:47 +0200586 "@type" : "koral:docGroup",
587 "operation" : "operation:or",
588 "operands" : [
589 {
590 "@type": 'koral:doc',
591 "key" : 'author',
592 "match": 'match:eq',
593 "value": 'Max Birkendale',
594 "type": 'type:string'
595 },
596 {
597 "@type" : "koral:docGroup",
598 "operation" : "operation:and",
599 "operands" : [
600 {
601 "@type": 'koral:doc',
602 "key": 'pubDate',
603 "match": 'match:geq',
604 "value": '2014-05-12',
605 "type": 'type:date'
606 },
607 {
608 "@type": 'koral:doc',
609 "key": 'pubDate',
610 "match": 'match:leq',
611 "value": '2014-12-05',
612 "type": 'type:date'
613 },
614 {
615 "@type": 'koral:doc',
616 "key": 'foo',
617 "match": 'match:ne',
618 "value": '[a]?bar',
619 "type": 'type:regex'
Akron5d4f2e42024-12-16 09:10:27 +0100620 },
621 {
622 "@type": 'koral:doc',
623 "key": 'KED.nToks',
624 "match": 'match:leq',
625 "value": '300',
626 "type": 'type:integer'
Akron712733a2018-04-05 18:17:47 +0200627 }
Akron5d4f2e42024-12-16 09:10:27 +0100628
Akron712733a2018-04-05 18:17:47 +0200629 ]
630 }
631 ]
Nils Diewald7c8ced22015-04-15 19:21:00 +0000632 });
633 expect(docGroup.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +0200634 'author = "Max Birkendale" | ' +
635 '(pubDate since 2014-05-12 & ' +
Akron5d4f2e42024-12-16 09:10:27 +0100636 'pubDate until 2014-12-05 & foo != /[a]?bar/ & ' +
637 'KED.nToks <= 300)'
Nils Diewald7c8ced22015-04-15 19:21:00 +0000638 );
hebastaa0282be2018-12-05 16:58:00 +0100639
640
641 // Check for incompletion and only serialize complete operands
642 expect(docGroup.incomplete()).toBeFalsy();
643 var op1 = docGroup.getOperand(0);
644 op1.value("");
645 expect(docGroup.incomplete()).toBeFalsy();
646 expect(docGroup.toQuery()).toEqual(
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)'
hebastaa0282be2018-12-05 16:58:00 +0100650 );
Nils Diewald7c8ced22015-04-15 19:21:00 +0000651 });
652 });
653
Akron88d237e2020-10-21 08:05:18 +0200654 describe('KorAP.VC.DocGroupRef', function () {
Akronb19803c2018-08-16 16:39:42 +0200655 // Create example factories
656 var docRefFactory = buildFactory(
657 docGroupRefClass,
658 {
659 "@type" : "koral:docGroupRef",
660 "ref" : "@max/myCorpus"
661 }
662 );
663
664 it('should be initializable', function () {
665 var vcRef = docGroupRefClass.create();
666 expect(vcRef.ref()).toBeUndefined();
667 });
668
669 it('should be definable', function () {
670 var vcRef = docGroupRefClass.create();
671 vcRef.ref("@peter/mycorpus");
672 expect(vcRef.ref()).toEqual("@peter/mycorpus");
673 vcRef.ref("@peter/mycorpus2");
674 expect(vcRef.ref()).toEqual("@peter/mycorpus2");
675 });
676
677 it('should deserialize JSON-LD string', function () {
678 var vcRef = docRefFactory.create();
679 expect(vcRef.ref()).toEqual("@max/myCorpus");
680 });
681
682 it('should serialize to JSON-LD', function () {
683 var vcRef = docRefFactory.create();
684 expect(vcRef.toJson()).toEqual(jasmine.objectContaining({
685 "@type" : "koral:docGroupRef",
686 "ref":"@max/myCorpus"
687 }));
688
689 vcRef.ref("@peter/myCorpus2");
690 expect(vcRef.toJson()).toEqual(jasmine.objectContaining({
691 "@type" : "koral:docGroupRef",
692 "ref":"@peter/myCorpus2"
693 }));
694 });
695
696 it('should serialize to a query', function () {
697 var vcRef = docRefFactory.create();
698 expect(vcRef.toQuery()).toEqual(
699 "referTo \"@max/myCorpus\""
700 );
701
702 vcRef.ref("@peter/myCorpus2");
703 expect(vcRef.toQuery()).toEqual(
704 "referTo \"@peter/myCorpus2\""
705 );
hebastaa0282be2018-12-05 16:58:00 +0100706
707 // Check for incompletion and only serialize complete operands
708 expect(vcRef.incomplete()).toBeFalsy();
709 vcRef.ref("");
710 expect(vcRef.incomplete()).toBeTruthy();
711 expect(vcRef.toQuery()).toEqual("");
Akronb19803c2018-08-16 16:39:42 +0200712 });
713 });
714
715
Akron88d237e2020-10-21 08:05:18 +0200716 describe('KorAP.VC.UnspecifiedDoc', function () {
Akron0f00b772020-12-02 17:32:13 +0100717
718 KorAP.vc = undefined;
719
Nils Diewald7c8ced22015-04-15 19:21:00 +0000720 it('should be initializable', function () {
721 var doc = unspecifiedClass.create();
722 var docElement = doc.element();
723 expect(docElement.getAttribute('class')).toEqual('doc unspecified');
Akronebc96662018-08-29 17:36:20 +0200724 expect(docElement.firstChild.firstChild.data).toEqual(KorAP.Locale.EMPTY);
725 expect(docElement.lastChild.lastChild.data).toEqual(KorAP.Locale.EMPTY);
Nils Diewald7c8ced22015-04-15 19:21:00 +0000726 expect(doc.toQuery()).toEqual('');
hebastaa0282be2018-12-05 16:58:00 +0100727 expect(doc.incomplete()).toBeTruthy();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000728
729 // Only removable
730 expect(docElement.lastChild.children.length).toEqual(0);
731 });
732
hebastad7c03742019-07-11 12:48:50 +0200733 it('should be removable, when no root', function () {
734 var vc = vcClass.create();
735 KorAP.vc = vc;
Nils Diewald7c8ced22015-04-15 19:21:00 +0000736 var docGroup = docGroupClass.create();
737 docGroup.operation('or');
738 expect(docGroup.operation()).toEqual('or');
739
740 docGroup.append({
Akron712733a2018-04-05 18:17:47 +0200741 "@type": 'koral:doc',
742 "key": 'pubDate',
743 "match": 'match:eq',
744 "value": '2014-12-05',
745 "type": 'type:date'
Nils Diewald7c8ced22015-04-15 19:21:00 +0000746 });
747
748 // Add unspecified object
749 docGroup.append();
750
Akrond141a362018-07-10 18:12:13 +0200751 var parent = document.createElement('div');
752 parent.appendChild(docGroup.element());
753
Nils Diewald7c8ced22015-04-15 19:21:00 +0000754 expect(docGroup.element().getAttribute('class')).toEqual('docGroup');
755 expect(docGroup.element().children[0].getAttribute('class')).toEqual('doc');
756
757 var unspec = docGroup.element().children[1];
758 expect(unspec.getAttribute('class')).toEqual('doc unspecified');
759
Akronb19803c2018-08-16 16:39:42 +0200760 // Only unspec and delete
761 expect(unspec.children.length).toEqual(2);
762
Nils Diewald7c8ced22015-04-15 19:21:00 +0000763 // Removable
764 expect(unspec.lastChild.children.length).toEqual(1);
765 expect(unspec.lastChild.children[0].getAttribute('class')).toEqual('delete');
766 });
767
Akrond141a362018-07-10 18:12:13 +0200768
Nils Diewald7c8ced22015-04-15 19:21:00 +0000769 it('should be replaceable by a doc', function () {
770 var doc = unspecifiedClass.create();
771 expect(doc.ldType()).toEqual("non");
772 // No parent, therefor not updateable
773 expect(doc.key("baum")).toBeNull();
774
775 var docGroup = docGroupClass.create();
776 docGroup.operation('or');
777 expect(docGroup.operation()).toEqual('or');
778
779 docGroup.append({
Akron712733a2018-04-05 18:17:47 +0200780 "@type": 'koral:doc',
781 "key": 'pubDate',
782 "match": 'match:eq',
783 "value": '2014-12-05',
784 "type": 'type:date'
Nils Diewald7c8ced22015-04-15 19:21:00 +0000785 });
786
787 expect(docGroup.toQuery()).toEqual("pubDate in 2014-12-05");
788 docGroup.append();
789
790 expect(docGroup.getOperand(0).ldType()).toEqual("doc");
791 expect(docGroup.getOperand(1).ldType()).toEqual("non");
792
793 var op = docGroup.getOperand(1).element().lastChild;
Akron0b489ad2018-02-02 16:49:32 +0100794 expect(op.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +0000795 expect(op.children[0].getAttribute('class')).toEqual('delete');
796 expect(op.children.length).toEqual(1);
797
798 // Replace unspecified doc
799 expect(docGroup.getOperand(1).key("name")).not.toBeNull();
800 expect(docGroup.getOperand(1).ldType()).toEqual("doc");
801 expect(docGroup.getOperand(1).key()).toEqual("name");
Akron55a343b2018-04-06 19:57:36 +0200802 expect(docGroup.getOperand(1).value()).toBeUndefined();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000803
Akronb19803c2018-08-16 16:39:42 +0200804 expect(docGroup.getOperand(1).element().children.length).toEqual(4);
805
Nils Diewald7c8ced22015-04-15 19:21:00 +0000806 op = docGroup.getOperand(1).element().lastChild;
Akron0b489ad2018-02-02 16:49:32 +0100807 expect(op.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +0000808 expect(op.children[0].getAttribute('class')).toEqual('and');
809 expect(op.children[1].getAttribute('class')).toEqual('or');
810 expect(op.children[2].getAttribute('class')).toEqual('delete');
Akronb19803c2018-08-16 16:39:42 +0200811
Nils Diewald7c8ced22015-04-15 19:21:00 +0000812 expect(op.children.length).toEqual(3);
813
814 docGroup.getOperand(1).value("Pachelbel");
815 expect(docGroup.getOperand(1).value()).toEqual("Pachelbel");
816 expect(docGroup.getOperand(1).type()).toEqual("string");
817 expect(docGroup.getOperand(1).matchop()).toEqual("eq");
818
819 // Specified!
820 expect(docGroup.toQuery()).toEqual('pubDate in 2014-12-05 | name = "Pachelbel"');
821 });
Akronb19803c2018-08-16 16:39:42 +0200822
Nils Diewald7c8ced22015-04-15 19:21:00 +0000823 it('should be replaceable on root', function () {
hebastaa0282be2018-12-05 16:58:00 +0100824
Nils Diewald6283d692015-04-23 20:32:53 +0000825 var vc = vcClass.create();
hebastaa0282be2018-12-05 16:58:00 +0100826 KorAP.vc = vc;
Nils Diewald7c8ced22015-04-15 19:21:00 +0000827 expect(vc.toQuery()).toEqual("");
828
829 expect(vc.root().ldType()).toEqual("non");
830
831 // No operators on root
832 op = vc.root().element().lastChild;
Akronebc96662018-08-29 17:36:20 +0200833 expect(op.lastChild.textContent).toEqual(KorAP.Locale.EMPTY);
Nils Diewald7c8ced22015-04-15 19:21:00 +0000834
835 // Replace
836 expect(vc.root().key("baum")).not.toBeNull();
837 expect(vc.root().ldType()).toEqual("doc");
838
839 op = vc.root().element().lastChild;
Akron0b489ad2018-02-02 16:49:32 +0100840 expect(op.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +0000841 expect(op.children[0].getAttribute('class')).toEqual('and');
842 expect(op.children[1].getAttribute('class')).toEqual('or');
843 expect(op.children[2].getAttribute('class')).toEqual('delete');
844 expect(op.children.length).toEqual(3);
845 });
Akron55a343b2018-04-06 19:57:36 +0200846
847 it('should be clickable', function () {
848 var vc = vcClass.create([
849 ["pubDate", "date"]
850 ]);
hebastaa0282be2018-12-05 16:58:00 +0100851 KorAP.vc = vc;
852
Akron55a343b2018-04-06 19:57:36 +0200853 expect(vc.toQuery()).toEqual("");
Akronebc96662018-08-29 17:36:20 +0200854 expect(vc.builder().firstChild.textContent).toEqual(KorAP.Locale.EMPTY);
855 expect(vc.builder().firstChild.classList.contains('unspecified')).toEqual(true);
Akronadab5e52018-08-20 13:50:53 +0200856 vc.builder().firstChild.firstChild.click();
Akron55a343b2018-04-06 19:57:36 +0200857
858 // Click on pubDate
Akron3ad46942018-08-22 16:47:14 +0200859 vc.element().firstChild.getElementsByTagName("LI")[1].click();
Akronadab5e52018-08-20 13:50:53 +0200860 expect(vc.builder().firstChild.firstChild.textContent).toEqual("pubDate");
861 expect(vc.builder().firstChild.children[1].getAttribute("data-type")).toEqual("date");
Akron55a343b2018-04-06 19:57:36 +0200862 });
Nils Diewald7c8ced22015-04-15 19:21:00 +0000863 });
864
Akron88d237e2020-10-21 08:05:18 +0200865 describe('KorAP.VC.Doc element', function () {
Nils Diewald7c8ced22015-04-15 19:21:00 +0000866 it('should be initializable', function () {
867 var docElement = docClass.create(undefined, {
Akron712733a2018-04-05 18:17:47 +0200868 "@type" : "koral:doc",
869 "key":"Titel",
870 "value":"Baum",
871 "match":"match:eq"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000872 });
873 expect(docElement.key()).toEqual('Titel');
874 expect(docElement.matchop()).toEqual('eq');
875 expect(docElement.value()).toEqual('Baum');
876
877 var docE = docElement.element();
878 expect(docE.children[0].firstChild.data).toEqual('Titel');
879 expect(docE.children[1].firstChild.data).toEqual('eq');
880 expect(docE.children[1].getAttribute('data-type')).toEqual('string');
881 expect(docE.children[2].firstChild.data).toEqual('Baum');
882 expect(docE.children[2].getAttribute('data-type')).toEqual('string');
883
884 expect(docElement.toJson()).toEqual(jasmine.objectContaining({
Akron712733a2018-04-05 18:17:47 +0200885 "@type" : "koral:doc",
886 "key":"Titel",
887 "value":"Baum",
888 "match":"match:eq"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000889 }));
890 });
Akronb19803c2018-08-16 16:39:42 +0200891
892
893 it('should be replacable by unspecified', function () {
894 var vc = vcClass.create([
895 ["pubDate", "date"]
896 ]).fromJson({
897 "@type" : "koral:doc",
898 "key":"Titel",
899 "value":"Baum",
900 "match":"match:eq"
901 });
hebastaa0282be2018-12-05 16:58:00 +0100902 KorAP.vc = vc;
Akronb19803c2018-08-16 16:39:42 +0200903 expect(vc.toQuery()).toEqual("Titel = \"Baum\"");
904
Akronadab5e52018-08-20 13:50:53 +0200905 var vcE = vc.builder();
Akronb19803c2018-08-16 16:39:42 +0200906 expect(vcE.firstChild.children.length).toEqual(4);
907
908 // Click to delete
909 vcE.firstChild.lastChild.lastChild.click();
910
911 expect(vcE.firstChild.children.length).toEqual(1);
912
Akronebc96662018-08-29 17:36:20 +0200913 expect(vcE.firstChild.textContent).toEqual(KorAP.Locale.EMPTY);
914 expect(vcE.firstChild.classList.contains("unspecified")).toBeTruthy();
Akronb19803c2018-08-16 16:39:42 +0200915 vcE.firstChild.firstChild.click();
916
917 // Click on pubDate
Akron3ad46942018-08-22 16:47:14 +0200918 vcE.firstChild.getElementsByTagName("LI")[1].click();
Akronb19803c2018-08-16 16:39:42 +0200919
920 expect(vcE.firstChild.firstChild.textContent).toEqual("pubDate");
921 expect(vcE.firstChild.children[1].getAttribute("data-type")).toEqual("date");
922
923 expect(vcE.firstChild.children.length).toEqual(4);
924 });
925
926
Akron587e4d92018-08-31 12:44:26 +0200927 it('should be replaceable by docGroupRef with deletion', function () {
Akron3ad46942018-08-22 16:47:14 +0200928 var vc = vcClass.create().fromJson({
Akronb19803c2018-08-16 16:39:42 +0200929 "@type" : "koral:doc",
930 "key":"Titel",
931 "value":"Baum",
932 "match":"match:eq"
933 });
934
hebastaa0282be2018-12-05 16:58:00 +0100935 KorAP.vc = vc;
Akronb19803c2018-08-16 16:39:42 +0200936 expect(vc.toQuery()).toEqual("Titel = \"Baum\"");
937
Akronadab5e52018-08-20 13:50:53 +0200938 var vcE = vc.builder();
Akronb19803c2018-08-16 16:39:42 +0200939 expect(vcE.firstChild.children.length).toEqual(4);
940
941 // Click to delete
942 vcE.firstChild.lastChild.lastChild.click();
943
944 expect(vcE.firstChild.children.length).toEqual(1);
945
Akronebc96662018-08-29 17:36:20 +0200946 expect(vcE.firstChild.textContent).toEqual(KorAP.Locale.EMPTY);
947 expect(vcE.firstChild.classList.contains('unspecified')).toEqual(true);
Akronb19803c2018-08-16 16:39:42 +0200948 vcE.firstChild.firstChild.click();
949
Akron3ad46942018-08-22 16:47:14 +0200950 // Click on referTo
Akronb19803c2018-08-16 16:39:42 +0200951 vcE.firstChild.getElementsByTagName("LI")[0].click();
952
Akron3ad46942018-08-22 16:47:14 +0200953 expect(vcE.firstChild.firstChild.textContent).toEqual("referTo");
Akronb19803c2018-08-16 16:39:42 +0200954 expect(vcE.firstChild.children[1].getAttribute("data-type")).toEqual("string");
Akron587e4d92018-08-31 12:44:26 +0200955
Akronb19803c2018-08-16 16:39:42 +0200956 expect(vcE.firstChild.children.length).toEqual(3);
Akron62ac95b2018-08-30 18:08:25 +0200957 expect(vcE.firstChild.children[1].classList.contains("unspecified")).toBeTruthy();
Akronb19803c2018-08-16 16:39:42 +0200958 });
Akron587e4d92018-08-31 12:44:26 +0200959
960
961 it('should be replaceable by docGroupRef on root', function () {
962 var vc = vcClass.create().fromJson({
963 "@type" : "koral:doc",
964 "key":"Titel",
965 "value":"Baum",
966 "match":"match:eq"
967 });
968
hebastaa0282be2018-12-05 16:58:00 +0100969 KorAP.vc = vc;
Akron587e4d92018-08-31 12:44:26 +0200970 expect(vc.toQuery()).toEqual("Titel = \"Baum\"");
971
972 var vcE = vc.builder();
973 expect(vcE.firstChild.children.length).toEqual(4);
974
975 // Click on the key
976 vcE.firstChild.firstChild.click();
977
978 expect(vcE.firstChild.getElementsByTagName("LI")[0].textContent).toEqual("referTo");
979
980 // Click on referTo
981 vcE.firstChild.getElementsByTagName("LI")[0].click();
982
983 // Now it's a referTo element
984 expect(vcE.firstChild.firstChild.textContent).toEqual("referTo");
985 expect(vcE.firstChild.children.length).toEqual(3);
986 expect(vcE.firstChild.children[1].classList.contains("unspecified")).toBeTruthy();
987 });
988
989 it('should be replaceable by docGroupRef nested', function () {
990 var vc = vcClass.create().fromJson({
991 "@type" : "koral:docGroup",
992 "operation" : "operation:and",
993 "operands" : [
994 {
995 "@type": 'koral:doc',
996 "key" : 'author',
997 "match": 'match:eq',
998 "value": 'Max Birkendale',
999 "type": 'type:string'
1000 },
1001 {
1002 "@type": 'koral:doc',
1003 "key": 'pubDate',
1004 "match": 'match:eq',
1005 "value": '2014-12-05',
1006 "type": 'type:date'
1007 }
1008 ]
1009 });
1010
hebastaa0282be2018-12-05 16:58:00 +01001011 KorAP.vc = vc;
Akron587e4d92018-08-31 12:44:26 +02001012 expect(vc.toQuery()).toEqual("author = \"Max Birkendale\" & pubDate in 2014-12-05");
1013
1014 var vcE = vc.builder();
1015
1016 // First doc
1017 var doc = vcE.firstChild.firstChild;
1018 expect(doc.children.length).toEqual(4);
1019
1020 // Click on the key
1021 doc.firstChild.click();
1022
1023 expect(doc.getElementsByTagName("LI")[0].textContent).toEqual("referTo");
1024
1025 // Click on referTo
1026 vcE.firstChild.getElementsByTagName("LI")[0].click();
1027
1028 // Now it's a referTo element
1029 expect(vcE.firstChild.firstChild.firstChild.textContent).toEqual("referTo");
1030 expect(vcE.firstChild.firstChild.children.length).toEqual(3);
1031 expect(vcE.firstChild.firstChild.children[1].classList.contains("unspecified")).toBeTruthy();
1032 });
Nils Diewald7c8ced22015-04-15 19:21:00 +00001033 });
1034
Akron88d237e2020-10-21 08:05:18 +02001035 describe('KorAP.VC.DocGroup element', function () {
Nils Diewald7c8ced22015-04-15 19:21:00 +00001036 it('should be initializable', function () {
1037
1038 var docGroup = docGroupClass.create(undefined, {
Akron712733a2018-04-05 18:17:47 +02001039 "@type" : "koral:docGroup",
1040 "operation" : "operation:and",
1041 "operands" : [
1042 {
1043 "@type": 'koral:doc',
1044 "key" : 'author',
1045 "match": 'match:eq',
1046 "value": 'Max Birkendale',
1047 "type": 'type:string'
1048 },
1049 {
1050 "@type": 'koral:doc',
1051 "key": 'pubDate',
1052 "match": 'match:eq',
1053 "value": '2014-12-05',
1054 "type": 'type:date'
1055 }
1056 ]
Nils Diewald7c8ced22015-04-15 19:21:00 +00001057 });
1058
1059 expect(docGroup.operation()).toEqual('and');
1060 var e = docGroup.element();
1061 expect(e.getAttribute('class')).toEqual('docGroup');
1062 expect(e.getAttribute('data-operation')).toEqual('and');
1063
1064 var first = e.children[0];
1065 expect(first.getAttribute('class')).toEqual('doc');
1066 expect(first.children[0].getAttribute('class')).toEqual('key');
1067 expect(first.children[1].getAttribute('class')).toEqual('match');
1068 expect(first.children[2].getAttribute('class')).toEqual('value');
1069 expect(first.children[2].getAttribute('data-type')).toEqual('string');
1070 expect(first.children[0].firstChild.data).toEqual('author');
1071 expect(first.children[1].firstChild.data).toEqual('eq');
1072 expect(first.children[2].firstChild.data).toEqual('Max Birkendale');
1073
1074 var second = e.children[1];
1075 expect(second.getAttribute('class')).toEqual('doc');
1076 expect(second.children[0].getAttribute('class')).toEqual('key');
1077 expect(second.children[1].getAttribute('class')).toEqual('match');
1078 expect(second.children[2].getAttribute('class')).toEqual('value');
1079 expect(second.children[2].getAttribute('data-type')).toEqual('date');
1080 expect(second.children[0].firstChild.data).toEqual('pubDate');
1081 expect(second.children[1].firstChild.data).toEqual('eq');
1082 expect(second.children[2].firstChild.data).toEqual('2014-12-05');
1083 });
1084
1085 it('should be deserializable with nested groups', function () {
1086 var docGroup = docGroupClass.create(undefined, {
Akron712733a2018-04-05 18:17:47 +02001087 "@type" : "koral:docGroup",
1088 "operation" : "operation:or",
1089 "operands" : [
1090 {
1091 "@type": 'koral:doc',
1092 "key" : 'author',
1093 "match": 'match:eq',
1094 "value": 'Max Birkendale',
1095 "type": 'type:string'
1096 },
1097 {
1098 "@type" : "koral:docGroup",
1099 "operation" : "operation:and",
1100 "operands" : [
1101 {
1102 "@type": 'koral:doc',
1103 "key": 'pubDate',
1104 "match": 'match:geq',
1105 "value": '2014-05-12',
1106 "type": 'type:date'
1107 },
1108 {
1109 "@type": 'koral:doc',
1110 "key": 'pubDate',
1111 "match": 'match:leq',
1112 "value": '2014-12-05',
1113 "type": 'type:date'
1114 }
1115 ]
1116 }
1117 ]
Nils Diewald7c8ced22015-04-15 19:21:00 +00001118 });
1119
1120 expect(docGroup.operation()).toEqual('or');
1121 var e = docGroup.element();
1122 expect(e.getAttribute('class')).toEqual('docGroup');
1123 expect(e.getAttribute('data-operation')).toEqual('or');
1124
1125 expect(e.children[0].getAttribute('class')).toEqual('doc');
1126 var docop = e.children[0].lastChild;
Akron0b489ad2018-02-02 16:49:32 +01001127 expect(docop.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001128 expect(docop.children[0].getAttribute('class')).toEqual('and');
1129 expect(docop.children[1].getAttribute('class')).toEqual('or');
1130 expect(docop.children[2].getAttribute('class')).toEqual('delete');
1131
1132 expect(e.children[1].getAttribute('class')).toEqual('docGroup');
1133 expect(e.children[1].getAttribute('data-operation')).toEqual('and');
1134
1135 // This and-operation can be "or"ed or "delete"d
1136 var secop = e.children[1].children[2];
Akron0b489ad2018-02-02 16:49:32 +01001137 expect(secop.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001138 expect(secop.children[0].getAttribute('class')).toEqual('or');
1139 expect(secop.children[1].getAttribute('class')).toEqual('delete');
1140
1141 // This or-operation can be "and"ed or "delete"d
Akron0b489ad2018-02-02 16:49:32 +01001142 expect(e.children[2].getAttribute('class')).toEqual('operators button-group');
1143 expect(e.lastChild.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001144 expect(e.lastChild.children[0].getAttribute('class')).toEqual('and');
1145 expect(e.lastChild.children[1].getAttribute('class')).toEqual('delete');
1146 });
1147 });
1148
Akron88d237e2020-10-21 08:05:18 +02001149 describe('KorAP.VC.DocGroupRef element', function () {
Akronb19803c2018-08-16 16:39:42 +02001150 it('should be initializable', function () {
1151 var docGroupRef = docGroupRefClass.create(undefined, {
1152 "@type" : "koral:docGroupRef",
1153 "ref" : "@franz/myVC1"
1154 });
1155 expect(docGroupRef.ref()).toEqual("@franz/myVC1");
1156 var dgrE = docGroupRef.element();
1157
Akron3ad46942018-08-22 16:47:14 +02001158 expect(dgrE.children[0].firstChild.data).toEqual("referTo");
Akronb19803c2018-08-16 16:39:42 +02001159 expect(dgrE.children[0].tagName).toEqual("SPAN");
1160 expect(dgrE.children[0].classList.contains("key")).toBeTruthy();
1161 expect(dgrE.children[0].classList.contains("fixed")).toBeTruthy();
1162 expect(dgrE.children[1].firstChild.data).toEqual("@franz/myVC1");
1163 expect(dgrE.children[1].tagName).toEqual("SPAN");
1164 expect(dgrE.children[1].classList.contains("value")).toBeTruthy();
1165 expect(dgrE.children[1].getAttribute("data-type")).toEqual("string");
1166 });
1167
1168 it('should be modifiable on reference', function () {
1169 var docGroupRef = docGroupRefClass.create(undefined, {
1170 "@type" : "koral:docGroupRef",
1171 "ref" : "@franz/myVC1"
1172 });
1173 var dgrE = docGroupRef.element();
1174 expect(docGroupRef.toQuery()).toEqual("referTo \"@franz/myVC1\"");
1175 dgrE.children[1].click();
1176
1177 var input = dgrE.children[1].firstChild;
1178 expect(input.tagName).toEqual("INPUT");
1179 input.value = "Versuch";
1180
1181 var event = new KeyboardEvent("keypress", {
1182 "key" : "[Enter]",
1183 "keyCode" : 13
1184 });
1185
1186 input.dispatchEvent(event);
1187 expect(docGroupRef.toQuery()).toEqual("referTo \"Versuch\"");
1188 });
1189 });
1190
1191
Akron88d237e2020-10-21 08:05:18 +02001192 describe('KorAP.VC.VirtualCorpus', function () {
Nils Diewald7c8ced22015-04-15 19:21:00 +00001193 var simpleGroupFactory = buildFactory(docGroupClass, {
1194 "@type" : "koral:docGroup",
1195 "operation" : "operation:and",
1196 "operands" : [
Akron712733a2018-04-05 18:17:47 +02001197 {
1198 "@type": 'koral:doc',
1199 "key" : 'author',
1200 "match": 'match:eq',
1201 "value": 'Max Birkendale',
1202 "type": 'type:string'
1203 },
1204 {
1205 "@type": 'koral:doc',
1206 "key": 'pubDate',
1207 "match": 'match:eq',
1208 "value": '2014-12-05',
1209 "type": 'type:date'
1210 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00001211 ]
1212 });
1213
1214 var nestedGroupFactory = buildFactory(vcClass, {
1215 "@type" : "koral:docGroup",
1216 "operation" : "operation:or",
1217 "operands" : [
Akron712733a2018-04-05 18:17:47 +02001218 {
1219 "@type": 'koral:doc',
1220 "key" : 'author',
1221 "match": 'match:eq',
1222 "value": 'Max Birkendale',
1223 "type": 'type:string'
1224 },
1225 {
1226 "@type" : "koral:docGroup",
1227 "operation" : "operation:and",
1228 "operands" : [
1229 {
1230 "@type": 'koral:doc',
1231 "key": 'pubDate',
1232 "match": 'match:geq',
1233 "value": '2014-05-12',
1234 "type": 'type:date'
1235 },
1236 {
1237 "@type": 'koral:doc',
1238 "key": 'pubDate',
1239 "match": 'match:leq',
1240 "value": '2014-12-05',
1241 "type": 'type:date'
1242 }
1243 ]
1244 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00001245 ]
1246 });
1247
1248 var flatGroupFactory = buildFactory(vcClass, {
1249 "@type" : "koral:docGroup",
1250 "operation" : "operation:and",
1251 "operands" : [
Akron712733a2018-04-05 18:17:47 +02001252 {
1253 "@type": 'koral:doc',
1254 "key": 'pubDate',
1255 "match": 'match:geq',
1256 "value": '2014-05-12',
1257 "type": 'type:date'
1258 },
1259 {
1260 "@type": 'koral:doc',
1261 "key": 'pubDate',
1262 "match": 'match:leq',
1263 "value": '2014-12-05',
1264 "type": 'type:date'
1265 },
1266 {
1267 "@type": 'koral:doc',
1268 "key": 'foo',
1269 "match": 'match:eq',
1270 "value": 'bar',
1271 "type": 'type:string'
1272 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00001273 ]
1274 });
1275
1276 it('should be initializable', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00001277 var vc = vcClass.create();
Nils Diewald7c8ced22015-04-15 19:21:00 +00001278 expect(vc.element().getAttribute('class')).toEqual('vc');
1279 expect(vc.root().element().getAttribute('class')).toEqual('doc unspecified');
1280
1281 // Not removable
1282 expect(vc.root().element().lastChild.children.length).toEqual(0);
1283 });
1284
1285 it('should be based on a doc', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00001286 var vc = vcClass.create().fromJson({
Akron712733a2018-04-05 18:17:47 +02001287 "@type" : "koral:doc",
1288 "key":"Titel",
1289 "value":"Baum",
1290 "match":"match:eq"
Nils Diewald7c8ced22015-04-15 19:21:00 +00001291 });
1292
1293 expect(vc.element().getAttribute('class')).toEqual('vc');
1294 expect(vc.root().element().getAttribute('class')).toEqual('doc');
1295 expect(vc.root().key()).toEqual('Titel');
1296 expect(vc.root().value()).toEqual('Baum');
1297 expect(vc.root().matchop()).toEqual('eq');
1298
1299 var docE = vc.root().element();
1300 expect(docE.children[0].firstChild.data).toEqual('Titel');
1301 expect(docE.children[1].firstChild.data).toEqual('eq');
1302 expect(docE.children[1].getAttribute('data-type')).toEqual('string');
1303 expect(docE.children[2].firstChild.data).toEqual('Baum');
1304 expect(docE.children[2].getAttribute('data-type')).toEqual('string');
1305 });
1306
1307 it('should be based on a docGroup', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00001308 var vc = vcClass.create().fromJson(simpleGroupFactory.create().toJson());
Nils Diewald7c8ced22015-04-15 19:21:00 +00001309
1310 expect(vc.element().getAttribute('class')).toEqual('vc');
1311 expect(vc.root().element().getAttribute('class')).toEqual('docGroup');
1312 expect(vc.root().operation()).toEqual('and');
1313
1314 var docGroup = vc.root();
1315
1316 var first = docGroup.getOperand(0);
1317 expect(first.key()).toEqual('author');
1318 expect(first.value()).toEqual('Max Birkendale');
1319 expect(first.matchop()).toEqual('eq');
1320
1321 var second = docGroup.getOperand(1);
1322 expect(second.key()).toEqual('pubDate');
1323 expect(second.value()).toEqual('2014-12-05');
1324 expect(second.matchop()).toEqual('eq');
1325 });
1326
Akronb19803c2018-08-16 16:39:42 +02001327 it('should be based on a docGroupRef', function () {
1328 var vc = vcClass.create().fromJson({
1329 "@type" : "koral:docGroupRef",
1330 "ref":"myCorpus"
1331 });
1332
Akronadab5e52018-08-20 13:50:53 +02001333 // iv class="doc groupref"><span class="key fixed">@referTo</span><span data-type="string" class="value">myCorpus</span>
1334 var vcE = vc.builder();
1335 expect(vcE.getAttribute('class')).toEqual('builder');
Akronb19803c2018-08-16 16:39:42 +02001336 expect(vcE.firstChild.tagName).toEqual('DIV');
1337 expect(vcE.firstChild.classList.contains('groupref')).toBeTruthy();
1338
1339 expect(vcE.firstChild.firstChild.tagName).toEqual('SPAN');
1340 expect(vcE.firstChild.firstChild.classList.contains('key')).toBeTruthy();
1341 expect(vcE.firstChild.firstChild.classList.contains('fixed')).toBeTruthy();
1342
Akron3ad46942018-08-22 16:47:14 +02001343 expect(vcE.firstChild.firstChild.textContent).toEqual("referTo");
Akronb19803c2018-08-16 16:39:42 +02001344
1345 expect(vcE.firstChild.children[1].tagName).toEqual('SPAN');
1346 expect(vcE.firstChild.children[1].classList.contains('value')).toBeTruthy();
1347 expect(vcE.firstChild.children[1].getAttribute('data-type')).toEqual('string');
1348 expect(vcE.firstChild.children[1].textContent).toEqual("myCorpus");
1349 });
Akron0f00b772020-12-02 17:32:13 +01001350
Nils Diewald7c8ced22015-04-15 19:21:00 +00001351 it('should be based on a nested docGroup', function () {
1352 var vc = nestedGroupFactory.create();
1353
Akronadab5e52018-08-20 13:50:53 +02001354 expect(vc.builder().getAttribute('class')).toEqual('builder');
1355 expect(vc.builder().firstChild.getAttribute('class')).toEqual('docGroup');
1356 expect(vc.builder().firstChild.children[0].getAttribute('class')).toEqual('doc');
1357 var dg = vc.builder().firstChild.children[1];
Nils Diewald7c8ced22015-04-15 19:21:00 +00001358 expect(dg.getAttribute('class')).toEqual('docGroup');
1359 expect(dg.children[0].getAttribute('class')).toEqual('doc');
1360 expect(dg.children[1].getAttribute('class')).toEqual('doc');
Akron0b489ad2018-02-02 16:49:32 +01001361 expect(dg.children[2].getAttribute('class')).toEqual('operators button-group');
Akronadab5e52018-08-20 13:50:53 +02001362 expect(vc.builder().firstChild.children[2].getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001363 });
1364
Akronb19803c2018-08-16 16:39:42 +02001365 it('should be based on a nested docGroupRef', function () {
1366 var vc = vcClass.create().fromJson({
1367 "@type" : "koral:docGroup",
1368 "operation" : "operation:and",
1369 "operands" : [{
1370 "@type" : "koral:docGroupRef",
1371 "ref":"myCorpus"
1372 },{
1373 "@type" : "koral:doc",
1374 "key":"Titel",
1375 "value":"Baum",
1376 "match":"match:eq"
1377 }]
1378 });
1379
1380 expect(vc._root.ldType()).toEqual("docGroup");
1381
1382 expect(vc.toQuery()).toEqual('referTo "myCorpus" & Titel = "Baum"');
1383 });
1384
Akron0f00b772020-12-02 17:32:13 +01001385 it('should accept an undefined KorAP.vc', function () {
1386 let temp = KorAP.vc;
1387 KorAP.vc = undefined;
1388 const vc = vcClass.create().fromJson({
1389 "@type" : "koral:docGroup",
1390 "operation" : "operation:and",
1391 "operands" : [{
1392 "@type" : "koral:docGroupRef",
1393 "ref":"myCorpus"
1394 },{
1395 "@type" : "koral:doc",
1396 "key":"Titel",
1397 "value":"Baum",
1398 "match":"match:eq"
1399 }]
1400 });
1401
1402 expect(vc._root.ldType()).toEqual("docGroup");
1403 expect(vc.toQuery()).toEqual('referTo "myCorpus" & Titel = "Baum"');
1404
1405 KorAP.vc = temp;
1406 });
Akronb19803c2018-08-16 16:39:42 +02001407
Nils Diewald7c8ced22015-04-15 19:21:00 +00001408 it('should be modifiable by deletion in flat docGroups', function () {
1409 var vc = flatGroupFactory.create();
1410 var docGroup = vc.root();
1411
1412 expect(docGroup.element().getAttribute('class')).toEqual('docGroup');
1413
1414 var doc = docGroup.getOperand(1);
1415 expect(doc.key()).toEqual("pubDate");
1416 expect(doc.value()).toEqual("2014-12-05");
1417
1418 // Remove operand 1
1419 expect(docGroup.delOperand(doc).update()).not.toBeUndefined();
Akron24aa0052020-11-10 11:00:34 +01001420 expect(doc._el).toEqual(undefined);
Nils Diewald7c8ced22015-04-15 19:21:00 +00001421
1422 doc = docGroup.getOperand(1);
1423 expect(doc.key()).toEqual("foo");
1424
1425 // Remove operand 1
1426 expect(docGroup.delOperand(doc).update()).not.toBeUndefined();
Akron24aa0052020-11-10 11:00:34 +01001427 expect(doc._el).toEqual(undefined);
Nils Diewald7c8ced22015-04-15 19:21:00 +00001428
1429 // Only one operand left ...
1430 expect(docGroup.getOperand(1)).toBeUndefined();
1431 // ... but there shouldn't be a group anymore at all!
1432 expect(docGroup.getOperand(0)).toBeUndefined();
1433
1434 var obj = vc.root();
1435 expect(obj.ldType()).toEqual("doc");
1436 expect(obj.key()).toEqual("pubDate");
1437 expect(obj.value()).toEqual("2014-05-12");
1438
1439 expect(obj.element().getAttribute('class')).toEqual('doc');
1440 });
1441
1442
1443 it('should be modifiable by deletion in nested docGroups (root case)', function () {
1444 var vc = nestedGroupFactory.create();
1445
1446 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001447 'author = "Max Birkendale" | (pubDate since 2014-05-12 & pubDate until 2014-12-05)'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001448 );
1449
1450 var docGroup = vc.root();
1451 expect(docGroup.ldType()).toEqual("docGroup");
1452 expect(docGroup.operation()).toEqual("or");
1453
1454 var doc = docGroup.getOperand(0);
1455 expect(doc.key()).toEqual("author");
1456 expect(doc.value()).toEqual("Max Birkendale");
1457
1458 docGroup = docGroup.getOperand(1);
1459 expect(docGroup.operation()).toEqual("and");
1460
1461 doc = docGroup.getOperand(0);
1462 expect(doc.key()).toEqual("pubDate");
1463 expect(doc.matchop()).toEqual("geq");
1464 expect(doc.value()).toEqual("2014-05-12");
1465 expect(doc.type()).toEqual("date");
1466
1467 doc = docGroup.getOperand(1);
1468 expect(doc.key()).toEqual("pubDate");
1469 expect(doc.matchop()).toEqual("leq");
1470 expect(doc.value()).toEqual("2014-12-05");
1471 expect(doc.type()).toEqual("date");
1472
1473 // Remove first operand so everything becomes root
1474 expect(
Akron712733a2018-04-05 18:17:47 +02001475 vc.root().delOperand(
1476 vc.root().getOperand(0)
1477 ).update().ldType()
Nils Diewald7c8ced22015-04-15 19:21:00 +00001478 ).toEqual("docGroup");
1479
1480 expect(vc.root().ldType()).toEqual("docGroup");
1481 expect(vc.root().operation()).toEqual("and");
1482 expect(vc.root().getOperand(0).ldType()).toEqual("doc");
1483
1484 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001485 'pubDate since 2014-05-12 & pubDate until 2014-12-05'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001486 );
1487 });
1488
1489 it('should be modifiable by deletion in nested docGroups (resolve group case)', function () {
1490 var vc = nestedGroupFactory.create();
1491
1492 // Get nested group
1493 var firstGroup = vc.root().getOperand(1);
1494 firstGroup.append(simpleGroupFactory.create({ "operation" : "operation:or" }));
1495
1496 // Structur is now:
1497 // or(doc, and(doc, doc, or(doc, doc)))
1498
1499 // Get nested or in and
1500 var orGroup = vc.root().getOperand(1).getOperand(2);
1501 expect(orGroup.ldType()).toEqual("docGroup");
1502 expect(orGroup.operation()).toEqual("or");
1503
1504 // Remove
1505 // Structur is now:
1506 // or(doc, and(doc, doc, doc)))
1507 expect(orGroup.delOperand(orGroup.getOperand(0)).update().operation()).toEqual("and");
1508 expect(vc.root().getOperand(1).operands().length).toEqual(3);
1509 });
1510
1511 it('should be modifiable by deletion in nested docGroups (identical group case)', function () {
1512 var vc = nestedGroupFactory.create();
1513
1514 // Get nested group
1515 var firstGroup = vc.root().getOperand(1);
1516 firstGroup.append(simpleGroupFactory.create({
Akron712733a2018-04-05 18:17:47 +02001517 "operation" : "operation:or"
Nils Diewald7c8ced22015-04-15 19:21:00 +00001518 }));
1519 var oldAuthor = firstGroup.getOperand(2).getOperand(0);
1520 oldAuthor.key("title");
1521 oldAuthor.value("Der Birnbaum");
1522
1523 // Structur is now:
1524 // or(doc, and(doc, doc, or(doc, doc)))
1525 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001526 'author = "Max Birkendale" | ' +
1527 '(pubDate since 2014-05-12 & ' +
1528 'pubDate until 2014-12-05 & ' +
1529 '(title = "Der Birnbaum" | ' +
1530 'pubDate in 2014-12-05))'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001531 );
1532
1533 var andGroup = vc.root().getOperand(1);
1534
1535 // Get leading docs in and
1536 var doc1 = andGroup.getOperand(0);
1537 expect(doc1.ldType()).toEqual("doc");
1538 expect(doc1.value()).toEqual("2014-05-12");
1539 var doc2 = andGroup.getOperand(1);
1540 expect(doc2.ldType()).toEqual("doc");
1541 expect(doc2.value()).toEqual("2014-12-05");
1542
1543 // Remove 2
1544 expect(
Akron712733a2018-04-05 18:17:47 +02001545 andGroup.delOperand(doc2).update().operation()
Nils Diewald7c8ced22015-04-15 19:21:00 +00001546 ).toEqual("and");
1547 // Structur is now:
1548 // or(doc, and(doc, or(doc, doc)))
1549
1550 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001551 'author = "Max Birkendale"' +
1552 ' | (pubDate since 2014-05-12 & ' +
1553 '(title = "Der Birnbaum" | pubDate in 2014-12-05))'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001554 );
1555
1556
1557 // Remove 1
1558 expect(andGroup.delOperand(doc1).update().operation()).toEqual("or");
1559 // Structur is now:
1560 // or(doc, doc, doc)
1561
1562 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001563 'author = "Max Birkendale" | title = "Der Birnbaum" | pubDate in 2014-12-05'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001564 );
1565 });
1566
1567 it('should be reducible to unspecification', function () {
1568 var vc = demoFactory.create();
1569
1570 expect(vc.toQuery()).toEqual(vc.root().toQuery());
1571 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001572 '(Titel = "Baum" & Veröffentlichungsort = "hihi" & ' +
1573 '(Titel = "Baum" | Veröffentlichungsort = "hihi")) ' +
1574 '| Untertitel ~ "huhu"');
Akrond141a362018-07-10 18:12:13 +02001575 expect(vc.root().element().lastChild.children[0].innerText).toEqual('and');
1576 expect(vc.root().element().lastChild.children[1].innerText).toEqual('×');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001577 expect(vc.root().delOperand(vc.root().getOperand(0)).update()).not.toBeUndefined();
Akron712733a2018-04-05 18:17:47 +02001578 expect(vc.toQuery()).toEqual('Untertitel ~ "huhu"');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001579
1580 var lc = vc.root().element().lastChild;
Akrond141a362018-07-10 18:12:13 +02001581 expect(lc.children[0].innerText).toEqual('and');
1582 expect(lc.children[1].innerText).toEqual('or');
1583 expect(lc.children[2].innerText).toEqual('×');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001584
1585 // Clean everything
1586 vc.clean();
1587 expect(vc.toQuery()).toEqual('');
1588 });
1589
1590 it('should flatten on import', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00001591 var vc = vcClass.create().fromJson({
Akron712733a2018-04-05 18:17:47 +02001592 "@type":"koral:docGroup",
1593 "operation":"operation:or",
1594 "operands":[
1595 {
1596 "@type":"koral:docGroup",
1597 "operation":"operation:or",
1598 "operands":[
Nils Diewald7c8ced22015-04-15 19:21:00 +00001599 {
Akron712733a2018-04-05 18:17:47 +02001600 "@type":"koral:doc",
1601 "key":"Titel",
1602 "value":"Baum",
1603 "match":"match:eq"
Nils Diewald7c8ced22015-04-15 19:21:00 +00001604 },
1605 {
Akron712733a2018-04-05 18:17:47 +02001606 "@type":"koral:doc",
1607 "key":"Veröffentlichungsort",
1608 "value":"hihi",
1609 "match":"match:eq"
Nils Diewald7c8ced22015-04-15 19:21:00 +00001610 },
1611 {
Akron712733a2018-04-05 18:17:47 +02001612 "@type":"koral:docGroup",
1613 "operation":"operation:or",
1614 "operands":[
1615 {
1616 "@type":"koral:doc",
1617 "key":"Titel",
1618 "value":"Baum",
1619 "match":"match:eq"
1620 },
1621 {
1622 "@type":"koral:doc",
1623 "key":"Veröffentlichungsort",
1624 "value":"hihi",
1625 "match":"match:eq"
1626 }
1627 ]
Nils Diewald7c8ced22015-04-15 19:21:00 +00001628 }
Akron712733a2018-04-05 18:17:47 +02001629 ]
1630 },
1631 {
1632 "@type":"koral:doc",
1633 "key":"Untertitel",
1634 "value":"huhu",
1635 "match":"match:contains"
1636 }
1637 ]
Nils Diewald7c8ced22015-04-15 19:21:00 +00001638 });
Nils Diewaldfda29d92015-01-22 17:28:01 +00001639
Nils Diewald7c8ced22015-04-15 19:21:00 +00001640 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001641 'Titel = "Baum" | Veröffentlichungsort = "hihi" | Untertitel ~ "huhu"'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001642 );
Nils Diewald86dad5b2015-01-28 15:09:07 +00001643 });
Akron1bdf5272018-07-24 18:51:30 +02001644
Akroncd42a142019-07-12 18:55:37 +02001645 it('should be deserializable from collection/corpus 1', function () {
Akron1bdf5272018-07-24 18:51:30 +02001646 var kq = {
1647 "matches":["..."],
1648 "collection":{
1649 "@type": "koral:docGroup",
1650 "operation": "operation:or",
1651 "operands": [{
1652 "@type": "koral:docGroup",
1653 "operation": "operation:and",
1654 "operands": [
1655 {
1656 "@type": "koral:doc",
1657 "key": "title",
1658 "match": "match:eq",
1659 "value": "Der Birnbaum",
1660 "type": "type:string"
1661 },
1662 {
1663 "@type": "koral:doc",
1664 "key": "pubPlace",
1665 "match": "match:eq",
1666 "value": "Mannheim",
1667 "type": "type:string"
1668 },
1669 {
1670 "@type": "koral:docGroup",
1671 "operation": "operation:or",
1672 "operands": [
1673 {
1674 "@type": "koral:doc",
1675 "key": "subTitle",
1676 "match": "match:eq",
1677 "value": "Aufzucht und Pflege",
1678 "type": "type:string"
1679 },
1680 {
1681 "@type": "koral:doc",
1682 "key": "subTitle",
1683 "match": "match:eq",
1684 "value": "Gedichte",
1685 "type": "type:string"
1686 }
1687 ]
1688 }
1689 ]
1690 },{
1691 "@type": "koral:doc",
1692 "key": "pubDate",
1693 "match": "match:geq",
1694 "value": "2015-03-05",
1695 "type": "type:date",
1696 "rewrites" : [{
1697 "@type" : "koral:rewrite",
1698 "operation" : "operation:modification",
1699 "src" : "querySerializer",
1700 "scope" : "tree"
1701 }]
1702 }]
1703 }
1704 };
1705
1706 var vc = vcClass.create().fromJson(kq["collection"]);
1707 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 +02001708
1709 kq["corpus"] = kq["collection"]
1710 delete kq["collection"]
1711
1712 vc = vcClass.create().fromJson(kq["corpus"]);
1713 expect(vc.toQuery()).toEqual('(title = "Der Birnbaum" & pubPlace = "Mannheim" & (subTitle = "Aufzucht und Pflege" | subTitle = "Gedichte")) | pubDate since 2015-03-05');
1714
Akron1bdf5272018-07-24 18:51:30 +02001715 });
1716
1717 it('should be deserializable from collection 2', function () {
1718 var kq = {
1719 "@context": "http://korap.ids-mannheim.de/ns/KoralQuery/v0.3/context.jsonld",
1720 "meta": {},
1721 "query": {
1722 "@type": "koral:token",
1723 "wrap": {
1724 "@type": "koral:term",
1725 "match": "match:eq",
1726 "layer": "orth",
1727 "key": "Baum",
1728 "foundry": "opennlp",
1729 "rewrites": [
1730 {
1731 "@type": "koral:rewrite",
1732 "src": "Kustvakt",
1733 "operation": "operation:injection",
1734 "scope": "foundry"
1735 }
1736 ]
1737 },
1738 "idn": "Baum_2227",
1739 "rewrites": [
1740 {
1741 "@type": "koral:rewrite",
1742 "src": "Kustvakt",
1743 "operation": "operation:injection",
1744 "scope": "idn"
1745 }
1746 ]
1747 },
1748 "collection": {
1749 "@type": "koral:docGroup",
1750 "operation": "operation:and",
1751 "operands": [
1752 {
1753 "@type": "koral:doc",
1754 "match": "match:eq",
1755 "type": "type:regex",
1756 "value": "CC-BY.*",
1757 "key": "availability"
1758 },
1759 {
1760 "@type": "koral:doc",
1761 "match": "match:eq",
1762 "type":"type:text",
1763 "value": "Goethe",
1764 "key": "author"
1765 }
1766 ],
1767 "rewrites": [
1768 {
1769 "@type": "koral:rewrite",
1770 "src": "Kustvakt",
1771 "operation": "operation:insertion",
1772 "scope": "availability(FREE)"
1773 }
1774 ]
1775 },
1776 "matches": []
1777 };
1778
1779 var vc = vcClass.create().fromJson(kq["collection"]);
1780 expect(vc.toQuery()).toEqual('availability = /CC-BY.*/ & author = "Goethe"');
1781 });
Nils Diewald86dad5b2015-01-28 15:09:07 +00001782
Akroncd42a142019-07-12 18:55:37 +02001783
Akron8a670162018-08-28 10:09:13 +02001784 it('shouldn\'t be deserializable from collection with unknown type', function () {
1785 var kq = {
1786 "@type" : "koral:doc",
1787 "match": "match:eq",
1788 "type":"type:failure",
1789 "value": "Goethe",
1790 "key": "author"
1791 };
Akron1bdf5272018-07-24 18:51:30 +02001792
Akron8a670162018-08-28 10:09:13 +02001793 expect(function () {
1794 vcClass.create().fromJson(kq)
1795 }).toThrow(new Error("Unknown value type: string"));
1796 });
1797
1798 it('should return a name', function () {
1799 var vc = vcClass.create();
1800 expect(vc.getName()).toEqual(KorAP.Locale.VC_allCorpora);
1801
1802 vc = vcClass.create().fromJson({"@type" : "koral:docGroupRef", "ref" : "DeReKo"});
1803 expect(vc.getName()).toEqual("DeReKo");
1804
1805 vc = vcClass.create().fromJson({"@type" : "koral:doc", "key" : "author", "value" : "Peter"});
1806 expect(vc.getName()).toEqual(KorAP.Locale.VC_oneCollection);
1807 });
Akrond2474aa2018-08-28 12:06:27 +02001808
1809 it('should check for rewrites', function () {
1810
1811 var vc = vcClass.create().fromJson({
1812 "@type" : "koral:doc",
1813 "key" : "author",
1814 "value" : "Goethe",
1815 "rewrites" : [{
1816 "@type" : "koral:rewrite",
1817 "operation" : "operation:modification",
1818 "src" : "querySerializer",
1819 "scope" : "value"
1820 }]
1821 });
1822 expect(vc.wasRewritten()).toBeTruthy();
1823
1824 var nested = {
1825 "@type" : "koral:docGroup",
1826 "operation" : "operation:or",
1827 "operands" : [
1828 {
1829 "@type" : "koral:doc",
1830 "key" : "author",
1831 "value" : "Goethe"
1832 },
1833 {
1834 "@type" : "koral:docGroup",
1835 "operation" : "operation:and",
1836 "operands" : [
1837 {
1838 "@type": "koral:doc",
1839 "key" : "author",
1840 "value" : "Schiller"
1841 },
1842 {
1843 "@type": "koral:doc",
1844 "key" : "author",
1845 "value" : "Fontane"
1846 }
1847 ]
1848 }
1849 ]
1850 };
1851 vc = vcClass.create().fromJson(nested);
1852 expect(vc.wasRewritten()).toBe(false);
1853
1854 nested["operands"][1]["operands"][1]["rewrites"] = [{
1855 "@type" : "koral:rewrite",
1856 "operation" : "operation:modification",
1857 "src" : "querySerializer",
1858 "scope" : "tree"
1859 }];
1860 vc = vcClass.create().fromJson(nested);
1861 expect(vc.wasRewritten()).toBeTruthy();
1862 });
Akron4feec9d2018-11-20 17:00:50 +01001863
1864 it('should add document at virtual corpus', function () {
1865 vc = vcClass.create();
1866 expect(vc.toQuery()).toEqual("");
1867
1868 let doc = docClass.create();
1869 doc.key("author");
1870 doc.type("string");
1871 doc.matchop("eq");
1872 doc.value("Goethe");
1873 expect(doc.toQuery()).toEqual('author = "Goethe"');
1874
1875 expect(vc.element().firstChild.children.length).toEqual(1);
1876 expect(vc.element().firstChild.firstChild.classList.contains("unspecified")).toBeTruthy();
1877
1878 vc.addRequired(doc);
1879 expect(vc.toQuery()).toEqual('author = "Goethe"');
1880
1881 expect(vc.element().firstChild.children.length).toEqual(1);
1882 expect(vc.element().firstChild.firstChild.classList.contains("doc")).toBeTruthy();
1883
1884 // Add as 'and' to doc
1885 let doc2 = docClass.create();
1886 doc2.key("author");
1887 doc2.type("string");
1888 doc2.matchop("eq");
1889 doc2.value("Schiller");
1890 vc.addRequired(doc2);
1891 expect(vc.toQuery()).toEqual('author = "Goethe" & author = "Schiller"');
1892
1893 expect(vc.element().firstChild.firstChild.classList.contains("docGroup")).toBeTruthy();
1894 expect(vc.element().firstChild.firstChild.children[0].classList.contains("doc")).toBeTruthy();
1895 expect(vc.element().firstChild.firstChild.children[1].classList.contains("doc")).toBeTruthy();
1896
1897
1898 // Add as 'and' to 'and'-docGroup
1899 let doc3 = docClass.create();
1900 doc3.key("author");
1901 doc3.type("string");
1902 doc3.matchop("eq");
1903 doc3.value("Fontane");
1904 vc.addRequired(doc3);
1905 expect(vc.toQuery()).toEqual('author = "Goethe" & author = "Schiller" & author = "Fontane"');
1906
1907 expect(vc.element().firstChild.firstChild.classList.contains("docGroup")).toBeTruthy();
1908 expect(vc.element().firstChild.firstChild.children[0].classList.contains("doc")).toBeTruthy();
1909 expect(vc.element().firstChild.firstChild.children[1].classList.contains("doc")).toBeTruthy();
1910 expect(vc.element().firstChild.firstChild.children[2].classList.contains("doc")).toBeTruthy();
1911
1912 // Add as 'and' to 'or'-docGroup
1913 vc = vcClass.create().fromJson({
1914 "@type" : 'koral:docGroup',
1915 'operation' : 'operation:or',
1916 'operands' : [
1917 {
1918 '@type' : 'koral:doc',
1919 'key' : 'title',
1920 'value' : 'Hello World!'
1921 },
1922 {
1923 '@type' : 'koral:doc',
1924 'key' : 'foo',
1925 'value' : 'bar'
1926 }
1927 ]
1928 });
1929 expect(vc.toQuery()).toEqual('title = "Hello World!" | foo = "bar"');
1930
1931 let doc4 = docClass.create();
1932 doc4.key("author");
1933 doc4.type("string");
1934 doc4.matchop("eq");
1935 doc4.value("Fontane");
1936 vc.addRequired(doc4);
1937 expect(vc.toQuery()).toEqual('(title = "Hello World!" | foo = "bar") & author = "Fontane"');
1938
1939 // Add as 'and' to 'or'-docGroup
1940 vc = vcClass.create().fromJson({
1941 "@type" : "koral:docGroupRef",
1942 "ref" : "@max/myCorpus"
1943 })
1944 let doc5 = docClass.create();
1945 doc5.key("author");
1946 doc5.type("string");
1947 doc5.matchop("eq");
1948 doc5.value("Goethe");
1949 expect(doc5.toQuery()).toEqual('author = "Goethe"');
1950 vc.addRequired(doc5);
1951 expect(vc.toQuery()).toEqual('referTo "@max/myCorpus" & author = "Goethe"');
1952 });
Akron13af2f42019-07-25 15:06:21 +02001953
1954 it('should be replaceble via JSON', function () {
1955 let vc = KorAP.vc = vcClass.create().fromJson({
1956 "@type" : 'koral:docGroup',
1957 'operation' : 'operation:or',
1958 'operands' : [
1959 {
1960 '@type' : 'koral:doc',
1961 'key' : 'title',
1962 'value' : 'Hello World!'
1963 },
1964 {
1965 '@type' : 'koral:doc',
1966 'key' : 'foo',
1967 'value' : 'bar'
1968 }
1969 ]
1970 });
1971
1972 expect(vc.toQuery()).toEqual('title = "Hello World!" | foo = "bar"')
1973
1974 let e = vc.element();
1975 expect(e.firstChild.firstChild.firstChild.children[0].textContent).toEqual("title");
1976 expect(e.firstChild.firstChild.firstChild.children[2].textContent).toEqual("Hello World!");
1977
1978 vc.fromJson({
1979 '@type' : 'koral:doc',
1980 'key' : 'foo',
1981 'value' : 'bar'
1982 });
1983
1984 expect(vc.toQuery()).toEqual('foo = "bar"');
1985 e = vc.element();
1986 expect(e.firstChild.firstChild.children[0].textContent).toEqual("foo");
1987 expect(e.firstChild.firstChild.children[2].textContent).toEqual("bar");
1988 })
Akron1bdf5272018-07-24 18:51:30 +02001989 });
1990
1991
Akron88d237e2020-10-21 08:05:18 +02001992 describe('KorAP.VC.Operators', function () {
Nils Diewald7c8ced22015-04-15 19:21:00 +00001993 it('should be initializable', function () {
1994 var op = operatorsClass.create(true, false, false);
1995 expect(op.and()).toBeTruthy();
1996 expect(op.or()).not.toBeTruthy();
1997 expect(op.del()).not.toBeTruthy();
1998
1999 op.and(false);
2000 expect(op.and()).not.toBeTruthy();
2001 expect(op.or()).not.toBeTruthy();
2002 expect(op.del()).not.toBeTruthy();
2003
2004 op.or(true);
2005 op.del(true);
2006 expect(op.and()).not.toBeTruthy();
2007 expect(op.or()).toBeTruthy();
2008 expect(op.del()).toBeTruthy();
2009
Akrond141a362018-07-10 18:12:13 +02002010 var e = op.update();
Akron0b489ad2018-02-02 16:49:32 +01002011 expect(e.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +00002012 expect(e.children[0].getAttribute('class')).toEqual('or');
Akrond141a362018-07-10 18:12:13 +02002013 expect(e.children[0].innerText).toEqual('or');
Nils Diewald7c8ced22015-04-15 19:21:00 +00002014 expect(e.children[1].getAttribute('class')).toEqual('delete');
Akrond141a362018-07-10 18:12:13 +02002015 expect(e.children[1].innerText).toEqual('×');
Nils Diewald7c8ced22015-04-15 19:21:00 +00002016
2017 op.and(true);
2018 op.del(false);
Akrond141a362018-07-10 18:12:13 +02002019 e = op.update();
Nils Diewald7c8ced22015-04-15 19:21:00 +00002020
Akron0b489ad2018-02-02 16:49:32 +01002021 expect(e.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +00002022 expect(e.children[0].getAttribute('class')).toEqual('and');
Akrond141a362018-07-10 18:12:13 +02002023 expect(e.children[0].innerText).toEqual('and');
Nils Diewald7c8ced22015-04-15 19:21:00 +00002024 expect(e.children[1].getAttribute('class')).toEqual('or');
Akrond141a362018-07-10 18:12:13 +02002025 expect(e.children[1].innerText).toEqual('or');
Nils Diewald7c8ced22015-04-15 19:21:00 +00002026 });
2027 });
2028
Akron88d237e2020-10-21 08:05:18 +02002029 describe('KorAP.VC._delete (event)', function () {
Nils Diewald7c8ced22015-04-15 19:21:00 +00002030 var complexVCFactory = buildFactory(vcClass,{
2031 "@type": 'koral:docGroup',
2032 'operation' : 'operation:and',
2033 'operands' : [
Akron712733a2018-04-05 18:17:47 +02002034 {
2035 "@type": 'koral:doc',
2036 "key": 'pubDate',
2037 "match": 'match:eq',
2038 "value": '2014-12-05',
2039 "type": 'type:date'
2040 },
2041 {
2042 "@type" : 'koral:docGroup',
2043 'operation' : 'operation:or',
2044 'operands' : [
2045 {
2046 '@type' : 'koral:doc',
2047 'key' : 'title',
2048 'value' : 'Hello World!'
2049 },
2050 {
2051 '@type' : 'koral:doc',
2052 'key' : 'foo',
2053 'value' : 'bar'
2054 }
2055 ]
2056 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00002057 ]
2058 });
2059
2060 it('should clean on root docs', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00002061 var vc = vcClass.create().fromJson({
Akron712733a2018-04-05 18:17:47 +02002062 "@type": 'koral:doc',
2063 "key": 'pubDate',
2064 "match": 'match:eq',
2065 "value": '2014-12-05',
2066 "type": 'type:date'
Nils Diewald86dad5b2015-01-28 15:09:07 +00002067 });
Nils Diewald7c8ced22015-04-15 19:21:00 +00002068 expect(vc.root().toQuery()).toEqual('pubDate in 2014-12-05');
Akron0b489ad2018-02-02 16:49:32 +01002069 expect(vc.root().element().lastChild.getAttribute('class')).toEqual('operators button-group');
Nils Diewald86dad5b2015-01-28 15:09:07 +00002070
Nils Diewald7c8ced22015-04-15 19:21:00 +00002071 // Clean with delete from root
2072 expect(vc.root().element().lastChild.lastChild.getAttribute('class')).toEqual('delete');
2073 _delOn(vc.root());
2074 expect(vc.root().toQuery()).toEqual('');
Akronebc96662018-08-29 17:36:20 +02002075 expect(vc.root().element().lastChild.lastChild.data).toEqual(KorAP.Locale.EMPTY);
2076 expect(vc.root().element().classList.contains('unspecified')).toEqual(true);
Nils Diewald7c8ced22015-04-15 19:21:00 +00002077 });
Nils Diewald86dad5b2015-01-28 15:09:07 +00002078
Nils Diewald7c8ced22015-04-15 19:21:00 +00002079 it('should remove on nested docs', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00002080 var vc = vcClass.create().fromJson(
Akron712733a2018-04-05 18:17:47 +02002081 {
2082 "@type": 'koral:docGroup',
2083 'operation' : 'operation:and',
2084 'operands' : [
2085 {
2086 "@type": 'koral:doc',
2087 "key": 'pubDate',
2088 "match": 'match:eq',
2089 "value": '2014-12-05',
2090 "type": 'type:date'
2091 },
2092 {
2093 "@type" : 'koral:doc',
2094 'key' : 'foo',
2095 'value' : 'bar'
2096 }
2097 ]
2098 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00002099 );
2100
2101 // Delete with direct element access
2102 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar"');
2103 _delOn(vc.root().getOperand(0));
2104
2105 expect(vc.toQuery()).toEqual('foo = "bar"');
2106 expect(vc.root().ldType()).toEqual('doc');
2107 });
2108
2109 it('should clean on doc groups', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00002110 var vc = vcClass.create().fromJson(
Akron712733a2018-04-05 18:17:47 +02002111 {
2112 "@type": 'koral:docGroup',
2113 'operation' : 'operation:and',
2114 'operands' : [
2115 {
2116 "@type": 'koral:doc',
2117 "key": 'pubDate',
2118 "match": 'match:eq',
2119 "value": '2014-12-05',
2120 "type": 'type:date'
2121 },
2122 {
2123 "@type" : 'koral:doc',
2124 'key' : 'foo',
2125 'value' : 'bar'
2126 }
2127 ]
2128 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00002129 );
2130
2131 // Cleanwith direct element access
2132 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar"');
2133 _delOn(vc.root());
2134 expect(vc.toQuery()).toEqual('');
2135 expect(vc.root().ldType()).toEqual('non');
2136 });
2137
2138 it('should remove on nested doc groups (case of ungrouping 1)', function () {
2139 var vc = complexVCFactory.create();
2140
2141 // Delete with direct element access
2142 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02002143 'pubDate in 2014-12-05 & (title = "Hello World!" | foo = "bar")'
Nils Diewald7c8ced22015-04-15 19:21:00 +00002144 );
2145
2146 // Remove hello world:
2147 _delOn(vc.root().getOperand(1).getOperand(0));
2148 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar"');
2149 expect(vc.root().ldType()).toEqual('docGroup');
2150 });
2151
2152 it('should remove on nested doc groups (case of ungrouping 2)', function () {
2153 var vc = complexVCFactory.create();
2154
2155 // Delete with direct element access
2156 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02002157 'pubDate in 2014-12-05 & (title = "Hello World!" | foo = "bar")'
Nils Diewald7c8ced22015-04-15 19:21:00 +00002158 );
2159
2160 // Remove bar
2161 _delOn(vc.root().getOperand(1).getOperand(1));
2162 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & title = "Hello World!"');
2163 expect(vc.root().ldType()).toEqual('docGroup');
2164 expect(vc.root().operation()).toEqual('and');
2165 });
2166
2167 it('should remove on nested doc groups (case of root changing)', function () {
2168 var vc = complexVCFactory.create();
2169
2170 // Delete with direct element access
2171 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02002172 'pubDate in 2014-12-05 & ' +
2173 '(title = "Hello World!" | foo = "bar")'
Nils Diewald7c8ced22015-04-15 19:21:00 +00002174 );
2175
2176 // Remove bar
2177 _delOn(vc.root().getOperand(0));
2178 expect(vc.toQuery()).toEqual('title = "Hello World!" | foo = "bar"');
2179 expect(vc.root().ldType()).toEqual('docGroup');
2180 expect(vc.root().operation()).toEqual('or');
2181 });
2182
2183 it('should remove on nested doc groups (list flattening)', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00002184 var vc = vcClass.create().fromJson(
Akron712733a2018-04-05 18:17:47 +02002185 {
2186 "@type": 'koral:docGroup',
2187 'operation' : 'operation:or',
2188 'operands' : [
2189 {
2190 "@type": 'koral:doc',
2191 "key": 'pubDate',
2192 "match": 'match:eq',
2193 "value": '2014-12-05',
2194 "type": 'type:date'
2195 },
2196 {
2197 "@type" : 'koral:doc',
2198 'key' : 'foo',
2199 'value' : 'bar'
2200 },
2201 {
2202 "@type": 'koral:docGroup',
2203 'operation' : 'operation:and',
2204 'operands' : [
2205 {
2206 "@type": 'koral:doc',
2207 "key": 'pubDate',
2208 "match": 'match:eq',
2209 "value": '2014-12-05',
2210 "type": 'type:date'
2211 },
2212 {
2213 "@type" : 'koral:docGroup',
2214 'operation' : 'operation:or',
2215 'operands' : [
2216 {
2217 '@type' : 'koral:doc',
2218 'key' : 'title',
2219 'value' : 'Hello World!'
2220 },
2221 {
2222 '@type' : 'koral:doc',
2223 'key' : 'yeah',
2224 'value' : 'juhu'
2225 }
2226 ]
2227 }
2228 ]
2229 }
2230 ]
2231 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00002232 );
2233
2234 // Delete with direct element access
2235 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02002236 'pubDate in 2014-12-05 | foo = "bar" | ' +
2237 '(pubDate in 2014-12-05 & ' +
2238 '(title = "Hello World!" | yeah = "juhu"))'
Nils Diewald7c8ced22015-04-15 19:21:00 +00002239 );
2240
2241 expect(vc.root().ldType()).toEqual('docGroup');
2242 expect(vc.root().operation()).toEqual('or');
2243
2244 // Operands and operators
Akronadab5e52018-08-20 13:50:53 +02002245 expect(vc.builder().firstChild.children.length).toEqual(4);
2246 expect(vc.builder().firstChild.lastChild.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +00002247
2248 // Remove inner group and flatten
2249 _delOn(vc.root().getOperand(2).getOperand(0));
2250
2251 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02002252 'pubDate in 2014-12-05 | foo = "bar" | title = "Hello World!" | yeah = "juhu"'
Nils Diewald7c8ced22015-04-15 19:21:00 +00002253 );
2254 expect(vc.root().ldType()).toEqual('docGroup');
2255 expect(vc.root().operation()).toEqual('or');
2256
2257 // Operands and operators
Akronadab5e52018-08-20 13:50:53 +02002258 expect(vc.builder().firstChild.children.length).toEqual(5);
2259 expect(vc.builder().firstChild.lastChild.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +00002260 });
2261 });
2262
Akron88d237e2020-10-21 08:05:18 +02002263 describe('KorAP.VC._add (event)', function () {
Nils Diewald7c8ced22015-04-15 19:21:00 +00002264 var complexVCFactory = buildFactory(vcClass,{
2265 "@type": 'koral:docGroup',
2266 'operation' : 'operation:and',
2267 'operands' : [
Akron712733a2018-04-05 18:17:47 +02002268 {
2269 "@type": 'koral:doc',
2270 "key": 'pubDate',
2271 "match": 'match:eq',
2272 "value": '2014-12-05',
2273 "type": 'type:date'
2274 },
2275 {
2276 "@type" : 'koral:docGroup',
2277 'operation' : 'operation:or',
2278 'operands' : [
2279 {
2280 '@type' : 'koral:doc',
2281 'key' : 'title',
2282 'value' : 'Hello World!'
2283 },
2284 {
2285 '@type' : 'koral:doc',
2286 'key' : 'foo',
2287 'value' : 'bar'
2288 }
2289 ]
2290 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00002291 ]
2292 });
2293
2294 it('should add new unspecified doc with "and"', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00002295 var vc = vcClass.create().fromJson(
Akron712733a2018-04-05 18:17:47 +02002296 {
2297 "@type": 'koral:docGroup',
2298 'operation' : 'operation:and',
2299 'operands' : [
2300 {
2301 "@type": 'koral:doc',
2302 "key": 'pubDate',
2303 "match": 'match:eq',
2304 "value": '2014-12-05',
2305 "type": 'type:date'
2306 },
2307 {
2308 "@type" : 'koral:doc',
2309 'key' : 'foo',
2310 'value' : 'bar'
Akronb19803c2018-08-16 16:39:42 +02002311 },
2312 {
2313 "@type" : "koral:docGroupRef",
2314 "ref" : "myCorpus"
Akron712733a2018-04-05 18:17:47 +02002315 }
2316 ]
2317 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00002318 );
2319
Akronb19803c2018-08-16 16:39:42 +02002320 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar" & referTo "myCorpus"');
Nils Diewald7c8ced22015-04-15 19:21:00 +00002321
Akronadab5e52018-08-20 13:50:53 +02002322 var fc = vc.builder().firstChild;
Nils Diewald7c8ced22015-04-15 19:21:00 +00002323 expect(fc.getAttribute('data-operation')).toEqual('and');
Akronb19803c2018-08-16 16:39:42 +02002324 expect(fc.children.length).toEqual(4);
Akron0b489ad2018-02-02 16:49:32 +01002325 expect(fc.lastChild.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +00002326 expect(fc.children[0].getAttribute('class')).toEqual('doc');
2327 expect(fc.children[1].getAttribute('class')).toEqual('doc');
Akronb19803c2018-08-16 16:39:42 +02002328 expect(fc.children[2].getAttribute('class')).toEqual('doc groupref');
Nils Diewald7c8ced22015-04-15 19:21:00 +00002329
2330 // add with 'and' in the middle
2331 _andOn(vc.root().getOperand(0));
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 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(5);
Akron0b489ad2018-02-02 16:49:32 +01002337 expect(fc.lastChild.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +00002338
2339 expect(fc.children[0].getAttribute('class')).toEqual('doc');
2340 expect(fc.children[1].getAttribute('class')).toEqual('doc unspecified');
2341 expect(fc.children[2].getAttribute('class')).toEqual('doc');
Akronb19803c2018-08-16 16:39:42 +02002342 expect(fc.children[3].getAttribute('class')).toEqual('doc groupref');
2343 expect(fc.children[4].classList.contains('button-group')).toBeTruthy();
2344 expect(fc.children.length).toEqual(5);
2345
2346 _andOn(vc.root().getOperand(3));
2347 expect(fc.children[0].getAttribute('class')).toEqual('doc');
2348 expect(fc.children[1].getAttribute('class')).toEqual('doc unspecified');
2349 expect(fc.children[2].getAttribute('class')).toEqual('doc');
2350 expect(fc.children[3].getAttribute('class')).toEqual('doc groupref');
2351 expect(fc.children[4].getAttribute('class')).toEqual('doc unspecified');
2352 expect(fc.children[5].classList.contains('button-group')).toBeTruthy();
2353 expect(fc.children.length).toEqual(6);
2354
Nils Diewald7c8ced22015-04-15 19:21:00 +00002355 });
2356
Akronb19803c2018-08-16 16:39:42 +02002357
Nils Diewald7c8ced22015-04-15 19:21:00 +00002358 it('should add new unspecified doc with "or"', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00002359 var vc = vcClass.create().fromJson(
Akron712733a2018-04-05 18:17:47 +02002360 {
2361 "@type": 'koral:docGroup',
2362 'operation' : 'operation:and',
2363 'operands' : [
2364 {
2365 "@type": 'koral:doc',
2366 "key": 'pubDate',
2367 "match": 'match:eq',
2368 "value": '2014-12-05',
2369 "type": 'type:date'
2370 },
2371 {
2372 "@type" : 'koral:doc',
2373 'key' : 'foo',
2374 'value' : 'bar'
Akronb19803c2018-08-16 16:39:42 +02002375 },
2376 {
2377 "@type" : "koral:docGroupRef",
2378 "ref" : "myCorpus"
Akron712733a2018-04-05 18:17:47 +02002379 }
2380 ]
2381 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00002382 );
2383
Akronb19803c2018-08-16 16:39:42 +02002384 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar" & referTo "myCorpus"');
Nils Diewald7c8ced22015-04-15 19:21:00 +00002385
Akronadab5e52018-08-20 13:50:53 +02002386 var fc = vc.builder().firstChild;
Akronb19803c2018-08-16 16:39:42 +02002387 expect(fc.children.length).toEqual(4);
Akron0b489ad2018-02-02 16:49:32 +01002388 expect(fc.lastChild.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +00002389 expect(fc.children[0].getAttribute('class')).toEqual('doc');
2390 expect(fc.children[1].getAttribute('class')).toEqual('doc');
Akronb19803c2018-08-16 16:39:42 +02002391 expect(fc.children[2].getAttribute('class')).toEqual('doc groupref');
Nils Diewald7c8ced22015-04-15 19:21:00 +00002392
2393 // add with 'or' in the middle
2394 _orOn(vc.root().getOperand(0));
Akronb19803c2018-08-16 16:39:42 +02002395 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar" & referTo "myCorpus"');
Akronadab5e52018-08-20 13:50:53 +02002396 fc = vc.builder().firstChild;
Nils Diewald7c8ced22015-04-15 19:21:00 +00002397
2398 expect(fc.getAttribute('data-operation')).toEqual('and');
Akronb19803c2018-08-16 16:39:42 +02002399 expect(fc.children.length).toEqual(4);
Nils Diewald7c8ced22015-04-15 19:21:00 +00002400 expect(fc.children[0].getAttribute('class')).toEqual('docGroup');
2401 expect(fc.children[0].getAttribute('data-operation')).toEqual('or');
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');
2404 expect(fc.children[3].getAttribute('class')).toEqual('operators button-group');
Akron0b489ad2018-02-02 16:49:32 +01002405 expect(fc.lastChild.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +00002406
Akronadab5e52018-08-20 13:50:53 +02002407 fc = vc.builder().firstChild.firstChild;
Nils Diewald7c8ced22015-04-15 19:21:00 +00002408 expect(fc.children.length).toEqual(3);
2409 expect(fc.children[0].getAttribute('class')).toEqual('doc');
2410 expect(fc.children[1].getAttribute('class')).toEqual('doc unspecified');
Akron0b489ad2018-02-02 16:49:32 +01002411 expect(fc.children[2].getAttribute('class')).toEqual('operators button-group');
2412 expect(fc.lastChild.getAttribute('class')).toEqual('operators button-group');
Akronb19803c2018-08-16 16:39:42 +02002413
2414 _orOn(vc.root().getOperand(2));
Akronadab5e52018-08-20 13:50:53 +02002415 fc = vc.builder().firstChild;
Akronb19803c2018-08-16 16:39:42 +02002416 expect(fc.children.length).toEqual(4);
2417
2418 expect(fc.children[0].getAttribute('class')).toEqual('docGroup');
2419 expect(fc.children[1].getAttribute('class')).toEqual('doc');
2420 expect(fc.children[2].getAttribute('class')).toEqual('docGroup');
2421 expect(fc.children[3].getAttribute('class')).toEqual('operators button-group');
2422
Akronadab5e52018-08-20 13:50:53 +02002423 fc = vc.builder().firstChild.children[2];
Akronb19803c2018-08-16 16:39:42 +02002424 expect(fc.children[0].getAttribute('class')).toEqual('doc groupref');
2425 expect(fc.children[1].getAttribute('class')).toEqual('doc unspecified');
2426 expect(fc.children[2].getAttribute('class')).toEqual('operators button-group');
2427 expect(fc.lastChild.getAttribute('class')).toEqual('operators button-group');
2428
Nils Diewald7c8ced22015-04-15 19:21:00 +00002429 });
2430
2431 it('should add new unspecified doc with "and" before group', function () {
2432 var vc = demoFactory.create();
2433
2434 // Wrap with direct element access
2435 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02002436 '(Titel = "Baum" & ' +
2437 'Veröffentlichungsort = "hihi" & ' +
2438 '(Titel = "Baum" | ' +
2439 'Veröffentlichungsort = "hihi")) | ' +
2440 'Untertitel ~ "huhu"'
Nils Diewald7c8ced22015-04-15 19:21:00 +00002441 );
2442
2443 expect(vc.root().getOperand(0).ldType()).toEqual('docGroup');
2444 expect(vc.root().getOperand(0).operation()).toEqual('and');
2445 expect(vc.root().getOperand(0).operands().length).toEqual(3);
2446
2447 // Add unspecified on the second doc
2448 var secDoc = vc.root().getOperand(0).getOperand(1);
2449 expect(secDoc.value()).toEqual('hihi');
2450
2451 // Add
2452 _andOn(secDoc);
2453
2454 var fo = vc.root().getOperand(0);
2455
2456 expect(fo.ldType()).toEqual('docGroup');
2457 expect(fo.operation()).toEqual('and');
2458 expect(fo.operands().length).toEqual(4);
2459
2460 expect(fo.getOperand(0).ldType()).toEqual('doc');
2461 expect(fo.getOperand(1).ldType()).toEqual('doc');
2462 expect(fo.getOperand(2).ldType()).toEqual('non');
2463 expect(fo.getOperand(3).ldType()).toEqual('docGroup');
2464 });
2465
2466
2467 it('should remove a doc with an unspecified doc in a nested group', function () {
2468 var vc = demoFactory.create();
2469
2470 // Wrap with direct element access
2471 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02002472 '(Titel = "Baum" & Veröffentlichungsort = "hihi" & (Titel = "Baum" | Veröffentlichungsort = "hihi")) | Untertitel ~ "huhu"'
Nils Diewald7c8ced22015-04-15 19:21:00 +00002473 );
2474
2475 var fo = vc.root().getOperand(0).getOperand(0);
2476 expect(fo.key()).toEqual('Titel');
2477 expect(fo.value()).toEqual('Baum');
2478
2479 // Add unspecified on the root group
2480 _orOn(fo);
2481
2482 fo = vc.root().getOperand(0).getOperand(0);
2483
2484 expect(fo.operation()).toEqual('or');
2485 expect(fo.getOperand(0).ldType()).toEqual('doc');
2486 expect(fo.getOperand(1).ldType()).toEqual('non');
2487
2488 // Delete document
2489 _delOn(fo.getOperand(0));
2490
2491 // The operand is now non
2492 expect(vc.root().getOperand(0).getOperand(0).ldType()).toEqual('non');
2493 expect(vc.root().getOperand(0).getOperand(1).ldType()).toEqual('doc');
2494 expect(vc.root().getOperand(0).getOperand(2).ldType()).toEqual('docGroup');
2495 });
2496
2497
Akron712733a2018-04-05 18:17:47 +02002498 it('should remove an unspecified doc with a doc in a nested group', function () {
Nils Diewald7c8ced22015-04-15 19:21:00 +00002499 var vc = demoFactory.create();
2500
2501 // Wrap with direct element access
2502 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02002503 '(Titel = "Baum" & ' +
2504 'Veröffentlichungsort = "hihi" & ' +
2505 '(Titel = "Baum" ' +
2506 '| Veröffentlichungsort = "hihi")) | ' +
2507 'Untertitel ~ "huhu"'
Nils Diewald7c8ced22015-04-15 19:21:00 +00002508 );
2509
2510 var fo = vc.root().getOperand(0).getOperand(0);
2511 expect(fo.key()).toEqual('Titel');
2512 expect(fo.value()).toEqual('Baum');
2513
2514 // Add unspecified on the root group
2515 _orOn(fo);
2516
2517 fo = vc.root().getOperand(0).getOperand(0);
2518
2519 expect(fo.operation()).toEqual('or');
2520 expect(fo.getOperand(0).ldType()).toEqual('doc');
2521 expect(fo.getOperand(1).ldType()).toEqual('non');
2522
2523 // Delete unspecified doc
2524 _delOn(fo.getOperand(1));
2525
2526 // The operand is now non
2527 fo = vc.root().getOperand(0);
2528 expect(fo.getOperand(0).ldType()).toEqual('doc');
2529 expect(fo.getOperand(0).key()).toEqual('Titel');
2530 expect(fo.getOperand(0).value()).toEqual('Baum');
2531 expect(fo.getOperand(1).ldType()).toEqual('doc');
2532 expect(fo.getOperand(2).ldType()).toEqual('docGroup');
2533 });
2534
2535
2536 it('should add on parent group (case "and")', function () {
2537 var vc = complexVCFactory.create();
2538
2539 // Wrap with direct element access
2540 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02002541 'pubDate in 2014-12-05 & (title = "Hello World!" | foo = "bar")'
Nils Diewald7c8ced22015-04-15 19:21:00 +00002542 );
2543
2544 expect(vc.root().operands().length).toEqual(2);
2545
2546 // Add unspecified on the root group
2547 _andOn(vc.root().getOperand(1));
2548 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02002549 'pubDate in 2014-12-05 & (title = "Hello World!" | foo = "bar")'
Nils Diewald7c8ced22015-04-15 19:21:00 +00002550 );
2551
2552 expect(vc.root().ldType()).toEqual('docGroup');
2553 expect(vc.root().operands().length).toEqual(3);
2554 expect(vc.root().getOperand(0).ldType()).toEqual('doc');
2555 expect(vc.root().getOperand(1).ldType()).toEqual('docGroup');
2556 expect(vc.root().getOperand(1).operation()).toEqual('or');
2557 expect(vc.root().getOperand(2).ldType()).toEqual('non');
2558
2559 // Add another unspecified on the root group
2560 _andOn(vc.root().getOperand(1));
2561
2562 expect(vc.root().operands().length).toEqual(4);
2563 expect(vc.root().getOperand(0).ldType()).toEqual('doc');
2564 expect(vc.root().getOperand(1).ldType()).toEqual('docGroup');
2565 expect(vc.root().getOperand(2).ldType()).toEqual('non');
2566 expect(vc.root().getOperand(3).ldType()).toEqual('non');
2567
2568 // Add another unspecified after the first doc
2569 _andOn(vc.root().getOperand(0));
2570
2571 expect(vc.root().operands().length).toEqual(5);
2572 expect(vc.root().getOperand(0).ldType()).toEqual('doc');
2573 expect(vc.root().getOperand(1).ldType()).toEqual('non');
2574 expect(vc.root().getOperand(2).ldType()).toEqual('docGroup');
2575 expect(vc.root().getOperand(3).ldType()).toEqual('non');
2576 expect(vc.root().getOperand(4).ldType()).toEqual('non');
2577 });
2578
2579 it('should wrap on root', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00002580 var vc = vcClass.create().fromJson(
Akron712733a2018-04-05 18:17:47 +02002581 {
2582 "@type": 'koral:docGroup',
2583 'operation' : 'operation:and',
2584 'operands' : [
2585 {
2586 "@type": 'koral:doc',
2587 "key": 'pubDate',
2588 "match": 'match:eq',
2589 "value": '2014-12-05',
2590 "type": 'type:date'
2591 },
2592 {
2593 "@type" : 'koral:doc',
2594 'key' : 'foo',
2595 'value' : 'bar'
2596 }
2597 ]
2598 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00002599 );
2600
2601 // Wrap on root
2602 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar"');
2603 expect(vc.root().ldType()).toEqual('docGroup');
2604 expect(vc.root().operation()).toEqual('and');
2605 _orOn(vc.root());
2606 expect(vc.root().ldType()).toEqual('docGroup');
2607 expect(vc.root().operation()).toEqual('or');
2608
2609 expect(vc.root().getOperand(0).ldType()).toEqual('docGroup');
2610 expect(vc.root().getOperand(0).operation()).toEqual('and');
2611 });
2612
2613 it('should add on root (case "and")', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00002614 var vc = vcClass.create().fromJson(
Akron712733a2018-04-05 18:17:47 +02002615 {
2616 "@type": 'koral:doc',
2617 "key": 'pubDate',
2618 "match": 'match:eq',
2619 "value": '2014-12-05',
2620 "type": 'type:date'
2621 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00002622 );
2623
2624 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05');
2625 expect(vc.root().ldType()).toEqual('doc');
2626 expect(vc.root().key()).toEqual('pubDate');
2627 expect(vc.root().value()).toEqual('2014-12-05');
2628
2629 // Wrap on root
2630 _andOn(vc.root());
2631 expect(vc.root().ldType()).toEqual('docGroup');
2632 expect(vc.root().operation()).toEqual('and');
2633 });
2634
2635 it('should add on root (case "or")', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00002636 var vc = vcClass.create().fromJson(
Akron712733a2018-04-05 18:17:47 +02002637 {
2638 "@type": 'koral:doc',
2639 "key": 'pubDate',
2640 "match": 'match:eq',
2641 "value": '2014-12-05',
2642 "type": 'type:date'
2643 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00002644 );
2645
2646 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05');
2647 expect(vc.root().key()).toEqual('pubDate');
2648 expect(vc.root().value()).toEqual('2014-12-05');
2649
2650 // Wrap on root
2651 _orOn(vc.root());
2652 expect(vc.root().ldType()).toEqual('docGroup');
2653 expect(vc.root().operation()).toEqual('or');
2654 });
2655
2656 it('should support multiple sub groups per group', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00002657 var vc = vcClass.create().fromJson(
Akron712733a2018-04-05 18:17:47 +02002658 {
2659 "@type": 'koral:docGroup',
2660 'operation' : 'operation:or',
2661 'operands' : [
2662 {
2663 "@type": 'koral:docGroup',
2664 'operation' : 'operation:and',
2665 'operands' : [
2666 {
2667 "@type": 'koral:doc',
2668 "key": 'title',
2669 "value": 't1',
2670 },
2671 {
2672 "@type" : 'koral:doc',
2673 'key' : 'title',
2674 'value' : 't2'
2675 }
2676 ]
2677 },
2678 {
2679 "@type": 'koral:docGroup',
2680 'operation' : 'operation:and',
2681 'operands' : [
2682 {
2683 "@type": 'koral:doc',
2684 "key": 'title',
2685 "value": 't3',
2686 },
2687 {
2688 "@type" : 'koral:doc',
2689 'key' : 'title',
2690 'value' : 't4'
2691 }
2692 ]
2693 }
2694 ]
2695 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00002696 );
2697 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02002698 '(title = "t1" & title = "t2") | ' +
2699 '(title = "t3" & title = "t4")'
Nils Diewald7c8ced22015-04-15 19:21:00 +00002700 );
2701 expect(vc.root().operation()).toEqual('or');
2702 expect(vc.root().getOperand(0).toQuery()).toEqual('title = "t1" & title = "t2"');
2703 expect(vc.root().getOperand(1).toQuery()).toEqual('title = "t3" & title = "t4"');
2704
2705 _andOn(vc.root());
2706
2707 expect(vc.root().operation()).toEqual('and');
2708 expect(vc.root().getOperand(0).ldType()).toEqual('docGroup');
2709 expect(vc.root().getOperand(1).ldType()).toEqual('non');
2710 });
2711 });
2712
Nils Diewald6283d692015-04-23 20:32:53 +00002713
Akron88d237e2020-10-21 08:05:18 +02002714 describe('KorAP.VC.Rewrite', function () {
Nils Diewald7c8ced22015-04-15 19:21:00 +00002715 it('should be initializable', function () {
2716 var rewrite = rewriteClass.create({
Akron712733a2018-04-05 18:17:47 +02002717 "@type" : "koral:rewrite",
2718 "operation" : "operation:modification",
2719 "src" : "querySerializer",
2720 "scope" : "tree"
Nils Diewald86dad5b2015-01-28 15:09:07 +00002721 });
Nils Diewald7c8ced22015-04-15 19:21:00 +00002722 expect(rewrite.toString()).toEqual('Modification of "tree" by "querySerializer"');
2723 });
Nils Diewald86dad5b2015-01-28 15:09:07 +00002724
Nils Diewald7c8ced22015-04-15 19:21:00 +00002725 it('should be deserialized by docs', function () {
2726 var doc = docClass.create(
Akron712733a2018-04-05 18:17:47 +02002727 undefined,
2728 {
2729 "@type":"koral:doc",
2730 "key":"Titel",
2731 "value":"Baum",
2732 "match":"match:eq"
2733 });
Nils Diewald7c8ced22015-04-15 19:21:00 +00002734
2735 expect(doc.element().classList.contains('doc')).toBeTruthy();
2736 expect(doc.element().classList.contains('rewritten')).toBe(false);
2737
2738 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 "rewrites" : [
2746 {
2747 "@type" : "koral:rewrite",
2748 "operation" : "operation:modification",
2749 "src" : "querySerializer",
2750 "scope" : "tree"
2751 }
2752 ]
2753 });
Nils Diewald7c8ced22015-04-15 19:21:00 +00002754
2755 expect(doc.element().classList.contains('doc')).toBeTruthy();
2756 expect(doc.element().classList.contains('rewritten')).toBeTruthy();
2757 });
Nils Diewald6283d692015-04-23 20:32:53 +00002758
Akron76c3dd62018-05-29 20:58:27 +02002759 it('should be described in a title attribute', function () {
2760
2761 doc = docClass.create(
2762 undefined,
2763 {
2764 "@type":"koral:doc",
2765 "key":"Titel",
2766 "value":"Baum",
2767 "match":"match:eq",
2768 "rewrites" : [
2769 {
2770 "@type" : "koral:rewrite",
2771 "operation" : "operation:modification",
2772 "src" : "querySerializer",
2773 "scope" : "tree"
2774 },
2775 {
2776 "@type" : "koral:rewrite",
2777 "operation" : "operation:injection",
2778 "src" : "me"
2779 }
2780 ]
2781 });
2782
2783 expect(doc.element().classList.contains('doc')).toBeTruthy();
2784 expect(doc.element().classList.contains('rewritten')).toBeTruthy();
2785 expect(doc.element().lastChild.getAttribute("title")).toEqual("querySerializer: tree (modification)\nme (injection)");
2786 });
2787
2788
Nils Diewald6283d692015-04-23 20:32:53 +00002789 xit('should be deserialized by docGroups', function () {
2790 var docGroup = docGroupClass.create(
Akron712733a2018-04-05 18:17:47 +02002791 undefined,
2792 {
2793 "@type" : "koral:docGroup",
2794 "operation" : "operation:or",
2795 "operands" : [
2796 {
2797 "@type" : "doc",
2798 "key" : "pubDate",
2799 "type" : "type:date",
2800 "value" : "2014-12-05"
2801 },
2802 {
2803 "@type" : "doc",
2804 "key" : "pubDate",
2805 "type" : "type:date",
2806 "value" : "2014-12-06"
2807 }
2808 ],
2809 "rewrites" : [
2810 {
2811 "@type" : "koral:rewrite",
2812 "operation" : "operation:modification",
2813 "src" : "querySerializer",
2814 "scope" : "tree"
2815 }
2816 ]
2817 }
Nils Diewald6283d692015-04-23 20:32:53 +00002818 );
2819
2820 expect(doc.element().classList.contains('docgroup')).toBeTruthy();
2821 expect(doc.element().classList.contains('rewritten')).toBe(false);
2822 });
Nils Diewald86dad5b2015-01-28 15:09:07 +00002823 });
Nils Diewaldf0c4f112015-05-05 12:56:59 +00002824
Akron88d237e2020-10-21 08:05:18 +02002825 describe('KorAP.VC.stringValue', function () {
Nils Diewaldf0c4f112015-05-05 12:56:59 +00002826 it('should be initializable', function () {
2827 var sv = stringValClass.create();
2828 expect(sv.regex()).toBe(false);
2829 expect(sv.value()).toBe('');
Nils Diewaldc4c4b832015-05-05 16:00:08 +00002830
2831 sv = stringValClass.create('Baum');
2832 expect(sv.regex()).toBe(false);
2833 expect(sv.value()).toBe('Baum');
2834
2835 sv = stringValClass.create('Baum', false);
2836 expect(sv.regex()).toBe(false);
2837 expect(sv.value()).toBe('Baum');
2838
2839 sv = stringValClass.create('Baum', true);
2840 expect(sv.regex()).toBe(true);
2841 expect(sv.value()).toBe('Baum');
2842 });
2843
2844 it('should be modifiable', function () {
2845 var sv = stringValClass.create();
2846 expect(sv.regex()).toBe(false);
2847 expect(sv.value()).toBe('');
2848
2849 expect(sv.value('Baum')).toBe('Baum');
2850 expect(sv.value()).toBe('Baum');
2851
2852 expect(sv.regex(true)).toBe(true);
2853 expect(sv.regex()).toBe(true);
2854 });
2855
2856 it('should have a toggleble regex value', function () {
2857 var sv = stringValClass.create();
Nils Diewald7991a3f2015-05-19 14:12:37 +00002858
2859 expect(sv.element().firstChild.value).toBe('');
2860 sv.element().firstChild.value = 'der'
2861 expect(sv.element().firstChild.value).toBe('der');
2862
Nils Diewaldc4c4b832015-05-05 16:00:08 +00002863 expect(sv.regex()).toBe(false);
2864
2865 sv.toggleRegex();
Nils Diewald7991a3f2015-05-19 14:12:37 +00002866 expect(sv.element().firstChild.value).toBe('der');
Nils Diewaldc4c4b832015-05-05 16:00:08 +00002867 expect(sv.regex()).toBe(true);
Nils Diewald7991a3f2015-05-19 14:12:37 +00002868 sv.element().firstChild.value = 'derbe'
Nils Diewaldc4c4b832015-05-05 16:00:08 +00002869
2870 sv.toggleRegex();
2871 expect(sv.regex()).toBe(false);
Nils Diewald7991a3f2015-05-19 14:12:37 +00002872 expect(sv.element().firstChild.value).toBe('derbe');
Nils Diewaldc4c4b832015-05-05 16:00:08 +00002873 });
2874
2875 it('should have an element', function () {
2876 var sv = stringValClass.create('der');
2877 expect(sv.element().nodeName).toBe('DIV');
2878 expect(sv.element().firstChild.nodeName).toBe('INPUT');
Akron5d4f2e42024-12-16 09:10:27 +01002879 expect(sv.element().firstChild.getAttribute('type')).toBeNull();
Nils Diewaldc4c4b832015-05-05 16:00:08 +00002880 expect(sv.element().firstChild.value).toBe('der');
2881 });
2882
2883 it('should have a classed element', function () {
Akrondbbe5ee2020-12-03 12:39:46 +01002884 const sv = stringValClass.create();
Nils Diewaldc4c4b832015-05-05 16:00:08 +00002885 expect(sv.element().classList.contains('regex')).toBe(false);
2886 expect(sv.regex()).toBe(false);
Akrondbbe5ee2020-12-03 12:39:46 +01002887
2888 const re = sv.element().children[1];
2889 expect(re.textContent).toEqual('RegEx');
2890 expect(re.getAttribute("title")).toEqual('Use as regular expression');
2891
2892 // Run event instead toggleRegex()
2893 re.click();
2894
Nils Diewaldc4c4b832015-05-05 16:00:08 +00002895 expect(sv.element().classList.contains('regex')).toBe(true);
2896 });
2897
2898 it('should be storable', function () {
2899 var sv = stringValClass.create();
2900 var count = 1;
2901 sv.store = function (value, regex) {
Akron712733a2018-04-05 18:17:47 +02002902 expect(regex).toBe(true);
2903 expect(value).toBe('tree');
Nils Diewaldc4c4b832015-05-05 16:00:08 +00002904 };
2905 sv.regex(true);
2906 sv.value('tree');
2907 sv.element().lastChild.click();
Nils Diewaldf0c4f112015-05-05 12:56:59 +00002908 });
Akron712733a2018-04-05 18:17:47 +02002909
Akronb19803c2018-08-16 16:39:42 +02002910 it('should have a disableoption for regex', function () {
2911 var sv = stringValClass.create(undefined, undefined, true);
2912 var svE = sv.element();
2913 expect(svE.children.length).toEqual(2);
2914
2915 sv = stringValClass.create(undefined, undefined, false);
2916 svE = sv.element();
2917 expect(svE.children.length).toEqual(1);
2918 });
2919
Nils Diewaldf0c4f112015-05-05 12:56:59 +00002920 });
Akrone4961b12017-05-10 21:04:46 +02002921
Akron5d4f2e42024-12-16 09:10:27 +01002922
2923 describe('KorAP.VC.intValue', function () {
2924 it('should be initializable', function () {
2925 var iv = intValClass.create();
2926 expect(iv.value()).toBe(0);
2927
2928 iv = intValClass.create('400');
2929 expect(iv.value()).toBe(400);
2930
2931 iv = intValClass.create(400);
2932 expect(iv.value()).toBe(400);
2933
2934 iv = intValClass.create('Baum');
2935 expect(iv.value()).toBe(0);
2936 });
2937
2938 it('should be modifiable', function () {
2939 var iv = intValClass.create();
2940 expect(iv.value()).toBe(0);
2941
2942 expect(iv.value('33')).toBe(33);
2943 expect(iv.value()).toBe(33);
2944 });
2945
2946 it('should have an element', function () {
2947 var iv = intValClass.create(22);
2948 expect(iv.element().nodeName).toBe('DIV');
2949 expect(iv.element().firstChild.nodeName).toBe('INPUT');
2950 expect(iv.element().firstChild.getAttribute('type')).toBe('number');
2951 expect(iv.element().firstChild.value).toBe('22');
2952 });
2953
2954 it('should be storable', function () {
2955 var iv = intValClass.create();
2956 var count = 1;
2957 iv.store = function (value) {
2958 expect(value).toBe(80);
2959 };
2960 iv.value('80');
2961 iv.element().lastChild.click();
2962 });
2963 });
2964
2965
Akron712733a2018-04-05 18:17:47 +02002966 describe('KorAP.VC.Menu', function () {
Akrone65a88a2018-04-05 19:14:20 +02002967
2968 var vc;
2969
Akron712733a2018-04-05 18:17:47 +02002970 it('should be initializable', function () {
2971
Akrone65a88a2018-04-05 19:14:20 +02002972 vc = vcClass.create([
Akron712733a2018-04-05 18:17:47 +02002973 ['a', 'text'],
2974 ['b', 'string'],
2975 ['c', 'date']
2976 ]).fromJson();
Akronadab5e52018-08-20 13:50:53 +02002977 expect(vc.builder().firstChild.classList.contains('unspecified')).toBeTruthy();
2978 expect(vc.builder().firstChild.firstChild.tagName).toEqual('SPAN');
Akron712733a2018-04-05 18:17:47 +02002979
2980 // Click on unspecified
Akronadab5e52018-08-20 13:50:53 +02002981 vc.builder().firstChild.firstChild.click();
2982 expect(vc.builder().firstChild.firstChild.tagName).toEqual('UL');
Akron712733a2018-04-05 18:17:47 +02002983
Akronadab5e52018-08-20 13:50:53 +02002984 var list = vc.builder().firstChild.firstChild;
Akron3ad46942018-08-22 16:47:14 +02002985 expect(list.getElementsByTagName("LI")[0].innerText).toEqual('referTo');
2986 expect(list.getElementsByTagName("LI")[1].innerText).toEqual('a');
2987 expect(list.getElementsByTagName("LI")[2].innerText).toEqual('b');
2988 expect(list.getElementsByTagName("LI")[3].innerText).toEqual('c');
Akron712733a2018-04-05 18:17:47 +02002989
2990 vc = vcClass.create([
2991 ['d', 'text'],
2992 ['e', 'string'],
Akron5d4f2e42024-12-16 09:10:27 +01002993 ['f', 'date'],
2994 ['g', 'integer']
Akron712733a2018-04-05 18:17:47 +02002995 ]).fromJson();
Akronadab5e52018-08-20 13:50:53 +02002996 expect(vc.builder().firstChild.classList.contains('unspecified')).toBeTruthy();
2997 expect(vc.builder().firstChild.firstChild.tagName).toEqual('SPAN');
Akron712733a2018-04-05 18:17:47 +02002998
2999 // Click on unspecified
Akronadab5e52018-08-20 13:50:53 +02003000 vc.builder().firstChild.firstChild.click();
3001 expect(vc.builder().firstChild.firstChild.tagName).toEqual('UL');
Akron712733a2018-04-05 18:17:47 +02003002
Akronadab5e52018-08-20 13:50:53 +02003003 list = vc.builder().firstChild.firstChild;
Akron3ad46942018-08-22 16:47:14 +02003004 expect(list.getElementsByTagName("LI")[0].innerText).toEqual('referTo');
3005 expect(list.getElementsByTagName("LI")[1].innerText).toEqual('d');
3006 expect(list.getElementsByTagName("LI")[2].innerText).toEqual('e');
3007 expect(list.getElementsByTagName("LI")[3].innerText).toEqual('f');
Akron5d4f2e42024-12-16 09:10:27 +01003008 expect(list.getElementsByTagName("LI")[4].innerText).toEqual('g');
Akron31d89942018-04-06 16:44:51 +02003009 // blur
3010 document.body.click();
Akron712733a2018-04-05 18:17:47 +02003011 });
Akrone65a88a2018-04-05 19:14:20 +02003012
3013 // Reinitialize to make tests stable
3014 vc = vcClass.create([
3015 ['d', 'text'],
3016 ['e', 'string'],
3017 ['f', 'date']
3018 ]).fromJson();
3019
3020 it('should be clickable on key', function () {
Akron31d89942018-04-06 16:44:51 +02003021 // Click on unspecified
Akronadab5e52018-08-20 13:50:53 +02003022 vc.builder().firstChild.firstChild.click();
Akrone65a88a2018-04-05 19:14:20 +02003023 // Click on "d"
Akronadab5e52018-08-20 13:50:53 +02003024 vc.builder().firstChild.firstChild.getElementsByTagName("LI")[1].click();
3025 expect(vc.builder().firstChild.firstChild.tagName).toEqual('SPAN');
3026 expect(vc.builder().firstChild.firstChild.innerText).toEqual('d');
3027 expect(vc.builder().firstChild.children[1].innerText).toEqual('eq');
3028 expect(vc.builder().firstChild.children[1].getAttribute('data-type')).toEqual('text');
Akron31d89942018-04-06 16:44:51 +02003029 // blur
3030 document.body.click();
Akrone65a88a2018-04-05 19:14:20 +02003031 });
3032
Akron31d89942018-04-06 16:44:51 +02003033 it('should be clickable on operation for text', function () {
3034 // Click on "d" (or unspecified)
Akronadab5e52018-08-20 13:50:53 +02003035 vc.builder().firstChild.firstChild.click();
Akron31d89942018-04-06 16:44:51 +02003036
3037 // Choose "d"
Akronadab5e52018-08-20 13:50:53 +02003038 vc.builder().firstChild.firstChild.getElementsByTagName("LI")[1].click();
Akron31d89942018-04-06 16:44:51 +02003039
3040 // Click on matchop
Akronadab5e52018-08-20 13:50:53 +02003041 vc.builder().firstChild.children[1].click();
Akron31d89942018-04-06 16:44:51 +02003042
Akronadab5e52018-08-20 13:50:53 +02003043 expect(vc.builder().firstChild.children[1].tagName).toEqual('UL');
Akron31d89942018-04-06 16:44:51 +02003044
Akronadab5e52018-08-20 13:50:53 +02003045 var ul = vc.builder().firstChild.children[1];
Akrone65a88a2018-04-05 19:14:20 +02003046 expect(ul.getElementsByTagName('li')[0].innerText).toEqual("eq");
3047 expect(ul.getElementsByTagName('li')[1].innerText).toEqual("ne");
3048 expect(ul.getElementsByTagName('li')[2].innerText).toEqual("contains");
3049 expect(ul.getElementsByTagName('li')[3].innerText).toEqual("containsnot");
3050 expect(ul.getElementsByTagName('li')[4]).toBeUndefined();
Akron31d89942018-04-06 16:44:51 +02003051
3052 // Choose "contains"
3053 ul.getElementsByTagName('li')[2].click();
Akronadab5e52018-08-20 13:50:53 +02003054 expect(vc.builder().firstChild.children[1].tagName).toEqual("SPAN");
3055 expect(vc.builder().firstChild.children[1].innerText).toEqual("contains");
Akron31d89942018-04-06 16:44:51 +02003056 // blur
3057 document.body.click();
Akrone65a88a2018-04-05 19:14:20 +02003058 })
Akron31d89942018-04-06 16:44:51 +02003059
3060 it('should be clickable on operation for string', function () {
3061 // Click on "d" (or unspecified)
Akronadab5e52018-08-20 13:50:53 +02003062 vc.builder().firstChild.firstChild.click();
Akron31d89942018-04-06 16:44:51 +02003063
3064 // Choose "e"
Akronadab5e52018-08-20 13:50:53 +02003065 vc.builder().firstChild.firstChild.getElementsByTagName("LI")[2].click();
3066
Akron31d89942018-04-06 16:44:51 +02003067 // As a consequence the matchoperator may no longer
3068 // be valid and needs to be re-evaluated
Akronadab5e52018-08-20 13:50:53 +02003069 var fc = vc.builder().firstChild;
Akron31d89942018-04-06 16:44:51 +02003070 expect(fc.firstChild.tagName).toEqual('SPAN');
3071 expect(fc.firstChild.innerText).toEqual('e');
3072 expect(fc.children[1].innerText).toEqual('eq');
3073 expect(fc.children[1].getAttribute('data-type')).toEqual('string');
3074
Akronadab5e52018-08-20 13:50:53 +02003075 vc.builder().firstChild.children[1].click();
Akron31d89942018-04-06 16:44:51 +02003076
Akronadab5e52018-08-20 13:50:53 +02003077 expect(vc.builder().firstChild.children[1].tagName).toEqual('UL');
Akron31d89942018-04-06 16:44:51 +02003078
Akronadab5e52018-08-20 13:50:53 +02003079 var ul = vc.builder().firstChild.children[1];
Akron31d89942018-04-06 16:44:51 +02003080 expect(ul.getElementsByTagName('li')[0].innerText).toEqual("eq");
3081 expect(ul.getElementsByTagName('li')[1].innerText).toEqual("ne");
3082 expect(ul.getElementsByTagName('li')[2]).toBeUndefined();
3083
3084 // Choose "ne"
3085 ul.getElementsByTagName('li')[1].click();
Akronadab5e52018-08-20 13:50:53 +02003086 expect(vc.builder().firstChild.children[1].tagName).toEqual("SPAN");
3087 expect(vc.builder().firstChild.children[1].innerText).toEqual("ne");
Akron8db5e3a2018-05-28 19:25:26 +02003088
3089 // Click on text
Akronebc96662018-08-29 17:36:20 +02003090 expect(vc.builder().firstChild.children[2].innerText).toEqual(KorAP.Locale.EMPTY);
3091 expect(vc.builder().firstChild.children[2].classList.contains('unspecified')).toEqual(true);
Akronadab5e52018-08-20 13:50:53 +02003092 vc.builder().firstChild.children[2].click();
Akron8db5e3a2018-05-28 19:25:26 +02003093
3094 // Blur text element
Akronadab5e52018-08-20 13:50:53 +02003095 expect(vc.builder().firstChild.children[2].firstChild.value).toEqual('');
Akron8db5e3a2018-05-28 19:25:26 +02003096
Akron31d89942018-04-06 16:44:51 +02003097 // blur
3098 document.body.click();
3099 });
3100
3101 it('should be clickable on operation for date', function () {
3102
3103 // Replay matchop check - so it's guaranteed that "ne" is chosen
3104 // Click on "e" (or unspecified)
Akronadab5e52018-08-20 13:50:53 +02003105 vc.builder().firstChild.firstChild.click();
Akron31d89942018-04-06 16:44:51 +02003106 // Rechoose "e"
Akronadab5e52018-08-20 13:50:53 +02003107 vc.builder().firstChild.firstChild.getElementsByTagName("LI")[1].click();
Akron31d89942018-04-06 16:44:51 +02003108 // Click on matchop
Akronadab5e52018-08-20 13:50:53 +02003109 vc.builder().firstChild.children[1].click();
Akron31d89942018-04-06 16:44:51 +02003110 // Choose "ne"
Akronadab5e52018-08-20 13:50:53 +02003111 vc.builder().firstChild.children[1].getElementsByTagName('li')[1].click();
3112 expect(vc.builder().firstChild.children[1].innerText).toEqual("ne");
Akron31d89942018-04-06 16:44:51 +02003113
3114 // Click on "e"
Akronadab5e52018-08-20 13:50:53 +02003115 vc.builder().firstChild.firstChild.click();
Akron31d89942018-04-06 16:44:51 +02003116 // Choose "f"
Akronadab5e52018-08-20 13:50:53 +02003117 vc.builder().firstChild.firstChild.getElementsByTagName("LI")[3].click();
Akron31d89942018-04-06 16:44:51 +02003118
3119 // The matchoperator should still be "ne" as this is valid for dates as well (now)
Akronadab5e52018-08-20 13:50:53 +02003120 var fc = vc.builder().firstChild;
Akron31d89942018-04-06 16:44:51 +02003121 expect(fc.firstChild.tagName).toEqual('SPAN');
3122 expect(fc.firstChild.innerText).toEqual('f');
3123 expect(fc.children[1].innerText).toEqual('ne');
3124 // blur
3125 document.body.click();
3126 });
Akronddc98a72018-04-06 17:33:52 +02003127
Akron5d4f2e42024-12-16 09:10:27 +01003128 it('should be clickable on operation for integer', function () {
3129
3130 vc.builder().firstChild.firstChild.click();// Choose "g"
3131 vc.builder().firstChild.firstChild.getElementsByTagName("LI")[4].click()
3132 // Click on "g" (or unspecified)
3133 vc.builder().firstChild.firstChild.click();
3134 // Rechoose "g"
3135 vc.builder().firstChild.firstChild.getElementsByTagName("LI")[4].click();
3136 // Click on matchop
3137 vc.builder().firstChild.children[1].click();
3138 // Choose "geq"
3139 vc.builder().firstChild.children[1].getElementsByTagName('li')[2].click();
3140 expect(vc.builder().firstChild.children[1].innerText).toEqual("geq");
3141
3142 // Click on "e"
3143 vc.builder().firstChild.firstChild.click();
3144 // Choose "f"
3145 vc.builder().firstChild.firstChild.getElementsByTagName("LI")[3].click();
3146
3147 // The matchoperator should still be "geq" as this is valid for dates as well (now)
3148 var fc = vc.builder().firstChild;
3149 expect(fc.firstChild.tagName).toEqual('SPAN');
3150 expect(fc.firstChild.innerText).toEqual('f');
3151 expect(fc.children[1].innerText).toEqual('geq');
3152 // blur
3153 document.body.click();
3154 });
Akronddc98a72018-04-06 17:33:52 +02003155
3156 // Check json deserialization
3157 it('should be initializable', function () {
3158 vc = vcClass.create([
3159 ['a', 'text'],
3160 ['b', 'string'],
3161 ['c', 'date']
3162 ]).fromJson({
3163 "@type" : "koral:doc",
3164 "key":"a",
3165 "value":"Baum"
3166 });
3167
Akronadab5e52018-08-20 13:50:53 +02003168 expect(vc.builder().firstChild.children[1].getAttribute('data-type')).toEqual('text');
Akronddc98a72018-04-06 17:33:52 +02003169 });
Akron712733a2018-04-05 18:17:47 +02003170 });
3171
3172
Akrone4961b12017-05-10 21:04:46 +02003173 // Check prefix
3174 describe('KorAP.VC.Prefix', function () {
3175
3176 it('should be initializable', function () {
3177 var p = prefixClass.create();
3178 expect(p.element().classList.contains('pref')).toBeTruthy();
3179 expect(p.isSet()).not.toBeTruthy();
3180 });
3181
3182
3183 it('should be clickable', function () {
hebastaa0282be2018-12-05 16:58:00 +01003184 KorAP.vc = vcClass.create([
Akron712733a2018-04-05 18:17:47 +02003185 ['a', null],
3186 ['b', null],
3187 ['c', null]
3188 ]).fromJson();
hebastaa0282be2018-12-05 16:58:00 +01003189
3190 //vc = KorAP.vc;
3191
3192 expect(KorAP.vc.builder().firstChild.classList.contains('unspecified')).toBeTruthy();
Akrone4961b12017-05-10 21:04:46 +02003193
3194 // This should open up the menu
hebastaa0282be2018-12-05 16:58:00 +01003195 KorAP.vc.builder().firstChild.firstChild.click();
3196 expect(KorAP.vc.builder().firstChild.firstChild.tagName).toEqual('UL');
Akrone4961b12017-05-10 21:04:46 +02003197
3198 KorAP._vcKeyMenu._prefix.clear();
3199 KorAP._vcKeyMenu._prefix.add('x');
3200
hebastaa0282be2018-12-05 16:58:00 +01003201 var prefElement = KorAP.vc.builder().querySelector('span.pref');
Akrone4961b12017-05-10 21:04:46 +02003202 expect(prefElement.innerText).toEqual('x');
3203
3204 // This should add key 'x' to VC
3205 prefElement.click();
3206
hebastaa0282be2018-12-05 16:58:00 +01003207 expect(KorAP.vc.builder().firstChild.classList.contains('doc')).toBeTruthy();
3208 expect(KorAP.vc.builder().firstChild.firstChild.className).toEqual('key');
3209 expect(KorAP.vc.builder().firstChild.firstChild.innerText).toEqual('x');
Akrone4961b12017-05-10 21:04:46 +02003210 });
3211 });
Akron68d28322018-08-27 15:02:42 +02003212
Akron889ec292018-11-19 17:56:01 +01003213 // Check fragment handling for corpusByMatch helper
Akron68d28322018-08-27 15:02:42 +02003214 describe('KorAP.VC.Fragment', function () {
3215 it('should be initializable', function () {
3216 var f = fragmentClass.create();
3217 var e = f.element();
3218 expect(e.classList.contains('vc')).toBeTruthy();
3219 expect(e.classList.contains('fragment')).toBeTruthy();
Akrond45a1702018-11-19 18:15:17 +01003220 expect(e.firstChild.children.length).toEqual(0);
Akron68d28322018-08-27 15:02:42 +02003221 });
3222
3223 it('should be expansable', function () {
3224 var f = fragmentClass.create();
3225 f.add("author", "Peter");
3226
Akrond45a1702018-11-19 18:15:17 +01003227 var root = f.element().lastChild.firstChild;
Akron68d28322018-08-27 15:02:42 +02003228
3229 expect(root.classList.contains("doc")).toBeTruthy();
3230 expect(root.children[0].tagName).toEqual("SPAN");
3231 expect(root.children[0].textContent).toEqual("author");
3232 expect(root.children[1].tagName).toEqual("SPAN");
3233 expect(root.children[1].textContent).toEqual("eq");
3234 expect(root.children[2].tagName).toEqual("SPAN");
3235 expect(root.children[2].textContent).toEqual("Peter");
3236
3237 f.add("title", "Example");
3238
Akrond45a1702018-11-19 18:15:17 +01003239 root = f.element().lastChild.firstChild;
Akron68d28322018-08-27 15:02:42 +02003240
3241 expect(root.classList.contains("docGroup")).toBeTruthy();
3242
3243 var doc = root.children[0];
3244
3245 expect(doc.children[0].tagName).toEqual("SPAN");
3246 expect(doc.children[0].textContent).toEqual("author");
3247 expect(doc.children[1].tagName).toEqual("SPAN");
3248 expect(doc.children[1].textContent).toEqual("eq");
3249 expect(doc.children[2].tagName).toEqual("SPAN");
3250 expect(doc.children[2].textContent).toEqual("Peter");
3251
3252 doc = root.children[1];
3253
3254 expect(doc.children[0].tagName).toEqual("SPAN");
3255 expect(doc.children[0].textContent).toEqual("title");
3256 expect(doc.children[1].tagName).toEqual("SPAN");
3257 expect(doc.children[1].textContent).toEqual("eq");
3258 expect(doc.children[2].tagName).toEqual("SPAN");
3259 expect(doc.children[2].textContent).toEqual("Example");
3260 });
3261
3262
3263 it('should be reducible', function () {
3264 var f = fragmentClass.create();
Akrond45a1702018-11-19 18:15:17 +01003265 expect(f.element().lastChild.children.length).toEqual(0);
Akron889ec292018-11-19 17:56:01 +01003266
Akron68d28322018-08-27 15:02:42 +02003267 f.add("author", "Peter");
3268 f.add("title", "Example");
3269
Akrond45a1702018-11-19 18:15:17 +01003270 expect(f.element().lastChild.children.length).toEqual(1);
Akron889ec292018-11-19 17:56:01 +01003271
Akrond45a1702018-11-19 18:15:17 +01003272 var root = f.element().lastChild.firstChild;
Akron889ec292018-11-19 17:56:01 +01003273
Akron68d28322018-08-27 15:02:42 +02003274 expect(root.classList.contains("docGroup")).toBeTruthy();
3275
3276 expect(root.children.length).toEqual(2);
3277
3278 f.remove("author","Peter");
3279
Akrond45a1702018-11-19 18:15:17 +01003280 root = f.element().lastChild.firstChild;
Akron68d28322018-08-27 15:02:42 +02003281 expect(root.classList.contains("doc")).toBeTruthy();
3282
3283 expect(root.children[0].tagName).toEqual("SPAN");
3284 expect(root.children[0].textContent).toEqual("title");
3285 expect(root.children[1].tagName).toEqual("SPAN");
3286 expect(root.children[1].textContent).toEqual("eq");
3287 expect(root.children[2].tagName).toEqual("SPAN");
3288 expect(root.children[2].textContent).toEqual("Example");
Akron889ec292018-11-19 17:56:01 +01003289
3290 f.remove("title","Example");
3291
Akrond45a1702018-11-19 18:15:17 +01003292 expect(f.element().lastChild.children.length).toEqual(0);
Akron68d28322018-08-27 15:02:42 +02003293 });
Akron2761d882020-10-13 10:35:09 +02003294
3295 it('should respect already set attributes', function () {
3296 var f = fragmentClass.create();
3297 expect(f.element().lastChild.children.length).toEqual(0);
3298
3299 expect(f.isEmpty()).toBeTruthy();
3300
3301 f.add("author", "Peter");
3302 f.add("title", "Example");
3303
3304 expect(f.isEmpty()).toBeFalsy();
3305
3306 expect(f.toQuery()).toEqual('author = "Peter" & title = "Example"');
3307
3308 f.add("author", "Peter");
3309
3310 expect(f.toQuery()).toEqual('title = "Example" & author = "Peter"');
3311 });
Akron68d28322018-08-27 15:02:42 +02003312 });
Nils Diewald2fe12e12015-03-06 16:47:06 +00003313});