blob: 87442bde850c5f68648f5ea528b0573e2950f39f [file] [log] [blame]
Nils Diewald6ac292b2015-01-15 21:33:21 +00001/*
Nils Diewald7c8ced22015-04-15 19:21:00 +00002 * Todo: In demoSpec: Create "and" on the last element of the top "or"-Group
3 */
Akrondd5c6d32018-08-17 14:12:58 +02004define([
5 'vc',
6 'vc/doc',
7 'vc/menu',
8 'vc/prefix',
9 'vc/docgroup',
10 'vc/docgroupref',
11 'vc/unspecified',
12 'vc/operators',
13 'vc/rewrite',
14 'vc/stringval'
15], function (vcClass,
16 docClass,
17 menuClass,
18 prefixClass,
19 docGroupClass,
20 docGroupRefClass,
21 unspecifiedClass,
22 operatorsClass,
23 rewriteClass,
24 stringValClass) {
Nils Diewald6ac292b2015-01-15 21:33:21 +000025
Akrondd5c6d32018-08-17 14:12:58 +020026 KorAP._vcKeyMenu = undefined;
27
Nils Diewald6ac292b2015-01-15 21:33:21 +000028
Nils Diewald7c8ced22015-04-15 19:21:00 +000029 // Helper method for building factories
30 buildFactory = function (objClass, defaults) {
31 return {
32 create : function (overwrites) {
Akron712733a2018-04-05 18:17:47 +020033 var newObj = {};
34 for (var prop in defaults) {
35 newObj[prop] = defaults[prop];
36 };
37 for (var prop in overwrites) {
38 newObj[prop] = overwrites[prop];
39 };
40 return objClass.create().fromJson(newObj);
Nils Diewald7c8ced22015-04-15 19:21:00 +000041 }
Nils Diewald0b6c0412014-12-19 03:55:57 +000042 }
Nils Diewald7c8ced22015-04-15 19:21:00 +000043 };
Nils Diewald0b6c0412014-12-19 03:55:57 +000044
Nils Diewald7c8ced22015-04-15 19:21:00 +000045 function _andOn (obj) {
Akrond141a362018-07-10 18:12:13 +020046 KorAP._and.apply(obj);
Nils Diewald7c8ced22015-04-15 19:21:00 +000047 };
Nils Diewald52f7eb12015-01-12 17:30:04 +000048
Nils Diewald7c8ced22015-04-15 19:21:00 +000049 function _orOn (obj) {
Akrond141a362018-07-10 18:12:13 +020050 KorAP._or.apply(obj);
Nils Diewald7c8ced22015-04-15 19:21:00 +000051 };
Nils Diewald52f7eb12015-01-12 17:30:04 +000052
Nils Diewald7c8ced22015-04-15 19:21:00 +000053 function _delOn (obj) {
Akrond141a362018-07-10 18:12:13 +020054 KorAP._delete.apply(obj);
Nils Diewald7c8ced22015-04-15 19:21:00 +000055 };
Nils Diewald52f7eb12015-01-12 17:30:04 +000056
Nils Diewald7c8ced22015-04-15 19:21:00 +000057 var demoFactory = buildFactory(vcClass, {
58 "@type":"koral:docGroup",
59 "operation":"operation:or",
60 "operands":[
Nils Diewaldf219eb82015-01-07 20:15:42 +000061 {
Akron712733a2018-04-05 18:17:47 +020062 "@type":"koral:docGroup",
63 "operation":"operation:and",
64 "operands":[
Nils Diewald7c8ced22015-04-15 19:21:00 +000065 {
66 "@type":"koral:doc",
67 "key":"Titel",
68 "value":"Baum",
69 "match":"match:eq"
70 },
71 {
72 "@type":"koral:doc",
73 "key":"Veröffentlichungsort",
74 "value":"hihi",
75 "match":"match:eq"
76 },
77 {
78 "@type":"koral:docGroup",
79 "operation":"operation:or",
80 "operands":[
81 {
Akron712733a2018-04-05 18:17:47 +020082 "@type":"koral:doc",
83 "key":"Titel",
84 "value":"Baum",
85 "match":"match:eq"
Nils Diewald7c8ced22015-04-15 19:21:00 +000086 },
87 {
Akron712733a2018-04-05 18:17:47 +020088 "@type":"koral:doc",
89 "key":"Veröffentlichungsort",
90 "value":"hihi",
91 "match":"match:eq"
Nils Diewald7c8ced22015-04-15 19:21:00 +000092 }
93 ]
94 }
Akron712733a2018-04-05 18:17:47 +020095 ]
Nils Diewaldf219eb82015-01-07 20:15:42 +000096 },
97 {
Akron712733a2018-04-05 18:17:47 +020098 "@type":"koral:doc",
99 "key":"Untertitel",
100 "value":"huhu",
101 "match":"match:contains"
Nils Diewaldf219eb82015-01-07 20:15:42 +0000102 }
103 ]
104 });
105
Nils Diewald7c8ced22015-04-15 19:21:00 +0000106 describe('KorAP.Doc', function () {
107 // Create example factories
108 var stringFactory = buildFactory(docClass, {
109 "key" : "author",
110 "value" : "Max Birkendale",
Akron31d89942018-04-06 16:44:51 +0200111 "type" : "type:string",
Nils Diewald7c8ced22015-04-15 19:21:00 +0000112 "@type" : "koral:doc"
113 });
114
115 // Create example factories
Akron712733a2018-04-05 18:17:47 +0200116 var textFactory = buildFactory(docClass, {
117 "key" : "author",
118 "value" : "Birkendale",
Akron31d89942018-04-06 16:44:51 +0200119 "type" : "type:string",
Akron712733a2018-04-05 18:17:47 +0200120 "match" : "match:contains",
121 "@type" : "koral:doc"
122 });
123
124 // Create example factories
Nils Diewald7c8ced22015-04-15 19:21:00 +0000125 var dateFactory = buildFactory(docClass, {
126 "key" : "pubDate",
127 "type" : "type:date",
128 "match" : "match:eq",
129 "value" : "2014-11-05",
130 "@type" : "koral:doc"
131 });
132
133 // Create example factories
134 var regexFactory = buildFactory(docClass, {
135 "key" : "title",
136 "type" : "type:regex",
137 "value" : "[^b]ee.+?",
138 "@type" : "koral:doc"
139 });
140
141 it('should be initializable', function () {
142 var doc = docClass.create();
143 expect(doc.matchop()).toEqual('eq');
144 expect(doc.key()).toBeUndefined();
145 expect(doc.value()).toBeUndefined();
146 expect(doc.type()).toEqual("string");
147 });
148
149 it('should be definable', function () {
150
151 // Empty doc
152 var doc = docClass.create();
153
154 // Set values
155 doc.key("title");
Akron8db5e3a2018-05-28 19:25:26 +0200156
Nils Diewald7c8ced22015-04-15 19:21:00 +0000157 doc.value("Der alte Mann");
158 expect(doc.matchop()).toEqual('eq');
159 expect(doc.key()).toEqual("title");
160 expect(doc.type()).toEqual("string");
161 expect(doc.value()).toEqual("Der alte Mann");
162 });
163
164
165 it('should deserialize JSON-LD string', function () {
166 var doc;
167
168 // String default
169 doc = stringFactory.create();
170 expect(doc.matchop()).toEqual('eq');
171 expect(doc.key()).toEqual("author");
172 expect(doc.type()).toEqual("string");
173 expect(doc.value()).toEqual("Max Birkendale");
174
175 // No valid string
176 doc = stringFactory.create({
Akron712733a2018-04-05 18:17:47 +0200177 value : undefined
Nils Diewald7c8ced22015-04-15 19:21:00 +0000178 });
179 expect(doc).toBeUndefined();
180
181 // No valid string
182 doc = stringFactory.create({
Akron712733a2018-04-05 18:17:47 +0200183 value : { "foo" : "bar" }
Nils Diewald7c8ced22015-04-15 19:21:00 +0000184 });
185 expect(doc).toBeUndefined();
186
187 // Change match type
188 doc = stringFactory.create({
Akron712733a2018-04-05 18:17:47 +0200189 "match" : "match:ne"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000190 });
191
192 expect(doc.matchop()).toEqual('ne');
193 expect(doc.key()).toEqual("author");
194 expect(doc.type()).toEqual("string");
195 expect(doc.value()).toEqual("Max Birkendale");
196
197 // Invalid match type
198 doc = stringFactory.create({
Akron712733a2018-04-05 18:17:47 +0200199 "match" : { "foo" : "bar" }
Nils Diewald7c8ced22015-04-15 19:21:00 +0000200 });
201 expect(doc).toBeUndefined();
202 });
203
204 it('should deserialize JSON-LD regex', function () {
205 var doc = regexFactory.create();
206 expect(doc.key()).toEqual("title");
207 expect(doc.type()).toEqual("regex");
208 expect(doc.value()).toEqual("[^b]ee.+?");
209 expect(doc.matchop()).toEqual('eq');
210
211 // change matcher
212 doc = regexFactory.create({
Akron712733a2018-04-05 18:17:47 +0200213 match : "match:ne"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000214 });
215 expect(doc.matchop()).toEqual('ne');
Akronea4e9052017-07-06 16:12:05 +0200216 expect(doc.rewrites()).toBeUndefined();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000217
218 // Invalid matcher
219 doc = regexFactory.create({
Akron712733a2018-04-05 18:17:47 +0200220 match : "match:chook"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000221 });
Akronea4e9052017-07-06 16:12:05 +0200222 expect(doc.matchop()).toEqual('eq');
223 expect(doc.rewrites()).toBeDefined();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000224
225 // Invalid regex
226 doc = regexFactory.create({
Akron712733a2018-04-05 18:17:47 +0200227 value : "[^b"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000228 });
229 expect(doc).toBeUndefined();
230 });
231
232 it('should deserialize JSON-LD date', function () {
233
234 // Normal date
235 doc = dateFactory.create({});
236
237 expect(doc.matchop()).toEqual('eq');
238 expect(doc.key()).toEqual("pubDate");
239 expect(doc.type()).toEqual("date");
240 expect(doc.value()).toEqual("2014-11-05");
241
242 // Short date 1
243 doc = dateFactory.create({
Akron712733a2018-04-05 18:17:47 +0200244 "value" : "2014-11"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000245 });
246
247 expect(doc.matchop()).toEqual('eq');
248 expect(doc.key()).toEqual("pubDate");
249 expect(doc.type()).toEqual("date");
250 expect(doc.value()).toEqual("2014-11");
251
252 // Short date 2
253 doc = dateFactory.create({
Akron712733a2018-04-05 18:17:47 +0200254 "value" : "2014"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000255 });
256
257 expect(doc.matchop()).toEqual('eq');
258 expect(doc.key()).toEqual("pubDate");
259 expect(doc.type()).toEqual("date");
260 expect(doc.value()).toEqual("2014");
261
262 // Invalid date!
263 doc = dateFactory.create({
Akron712733a2018-04-05 18:17:47 +0200264 "value" : "2014-11-050"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000265 });
266 expect(doc).toBeUndefined();
267
268 // Invalid matcher!
269 doc = dateFactory.create({
Akron31d89942018-04-06 16:44:51 +0200270 "match" : "match:contains",
Nils Diewald7c8ced22015-04-15 19:21:00 +0000271 });
Akronea4e9052017-07-06 16:12:05 +0200272 expect(doc).toBeDefined();
273 expect(doc.rewrites()).toBeDefined();
274 expect(doc.matchop()).toEqual('eq');
Nils Diewald7c8ced22015-04-15 19:21:00 +0000275 });
276
277 it('should be serializale to JSON', function () {
278
279 // Empty doc
280 var doc = docClass.create();
281 expect(doc.toJson()).toEqual(jasmine.any(Object));
282
283 // Serialize string
284 doc = stringFactory.create();
285 expect(doc.toJson()).toEqual(jasmine.objectContaining({
Akron712733a2018-04-05 18:17:47 +0200286 "@type" : "koral:doc",
287 "type" : "type:string",
288 "key" : "author",
289 "value" : "Max Birkendale",
290 "match" : "match:eq"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000291 }));
292
293 // Serialize regex
294 doc = regexFactory.create();
295 expect(doc.toJson()).toEqual(jasmine.objectContaining({
Akron712733a2018-04-05 18:17:47 +0200296 "@type" : "koral:doc",
297 "type" : "type:regex",
298 "value" : "[^b]ee.+?",
299 "match" : "match:eq",
300 "key" : 'title'
Nils Diewald7c8ced22015-04-15 19:21:00 +0000301 }));
302
303 doc = regexFactory.create({
Akron712733a2018-04-05 18:17:47 +0200304 match: "match:ne"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000305 });
306 expect(doc.toJson()).toEqual(jasmine.objectContaining({
Akron712733a2018-04-05 18:17:47 +0200307 "@type" : "koral:doc",
308 "type" : "type:regex",
309 "value" : "[^b]ee.+?",
310 "match" : "match:ne",
311 "key" : 'title'
Nils Diewald7c8ced22015-04-15 19:21:00 +0000312 }));
313
314 doc = dateFactory.create();
315 expect(doc.toJson()).toEqual(jasmine.objectContaining({
Akron712733a2018-04-05 18:17:47 +0200316 "@type" : "koral:doc",
317 "type" : "type:date",
318 "value" : "2014-11-05",
319 "match" : "match:eq",
320 "key" : 'pubDate'
Nils Diewald7c8ced22015-04-15 19:21:00 +0000321 }));
322
323 doc = dateFactory.create({
Akron712733a2018-04-05 18:17:47 +0200324 value : "2014"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000325 });
326 expect(doc.toJson()).toEqual(jasmine.objectContaining({
Akron712733a2018-04-05 18:17:47 +0200327 "@type" : "koral:doc",
328 "type" : "type:date",
329 "value" : "2014",
330 "match" : "match:eq",
331 "key" : 'pubDate'
Nils Diewald7c8ced22015-04-15 19:21:00 +0000332 }));
333 });
334
335
336 it('should be serializale to String', function () {
337 // Empty doc
338 var doc = docClass.create();
339 expect(doc.toQuery()).toEqual("");
340
341 // Serialize string
342 doc = stringFactory.create();
343 expect(doc.toQuery()).toEqual('author = "Max Birkendale"');
344
345 // Serialize string with quotes
346 doc = stringFactory.create({ "value" : 'Max "Der Coole" Birkendate'});
347 expect(doc.toQuery()).toEqual('author = "Max \\"Der Coole\\" Birkendate"');
348
349 // Serialize regex
350 doc = regexFactory.create();
351 expect(doc.toQuery()).toEqual('title = /[^b]ee.+?/');
352
353 doc = regexFactory.create({
Akron712733a2018-04-05 18:17:47 +0200354 match: "match:ne"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000355 });
356 expect(doc.toQuery()).toEqual('title != /[^b]ee.+?/');
357
Akron8778f5d2017-06-30 21:25:55 +0200358 doc = regexFactory.create({
Akron712733a2018-04-05 18:17:47 +0200359 value: "WPD/AAA/00001"
Akron8778f5d2017-06-30 21:25:55 +0200360 });
361 expect(doc.toQuery()).toEqual('title = /WPD\\/AAA\\/00001/');
362
Nils Diewald7c8ced22015-04-15 19:21:00 +0000363 doc = dateFactory.create();
364 expect(doc.toQuery()).toEqual('pubDate in 2014-11-05');
365
366 doc = dateFactory.create({
Akron712733a2018-04-05 18:17:47 +0200367 value : "2014"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000368 });
369 expect(doc.toQuery()).toEqual('pubDate in 2014');
370 });
371 });
372
373
374 describe('KorAP.DocGroup', function () {
375 // Create example factories
376 var docFactory = buildFactory(
377 docClass,
Nils Diewaldf219eb82015-01-07 20:15:42 +0000378 {
Akron712733a2018-04-05 18:17:47 +0200379 "@type" : "koral:doc",
380 "match":"match:eq",
381 "key" : "author",
382 "value" : "Max Birkendale"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000383 }
384 );
385
386 var docGroupFactory = buildFactory(
387 docGroupClass, {
Akron712733a2018-04-05 18:17:47 +0200388 "@type" : "koral:docGroup",
389 "operation" : "operation:and",
390 "operands" : [
391 docFactory.create().toJson(),
392 docFactory.create({
393 "key" : "pubDate",
394 "type" : "type:date",
395 "value" : "2014-12-05"
396 }).toJson()
397 ]
Nils Diewald7c8ced22015-04-15 19:21:00 +0000398 });
399
400 it('should be initializable', function () {
401 // Create empty group
402 var docGroup = docGroupClass.create();
403 expect(docGroup.operation()).toEqual('and');
404
405 // Create empty group
406 docGroup = docGroupClass.create();
407 docGroup.operation('or');
408 expect(docGroup.operation()).toEqual('or');
409 });
410
411 it('should be definable', function () {
412
413 // Empty group
414 var docGroup = docGroupClass.create();
415 expect(docGroup.operation()).toEqual('and');
416
417 // Set values
418 docGroup.operation("or");
419 expect(docGroup.operation()).toEqual('or');
420
421 // Set invalid values
422 docGroup.operation("hui");
423 expect(docGroup.operation()).toEqual('or');
424 });
425
426 it('should be deserializable', function () {
427 var docGroup = docGroupFactory.create();
428 expect(docGroup.operation()).toEqual("and");
429 expect(docGroup.operands().length).toEqual(2);
430
431 var op1 = docGroup.getOperand(0);
432 expect(op1.type()).toEqual("string");
433 expect(op1.key()).toEqual("author");
434 expect(op1.value()).toEqual("Max Birkendale");
435 expect(op1.matchop()).toEqual("eq");
436
437 var op2 = docGroup.getOperand(1);
438 expect(op2.type()).toEqual("date");
439 expect(op2.key()).toEqual("pubDate");
440 expect(op2.value()).toEqual("2014-12-05");
441 expect(op2.matchop()).toEqual("eq");
442
443 // Append empty group
444 var newGroup = docGroup.append(docGroupClass.create());
445 newGroup.operation('or');
446 newGroup.append(docFactory.create());
447 newGroup.append(docFactory.create({
Akron712733a2018-04-05 18:17:47 +0200448 "type" : "type:regex",
449 "key" : "title",
450 "value" : "^e.+?$",
451 "match" : "match:ne"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000452 }));
453
454 expect(docGroup.operation()).toEqual("and");
455 expect(docGroup.operands().length).toEqual(3);
456
457 var op1 = docGroup.getOperand(0);
458 expect(op1.ldType()).toEqual("doc");
459 expect(op1.type()).toEqual("string");
460 expect(op1.key()).toEqual("author");
461 expect(op1.value()).toEqual("Max Birkendale");
462 expect(op1.matchop()).toEqual("eq");
463
464 var op2 = docGroup.getOperand(1);
465 expect(op2.ldType()).toEqual("doc");
466 expect(op2.type()).toEqual("date");
467 expect(op2.key()).toEqual("pubDate");
468 expect(op2.value()).toEqual("2014-12-05");
469 expect(op2.matchop()).toEqual("eq");
470
471 var op3 = docGroup.getOperand(2);
472 expect(op3.ldType()).toEqual("docGroup");
473 expect(op3.operation()).toEqual("or");
474
475 var op4 = op3.getOperand(0);
476 expect(op4.ldType()).toEqual("doc");
477 expect(op4.type()).toEqual("string");
478 expect(op4.key()).toEqual("author");
479 expect(op4.value()).toEqual("Max Birkendale");
480 expect(op4.matchop()).toEqual("eq");
481
482 var op5 = op3.getOperand(1);
483 expect(op5.ldType()).toEqual("doc");
484 expect(op5.type()).toEqual("regex");
485 expect(op5.key()).toEqual("title");
486 expect(op5.value()).toEqual("^e.+?$");
487 expect(op5.matchop()).toEqual("ne");
488 });
489
490 it('should be serializable to JSON', function () {
491 var docGroup = docGroupFactory.create();
492
493 expect(docGroup.toJson()).toEqual(jasmine.objectContaining({
Akron712733a2018-04-05 18:17:47 +0200494 "@type" : "koral:docGroup",
495 "operation" : "operation:and",
496 "operands" : [
497 {
498 "@type": 'koral:doc',
499 "key" : 'author',
500 "match": 'match:eq',
501 "value": 'Max Birkendale',
502 "type": 'type:string'
503 },
504 {
505 "@type": 'koral:doc',
506 "key": 'pubDate',
507 "match": 'match:eq',
508 "value": '2014-12-05',
509 "type": 'type:date'
510 }
511 ]
Nils Diewald7c8ced22015-04-15 19:21:00 +0000512 }));
513 });
Nils Diewalde15b7a22015-01-09 21:50:21 +0000514
Nils Diewald7c8ced22015-04-15 19:21:00 +0000515 it('should be serializable to String', function () {
516 var docGroup = docGroupFactory.create();
517 expect(docGroup.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +0200518 'author = "Max Birkendale" & pubDate in 2014-12-05'
Nils Diewald7c8ced22015-04-15 19:21:00 +0000519 );
Nils Diewald52f7eb12015-01-12 17:30:04 +0000520
Nils Diewald7c8ced22015-04-15 19:21:00 +0000521 docGroup = docGroupFactory.create({
Akron712733a2018-04-05 18:17:47 +0200522 "@type" : "koral:docGroup",
523 "operation" : "operation:or",
524 "operands" : [
525 {
526 "@type": 'koral:doc',
527 "key" : 'author',
528 "match": 'match:eq',
529 "value": 'Max Birkendale',
530 "type": 'type:string'
531 },
532 {
533 "@type" : "koral:docGroup",
534 "operation" : "operation:and",
535 "operands" : [
536 {
537 "@type": 'koral:doc',
538 "key": 'pubDate',
539 "match": 'match:geq',
540 "value": '2014-05-12',
541 "type": 'type:date'
542 },
543 {
544 "@type": 'koral:doc',
545 "key": 'pubDate',
546 "match": 'match:leq',
547 "value": '2014-12-05',
548 "type": 'type:date'
549 },
550 {
551 "@type": 'koral:doc',
552 "key": 'foo',
553 "match": 'match:ne',
554 "value": '[a]?bar',
555 "type": 'type:regex'
556 }
557 ]
558 }
559 ]
Nils Diewald7c8ced22015-04-15 19:21:00 +0000560 });
561 expect(docGroup.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +0200562 'author = "Max Birkendale" | ' +
563 '(pubDate since 2014-05-12 & ' +
564 'pubDate until 2014-12-05 & foo != /[a]?bar/)'
Nils Diewald7c8ced22015-04-15 19:21:00 +0000565 );
566 });
567 });
568
Akronb19803c2018-08-16 16:39:42 +0200569 describe('KorAP.DocGroupRef', function () {
570 // Create example factories
571 var docRefFactory = buildFactory(
572 docGroupRefClass,
573 {
574 "@type" : "koral:docGroupRef",
575 "ref" : "@max/myCorpus"
576 }
577 );
578
579 it('should be initializable', function () {
580 var vcRef = docGroupRefClass.create();
581 expect(vcRef.ref()).toBeUndefined();
582 });
583
584 it('should be definable', function () {
585 var vcRef = docGroupRefClass.create();
586 vcRef.ref("@peter/mycorpus");
587 expect(vcRef.ref()).toEqual("@peter/mycorpus");
588 vcRef.ref("@peter/mycorpus2");
589 expect(vcRef.ref()).toEqual("@peter/mycorpus2");
590 });
591
592 it('should deserialize JSON-LD string', function () {
593 var vcRef = docRefFactory.create();
594 expect(vcRef.ref()).toEqual("@max/myCorpus");
595 });
596
597 it('should serialize to JSON-LD', function () {
598 var vcRef = docRefFactory.create();
599 expect(vcRef.toJson()).toEqual(jasmine.objectContaining({
600 "@type" : "koral:docGroupRef",
601 "ref":"@max/myCorpus"
602 }));
603
604 vcRef.ref("@peter/myCorpus2");
605 expect(vcRef.toJson()).toEqual(jasmine.objectContaining({
606 "@type" : "koral:docGroupRef",
607 "ref":"@peter/myCorpus2"
608 }));
609 });
610
611 it('should serialize to a query', function () {
612 var vcRef = docRefFactory.create();
613 expect(vcRef.toQuery()).toEqual(
614 "referTo \"@max/myCorpus\""
615 );
616
617 vcRef.ref("@peter/myCorpus2");
618 expect(vcRef.toQuery()).toEqual(
619 "referTo \"@peter/myCorpus2\""
620 );
621 });
622 });
623
624
Nils Diewald7c8ced22015-04-15 19:21:00 +0000625 describe('KorAP.UnspecifiedDoc', function () {
626 it('should be initializable', function () {
627 var doc = unspecifiedClass.create();
628 var docElement = doc.element();
629 expect(docElement.getAttribute('class')).toEqual('doc unspecified');
630 expect(docElement.firstChild.firstChild.data).toEqual('⋯');
631 expect(docElement.lastChild.lastChild.data).toEqual('⋯');
632 expect(doc.toQuery()).toEqual('');
633
634 // Only removable
635 expect(docElement.lastChild.children.length).toEqual(0);
636 });
637
Akrond141a362018-07-10 18:12:13 +0200638 it('should be removable, when no root', function () {
Nils Diewald7c8ced22015-04-15 19:21:00 +0000639 var docGroup = docGroupClass.create();
640 docGroup.operation('or');
641 expect(docGroup.operation()).toEqual('or');
642
643 docGroup.append({
Akron712733a2018-04-05 18:17:47 +0200644 "@type": 'koral:doc',
645 "key": 'pubDate',
646 "match": 'match:eq',
647 "value": '2014-12-05',
648 "type": 'type:date'
Nils Diewald7c8ced22015-04-15 19:21:00 +0000649 });
650
651 // Add unspecified object
652 docGroup.append();
653
Akrond141a362018-07-10 18:12:13 +0200654 var parent = document.createElement('div');
655 parent.appendChild(docGroup.element());
656
Nils Diewald7c8ced22015-04-15 19:21:00 +0000657 expect(docGroup.element().getAttribute('class')).toEqual('docGroup');
658 expect(docGroup.element().children[0].getAttribute('class')).toEqual('doc');
659
660 var unspec = docGroup.element().children[1];
661 expect(unspec.getAttribute('class')).toEqual('doc unspecified');
662
Akronb19803c2018-08-16 16:39:42 +0200663 // Only unspec and delete
664 expect(unspec.children.length).toEqual(2);
665
Nils Diewald7c8ced22015-04-15 19:21:00 +0000666 // Removable
667 expect(unspec.lastChild.children.length).toEqual(1);
668 expect(unspec.lastChild.children[0].getAttribute('class')).toEqual('delete');
669 });
670
Akrond141a362018-07-10 18:12:13 +0200671
Nils Diewald7c8ced22015-04-15 19:21:00 +0000672 it('should be replaceable by a doc', function () {
673 var doc = unspecifiedClass.create();
674 expect(doc.ldType()).toEqual("non");
675 // No parent, therefor not updateable
676 expect(doc.key("baum")).toBeNull();
677
678 var docGroup = docGroupClass.create();
679 docGroup.operation('or');
680 expect(docGroup.operation()).toEqual('or');
681
682 docGroup.append({
Akron712733a2018-04-05 18:17:47 +0200683 "@type": 'koral:doc',
684 "key": 'pubDate',
685 "match": 'match:eq',
686 "value": '2014-12-05',
687 "type": 'type:date'
Nils Diewald7c8ced22015-04-15 19:21:00 +0000688 });
689
690 expect(docGroup.toQuery()).toEqual("pubDate in 2014-12-05");
691 docGroup.append();
692
693 expect(docGroup.getOperand(0).ldType()).toEqual("doc");
694 expect(docGroup.getOperand(1).ldType()).toEqual("non");
695
696 var op = docGroup.getOperand(1).element().lastChild;
Akron0b489ad2018-02-02 16:49:32 +0100697 expect(op.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +0000698 expect(op.children[0].getAttribute('class')).toEqual('delete');
699 expect(op.children.length).toEqual(1);
700
701 // Replace unspecified doc
702 expect(docGroup.getOperand(1).key("name")).not.toBeNull();
703 expect(docGroup.getOperand(1).ldType()).toEqual("doc");
704 expect(docGroup.getOperand(1).key()).toEqual("name");
Akron55a343b2018-04-06 19:57:36 +0200705 expect(docGroup.getOperand(1).value()).toBeUndefined();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000706
Akronb19803c2018-08-16 16:39:42 +0200707 expect(docGroup.getOperand(1).element().children.length).toEqual(4);
708
Nils Diewald7c8ced22015-04-15 19:21:00 +0000709 op = docGroup.getOperand(1).element().lastChild;
Akron0b489ad2018-02-02 16:49:32 +0100710 expect(op.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +0000711 expect(op.children[0].getAttribute('class')).toEqual('and');
712 expect(op.children[1].getAttribute('class')).toEqual('or');
713 expect(op.children[2].getAttribute('class')).toEqual('delete');
Akronb19803c2018-08-16 16:39:42 +0200714
Nils Diewald7c8ced22015-04-15 19:21:00 +0000715 expect(op.children.length).toEqual(3);
716
717 docGroup.getOperand(1).value("Pachelbel");
718 expect(docGroup.getOperand(1).value()).toEqual("Pachelbel");
719 expect(docGroup.getOperand(1).type()).toEqual("string");
720 expect(docGroup.getOperand(1).matchop()).toEqual("eq");
721
722 // Specified!
723 expect(docGroup.toQuery()).toEqual('pubDate in 2014-12-05 | name = "Pachelbel"');
724 });
Akronb19803c2018-08-16 16:39:42 +0200725
Nils Diewald7c8ced22015-04-15 19:21:00 +0000726 it('should be replaceable on root', function () {
Nils Diewald6283d692015-04-23 20:32:53 +0000727 var vc = vcClass.create();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000728 expect(vc.toQuery()).toEqual("");
729
730 expect(vc.root().ldType()).toEqual("non");
731
732 // No operators on root
733 op = vc.root().element().lastChild;
734 expect(op.lastChild.textContent).toEqual('⋯');
735
736 // Replace
737 expect(vc.root().key("baum")).not.toBeNull();
738 expect(vc.root().ldType()).toEqual("doc");
739
740 op = vc.root().element().lastChild;
Akron0b489ad2018-02-02 16:49:32 +0100741 expect(op.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +0000742 expect(op.children[0].getAttribute('class')).toEqual('and');
743 expect(op.children[1].getAttribute('class')).toEqual('or');
744 expect(op.children[2].getAttribute('class')).toEqual('delete');
745 expect(op.children.length).toEqual(3);
746 });
Akron55a343b2018-04-06 19:57:36 +0200747
748 it('should be clickable', function () {
749 var vc = vcClass.create([
750 ["pubDate", "date"]
751 ]);
752 expect(vc.toQuery()).toEqual("");
753 expect(vc.element().firstChild.textContent).toEqual("⋯");
754 vc.element().firstChild.firstChild.click();
755
756 // Click on pubDate
Akron3ad46942018-08-22 16:47:14 +0200757 vc.element().firstChild.getElementsByTagName("LI")[1].click();
Akron55a343b2018-04-06 19:57:36 +0200758
759 expect(vc.element().firstChild.firstChild.textContent).toEqual("pubDate");
760 expect(vc.element().firstChild.children[1].getAttribute("data-type")).toEqual("date");
761 });
Nils Diewald7c8ced22015-04-15 19:21:00 +0000762 });
763
764 describe('KorAP.Doc element', function () {
765 it('should be initializable', function () {
766 var docElement = docClass.create(undefined, {
Akron712733a2018-04-05 18:17:47 +0200767 "@type" : "koral:doc",
768 "key":"Titel",
769 "value":"Baum",
770 "match":"match:eq"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000771 });
772 expect(docElement.key()).toEqual('Titel');
773 expect(docElement.matchop()).toEqual('eq');
774 expect(docElement.value()).toEqual('Baum');
775
776 var docE = docElement.element();
777 expect(docE.children[0].firstChild.data).toEqual('Titel');
778 expect(docE.children[1].firstChild.data).toEqual('eq');
779 expect(docE.children[1].getAttribute('data-type')).toEqual('string');
780 expect(docE.children[2].firstChild.data).toEqual('Baum');
781 expect(docE.children[2].getAttribute('data-type')).toEqual('string');
782
783 expect(docElement.toJson()).toEqual(jasmine.objectContaining({
Akron712733a2018-04-05 18:17:47 +0200784 "@type" : "koral:doc",
785 "key":"Titel",
786 "value":"Baum",
787 "match":"match:eq"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000788 }));
789 });
Akronb19803c2018-08-16 16:39:42 +0200790
791
792 it('should be replacable by unspecified', function () {
793 var vc = vcClass.create([
794 ["pubDate", "date"]
795 ]).fromJson({
796 "@type" : "koral:doc",
797 "key":"Titel",
798 "value":"Baum",
799 "match":"match:eq"
800 });
801 expect(vc.toQuery()).toEqual("Titel = \"Baum\"");
802
803 var vcE = vc.element();
804 expect(vcE.firstChild.children.length).toEqual(4);
805
806 // Click to delete
807 vcE.firstChild.lastChild.lastChild.click();
808
809 expect(vcE.firstChild.children.length).toEqual(1);
810
811 expect(vcE.firstChild.textContent).toEqual("⋯");
812 vcE.firstChild.firstChild.click();
813
814 // Click on pubDate
Akron3ad46942018-08-22 16:47:14 +0200815 vcE.firstChild.getElementsByTagName("LI")[1].click();
Akronb19803c2018-08-16 16:39:42 +0200816
817 expect(vcE.firstChild.firstChild.textContent).toEqual("pubDate");
818 expect(vcE.firstChild.children[1].getAttribute("data-type")).toEqual("date");
819
820 expect(vcE.firstChild.children.length).toEqual(4);
821 });
822
823
824 it('should be replaceable by a docGroupRef', function () {
Akron3ad46942018-08-22 16:47:14 +0200825 var vc = vcClass.create().fromJson({
Akronb19803c2018-08-16 16:39:42 +0200826 "@type" : "koral:doc",
827 "key":"Titel",
828 "value":"Baum",
829 "match":"match:eq"
830 });
831
832 expect(vc.toQuery()).toEqual("Titel = \"Baum\"");
833
834 var vcE = vc.element();
835 expect(vcE.firstChild.children.length).toEqual(4);
836
837 // Click to delete
838 vcE.firstChild.lastChild.lastChild.click();
839
840 expect(vcE.firstChild.children.length).toEqual(1);
841
842 expect(vcE.firstChild.textContent).toEqual("⋯");
843 vcE.firstChild.firstChild.click();
844
Akron3ad46942018-08-22 16:47:14 +0200845 // Click on referTo
Akronb19803c2018-08-16 16:39:42 +0200846 vcE.firstChild.getElementsByTagName("LI")[0].click();
847
Akron3ad46942018-08-22 16:47:14 +0200848 expect(vcE.firstChild.firstChild.textContent).toEqual("referTo");
Akronb19803c2018-08-16 16:39:42 +0200849 expect(vcE.firstChild.children[1].getAttribute("data-type")).toEqual("string");
850 expect(vcE.firstChild.children.length).toEqual(3);
851 });
Nils Diewald7c8ced22015-04-15 19:21:00 +0000852 });
853
854 describe('KorAP.DocGroup element', function () {
855 it('should be initializable', function () {
856
857 var docGroup = docGroupClass.create(undefined, {
Akron712733a2018-04-05 18:17:47 +0200858 "@type" : "koral:docGroup",
859 "operation" : "operation:and",
860 "operands" : [
861 {
862 "@type": 'koral:doc',
863 "key" : 'author',
864 "match": 'match:eq',
865 "value": 'Max Birkendale',
866 "type": 'type:string'
867 },
868 {
869 "@type": 'koral:doc',
870 "key": 'pubDate',
871 "match": 'match:eq',
872 "value": '2014-12-05',
873 "type": 'type:date'
874 }
875 ]
Nils Diewald7c8ced22015-04-15 19:21:00 +0000876 });
877
878 expect(docGroup.operation()).toEqual('and');
879 var e = docGroup.element();
880 expect(e.getAttribute('class')).toEqual('docGroup');
881 expect(e.getAttribute('data-operation')).toEqual('and');
882
883 var first = e.children[0];
884 expect(first.getAttribute('class')).toEqual('doc');
885 expect(first.children[0].getAttribute('class')).toEqual('key');
886 expect(first.children[1].getAttribute('class')).toEqual('match');
887 expect(first.children[2].getAttribute('class')).toEqual('value');
888 expect(first.children[2].getAttribute('data-type')).toEqual('string');
889 expect(first.children[0].firstChild.data).toEqual('author');
890 expect(first.children[1].firstChild.data).toEqual('eq');
891 expect(first.children[2].firstChild.data).toEqual('Max Birkendale');
892
893 var second = e.children[1];
894 expect(second.getAttribute('class')).toEqual('doc');
895 expect(second.children[0].getAttribute('class')).toEqual('key');
896 expect(second.children[1].getAttribute('class')).toEqual('match');
897 expect(second.children[2].getAttribute('class')).toEqual('value');
898 expect(second.children[2].getAttribute('data-type')).toEqual('date');
899 expect(second.children[0].firstChild.data).toEqual('pubDate');
900 expect(second.children[1].firstChild.data).toEqual('eq');
901 expect(second.children[2].firstChild.data).toEqual('2014-12-05');
902 });
903
904 it('should be deserializable with nested groups', function () {
905 var docGroup = docGroupClass.create(undefined, {
Akron712733a2018-04-05 18:17:47 +0200906 "@type" : "koral:docGroup",
907 "operation" : "operation:or",
908 "operands" : [
909 {
910 "@type": 'koral:doc',
911 "key" : 'author',
912 "match": 'match:eq',
913 "value": 'Max Birkendale',
914 "type": 'type:string'
915 },
916 {
917 "@type" : "koral:docGroup",
918 "operation" : "operation:and",
919 "operands" : [
920 {
921 "@type": 'koral:doc',
922 "key": 'pubDate',
923 "match": 'match:geq',
924 "value": '2014-05-12',
925 "type": 'type:date'
926 },
927 {
928 "@type": 'koral:doc',
929 "key": 'pubDate',
930 "match": 'match:leq',
931 "value": '2014-12-05',
932 "type": 'type:date'
933 }
934 ]
935 }
936 ]
Nils Diewald7c8ced22015-04-15 19:21:00 +0000937 });
938
939 expect(docGroup.operation()).toEqual('or');
940 var e = docGroup.element();
941 expect(e.getAttribute('class')).toEqual('docGroup');
942 expect(e.getAttribute('data-operation')).toEqual('or');
943
944 expect(e.children[0].getAttribute('class')).toEqual('doc');
945 var docop = e.children[0].lastChild;
Akron0b489ad2018-02-02 16:49:32 +0100946 expect(docop.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +0000947 expect(docop.children[0].getAttribute('class')).toEqual('and');
948 expect(docop.children[1].getAttribute('class')).toEqual('or');
949 expect(docop.children[2].getAttribute('class')).toEqual('delete');
950
951 expect(e.children[1].getAttribute('class')).toEqual('docGroup');
952 expect(e.children[1].getAttribute('data-operation')).toEqual('and');
953
954 // This and-operation can be "or"ed or "delete"d
955 var secop = e.children[1].children[2];
Akron0b489ad2018-02-02 16:49:32 +0100956 expect(secop.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +0000957 expect(secop.children[0].getAttribute('class')).toEqual('or');
958 expect(secop.children[1].getAttribute('class')).toEqual('delete');
959
960 // This or-operation can be "and"ed or "delete"d
Akron0b489ad2018-02-02 16:49:32 +0100961 expect(e.children[2].getAttribute('class')).toEqual('operators button-group');
962 expect(e.lastChild.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +0000963 expect(e.lastChild.children[0].getAttribute('class')).toEqual('and');
964 expect(e.lastChild.children[1].getAttribute('class')).toEqual('delete');
965 });
966 });
967
Akronb19803c2018-08-16 16:39:42 +0200968 describe('KorAP.DocGroupRef element', function () {
969 it('should be initializable', function () {
970 var docGroupRef = docGroupRefClass.create(undefined, {
971 "@type" : "koral:docGroupRef",
972 "ref" : "@franz/myVC1"
973 });
974 expect(docGroupRef.ref()).toEqual("@franz/myVC1");
975 var dgrE = docGroupRef.element();
976
Akron3ad46942018-08-22 16:47:14 +0200977 expect(dgrE.children[0].firstChild.data).toEqual("referTo");
Akronb19803c2018-08-16 16:39:42 +0200978 expect(dgrE.children[0].tagName).toEqual("SPAN");
979 expect(dgrE.children[0].classList.contains("key")).toBeTruthy();
980 expect(dgrE.children[0].classList.contains("fixed")).toBeTruthy();
981 expect(dgrE.children[1].firstChild.data).toEqual("@franz/myVC1");
982 expect(dgrE.children[1].tagName).toEqual("SPAN");
983 expect(dgrE.children[1].classList.contains("value")).toBeTruthy();
984 expect(dgrE.children[1].getAttribute("data-type")).toEqual("string");
985 });
986
987 it('should be modifiable on reference', function () {
988 var docGroupRef = docGroupRefClass.create(undefined, {
989 "@type" : "koral:docGroupRef",
990 "ref" : "@franz/myVC1"
991 });
992 var dgrE = docGroupRef.element();
993 expect(docGroupRef.toQuery()).toEqual("referTo \"@franz/myVC1\"");
994 dgrE.children[1].click();
995
996 var input = dgrE.children[1].firstChild;
997 expect(input.tagName).toEqual("INPUT");
998 input.value = "Versuch";
999
1000 var event = new KeyboardEvent("keypress", {
1001 "key" : "[Enter]",
1002 "keyCode" : 13
1003 });
1004
1005 input.dispatchEvent(event);
1006 expect(docGroupRef.toQuery()).toEqual("referTo \"Versuch\"");
1007 });
1008 });
1009
1010
Akrone4961b12017-05-10 21:04:46 +02001011 describe('KorAP.VirtualCorpus', function () {
Nils Diewald7c8ced22015-04-15 19:21:00 +00001012 var simpleGroupFactory = buildFactory(docGroupClass, {
1013 "@type" : "koral:docGroup",
1014 "operation" : "operation:and",
1015 "operands" : [
Akron712733a2018-04-05 18:17:47 +02001016 {
1017 "@type": 'koral:doc',
1018 "key" : 'author',
1019 "match": 'match:eq',
1020 "value": 'Max Birkendale',
1021 "type": 'type:string'
1022 },
1023 {
1024 "@type": 'koral:doc',
1025 "key": 'pubDate',
1026 "match": 'match:eq',
1027 "value": '2014-12-05',
1028 "type": 'type:date'
1029 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00001030 ]
1031 });
1032
1033 var nestedGroupFactory = buildFactory(vcClass, {
1034 "@type" : "koral:docGroup",
1035 "operation" : "operation:or",
1036 "operands" : [
Akron712733a2018-04-05 18:17:47 +02001037 {
1038 "@type": 'koral:doc',
1039 "key" : 'author',
1040 "match": 'match:eq',
1041 "value": 'Max Birkendale',
1042 "type": 'type:string'
1043 },
1044 {
1045 "@type" : "koral:docGroup",
1046 "operation" : "operation:and",
1047 "operands" : [
1048 {
1049 "@type": 'koral:doc',
1050 "key": 'pubDate',
1051 "match": 'match:geq',
1052 "value": '2014-05-12',
1053 "type": 'type:date'
1054 },
1055 {
1056 "@type": 'koral:doc',
1057 "key": 'pubDate',
1058 "match": 'match:leq',
1059 "value": '2014-12-05',
1060 "type": 'type:date'
1061 }
1062 ]
1063 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00001064 ]
1065 });
1066
1067 var flatGroupFactory = buildFactory(vcClass, {
1068 "@type" : "koral:docGroup",
1069 "operation" : "operation:and",
1070 "operands" : [
Akron712733a2018-04-05 18:17:47 +02001071 {
1072 "@type": 'koral:doc',
1073 "key": 'pubDate',
1074 "match": 'match:geq',
1075 "value": '2014-05-12',
1076 "type": 'type:date'
1077 },
1078 {
1079 "@type": 'koral:doc',
1080 "key": 'pubDate',
1081 "match": 'match:leq',
1082 "value": '2014-12-05',
1083 "type": 'type:date'
1084 },
1085 {
1086 "@type": 'koral:doc',
1087 "key": 'foo',
1088 "match": 'match:eq',
1089 "value": 'bar',
1090 "type": 'type:string'
1091 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00001092 ]
1093 });
1094
1095 it('should be initializable', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00001096 var vc = vcClass.create();
Nils Diewald7c8ced22015-04-15 19:21:00 +00001097 expect(vc.element().getAttribute('class')).toEqual('vc');
1098 expect(vc.root().element().getAttribute('class')).toEqual('doc unspecified');
1099
1100 // Not removable
1101 expect(vc.root().element().lastChild.children.length).toEqual(0);
1102 });
1103
1104 it('should be based on a doc', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00001105 var vc = vcClass.create().fromJson({
Akron712733a2018-04-05 18:17:47 +02001106 "@type" : "koral:doc",
1107 "key":"Titel",
1108 "value":"Baum",
1109 "match":"match:eq"
Nils Diewald7c8ced22015-04-15 19:21:00 +00001110 });
1111
1112 expect(vc.element().getAttribute('class')).toEqual('vc');
1113 expect(vc.root().element().getAttribute('class')).toEqual('doc');
1114 expect(vc.root().key()).toEqual('Titel');
1115 expect(vc.root().value()).toEqual('Baum');
1116 expect(vc.root().matchop()).toEqual('eq');
1117
1118 var docE = vc.root().element();
1119 expect(docE.children[0].firstChild.data).toEqual('Titel');
1120 expect(docE.children[1].firstChild.data).toEqual('eq');
1121 expect(docE.children[1].getAttribute('data-type')).toEqual('string');
1122 expect(docE.children[2].firstChild.data).toEqual('Baum');
1123 expect(docE.children[2].getAttribute('data-type')).toEqual('string');
1124 });
1125
1126 it('should be based on a docGroup', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00001127 var vc = vcClass.create().fromJson(simpleGroupFactory.create().toJson());
Nils Diewald7c8ced22015-04-15 19:21:00 +00001128
1129 expect(vc.element().getAttribute('class')).toEqual('vc');
1130 expect(vc.root().element().getAttribute('class')).toEqual('docGroup');
1131 expect(vc.root().operation()).toEqual('and');
1132
1133 var docGroup = vc.root();
1134
1135 var first = docGroup.getOperand(0);
1136 expect(first.key()).toEqual('author');
1137 expect(first.value()).toEqual('Max Birkendale');
1138 expect(first.matchop()).toEqual('eq');
1139
1140 var second = docGroup.getOperand(1);
1141 expect(second.key()).toEqual('pubDate');
1142 expect(second.value()).toEqual('2014-12-05');
1143 expect(second.matchop()).toEqual('eq');
1144 });
1145
Akronb19803c2018-08-16 16:39:42 +02001146 it('should be based on a docGroupRef', function () {
1147 var vc = vcClass.create().fromJson({
1148 "@type" : "koral:docGroupRef",
1149 "ref":"myCorpus"
1150 });
1151
Akron3ad46942018-08-22 16:47:14 +02001152 // iv class="doc groupref"><span class="key fixed">referTo</span><span data-type="string" class="value">myCorpus</span>
Akronb19803c2018-08-16 16:39:42 +02001153 var vcE = vc.element();
1154 expect(vcE.getAttribute('class')).toEqual('vc');
1155 expect(vcE.firstChild.tagName).toEqual('DIV');
1156 expect(vcE.firstChild.classList.contains('groupref')).toBeTruthy();
1157
1158 expect(vcE.firstChild.firstChild.tagName).toEqual('SPAN');
1159 expect(vcE.firstChild.firstChild.classList.contains('key')).toBeTruthy();
1160 expect(vcE.firstChild.firstChild.classList.contains('fixed')).toBeTruthy();
1161
Akron3ad46942018-08-22 16:47:14 +02001162 expect(vcE.firstChild.firstChild.textContent).toEqual("referTo");
Akronb19803c2018-08-16 16:39:42 +02001163
1164 expect(vcE.firstChild.children[1].tagName).toEqual('SPAN');
1165 expect(vcE.firstChild.children[1].classList.contains('value')).toBeTruthy();
1166 expect(vcE.firstChild.children[1].getAttribute('data-type')).toEqual('string');
1167 expect(vcE.firstChild.children[1].textContent).toEqual("myCorpus");
1168 });
Nils Diewald7c8ced22015-04-15 19:21:00 +00001169
1170 it('should be based on a nested docGroup', function () {
1171 var vc = nestedGroupFactory.create();
1172
1173 expect(vc.element().getAttribute('class')).toEqual('vc');
1174 expect(vc.element().firstChild.getAttribute('class')).toEqual('docGroup');
1175 expect(vc.element().firstChild.children[0].getAttribute('class')).toEqual('doc');
1176 var dg = vc.element().firstChild.children[1];
1177 expect(dg.getAttribute('class')).toEqual('docGroup');
1178 expect(dg.children[0].getAttribute('class')).toEqual('doc');
1179 expect(dg.children[1].getAttribute('class')).toEqual('doc');
Akron0b489ad2018-02-02 16:49:32 +01001180 expect(dg.children[2].getAttribute('class')).toEqual('operators button-group');
1181 expect(vc.element().firstChild.children[2].getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001182 });
1183
Akronb19803c2018-08-16 16:39:42 +02001184 it('should be based on a nested docGroupRef', function () {
1185 var vc = vcClass.create().fromJson({
1186 "@type" : "koral:docGroup",
1187 "operation" : "operation:and",
1188 "operands" : [{
1189 "@type" : "koral:docGroupRef",
1190 "ref":"myCorpus"
1191 },{
1192 "@type" : "koral:doc",
1193 "key":"Titel",
1194 "value":"Baum",
1195 "match":"match:eq"
1196 }]
1197 });
1198
1199 expect(vc._root.ldType()).toEqual("docGroup");
1200
1201 expect(vc.toQuery()).toEqual('referTo "myCorpus" & Titel = "Baum"');
1202 });
1203
1204
Nils Diewald7c8ced22015-04-15 19:21:00 +00001205 it('should be modifiable by deletion in flat docGroups', function () {
1206 var vc = flatGroupFactory.create();
1207 var docGroup = vc.root();
1208
1209 expect(docGroup.element().getAttribute('class')).toEqual('docGroup');
1210
1211 var doc = docGroup.getOperand(1);
1212 expect(doc.key()).toEqual("pubDate");
1213 expect(doc.value()).toEqual("2014-12-05");
1214
1215 // Remove operand 1
1216 expect(docGroup.delOperand(doc).update()).not.toBeUndefined();
1217 expect(doc._element).toEqual(undefined);
1218
1219 doc = docGroup.getOperand(1);
1220 expect(doc.key()).toEqual("foo");
1221
1222 // Remove operand 1
1223 expect(docGroup.delOperand(doc).update()).not.toBeUndefined();
1224 expect(doc._element).toEqual(undefined);
1225
1226 // Only one operand left ...
1227 expect(docGroup.getOperand(1)).toBeUndefined();
1228 // ... but there shouldn't be a group anymore at all!
1229 expect(docGroup.getOperand(0)).toBeUndefined();
1230
1231 var obj = vc.root();
1232 expect(obj.ldType()).toEqual("doc");
1233 expect(obj.key()).toEqual("pubDate");
1234 expect(obj.value()).toEqual("2014-05-12");
1235
1236 expect(obj.element().getAttribute('class')).toEqual('doc');
1237 });
1238
1239
1240 it('should be modifiable by deletion in nested docGroups (root case)', function () {
1241 var vc = nestedGroupFactory.create();
1242
1243 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001244 'author = "Max Birkendale" | (pubDate since 2014-05-12 & pubDate until 2014-12-05)'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001245 );
1246
1247 var docGroup = vc.root();
1248 expect(docGroup.ldType()).toEqual("docGroup");
1249 expect(docGroup.operation()).toEqual("or");
1250
1251 var doc = docGroup.getOperand(0);
1252 expect(doc.key()).toEqual("author");
1253 expect(doc.value()).toEqual("Max Birkendale");
1254
1255 docGroup = docGroup.getOperand(1);
1256 expect(docGroup.operation()).toEqual("and");
1257
1258 doc = docGroup.getOperand(0);
1259 expect(doc.key()).toEqual("pubDate");
1260 expect(doc.matchop()).toEqual("geq");
1261 expect(doc.value()).toEqual("2014-05-12");
1262 expect(doc.type()).toEqual("date");
1263
1264 doc = docGroup.getOperand(1);
1265 expect(doc.key()).toEqual("pubDate");
1266 expect(doc.matchop()).toEqual("leq");
1267 expect(doc.value()).toEqual("2014-12-05");
1268 expect(doc.type()).toEqual("date");
1269
1270 // Remove first operand so everything becomes root
1271 expect(
Akron712733a2018-04-05 18:17:47 +02001272 vc.root().delOperand(
1273 vc.root().getOperand(0)
1274 ).update().ldType()
Nils Diewald7c8ced22015-04-15 19:21:00 +00001275 ).toEqual("docGroup");
1276
1277 expect(vc.root().ldType()).toEqual("docGroup");
1278 expect(vc.root().operation()).toEqual("and");
1279 expect(vc.root().getOperand(0).ldType()).toEqual("doc");
1280
1281 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001282 'pubDate since 2014-05-12 & pubDate until 2014-12-05'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001283 );
1284 });
1285
1286 it('should be modifiable by deletion in nested docGroups (resolve group case)', function () {
1287 var vc = nestedGroupFactory.create();
1288
1289 // Get nested group
1290 var firstGroup = vc.root().getOperand(1);
1291 firstGroup.append(simpleGroupFactory.create({ "operation" : "operation:or" }));
1292
1293 // Structur is now:
1294 // or(doc, and(doc, doc, or(doc, doc)))
1295
1296 // Get nested or in and
1297 var orGroup = vc.root().getOperand(1).getOperand(2);
1298 expect(orGroup.ldType()).toEqual("docGroup");
1299 expect(orGroup.operation()).toEqual("or");
1300
1301 // Remove
1302 // Structur is now:
1303 // or(doc, and(doc, doc, doc)))
1304 expect(orGroup.delOperand(orGroup.getOperand(0)).update().operation()).toEqual("and");
1305 expect(vc.root().getOperand(1).operands().length).toEqual(3);
1306 });
1307
1308 it('should be modifiable by deletion in nested docGroups (identical group case)', function () {
1309 var vc = nestedGroupFactory.create();
1310
1311 // Get nested group
1312 var firstGroup = vc.root().getOperand(1);
1313 firstGroup.append(simpleGroupFactory.create({
Akron712733a2018-04-05 18:17:47 +02001314 "operation" : "operation:or"
Nils Diewald7c8ced22015-04-15 19:21:00 +00001315 }));
1316 var oldAuthor = firstGroup.getOperand(2).getOperand(0);
1317 oldAuthor.key("title");
1318 oldAuthor.value("Der Birnbaum");
1319
1320 // Structur is now:
1321 // or(doc, and(doc, doc, or(doc, doc)))
1322 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001323 'author = "Max Birkendale" | ' +
1324 '(pubDate since 2014-05-12 & ' +
1325 'pubDate until 2014-12-05 & ' +
1326 '(title = "Der Birnbaum" | ' +
1327 'pubDate in 2014-12-05))'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001328 );
1329
1330 var andGroup = vc.root().getOperand(1);
1331
1332 // Get leading docs in and
1333 var doc1 = andGroup.getOperand(0);
1334 expect(doc1.ldType()).toEqual("doc");
1335 expect(doc1.value()).toEqual("2014-05-12");
1336 var doc2 = andGroup.getOperand(1);
1337 expect(doc2.ldType()).toEqual("doc");
1338 expect(doc2.value()).toEqual("2014-12-05");
1339
1340 // Remove 2
1341 expect(
Akron712733a2018-04-05 18:17:47 +02001342 andGroup.delOperand(doc2).update().operation()
Nils Diewald7c8ced22015-04-15 19:21:00 +00001343 ).toEqual("and");
1344 // Structur is now:
1345 // or(doc, and(doc, or(doc, doc)))
1346
1347 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001348 'author = "Max Birkendale"' +
1349 ' | (pubDate since 2014-05-12 & ' +
1350 '(title = "Der Birnbaum" | pubDate in 2014-12-05))'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001351 );
1352
1353
1354 // Remove 1
1355 expect(andGroup.delOperand(doc1).update().operation()).toEqual("or");
1356 // Structur is now:
1357 // or(doc, doc, doc)
1358
1359 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001360 'author = "Max Birkendale" | title = "Der Birnbaum" | pubDate in 2014-12-05'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001361 );
1362 });
1363
1364 it('should be reducible to unspecification', function () {
1365 var vc = demoFactory.create();
1366
1367 expect(vc.toQuery()).toEqual(vc.root().toQuery());
1368 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001369 '(Titel = "Baum" & Veröffentlichungsort = "hihi" & ' +
1370 '(Titel = "Baum" | Veröffentlichungsort = "hihi")) ' +
1371 '| Untertitel ~ "huhu"');
Akrond141a362018-07-10 18:12:13 +02001372 expect(vc.root().element().lastChild.children[0].innerText).toEqual('and');
1373 expect(vc.root().element().lastChild.children[1].innerText).toEqual('×');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001374 expect(vc.root().delOperand(vc.root().getOperand(0)).update()).not.toBeUndefined();
Akron712733a2018-04-05 18:17:47 +02001375 expect(vc.toQuery()).toEqual('Untertitel ~ "huhu"');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001376
1377 var lc = vc.root().element().lastChild;
Akrond141a362018-07-10 18:12:13 +02001378 expect(lc.children[0].innerText).toEqual('and');
1379 expect(lc.children[1].innerText).toEqual('or');
1380 expect(lc.children[2].innerText).toEqual('×');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001381
1382 // Clean everything
1383 vc.clean();
1384 expect(vc.toQuery()).toEqual('');
1385 });
1386
1387 it('should flatten on import', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00001388 var vc = vcClass.create().fromJson({
Akron712733a2018-04-05 18:17:47 +02001389 "@type":"koral:docGroup",
1390 "operation":"operation:or",
1391 "operands":[
1392 {
1393 "@type":"koral:docGroup",
1394 "operation":"operation:or",
1395 "operands":[
Nils Diewald7c8ced22015-04-15 19:21:00 +00001396 {
Akron712733a2018-04-05 18:17:47 +02001397 "@type":"koral:doc",
1398 "key":"Titel",
1399 "value":"Baum",
1400 "match":"match:eq"
Nils Diewald7c8ced22015-04-15 19:21:00 +00001401 },
1402 {
Akron712733a2018-04-05 18:17:47 +02001403 "@type":"koral:doc",
1404 "key":"Veröffentlichungsort",
1405 "value":"hihi",
1406 "match":"match:eq"
Nils Diewald7c8ced22015-04-15 19:21:00 +00001407 },
1408 {
Akron712733a2018-04-05 18:17:47 +02001409 "@type":"koral:docGroup",
1410 "operation":"operation:or",
1411 "operands":[
1412 {
1413 "@type":"koral:doc",
1414 "key":"Titel",
1415 "value":"Baum",
1416 "match":"match:eq"
1417 },
1418 {
1419 "@type":"koral:doc",
1420 "key":"Veröffentlichungsort",
1421 "value":"hihi",
1422 "match":"match:eq"
1423 }
1424 ]
Nils Diewald7c8ced22015-04-15 19:21:00 +00001425 }
Akron712733a2018-04-05 18:17:47 +02001426 ]
1427 },
1428 {
1429 "@type":"koral:doc",
1430 "key":"Untertitel",
1431 "value":"huhu",
1432 "match":"match:contains"
1433 }
1434 ]
Nils Diewald7c8ced22015-04-15 19:21:00 +00001435 });
Nils Diewaldfda29d92015-01-22 17:28:01 +00001436
Nils Diewald7c8ced22015-04-15 19:21:00 +00001437 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001438 'Titel = "Baum" | Veröffentlichungsort = "hihi" | Untertitel ~ "huhu"'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001439 );
Nils Diewald86dad5b2015-01-28 15:09:07 +00001440 });
Akron1bdf5272018-07-24 18:51:30 +02001441
1442 it('should be deserializable from collection 1', function () {
1443 var kq = {
1444 "matches":["..."],
1445 "collection":{
1446 "@type": "koral:docGroup",
1447 "operation": "operation:or",
1448 "operands": [{
1449 "@type": "koral:docGroup",
1450 "operation": "operation:and",
1451 "operands": [
1452 {
1453 "@type": "koral:doc",
1454 "key": "title",
1455 "match": "match:eq",
1456 "value": "Der Birnbaum",
1457 "type": "type:string"
1458 },
1459 {
1460 "@type": "koral:doc",
1461 "key": "pubPlace",
1462 "match": "match:eq",
1463 "value": "Mannheim",
1464 "type": "type:string"
1465 },
1466 {
1467 "@type": "koral:docGroup",
1468 "operation": "operation:or",
1469 "operands": [
1470 {
1471 "@type": "koral:doc",
1472 "key": "subTitle",
1473 "match": "match:eq",
1474 "value": "Aufzucht und Pflege",
1475 "type": "type:string"
1476 },
1477 {
1478 "@type": "koral:doc",
1479 "key": "subTitle",
1480 "match": "match:eq",
1481 "value": "Gedichte",
1482 "type": "type:string"
1483 }
1484 ]
1485 }
1486 ]
1487 },{
1488 "@type": "koral:doc",
1489 "key": "pubDate",
1490 "match": "match:geq",
1491 "value": "2015-03-05",
1492 "type": "type:date",
1493 "rewrites" : [{
1494 "@type" : "koral:rewrite",
1495 "operation" : "operation:modification",
1496 "src" : "querySerializer",
1497 "scope" : "tree"
1498 }]
1499 }]
1500 }
1501 };
1502
1503 var vc = vcClass.create().fromJson(kq["collection"]);
1504 expect(vc.toQuery()).toEqual('(title = "Der Birnbaum" & pubPlace = "Mannheim" & (subTitle = "Aufzucht und Pflege" | subTitle = "Gedichte")) | pubDate since 2015-03-05');
1505 });
1506
1507 it('should be deserializable from collection 2', function () {
1508 var kq = {
1509 "@context": "http://korap.ids-mannheim.de/ns/KoralQuery/v0.3/context.jsonld",
1510 "meta": {},
1511 "query": {
1512 "@type": "koral:token",
1513 "wrap": {
1514 "@type": "koral:term",
1515 "match": "match:eq",
1516 "layer": "orth",
1517 "key": "Baum",
1518 "foundry": "opennlp",
1519 "rewrites": [
1520 {
1521 "@type": "koral:rewrite",
1522 "src": "Kustvakt",
1523 "operation": "operation:injection",
1524 "scope": "foundry"
1525 }
1526 ]
1527 },
1528 "idn": "Baum_2227",
1529 "rewrites": [
1530 {
1531 "@type": "koral:rewrite",
1532 "src": "Kustvakt",
1533 "operation": "operation:injection",
1534 "scope": "idn"
1535 }
1536 ]
1537 },
1538 "collection": {
1539 "@type": "koral:docGroup",
1540 "operation": "operation:and",
1541 "operands": [
1542 {
1543 "@type": "koral:doc",
1544 "match": "match:eq",
1545 "type": "type:regex",
1546 "value": "CC-BY.*",
1547 "key": "availability"
1548 },
1549 {
1550 "@type": "koral:doc",
1551 "match": "match:eq",
1552 "type":"type:text",
1553 "value": "Goethe",
1554 "key": "author"
1555 }
1556 ],
1557 "rewrites": [
1558 {
1559 "@type": "koral:rewrite",
1560 "src": "Kustvakt",
1561 "operation": "operation:insertion",
1562 "scope": "availability(FREE)"
1563 }
1564 ]
1565 },
1566 "matches": []
1567 };
1568
1569 var vc = vcClass.create().fromJson(kq["collection"]);
1570 expect(vc.toQuery()).toEqual('availability = /CC-BY.*/ & author = "Goethe"');
1571 });
Nils Diewald86dad5b2015-01-28 15:09:07 +00001572
Akron8a670162018-08-28 10:09:13 +02001573 it('shouldn\'t be deserializable from collection with unknown type', function () {
1574 var kq = {
1575 "@type" : "koral:doc",
1576 "match": "match:eq",
1577 "type":"type:failure",
1578 "value": "Goethe",
1579 "key": "author"
1580 };
Akron1bdf5272018-07-24 18:51:30 +02001581
Akron8a670162018-08-28 10:09:13 +02001582 expect(function () {
1583 vcClass.create().fromJson(kq)
1584 }).toThrow(new Error("Unknown value type: string"));
1585 });
1586
1587 it('should return a name', function () {
1588 var vc = vcClass.create();
1589 expect(vc.getName()).toEqual(KorAP.Locale.VC_allCorpora);
1590
1591 vc = vcClass.create().fromJson({"@type" : "koral:docGroupRef", "ref" : "DeReKo"});
1592 expect(vc.getName()).toEqual("DeReKo");
1593
1594 vc = vcClass.create().fromJson({"@type" : "koral:doc", "key" : "author", "value" : "Peter"});
1595 expect(vc.getName()).toEqual(KorAP.Locale.VC_oneCollection);
1596 });
Akrond2474aa2018-08-28 12:06:27 +02001597
1598 it('should check for rewrites', function () {
1599
1600 var vc = vcClass.create().fromJson({
1601 "@type" : "koral:doc",
1602 "key" : "author",
1603 "value" : "Goethe",
1604 "rewrites" : [{
1605 "@type" : "koral:rewrite",
1606 "operation" : "operation:modification",
1607 "src" : "querySerializer",
1608 "scope" : "value"
1609 }]
1610 });
1611 expect(vc.wasRewritten()).toBeTruthy();
1612
1613 var nested = {
1614 "@type" : "koral:docGroup",
1615 "operation" : "operation:or",
1616 "operands" : [
1617 {
1618 "@type" : "koral:doc",
1619 "key" : "author",
1620 "value" : "Goethe"
1621 },
1622 {
1623 "@type" : "koral:docGroup",
1624 "operation" : "operation:and",
1625 "operands" : [
1626 {
1627 "@type": "koral:doc",
1628 "key" : "author",
1629 "value" : "Schiller"
1630 },
1631 {
1632 "@type": "koral:doc",
1633 "key" : "author",
1634 "value" : "Fontane"
1635 }
1636 ]
1637 }
1638 ]
1639 };
1640 vc = vcClass.create().fromJson(nested);
1641 expect(vc.wasRewritten()).toBe(false);
1642
1643 nested["operands"][1]["operands"][1]["rewrites"] = [{
1644 "@type" : "koral:rewrite",
1645 "operation" : "operation:modification",
1646 "src" : "querySerializer",
1647 "scope" : "tree"
1648 }];
1649 vc = vcClass.create().fromJson(nested);
1650 expect(vc.wasRewritten()).toBeTruthy();
1651 });
Akron1bdf5272018-07-24 18:51:30 +02001652 });
1653
1654
Nils Diewald7c8ced22015-04-15 19:21:00 +00001655 describe('KorAP.Operators', function () {
1656 it('should be initializable', function () {
1657 var op = operatorsClass.create(true, false, false);
1658 expect(op.and()).toBeTruthy();
1659 expect(op.or()).not.toBeTruthy();
1660 expect(op.del()).not.toBeTruthy();
1661
1662 op.and(false);
1663 expect(op.and()).not.toBeTruthy();
1664 expect(op.or()).not.toBeTruthy();
1665 expect(op.del()).not.toBeTruthy();
1666
1667 op.or(true);
1668 op.del(true);
1669 expect(op.and()).not.toBeTruthy();
1670 expect(op.or()).toBeTruthy();
1671 expect(op.del()).toBeTruthy();
1672
Akrond141a362018-07-10 18:12:13 +02001673 var e = op.update();
Akron0b489ad2018-02-02 16:49:32 +01001674 expect(e.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001675 expect(e.children[0].getAttribute('class')).toEqual('or');
Akrond141a362018-07-10 18:12:13 +02001676 expect(e.children[0].innerText).toEqual('or');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001677 expect(e.children[1].getAttribute('class')).toEqual('delete');
Akrond141a362018-07-10 18:12:13 +02001678 expect(e.children[1].innerText).toEqual('×');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001679
1680 op.and(true);
1681 op.del(false);
Akrond141a362018-07-10 18:12:13 +02001682 e = op.update();
Nils Diewald7c8ced22015-04-15 19:21:00 +00001683
Akron0b489ad2018-02-02 16:49:32 +01001684 expect(e.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001685 expect(e.children[0].getAttribute('class')).toEqual('and');
Akrond141a362018-07-10 18:12:13 +02001686 expect(e.children[0].innerText).toEqual('and');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001687 expect(e.children[1].getAttribute('class')).toEqual('or');
Akrond141a362018-07-10 18:12:13 +02001688 expect(e.children[1].innerText).toEqual('or');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001689 });
1690 });
1691
1692 describe('KorAP._delete (event)', function () {
1693 var complexVCFactory = buildFactory(vcClass,{
1694 "@type": 'koral:docGroup',
1695 'operation' : 'operation:and',
1696 'operands' : [
Akron712733a2018-04-05 18:17:47 +02001697 {
1698 "@type": 'koral:doc',
1699 "key": 'pubDate',
1700 "match": 'match:eq',
1701 "value": '2014-12-05',
1702 "type": 'type:date'
1703 },
1704 {
1705 "@type" : 'koral:docGroup',
1706 'operation' : 'operation:or',
1707 'operands' : [
1708 {
1709 '@type' : 'koral:doc',
1710 'key' : 'title',
1711 'value' : 'Hello World!'
1712 },
1713 {
1714 '@type' : 'koral:doc',
1715 'key' : 'foo',
1716 'value' : 'bar'
1717 }
1718 ]
1719 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00001720 ]
1721 });
1722
1723 it('should clean on root docs', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00001724 var vc = vcClass.create().fromJson({
Akron712733a2018-04-05 18:17:47 +02001725 "@type": 'koral:doc',
1726 "key": 'pubDate',
1727 "match": 'match:eq',
1728 "value": '2014-12-05',
1729 "type": 'type:date'
Nils Diewald86dad5b2015-01-28 15:09:07 +00001730 });
Nils Diewald7c8ced22015-04-15 19:21:00 +00001731 expect(vc.root().toQuery()).toEqual('pubDate in 2014-12-05');
Akron0b489ad2018-02-02 16:49:32 +01001732 expect(vc.root().element().lastChild.getAttribute('class')).toEqual('operators button-group');
Nils Diewald86dad5b2015-01-28 15:09:07 +00001733
Nils Diewald7c8ced22015-04-15 19:21:00 +00001734 // Clean with delete from root
1735 expect(vc.root().element().lastChild.lastChild.getAttribute('class')).toEqual('delete');
1736 _delOn(vc.root());
1737 expect(vc.root().toQuery()).toEqual('');
1738 expect(vc.root().element().lastChild.lastChild.data).toEqual('⋯');
1739 });
Nils Diewald86dad5b2015-01-28 15:09:07 +00001740
Nils Diewald7c8ced22015-04-15 19:21:00 +00001741 it('should remove on nested docs', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00001742 var vc = vcClass.create().fromJson(
Akron712733a2018-04-05 18:17:47 +02001743 {
1744 "@type": 'koral:docGroup',
1745 'operation' : 'operation:and',
1746 'operands' : [
1747 {
1748 "@type": 'koral:doc',
1749 "key": 'pubDate',
1750 "match": 'match:eq',
1751 "value": '2014-12-05',
1752 "type": 'type:date'
1753 },
1754 {
1755 "@type" : 'koral:doc',
1756 'key' : 'foo',
1757 'value' : 'bar'
1758 }
1759 ]
1760 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00001761 );
1762
1763 // Delete with direct element access
1764 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar"');
1765 _delOn(vc.root().getOperand(0));
1766
1767 expect(vc.toQuery()).toEqual('foo = "bar"');
1768 expect(vc.root().ldType()).toEqual('doc');
1769 });
1770
1771 it('should clean on doc groups', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00001772 var vc = vcClass.create().fromJson(
Akron712733a2018-04-05 18:17:47 +02001773 {
1774 "@type": 'koral:docGroup',
1775 'operation' : 'operation:and',
1776 'operands' : [
1777 {
1778 "@type": 'koral:doc',
1779 "key": 'pubDate',
1780 "match": 'match:eq',
1781 "value": '2014-12-05',
1782 "type": 'type:date'
1783 },
1784 {
1785 "@type" : 'koral:doc',
1786 'key' : 'foo',
1787 'value' : 'bar'
1788 }
1789 ]
1790 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00001791 );
1792
1793 // Cleanwith direct element access
1794 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar"');
1795 _delOn(vc.root());
1796 expect(vc.toQuery()).toEqual('');
1797 expect(vc.root().ldType()).toEqual('non');
1798 });
1799
1800 it('should remove on nested doc groups (case of ungrouping 1)', function () {
1801 var vc = complexVCFactory.create();
1802
1803 // Delete with direct element access
1804 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001805 'pubDate in 2014-12-05 & (title = "Hello World!" | foo = "bar")'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001806 );
1807
1808 // Remove hello world:
1809 _delOn(vc.root().getOperand(1).getOperand(0));
1810 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar"');
1811 expect(vc.root().ldType()).toEqual('docGroup');
1812 });
1813
1814 it('should remove on nested doc groups (case of ungrouping 2)', function () {
1815 var vc = complexVCFactory.create();
1816
1817 // Delete with direct element access
1818 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001819 'pubDate in 2014-12-05 & (title = "Hello World!" | foo = "bar")'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001820 );
1821
1822 // Remove bar
1823 _delOn(vc.root().getOperand(1).getOperand(1));
1824 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & title = "Hello World!"');
1825 expect(vc.root().ldType()).toEqual('docGroup');
1826 expect(vc.root().operation()).toEqual('and');
1827 });
1828
1829 it('should remove on nested doc groups (case of root changing)', function () {
1830 var vc = complexVCFactory.create();
1831
1832 // Delete with direct element access
1833 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001834 'pubDate in 2014-12-05 & ' +
1835 '(title = "Hello World!" | foo = "bar")'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001836 );
1837
1838 // Remove bar
1839 _delOn(vc.root().getOperand(0));
1840 expect(vc.toQuery()).toEqual('title = "Hello World!" | foo = "bar"');
1841 expect(vc.root().ldType()).toEqual('docGroup');
1842 expect(vc.root().operation()).toEqual('or');
1843 });
1844
1845 it('should remove on nested doc groups (list flattening)', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00001846 var vc = vcClass.create().fromJson(
Akron712733a2018-04-05 18:17:47 +02001847 {
1848 "@type": 'koral:docGroup',
1849 'operation' : 'operation:or',
1850 'operands' : [
1851 {
1852 "@type": 'koral:doc',
1853 "key": 'pubDate',
1854 "match": 'match:eq',
1855 "value": '2014-12-05',
1856 "type": 'type:date'
1857 },
1858 {
1859 "@type" : 'koral:doc',
1860 'key' : 'foo',
1861 'value' : 'bar'
1862 },
1863 {
1864 "@type": 'koral:docGroup',
1865 'operation' : 'operation:and',
1866 'operands' : [
1867 {
1868 "@type": 'koral:doc',
1869 "key": 'pubDate',
1870 "match": 'match:eq',
1871 "value": '2014-12-05',
1872 "type": 'type:date'
1873 },
1874 {
1875 "@type" : 'koral:docGroup',
1876 'operation' : 'operation:or',
1877 'operands' : [
1878 {
1879 '@type' : 'koral:doc',
1880 'key' : 'title',
1881 'value' : 'Hello World!'
1882 },
1883 {
1884 '@type' : 'koral:doc',
1885 'key' : 'yeah',
1886 'value' : 'juhu'
1887 }
1888 ]
1889 }
1890 ]
1891 }
1892 ]
1893 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00001894 );
1895
1896 // Delete with direct element access
1897 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001898 'pubDate in 2014-12-05 | foo = "bar" | ' +
1899 '(pubDate in 2014-12-05 & ' +
1900 '(title = "Hello World!" | yeah = "juhu"))'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001901 );
1902
1903 expect(vc.root().ldType()).toEqual('docGroup');
1904 expect(vc.root().operation()).toEqual('or');
1905
1906 // Operands and operators
1907 expect(vc.element().firstChild.children.length).toEqual(4);
Akron0b489ad2018-02-02 16:49:32 +01001908 expect(vc.element().firstChild.lastChild.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001909
1910 // Remove inner group and flatten
1911 _delOn(vc.root().getOperand(2).getOperand(0));
1912
1913 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001914 'pubDate in 2014-12-05 | foo = "bar" | title = "Hello World!" | yeah = "juhu"'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001915 );
1916 expect(vc.root().ldType()).toEqual('docGroup');
1917 expect(vc.root().operation()).toEqual('or');
1918
1919 // Operands and operators
1920 expect(vc.element().firstChild.children.length).toEqual(5);
Akron0b489ad2018-02-02 16:49:32 +01001921 expect(vc.element().firstChild.lastChild.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001922 });
1923 });
1924
1925 describe('KorAP._add (event)', function () {
1926 var complexVCFactory = buildFactory(vcClass,{
1927 "@type": 'koral:docGroup',
1928 'operation' : 'operation:and',
1929 'operands' : [
Akron712733a2018-04-05 18:17:47 +02001930 {
1931 "@type": 'koral:doc',
1932 "key": 'pubDate',
1933 "match": 'match:eq',
1934 "value": '2014-12-05',
1935 "type": 'type:date'
1936 },
1937 {
1938 "@type" : 'koral:docGroup',
1939 'operation' : 'operation:or',
1940 'operands' : [
1941 {
1942 '@type' : 'koral:doc',
1943 'key' : 'title',
1944 'value' : 'Hello World!'
1945 },
1946 {
1947 '@type' : 'koral:doc',
1948 'key' : 'foo',
1949 'value' : 'bar'
1950 }
1951 ]
1952 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00001953 ]
1954 });
1955
1956 it('should add new unspecified doc with "and"', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00001957 var vc = vcClass.create().fromJson(
Akron712733a2018-04-05 18:17:47 +02001958 {
1959 "@type": 'koral:docGroup',
1960 'operation' : 'operation:and',
1961 'operands' : [
1962 {
1963 "@type": 'koral:doc',
1964 "key": 'pubDate',
1965 "match": 'match:eq',
1966 "value": '2014-12-05',
1967 "type": 'type:date'
1968 },
1969 {
1970 "@type" : 'koral:doc',
1971 'key' : 'foo',
1972 'value' : 'bar'
Akronb19803c2018-08-16 16:39:42 +02001973 },
1974 {
1975 "@type" : "koral:docGroupRef",
1976 "ref" : "myCorpus"
Akron712733a2018-04-05 18:17:47 +02001977 }
1978 ]
1979 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00001980 );
1981
Akronb19803c2018-08-16 16:39:42 +02001982 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar" & referTo "myCorpus"');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001983
1984 var fc = vc.element().firstChild;
1985 expect(fc.getAttribute('data-operation')).toEqual('and');
Akronb19803c2018-08-16 16:39:42 +02001986 expect(fc.children.length).toEqual(4);
Akron0b489ad2018-02-02 16:49:32 +01001987 expect(fc.lastChild.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001988 expect(fc.children[0].getAttribute('class')).toEqual('doc');
1989 expect(fc.children[1].getAttribute('class')).toEqual('doc');
Akronb19803c2018-08-16 16:39:42 +02001990 expect(fc.children[2].getAttribute('class')).toEqual('doc groupref');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001991
1992 // add with 'and' in the middle
1993 _andOn(vc.root().getOperand(0));
Akronb19803c2018-08-16 16:39:42 +02001994 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar" & referTo "myCorpus"');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001995
1996 fc = vc.element().firstChild;
1997 expect(fc.getAttribute('data-operation')).toEqual('and');
Akronb19803c2018-08-16 16:39:42 +02001998 expect(fc.children.length).toEqual(5);
Akron0b489ad2018-02-02 16:49:32 +01001999 expect(fc.lastChild.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +00002000
2001 expect(fc.children[0].getAttribute('class')).toEqual('doc');
2002 expect(fc.children[1].getAttribute('class')).toEqual('doc unspecified');
2003 expect(fc.children[2].getAttribute('class')).toEqual('doc');
Akronb19803c2018-08-16 16:39:42 +02002004 expect(fc.children[3].getAttribute('class')).toEqual('doc groupref');
2005 expect(fc.children[4].classList.contains('button-group')).toBeTruthy();
2006 expect(fc.children.length).toEqual(5);
2007
2008 _andOn(vc.root().getOperand(3));
2009 expect(fc.children[0].getAttribute('class')).toEqual('doc');
2010 expect(fc.children[1].getAttribute('class')).toEqual('doc unspecified');
2011 expect(fc.children[2].getAttribute('class')).toEqual('doc');
2012 expect(fc.children[3].getAttribute('class')).toEqual('doc groupref');
2013 expect(fc.children[4].getAttribute('class')).toEqual('doc unspecified');
2014 expect(fc.children[5].classList.contains('button-group')).toBeTruthy();
2015 expect(fc.children.length).toEqual(6);
2016
Nils Diewald7c8ced22015-04-15 19:21:00 +00002017 });
2018
Akronb19803c2018-08-16 16:39:42 +02002019
Nils Diewald7c8ced22015-04-15 19:21:00 +00002020 it('should add new unspecified doc with "or"', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00002021 var vc = vcClass.create().fromJson(
Akron712733a2018-04-05 18:17:47 +02002022 {
2023 "@type": 'koral:docGroup',
2024 'operation' : 'operation:and',
2025 'operands' : [
2026 {
2027 "@type": 'koral:doc',
2028 "key": 'pubDate',
2029 "match": 'match:eq',
2030 "value": '2014-12-05',
2031 "type": 'type:date'
2032 },
2033 {
2034 "@type" : 'koral:doc',
2035 'key' : 'foo',
2036 'value' : 'bar'
Akronb19803c2018-08-16 16:39:42 +02002037 },
2038 {
2039 "@type" : "koral:docGroupRef",
2040 "ref" : "myCorpus"
Akron712733a2018-04-05 18:17:47 +02002041 }
2042 ]
2043 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00002044 );
2045
Akronb19803c2018-08-16 16:39:42 +02002046 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar" & referTo "myCorpus"');
Nils Diewald7c8ced22015-04-15 19:21:00 +00002047
2048 var fc = vc.element().firstChild;
Akronb19803c2018-08-16 16:39:42 +02002049 expect(fc.children.length).toEqual(4);
Akron0b489ad2018-02-02 16:49:32 +01002050 expect(fc.lastChild.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +00002051 expect(fc.children[0].getAttribute('class')).toEqual('doc');
2052 expect(fc.children[1].getAttribute('class')).toEqual('doc');
Akronb19803c2018-08-16 16:39:42 +02002053 expect(fc.children[2].getAttribute('class')).toEqual('doc groupref');
Nils Diewald7c8ced22015-04-15 19:21:00 +00002054
2055 // add with 'or' in the middle
2056 _orOn(vc.root().getOperand(0));
Akronb19803c2018-08-16 16:39:42 +02002057 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar" & referTo "myCorpus"');
Nils Diewald7c8ced22015-04-15 19:21:00 +00002058 fc = vc.element().firstChild;
2059
2060 expect(fc.getAttribute('data-operation')).toEqual('and');
Akronb19803c2018-08-16 16:39:42 +02002061 expect(fc.children.length).toEqual(4);
Nils Diewald7c8ced22015-04-15 19:21:00 +00002062 expect(fc.children[0].getAttribute('class')).toEqual('docGroup');
2063 expect(fc.children[0].getAttribute('data-operation')).toEqual('or');
2064 expect(fc.children[1].getAttribute('class')).toEqual('doc');
Akronb19803c2018-08-16 16:39:42 +02002065 expect(fc.children[2].getAttribute('class')).toEqual('doc groupref');
2066 expect(fc.children[3].getAttribute('class')).toEqual('operators button-group');
Akron0b489ad2018-02-02 16:49:32 +01002067 expect(fc.lastChild.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +00002068
2069 fc = vc.element().firstChild.firstChild;
2070 expect(fc.children.length).toEqual(3);
2071 expect(fc.children[0].getAttribute('class')).toEqual('doc');
2072 expect(fc.children[1].getAttribute('class')).toEqual('doc unspecified');
Akron0b489ad2018-02-02 16:49:32 +01002073 expect(fc.children[2].getAttribute('class')).toEqual('operators button-group');
2074 expect(fc.lastChild.getAttribute('class')).toEqual('operators button-group');
Akronb19803c2018-08-16 16:39:42 +02002075
2076 _orOn(vc.root().getOperand(2));
2077 fc = vc.element().firstChild;
2078 expect(fc.children.length).toEqual(4);
2079
2080 expect(fc.children[0].getAttribute('class')).toEqual('docGroup');
2081 expect(fc.children[1].getAttribute('class')).toEqual('doc');
2082 expect(fc.children[2].getAttribute('class')).toEqual('docGroup');
2083 expect(fc.children[3].getAttribute('class')).toEqual('operators button-group');
2084
2085 fc = vc.element().firstChild.children[2];
2086 expect(fc.children[0].getAttribute('class')).toEqual('doc groupref');
2087 expect(fc.children[1].getAttribute('class')).toEqual('doc unspecified');
2088 expect(fc.children[2].getAttribute('class')).toEqual('operators button-group');
2089 expect(fc.lastChild.getAttribute('class')).toEqual('operators button-group');
2090
Nils Diewald7c8ced22015-04-15 19:21:00 +00002091 });
2092
2093 it('should add new unspecified doc with "and" before group', function () {
2094 var vc = demoFactory.create();
2095
2096 // Wrap with direct element access
2097 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02002098 '(Titel = "Baum" & ' +
2099 'Veröffentlichungsort = "hihi" & ' +
2100 '(Titel = "Baum" | ' +
2101 'Veröffentlichungsort = "hihi")) | ' +
2102 'Untertitel ~ "huhu"'
Nils Diewald7c8ced22015-04-15 19:21:00 +00002103 );
2104
2105 expect(vc.root().getOperand(0).ldType()).toEqual('docGroup');
2106 expect(vc.root().getOperand(0).operation()).toEqual('and');
2107 expect(vc.root().getOperand(0).operands().length).toEqual(3);
2108
2109 // Add unspecified on the second doc
2110 var secDoc = vc.root().getOperand(0).getOperand(1);
2111 expect(secDoc.value()).toEqual('hihi');
2112
2113 // Add
2114 _andOn(secDoc);
2115
2116 var fo = vc.root().getOperand(0);
2117
2118 expect(fo.ldType()).toEqual('docGroup');
2119 expect(fo.operation()).toEqual('and');
2120 expect(fo.operands().length).toEqual(4);
2121
2122 expect(fo.getOperand(0).ldType()).toEqual('doc');
2123 expect(fo.getOperand(1).ldType()).toEqual('doc');
2124 expect(fo.getOperand(2).ldType()).toEqual('non');
2125 expect(fo.getOperand(3).ldType()).toEqual('docGroup');
2126 });
2127
2128
2129 it('should remove a doc with an unspecified doc in a nested group', function () {
2130 var vc = demoFactory.create();
2131
2132 // Wrap with direct element access
2133 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02002134 '(Titel = "Baum" & Veröffentlichungsort = "hihi" & (Titel = "Baum" | Veröffentlichungsort = "hihi")) | Untertitel ~ "huhu"'
Nils Diewald7c8ced22015-04-15 19:21:00 +00002135 );
2136
2137 var fo = vc.root().getOperand(0).getOperand(0);
2138 expect(fo.key()).toEqual('Titel');
2139 expect(fo.value()).toEqual('Baum');
2140
2141 // Add unspecified on the root group
2142 _orOn(fo);
2143
2144 fo = vc.root().getOperand(0).getOperand(0);
2145
2146 expect(fo.operation()).toEqual('or');
2147 expect(fo.getOperand(0).ldType()).toEqual('doc');
2148 expect(fo.getOperand(1).ldType()).toEqual('non');
2149
2150 // Delete document
2151 _delOn(fo.getOperand(0));
2152
2153 // The operand is now non
2154 expect(vc.root().getOperand(0).getOperand(0).ldType()).toEqual('non');
2155 expect(vc.root().getOperand(0).getOperand(1).ldType()).toEqual('doc');
2156 expect(vc.root().getOperand(0).getOperand(2).ldType()).toEqual('docGroup');
2157 });
2158
2159
Akron712733a2018-04-05 18:17:47 +02002160 it('should remove an unspecified doc with a doc in a nested group', function () {
Nils Diewald7c8ced22015-04-15 19:21:00 +00002161 var vc = demoFactory.create();
2162
2163 // Wrap with direct element access
2164 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02002165 '(Titel = "Baum" & ' +
2166 'Veröffentlichungsort = "hihi" & ' +
2167 '(Titel = "Baum" ' +
2168 '| Veröffentlichungsort = "hihi")) | ' +
2169 'Untertitel ~ "huhu"'
Nils Diewald7c8ced22015-04-15 19:21:00 +00002170 );
2171
2172 var fo = vc.root().getOperand(0).getOperand(0);
2173 expect(fo.key()).toEqual('Titel');
2174 expect(fo.value()).toEqual('Baum');
2175
2176 // Add unspecified on the root group
2177 _orOn(fo);
2178
2179 fo = vc.root().getOperand(0).getOperand(0);
2180
2181 expect(fo.operation()).toEqual('or');
2182 expect(fo.getOperand(0).ldType()).toEqual('doc');
2183 expect(fo.getOperand(1).ldType()).toEqual('non');
2184
2185 // Delete unspecified doc
2186 _delOn(fo.getOperand(1));
2187
2188 // The operand is now non
2189 fo = vc.root().getOperand(0);
2190 expect(fo.getOperand(0).ldType()).toEqual('doc');
2191 expect(fo.getOperand(0).key()).toEqual('Titel');
2192 expect(fo.getOperand(0).value()).toEqual('Baum');
2193 expect(fo.getOperand(1).ldType()).toEqual('doc');
2194 expect(fo.getOperand(2).ldType()).toEqual('docGroup');
2195 });
2196
2197
2198 it('should add on parent group (case "and")', function () {
2199 var vc = complexVCFactory.create();
2200
2201 // Wrap with direct element access
2202 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02002203 'pubDate in 2014-12-05 & (title = "Hello World!" | foo = "bar")'
Nils Diewald7c8ced22015-04-15 19:21:00 +00002204 );
2205
2206 expect(vc.root().operands().length).toEqual(2);
2207
2208 // Add unspecified on the root group
2209 _andOn(vc.root().getOperand(1));
2210 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02002211 'pubDate in 2014-12-05 & (title = "Hello World!" | foo = "bar")'
Nils Diewald7c8ced22015-04-15 19:21:00 +00002212 );
2213
2214 expect(vc.root().ldType()).toEqual('docGroup');
2215 expect(vc.root().operands().length).toEqual(3);
2216 expect(vc.root().getOperand(0).ldType()).toEqual('doc');
2217 expect(vc.root().getOperand(1).ldType()).toEqual('docGroup');
2218 expect(vc.root().getOperand(1).operation()).toEqual('or');
2219 expect(vc.root().getOperand(2).ldType()).toEqual('non');
2220
2221 // Add another unspecified on the root group
2222 _andOn(vc.root().getOperand(1));
2223
2224 expect(vc.root().operands().length).toEqual(4);
2225 expect(vc.root().getOperand(0).ldType()).toEqual('doc');
2226 expect(vc.root().getOperand(1).ldType()).toEqual('docGroup');
2227 expect(vc.root().getOperand(2).ldType()).toEqual('non');
2228 expect(vc.root().getOperand(3).ldType()).toEqual('non');
2229
2230 // Add another unspecified after the first doc
2231 _andOn(vc.root().getOperand(0));
2232
2233 expect(vc.root().operands().length).toEqual(5);
2234 expect(vc.root().getOperand(0).ldType()).toEqual('doc');
2235 expect(vc.root().getOperand(1).ldType()).toEqual('non');
2236 expect(vc.root().getOperand(2).ldType()).toEqual('docGroup');
2237 expect(vc.root().getOperand(3).ldType()).toEqual('non');
2238 expect(vc.root().getOperand(4).ldType()).toEqual('non');
2239 });
2240
2241 it('should wrap on root', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00002242 var vc = vcClass.create().fromJson(
Akron712733a2018-04-05 18:17:47 +02002243 {
2244 "@type": 'koral:docGroup',
2245 'operation' : 'operation:and',
2246 'operands' : [
2247 {
2248 "@type": 'koral:doc',
2249 "key": 'pubDate',
2250 "match": 'match:eq',
2251 "value": '2014-12-05',
2252 "type": 'type:date'
2253 },
2254 {
2255 "@type" : 'koral:doc',
2256 'key' : 'foo',
2257 'value' : 'bar'
2258 }
2259 ]
2260 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00002261 );
2262
2263 // Wrap on root
2264 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar"');
2265 expect(vc.root().ldType()).toEqual('docGroup');
2266 expect(vc.root().operation()).toEqual('and');
2267 _orOn(vc.root());
2268 expect(vc.root().ldType()).toEqual('docGroup');
2269 expect(vc.root().operation()).toEqual('or');
2270
2271 expect(vc.root().getOperand(0).ldType()).toEqual('docGroup');
2272 expect(vc.root().getOperand(0).operation()).toEqual('and');
2273 });
2274
2275 it('should add on root (case "and")', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00002276 var vc = vcClass.create().fromJson(
Akron712733a2018-04-05 18:17:47 +02002277 {
2278 "@type": 'koral:doc',
2279 "key": 'pubDate',
2280 "match": 'match:eq',
2281 "value": '2014-12-05',
2282 "type": 'type:date'
2283 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00002284 );
2285
2286 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05');
2287 expect(vc.root().ldType()).toEqual('doc');
2288 expect(vc.root().key()).toEqual('pubDate');
2289 expect(vc.root().value()).toEqual('2014-12-05');
2290
2291 // Wrap on root
2292 _andOn(vc.root());
2293 expect(vc.root().ldType()).toEqual('docGroup');
2294 expect(vc.root().operation()).toEqual('and');
2295 });
2296
2297 it('should add on root (case "or")', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00002298 var vc = vcClass.create().fromJson(
Akron712733a2018-04-05 18:17:47 +02002299 {
2300 "@type": 'koral:doc',
2301 "key": 'pubDate',
2302 "match": 'match:eq',
2303 "value": '2014-12-05',
2304 "type": 'type:date'
2305 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00002306 );
2307
2308 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05');
2309 expect(vc.root().key()).toEqual('pubDate');
2310 expect(vc.root().value()).toEqual('2014-12-05');
2311
2312 // Wrap on root
2313 _orOn(vc.root());
2314 expect(vc.root().ldType()).toEqual('docGroup');
2315 expect(vc.root().operation()).toEqual('or');
2316 });
2317
2318 it('should support multiple sub groups per group', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00002319 var vc = vcClass.create().fromJson(
Akron712733a2018-04-05 18:17:47 +02002320 {
2321 "@type": 'koral:docGroup',
2322 'operation' : 'operation:or',
2323 'operands' : [
2324 {
2325 "@type": 'koral:docGroup',
2326 'operation' : 'operation:and',
2327 'operands' : [
2328 {
2329 "@type": 'koral:doc',
2330 "key": 'title',
2331 "value": 't1',
2332 },
2333 {
2334 "@type" : 'koral:doc',
2335 'key' : 'title',
2336 'value' : 't2'
2337 }
2338 ]
2339 },
2340 {
2341 "@type": 'koral:docGroup',
2342 'operation' : 'operation:and',
2343 'operands' : [
2344 {
2345 "@type": 'koral:doc',
2346 "key": 'title',
2347 "value": 't3',
2348 },
2349 {
2350 "@type" : 'koral:doc',
2351 'key' : 'title',
2352 'value' : 't4'
2353 }
2354 ]
2355 }
2356 ]
2357 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00002358 );
2359 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02002360 '(title = "t1" & title = "t2") | ' +
2361 '(title = "t3" & title = "t4")'
Nils Diewald7c8ced22015-04-15 19:21:00 +00002362 );
2363 expect(vc.root().operation()).toEqual('or');
2364 expect(vc.root().getOperand(0).toQuery()).toEqual('title = "t1" & title = "t2"');
2365 expect(vc.root().getOperand(1).toQuery()).toEqual('title = "t3" & title = "t4"');
2366
2367 _andOn(vc.root());
2368
2369 expect(vc.root().operation()).toEqual('and');
2370 expect(vc.root().getOperand(0).ldType()).toEqual('docGroup');
2371 expect(vc.root().getOperand(1).ldType()).toEqual('non');
2372 });
2373 });
2374
Akron5c829e92017-05-12 18:10:00 +02002375 // Check class method
Akrond2474aa2018-08-28 12:06:27 +02002376 xdescribe('KorAP.VC.checkRewrite', function () {
2377
2378 // Class method is deprecated!
Akron5c829e92017-05-12 18:10:00 +02002379
2380 it('should check for simple rewrites', function () {
2381 expect(vcClass.checkRewrite(
2382 {
2383 "@type" : "koral:doc",
2384 "rewrites" : [{
Akron712733a2018-04-05 18:17:47 +02002385 "@type" : "koral:rewrite",
2386 "operation" : "operation:modification",
2387 "src" : "querySerializer",
2388 "scope" : "tree"
Akron5c829e92017-05-12 18:10:00 +02002389 }]
2390 }
2391 )).toBeTruthy();
Nils Diewald7c8ced22015-04-15 19:21:00 +00002392
Akron5c829e92017-05-12 18:10:00 +02002393 var nested = {
2394 "@type" : "koral:docGroup",
2395 "operands" : [
2396 {
2397 "@type" : "koral:doc"
2398 },
2399 {
2400 "@type" : "koral:docGroup",
2401 "operands" : [
2402 {
2403 "@type": "koral:doc"
2404 },
2405 {
2406 "@type": "koral:doc"
2407 }
2408 ]
2409 }
2410 ]
2411 };
2412
2413 expect(vcClass.checkRewrite(nested)).toBe(false);
2414
2415 nested["operands"][1]["operands"][1]["rewrites"] = [{
Akron712733a2018-04-05 18:17:47 +02002416 "@type" : "koral:rewrite",
2417 "operation" : "operation:modification",
2418 "src" : "querySerializer",
2419 "scope" : "tree"
Akron5c829e92017-05-12 18:10:00 +02002420 }];
2421
2422 expect(vcClass.checkRewrite(nested)).toBeTruthy();
2423 });
2424 });
Nils Diewald6283d692015-04-23 20:32:53 +00002425
2426 describe('KorAP.Rewrite', function () {
Nils Diewald7c8ced22015-04-15 19:21:00 +00002427 it('should be initializable', function () {
2428 var rewrite = rewriteClass.create({
Akron712733a2018-04-05 18:17:47 +02002429 "@type" : "koral:rewrite",
2430 "operation" : "operation:modification",
2431 "src" : "querySerializer",
2432 "scope" : "tree"
Nils Diewald86dad5b2015-01-28 15:09:07 +00002433 });
Nils Diewald7c8ced22015-04-15 19:21:00 +00002434 expect(rewrite.toString()).toEqual('Modification of "tree" by "querySerializer"');
2435 });
Nils Diewald86dad5b2015-01-28 15:09:07 +00002436
Nils Diewald7c8ced22015-04-15 19:21:00 +00002437 it('should be deserialized by docs', function () {
2438 var doc = docClass.create(
Akron712733a2018-04-05 18:17:47 +02002439 undefined,
2440 {
2441 "@type":"koral:doc",
2442 "key":"Titel",
2443 "value":"Baum",
2444 "match":"match:eq"
2445 });
Nils Diewald7c8ced22015-04-15 19:21:00 +00002446
2447 expect(doc.element().classList.contains('doc')).toBeTruthy();
2448 expect(doc.element().classList.contains('rewritten')).toBe(false);
2449
2450 doc = docClass.create(
Akron712733a2018-04-05 18:17:47 +02002451 undefined,
2452 {
2453 "@type":"koral:doc",
2454 "key":"Titel",
2455 "value":"Baum",
2456 "match":"match:eq",
2457 "rewrites" : [
2458 {
2459 "@type" : "koral:rewrite",
2460 "operation" : "operation:modification",
2461 "src" : "querySerializer",
2462 "scope" : "tree"
2463 }
2464 ]
2465 });
Nils Diewald7c8ced22015-04-15 19:21:00 +00002466
2467 expect(doc.element().classList.contains('doc')).toBeTruthy();
2468 expect(doc.element().classList.contains('rewritten')).toBeTruthy();
2469 });
Nils Diewald6283d692015-04-23 20:32:53 +00002470
Akron76c3dd62018-05-29 20:58:27 +02002471 it('should be described in a title attribute', function () {
2472
2473 doc = docClass.create(
2474 undefined,
2475 {
2476 "@type":"koral:doc",
2477 "key":"Titel",
2478 "value":"Baum",
2479 "match":"match:eq",
2480 "rewrites" : [
2481 {
2482 "@type" : "koral:rewrite",
2483 "operation" : "operation:modification",
2484 "src" : "querySerializer",
2485 "scope" : "tree"
2486 },
2487 {
2488 "@type" : "koral:rewrite",
2489 "operation" : "operation:injection",
2490 "src" : "me"
2491 }
2492 ]
2493 });
2494
2495 expect(doc.element().classList.contains('doc')).toBeTruthy();
2496 expect(doc.element().classList.contains('rewritten')).toBeTruthy();
2497 expect(doc.element().lastChild.getAttribute("title")).toEqual("querySerializer: tree (modification)\nme (injection)");
2498 });
2499
2500
Nils Diewald6283d692015-04-23 20:32:53 +00002501 xit('should be deserialized by docGroups', function () {
2502 var docGroup = docGroupClass.create(
Akron712733a2018-04-05 18:17:47 +02002503 undefined,
2504 {
2505 "@type" : "koral:docGroup",
2506 "operation" : "operation:or",
2507 "operands" : [
2508 {
2509 "@type" : "doc",
2510 "key" : "pubDate",
2511 "type" : "type:date",
2512 "value" : "2014-12-05"
2513 },
2514 {
2515 "@type" : "doc",
2516 "key" : "pubDate",
2517 "type" : "type:date",
2518 "value" : "2014-12-06"
2519 }
2520 ],
2521 "rewrites" : [
2522 {
2523 "@type" : "koral:rewrite",
2524 "operation" : "operation:modification",
2525 "src" : "querySerializer",
2526 "scope" : "tree"
2527 }
2528 ]
2529 }
Nils Diewald6283d692015-04-23 20:32:53 +00002530 );
2531
2532 expect(doc.element().classList.contains('docgroup')).toBeTruthy();
2533 expect(doc.element().classList.contains('rewritten')).toBe(false);
2534 });
Nils Diewald86dad5b2015-01-28 15:09:07 +00002535 });
Nils Diewaldf0c4f112015-05-05 12:56:59 +00002536
2537 describe('KorAP.stringValue', function () {
2538 it('should be initializable', function () {
2539 var sv = stringValClass.create();
2540 expect(sv.regex()).toBe(false);
2541 expect(sv.value()).toBe('');
Nils Diewaldc4c4b832015-05-05 16:00:08 +00002542
2543 sv = stringValClass.create('Baum');
2544 expect(sv.regex()).toBe(false);
2545 expect(sv.value()).toBe('Baum');
2546
2547 sv = stringValClass.create('Baum', false);
2548 expect(sv.regex()).toBe(false);
2549 expect(sv.value()).toBe('Baum');
2550
2551 sv = stringValClass.create('Baum', true);
2552 expect(sv.regex()).toBe(true);
2553 expect(sv.value()).toBe('Baum');
2554 });
2555
2556 it('should be modifiable', function () {
2557 var sv = stringValClass.create();
2558 expect(sv.regex()).toBe(false);
2559 expect(sv.value()).toBe('');
2560
2561 expect(sv.value('Baum')).toBe('Baum');
2562 expect(sv.value()).toBe('Baum');
2563
2564 expect(sv.regex(true)).toBe(true);
2565 expect(sv.regex()).toBe(true);
2566 });
2567
2568 it('should have a toggleble regex value', function () {
2569 var sv = stringValClass.create();
Nils Diewald7991a3f2015-05-19 14:12:37 +00002570
2571 expect(sv.element().firstChild.value).toBe('');
2572 sv.element().firstChild.value = 'der'
2573 expect(sv.element().firstChild.value).toBe('der');
2574
Nils Diewaldc4c4b832015-05-05 16:00:08 +00002575 expect(sv.regex()).toBe(false);
2576
2577 sv.toggleRegex();
Nils Diewald7991a3f2015-05-19 14:12:37 +00002578 expect(sv.element().firstChild.value).toBe('der');
Nils Diewaldc4c4b832015-05-05 16:00:08 +00002579 expect(sv.regex()).toBe(true);
Nils Diewald7991a3f2015-05-19 14:12:37 +00002580 sv.element().firstChild.value = 'derbe'
Nils Diewaldc4c4b832015-05-05 16:00:08 +00002581
2582 sv.toggleRegex();
2583 expect(sv.regex()).toBe(false);
Nils Diewald7991a3f2015-05-19 14:12:37 +00002584 expect(sv.element().firstChild.value).toBe('derbe');
Nils Diewaldc4c4b832015-05-05 16:00:08 +00002585 });
2586
2587 it('should have an element', function () {
2588 var sv = stringValClass.create('der');
2589 expect(sv.element().nodeName).toBe('DIV');
2590 expect(sv.element().firstChild.nodeName).toBe('INPUT');
2591 expect(sv.element().firstChild.value).toBe('der');
2592 });
2593
2594 it('should have a classed element', function () {
2595 var sv = stringValClass.create();
Nils Diewaldc4c4b832015-05-05 16:00:08 +00002596 expect(sv.element().classList.contains('regex')).toBe(false);
2597 expect(sv.regex()).toBe(false);
2598 sv.toggleRegex();
2599 expect(sv.element().classList.contains('regex')).toBe(true);
2600 });
2601
2602 it('should be storable', function () {
2603 var sv = stringValClass.create();
2604 var count = 1;
2605 sv.store = function (value, regex) {
Akron712733a2018-04-05 18:17:47 +02002606 expect(regex).toBe(true);
2607 expect(value).toBe('tree');
Nils Diewaldc4c4b832015-05-05 16:00:08 +00002608 };
2609 sv.regex(true);
2610 sv.value('tree');
2611 sv.element().lastChild.click();
Nils Diewaldf0c4f112015-05-05 12:56:59 +00002612 });
Akron712733a2018-04-05 18:17:47 +02002613
Akronb19803c2018-08-16 16:39:42 +02002614 it('should have a disableoption for regex', function () {
2615 var sv = stringValClass.create(undefined, undefined, true);
2616 var svE = sv.element();
2617 expect(svE.children.length).toEqual(2);
2618
2619 sv = stringValClass.create(undefined, undefined, false);
2620 svE = sv.element();
2621 expect(svE.children.length).toEqual(1);
2622 });
2623
Nils Diewaldf0c4f112015-05-05 12:56:59 +00002624 });
Akrone4961b12017-05-10 21:04:46 +02002625
Akron712733a2018-04-05 18:17:47 +02002626 describe('KorAP.VC.Menu', function () {
Akrone65a88a2018-04-05 19:14:20 +02002627
2628 var vc;
2629
Akron712733a2018-04-05 18:17:47 +02002630 it('should be initializable', function () {
2631
Akrone65a88a2018-04-05 19:14:20 +02002632 vc = vcClass.create([
Akron712733a2018-04-05 18:17:47 +02002633 ['a', 'text'],
2634 ['b', 'string'],
2635 ['c', 'date']
2636 ]).fromJson();
2637 expect(vc.element().firstChild.classList.contains('unspecified')).toBeTruthy();
2638 expect(vc.element().firstChild.firstChild.tagName).toEqual('SPAN');
2639
2640 // Click on unspecified
2641 vc.element().firstChild.firstChild.click();
2642 expect(vc.element().firstChild.firstChild.tagName).toEqual('UL');
2643
2644 var list = vc.element().firstChild.firstChild;
Akron3ad46942018-08-22 16:47:14 +02002645 expect(list.getElementsByTagName("LI")[0].innerText).toEqual('referTo');
2646 expect(list.getElementsByTagName("LI")[1].innerText).toEqual('a');
2647 expect(list.getElementsByTagName("LI")[2].innerText).toEqual('b');
2648 expect(list.getElementsByTagName("LI")[3].innerText).toEqual('c');
Akron712733a2018-04-05 18:17:47 +02002649
2650 vc = vcClass.create([
2651 ['d', 'text'],
2652 ['e', 'string'],
2653 ['f', 'date']
2654 ]).fromJson();
2655 expect(vc.element().firstChild.classList.contains('unspecified')).toBeTruthy();
2656 expect(vc.element().firstChild.firstChild.tagName).toEqual('SPAN');
2657
2658 // Click on unspecified
2659 vc.element().firstChild.firstChild.click();
2660 expect(vc.element().firstChild.firstChild.tagName).toEqual('UL');
2661
2662 list = vc.element().firstChild.firstChild;
Akron3ad46942018-08-22 16:47:14 +02002663 expect(list.getElementsByTagName("LI")[0].innerText).toEqual('referTo');
2664 expect(list.getElementsByTagName("LI")[1].innerText).toEqual('d');
2665 expect(list.getElementsByTagName("LI")[2].innerText).toEqual('e');
2666 expect(list.getElementsByTagName("LI")[3].innerText).toEqual('f');
Akron31d89942018-04-06 16:44:51 +02002667 // blur
2668 document.body.click();
Akron712733a2018-04-05 18:17:47 +02002669 });
Akrone65a88a2018-04-05 19:14:20 +02002670
2671 // Reinitialize to make tests stable
2672 vc = vcClass.create([
2673 ['d', 'text'],
2674 ['e', 'string'],
2675 ['f', 'date']
2676 ]).fromJson();
2677
2678 it('should be clickable on key', function () {
Akron31d89942018-04-06 16:44:51 +02002679 // Click on unspecified
2680 vc.element().firstChild.firstChild.click();
Akrone65a88a2018-04-05 19:14:20 +02002681 // Click on "d"
Akron3ad46942018-08-22 16:47:14 +02002682 vc.element().firstChild.firstChild.getElementsByTagName("LI")[1].click();
Akrone65a88a2018-04-05 19:14:20 +02002683 expect(vc.element().firstChild.firstChild.tagName).toEqual('SPAN');
2684 expect(vc.element().firstChild.firstChild.innerText).toEqual('d');
2685 expect(vc.element().firstChild.children[1].innerText).toEqual('eq');
2686 expect(vc.element().firstChild.children[1].getAttribute('data-type')).toEqual('text');
Akron31d89942018-04-06 16:44:51 +02002687 // blur
2688 document.body.click();
Akrone65a88a2018-04-05 19:14:20 +02002689 });
2690
Akron31d89942018-04-06 16:44:51 +02002691 it('should be clickable on operation for text', function () {
2692 // Click on "d" (or unspecified)
2693 vc.element().firstChild.firstChild.click();
2694
2695 // Choose "d"
Akron3ad46942018-08-22 16:47:14 +02002696 vc.element().firstChild.firstChild.getElementsByTagName("LI")[1].click();
Akron31d89942018-04-06 16:44:51 +02002697
2698 // Click on matchop
Akrone65a88a2018-04-05 19:14:20 +02002699 vc.element().firstChild.children[1].click();
Akron31d89942018-04-06 16:44:51 +02002700
Akrone65a88a2018-04-05 19:14:20 +02002701 expect(vc.element().firstChild.children[1].tagName).toEqual('UL');
Akron31d89942018-04-06 16:44:51 +02002702
Akrone65a88a2018-04-05 19:14:20 +02002703 var ul = vc.element().firstChild.children[1];
2704 expect(ul.getElementsByTagName('li')[0].innerText).toEqual("eq");
2705 expect(ul.getElementsByTagName('li')[1].innerText).toEqual("ne");
2706 expect(ul.getElementsByTagName('li')[2].innerText).toEqual("contains");
2707 expect(ul.getElementsByTagName('li')[3].innerText).toEqual("containsnot");
2708 expect(ul.getElementsByTagName('li')[4]).toBeUndefined();
Akron31d89942018-04-06 16:44:51 +02002709
2710 // Choose "contains"
2711 ul.getElementsByTagName('li')[2].click();
2712 expect(vc.element().firstChild.children[1].tagName).toEqual("SPAN");
2713 expect(vc.element().firstChild.children[1].innerText).toEqual("contains");
2714 // blur
2715 document.body.click();
Akrone65a88a2018-04-05 19:14:20 +02002716 })
Akron31d89942018-04-06 16:44:51 +02002717
2718 it('should be clickable on operation for string', function () {
2719 // Click on "d" (or unspecified)
2720 vc.element().firstChild.firstChild.click();
2721
2722 // Choose "e"
Akron3ad46942018-08-22 16:47:14 +02002723 vc.element().firstChild.firstChild.getElementsByTagName("LI")[2].click();
2724
Akron31d89942018-04-06 16:44:51 +02002725 // As a consequence the matchoperator may no longer
2726 // be valid and needs to be re-evaluated
2727 var fc = vc.element().firstChild;
Akron3ad46942018-08-22 16:47:14 +02002728
Akron31d89942018-04-06 16:44:51 +02002729 expect(fc.firstChild.tagName).toEqual('SPAN');
2730 expect(fc.firstChild.innerText).toEqual('e');
2731 expect(fc.children[1].innerText).toEqual('eq');
2732 expect(fc.children[1].getAttribute('data-type')).toEqual('string');
2733
2734 vc.element().firstChild.children[1].click();
2735
2736 expect(vc.element().firstChild.children[1].tagName).toEqual('UL');
2737
2738 var ul = vc.element().firstChild.children[1];
2739 expect(ul.getElementsByTagName('li')[0].innerText).toEqual("eq");
2740 expect(ul.getElementsByTagName('li')[1].innerText).toEqual("ne");
2741 expect(ul.getElementsByTagName('li')[2]).toBeUndefined();
2742
2743 // Choose "ne"
2744 ul.getElementsByTagName('li')[1].click();
2745 expect(vc.element().firstChild.children[1].tagName).toEqual("SPAN");
2746 expect(vc.element().firstChild.children[1].innerText).toEqual("ne");
Akron8db5e3a2018-05-28 19:25:26 +02002747
2748 // Click on text
2749 expect(vc.element().firstChild.children[2].innerText).toEqual("⋯");
2750 vc.element().firstChild.children[2].click();
2751
2752 // Blur text element
2753 expect(vc.element().firstChild.children[2].firstChild.value).toEqual('');
2754
Akron31d89942018-04-06 16:44:51 +02002755 // blur
2756 document.body.click();
2757 });
2758
2759 it('should be clickable on operation for date', function () {
2760
2761 // Replay matchop check - so it's guaranteed that "ne" is chosen
2762 // Click on "e" (or unspecified)
2763 vc.element().firstChild.firstChild.click();
2764 // Rechoose "e"
2765 vc.element().firstChild.firstChild.getElementsByTagName("LI")[1].click();
2766 // Click on matchop
2767 vc.element().firstChild.children[1].click();
2768 // Choose "ne"
2769 vc.element().firstChild.children[1].getElementsByTagName('li')[1].click();
2770 expect(vc.element().firstChild.children[1].innerText).toEqual("ne");
2771
2772 // Click on "e"
2773 vc.element().firstChild.firstChild.click();
2774 // Choose "f"
Akron3ad46942018-08-22 16:47:14 +02002775 vc.element().firstChild.firstChild.getElementsByTagName("LI")[3].click();
Akron31d89942018-04-06 16:44:51 +02002776
2777 // The matchoperator should still be "ne" as this is valid for dates as well (now)
2778 var fc = vc.element().firstChild;
2779 expect(fc.firstChild.tagName).toEqual('SPAN');
2780 expect(fc.firstChild.innerText).toEqual('f');
2781 expect(fc.children[1].innerText).toEqual('ne');
2782 // blur
2783 document.body.click();
2784 });
Akronddc98a72018-04-06 17:33:52 +02002785
2786
2787 // Check json deserialization
2788 it('should be initializable', function () {
2789 vc = vcClass.create([
2790 ['a', 'text'],
2791 ['b', 'string'],
2792 ['c', 'date']
2793 ]).fromJson({
2794 "@type" : "koral:doc",
2795 "key":"a",
2796 "value":"Baum"
2797 });
2798
2799 expect(vc.element().firstChild.children[1].getAttribute('data-type')).toEqual('text');
2800 });
Akron712733a2018-04-05 18:17:47 +02002801 });
2802
2803
Akrone4961b12017-05-10 21:04:46 +02002804 // Check prefix
2805 describe('KorAP.VC.Prefix', function () {
2806
2807 it('should be initializable', function () {
2808 var p = prefixClass.create();
2809 expect(p.element().classList.contains('pref')).toBeTruthy();
2810 expect(p.isSet()).not.toBeTruthy();
2811 });
2812
2813
2814 it('should be clickable', function () {
2815 var vc = vcClass.create([
Akron712733a2018-04-05 18:17:47 +02002816 ['a', null],
2817 ['b', null],
2818 ['c', null]
2819 ]).fromJson();
Akrone4961b12017-05-10 21:04:46 +02002820 expect(vc.element().firstChild.classList.contains('unspecified')).toBeTruthy();
2821
2822 // This should open up the menu
2823 vc.element().firstChild.firstChild.click();
2824 expect(vc.element().firstChild.firstChild.tagName).toEqual('UL');
2825
2826 KorAP._vcKeyMenu._prefix.clear();
2827 KorAP._vcKeyMenu._prefix.add('x');
2828
2829 var prefElement = vc.element().querySelector('span.pref');
2830 expect(prefElement.innerText).toEqual('x');
2831
2832 // This should add key 'x' to VC
2833 prefElement.click();
2834
2835 expect(vc.element().firstChild.classList.contains('doc')).toBeTruthy();
2836 expect(vc.element().firstChild.firstChild.className).toEqual('key');
2837 expect(vc.element().firstChild.firstChild.innerText).toEqual('x');
2838 });
2839 });
Nils Diewald2fe12e12015-03-06 16:47:06 +00002840});