blob: 8e745e1d1d279858773b55e3429216492acc822d [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");
628 expect(docGroup.getOperand(1).value()).toEqual("");
629
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 });
667 });
668
669 describe('KorAP.Doc element', function () {
670 it('should be initializable', function () {
671 var docElement = docClass.create(undefined, {
Akron712733a2018-04-05 18:17:47 +0200672 "@type" : "koral:doc",
673 "key":"Titel",
674 "value":"Baum",
675 "match":"match:eq"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000676 });
677 expect(docElement.key()).toEqual('Titel');
678 expect(docElement.matchop()).toEqual('eq');
679 expect(docElement.value()).toEqual('Baum');
680
681 var docE = docElement.element();
682 expect(docE.children[0].firstChild.data).toEqual('Titel');
683 expect(docE.children[1].firstChild.data).toEqual('eq');
684 expect(docE.children[1].getAttribute('data-type')).toEqual('string');
685 expect(docE.children[2].firstChild.data).toEqual('Baum');
686 expect(docE.children[2].getAttribute('data-type')).toEqual('string');
687
688 expect(docElement.toJson()).toEqual(jasmine.objectContaining({
Akron712733a2018-04-05 18:17:47 +0200689 "@type" : "koral:doc",
690 "key":"Titel",
691 "value":"Baum",
692 "match":"match:eq"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000693 }));
694 });
695 });
696
697 describe('KorAP.DocGroup element', function () {
698 it('should be initializable', function () {
699
700 var docGroup = docGroupClass.create(undefined, {
Akron712733a2018-04-05 18:17:47 +0200701 "@type" : "koral:docGroup",
702 "operation" : "operation:and",
703 "operands" : [
704 {
705 "@type": 'koral:doc',
706 "key" : 'author',
707 "match": 'match:eq',
708 "value": 'Max Birkendale',
709 "type": 'type:string'
710 },
711 {
712 "@type": 'koral:doc',
713 "key": 'pubDate',
714 "match": 'match:eq',
715 "value": '2014-12-05',
716 "type": 'type:date'
717 }
718 ]
Nils Diewald7c8ced22015-04-15 19:21:00 +0000719 });
720
721 expect(docGroup.operation()).toEqual('and');
722 var e = docGroup.element();
723 expect(e.getAttribute('class')).toEqual('docGroup');
724 expect(e.getAttribute('data-operation')).toEqual('and');
725
726 var first = e.children[0];
727 expect(first.getAttribute('class')).toEqual('doc');
728 expect(first.children[0].getAttribute('class')).toEqual('key');
729 expect(first.children[1].getAttribute('class')).toEqual('match');
730 expect(first.children[2].getAttribute('class')).toEqual('value');
731 expect(first.children[2].getAttribute('data-type')).toEqual('string');
732 expect(first.children[0].firstChild.data).toEqual('author');
733 expect(first.children[1].firstChild.data).toEqual('eq');
734 expect(first.children[2].firstChild.data).toEqual('Max Birkendale');
735
736 var second = e.children[1];
737 expect(second.getAttribute('class')).toEqual('doc');
738 expect(second.children[0].getAttribute('class')).toEqual('key');
739 expect(second.children[1].getAttribute('class')).toEqual('match');
740 expect(second.children[2].getAttribute('class')).toEqual('value');
741 expect(second.children[2].getAttribute('data-type')).toEqual('date');
742 expect(second.children[0].firstChild.data).toEqual('pubDate');
743 expect(second.children[1].firstChild.data).toEqual('eq');
744 expect(second.children[2].firstChild.data).toEqual('2014-12-05');
745 });
746
747 it('should be deserializable with nested groups', function () {
748 var docGroup = docGroupClass.create(undefined, {
Akron712733a2018-04-05 18:17:47 +0200749 "@type" : "koral:docGroup",
750 "operation" : "operation:or",
751 "operands" : [
752 {
753 "@type": 'koral:doc',
754 "key" : 'author',
755 "match": 'match:eq',
756 "value": 'Max Birkendale',
757 "type": 'type:string'
758 },
759 {
760 "@type" : "koral:docGroup",
761 "operation" : "operation:and",
762 "operands" : [
763 {
764 "@type": 'koral:doc',
765 "key": 'pubDate',
766 "match": 'match:geq',
767 "value": '2014-05-12',
768 "type": 'type:date'
769 },
770 {
771 "@type": 'koral:doc',
772 "key": 'pubDate',
773 "match": 'match:leq',
774 "value": '2014-12-05',
775 "type": 'type:date'
776 }
777 ]
778 }
779 ]
Nils Diewald7c8ced22015-04-15 19:21:00 +0000780 });
781
782 expect(docGroup.operation()).toEqual('or');
783 var e = docGroup.element();
784 expect(e.getAttribute('class')).toEqual('docGroup');
785 expect(e.getAttribute('data-operation')).toEqual('or');
786
787 expect(e.children[0].getAttribute('class')).toEqual('doc');
788 var docop = e.children[0].lastChild;
Akron0b489ad2018-02-02 16:49:32 +0100789 expect(docop.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +0000790 expect(docop.children[0].getAttribute('class')).toEqual('and');
791 expect(docop.children[1].getAttribute('class')).toEqual('or');
792 expect(docop.children[2].getAttribute('class')).toEqual('delete');
793
794 expect(e.children[1].getAttribute('class')).toEqual('docGroup');
795 expect(e.children[1].getAttribute('data-operation')).toEqual('and');
796
797 // This and-operation can be "or"ed or "delete"d
798 var secop = e.children[1].children[2];
Akron0b489ad2018-02-02 16:49:32 +0100799 expect(secop.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +0000800 expect(secop.children[0].getAttribute('class')).toEqual('or');
801 expect(secop.children[1].getAttribute('class')).toEqual('delete');
802
803 // This or-operation can be "and"ed or "delete"d
Akron0b489ad2018-02-02 16:49:32 +0100804 expect(e.children[2].getAttribute('class')).toEqual('operators button-group');
805 expect(e.lastChild.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +0000806 expect(e.lastChild.children[0].getAttribute('class')).toEqual('and');
807 expect(e.lastChild.children[1].getAttribute('class')).toEqual('delete');
808 });
809 });
810
Akrone4961b12017-05-10 21:04:46 +0200811 describe('KorAP.VirtualCorpus', function () {
Nils Diewald7c8ced22015-04-15 19:21:00 +0000812 var simpleGroupFactory = buildFactory(docGroupClass, {
813 "@type" : "koral:docGroup",
814 "operation" : "operation:and",
815 "operands" : [
Akron712733a2018-04-05 18:17:47 +0200816 {
817 "@type": 'koral:doc',
818 "key" : 'author',
819 "match": 'match:eq',
820 "value": 'Max Birkendale',
821 "type": 'type:string'
822 },
823 {
824 "@type": 'koral:doc',
825 "key": 'pubDate',
826 "match": 'match:eq',
827 "value": '2014-12-05',
828 "type": 'type:date'
829 }
Nils Diewald7c8ced22015-04-15 19:21:00 +0000830 ]
831 });
832
833 var nestedGroupFactory = buildFactory(vcClass, {
834 "@type" : "koral:docGroup",
835 "operation" : "operation:or",
836 "operands" : [
Akron712733a2018-04-05 18:17:47 +0200837 {
838 "@type": 'koral:doc',
839 "key" : 'author',
840 "match": 'match:eq',
841 "value": 'Max Birkendale',
842 "type": 'type:string'
843 },
844 {
845 "@type" : "koral:docGroup",
846 "operation" : "operation:and",
847 "operands" : [
848 {
849 "@type": 'koral:doc',
850 "key": 'pubDate',
851 "match": 'match:geq',
852 "value": '2014-05-12',
853 "type": 'type:date'
854 },
855 {
856 "@type": 'koral:doc',
857 "key": 'pubDate',
858 "match": 'match:leq',
859 "value": '2014-12-05',
860 "type": 'type:date'
861 }
862 ]
863 }
Nils Diewald7c8ced22015-04-15 19:21:00 +0000864 ]
865 });
866
867 var flatGroupFactory = buildFactory(vcClass, {
868 "@type" : "koral:docGroup",
869 "operation" : "operation:and",
870 "operands" : [
Akron712733a2018-04-05 18:17:47 +0200871 {
872 "@type": 'koral:doc',
873 "key": 'pubDate',
874 "match": 'match:geq',
875 "value": '2014-05-12',
876 "type": 'type:date'
877 },
878 {
879 "@type": 'koral:doc',
880 "key": 'pubDate',
881 "match": 'match:leq',
882 "value": '2014-12-05',
883 "type": 'type:date'
884 },
885 {
886 "@type": 'koral:doc',
887 "key": 'foo',
888 "match": 'match:eq',
889 "value": 'bar',
890 "type": 'type:string'
891 }
Nils Diewald7c8ced22015-04-15 19:21:00 +0000892 ]
893 });
894
895 it('should be initializable', function () {
Nils Diewald6283d692015-04-23 20:32:53 +0000896 var vc = vcClass.create();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000897 expect(vc.element().getAttribute('class')).toEqual('vc');
898 expect(vc.root().element().getAttribute('class')).toEqual('doc unspecified');
899
900 // Not removable
901 expect(vc.root().element().lastChild.children.length).toEqual(0);
902 });
903
904 it('should be based on a doc', function () {
Nils Diewald6283d692015-04-23 20:32:53 +0000905 var vc = vcClass.create().fromJson({
Akron712733a2018-04-05 18:17:47 +0200906 "@type" : "koral:doc",
907 "key":"Titel",
908 "value":"Baum",
909 "match":"match:eq"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000910 });
911
912 expect(vc.element().getAttribute('class')).toEqual('vc');
913 expect(vc.root().element().getAttribute('class')).toEqual('doc');
914 expect(vc.root().key()).toEqual('Titel');
915 expect(vc.root().value()).toEqual('Baum');
916 expect(vc.root().matchop()).toEqual('eq');
917
918 var docE = vc.root().element();
919 expect(docE.children[0].firstChild.data).toEqual('Titel');
920 expect(docE.children[1].firstChild.data).toEqual('eq');
921 expect(docE.children[1].getAttribute('data-type')).toEqual('string');
922 expect(docE.children[2].firstChild.data).toEqual('Baum');
923 expect(docE.children[2].getAttribute('data-type')).toEqual('string');
924 });
925
926 it('should be based on a docGroup', function () {
Nils Diewald6283d692015-04-23 20:32:53 +0000927 var vc = vcClass.create().fromJson(simpleGroupFactory.create().toJson());
Nils Diewald7c8ced22015-04-15 19:21:00 +0000928
929 expect(vc.element().getAttribute('class')).toEqual('vc');
930 expect(vc.root().element().getAttribute('class')).toEqual('docGroup');
931 expect(vc.root().operation()).toEqual('and');
932
933 var docGroup = vc.root();
934
935 var first = docGroup.getOperand(0);
936 expect(first.key()).toEqual('author');
937 expect(first.value()).toEqual('Max Birkendale');
938 expect(first.matchop()).toEqual('eq');
939
940 var second = docGroup.getOperand(1);
941 expect(second.key()).toEqual('pubDate');
942 expect(second.value()).toEqual('2014-12-05');
943 expect(second.matchop()).toEqual('eq');
944 });
945
946
947 it('should be based on a nested docGroup', function () {
948 var vc = nestedGroupFactory.create();
949
950 expect(vc.element().getAttribute('class')).toEqual('vc');
951 expect(vc.element().firstChild.getAttribute('class')).toEqual('docGroup');
952 expect(vc.element().firstChild.children[0].getAttribute('class')).toEqual('doc');
953 var dg = vc.element().firstChild.children[1];
954 expect(dg.getAttribute('class')).toEqual('docGroup');
955 expect(dg.children[0].getAttribute('class')).toEqual('doc');
956 expect(dg.children[1].getAttribute('class')).toEqual('doc');
Akron0b489ad2018-02-02 16:49:32 +0100957 expect(dg.children[2].getAttribute('class')).toEqual('operators button-group');
958 expect(vc.element().firstChild.children[2].getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +0000959 });
960
961 it('should be modifiable by deletion in flat docGroups', function () {
962 var vc = flatGroupFactory.create();
963 var docGroup = vc.root();
964
965 expect(docGroup.element().getAttribute('class')).toEqual('docGroup');
966
967 var doc = docGroup.getOperand(1);
968 expect(doc.key()).toEqual("pubDate");
969 expect(doc.value()).toEqual("2014-12-05");
970
971 // Remove operand 1
972 expect(docGroup.delOperand(doc).update()).not.toBeUndefined();
973 expect(doc._element).toEqual(undefined);
974
975 doc = docGroup.getOperand(1);
976 expect(doc.key()).toEqual("foo");
977
978 // Remove operand 1
979 expect(docGroup.delOperand(doc).update()).not.toBeUndefined();
980 expect(doc._element).toEqual(undefined);
981
982 // Only one operand left ...
983 expect(docGroup.getOperand(1)).toBeUndefined();
984 // ... but there shouldn't be a group anymore at all!
985 expect(docGroup.getOperand(0)).toBeUndefined();
986
987 var obj = vc.root();
988 expect(obj.ldType()).toEqual("doc");
989 expect(obj.key()).toEqual("pubDate");
990 expect(obj.value()).toEqual("2014-05-12");
991
992 expect(obj.element().getAttribute('class')).toEqual('doc');
993 });
994
995
996 it('should be modifiable by deletion in nested docGroups (root case)', function () {
997 var vc = nestedGroupFactory.create();
998
999 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001000 'author = "Max Birkendale" | (pubDate since 2014-05-12 & pubDate until 2014-12-05)'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001001 );
1002
1003 var docGroup = vc.root();
1004 expect(docGroup.ldType()).toEqual("docGroup");
1005 expect(docGroup.operation()).toEqual("or");
1006
1007 var doc = docGroup.getOperand(0);
1008 expect(doc.key()).toEqual("author");
1009 expect(doc.value()).toEqual("Max Birkendale");
1010
1011 docGroup = docGroup.getOperand(1);
1012 expect(docGroup.operation()).toEqual("and");
1013
1014 doc = docGroup.getOperand(0);
1015 expect(doc.key()).toEqual("pubDate");
1016 expect(doc.matchop()).toEqual("geq");
1017 expect(doc.value()).toEqual("2014-05-12");
1018 expect(doc.type()).toEqual("date");
1019
1020 doc = docGroup.getOperand(1);
1021 expect(doc.key()).toEqual("pubDate");
1022 expect(doc.matchop()).toEqual("leq");
1023 expect(doc.value()).toEqual("2014-12-05");
1024 expect(doc.type()).toEqual("date");
1025
1026 // Remove first operand so everything becomes root
1027 expect(
Akron712733a2018-04-05 18:17:47 +02001028 vc.root().delOperand(
1029 vc.root().getOperand(0)
1030 ).update().ldType()
Nils Diewald7c8ced22015-04-15 19:21:00 +00001031 ).toEqual("docGroup");
1032
1033 expect(vc.root().ldType()).toEqual("docGroup");
1034 expect(vc.root().operation()).toEqual("and");
1035 expect(vc.root().getOperand(0).ldType()).toEqual("doc");
1036
1037 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001038 'pubDate since 2014-05-12 & pubDate until 2014-12-05'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001039 );
1040 });
1041
1042 it('should be modifiable by deletion in nested docGroups (resolve group case)', function () {
1043 var vc = nestedGroupFactory.create();
1044
1045 // Get nested group
1046 var firstGroup = vc.root().getOperand(1);
1047 firstGroup.append(simpleGroupFactory.create({ "operation" : "operation:or" }));
1048
1049 // Structur is now:
1050 // or(doc, and(doc, doc, or(doc, doc)))
1051
1052 // Get nested or in and
1053 var orGroup = vc.root().getOperand(1).getOperand(2);
1054 expect(orGroup.ldType()).toEqual("docGroup");
1055 expect(orGroup.operation()).toEqual("or");
1056
1057 // Remove
1058 // Structur is now:
1059 // or(doc, and(doc, doc, doc)))
1060 expect(orGroup.delOperand(orGroup.getOperand(0)).update().operation()).toEqual("and");
1061 expect(vc.root().getOperand(1).operands().length).toEqual(3);
1062 });
1063
1064 it('should be modifiable by deletion in nested docGroups (identical group case)', function () {
1065 var vc = nestedGroupFactory.create();
1066
1067 // Get nested group
1068 var firstGroup = vc.root().getOperand(1);
1069 firstGroup.append(simpleGroupFactory.create({
Akron712733a2018-04-05 18:17:47 +02001070 "operation" : "operation:or"
Nils Diewald7c8ced22015-04-15 19:21:00 +00001071 }));
1072 var oldAuthor = firstGroup.getOperand(2).getOperand(0);
1073 oldAuthor.key("title");
1074 oldAuthor.value("Der Birnbaum");
1075
1076 // Structur is now:
1077 // or(doc, and(doc, doc, or(doc, doc)))
1078 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001079 'author = "Max Birkendale" | ' +
1080 '(pubDate since 2014-05-12 & ' +
1081 'pubDate until 2014-12-05 & ' +
1082 '(title = "Der Birnbaum" | ' +
1083 'pubDate in 2014-12-05))'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001084 );
1085
1086 var andGroup = vc.root().getOperand(1);
1087
1088 // Get leading docs in and
1089 var doc1 = andGroup.getOperand(0);
1090 expect(doc1.ldType()).toEqual("doc");
1091 expect(doc1.value()).toEqual("2014-05-12");
1092 var doc2 = andGroup.getOperand(1);
1093 expect(doc2.ldType()).toEqual("doc");
1094 expect(doc2.value()).toEqual("2014-12-05");
1095
1096 // Remove 2
1097 expect(
Akron712733a2018-04-05 18:17:47 +02001098 andGroup.delOperand(doc2).update().operation()
Nils Diewald7c8ced22015-04-15 19:21:00 +00001099 ).toEqual("and");
1100 // Structur is now:
1101 // or(doc, and(doc, or(doc, doc)))
1102
1103 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001104 'author = "Max Birkendale"' +
1105 ' | (pubDate since 2014-05-12 & ' +
1106 '(title = "Der Birnbaum" | pubDate in 2014-12-05))'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001107 );
1108
1109
1110 // Remove 1
1111 expect(andGroup.delOperand(doc1).update().operation()).toEqual("or");
1112 // Structur is now:
1113 // or(doc, doc, doc)
1114
1115 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001116 'author = "Max Birkendale" | title = "Der Birnbaum" | pubDate in 2014-12-05'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001117 );
1118 });
1119
1120 it('should be reducible to unspecification', function () {
1121 var vc = demoFactory.create();
1122
1123 expect(vc.toQuery()).toEqual(vc.root().toQuery());
1124 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001125 '(Titel = "Baum" & Veröffentlichungsort = "hihi" & ' +
1126 '(Titel = "Baum" | Veröffentlichungsort = "hihi")) ' +
1127 '| Untertitel ~ "huhu"');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001128 expect(vc.root().element().lastChild.children[0].firstChild.nodeValue).toEqual('and');
1129 expect(vc.root().element().lastChild.children[1].firstChild.nodeValue).toEqual('×');
1130 expect(vc.root().delOperand(vc.root().getOperand(0)).update()).not.toBeUndefined();
Akron712733a2018-04-05 18:17:47 +02001131 expect(vc.toQuery()).toEqual('Untertitel ~ "huhu"');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001132
1133 var lc = vc.root().element().lastChild;
1134 expect(lc.children[0].firstChild.nodeValue).toEqual('and');
1135 expect(lc.children[1].firstChild.nodeValue).toEqual('or');
1136 expect(lc.children[2].firstChild.nodeValue).toEqual('×');
1137
1138 // Clean everything
1139 vc.clean();
1140 expect(vc.toQuery()).toEqual('');
1141 });
1142
1143 it('should flatten on import', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00001144 var vc = vcClass.create().fromJson({
Akron712733a2018-04-05 18:17:47 +02001145 "@type":"koral:docGroup",
1146 "operation":"operation:or",
1147 "operands":[
1148 {
1149 "@type":"koral:docGroup",
1150 "operation":"operation:or",
1151 "operands":[
Nils Diewald7c8ced22015-04-15 19:21:00 +00001152 {
Akron712733a2018-04-05 18:17:47 +02001153 "@type":"koral:doc",
1154 "key":"Titel",
1155 "value":"Baum",
1156 "match":"match:eq"
Nils Diewald7c8ced22015-04-15 19:21:00 +00001157 },
1158 {
Akron712733a2018-04-05 18:17:47 +02001159 "@type":"koral:doc",
1160 "key":"Veröffentlichungsort",
1161 "value":"hihi",
1162 "match":"match:eq"
Nils Diewald7c8ced22015-04-15 19:21:00 +00001163 },
1164 {
Akron712733a2018-04-05 18:17:47 +02001165 "@type":"koral:docGroup",
1166 "operation":"operation:or",
1167 "operands":[
1168 {
1169 "@type":"koral:doc",
1170 "key":"Titel",
1171 "value":"Baum",
1172 "match":"match:eq"
1173 },
1174 {
1175 "@type":"koral:doc",
1176 "key":"Veröffentlichungsort",
1177 "value":"hihi",
1178 "match":"match:eq"
1179 }
1180 ]
Nils Diewald7c8ced22015-04-15 19:21:00 +00001181 }
Akron712733a2018-04-05 18:17:47 +02001182 ]
1183 },
1184 {
1185 "@type":"koral:doc",
1186 "key":"Untertitel",
1187 "value":"huhu",
1188 "match":"match:contains"
1189 }
1190 ]
Nils Diewald7c8ced22015-04-15 19:21:00 +00001191 });
Nils Diewaldfda29d92015-01-22 17:28:01 +00001192
Nils Diewald7c8ced22015-04-15 19:21:00 +00001193 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001194 'Titel = "Baum" | Veröffentlichungsort = "hihi" | Untertitel ~ "huhu"'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001195 );
Nils Diewald86dad5b2015-01-28 15:09:07 +00001196 });
Nils Diewald86dad5b2015-01-28 15:09:07 +00001197 });
1198
Nils Diewald7c8ced22015-04-15 19:21:00 +00001199 describe('KorAP.Operators', function () {
1200 it('should be initializable', function () {
1201 var op = operatorsClass.create(true, false, false);
1202 expect(op.and()).toBeTruthy();
1203 expect(op.or()).not.toBeTruthy();
1204 expect(op.del()).not.toBeTruthy();
1205
1206 op.and(false);
1207 expect(op.and()).not.toBeTruthy();
1208 expect(op.or()).not.toBeTruthy();
1209 expect(op.del()).not.toBeTruthy();
1210
1211 op.or(true);
1212 op.del(true);
1213 expect(op.and()).not.toBeTruthy();
1214 expect(op.or()).toBeTruthy();
1215 expect(op.del()).toBeTruthy();
1216
1217 var e = op.element();
Akron0b489ad2018-02-02 16:49:32 +01001218 expect(e.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001219 expect(e.children[0].getAttribute('class')).toEqual('or');
1220 expect(e.children[0].firstChild.data).toEqual('or');
1221 expect(e.children[1].getAttribute('class')).toEqual('delete');
1222 expect(e.children[1].firstChild.data).toEqual('×');
1223
1224 op.and(true);
1225 op.del(false);
1226 op.update();
1227
1228 e = op.element();
Akron0b489ad2018-02-02 16:49:32 +01001229 expect(e.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001230 expect(e.children[0].getAttribute('class')).toEqual('and');
1231 expect(e.children[0].firstChild.data).toEqual('and');
1232 expect(e.children[1].getAttribute('class')).toEqual('or');
1233 expect(e.children[1].firstChild.data).toEqual('or');
1234 });
1235 });
1236
1237 describe('KorAP._delete (event)', function () {
1238 var complexVCFactory = buildFactory(vcClass,{
1239 "@type": 'koral:docGroup',
1240 'operation' : 'operation:and',
1241 'operands' : [
Akron712733a2018-04-05 18:17:47 +02001242 {
1243 "@type": 'koral:doc',
1244 "key": 'pubDate',
1245 "match": 'match:eq',
1246 "value": '2014-12-05',
1247 "type": 'type:date'
1248 },
1249 {
1250 "@type" : 'koral:docGroup',
1251 'operation' : 'operation:or',
1252 'operands' : [
1253 {
1254 '@type' : 'koral:doc',
1255 'key' : 'title',
1256 'value' : 'Hello World!'
1257 },
1258 {
1259 '@type' : 'koral:doc',
1260 'key' : 'foo',
1261 'value' : 'bar'
1262 }
1263 ]
1264 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00001265 ]
1266 });
1267
1268 it('should clean on root docs', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00001269 var vc = vcClass.create().fromJson({
Akron712733a2018-04-05 18:17:47 +02001270 "@type": 'koral:doc',
1271 "key": 'pubDate',
1272 "match": 'match:eq',
1273 "value": '2014-12-05',
1274 "type": 'type:date'
Nils Diewald86dad5b2015-01-28 15:09:07 +00001275 });
Nils Diewald7c8ced22015-04-15 19:21:00 +00001276 expect(vc.root().toQuery()).toEqual('pubDate in 2014-12-05');
Akron0b489ad2018-02-02 16:49:32 +01001277 expect(vc.root().element().lastChild.getAttribute('class')).toEqual('operators button-group');
Nils Diewald86dad5b2015-01-28 15:09:07 +00001278
Nils Diewald7c8ced22015-04-15 19:21:00 +00001279 // Clean with delete from root
1280 expect(vc.root().element().lastChild.lastChild.getAttribute('class')).toEqual('delete');
1281 _delOn(vc.root());
1282 expect(vc.root().toQuery()).toEqual('');
1283 expect(vc.root().element().lastChild.lastChild.data).toEqual('⋯');
1284 });
Nils Diewald86dad5b2015-01-28 15:09:07 +00001285
Nils Diewald7c8ced22015-04-15 19:21:00 +00001286 it('should remove on nested docs', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00001287 var vc = vcClass.create().fromJson(
Akron712733a2018-04-05 18:17:47 +02001288 {
1289 "@type": 'koral:docGroup',
1290 'operation' : 'operation:and',
1291 'operands' : [
1292 {
1293 "@type": 'koral:doc',
1294 "key": 'pubDate',
1295 "match": 'match:eq',
1296 "value": '2014-12-05',
1297 "type": 'type:date'
1298 },
1299 {
1300 "@type" : 'koral:doc',
1301 'key' : 'foo',
1302 'value' : 'bar'
1303 }
1304 ]
1305 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00001306 );
1307
1308 // Delete with direct element access
1309 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar"');
1310 _delOn(vc.root().getOperand(0));
1311
1312 expect(vc.toQuery()).toEqual('foo = "bar"');
1313 expect(vc.root().ldType()).toEqual('doc');
1314 });
1315
1316 it('should clean on doc groups', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00001317 var vc = vcClass.create().fromJson(
Akron712733a2018-04-05 18:17:47 +02001318 {
1319 "@type": 'koral:docGroup',
1320 'operation' : 'operation:and',
1321 'operands' : [
1322 {
1323 "@type": 'koral:doc',
1324 "key": 'pubDate',
1325 "match": 'match:eq',
1326 "value": '2014-12-05',
1327 "type": 'type:date'
1328 },
1329 {
1330 "@type" : 'koral:doc',
1331 'key' : 'foo',
1332 'value' : 'bar'
1333 }
1334 ]
1335 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00001336 );
1337
1338 // Cleanwith direct element access
1339 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar"');
1340 _delOn(vc.root());
1341 expect(vc.toQuery()).toEqual('');
1342 expect(vc.root().ldType()).toEqual('non');
1343 });
1344
1345 it('should remove on nested doc groups (case of ungrouping 1)', function () {
1346 var vc = complexVCFactory.create();
1347
1348 // Delete with direct element access
1349 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001350 'pubDate in 2014-12-05 & (title = "Hello World!" | foo = "bar")'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001351 );
1352
1353 // Remove hello world:
1354 _delOn(vc.root().getOperand(1).getOperand(0));
1355 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar"');
1356 expect(vc.root().ldType()).toEqual('docGroup');
1357 });
1358
1359 it('should remove on nested doc groups (case of ungrouping 2)', function () {
1360 var vc = complexVCFactory.create();
1361
1362 // Delete with direct element access
1363 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001364 'pubDate in 2014-12-05 & (title = "Hello World!" | foo = "bar")'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001365 );
1366
1367 // Remove bar
1368 _delOn(vc.root().getOperand(1).getOperand(1));
1369 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & title = "Hello World!"');
1370 expect(vc.root().ldType()).toEqual('docGroup');
1371 expect(vc.root().operation()).toEqual('and');
1372 });
1373
1374 it('should remove on nested doc groups (case of root changing)', 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 & ' +
1380 '(title = "Hello World!" | foo = "bar")'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001381 );
1382
1383 // Remove bar
1384 _delOn(vc.root().getOperand(0));
1385 expect(vc.toQuery()).toEqual('title = "Hello World!" | foo = "bar"');
1386 expect(vc.root().ldType()).toEqual('docGroup');
1387 expect(vc.root().operation()).toEqual('or');
1388 });
1389
1390 it('should remove on nested doc groups (list flattening)', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00001391 var vc = vcClass.create().fromJson(
Akron712733a2018-04-05 18:17:47 +02001392 {
1393 "@type": 'koral:docGroup',
1394 'operation' : 'operation:or',
1395 'operands' : [
1396 {
1397 "@type": 'koral:doc',
1398 "key": 'pubDate',
1399 "match": 'match:eq',
1400 "value": '2014-12-05',
1401 "type": 'type:date'
1402 },
1403 {
1404 "@type" : 'koral:doc',
1405 'key' : 'foo',
1406 'value' : 'bar'
1407 },
1408 {
1409 "@type": 'koral:docGroup',
1410 'operation' : 'operation:and',
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:docGroup',
1421 'operation' : 'operation:or',
1422 'operands' : [
1423 {
1424 '@type' : 'koral:doc',
1425 'key' : 'title',
1426 'value' : 'Hello World!'
1427 },
1428 {
1429 '@type' : 'koral:doc',
1430 'key' : 'yeah',
1431 'value' : 'juhu'
1432 }
1433 ]
1434 }
1435 ]
1436 }
1437 ]
1438 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00001439 );
1440
1441 // Delete with direct element access
1442 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001443 'pubDate in 2014-12-05 | foo = "bar" | ' +
1444 '(pubDate in 2014-12-05 & ' +
1445 '(title = "Hello World!" | yeah = "juhu"))'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001446 );
1447
1448 expect(vc.root().ldType()).toEqual('docGroup');
1449 expect(vc.root().operation()).toEqual('or');
1450
1451 // Operands and operators
1452 expect(vc.element().firstChild.children.length).toEqual(4);
Akron0b489ad2018-02-02 16:49:32 +01001453 expect(vc.element().firstChild.lastChild.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001454
1455 // Remove inner group and flatten
1456 _delOn(vc.root().getOperand(2).getOperand(0));
1457
1458 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001459 'pubDate in 2014-12-05 | foo = "bar" | title = "Hello World!" | yeah = "juhu"'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001460 );
1461 expect(vc.root().ldType()).toEqual('docGroup');
1462 expect(vc.root().operation()).toEqual('or');
1463
1464 // Operands and operators
1465 expect(vc.element().firstChild.children.length).toEqual(5);
Akron0b489ad2018-02-02 16:49:32 +01001466 expect(vc.element().firstChild.lastChild.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001467 });
1468 });
1469
1470 describe('KorAP._add (event)', function () {
1471 var complexVCFactory = buildFactory(vcClass,{
1472 "@type": 'koral:docGroup',
1473 'operation' : 'operation:and',
1474 'operands' : [
Akron712733a2018-04-05 18:17:47 +02001475 {
1476 "@type": 'koral:doc',
1477 "key": 'pubDate',
1478 "match": 'match:eq',
1479 "value": '2014-12-05',
1480 "type": 'type:date'
1481 },
1482 {
1483 "@type" : 'koral:docGroup',
1484 'operation' : 'operation:or',
1485 'operands' : [
1486 {
1487 '@type' : 'koral:doc',
1488 'key' : 'title',
1489 'value' : 'Hello World!'
1490 },
1491 {
1492 '@type' : 'koral:doc',
1493 'key' : 'foo',
1494 'value' : 'bar'
1495 }
1496 ]
1497 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00001498 ]
1499 });
1500
1501 it('should add new unspecified doc with "and"', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00001502 var vc = vcClass.create().fromJson(
Akron712733a2018-04-05 18:17:47 +02001503 {
1504 "@type": 'koral:docGroup',
1505 'operation' : 'operation:and',
1506 'operands' : [
1507 {
1508 "@type": 'koral:doc',
1509 "key": 'pubDate',
1510 "match": 'match:eq',
1511 "value": '2014-12-05',
1512 "type": 'type:date'
1513 },
1514 {
1515 "@type" : 'koral:doc',
1516 'key' : 'foo',
1517 'value' : 'bar'
1518 }
1519 ]
1520 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00001521 );
1522
1523 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar"');
1524
1525 var fc = vc.element().firstChild;
1526 expect(fc.getAttribute('data-operation')).toEqual('and');
1527 expect(fc.children.length).toEqual(3);
Akron0b489ad2018-02-02 16:49:32 +01001528 expect(fc.lastChild.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001529 expect(fc.children[0].getAttribute('class')).toEqual('doc');
1530 expect(fc.children[1].getAttribute('class')).toEqual('doc');
1531
1532 // add with 'and' in the middle
1533 _andOn(vc.root().getOperand(0));
1534 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar"');
1535
1536 fc = vc.element().firstChild;
1537 expect(fc.getAttribute('data-operation')).toEqual('and');
1538 expect(fc.children.length).toEqual(4);
Akron0b489ad2018-02-02 16:49:32 +01001539 expect(fc.lastChild.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001540
1541 expect(fc.children[0].getAttribute('class')).toEqual('doc');
1542 expect(fc.children[1].getAttribute('class')).toEqual('doc unspecified');
1543 expect(fc.children[2].getAttribute('class')).toEqual('doc');
1544 });
1545
1546 it('should add new unspecified doc with "or"', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00001547 var vc = vcClass.create().fromJson(
Akron712733a2018-04-05 18:17:47 +02001548 {
1549 "@type": 'koral:docGroup',
1550 'operation' : 'operation:and',
1551 'operands' : [
1552 {
1553 "@type": 'koral:doc',
1554 "key": 'pubDate',
1555 "match": 'match:eq',
1556 "value": '2014-12-05',
1557 "type": 'type:date'
1558 },
1559 {
1560 "@type" : 'koral:doc',
1561 'key' : 'foo',
1562 'value' : 'bar'
1563 }
1564 ]
1565 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00001566 );
1567
1568 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar"');
1569
1570 var fc = vc.element().firstChild;
1571 expect(fc.children.length).toEqual(3);
Akron0b489ad2018-02-02 16:49:32 +01001572 expect(fc.lastChild.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001573 expect(fc.children[0].getAttribute('class')).toEqual('doc');
1574 expect(fc.children[1].getAttribute('class')).toEqual('doc');
1575
1576 // add with 'or' in the middle
1577 _orOn(vc.root().getOperand(0));
1578 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar"');
1579 fc = vc.element().firstChild;
1580
1581 expect(fc.getAttribute('data-operation')).toEqual('and');
1582 expect(fc.children.length).toEqual(3);
1583 expect(fc.children[0].getAttribute('class')).toEqual('docGroup');
1584 expect(fc.children[0].getAttribute('data-operation')).toEqual('or');
1585 expect(fc.children[1].getAttribute('class')).toEqual('doc');
Akron0b489ad2018-02-02 16:49:32 +01001586 expect(fc.children[2].getAttribute('class')).toEqual('operators button-group');
1587 expect(fc.lastChild.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001588
1589 fc = vc.element().firstChild.firstChild;
1590 expect(fc.children.length).toEqual(3);
1591 expect(fc.children[0].getAttribute('class')).toEqual('doc');
1592 expect(fc.children[1].getAttribute('class')).toEqual('doc unspecified');
Akron0b489ad2018-02-02 16:49:32 +01001593 expect(fc.children[2].getAttribute('class')).toEqual('operators button-group');
1594 expect(fc.lastChild.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001595 });
1596
1597 it('should add new unspecified doc with "and" before group', function () {
1598 var vc = demoFactory.create();
1599
1600 // Wrap with direct element access
1601 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001602 '(Titel = "Baum" & ' +
1603 'Veröffentlichungsort = "hihi" & ' +
1604 '(Titel = "Baum" | ' +
1605 'Veröffentlichungsort = "hihi")) | ' +
1606 'Untertitel ~ "huhu"'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001607 );
1608
1609 expect(vc.root().getOperand(0).ldType()).toEqual('docGroup');
1610 expect(vc.root().getOperand(0).operation()).toEqual('and');
1611 expect(vc.root().getOperand(0).operands().length).toEqual(3);
1612
1613 // Add unspecified on the second doc
1614 var secDoc = vc.root().getOperand(0).getOperand(1);
1615 expect(secDoc.value()).toEqual('hihi');
1616
1617 // Add
1618 _andOn(secDoc);
1619
1620 var fo = vc.root().getOperand(0);
1621
1622 expect(fo.ldType()).toEqual('docGroup');
1623 expect(fo.operation()).toEqual('and');
1624 expect(fo.operands().length).toEqual(4);
1625
1626 expect(fo.getOperand(0).ldType()).toEqual('doc');
1627 expect(fo.getOperand(1).ldType()).toEqual('doc');
1628 expect(fo.getOperand(2).ldType()).toEqual('non');
1629 expect(fo.getOperand(3).ldType()).toEqual('docGroup');
1630 });
1631
1632
1633 it('should remove a doc with an unspecified doc in a nested group', function () {
1634 var vc = demoFactory.create();
1635
1636 // Wrap with direct element access
1637 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001638 '(Titel = "Baum" & Veröffentlichungsort = "hihi" & (Titel = "Baum" | Veröffentlichungsort = "hihi")) | Untertitel ~ "huhu"'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001639 );
1640
1641 var fo = vc.root().getOperand(0).getOperand(0);
1642 expect(fo.key()).toEqual('Titel');
1643 expect(fo.value()).toEqual('Baum');
1644
1645 // Add unspecified on the root group
1646 _orOn(fo);
1647
1648 fo = vc.root().getOperand(0).getOperand(0);
1649
1650 expect(fo.operation()).toEqual('or');
1651 expect(fo.getOperand(0).ldType()).toEqual('doc');
1652 expect(fo.getOperand(1).ldType()).toEqual('non');
1653
1654 // Delete document
1655 _delOn(fo.getOperand(0));
1656
1657 // The operand is now non
1658 expect(vc.root().getOperand(0).getOperand(0).ldType()).toEqual('non');
1659 expect(vc.root().getOperand(0).getOperand(1).ldType()).toEqual('doc');
1660 expect(vc.root().getOperand(0).getOperand(2).ldType()).toEqual('docGroup');
1661 });
1662
1663
Akron712733a2018-04-05 18:17:47 +02001664 it('should remove an unspecified doc with a doc in a nested group', function () {
Nils Diewald7c8ced22015-04-15 19:21:00 +00001665 var vc = demoFactory.create();
1666
1667 // Wrap with direct element access
1668 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001669 '(Titel = "Baum" & ' +
1670 'Veröffentlichungsort = "hihi" & ' +
1671 '(Titel = "Baum" ' +
1672 '| Veröffentlichungsort = "hihi")) | ' +
1673 'Untertitel ~ "huhu"'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001674 );
1675
1676 var fo = vc.root().getOperand(0).getOperand(0);
1677 expect(fo.key()).toEqual('Titel');
1678 expect(fo.value()).toEqual('Baum');
1679
1680 // Add unspecified on the root group
1681 _orOn(fo);
1682
1683 fo = vc.root().getOperand(0).getOperand(0);
1684
1685 expect(fo.operation()).toEqual('or');
1686 expect(fo.getOperand(0).ldType()).toEqual('doc');
1687 expect(fo.getOperand(1).ldType()).toEqual('non');
1688
1689 // Delete unspecified doc
1690 _delOn(fo.getOperand(1));
1691
1692 // The operand is now non
1693 fo = vc.root().getOperand(0);
1694 expect(fo.getOperand(0).ldType()).toEqual('doc');
1695 expect(fo.getOperand(0).key()).toEqual('Titel');
1696 expect(fo.getOperand(0).value()).toEqual('Baum');
1697 expect(fo.getOperand(1).ldType()).toEqual('doc');
1698 expect(fo.getOperand(2).ldType()).toEqual('docGroup');
1699 });
1700
1701
1702 it('should add on parent group (case "and")', function () {
1703 var vc = complexVCFactory.create();
1704
1705 // Wrap with direct element access
1706 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001707 'pubDate in 2014-12-05 & (title = "Hello World!" | foo = "bar")'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001708 );
1709
1710 expect(vc.root().operands().length).toEqual(2);
1711
1712 // Add unspecified on the root group
1713 _andOn(vc.root().getOperand(1));
1714 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001715 'pubDate in 2014-12-05 & (title = "Hello World!" | foo = "bar")'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001716 );
1717
1718 expect(vc.root().ldType()).toEqual('docGroup');
1719 expect(vc.root().operands().length).toEqual(3);
1720 expect(vc.root().getOperand(0).ldType()).toEqual('doc');
1721 expect(vc.root().getOperand(1).ldType()).toEqual('docGroup');
1722 expect(vc.root().getOperand(1).operation()).toEqual('or');
1723 expect(vc.root().getOperand(2).ldType()).toEqual('non');
1724
1725 // Add another unspecified on the root group
1726 _andOn(vc.root().getOperand(1));
1727
1728 expect(vc.root().operands().length).toEqual(4);
1729 expect(vc.root().getOperand(0).ldType()).toEqual('doc');
1730 expect(vc.root().getOperand(1).ldType()).toEqual('docGroup');
1731 expect(vc.root().getOperand(2).ldType()).toEqual('non');
1732 expect(vc.root().getOperand(3).ldType()).toEqual('non');
1733
1734 // Add another unspecified after the first doc
1735 _andOn(vc.root().getOperand(0));
1736
1737 expect(vc.root().operands().length).toEqual(5);
1738 expect(vc.root().getOperand(0).ldType()).toEqual('doc');
1739 expect(vc.root().getOperand(1).ldType()).toEqual('non');
1740 expect(vc.root().getOperand(2).ldType()).toEqual('docGroup');
1741 expect(vc.root().getOperand(3).ldType()).toEqual('non');
1742 expect(vc.root().getOperand(4).ldType()).toEqual('non');
1743 });
1744
1745 it('should wrap on root', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00001746 var vc = vcClass.create().fromJson(
Akron712733a2018-04-05 18:17:47 +02001747 {
1748 "@type": 'koral:docGroup',
1749 'operation' : 'operation:and',
1750 'operands' : [
1751 {
1752 "@type": 'koral:doc',
1753 "key": 'pubDate',
1754 "match": 'match:eq',
1755 "value": '2014-12-05',
1756 "type": 'type:date'
1757 },
1758 {
1759 "@type" : 'koral:doc',
1760 'key' : 'foo',
1761 'value' : 'bar'
1762 }
1763 ]
1764 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00001765 );
1766
1767 // Wrap on root
1768 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar"');
1769 expect(vc.root().ldType()).toEqual('docGroup');
1770 expect(vc.root().operation()).toEqual('and');
1771 _orOn(vc.root());
1772 expect(vc.root().ldType()).toEqual('docGroup');
1773 expect(vc.root().operation()).toEqual('or');
1774
1775 expect(vc.root().getOperand(0).ldType()).toEqual('docGroup');
1776 expect(vc.root().getOperand(0).operation()).toEqual('and');
1777 });
1778
1779 it('should add on root (case "and")', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00001780 var vc = vcClass.create().fromJson(
Akron712733a2018-04-05 18:17:47 +02001781 {
1782 "@type": 'koral:doc',
1783 "key": 'pubDate',
1784 "match": 'match:eq',
1785 "value": '2014-12-05',
1786 "type": 'type:date'
1787 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00001788 );
1789
1790 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05');
1791 expect(vc.root().ldType()).toEqual('doc');
1792 expect(vc.root().key()).toEqual('pubDate');
1793 expect(vc.root().value()).toEqual('2014-12-05');
1794
1795 // Wrap on root
1796 _andOn(vc.root());
1797 expect(vc.root().ldType()).toEqual('docGroup');
1798 expect(vc.root().operation()).toEqual('and');
1799 });
1800
1801 it('should add on root (case "or")', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00001802 var vc = vcClass.create().fromJson(
Akron712733a2018-04-05 18:17:47 +02001803 {
1804 "@type": 'koral:doc',
1805 "key": 'pubDate',
1806 "match": 'match:eq',
1807 "value": '2014-12-05',
1808 "type": 'type:date'
1809 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00001810 );
1811
1812 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05');
1813 expect(vc.root().key()).toEqual('pubDate');
1814 expect(vc.root().value()).toEqual('2014-12-05');
1815
1816 // Wrap on root
1817 _orOn(vc.root());
1818 expect(vc.root().ldType()).toEqual('docGroup');
1819 expect(vc.root().operation()).toEqual('or');
1820 });
1821
1822 it('should support multiple sub groups per group', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00001823 var vc = vcClass.create().fromJson(
Akron712733a2018-04-05 18:17:47 +02001824 {
1825 "@type": 'koral:docGroup',
1826 'operation' : 'operation:or',
1827 'operands' : [
1828 {
1829 "@type": 'koral:docGroup',
1830 'operation' : 'operation:and',
1831 'operands' : [
1832 {
1833 "@type": 'koral:doc',
1834 "key": 'title',
1835 "value": 't1',
1836 },
1837 {
1838 "@type" : 'koral:doc',
1839 'key' : 'title',
1840 'value' : 't2'
1841 }
1842 ]
1843 },
1844 {
1845 "@type": 'koral:docGroup',
1846 'operation' : 'operation:and',
1847 'operands' : [
1848 {
1849 "@type": 'koral:doc',
1850 "key": 'title',
1851 "value": 't3',
1852 },
1853 {
1854 "@type" : 'koral:doc',
1855 'key' : 'title',
1856 'value' : 't4'
1857 }
1858 ]
1859 }
1860 ]
1861 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00001862 );
1863 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001864 '(title = "t1" & title = "t2") | ' +
1865 '(title = "t3" & title = "t4")'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001866 );
1867 expect(vc.root().operation()).toEqual('or');
1868 expect(vc.root().getOperand(0).toQuery()).toEqual('title = "t1" & title = "t2"');
1869 expect(vc.root().getOperand(1).toQuery()).toEqual('title = "t3" & title = "t4"');
1870
1871 _andOn(vc.root());
1872
1873 expect(vc.root().operation()).toEqual('and');
1874 expect(vc.root().getOperand(0).ldType()).toEqual('docGroup');
1875 expect(vc.root().getOperand(1).ldType()).toEqual('non');
1876 });
1877 });
1878
Akron5c829e92017-05-12 18:10:00 +02001879 // Check class method
1880 describe('KorAP.VC.checkRewrite', function () {
1881
1882 it('should check for simple rewrites', function () {
1883 expect(vcClass.checkRewrite(
1884 {
1885 "@type" : "koral:doc",
1886 "rewrites" : [{
Akron712733a2018-04-05 18:17:47 +02001887 "@type" : "koral:rewrite",
1888 "operation" : "operation:modification",
1889 "src" : "querySerializer",
1890 "scope" : "tree"
Akron5c829e92017-05-12 18:10:00 +02001891 }]
1892 }
1893 )).toBeTruthy();
Nils Diewald7c8ced22015-04-15 19:21:00 +00001894
Akron5c829e92017-05-12 18:10:00 +02001895 var nested = {
1896 "@type" : "koral:docGroup",
1897 "operands" : [
1898 {
1899 "@type" : "koral:doc"
1900 },
1901 {
1902 "@type" : "koral:docGroup",
1903 "operands" : [
1904 {
1905 "@type": "koral:doc"
1906 },
1907 {
1908 "@type": "koral:doc"
1909 }
1910 ]
1911 }
1912 ]
1913 };
1914
1915 expect(vcClass.checkRewrite(nested)).toBe(false);
1916
1917 nested["operands"][1]["operands"][1]["rewrites"] = [{
Akron712733a2018-04-05 18:17:47 +02001918 "@type" : "koral:rewrite",
1919 "operation" : "operation:modification",
1920 "src" : "querySerializer",
1921 "scope" : "tree"
Akron5c829e92017-05-12 18:10:00 +02001922 }];
1923
1924 expect(vcClass.checkRewrite(nested)).toBeTruthy();
1925 });
1926 });
Nils Diewald6283d692015-04-23 20:32:53 +00001927
1928 describe('KorAP.Rewrite', function () {
Nils Diewald7c8ced22015-04-15 19:21:00 +00001929 it('should be initializable', function () {
1930 var rewrite = rewriteClass.create({
Akron712733a2018-04-05 18:17:47 +02001931 "@type" : "koral:rewrite",
1932 "operation" : "operation:modification",
1933 "src" : "querySerializer",
1934 "scope" : "tree"
Nils Diewald86dad5b2015-01-28 15:09:07 +00001935 });
Nils Diewald7c8ced22015-04-15 19:21:00 +00001936 expect(rewrite.toString()).toEqual('Modification of "tree" by "querySerializer"');
1937 });
Nils Diewald86dad5b2015-01-28 15:09:07 +00001938
Nils Diewald7c8ced22015-04-15 19:21:00 +00001939 it('should be deserialized by docs', function () {
1940 var doc = docClass.create(
Akron712733a2018-04-05 18:17:47 +02001941 undefined,
1942 {
1943 "@type":"koral:doc",
1944 "key":"Titel",
1945 "value":"Baum",
1946 "match":"match:eq"
1947 });
Nils Diewald7c8ced22015-04-15 19:21:00 +00001948
1949 expect(doc.element().classList.contains('doc')).toBeTruthy();
1950 expect(doc.element().classList.contains('rewritten')).toBe(false);
1951
1952 doc = docClass.create(
Akron712733a2018-04-05 18:17:47 +02001953 undefined,
1954 {
1955 "@type":"koral:doc",
1956 "key":"Titel",
1957 "value":"Baum",
1958 "match":"match:eq",
1959 "rewrites" : [
1960 {
1961 "@type" : "koral:rewrite",
1962 "operation" : "operation:modification",
1963 "src" : "querySerializer",
1964 "scope" : "tree"
1965 }
1966 ]
1967 });
Nils Diewald7c8ced22015-04-15 19:21:00 +00001968
1969 expect(doc.element().classList.contains('doc')).toBeTruthy();
1970 expect(doc.element().classList.contains('rewritten')).toBeTruthy();
1971 });
Nils Diewald6283d692015-04-23 20:32:53 +00001972
1973 xit('should be deserialized by docGroups', function () {
1974 var docGroup = docGroupClass.create(
Akron712733a2018-04-05 18:17:47 +02001975 undefined,
1976 {
1977 "@type" : "koral:docGroup",
1978 "operation" : "operation:or",
1979 "operands" : [
1980 {
1981 "@type" : "doc",
1982 "key" : "pubDate",
1983 "type" : "type:date",
1984 "value" : "2014-12-05"
1985 },
1986 {
1987 "@type" : "doc",
1988 "key" : "pubDate",
1989 "type" : "type:date",
1990 "value" : "2014-12-06"
1991 }
1992 ],
1993 "rewrites" : [
1994 {
1995 "@type" : "koral:rewrite",
1996 "operation" : "operation:modification",
1997 "src" : "querySerializer",
1998 "scope" : "tree"
1999 }
2000 ]
2001 }
Nils Diewald6283d692015-04-23 20:32:53 +00002002 );
2003
2004 expect(doc.element().classList.contains('docgroup')).toBeTruthy();
2005 expect(doc.element().classList.contains('rewritten')).toBe(false);
2006 });
Nils Diewald86dad5b2015-01-28 15:09:07 +00002007 });
Nils Diewaldf0c4f112015-05-05 12:56:59 +00002008
2009 describe('KorAP.stringValue', function () {
2010 it('should be initializable', function () {
2011 var sv = stringValClass.create();
2012 expect(sv.regex()).toBe(false);
2013 expect(sv.value()).toBe('');
Nils Diewaldc4c4b832015-05-05 16:00:08 +00002014
2015 sv = stringValClass.create('Baum');
2016 expect(sv.regex()).toBe(false);
2017 expect(sv.value()).toBe('Baum');
2018
2019 sv = stringValClass.create('Baum', false);
2020 expect(sv.regex()).toBe(false);
2021 expect(sv.value()).toBe('Baum');
2022
2023 sv = stringValClass.create('Baum', true);
2024 expect(sv.regex()).toBe(true);
2025 expect(sv.value()).toBe('Baum');
2026 });
2027
2028 it('should be modifiable', function () {
2029 var sv = stringValClass.create();
2030 expect(sv.regex()).toBe(false);
2031 expect(sv.value()).toBe('');
2032
2033 expect(sv.value('Baum')).toBe('Baum');
2034 expect(sv.value()).toBe('Baum');
2035
2036 expect(sv.regex(true)).toBe(true);
2037 expect(sv.regex()).toBe(true);
2038 });
2039
2040 it('should have a toggleble regex value', function () {
2041 var sv = stringValClass.create();
Nils Diewald7991a3f2015-05-19 14:12:37 +00002042
2043 expect(sv.element().firstChild.value).toBe('');
2044 sv.element().firstChild.value = 'der'
2045 expect(sv.element().firstChild.value).toBe('der');
2046
Nils Diewaldc4c4b832015-05-05 16:00:08 +00002047 expect(sv.regex()).toBe(false);
2048
2049 sv.toggleRegex();
Nils Diewald7991a3f2015-05-19 14:12:37 +00002050 expect(sv.element().firstChild.value).toBe('der');
Nils Diewaldc4c4b832015-05-05 16:00:08 +00002051 expect(sv.regex()).toBe(true);
Nils Diewald7991a3f2015-05-19 14:12:37 +00002052 sv.element().firstChild.value = 'derbe'
Nils Diewaldc4c4b832015-05-05 16:00:08 +00002053
2054 sv.toggleRegex();
2055 expect(sv.regex()).toBe(false);
Nils Diewald7991a3f2015-05-19 14:12:37 +00002056 expect(sv.element().firstChild.value).toBe('derbe');
Nils Diewaldc4c4b832015-05-05 16:00:08 +00002057 });
2058
2059 it('should have an element', function () {
2060 var sv = stringValClass.create('der');
2061 expect(sv.element().nodeName).toBe('DIV');
2062 expect(sv.element().firstChild.nodeName).toBe('INPUT');
2063 expect(sv.element().firstChild.value).toBe('der');
2064 });
2065
2066 it('should have a classed element', function () {
2067 var sv = stringValClass.create();
Nils Diewaldc4c4b832015-05-05 16:00:08 +00002068 expect(sv.element().classList.contains('regex')).toBe(false);
2069 expect(sv.regex()).toBe(false);
2070 sv.toggleRegex();
2071 expect(sv.element().classList.contains('regex')).toBe(true);
2072 });
2073
2074 it('should be storable', function () {
2075 var sv = stringValClass.create();
2076 var count = 1;
2077 sv.store = function (value, regex) {
Akron712733a2018-04-05 18:17:47 +02002078 expect(regex).toBe(true);
2079 expect(value).toBe('tree');
Nils Diewaldc4c4b832015-05-05 16:00:08 +00002080 };
2081 sv.regex(true);
2082 sv.value('tree');
2083 sv.element().lastChild.click();
Nils Diewaldf0c4f112015-05-05 12:56:59 +00002084 });
Akron712733a2018-04-05 18:17:47 +02002085
Nils Diewaldf0c4f112015-05-05 12:56:59 +00002086 });
Akrone4961b12017-05-10 21:04:46 +02002087
Akron712733a2018-04-05 18:17:47 +02002088 describe('KorAP.VC.Menu', function () {
Akrone65a88a2018-04-05 19:14:20 +02002089
2090 var vc;
2091
Akron712733a2018-04-05 18:17:47 +02002092 it('should be initializable', function () {
2093
Akrone65a88a2018-04-05 19:14:20 +02002094 vc = vcClass.create([
Akron712733a2018-04-05 18:17:47 +02002095 ['a', 'text'],
2096 ['b', 'string'],
2097 ['c', 'date']
2098 ]).fromJson();
2099 expect(vc.element().firstChild.classList.contains('unspecified')).toBeTruthy();
2100 expect(vc.element().firstChild.firstChild.tagName).toEqual('SPAN');
2101
2102 // Click on unspecified
2103 vc.element().firstChild.firstChild.click();
2104 expect(vc.element().firstChild.firstChild.tagName).toEqual('UL');
2105
2106 var list = vc.element().firstChild.firstChild;
2107 expect(list.getElementsByTagName("LI")[0].innerText).toEqual('a');
2108 expect(list.getElementsByTagName("LI")[1].innerText).toEqual('b');
2109 expect(list.getElementsByTagName("LI")[2].innerText).toEqual('c');
2110
2111 vc = vcClass.create([
2112 ['d', 'text'],
2113 ['e', 'string'],
2114 ['f', 'date']
2115 ]).fromJson();
2116 expect(vc.element().firstChild.classList.contains('unspecified')).toBeTruthy();
2117 expect(vc.element().firstChild.firstChild.tagName).toEqual('SPAN');
2118
2119 // Click on unspecified
2120 vc.element().firstChild.firstChild.click();
2121 expect(vc.element().firstChild.firstChild.tagName).toEqual('UL');
2122
2123 list = vc.element().firstChild.firstChild;
2124 expect(list.getElementsByTagName("LI")[0].innerText).toEqual('d');
2125 expect(list.getElementsByTagName("LI")[1].innerText).toEqual('e');
2126 expect(list.getElementsByTagName("LI")[2].innerText).toEqual('f');
Akron31d89942018-04-06 16:44:51 +02002127 // blur
2128 document.body.click();
Akron712733a2018-04-05 18:17:47 +02002129 });
Akrone65a88a2018-04-05 19:14:20 +02002130
2131 // Reinitialize to make tests stable
2132 vc = vcClass.create([
2133 ['d', 'text'],
2134 ['e', 'string'],
2135 ['f', 'date']
2136 ]).fromJson();
2137
2138 it('should be clickable on key', function () {
Akron31d89942018-04-06 16:44:51 +02002139 // Click on unspecified
2140 vc.element().firstChild.firstChild.click();
Akrone65a88a2018-04-05 19:14:20 +02002141 // Click on "d"
2142 vc.element().firstChild.firstChild.getElementsByTagName("LI")[0].click();
2143 expect(vc.element().firstChild.firstChild.tagName).toEqual('SPAN');
2144 expect(vc.element().firstChild.firstChild.innerText).toEqual('d');
2145 expect(vc.element().firstChild.children[1].innerText).toEqual('eq');
2146 expect(vc.element().firstChild.children[1].getAttribute('data-type')).toEqual('text');
Akron31d89942018-04-06 16:44:51 +02002147 // blur
2148 document.body.click();
Akrone65a88a2018-04-05 19:14:20 +02002149 });
2150
Akron31d89942018-04-06 16:44:51 +02002151 it('should be clickable on operation for text', function () {
2152 // Click on "d" (or unspecified)
2153 vc.element().firstChild.firstChild.click();
2154
2155 // Choose "d"
2156 vc.element().firstChild.firstChild.getElementsByTagName("LI")[0].click();
2157
2158 // Click on matchop
Akrone65a88a2018-04-05 19:14:20 +02002159 vc.element().firstChild.children[1].click();
Akron31d89942018-04-06 16:44:51 +02002160
Akrone65a88a2018-04-05 19:14:20 +02002161 expect(vc.element().firstChild.children[1].tagName).toEqual('UL');
Akron31d89942018-04-06 16:44:51 +02002162
Akrone65a88a2018-04-05 19:14:20 +02002163 var ul = vc.element().firstChild.children[1];
2164 expect(ul.getElementsByTagName('li')[0].innerText).toEqual("eq");
2165 expect(ul.getElementsByTagName('li')[1].innerText).toEqual("ne");
2166 expect(ul.getElementsByTagName('li')[2].innerText).toEqual("contains");
2167 expect(ul.getElementsByTagName('li')[3].innerText).toEqual("containsnot");
2168 expect(ul.getElementsByTagName('li')[4]).toBeUndefined();
Akron31d89942018-04-06 16:44:51 +02002169
2170 // Choose "contains"
2171 ul.getElementsByTagName('li')[2].click();
2172 expect(vc.element().firstChild.children[1].tagName).toEqual("SPAN");
2173 expect(vc.element().firstChild.children[1].innerText).toEqual("contains");
2174 // blur
2175 document.body.click();
Akrone65a88a2018-04-05 19:14:20 +02002176 })
Akron31d89942018-04-06 16:44:51 +02002177
2178 it('should be clickable on operation for string', function () {
2179 // Click on "d" (or unspecified)
2180 vc.element().firstChild.firstChild.click();
2181
2182 // Choose "e"
2183 vc.element().firstChild.firstChild.getElementsByTagName("LI")[1].click();
2184
2185 // As a consequence the matchoperator may no longer
2186 // be valid and needs to be re-evaluated
2187 var fc = vc.element().firstChild;
2188 expect(fc.firstChild.tagName).toEqual('SPAN');
2189 expect(fc.firstChild.innerText).toEqual('e');
2190 expect(fc.children[1].innerText).toEqual('eq');
2191 expect(fc.children[1].getAttribute('data-type')).toEqual('string');
2192
2193 vc.element().firstChild.children[1].click();
2194
2195 expect(vc.element().firstChild.children[1].tagName).toEqual('UL');
2196
2197 var ul = vc.element().firstChild.children[1];
2198 expect(ul.getElementsByTagName('li')[0].innerText).toEqual("eq");
2199 expect(ul.getElementsByTagName('li')[1].innerText).toEqual("ne");
2200 expect(ul.getElementsByTagName('li')[2]).toBeUndefined();
2201
2202 // Choose "ne"
2203 ul.getElementsByTagName('li')[1].click();
2204 expect(vc.element().firstChild.children[1].tagName).toEqual("SPAN");
2205 expect(vc.element().firstChild.children[1].innerText).toEqual("ne");
2206 // blur
2207 document.body.click();
2208 });
2209
2210 it('should be clickable on operation for date', function () {
2211
2212 // Replay matchop check - so it's guaranteed that "ne" is chosen
2213 // Click on "e" (or unspecified)
2214 vc.element().firstChild.firstChild.click();
2215 // Rechoose "e"
2216 vc.element().firstChild.firstChild.getElementsByTagName("LI")[1].click();
2217 // Click on matchop
2218 vc.element().firstChild.children[1].click();
2219 // Choose "ne"
2220 vc.element().firstChild.children[1].getElementsByTagName('li')[1].click();
2221 expect(vc.element().firstChild.children[1].innerText).toEqual("ne");
2222
2223 // Click on "e"
2224 vc.element().firstChild.firstChild.click();
2225 // Choose "f"
2226 vc.element().firstChild.firstChild.getElementsByTagName("LI")[2].click();
2227
2228 // The matchoperator should still be "ne" as this is valid for dates as well (now)
2229 var fc = vc.element().firstChild;
2230 expect(fc.firstChild.tagName).toEqual('SPAN');
2231 expect(fc.firstChild.innerText).toEqual('f');
2232 expect(fc.children[1].innerText).toEqual('ne');
2233 // blur
2234 document.body.click();
2235 });
Akronddc98a72018-04-06 17:33:52 +02002236
2237
2238 // Check json deserialization
2239 it('should be initializable', function () {
2240 vc = vcClass.create([
2241 ['a', 'text'],
2242 ['b', 'string'],
2243 ['c', 'date']
2244 ]).fromJson({
2245 "@type" : "koral:doc",
2246 "key":"a",
2247 "value":"Baum"
2248 });
2249
2250 expect(vc.element().firstChild.children[1].getAttribute('data-type')).toEqual('text');
2251 });
Akron712733a2018-04-05 18:17:47 +02002252 });
2253
2254
Akrone4961b12017-05-10 21:04:46 +02002255 // Check prefix
2256 describe('KorAP.VC.Prefix', function () {
2257
2258 it('should be initializable', function () {
2259 var p = prefixClass.create();
2260 expect(p.element().classList.contains('pref')).toBeTruthy();
2261 expect(p.isSet()).not.toBeTruthy();
2262 });
2263
2264
2265 it('should be clickable', function () {
2266 var vc = vcClass.create([
Akron712733a2018-04-05 18:17:47 +02002267 ['a', null],
2268 ['b', null],
2269 ['c', null]
2270 ]).fromJson();
Akrone4961b12017-05-10 21:04:46 +02002271 expect(vc.element().firstChild.classList.contains('unspecified')).toBeTruthy();
2272
2273 // This should open up the menu
2274 vc.element().firstChild.firstChild.click();
2275 expect(vc.element().firstChild.firstChild.tagName).toEqual('UL');
2276
2277 KorAP._vcKeyMenu._prefix.clear();
2278 KorAP._vcKeyMenu._prefix.add('x');
2279
2280 var prefElement = vc.element().querySelector('span.pref');
2281 expect(prefElement.innerText).toEqual('x');
2282
2283 // This should add key 'x' to VC
2284 prefElement.click();
2285
2286 expect(vc.element().firstChild.classList.contains('doc')).toBeTruthy();
2287 expect(vc.element().firstChild.firstChild.className).toEqual('key');
2288 expect(vc.element().firstChild.firstChild.innerText).toEqual('x');
2289 });
2290 });
Nils Diewald2fe12e12015-03-06 16:47:06 +00002291});