blob: 482d3848912cb5695e06e92d6ca5df9d965916a2 [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) {
33 KorAP._and.bind(obj.element().lastChild.firstChild).apply();
34 };
Nils Diewald52f7eb12015-01-12 17:30:04 +000035
Nils Diewald7c8ced22015-04-15 19:21:00 +000036 function _orOn (obj) {
37 KorAP._or.bind(obj.element().lastChild.firstChild).apply();
38 };
Nils Diewald52f7eb12015-01-12 17:30:04 +000039
Nils Diewald7c8ced22015-04-15 19:21:00 +000040 function _delOn (obj) {
41 KorAP._delete.bind(obj.element().lastChild.firstChild).apply();
42 };
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
569 it('should be removable, when no root', function () {
570 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
585 expect(docGroup.element().getAttribute('class')).toEqual('docGroup');
586 expect(docGroup.element().children[0].getAttribute('class')).toEqual('doc');
587
588 var unspec = docGroup.element().children[1];
589 expect(unspec.getAttribute('class')).toEqual('doc unspecified');
590
591 // Removable
592 expect(unspec.lastChild.children.length).toEqual(1);
593 expect(unspec.lastChild.children[0].getAttribute('class')).toEqual('delete');
594 });
595
596 it('should be replaceable by a doc', function () {
597 var doc = unspecifiedClass.create();
598 expect(doc.ldType()).toEqual("non");
599 // No parent, therefor not updateable
600 expect(doc.key("baum")).toBeNull();
601
602 var docGroup = docGroupClass.create();
603 docGroup.operation('or');
604 expect(docGroup.operation()).toEqual('or');
605
606 docGroup.append({
Akron712733a2018-04-05 18:17:47 +0200607 "@type": 'koral:doc',
608 "key": 'pubDate',
609 "match": 'match:eq',
610 "value": '2014-12-05',
611 "type": 'type:date'
Nils Diewald7c8ced22015-04-15 19:21:00 +0000612 });
613
614 expect(docGroup.toQuery()).toEqual("pubDate in 2014-12-05");
615 docGroup.append();
616
617 expect(docGroup.getOperand(0).ldType()).toEqual("doc");
618 expect(docGroup.getOperand(1).ldType()).toEqual("non");
619
620 var op = docGroup.getOperand(1).element().lastChild;
Akron0b489ad2018-02-02 16:49:32 +0100621 expect(op.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +0000622 expect(op.children[0].getAttribute('class')).toEqual('delete');
623 expect(op.children.length).toEqual(1);
624
625 // Replace unspecified doc
626 expect(docGroup.getOperand(1).key("name")).not.toBeNull();
627 expect(docGroup.getOperand(1).ldType()).toEqual("doc");
628 expect(docGroup.getOperand(1).key()).toEqual("name");
Akron55a343b2018-04-06 19:57:36 +0200629 expect(docGroup.getOperand(1).value()).toBeUndefined();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000630
631 op = docGroup.getOperand(1).element().lastChild;
Akron0b489ad2018-02-02 16:49:32 +0100632 expect(op.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +0000633 expect(op.children[0].getAttribute('class')).toEqual('and');
634 expect(op.children[1].getAttribute('class')).toEqual('or');
635 expect(op.children[2].getAttribute('class')).toEqual('delete');
636 expect(op.children.length).toEqual(3);
637
638 docGroup.getOperand(1).value("Pachelbel");
639 expect(docGroup.getOperand(1).value()).toEqual("Pachelbel");
640 expect(docGroup.getOperand(1).type()).toEqual("string");
641 expect(docGroup.getOperand(1).matchop()).toEqual("eq");
642
643 // Specified!
644 expect(docGroup.toQuery()).toEqual('pubDate in 2014-12-05 | name = "Pachelbel"');
645 });
646
647 it('should be replaceable on root', function () {
Nils Diewald6283d692015-04-23 20:32:53 +0000648 var vc = vcClass.create();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000649 expect(vc.toQuery()).toEqual("");
650
651 expect(vc.root().ldType()).toEqual("non");
652
653 // No operators on root
654 op = vc.root().element().lastChild;
655 expect(op.lastChild.textContent).toEqual('⋯');
656
657 // Replace
658 expect(vc.root().key("baum")).not.toBeNull();
659 expect(vc.root().ldType()).toEqual("doc");
660
661 op = vc.root().element().lastChild;
Akron0b489ad2018-02-02 16:49:32 +0100662 expect(op.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +0000663 expect(op.children[0].getAttribute('class')).toEqual('and');
664 expect(op.children[1].getAttribute('class')).toEqual('or');
665 expect(op.children[2].getAttribute('class')).toEqual('delete');
666 expect(op.children.length).toEqual(3);
667 });
Akron55a343b2018-04-06 19:57:36 +0200668
669 it('should be clickable', function () {
670 var vc = vcClass.create([
671 ["pubDate", "date"]
672 ]);
673 expect(vc.toQuery()).toEqual("");
674 expect(vc.element().firstChild.textContent).toEqual("⋯");
675 vc.element().firstChild.firstChild.click();
676
677 // Click on pubDate
678 vc.element().firstChild.getElementsByTagName("LI")[0].click();
679
680 expect(vc.element().firstChild.firstChild.textContent).toEqual("pubDate");
681 expect(vc.element().firstChild.children[1].getAttribute("data-type")).toEqual("date");
682 });
Nils Diewald7c8ced22015-04-15 19:21:00 +0000683 });
684
685 describe('KorAP.Doc element', function () {
686 it('should be initializable', function () {
687 var docElement = docClass.create(undefined, {
Akron712733a2018-04-05 18:17:47 +0200688 "@type" : "koral:doc",
689 "key":"Titel",
690 "value":"Baum",
691 "match":"match:eq"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000692 });
693 expect(docElement.key()).toEqual('Titel');
694 expect(docElement.matchop()).toEqual('eq');
695 expect(docElement.value()).toEqual('Baum');
696
697 var docE = docElement.element();
698 expect(docE.children[0].firstChild.data).toEqual('Titel');
699 expect(docE.children[1].firstChild.data).toEqual('eq');
700 expect(docE.children[1].getAttribute('data-type')).toEqual('string');
701 expect(docE.children[2].firstChild.data).toEqual('Baum');
702 expect(docE.children[2].getAttribute('data-type')).toEqual('string');
703
704 expect(docElement.toJson()).toEqual(jasmine.objectContaining({
Akron712733a2018-04-05 18:17:47 +0200705 "@type" : "koral:doc",
706 "key":"Titel",
707 "value":"Baum",
708 "match":"match:eq"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000709 }));
710 });
711 });
712
713 describe('KorAP.DocGroup element', function () {
714 it('should be initializable', function () {
715
716 var docGroup = docGroupClass.create(undefined, {
Akron712733a2018-04-05 18:17:47 +0200717 "@type" : "koral:docGroup",
718 "operation" : "operation:and",
719 "operands" : [
720 {
721 "@type": 'koral:doc',
722 "key" : 'author',
723 "match": 'match:eq',
724 "value": 'Max Birkendale',
725 "type": 'type:string'
726 },
727 {
728 "@type": 'koral:doc',
729 "key": 'pubDate',
730 "match": 'match:eq',
731 "value": '2014-12-05',
732 "type": 'type:date'
733 }
734 ]
Nils Diewald7c8ced22015-04-15 19:21:00 +0000735 });
736
737 expect(docGroup.operation()).toEqual('and');
738 var e = docGroup.element();
739 expect(e.getAttribute('class')).toEqual('docGroup');
740 expect(e.getAttribute('data-operation')).toEqual('and');
741
742 var first = e.children[0];
743 expect(first.getAttribute('class')).toEqual('doc');
744 expect(first.children[0].getAttribute('class')).toEqual('key');
745 expect(first.children[1].getAttribute('class')).toEqual('match');
746 expect(first.children[2].getAttribute('class')).toEqual('value');
747 expect(first.children[2].getAttribute('data-type')).toEqual('string');
748 expect(first.children[0].firstChild.data).toEqual('author');
749 expect(first.children[1].firstChild.data).toEqual('eq');
750 expect(first.children[2].firstChild.data).toEqual('Max Birkendale');
751
752 var second = e.children[1];
753 expect(second.getAttribute('class')).toEqual('doc');
754 expect(second.children[0].getAttribute('class')).toEqual('key');
755 expect(second.children[1].getAttribute('class')).toEqual('match');
756 expect(second.children[2].getAttribute('class')).toEqual('value');
757 expect(second.children[2].getAttribute('data-type')).toEqual('date');
758 expect(second.children[0].firstChild.data).toEqual('pubDate');
759 expect(second.children[1].firstChild.data).toEqual('eq');
760 expect(second.children[2].firstChild.data).toEqual('2014-12-05');
761 });
762
763 it('should be deserializable with nested groups', function () {
764 var docGroup = docGroupClass.create(undefined, {
Akron712733a2018-04-05 18:17:47 +0200765 "@type" : "koral:docGroup",
766 "operation" : "operation:or",
767 "operands" : [
768 {
769 "@type": 'koral:doc',
770 "key" : 'author',
771 "match": 'match:eq',
772 "value": 'Max Birkendale',
773 "type": 'type:string'
774 },
775 {
776 "@type" : "koral:docGroup",
777 "operation" : "operation:and",
778 "operands" : [
779 {
780 "@type": 'koral:doc',
781 "key": 'pubDate',
782 "match": 'match:geq',
783 "value": '2014-05-12',
784 "type": 'type:date'
785 },
786 {
787 "@type": 'koral:doc',
788 "key": 'pubDate',
789 "match": 'match:leq',
790 "value": '2014-12-05',
791 "type": 'type:date'
792 }
793 ]
794 }
795 ]
Nils Diewald7c8ced22015-04-15 19:21:00 +0000796 });
797
798 expect(docGroup.operation()).toEqual('or');
799 var e = docGroup.element();
800 expect(e.getAttribute('class')).toEqual('docGroup');
801 expect(e.getAttribute('data-operation')).toEqual('or');
802
803 expect(e.children[0].getAttribute('class')).toEqual('doc');
804 var docop = e.children[0].lastChild;
Akron0b489ad2018-02-02 16:49:32 +0100805 expect(docop.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +0000806 expect(docop.children[0].getAttribute('class')).toEqual('and');
807 expect(docop.children[1].getAttribute('class')).toEqual('or');
808 expect(docop.children[2].getAttribute('class')).toEqual('delete');
809
810 expect(e.children[1].getAttribute('class')).toEqual('docGroup');
811 expect(e.children[1].getAttribute('data-operation')).toEqual('and');
812
813 // This and-operation can be "or"ed or "delete"d
814 var secop = e.children[1].children[2];
Akron0b489ad2018-02-02 16:49:32 +0100815 expect(secop.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +0000816 expect(secop.children[0].getAttribute('class')).toEqual('or');
817 expect(secop.children[1].getAttribute('class')).toEqual('delete');
818
819 // This or-operation can be "and"ed or "delete"d
Akron0b489ad2018-02-02 16:49:32 +0100820 expect(e.children[2].getAttribute('class')).toEqual('operators button-group');
821 expect(e.lastChild.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +0000822 expect(e.lastChild.children[0].getAttribute('class')).toEqual('and');
823 expect(e.lastChild.children[1].getAttribute('class')).toEqual('delete');
824 });
825 });
826
Akrone4961b12017-05-10 21:04:46 +0200827 describe('KorAP.VirtualCorpus', function () {
Nils Diewald7c8ced22015-04-15 19:21:00 +0000828 var simpleGroupFactory = buildFactory(docGroupClass, {
829 "@type" : "koral:docGroup",
830 "operation" : "operation:and",
831 "operands" : [
Akron712733a2018-04-05 18:17:47 +0200832 {
833 "@type": 'koral:doc',
834 "key" : 'author',
835 "match": 'match:eq',
836 "value": 'Max Birkendale',
837 "type": 'type:string'
838 },
839 {
840 "@type": 'koral:doc',
841 "key": 'pubDate',
842 "match": 'match:eq',
843 "value": '2014-12-05',
844 "type": 'type:date'
845 }
Nils Diewald7c8ced22015-04-15 19:21:00 +0000846 ]
847 });
848
849 var nestedGroupFactory = buildFactory(vcClass, {
850 "@type" : "koral:docGroup",
851 "operation" : "operation:or",
852 "operands" : [
Akron712733a2018-04-05 18:17:47 +0200853 {
854 "@type": 'koral:doc',
855 "key" : 'author',
856 "match": 'match:eq',
857 "value": 'Max Birkendale',
858 "type": 'type:string'
859 },
860 {
861 "@type" : "koral:docGroup",
862 "operation" : "operation:and",
863 "operands" : [
864 {
865 "@type": 'koral:doc',
866 "key": 'pubDate',
867 "match": 'match:geq',
868 "value": '2014-05-12',
869 "type": 'type:date'
870 },
871 {
872 "@type": 'koral:doc',
873 "key": 'pubDate',
874 "match": 'match:leq',
875 "value": '2014-12-05',
876 "type": 'type:date'
877 }
878 ]
879 }
Nils Diewald7c8ced22015-04-15 19:21:00 +0000880 ]
881 });
882
883 var flatGroupFactory = buildFactory(vcClass, {
884 "@type" : "koral:docGroup",
885 "operation" : "operation:and",
886 "operands" : [
Akron712733a2018-04-05 18:17:47 +0200887 {
888 "@type": 'koral:doc',
889 "key": 'pubDate',
890 "match": 'match:geq',
891 "value": '2014-05-12',
892 "type": 'type:date'
893 },
894 {
895 "@type": 'koral:doc',
896 "key": 'pubDate',
897 "match": 'match:leq',
898 "value": '2014-12-05',
899 "type": 'type:date'
900 },
901 {
902 "@type": 'koral:doc',
903 "key": 'foo',
904 "match": 'match:eq',
905 "value": 'bar',
906 "type": 'type:string'
907 }
Nils Diewald7c8ced22015-04-15 19:21:00 +0000908 ]
909 });
910
911 it('should be initializable', function () {
Nils Diewald6283d692015-04-23 20:32:53 +0000912 var vc = vcClass.create();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000913 expect(vc.element().getAttribute('class')).toEqual('vc');
914 expect(vc.root().element().getAttribute('class')).toEqual('doc unspecified');
915
916 // Not removable
917 expect(vc.root().element().lastChild.children.length).toEqual(0);
918 });
919
920 it('should be based on a doc', function () {
Nils Diewald6283d692015-04-23 20:32:53 +0000921 var vc = vcClass.create().fromJson({
Akron712733a2018-04-05 18:17:47 +0200922 "@type" : "koral:doc",
923 "key":"Titel",
924 "value":"Baum",
925 "match":"match:eq"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000926 });
927
928 expect(vc.element().getAttribute('class')).toEqual('vc');
929 expect(vc.root().element().getAttribute('class')).toEqual('doc');
930 expect(vc.root().key()).toEqual('Titel');
931 expect(vc.root().value()).toEqual('Baum');
932 expect(vc.root().matchop()).toEqual('eq');
933
934 var docE = vc.root().element();
935 expect(docE.children[0].firstChild.data).toEqual('Titel');
936 expect(docE.children[1].firstChild.data).toEqual('eq');
937 expect(docE.children[1].getAttribute('data-type')).toEqual('string');
938 expect(docE.children[2].firstChild.data).toEqual('Baum');
939 expect(docE.children[2].getAttribute('data-type')).toEqual('string');
940 });
941
942 it('should be based on a docGroup', function () {
Nils Diewald6283d692015-04-23 20:32:53 +0000943 var vc = vcClass.create().fromJson(simpleGroupFactory.create().toJson());
Nils Diewald7c8ced22015-04-15 19:21:00 +0000944
945 expect(vc.element().getAttribute('class')).toEqual('vc');
946 expect(vc.root().element().getAttribute('class')).toEqual('docGroup');
947 expect(vc.root().operation()).toEqual('and');
948
949 var docGroup = vc.root();
950
951 var first = docGroup.getOperand(0);
952 expect(first.key()).toEqual('author');
953 expect(first.value()).toEqual('Max Birkendale');
954 expect(first.matchop()).toEqual('eq');
955
956 var second = docGroup.getOperand(1);
957 expect(second.key()).toEqual('pubDate');
958 expect(second.value()).toEqual('2014-12-05');
959 expect(second.matchop()).toEqual('eq');
960 });
961
962
963 it('should be based on a nested docGroup', function () {
964 var vc = nestedGroupFactory.create();
965
966 expect(vc.element().getAttribute('class')).toEqual('vc');
967 expect(vc.element().firstChild.getAttribute('class')).toEqual('docGroup');
968 expect(vc.element().firstChild.children[0].getAttribute('class')).toEqual('doc');
969 var dg = vc.element().firstChild.children[1];
970 expect(dg.getAttribute('class')).toEqual('docGroup');
971 expect(dg.children[0].getAttribute('class')).toEqual('doc');
972 expect(dg.children[1].getAttribute('class')).toEqual('doc');
Akron0b489ad2018-02-02 16:49:32 +0100973 expect(dg.children[2].getAttribute('class')).toEqual('operators button-group');
974 expect(vc.element().firstChild.children[2].getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +0000975 });
976
977 it('should be modifiable by deletion in flat docGroups', function () {
978 var vc = flatGroupFactory.create();
979 var docGroup = vc.root();
980
981 expect(docGroup.element().getAttribute('class')).toEqual('docGroup');
982
983 var doc = docGroup.getOperand(1);
984 expect(doc.key()).toEqual("pubDate");
985 expect(doc.value()).toEqual("2014-12-05");
986
987 // Remove operand 1
988 expect(docGroup.delOperand(doc).update()).not.toBeUndefined();
989 expect(doc._element).toEqual(undefined);
990
991 doc = docGroup.getOperand(1);
992 expect(doc.key()).toEqual("foo");
993
994 // Remove operand 1
995 expect(docGroup.delOperand(doc).update()).not.toBeUndefined();
996 expect(doc._element).toEqual(undefined);
997
998 // Only one operand left ...
999 expect(docGroup.getOperand(1)).toBeUndefined();
1000 // ... but there shouldn't be a group anymore at all!
1001 expect(docGroup.getOperand(0)).toBeUndefined();
1002
1003 var obj = vc.root();
1004 expect(obj.ldType()).toEqual("doc");
1005 expect(obj.key()).toEqual("pubDate");
1006 expect(obj.value()).toEqual("2014-05-12");
1007
1008 expect(obj.element().getAttribute('class')).toEqual('doc');
1009 });
1010
1011
1012 it('should be modifiable by deletion in nested docGroups (root case)', function () {
1013 var vc = nestedGroupFactory.create();
1014
1015 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001016 'author = "Max Birkendale" | (pubDate since 2014-05-12 & pubDate until 2014-12-05)'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001017 );
1018
1019 var docGroup = vc.root();
1020 expect(docGroup.ldType()).toEqual("docGroup");
1021 expect(docGroup.operation()).toEqual("or");
1022
1023 var doc = docGroup.getOperand(0);
1024 expect(doc.key()).toEqual("author");
1025 expect(doc.value()).toEqual("Max Birkendale");
1026
1027 docGroup = docGroup.getOperand(1);
1028 expect(docGroup.operation()).toEqual("and");
1029
1030 doc = docGroup.getOperand(0);
1031 expect(doc.key()).toEqual("pubDate");
1032 expect(doc.matchop()).toEqual("geq");
1033 expect(doc.value()).toEqual("2014-05-12");
1034 expect(doc.type()).toEqual("date");
1035
1036 doc = docGroup.getOperand(1);
1037 expect(doc.key()).toEqual("pubDate");
1038 expect(doc.matchop()).toEqual("leq");
1039 expect(doc.value()).toEqual("2014-12-05");
1040 expect(doc.type()).toEqual("date");
1041
1042 // Remove first operand so everything becomes root
1043 expect(
Akron712733a2018-04-05 18:17:47 +02001044 vc.root().delOperand(
1045 vc.root().getOperand(0)
1046 ).update().ldType()
Nils Diewald7c8ced22015-04-15 19:21:00 +00001047 ).toEqual("docGroup");
1048
1049 expect(vc.root().ldType()).toEqual("docGroup");
1050 expect(vc.root().operation()).toEqual("and");
1051 expect(vc.root().getOperand(0).ldType()).toEqual("doc");
1052
1053 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001054 'pubDate since 2014-05-12 & pubDate until 2014-12-05'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001055 );
1056 });
1057
1058 it('should be modifiable by deletion in nested docGroups (resolve group case)', function () {
1059 var vc = nestedGroupFactory.create();
1060
1061 // Get nested group
1062 var firstGroup = vc.root().getOperand(1);
1063 firstGroup.append(simpleGroupFactory.create({ "operation" : "operation:or" }));
1064
1065 // Structur is now:
1066 // or(doc, and(doc, doc, or(doc, doc)))
1067
1068 // Get nested or in and
1069 var orGroup = vc.root().getOperand(1).getOperand(2);
1070 expect(orGroup.ldType()).toEqual("docGroup");
1071 expect(orGroup.operation()).toEqual("or");
1072
1073 // Remove
1074 // Structur is now:
1075 // or(doc, and(doc, doc, doc)))
1076 expect(orGroup.delOperand(orGroup.getOperand(0)).update().operation()).toEqual("and");
1077 expect(vc.root().getOperand(1).operands().length).toEqual(3);
1078 });
1079
1080 it('should be modifiable by deletion in nested docGroups (identical group case)', function () {
1081 var vc = nestedGroupFactory.create();
1082
1083 // Get nested group
1084 var firstGroup = vc.root().getOperand(1);
1085 firstGroup.append(simpleGroupFactory.create({
Akron712733a2018-04-05 18:17:47 +02001086 "operation" : "operation:or"
Nils Diewald7c8ced22015-04-15 19:21:00 +00001087 }));
1088 var oldAuthor = firstGroup.getOperand(2).getOperand(0);
1089 oldAuthor.key("title");
1090 oldAuthor.value("Der Birnbaum");
1091
1092 // Structur is now:
1093 // or(doc, and(doc, doc, or(doc, doc)))
1094 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001095 'author = "Max Birkendale" | ' +
1096 '(pubDate since 2014-05-12 & ' +
1097 'pubDate until 2014-12-05 & ' +
1098 '(title = "Der Birnbaum" | ' +
1099 'pubDate in 2014-12-05))'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001100 );
1101
1102 var andGroup = vc.root().getOperand(1);
1103
1104 // Get leading docs in and
1105 var doc1 = andGroup.getOperand(0);
1106 expect(doc1.ldType()).toEqual("doc");
1107 expect(doc1.value()).toEqual("2014-05-12");
1108 var doc2 = andGroup.getOperand(1);
1109 expect(doc2.ldType()).toEqual("doc");
1110 expect(doc2.value()).toEqual("2014-12-05");
1111
1112 // Remove 2
1113 expect(
Akron712733a2018-04-05 18:17:47 +02001114 andGroup.delOperand(doc2).update().operation()
Nils Diewald7c8ced22015-04-15 19:21:00 +00001115 ).toEqual("and");
1116 // Structur is now:
1117 // or(doc, and(doc, or(doc, doc)))
1118
1119 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001120 'author = "Max Birkendale"' +
1121 ' | (pubDate since 2014-05-12 & ' +
1122 '(title = "Der Birnbaum" | pubDate in 2014-12-05))'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001123 );
1124
1125
1126 // Remove 1
1127 expect(andGroup.delOperand(doc1).update().operation()).toEqual("or");
1128 // Structur is now:
1129 // or(doc, doc, doc)
1130
1131 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001132 'author = "Max Birkendale" | title = "Der Birnbaum" | pubDate in 2014-12-05'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001133 );
1134 });
1135
1136 it('should be reducible to unspecification', function () {
1137 var vc = demoFactory.create();
1138
1139 expect(vc.toQuery()).toEqual(vc.root().toQuery());
1140 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001141 '(Titel = "Baum" & Veröffentlichungsort = "hihi" & ' +
1142 '(Titel = "Baum" | Veröffentlichungsort = "hihi")) ' +
1143 '| Untertitel ~ "huhu"');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001144 expect(vc.root().element().lastChild.children[0].firstChild.nodeValue).toEqual('and');
1145 expect(vc.root().element().lastChild.children[1].firstChild.nodeValue).toEqual('×');
1146 expect(vc.root().delOperand(vc.root().getOperand(0)).update()).not.toBeUndefined();
Akron712733a2018-04-05 18:17:47 +02001147 expect(vc.toQuery()).toEqual('Untertitel ~ "huhu"');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001148
1149 var lc = vc.root().element().lastChild;
1150 expect(lc.children[0].firstChild.nodeValue).toEqual('and');
1151 expect(lc.children[1].firstChild.nodeValue).toEqual('or');
1152 expect(lc.children[2].firstChild.nodeValue).toEqual('×');
1153
1154 // Clean everything
1155 vc.clean();
1156 expect(vc.toQuery()).toEqual('');
1157 });
1158
1159 it('should flatten on import', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00001160 var vc = vcClass.create().fromJson({
Akron712733a2018-04-05 18:17:47 +02001161 "@type":"koral:docGroup",
1162 "operation":"operation:or",
1163 "operands":[
1164 {
1165 "@type":"koral:docGroup",
1166 "operation":"operation:or",
1167 "operands":[
Nils Diewald7c8ced22015-04-15 19:21:00 +00001168 {
Akron712733a2018-04-05 18:17:47 +02001169 "@type":"koral:doc",
1170 "key":"Titel",
1171 "value":"Baum",
1172 "match":"match:eq"
Nils Diewald7c8ced22015-04-15 19:21:00 +00001173 },
1174 {
Akron712733a2018-04-05 18:17:47 +02001175 "@type":"koral:doc",
1176 "key":"Veröffentlichungsort",
1177 "value":"hihi",
1178 "match":"match:eq"
Nils Diewald7c8ced22015-04-15 19:21:00 +00001179 },
1180 {
Akron712733a2018-04-05 18:17:47 +02001181 "@type":"koral:docGroup",
1182 "operation":"operation:or",
1183 "operands":[
1184 {
1185 "@type":"koral:doc",
1186 "key":"Titel",
1187 "value":"Baum",
1188 "match":"match:eq"
1189 },
1190 {
1191 "@type":"koral:doc",
1192 "key":"Veröffentlichungsort",
1193 "value":"hihi",
1194 "match":"match:eq"
1195 }
1196 ]
Nils Diewald7c8ced22015-04-15 19:21:00 +00001197 }
Akron712733a2018-04-05 18:17:47 +02001198 ]
1199 },
1200 {
1201 "@type":"koral:doc",
1202 "key":"Untertitel",
1203 "value":"huhu",
1204 "match":"match:contains"
1205 }
1206 ]
Nils Diewald7c8ced22015-04-15 19:21:00 +00001207 });
Nils Diewaldfda29d92015-01-22 17:28:01 +00001208
Nils Diewald7c8ced22015-04-15 19:21:00 +00001209 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001210 'Titel = "Baum" | Veröffentlichungsort = "hihi" | Untertitel ~ "huhu"'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001211 );
Nils Diewald86dad5b2015-01-28 15:09:07 +00001212 });
Nils Diewald86dad5b2015-01-28 15:09:07 +00001213 });
1214
Nils Diewald7c8ced22015-04-15 19:21:00 +00001215 describe('KorAP.Operators', function () {
1216 it('should be initializable', function () {
1217 var op = operatorsClass.create(true, false, false);
1218 expect(op.and()).toBeTruthy();
1219 expect(op.or()).not.toBeTruthy();
1220 expect(op.del()).not.toBeTruthy();
1221
1222 op.and(false);
1223 expect(op.and()).not.toBeTruthy();
1224 expect(op.or()).not.toBeTruthy();
1225 expect(op.del()).not.toBeTruthy();
1226
1227 op.or(true);
1228 op.del(true);
1229 expect(op.and()).not.toBeTruthy();
1230 expect(op.or()).toBeTruthy();
1231 expect(op.del()).toBeTruthy();
1232
1233 var e = op.element();
Akron0b489ad2018-02-02 16:49:32 +01001234 expect(e.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001235 expect(e.children[0].getAttribute('class')).toEqual('or');
1236 expect(e.children[0].firstChild.data).toEqual('or');
1237 expect(e.children[1].getAttribute('class')).toEqual('delete');
1238 expect(e.children[1].firstChild.data).toEqual('×');
1239
1240 op.and(true);
1241 op.del(false);
1242 op.update();
1243
1244 e = op.element();
Akron0b489ad2018-02-02 16:49:32 +01001245 expect(e.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001246 expect(e.children[0].getAttribute('class')).toEqual('and');
1247 expect(e.children[0].firstChild.data).toEqual('and');
1248 expect(e.children[1].getAttribute('class')).toEqual('or');
1249 expect(e.children[1].firstChild.data).toEqual('or');
1250 });
1251 });
1252
1253 describe('KorAP._delete (event)', function () {
1254 var complexVCFactory = buildFactory(vcClass,{
1255 "@type": 'koral:docGroup',
1256 'operation' : 'operation:and',
1257 'operands' : [
Akron712733a2018-04-05 18:17:47 +02001258 {
1259 "@type": 'koral:doc',
1260 "key": 'pubDate',
1261 "match": 'match:eq',
1262 "value": '2014-12-05',
1263 "type": 'type:date'
1264 },
1265 {
1266 "@type" : 'koral:docGroup',
1267 'operation' : 'operation:or',
1268 'operands' : [
1269 {
1270 '@type' : 'koral:doc',
1271 'key' : 'title',
1272 'value' : 'Hello World!'
1273 },
1274 {
1275 '@type' : 'koral:doc',
1276 'key' : 'foo',
1277 'value' : 'bar'
1278 }
1279 ]
1280 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00001281 ]
1282 });
1283
1284 it('should clean on root docs', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00001285 var vc = vcClass.create().fromJson({
Akron712733a2018-04-05 18:17:47 +02001286 "@type": 'koral:doc',
1287 "key": 'pubDate',
1288 "match": 'match:eq',
1289 "value": '2014-12-05',
1290 "type": 'type:date'
Nils Diewald86dad5b2015-01-28 15:09:07 +00001291 });
Nils Diewald7c8ced22015-04-15 19:21:00 +00001292 expect(vc.root().toQuery()).toEqual('pubDate in 2014-12-05');
Akron0b489ad2018-02-02 16:49:32 +01001293 expect(vc.root().element().lastChild.getAttribute('class')).toEqual('operators button-group');
Nils Diewald86dad5b2015-01-28 15:09:07 +00001294
Nils Diewald7c8ced22015-04-15 19:21:00 +00001295 // Clean with delete from root
1296 expect(vc.root().element().lastChild.lastChild.getAttribute('class')).toEqual('delete');
1297 _delOn(vc.root());
1298 expect(vc.root().toQuery()).toEqual('');
1299 expect(vc.root().element().lastChild.lastChild.data).toEqual('⋯');
1300 });
Nils Diewald86dad5b2015-01-28 15:09:07 +00001301
Nils Diewald7c8ced22015-04-15 19:21:00 +00001302 it('should remove on nested docs', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00001303 var vc = vcClass.create().fromJson(
Akron712733a2018-04-05 18:17:47 +02001304 {
1305 "@type": 'koral:docGroup',
1306 'operation' : 'operation:and',
1307 'operands' : [
1308 {
1309 "@type": 'koral:doc',
1310 "key": 'pubDate',
1311 "match": 'match:eq',
1312 "value": '2014-12-05',
1313 "type": 'type:date'
1314 },
1315 {
1316 "@type" : 'koral:doc',
1317 'key' : 'foo',
1318 'value' : 'bar'
1319 }
1320 ]
1321 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00001322 );
1323
1324 // Delete with direct element access
1325 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar"');
1326 _delOn(vc.root().getOperand(0));
1327
1328 expect(vc.toQuery()).toEqual('foo = "bar"');
1329 expect(vc.root().ldType()).toEqual('doc');
1330 });
1331
1332 it('should clean on doc groups', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00001333 var vc = vcClass.create().fromJson(
Akron712733a2018-04-05 18:17:47 +02001334 {
1335 "@type": 'koral:docGroup',
1336 'operation' : 'operation:and',
1337 'operands' : [
1338 {
1339 "@type": 'koral:doc',
1340 "key": 'pubDate',
1341 "match": 'match:eq',
1342 "value": '2014-12-05',
1343 "type": 'type:date'
1344 },
1345 {
1346 "@type" : 'koral:doc',
1347 'key' : 'foo',
1348 'value' : 'bar'
1349 }
1350 ]
1351 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00001352 );
1353
1354 // Cleanwith direct element access
1355 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar"');
1356 _delOn(vc.root());
1357 expect(vc.toQuery()).toEqual('');
1358 expect(vc.root().ldType()).toEqual('non');
1359 });
1360
1361 it('should remove on nested doc groups (case of ungrouping 1)', function () {
1362 var vc = complexVCFactory.create();
1363
1364 // Delete with direct element access
1365 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001366 'pubDate in 2014-12-05 & (title = "Hello World!" | foo = "bar")'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001367 );
1368
1369 // Remove hello world:
1370 _delOn(vc.root().getOperand(1).getOperand(0));
1371 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar"');
1372 expect(vc.root().ldType()).toEqual('docGroup');
1373 });
1374
1375 it('should remove on nested doc groups (case of ungrouping 2)', function () {
1376 var vc = complexVCFactory.create();
1377
1378 // Delete with direct element access
1379 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001380 'pubDate in 2014-12-05 & (title = "Hello World!" | foo = "bar")'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001381 );
1382
1383 // Remove bar
1384 _delOn(vc.root().getOperand(1).getOperand(1));
1385 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & title = "Hello World!"');
1386 expect(vc.root().ldType()).toEqual('docGroup');
1387 expect(vc.root().operation()).toEqual('and');
1388 });
1389
1390 it('should remove on nested doc groups (case of root changing)', function () {
1391 var vc = complexVCFactory.create();
1392
1393 // Delete with direct element access
1394 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001395 'pubDate in 2014-12-05 & ' +
1396 '(title = "Hello World!" | foo = "bar")'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001397 );
1398
1399 // Remove bar
1400 _delOn(vc.root().getOperand(0));
1401 expect(vc.toQuery()).toEqual('title = "Hello World!" | foo = "bar"');
1402 expect(vc.root().ldType()).toEqual('docGroup');
1403 expect(vc.root().operation()).toEqual('or');
1404 });
1405
1406 it('should remove on nested doc groups (list flattening)', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00001407 var vc = vcClass.create().fromJson(
Akron712733a2018-04-05 18:17:47 +02001408 {
1409 "@type": 'koral:docGroup',
1410 'operation' : 'operation:or',
1411 'operands' : [
1412 {
1413 "@type": 'koral:doc',
1414 "key": 'pubDate',
1415 "match": 'match:eq',
1416 "value": '2014-12-05',
1417 "type": 'type:date'
1418 },
1419 {
1420 "@type" : 'koral:doc',
1421 'key' : 'foo',
1422 'value' : 'bar'
1423 },
1424 {
1425 "@type": 'koral:docGroup',
1426 'operation' : 'operation:and',
1427 'operands' : [
1428 {
1429 "@type": 'koral:doc',
1430 "key": 'pubDate',
1431 "match": 'match:eq',
1432 "value": '2014-12-05',
1433 "type": 'type:date'
1434 },
1435 {
1436 "@type" : 'koral:docGroup',
1437 'operation' : 'operation:or',
1438 'operands' : [
1439 {
1440 '@type' : 'koral:doc',
1441 'key' : 'title',
1442 'value' : 'Hello World!'
1443 },
1444 {
1445 '@type' : 'koral:doc',
1446 'key' : 'yeah',
1447 'value' : 'juhu'
1448 }
1449 ]
1450 }
1451 ]
1452 }
1453 ]
1454 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00001455 );
1456
1457 // Delete with direct element access
1458 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001459 'pubDate in 2014-12-05 | foo = "bar" | ' +
1460 '(pubDate in 2014-12-05 & ' +
1461 '(title = "Hello World!" | yeah = "juhu"))'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001462 );
1463
1464 expect(vc.root().ldType()).toEqual('docGroup');
1465 expect(vc.root().operation()).toEqual('or');
1466
1467 // Operands and operators
1468 expect(vc.element().firstChild.children.length).toEqual(4);
Akron0b489ad2018-02-02 16:49:32 +01001469 expect(vc.element().firstChild.lastChild.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001470
1471 // Remove inner group and flatten
1472 _delOn(vc.root().getOperand(2).getOperand(0));
1473
1474 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001475 'pubDate in 2014-12-05 | foo = "bar" | title = "Hello World!" | yeah = "juhu"'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001476 );
1477 expect(vc.root().ldType()).toEqual('docGroup');
1478 expect(vc.root().operation()).toEqual('or');
1479
1480 // Operands and operators
1481 expect(vc.element().firstChild.children.length).toEqual(5);
Akron0b489ad2018-02-02 16:49:32 +01001482 expect(vc.element().firstChild.lastChild.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001483 });
1484 });
1485
1486 describe('KorAP._add (event)', function () {
1487 var complexVCFactory = buildFactory(vcClass,{
1488 "@type": 'koral:docGroup',
1489 'operation' : 'operation:and',
1490 'operands' : [
Akron712733a2018-04-05 18:17:47 +02001491 {
1492 "@type": 'koral:doc',
1493 "key": 'pubDate',
1494 "match": 'match:eq',
1495 "value": '2014-12-05',
1496 "type": 'type:date'
1497 },
1498 {
1499 "@type" : 'koral:docGroup',
1500 'operation' : 'operation:or',
1501 'operands' : [
1502 {
1503 '@type' : 'koral:doc',
1504 'key' : 'title',
1505 'value' : 'Hello World!'
1506 },
1507 {
1508 '@type' : 'koral:doc',
1509 'key' : 'foo',
1510 'value' : 'bar'
1511 }
1512 ]
1513 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00001514 ]
1515 });
1516
1517 it('should add new unspecified doc with "and"', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00001518 var vc = vcClass.create().fromJson(
Akron712733a2018-04-05 18:17:47 +02001519 {
1520 "@type": 'koral:docGroup',
1521 'operation' : 'operation:and',
1522 'operands' : [
1523 {
1524 "@type": 'koral:doc',
1525 "key": 'pubDate',
1526 "match": 'match:eq',
1527 "value": '2014-12-05',
1528 "type": 'type:date'
1529 },
1530 {
1531 "@type" : 'koral:doc',
1532 'key' : 'foo',
1533 'value' : 'bar'
1534 }
1535 ]
1536 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00001537 );
1538
1539 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar"');
1540
1541 var fc = vc.element().firstChild;
1542 expect(fc.getAttribute('data-operation')).toEqual('and');
1543 expect(fc.children.length).toEqual(3);
Akron0b489ad2018-02-02 16:49:32 +01001544 expect(fc.lastChild.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001545 expect(fc.children[0].getAttribute('class')).toEqual('doc');
1546 expect(fc.children[1].getAttribute('class')).toEqual('doc');
1547
1548 // add with 'and' in the middle
1549 _andOn(vc.root().getOperand(0));
1550 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar"');
1551
1552 fc = vc.element().firstChild;
1553 expect(fc.getAttribute('data-operation')).toEqual('and');
1554 expect(fc.children.length).toEqual(4);
Akron0b489ad2018-02-02 16:49:32 +01001555 expect(fc.lastChild.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001556
1557 expect(fc.children[0].getAttribute('class')).toEqual('doc');
1558 expect(fc.children[1].getAttribute('class')).toEqual('doc unspecified');
1559 expect(fc.children[2].getAttribute('class')).toEqual('doc');
1560 });
1561
1562 it('should add new unspecified doc with "or"', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00001563 var vc = vcClass.create().fromJson(
Akron712733a2018-04-05 18:17:47 +02001564 {
1565 "@type": 'koral:docGroup',
1566 'operation' : 'operation:and',
1567 'operands' : [
1568 {
1569 "@type": 'koral:doc',
1570 "key": 'pubDate',
1571 "match": 'match:eq',
1572 "value": '2014-12-05',
1573 "type": 'type:date'
1574 },
1575 {
1576 "@type" : 'koral:doc',
1577 'key' : 'foo',
1578 'value' : 'bar'
1579 }
1580 ]
1581 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00001582 );
1583
1584 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar"');
1585
1586 var fc = vc.element().firstChild;
1587 expect(fc.children.length).toEqual(3);
Akron0b489ad2018-02-02 16:49:32 +01001588 expect(fc.lastChild.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001589 expect(fc.children[0].getAttribute('class')).toEqual('doc');
1590 expect(fc.children[1].getAttribute('class')).toEqual('doc');
1591
1592 // add with 'or' in the middle
1593 _orOn(vc.root().getOperand(0));
1594 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar"');
1595 fc = vc.element().firstChild;
1596
1597 expect(fc.getAttribute('data-operation')).toEqual('and');
1598 expect(fc.children.length).toEqual(3);
1599 expect(fc.children[0].getAttribute('class')).toEqual('docGroup');
1600 expect(fc.children[0].getAttribute('data-operation')).toEqual('or');
1601 expect(fc.children[1].getAttribute('class')).toEqual('doc');
Akron0b489ad2018-02-02 16:49:32 +01001602 expect(fc.children[2].getAttribute('class')).toEqual('operators button-group');
1603 expect(fc.lastChild.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001604
1605 fc = vc.element().firstChild.firstChild;
1606 expect(fc.children.length).toEqual(3);
1607 expect(fc.children[0].getAttribute('class')).toEqual('doc');
1608 expect(fc.children[1].getAttribute('class')).toEqual('doc unspecified');
Akron0b489ad2018-02-02 16:49:32 +01001609 expect(fc.children[2].getAttribute('class')).toEqual('operators button-group');
1610 expect(fc.lastChild.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001611 });
1612
1613 it('should add new unspecified doc with "and" before group', function () {
1614 var vc = demoFactory.create();
1615
1616 // Wrap with direct element access
1617 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001618 '(Titel = "Baum" & ' +
1619 'Veröffentlichungsort = "hihi" & ' +
1620 '(Titel = "Baum" | ' +
1621 'Veröffentlichungsort = "hihi")) | ' +
1622 'Untertitel ~ "huhu"'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001623 );
1624
1625 expect(vc.root().getOperand(0).ldType()).toEqual('docGroup');
1626 expect(vc.root().getOperand(0).operation()).toEqual('and');
1627 expect(vc.root().getOperand(0).operands().length).toEqual(3);
1628
1629 // Add unspecified on the second doc
1630 var secDoc = vc.root().getOperand(0).getOperand(1);
1631 expect(secDoc.value()).toEqual('hihi');
1632
1633 // Add
1634 _andOn(secDoc);
1635
1636 var fo = vc.root().getOperand(0);
1637
1638 expect(fo.ldType()).toEqual('docGroup');
1639 expect(fo.operation()).toEqual('and');
1640 expect(fo.operands().length).toEqual(4);
1641
1642 expect(fo.getOperand(0).ldType()).toEqual('doc');
1643 expect(fo.getOperand(1).ldType()).toEqual('doc');
1644 expect(fo.getOperand(2).ldType()).toEqual('non');
1645 expect(fo.getOperand(3).ldType()).toEqual('docGroup');
1646 });
1647
1648
1649 it('should remove a doc with an unspecified doc in a nested group', function () {
1650 var vc = demoFactory.create();
1651
1652 // Wrap with direct element access
1653 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001654 '(Titel = "Baum" & Veröffentlichungsort = "hihi" & (Titel = "Baum" | Veröffentlichungsort = "hihi")) | Untertitel ~ "huhu"'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001655 );
1656
1657 var fo = vc.root().getOperand(0).getOperand(0);
1658 expect(fo.key()).toEqual('Titel');
1659 expect(fo.value()).toEqual('Baum');
1660
1661 // Add unspecified on the root group
1662 _orOn(fo);
1663
1664 fo = vc.root().getOperand(0).getOperand(0);
1665
1666 expect(fo.operation()).toEqual('or');
1667 expect(fo.getOperand(0).ldType()).toEqual('doc');
1668 expect(fo.getOperand(1).ldType()).toEqual('non');
1669
1670 // Delete document
1671 _delOn(fo.getOperand(0));
1672
1673 // The operand is now non
1674 expect(vc.root().getOperand(0).getOperand(0).ldType()).toEqual('non');
1675 expect(vc.root().getOperand(0).getOperand(1).ldType()).toEqual('doc');
1676 expect(vc.root().getOperand(0).getOperand(2).ldType()).toEqual('docGroup');
1677 });
1678
1679
Akron712733a2018-04-05 18:17:47 +02001680 it('should remove an unspecified doc with a doc in a nested group', function () {
Nils Diewald7c8ced22015-04-15 19:21:00 +00001681 var vc = demoFactory.create();
1682
1683 // Wrap with direct element access
1684 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001685 '(Titel = "Baum" & ' +
1686 'Veröffentlichungsort = "hihi" & ' +
1687 '(Titel = "Baum" ' +
1688 '| Veröffentlichungsort = "hihi")) | ' +
1689 'Untertitel ~ "huhu"'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001690 );
1691
1692 var fo = vc.root().getOperand(0).getOperand(0);
1693 expect(fo.key()).toEqual('Titel');
1694 expect(fo.value()).toEqual('Baum');
1695
1696 // Add unspecified on the root group
1697 _orOn(fo);
1698
1699 fo = vc.root().getOperand(0).getOperand(0);
1700
1701 expect(fo.operation()).toEqual('or');
1702 expect(fo.getOperand(0).ldType()).toEqual('doc');
1703 expect(fo.getOperand(1).ldType()).toEqual('non');
1704
1705 // Delete unspecified doc
1706 _delOn(fo.getOperand(1));
1707
1708 // The operand is now non
1709 fo = vc.root().getOperand(0);
1710 expect(fo.getOperand(0).ldType()).toEqual('doc');
1711 expect(fo.getOperand(0).key()).toEqual('Titel');
1712 expect(fo.getOperand(0).value()).toEqual('Baum');
1713 expect(fo.getOperand(1).ldType()).toEqual('doc');
1714 expect(fo.getOperand(2).ldType()).toEqual('docGroup');
1715 });
1716
1717
1718 it('should add on parent group (case "and")', function () {
1719 var vc = complexVCFactory.create();
1720
1721 // Wrap with direct element access
1722 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001723 'pubDate in 2014-12-05 & (title = "Hello World!" | foo = "bar")'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001724 );
1725
1726 expect(vc.root().operands().length).toEqual(2);
1727
1728 // Add unspecified on the root group
1729 _andOn(vc.root().getOperand(1));
1730 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001731 'pubDate in 2014-12-05 & (title = "Hello World!" | foo = "bar")'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001732 );
1733
1734 expect(vc.root().ldType()).toEqual('docGroup');
1735 expect(vc.root().operands().length).toEqual(3);
1736 expect(vc.root().getOperand(0).ldType()).toEqual('doc');
1737 expect(vc.root().getOperand(1).ldType()).toEqual('docGroup');
1738 expect(vc.root().getOperand(1).operation()).toEqual('or');
1739 expect(vc.root().getOperand(2).ldType()).toEqual('non');
1740
1741 // Add another unspecified on the root group
1742 _andOn(vc.root().getOperand(1));
1743
1744 expect(vc.root().operands().length).toEqual(4);
1745 expect(vc.root().getOperand(0).ldType()).toEqual('doc');
1746 expect(vc.root().getOperand(1).ldType()).toEqual('docGroup');
1747 expect(vc.root().getOperand(2).ldType()).toEqual('non');
1748 expect(vc.root().getOperand(3).ldType()).toEqual('non');
1749
1750 // Add another unspecified after the first doc
1751 _andOn(vc.root().getOperand(0));
1752
1753 expect(vc.root().operands().length).toEqual(5);
1754 expect(vc.root().getOperand(0).ldType()).toEqual('doc');
1755 expect(vc.root().getOperand(1).ldType()).toEqual('non');
1756 expect(vc.root().getOperand(2).ldType()).toEqual('docGroup');
1757 expect(vc.root().getOperand(3).ldType()).toEqual('non');
1758 expect(vc.root().getOperand(4).ldType()).toEqual('non');
1759 });
1760
1761 it('should wrap on root', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00001762 var vc = vcClass.create().fromJson(
Akron712733a2018-04-05 18:17:47 +02001763 {
1764 "@type": 'koral:docGroup',
1765 'operation' : 'operation:and',
1766 'operands' : [
1767 {
1768 "@type": 'koral:doc',
1769 "key": 'pubDate',
1770 "match": 'match:eq',
1771 "value": '2014-12-05',
1772 "type": 'type:date'
1773 },
1774 {
1775 "@type" : 'koral:doc',
1776 'key' : 'foo',
1777 'value' : 'bar'
1778 }
1779 ]
1780 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00001781 );
1782
1783 // Wrap on root
1784 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar"');
1785 expect(vc.root().ldType()).toEqual('docGroup');
1786 expect(vc.root().operation()).toEqual('and');
1787 _orOn(vc.root());
1788 expect(vc.root().ldType()).toEqual('docGroup');
1789 expect(vc.root().operation()).toEqual('or');
1790
1791 expect(vc.root().getOperand(0).ldType()).toEqual('docGroup');
1792 expect(vc.root().getOperand(0).operation()).toEqual('and');
1793 });
1794
1795 it('should add on root (case "and")', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00001796 var vc = vcClass.create().fromJson(
Akron712733a2018-04-05 18:17:47 +02001797 {
1798 "@type": 'koral:doc',
1799 "key": 'pubDate',
1800 "match": 'match:eq',
1801 "value": '2014-12-05',
1802 "type": 'type:date'
1803 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00001804 );
1805
1806 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05');
1807 expect(vc.root().ldType()).toEqual('doc');
1808 expect(vc.root().key()).toEqual('pubDate');
1809 expect(vc.root().value()).toEqual('2014-12-05');
1810
1811 // Wrap on root
1812 _andOn(vc.root());
1813 expect(vc.root().ldType()).toEqual('docGroup');
1814 expect(vc.root().operation()).toEqual('and');
1815 });
1816
1817 it('should add on root (case "or")', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00001818 var vc = vcClass.create().fromJson(
Akron712733a2018-04-05 18:17:47 +02001819 {
1820 "@type": 'koral:doc',
1821 "key": 'pubDate',
1822 "match": 'match:eq',
1823 "value": '2014-12-05',
1824 "type": 'type:date'
1825 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00001826 );
1827
1828 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05');
1829 expect(vc.root().key()).toEqual('pubDate');
1830 expect(vc.root().value()).toEqual('2014-12-05');
1831
1832 // Wrap on root
1833 _orOn(vc.root());
1834 expect(vc.root().ldType()).toEqual('docGroup');
1835 expect(vc.root().operation()).toEqual('or');
1836 });
1837
1838 it('should support multiple sub groups per group', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00001839 var vc = vcClass.create().fromJson(
Akron712733a2018-04-05 18:17:47 +02001840 {
1841 "@type": 'koral:docGroup',
1842 'operation' : 'operation:or',
1843 'operands' : [
1844 {
1845 "@type": 'koral:docGroup',
1846 'operation' : 'operation:and',
1847 'operands' : [
1848 {
1849 "@type": 'koral:doc',
1850 "key": 'title',
1851 "value": 't1',
1852 },
1853 {
1854 "@type" : 'koral:doc',
1855 'key' : 'title',
1856 'value' : 't2'
1857 }
1858 ]
1859 },
1860 {
1861 "@type": 'koral:docGroup',
1862 'operation' : 'operation:and',
1863 'operands' : [
1864 {
1865 "@type": 'koral:doc',
1866 "key": 'title',
1867 "value": 't3',
1868 },
1869 {
1870 "@type" : 'koral:doc',
1871 'key' : 'title',
1872 'value' : 't4'
1873 }
1874 ]
1875 }
1876 ]
1877 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00001878 );
1879 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001880 '(title = "t1" & title = "t2") | ' +
1881 '(title = "t3" & title = "t4")'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001882 );
1883 expect(vc.root().operation()).toEqual('or');
1884 expect(vc.root().getOperand(0).toQuery()).toEqual('title = "t1" & title = "t2"');
1885 expect(vc.root().getOperand(1).toQuery()).toEqual('title = "t3" & title = "t4"');
1886
1887 _andOn(vc.root());
1888
1889 expect(vc.root().operation()).toEqual('and');
1890 expect(vc.root().getOperand(0).ldType()).toEqual('docGroup');
1891 expect(vc.root().getOperand(1).ldType()).toEqual('non');
1892 });
1893 });
1894
Akron5c829e92017-05-12 18:10:00 +02001895 // Check class method
1896 describe('KorAP.VC.checkRewrite', function () {
1897
1898 it('should check for simple rewrites', function () {
1899 expect(vcClass.checkRewrite(
1900 {
1901 "@type" : "koral:doc",
1902 "rewrites" : [{
Akron712733a2018-04-05 18:17:47 +02001903 "@type" : "koral:rewrite",
1904 "operation" : "operation:modification",
1905 "src" : "querySerializer",
1906 "scope" : "tree"
Akron5c829e92017-05-12 18:10:00 +02001907 }]
1908 }
1909 )).toBeTruthy();
Nils Diewald7c8ced22015-04-15 19:21:00 +00001910
Akron5c829e92017-05-12 18:10:00 +02001911 var nested = {
1912 "@type" : "koral:docGroup",
1913 "operands" : [
1914 {
1915 "@type" : "koral:doc"
1916 },
1917 {
1918 "@type" : "koral:docGroup",
1919 "operands" : [
1920 {
1921 "@type": "koral:doc"
1922 },
1923 {
1924 "@type": "koral:doc"
1925 }
1926 ]
1927 }
1928 ]
1929 };
1930
1931 expect(vcClass.checkRewrite(nested)).toBe(false);
1932
1933 nested["operands"][1]["operands"][1]["rewrites"] = [{
Akron712733a2018-04-05 18:17:47 +02001934 "@type" : "koral:rewrite",
1935 "operation" : "operation:modification",
1936 "src" : "querySerializer",
1937 "scope" : "tree"
Akron5c829e92017-05-12 18:10:00 +02001938 }];
1939
1940 expect(vcClass.checkRewrite(nested)).toBeTruthy();
1941 });
1942 });
Nils Diewald6283d692015-04-23 20:32:53 +00001943
1944 describe('KorAP.Rewrite', function () {
Nils Diewald7c8ced22015-04-15 19:21:00 +00001945 it('should be initializable', function () {
1946 var rewrite = rewriteClass.create({
Akron712733a2018-04-05 18:17:47 +02001947 "@type" : "koral:rewrite",
1948 "operation" : "operation:modification",
1949 "src" : "querySerializer",
1950 "scope" : "tree"
Nils Diewald86dad5b2015-01-28 15:09:07 +00001951 });
Nils Diewald7c8ced22015-04-15 19:21:00 +00001952 expect(rewrite.toString()).toEqual('Modification of "tree" by "querySerializer"');
1953 });
Nils Diewald86dad5b2015-01-28 15:09:07 +00001954
Nils Diewald7c8ced22015-04-15 19:21:00 +00001955 it('should be deserialized by docs', function () {
1956 var doc = docClass.create(
Akron712733a2018-04-05 18:17:47 +02001957 undefined,
1958 {
1959 "@type":"koral:doc",
1960 "key":"Titel",
1961 "value":"Baum",
1962 "match":"match:eq"
1963 });
Nils Diewald7c8ced22015-04-15 19:21:00 +00001964
1965 expect(doc.element().classList.contains('doc')).toBeTruthy();
1966 expect(doc.element().classList.contains('rewritten')).toBe(false);
1967
1968 doc = docClass.create(
Akron712733a2018-04-05 18:17:47 +02001969 undefined,
1970 {
1971 "@type":"koral:doc",
1972 "key":"Titel",
1973 "value":"Baum",
1974 "match":"match:eq",
1975 "rewrites" : [
1976 {
1977 "@type" : "koral:rewrite",
1978 "operation" : "operation:modification",
1979 "src" : "querySerializer",
1980 "scope" : "tree"
1981 }
1982 ]
1983 });
Nils Diewald7c8ced22015-04-15 19:21:00 +00001984
1985 expect(doc.element().classList.contains('doc')).toBeTruthy();
1986 expect(doc.element().classList.contains('rewritten')).toBeTruthy();
1987 });
Nils Diewald6283d692015-04-23 20:32:53 +00001988
Akron76c3dd62018-05-29 20:58:27 +02001989 it('should be described in a title attribute', function () {
1990
1991 doc = docClass.create(
1992 undefined,
1993 {
1994 "@type":"koral:doc",
1995 "key":"Titel",
1996 "value":"Baum",
1997 "match":"match:eq",
1998 "rewrites" : [
1999 {
2000 "@type" : "koral:rewrite",
2001 "operation" : "operation:modification",
2002 "src" : "querySerializer",
2003 "scope" : "tree"
2004 },
2005 {
2006 "@type" : "koral:rewrite",
2007 "operation" : "operation:injection",
2008 "src" : "me"
2009 }
2010 ]
2011 });
2012
2013 expect(doc.element().classList.contains('doc')).toBeTruthy();
2014 expect(doc.element().classList.contains('rewritten')).toBeTruthy();
2015 expect(doc.element().lastChild.getAttribute("title")).toEqual("querySerializer: tree (modification)\nme (injection)");
2016 });
2017
2018
Nils Diewald6283d692015-04-23 20:32:53 +00002019 xit('should be deserialized by docGroups', function () {
2020 var docGroup = docGroupClass.create(
Akron712733a2018-04-05 18:17:47 +02002021 undefined,
2022 {
2023 "@type" : "koral:docGroup",
2024 "operation" : "operation:or",
2025 "operands" : [
2026 {
2027 "@type" : "doc",
2028 "key" : "pubDate",
2029 "type" : "type:date",
2030 "value" : "2014-12-05"
2031 },
2032 {
2033 "@type" : "doc",
2034 "key" : "pubDate",
2035 "type" : "type:date",
2036 "value" : "2014-12-06"
2037 }
2038 ],
2039 "rewrites" : [
2040 {
2041 "@type" : "koral:rewrite",
2042 "operation" : "operation:modification",
2043 "src" : "querySerializer",
2044 "scope" : "tree"
2045 }
2046 ]
2047 }
Nils Diewald6283d692015-04-23 20:32:53 +00002048 );
2049
2050 expect(doc.element().classList.contains('docgroup')).toBeTruthy();
2051 expect(doc.element().classList.contains('rewritten')).toBe(false);
2052 });
Nils Diewald86dad5b2015-01-28 15:09:07 +00002053 });
Nils Diewaldf0c4f112015-05-05 12:56:59 +00002054
2055 describe('KorAP.stringValue', function () {
2056 it('should be initializable', function () {
2057 var sv = stringValClass.create();
2058 expect(sv.regex()).toBe(false);
2059 expect(sv.value()).toBe('');
Nils Diewaldc4c4b832015-05-05 16:00:08 +00002060
2061 sv = stringValClass.create('Baum');
2062 expect(sv.regex()).toBe(false);
2063 expect(sv.value()).toBe('Baum');
2064
2065 sv = stringValClass.create('Baum', false);
2066 expect(sv.regex()).toBe(false);
2067 expect(sv.value()).toBe('Baum');
2068
2069 sv = stringValClass.create('Baum', true);
2070 expect(sv.regex()).toBe(true);
2071 expect(sv.value()).toBe('Baum');
2072 });
2073
2074 it('should be modifiable', function () {
2075 var sv = stringValClass.create();
2076 expect(sv.regex()).toBe(false);
2077 expect(sv.value()).toBe('');
2078
2079 expect(sv.value('Baum')).toBe('Baum');
2080 expect(sv.value()).toBe('Baum');
2081
2082 expect(sv.regex(true)).toBe(true);
2083 expect(sv.regex()).toBe(true);
2084 });
2085
2086 it('should have a toggleble regex value', function () {
2087 var sv = stringValClass.create();
Nils Diewald7991a3f2015-05-19 14:12:37 +00002088
2089 expect(sv.element().firstChild.value).toBe('');
2090 sv.element().firstChild.value = 'der'
2091 expect(sv.element().firstChild.value).toBe('der');
2092
Nils Diewaldc4c4b832015-05-05 16:00:08 +00002093 expect(sv.regex()).toBe(false);
2094
2095 sv.toggleRegex();
Nils Diewald7991a3f2015-05-19 14:12:37 +00002096 expect(sv.element().firstChild.value).toBe('der');
Nils Diewaldc4c4b832015-05-05 16:00:08 +00002097 expect(sv.regex()).toBe(true);
Nils Diewald7991a3f2015-05-19 14:12:37 +00002098 sv.element().firstChild.value = 'derbe'
Nils Diewaldc4c4b832015-05-05 16:00:08 +00002099
2100 sv.toggleRegex();
2101 expect(sv.regex()).toBe(false);
Nils Diewald7991a3f2015-05-19 14:12:37 +00002102 expect(sv.element().firstChild.value).toBe('derbe');
Nils Diewaldc4c4b832015-05-05 16:00:08 +00002103 });
2104
2105 it('should have an element', function () {
2106 var sv = stringValClass.create('der');
2107 expect(sv.element().nodeName).toBe('DIV');
2108 expect(sv.element().firstChild.nodeName).toBe('INPUT');
2109 expect(sv.element().firstChild.value).toBe('der');
2110 });
2111
2112 it('should have a classed element', function () {
2113 var sv = stringValClass.create();
Nils Diewaldc4c4b832015-05-05 16:00:08 +00002114 expect(sv.element().classList.contains('regex')).toBe(false);
2115 expect(sv.regex()).toBe(false);
2116 sv.toggleRegex();
2117 expect(sv.element().classList.contains('regex')).toBe(true);
2118 });
2119
2120 it('should be storable', function () {
2121 var sv = stringValClass.create();
2122 var count = 1;
2123 sv.store = function (value, regex) {
Akron712733a2018-04-05 18:17:47 +02002124 expect(regex).toBe(true);
2125 expect(value).toBe('tree');
Nils Diewaldc4c4b832015-05-05 16:00:08 +00002126 };
2127 sv.regex(true);
2128 sv.value('tree');
2129 sv.element().lastChild.click();
Nils Diewaldf0c4f112015-05-05 12:56:59 +00002130 });
Akron712733a2018-04-05 18:17:47 +02002131
Nils Diewaldf0c4f112015-05-05 12:56:59 +00002132 });
Akrone4961b12017-05-10 21:04:46 +02002133
Akron712733a2018-04-05 18:17:47 +02002134 describe('KorAP.VC.Menu', function () {
Akrone65a88a2018-04-05 19:14:20 +02002135
2136 var vc;
2137
Akron712733a2018-04-05 18:17:47 +02002138 it('should be initializable', function () {
2139
Akrone65a88a2018-04-05 19:14:20 +02002140 vc = vcClass.create([
Akron712733a2018-04-05 18:17:47 +02002141 ['a', 'text'],
2142 ['b', 'string'],
2143 ['c', 'date']
2144 ]).fromJson();
2145 expect(vc.element().firstChild.classList.contains('unspecified')).toBeTruthy();
2146 expect(vc.element().firstChild.firstChild.tagName).toEqual('SPAN');
2147
2148 // Click on unspecified
2149 vc.element().firstChild.firstChild.click();
2150 expect(vc.element().firstChild.firstChild.tagName).toEqual('UL');
2151
2152 var list = vc.element().firstChild.firstChild;
2153 expect(list.getElementsByTagName("LI")[0].innerText).toEqual('a');
2154 expect(list.getElementsByTagName("LI")[1].innerText).toEqual('b');
2155 expect(list.getElementsByTagName("LI")[2].innerText).toEqual('c');
2156
2157 vc = vcClass.create([
2158 ['d', 'text'],
2159 ['e', 'string'],
2160 ['f', 'date']
2161 ]).fromJson();
2162 expect(vc.element().firstChild.classList.contains('unspecified')).toBeTruthy();
2163 expect(vc.element().firstChild.firstChild.tagName).toEqual('SPAN');
2164
2165 // Click on unspecified
2166 vc.element().firstChild.firstChild.click();
2167 expect(vc.element().firstChild.firstChild.tagName).toEqual('UL');
2168
2169 list = vc.element().firstChild.firstChild;
2170 expect(list.getElementsByTagName("LI")[0].innerText).toEqual('d');
2171 expect(list.getElementsByTagName("LI")[1].innerText).toEqual('e');
2172 expect(list.getElementsByTagName("LI")[2].innerText).toEqual('f');
Akron31d89942018-04-06 16:44:51 +02002173 // blur
2174 document.body.click();
Akron712733a2018-04-05 18:17:47 +02002175 });
Akrone65a88a2018-04-05 19:14:20 +02002176
2177 // Reinitialize to make tests stable
2178 vc = vcClass.create([
2179 ['d', 'text'],
2180 ['e', 'string'],
2181 ['f', 'date']
2182 ]).fromJson();
2183
2184 it('should be clickable on key', function () {
Akron31d89942018-04-06 16:44:51 +02002185 // Click on unspecified
2186 vc.element().firstChild.firstChild.click();
Akrone65a88a2018-04-05 19:14:20 +02002187 // Click on "d"
2188 vc.element().firstChild.firstChild.getElementsByTagName("LI")[0].click();
2189 expect(vc.element().firstChild.firstChild.tagName).toEqual('SPAN');
2190 expect(vc.element().firstChild.firstChild.innerText).toEqual('d');
2191 expect(vc.element().firstChild.children[1].innerText).toEqual('eq');
2192 expect(vc.element().firstChild.children[1].getAttribute('data-type')).toEqual('text');
Akron31d89942018-04-06 16:44:51 +02002193 // blur
2194 document.body.click();
Akrone65a88a2018-04-05 19:14:20 +02002195 });
2196
Akron31d89942018-04-06 16:44:51 +02002197 it('should be clickable on operation for text', function () {
2198 // Click on "d" (or unspecified)
2199 vc.element().firstChild.firstChild.click();
2200
2201 // Choose "d"
2202 vc.element().firstChild.firstChild.getElementsByTagName("LI")[0].click();
2203
2204 // Click on matchop
Akrone65a88a2018-04-05 19:14:20 +02002205 vc.element().firstChild.children[1].click();
Akron31d89942018-04-06 16:44:51 +02002206
Akrone65a88a2018-04-05 19:14:20 +02002207 expect(vc.element().firstChild.children[1].tagName).toEqual('UL');
Akron31d89942018-04-06 16:44:51 +02002208
Akrone65a88a2018-04-05 19:14:20 +02002209 var ul = vc.element().firstChild.children[1];
2210 expect(ul.getElementsByTagName('li')[0].innerText).toEqual("eq");
2211 expect(ul.getElementsByTagName('li')[1].innerText).toEqual("ne");
2212 expect(ul.getElementsByTagName('li')[2].innerText).toEqual("contains");
2213 expect(ul.getElementsByTagName('li')[3].innerText).toEqual("containsnot");
2214 expect(ul.getElementsByTagName('li')[4]).toBeUndefined();
Akron31d89942018-04-06 16:44:51 +02002215
2216 // Choose "contains"
2217 ul.getElementsByTagName('li')[2].click();
2218 expect(vc.element().firstChild.children[1].tagName).toEqual("SPAN");
2219 expect(vc.element().firstChild.children[1].innerText).toEqual("contains");
2220 // blur
2221 document.body.click();
Akrone65a88a2018-04-05 19:14:20 +02002222 })
Akron31d89942018-04-06 16:44:51 +02002223
2224 it('should be clickable on operation for string', function () {
2225 // Click on "d" (or unspecified)
2226 vc.element().firstChild.firstChild.click();
2227
2228 // Choose "e"
2229 vc.element().firstChild.firstChild.getElementsByTagName("LI")[1].click();
2230
2231 // As a consequence the matchoperator may no longer
2232 // be valid and needs to be re-evaluated
2233 var fc = vc.element().firstChild;
2234 expect(fc.firstChild.tagName).toEqual('SPAN');
2235 expect(fc.firstChild.innerText).toEqual('e');
2236 expect(fc.children[1].innerText).toEqual('eq');
2237 expect(fc.children[1].getAttribute('data-type')).toEqual('string');
2238
2239 vc.element().firstChild.children[1].click();
2240
2241 expect(vc.element().firstChild.children[1].tagName).toEqual('UL');
2242
2243 var ul = vc.element().firstChild.children[1];
2244 expect(ul.getElementsByTagName('li')[0].innerText).toEqual("eq");
2245 expect(ul.getElementsByTagName('li')[1].innerText).toEqual("ne");
2246 expect(ul.getElementsByTagName('li')[2]).toBeUndefined();
2247
2248 // Choose "ne"
2249 ul.getElementsByTagName('li')[1].click();
2250 expect(vc.element().firstChild.children[1].tagName).toEqual("SPAN");
2251 expect(vc.element().firstChild.children[1].innerText).toEqual("ne");
Akron8db5e3a2018-05-28 19:25:26 +02002252
2253 // Click on text
2254 expect(vc.element().firstChild.children[2].innerText).toEqual("⋯");
2255 vc.element().firstChild.children[2].click();
2256
2257 // Blur text element
2258 expect(vc.element().firstChild.children[2].firstChild.value).toEqual('');
2259
Akron31d89942018-04-06 16:44:51 +02002260 // blur
2261 document.body.click();
2262 });
2263
2264 it('should be clickable on operation for date', function () {
2265
2266 // Replay matchop check - so it's guaranteed that "ne" is chosen
2267 // Click on "e" (or unspecified)
2268 vc.element().firstChild.firstChild.click();
2269 // Rechoose "e"
2270 vc.element().firstChild.firstChild.getElementsByTagName("LI")[1].click();
2271 // Click on matchop
2272 vc.element().firstChild.children[1].click();
2273 // Choose "ne"
2274 vc.element().firstChild.children[1].getElementsByTagName('li')[1].click();
2275 expect(vc.element().firstChild.children[1].innerText).toEqual("ne");
2276
2277 // Click on "e"
2278 vc.element().firstChild.firstChild.click();
2279 // Choose "f"
2280 vc.element().firstChild.firstChild.getElementsByTagName("LI")[2].click();
2281
2282 // The matchoperator should still be "ne" as this is valid for dates as well (now)
2283 var fc = vc.element().firstChild;
2284 expect(fc.firstChild.tagName).toEqual('SPAN');
2285 expect(fc.firstChild.innerText).toEqual('f');
2286 expect(fc.children[1].innerText).toEqual('ne');
2287 // blur
2288 document.body.click();
2289 });
Akronddc98a72018-04-06 17:33:52 +02002290
2291
2292 // Check json deserialization
2293 it('should be initializable', function () {
2294 vc = vcClass.create([
2295 ['a', 'text'],
2296 ['b', 'string'],
2297 ['c', 'date']
2298 ]).fromJson({
2299 "@type" : "koral:doc",
2300 "key":"a",
2301 "value":"Baum"
2302 });
2303
2304 expect(vc.element().firstChild.children[1].getAttribute('data-type')).toEqual('text');
2305 });
Akron712733a2018-04-05 18:17:47 +02002306 });
2307
2308
Akrone4961b12017-05-10 21:04:46 +02002309 // Check prefix
2310 describe('KorAP.VC.Prefix', function () {
2311
2312 it('should be initializable', function () {
2313 var p = prefixClass.create();
2314 expect(p.element().classList.contains('pref')).toBeTruthy();
2315 expect(p.isSet()).not.toBeTruthy();
2316 });
2317
2318
2319 it('should be clickable', function () {
2320 var vc = vcClass.create([
Akron712733a2018-04-05 18:17:47 +02002321 ['a', null],
2322 ['b', null],
2323 ['c', null]
2324 ]).fromJson();
Akrone4961b12017-05-10 21:04:46 +02002325 expect(vc.element().firstChild.classList.contains('unspecified')).toBeTruthy();
2326
2327 // This should open up the menu
2328 vc.element().firstChild.firstChild.click();
2329 expect(vc.element().firstChild.firstChild.tagName).toEqual('UL');
2330
2331 KorAP._vcKeyMenu._prefix.clear();
2332 KorAP._vcKeyMenu._prefix.add('x');
2333
2334 var prefElement = vc.element().querySelector('span.pref');
2335 expect(prefElement.innerText).toEqual('x');
2336
2337 // This should add key 'x' to VC
2338 prefElement.click();
2339
2340 expect(vc.element().firstChild.classList.contains('doc')).toBeTruthy();
2341 expect(vc.element().firstChild.firstChild.className).toEqual('key');
2342 expect(vc.element().firstChild.firstChild.innerText).toEqual('x');
2343 });
2344 });
Nils Diewald2fe12e12015-03-06 16:47:06 +00002345});