blob: 66183f4c547c73270faa8fe12887c004dcc9fcd9 [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 */
4define(['vc'], function () {
Nils Diewald6ac292b2015-01-15 21:33:21 +00005
Nils Diewald7c8ced22015-04-15 19:21:00 +00006 var vcClass = require('vc');
7 var docClass = require('vc/doc');
Akrone4961b12017-05-10 21:04:46 +02008 var menuClass = require('vc/menu');
9 var prefixClass = require('vc/prefix');
Nils Diewald7c8ced22015-04-15 19:21:00 +000010 var docGroupClass = require('vc/docgroup');
11 var unspecifiedClass = require('vc/unspecified');
12 var operatorsClass = require('vc/operators');
13 var rewriteClass = require('vc/rewrite');
Nils Diewaldf0c4f112015-05-05 12:56:59 +000014 var stringValClass = require('vc/stringval');
Nils Diewald6ac292b2015-01-15 21:33:21 +000015
Nils Diewald7c8ced22015-04-15 19:21:00 +000016 // Helper method for building factories
17 buildFactory = function (objClass, defaults) {
18 return {
19 create : function (overwrites) {
Akron712733a2018-04-05 18:17:47 +020020 var newObj = {};
21 for (var prop in defaults) {
22 newObj[prop] = defaults[prop];
23 };
24 for (var prop in overwrites) {
25 newObj[prop] = overwrites[prop];
26 };
27 return objClass.create().fromJson(newObj);
Nils Diewald7c8ced22015-04-15 19:21:00 +000028 }
Nils Diewald0b6c0412014-12-19 03:55:57 +000029 }
Nils Diewald7c8ced22015-04-15 19:21:00 +000030 };
Nils Diewald0b6c0412014-12-19 03:55:57 +000031
Nils Diewald7c8ced22015-04-15 19:21:00 +000032 function _andOn (obj) {
Akrond141a362018-07-10 18:12:13 +020033 KorAP._and.apply(obj);
Nils Diewald7c8ced22015-04-15 19:21:00 +000034 };
Nils Diewald52f7eb12015-01-12 17:30:04 +000035
Nils Diewald7c8ced22015-04-15 19:21:00 +000036 function _orOn (obj) {
Akrond141a362018-07-10 18:12:13 +020037 KorAP._or.apply(obj);
Nils Diewald7c8ced22015-04-15 19:21:00 +000038 };
Nils Diewald52f7eb12015-01-12 17:30:04 +000039
Nils Diewald7c8ced22015-04-15 19:21:00 +000040 function _delOn (obj) {
Akrond141a362018-07-10 18:12:13 +020041 KorAP._delete.apply(obj);
Nils Diewald7c8ced22015-04-15 19:21:00 +000042 };
Nils Diewald52f7eb12015-01-12 17:30:04 +000043
Nils Diewald7c8ced22015-04-15 19:21:00 +000044 var demoFactory = buildFactory(vcClass, {
45 "@type":"koral:docGroup",
46 "operation":"operation:or",
47 "operands":[
Nils Diewaldf219eb82015-01-07 20:15:42 +000048 {
Akron712733a2018-04-05 18:17:47 +020049 "@type":"koral:docGroup",
50 "operation":"operation:and",
51 "operands":[
Nils Diewald7c8ced22015-04-15 19:21:00 +000052 {
53 "@type":"koral:doc",
54 "key":"Titel",
55 "value":"Baum",
56 "match":"match:eq"
57 },
58 {
59 "@type":"koral:doc",
60 "key":"Veröffentlichungsort",
61 "value":"hihi",
62 "match":"match:eq"
63 },
64 {
65 "@type":"koral:docGroup",
66 "operation":"operation:or",
67 "operands":[
68 {
Akron712733a2018-04-05 18:17:47 +020069 "@type":"koral:doc",
70 "key":"Titel",
71 "value":"Baum",
72 "match":"match:eq"
Nils Diewald7c8ced22015-04-15 19:21:00 +000073 },
74 {
Akron712733a2018-04-05 18:17:47 +020075 "@type":"koral:doc",
76 "key":"Veröffentlichungsort",
77 "value":"hihi",
78 "match":"match:eq"
Nils Diewald7c8ced22015-04-15 19:21:00 +000079 }
80 ]
81 }
Akron712733a2018-04-05 18:17:47 +020082 ]
Nils Diewaldf219eb82015-01-07 20:15:42 +000083 },
84 {
Akron712733a2018-04-05 18:17:47 +020085 "@type":"koral:doc",
86 "key":"Untertitel",
87 "value":"huhu",
88 "match":"match:contains"
Nils Diewaldf219eb82015-01-07 20:15:42 +000089 }
90 ]
91 });
92
Nils Diewald7c8ced22015-04-15 19:21:00 +000093 describe('KorAP.Doc', function () {
94 // Create example factories
95 var stringFactory = buildFactory(docClass, {
96 "key" : "author",
97 "value" : "Max Birkendale",
Akron31d89942018-04-06 16:44:51 +020098 "type" : "type:string",
Nils Diewald7c8ced22015-04-15 19:21:00 +000099 "@type" : "koral:doc"
100 });
101
102 // Create example factories
Akron712733a2018-04-05 18:17:47 +0200103 var textFactory = buildFactory(docClass, {
104 "key" : "author",
105 "value" : "Birkendale",
Akron31d89942018-04-06 16:44:51 +0200106 "type" : "type:string",
Akron712733a2018-04-05 18:17:47 +0200107 "match" : "match:contains",
108 "@type" : "koral:doc"
109 });
110
111 // Create example factories
Nils Diewald7c8ced22015-04-15 19:21:00 +0000112 var dateFactory = buildFactory(docClass, {
113 "key" : "pubDate",
114 "type" : "type:date",
115 "match" : "match:eq",
116 "value" : "2014-11-05",
117 "@type" : "koral:doc"
118 });
119
120 // Create example factories
121 var regexFactory = buildFactory(docClass, {
122 "key" : "title",
123 "type" : "type:regex",
124 "value" : "[^b]ee.+?",
125 "@type" : "koral:doc"
126 });
127
128 it('should be initializable', function () {
129 var doc = docClass.create();
130 expect(doc.matchop()).toEqual('eq');
131 expect(doc.key()).toBeUndefined();
132 expect(doc.value()).toBeUndefined();
133 expect(doc.type()).toEqual("string");
134 });
135
136 it('should be definable', function () {
137
138 // Empty doc
139 var doc = docClass.create();
140
141 // Set values
142 doc.key("title");
Akron8db5e3a2018-05-28 19:25:26 +0200143
Nils Diewald7c8ced22015-04-15 19:21:00 +0000144 doc.value("Der alte Mann");
145 expect(doc.matchop()).toEqual('eq');
146 expect(doc.key()).toEqual("title");
147 expect(doc.type()).toEqual("string");
148 expect(doc.value()).toEqual("Der alte Mann");
149 });
150
151
152 it('should deserialize JSON-LD string', function () {
153 var doc;
154
155 // String default
156 doc = stringFactory.create();
157 expect(doc.matchop()).toEqual('eq');
158 expect(doc.key()).toEqual("author");
159 expect(doc.type()).toEqual("string");
160 expect(doc.value()).toEqual("Max Birkendale");
161
162 // No valid string
163 doc = stringFactory.create({
Akron712733a2018-04-05 18:17:47 +0200164 value : undefined
Nils Diewald7c8ced22015-04-15 19:21:00 +0000165 });
166 expect(doc).toBeUndefined();
167
168 // No valid string
169 doc = stringFactory.create({
Akron712733a2018-04-05 18:17:47 +0200170 value : { "foo" : "bar" }
Nils Diewald7c8ced22015-04-15 19:21:00 +0000171 });
172 expect(doc).toBeUndefined();
173
174 // Change match type
175 doc = stringFactory.create({
Akron712733a2018-04-05 18:17:47 +0200176 "match" : "match:ne"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000177 });
178
179 expect(doc.matchop()).toEqual('ne');
180 expect(doc.key()).toEqual("author");
181 expect(doc.type()).toEqual("string");
182 expect(doc.value()).toEqual("Max Birkendale");
183
184 // Invalid match type
185 doc = stringFactory.create({
Akron712733a2018-04-05 18:17:47 +0200186 "match" : { "foo" : "bar" }
Nils Diewald7c8ced22015-04-15 19:21:00 +0000187 });
188 expect(doc).toBeUndefined();
189 });
190
191 it('should deserialize JSON-LD regex', function () {
192 var doc = regexFactory.create();
193 expect(doc.key()).toEqual("title");
194 expect(doc.type()).toEqual("regex");
195 expect(doc.value()).toEqual("[^b]ee.+?");
196 expect(doc.matchop()).toEqual('eq');
197
198 // change matcher
199 doc = regexFactory.create({
Akron712733a2018-04-05 18:17:47 +0200200 match : "match:ne"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000201 });
202 expect(doc.matchop()).toEqual('ne');
Akronea4e9052017-07-06 16:12:05 +0200203 expect(doc.rewrites()).toBeUndefined();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000204
205 // Invalid matcher
206 doc = regexFactory.create({
Akron712733a2018-04-05 18:17:47 +0200207 match : "match:chook"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000208 });
Akronea4e9052017-07-06 16:12:05 +0200209 expect(doc.matchop()).toEqual('eq');
210 expect(doc.rewrites()).toBeDefined();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000211
212 // Invalid regex
213 doc = regexFactory.create({
Akron712733a2018-04-05 18:17:47 +0200214 value : "[^b"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000215 });
216 expect(doc).toBeUndefined();
217 });
218
219 it('should deserialize JSON-LD date', function () {
220
221 // Normal date
222 doc = dateFactory.create({});
223
224 expect(doc.matchop()).toEqual('eq');
225 expect(doc.key()).toEqual("pubDate");
226 expect(doc.type()).toEqual("date");
227 expect(doc.value()).toEqual("2014-11-05");
228
229 // Short date 1
230 doc = dateFactory.create({
Akron712733a2018-04-05 18:17:47 +0200231 "value" : "2014-11"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000232 });
233
234 expect(doc.matchop()).toEqual('eq');
235 expect(doc.key()).toEqual("pubDate");
236 expect(doc.type()).toEqual("date");
237 expect(doc.value()).toEqual("2014-11");
238
239 // Short date 2
240 doc = dateFactory.create({
Akron712733a2018-04-05 18:17:47 +0200241 "value" : "2014"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000242 });
243
244 expect(doc.matchop()).toEqual('eq');
245 expect(doc.key()).toEqual("pubDate");
246 expect(doc.type()).toEqual("date");
247 expect(doc.value()).toEqual("2014");
248
249 // Invalid date!
250 doc = dateFactory.create({
Akron712733a2018-04-05 18:17:47 +0200251 "value" : "2014-11-050"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000252 });
253 expect(doc).toBeUndefined();
254
255 // Invalid matcher!
256 doc = dateFactory.create({
Akron31d89942018-04-06 16:44:51 +0200257 "match" : "match:contains",
Nils Diewald7c8ced22015-04-15 19:21:00 +0000258 });
Akronea4e9052017-07-06 16:12:05 +0200259 expect(doc).toBeDefined();
260 expect(doc.rewrites()).toBeDefined();
261 expect(doc.matchop()).toEqual('eq');
Nils Diewald7c8ced22015-04-15 19:21:00 +0000262 });
263
264 it('should be serializale to JSON', function () {
265
266 // Empty doc
267 var doc = docClass.create();
268 expect(doc.toJson()).toEqual(jasmine.any(Object));
269
270 // Serialize string
271 doc = stringFactory.create();
272 expect(doc.toJson()).toEqual(jasmine.objectContaining({
Akron712733a2018-04-05 18:17:47 +0200273 "@type" : "koral:doc",
274 "type" : "type:string",
275 "key" : "author",
276 "value" : "Max Birkendale",
277 "match" : "match:eq"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000278 }));
279
280 // Serialize regex
281 doc = regexFactory.create();
282 expect(doc.toJson()).toEqual(jasmine.objectContaining({
Akron712733a2018-04-05 18:17:47 +0200283 "@type" : "koral:doc",
284 "type" : "type:regex",
285 "value" : "[^b]ee.+?",
286 "match" : "match:eq",
287 "key" : 'title'
Nils Diewald7c8ced22015-04-15 19:21:00 +0000288 }));
289
290 doc = regexFactory.create({
Akron712733a2018-04-05 18:17:47 +0200291 match: "match:ne"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000292 });
293 expect(doc.toJson()).toEqual(jasmine.objectContaining({
Akron712733a2018-04-05 18:17:47 +0200294 "@type" : "koral:doc",
295 "type" : "type:regex",
296 "value" : "[^b]ee.+?",
297 "match" : "match:ne",
298 "key" : 'title'
Nils Diewald7c8ced22015-04-15 19:21:00 +0000299 }));
300
301 doc = dateFactory.create();
302 expect(doc.toJson()).toEqual(jasmine.objectContaining({
Akron712733a2018-04-05 18:17:47 +0200303 "@type" : "koral:doc",
304 "type" : "type:date",
305 "value" : "2014-11-05",
306 "match" : "match:eq",
307 "key" : 'pubDate'
Nils Diewald7c8ced22015-04-15 19:21:00 +0000308 }));
309
310 doc = dateFactory.create({
Akron712733a2018-04-05 18:17:47 +0200311 value : "2014"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000312 });
313 expect(doc.toJson()).toEqual(jasmine.objectContaining({
Akron712733a2018-04-05 18:17:47 +0200314 "@type" : "koral:doc",
315 "type" : "type:date",
316 "value" : "2014",
317 "match" : "match:eq",
318 "key" : 'pubDate'
Nils Diewald7c8ced22015-04-15 19:21:00 +0000319 }));
320 });
321
322
323 it('should be serializale to String', function () {
324 // Empty doc
325 var doc = docClass.create();
326 expect(doc.toQuery()).toEqual("");
327
328 // Serialize string
329 doc = stringFactory.create();
330 expect(doc.toQuery()).toEqual('author = "Max Birkendale"');
331
332 // Serialize string with quotes
333 doc = stringFactory.create({ "value" : 'Max "Der Coole" Birkendate'});
334 expect(doc.toQuery()).toEqual('author = "Max \\"Der Coole\\" Birkendate"');
335
336 // Serialize regex
337 doc = regexFactory.create();
338 expect(doc.toQuery()).toEqual('title = /[^b]ee.+?/');
339
340 doc = regexFactory.create({
Akron712733a2018-04-05 18:17:47 +0200341 match: "match:ne"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000342 });
343 expect(doc.toQuery()).toEqual('title != /[^b]ee.+?/');
344
Akron8778f5d2017-06-30 21:25:55 +0200345 doc = regexFactory.create({
Akron712733a2018-04-05 18:17:47 +0200346 value: "WPD/AAA/00001"
Akron8778f5d2017-06-30 21:25:55 +0200347 });
348 expect(doc.toQuery()).toEqual('title = /WPD\\/AAA\\/00001/');
349
Nils Diewald7c8ced22015-04-15 19:21:00 +0000350 doc = dateFactory.create();
351 expect(doc.toQuery()).toEqual('pubDate in 2014-11-05');
352
353 doc = dateFactory.create({
Akron712733a2018-04-05 18:17:47 +0200354 value : "2014"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000355 });
356 expect(doc.toQuery()).toEqual('pubDate in 2014');
357 });
358 });
359
360
361 describe('KorAP.DocGroup', function () {
362 // Create example factories
363 var docFactory = buildFactory(
364 docClass,
Nils Diewaldf219eb82015-01-07 20:15:42 +0000365 {
Akron712733a2018-04-05 18:17:47 +0200366 "@type" : "koral:doc",
367 "match":"match:eq",
368 "key" : "author",
369 "value" : "Max Birkendale"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000370 }
371 );
372
373 var docGroupFactory = buildFactory(
374 docGroupClass, {
Akron712733a2018-04-05 18:17:47 +0200375 "@type" : "koral:docGroup",
376 "operation" : "operation:and",
377 "operands" : [
378 docFactory.create().toJson(),
379 docFactory.create({
380 "key" : "pubDate",
381 "type" : "type:date",
382 "value" : "2014-12-05"
383 }).toJson()
384 ]
Nils Diewald7c8ced22015-04-15 19:21:00 +0000385 });
386
387 it('should be initializable', function () {
388 // Create empty group
389 var docGroup = docGroupClass.create();
390 expect(docGroup.operation()).toEqual('and');
391
392 // Create empty group
393 docGroup = docGroupClass.create();
394 docGroup.operation('or');
395 expect(docGroup.operation()).toEqual('or');
396 });
397
398 it('should be definable', function () {
399
400 // Empty group
401 var docGroup = docGroupClass.create();
402 expect(docGroup.operation()).toEqual('and');
403
404 // Set values
405 docGroup.operation("or");
406 expect(docGroup.operation()).toEqual('or');
407
408 // Set invalid values
409 docGroup.operation("hui");
410 expect(docGroup.operation()).toEqual('or');
411 });
412
413 it('should be deserializable', function () {
414 var docGroup = docGroupFactory.create();
415 expect(docGroup.operation()).toEqual("and");
416 expect(docGroup.operands().length).toEqual(2);
417
418 var op1 = docGroup.getOperand(0);
419 expect(op1.type()).toEqual("string");
420 expect(op1.key()).toEqual("author");
421 expect(op1.value()).toEqual("Max Birkendale");
422 expect(op1.matchop()).toEqual("eq");
423
424 var op2 = docGroup.getOperand(1);
425 expect(op2.type()).toEqual("date");
426 expect(op2.key()).toEqual("pubDate");
427 expect(op2.value()).toEqual("2014-12-05");
428 expect(op2.matchop()).toEqual("eq");
429
430 // Append empty group
431 var newGroup = docGroup.append(docGroupClass.create());
432 newGroup.operation('or');
433 newGroup.append(docFactory.create());
434 newGroup.append(docFactory.create({
Akron712733a2018-04-05 18:17:47 +0200435 "type" : "type:regex",
436 "key" : "title",
437 "value" : "^e.+?$",
438 "match" : "match:ne"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000439 }));
440
441 expect(docGroup.operation()).toEqual("and");
442 expect(docGroup.operands().length).toEqual(3);
443
444 var op1 = docGroup.getOperand(0);
445 expect(op1.ldType()).toEqual("doc");
446 expect(op1.type()).toEqual("string");
447 expect(op1.key()).toEqual("author");
448 expect(op1.value()).toEqual("Max Birkendale");
449 expect(op1.matchop()).toEqual("eq");
450
451 var op2 = docGroup.getOperand(1);
452 expect(op2.ldType()).toEqual("doc");
453 expect(op2.type()).toEqual("date");
454 expect(op2.key()).toEqual("pubDate");
455 expect(op2.value()).toEqual("2014-12-05");
456 expect(op2.matchop()).toEqual("eq");
457
458 var op3 = docGroup.getOperand(2);
459 expect(op3.ldType()).toEqual("docGroup");
460 expect(op3.operation()).toEqual("or");
461
462 var op4 = op3.getOperand(0);
463 expect(op4.ldType()).toEqual("doc");
464 expect(op4.type()).toEqual("string");
465 expect(op4.key()).toEqual("author");
466 expect(op4.value()).toEqual("Max Birkendale");
467 expect(op4.matchop()).toEqual("eq");
468
469 var op5 = op3.getOperand(1);
470 expect(op5.ldType()).toEqual("doc");
471 expect(op5.type()).toEqual("regex");
472 expect(op5.key()).toEqual("title");
473 expect(op5.value()).toEqual("^e.+?$");
474 expect(op5.matchop()).toEqual("ne");
475 });
476
477 it('should be serializable to JSON', function () {
478 var docGroup = docGroupFactory.create();
479
480 expect(docGroup.toJson()).toEqual(jasmine.objectContaining({
Akron712733a2018-04-05 18:17:47 +0200481 "@type" : "koral:docGroup",
482 "operation" : "operation:and",
483 "operands" : [
484 {
485 "@type": 'koral:doc',
486 "key" : 'author',
487 "match": 'match:eq',
488 "value": 'Max Birkendale',
489 "type": 'type:string'
490 },
491 {
492 "@type": 'koral:doc',
493 "key": 'pubDate',
494 "match": 'match:eq',
495 "value": '2014-12-05',
496 "type": 'type:date'
497 }
498 ]
Nils Diewald7c8ced22015-04-15 19:21:00 +0000499 }));
500 });
Nils Diewalde15b7a22015-01-09 21:50:21 +0000501
Nils Diewald7c8ced22015-04-15 19:21:00 +0000502 it('should be serializable to String', function () {
503 var docGroup = docGroupFactory.create();
504 expect(docGroup.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +0200505 'author = "Max Birkendale" & pubDate in 2014-12-05'
Nils Diewald7c8ced22015-04-15 19:21:00 +0000506 );
Nils Diewald52f7eb12015-01-12 17:30:04 +0000507
Nils Diewald7c8ced22015-04-15 19:21:00 +0000508 docGroup = docGroupFactory.create({
Akron712733a2018-04-05 18:17:47 +0200509 "@type" : "koral:docGroup",
510 "operation" : "operation:or",
511 "operands" : [
512 {
513 "@type": 'koral:doc',
514 "key" : 'author',
515 "match": 'match:eq',
516 "value": 'Max Birkendale',
517 "type": 'type:string'
518 },
519 {
520 "@type" : "koral:docGroup",
521 "operation" : "operation:and",
522 "operands" : [
523 {
524 "@type": 'koral:doc',
525 "key": 'pubDate',
526 "match": 'match:geq',
527 "value": '2014-05-12',
528 "type": 'type:date'
529 },
530 {
531 "@type": 'koral:doc',
532 "key": 'pubDate',
533 "match": 'match:leq',
534 "value": '2014-12-05',
535 "type": 'type:date'
536 },
537 {
538 "@type": 'koral:doc',
539 "key": 'foo',
540 "match": 'match:ne',
541 "value": '[a]?bar',
542 "type": 'type:regex'
543 }
544 ]
545 }
546 ]
Nils Diewald7c8ced22015-04-15 19:21:00 +0000547 });
548 expect(docGroup.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +0200549 'author = "Max Birkendale" | ' +
550 '(pubDate since 2014-05-12 & ' +
551 'pubDate until 2014-12-05 & foo != /[a]?bar/)'
Nils Diewald7c8ced22015-04-15 19:21:00 +0000552 );
553 });
554 });
555
556 describe('KorAP.UnspecifiedDoc', function () {
557 it('should be initializable', function () {
558 var doc = unspecifiedClass.create();
559 var docElement = doc.element();
560 expect(docElement.getAttribute('class')).toEqual('doc unspecified');
561 expect(docElement.firstChild.firstChild.data).toEqual('⋯');
562 expect(docElement.lastChild.lastChild.data).toEqual('⋯');
563 expect(doc.toQuery()).toEqual('');
564
565 // Only removable
566 expect(docElement.lastChild.children.length).toEqual(0);
567 });
568
Akrond141a362018-07-10 18:12:13 +0200569 it('should be removable, when no root', function () {
Nils Diewald7c8ced22015-04-15 19:21:00 +0000570 var docGroup = docGroupClass.create();
571 docGroup.operation('or');
572 expect(docGroup.operation()).toEqual('or');
573
574 docGroup.append({
Akron712733a2018-04-05 18:17:47 +0200575 "@type": 'koral:doc',
576 "key": 'pubDate',
577 "match": 'match:eq',
578 "value": '2014-12-05',
579 "type": 'type:date'
Nils Diewald7c8ced22015-04-15 19:21:00 +0000580 });
581
582 // Add unspecified object
583 docGroup.append();
584
Akrond141a362018-07-10 18:12:13 +0200585 var parent = document.createElement('div');
586 parent.appendChild(docGroup.element());
587
Nils Diewald7c8ced22015-04-15 19:21:00 +0000588 expect(docGroup.element().getAttribute('class')).toEqual('docGroup');
589 expect(docGroup.element().children[0].getAttribute('class')).toEqual('doc');
590
591 var unspec = docGroup.element().children[1];
592 expect(unspec.getAttribute('class')).toEqual('doc unspecified');
593
594 // Removable
595 expect(unspec.lastChild.children.length).toEqual(1);
596 expect(unspec.lastChild.children[0].getAttribute('class')).toEqual('delete');
597 });
598
Akrond141a362018-07-10 18:12:13 +0200599
Nils Diewald7c8ced22015-04-15 19:21:00 +0000600 it('should be replaceable by a doc', function () {
601 var doc = unspecifiedClass.create();
602 expect(doc.ldType()).toEqual("non");
603 // No parent, therefor not updateable
604 expect(doc.key("baum")).toBeNull();
605
606 var docGroup = docGroupClass.create();
607 docGroup.operation('or');
608 expect(docGroup.operation()).toEqual('or');
609
610 docGroup.append({
Akron712733a2018-04-05 18:17:47 +0200611 "@type": 'koral:doc',
612 "key": 'pubDate',
613 "match": 'match:eq',
614 "value": '2014-12-05',
615 "type": 'type:date'
Nils Diewald7c8ced22015-04-15 19:21:00 +0000616 });
617
618 expect(docGroup.toQuery()).toEqual("pubDate in 2014-12-05");
619 docGroup.append();
620
621 expect(docGroup.getOperand(0).ldType()).toEqual("doc");
622 expect(docGroup.getOperand(1).ldType()).toEqual("non");
623
624 var op = docGroup.getOperand(1).element().lastChild;
Akron0b489ad2018-02-02 16:49:32 +0100625 expect(op.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +0000626 expect(op.children[0].getAttribute('class')).toEqual('delete');
627 expect(op.children.length).toEqual(1);
628
629 // Replace unspecified doc
630 expect(docGroup.getOperand(1).key("name")).not.toBeNull();
631 expect(docGroup.getOperand(1).ldType()).toEqual("doc");
632 expect(docGroup.getOperand(1).key()).toEqual("name");
Akron55a343b2018-04-06 19:57:36 +0200633 expect(docGroup.getOperand(1).value()).toBeUndefined();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000634
635 op = docGroup.getOperand(1).element().lastChild;
Akron0b489ad2018-02-02 16:49:32 +0100636 expect(op.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +0000637 expect(op.children[0].getAttribute('class')).toEqual('and');
638 expect(op.children[1].getAttribute('class')).toEqual('or');
639 expect(op.children[2].getAttribute('class')).toEqual('delete');
640 expect(op.children.length).toEqual(3);
641
642 docGroup.getOperand(1).value("Pachelbel");
643 expect(docGroup.getOperand(1).value()).toEqual("Pachelbel");
644 expect(docGroup.getOperand(1).type()).toEqual("string");
645 expect(docGroup.getOperand(1).matchop()).toEqual("eq");
646
647 // Specified!
648 expect(docGroup.toQuery()).toEqual('pubDate in 2014-12-05 | name = "Pachelbel"');
649 });
650
651 it('should be replaceable on root', function () {
Nils Diewald6283d692015-04-23 20:32:53 +0000652 var vc = vcClass.create();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000653 expect(vc.toQuery()).toEqual("");
654
655 expect(vc.root().ldType()).toEqual("non");
656
657 // No operators on root
658 op = vc.root().element().lastChild;
659 expect(op.lastChild.textContent).toEqual('⋯');
660
661 // Replace
662 expect(vc.root().key("baum")).not.toBeNull();
663 expect(vc.root().ldType()).toEqual("doc");
664
665 op = vc.root().element().lastChild;
Akron0b489ad2018-02-02 16:49:32 +0100666 expect(op.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +0000667 expect(op.children[0].getAttribute('class')).toEqual('and');
668 expect(op.children[1].getAttribute('class')).toEqual('or');
669 expect(op.children[2].getAttribute('class')).toEqual('delete');
670 expect(op.children.length).toEqual(3);
671 });
Akron55a343b2018-04-06 19:57:36 +0200672
673 it('should be clickable', function () {
674 var vc = vcClass.create([
675 ["pubDate", "date"]
676 ]);
677 expect(vc.toQuery()).toEqual("");
678 expect(vc.element().firstChild.textContent).toEqual("⋯");
679 vc.element().firstChild.firstChild.click();
680
681 // Click on pubDate
682 vc.element().firstChild.getElementsByTagName("LI")[0].click();
683
684 expect(vc.element().firstChild.firstChild.textContent).toEqual("pubDate");
685 expect(vc.element().firstChild.children[1].getAttribute("data-type")).toEqual("date");
686 });
Nils Diewald7c8ced22015-04-15 19:21:00 +0000687 });
688
689 describe('KorAP.Doc element', function () {
690 it('should be initializable', function () {
691 var docElement = docClass.create(undefined, {
Akron712733a2018-04-05 18:17:47 +0200692 "@type" : "koral:doc",
693 "key":"Titel",
694 "value":"Baum",
695 "match":"match:eq"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000696 });
697 expect(docElement.key()).toEqual('Titel');
698 expect(docElement.matchop()).toEqual('eq');
699 expect(docElement.value()).toEqual('Baum');
700
701 var docE = docElement.element();
702 expect(docE.children[0].firstChild.data).toEqual('Titel');
703 expect(docE.children[1].firstChild.data).toEqual('eq');
704 expect(docE.children[1].getAttribute('data-type')).toEqual('string');
705 expect(docE.children[2].firstChild.data).toEqual('Baum');
706 expect(docE.children[2].getAttribute('data-type')).toEqual('string');
707
708 expect(docElement.toJson()).toEqual(jasmine.objectContaining({
Akron712733a2018-04-05 18:17:47 +0200709 "@type" : "koral:doc",
710 "key":"Titel",
711 "value":"Baum",
712 "match":"match:eq"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000713 }));
714 });
715 });
716
717 describe('KorAP.DocGroup element', function () {
718 it('should be initializable', function () {
719
720 var docGroup = docGroupClass.create(undefined, {
Akron712733a2018-04-05 18:17:47 +0200721 "@type" : "koral:docGroup",
722 "operation" : "operation:and",
723 "operands" : [
724 {
725 "@type": 'koral:doc',
726 "key" : 'author',
727 "match": 'match:eq',
728 "value": 'Max Birkendale',
729 "type": 'type:string'
730 },
731 {
732 "@type": 'koral:doc',
733 "key": 'pubDate',
734 "match": 'match:eq',
735 "value": '2014-12-05',
736 "type": 'type:date'
737 }
738 ]
Nils Diewald7c8ced22015-04-15 19:21:00 +0000739 });
740
741 expect(docGroup.operation()).toEqual('and');
742 var e = docGroup.element();
743 expect(e.getAttribute('class')).toEqual('docGroup');
744 expect(e.getAttribute('data-operation')).toEqual('and');
745
746 var first = e.children[0];
747 expect(first.getAttribute('class')).toEqual('doc');
748 expect(first.children[0].getAttribute('class')).toEqual('key');
749 expect(first.children[1].getAttribute('class')).toEqual('match');
750 expect(first.children[2].getAttribute('class')).toEqual('value');
751 expect(first.children[2].getAttribute('data-type')).toEqual('string');
752 expect(first.children[0].firstChild.data).toEqual('author');
753 expect(first.children[1].firstChild.data).toEqual('eq');
754 expect(first.children[2].firstChild.data).toEqual('Max Birkendale');
755
756 var second = e.children[1];
757 expect(second.getAttribute('class')).toEqual('doc');
758 expect(second.children[0].getAttribute('class')).toEqual('key');
759 expect(second.children[1].getAttribute('class')).toEqual('match');
760 expect(second.children[2].getAttribute('class')).toEqual('value');
761 expect(second.children[2].getAttribute('data-type')).toEqual('date');
762 expect(second.children[0].firstChild.data).toEqual('pubDate');
763 expect(second.children[1].firstChild.data).toEqual('eq');
764 expect(second.children[2].firstChild.data).toEqual('2014-12-05');
765 });
766
767 it('should be deserializable with nested groups', function () {
768 var docGroup = docGroupClass.create(undefined, {
Akron712733a2018-04-05 18:17:47 +0200769 "@type" : "koral:docGroup",
770 "operation" : "operation:or",
771 "operands" : [
772 {
773 "@type": 'koral:doc',
774 "key" : 'author',
775 "match": 'match:eq',
776 "value": 'Max Birkendale',
777 "type": 'type:string'
778 },
779 {
780 "@type" : "koral:docGroup",
781 "operation" : "operation:and",
782 "operands" : [
783 {
784 "@type": 'koral:doc',
785 "key": 'pubDate',
786 "match": 'match:geq',
787 "value": '2014-05-12',
788 "type": 'type:date'
789 },
790 {
791 "@type": 'koral:doc',
792 "key": 'pubDate',
793 "match": 'match:leq',
794 "value": '2014-12-05',
795 "type": 'type:date'
796 }
797 ]
798 }
799 ]
Nils Diewald7c8ced22015-04-15 19:21:00 +0000800 });
801
802 expect(docGroup.operation()).toEqual('or');
803 var e = docGroup.element();
804 expect(e.getAttribute('class')).toEqual('docGroup');
805 expect(e.getAttribute('data-operation')).toEqual('or');
806
807 expect(e.children[0].getAttribute('class')).toEqual('doc');
808 var docop = e.children[0].lastChild;
Akron0b489ad2018-02-02 16:49:32 +0100809 expect(docop.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +0000810 expect(docop.children[0].getAttribute('class')).toEqual('and');
811 expect(docop.children[1].getAttribute('class')).toEqual('or');
812 expect(docop.children[2].getAttribute('class')).toEqual('delete');
813
814 expect(e.children[1].getAttribute('class')).toEqual('docGroup');
815 expect(e.children[1].getAttribute('data-operation')).toEqual('and');
816
817 // This and-operation can be "or"ed or "delete"d
818 var secop = e.children[1].children[2];
Akron0b489ad2018-02-02 16:49:32 +0100819 expect(secop.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +0000820 expect(secop.children[0].getAttribute('class')).toEqual('or');
821 expect(secop.children[1].getAttribute('class')).toEqual('delete');
822
823 // This or-operation can be "and"ed or "delete"d
Akron0b489ad2018-02-02 16:49:32 +0100824 expect(e.children[2].getAttribute('class')).toEqual('operators button-group');
825 expect(e.lastChild.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +0000826 expect(e.lastChild.children[0].getAttribute('class')).toEqual('and');
827 expect(e.lastChild.children[1].getAttribute('class')).toEqual('delete');
828 });
829 });
830
Akrone4961b12017-05-10 21:04:46 +0200831 describe('KorAP.VirtualCorpus', function () {
Nils Diewald7c8ced22015-04-15 19:21:00 +0000832 var simpleGroupFactory = buildFactory(docGroupClass, {
833 "@type" : "koral:docGroup",
834 "operation" : "operation:and",
835 "operands" : [
Akron712733a2018-04-05 18:17:47 +0200836 {
837 "@type": 'koral:doc',
838 "key" : 'author',
839 "match": 'match:eq',
840 "value": 'Max Birkendale',
841 "type": 'type:string'
842 },
843 {
844 "@type": 'koral:doc',
845 "key": 'pubDate',
846 "match": 'match:eq',
847 "value": '2014-12-05',
848 "type": 'type:date'
849 }
Nils Diewald7c8ced22015-04-15 19:21:00 +0000850 ]
851 });
852
853 var nestedGroupFactory = buildFactory(vcClass, {
854 "@type" : "koral:docGroup",
855 "operation" : "operation:or",
856 "operands" : [
Akron712733a2018-04-05 18:17:47 +0200857 {
858 "@type": 'koral:doc',
859 "key" : 'author',
860 "match": 'match:eq',
861 "value": 'Max Birkendale',
862 "type": 'type:string'
863 },
864 {
865 "@type" : "koral:docGroup",
866 "operation" : "operation:and",
867 "operands" : [
868 {
869 "@type": 'koral:doc',
870 "key": 'pubDate',
871 "match": 'match:geq',
872 "value": '2014-05-12',
873 "type": 'type:date'
874 },
875 {
876 "@type": 'koral:doc',
877 "key": 'pubDate',
878 "match": 'match:leq',
879 "value": '2014-12-05',
880 "type": 'type:date'
881 }
882 ]
883 }
Nils Diewald7c8ced22015-04-15 19:21:00 +0000884 ]
885 });
886
887 var flatGroupFactory = buildFactory(vcClass, {
888 "@type" : "koral:docGroup",
889 "operation" : "operation:and",
890 "operands" : [
Akron712733a2018-04-05 18:17:47 +0200891 {
892 "@type": 'koral:doc',
893 "key": 'pubDate',
894 "match": 'match:geq',
895 "value": '2014-05-12',
896 "type": 'type:date'
897 },
898 {
899 "@type": 'koral:doc',
900 "key": 'pubDate',
901 "match": 'match:leq',
902 "value": '2014-12-05',
903 "type": 'type:date'
904 },
905 {
906 "@type": 'koral:doc',
907 "key": 'foo',
908 "match": 'match:eq',
909 "value": 'bar',
910 "type": 'type:string'
911 }
Nils Diewald7c8ced22015-04-15 19:21:00 +0000912 ]
913 });
914
915 it('should be initializable', function () {
Nils Diewald6283d692015-04-23 20:32:53 +0000916 var vc = vcClass.create();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000917 expect(vc.element().getAttribute('class')).toEqual('vc');
918 expect(vc.root().element().getAttribute('class')).toEqual('doc unspecified');
919
920 // Not removable
921 expect(vc.root().element().lastChild.children.length).toEqual(0);
922 });
923
924 it('should be based on a doc', function () {
Nils Diewald6283d692015-04-23 20:32:53 +0000925 var vc = vcClass.create().fromJson({
Akron712733a2018-04-05 18:17:47 +0200926 "@type" : "koral:doc",
927 "key":"Titel",
928 "value":"Baum",
929 "match":"match:eq"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000930 });
931
932 expect(vc.element().getAttribute('class')).toEqual('vc');
933 expect(vc.root().element().getAttribute('class')).toEqual('doc');
934 expect(vc.root().key()).toEqual('Titel');
935 expect(vc.root().value()).toEqual('Baum');
936 expect(vc.root().matchop()).toEqual('eq');
937
938 var docE = vc.root().element();
939 expect(docE.children[0].firstChild.data).toEqual('Titel');
940 expect(docE.children[1].firstChild.data).toEqual('eq');
941 expect(docE.children[1].getAttribute('data-type')).toEqual('string');
942 expect(docE.children[2].firstChild.data).toEqual('Baum');
943 expect(docE.children[2].getAttribute('data-type')).toEqual('string');
944 });
945
946 it('should be based on a docGroup', function () {
Nils Diewald6283d692015-04-23 20:32:53 +0000947 var vc = vcClass.create().fromJson(simpleGroupFactory.create().toJson());
Nils Diewald7c8ced22015-04-15 19:21:00 +0000948
949 expect(vc.element().getAttribute('class')).toEqual('vc');
950 expect(vc.root().element().getAttribute('class')).toEqual('docGroup');
951 expect(vc.root().operation()).toEqual('and');
952
953 var docGroup = vc.root();
954
955 var first = docGroup.getOperand(0);
956 expect(first.key()).toEqual('author');
957 expect(first.value()).toEqual('Max Birkendale');
958 expect(first.matchop()).toEqual('eq');
959
960 var second = docGroup.getOperand(1);
961 expect(second.key()).toEqual('pubDate');
962 expect(second.value()).toEqual('2014-12-05');
963 expect(second.matchop()).toEqual('eq');
964 });
965
966
967 it('should be based on a nested docGroup', function () {
968 var vc = nestedGroupFactory.create();
969
970 expect(vc.element().getAttribute('class')).toEqual('vc');
971 expect(vc.element().firstChild.getAttribute('class')).toEqual('docGroup');
972 expect(vc.element().firstChild.children[0].getAttribute('class')).toEqual('doc');
973 var dg = vc.element().firstChild.children[1];
974 expect(dg.getAttribute('class')).toEqual('docGroup');
975 expect(dg.children[0].getAttribute('class')).toEqual('doc');
976 expect(dg.children[1].getAttribute('class')).toEqual('doc');
Akron0b489ad2018-02-02 16:49:32 +0100977 expect(dg.children[2].getAttribute('class')).toEqual('operators button-group');
978 expect(vc.element().firstChild.children[2].getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +0000979 });
980
981 it('should be modifiable by deletion in flat docGroups', function () {
982 var vc = flatGroupFactory.create();
983 var docGroup = vc.root();
984
985 expect(docGroup.element().getAttribute('class')).toEqual('docGroup');
986
987 var doc = docGroup.getOperand(1);
988 expect(doc.key()).toEqual("pubDate");
989 expect(doc.value()).toEqual("2014-12-05");
990
991 // Remove operand 1
992 expect(docGroup.delOperand(doc).update()).not.toBeUndefined();
993 expect(doc._element).toEqual(undefined);
994
995 doc = docGroup.getOperand(1);
996 expect(doc.key()).toEqual("foo");
997
998 // Remove operand 1
999 expect(docGroup.delOperand(doc).update()).not.toBeUndefined();
1000 expect(doc._element).toEqual(undefined);
1001
1002 // Only one operand left ...
1003 expect(docGroup.getOperand(1)).toBeUndefined();
1004 // ... but there shouldn't be a group anymore at all!
1005 expect(docGroup.getOperand(0)).toBeUndefined();
1006
1007 var obj = vc.root();
1008 expect(obj.ldType()).toEqual("doc");
1009 expect(obj.key()).toEqual("pubDate");
1010 expect(obj.value()).toEqual("2014-05-12");
1011
1012 expect(obj.element().getAttribute('class')).toEqual('doc');
1013 });
1014
1015
1016 it('should be modifiable by deletion in nested docGroups (root case)', function () {
1017 var vc = nestedGroupFactory.create();
1018
1019 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001020 'author = "Max Birkendale" | (pubDate since 2014-05-12 & pubDate until 2014-12-05)'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001021 );
1022
1023 var docGroup = vc.root();
1024 expect(docGroup.ldType()).toEqual("docGroup");
1025 expect(docGroup.operation()).toEqual("or");
1026
1027 var doc = docGroup.getOperand(0);
1028 expect(doc.key()).toEqual("author");
1029 expect(doc.value()).toEqual("Max Birkendale");
1030
1031 docGroup = docGroup.getOperand(1);
1032 expect(docGroup.operation()).toEqual("and");
1033
1034 doc = docGroup.getOperand(0);
1035 expect(doc.key()).toEqual("pubDate");
1036 expect(doc.matchop()).toEqual("geq");
1037 expect(doc.value()).toEqual("2014-05-12");
1038 expect(doc.type()).toEqual("date");
1039
1040 doc = docGroup.getOperand(1);
1041 expect(doc.key()).toEqual("pubDate");
1042 expect(doc.matchop()).toEqual("leq");
1043 expect(doc.value()).toEqual("2014-12-05");
1044 expect(doc.type()).toEqual("date");
1045
1046 // Remove first operand so everything becomes root
1047 expect(
Akron712733a2018-04-05 18:17:47 +02001048 vc.root().delOperand(
1049 vc.root().getOperand(0)
1050 ).update().ldType()
Nils Diewald7c8ced22015-04-15 19:21:00 +00001051 ).toEqual("docGroup");
1052
1053 expect(vc.root().ldType()).toEqual("docGroup");
1054 expect(vc.root().operation()).toEqual("and");
1055 expect(vc.root().getOperand(0).ldType()).toEqual("doc");
1056
1057 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001058 'pubDate since 2014-05-12 & pubDate until 2014-12-05'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001059 );
1060 });
1061
1062 it('should be modifiable by deletion in nested docGroups (resolve group case)', function () {
1063 var vc = nestedGroupFactory.create();
1064
1065 // Get nested group
1066 var firstGroup = vc.root().getOperand(1);
1067 firstGroup.append(simpleGroupFactory.create({ "operation" : "operation:or" }));
1068
1069 // Structur is now:
1070 // or(doc, and(doc, doc, or(doc, doc)))
1071
1072 // Get nested or in and
1073 var orGroup = vc.root().getOperand(1).getOperand(2);
1074 expect(orGroup.ldType()).toEqual("docGroup");
1075 expect(orGroup.operation()).toEqual("or");
1076
1077 // Remove
1078 // Structur is now:
1079 // or(doc, and(doc, doc, doc)))
1080 expect(orGroup.delOperand(orGroup.getOperand(0)).update().operation()).toEqual("and");
1081 expect(vc.root().getOperand(1).operands().length).toEqual(3);
1082 });
1083
1084 it('should be modifiable by deletion in nested docGroups (identical group case)', function () {
1085 var vc = nestedGroupFactory.create();
1086
1087 // Get nested group
1088 var firstGroup = vc.root().getOperand(1);
1089 firstGroup.append(simpleGroupFactory.create({
Akron712733a2018-04-05 18:17:47 +02001090 "operation" : "operation:or"
Nils Diewald7c8ced22015-04-15 19:21:00 +00001091 }));
1092 var oldAuthor = firstGroup.getOperand(2).getOperand(0);
1093 oldAuthor.key("title");
1094 oldAuthor.value("Der Birnbaum");
1095
1096 // Structur is now:
1097 // or(doc, and(doc, doc, or(doc, doc)))
1098 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001099 'author = "Max Birkendale" | ' +
1100 '(pubDate since 2014-05-12 & ' +
1101 'pubDate until 2014-12-05 & ' +
1102 '(title = "Der Birnbaum" | ' +
1103 'pubDate in 2014-12-05))'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001104 );
1105
1106 var andGroup = vc.root().getOperand(1);
1107
1108 // Get leading docs in and
1109 var doc1 = andGroup.getOperand(0);
1110 expect(doc1.ldType()).toEqual("doc");
1111 expect(doc1.value()).toEqual("2014-05-12");
1112 var doc2 = andGroup.getOperand(1);
1113 expect(doc2.ldType()).toEqual("doc");
1114 expect(doc2.value()).toEqual("2014-12-05");
1115
1116 // Remove 2
1117 expect(
Akron712733a2018-04-05 18:17:47 +02001118 andGroup.delOperand(doc2).update().operation()
Nils Diewald7c8ced22015-04-15 19:21:00 +00001119 ).toEqual("and");
1120 // Structur is now:
1121 // or(doc, and(doc, or(doc, doc)))
1122
1123 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001124 'author = "Max Birkendale"' +
1125 ' | (pubDate since 2014-05-12 & ' +
1126 '(title = "Der Birnbaum" | pubDate in 2014-12-05))'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001127 );
1128
1129
1130 // Remove 1
1131 expect(andGroup.delOperand(doc1).update().operation()).toEqual("or");
1132 // Structur is now:
1133 // or(doc, doc, doc)
1134
1135 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001136 'author = "Max Birkendale" | title = "Der Birnbaum" | pubDate in 2014-12-05'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001137 );
1138 });
1139
1140 it('should be reducible to unspecification', function () {
1141 var vc = demoFactory.create();
1142
1143 expect(vc.toQuery()).toEqual(vc.root().toQuery());
1144 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001145 '(Titel = "Baum" & Veröffentlichungsort = "hihi" & ' +
1146 '(Titel = "Baum" | Veröffentlichungsort = "hihi")) ' +
1147 '| Untertitel ~ "huhu"');
Akrond141a362018-07-10 18:12:13 +02001148 expect(vc.root().element().lastChild.children[0].innerText).toEqual('and');
1149 expect(vc.root().element().lastChild.children[1].innerText).toEqual('×');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001150 expect(vc.root().delOperand(vc.root().getOperand(0)).update()).not.toBeUndefined();
Akron712733a2018-04-05 18:17:47 +02001151 expect(vc.toQuery()).toEqual('Untertitel ~ "huhu"');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001152
1153 var lc = vc.root().element().lastChild;
Akrond141a362018-07-10 18:12:13 +02001154 expect(lc.children[0].innerText).toEqual('and');
1155 expect(lc.children[1].innerText).toEqual('or');
1156 expect(lc.children[2].innerText).toEqual('×');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001157
1158 // Clean everything
1159 vc.clean();
1160 expect(vc.toQuery()).toEqual('');
1161 });
1162
1163 it('should flatten on import', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00001164 var vc = vcClass.create().fromJson({
Akron712733a2018-04-05 18:17:47 +02001165 "@type":"koral:docGroup",
1166 "operation":"operation:or",
1167 "operands":[
1168 {
1169 "@type":"koral:docGroup",
1170 "operation":"operation:or",
1171 "operands":[
Nils Diewald7c8ced22015-04-15 19:21:00 +00001172 {
Akron712733a2018-04-05 18:17:47 +02001173 "@type":"koral:doc",
1174 "key":"Titel",
1175 "value":"Baum",
1176 "match":"match:eq"
Nils Diewald7c8ced22015-04-15 19:21:00 +00001177 },
1178 {
Akron712733a2018-04-05 18:17:47 +02001179 "@type":"koral:doc",
1180 "key":"Veröffentlichungsort",
1181 "value":"hihi",
1182 "match":"match:eq"
Nils Diewald7c8ced22015-04-15 19:21:00 +00001183 },
1184 {
Akron712733a2018-04-05 18:17:47 +02001185 "@type":"koral:docGroup",
1186 "operation":"operation:or",
1187 "operands":[
1188 {
1189 "@type":"koral:doc",
1190 "key":"Titel",
1191 "value":"Baum",
1192 "match":"match:eq"
1193 },
1194 {
1195 "@type":"koral:doc",
1196 "key":"Veröffentlichungsort",
1197 "value":"hihi",
1198 "match":"match:eq"
1199 }
1200 ]
Nils Diewald7c8ced22015-04-15 19:21:00 +00001201 }
Akron712733a2018-04-05 18:17:47 +02001202 ]
1203 },
1204 {
1205 "@type":"koral:doc",
1206 "key":"Untertitel",
1207 "value":"huhu",
1208 "match":"match:contains"
1209 }
1210 ]
Nils Diewald7c8ced22015-04-15 19:21:00 +00001211 });
Nils Diewaldfda29d92015-01-22 17:28:01 +00001212
Nils Diewald7c8ced22015-04-15 19:21:00 +00001213 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001214 'Titel = "Baum" | Veröffentlichungsort = "hihi" | Untertitel ~ "huhu"'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001215 );
Nils Diewald86dad5b2015-01-28 15:09:07 +00001216 });
Nils Diewald86dad5b2015-01-28 15:09:07 +00001217 });
1218
Nils Diewald7c8ced22015-04-15 19:21:00 +00001219 describe('KorAP.Operators', function () {
1220 it('should be initializable', function () {
1221 var op = operatorsClass.create(true, false, false);
1222 expect(op.and()).toBeTruthy();
1223 expect(op.or()).not.toBeTruthy();
1224 expect(op.del()).not.toBeTruthy();
1225
1226 op.and(false);
1227 expect(op.and()).not.toBeTruthy();
1228 expect(op.or()).not.toBeTruthy();
1229 expect(op.del()).not.toBeTruthy();
1230
1231 op.or(true);
1232 op.del(true);
1233 expect(op.and()).not.toBeTruthy();
1234 expect(op.or()).toBeTruthy();
1235 expect(op.del()).toBeTruthy();
1236
Akrond141a362018-07-10 18:12:13 +02001237 var e = op.update();
Akron0b489ad2018-02-02 16:49:32 +01001238 expect(e.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001239 expect(e.children[0].getAttribute('class')).toEqual('or');
Akrond141a362018-07-10 18:12:13 +02001240 expect(e.children[0].innerText).toEqual('or');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001241 expect(e.children[1].getAttribute('class')).toEqual('delete');
Akrond141a362018-07-10 18:12:13 +02001242 expect(e.children[1].innerText).toEqual('×');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001243
1244 op.and(true);
1245 op.del(false);
Akrond141a362018-07-10 18:12:13 +02001246 e = op.update();
Nils Diewald7c8ced22015-04-15 19:21:00 +00001247
Akron0b489ad2018-02-02 16:49:32 +01001248 expect(e.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001249 expect(e.children[0].getAttribute('class')).toEqual('and');
Akrond141a362018-07-10 18:12:13 +02001250 expect(e.children[0].innerText).toEqual('and');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001251 expect(e.children[1].getAttribute('class')).toEqual('or');
Akrond141a362018-07-10 18:12:13 +02001252 expect(e.children[1].innerText).toEqual('or');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001253 });
1254 });
1255
1256 describe('KorAP._delete (event)', function () {
1257 var complexVCFactory = buildFactory(vcClass,{
1258 "@type": 'koral:docGroup',
1259 'operation' : 'operation:and',
1260 'operands' : [
Akron712733a2018-04-05 18:17:47 +02001261 {
1262 "@type": 'koral:doc',
1263 "key": 'pubDate',
1264 "match": 'match:eq',
1265 "value": '2014-12-05',
1266 "type": 'type:date'
1267 },
1268 {
1269 "@type" : 'koral:docGroup',
1270 'operation' : 'operation:or',
1271 'operands' : [
1272 {
1273 '@type' : 'koral:doc',
1274 'key' : 'title',
1275 'value' : 'Hello World!'
1276 },
1277 {
1278 '@type' : 'koral:doc',
1279 'key' : 'foo',
1280 'value' : 'bar'
1281 }
1282 ]
1283 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00001284 ]
1285 });
1286
1287 it('should clean on root docs', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00001288 var vc = vcClass.create().fromJson({
Akron712733a2018-04-05 18:17:47 +02001289 "@type": 'koral:doc',
1290 "key": 'pubDate',
1291 "match": 'match:eq',
1292 "value": '2014-12-05',
1293 "type": 'type:date'
Nils Diewald86dad5b2015-01-28 15:09:07 +00001294 });
Nils Diewald7c8ced22015-04-15 19:21:00 +00001295 expect(vc.root().toQuery()).toEqual('pubDate in 2014-12-05');
Akron0b489ad2018-02-02 16:49:32 +01001296 expect(vc.root().element().lastChild.getAttribute('class')).toEqual('operators button-group');
Nils Diewald86dad5b2015-01-28 15:09:07 +00001297
Nils Diewald7c8ced22015-04-15 19:21:00 +00001298 // Clean with delete from root
1299 expect(vc.root().element().lastChild.lastChild.getAttribute('class')).toEqual('delete');
1300 _delOn(vc.root());
1301 expect(vc.root().toQuery()).toEqual('');
1302 expect(vc.root().element().lastChild.lastChild.data).toEqual('⋯');
1303 });
Nils Diewald86dad5b2015-01-28 15:09:07 +00001304
Nils Diewald7c8ced22015-04-15 19:21:00 +00001305 it('should remove on nested docs', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00001306 var vc = vcClass.create().fromJson(
Akron712733a2018-04-05 18:17:47 +02001307 {
1308 "@type": 'koral:docGroup',
1309 'operation' : 'operation:and',
1310 'operands' : [
1311 {
1312 "@type": 'koral:doc',
1313 "key": 'pubDate',
1314 "match": 'match:eq',
1315 "value": '2014-12-05',
1316 "type": 'type:date'
1317 },
1318 {
1319 "@type" : 'koral:doc',
1320 'key' : 'foo',
1321 'value' : 'bar'
1322 }
1323 ]
1324 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00001325 );
1326
1327 // Delete with direct element access
1328 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar"');
1329 _delOn(vc.root().getOperand(0));
1330
1331 expect(vc.toQuery()).toEqual('foo = "bar"');
1332 expect(vc.root().ldType()).toEqual('doc');
1333 });
1334
1335 it('should clean on doc groups', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00001336 var vc = vcClass.create().fromJson(
Akron712733a2018-04-05 18:17:47 +02001337 {
1338 "@type": 'koral:docGroup',
1339 'operation' : 'operation:and',
1340 'operands' : [
1341 {
1342 "@type": 'koral:doc',
1343 "key": 'pubDate',
1344 "match": 'match:eq',
1345 "value": '2014-12-05',
1346 "type": 'type:date'
1347 },
1348 {
1349 "@type" : 'koral:doc',
1350 'key' : 'foo',
1351 'value' : 'bar'
1352 }
1353 ]
1354 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00001355 );
1356
1357 // Cleanwith direct element access
1358 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar"');
1359 _delOn(vc.root());
1360 expect(vc.toQuery()).toEqual('');
1361 expect(vc.root().ldType()).toEqual('non');
1362 });
1363
1364 it('should remove on nested doc groups (case of ungrouping 1)', function () {
1365 var vc = complexVCFactory.create();
1366
1367 // Delete with direct element access
1368 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001369 'pubDate in 2014-12-05 & (title = "Hello World!" | foo = "bar")'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001370 );
1371
1372 // Remove hello world:
1373 _delOn(vc.root().getOperand(1).getOperand(0));
1374 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar"');
1375 expect(vc.root().ldType()).toEqual('docGroup');
1376 });
1377
1378 it('should remove on nested doc groups (case of ungrouping 2)', function () {
1379 var vc = complexVCFactory.create();
1380
1381 // Delete with direct element access
1382 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001383 'pubDate in 2014-12-05 & (title = "Hello World!" | foo = "bar")'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001384 );
1385
1386 // Remove bar
1387 _delOn(vc.root().getOperand(1).getOperand(1));
1388 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & title = "Hello World!"');
1389 expect(vc.root().ldType()).toEqual('docGroup');
1390 expect(vc.root().operation()).toEqual('and');
1391 });
1392
1393 it('should remove on nested doc groups (case of root changing)', function () {
1394 var vc = complexVCFactory.create();
1395
1396 // Delete with direct element access
1397 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001398 'pubDate in 2014-12-05 & ' +
1399 '(title = "Hello World!" | foo = "bar")'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001400 );
1401
1402 // Remove bar
1403 _delOn(vc.root().getOperand(0));
1404 expect(vc.toQuery()).toEqual('title = "Hello World!" | foo = "bar"');
1405 expect(vc.root().ldType()).toEqual('docGroup');
1406 expect(vc.root().operation()).toEqual('or');
1407 });
1408
1409 it('should remove on nested doc groups (list flattening)', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00001410 var vc = vcClass.create().fromJson(
Akron712733a2018-04-05 18:17:47 +02001411 {
1412 "@type": 'koral:docGroup',
1413 'operation' : 'operation:or',
1414 'operands' : [
1415 {
1416 "@type": 'koral:doc',
1417 "key": 'pubDate',
1418 "match": 'match:eq',
1419 "value": '2014-12-05',
1420 "type": 'type:date'
1421 },
1422 {
1423 "@type" : 'koral:doc',
1424 'key' : 'foo',
1425 'value' : 'bar'
1426 },
1427 {
1428 "@type": 'koral:docGroup',
1429 'operation' : 'operation:and',
1430 'operands' : [
1431 {
1432 "@type": 'koral:doc',
1433 "key": 'pubDate',
1434 "match": 'match:eq',
1435 "value": '2014-12-05',
1436 "type": 'type:date'
1437 },
1438 {
1439 "@type" : 'koral:docGroup',
1440 'operation' : 'operation:or',
1441 'operands' : [
1442 {
1443 '@type' : 'koral:doc',
1444 'key' : 'title',
1445 'value' : 'Hello World!'
1446 },
1447 {
1448 '@type' : 'koral:doc',
1449 'key' : 'yeah',
1450 'value' : 'juhu'
1451 }
1452 ]
1453 }
1454 ]
1455 }
1456 ]
1457 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00001458 );
1459
1460 // Delete with direct element access
1461 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001462 'pubDate in 2014-12-05 | foo = "bar" | ' +
1463 '(pubDate in 2014-12-05 & ' +
1464 '(title = "Hello World!" | yeah = "juhu"))'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001465 );
1466
1467 expect(vc.root().ldType()).toEqual('docGroup');
1468 expect(vc.root().operation()).toEqual('or');
1469
1470 // Operands and operators
1471 expect(vc.element().firstChild.children.length).toEqual(4);
Akron0b489ad2018-02-02 16:49:32 +01001472 expect(vc.element().firstChild.lastChild.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001473
1474 // Remove inner group and flatten
1475 _delOn(vc.root().getOperand(2).getOperand(0));
1476
1477 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001478 'pubDate in 2014-12-05 | foo = "bar" | title = "Hello World!" | yeah = "juhu"'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001479 );
1480 expect(vc.root().ldType()).toEqual('docGroup');
1481 expect(vc.root().operation()).toEqual('or');
1482
1483 // Operands and operators
1484 expect(vc.element().firstChild.children.length).toEqual(5);
Akron0b489ad2018-02-02 16:49:32 +01001485 expect(vc.element().firstChild.lastChild.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001486 });
1487 });
1488
1489 describe('KorAP._add (event)', function () {
1490 var complexVCFactory = buildFactory(vcClass,{
1491 "@type": 'koral:docGroup',
1492 'operation' : 'operation:and',
1493 'operands' : [
Akron712733a2018-04-05 18:17:47 +02001494 {
1495 "@type": 'koral:doc',
1496 "key": 'pubDate',
1497 "match": 'match:eq',
1498 "value": '2014-12-05',
1499 "type": 'type:date'
1500 },
1501 {
1502 "@type" : 'koral:docGroup',
1503 'operation' : 'operation:or',
1504 'operands' : [
1505 {
1506 '@type' : 'koral:doc',
1507 'key' : 'title',
1508 'value' : 'Hello World!'
1509 },
1510 {
1511 '@type' : 'koral:doc',
1512 'key' : 'foo',
1513 'value' : 'bar'
1514 }
1515 ]
1516 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00001517 ]
1518 });
1519
1520 it('should add new unspecified doc with "and"', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00001521 var vc = vcClass.create().fromJson(
Akron712733a2018-04-05 18:17:47 +02001522 {
1523 "@type": 'koral:docGroup',
1524 'operation' : 'operation:and',
1525 'operands' : [
1526 {
1527 "@type": 'koral:doc',
1528 "key": 'pubDate',
1529 "match": 'match:eq',
1530 "value": '2014-12-05',
1531 "type": 'type:date'
1532 },
1533 {
1534 "@type" : 'koral:doc',
1535 'key' : 'foo',
1536 'value' : 'bar'
1537 }
1538 ]
1539 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00001540 );
1541
1542 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar"');
1543
1544 var fc = vc.element().firstChild;
1545 expect(fc.getAttribute('data-operation')).toEqual('and');
1546 expect(fc.children.length).toEqual(3);
Akron0b489ad2018-02-02 16:49:32 +01001547 expect(fc.lastChild.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001548 expect(fc.children[0].getAttribute('class')).toEqual('doc');
1549 expect(fc.children[1].getAttribute('class')).toEqual('doc');
1550
1551 // add with 'and' in the middle
1552 _andOn(vc.root().getOperand(0));
1553 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar"');
1554
1555 fc = vc.element().firstChild;
1556 expect(fc.getAttribute('data-operation')).toEqual('and');
1557 expect(fc.children.length).toEqual(4);
Akron0b489ad2018-02-02 16:49:32 +01001558 expect(fc.lastChild.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001559
1560 expect(fc.children[0].getAttribute('class')).toEqual('doc');
1561 expect(fc.children[1].getAttribute('class')).toEqual('doc unspecified');
1562 expect(fc.children[2].getAttribute('class')).toEqual('doc');
1563 });
1564
1565 it('should add new unspecified doc with "or"', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00001566 var vc = vcClass.create().fromJson(
Akron712733a2018-04-05 18:17:47 +02001567 {
1568 "@type": 'koral:docGroup',
1569 'operation' : 'operation:and',
1570 'operands' : [
1571 {
1572 "@type": 'koral:doc',
1573 "key": 'pubDate',
1574 "match": 'match:eq',
1575 "value": '2014-12-05',
1576 "type": 'type:date'
1577 },
1578 {
1579 "@type" : 'koral:doc',
1580 'key' : 'foo',
1581 'value' : 'bar'
1582 }
1583 ]
1584 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00001585 );
1586
1587 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar"');
1588
1589 var fc = vc.element().firstChild;
1590 expect(fc.children.length).toEqual(3);
Akron0b489ad2018-02-02 16:49:32 +01001591 expect(fc.lastChild.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001592 expect(fc.children[0].getAttribute('class')).toEqual('doc');
1593 expect(fc.children[1].getAttribute('class')).toEqual('doc');
1594
1595 // add with 'or' in the middle
1596 _orOn(vc.root().getOperand(0));
1597 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar"');
1598 fc = vc.element().firstChild;
1599
1600 expect(fc.getAttribute('data-operation')).toEqual('and');
1601 expect(fc.children.length).toEqual(3);
1602 expect(fc.children[0].getAttribute('class')).toEqual('docGroup');
1603 expect(fc.children[0].getAttribute('data-operation')).toEqual('or');
1604 expect(fc.children[1].getAttribute('class')).toEqual('doc');
Akron0b489ad2018-02-02 16:49:32 +01001605 expect(fc.children[2].getAttribute('class')).toEqual('operators button-group');
1606 expect(fc.lastChild.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001607
1608 fc = vc.element().firstChild.firstChild;
1609 expect(fc.children.length).toEqual(3);
1610 expect(fc.children[0].getAttribute('class')).toEqual('doc');
1611 expect(fc.children[1].getAttribute('class')).toEqual('doc unspecified');
Akron0b489ad2018-02-02 16:49:32 +01001612 expect(fc.children[2].getAttribute('class')).toEqual('operators button-group');
1613 expect(fc.lastChild.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001614 });
1615
1616 it('should add new unspecified doc with "and" before group', function () {
1617 var vc = demoFactory.create();
1618
1619 // Wrap with direct element access
1620 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001621 '(Titel = "Baum" & ' +
1622 'Veröffentlichungsort = "hihi" & ' +
1623 '(Titel = "Baum" | ' +
1624 'Veröffentlichungsort = "hihi")) | ' +
1625 'Untertitel ~ "huhu"'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001626 );
1627
1628 expect(vc.root().getOperand(0).ldType()).toEqual('docGroup');
1629 expect(vc.root().getOperand(0).operation()).toEqual('and');
1630 expect(vc.root().getOperand(0).operands().length).toEqual(3);
1631
1632 // Add unspecified on the second doc
1633 var secDoc = vc.root().getOperand(0).getOperand(1);
1634 expect(secDoc.value()).toEqual('hihi');
1635
1636 // Add
1637 _andOn(secDoc);
1638
1639 var fo = vc.root().getOperand(0);
1640
1641 expect(fo.ldType()).toEqual('docGroup');
1642 expect(fo.operation()).toEqual('and');
1643 expect(fo.operands().length).toEqual(4);
1644
1645 expect(fo.getOperand(0).ldType()).toEqual('doc');
1646 expect(fo.getOperand(1).ldType()).toEqual('doc');
1647 expect(fo.getOperand(2).ldType()).toEqual('non');
1648 expect(fo.getOperand(3).ldType()).toEqual('docGroup');
1649 });
1650
1651
1652 it('should remove a doc with an unspecified doc in a nested group', function () {
1653 var vc = demoFactory.create();
1654
1655 // Wrap with direct element access
1656 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001657 '(Titel = "Baum" & Veröffentlichungsort = "hihi" & (Titel = "Baum" | Veröffentlichungsort = "hihi")) | Untertitel ~ "huhu"'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001658 );
1659
1660 var fo = vc.root().getOperand(0).getOperand(0);
1661 expect(fo.key()).toEqual('Titel');
1662 expect(fo.value()).toEqual('Baum');
1663
1664 // Add unspecified on the root group
1665 _orOn(fo);
1666
1667 fo = vc.root().getOperand(0).getOperand(0);
1668
1669 expect(fo.operation()).toEqual('or');
1670 expect(fo.getOperand(0).ldType()).toEqual('doc');
1671 expect(fo.getOperand(1).ldType()).toEqual('non');
1672
1673 // Delete document
1674 _delOn(fo.getOperand(0));
1675
1676 // The operand is now non
1677 expect(vc.root().getOperand(0).getOperand(0).ldType()).toEqual('non');
1678 expect(vc.root().getOperand(0).getOperand(1).ldType()).toEqual('doc');
1679 expect(vc.root().getOperand(0).getOperand(2).ldType()).toEqual('docGroup');
1680 });
1681
1682
Akron712733a2018-04-05 18:17:47 +02001683 it('should remove an unspecified doc with a doc in a nested group', function () {
Nils Diewald7c8ced22015-04-15 19:21:00 +00001684 var vc = demoFactory.create();
1685
1686 // Wrap with direct element access
1687 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001688 '(Titel = "Baum" & ' +
1689 'Veröffentlichungsort = "hihi" & ' +
1690 '(Titel = "Baum" ' +
1691 '| Veröffentlichungsort = "hihi")) | ' +
1692 'Untertitel ~ "huhu"'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001693 );
1694
1695 var fo = vc.root().getOperand(0).getOperand(0);
1696 expect(fo.key()).toEqual('Titel');
1697 expect(fo.value()).toEqual('Baum');
1698
1699 // Add unspecified on the root group
1700 _orOn(fo);
1701
1702 fo = vc.root().getOperand(0).getOperand(0);
1703
1704 expect(fo.operation()).toEqual('or');
1705 expect(fo.getOperand(0).ldType()).toEqual('doc');
1706 expect(fo.getOperand(1).ldType()).toEqual('non');
1707
1708 // Delete unspecified doc
1709 _delOn(fo.getOperand(1));
1710
1711 // The operand is now non
1712 fo = vc.root().getOperand(0);
1713 expect(fo.getOperand(0).ldType()).toEqual('doc');
1714 expect(fo.getOperand(0).key()).toEqual('Titel');
1715 expect(fo.getOperand(0).value()).toEqual('Baum');
1716 expect(fo.getOperand(1).ldType()).toEqual('doc');
1717 expect(fo.getOperand(2).ldType()).toEqual('docGroup');
1718 });
1719
1720
1721 it('should add on parent group (case "and")', function () {
1722 var vc = complexVCFactory.create();
1723
1724 // Wrap with direct element access
1725 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001726 'pubDate in 2014-12-05 & (title = "Hello World!" | foo = "bar")'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001727 );
1728
1729 expect(vc.root().operands().length).toEqual(2);
1730
1731 // Add unspecified on the root group
1732 _andOn(vc.root().getOperand(1));
1733 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001734 'pubDate in 2014-12-05 & (title = "Hello World!" | foo = "bar")'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001735 );
1736
1737 expect(vc.root().ldType()).toEqual('docGroup');
1738 expect(vc.root().operands().length).toEqual(3);
1739 expect(vc.root().getOperand(0).ldType()).toEqual('doc');
1740 expect(vc.root().getOperand(1).ldType()).toEqual('docGroup');
1741 expect(vc.root().getOperand(1).operation()).toEqual('or');
1742 expect(vc.root().getOperand(2).ldType()).toEqual('non');
1743
1744 // Add another unspecified on the root group
1745 _andOn(vc.root().getOperand(1));
1746
1747 expect(vc.root().operands().length).toEqual(4);
1748 expect(vc.root().getOperand(0).ldType()).toEqual('doc');
1749 expect(vc.root().getOperand(1).ldType()).toEqual('docGroup');
1750 expect(vc.root().getOperand(2).ldType()).toEqual('non');
1751 expect(vc.root().getOperand(3).ldType()).toEqual('non');
1752
1753 // Add another unspecified after the first doc
1754 _andOn(vc.root().getOperand(0));
1755
1756 expect(vc.root().operands().length).toEqual(5);
1757 expect(vc.root().getOperand(0).ldType()).toEqual('doc');
1758 expect(vc.root().getOperand(1).ldType()).toEqual('non');
1759 expect(vc.root().getOperand(2).ldType()).toEqual('docGroup');
1760 expect(vc.root().getOperand(3).ldType()).toEqual('non');
1761 expect(vc.root().getOperand(4).ldType()).toEqual('non');
1762 });
1763
1764 it('should wrap on root', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00001765 var vc = vcClass.create().fromJson(
Akron712733a2018-04-05 18:17:47 +02001766 {
1767 "@type": 'koral:docGroup',
1768 'operation' : 'operation:and',
1769 'operands' : [
1770 {
1771 "@type": 'koral:doc',
1772 "key": 'pubDate',
1773 "match": 'match:eq',
1774 "value": '2014-12-05',
1775 "type": 'type:date'
1776 },
1777 {
1778 "@type" : 'koral:doc',
1779 'key' : 'foo',
1780 'value' : 'bar'
1781 }
1782 ]
1783 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00001784 );
1785
1786 // Wrap on root
1787 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar"');
1788 expect(vc.root().ldType()).toEqual('docGroup');
1789 expect(vc.root().operation()).toEqual('and');
1790 _orOn(vc.root());
1791 expect(vc.root().ldType()).toEqual('docGroup');
1792 expect(vc.root().operation()).toEqual('or');
1793
1794 expect(vc.root().getOperand(0).ldType()).toEqual('docGroup');
1795 expect(vc.root().getOperand(0).operation()).toEqual('and');
1796 });
1797
1798 it('should add on root (case "and")', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00001799 var vc = vcClass.create().fromJson(
Akron712733a2018-04-05 18:17:47 +02001800 {
1801 "@type": 'koral:doc',
1802 "key": 'pubDate',
1803 "match": 'match:eq',
1804 "value": '2014-12-05',
1805 "type": 'type:date'
1806 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00001807 );
1808
1809 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05');
1810 expect(vc.root().ldType()).toEqual('doc');
1811 expect(vc.root().key()).toEqual('pubDate');
1812 expect(vc.root().value()).toEqual('2014-12-05');
1813
1814 // Wrap on root
1815 _andOn(vc.root());
1816 expect(vc.root().ldType()).toEqual('docGroup');
1817 expect(vc.root().operation()).toEqual('and');
1818 });
1819
1820 it('should add on root (case "or")', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00001821 var vc = vcClass.create().fromJson(
Akron712733a2018-04-05 18:17:47 +02001822 {
1823 "@type": 'koral:doc',
1824 "key": 'pubDate',
1825 "match": 'match:eq',
1826 "value": '2014-12-05',
1827 "type": 'type:date'
1828 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00001829 );
1830
1831 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05');
1832 expect(vc.root().key()).toEqual('pubDate');
1833 expect(vc.root().value()).toEqual('2014-12-05');
1834
1835 // Wrap on root
1836 _orOn(vc.root());
1837 expect(vc.root().ldType()).toEqual('docGroup');
1838 expect(vc.root().operation()).toEqual('or');
1839 });
1840
1841 it('should support multiple sub groups per group', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00001842 var vc = vcClass.create().fromJson(
Akron712733a2018-04-05 18:17:47 +02001843 {
1844 "@type": 'koral:docGroup',
1845 'operation' : 'operation:or',
1846 'operands' : [
1847 {
1848 "@type": 'koral:docGroup',
1849 'operation' : 'operation:and',
1850 'operands' : [
1851 {
1852 "@type": 'koral:doc',
1853 "key": 'title',
1854 "value": 't1',
1855 },
1856 {
1857 "@type" : 'koral:doc',
1858 'key' : 'title',
1859 'value' : 't2'
1860 }
1861 ]
1862 },
1863 {
1864 "@type": 'koral:docGroup',
1865 'operation' : 'operation:and',
1866 'operands' : [
1867 {
1868 "@type": 'koral:doc',
1869 "key": 'title',
1870 "value": 't3',
1871 },
1872 {
1873 "@type" : 'koral:doc',
1874 'key' : 'title',
1875 'value' : 't4'
1876 }
1877 ]
1878 }
1879 ]
1880 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00001881 );
1882 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001883 '(title = "t1" & title = "t2") | ' +
1884 '(title = "t3" & title = "t4")'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001885 );
1886 expect(vc.root().operation()).toEqual('or');
1887 expect(vc.root().getOperand(0).toQuery()).toEqual('title = "t1" & title = "t2"');
1888 expect(vc.root().getOperand(1).toQuery()).toEqual('title = "t3" & title = "t4"');
1889
1890 _andOn(vc.root());
1891
1892 expect(vc.root().operation()).toEqual('and');
1893 expect(vc.root().getOperand(0).ldType()).toEqual('docGroup');
1894 expect(vc.root().getOperand(1).ldType()).toEqual('non');
1895 });
1896 });
1897
Akron5c829e92017-05-12 18:10:00 +02001898 // Check class method
1899 describe('KorAP.VC.checkRewrite', function () {
1900
1901 it('should check for simple rewrites', function () {
1902 expect(vcClass.checkRewrite(
1903 {
1904 "@type" : "koral:doc",
1905 "rewrites" : [{
Akron712733a2018-04-05 18:17:47 +02001906 "@type" : "koral:rewrite",
1907 "operation" : "operation:modification",
1908 "src" : "querySerializer",
1909 "scope" : "tree"
Akron5c829e92017-05-12 18:10:00 +02001910 }]
1911 }
1912 )).toBeTruthy();
Nils Diewald7c8ced22015-04-15 19:21:00 +00001913
Akron5c829e92017-05-12 18:10:00 +02001914 var nested = {
1915 "@type" : "koral:docGroup",
1916 "operands" : [
1917 {
1918 "@type" : "koral:doc"
1919 },
1920 {
1921 "@type" : "koral:docGroup",
1922 "operands" : [
1923 {
1924 "@type": "koral:doc"
1925 },
1926 {
1927 "@type": "koral:doc"
1928 }
1929 ]
1930 }
1931 ]
1932 };
1933
1934 expect(vcClass.checkRewrite(nested)).toBe(false);
1935
1936 nested["operands"][1]["operands"][1]["rewrites"] = [{
Akron712733a2018-04-05 18:17:47 +02001937 "@type" : "koral:rewrite",
1938 "operation" : "operation:modification",
1939 "src" : "querySerializer",
1940 "scope" : "tree"
Akron5c829e92017-05-12 18:10:00 +02001941 }];
1942
1943 expect(vcClass.checkRewrite(nested)).toBeTruthy();
1944 });
1945 });
Nils Diewald6283d692015-04-23 20:32:53 +00001946
1947 describe('KorAP.Rewrite', function () {
Nils Diewald7c8ced22015-04-15 19:21:00 +00001948 it('should be initializable', function () {
1949 var rewrite = rewriteClass.create({
Akron712733a2018-04-05 18:17:47 +02001950 "@type" : "koral:rewrite",
1951 "operation" : "operation:modification",
1952 "src" : "querySerializer",
1953 "scope" : "tree"
Nils Diewald86dad5b2015-01-28 15:09:07 +00001954 });
Nils Diewald7c8ced22015-04-15 19:21:00 +00001955 expect(rewrite.toString()).toEqual('Modification of "tree" by "querySerializer"');
1956 });
Nils Diewald86dad5b2015-01-28 15:09:07 +00001957
Nils Diewald7c8ced22015-04-15 19:21:00 +00001958 it('should be deserialized by docs', function () {
1959 var doc = docClass.create(
Akron712733a2018-04-05 18:17:47 +02001960 undefined,
1961 {
1962 "@type":"koral:doc",
1963 "key":"Titel",
1964 "value":"Baum",
1965 "match":"match:eq"
1966 });
Nils Diewald7c8ced22015-04-15 19:21:00 +00001967
1968 expect(doc.element().classList.contains('doc')).toBeTruthy();
1969 expect(doc.element().classList.contains('rewritten')).toBe(false);
1970
1971 doc = docClass.create(
Akron712733a2018-04-05 18:17:47 +02001972 undefined,
1973 {
1974 "@type":"koral:doc",
1975 "key":"Titel",
1976 "value":"Baum",
1977 "match":"match:eq",
1978 "rewrites" : [
1979 {
1980 "@type" : "koral:rewrite",
1981 "operation" : "operation:modification",
1982 "src" : "querySerializer",
1983 "scope" : "tree"
1984 }
1985 ]
1986 });
Nils Diewald7c8ced22015-04-15 19:21:00 +00001987
1988 expect(doc.element().classList.contains('doc')).toBeTruthy();
1989 expect(doc.element().classList.contains('rewritten')).toBeTruthy();
1990 });
Nils Diewald6283d692015-04-23 20:32:53 +00001991
Akron76c3dd62018-05-29 20:58:27 +02001992 it('should be described in a title attribute', function () {
1993
1994 doc = docClass.create(
1995 undefined,
1996 {
1997 "@type":"koral:doc",
1998 "key":"Titel",
1999 "value":"Baum",
2000 "match":"match:eq",
2001 "rewrites" : [
2002 {
2003 "@type" : "koral:rewrite",
2004 "operation" : "operation:modification",
2005 "src" : "querySerializer",
2006 "scope" : "tree"
2007 },
2008 {
2009 "@type" : "koral:rewrite",
2010 "operation" : "operation:injection",
2011 "src" : "me"
2012 }
2013 ]
2014 });
2015
2016 expect(doc.element().classList.contains('doc')).toBeTruthy();
2017 expect(doc.element().classList.contains('rewritten')).toBeTruthy();
2018 expect(doc.element().lastChild.getAttribute("title")).toEqual("querySerializer: tree (modification)\nme (injection)");
2019 });
2020
2021
Nils Diewald6283d692015-04-23 20:32:53 +00002022 xit('should be deserialized by docGroups', function () {
2023 var docGroup = docGroupClass.create(
Akron712733a2018-04-05 18:17:47 +02002024 undefined,
2025 {
2026 "@type" : "koral:docGroup",
2027 "operation" : "operation:or",
2028 "operands" : [
2029 {
2030 "@type" : "doc",
2031 "key" : "pubDate",
2032 "type" : "type:date",
2033 "value" : "2014-12-05"
2034 },
2035 {
2036 "@type" : "doc",
2037 "key" : "pubDate",
2038 "type" : "type:date",
2039 "value" : "2014-12-06"
2040 }
2041 ],
2042 "rewrites" : [
2043 {
2044 "@type" : "koral:rewrite",
2045 "operation" : "operation:modification",
2046 "src" : "querySerializer",
2047 "scope" : "tree"
2048 }
2049 ]
2050 }
Nils Diewald6283d692015-04-23 20:32:53 +00002051 );
2052
2053 expect(doc.element().classList.contains('docgroup')).toBeTruthy();
2054 expect(doc.element().classList.contains('rewritten')).toBe(false);
2055 });
Nils Diewald86dad5b2015-01-28 15:09:07 +00002056 });
Nils Diewaldf0c4f112015-05-05 12:56:59 +00002057
2058 describe('KorAP.stringValue', function () {
2059 it('should be initializable', function () {
2060 var sv = stringValClass.create();
2061 expect(sv.regex()).toBe(false);
2062 expect(sv.value()).toBe('');
Nils Diewaldc4c4b832015-05-05 16:00:08 +00002063
2064 sv = stringValClass.create('Baum');
2065 expect(sv.regex()).toBe(false);
2066 expect(sv.value()).toBe('Baum');
2067
2068 sv = stringValClass.create('Baum', false);
2069 expect(sv.regex()).toBe(false);
2070 expect(sv.value()).toBe('Baum');
2071
2072 sv = stringValClass.create('Baum', true);
2073 expect(sv.regex()).toBe(true);
2074 expect(sv.value()).toBe('Baum');
2075 });
2076
2077 it('should be modifiable', function () {
2078 var sv = stringValClass.create();
2079 expect(sv.regex()).toBe(false);
2080 expect(sv.value()).toBe('');
2081
2082 expect(sv.value('Baum')).toBe('Baum');
2083 expect(sv.value()).toBe('Baum');
2084
2085 expect(sv.regex(true)).toBe(true);
2086 expect(sv.regex()).toBe(true);
2087 });
2088
2089 it('should have a toggleble regex value', function () {
2090 var sv = stringValClass.create();
Nils Diewald7991a3f2015-05-19 14:12:37 +00002091
2092 expect(sv.element().firstChild.value).toBe('');
2093 sv.element().firstChild.value = 'der'
2094 expect(sv.element().firstChild.value).toBe('der');
2095
Nils Diewaldc4c4b832015-05-05 16:00:08 +00002096 expect(sv.regex()).toBe(false);
2097
2098 sv.toggleRegex();
Nils Diewald7991a3f2015-05-19 14:12:37 +00002099 expect(sv.element().firstChild.value).toBe('der');
Nils Diewaldc4c4b832015-05-05 16:00:08 +00002100 expect(sv.regex()).toBe(true);
Nils Diewald7991a3f2015-05-19 14:12:37 +00002101 sv.element().firstChild.value = 'derbe'
Nils Diewaldc4c4b832015-05-05 16:00:08 +00002102
2103 sv.toggleRegex();
2104 expect(sv.regex()).toBe(false);
Nils Diewald7991a3f2015-05-19 14:12:37 +00002105 expect(sv.element().firstChild.value).toBe('derbe');
Nils Diewaldc4c4b832015-05-05 16:00:08 +00002106 });
2107
2108 it('should have an element', function () {
2109 var sv = stringValClass.create('der');
2110 expect(sv.element().nodeName).toBe('DIV');
2111 expect(sv.element().firstChild.nodeName).toBe('INPUT');
2112 expect(sv.element().firstChild.value).toBe('der');
2113 });
2114
2115 it('should have a classed element', function () {
2116 var sv = stringValClass.create();
Nils Diewaldc4c4b832015-05-05 16:00:08 +00002117 expect(sv.element().classList.contains('regex')).toBe(false);
2118 expect(sv.regex()).toBe(false);
2119 sv.toggleRegex();
2120 expect(sv.element().classList.contains('regex')).toBe(true);
2121 });
2122
2123 it('should be storable', function () {
2124 var sv = stringValClass.create();
2125 var count = 1;
2126 sv.store = function (value, regex) {
Akron712733a2018-04-05 18:17:47 +02002127 expect(regex).toBe(true);
2128 expect(value).toBe('tree');
Nils Diewaldc4c4b832015-05-05 16:00:08 +00002129 };
2130 sv.regex(true);
2131 sv.value('tree');
2132 sv.element().lastChild.click();
Nils Diewaldf0c4f112015-05-05 12:56:59 +00002133 });
Akron712733a2018-04-05 18:17:47 +02002134
Nils Diewaldf0c4f112015-05-05 12:56:59 +00002135 });
Akrone4961b12017-05-10 21:04:46 +02002136
Akron712733a2018-04-05 18:17:47 +02002137 describe('KorAP.VC.Menu', function () {
Akrone65a88a2018-04-05 19:14:20 +02002138
2139 var vc;
2140
Akron712733a2018-04-05 18:17:47 +02002141 it('should be initializable', function () {
2142
Akrone65a88a2018-04-05 19:14:20 +02002143 vc = vcClass.create([
Akron712733a2018-04-05 18:17:47 +02002144 ['a', 'text'],
2145 ['b', 'string'],
2146 ['c', 'date']
2147 ]).fromJson();
2148 expect(vc.element().firstChild.classList.contains('unspecified')).toBeTruthy();
2149 expect(vc.element().firstChild.firstChild.tagName).toEqual('SPAN');
2150
2151 // Click on unspecified
2152 vc.element().firstChild.firstChild.click();
2153 expect(vc.element().firstChild.firstChild.tagName).toEqual('UL');
2154
2155 var list = vc.element().firstChild.firstChild;
2156 expect(list.getElementsByTagName("LI")[0].innerText).toEqual('a');
2157 expect(list.getElementsByTagName("LI")[1].innerText).toEqual('b');
2158 expect(list.getElementsByTagName("LI")[2].innerText).toEqual('c');
2159
2160 vc = vcClass.create([
2161 ['d', 'text'],
2162 ['e', 'string'],
2163 ['f', 'date']
2164 ]).fromJson();
2165 expect(vc.element().firstChild.classList.contains('unspecified')).toBeTruthy();
2166 expect(vc.element().firstChild.firstChild.tagName).toEqual('SPAN');
2167
2168 // Click on unspecified
2169 vc.element().firstChild.firstChild.click();
2170 expect(vc.element().firstChild.firstChild.tagName).toEqual('UL');
2171
2172 list = vc.element().firstChild.firstChild;
2173 expect(list.getElementsByTagName("LI")[0].innerText).toEqual('d');
2174 expect(list.getElementsByTagName("LI")[1].innerText).toEqual('e');
2175 expect(list.getElementsByTagName("LI")[2].innerText).toEqual('f');
Akron31d89942018-04-06 16:44:51 +02002176 // blur
2177 document.body.click();
Akron712733a2018-04-05 18:17:47 +02002178 });
Akrone65a88a2018-04-05 19:14:20 +02002179
2180 // Reinitialize to make tests stable
2181 vc = vcClass.create([
2182 ['d', 'text'],
2183 ['e', 'string'],
2184 ['f', 'date']
2185 ]).fromJson();
2186
2187 it('should be clickable on key', function () {
Akron31d89942018-04-06 16:44:51 +02002188 // Click on unspecified
2189 vc.element().firstChild.firstChild.click();
Akrone65a88a2018-04-05 19:14:20 +02002190 // Click on "d"
2191 vc.element().firstChild.firstChild.getElementsByTagName("LI")[0].click();
2192 expect(vc.element().firstChild.firstChild.tagName).toEqual('SPAN');
2193 expect(vc.element().firstChild.firstChild.innerText).toEqual('d');
2194 expect(vc.element().firstChild.children[1].innerText).toEqual('eq');
2195 expect(vc.element().firstChild.children[1].getAttribute('data-type')).toEqual('text');
Akron31d89942018-04-06 16:44:51 +02002196 // blur
2197 document.body.click();
Akrone65a88a2018-04-05 19:14:20 +02002198 });
2199
Akron31d89942018-04-06 16:44:51 +02002200 it('should be clickable on operation for text', function () {
2201 // Click on "d" (or unspecified)
2202 vc.element().firstChild.firstChild.click();
2203
2204 // Choose "d"
2205 vc.element().firstChild.firstChild.getElementsByTagName("LI")[0].click();
2206
2207 // Click on matchop
Akrone65a88a2018-04-05 19:14:20 +02002208 vc.element().firstChild.children[1].click();
Akron31d89942018-04-06 16:44:51 +02002209
Akrone65a88a2018-04-05 19:14:20 +02002210 expect(vc.element().firstChild.children[1].tagName).toEqual('UL');
Akron31d89942018-04-06 16:44:51 +02002211
Akrone65a88a2018-04-05 19:14:20 +02002212 var ul = vc.element().firstChild.children[1];
2213 expect(ul.getElementsByTagName('li')[0].innerText).toEqual("eq");
2214 expect(ul.getElementsByTagName('li')[1].innerText).toEqual("ne");
2215 expect(ul.getElementsByTagName('li')[2].innerText).toEqual("contains");
2216 expect(ul.getElementsByTagName('li')[3].innerText).toEqual("containsnot");
2217 expect(ul.getElementsByTagName('li')[4]).toBeUndefined();
Akron31d89942018-04-06 16:44:51 +02002218
2219 // Choose "contains"
2220 ul.getElementsByTagName('li')[2].click();
2221 expect(vc.element().firstChild.children[1].tagName).toEqual("SPAN");
2222 expect(vc.element().firstChild.children[1].innerText).toEqual("contains");
2223 // blur
2224 document.body.click();
Akrone65a88a2018-04-05 19:14:20 +02002225 })
Akron31d89942018-04-06 16:44:51 +02002226
2227 it('should be clickable on operation for string', function () {
2228 // Click on "d" (or unspecified)
2229 vc.element().firstChild.firstChild.click();
2230
2231 // Choose "e"
2232 vc.element().firstChild.firstChild.getElementsByTagName("LI")[1].click();
2233
2234 // As a consequence the matchoperator may no longer
2235 // be valid and needs to be re-evaluated
2236 var fc = vc.element().firstChild;
2237 expect(fc.firstChild.tagName).toEqual('SPAN');
2238 expect(fc.firstChild.innerText).toEqual('e');
2239 expect(fc.children[1].innerText).toEqual('eq');
2240 expect(fc.children[1].getAttribute('data-type')).toEqual('string');
2241
2242 vc.element().firstChild.children[1].click();
2243
2244 expect(vc.element().firstChild.children[1].tagName).toEqual('UL');
2245
2246 var ul = vc.element().firstChild.children[1];
2247 expect(ul.getElementsByTagName('li')[0].innerText).toEqual("eq");
2248 expect(ul.getElementsByTagName('li')[1].innerText).toEqual("ne");
2249 expect(ul.getElementsByTagName('li')[2]).toBeUndefined();
2250
2251 // Choose "ne"
2252 ul.getElementsByTagName('li')[1].click();
2253 expect(vc.element().firstChild.children[1].tagName).toEqual("SPAN");
2254 expect(vc.element().firstChild.children[1].innerText).toEqual("ne");
Akron8db5e3a2018-05-28 19:25:26 +02002255
2256 // Click on text
2257 expect(vc.element().firstChild.children[2].innerText).toEqual("⋯");
2258 vc.element().firstChild.children[2].click();
2259
2260 // Blur text element
2261 expect(vc.element().firstChild.children[2].firstChild.value).toEqual('');
2262
Akron31d89942018-04-06 16:44:51 +02002263 // blur
2264 document.body.click();
2265 });
2266
2267 it('should be clickable on operation for date', function () {
2268
2269 // Replay matchop check - so it's guaranteed that "ne" is chosen
2270 // Click on "e" (or unspecified)
2271 vc.element().firstChild.firstChild.click();
2272 // Rechoose "e"
2273 vc.element().firstChild.firstChild.getElementsByTagName("LI")[1].click();
2274 // Click on matchop
2275 vc.element().firstChild.children[1].click();
2276 // Choose "ne"
2277 vc.element().firstChild.children[1].getElementsByTagName('li')[1].click();
2278 expect(vc.element().firstChild.children[1].innerText).toEqual("ne");
2279
2280 // Click on "e"
2281 vc.element().firstChild.firstChild.click();
2282 // Choose "f"
2283 vc.element().firstChild.firstChild.getElementsByTagName("LI")[2].click();
2284
2285 // The matchoperator should still be "ne" as this is valid for dates as well (now)
2286 var fc = vc.element().firstChild;
2287 expect(fc.firstChild.tagName).toEqual('SPAN');
2288 expect(fc.firstChild.innerText).toEqual('f');
2289 expect(fc.children[1].innerText).toEqual('ne');
2290 // blur
2291 document.body.click();
2292 });
Akronddc98a72018-04-06 17:33:52 +02002293
2294
2295 // Check json deserialization
2296 it('should be initializable', function () {
2297 vc = vcClass.create([
2298 ['a', 'text'],
2299 ['b', 'string'],
2300 ['c', 'date']
2301 ]).fromJson({
2302 "@type" : "koral:doc",
2303 "key":"a",
2304 "value":"Baum"
2305 });
2306
2307 expect(vc.element().firstChild.children[1].getAttribute('data-type')).toEqual('text');
2308 });
Akron712733a2018-04-05 18:17:47 +02002309 });
2310
2311
Akrone4961b12017-05-10 21:04:46 +02002312 // Check prefix
2313 describe('KorAP.VC.Prefix', function () {
2314
2315 it('should be initializable', function () {
2316 var p = prefixClass.create();
2317 expect(p.element().classList.contains('pref')).toBeTruthy();
2318 expect(p.isSet()).not.toBeTruthy();
2319 });
2320
2321
2322 it('should be clickable', function () {
2323 var vc = vcClass.create([
Akron712733a2018-04-05 18:17:47 +02002324 ['a', null],
2325 ['b', null],
2326 ['c', null]
2327 ]).fromJson();
Akrone4961b12017-05-10 21:04:46 +02002328 expect(vc.element().firstChild.classList.contains('unspecified')).toBeTruthy();
2329
2330 // This should open up the menu
2331 vc.element().firstChild.firstChild.click();
2332 expect(vc.element().firstChild.firstChild.tagName).toEqual('UL');
2333
2334 KorAP._vcKeyMenu._prefix.clear();
2335 KorAP._vcKeyMenu._prefix.add('x');
2336
2337 var prefElement = vc.element().querySelector('span.pref');
2338 expect(prefElement.innerText).toEqual('x');
2339
2340 // This should add key 'x' to VC
2341 prefElement.click();
2342
2343 expect(vc.element().firstChild.classList.contains('doc')).toBeTruthy();
2344 expect(vc.element().firstChild.firstChild.className).toEqual('key');
2345 expect(vc.element().firstChild.firstChild.innerText).toEqual('x');
2346 });
2347 });
Nils Diewald2fe12e12015-03-06 16:47:06 +00002348});