blob: 3edfdf82545f37ef32a81da43a0d761759c5f589 [file] [log] [blame]
Nils Diewald6ac292b2015-01-15 21:33:21 +00001/*
Nils Diewald7c8ced22015-04-15 19:21:00 +00002 * Todo: In demoSpec: Create "and" on the last element of the top "or"-Group
3 */
Akrondd5c6d32018-08-17 14:12:58 +02004define([
5 'vc',
6 'vc/doc',
7 'vc/menu',
8 'vc/prefix',
9 'vc/docgroup',
10 'vc/docgroupref',
11 'vc/unspecified',
12 'vc/operators',
13 'vc/rewrite',
14 'vc/stringval'
15], function (vcClass,
16 docClass,
17 menuClass,
18 prefixClass,
19 docGroupClass,
20 docGroupRefClass,
21 unspecifiedClass,
22 operatorsClass,
23 rewriteClass,
24 stringValClass) {
Nils Diewald6ac292b2015-01-15 21:33:21 +000025
Akrondd5c6d32018-08-17 14:12:58 +020026 KorAP._vcKeyMenu = undefined;
27
Nils Diewald6ac292b2015-01-15 21:33:21 +000028
Nils Diewald7c8ced22015-04-15 19:21:00 +000029 // Helper method for building factories
30 buildFactory = function (objClass, defaults) {
31 return {
32 create : function (overwrites) {
Akron712733a2018-04-05 18:17:47 +020033 var newObj = {};
34 for (var prop in defaults) {
35 newObj[prop] = defaults[prop];
36 };
37 for (var prop in overwrites) {
38 newObj[prop] = overwrites[prop];
39 };
40 return objClass.create().fromJson(newObj);
Nils Diewald7c8ced22015-04-15 19:21:00 +000041 }
Nils Diewald0b6c0412014-12-19 03:55:57 +000042 }
Nils Diewald7c8ced22015-04-15 19:21:00 +000043 };
Nils Diewald0b6c0412014-12-19 03:55:57 +000044
Nils Diewald7c8ced22015-04-15 19:21:00 +000045 function _andOn (obj) {
Akrond141a362018-07-10 18:12:13 +020046 KorAP._and.apply(obj);
Nils Diewald7c8ced22015-04-15 19:21:00 +000047 };
Nils Diewald52f7eb12015-01-12 17:30:04 +000048
Nils Diewald7c8ced22015-04-15 19:21:00 +000049 function _orOn (obj) {
Akrond141a362018-07-10 18:12:13 +020050 KorAP._or.apply(obj);
Nils Diewald7c8ced22015-04-15 19:21:00 +000051 };
Nils Diewald52f7eb12015-01-12 17:30:04 +000052
Nils Diewald7c8ced22015-04-15 19:21:00 +000053 function _delOn (obj) {
Akrond141a362018-07-10 18:12:13 +020054 KorAP._delete.apply(obj);
Nils Diewald7c8ced22015-04-15 19:21:00 +000055 };
Nils Diewald52f7eb12015-01-12 17:30:04 +000056
Nils Diewald7c8ced22015-04-15 19:21:00 +000057 var demoFactory = buildFactory(vcClass, {
58 "@type":"koral:docGroup",
59 "operation":"operation:or",
60 "operands":[
Nils Diewaldf219eb82015-01-07 20:15:42 +000061 {
Akron712733a2018-04-05 18:17:47 +020062 "@type":"koral:docGroup",
63 "operation":"operation:and",
64 "operands":[
Nils Diewald7c8ced22015-04-15 19:21:00 +000065 {
66 "@type":"koral:doc",
67 "key":"Titel",
68 "value":"Baum",
69 "match":"match:eq"
70 },
71 {
72 "@type":"koral:doc",
73 "key":"Veröffentlichungsort",
74 "value":"hihi",
75 "match":"match:eq"
76 },
77 {
78 "@type":"koral:docGroup",
79 "operation":"operation:or",
80 "operands":[
81 {
Akron712733a2018-04-05 18:17:47 +020082 "@type":"koral:doc",
83 "key":"Titel",
84 "value":"Baum",
85 "match":"match:eq"
Nils Diewald7c8ced22015-04-15 19:21:00 +000086 },
87 {
Akron712733a2018-04-05 18:17:47 +020088 "@type":"koral:doc",
89 "key":"Veröffentlichungsort",
90 "value":"hihi",
91 "match":"match:eq"
Nils Diewald7c8ced22015-04-15 19:21:00 +000092 }
93 ]
94 }
Akron712733a2018-04-05 18:17:47 +020095 ]
Nils Diewaldf219eb82015-01-07 20:15:42 +000096 },
97 {
Akron712733a2018-04-05 18:17:47 +020098 "@type":"koral:doc",
99 "key":"Untertitel",
100 "value":"huhu",
101 "match":"match:contains"
Nils Diewaldf219eb82015-01-07 20:15:42 +0000102 }
103 ]
104 });
105
Nils Diewald7c8ced22015-04-15 19:21:00 +0000106 describe('KorAP.Doc', function () {
107 // Create example factories
108 var stringFactory = buildFactory(docClass, {
109 "key" : "author",
110 "value" : "Max Birkendale",
Akron31d89942018-04-06 16:44:51 +0200111 "type" : "type:string",
Nils Diewald7c8ced22015-04-15 19:21:00 +0000112 "@type" : "koral:doc"
113 });
114
115 // Create example factories
Akron712733a2018-04-05 18:17:47 +0200116 var textFactory = buildFactory(docClass, {
117 "key" : "author",
118 "value" : "Birkendale",
Akron31d89942018-04-06 16:44:51 +0200119 "type" : "type:string",
Akron712733a2018-04-05 18:17:47 +0200120 "match" : "match:contains",
121 "@type" : "koral:doc"
122 });
123
124 // Create example factories
Nils Diewald7c8ced22015-04-15 19:21:00 +0000125 var dateFactory = buildFactory(docClass, {
126 "key" : "pubDate",
127 "type" : "type:date",
128 "match" : "match:eq",
129 "value" : "2014-11-05",
130 "@type" : "koral:doc"
131 });
132
133 // Create example factories
134 var regexFactory = buildFactory(docClass, {
135 "key" : "title",
136 "type" : "type:regex",
137 "value" : "[^b]ee.+?",
138 "@type" : "koral:doc"
139 });
140
141 it('should be initializable', function () {
142 var doc = docClass.create();
143 expect(doc.matchop()).toEqual('eq');
144 expect(doc.key()).toBeUndefined();
145 expect(doc.value()).toBeUndefined();
146 expect(doc.type()).toEqual("string");
147 });
148
149 it('should be definable', function () {
150
151 // Empty doc
152 var doc = docClass.create();
153
154 // Set values
155 doc.key("title");
Akron8db5e3a2018-05-28 19:25:26 +0200156
Nils Diewald7c8ced22015-04-15 19:21:00 +0000157 doc.value("Der alte Mann");
158 expect(doc.matchop()).toEqual('eq');
159 expect(doc.key()).toEqual("title");
160 expect(doc.type()).toEqual("string");
161 expect(doc.value()).toEqual("Der alte Mann");
162 });
163
164
165 it('should deserialize JSON-LD string', function () {
166 var doc;
167
168 // String default
169 doc = stringFactory.create();
170 expect(doc.matchop()).toEqual('eq');
171 expect(doc.key()).toEqual("author");
172 expect(doc.type()).toEqual("string");
173 expect(doc.value()).toEqual("Max Birkendale");
174
175 // No valid string
176 doc = stringFactory.create({
Akron712733a2018-04-05 18:17:47 +0200177 value : undefined
Nils Diewald7c8ced22015-04-15 19:21:00 +0000178 });
179 expect(doc).toBeUndefined();
180
181 // No valid string
182 doc = stringFactory.create({
Akron712733a2018-04-05 18:17:47 +0200183 value : { "foo" : "bar" }
Nils Diewald7c8ced22015-04-15 19:21:00 +0000184 });
185 expect(doc).toBeUndefined();
186
187 // Change match type
188 doc = stringFactory.create({
Akron712733a2018-04-05 18:17:47 +0200189 "match" : "match:ne"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000190 });
191
192 expect(doc.matchop()).toEqual('ne');
193 expect(doc.key()).toEqual("author");
194 expect(doc.type()).toEqual("string");
195 expect(doc.value()).toEqual("Max Birkendale");
196
197 // Invalid match type
198 doc = stringFactory.create({
Akron712733a2018-04-05 18:17:47 +0200199 "match" : { "foo" : "bar" }
Nils Diewald7c8ced22015-04-15 19:21:00 +0000200 });
201 expect(doc).toBeUndefined();
202 });
203
204 it('should deserialize JSON-LD regex', function () {
205 var doc = regexFactory.create();
206 expect(doc.key()).toEqual("title");
207 expect(doc.type()).toEqual("regex");
208 expect(doc.value()).toEqual("[^b]ee.+?");
209 expect(doc.matchop()).toEqual('eq');
210
211 // change matcher
212 doc = regexFactory.create({
Akron712733a2018-04-05 18:17:47 +0200213 match : "match:ne"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000214 });
215 expect(doc.matchop()).toEqual('ne');
Akronea4e9052017-07-06 16:12:05 +0200216 expect(doc.rewrites()).toBeUndefined();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000217
218 // Invalid matcher
219 doc = regexFactory.create({
Akron712733a2018-04-05 18:17:47 +0200220 match : "match:chook"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000221 });
Akronea4e9052017-07-06 16:12:05 +0200222 expect(doc.matchop()).toEqual('eq');
223 expect(doc.rewrites()).toBeDefined();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000224
225 // Invalid regex
226 doc = regexFactory.create({
Akron712733a2018-04-05 18:17:47 +0200227 value : "[^b"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000228 });
229 expect(doc).toBeUndefined();
230 });
231
232 it('should deserialize JSON-LD date', function () {
233
234 // Normal date
235 doc = dateFactory.create({});
236
237 expect(doc.matchop()).toEqual('eq');
238 expect(doc.key()).toEqual("pubDate");
239 expect(doc.type()).toEqual("date");
240 expect(doc.value()).toEqual("2014-11-05");
241
242 // Short date 1
243 doc = dateFactory.create({
Akron712733a2018-04-05 18:17:47 +0200244 "value" : "2014-11"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000245 });
246
247 expect(doc.matchop()).toEqual('eq');
248 expect(doc.key()).toEqual("pubDate");
249 expect(doc.type()).toEqual("date");
250 expect(doc.value()).toEqual("2014-11");
251
252 // Short date 2
253 doc = dateFactory.create({
Akron712733a2018-04-05 18:17:47 +0200254 "value" : "2014"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000255 });
256
257 expect(doc.matchop()).toEqual('eq');
258 expect(doc.key()).toEqual("pubDate");
259 expect(doc.type()).toEqual("date");
260 expect(doc.value()).toEqual("2014");
261
262 // Invalid date!
263 doc = dateFactory.create({
Akron712733a2018-04-05 18:17:47 +0200264 "value" : "2014-11-050"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000265 });
266 expect(doc).toBeUndefined();
267
268 // Invalid matcher!
269 doc = dateFactory.create({
Akron31d89942018-04-06 16:44:51 +0200270 "match" : "match:contains",
Nils Diewald7c8ced22015-04-15 19:21:00 +0000271 });
Akronea4e9052017-07-06 16:12:05 +0200272 expect(doc).toBeDefined();
273 expect(doc.rewrites()).toBeDefined();
274 expect(doc.matchop()).toEqual('eq');
Nils Diewald7c8ced22015-04-15 19:21:00 +0000275 });
276
277 it('should be serializale to JSON', function () {
278
279 // Empty doc
280 var doc = docClass.create();
281 expect(doc.toJson()).toEqual(jasmine.any(Object));
282
283 // Serialize string
284 doc = stringFactory.create();
285 expect(doc.toJson()).toEqual(jasmine.objectContaining({
Akron712733a2018-04-05 18:17:47 +0200286 "@type" : "koral:doc",
287 "type" : "type:string",
288 "key" : "author",
289 "value" : "Max Birkendale",
290 "match" : "match:eq"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000291 }));
292
293 // Serialize regex
294 doc = regexFactory.create();
295 expect(doc.toJson()).toEqual(jasmine.objectContaining({
Akron712733a2018-04-05 18:17:47 +0200296 "@type" : "koral:doc",
297 "type" : "type:regex",
298 "value" : "[^b]ee.+?",
299 "match" : "match:eq",
300 "key" : 'title'
Nils Diewald7c8ced22015-04-15 19:21:00 +0000301 }));
302
303 doc = regexFactory.create({
Akron712733a2018-04-05 18:17:47 +0200304 match: "match:ne"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000305 });
306 expect(doc.toJson()).toEqual(jasmine.objectContaining({
Akron712733a2018-04-05 18:17:47 +0200307 "@type" : "koral:doc",
308 "type" : "type:regex",
309 "value" : "[^b]ee.+?",
310 "match" : "match:ne",
311 "key" : 'title'
Nils Diewald7c8ced22015-04-15 19:21:00 +0000312 }));
313
314 doc = dateFactory.create();
315 expect(doc.toJson()).toEqual(jasmine.objectContaining({
Akron712733a2018-04-05 18:17:47 +0200316 "@type" : "koral:doc",
317 "type" : "type:date",
318 "value" : "2014-11-05",
319 "match" : "match:eq",
320 "key" : 'pubDate'
Nils Diewald7c8ced22015-04-15 19:21:00 +0000321 }));
322
323 doc = dateFactory.create({
Akron712733a2018-04-05 18:17:47 +0200324 value : "2014"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000325 });
326 expect(doc.toJson()).toEqual(jasmine.objectContaining({
Akron712733a2018-04-05 18:17:47 +0200327 "@type" : "koral:doc",
328 "type" : "type:date",
329 "value" : "2014",
330 "match" : "match:eq",
331 "key" : 'pubDate'
Nils Diewald7c8ced22015-04-15 19:21:00 +0000332 }));
333 });
334
335
336 it('should be serializale to String', function () {
337 // Empty doc
338 var doc = docClass.create();
339 expect(doc.toQuery()).toEqual("");
340
341 // Serialize string
342 doc = stringFactory.create();
343 expect(doc.toQuery()).toEqual('author = "Max Birkendale"');
344
345 // Serialize string with quotes
346 doc = stringFactory.create({ "value" : 'Max "Der Coole" Birkendate'});
347 expect(doc.toQuery()).toEqual('author = "Max \\"Der Coole\\" Birkendate"');
348
349 // Serialize regex
350 doc = regexFactory.create();
351 expect(doc.toQuery()).toEqual('title = /[^b]ee.+?/');
352
353 doc = regexFactory.create({
Akron712733a2018-04-05 18:17:47 +0200354 match: "match:ne"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000355 });
356 expect(doc.toQuery()).toEqual('title != /[^b]ee.+?/');
357
Akron8778f5d2017-06-30 21:25:55 +0200358 doc = regexFactory.create({
Akron712733a2018-04-05 18:17:47 +0200359 value: "WPD/AAA/00001"
Akron8778f5d2017-06-30 21:25:55 +0200360 });
361 expect(doc.toQuery()).toEqual('title = /WPD\\/AAA\\/00001/');
362
Nils Diewald7c8ced22015-04-15 19:21:00 +0000363 doc = dateFactory.create();
364 expect(doc.toQuery()).toEqual('pubDate in 2014-11-05');
365
366 doc = dateFactory.create({
Akron712733a2018-04-05 18:17:47 +0200367 value : "2014"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000368 });
369 expect(doc.toQuery()).toEqual('pubDate in 2014');
370 });
371 });
372
373
374 describe('KorAP.DocGroup', function () {
375 // Create example factories
376 var docFactory = buildFactory(
377 docClass,
Nils Diewaldf219eb82015-01-07 20:15:42 +0000378 {
Akron712733a2018-04-05 18:17:47 +0200379 "@type" : "koral:doc",
380 "match":"match:eq",
381 "key" : "author",
382 "value" : "Max Birkendale"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000383 }
384 );
385
386 var docGroupFactory = buildFactory(
387 docGroupClass, {
Akron712733a2018-04-05 18:17:47 +0200388 "@type" : "koral:docGroup",
389 "operation" : "operation:and",
390 "operands" : [
391 docFactory.create().toJson(),
392 docFactory.create({
393 "key" : "pubDate",
394 "type" : "type:date",
395 "value" : "2014-12-05"
396 }).toJson()
397 ]
Nils Diewald7c8ced22015-04-15 19:21:00 +0000398 });
399
400 it('should be initializable', function () {
401 // Create empty group
402 var docGroup = docGroupClass.create();
403 expect(docGroup.operation()).toEqual('and');
404
405 // Create empty group
406 docGroup = docGroupClass.create();
407 docGroup.operation('or');
408 expect(docGroup.operation()).toEqual('or');
409 });
410
411 it('should be definable', function () {
412
413 // Empty group
414 var docGroup = docGroupClass.create();
415 expect(docGroup.operation()).toEqual('and');
416
417 // Set values
418 docGroup.operation("or");
419 expect(docGroup.operation()).toEqual('or');
420
421 // Set invalid values
422 docGroup.operation("hui");
423 expect(docGroup.operation()).toEqual('or');
424 });
425
426 it('should be deserializable', function () {
Akronadab5e52018-08-20 13:50:53 +0200427
428 // Reset list
429 KorAP._vcKeyMenu = menuClass.create([['referTo','ref']]);
430
Nils Diewald7c8ced22015-04-15 19:21:00 +0000431 var docGroup = docGroupFactory.create();
432 expect(docGroup.operation()).toEqual("and");
433 expect(docGroup.operands().length).toEqual(2);
434
435 var op1 = docGroup.getOperand(0);
436 expect(op1.type()).toEqual("string");
437 expect(op1.key()).toEqual("author");
438 expect(op1.value()).toEqual("Max Birkendale");
439 expect(op1.matchop()).toEqual("eq");
440
441 var op2 = docGroup.getOperand(1);
442 expect(op2.type()).toEqual("date");
443 expect(op2.key()).toEqual("pubDate");
444 expect(op2.value()).toEqual("2014-12-05");
445 expect(op2.matchop()).toEqual("eq");
446
447 // Append empty group
448 var newGroup = docGroup.append(docGroupClass.create());
449 newGroup.operation('or');
450 newGroup.append(docFactory.create());
451 newGroup.append(docFactory.create({
Akron712733a2018-04-05 18:17:47 +0200452 "type" : "type:regex",
453 "key" : "title",
454 "value" : "^e.+?$",
455 "match" : "match:ne"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000456 }));
457
458 expect(docGroup.operation()).toEqual("and");
459 expect(docGroup.operands().length).toEqual(3);
460
461 var op1 = docGroup.getOperand(0);
462 expect(op1.ldType()).toEqual("doc");
463 expect(op1.type()).toEqual("string");
464 expect(op1.key()).toEqual("author");
465 expect(op1.value()).toEqual("Max Birkendale");
466 expect(op1.matchop()).toEqual("eq");
467
468 var op2 = docGroup.getOperand(1);
469 expect(op2.ldType()).toEqual("doc");
470 expect(op2.type()).toEqual("date");
471 expect(op2.key()).toEqual("pubDate");
472 expect(op2.value()).toEqual("2014-12-05");
473 expect(op2.matchop()).toEqual("eq");
474
475 var op3 = docGroup.getOperand(2);
476 expect(op3.ldType()).toEqual("docGroup");
477 expect(op3.operation()).toEqual("or");
Akronadab5e52018-08-20 13:50:53 +0200478
Nils Diewald7c8ced22015-04-15 19:21:00 +0000479 var op4 = op3.getOperand(0);
480 expect(op4.ldType()).toEqual("doc");
481 expect(op4.type()).toEqual("string");
482 expect(op4.key()).toEqual("author");
483 expect(op4.value()).toEqual("Max Birkendale");
484 expect(op4.matchop()).toEqual("eq");
485
486 var op5 = op3.getOperand(1);
487 expect(op5.ldType()).toEqual("doc");
488 expect(op5.type()).toEqual("regex");
489 expect(op5.key()).toEqual("title");
490 expect(op5.value()).toEqual("^e.+?$");
491 expect(op5.matchop()).toEqual("ne");
492 });
493
494 it('should be serializable to JSON', function () {
495 var docGroup = docGroupFactory.create();
496
497 expect(docGroup.toJson()).toEqual(jasmine.objectContaining({
Akron712733a2018-04-05 18:17:47 +0200498 "@type" : "koral:docGroup",
499 "operation" : "operation:and",
500 "operands" : [
501 {
502 "@type": 'koral:doc',
503 "key" : 'author',
504 "match": 'match:eq',
505 "value": 'Max Birkendale',
506 "type": 'type:string'
507 },
508 {
509 "@type": 'koral:doc',
510 "key": 'pubDate',
511 "match": 'match:eq',
512 "value": '2014-12-05',
513 "type": 'type:date'
514 }
515 ]
Nils Diewald7c8ced22015-04-15 19:21:00 +0000516 }));
517 });
Nils Diewalde15b7a22015-01-09 21:50:21 +0000518
Nils Diewald7c8ced22015-04-15 19:21:00 +0000519 it('should be serializable to String', function () {
520 var docGroup = docGroupFactory.create();
521 expect(docGroup.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +0200522 'author = "Max Birkendale" & pubDate in 2014-12-05'
Nils Diewald7c8ced22015-04-15 19:21:00 +0000523 );
Nils Diewald52f7eb12015-01-12 17:30:04 +0000524
Nils Diewald7c8ced22015-04-15 19:21:00 +0000525 docGroup = docGroupFactory.create({
Akron712733a2018-04-05 18:17:47 +0200526 "@type" : "koral:docGroup",
527 "operation" : "operation:or",
528 "operands" : [
529 {
530 "@type": 'koral:doc',
531 "key" : 'author',
532 "match": 'match:eq',
533 "value": 'Max Birkendale',
534 "type": 'type:string'
535 },
536 {
537 "@type" : "koral:docGroup",
538 "operation" : "operation:and",
539 "operands" : [
540 {
541 "@type": 'koral:doc',
542 "key": 'pubDate',
543 "match": 'match:geq',
544 "value": '2014-05-12',
545 "type": 'type:date'
546 },
547 {
548 "@type": 'koral:doc',
549 "key": 'pubDate',
550 "match": 'match:leq',
551 "value": '2014-12-05',
552 "type": 'type:date'
553 },
554 {
555 "@type": 'koral:doc',
556 "key": 'foo',
557 "match": 'match:ne',
558 "value": '[a]?bar',
559 "type": 'type:regex'
560 }
561 ]
562 }
563 ]
Nils Diewald7c8ced22015-04-15 19:21:00 +0000564 });
565 expect(docGroup.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +0200566 'author = "Max Birkendale" | ' +
567 '(pubDate since 2014-05-12 & ' +
568 'pubDate until 2014-12-05 & foo != /[a]?bar/)'
Nils Diewald7c8ced22015-04-15 19:21:00 +0000569 );
570 });
571 });
572
Akronb19803c2018-08-16 16:39:42 +0200573 describe('KorAP.DocGroupRef', function () {
574 // Create example factories
575 var docRefFactory = buildFactory(
576 docGroupRefClass,
577 {
578 "@type" : "koral:docGroupRef",
579 "ref" : "@max/myCorpus"
580 }
581 );
582
583 it('should be initializable', function () {
584 var vcRef = docGroupRefClass.create();
585 expect(vcRef.ref()).toBeUndefined();
586 });
587
588 it('should be definable', function () {
589 var vcRef = docGroupRefClass.create();
590 vcRef.ref("@peter/mycorpus");
591 expect(vcRef.ref()).toEqual("@peter/mycorpus");
592 vcRef.ref("@peter/mycorpus2");
593 expect(vcRef.ref()).toEqual("@peter/mycorpus2");
594 });
595
596 it('should deserialize JSON-LD string', function () {
597 var vcRef = docRefFactory.create();
598 expect(vcRef.ref()).toEqual("@max/myCorpus");
599 });
600
601 it('should serialize to JSON-LD', function () {
602 var vcRef = docRefFactory.create();
603 expect(vcRef.toJson()).toEqual(jasmine.objectContaining({
604 "@type" : "koral:docGroupRef",
605 "ref":"@max/myCorpus"
606 }));
607
608 vcRef.ref("@peter/myCorpus2");
609 expect(vcRef.toJson()).toEqual(jasmine.objectContaining({
610 "@type" : "koral:docGroupRef",
611 "ref":"@peter/myCorpus2"
612 }));
613 });
614
615 it('should serialize to a query', function () {
616 var vcRef = docRefFactory.create();
617 expect(vcRef.toQuery()).toEqual(
618 "referTo \"@max/myCorpus\""
619 );
620
621 vcRef.ref("@peter/myCorpus2");
622 expect(vcRef.toQuery()).toEqual(
623 "referTo \"@peter/myCorpus2\""
624 );
625 });
626 });
627
628
Nils Diewald7c8ced22015-04-15 19:21:00 +0000629 describe('KorAP.UnspecifiedDoc', function () {
630 it('should be initializable', function () {
631 var doc = unspecifiedClass.create();
632 var docElement = doc.element();
633 expect(docElement.getAttribute('class')).toEqual('doc unspecified');
634 expect(docElement.firstChild.firstChild.data).toEqual('⋯');
635 expect(docElement.lastChild.lastChild.data).toEqual('⋯');
636 expect(doc.toQuery()).toEqual('');
637
638 // Only removable
639 expect(docElement.lastChild.children.length).toEqual(0);
640 });
641
Akrond141a362018-07-10 18:12:13 +0200642 it('should be removable, when no root', function () {
Nils Diewald7c8ced22015-04-15 19:21:00 +0000643 var docGroup = docGroupClass.create();
644 docGroup.operation('or');
645 expect(docGroup.operation()).toEqual('or');
646
647 docGroup.append({
Akron712733a2018-04-05 18:17:47 +0200648 "@type": 'koral:doc',
649 "key": 'pubDate',
650 "match": 'match:eq',
651 "value": '2014-12-05',
652 "type": 'type:date'
Nils Diewald7c8ced22015-04-15 19:21:00 +0000653 });
654
655 // Add unspecified object
656 docGroup.append();
657
Akrond141a362018-07-10 18:12:13 +0200658 var parent = document.createElement('div');
659 parent.appendChild(docGroup.element());
660
Nils Diewald7c8ced22015-04-15 19:21:00 +0000661 expect(docGroup.element().getAttribute('class')).toEqual('docGroup');
662 expect(docGroup.element().children[0].getAttribute('class')).toEqual('doc');
663
664 var unspec = docGroup.element().children[1];
665 expect(unspec.getAttribute('class')).toEqual('doc unspecified');
666
Akronb19803c2018-08-16 16:39:42 +0200667 // Only unspec and delete
668 expect(unspec.children.length).toEqual(2);
669
Nils Diewald7c8ced22015-04-15 19:21:00 +0000670 // Removable
671 expect(unspec.lastChild.children.length).toEqual(1);
672 expect(unspec.lastChild.children[0].getAttribute('class')).toEqual('delete');
673 });
674
Akrond141a362018-07-10 18:12:13 +0200675
Nils Diewald7c8ced22015-04-15 19:21:00 +0000676 it('should be replaceable by a doc', function () {
677 var doc = unspecifiedClass.create();
678 expect(doc.ldType()).toEqual("non");
679 // No parent, therefor not updateable
680 expect(doc.key("baum")).toBeNull();
681
682 var docGroup = docGroupClass.create();
683 docGroup.operation('or');
684 expect(docGroup.operation()).toEqual('or');
685
686 docGroup.append({
Akron712733a2018-04-05 18:17:47 +0200687 "@type": 'koral:doc',
688 "key": 'pubDate',
689 "match": 'match:eq',
690 "value": '2014-12-05',
691 "type": 'type:date'
Nils Diewald7c8ced22015-04-15 19:21:00 +0000692 });
693
694 expect(docGroup.toQuery()).toEqual("pubDate in 2014-12-05");
695 docGroup.append();
696
697 expect(docGroup.getOperand(0).ldType()).toEqual("doc");
698 expect(docGroup.getOperand(1).ldType()).toEqual("non");
699
700 var op = docGroup.getOperand(1).element().lastChild;
Akron0b489ad2018-02-02 16:49:32 +0100701 expect(op.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +0000702 expect(op.children[0].getAttribute('class')).toEqual('delete');
703 expect(op.children.length).toEqual(1);
704
705 // Replace unspecified doc
706 expect(docGroup.getOperand(1).key("name")).not.toBeNull();
707 expect(docGroup.getOperand(1).ldType()).toEqual("doc");
708 expect(docGroup.getOperand(1).key()).toEqual("name");
Akron55a343b2018-04-06 19:57:36 +0200709 expect(docGroup.getOperand(1).value()).toBeUndefined();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000710
Akronb19803c2018-08-16 16:39:42 +0200711 expect(docGroup.getOperand(1).element().children.length).toEqual(4);
712
Nils Diewald7c8ced22015-04-15 19:21:00 +0000713 op = docGroup.getOperand(1).element().lastChild;
Akron0b489ad2018-02-02 16:49:32 +0100714 expect(op.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +0000715 expect(op.children[0].getAttribute('class')).toEqual('and');
716 expect(op.children[1].getAttribute('class')).toEqual('or');
717 expect(op.children[2].getAttribute('class')).toEqual('delete');
Akronb19803c2018-08-16 16:39:42 +0200718
Nils Diewald7c8ced22015-04-15 19:21:00 +0000719 expect(op.children.length).toEqual(3);
720
721 docGroup.getOperand(1).value("Pachelbel");
722 expect(docGroup.getOperand(1).value()).toEqual("Pachelbel");
723 expect(docGroup.getOperand(1).type()).toEqual("string");
724 expect(docGroup.getOperand(1).matchop()).toEqual("eq");
725
726 // Specified!
727 expect(docGroup.toQuery()).toEqual('pubDate in 2014-12-05 | name = "Pachelbel"');
728 });
Akronb19803c2018-08-16 16:39:42 +0200729
Nils Diewald7c8ced22015-04-15 19:21:00 +0000730 it('should be replaceable on root', function () {
Nils Diewald6283d692015-04-23 20:32:53 +0000731 var vc = vcClass.create();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000732 expect(vc.toQuery()).toEqual("");
733
734 expect(vc.root().ldType()).toEqual("non");
735
736 // No operators on root
737 op = vc.root().element().lastChild;
738 expect(op.lastChild.textContent).toEqual('⋯');
739
740 // Replace
741 expect(vc.root().key("baum")).not.toBeNull();
742 expect(vc.root().ldType()).toEqual("doc");
743
744 op = vc.root().element().lastChild;
Akron0b489ad2018-02-02 16:49:32 +0100745 expect(op.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +0000746 expect(op.children[0].getAttribute('class')).toEqual('and');
747 expect(op.children[1].getAttribute('class')).toEqual('or');
748 expect(op.children[2].getAttribute('class')).toEqual('delete');
749 expect(op.children.length).toEqual(3);
750 });
Akron55a343b2018-04-06 19:57:36 +0200751
752 it('should be clickable', function () {
753 var vc = vcClass.create([
754 ["pubDate", "date"]
755 ]);
756 expect(vc.toQuery()).toEqual("");
Akronadab5e52018-08-20 13:50:53 +0200757 expect(vc.builder().firstChild.textContent).toEqual("⋯");
758 vc.builder().firstChild.firstChild.click();
Akron55a343b2018-04-06 19:57:36 +0200759
760 // Click on pubDate
Akron3ad46942018-08-22 16:47:14 +0200761 vc.element().firstChild.getElementsByTagName("LI")[1].click();
Akronadab5e52018-08-20 13:50:53 +0200762 expect(vc.builder().firstChild.firstChild.textContent).toEqual("pubDate");
763 expect(vc.builder().firstChild.children[1].getAttribute("data-type")).toEqual("date");
Akron55a343b2018-04-06 19:57:36 +0200764 });
Nils Diewald7c8ced22015-04-15 19:21:00 +0000765 });
766
767 describe('KorAP.Doc element', function () {
768 it('should be initializable', function () {
769 var docElement = docClass.create(undefined, {
Akron712733a2018-04-05 18:17:47 +0200770 "@type" : "koral:doc",
771 "key":"Titel",
772 "value":"Baum",
773 "match":"match:eq"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000774 });
775 expect(docElement.key()).toEqual('Titel');
776 expect(docElement.matchop()).toEqual('eq');
777 expect(docElement.value()).toEqual('Baum');
778
779 var docE = docElement.element();
780 expect(docE.children[0].firstChild.data).toEqual('Titel');
781 expect(docE.children[1].firstChild.data).toEqual('eq');
782 expect(docE.children[1].getAttribute('data-type')).toEqual('string');
783 expect(docE.children[2].firstChild.data).toEqual('Baum');
784 expect(docE.children[2].getAttribute('data-type')).toEqual('string');
785
786 expect(docElement.toJson()).toEqual(jasmine.objectContaining({
Akron712733a2018-04-05 18:17:47 +0200787 "@type" : "koral:doc",
788 "key":"Titel",
789 "value":"Baum",
790 "match":"match:eq"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000791 }));
792 });
Akronb19803c2018-08-16 16:39:42 +0200793
794
795 it('should be replacable by unspecified', function () {
796 var vc = vcClass.create([
797 ["pubDate", "date"]
798 ]).fromJson({
799 "@type" : "koral:doc",
800 "key":"Titel",
801 "value":"Baum",
802 "match":"match:eq"
803 });
804 expect(vc.toQuery()).toEqual("Titel = \"Baum\"");
805
Akronadab5e52018-08-20 13:50:53 +0200806 var vcE = vc.builder();
Akronb19803c2018-08-16 16:39:42 +0200807 expect(vcE.firstChild.children.length).toEqual(4);
808
809 // Click to delete
810 vcE.firstChild.lastChild.lastChild.click();
811
812 expect(vcE.firstChild.children.length).toEqual(1);
813
814 expect(vcE.firstChild.textContent).toEqual("⋯");
815 vcE.firstChild.firstChild.click();
816
817 // Click on pubDate
Akron3ad46942018-08-22 16:47:14 +0200818 vcE.firstChild.getElementsByTagName("LI")[1].click();
Akronb19803c2018-08-16 16:39:42 +0200819
820 expect(vcE.firstChild.firstChild.textContent).toEqual("pubDate");
821 expect(vcE.firstChild.children[1].getAttribute("data-type")).toEqual("date");
822
823 expect(vcE.firstChild.children.length).toEqual(4);
824 });
825
826
827 it('should be replaceable by a docGroupRef', function () {
Akron3ad46942018-08-22 16:47:14 +0200828 var vc = vcClass.create().fromJson({
Akronb19803c2018-08-16 16:39:42 +0200829 "@type" : "koral:doc",
830 "key":"Titel",
831 "value":"Baum",
832 "match":"match:eq"
833 });
834
835 expect(vc.toQuery()).toEqual("Titel = \"Baum\"");
836
Akronadab5e52018-08-20 13:50:53 +0200837 var vcE = vc.builder();
Akronb19803c2018-08-16 16:39:42 +0200838 expect(vcE.firstChild.children.length).toEqual(4);
839
840 // Click to delete
841 vcE.firstChild.lastChild.lastChild.click();
842
843 expect(vcE.firstChild.children.length).toEqual(1);
844
845 expect(vcE.firstChild.textContent).toEqual("⋯");
846 vcE.firstChild.firstChild.click();
847
Akron3ad46942018-08-22 16:47:14 +0200848 // Click on referTo
Akronb19803c2018-08-16 16:39:42 +0200849 vcE.firstChild.getElementsByTagName("LI")[0].click();
850
Akron3ad46942018-08-22 16:47:14 +0200851 expect(vcE.firstChild.firstChild.textContent).toEqual("referTo");
Akronb19803c2018-08-16 16:39:42 +0200852 expect(vcE.firstChild.children[1].getAttribute("data-type")).toEqual("string");
853 expect(vcE.firstChild.children.length).toEqual(3);
854 });
Nils Diewald7c8ced22015-04-15 19:21:00 +0000855 });
856
857 describe('KorAP.DocGroup element', function () {
858 it('should be initializable', function () {
859
860 var docGroup = docGroupClass.create(undefined, {
Akron712733a2018-04-05 18:17:47 +0200861 "@type" : "koral:docGroup",
862 "operation" : "operation:and",
863 "operands" : [
864 {
865 "@type": 'koral:doc',
866 "key" : 'author',
867 "match": 'match:eq',
868 "value": 'Max Birkendale',
869 "type": 'type:string'
870 },
871 {
872 "@type": 'koral:doc',
873 "key": 'pubDate',
874 "match": 'match:eq',
875 "value": '2014-12-05',
876 "type": 'type:date'
877 }
878 ]
Nils Diewald7c8ced22015-04-15 19:21:00 +0000879 });
880
881 expect(docGroup.operation()).toEqual('and');
882 var e = docGroup.element();
883 expect(e.getAttribute('class')).toEqual('docGroup');
884 expect(e.getAttribute('data-operation')).toEqual('and');
885
886 var first = e.children[0];
887 expect(first.getAttribute('class')).toEqual('doc');
888 expect(first.children[0].getAttribute('class')).toEqual('key');
889 expect(first.children[1].getAttribute('class')).toEqual('match');
890 expect(first.children[2].getAttribute('class')).toEqual('value');
891 expect(first.children[2].getAttribute('data-type')).toEqual('string');
892 expect(first.children[0].firstChild.data).toEqual('author');
893 expect(first.children[1].firstChild.data).toEqual('eq');
894 expect(first.children[2].firstChild.data).toEqual('Max Birkendale');
895
896 var second = e.children[1];
897 expect(second.getAttribute('class')).toEqual('doc');
898 expect(second.children[0].getAttribute('class')).toEqual('key');
899 expect(second.children[1].getAttribute('class')).toEqual('match');
900 expect(second.children[2].getAttribute('class')).toEqual('value');
901 expect(second.children[2].getAttribute('data-type')).toEqual('date');
902 expect(second.children[0].firstChild.data).toEqual('pubDate');
903 expect(second.children[1].firstChild.data).toEqual('eq');
904 expect(second.children[2].firstChild.data).toEqual('2014-12-05');
905 });
906
907 it('should be deserializable with nested groups', function () {
908 var docGroup = docGroupClass.create(undefined, {
Akron712733a2018-04-05 18:17:47 +0200909 "@type" : "koral:docGroup",
910 "operation" : "operation:or",
911 "operands" : [
912 {
913 "@type": 'koral:doc',
914 "key" : 'author',
915 "match": 'match:eq',
916 "value": 'Max Birkendale',
917 "type": 'type:string'
918 },
919 {
920 "@type" : "koral:docGroup",
921 "operation" : "operation:and",
922 "operands" : [
923 {
924 "@type": 'koral:doc',
925 "key": 'pubDate',
926 "match": 'match:geq',
927 "value": '2014-05-12',
928 "type": 'type:date'
929 },
930 {
931 "@type": 'koral:doc',
932 "key": 'pubDate',
933 "match": 'match:leq',
934 "value": '2014-12-05',
935 "type": 'type:date'
936 }
937 ]
938 }
939 ]
Nils Diewald7c8ced22015-04-15 19:21:00 +0000940 });
941
942 expect(docGroup.operation()).toEqual('or');
943 var e = docGroup.element();
944 expect(e.getAttribute('class')).toEqual('docGroup');
945 expect(e.getAttribute('data-operation')).toEqual('or');
946
947 expect(e.children[0].getAttribute('class')).toEqual('doc');
948 var docop = e.children[0].lastChild;
Akron0b489ad2018-02-02 16:49:32 +0100949 expect(docop.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +0000950 expect(docop.children[0].getAttribute('class')).toEqual('and');
951 expect(docop.children[1].getAttribute('class')).toEqual('or');
952 expect(docop.children[2].getAttribute('class')).toEqual('delete');
953
954 expect(e.children[1].getAttribute('class')).toEqual('docGroup');
955 expect(e.children[1].getAttribute('data-operation')).toEqual('and');
956
957 // This and-operation can be "or"ed or "delete"d
958 var secop = e.children[1].children[2];
Akron0b489ad2018-02-02 16:49:32 +0100959 expect(secop.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +0000960 expect(secop.children[0].getAttribute('class')).toEqual('or');
961 expect(secop.children[1].getAttribute('class')).toEqual('delete');
962
963 // This or-operation can be "and"ed or "delete"d
Akron0b489ad2018-02-02 16:49:32 +0100964 expect(e.children[2].getAttribute('class')).toEqual('operators button-group');
965 expect(e.lastChild.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +0000966 expect(e.lastChild.children[0].getAttribute('class')).toEqual('and');
967 expect(e.lastChild.children[1].getAttribute('class')).toEqual('delete');
968 });
969 });
970
Akronb19803c2018-08-16 16:39:42 +0200971 describe('KorAP.DocGroupRef element', function () {
972 it('should be initializable', function () {
973 var docGroupRef = docGroupRefClass.create(undefined, {
974 "@type" : "koral:docGroupRef",
975 "ref" : "@franz/myVC1"
976 });
977 expect(docGroupRef.ref()).toEqual("@franz/myVC1");
978 var dgrE = docGroupRef.element();
979
Akron3ad46942018-08-22 16:47:14 +0200980 expect(dgrE.children[0].firstChild.data).toEqual("referTo");
Akronb19803c2018-08-16 16:39:42 +0200981 expect(dgrE.children[0].tagName).toEqual("SPAN");
982 expect(dgrE.children[0].classList.contains("key")).toBeTruthy();
983 expect(dgrE.children[0].classList.contains("fixed")).toBeTruthy();
984 expect(dgrE.children[1].firstChild.data).toEqual("@franz/myVC1");
985 expect(dgrE.children[1].tagName).toEqual("SPAN");
986 expect(dgrE.children[1].classList.contains("value")).toBeTruthy();
987 expect(dgrE.children[1].getAttribute("data-type")).toEqual("string");
988 });
989
990 it('should be modifiable on reference', function () {
991 var docGroupRef = docGroupRefClass.create(undefined, {
992 "@type" : "koral:docGroupRef",
993 "ref" : "@franz/myVC1"
994 });
995 var dgrE = docGroupRef.element();
996 expect(docGroupRef.toQuery()).toEqual("referTo \"@franz/myVC1\"");
997 dgrE.children[1].click();
998
999 var input = dgrE.children[1].firstChild;
1000 expect(input.tagName).toEqual("INPUT");
1001 input.value = "Versuch";
1002
1003 var event = new KeyboardEvent("keypress", {
1004 "key" : "[Enter]",
1005 "keyCode" : 13
1006 });
1007
1008 input.dispatchEvent(event);
1009 expect(docGroupRef.toQuery()).toEqual("referTo \"Versuch\"");
1010 });
1011 });
1012
1013
Akrone4961b12017-05-10 21:04:46 +02001014 describe('KorAP.VirtualCorpus', function () {
Nils Diewald7c8ced22015-04-15 19:21:00 +00001015 var simpleGroupFactory = buildFactory(docGroupClass, {
1016 "@type" : "koral:docGroup",
1017 "operation" : "operation:and",
1018 "operands" : [
Akron712733a2018-04-05 18:17:47 +02001019 {
1020 "@type": 'koral:doc',
1021 "key" : 'author',
1022 "match": 'match:eq',
1023 "value": 'Max Birkendale',
1024 "type": 'type:string'
1025 },
1026 {
1027 "@type": 'koral:doc',
1028 "key": 'pubDate',
1029 "match": 'match:eq',
1030 "value": '2014-12-05',
1031 "type": 'type:date'
1032 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00001033 ]
1034 });
1035
1036 var nestedGroupFactory = buildFactory(vcClass, {
1037 "@type" : "koral:docGroup",
1038 "operation" : "operation:or",
1039 "operands" : [
Akron712733a2018-04-05 18:17:47 +02001040 {
1041 "@type": 'koral:doc',
1042 "key" : 'author',
1043 "match": 'match:eq',
1044 "value": 'Max Birkendale',
1045 "type": 'type:string'
1046 },
1047 {
1048 "@type" : "koral:docGroup",
1049 "operation" : "operation:and",
1050 "operands" : [
1051 {
1052 "@type": 'koral:doc',
1053 "key": 'pubDate',
1054 "match": 'match:geq',
1055 "value": '2014-05-12',
1056 "type": 'type:date'
1057 },
1058 {
1059 "@type": 'koral:doc',
1060 "key": 'pubDate',
1061 "match": 'match:leq',
1062 "value": '2014-12-05',
1063 "type": 'type:date'
1064 }
1065 ]
1066 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00001067 ]
1068 });
1069
1070 var flatGroupFactory = buildFactory(vcClass, {
1071 "@type" : "koral:docGroup",
1072 "operation" : "operation:and",
1073 "operands" : [
Akron712733a2018-04-05 18:17:47 +02001074 {
1075 "@type": 'koral:doc',
1076 "key": 'pubDate',
1077 "match": 'match:geq',
1078 "value": '2014-05-12',
1079 "type": 'type:date'
1080 },
1081 {
1082 "@type": 'koral:doc',
1083 "key": 'pubDate',
1084 "match": 'match:leq',
1085 "value": '2014-12-05',
1086 "type": 'type:date'
1087 },
1088 {
1089 "@type": 'koral:doc',
1090 "key": 'foo',
1091 "match": 'match:eq',
1092 "value": 'bar',
1093 "type": 'type:string'
1094 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00001095 ]
1096 });
1097
1098 it('should be initializable', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00001099 var vc = vcClass.create();
Nils Diewald7c8ced22015-04-15 19:21:00 +00001100 expect(vc.element().getAttribute('class')).toEqual('vc');
1101 expect(vc.root().element().getAttribute('class')).toEqual('doc unspecified');
1102
1103 // Not removable
1104 expect(vc.root().element().lastChild.children.length).toEqual(0);
1105 });
1106
1107 it('should be based on a doc', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00001108 var vc = vcClass.create().fromJson({
Akron712733a2018-04-05 18:17:47 +02001109 "@type" : "koral:doc",
1110 "key":"Titel",
1111 "value":"Baum",
1112 "match":"match:eq"
Nils Diewald7c8ced22015-04-15 19:21:00 +00001113 });
1114
1115 expect(vc.element().getAttribute('class')).toEqual('vc');
1116 expect(vc.root().element().getAttribute('class')).toEqual('doc');
1117 expect(vc.root().key()).toEqual('Titel');
1118 expect(vc.root().value()).toEqual('Baum');
1119 expect(vc.root().matchop()).toEqual('eq');
1120
1121 var docE = vc.root().element();
1122 expect(docE.children[0].firstChild.data).toEqual('Titel');
1123 expect(docE.children[1].firstChild.data).toEqual('eq');
1124 expect(docE.children[1].getAttribute('data-type')).toEqual('string');
1125 expect(docE.children[2].firstChild.data).toEqual('Baum');
1126 expect(docE.children[2].getAttribute('data-type')).toEqual('string');
1127 });
1128
1129 it('should be based on a docGroup', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00001130 var vc = vcClass.create().fromJson(simpleGroupFactory.create().toJson());
Nils Diewald7c8ced22015-04-15 19:21:00 +00001131
1132 expect(vc.element().getAttribute('class')).toEqual('vc');
1133 expect(vc.root().element().getAttribute('class')).toEqual('docGroup');
1134 expect(vc.root().operation()).toEqual('and');
1135
1136 var docGroup = vc.root();
1137
1138 var first = docGroup.getOperand(0);
1139 expect(first.key()).toEqual('author');
1140 expect(first.value()).toEqual('Max Birkendale');
1141 expect(first.matchop()).toEqual('eq');
1142
1143 var second = docGroup.getOperand(1);
1144 expect(second.key()).toEqual('pubDate');
1145 expect(second.value()).toEqual('2014-12-05');
1146 expect(second.matchop()).toEqual('eq');
1147 });
1148
Akronb19803c2018-08-16 16:39:42 +02001149 it('should be based on a docGroupRef', function () {
1150 var vc = vcClass.create().fromJson({
1151 "@type" : "koral:docGroupRef",
1152 "ref":"myCorpus"
1153 });
1154
Akronadab5e52018-08-20 13:50:53 +02001155 // iv class="doc groupref"><span class="key fixed">@referTo</span><span data-type="string" class="value">myCorpus</span>
1156 var vcE = vc.builder();
1157 expect(vcE.getAttribute('class')).toEqual('builder');
Akronb19803c2018-08-16 16:39:42 +02001158 expect(vcE.firstChild.tagName).toEqual('DIV');
1159 expect(vcE.firstChild.classList.contains('groupref')).toBeTruthy();
1160
1161 expect(vcE.firstChild.firstChild.tagName).toEqual('SPAN');
1162 expect(vcE.firstChild.firstChild.classList.contains('key')).toBeTruthy();
1163 expect(vcE.firstChild.firstChild.classList.contains('fixed')).toBeTruthy();
1164
Akron3ad46942018-08-22 16:47:14 +02001165 expect(vcE.firstChild.firstChild.textContent).toEqual("referTo");
Akronb19803c2018-08-16 16:39:42 +02001166
1167 expect(vcE.firstChild.children[1].tagName).toEqual('SPAN');
1168 expect(vcE.firstChild.children[1].classList.contains('value')).toBeTruthy();
1169 expect(vcE.firstChild.children[1].getAttribute('data-type')).toEqual('string');
1170 expect(vcE.firstChild.children[1].textContent).toEqual("myCorpus");
1171 });
Nils Diewald7c8ced22015-04-15 19:21:00 +00001172
1173 it('should be based on a nested docGroup', function () {
1174 var vc = nestedGroupFactory.create();
1175
Akronadab5e52018-08-20 13:50:53 +02001176 expect(vc.builder().getAttribute('class')).toEqual('builder');
1177 expect(vc.builder().firstChild.getAttribute('class')).toEqual('docGroup');
1178 expect(vc.builder().firstChild.children[0].getAttribute('class')).toEqual('doc');
1179 var dg = vc.builder().firstChild.children[1];
Nils Diewald7c8ced22015-04-15 19:21:00 +00001180 expect(dg.getAttribute('class')).toEqual('docGroup');
1181 expect(dg.children[0].getAttribute('class')).toEqual('doc');
1182 expect(dg.children[1].getAttribute('class')).toEqual('doc');
Akron0b489ad2018-02-02 16:49:32 +01001183 expect(dg.children[2].getAttribute('class')).toEqual('operators button-group');
Akronadab5e52018-08-20 13:50:53 +02001184 expect(vc.builder().firstChild.children[2].getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001185 });
1186
Akronb19803c2018-08-16 16:39:42 +02001187 it('should be based on a nested docGroupRef', function () {
1188 var vc = vcClass.create().fromJson({
1189 "@type" : "koral:docGroup",
1190 "operation" : "operation:and",
1191 "operands" : [{
1192 "@type" : "koral:docGroupRef",
1193 "ref":"myCorpus"
1194 },{
1195 "@type" : "koral:doc",
1196 "key":"Titel",
1197 "value":"Baum",
1198 "match":"match:eq"
1199 }]
1200 });
1201
1202 expect(vc._root.ldType()).toEqual("docGroup");
1203
1204 expect(vc.toQuery()).toEqual('referTo "myCorpus" & Titel = "Baum"');
1205 });
1206
1207
Nils Diewald7c8ced22015-04-15 19:21:00 +00001208 it('should be modifiable by deletion in flat docGroups', function () {
1209 var vc = flatGroupFactory.create();
1210 var docGroup = vc.root();
1211
1212 expect(docGroup.element().getAttribute('class')).toEqual('docGroup');
1213
1214 var doc = docGroup.getOperand(1);
1215 expect(doc.key()).toEqual("pubDate");
1216 expect(doc.value()).toEqual("2014-12-05");
1217
1218 // Remove operand 1
1219 expect(docGroup.delOperand(doc).update()).not.toBeUndefined();
1220 expect(doc._element).toEqual(undefined);
1221
1222 doc = docGroup.getOperand(1);
1223 expect(doc.key()).toEqual("foo");
1224
1225 // Remove operand 1
1226 expect(docGroup.delOperand(doc).update()).not.toBeUndefined();
1227 expect(doc._element).toEqual(undefined);
1228
1229 // Only one operand left ...
1230 expect(docGroup.getOperand(1)).toBeUndefined();
1231 // ... but there shouldn't be a group anymore at all!
1232 expect(docGroup.getOperand(0)).toBeUndefined();
1233
1234 var obj = vc.root();
1235 expect(obj.ldType()).toEqual("doc");
1236 expect(obj.key()).toEqual("pubDate");
1237 expect(obj.value()).toEqual("2014-05-12");
1238
1239 expect(obj.element().getAttribute('class')).toEqual('doc');
1240 });
1241
1242
1243 it('should be modifiable by deletion in nested docGroups (root case)', function () {
1244 var vc = nestedGroupFactory.create();
1245
1246 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001247 'author = "Max Birkendale" | (pubDate since 2014-05-12 & pubDate until 2014-12-05)'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001248 );
1249
1250 var docGroup = vc.root();
1251 expect(docGroup.ldType()).toEqual("docGroup");
1252 expect(docGroup.operation()).toEqual("or");
1253
1254 var doc = docGroup.getOperand(0);
1255 expect(doc.key()).toEqual("author");
1256 expect(doc.value()).toEqual("Max Birkendale");
1257
1258 docGroup = docGroup.getOperand(1);
1259 expect(docGroup.operation()).toEqual("and");
1260
1261 doc = docGroup.getOperand(0);
1262 expect(doc.key()).toEqual("pubDate");
1263 expect(doc.matchop()).toEqual("geq");
1264 expect(doc.value()).toEqual("2014-05-12");
1265 expect(doc.type()).toEqual("date");
1266
1267 doc = docGroup.getOperand(1);
1268 expect(doc.key()).toEqual("pubDate");
1269 expect(doc.matchop()).toEqual("leq");
1270 expect(doc.value()).toEqual("2014-12-05");
1271 expect(doc.type()).toEqual("date");
1272
1273 // Remove first operand so everything becomes root
1274 expect(
Akron712733a2018-04-05 18:17:47 +02001275 vc.root().delOperand(
1276 vc.root().getOperand(0)
1277 ).update().ldType()
Nils Diewald7c8ced22015-04-15 19:21:00 +00001278 ).toEqual("docGroup");
1279
1280 expect(vc.root().ldType()).toEqual("docGroup");
1281 expect(vc.root().operation()).toEqual("and");
1282 expect(vc.root().getOperand(0).ldType()).toEqual("doc");
1283
1284 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001285 'pubDate since 2014-05-12 & pubDate until 2014-12-05'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001286 );
1287 });
1288
1289 it('should be modifiable by deletion in nested docGroups (resolve group case)', function () {
1290 var vc = nestedGroupFactory.create();
1291
1292 // Get nested group
1293 var firstGroup = vc.root().getOperand(1);
1294 firstGroup.append(simpleGroupFactory.create({ "operation" : "operation:or" }));
1295
1296 // Structur is now:
1297 // or(doc, and(doc, doc, or(doc, doc)))
1298
1299 // Get nested or in and
1300 var orGroup = vc.root().getOperand(1).getOperand(2);
1301 expect(orGroup.ldType()).toEqual("docGroup");
1302 expect(orGroup.operation()).toEqual("or");
1303
1304 // Remove
1305 // Structur is now:
1306 // or(doc, and(doc, doc, doc)))
1307 expect(orGroup.delOperand(orGroup.getOperand(0)).update().operation()).toEqual("and");
1308 expect(vc.root().getOperand(1).operands().length).toEqual(3);
1309 });
1310
1311 it('should be modifiable by deletion in nested docGroups (identical group case)', function () {
1312 var vc = nestedGroupFactory.create();
1313
1314 // Get nested group
1315 var firstGroup = vc.root().getOperand(1);
1316 firstGroup.append(simpleGroupFactory.create({
Akron712733a2018-04-05 18:17:47 +02001317 "operation" : "operation:or"
Nils Diewald7c8ced22015-04-15 19:21:00 +00001318 }));
1319 var oldAuthor = firstGroup.getOperand(2).getOperand(0);
1320 oldAuthor.key("title");
1321 oldAuthor.value("Der Birnbaum");
1322
1323 // Structur is now:
1324 // or(doc, and(doc, doc, or(doc, doc)))
1325 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001326 'author = "Max Birkendale" | ' +
1327 '(pubDate since 2014-05-12 & ' +
1328 'pubDate until 2014-12-05 & ' +
1329 '(title = "Der Birnbaum" | ' +
1330 'pubDate in 2014-12-05))'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001331 );
1332
1333 var andGroup = vc.root().getOperand(1);
1334
1335 // Get leading docs in and
1336 var doc1 = andGroup.getOperand(0);
1337 expect(doc1.ldType()).toEqual("doc");
1338 expect(doc1.value()).toEqual("2014-05-12");
1339 var doc2 = andGroup.getOperand(1);
1340 expect(doc2.ldType()).toEqual("doc");
1341 expect(doc2.value()).toEqual("2014-12-05");
1342
1343 // Remove 2
1344 expect(
Akron712733a2018-04-05 18:17:47 +02001345 andGroup.delOperand(doc2).update().operation()
Nils Diewald7c8ced22015-04-15 19:21:00 +00001346 ).toEqual("and");
1347 // Structur is now:
1348 // or(doc, and(doc, or(doc, doc)))
1349
1350 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001351 'author = "Max Birkendale"' +
1352 ' | (pubDate since 2014-05-12 & ' +
1353 '(title = "Der Birnbaum" | pubDate in 2014-12-05))'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001354 );
1355
1356
1357 // Remove 1
1358 expect(andGroup.delOperand(doc1).update().operation()).toEqual("or");
1359 // Structur is now:
1360 // or(doc, doc, doc)
1361
1362 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001363 'author = "Max Birkendale" | title = "Der Birnbaum" | pubDate in 2014-12-05'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001364 );
1365 });
1366
1367 it('should be reducible to unspecification', function () {
1368 var vc = demoFactory.create();
1369
1370 expect(vc.toQuery()).toEqual(vc.root().toQuery());
1371 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001372 '(Titel = "Baum" & Veröffentlichungsort = "hihi" & ' +
1373 '(Titel = "Baum" | Veröffentlichungsort = "hihi")) ' +
1374 '| Untertitel ~ "huhu"');
Akrond141a362018-07-10 18:12:13 +02001375 expect(vc.root().element().lastChild.children[0].innerText).toEqual('and');
1376 expect(vc.root().element().lastChild.children[1].innerText).toEqual('×');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001377 expect(vc.root().delOperand(vc.root().getOperand(0)).update()).not.toBeUndefined();
Akron712733a2018-04-05 18:17:47 +02001378 expect(vc.toQuery()).toEqual('Untertitel ~ "huhu"');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001379
1380 var lc = vc.root().element().lastChild;
Akrond141a362018-07-10 18:12:13 +02001381 expect(lc.children[0].innerText).toEqual('and');
1382 expect(lc.children[1].innerText).toEqual('or');
1383 expect(lc.children[2].innerText).toEqual('×');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001384
1385 // Clean everything
1386 vc.clean();
1387 expect(vc.toQuery()).toEqual('');
1388 });
1389
1390 it('should flatten on import', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00001391 var vc = vcClass.create().fromJson({
Akron712733a2018-04-05 18:17:47 +02001392 "@type":"koral:docGroup",
1393 "operation":"operation:or",
1394 "operands":[
1395 {
1396 "@type":"koral:docGroup",
1397 "operation":"operation:or",
1398 "operands":[
Nils Diewald7c8ced22015-04-15 19:21:00 +00001399 {
Akron712733a2018-04-05 18:17:47 +02001400 "@type":"koral:doc",
1401 "key":"Titel",
1402 "value":"Baum",
1403 "match":"match:eq"
Nils Diewald7c8ced22015-04-15 19:21:00 +00001404 },
1405 {
Akron712733a2018-04-05 18:17:47 +02001406 "@type":"koral:doc",
1407 "key":"Veröffentlichungsort",
1408 "value":"hihi",
1409 "match":"match:eq"
Nils Diewald7c8ced22015-04-15 19:21:00 +00001410 },
1411 {
Akron712733a2018-04-05 18:17:47 +02001412 "@type":"koral:docGroup",
1413 "operation":"operation:or",
1414 "operands":[
1415 {
1416 "@type":"koral:doc",
1417 "key":"Titel",
1418 "value":"Baum",
1419 "match":"match:eq"
1420 },
1421 {
1422 "@type":"koral:doc",
1423 "key":"Veröffentlichungsort",
1424 "value":"hihi",
1425 "match":"match:eq"
1426 }
1427 ]
Nils Diewald7c8ced22015-04-15 19:21:00 +00001428 }
Akron712733a2018-04-05 18:17:47 +02001429 ]
1430 },
1431 {
1432 "@type":"koral:doc",
1433 "key":"Untertitel",
1434 "value":"huhu",
1435 "match":"match:contains"
1436 }
1437 ]
Nils Diewald7c8ced22015-04-15 19:21:00 +00001438 });
Nils Diewaldfda29d92015-01-22 17:28:01 +00001439
Nils Diewald7c8ced22015-04-15 19:21:00 +00001440 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001441 'Titel = "Baum" | Veröffentlichungsort = "hihi" | Untertitel ~ "huhu"'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001442 );
Nils Diewald86dad5b2015-01-28 15:09:07 +00001443 });
Akron1bdf5272018-07-24 18:51:30 +02001444
1445 it('should be deserializable from collection 1', function () {
1446 var kq = {
1447 "matches":["..."],
1448 "collection":{
1449 "@type": "koral:docGroup",
1450 "operation": "operation:or",
1451 "operands": [{
1452 "@type": "koral:docGroup",
1453 "operation": "operation:and",
1454 "operands": [
1455 {
1456 "@type": "koral:doc",
1457 "key": "title",
1458 "match": "match:eq",
1459 "value": "Der Birnbaum",
1460 "type": "type:string"
1461 },
1462 {
1463 "@type": "koral:doc",
1464 "key": "pubPlace",
1465 "match": "match:eq",
1466 "value": "Mannheim",
1467 "type": "type:string"
1468 },
1469 {
1470 "@type": "koral:docGroup",
1471 "operation": "operation:or",
1472 "operands": [
1473 {
1474 "@type": "koral:doc",
1475 "key": "subTitle",
1476 "match": "match:eq",
1477 "value": "Aufzucht und Pflege",
1478 "type": "type:string"
1479 },
1480 {
1481 "@type": "koral:doc",
1482 "key": "subTitle",
1483 "match": "match:eq",
1484 "value": "Gedichte",
1485 "type": "type:string"
1486 }
1487 ]
1488 }
1489 ]
1490 },{
1491 "@type": "koral:doc",
1492 "key": "pubDate",
1493 "match": "match:geq",
1494 "value": "2015-03-05",
1495 "type": "type:date",
1496 "rewrites" : [{
1497 "@type" : "koral:rewrite",
1498 "operation" : "operation:modification",
1499 "src" : "querySerializer",
1500 "scope" : "tree"
1501 }]
1502 }]
1503 }
1504 };
1505
1506 var vc = vcClass.create().fromJson(kq["collection"]);
1507 expect(vc.toQuery()).toEqual('(title = "Der Birnbaum" & pubPlace = "Mannheim" & (subTitle = "Aufzucht und Pflege" | subTitle = "Gedichte")) | pubDate since 2015-03-05');
1508 });
1509
1510 it('should be deserializable from collection 2', function () {
1511 var kq = {
1512 "@context": "http://korap.ids-mannheim.de/ns/KoralQuery/v0.3/context.jsonld",
1513 "meta": {},
1514 "query": {
1515 "@type": "koral:token",
1516 "wrap": {
1517 "@type": "koral:term",
1518 "match": "match:eq",
1519 "layer": "orth",
1520 "key": "Baum",
1521 "foundry": "opennlp",
1522 "rewrites": [
1523 {
1524 "@type": "koral:rewrite",
1525 "src": "Kustvakt",
1526 "operation": "operation:injection",
1527 "scope": "foundry"
1528 }
1529 ]
1530 },
1531 "idn": "Baum_2227",
1532 "rewrites": [
1533 {
1534 "@type": "koral:rewrite",
1535 "src": "Kustvakt",
1536 "operation": "operation:injection",
1537 "scope": "idn"
1538 }
1539 ]
1540 },
1541 "collection": {
1542 "@type": "koral:docGroup",
1543 "operation": "operation:and",
1544 "operands": [
1545 {
1546 "@type": "koral:doc",
1547 "match": "match:eq",
1548 "type": "type:regex",
1549 "value": "CC-BY.*",
1550 "key": "availability"
1551 },
1552 {
1553 "@type": "koral:doc",
1554 "match": "match:eq",
1555 "type":"type:text",
1556 "value": "Goethe",
1557 "key": "author"
1558 }
1559 ],
1560 "rewrites": [
1561 {
1562 "@type": "koral:rewrite",
1563 "src": "Kustvakt",
1564 "operation": "operation:insertion",
1565 "scope": "availability(FREE)"
1566 }
1567 ]
1568 },
1569 "matches": []
1570 };
1571
1572 var vc = vcClass.create().fromJson(kq["collection"]);
1573 expect(vc.toQuery()).toEqual('availability = /CC-BY.*/ & author = "Goethe"');
1574 });
Nils Diewald86dad5b2015-01-28 15:09:07 +00001575
Akron8a670162018-08-28 10:09:13 +02001576 it('shouldn\'t be deserializable from collection with unknown type', function () {
1577 var kq = {
1578 "@type" : "koral:doc",
1579 "match": "match:eq",
1580 "type":"type:failure",
1581 "value": "Goethe",
1582 "key": "author"
1583 };
Akron1bdf5272018-07-24 18:51:30 +02001584
Akron8a670162018-08-28 10:09:13 +02001585 expect(function () {
1586 vcClass.create().fromJson(kq)
1587 }).toThrow(new Error("Unknown value type: string"));
1588 });
1589
1590 it('should return a name', function () {
1591 var vc = vcClass.create();
1592 expect(vc.getName()).toEqual(KorAP.Locale.VC_allCorpora);
1593
1594 vc = vcClass.create().fromJson({"@type" : "koral:docGroupRef", "ref" : "DeReKo"});
1595 expect(vc.getName()).toEqual("DeReKo");
1596
1597 vc = vcClass.create().fromJson({"@type" : "koral:doc", "key" : "author", "value" : "Peter"});
1598 expect(vc.getName()).toEqual(KorAP.Locale.VC_oneCollection);
1599 });
Akrond2474aa2018-08-28 12:06:27 +02001600
1601 it('should check for rewrites', function () {
1602
1603 var vc = vcClass.create().fromJson({
1604 "@type" : "koral:doc",
1605 "key" : "author",
1606 "value" : "Goethe",
1607 "rewrites" : [{
1608 "@type" : "koral:rewrite",
1609 "operation" : "operation:modification",
1610 "src" : "querySerializer",
1611 "scope" : "value"
1612 }]
1613 });
1614 expect(vc.wasRewritten()).toBeTruthy();
1615
1616 var nested = {
1617 "@type" : "koral:docGroup",
1618 "operation" : "operation:or",
1619 "operands" : [
1620 {
1621 "@type" : "koral:doc",
1622 "key" : "author",
1623 "value" : "Goethe"
1624 },
1625 {
1626 "@type" : "koral:docGroup",
1627 "operation" : "operation:and",
1628 "operands" : [
1629 {
1630 "@type": "koral:doc",
1631 "key" : "author",
1632 "value" : "Schiller"
1633 },
1634 {
1635 "@type": "koral:doc",
1636 "key" : "author",
1637 "value" : "Fontane"
1638 }
1639 ]
1640 }
1641 ]
1642 };
1643 vc = vcClass.create().fromJson(nested);
1644 expect(vc.wasRewritten()).toBe(false);
1645
1646 nested["operands"][1]["operands"][1]["rewrites"] = [{
1647 "@type" : "koral:rewrite",
1648 "operation" : "operation:modification",
1649 "src" : "querySerializer",
1650 "scope" : "tree"
1651 }];
1652 vc = vcClass.create().fromJson(nested);
1653 expect(vc.wasRewritten()).toBeTruthy();
1654 });
Akron1bdf5272018-07-24 18:51:30 +02001655 });
1656
1657
Nils Diewald7c8ced22015-04-15 19:21:00 +00001658 describe('KorAP.Operators', function () {
1659 it('should be initializable', function () {
1660 var op = operatorsClass.create(true, false, false);
1661 expect(op.and()).toBeTruthy();
1662 expect(op.or()).not.toBeTruthy();
1663 expect(op.del()).not.toBeTruthy();
1664
1665 op.and(false);
1666 expect(op.and()).not.toBeTruthy();
1667 expect(op.or()).not.toBeTruthy();
1668 expect(op.del()).not.toBeTruthy();
1669
1670 op.or(true);
1671 op.del(true);
1672 expect(op.and()).not.toBeTruthy();
1673 expect(op.or()).toBeTruthy();
1674 expect(op.del()).toBeTruthy();
1675
Akrond141a362018-07-10 18:12:13 +02001676 var e = op.update();
Akron0b489ad2018-02-02 16:49:32 +01001677 expect(e.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001678 expect(e.children[0].getAttribute('class')).toEqual('or');
Akrond141a362018-07-10 18:12:13 +02001679 expect(e.children[0].innerText).toEqual('or');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001680 expect(e.children[1].getAttribute('class')).toEqual('delete');
Akrond141a362018-07-10 18:12:13 +02001681 expect(e.children[1].innerText).toEqual('×');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001682
1683 op.and(true);
1684 op.del(false);
Akrond141a362018-07-10 18:12:13 +02001685 e = op.update();
Nils Diewald7c8ced22015-04-15 19:21:00 +00001686
Akron0b489ad2018-02-02 16:49:32 +01001687 expect(e.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001688 expect(e.children[0].getAttribute('class')).toEqual('and');
Akrond141a362018-07-10 18:12:13 +02001689 expect(e.children[0].innerText).toEqual('and');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001690 expect(e.children[1].getAttribute('class')).toEqual('or');
Akrond141a362018-07-10 18:12:13 +02001691 expect(e.children[1].innerText).toEqual('or');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001692 });
1693 });
1694
1695 describe('KorAP._delete (event)', function () {
1696 var complexVCFactory = buildFactory(vcClass,{
1697 "@type": 'koral:docGroup',
1698 'operation' : 'operation:and',
1699 'operands' : [
Akron712733a2018-04-05 18:17:47 +02001700 {
1701 "@type": 'koral:doc',
1702 "key": 'pubDate',
1703 "match": 'match:eq',
1704 "value": '2014-12-05',
1705 "type": 'type:date'
1706 },
1707 {
1708 "@type" : 'koral:docGroup',
1709 'operation' : 'operation:or',
1710 'operands' : [
1711 {
1712 '@type' : 'koral:doc',
1713 'key' : 'title',
1714 'value' : 'Hello World!'
1715 },
1716 {
1717 '@type' : 'koral:doc',
1718 'key' : 'foo',
1719 'value' : 'bar'
1720 }
1721 ]
1722 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00001723 ]
1724 });
1725
1726 it('should clean on root docs', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00001727 var vc = vcClass.create().fromJson({
Akron712733a2018-04-05 18:17:47 +02001728 "@type": 'koral:doc',
1729 "key": 'pubDate',
1730 "match": 'match:eq',
1731 "value": '2014-12-05',
1732 "type": 'type:date'
Nils Diewald86dad5b2015-01-28 15:09:07 +00001733 });
Nils Diewald7c8ced22015-04-15 19:21:00 +00001734 expect(vc.root().toQuery()).toEqual('pubDate in 2014-12-05');
Akron0b489ad2018-02-02 16:49:32 +01001735 expect(vc.root().element().lastChild.getAttribute('class')).toEqual('operators button-group');
Nils Diewald86dad5b2015-01-28 15:09:07 +00001736
Nils Diewald7c8ced22015-04-15 19:21:00 +00001737 // Clean with delete from root
1738 expect(vc.root().element().lastChild.lastChild.getAttribute('class')).toEqual('delete');
1739 _delOn(vc.root());
1740 expect(vc.root().toQuery()).toEqual('');
1741 expect(vc.root().element().lastChild.lastChild.data).toEqual('⋯');
1742 });
Nils Diewald86dad5b2015-01-28 15:09:07 +00001743
Nils Diewald7c8ced22015-04-15 19:21:00 +00001744 it('should remove on nested docs', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00001745 var vc = vcClass.create().fromJson(
Akron712733a2018-04-05 18:17:47 +02001746 {
1747 "@type": 'koral:docGroup',
1748 'operation' : 'operation:and',
1749 'operands' : [
1750 {
1751 "@type": 'koral:doc',
1752 "key": 'pubDate',
1753 "match": 'match:eq',
1754 "value": '2014-12-05',
1755 "type": 'type:date'
1756 },
1757 {
1758 "@type" : 'koral:doc',
1759 'key' : 'foo',
1760 'value' : 'bar'
1761 }
1762 ]
1763 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00001764 );
1765
1766 // Delete with direct element access
1767 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar"');
1768 _delOn(vc.root().getOperand(0));
1769
1770 expect(vc.toQuery()).toEqual('foo = "bar"');
1771 expect(vc.root().ldType()).toEqual('doc');
1772 });
1773
1774 it('should clean on doc groups', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00001775 var vc = vcClass.create().fromJson(
Akron712733a2018-04-05 18:17:47 +02001776 {
1777 "@type": 'koral:docGroup',
1778 'operation' : 'operation:and',
1779 'operands' : [
1780 {
1781 "@type": 'koral:doc',
1782 "key": 'pubDate',
1783 "match": 'match:eq',
1784 "value": '2014-12-05',
1785 "type": 'type:date'
1786 },
1787 {
1788 "@type" : 'koral:doc',
1789 'key' : 'foo',
1790 'value' : 'bar'
1791 }
1792 ]
1793 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00001794 );
1795
1796 // Cleanwith direct element access
1797 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar"');
1798 _delOn(vc.root());
1799 expect(vc.toQuery()).toEqual('');
1800 expect(vc.root().ldType()).toEqual('non');
1801 });
1802
1803 it('should remove on nested doc groups (case of ungrouping 1)', function () {
1804 var vc = complexVCFactory.create();
1805
1806 // Delete with direct element access
1807 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001808 'pubDate in 2014-12-05 & (title = "Hello World!" | foo = "bar")'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001809 );
1810
1811 // Remove hello world:
1812 _delOn(vc.root().getOperand(1).getOperand(0));
1813 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar"');
1814 expect(vc.root().ldType()).toEqual('docGroup');
1815 });
1816
1817 it('should remove on nested doc groups (case of ungrouping 2)', function () {
1818 var vc = complexVCFactory.create();
1819
1820 // Delete with direct element access
1821 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001822 'pubDate in 2014-12-05 & (title = "Hello World!" | foo = "bar")'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001823 );
1824
1825 // Remove bar
1826 _delOn(vc.root().getOperand(1).getOperand(1));
1827 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & title = "Hello World!"');
1828 expect(vc.root().ldType()).toEqual('docGroup');
1829 expect(vc.root().operation()).toEqual('and');
1830 });
1831
1832 it('should remove on nested doc groups (case of root changing)', function () {
1833 var vc = complexVCFactory.create();
1834
1835 // Delete with direct element access
1836 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001837 'pubDate in 2014-12-05 & ' +
1838 '(title = "Hello World!" | foo = "bar")'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001839 );
1840
1841 // Remove bar
1842 _delOn(vc.root().getOperand(0));
1843 expect(vc.toQuery()).toEqual('title = "Hello World!" | foo = "bar"');
1844 expect(vc.root().ldType()).toEqual('docGroup');
1845 expect(vc.root().operation()).toEqual('or');
1846 });
1847
1848 it('should remove on nested doc groups (list flattening)', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00001849 var vc = vcClass.create().fromJson(
Akron712733a2018-04-05 18:17:47 +02001850 {
1851 "@type": 'koral:docGroup',
1852 'operation' : 'operation:or',
1853 'operands' : [
1854 {
1855 "@type": 'koral:doc',
1856 "key": 'pubDate',
1857 "match": 'match:eq',
1858 "value": '2014-12-05',
1859 "type": 'type:date'
1860 },
1861 {
1862 "@type" : 'koral:doc',
1863 'key' : 'foo',
1864 'value' : 'bar'
1865 },
1866 {
1867 "@type": 'koral:docGroup',
1868 'operation' : 'operation:and',
1869 'operands' : [
1870 {
1871 "@type": 'koral:doc',
1872 "key": 'pubDate',
1873 "match": 'match:eq',
1874 "value": '2014-12-05',
1875 "type": 'type:date'
1876 },
1877 {
1878 "@type" : 'koral:docGroup',
1879 'operation' : 'operation:or',
1880 'operands' : [
1881 {
1882 '@type' : 'koral:doc',
1883 'key' : 'title',
1884 'value' : 'Hello World!'
1885 },
1886 {
1887 '@type' : 'koral:doc',
1888 'key' : 'yeah',
1889 'value' : 'juhu'
1890 }
1891 ]
1892 }
1893 ]
1894 }
1895 ]
1896 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00001897 );
1898
1899 // Delete with direct element access
1900 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001901 'pubDate in 2014-12-05 | foo = "bar" | ' +
1902 '(pubDate in 2014-12-05 & ' +
1903 '(title = "Hello World!" | yeah = "juhu"))'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001904 );
1905
1906 expect(vc.root().ldType()).toEqual('docGroup');
1907 expect(vc.root().operation()).toEqual('or');
1908
1909 // Operands and operators
Akronadab5e52018-08-20 13:50:53 +02001910 expect(vc.builder().firstChild.children.length).toEqual(4);
1911 expect(vc.builder().firstChild.lastChild.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001912
1913 // Remove inner group and flatten
1914 _delOn(vc.root().getOperand(2).getOperand(0));
1915
1916 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001917 'pubDate in 2014-12-05 | foo = "bar" | title = "Hello World!" | yeah = "juhu"'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001918 );
1919 expect(vc.root().ldType()).toEqual('docGroup');
1920 expect(vc.root().operation()).toEqual('or');
1921
1922 // Operands and operators
Akronadab5e52018-08-20 13:50:53 +02001923 expect(vc.builder().firstChild.children.length).toEqual(5);
1924 expect(vc.builder().firstChild.lastChild.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001925 });
1926 });
1927
1928 describe('KorAP._add (event)', function () {
1929 var complexVCFactory = buildFactory(vcClass,{
1930 "@type": 'koral:docGroup',
1931 'operation' : 'operation:and',
1932 'operands' : [
Akron712733a2018-04-05 18:17:47 +02001933 {
1934 "@type": 'koral:doc',
1935 "key": 'pubDate',
1936 "match": 'match:eq',
1937 "value": '2014-12-05',
1938 "type": 'type:date'
1939 },
1940 {
1941 "@type" : 'koral:docGroup',
1942 'operation' : 'operation:or',
1943 'operands' : [
1944 {
1945 '@type' : 'koral:doc',
1946 'key' : 'title',
1947 'value' : 'Hello World!'
1948 },
1949 {
1950 '@type' : 'koral:doc',
1951 'key' : 'foo',
1952 'value' : 'bar'
1953 }
1954 ]
1955 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00001956 ]
1957 });
1958
1959 it('should add new unspecified doc with "and"', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00001960 var vc = vcClass.create().fromJson(
Akron712733a2018-04-05 18:17:47 +02001961 {
1962 "@type": 'koral:docGroup',
1963 'operation' : 'operation:and',
1964 'operands' : [
1965 {
1966 "@type": 'koral:doc',
1967 "key": 'pubDate',
1968 "match": 'match:eq',
1969 "value": '2014-12-05',
1970 "type": 'type:date'
1971 },
1972 {
1973 "@type" : 'koral:doc',
1974 'key' : 'foo',
1975 'value' : 'bar'
Akronb19803c2018-08-16 16:39:42 +02001976 },
1977 {
1978 "@type" : "koral:docGroupRef",
1979 "ref" : "myCorpus"
Akron712733a2018-04-05 18:17:47 +02001980 }
1981 ]
1982 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00001983 );
1984
Akronb19803c2018-08-16 16:39:42 +02001985 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar" & referTo "myCorpus"');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001986
Akronadab5e52018-08-20 13:50:53 +02001987 var fc = vc.builder().firstChild;
Nils Diewald7c8ced22015-04-15 19:21:00 +00001988 expect(fc.getAttribute('data-operation')).toEqual('and');
Akronb19803c2018-08-16 16:39:42 +02001989 expect(fc.children.length).toEqual(4);
Akron0b489ad2018-02-02 16:49:32 +01001990 expect(fc.lastChild.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001991 expect(fc.children[0].getAttribute('class')).toEqual('doc');
1992 expect(fc.children[1].getAttribute('class')).toEqual('doc');
Akronb19803c2018-08-16 16:39:42 +02001993 expect(fc.children[2].getAttribute('class')).toEqual('doc groupref');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001994
1995 // add with 'and' in the middle
1996 _andOn(vc.root().getOperand(0));
Akronb19803c2018-08-16 16:39:42 +02001997 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar" & referTo "myCorpus"');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001998
Akronadab5e52018-08-20 13:50:53 +02001999 fc = vc.builder().firstChild;
Nils Diewald7c8ced22015-04-15 19:21:00 +00002000 expect(fc.getAttribute('data-operation')).toEqual('and');
Akronb19803c2018-08-16 16:39:42 +02002001 expect(fc.children.length).toEqual(5);
Akron0b489ad2018-02-02 16:49:32 +01002002 expect(fc.lastChild.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +00002003
2004 expect(fc.children[0].getAttribute('class')).toEqual('doc');
2005 expect(fc.children[1].getAttribute('class')).toEqual('doc unspecified');
2006 expect(fc.children[2].getAttribute('class')).toEqual('doc');
Akronb19803c2018-08-16 16:39:42 +02002007 expect(fc.children[3].getAttribute('class')).toEqual('doc groupref');
2008 expect(fc.children[4].classList.contains('button-group')).toBeTruthy();
2009 expect(fc.children.length).toEqual(5);
2010
2011 _andOn(vc.root().getOperand(3));
2012 expect(fc.children[0].getAttribute('class')).toEqual('doc');
2013 expect(fc.children[1].getAttribute('class')).toEqual('doc unspecified');
2014 expect(fc.children[2].getAttribute('class')).toEqual('doc');
2015 expect(fc.children[3].getAttribute('class')).toEqual('doc groupref');
2016 expect(fc.children[4].getAttribute('class')).toEqual('doc unspecified');
2017 expect(fc.children[5].classList.contains('button-group')).toBeTruthy();
2018 expect(fc.children.length).toEqual(6);
2019
Nils Diewald7c8ced22015-04-15 19:21:00 +00002020 });
2021
Akronb19803c2018-08-16 16:39:42 +02002022
Nils Diewald7c8ced22015-04-15 19:21:00 +00002023 it('should add new unspecified doc with "or"', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00002024 var vc = vcClass.create().fromJson(
Akron712733a2018-04-05 18:17:47 +02002025 {
2026 "@type": 'koral:docGroup',
2027 'operation' : 'operation:and',
2028 'operands' : [
2029 {
2030 "@type": 'koral:doc',
2031 "key": 'pubDate',
2032 "match": 'match:eq',
2033 "value": '2014-12-05',
2034 "type": 'type:date'
2035 },
2036 {
2037 "@type" : 'koral:doc',
2038 'key' : 'foo',
2039 'value' : 'bar'
Akronb19803c2018-08-16 16:39:42 +02002040 },
2041 {
2042 "@type" : "koral:docGroupRef",
2043 "ref" : "myCorpus"
Akron712733a2018-04-05 18:17:47 +02002044 }
2045 ]
2046 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00002047 );
2048
Akronb19803c2018-08-16 16:39:42 +02002049 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar" & referTo "myCorpus"');
Nils Diewald7c8ced22015-04-15 19:21:00 +00002050
Akronadab5e52018-08-20 13:50:53 +02002051 var fc = vc.builder().firstChild;
Akronb19803c2018-08-16 16:39:42 +02002052 expect(fc.children.length).toEqual(4);
Akron0b489ad2018-02-02 16:49:32 +01002053 expect(fc.lastChild.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +00002054 expect(fc.children[0].getAttribute('class')).toEqual('doc');
2055 expect(fc.children[1].getAttribute('class')).toEqual('doc');
Akronb19803c2018-08-16 16:39:42 +02002056 expect(fc.children[2].getAttribute('class')).toEqual('doc groupref');
Nils Diewald7c8ced22015-04-15 19:21:00 +00002057
2058 // add with 'or' in the middle
2059 _orOn(vc.root().getOperand(0));
Akronb19803c2018-08-16 16:39:42 +02002060 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar" & referTo "myCorpus"');
Akronadab5e52018-08-20 13:50:53 +02002061 fc = vc.builder().firstChild;
Nils Diewald7c8ced22015-04-15 19:21:00 +00002062
2063 expect(fc.getAttribute('data-operation')).toEqual('and');
Akronb19803c2018-08-16 16:39:42 +02002064 expect(fc.children.length).toEqual(4);
Nils Diewald7c8ced22015-04-15 19:21:00 +00002065 expect(fc.children[0].getAttribute('class')).toEqual('docGroup');
2066 expect(fc.children[0].getAttribute('data-operation')).toEqual('or');
2067 expect(fc.children[1].getAttribute('class')).toEqual('doc');
Akronb19803c2018-08-16 16:39:42 +02002068 expect(fc.children[2].getAttribute('class')).toEqual('doc groupref');
2069 expect(fc.children[3].getAttribute('class')).toEqual('operators button-group');
Akron0b489ad2018-02-02 16:49:32 +01002070 expect(fc.lastChild.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +00002071
Akronadab5e52018-08-20 13:50:53 +02002072 fc = vc.builder().firstChild.firstChild;
Nils Diewald7c8ced22015-04-15 19:21:00 +00002073 expect(fc.children.length).toEqual(3);
2074 expect(fc.children[0].getAttribute('class')).toEqual('doc');
2075 expect(fc.children[1].getAttribute('class')).toEqual('doc unspecified');
Akron0b489ad2018-02-02 16:49:32 +01002076 expect(fc.children[2].getAttribute('class')).toEqual('operators button-group');
2077 expect(fc.lastChild.getAttribute('class')).toEqual('operators button-group');
Akronb19803c2018-08-16 16:39:42 +02002078
2079 _orOn(vc.root().getOperand(2));
Akronadab5e52018-08-20 13:50:53 +02002080 fc = vc.builder().firstChild;
Akronb19803c2018-08-16 16:39:42 +02002081 expect(fc.children.length).toEqual(4);
2082
2083 expect(fc.children[0].getAttribute('class')).toEqual('docGroup');
2084 expect(fc.children[1].getAttribute('class')).toEqual('doc');
2085 expect(fc.children[2].getAttribute('class')).toEqual('docGroup');
2086 expect(fc.children[3].getAttribute('class')).toEqual('operators button-group');
2087
Akronadab5e52018-08-20 13:50:53 +02002088 fc = vc.builder().firstChild.children[2];
Akronb19803c2018-08-16 16:39:42 +02002089 expect(fc.children[0].getAttribute('class')).toEqual('doc groupref');
2090 expect(fc.children[1].getAttribute('class')).toEqual('doc unspecified');
2091 expect(fc.children[2].getAttribute('class')).toEqual('operators button-group');
2092 expect(fc.lastChild.getAttribute('class')).toEqual('operators button-group');
2093
Nils Diewald7c8ced22015-04-15 19:21:00 +00002094 });
2095
2096 it('should add new unspecified doc with "and" before group', function () {
2097 var vc = demoFactory.create();
2098
2099 // Wrap with direct element access
2100 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02002101 '(Titel = "Baum" & ' +
2102 'Veröffentlichungsort = "hihi" & ' +
2103 '(Titel = "Baum" | ' +
2104 'Veröffentlichungsort = "hihi")) | ' +
2105 'Untertitel ~ "huhu"'
Nils Diewald7c8ced22015-04-15 19:21:00 +00002106 );
2107
2108 expect(vc.root().getOperand(0).ldType()).toEqual('docGroup');
2109 expect(vc.root().getOperand(0).operation()).toEqual('and');
2110 expect(vc.root().getOperand(0).operands().length).toEqual(3);
2111
2112 // Add unspecified on the second doc
2113 var secDoc = vc.root().getOperand(0).getOperand(1);
2114 expect(secDoc.value()).toEqual('hihi');
2115
2116 // Add
2117 _andOn(secDoc);
2118
2119 var fo = vc.root().getOperand(0);
2120
2121 expect(fo.ldType()).toEqual('docGroup');
2122 expect(fo.operation()).toEqual('and');
2123 expect(fo.operands().length).toEqual(4);
2124
2125 expect(fo.getOperand(0).ldType()).toEqual('doc');
2126 expect(fo.getOperand(1).ldType()).toEqual('doc');
2127 expect(fo.getOperand(2).ldType()).toEqual('non');
2128 expect(fo.getOperand(3).ldType()).toEqual('docGroup');
2129 });
2130
2131
2132 it('should remove a doc with an unspecified doc in a nested group', function () {
2133 var vc = demoFactory.create();
2134
2135 // Wrap with direct element access
2136 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02002137 '(Titel = "Baum" & Veröffentlichungsort = "hihi" & (Titel = "Baum" | Veröffentlichungsort = "hihi")) | Untertitel ~ "huhu"'
Nils Diewald7c8ced22015-04-15 19:21:00 +00002138 );
2139
2140 var fo = vc.root().getOperand(0).getOperand(0);
2141 expect(fo.key()).toEqual('Titel');
2142 expect(fo.value()).toEqual('Baum');
2143
2144 // Add unspecified on the root group
2145 _orOn(fo);
2146
2147 fo = vc.root().getOperand(0).getOperand(0);
2148
2149 expect(fo.operation()).toEqual('or');
2150 expect(fo.getOperand(0).ldType()).toEqual('doc');
2151 expect(fo.getOperand(1).ldType()).toEqual('non');
2152
2153 // Delete document
2154 _delOn(fo.getOperand(0));
2155
2156 // The operand is now non
2157 expect(vc.root().getOperand(0).getOperand(0).ldType()).toEqual('non');
2158 expect(vc.root().getOperand(0).getOperand(1).ldType()).toEqual('doc');
2159 expect(vc.root().getOperand(0).getOperand(2).ldType()).toEqual('docGroup');
2160 });
2161
2162
Akron712733a2018-04-05 18:17:47 +02002163 it('should remove an unspecified doc with a doc in a nested group', function () {
Nils Diewald7c8ced22015-04-15 19:21:00 +00002164 var vc = demoFactory.create();
2165
2166 // Wrap with direct element access
2167 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02002168 '(Titel = "Baum" & ' +
2169 'Veröffentlichungsort = "hihi" & ' +
2170 '(Titel = "Baum" ' +
2171 '| Veröffentlichungsort = "hihi")) | ' +
2172 'Untertitel ~ "huhu"'
Nils Diewald7c8ced22015-04-15 19:21:00 +00002173 );
2174
2175 var fo = vc.root().getOperand(0).getOperand(0);
2176 expect(fo.key()).toEqual('Titel');
2177 expect(fo.value()).toEqual('Baum');
2178
2179 // Add unspecified on the root group
2180 _orOn(fo);
2181
2182 fo = vc.root().getOperand(0).getOperand(0);
2183
2184 expect(fo.operation()).toEqual('or');
2185 expect(fo.getOperand(0).ldType()).toEqual('doc');
2186 expect(fo.getOperand(1).ldType()).toEqual('non');
2187
2188 // Delete unspecified doc
2189 _delOn(fo.getOperand(1));
2190
2191 // The operand is now non
2192 fo = vc.root().getOperand(0);
2193 expect(fo.getOperand(0).ldType()).toEqual('doc');
2194 expect(fo.getOperand(0).key()).toEqual('Titel');
2195 expect(fo.getOperand(0).value()).toEqual('Baum');
2196 expect(fo.getOperand(1).ldType()).toEqual('doc');
2197 expect(fo.getOperand(2).ldType()).toEqual('docGroup');
2198 });
2199
2200
2201 it('should add on parent group (case "and")', function () {
2202 var vc = complexVCFactory.create();
2203
2204 // Wrap with direct element access
2205 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02002206 'pubDate in 2014-12-05 & (title = "Hello World!" | foo = "bar")'
Nils Diewald7c8ced22015-04-15 19:21:00 +00002207 );
2208
2209 expect(vc.root().operands().length).toEqual(2);
2210
2211 // Add unspecified on the root group
2212 _andOn(vc.root().getOperand(1));
2213 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02002214 'pubDate in 2014-12-05 & (title = "Hello World!" | foo = "bar")'
Nils Diewald7c8ced22015-04-15 19:21:00 +00002215 );
2216
2217 expect(vc.root().ldType()).toEqual('docGroup');
2218 expect(vc.root().operands().length).toEqual(3);
2219 expect(vc.root().getOperand(0).ldType()).toEqual('doc');
2220 expect(vc.root().getOperand(1).ldType()).toEqual('docGroup');
2221 expect(vc.root().getOperand(1).operation()).toEqual('or');
2222 expect(vc.root().getOperand(2).ldType()).toEqual('non');
2223
2224 // Add another unspecified on the root group
2225 _andOn(vc.root().getOperand(1));
2226
2227 expect(vc.root().operands().length).toEqual(4);
2228 expect(vc.root().getOperand(0).ldType()).toEqual('doc');
2229 expect(vc.root().getOperand(1).ldType()).toEqual('docGroup');
2230 expect(vc.root().getOperand(2).ldType()).toEqual('non');
2231 expect(vc.root().getOperand(3).ldType()).toEqual('non');
2232
2233 // Add another unspecified after the first doc
2234 _andOn(vc.root().getOperand(0));
2235
2236 expect(vc.root().operands().length).toEqual(5);
2237 expect(vc.root().getOperand(0).ldType()).toEqual('doc');
2238 expect(vc.root().getOperand(1).ldType()).toEqual('non');
2239 expect(vc.root().getOperand(2).ldType()).toEqual('docGroup');
2240 expect(vc.root().getOperand(3).ldType()).toEqual('non');
2241 expect(vc.root().getOperand(4).ldType()).toEqual('non');
2242 });
2243
2244 it('should wrap on root', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00002245 var vc = vcClass.create().fromJson(
Akron712733a2018-04-05 18:17:47 +02002246 {
2247 "@type": 'koral:docGroup',
2248 'operation' : 'operation:and',
2249 'operands' : [
2250 {
2251 "@type": 'koral:doc',
2252 "key": 'pubDate',
2253 "match": 'match:eq',
2254 "value": '2014-12-05',
2255 "type": 'type:date'
2256 },
2257 {
2258 "@type" : 'koral:doc',
2259 'key' : 'foo',
2260 'value' : 'bar'
2261 }
2262 ]
2263 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00002264 );
2265
2266 // Wrap on root
2267 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar"');
2268 expect(vc.root().ldType()).toEqual('docGroup');
2269 expect(vc.root().operation()).toEqual('and');
2270 _orOn(vc.root());
2271 expect(vc.root().ldType()).toEqual('docGroup');
2272 expect(vc.root().operation()).toEqual('or');
2273
2274 expect(vc.root().getOperand(0).ldType()).toEqual('docGroup');
2275 expect(vc.root().getOperand(0).operation()).toEqual('and');
2276 });
2277
2278 it('should add on root (case "and")', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00002279 var vc = vcClass.create().fromJson(
Akron712733a2018-04-05 18:17:47 +02002280 {
2281 "@type": 'koral:doc',
2282 "key": 'pubDate',
2283 "match": 'match:eq',
2284 "value": '2014-12-05',
2285 "type": 'type:date'
2286 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00002287 );
2288
2289 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05');
2290 expect(vc.root().ldType()).toEqual('doc');
2291 expect(vc.root().key()).toEqual('pubDate');
2292 expect(vc.root().value()).toEqual('2014-12-05');
2293
2294 // Wrap on root
2295 _andOn(vc.root());
2296 expect(vc.root().ldType()).toEqual('docGroup');
2297 expect(vc.root().operation()).toEqual('and');
2298 });
2299
2300 it('should add on root (case "or")', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00002301 var vc = vcClass.create().fromJson(
Akron712733a2018-04-05 18:17:47 +02002302 {
2303 "@type": 'koral:doc',
2304 "key": 'pubDate',
2305 "match": 'match:eq',
2306 "value": '2014-12-05',
2307 "type": 'type:date'
2308 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00002309 );
2310
2311 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05');
2312 expect(vc.root().key()).toEqual('pubDate');
2313 expect(vc.root().value()).toEqual('2014-12-05');
2314
2315 // Wrap on root
2316 _orOn(vc.root());
2317 expect(vc.root().ldType()).toEqual('docGroup');
2318 expect(vc.root().operation()).toEqual('or');
2319 });
2320
2321 it('should support multiple sub groups per group', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00002322 var vc = vcClass.create().fromJson(
Akron712733a2018-04-05 18:17:47 +02002323 {
2324 "@type": 'koral:docGroup',
2325 'operation' : 'operation:or',
2326 'operands' : [
2327 {
2328 "@type": 'koral:docGroup',
2329 'operation' : 'operation:and',
2330 'operands' : [
2331 {
2332 "@type": 'koral:doc',
2333 "key": 'title',
2334 "value": 't1',
2335 },
2336 {
2337 "@type" : 'koral:doc',
2338 'key' : 'title',
2339 'value' : 't2'
2340 }
2341 ]
2342 },
2343 {
2344 "@type": 'koral:docGroup',
2345 'operation' : 'operation:and',
2346 'operands' : [
2347 {
2348 "@type": 'koral:doc',
2349 "key": 'title',
2350 "value": 't3',
2351 },
2352 {
2353 "@type" : 'koral:doc',
2354 'key' : 'title',
2355 'value' : 't4'
2356 }
2357 ]
2358 }
2359 ]
2360 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00002361 );
2362 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02002363 '(title = "t1" & title = "t2") | ' +
2364 '(title = "t3" & title = "t4")'
Nils Diewald7c8ced22015-04-15 19:21:00 +00002365 );
2366 expect(vc.root().operation()).toEqual('or');
2367 expect(vc.root().getOperand(0).toQuery()).toEqual('title = "t1" & title = "t2"');
2368 expect(vc.root().getOperand(1).toQuery()).toEqual('title = "t3" & title = "t4"');
2369
2370 _andOn(vc.root());
2371
2372 expect(vc.root().operation()).toEqual('and');
2373 expect(vc.root().getOperand(0).ldType()).toEqual('docGroup');
2374 expect(vc.root().getOperand(1).ldType()).toEqual('non');
2375 });
2376 });
2377
Nils Diewald6283d692015-04-23 20:32:53 +00002378
2379 describe('KorAP.Rewrite', function () {
Nils Diewald7c8ced22015-04-15 19:21:00 +00002380 it('should be initializable', function () {
2381 var rewrite = rewriteClass.create({
Akron712733a2018-04-05 18:17:47 +02002382 "@type" : "koral:rewrite",
2383 "operation" : "operation:modification",
2384 "src" : "querySerializer",
2385 "scope" : "tree"
Nils Diewald86dad5b2015-01-28 15:09:07 +00002386 });
Nils Diewald7c8ced22015-04-15 19:21:00 +00002387 expect(rewrite.toString()).toEqual('Modification of "tree" by "querySerializer"');
2388 });
Nils Diewald86dad5b2015-01-28 15:09:07 +00002389
Nils Diewald7c8ced22015-04-15 19:21:00 +00002390 it('should be deserialized by docs', function () {
2391 var doc = docClass.create(
Akron712733a2018-04-05 18:17:47 +02002392 undefined,
2393 {
2394 "@type":"koral:doc",
2395 "key":"Titel",
2396 "value":"Baum",
2397 "match":"match:eq"
2398 });
Nils Diewald7c8ced22015-04-15 19:21:00 +00002399
2400 expect(doc.element().classList.contains('doc')).toBeTruthy();
2401 expect(doc.element().classList.contains('rewritten')).toBe(false);
2402
2403 doc = docClass.create(
Akron712733a2018-04-05 18:17:47 +02002404 undefined,
2405 {
2406 "@type":"koral:doc",
2407 "key":"Titel",
2408 "value":"Baum",
2409 "match":"match:eq",
2410 "rewrites" : [
2411 {
2412 "@type" : "koral:rewrite",
2413 "operation" : "operation:modification",
2414 "src" : "querySerializer",
2415 "scope" : "tree"
2416 }
2417 ]
2418 });
Nils Diewald7c8ced22015-04-15 19:21:00 +00002419
2420 expect(doc.element().classList.contains('doc')).toBeTruthy();
2421 expect(doc.element().classList.contains('rewritten')).toBeTruthy();
2422 });
Nils Diewald6283d692015-04-23 20:32:53 +00002423
Akron76c3dd62018-05-29 20:58:27 +02002424 it('should be described in a title attribute', function () {
2425
2426 doc = docClass.create(
2427 undefined,
2428 {
2429 "@type":"koral:doc",
2430 "key":"Titel",
2431 "value":"Baum",
2432 "match":"match:eq",
2433 "rewrites" : [
2434 {
2435 "@type" : "koral:rewrite",
2436 "operation" : "operation:modification",
2437 "src" : "querySerializer",
2438 "scope" : "tree"
2439 },
2440 {
2441 "@type" : "koral:rewrite",
2442 "operation" : "operation:injection",
2443 "src" : "me"
2444 }
2445 ]
2446 });
2447
2448 expect(doc.element().classList.contains('doc')).toBeTruthy();
2449 expect(doc.element().classList.contains('rewritten')).toBeTruthy();
2450 expect(doc.element().lastChild.getAttribute("title")).toEqual("querySerializer: tree (modification)\nme (injection)");
2451 });
2452
2453
Nils Diewald6283d692015-04-23 20:32:53 +00002454 xit('should be deserialized by docGroups', function () {
2455 var docGroup = docGroupClass.create(
Akron712733a2018-04-05 18:17:47 +02002456 undefined,
2457 {
2458 "@type" : "koral:docGroup",
2459 "operation" : "operation:or",
2460 "operands" : [
2461 {
2462 "@type" : "doc",
2463 "key" : "pubDate",
2464 "type" : "type:date",
2465 "value" : "2014-12-05"
2466 },
2467 {
2468 "@type" : "doc",
2469 "key" : "pubDate",
2470 "type" : "type:date",
2471 "value" : "2014-12-06"
2472 }
2473 ],
2474 "rewrites" : [
2475 {
2476 "@type" : "koral:rewrite",
2477 "operation" : "operation:modification",
2478 "src" : "querySerializer",
2479 "scope" : "tree"
2480 }
2481 ]
2482 }
Nils Diewald6283d692015-04-23 20:32:53 +00002483 );
2484
2485 expect(doc.element().classList.contains('docgroup')).toBeTruthy();
2486 expect(doc.element().classList.contains('rewritten')).toBe(false);
2487 });
Nils Diewald86dad5b2015-01-28 15:09:07 +00002488 });
Nils Diewaldf0c4f112015-05-05 12:56:59 +00002489
2490 describe('KorAP.stringValue', function () {
2491 it('should be initializable', function () {
2492 var sv = stringValClass.create();
2493 expect(sv.regex()).toBe(false);
2494 expect(sv.value()).toBe('');
Nils Diewaldc4c4b832015-05-05 16:00:08 +00002495
2496 sv = stringValClass.create('Baum');
2497 expect(sv.regex()).toBe(false);
2498 expect(sv.value()).toBe('Baum');
2499
2500 sv = stringValClass.create('Baum', false);
2501 expect(sv.regex()).toBe(false);
2502 expect(sv.value()).toBe('Baum');
2503
2504 sv = stringValClass.create('Baum', true);
2505 expect(sv.regex()).toBe(true);
2506 expect(sv.value()).toBe('Baum');
2507 });
2508
2509 it('should be modifiable', function () {
2510 var sv = stringValClass.create();
2511 expect(sv.regex()).toBe(false);
2512 expect(sv.value()).toBe('');
2513
2514 expect(sv.value('Baum')).toBe('Baum');
2515 expect(sv.value()).toBe('Baum');
2516
2517 expect(sv.regex(true)).toBe(true);
2518 expect(sv.regex()).toBe(true);
2519 });
2520
2521 it('should have a toggleble regex value', function () {
2522 var sv = stringValClass.create();
Nils Diewald7991a3f2015-05-19 14:12:37 +00002523
2524 expect(sv.element().firstChild.value).toBe('');
2525 sv.element().firstChild.value = 'der'
2526 expect(sv.element().firstChild.value).toBe('der');
2527
Nils Diewaldc4c4b832015-05-05 16:00:08 +00002528 expect(sv.regex()).toBe(false);
2529
2530 sv.toggleRegex();
Nils Diewald7991a3f2015-05-19 14:12:37 +00002531 expect(sv.element().firstChild.value).toBe('der');
Nils Diewaldc4c4b832015-05-05 16:00:08 +00002532 expect(sv.regex()).toBe(true);
Nils Diewald7991a3f2015-05-19 14:12:37 +00002533 sv.element().firstChild.value = 'derbe'
Nils Diewaldc4c4b832015-05-05 16:00:08 +00002534
2535 sv.toggleRegex();
2536 expect(sv.regex()).toBe(false);
Nils Diewald7991a3f2015-05-19 14:12:37 +00002537 expect(sv.element().firstChild.value).toBe('derbe');
Nils Diewaldc4c4b832015-05-05 16:00:08 +00002538 });
2539
2540 it('should have an element', function () {
2541 var sv = stringValClass.create('der');
2542 expect(sv.element().nodeName).toBe('DIV');
2543 expect(sv.element().firstChild.nodeName).toBe('INPUT');
2544 expect(sv.element().firstChild.value).toBe('der');
2545 });
2546
2547 it('should have a classed element', function () {
2548 var sv = stringValClass.create();
Nils Diewaldc4c4b832015-05-05 16:00:08 +00002549 expect(sv.element().classList.contains('regex')).toBe(false);
2550 expect(sv.regex()).toBe(false);
2551 sv.toggleRegex();
2552 expect(sv.element().classList.contains('regex')).toBe(true);
2553 });
2554
2555 it('should be storable', function () {
2556 var sv = stringValClass.create();
2557 var count = 1;
2558 sv.store = function (value, regex) {
Akron712733a2018-04-05 18:17:47 +02002559 expect(regex).toBe(true);
2560 expect(value).toBe('tree');
Nils Diewaldc4c4b832015-05-05 16:00:08 +00002561 };
2562 sv.regex(true);
2563 sv.value('tree');
2564 sv.element().lastChild.click();
Nils Diewaldf0c4f112015-05-05 12:56:59 +00002565 });
Akron712733a2018-04-05 18:17:47 +02002566
Akronb19803c2018-08-16 16:39:42 +02002567 it('should have a disableoption for regex', function () {
2568 var sv = stringValClass.create(undefined, undefined, true);
2569 var svE = sv.element();
2570 expect(svE.children.length).toEqual(2);
2571
2572 sv = stringValClass.create(undefined, undefined, false);
2573 svE = sv.element();
2574 expect(svE.children.length).toEqual(1);
2575 });
2576
Nils Diewaldf0c4f112015-05-05 12:56:59 +00002577 });
Akrone4961b12017-05-10 21:04:46 +02002578
Akron712733a2018-04-05 18:17:47 +02002579 describe('KorAP.VC.Menu', function () {
Akrone65a88a2018-04-05 19:14:20 +02002580
2581 var vc;
2582
Akron712733a2018-04-05 18:17:47 +02002583 it('should be initializable', function () {
2584
Akrone65a88a2018-04-05 19:14:20 +02002585 vc = vcClass.create([
Akron712733a2018-04-05 18:17:47 +02002586 ['a', 'text'],
2587 ['b', 'string'],
2588 ['c', 'date']
2589 ]).fromJson();
Akronadab5e52018-08-20 13:50:53 +02002590 expect(vc.builder().firstChild.classList.contains('unspecified')).toBeTruthy();
2591 expect(vc.builder().firstChild.firstChild.tagName).toEqual('SPAN');
Akron712733a2018-04-05 18:17:47 +02002592
2593 // Click on unspecified
Akronadab5e52018-08-20 13:50:53 +02002594 vc.builder().firstChild.firstChild.click();
2595 expect(vc.builder().firstChild.firstChild.tagName).toEqual('UL');
Akron712733a2018-04-05 18:17:47 +02002596
Akronadab5e52018-08-20 13:50:53 +02002597 var list = vc.builder().firstChild.firstChild;
Akron3ad46942018-08-22 16:47:14 +02002598 expect(list.getElementsByTagName("LI")[0].innerText).toEqual('referTo');
2599 expect(list.getElementsByTagName("LI")[1].innerText).toEqual('a');
2600 expect(list.getElementsByTagName("LI")[2].innerText).toEqual('b');
2601 expect(list.getElementsByTagName("LI")[3].innerText).toEqual('c');
Akron712733a2018-04-05 18:17:47 +02002602
2603 vc = vcClass.create([
2604 ['d', 'text'],
2605 ['e', 'string'],
2606 ['f', 'date']
2607 ]).fromJson();
Akronadab5e52018-08-20 13:50:53 +02002608 expect(vc.builder().firstChild.classList.contains('unspecified')).toBeTruthy();
2609 expect(vc.builder().firstChild.firstChild.tagName).toEqual('SPAN');
Akron712733a2018-04-05 18:17:47 +02002610
2611 // Click on unspecified
Akronadab5e52018-08-20 13:50:53 +02002612 vc.builder().firstChild.firstChild.click();
2613 expect(vc.builder().firstChild.firstChild.tagName).toEqual('UL');
Akron712733a2018-04-05 18:17:47 +02002614
Akronadab5e52018-08-20 13:50:53 +02002615 list = vc.builder().firstChild.firstChild;
Akron3ad46942018-08-22 16:47:14 +02002616 expect(list.getElementsByTagName("LI")[0].innerText).toEqual('referTo');
2617 expect(list.getElementsByTagName("LI")[1].innerText).toEqual('d');
2618 expect(list.getElementsByTagName("LI")[2].innerText).toEqual('e');
2619 expect(list.getElementsByTagName("LI")[3].innerText).toEqual('f');
Akron31d89942018-04-06 16:44:51 +02002620 // blur
2621 document.body.click();
Akron712733a2018-04-05 18:17:47 +02002622 });
Akrone65a88a2018-04-05 19:14:20 +02002623
2624 // Reinitialize to make tests stable
2625 vc = vcClass.create([
2626 ['d', 'text'],
2627 ['e', 'string'],
2628 ['f', 'date']
2629 ]).fromJson();
2630
2631 it('should be clickable on key', function () {
Akron31d89942018-04-06 16:44:51 +02002632 // Click on unspecified
Akronadab5e52018-08-20 13:50:53 +02002633 vc.builder().firstChild.firstChild.click();
Akrone65a88a2018-04-05 19:14:20 +02002634 // Click on "d"
Akronadab5e52018-08-20 13:50:53 +02002635 vc.builder().firstChild.firstChild.getElementsByTagName("LI")[1].click();
2636 expect(vc.builder().firstChild.firstChild.tagName).toEqual('SPAN');
2637 expect(vc.builder().firstChild.firstChild.innerText).toEqual('d');
2638 expect(vc.builder().firstChild.children[1].innerText).toEqual('eq');
2639 expect(vc.builder().firstChild.children[1].getAttribute('data-type')).toEqual('text');
Akron31d89942018-04-06 16:44:51 +02002640 // blur
2641 document.body.click();
Akrone65a88a2018-04-05 19:14:20 +02002642 });
2643
Akron31d89942018-04-06 16:44:51 +02002644 it('should be clickable on operation for text', function () {
2645 // Click on "d" (or unspecified)
Akronadab5e52018-08-20 13:50:53 +02002646 vc.builder().firstChild.firstChild.click();
Akron31d89942018-04-06 16:44:51 +02002647
2648 // Choose "d"
Akronadab5e52018-08-20 13:50:53 +02002649 vc.builder().firstChild.firstChild.getElementsByTagName("LI")[1].click();
Akron31d89942018-04-06 16:44:51 +02002650
2651 // Click on matchop
Akronadab5e52018-08-20 13:50:53 +02002652 vc.builder().firstChild.children[1].click();
Akron31d89942018-04-06 16:44:51 +02002653
Akronadab5e52018-08-20 13:50:53 +02002654 expect(vc.builder().firstChild.children[1].tagName).toEqual('UL');
Akron31d89942018-04-06 16:44:51 +02002655
Akronadab5e52018-08-20 13:50:53 +02002656 var ul = vc.builder().firstChild.children[1];
Akrone65a88a2018-04-05 19:14:20 +02002657 expect(ul.getElementsByTagName('li')[0].innerText).toEqual("eq");
2658 expect(ul.getElementsByTagName('li')[1].innerText).toEqual("ne");
2659 expect(ul.getElementsByTagName('li')[2].innerText).toEqual("contains");
2660 expect(ul.getElementsByTagName('li')[3].innerText).toEqual("containsnot");
2661 expect(ul.getElementsByTagName('li')[4]).toBeUndefined();
Akron31d89942018-04-06 16:44:51 +02002662
2663 // Choose "contains"
2664 ul.getElementsByTagName('li')[2].click();
Akronadab5e52018-08-20 13:50:53 +02002665 expect(vc.builder().firstChild.children[1].tagName).toEqual("SPAN");
2666 expect(vc.builder().firstChild.children[1].innerText).toEqual("contains");
Akron31d89942018-04-06 16:44:51 +02002667 // blur
2668 document.body.click();
Akrone65a88a2018-04-05 19:14:20 +02002669 })
Akron31d89942018-04-06 16:44:51 +02002670
2671 it('should be clickable on operation for string', function () {
2672 // Click on "d" (or unspecified)
Akronadab5e52018-08-20 13:50:53 +02002673 vc.builder().firstChild.firstChild.click();
Akron31d89942018-04-06 16:44:51 +02002674
2675 // Choose "e"
Akronadab5e52018-08-20 13:50:53 +02002676 vc.builder().firstChild.firstChild.getElementsByTagName("LI")[2].click();
2677
Akron31d89942018-04-06 16:44:51 +02002678 // As a consequence the matchoperator may no longer
2679 // be valid and needs to be re-evaluated
Akronadab5e52018-08-20 13:50:53 +02002680 var fc = vc.builder().firstChild;
Akron31d89942018-04-06 16:44:51 +02002681 expect(fc.firstChild.tagName).toEqual('SPAN');
2682 expect(fc.firstChild.innerText).toEqual('e');
2683 expect(fc.children[1].innerText).toEqual('eq');
2684 expect(fc.children[1].getAttribute('data-type')).toEqual('string');
2685
Akronadab5e52018-08-20 13:50:53 +02002686 vc.builder().firstChild.children[1].click();
Akron31d89942018-04-06 16:44:51 +02002687
Akronadab5e52018-08-20 13:50:53 +02002688 expect(vc.builder().firstChild.children[1].tagName).toEqual('UL');
Akron31d89942018-04-06 16:44:51 +02002689
Akronadab5e52018-08-20 13:50:53 +02002690 var ul = vc.builder().firstChild.children[1];
Akron31d89942018-04-06 16:44:51 +02002691 expect(ul.getElementsByTagName('li')[0].innerText).toEqual("eq");
2692 expect(ul.getElementsByTagName('li')[1].innerText).toEqual("ne");
2693 expect(ul.getElementsByTagName('li')[2]).toBeUndefined();
2694
2695 // Choose "ne"
2696 ul.getElementsByTagName('li')[1].click();
Akronadab5e52018-08-20 13:50:53 +02002697 expect(vc.builder().firstChild.children[1].tagName).toEqual("SPAN");
2698 expect(vc.builder().firstChild.children[1].innerText).toEqual("ne");
Akron8db5e3a2018-05-28 19:25:26 +02002699
2700 // Click on text
Akronadab5e52018-08-20 13:50:53 +02002701 expect(vc.builder().firstChild.children[2].innerText).toEqual("⋯");
2702 vc.builder().firstChild.children[2].click();
Akron8db5e3a2018-05-28 19:25:26 +02002703
2704 // Blur text element
Akronadab5e52018-08-20 13:50:53 +02002705 expect(vc.builder().firstChild.children[2].firstChild.value).toEqual('');
Akron8db5e3a2018-05-28 19:25:26 +02002706
Akron31d89942018-04-06 16:44:51 +02002707 // blur
2708 document.body.click();
2709 });
2710
2711 it('should be clickable on operation for date', function () {
2712
2713 // Replay matchop check - so it's guaranteed that "ne" is chosen
2714 // Click on "e" (or unspecified)
Akronadab5e52018-08-20 13:50:53 +02002715 vc.builder().firstChild.firstChild.click();
Akron31d89942018-04-06 16:44:51 +02002716 // Rechoose "e"
Akronadab5e52018-08-20 13:50:53 +02002717 vc.builder().firstChild.firstChild.getElementsByTagName("LI")[1].click();
Akron31d89942018-04-06 16:44:51 +02002718 // Click on matchop
Akronadab5e52018-08-20 13:50:53 +02002719 vc.builder().firstChild.children[1].click();
Akron31d89942018-04-06 16:44:51 +02002720 // Choose "ne"
Akronadab5e52018-08-20 13:50:53 +02002721 vc.builder().firstChild.children[1].getElementsByTagName('li')[1].click();
2722 expect(vc.builder().firstChild.children[1].innerText).toEqual("ne");
Akron31d89942018-04-06 16:44:51 +02002723
2724 // Click on "e"
Akronadab5e52018-08-20 13:50:53 +02002725 vc.builder().firstChild.firstChild.click();
Akron31d89942018-04-06 16:44:51 +02002726 // Choose "f"
Akronadab5e52018-08-20 13:50:53 +02002727 vc.builder().firstChild.firstChild.getElementsByTagName("LI")[3].click();
Akron31d89942018-04-06 16:44:51 +02002728
2729 // The matchoperator should still be "ne" as this is valid for dates as well (now)
Akronadab5e52018-08-20 13:50:53 +02002730 var fc = vc.builder().firstChild;
Akron31d89942018-04-06 16:44:51 +02002731 expect(fc.firstChild.tagName).toEqual('SPAN');
2732 expect(fc.firstChild.innerText).toEqual('f');
2733 expect(fc.children[1].innerText).toEqual('ne');
2734 // blur
2735 document.body.click();
2736 });
Akronddc98a72018-04-06 17:33:52 +02002737
2738
2739 // Check json deserialization
2740 it('should be initializable', function () {
2741 vc = vcClass.create([
2742 ['a', 'text'],
2743 ['b', 'string'],
2744 ['c', 'date']
2745 ]).fromJson({
2746 "@type" : "koral:doc",
2747 "key":"a",
2748 "value":"Baum"
2749 });
2750
Akronadab5e52018-08-20 13:50:53 +02002751 expect(vc.builder().firstChild.children[1].getAttribute('data-type')).toEqual('text');
Akronddc98a72018-04-06 17:33:52 +02002752 });
Akron712733a2018-04-05 18:17:47 +02002753 });
2754
2755
Akrone4961b12017-05-10 21:04:46 +02002756 // Check prefix
2757 describe('KorAP.VC.Prefix', function () {
2758
2759 it('should be initializable', function () {
2760 var p = prefixClass.create();
2761 expect(p.element().classList.contains('pref')).toBeTruthy();
2762 expect(p.isSet()).not.toBeTruthy();
2763 });
2764
2765
2766 it('should be clickable', function () {
2767 var vc = vcClass.create([
Akron712733a2018-04-05 18:17:47 +02002768 ['a', null],
2769 ['b', null],
2770 ['c', null]
2771 ]).fromJson();
Akronadab5e52018-08-20 13:50:53 +02002772 expect(vc.builder().firstChild.classList.contains('unspecified')).toBeTruthy();
Akrone4961b12017-05-10 21:04:46 +02002773
2774 // This should open up the menu
Akronadab5e52018-08-20 13:50:53 +02002775 vc.builder().firstChild.firstChild.click();
2776 expect(vc.builder().firstChild.firstChild.tagName).toEqual('UL');
Akrone4961b12017-05-10 21:04:46 +02002777
2778 KorAP._vcKeyMenu._prefix.clear();
2779 KorAP._vcKeyMenu._prefix.add('x');
2780
Akronadab5e52018-08-20 13:50:53 +02002781 var prefElement = vc.builder().querySelector('span.pref');
Akrone4961b12017-05-10 21:04:46 +02002782 expect(prefElement.innerText).toEqual('x');
2783
2784 // This should add key 'x' to VC
2785 prefElement.click();
2786
Akronadab5e52018-08-20 13:50:53 +02002787 expect(vc.builder().firstChild.classList.contains('doc')).toBeTruthy();
2788 expect(vc.builder().firstChild.firstChild.className).toEqual('key');
2789 expect(vc.builder().firstChild.firstChild.innerText).toEqual('x');
Akrone4961b12017-05-10 21:04:46 +02002790 });
2791 });
Nils Diewald2fe12e12015-03-06 16:47:06 +00002792});