blob: ae62f101ad280d11b86d90755220e923757db7c6 [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");
143 doc.value("Der alte Mann");
144 expect(doc.matchop()).toEqual('eq');
145 expect(doc.key()).toEqual("title");
146 expect(doc.type()).toEqual("string");
147 expect(doc.value()).toEqual("Der alte Mann");
148 });
149
150
151 it('should deserialize JSON-LD string', function () {
152 var doc;
153
154 // String default
155 doc = stringFactory.create();
156 expect(doc.matchop()).toEqual('eq');
157 expect(doc.key()).toEqual("author");
158 expect(doc.type()).toEqual("string");
159 expect(doc.value()).toEqual("Max Birkendale");
160
161 // No valid string
162 doc = stringFactory.create({
Akron712733a2018-04-05 18:17:47 +0200163 value : undefined
Nils Diewald7c8ced22015-04-15 19:21:00 +0000164 });
165 expect(doc).toBeUndefined();
166
167 // No valid string
168 doc = stringFactory.create({
Akron712733a2018-04-05 18:17:47 +0200169 value : { "foo" : "bar" }
Nils Diewald7c8ced22015-04-15 19:21:00 +0000170 });
171 expect(doc).toBeUndefined();
172
173 // Change match type
174 doc = stringFactory.create({
Akron712733a2018-04-05 18:17:47 +0200175 "match" : "match:ne"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000176 });
177
178 expect(doc.matchop()).toEqual('ne');
179 expect(doc.key()).toEqual("author");
180 expect(doc.type()).toEqual("string");
181 expect(doc.value()).toEqual("Max Birkendale");
182
183 // Invalid match type
184 doc = stringFactory.create({
Akron712733a2018-04-05 18:17:47 +0200185 "match" : { "foo" : "bar" }
Nils Diewald7c8ced22015-04-15 19:21:00 +0000186 });
187 expect(doc).toBeUndefined();
188 });
189
190 it('should deserialize JSON-LD regex', function () {
191 var doc = regexFactory.create();
192 expect(doc.key()).toEqual("title");
193 expect(doc.type()).toEqual("regex");
194 expect(doc.value()).toEqual("[^b]ee.+?");
195 expect(doc.matchop()).toEqual('eq');
196
197 // change matcher
198 doc = regexFactory.create({
Akron712733a2018-04-05 18:17:47 +0200199 match : "match:ne"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000200 });
201 expect(doc.matchop()).toEqual('ne');
Akronea4e9052017-07-06 16:12:05 +0200202 expect(doc.rewrites()).toBeUndefined();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000203
204 // Invalid matcher
205 doc = regexFactory.create({
Akron712733a2018-04-05 18:17:47 +0200206 match : "match:chook"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000207 });
Akronea4e9052017-07-06 16:12:05 +0200208 expect(doc.matchop()).toEqual('eq');
209 expect(doc.rewrites()).toBeDefined();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000210
211 // Invalid regex
212 doc = regexFactory.create({
Akron712733a2018-04-05 18:17:47 +0200213 value : "[^b"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000214 });
215 expect(doc).toBeUndefined();
216 });
217
218 it('should deserialize JSON-LD date', function () {
219
220 // Normal date
221 doc = dateFactory.create({});
222
223 expect(doc.matchop()).toEqual('eq');
224 expect(doc.key()).toEqual("pubDate");
225 expect(doc.type()).toEqual("date");
226 expect(doc.value()).toEqual("2014-11-05");
227
228 // Short date 1
229 doc = dateFactory.create({
Akron712733a2018-04-05 18:17:47 +0200230 "value" : "2014-11"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000231 });
232
233 expect(doc.matchop()).toEqual('eq');
234 expect(doc.key()).toEqual("pubDate");
235 expect(doc.type()).toEqual("date");
236 expect(doc.value()).toEqual("2014-11");
237
238 // Short date 2
239 doc = dateFactory.create({
Akron712733a2018-04-05 18:17:47 +0200240 "value" : "2014"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000241 });
242
243 expect(doc.matchop()).toEqual('eq');
244 expect(doc.key()).toEqual("pubDate");
245 expect(doc.type()).toEqual("date");
246 expect(doc.value()).toEqual("2014");
247
248 // Invalid date!
249 doc = dateFactory.create({
Akron712733a2018-04-05 18:17:47 +0200250 "value" : "2014-11-050"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000251 });
252 expect(doc).toBeUndefined();
253
254 // Invalid matcher!
255 doc = dateFactory.create({
Akron31d89942018-04-06 16:44:51 +0200256 "match" : "match:contains",
Nils Diewald7c8ced22015-04-15 19:21:00 +0000257 });
Akronea4e9052017-07-06 16:12:05 +0200258 expect(doc).toBeDefined();
259 expect(doc.rewrites()).toBeDefined();
260 expect(doc.matchop()).toEqual('eq');
Nils Diewald7c8ced22015-04-15 19:21:00 +0000261 });
262
263 it('should be serializale to JSON', function () {
264
265 // Empty doc
266 var doc = docClass.create();
267 expect(doc.toJson()).toEqual(jasmine.any(Object));
268
269 // Serialize string
270 doc = stringFactory.create();
271 expect(doc.toJson()).toEqual(jasmine.objectContaining({
Akron712733a2018-04-05 18:17:47 +0200272 "@type" : "koral:doc",
273 "type" : "type:string",
274 "key" : "author",
275 "value" : "Max Birkendale",
276 "match" : "match:eq"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000277 }));
278
279 // Serialize regex
280 doc = regexFactory.create();
281 expect(doc.toJson()).toEqual(jasmine.objectContaining({
Akron712733a2018-04-05 18:17:47 +0200282 "@type" : "koral:doc",
283 "type" : "type:regex",
284 "value" : "[^b]ee.+?",
285 "match" : "match:eq",
286 "key" : 'title'
Nils Diewald7c8ced22015-04-15 19:21:00 +0000287 }));
288
289 doc = regexFactory.create({
Akron712733a2018-04-05 18:17:47 +0200290 match: "match:ne"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000291 });
292 expect(doc.toJson()).toEqual(jasmine.objectContaining({
Akron712733a2018-04-05 18:17:47 +0200293 "@type" : "koral:doc",
294 "type" : "type:regex",
295 "value" : "[^b]ee.+?",
296 "match" : "match:ne",
297 "key" : 'title'
Nils Diewald7c8ced22015-04-15 19:21:00 +0000298 }));
299
300 doc = dateFactory.create();
301 expect(doc.toJson()).toEqual(jasmine.objectContaining({
Akron712733a2018-04-05 18:17:47 +0200302 "@type" : "koral:doc",
303 "type" : "type:date",
304 "value" : "2014-11-05",
305 "match" : "match:eq",
306 "key" : 'pubDate'
Nils Diewald7c8ced22015-04-15 19:21:00 +0000307 }));
308
309 doc = dateFactory.create({
Akron712733a2018-04-05 18:17:47 +0200310 value : "2014"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000311 });
312 expect(doc.toJson()).toEqual(jasmine.objectContaining({
Akron712733a2018-04-05 18:17:47 +0200313 "@type" : "koral:doc",
314 "type" : "type:date",
315 "value" : "2014",
316 "match" : "match:eq",
317 "key" : 'pubDate'
Nils Diewald7c8ced22015-04-15 19:21:00 +0000318 }));
319 });
320
321
322 it('should be serializale to String', function () {
323 // Empty doc
324 var doc = docClass.create();
325 expect(doc.toQuery()).toEqual("");
326
327 // Serialize string
328 doc = stringFactory.create();
329 expect(doc.toQuery()).toEqual('author = "Max Birkendale"');
330
331 // Serialize string with quotes
332 doc = stringFactory.create({ "value" : 'Max "Der Coole" Birkendate'});
333 expect(doc.toQuery()).toEqual('author = "Max \\"Der Coole\\" Birkendate"');
334
335 // Serialize regex
336 doc = regexFactory.create();
337 expect(doc.toQuery()).toEqual('title = /[^b]ee.+?/');
338
339 doc = regexFactory.create({
Akron712733a2018-04-05 18:17:47 +0200340 match: "match:ne"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000341 });
342 expect(doc.toQuery()).toEqual('title != /[^b]ee.+?/');
343
Akron8778f5d2017-06-30 21:25:55 +0200344 doc = regexFactory.create({
Akron712733a2018-04-05 18:17:47 +0200345 value: "WPD/AAA/00001"
Akron8778f5d2017-06-30 21:25:55 +0200346 });
347 expect(doc.toQuery()).toEqual('title = /WPD\\/AAA\\/00001/');
348
Nils Diewald7c8ced22015-04-15 19:21:00 +0000349 doc = dateFactory.create();
350 expect(doc.toQuery()).toEqual('pubDate in 2014-11-05');
351
352 doc = dateFactory.create({
Akron712733a2018-04-05 18:17:47 +0200353 value : "2014"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000354 });
355 expect(doc.toQuery()).toEqual('pubDate in 2014');
356 });
357 });
358
359
360 describe('KorAP.DocGroup', function () {
361 // Create example factories
362 var docFactory = buildFactory(
363 docClass,
Nils Diewaldf219eb82015-01-07 20:15:42 +0000364 {
Akron712733a2018-04-05 18:17:47 +0200365 "@type" : "koral:doc",
366 "match":"match:eq",
367 "key" : "author",
368 "value" : "Max Birkendale"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000369 }
370 );
371
372 var docGroupFactory = buildFactory(
373 docGroupClass, {
Akron712733a2018-04-05 18:17:47 +0200374 "@type" : "koral:docGroup",
375 "operation" : "operation:and",
376 "operands" : [
377 docFactory.create().toJson(),
378 docFactory.create({
379 "key" : "pubDate",
380 "type" : "type:date",
381 "value" : "2014-12-05"
382 }).toJson()
383 ]
Nils Diewald7c8ced22015-04-15 19:21:00 +0000384 });
385
386 it('should be initializable', function () {
387 // Create empty group
388 var docGroup = docGroupClass.create();
389 expect(docGroup.operation()).toEqual('and');
390
391 // Create empty group
392 docGroup = docGroupClass.create();
393 docGroup.operation('or');
394 expect(docGroup.operation()).toEqual('or');
395 });
396
397 it('should be definable', function () {
398
399 // Empty group
400 var docGroup = docGroupClass.create();
401 expect(docGroup.operation()).toEqual('and');
402
403 // Set values
404 docGroup.operation("or");
405 expect(docGroup.operation()).toEqual('or');
406
407 // Set invalid values
408 docGroup.operation("hui");
409 expect(docGroup.operation()).toEqual('or');
410 });
411
412 it('should be deserializable', function () {
413 var docGroup = docGroupFactory.create();
414 expect(docGroup.operation()).toEqual("and");
415 expect(docGroup.operands().length).toEqual(2);
416
417 var op1 = docGroup.getOperand(0);
418 expect(op1.type()).toEqual("string");
419 expect(op1.key()).toEqual("author");
420 expect(op1.value()).toEqual("Max Birkendale");
421 expect(op1.matchop()).toEqual("eq");
422
423 var op2 = docGroup.getOperand(1);
424 expect(op2.type()).toEqual("date");
425 expect(op2.key()).toEqual("pubDate");
426 expect(op2.value()).toEqual("2014-12-05");
427 expect(op2.matchop()).toEqual("eq");
428
429 // Append empty group
430 var newGroup = docGroup.append(docGroupClass.create());
431 newGroup.operation('or');
432 newGroup.append(docFactory.create());
433 newGroup.append(docFactory.create({
Akron712733a2018-04-05 18:17:47 +0200434 "type" : "type:regex",
435 "key" : "title",
436 "value" : "^e.+?$",
437 "match" : "match:ne"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000438 }));
439
440 expect(docGroup.operation()).toEqual("and");
441 expect(docGroup.operands().length).toEqual(3);
442
443 var op1 = docGroup.getOperand(0);
444 expect(op1.ldType()).toEqual("doc");
445 expect(op1.type()).toEqual("string");
446 expect(op1.key()).toEqual("author");
447 expect(op1.value()).toEqual("Max Birkendale");
448 expect(op1.matchop()).toEqual("eq");
449
450 var op2 = docGroup.getOperand(1);
451 expect(op2.ldType()).toEqual("doc");
452 expect(op2.type()).toEqual("date");
453 expect(op2.key()).toEqual("pubDate");
454 expect(op2.value()).toEqual("2014-12-05");
455 expect(op2.matchop()).toEqual("eq");
456
457 var op3 = docGroup.getOperand(2);
458 expect(op3.ldType()).toEqual("docGroup");
459 expect(op3.operation()).toEqual("or");
460
461 var op4 = op3.getOperand(0);
462 expect(op4.ldType()).toEqual("doc");
463 expect(op4.type()).toEqual("string");
464 expect(op4.key()).toEqual("author");
465 expect(op4.value()).toEqual("Max Birkendale");
466 expect(op4.matchop()).toEqual("eq");
467
468 var op5 = op3.getOperand(1);
469 expect(op5.ldType()).toEqual("doc");
470 expect(op5.type()).toEqual("regex");
471 expect(op5.key()).toEqual("title");
472 expect(op5.value()).toEqual("^e.+?$");
473 expect(op5.matchop()).toEqual("ne");
474 });
475
476 it('should be serializable to JSON', function () {
477 var docGroup = docGroupFactory.create();
478
479 expect(docGroup.toJson()).toEqual(jasmine.objectContaining({
Akron712733a2018-04-05 18:17:47 +0200480 "@type" : "koral:docGroup",
481 "operation" : "operation:and",
482 "operands" : [
483 {
484 "@type": 'koral:doc',
485 "key" : 'author',
486 "match": 'match:eq',
487 "value": 'Max Birkendale',
488 "type": 'type:string'
489 },
490 {
491 "@type": 'koral:doc',
492 "key": 'pubDate',
493 "match": 'match:eq',
494 "value": '2014-12-05',
495 "type": 'type:date'
496 }
497 ]
Nils Diewald7c8ced22015-04-15 19:21:00 +0000498 }));
499 });
Nils Diewalde15b7a22015-01-09 21:50:21 +0000500
Nils Diewald7c8ced22015-04-15 19:21:00 +0000501 it('should be serializable to String', function () {
502 var docGroup = docGroupFactory.create();
503 expect(docGroup.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +0200504 'author = "Max Birkendale" & pubDate in 2014-12-05'
Nils Diewald7c8ced22015-04-15 19:21:00 +0000505 );
Nils Diewald52f7eb12015-01-12 17:30:04 +0000506
Nils Diewald7c8ced22015-04-15 19:21:00 +0000507 docGroup = docGroupFactory.create({
Akron712733a2018-04-05 18:17:47 +0200508 "@type" : "koral:docGroup",
509 "operation" : "operation:or",
510 "operands" : [
511 {
512 "@type": 'koral:doc',
513 "key" : 'author',
514 "match": 'match:eq',
515 "value": 'Max Birkendale',
516 "type": 'type:string'
517 },
518 {
519 "@type" : "koral:docGroup",
520 "operation" : "operation:and",
521 "operands" : [
522 {
523 "@type": 'koral:doc',
524 "key": 'pubDate',
525 "match": 'match:geq',
526 "value": '2014-05-12',
527 "type": 'type:date'
528 },
529 {
530 "@type": 'koral:doc',
531 "key": 'pubDate',
532 "match": 'match:leq',
533 "value": '2014-12-05',
534 "type": 'type:date'
535 },
536 {
537 "@type": 'koral:doc',
538 "key": 'foo',
539 "match": 'match:ne',
540 "value": '[a]?bar',
541 "type": 'type:regex'
542 }
543 ]
544 }
545 ]
Nils Diewald7c8ced22015-04-15 19:21:00 +0000546 });
547 expect(docGroup.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +0200548 'author = "Max Birkendale" | ' +
549 '(pubDate since 2014-05-12 & ' +
550 'pubDate until 2014-12-05 & foo != /[a]?bar/)'
Nils Diewald7c8ced22015-04-15 19:21:00 +0000551 );
552 });
553 });
554
555 describe('KorAP.UnspecifiedDoc', function () {
556 it('should be initializable', function () {
557 var doc = unspecifiedClass.create();
558 var docElement = doc.element();
559 expect(docElement.getAttribute('class')).toEqual('doc unspecified');
560 expect(docElement.firstChild.firstChild.data).toEqual('⋯');
561 expect(docElement.lastChild.lastChild.data).toEqual('⋯');
562 expect(doc.toQuery()).toEqual('');
563
564 // Only removable
565 expect(docElement.lastChild.children.length).toEqual(0);
566 });
567
568 it('should be removable, when no root', function () {
569 var docGroup = docGroupClass.create();
570 docGroup.operation('or');
571 expect(docGroup.operation()).toEqual('or');
572
573 docGroup.append({
Akron712733a2018-04-05 18:17:47 +0200574 "@type": 'koral:doc',
575 "key": 'pubDate',
576 "match": 'match:eq',
577 "value": '2014-12-05',
578 "type": 'type:date'
Nils Diewald7c8ced22015-04-15 19:21:00 +0000579 });
580
581 // Add unspecified object
582 docGroup.append();
583
584 expect(docGroup.element().getAttribute('class')).toEqual('docGroup');
585 expect(docGroup.element().children[0].getAttribute('class')).toEqual('doc');
586
587 var unspec = docGroup.element().children[1];
588 expect(unspec.getAttribute('class')).toEqual('doc unspecified');
589
590 // Removable
591 expect(unspec.lastChild.children.length).toEqual(1);
592 expect(unspec.lastChild.children[0].getAttribute('class')).toEqual('delete');
593 });
594
595 it('should be replaceable by a doc', function () {
596 var doc = unspecifiedClass.create();
597 expect(doc.ldType()).toEqual("non");
598 // No parent, therefor not updateable
599 expect(doc.key("baum")).toBeNull();
600
601 var docGroup = docGroupClass.create();
602 docGroup.operation('or');
603 expect(docGroup.operation()).toEqual('or');
604
605 docGroup.append({
Akron712733a2018-04-05 18:17:47 +0200606 "@type": 'koral:doc',
607 "key": 'pubDate',
608 "match": 'match:eq',
609 "value": '2014-12-05',
610 "type": 'type:date'
Nils Diewald7c8ced22015-04-15 19:21:00 +0000611 });
612
613 expect(docGroup.toQuery()).toEqual("pubDate in 2014-12-05");
614 docGroup.append();
615
616 expect(docGroup.getOperand(0).ldType()).toEqual("doc");
617 expect(docGroup.getOperand(1).ldType()).toEqual("non");
618
619 var op = docGroup.getOperand(1).element().lastChild;
Akron0b489ad2018-02-02 16:49:32 +0100620 expect(op.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +0000621 expect(op.children[0].getAttribute('class')).toEqual('delete');
622 expect(op.children.length).toEqual(1);
623
624 // Replace unspecified doc
625 expect(docGroup.getOperand(1).key("name")).not.toBeNull();
626 expect(docGroup.getOperand(1).ldType()).toEqual("doc");
627 expect(docGroup.getOperand(1).key()).toEqual("name");
Akron55a343b2018-04-06 19:57:36 +0200628 expect(docGroup.getOperand(1).value()).toBeUndefined();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000629
630 op = docGroup.getOperand(1).element().lastChild;
Akron0b489ad2018-02-02 16:49:32 +0100631 expect(op.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +0000632 expect(op.children[0].getAttribute('class')).toEqual('and');
633 expect(op.children[1].getAttribute('class')).toEqual('or');
634 expect(op.children[2].getAttribute('class')).toEqual('delete');
635 expect(op.children.length).toEqual(3);
636
637 docGroup.getOperand(1).value("Pachelbel");
638 expect(docGroup.getOperand(1).value()).toEqual("Pachelbel");
639 expect(docGroup.getOperand(1).type()).toEqual("string");
640 expect(docGroup.getOperand(1).matchop()).toEqual("eq");
641
642 // Specified!
643 expect(docGroup.toQuery()).toEqual('pubDate in 2014-12-05 | name = "Pachelbel"');
644 });
645
646 it('should be replaceable on root', function () {
Nils Diewald6283d692015-04-23 20:32:53 +0000647 var vc = vcClass.create();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000648 expect(vc.toQuery()).toEqual("");
649
650 expect(vc.root().ldType()).toEqual("non");
651
652 // No operators on root
653 op = vc.root().element().lastChild;
654 expect(op.lastChild.textContent).toEqual('⋯');
655
656 // Replace
657 expect(vc.root().key("baum")).not.toBeNull();
658 expect(vc.root().ldType()).toEqual("doc");
659
660 op = vc.root().element().lastChild;
Akron0b489ad2018-02-02 16:49:32 +0100661 expect(op.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +0000662 expect(op.children[0].getAttribute('class')).toEqual('and');
663 expect(op.children[1].getAttribute('class')).toEqual('or');
664 expect(op.children[2].getAttribute('class')).toEqual('delete');
665 expect(op.children.length).toEqual(3);
666 });
Akron55a343b2018-04-06 19:57:36 +0200667
668 it('should be clickable', function () {
669 var vc = vcClass.create([
670 ["pubDate", "date"]
671 ]);
672 expect(vc.toQuery()).toEqual("");
673 expect(vc.element().firstChild.textContent).toEqual("⋯");
674 vc.element().firstChild.firstChild.click();
675
676 // Click on pubDate
677 vc.element().firstChild.getElementsByTagName("LI")[0].click();
678
679 expect(vc.element().firstChild.firstChild.textContent).toEqual("pubDate");
680 expect(vc.element().firstChild.children[1].getAttribute("data-type")).toEqual("date");
681 });
Nils Diewald7c8ced22015-04-15 19:21:00 +0000682 });
683
684 describe('KorAP.Doc element', function () {
685 it('should be initializable', function () {
686 var docElement = docClass.create(undefined, {
Akron712733a2018-04-05 18:17:47 +0200687 "@type" : "koral:doc",
688 "key":"Titel",
689 "value":"Baum",
690 "match":"match:eq"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000691 });
692 expect(docElement.key()).toEqual('Titel');
693 expect(docElement.matchop()).toEqual('eq');
694 expect(docElement.value()).toEqual('Baum');
695
696 var docE = docElement.element();
697 expect(docE.children[0].firstChild.data).toEqual('Titel');
698 expect(docE.children[1].firstChild.data).toEqual('eq');
699 expect(docE.children[1].getAttribute('data-type')).toEqual('string');
700 expect(docE.children[2].firstChild.data).toEqual('Baum');
701 expect(docE.children[2].getAttribute('data-type')).toEqual('string');
702
703 expect(docElement.toJson()).toEqual(jasmine.objectContaining({
Akron712733a2018-04-05 18:17:47 +0200704 "@type" : "koral:doc",
705 "key":"Titel",
706 "value":"Baum",
707 "match":"match:eq"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000708 }));
709 });
710 });
711
712 describe('KorAP.DocGroup element', function () {
713 it('should be initializable', function () {
714
715 var docGroup = docGroupClass.create(undefined, {
Akron712733a2018-04-05 18:17:47 +0200716 "@type" : "koral:docGroup",
717 "operation" : "operation:and",
718 "operands" : [
719 {
720 "@type": 'koral:doc',
721 "key" : 'author',
722 "match": 'match:eq',
723 "value": 'Max Birkendale',
724 "type": 'type:string'
725 },
726 {
727 "@type": 'koral:doc',
728 "key": 'pubDate',
729 "match": 'match:eq',
730 "value": '2014-12-05',
731 "type": 'type:date'
732 }
733 ]
Nils Diewald7c8ced22015-04-15 19:21:00 +0000734 });
735
736 expect(docGroup.operation()).toEqual('and');
737 var e = docGroup.element();
738 expect(e.getAttribute('class')).toEqual('docGroup');
739 expect(e.getAttribute('data-operation')).toEqual('and');
740
741 var first = e.children[0];
742 expect(first.getAttribute('class')).toEqual('doc');
743 expect(first.children[0].getAttribute('class')).toEqual('key');
744 expect(first.children[1].getAttribute('class')).toEqual('match');
745 expect(first.children[2].getAttribute('class')).toEqual('value');
746 expect(first.children[2].getAttribute('data-type')).toEqual('string');
747 expect(first.children[0].firstChild.data).toEqual('author');
748 expect(first.children[1].firstChild.data).toEqual('eq');
749 expect(first.children[2].firstChild.data).toEqual('Max Birkendale');
750
751 var second = e.children[1];
752 expect(second.getAttribute('class')).toEqual('doc');
753 expect(second.children[0].getAttribute('class')).toEqual('key');
754 expect(second.children[1].getAttribute('class')).toEqual('match');
755 expect(second.children[2].getAttribute('class')).toEqual('value');
756 expect(second.children[2].getAttribute('data-type')).toEqual('date');
757 expect(second.children[0].firstChild.data).toEqual('pubDate');
758 expect(second.children[1].firstChild.data).toEqual('eq');
759 expect(second.children[2].firstChild.data).toEqual('2014-12-05');
760 });
761
762 it('should be deserializable with nested groups', function () {
763 var docGroup = docGroupClass.create(undefined, {
Akron712733a2018-04-05 18:17:47 +0200764 "@type" : "koral:docGroup",
765 "operation" : "operation:or",
766 "operands" : [
767 {
768 "@type": 'koral:doc',
769 "key" : 'author',
770 "match": 'match:eq',
771 "value": 'Max Birkendale',
772 "type": 'type:string'
773 },
774 {
775 "@type" : "koral:docGroup",
776 "operation" : "operation:and",
777 "operands" : [
778 {
779 "@type": 'koral:doc',
780 "key": 'pubDate',
781 "match": 'match:geq',
782 "value": '2014-05-12',
783 "type": 'type:date'
784 },
785 {
786 "@type": 'koral:doc',
787 "key": 'pubDate',
788 "match": 'match:leq',
789 "value": '2014-12-05',
790 "type": 'type:date'
791 }
792 ]
793 }
794 ]
Nils Diewald7c8ced22015-04-15 19:21:00 +0000795 });
796
797 expect(docGroup.operation()).toEqual('or');
798 var e = docGroup.element();
799 expect(e.getAttribute('class')).toEqual('docGroup');
800 expect(e.getAttribute('data-operation')).toEqual('or');
801
802 expect(e.children[0].getAttribute('class')).toEqual('doc');
803 var docop = e.children[0].lastChild;
Akron0b489ad2018-02-02 16:49:32 +0100804 expect(docop.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +0000805 expect(docop.children[0].getAttribute('class')).toEqual('and');
806 expect(docop.children[1].getAttribute('class')).toEqual('or');
807 expect(docop.children[2].getAttribute('class')).toEqual('delete');
808
809 expect(e.children[1].getAttribute('class')).toEqual('docGroup');
810 expect(e.children[1].getAttribute('data-operation')).toEqual('and');
811
812 // This and-operation can be "or"ed or "delete"d
813 var secop = e.children[1].children[2];
Akron0b489ad2018-02-02 16:49:32 +0100814 expect(secop.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +0000815 expect(secop.children[0].getAttribute('class')).toEqual('or');
816 expect(secop.children[1].getAttribute('class')).toEqual('delete');
817
818 // This or-operation can be "and"ed or "delete"d
Akron0b489ad2018-02-02 16:49:32 +0100819 expect(e.children[2].getAttribute('class')).toEqual('operators button-group');
820 expect(e.lastChild.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +0000821 expect(e.lastChild.children[0].getAttribute('class')).toEqual('and');
822 expect(e.lastChild.children[1].getAttribute('class')).toEqual('delete');
823 });
824 });
825
Akrone4961b12017-05-10 21:04:46 +0200826 describe('KorAP.VirtualCorpus', function () {
Nils Diewald7c8ced22015-04-15 19:21:00 +0000827 var simpleGroupFactory = buildFactory(docGroupClass, {
828 "@type" : "koral:docGroup",
829 "operation" : "operation:and",
830 "operands" : [
Akron712733a2018-04-05 18:17:47 +0200831 {
832 "@type": 'koral:doc',
833 "key" : 'author',
834 "match": 'match:eq',
835 "value": 'Max Birkendale',
836 "type": 'type:string'
837 },
838 {
839 "@type": 'koral:doc',
840 "key": 'pubDate',
841 "match": 'match:eq',
842 "value": '2014-12-05',
843 "type": 'type:date'
844 }
Nils Diewald7c8ced22015-04-15 19:21:00 +0000845 ]
846 });
847
848 var nestedGroupFactory = buildFactory(vcClass, {
849 "@type" : "koral:docGroup",
850 "operation" : "operation:or",
851 "operands" : [
Akron712733a2018-04-05 18:17:47 +0200852 {
853 "@type": 'koral:doc',
854 "key" : 'author',
855 "match": 'match:eq',
856 "value": 'Max Birkendale',
857 "type": 'type:string'
858 },
859 {
860 "@type" : "koral:docGroup",
861 "operation" : "operation:and",
862 "operands" : [
863 {
864 "@type": 'koral:doc',
865 "key": 'pubDate',
866 "match": 'match:geq',
867 "value": '2014-05-12',
868 "type": 'type:date'
869 },
870 {
871 "@type": 'koral:doc',
872 "key": 'pubDate',
873 "match": 'match:leq',
874 "value": '2014-12-05',
875 "type": 'type:date'
876 }
877 ]
878 }
Nils Diewald7c8ced22015-04-15 19:21:00 +0000879 ]
880 });
881
882 var flatGroupFactory = buildFactory(vcClass, {
883 "@type" : "koral:docGroup",
884 "operation" : "operation:and",
885 "operands" : [
Akron712733a2018-04-05 18:17:47 +0200886 {
887 "@type": 'koral:doc',
888 "key": 'pubDate',
889 "match": 'match:geq',
890 "value": '2014-05-12',
891 "type": 'type:date'
892 },
893 {
894 "@type": 'koral:doc',
895 "key": 'pubDate',
896 "match": 'match:leq',
897 "value": '2014-12-05',
898 "type": 'type:date'
899 },
900 {
901 "@type": 'koral:doc',
902 "key": 'foo',
903 "match": 'match:eq',
904 "value": 'bar',
905 "type": 'type:string'
906 }
Nils Diewald7c8ced22015-04-15 19:21:00 +0000907 ]
908 });
909
910 it('should be initializable', function () {
Nils Diewald6283d692015-04-23 20:32:53 +0000911 var vc = vcClass.create();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000912 expect(vc.element().getAttribute('class')).toEqual('vc');
913 expect(vc.root().element().getAttribute('class')).toEqual('doc unspecified');
914
915 // Not removable
916 expect(vc.root().element().lastChild.children.length).toEqual(0);
917 });
918
919 it('should be based on a doc', function () {
Nils Diewald6283d692015-04-23 20:32:53 +0000920 var vc = vcClass.create().fromJson({
Akron712733a2018-04-05 18:17:47 +0200921 "@type" : "koral:doc",
922 "key":"Titel",
923 "value":"Baum",
924 "match":"match:eq"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000925 });
926
927 expect(vc.element().getAttribute('class')).toEqual('vc');
928 expect(vc.root().element().getAttribute('class')).toEqual('doc');
929 expect(vc.root().key()).toEqual('Titel');
930 expect(vc.root().value()).toEqual('Baum');
931 expect(vc.root().matchop()).toEqual('eq');
932
933 var docE = vc.root().element();
934 expect(docE.children[0].firstChild.data).toEqual('Titel');
935 expect(docE.children[1].firstChild.data).toEqual('eq');
936 expect(docE.children[1].getAttribute('data-type')).toEqual('string');
937 expect(docE.children[2].firstChild.data).toEqual('Baum');
938 expect(docE.children[2].getAttribute('data-type')).toEqual('string');
939 });
940
941 it('should be based on a docGroup', function () {
Nils Diewald6283d692015-04-23 20:32:53 +0000942 var vc = vcClass.create().fromJson(simpleGroupFactory.create().toJson());
Nils Diewald7c8ced22015-04-15 19:21:00 +0000943
944 expect(vc.element().getAttribute('class')).toEqual('vc');
945 expect(vc.root().element().getAttribute('class')).toEqual('docGroup');
946 expect(vc.root().operation()).toEqual('and');
947
948 var docGroup = vc.root();
949
950 var first = docGroup.getOperand(0);
951 expect(first.key()).toEqual('author');
952 expect(first.value()).toEqual('Max Birkendale');
953 expect(first.matchop()).toEqual('eq');
954
955 var second = docGroup.getOperand(1);
956 expect(second.key()).toEqual('pubDate');
957 expect(second.value()).toEqual('2014-12-05');
958 expect(second.matchop()).toEqual('eq');
959 });
960
961
962 it('should be based on a nested docGroup', function () {
963 var vc = nestedGroupFactory.create();
964
965 expect(vc.element().getAttribute('class')).toEqual('vc');
966 expect(vc.element().firstChild.getAttribute('class')).toEqual('docGroup');
967 expect(vc.element().firstChild.children[0].getAttribute('class')).toEqual('doc');
968 var dg = vc.element().firstChild.children[1];
969 expect(dg.getAttribute('class')).toEqual('docGroup');
970 expect(dg.children[0].getAttribute('class')).toEqual('doc');
971 expect(dg.children[1].getAttribute('class')).toEqual('doc');
Akron0b489ad2018-02-02 16:49:32 +0100972 expect(dg.children[2].getAttribute('class')).toEqual('operators button-group');
973 expect(vc.element().firstChild.children[2].getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +0000974 });
975
976 it('should be modifiable by deletion in flat docGroups', function () {
977 var vc = flatGroupFactory.create();
978 var docGroup = vc.root();
979
980 expect(docGroup.element().getAttribute('class')).toEqual('docGroup');
981
982 var doc = docGroup.getOperand(1);
983 expect(doc.key()).toEqual("pubDate");
984 expect(doc.value()).toEqual("2014-12-05");
985
986 // Remove operand 1
987 expect(docGroup.delOperand(doc).update()).not.toBeUndefined();
988 expect(doc._element).toEqual(undefined);
989
990 doc = docGroup.getOperand(1);
991 expect(doc.key()).toEqual("foo");
992
993 // Remove operand 1
994 expect(docGroup.delOperand(doc).update()).not.toBeUndefined();
995 expect(doc._element).toEqual(undefined);
996
997 // Only one operand left ...
998 expect(docGroup.getOperand(1)).toBeUndefined();
999 // ... but there shouldn't be a group anymore at all!
1000 expect(docGroup.getOperand(0)).toBeUndefined();
1001
1002 var obj = vc.root();
1003 expect(obj.ldType()).toEqual("doc");
1004 expect(obj.key()).toEqual("pubDate");
1005 expect(obj.value()).toEqual("2014-05-12");
1006
1007 expect(obj.element().getAttribute('class')).toEqual('doc');
1008 });
1009
1010
1011 it('should be modifiable by deletion in nested docGroups (root case)', function () {
1012 var vc = nestedGroupFactory.create();
1013
1014 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001015 'author = "Max Birkendale" | (pubDate since 2014-05-12 & pubDate until 2014-12-05)'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001016 );
1017
1018 var docGroup = vc.root();
1019 expect(docGroup.ldType()).toEqual("docGroup");
1020 expect(docGroup.operation()).toEqual("or");
1021
1022 var doc = docGroup.getOperand(0);
1023 expect(doc.key()).toEqual("author");
1024 expect(doc.value()).toEqual("Max Birkendale");
1025
1026 docGroup = docGroup.getOperand(1);
1027 expect(docGroup.operation()).toEqual("and");
1028
1029 doc = docGroup.getOperand(0);
1030 expect(doc.key()).toEqual("pubDate");
1031 expect(doc.matchop()).toEqual("geq");
1032 expect(doc.value()).toEqual("2014-05-12");
1033 expect(doc.type()).toEqual("date");
1034
1035 doc = docGroup.getOperand(1);
1036 expect(doc.key()).toEqual("pubDate");
1037 expect(doc.matchop()).toEqual("leq");
1038 expect(doc.value()).toEqual("2014-12-05");
1039 expect(doc.type()).toEqual("date");
1040
1041 // Remove first operand so everything becomes root
1042 expect(
Akron712733a2018-04-05 18:17:47 +02001043 vc.root().delOperand(
1044 vc.root().getOperand(0)
1045 ).update().ldType()
Nils Diewald7c8ced22015-04-15 19:21:00 +00001046 ).toEqual("docGroup");
1047
1048 expect(vc.root().ldType()).toEqual("docGroup");
1049 expect(vc.root().operation()).toEqual("and");
1050 expect(vc.root().getOperand(0).ldType()).toEqual("doc");
1051
1052 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001053 'pubDate since 2014-05-12 & pubDate until 2014-12-05'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001054 );
1055 });
1056
1057 it('should be modifiable by deletion in nested docGroups (resolve group case)', function () {
1058 var vc = nestedGroupFactory.create();
1059
1060 // Get nested group
1061 var firstGroup = vc.root().getOperand(1);
1062 firstGroup.append(simpleGroupFactory.create({ "operation" : "operation:or" }));
1063
1064 // Structur is now:
1065 // or(doc, and(doc, doc, or(doc, doc)))
1066
1067 // Get nested or in and
1068 var orGroup = vc.root().getOperand(1).getOperand(2);
1069 expect(orGroup.ldType()).toEqual("docGroup");
1070 expect(orGroup.operation()).toEqual("or");
1071
1072 // Remove
1073 // Structur is now:
1074 // or(doc, and(doc, doc, doc)))
1075 expect(orGroup.delOperand(orGroup.getOperand(0)).update().operation()).toEqual("and");
1076 expect(vc.root().getOperand(1).operands().length).toEqual(3);
1077 });
1078
1079 it('should be modifiable by deletion in nested docGroups (identical group case)', function () {
1080 var vc = nestedGroupFactory.create();
1081
1082 // Get nested group
1083 var firstGroup = vc.root().getOperand(1);
1084 firstGroup.append(simpleGroupFactory.create({
Akron712733a2018-04-05 18:17:47 +02001085 "operation" : "operation:or"
Nils Diewald7c8ced22015-04-15 19:21:00 +00001086 }));
1087 var oldAuthor = firstGroup.getOperand(2).getOperand(0);
1088 oldAuthor.key("title");
1089 oldAuthor.value("Der Birnbaum");
1090
1091 // Structur is now:
1092 // or(doc, and(doc, doc, or(doc, doc)))
1093 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001094 'author = "Max Birkendale" | ' +
1095 '(pubDate since 2014-05-12 & ' +
1096 'pubDate until 2014-12-05 & ' +
1097 '(title = "Der Birnbaum" | ' +
1098 'pubDate in 2014-12-05))'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001099 );
1100
1101 var andGroup = vc.root().getOperand(1);
1102
1103 // Get leading docs in and
1104 var doc1 = andGroup.getOperand(0);
1105 expect(doc1.ldType()).toEqual("doc");
1106 expect(doc1.value()).toEqual("2014-05-12");
1107 var doc2 = andGroup.getOperand(1);
1108 expect(doc2.ldType()).toEqual("doc");
1109 expect(doc2.value()).toEqual("2014-12-05");
1110
1111 // Remove 2
1112 expect(
Akron712733a2018-04-05 18:17:47 +02001113 andGroup.delOperand(doc2).update().operation()
Nils Diewald7c8ced22015-04-15 19:21:00 +00001114 ).toEqual("and");
1115 // Structur is now:
1116 // or(doc, and(doc, or(doc, doc)))
1117
1118 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001119 'author = "Max Birkendale"' +
1120 ' | (pubDate since 2014-05-12 & ' +
1121 '(title = "Der Birnbaum" | pubDate in 2014-12-05))'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001122 );
1123
1124
1125 // Remove 1
1126 expect(andGroup.delOperand(doc1).update().operation()).toEqual("or");
1127 // Structur is now:
1128 // or(doc, doc, doc)
1129
1130 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001131 'author = "Max Birkendale" | title = "Der Birnbaum" | pubDate in 2014-12-05'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001132 );
1133 });
1134
1135 it('should be reducible to unspecification', function () {
1136 var vc = demoFactory.create();
1137
1138 expect(vc.toQuery()).toEqual(vc.root().toQuery());
1139 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001140 '(Titel = "Baum" & Veröffentlichungsort = "hihi" & ' +
1141 '(Titel = "Baum" | Veröffentlichungsort = "hihi")) ' +
1142 '| Untertitel ~ "huhu"');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001143 expect(vc.root().element().lastChild.children[0].firstChild.nodeValue).toEqual('and');
1144 expect(vc.root().element().lastChild.children[1].firstChild.nodeValue).toEqual('×');
1145 expect(vc.root().delOperand(vc.root().getOperand(0)).update()).not.toBeUndefined();
Akron712733a2018-04-05 18:17:47 +02001146 expect(vc.toQuery()).toEqual('Untertitel ~ "huhu"');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001147
1148 var lc = vc.root().element().lastChild;
1149 expect(lc.children[0].firstChild.nodeValue).toEqual('and');
1150 expect(lc.children[1].firstChild.nodeValue).toEqual('or');
1151 expect(lc.children[2].firstChild.nodeValue).toEqual('×');
1152
1153 // Clean everything
1154 vc.clean();
1155 expect(vc.toQuery()).toEqual('');
1156 });
1157
1158 it('should flatten on import', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00001159 var vc = vcClass.create().fromJson({
Akron712733a2018-04-05 18:17:47 +02001160 "@type":"koral:docGroup",
1161 "operation":"operation:or",
1162 "operands":[
1163 {
1164 "@type":"koral:docGroup",
1165 "operation":"operation:or",
1166 "operands":[
Nils Diewald7c8ced22015-04-15 19:21:00 +00001167 {
Akron712733a2018-04-05 18:17:47 +02001168 "@type":"koral:doc",
1169 "key":"Titel",
1170 "value":"Baum",
1171 "match":"match:eq"
Nils Diewald7c8ced22015-04-15 19:21:00 +00001172 },
1173 {
Akron712733a2018-04-05 18:17:47 +02001174 "@type":"koral:doc",
1175 "key":"Veröffentlichungsort",
1176 "value":"hihi",
1177 "match":"match:eq"
Nils Diewald7c8ced22015-04-15 19:21:00 +00001178 },
1179 {
Akron712733a2018-04-05 18:17:47 +02001180 "@type":"koral:docGroup",
1181 "operation":"operation:or",
1182 "operands":[
1183 {
1184 "@type":"koral:doc",
1185 "key":"Titel",
1186 "value":"Baum",
1187 "match":"match:eq"
1188 },
1189 {
1190 "@type":"koral:doc",
1191 "key":"Veröffentlichungsort",
1192 "value":"hihi",
1193 "match":"match:eq"
1194 }
1195 ]
Nils Diewald7c8ced22015-04-15 19:21:00 +00001196 }
Akron712733a2018-04-05 18:17:47 +02001197 ]
1198 },
1199 {
1200 "@type":"koral:doc",
1201 "key":"Untertitel",
1202 "value":"huhu",
1203 "match":"match:contains"
1204 }
1205 ]
Nils Diewald7c8ced22015-04-15 19:21:00 +00001206 });
Nils Diewaldfda29d92015-01-22 17:28:01 +00001207
Nils Diewald7c8ced22015-04-15 19:21:00 +00001208 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001209 'Titel = "Baum" | Veröffentlichungsort = "hihi" | Untertitel ~ "huhu"'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001210 );
Nils Diewald86dad5b2015-01-28 15:09:07 +00001211 });
Nils Diewald86dad5b2015-01-28 15:09:07 +00001212 });
1213
Nils Diewald7c8ced22015-04-15 19:21:00 +00001214 describe('KorAP.Operators', function () {
1215 it('should be initializable', function () {
1216 var op = operatorsClass.create(true, false, false);
1217 expect(op.and()).toBeTruthy();
1218 expect(op.or()).not.toBeTruthy();
1219 expect(op.del()).not.toBeTruthy();
1220
1221 op.and(false);
1222 expect(op.and()).not.toBeTruthy();
1223 expect(op.or()).not.toBeTruthy();
1224 expect(op.del()).not.toBeTruthy();
1225
1226 op.or(true);
1227 op.del(true);
1228 expect(op.and()).not.toBeTruthy();
1229 expect(op.or()).toBeTruthy();
1230 expect(op.del()).toBeTruthy();
1231
1232 var e = op.element();
Akron0b489ad2018-02-02 16:49:32 +01001233 expect(e.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001234 expect(e.children[0].getAttribute('class')).toEqual('or');
1235 expect(e.children[0].firstChild.data).toEqual('or');
1236 expect(e.children[1].getAttribute('class')).toEqual('delete');
1237 expect(e.children[1].firstChild.data).toEqual('×');
1238
1239 op.and(true);
1240 op.del(false);
1241 op.update();
1242
1243 e = op.element();
Akron0b489ad2018-02-02 16:49:32 +01001244 expect(e.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001245 expect(e.children[0].getAttribute('class')).toEqual('and');
1246 expect(e.children[0].firstChild.data).toEqual('and');
1247 expect(e.children[1].getAttribute('class')).toEqual('or');
1248 expect(e.children[1].firstChild.data).toEqual('or');
1249 });
1250 });
1251
1252 describe('KorAP._delete (event)', function () {
1253 var complexVCFactory = buildFactory(vcClass,{
1254 "@type": 'koral:docGroup',
1255 'operation' : 'operation:and',
1256 'operands' : [
Akron712733a2018-04-05 18:17:47 +02001257 {
1258 "@type": 'koral:doc',
1259 "key": 'pubDate',
1260 "match": 'match:eq',
1261 "value": '2014-12-05',
1262 "type": 'type:date'
1263 },
1264 {
1265 "@type" : 'koral:docGroup',
1266 'operation' : 'operation:or',
1267 'operands' : [
1268 {
1269 '@type' : 'koral:doc',
1270 'key' : 'title',
1271 'value' : 'Hello World!'
1272 },
1273 {
1274 '@type' : 'koral:doc',
1275 'key' : 'foo',
1276 'value' : 'bar'
1277 }
1278 ]
1279 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00001280 ]
1281 });
1282
1283 it('should clean on root docs', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00001284 var vc = vcClass.create().fromJson({
Akron712733a2018-04-05 18:17:47 +02001285 "@type": 'koral:doc',
1286 "key": 'pubDate',
1287 "match": 'match:eq',
1288 "value": '2014-12-05',
1289 "type": 'type:date'
Nils Diewald86dad5b2015-01-28 15:09:07 +00001290 });
Nils Diewald7c8ced22015-04-15 19:21:00 +00001291 expect(vc.root().toQuery()).toEqual('pubDate in 2014-12-05');
Akron0b489ad2018-02-02 16:49:32 +01001292 expect(vc.root().element().lastChild.getAttribute('class')).toEqual('operators button-group');
Nils Diewald86dad5b2015-01-28 15:09:07 +00001293
Nils Diewald7c8ced22015-04-15 19:21:00 +00001294 // Clean with delete from root
1295 expect(vc.root().element().lastChild.lastChild.getAttribute('class')).toEqual('delete');
1296 _delOn(vc.root());
1297 expect(vc.root().toQuery()).toEqual('');
1298 expect(vc.root().element().lastChild.lastChild.data).toEqual('⋯');
1299 });
Nils Diewald86dad5b2015-01-28 15:09:07 +00001300
Nils Diewald7c8ced22015-04-15 19:21:00 +00001301 it('should remove on nested docs', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00001302 var vc = vcClass.create().fromJson(
Akron712733a2018-04-05 18:17:47 +02001303 {
1304 "@type": 'koral:docGroup',
1305 'operation' : 'operation:and',
1306 'operands' : [
1307 {
1308 "@type": 'koral:doc',
1309 "key": 'pubDate',
1310 "match": 'match:eq',
1311 "value": '2014-12-05',
1312 "type": 'type:date'
1313 },
1314 {
1315 "@type" : 'koral:doc',
1316 'key' : 'foo',
1317 'value' : 'bar'
1318 }
1319 ]
1320 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00001321 );
1322
1323 // Delete with direct element access
1324 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar"');
1325 _delOn(vc.root().getOperand(0));
1326
1327 expect(vc.toQuery()).toEqual('foo = "bar"');
1328 expect(vc.root().ldType()).toEqual('doc');
1329 });
1330
1331 it('should clean on doc groups', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00001332 var vc = vcClass.create().fromJson(
Akron712733a2018-04-05 18:17:47 +02001333 {
1334 "@type": 'koral:docGroup',
1335 'operation' : 'operation:and',
1336 'operands' : [
1337 {
1338 "@type": 'koral:doc',
1339 "key": 'pubDate',
1340 "match": 'match:eq',
1341 "value": '2014-12-05',
1342 "type": 'type:date'
1343 },
1344 {
1345 "@type" : 'koral:doc',
1346 'key' : 'foo',
1347 'value' : 'bar'
1348 }
1349 ]
1350 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00001351 );
1352
1353 // Cleanwith direct element access
1354 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar"');
1355 _delOn(vc.root());
1356 expect(vc.toQuery()).toEqual('');
1357 expect(vc.root().ldType()).toEqual('non');
1358 });
1359
1360 it('should remove on nested doc groups (case of ungrouping 1)', function () {
1361 var vc = complexVCFactory.create();
1362
1363 // Delete with direct element access
1364 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001365 'pubDate in 2014-12-05 & (title = "Hello World!" | foo = "bar")'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001366 );
1367
1368 // Remove hello world:
1369 _delOn(vc.root().getOperand(1).getOperand(0));
1370 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar"');
1371 expect(vc.root().ldType()).toEqual('docGroup');
1372 });
1373
1374 it('should remove on nested doc groups (case of ungrouping 2)', function () {
1375 var vc = complexVCFactory.create();
1376
1377 // Delete with direct element access
1378 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001379 'pubDate in 2014-12-05 & (title = "Hello World!" | foo = "bar")'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001380 );
1381
1382 // Remove bar
1383 _delOn(vc.root().getOperand(1).getOperand(1));
1384 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & title = "Hello World!"');
1385 expect(vc.root().ldType()).toEqual('docGroup');
1386 expect(vc.root().operation()).toEqual('and');
1387 });
1388
1389 it('should remove on nested doc groups (case of root changing)', function () {
1390 var vc = complexVCFactory.create();
1391
1392 // Delete with direct element access
1393 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001394 'pubDate in 2014-12-05 & ' +
1395 '(title = "Hello World!" | foo = "bar")'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001396 );
1397
1398 // Remove bar
1399 _delOn(vc.root().getOperand(0));
1400 expect(vc.toQuery()).toEqual('title = "Hello World!" | foo = "bar"');
1401 expect(vc.root().ldType()).toEqual('docGroup');
1402 expect(vc.root().operation()).toEqual('or');
1403 });
1404
1405 it('should remove on nested doc groups (list flattening)', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00001406 var vc = vcClass.create().fromJson(
Akron712733a2018-04-05 18:17:47 +02001407 {
1408 "@type": 'koral:docGroup',
1409 'operation' : 'operation:or',
1410 'operands' : [
1411 {
1412 "@type": 'koral:doc',
1413 "key": 'pubDate',
1414 "match": 'match:eq',
1415 "value": '2014-12-05',
1416 "type": 'type:date'
1417 },
1418 {
1419 "@type" : 'koral:doc',
1420 'key' : 'foo',
1421 'value' : 'bar'
1422 },
1423 {
1424 "@type": 'koral:docGroup',
1425 'operation' : 'operation:and',
1426 'operands' : [
1427 {
1428 "@type": 'koral:doc',
1429 "key": 'pubDate',
1430 "match": 'match:eq',
1431 "value": '2014-12-05',
1432 "type": 'type:date'
1433 },
1434 {
1435 "@type" : 'koral:docGroup',
1436 'operation' : 'operation:or',
1437 'operands' : [
1438 {
1439 '@type' : 'koral:doc',
1440 'key' : 'title',
1441 'value' : 'Hello World!'
1442 },
1443 {
1444 '@type' : 'koral:doc',
1445 'key' : 'yeah',
1446 'value' : 'juhu'
1447 }
1448 ]
1449 }
1450 ]
1451 }
1452 ]
1453 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00001454 );
1455
1456 // Delete with direct element access
1457 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001458 'pubDate in 2014-12-05 | foo = "bar" | ' +
1459 '(pubDate in 2014-12-05 & ' +
1460 '(title = "Hello World!" | yeah = "juhu"))'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001461 );
1462
1463 expect(vc.root().ldType()).toEqual('docGroup');
1464 expect(vc.root().operation()).toEqual('or');
1465
1466 // Operands and operators
1467 expect(vc.element().firstChild.children.length).toEqual(4);
Akron0b489ad2018-02-02 16:49:32 +01001468 expect(vc.element().firstChild.lastChild.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001469
1470 // Remove inner group and flatten
1471 _delOn(vc.root().getOperand(2).getOperand(0));
1472
1473 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001474 'pubDate in 2014-12-05 | foo = "bar" | title = "Hello World!" | yeah = "juhu"'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001475 );
1476 expect(vc.root().ldType()).toEqual('docGroup');
1477 expect(vc.root().operation()).toEqual('or');
1478
1479 // Operands and operators
1480 expect(vc.element().firstChild.children.length).toEqual(5);
Akron0b489ad2018-02-02 16:49:32 +01001481 expect(vc.element().firstChild.lastChild.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001482 });
1483 });
1484
1485 describe('KorAP._add (event)', function () {
1486 var complexVCFactory = buildFactory(vcClass,{
1487 "@type": 'koral:docGroup',
1488 'operation' : 'operation:and',
1489 'operands' : [
Akron712733a2018-04-05 18:17:47 +02001490 {
1491 "@type": 'koral:doc',
1492 "key": 'pubDate',
1493 "match": 'match:eq',
1494 "value": '2014-12-05',
1495 "type": 'type:date'
1496 },
1497 {
1498 "@type" : 'koral:docGroup',
1499 'operation' : 'operation:or',
1500 'operands' : [
1501 {
1502 '@type' : 'koral:doc',
1503 'key' : 'title',
1504 'value' : 'Hello World!'
1505 },
1506 {
1507 '@type' : 'koral:doc',
1508 'key' : 'foo',
1509 'value' : 'bar'
1510 }
1511 ]
1512 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00001513 ]
1514 });
1515
1516 it('should add new unspecified doc with "and"', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00001517 var vc = vcClass.create().fromJson(
Akron712733a2018-04-05 18:17:47 +02001518 {
1519 "@type": 'koral:docGroup',
1520 'operation' : 'operation:and',
1521 'operands' : [
1522 {
1523 "@type": 'koral:doc',
1524 "key": 'pubDate',
1525 "match": 'match:eq',
1526 "value": '2014-12-05',
1527 "type": 'type:date'
1528 },
1529 {
1530 "@type" : 'koral:doc',
1531 'key' : 'foo',
1532 'value' : 'bar'
1533 }
1534 ]
1535 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00001536 );
1537
1538 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar"');
1539
1540 var fc = vc.element().firstChild;
1541 expect(fc.getAttribute('data-operation')).toEqual('and');
1542 expect(fc.children.length).toEqual(3);
Akron0b489ad2018-02-02 16:49:32 +01001543 expect(fc.lastChild.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001544 expect(fc.children[0].getAttribute('class')).toEqual('doc');
1545 expect(fc.children[1].getAttribute('class')).toEqual('doc');
1546
1547 // add with 'and' in the middle
1548 _andOn(vc.root().getOperand(0));
1549 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar"');
1550
1551 fc = vc.element().firstChild;
1552 expect(fc.getAttribute('data-operation')).toEqual('and');
1553 expect(fc.children.length).toEqual(4);
Akron0b489ad2018-02-02 16:49:32 +01001554 expect(fc.lastChild.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001555
1556 expect(fc.children[0].getAttribute('class')).toEqual('doc');
1557 expect(fc.children[1].getAttribute('class')).toEqual('doc unspecified');
1558 expect(fc.children[2].getAttribute('class')).toEqual('doc');
1559 });
1560
1561 it('should add new unspecified doc with "or"', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00001562 var vc = vcClass.create().fromJson(
Akron712733a2018-04-05 18:17:47 +02001563 {
1564 "@type": 'koral:docGroup',
1565 'operation' : 'operation:and',
1566 'operands' : [
1567 {
1568 "@type": 'koral:doc',
1569 "key": 'pubDate',
1570 "match": 'match:eq',
1571 "value": '2014-12-05',
1572 "type": 'type:date'
1573 },
1574 {
1575 "@type" : 'koral:doc',
1576 'key' : 'foo',
1577 'value' : 'bar'
1578 }
1579 ]
1580 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00001581 );
1582
1583 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar"');
1584
1585 var fc = vc.element().firstChild;
1586 expect(fc.children.length).toEqual(3);
Akron0b489ad2018-02-02 16:49:32 +01001587 expect(fc.lastChild.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001588 expect(fc.children[0].getAttribute('class')).toEqual('doc');
1589 expect(fc.children[1].getAttribute('class')).toEqual('doc');
1590
1591 // add with 'or' in the middle
1592 _orOn(vc.root().getOperand(0));
1593 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar"');
1594 fc = vc.element().firstChild;
1595
1596 expect(fc.getAttribute('data-operation')).toEqual('and');
1597 expect(fc.children.length).toEqual(3);
1598 expect(fc.children[0].getAttribute('class')).toEqual('docGroup');
1599 expect(fc.children[0].getAttribute('data-operation')).toEqual('or');
1600 expect(fc.children[1].getAttribute('class')).toEqual('doc');
Akron0b489ad2018-02-02 16:49:32 +01001601 expect(fc.children[2].getAttribute('class')).toEqual('operators button-group');
1602 expect(fc.lastChild.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001603
1604 fc = vc.element().firstChild.firstChild;
1605 expect(fc.children.length).toEqual(3);
1606 expect(fc.children[0].getAttribute('class')).toEqual('doc');
1607 expect(fc.children[1].getAttribute('class')).toEqual('doc unspecified');
Akron0b489ad2018-02-02 16:49:32 +01001608 expect(fc.children[2].getAttribute('class')).toEqual('operators button-group');
1609 expect(fc.lastChild.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001610 });
1611
1612 it('should add new unspecified doc with "and" before group', function () {
1613 var vc = demoFactory.create();
1614
1615 // Wrap with direct element access
1616 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001617 '(Titel = "Baum" & ' +
1618 'Veröffentlichungsort = "hihi" & ' +
1619 '(Titel = "Baum" | ' +
1620 'Veröffentlichungsort = "hihi")) | ' +
1621 'Untertitel ~ "huhu"'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001622 );
1623
1624 expect(vc.root().getOperand(0).ldType()).toEqual('docGroup');
1625 expect(vc.root().getOperand(0).operation()).toEqual('and');
1626 expect(vc.root().getOperand(0).operands().length).toEqual(3);
1627
1628 // Add unspecified on the second doc
1629 var secDoc = vc.root().getOperand(0).getOperand(1);
1630 expect(secDoc.value()).toEqual('hihi');
1631
1632 // Add
1633 _andOn(secDoc);
1634
1635 var fo = vc.root().getOperand(0);
1636
1637 expect(fo.ldType()).toEqual('docGroup');
1638 expect(fo.operation()).toEqual('and');
1639 expect(fo.operands().length).toEqual(4);
1640
1641 expect(fo.getOperand(0).ldType()).toEqual('doc');
1642 expect(fo.getOperand(1).ldType()).toEqual('doc');
1643 expect(fo.getOperand(2).ldType()).toEqual('non');
1644 expect(fo.getOperand(3).ldType()).toEqual('docGroup');
1645 });
1646
1647
1648 it('should remove a doc with an unspecified doc in a nested group', function () {
1649 var vc = demoFactory.create();
1650
1651 // Wrap with direct element access
1652 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001653 '(Titel = "Baum" & Veröffentlichungsort = "hihi" & (Titel = "Baum" | Veröffentlichungsort = "hihi")) | Untertitel ~ "huhu"'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001654 );
1655
1656 var fo = vc.root().getOperand(0).getOperand(0);
1657 expect(fo.key()).toEqual('Titel');
1658 expect(fo.value()).toEqual('Baum');
1659
1660 // Add unspecified on the root group
1661 _orOn(fo);
1662
1663 fo = vc.root().getOperand(0).getOperand(0);
1664
1665 expect(fo.operation()).toEqual('or');
1666 expect(fo.getOperand(0).ldType()).toEqual('doc');
1667 expect(fo.getOperand(1).ldType()).toEqual('non');
1668
1669 // Delete document
1670 _delOn(fo.getOperand(0));
1671
1672 // The operand is now non
1673 expect(vc.root().getOperand(0).getOperand(0).ldType()).toEqual('non');
1674 expect(vc.root().getOperand(0).getOperand(1).ldType()).toEqual('doc');
1675 expect(vc.root().getOperand(0).getOperand(2).ldType()).toEqual('docGroup');
1676 });
1677
1678
Akron712733a2018-04-05 18:17:47 +02001679 it('should remove an unspecified doc with a doc in a nested group', function () {
Nils Diewald7c8ced22015-04-15 19:21:00 +00001680 var vc = demoFactory.create();
1681
1682 // Wrap with direct element access
1683 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001684 '(Titel = "Baum" & ' +
1685 'Veröffentlichungsort = "hihi" & ' +
1686 '(Titel = "Baum" ' +
1687 '| Veröffentlichungsort = "hihi")) | ' +
1688 'Untertitel ~ "huhu"'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001689 );
1690
1691 var fo = vc.root().getOperand(0).getOperand(0);
1692 expect(fo.key()).toEqual('Titel');
1693 expect(fo.value()).toEqual('Baum');
1694
1695 // Add unspecified on the root group
1696 _orOn(fo);
1697
1698 fo = vc.root().getOperand(0).getOperand(0);
1699
1700 expect(fo.operation()).toEqual('or');
1701 expect(fo.getOperand(0).ldType()).toEqual('doc');
1702 expect(fo.getOperand(1).ldType()).toEqual('non');
1703
1704 // Delete unspecified doc
1705 _delOn(fo.getOperand(1));
1706
1707 // The operand is now non
1708 fo = vc.root().getOperand(0);
1709 expect(fo.getOperand(0).ldType()).toEqual('doc');
1710 expect(fo.getOperand(0).key()).toEqual('Titel');
1711 expect(fo.getOperand(0).value()).toEqual('Baum');
1712 expect(fo.getOperand(1).ldType()).toEqual('doc');
1713 expect(fo.getOperand(2).ldType()).toEqual('docGroup');
1714 });
1715
1716
1717 it('should add on parent group (case "and")', function () {
1718 var vc = complexVCFactory.create();
1719
1720 // Wrap with direct element access
1721 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001722 'pubDate in 2014-12-05 & (title = "Hello World!" | foo = "bar")'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001723 );
1724
1725 expect(vc.root().operands().length).toEqual(2);
1726
1727 // Add unspecified on the root group
1728 _andOn(vc.root().getOperand(1));
1729 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001730 'pubDate in 2014-12-05 & (title = "Hello World!" | foo = "bar")'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001731 );
1732
1733 expect(vc.root().ldType()).toEqual('docGroup');
1734 expect(vc.root().operands().length).toEqual(3);
1735 expect(vc.root().getOperand(0).ldType()).toEqual('doc');
1736 expect(vc.root().getOperand(1).ldType()).toEqual('docGroup');
1737 expect(vc.root().getOperand(1).operation()).toEqual('or');
1738 expect(vc.root().getOperand(2).ldType()).toEqual('non');
1739
1740 // Add another unspecified on the root group
1741 _andOn(vc.root().getOperand(1));
1742
1743 expect(vc.root().operands().length).toEqual(4);
1744 expect(vc.root().getOperand(0).ldType()).toEqual('doc');
1745 expect(vc.root().getOperand(1).ldType()).toEqual('docGroup');
1746 expect(vc.root().getOperand(2).ldType()).toEqual('non');
1747 expect(vc.root().getOperand(3).ldType()).toEqual('non');
1748
1749 // Add another unspecified after the first doc
1750 _andOn(vc.root().getOperand(0));
1751
1752 expect(vc.root().operands().length).toEqual(5);
1753 expect(vc.root().getOperand(0).ldType()).toEqual('doc');
1754 expect(vc.root().getOperand(1).ldType()).toEqual('non');
1755 expect(vc.root().getOperand(2).ldType()).toEqual('docGroup');
1756 expect(vc.root().getOperand(3).ldType()).toEqual('non');
1757 expect(vc.root().getOperand(4).ldType()).toEqual('non');
1758 });
1759
1760 it('should wrap on root', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00001761 var vc = vcClass.create().fromJson(
Akron712733a2018-04-05 18:17:47 +02001762 {
1763 "@type": 'koral:docGroup',
1764 'operation' : 'operation:and',
1765 'operands' : [
1766 {
1767 "@type": 'koral:doc',
1768 "key": 'pubDate',
1769 "match": 'match:eq',
1770 "value": '2014-12-05',
1771 "type": 'type:date'
1772 },
1773 {
1774 "@type" : 'koral:doc',
1775 'key' : 'foo',
1776 'value' : 'bar'
1777 }
1778 ]
1779 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00001780 );
1781
1782 // Wrap on root
1783 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar"');
1784 expect(vc.root().ldType()).toEqual('docGroup');
1785 expect(vc.root().operation()).toEqual('and');
1786 _orOn(vc.root());
1787 expect(vc.root().ldType()).toEqual('docGroup');
1788 expect(vc.root().operation()).toEqual('or');
1789
1790 expect(vc.root().getOperand(0).ldType()).toEqual('docGroup');
1791 expect(vc.root().getOperand(0).operation()).toEqual('and');
1792 });
1793
1794 it('should add on root (case "and")', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00001795 var vc = vcClass.create().fromJson(
Akron712733a2018-04-05 18:17:47 +02001796 {
1797 "@type": 'koral:doc',
1798 "key": 'pubDate',
1799 "match": 'match:eq',
1800 "value": '2014-12-05',
1801 "type": 'type:date'
1802 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00001803 );
1804
1805 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05');
1806 expect(vc.root().ldType()).toEqual('doc');
1807 expect(vc.root().key()).toEqual('pubDate');
1808 expect(vc.root().value()).toEqual('2014-12-05');
1809
1810 // Wrap on root
1811 _andOn(vc.root());
1812 expect(vc.root().ldType()).toEqual('docGroup');
1813 expect(vc.root().operation()).toEqual('and');
1814 });
1815
1816 it('should add on root (case "or")', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00001817 var vc = vcClass.create().fromJson(
Akron712733a2018-04-05 18:17:47 +02001818 {
1819 "@type": 'koral:doc',
1820 "key": 'pubDate',
1821 "match": 'match:eq',
1822 "value": '2014-12-05',
1823 "type": 'type:date'
1824 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00001825 );
1826
1827 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05');
1828 expect(vc.root().key()).toEqual('pubDate');
1829 expect(vc.root().value()).toEqual('2014-12-05');
1830
1831 // Wrap on root
1832 _orOn(vc.root());
1833 expect(vc.root().ldType()).toEqual('docGroup');
1834 expect(vc.root().operation()).toEqual('or');
1835 });
1836
1837 it('should support multiple sub groups per group', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00001838 var vc = vcClass.create().fromJson(
Akron712733a2018-04-05 18:17:47 +02001839 {
1840 "@type": 'koral:docGroup',
1841 'operation' : 'operation:or',
1842 'operands' : [
1843 {
1844 "@type": 'koral:docGroup',
1845 'operation' : 'operation:and',
1846 'operands' : [
1847 {
1848 "@type": 'koral:doc',
1849 "key": 'title',
1850 "value": 't1',
1851 },
1852 {
1853 "@type" : 'koral:doc',
1854 'key' : 'title',
1855 'value' : 't2'
1856 }
1857 ]
1858 },
1859 {
1860 "@type": 'koral:docGroup',
1861 'operation' : 'operation:and',
1862 'operands' : [
1863 {
1864 "@type": 'koral:doc',
1865 "key": 'title',
1866 "value": 't3',
1867 },
1868 {
1869 "@type" : 'koral:doc',
1870 'key' : 'title',
1871 'value' : 't4'
1872 }
1873 ]
1874 }
1875 ]
1876 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00001877 );
1878 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001879 '(title = "t1" & title = "t2") | ' +
1880 '(title = "t3" & title = "t4")'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001881 );
1882 expect(vc.root().operation()).toEqual('or');
1883 expect(vc.root().getOperand(0).toQuery()).toEqual('title = "t1" & title = "t2"');
1884 expect(vc.root().getOperand(1).toQuery()).toEqual('title = "t3" & title = "t4"');
1885
1886 _andOn(vc.root());
1887
1888 expect(vc.root().operation()).toEqual('and');
1889 expect(vc.root().getOperand(0).ldType()).toEqual('docGroup');
1890 expect(vc.root().getOperand(1).ldType()).toEqual('non');
1891 });
1892 });
1893
Akron5c829e92017-05-12 18:10:00 +02001894 // Check class method
1895 describe('KorAP.VC.checkRewrite', function () {
1896
1897 it('should check for simple rewrites', function () {
1898 expect(vcClass.checkRewrite(
1899 {
1900 "@type" : "koral:doc",
1901 "rewrites" : [{
Akron712733a2018-04-05 18:17:47 +02001902 "@type" : "koral:rewrite",
1903 "operation" : "operation:modification",
1904 "src" : "querySerializer",
1905 "scope" : "tree"
Akron5c829e92017-05-12 18:10:00 +02001906 }]
1907 }
1908 )).toBeTruthy();
Nils Diewald7c8ced22015-04-15 19:21:00 +00001909
Akron5c829e92017-05-12 18:10:00 +02001910 var nested = {
1911 "@type" : "koral:docGroup",
1912 "operands" : [
1913 {
1914 "@type" : "koral:doc"
1915 },
1916 {
1917 "@type" : "koral:docGroup",
1918 "operands" : [
1919 {
1920 "@type": "koral:doc"
1921 },
1922 {
1923 "@type": "koral:doc"
1924 }
1925 ]
1926 }
1927 ]
1928 };
1929
1930 expect(vcClass.checkRewrite(nested)).toBe(false);
1931
1932 nested["operands"][1]["operands"][1]["rewrites"] = [{
Akron712733a2018-04-05 18:17:47 +02001933 "@type" : "koral:rewrite",
1934 "operation" : "operation:modification",
1935 "src" : "querySerializer",
1936 "scope" : "tree"
Akron5c829e92017-05-12 18:10:00 +02001937 }];
1938
1939 expect(vcClass.checkRewrite(nested)).toBeTruthy();
1940 });
1941 });
Nils Diewald6283d692015-04-23 20:32:53 +00001942
1943 describe('KorAP.Rewrite', function () {
Nils Diewald7c8ced22015-04-15 19:21:00 +00001944 it('should be initializable', function () {
1945 var rewrite = rewriteClass.create({
Akron712733a2018-04-05 18:17:47 +02001946 "@type" : "koral:rewrite",
1947 "operation" : "operation:modification",
1948 "src" : "querySerializer",
1949 "scope" : "tree"
Nils Diewald86dad5b2015-01-28 15:09:07 +00001950 });
Nils Diewald7c8ced22015-04-15 19:21:00 +00001951 expect(rewrite.toString()).toEqual('Modification of "tree" by "querySerializer"');
1952 });
Nils Diewald86dad5b2015-01-28 15:09:07 +00001953
Nils Diewald7c8ced22015-04-15 19:21:00 +00001954 it('should be deserialized by docs', function () {
1955 var doc = docClass.create(
Akron712733a2018-04-05 18:17:47 +02001956 undefined,
1957 {
1958 "@type":"koral:doc",
1959 "key":"Titel",
1960 "value":"Baum",
1961 "match":"match:eq"
1962 });
Nils Diewald7c8ced22015-04-15 19:21:00 +00001963
1964 expect(doc.element().classList.contains('doc')).toBeTruthy();
1965 expect(doc.element().classList.contains('rewritten')).toBe(false);
1966
1967 doc = docClass.create(
Akron712733a2018-04-05 18:17:47 +02001968 undefined,
1969 {
1970 "@type":"koral:doc",
1971 "key":"Titel",
1972 "value":"Baum",
1973 "match":"match:eq",
1974 "rewrites" : [
1975 {
1976 "@type" : "koral:rewrite",
1977 "operation" : "operation:modification",
1978 "src" : "querySerializer",
1979 "scope" : "tree"
1980 }
1981 ]
1982 });
Nils Diewald7c8ced22015-04-15 19:21:00 +00001983
1984 expect(doc.element().classList.contains('doc')).toBeTruthy();
1985 expect(doc.element().classList.contains('rewritten')).toBeTruthy();
1986 });
Nils Diewald6283d692015-04-23 20:32:53 +00001987
1988 xit('should be deserialized by docGroups', function () {
1989 var docGroup = docGroupClass.create(
Akron712733a2018-04-05 18:17:47 +02001990 undefined,
1991 {
1992 "@type" : "koral:docGroup",
1993 "operation" : "operation:or",
1994 "operands" : [
1995 {
1996 "@type" : "doc",
1997 "key" : "pubDate",
1998 "type" : "type:date",
1999 "value" : "2014-12-05"
2000 },
2001 {
2002 "@type" : "doc",
2003 "key" : "pubDate",
2004 "type" : "type:date",
2005 "value" : "2014-12-06"
2006 }
2007 ],
2008 "rewrites" : [
2009 {
2010 "@type" : "koral:rewrite",
2011 "operation" : "operation:modification",
2012 "src" : "querySerializer",
2013 "scope" : "tree"
2014 }
2015 ]
2016 }
Nils Diewald6283d692015-04-23 20:32:53 +00002017 );
2018
2019 expect(doc.element().classList.contains('docgroup')).toBeTruthy();
2020 expect(doc.element().classList.contains('rewritten')).toBe(false);
2021 });
Nils Diewald86dad5b2015-01-28 15:09:07 +00002022 });
Nils Diewaldf0c4f112015-05-05 12:56:59 +00002023
2024 describe('KorAP.stringValue', function () {
2025 it('should be initializable', function () {
2026 var sv = stringValClass.create();
2027 expect(sv.regex()).toBe(false);
2028 expect(sv.value()).toBe('');
Nils Diewaldc4c4b832015-05-05 16:00:08 +00002029
2030 sv = stringValClass.create('Baum');
2031 expect(sv.regex()).toBe(false);
2032 expect(sv.value()).toBe('Baum');
2033
2034 sv = stringValClass.create('Baum', false);
2035 expect(sv.regex()).toBe(false);
2036 expect(sv.value()).toBe('Baum');
2037
2038 sv = stringValClass.create('Baum', true);
2039 expect(sv.regex()).toBe(true);
2040 expect(sv.value()).toBe('Baum');
2041 });
2042
2043 it('should be modifiable', function () {
2044 var sv = stringValClass.create();
2045 expect(sv.regex()).toBe(false);
2046 expect(sv.value()).toBe('');
2047
2048 expect(sv.value('Baum')).toBe('Baum');
2049 expect(sv.value()).toBe('Baum');
2050
2051 expect(sv.regex(true)).toBe(true);
2052 expect(sv.regex()).toBe(true);
2053 });
2054
2055 it('should have a toggleble regex value', function () {
2056 var sv = stringValClass.create();
Nils Diewald7991a3f2015-05-19 14:12:37 +00002057
2058 expect(sv.element().firstChild.value).toBe('');
2059 sv.element().firstChild.value = 'der'
2060 expect(sv.element().firstChild.value).toBe('der');
2061
Nils Diewaldc4c4b832015-05-05 16:00:08 +00002062 expect(sv.regex()).toBe(false);
2063
2064 sv.toggleRegex();
Nils Diewald7991a3f2015-05-19 14:12:37 +00002065 expect(sv.element().firstChild.value).toBe('der');
Nils Diewaldc4c4b832015-05-05 16:00:08 +00002066 expect(sv.regex()).toBe(true);
Nils Diewald7991a3f2015-05-19 14:12:37 +00002067 sv.element().firstChild.value = 'derbe'
Nils Diewaldc4c4b832015-05-05 16:00:08 +00002068
2069 sv.toggleRegex();
2070 expect(sv.regex()).toBe(false);
Nils Diewald7991a3f2015-05-19 14:12:37 +00002071 expect(sv.element().firstChild.value).toBe('derbe');
Nils Diewaldc4c4b832015-05-05 16:00:08 +00002072 });
2073
2074 it('should have an element', function () {
2075 var sv = stringValClass.create('der');
2076 expect(sv.element().nodeName).toBe('DIV');
2077 expect(sv.element().firstChild.nodeName).toBe('INPUT');
2078 expect(sv.element().firstChild.value).toBe('der');
2079 });
2080
2081 it('should have a classed element', function () {
2082 var sv = stringValClass.create();
Nils Diewaldc4c4b832015-05-05 16:00:08 +00002083 expect(sv.element().classList.contains('regex')).toBe(false);
2084 expect(sv.regex()).toBe(false);
2085 sv.toggleRegex();
2086 expect(sv.element().classList.contains('regex')).toBe(true);
2087 });
2088
2089 it('should be storable', function () {
2090 var sv = stringValClass.create();
2091 var count = 1;
2092 sv.store = function (value, regex) {
Akron712733a2018-04-05 18:17:47 +02002093 expect(regex).toBe(true);
2094 expect(value).toBe('tree');
Nils Diewaldc4c4b832015-05-05 16:00:08 +00002095 };
2096 sv.regex(true);
2097 sv.value('tree');
2098 sv.element().lastChild.click();
Nils Diewaldf0c4f112015-05-05 12:56:59 +00002099 });
Akron712733a2018-04-05 18:17:47 +02002100
Nils Diewaldf0c4f112015-05-05 12:56:59 +00002101 });
Akrone4961b12017-05-10 21:04:46 +02002102
Akron712733a2018-04-05 18:17:47 +02002103 describe('KorAP.VC.Menu', function () {
Akrone65a88a2018-04-05 19:14:20 +02002104
2105 var vc;
2106
Akron712733a2018-04-05 18:17:47 +02002107 it('should be initializable', function () {
2108
Akrone65a88a2018-04-05 19:14:20 +02002109 vc = vcClass.create([
Akron712733a2018-04-05 18:17:47 +02002110 ['a', 'text'],
2111 ['b', 'string'],
2112 ['c', 'date']
2113 ]).fromJson();
2114 expect(vc.element().firstChild.classList.contains('unspecified')).toBeTruthy();
2115 expect(vc.element().firstChild.firstChild.tagName).toEqual('SPAN');
2116
2117 // Click on unspecified
2118 vc.element().firstChild.firstChild.click();
2119 expect(vc.element().firstChild.firstChild.tagName).toEqual('UL');
2120
2121 var list = vc.element().firstChild.firstChild;
2122 expect(list.getElementsByTagName("LI")[0].innerText).toEqual('a');
2123 expect(list.getElementsByTagName("LI")[1].innerText).toEqual('b');
2124 expect(list.getElementsByTagName("LI")[2].innerText).toEqual('c');
2125
2126 vc = vcClass.create([
2127 ['d', 'text'],
2128 ['e', 'string'],
2129 ['f', 'date']
2130 ]).fromJson();
2131 expect(vc.element().firstChild.classList.contains('unspecified')).toBeTruthy();
2132 expect(vc.element().firstChild.firstChild.tagName).toEqual('SPAN');
2133
2134 // Click on unspecified
2135 vc.element().firstChild.firstChild.click();
2136 expect(vc.element().firstChild.firstChild.tagName).toEqual('UL');
2137
2138 list = vc.element().firstChild.firstChild;
2139 expect(list.getElementsByTagName("LI")[0].innerText).toEqual('d');
2140 expect(list.getElementsByTagName("LI")[1].innerText).toEqual('e');
2141 expect(list.getElementsByTagName("LI")[2].innerText).toEqual('f');
Akron31d89942018-04-06 16:44:51 +02002142 // blur
2143 document.body.click();
Akron712733a2018-04-05 18:17:47 +02002144 });
Akrone65a88a2018-04-05 19:14:20 +02002145
2146 // Reinitialize to make tests stable
2147 vc = vcClass.create([
2148 ['d', 'text'],
2149 ['e', 'string'],
2150 ['f', 'date']
2151 ]).fromJson();
2152
2153 it('should be clickable on key', function () {
Akron31d89942018-04-06 16:44:51 +02002154 // Click on unspecified
2155 vc.element().firstChild.firstChild.click();
Akrone65a88a2018-04-05 19:14:20 +02002156 // Click on "d"
2157 vc.element().firstChild.firstChild.getElementsByTagName("LI")[0].click();
2158 expect(vc.element().firstChild.firstChild.tagName).toEqual('SPAN');
2159 expect(vc.element().firstChild.firstChild.innerText).toEqual('d');
2160 expect(vc.element().firstChild.children[1].innerText).toEqual('eq');
2161 expect(vc.element().firstChild.children[1].getAttribute('data-type')).toEqual('text');
Akron31d89942018-04-06 16:44:51 +02002162 // blur
2163 document.body.click();
Akrone65a88a2018-04-05 19:14:20 +02002164 });
2165
Akron31d89942018-04-06 16:44:51 +02002166 it('should be clickable on operation for text', function () {
2167 // Click on "d" (or unspecified)
2168 vc.element().firstChild.firstChild.click();
2169
2170 // Choose "d"
2171 vc.element().firstChild.firstChild.getElementsByTagName("LI")[0].click();
2172
2173 // Click on matchop
Akrone65a88a2018-04-05 19:14:20 +02002174 vc.element().firstChild.children[1].click();
Akron31d89942018-04-06 16:44:51 +02002175
Akrone65a88a2018-04-05 19:14:20 +02002176 expect(vc.element().firstChild.children[1].tagName).toEqual('UL');
Akron31d89942018-04-06 16:44:51 +02002177
Akrone65a88a2018-04-05 19:14:20 +02002178 var ul = vc.element().firstChild.children[1];
2179 expect(ul.getElementsByTagName('li')[0].innerText).toEqual("eq");
2180 expect(ul.getElementsByTagName('li')[1].innerText).toEqual("ne");
2181 expect(ul.getElementsByTagName('li')[2].innerText).toEqual("contains");
2182 expect(ul.getElementsByTagName('li')[3].innerText).toEqual("containsnot");
2183 expect(ul.getElementsByTagName('li')[4]).toBeUndefined();
Akron31d89942018-04-06 16:44:51 +02002184
2185 // Choose "contains"
2186 ul.getElementsByTagName('li')[2].click();
2187 expect(vc.element().firstChild.children[1].tagName).toEqual("SPAN");
2188 expect(vc.element().firstChild.children[1].innerText).toEqual("contains");
2189 // blur
2190 document.body.click();
Akrone65a88a2018-04-05 19:14:20 +02002191 })
Akron31d89942018-04-06 16:44:51 +02002192
2193 it('should be clickable on operation for string', function () {
2194 // Click on "d" (or unspecified)
2195 vc.element().firstChild.firstChild.click();
2196
2197 // Choose "e"
2198 vc.element().firstChild.firstChild.getElementsByTagName("LI")[1].click();
2199
2200 // As a consequence the matchoperator may no longer
2201 // be valid and needs to be re-evaluated
2202 var fc = vc.element().firstChild;
2203 expect(fc.firstChild.tagName).toEqual('SPAN');
2204 expect(fc.firstChild.innerText).toEqual('e');
2205 expect(fc.children[1].innerText).toEqual('eq');
2206 expect(fc.children[1].getAttribute('data-type')).toEqual('string');
2207
2208 vc.element().firstChild.children[1].click();
2209
2210 expect(vc.element().firstChild.children[1].tagName).toEqual('UL');
2211
2212 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]).toBeUndefined();
2216
2217 // Choose "ne"
2218 ul.getElementsByTagName('li')[1].click();
2219 expect(vc.element().firstChild.children[1].tagName).toEqual("SPAN");
2220 expect(vc.element().firstChild.children[1].innerText).toEqual("ne");
2221 // blur
2222 document.body.click();
2223 });
2224
2225 it('should be clickable on operation for date', function () {
2226
2227 // Replay matchop check - so it's guaranteed that "ne" is chosen
2228 // Click on "e" (or unspecified)
2229 vc.element().firstChild.firstChild.click();
2230 // Rechoose "e"
2231 vc.element().firstChild.firstChild.getElementsByTagName("LI")[1].click();
2232 // Click on matchop
2233 vc.element().firstChild.children[1].click();
2234 // Choose "ne"
2235 vc.element().firstChild.children[1].getElementsByTagName('li')[1].click();
2236 expect(vc.element().firstChild.children[1].innerText).toEqual("ne");
2237
2238 // Click on "e"
2239 vc.element().firstChild.firstChild.click();
2240 // Choose "f"
2241 vc.element().firstChild.firstChild.getElementsByTagName("LI")[2].click();
2242
2243 // The matchoperator should still be "ne" as this is valid for dates as well (now)
2244 var fc = vc.element().firstChild;
2245 expect(fc.firstChild.tagName).toEqual('SPAN');
2246 expect(fc.firstChild.innerText).toEqual('f');
2247 expect(fc.children[1].innerText).toEqual('ne');
2248 // blur
2249 document.body.click();
2250 });
Akronddc98a72018-04-06 17:33:52 +02002251
2252
2253 // Check json deserialization
2254 it('should be initializable', function () {
2255 vc = vcClass.create([
2256 ['a', 'text'],
2257 ['b', 'string'],
2258 ['c', 'date']
2259 ]).fromJson({
2260 "@type" : "koral:doc",
2261 "key":"a",
2262 "value":"Baum"
2263 });
2264
2265 expect(vc.element().firstChild.children[1].getAttribute('data-type')).toEqual('text');
2266 });
Akron712733a2018-04-05 18:17:47 +02002267 });
2268
2269
Akrone4961b12017-05-10 21:04:46 +02002270 // Check prefix
2271 describe('KorAP.VC.Prefix', function () {
2272
2273 it('should be initializable', function () {
2274 var p = prefixClass.create();
2275 expect(p.element().classList.contains('pref')).toBeTruthy();
2276 expect(p.isSet()).not.toBeTruthy();
2277 });
2278
2279
2280 it('should be clickable', function () {
2281 var vc = vcClass.create([
Akron712733a2018-04-05 18:17:47 +02002282 ['a', null],
2283 ['b', null],
2284 ['c', null]
2285 ]).fromJson();
Akrone4961b12017-05-10 21:04:46 +02002286 expect(vc.element().firstChild.classList.contains('unspecified')).toBeTruthy();
2287
2288 // This should open up the menu
2289 vc.element().firstChild.firstChild.click();
2290 expect(vc.element().firstChild.firstChild.tagName).toEqual('UL');
2291
2292 KorAP._vcKeyMenu._prefix.clear();
2293 KorAP._vcKeyMenu._prefix.add('x');
2294
2295 var prefElement = vc.element().querySelector('span.pref');
2296 expect(prefElement.innerText).toEqual('x');
2297
2298 // This should add key 'x' to VC
2299 prefElement.click();
2300
2301 expect(vc.element().firstChild.classList.contains('doc')).toBeTruthy();
2302 expect(vc.element().firstChild.firstChild.className).toEqual('key');
2303 expect(vc.element().firstChild.firstChild.innerText).toEqual('x');
2304 });
2305 });
Nils Diewald2fe12e12015-03-06 16:47:06 +00002306});