blob: ef033ab431c4bdad1731b06830e3f00e50cb58c5 [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();
Akronebc96662018-08-29 17:36:20 +0200339
Nils Diewald7c8ced22015-04-15 19:21:00 +0000340 expect(doc.toQuery()).toEqual("");
341
342 // Serialize string
343 doc = stringFactory.create();
344 expect(doc.toQuery()).toEqual('author = "Max Birkendale"');
345
346 // Serialize string with quotes
347 doc = stringFactory.create({ "value" : 'Max "Der Coole" Birkendate'});
348 expect(doc.toQuery()).toEqual('author = "Max \\"Der Coole\\" Birkendate"');
349
350 // Serialize regex
351 doc = regexFactory.create();
352 expect(doc.toQuery()).toEqual('title = /[^b]ee.+?/');
353
354 doc = regexFactory.create({
Akron712733a2018-04-05 18:17:47 +0200355 match: "match:ne"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000356 });
357 expect(doc.toQuery()).toEqual('title != /[^b]ee.+?/');
358
Akron8778f5d2017-06-30 21:25:55 +0200359 doc = regexFactory.create({
Akron712733a2018-04-05 18:17:47 +0200360 value: "WPD/AAA/00001"
Akron8778f5d2017-06-30 21:25:55 +0200361 });
362 expect(doc.toQuery()).toEqual('title = /WPD\\/AAA\\/00001/');
363
Nils Diewald7c8ced22015-04-15 19:21:00 +0000364 doc = dateFactory.create();
365 expect(doc.toQuery()).toEqual('pubDate in 2014-11-05');
366
367 doc = dateFactory.create({
Akron712733a2018-04-05 18:17:47 +0200368 value : "2014"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000369 });
370 expect(doc.toQuery()).toEqual('pubDate in 2014');
371 });
372 });
373
374
375 describe('KorAP.DocGroup', function () {
376 // Create example factories
377 var docFactory = buildFactory(
378 docClass,
Nils Diewaldf219eb82015-01-07 20:15:42 +0000379 {
Akron712733a2018-04-05 18:17:47 +0200380 "@type" : "koral:doc",
381 "match":"match:eq",
382 "key" : "author",
383 "value" : "Max Birkendale"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000384 }
385 );
386
387 var docGroupFactory = buildFactory(
388 docGroupClass, {
Akron712733a2018-04-05 18:17:47 +0200389 "@type" : "koral:docGroup",
390 "operation" : "operation:and",
391 "operands" : [
392 docFactory.create().toJson(),
393 docFactory.create({
394 "key" : "pubDate",
395 "type" : "type:date",
396 "value" : "2014-12-05"
397 }).toJson()
398 ]
Nils Diewald7c8ced22015-04-15 19:21:00 +0000399 });
400
401 it('should be initializable', function () {
402 // Create empty group
403 var docGroup = docGroupClass.create();
404 expect(docGroup.operation()).toEqual('and');
405
406 // Create empty group
407 docGroup = docGroupClass.create();
408 docGroup.operation('or');
409 expect(docGroup.operation()).toEqual('or');
410 });
411
412 it('should be definable', function () {
413
414 // Empty group
415 var docGroup = docGroupClass.create();
416 expect(docGroup.operation()).toEqual('and');
417
418 // Set values
419 docGroup.operation("or");
420 expect(docGroup.operation()).toEqual('or');
421
422 // Set invalid values
423 docGroup.operation("hui");
424 expect(docGroup.operation()).toEqual('or');
425 });
426
427 it('should be deserializable', function () {
Akronadab5e52018-08-20 13:50:53 +0200428
429 // Reset list
430 KorAP._vcKeyMenu = menuClass.create([['referTo','ref']]);
431
Nils Diewald7c8ced22015-04-15 19:21:00 +0000432 var docGroup = docGroupFactory.create();
433 expect(docGroup.operation()).toEqual("and");
434 expect(docGroup.operands().length).toEqual(2);
435
436 var op1 = docGroup.getOperand(0);
437 expect(op1.type()).toEqual("string");
438 expect(op1.key()).toEqual("author");
439 expect(op1.value()).toEqual("Max Birkendale");
440 expect(op1.matchop()).toEqual("eq");
441
442 var op2 = docGroup.getOperand(1);
443 expect(op2.type()).toEqual("date");
444 expect(op2.key()).toEqual("pubDate");
445 expect(op2.value()).toEqual("2014-12-05");
446 expect(op2.matchop()).toEqual("eq");
447
448 // Append empty group
449 var newGroup = docGroup.append(docGroupClass.create());
450 newGroup.operation('or');
451 newGroup.append(docFactory.create());
452 newGroup.append(docFactory.create({
Akron712733a2018-04-05 18:17:47 +0200453 "type" : "type:regex",
454 "key" : "title",
455 "value" : "^e.+?$",
456 "match" : "match:ne"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000457 }));
458
459 expect(docGroup.operation()).toEqual("and");
460 expect(docGroup.operands().length).toEqual(3);
461
462 var op1 = docGroup.getOperand(0);
463 expect(op1.ldType()).toEqual("doc");
464 expect(op1.type()).toEqual("string");
465 expect(op1.key()).toEqual("author");
466 expect(op1.value()).toEqual("Max Birkendale");
467 expect(op1.matchop()).toEqual("eq");
468
469 var op2 = docGroup.getOperand(1);
470 expect(op2.ldType()).toEqual("doc");
471 expect(op2.type()).toEqual("date");
472 expect(op2.key()).toEqual("pubDate");
473 expect(op2.value()).toEqual("2014-12-05");
474 expect(op2.matchop()).toEqual("eq");
475
476 var op3 = docGroup.getOperand(2);
477 expect(op3.ldType()).toEqual("docGroup");
478 expect(op3.operation()).toEqual("or");
Akronadab5e52018-08-20 13:50:53 +0200479
Nils Diewald7c8ced22015-04-15 19:21:00 +0000480 var op4 = op3.getOperand(0);
481 expect(op4.ldType()).toEqual("doc");
482 expect(op4.type()).toEqual("string");
483 expect(op4.key()).toEqual("author");
484 expect(op4.value()).toEqual("Max Birkendale");
485 expect(op4.matchop()).toEqual("eq");
486
487 var op5 = op3.getOperand(1);
488 expect(op5.ldType()).toEqual("doc");
489 expect(op5.type()).toEqual("regex");
490 expect(op5.key()).toEqual("title");
491 expect(op5.value()).toEqual("^e.+?$");
492 expect(op5.matchop()).toEqual("ne");
493 });
494
495 it('should be serializable to JSON', function () {
496 var docGroup = docGroupFactory.create();
497
498 expect(docGroup.toJson()).toEqual(jasmine.objectContaining({
Akron712733a2018-04-05 18:17:47 +0200499 "@type" : "koral:docGroup",
500 "operation" : "operation:and",
501 "operands" : [
502 {
503 "@type": 'koral:doc',
504 "key" : 'author',
505 "match": 'match:eq',
506 "value": 'Max Birkendale',
507 "type": 'type:string'
508 },
509 {
510 "@type": 'koral:doc',
511 "key": 'pubDate',
512 "match": 'match:eq',
513 "value": '2014-12-05',
514 "type": 'type:date'
515 }
516 ]
Nils Diewald7c8ced22015-04-15 19:21:00 +0000517 }));
518 });
Nils Diewalde15b7a22015-01-09 21:50:21 +0000519
Nils Diewald7c8ced22015-04-15 19:21:00 +0000520 it('should be serializable to String', function () {
521 var docGroup = docGroupFactory.create();
522 expect(docGroup.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +0200523 'author = "Max Birkendale" & pubDate in 2014-12-05'
Nils Diewald7c8ced22015-04-15 19:21:00 +0000524 );
Nils Diewald52f7eb12015-01-12 17:30:04 +0000525
Nils Diewald7c8ced22015-04-15 19:21:00 +0000526 docGroup = docGroupFactory.create({
Akron712733a2018-04-05 18:17:47 +0200527 "@type" : "koral:docGroup",
528 "operation" : "operation:or",
529 "operands" : [
530 {
531 "@type": 'koral:doc',
532 "key" : 'author',
533 "match": 'match:eq',
534 "value": 'Max Birkendale',
535 "type": 'type:string'
536 },
537 {
538 "@type" : "koral:docGroup",
539 "operation" : "operation:and",
540 "operands" : [
541 {
542 "@type": 'koral:doc',
543 "key": 'pubDate',
544 "match": 'match:geq',
545 "value": '2014-05-12',
546 "type": 'type:date'
547 },
548 {
549 "@type": 'koral:doc',
550 "key": 'pubDate',
551 "match": 'match:leq',
552 "value": '2014-12-05',
553 "type": 'type:date'
554 },
555 {
556 "@type": 'koral:doc',
557 "key": 'foo',
558 "match": 'match:ne',
559 "value": '[a]?bar',
560 "type": 'type:regex'
561 }
562 ]
563 }
564 ]
Nils Diewald7c8ced22015-04-15 19:21:00 +0000565 });
566 expect(docGroup.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +0200567 'author = "Max Birkendale" | ' +
568 '(pubDate since 2014-05-12 & ' +
569 'pubDate until 2014-12-05 & foo != /[a]?bar/)'
Nils Diewald7c8ced22015-04-15 19:21:00 +0000570 );
571 });
572 });
573
Akronb19803c2018-08-16 16:39:42 +0200574 describe('KorAP.DocGroupRef', function () {
575 // Create example factories
576 var docRefFactory = buildFactory(
577 docGroupRefClass,
578 {
579 "@type" : "koral:docGroupRef",
580 "ref" : "@max/myCorpus"
581 }
582 );
583
584 it('should be initializable', function () {
585 var vcRef = docGroupRefClass.create();
586 expect(vcRef.ref()).toBeUndefined();
587 });
588
589 it('should be definable', function () {
590 var vcRef = docGroupRefClass.create();
591 vcRef.ref("@peter/mycorpus");
592 expect(vcRef.ref()).toEqual("@peter/mycorpus");
593 vcRef.ref("@peter/mycorpus2");
594 expect(vcRef.ref()).toEqual("@peter/mycorpus2");
595 });
596
597 it('should deserialize JSON-LD string', function () {
598 var vcRef = docRefFactory.create();
599 expect(vcRef.ref()).toEqual("@max/myCorpus");
600 });
601
602 it('should serialize to JSON-LD', function () {
603 var vcRef = docRefFactory.create();
604 expect(vcRef.toJson()).toEqual(jasmine.objectContaining({
605 "@type" : "koral:docGroupRef",
606 "ref":"@max/myCorpus"
607 }));
608
609 vcRef.ref("@peter/myCorpus2");
610 expect(vcRef.toJson()).toEqual(jasmine.objectContaining({
611 "@type" : "koral:docGroupRef",
612 "ref":"@peter/myCorpus2"
613 }));
614 });
615
616 it('should serialize to a query', function () {
617 var vcRef = docRefFactory.create();
618 expect(vcRef.toQuery()).toEqual(
619 "referTo \"@max/myCorpus\""
620 );
621
622 vcRef.ref("@peter/myCorpus2");
623 expect(vcRef.toQuery()).toEqual(
624 "referTo \"@peter/myCorpus2\""
625 );
626 });
627 });
628
629
Nils Diewald7c8ced22015-04-15 19:21:00 +0000630 describe('KorAP.UnspecifiedDoc', function () {
631 it('should be initializable', function () {
632 var doc = unspecifiedClass.create();
633 var docElement = doc.element();
634 expect(docElement.getAttribute('class')).toEqual('doc unspecified');
Akronebc96662018-08-29 17:36:20 +0200635 expect(docElement.firstChild.firstChild.data).toEqual(KorAP.Locale.EMPTY);
636 expect(docElement.lastChild.lastChild.data).toEqual(KorAP.Locale.EMPTY);
Nils Diewald7c8ced22015-04-15 19:21:00 +0000637 expect(doc.toQuery()).toEqual('');
638
639 // Only removable
640 expect(docElement.lastChild.children.length).toEqual(0);
641 });
642
Akrond141a362018-07-10 18:12:13 +0200643 it('should be removable, when no root', function () {
Nils Diewald7c8ced22015-04-15 19:21:00 +0000644 var docGroup = docGroupClass.create();
645 docGroup.operation('or');
646 expect(docGroup.operation()).toEqual('or');
647
648 docGroup.append({
Akron712733a2018-04-05 18:17:47 +0200649 "@type": 'koral:doc',
650 "key": 'pubDate',
651 "match": 'match:eq',
652 "value": '2014-12-05',
653 "type": 'type:date'
Nils Diewald7c8ced22015-04-15 19:21:00 +0000654 });
655
656 // Add unspecified object
657 docGroup.append();
658
Akrond141a362018-07-10 18:12:13 +0200659 var parent = document.createElement('div');
660 parent.appendChild(docGroup.element());
661
Nils Diewald7c8ced22015-04-15 19:21:00 +0000662 expect(docGroup.element().getAttribute('class')).toEqual('docGroup');
663 expect(docGroup.element().children[0].getAttribute('class')).toEqual('doc');
664
665 var unspec = docGroup.element().children[1];
666 expect(unspec.getAttribute('class')).toEqual('doc unspecified');
667
Akronb19803c2018-08-16 16:39:42 +0200668 // Only unspec and delete
669 expect(unspec.children.length).toEqual(2);
670
Nils Diewald7c8ced22015-04-15 19:21:00 +0000671 // Removable
672 expect(unspec.lastChild.children.length).toEqual(1);
673 expect(unspec.lastChild.children[0].getAttribute('class')).toEqual('delete');
674 });
675
Akrond141a362018-07-10 18:12:13 +0200676
Nils Diewald7c8ced22015-04-15 19:21:00 +0000677 it('should be replaceable by a doc', function () {
678 var doc = unspecifiedClass.create();
679 expect(doc.ldType()).toEqual("non");
680 // No parent, therefor not updateable
681 expect(doc.key("baum")).toBeNull();
682
683 var docGroup = docGroupClass.create();
684 docGroup.operation('or');
685 expect(docGroup.operation()).toEqual('or');
686
687 docGroup.append({
Akron712733a2018-04-05 18:17:47 +0200688 "@type": 'koral:doc',
689 "key": 'pubDate',
690 "match": 'match:eq',
691 "value": '2014-12-05',
692 "type": 'type:date'
Nils Diewald7c8ced22015-04-15 19:21:00 +0000693 });
694
695 expect(docGroup.toQuery()).toEqual("pubDate in 2014-12-05");
696 docGroup.append();
697
698 expect(docGroup.getOperand(0).ldType()).toEqual("doc");
699 expect(docGroup.getOperand(1).ldType()).toEqual("non");
700
701 var op = docGroup.getOperand(1).element().lastChild;
Akron0b489ad2018-02-02 16:49:32 +0100702 expect(op.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +0000703 expect(op.children[0].getAttribute('class')).toEqual('delete');
704 expect(op.children.length).toEqual(1);
705
706 // Replace unspecified doc
707 expect(docGroup.getOperand(1).key("name")).not.toBeNull();
708 expect(docGroup.getOperand(1).ldType()).toEqual("doc");
709 expect(docGroup.getOperand(1).key()).toEqual("name");
Akron55a343b2018-04-06 19:57:36 +0200710 expect(docGroup.getOperand(1).value()).toBeUndefined();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000711
Akronb19803c2018-08-16 16:39:42 +0200712 expect(docGroup.getOperand(1).element().children.length).toEqual(4);
713
Nils Diewald7c8ced22015-04-15 19:21:00 +0000714 op = docGroup.getOperand(1).element().lastChild;
Akron0b489ad2018-02-02 16:49:32 +0100715 expect(op.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +0000716 expect(op.children[0].getAttribute('class')).toEqual('and');
717 expect(op.children[1].getAttribute('class')).toEqual('or');
718 expect(op.children[2].getAttribute('class')).toEqual('delete');
Akronb19803c2018-08-16 16:39:42 +0200719
Nils Diewald7c8ced22015-04-15 19:21:00 +0000720 expect(op.children.length).toEqual(3);
721
722 docGroup.getOperand(1).value("Pachelbel");
723 expect(docGroup.getOperand(1).value()).toEqual("Pachelbel");
724 expect(docGroup.getOperand(1).type()).toEqual("string");
725 expect(docGroup.getOperand(1).matchop()).toEqual("eq");
726
727 // Specified!
728 expect(docGroup.toQuery()).toEqual('pubDate in 2014-12-05 | name = "Pachelbel"');
729 });
Akronb19803c2018-08-16 16:39:42 +0200730
Nils Diewald7c8ced22015-04-15 19:21:00 +0000731 it('should be replaceable on root', function () {
Nils Diewald6283d692015-04-23 20:32:53 +0000732 var vc = vcClass.create();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000733 expect(vc.toQuery()).toEqual("");
734
735 expect(vc.root().ldType()).toEqual("non");
736
737 // No operators on root
738 op = vc.root().element().lastChild;
Akronebc96662018-08-29 17:36:20 +0200739 expect(op.lastChild.textContent).toEqual(KorAP.Locale.EMPTY);
Nils Diewald7c8ced22015-04-15 19:21:00 +0000740
741 // Replace
742 expect(vc.root().key("baum")).not.toBeNull();
743 expect(vc.root().ldType()).toEqual("doc");
744
745 op = vc.root().element().lastChild;
Akron0b489ad2018-02-02 16:49:32 +0100746 expect(op.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +0000747 expect(op.children[0].getAttribute('class')).toEqual('and');
748 expect(op.children[1].getAttribute('class')).toEqual('or');
749 expect(op.children[2].getAttribute('class')).toEqual('delete');
750 expect(op.children.length).toEqual(3);
751 });
Akron55a343b2018-04-06 19:57:36 +0200752
753 it('should be clickable', function () {
754 var vc = vcClass.create([
755 ["pubDate", "date"]
756 ]);
757 expect(vc.toQuery()).toEqual("");
Akronebc96662018-08-29 17:36:20 +0200758 expect(vc.builder().firstChild.textContent).toEqual(KorAP.Locale.EMPTY);
759 expect(vc.builder().firstChild.classList.contains('unspecified')).toEqual(true);
Akronadab5e52018-08-20 13:50:53 +0200760 vc.builder().firstChild.firstChild.click();
Akron55a343b2018-04-06 19:57:36 +0200761
762 // Click on pubDate
Akron3ad46942018-08-22 16:47:14 +0200763 vc.element().firstChild.getElementsByTagName("LI")[1].click();
Akronadab5e52018-08-20 13:50:53 +0200764 expect(vc.builder().firstChild.firstChild.textContent).toEqual("pubDate");
765 expect(vc.builder().firstChild.children[1].getAttribute("data-type")).toEqual("date");
Akron55a343b2018-04-06 19:57:36 +0200766 });
Nils Diewald7c8ced22015-04-15 19:21:00 +0000767 });
768
769 describe('KorAP.Doc element', function () {
770 it('should be initializable', function () {
771 var docElement = docClass.create(undefined, {
Akron712733a2018-04-05 18:17:47 +0200772 "@type" : "koral:doc",
773 "key":"Titel",
774 "value":"Baum",
775 "match":"match:eq"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000776 });
777 expect(docElement.key()).toEqual('Titel');
778 expect(docElement.matchop()).toEqual('eq');
779 expect(docElement.value()).toEqual('Baum');
780
781 var docE = docElement.element();
782 expect(docE.children[0].firstChild.data).toEqual('Titel');
783 expect(docE.children[1].firstChild.data).toEqual('eq');
784 expect(docE.children[1].getAttribute('data-type')).toEqual('string');
785 expect(docE.children[2].firstChild.data).toEqual('Baum');
786 expect(docE.children[2].getAttribute('data-type')).toEqual('string');
787
788 expect(docElement.toJson()).toEqual(jasmine.objectContaining({
Akron712733a2018-04-05 18:17:47 +0200789 "@type" : "koral:doc",
790 "key":"Titel",
791 "value":"Baum",
792 "match":"match:eq"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000793 }));
794 });
Akronb19803c2018-08-16 16:39:42 +0200795
796
797 it('should be replacable by unspecified', function () {
798 var vc = vcClass.create([
799 ["pubDate", "date"]
800 ]).fromJson({
801 "@type" : "koral:doc",
802 "key":"Titel",
803 "value":"Baum",
804 "match":"match:eq"
805 });
806 expect(vc.toQuery()).toEqual("Titel = \"Baum\"");
807
Akronadab5e52018-08-20 13:50:53 +0200808 var vcE = vc.builder();
Akronb19803c2018-08-16 16:39:42 +0200809 expect(vcE.firstChild.children.length).toEqual(4);
810
811 // Click to delete
812 vcE.firstChild.lastChild.lastChild.click();
813
814 expect(vcE.firstChild.children.length).toEqual(1);
815
Akronebc96662018-08-29 17:36:20 +0200816 expect(vcE.firstChild.textContent).toEqual(KorAP.Locale.EMPTY);
817 expect(vcE.firstChild.classList.contains("unspecified")).toBeTruthy();
Akronb19803c2018-08-16 16:39:42 +0200818 vcE.firstChild.firstChild.click();
819
820 // Click on pubDate
Akron3ad46942018-08-22 16:47:14 +0200821 vcE.firstChild.getElementsByTagName("LI")[1].click();
Akronb19803c2018-08-16 16:39:42 +0200822
823 expect(vcE.firstChild.firstChild.textContent).toEqual("pubDate");
824 expect(vcE.firstChild.children[1].getAttribute("data-type")).toEqual("date");
825
826 expect(vcE.firstChild.children.length).toEqual(4);
827 });
828
829
830 it('should be replaceable by a docGroupRef', function () {
Akron3ad46942018-08-22 16:47:14 +0200831 var vc = vcClass.create().fromJson({
Akronb19803c2018-08-16 16:39:42 +0200832 "@type" : "koral:doc",
833 "key":"Titel",
834 "value":"Baum",
835 "match":"match:eq"
836 });
837
838 expect(vc.toQuery()).toEqual("Titel = \"Baum\"");
839
Akronadab5e52018-08-20 13:50:53 +0200840 var vcE = vc.builder();
Akronb19803c2018-08-16 16:39:42 +0200841 expect(vcE.firstChild.children.length).toEqual(4);
842
843 // Click to delete
844 vcE.firstChild.lastChild.lastChild.click();
845
846 expect(vcE.firstChild.children.length).toEqual(1);
847
Akronebc96662018-08-29 17:36:20 +0200848 expect(vcE.firstChild.textContent).toEqual(KorAP.Locale.EMPTY);
849 expect(vcE.firstChild.classList.contains('unspecified')).toEqual(true);
Akronb19803c2018-08-16 16:39:42 +0200850 vcE.firstChild.firstChild.click();
851
Akron3ad46942018-08-22 16:47:14 +0200852 // Click on referTo
Akronb19803c2018-08-16 16:39:42 +0200853 vcE.firstChild.getElementsByTagName("LI")[0].click();
854
Akron3ad46942018-08-22 16:47:14 +0200855 expect(vcE.firstChild.firstChild.textContent).toEqual("referTo");
Akronb19803c2018-08-16 16:39:42 +0200856 expect(vcE.firstChild.children[1].getAttribute("data-type")).toEqual("string");
857 expect(vcE.firstChild.children.length).toEqual(3);
Akron62ac95b2018-08-30 18:08:25 +0200858 expect(vcE.firstChild.children[1].classList.contains("unspecified")).toBeTruthy();
Akronb19803c2018-08-16 16:39:42 +0200859 });
Nils Diewald7c8ced22015-04-15 19:21:00 +0000860 });
861
862 describe('KorAP.DocGroup element', function () {
863 it('should be initializable', function () {
864
865 var docGroup = docGroupClass.create(undefined, {
Akron712733a2018-04-05 18:17:47 +0200866 "@type" : "koral:docGroup",
867 "operation" : "operation:and",
868 "operands" : [
869 {
870 "@type": 'koral:doc',
871 "key" : 'author',
872 "match": 'match:eq',
873 "value": 'Max Birkendale',
874 "type": 'type:string'
875 },
876 {
877 "@type": 'koral:doc',
878 "key": 'pubDate',
879 "match": 'match:eq',
880 "value": '2014-12-05',
881 "type": 'type:date'
882 }
883 ]
Nils Diewald7c8ced22015-04-15 19:21:00 +0000884 });
885
886 expect(docGroup.operation()).toEqual('and');
887 var e = docGroup.element();
888 expect(e.getAttribute('class')).toEqual('docGroup');
889 expect(e.getAttribute('data-operation')).toEqual('and');
890
891 var first = e.children[0];
892 expect(first.getAttribute('class')).toEqual('doc');
893 expect(first.children[0].getAttribute('class')).toEqual('key');
894 expect(first.children[1].getAttribute('class')).toEqual('match');
895 expect(first.children[2].getAttribute('class')).toEqual('value');
896 expect(first.children[2].getAttribute('data-type')).toEqual('string');
897 expect(first.children[0].firstChild.data).toEqual('author');
898 expect(first.children[1].firstChild.data).toEqual('eq');
899 expect(first.children[2].firstChild.data).toEqual('Max Birkendale');
900
901 var second = e.children[1];
902 expect(second.getAttribute('class')).toEqual('doc');
903 expect(second.children[0].getAttribute('class')).toEqual('key');
904 expect(second.children[1].getAttribute('class')).toEqual('match');
905 expect(second.children[2].getAttribute('class')).toEqual('value');
906 expect(second.children[2].getAttribute('data-type')).toEqual('date');
907 expect(second.children[0].firstChild.data).toEqual('pubDate');
908 expect(second.children[1].firstChild.data).toEqual('eq');
909 expect(second.children[2].firstChild.data).toEqual('2014-12-05');
910 });
911
912 it('should be deserializable with nested groups', function () {
913 var docGroup = docGroupClass.create(undefined, {
Akron712733a2018-04-05 18:17:47 +0200914 "@type" : "koral:docGroup",
915 "operation" : "operation:or",
916 "operands" : [
917 {
918 "@type": 'koral:doc',
919 "key" : 'author',
920 "match": 'match:eq',
921 "value": 'Max Birkendale',
922 "type": 'type:string'
923 },
924 {
925 "@type" : "koral:docGroup",
926 "operation" : "operation:and",
927 "operands" : [
928 {
929 "@type": 'koral:doc',
930 "key": 'pubDate',
931 "match": 'match:geq',
932 "value": '2014-05-12',
933 "type": 'type:date'
934 },
935 {
936 "@type": 'koral:doc',
937 "key": 'pubDate',
938 "match": 'match:leq',
939 "value": '2014-12-05',
940 "type": 'type:date'
941 }
942 ]
943 }
944 ]
Nils Diewald7c8ced22015-04-15 19:21:00 +0000945 });
946
947 expect(docGroup.operation()).toEqual('or');
948 var e = docGroup.element();
949 expect(e.getAttribute('class')).toEqual('docGroup');
950 expect(e.getAttribute('data-operation')).toEqual('or');
951
952 expect(e.children[0].getAttribute('class')).toEqual('doc');
953 var docop = e.children[0].lastChild;
Akron0b489ad2018-02-02 16:49:32 +0100954 expect(docop.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +0000955 expect(docop.children[0].getAttribute('class')).toEqual('and');
956 expect(docop.children[1].getAttribute('class')).toEqual('or');
957 expect(docop.children[2].getAttribute('class')).toEqual('delete');
958
959 expect(e.children[1].getAttribute('class')).toEqual('docGroup');
960 expect(e.children[1].getAttribute('data-operation')).toEqual('and');
961
962 // This and-operation can be "or"ed or "delete"d
963 var secop = e.children[1].children[2];
Akron0b489ad2018-02-02 16:49:32 +0100964 expect(secop.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +0000965 expect(secop.children[0].getAttribute('class')).toEqual('or');
966 expect(secop.children[1].getAttribute('class')).toEqual('delete');
967
968 // This or-operation can be "and"ed or "delete"d
Akron0b489ad2018-02-02 16:49:32 +0100969 expect(e.children[2].getAttribute('class')).toEqual('operators button-group');
970 expect(e.lastChild.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +0000971 expect(e.lastChild.children[0].getAttribute('class')).toEqual('and');
972 expect(e.lastChild.children[1].getAttribute('class')).toEqual('delete');
973 });
974 });
975
Akronb19803c2018-08-16 16:39:42 +0200976 describe('KorAP.DocGroupRef element', function () {
977 it('should be initializable', function () {
978 var docGroupRef = docGroupRefClass.create(undefined, {
979 "@type" : "koral:docGroupRef",
980 "ref" : "@franz/myVC1"
981 });
982 expect(docGroupRef.ref()).toEqual("@franz/myVC1");
983 var dgrE = docGroupRef.element();
984
Akron3ad46942018-08-22 16:47:14 +0200985 expect(dgrE.children[0].firstChild.data).toEqual("referTo");
Akronb19803c2018-08-16 16:39:42 +0200986 expect(dgrE.children[0].tagName).toEqual("SPAN");
987 expect(dgrE.children[0].classList.contains("key")).toBeTruthy();
988 expect(dgrE.children[0].classList.contains("fixed")).toBeTruthy();
989 expect(dgrE.children[1].firstChild.data).toEqual("@franz/myVC1");
990 expect(dgrE.children[1].tagName).toEqual("SPAN");
991 expect(dgrE.children[1].classList.contains("value")).toBeTruthy();
992 expect(dgrE.children[1].getAttribute("data-type")).toEqual("string");
993 });
994
995 it('should be modifiable on reference', function () {
996 var docGroupRef = docGroupRefClass.create(undefined, {
997 "@type" : "koral:docGroupRef",
998 "ref" : "@franz/myVC1"
999 });
1000 var dgrE = docGroupRef.element();
1001 expect(docGroupRef.toQuery()).toEqual("referTo \"@franz/myVC1\"");
1002 dgrE.children[1].click();
1003
1004 var input = dgrE.children[1].firstChild;
1005 expect(input.tagName).toEqual("INPUT");
1006 input.value = "Versuch";
1007
1008 var event = new KeyboardEvent("keypress", {
1009 "key" : "[Enter]",
1010 "keyCode" : 13
1011 });
1012
1013 input.dispatchEvent(event);
1014 expect(docGroupRef.toQuery()).toEqual("referTo \"Versuch\"");
1015 });
1016 });
1017
1018
Akrone4961b12017-05-10 21:04:46 +02001019 describe('KorAP.VirtualCorpus', function () {
Nils Diewald7c8ced22015-04-15 19:21:00 +00001020 var simpleGroupFactory = buildFactory(docGroupClass, {
1021 "@type" : "koral:docGroup",
1022 "operation" : "operation:and",
1023 "operands" : [
Akron712733a2018-04-05 18:17:47 +02001024 {
1025 "@type": 'koral:doc',
1026 "key" : 'author',
1027 "match": 'match:eq',
1028 "value": 'Max Birkendale',
1029 "type": 'type:string'
1030 },
1031 {
1032 "@type": 'koral:doc',
1033 "key": 'pubDate',
1034 "match": 'match:eq',
1035 "value": '2014-12-05',
1036 "type": 'type:date'
1037 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00001038 ]
1039 });
1040
1041 var nestedGroupFactory = buildFactory(vcClass, {
1042 "@type" : "koral:docGroup",
1043 "operation" : "operation:or",
1044 "operands" : [
Akron712733a2018-04-05 18:17:47 +02001045 {
1046 "@type": 'koral:doc',
1047 "key" : 'author',
1048 "match": 'match:eq',
1049 "value": 'Max Birkendale',
1050 "type": 'type:string'
1051 },
1052 {
1053 "@type" : "koral:docGroup",
1054 "operation" : "operation:and",
1055 "operands" : [
1056 {
1057 "@type": 'koral:doc',
1058 "key": 'pubDate',
1059 "match": 'match:geq',
1060 "value": '2014-05-12',
1061 "type": 'type:date'
1062 },
1063 {
1064 "@type": 'koral:doc',
1065 "key": 'pubDate',
1066 "match": 'match:leq',
1067 "value": '2014-12-05',
1068 "type": 'type:date'
1069 }
1070 ]
1071 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00001072 ]
1073 });
1074
1075 var flatGroupFactory = buildFactory(vcClass, {
1076 "@type" : "koral:docGroup",
1077 "operation" : "operation:and",
1078 "operands" : [
Akron712733a2018-04-05 18:17:47 +02001079 {
1080 "@type": 'koral:doc',
1081 "key": 'pubDate',
1082 "match": 'match:geq',
1083 "value": '2014-05-12',
1084 "type": 'type:date'
1085 },
1086 {
1087 "@type": 'koral:doc',
1088 "key": 'pubDate',
1089 "match": 'match:leq',
1090 "value": '2014-12-05',
1091 "type": 'type:date'
1092 },
1093 {
1094 "@type": 'koral:doc',
1095 "key": 'foo',
1096 "match": 'match:eq',
1097 "value": 'bar',
1098 "type": 'type:string'
1099 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00001100 ]
1101 });
1102
1103 it('should be initializable', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00001104 var vc = vcClass.create();
Nils Diewald7c8ced22015-04-15 19:21:00 +00001105 expect(vc.element().getAttribute('class')).toEqual('vc');
1106 expect(vc.root().element().getAttribute('class')).toEqual('doc unspecified');
1107
1108 // Not removable
1109 expect(vc.root().element().lastChild.children.length).toEqual(0);
1110 });
1111
1112 it('should be based on a doc', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00001113 var vc = vcClass.create().fromJson({
Akron712733a2018-04-05 18:17:47 +02001114 "@type" : "koral:doc",
1115 "key":"Titel",
1116 "value":"Baum",
1117 "match":"match:eq"
Nils Diewald7c8ced22015-04-15 19:21:00 +00001118 });
1119
1120 expect(vc.element().getAttribute('class')).toEqual('vc');
1121 expect(vc.root().element().getAttribute('class')).toEqual('doc');
1122 expect(vc.root().key()).toEqual('Titel');
1123 expect(vc.root().value()).toEqual('Baum');
1124 expect(vc.root().matchop()).toEqual('eq');
1125
1126 var docE = vc.root().element();
1127 expect(docE.children[0].firstChild.data).toEqual('Titel');
1128 expect(docE.children[1].firstChild.data).toEqual('eq');
1129 expect(docE.children[1].getAttribute('data-type')).toEqual('string');
1130 expect(docE.children[2].firstChild.data).toEqual('Baum');
1131 expect(docE.children[2].getAttribute('data-type')).toEqual('string');
1132 });
1133
1134 it('should be based on a docGroup', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00001135 var vc = vcClass.create().fromJson(simpleGroupFactory.create().toJson());
Nils Diewald7c8ced22015-04-15 19:21:00 +00001136
1137 expect(vc.element().getAttribute('class')).toEqual('vc');
1138 expect(vc.root().element().getAttribute('class')).toEqual('docGroup');
1139 expect(vc.root().operation()).toEqual('and');
1140
1141 var docGroup = vc.root();
1142
1143 var first = docGroup.getOperand(0);
1144 expect(first.key()).toEqual('author');
1145 expect(first.value()).toEqual('Max Birkendale');
1146 expect(first.matchop()).toEqual('eq');
1147
1148 var second = docGroup.getOperand(1);
1149 expect(second.key()).toEqual('pubDate');
1150 expect(second.value()).toEqual('2014-12-05');
1151 expect(second.matchop()).toEqual('eq');
1152 });
1153
Akronb19803c2018-08-16 16:39:42 +02001154 it('should be based on a docGroupRef', function () {
1155 var vc = vcClass.create().fromJson({
1156 "@type" : "koral:docGroupRef",
1157 "ref":"myCorpus"
1158 });
1159
Akronadab5e52018-08-20 13:50:53 +02001160 // iv class="doc groupref"><span class="key fixed">@referTo</span><span data-type="string" class="value">myCorpus</span>
1161 var vcE = vc.builder();
1162 expect(vcE.getAttribute('class')).toEqual('builder');
Akronb19803c2018-08-16 16:39:42 +02001163 expect(vcE.firstChild.tagName).toEqual('DIV');
1164 expect(vcE.firstChild.classList.contains('groupref')).toBeTruthy();
1165
1166 expect(vcE.firstChild.firstChild.tagName).toEqual('SPAN');
1167 expect(vcE.firstChild.firstChild.classList.contains('key')).toBeTruthy();
1168 expect(vcE.firstChild.firstChild.classList.contains('fixed')).toBeTruthy();
1169
Akron3ad46942018-08-22 16:47:14 +02001170 expect(vcE.firstChild.firstChild.textContent).toEqual("referTo");
Akronb19803c2018-08-16 16:39:42 +02001171
1172 expect(vcE.firstChild.children[1].tagName).toEqual('SPAN');
1173 expect(vcE.firstChild.children[1].classList.contains('value')).toBeTruthy();
1174 expect(vcE.firstChild.children[1].getAttribute('data-type')).toEqual('string');
1175 expect(vcE.firstChild.children[1].textContent).toEqual("myCorpus");
1176 });
Nils Diewald7c8ced22015-04-15 19:21:00 +00001177
1178 it('should be based on a nested docGroup', function () {
1179 var vc = nestedGroupFactory.create();
1180
Akronadab5e52018-08-20 13:50:53 +02001181 expect(vc.builder().getAttribute('class')).toEqual('builder');
1182 expect(vc.builder().firstChild.getAttribute('class')).toEqual('docGroup');
1183 expect(vc.builder().firstChild.children[0].getAttribute('class')).toEqual('doc');
1184 var dg = vc.builder().firstChild.children[1];
Nils Diewald7c8ced22015-04-15 19:21:00 +00001185 expect(dg.getAttribute('class')).toEqual('docGroup');
1186 expect(dg.children[0].getAttribute('class')).toEqual('doc');
1187 expect(dg.children[1].getAttribute('class')).toEqual('doc');
Akron0b489ad2018-02-02 16:49:32 +01001188 expect(dg.children[2].getAttribute('class')).toEqual('operators button-group');
Akronadab5e52018-08-20 13:50:53 +02001189 expect(vc.builder().firstChild.children[2].getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001190 });
1191
Akronb19803c2018-08-16 16:39:42 +02001192 it('should be based on a nested docGroupRef', function () {
1193 var vc = vcClass.create().fromJson({
1194 "@type" : "koral:docGroup",
1195 "operation" : "operation:and",
1196 "operands" : [{
1197 "@type" : "koral:docGroupRef",
1198 "ref":"myCorpus"
1199 },{
1200 "@type" : "koral:doc",
1201 "key":"Titel",
1202 "value":"Baum",
1203 "match":"match:eq"
1204 }]
1205 });
1206
1207 expect(vc._root.ldType()).toEqual("docGroup");
1208
1209 expect(vc.toQuery()).toEqual('referTo "myCorpus" & Titel = "Baum"');
1210 });
1211
1212
Nils Diewald7c8ced22015-04-15 19:21:00 +00001213 it('should be modifiable by deletion in flat docGroups', function () {
1214 var vc = flatGroupFactory.create();
1215 var docGroup = vc.root();
1216
1217 expect(docGroup.element().getAttribute('class')).toEqual('docGroup');
1218
1219 var doc = docGroup.getOperand(1);
1220 expect(doc.key()).toEqual("pubDate");
1221 expect(doc.value()).toEqual("2014-12-05");
1222
1223 // Remove operand 1
1224 expect(docGroup.delOperand(doc).update()).not.toBeUndefined();
1225 expect(doc._element).toEqual(undefined);
1226
1227 doc = docGroup.getOperand(1);
1228 expect(doc.key()).toEqual("foo");
1229
1230 // Remove operand 1
1231 expect(docGroup.delOperand(doc).update()).not.toBeUndefined();
1232 expect(doc._element).toEqual(undefined);
1233
1234 // Only one operand left ...
1235 expect(docGroup.getOperand(1)).toBeUndefined();
1236 // ... but there shouldn't be a group anymore at all!
1237 expect(docGroup.getOperand(0)).toBeUndefined();
1238
1239 var obj = vc.root();
1240 expect(obj.ldType()).toEqual("doc");
1241 expect(obj.key()).toEqual("pubDate");
1242 expect(obj.value()).toEqual("2014-05-12");
1243
1244 expect(obj.element().getAttribute('class')).toEqual('doc');
1245 });
1246
1247
1248 it('should be modifiable by deletion in nested docGroups (root case)', function () {
1249 var vc = nestedGroupFactory.create();
1250
1251 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001252 'author = "Max Birkendale" | (pubDate since 2014-05-12 & pubDate until 2014-12-05)'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001253 );
1254
1255 var docGroup = vc.root();
1256 expect(docGroup.ldType()).toEqual("docGroup");
1257 expect(docGroup.operation()).toEqual("or");
1258
1259 var doc = docGroup.getOperand(0);
1260 expect(doc.key()).toEqual("author");
1261 expect(doc.value()).toEqual("Max Birkendale");
1262
1263 docGroup = docGroup.getOperand(1);
1264 expect(docGroup.operation()).toEqual("and");
1265
1266 doc = docGroup.getOperand(0);
1267 expect(doc.key()).toEqual("pubDate");
1268 expect(doc.matchop()).toEqual("geq");
1269 expect(doc.value()).toEqual("2014-05-12");
1270 expect(doc.type()).toEqual("date");
1271
1272 doc = docGroup.getOperand(1);
1273 expect(doc.key()).toEqual("pubDate");
1274 expect(doc.matchop()).toEqual("leq");
1275 expect(doc.value()).toEqual("2014-12-05");
1276 expect(doc.type()).toEqual("date");
1277
1278 // Remove first operand so everything becomes root
1279 expect(
Akron712733a2018-04-05 18:17:47 +02001280 vc.root().delOperand(
1281 vc.root().getOperand(0)
1282 ).update().ldType()
Nils Diewald7c8ced22015-04-15 19:21:00 +00001283 ).toEqual("docGroup");
1284
1285 expect(vc.root().ldType()).toEqual("docGroup");
1286 expect(vc.root().operation()).toEqual("and");
1287 expect(vc.root().getOperand(0).ldType()).toEqual("doc");
1288
1289 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001290 'pubDate since 2014-05-12 & pubDate until 2014-12-05'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001291 );
1292 });
1293
1294 it('should be modifiable by deletion in nested docGroups (resolve group case)', function () {
1295 var vc = nestedGroupFactory.create();
1296
1297 // Get nested group
1298 var firstGroup = vc.root().getOperand(1);
1299 firstGroup.append(simpleGroupFactory.create({ "operation" : "operation:or" }));
1300
1301 // Structur is now:
1302 // or(doc, and(doc, doc, or(doc, doc)))
1303
1304 // Get nested or in and
1305 var orGroup = vc.root().getOperand(1).getOperand(2);
1306 expect(orGroup.ldType()).toEqual("docGroup");
1307 expect(orGroup.operation()).toEqual("or");
1308
1309 // Remove
1310 // Structur is now:
1311 // or(doc, and(doc, doc, doc)))
1312 expect(orGroup.delOperand(orGroup.getOperand(0)).update().operation()).toEqual("and");
1313 expect(vc.root().getOperand(1).operands().length).toEqual(3);
1314 });
1315
1316 it('should be modifiable by deletion in nested docGroups (identical group case)', function () {
1317 var vc = nestedGroupFactory.create();
1318
1319 // Get nested group
1320 var firstGroup = vc.root().getOperand(1);
1321 firstGroup.append(simpleGroupFactory.create({
Akron712733a2018-04-05 18:17:47 +02001322 "operation" : "operation:or"
Nils Diewald7c8ced22015-04-15 19:21:00 +00001323 }));
1324 var oldAuthor = firstGroup.getOperand(2).getOperand(0);
1325 oldAuthor.key("title");
1326 oldAuthor.value("Der Birnbaum");
1327
1328 // Structur is now:
1329 // or(doc, and(doc, doc, or(doc, doc)))
1330 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001331 'author = "Max Birkendale" | ' +
1332 '(pubDate since 2014-05-12 & ' +
1333 'pubDate until 2014-12-05 & ' +
1334 '(title = "Der Birnbaum" | ' +
1335 'pubDate in 2014-12-05))'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001336 );
1337
1338 var andGroup = vc.root().getOperand(1);
1339
1340 // Get leading docs in and
1341 var doc1 = andGroup.getOperand(0);
1342 expect(doc1.ldType()).toEqual("doc");
1343 expect(doc1.value()).toEqual("2014-05-12");
1344 var doc2 = andGroup.getOperand(1);
1345 expect(doc2.ldType()).toEqual("doc");
1346 expect(doc2.value()).toEqual("2014-12-05");
1347
1348 // Remove 2
1349 expect(
Akron712733a2018-04-05 18:17:47 +02001350 andGroup.delOperand(doc2).update().operation()
Nils Diewald7c8ced22015-04-15 19:21:00 +00001351 ).toEqual("and");
1352 // Structur is now:
1353 // or(doc, and(doc, or(doc, doc)))
1354
1355 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001356 'author = "Max Birkendale"' +
1357 ' | (pubDate since 2014-05-12 & ' +
1358 '(title = "Der Birnbaum" | pubDate in 2014-12-05))'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001359 );
1360
1361
1362 // Remove 1
1363 expect(andGroup.delOperand(doc1).update().operation()).toEqual("or");
1364 // Structur is now:
1365 // or(doc, doc, doc)
1366
1367 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001368 'author = "Max Birkendale" | title = "Der Birnbaum" | pubDate in 2014-12-05'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001369 );
1370 });
1371
1372 it('should be reducible to unspecification', function () {
1373 var vc = demoFactory.create();
1374
1375 expect(vc.toQuery()).toEqual(vc.root().toQuery());
1376 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001377 '(Titel = "Baum" & Veröffentlichungsort = "hihi" & ' +
1378 '(Titel = "Baum" | Veröffentlichungsort = "hihi")) ' +
1379 '| Untertitel ~ "huhu"');
Akrond141a362018-07-10 18:12:13 +02001380 expect(vc.root().element().lastChild.children[0].innerText).toEqual('and');
1381 expect(vc.root().element().lastChild.children[1].innerText).toEqual('×');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001382 expect(vc.root().delOperand(vc.root().getOperand(0)).update()).not.toBeUndefined();
Akron712733a2018-04-05 18:17:47 +02001383 expect(vc.toQuery()).toEqual('Untertitel ~ "huhu"');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001384
1385 var lc = vc.root().element().lastChild;
Akrond141a362018-07-10 18:12:13 +02001386 expect(lc.children[0].innerText).toEqual('and');
1387 expect(lc.children[1].innerText).toEqual('or');
1388 expect(lc.children[2].innerText).toEqual('×');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001389
1390 // Clean everything
1391 vc.clean();
1392 expect(vc.toQuery()).toEqual('');
1393 });
1394
1395 it('should flatten on import', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00001396 var vc = vcClass.create().fromJson({
Akron712733a2018-04-05 18:17:47 +02001397 "@type":"koral:docGroup",
1398 "operation":"operation:or",
1399 "operands":[
1400 {
1401 "@type":"koral:docGroup",
1402 "operation":"operation:or",
1403 "operands":[
Nils Diewald7c8ced22015-04-15 19:21:00 +00001404 {
Akron712733a2018-04-05 18:17:47 +02001405 "@type":"koral:doc",
1406 "key":"Titel",
1407 "value":"Baum",
1408 "match":"match:eq"
Nils Diewald7c8ced22015-04-15 19:21:00 +00001409 },
1410 {
Akron712733a2018-04-05 18:17:47 +02001411 "@type":"koral:doc",
1412 "key":"Veröffentlichungsort",
1413 "value":"hihi",
1414 "match":"match:eq"
Nils Diewald7c8ced22015-04-15 19:21:00 +00001415 },
1416 {
Akron712733a2018-04-05 18:17:47 +02001417 "@type":"koral:docGroup",
1418 "operation":"operation:or",
1419 "operands":[
1420 {
1421 "@type":"koral:doc",
1422 "key":"Titel",
1423 "value":"Baum",
1424 "match":"match:eq"
1425 },
1426 {
1427 "@type":"koral:doc",
1428 "key":"Veröffentlichungsort",
1429 "value":"hihi",
1430 "match":"match:eq"
1431 }
1432 ]
Nils Diewald7c8ced22015-04-15 19:21:00 +00001433 }
Akron712733a2018-04-05 18:17:47 +02001434 ]
1435 },
1436 {
1437 "@type":"koral:doc",
1438 "key":"Untertitel",
1439 "value":"huhu",
1440 "match":"match:contains"
1441 }
1442 ]
Nils Diewald7c8ced22015-04-15 19:21:00 +00001443 });
Nils Diewaldfda29d92015-01-22 17:28:01 +00001444
Nils Diewald7c8ced22015-04-15 19:21:00 +00001445 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001446 'Titel = "Baum" | Veröffentlichungsort = "hihi" | Untertitel ~ "huhu"'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001447 );
Nils Diewald86dad5b2015-01-28 15:09:07 +00001448 });
Akron1bdf5272018-07-24 18:51:30 +02001449
1450 it('should be deserializable from collection 1', function () {
1451 var kq = {
1452 "matches":["..."],
1453 "collection":{
1454 "@type": "koral:docGroup",
1455 "operation": "operation:or",
1456 "operands": [{
1457 "@type": "koral:docGroup",
1458 "operation": "operation:and",
1459 "operands": [
1460 {
1461 "@type": "koral:doc",
1462 "key": "title",
1463 "match": "match:eq",
1464 "value": "Der Birnbaum",
1465 "type": "type:string"
1466 },
1467 {
1468 "@type": "koral:doc",
1469 "key": "pubPlace",
1470 "match": "match:eq",
1471 "value": "Mannheim",
1472 "type": "type:string"
1473 },
1474 {
1475 "@type": "koral:docGroup",
1476 "operation": "operation:or",
1477 "operands": [
1478 {
1479 "@type": "koral:doc",
1480 "key": "subTitle",
1481 "match": "match:eq",
1482 "value": "Aufzucht und Pflege",
1483 "type": "type:string"
1484 },
1485 {
1486 "@type": "koral:doc",
1487 "key": "subTitle",
1488 "match": "match:eq",
1489 "value": "Gedichte",
1490 "type": "type:string"
1491 }
1492 ]
1493 }
1494 ]
1495 },{
1496 "@type": "koral:doc",
1497 "key": "pubDate",
1498 "match": "match:geq",
1499 "value": "2015-03-05",
1500 "type": "type:date",
1501 "rewrites" : [{
1502 "@type" : "koral:rewrite",
1503 "operation" : "operation:modification",
1504 "src" : "querySerializer",
1505 "scope" : "tree"
1506 }]
1507 }]
1508 }
1509 };
1510
1511 var vc = vcClass.create().fromJson(kq["collection"]);
1512 expect(vc.toQuery()).toEqual('(title = "Der Birnbaum" & pubPlace = "Mannheim" & (subTitle = "Aufzucht und Pflege" | subTitle = "Gedichte")) | pubDate since 2015-03-05');
1513 });
1514
1515 it('should be deserializable from collection 2', function () {
1516 var kq = {
1517 "@context": "http://korap.ids-mannheim.de/ns/KoralQuery/v0.3/context.jsonld",
1518 "meta": {},
1519 "query": {
1520 "@type": "koral:token",
1521 "wrap": {
1522 "@type": "koral:term",
1523 "match": "match:eq",
1524 "layer": "orth",
1525 "key": "Baum",
1526 "foundry": "opennlp",
1527 "rewrites": [
1528 {
1529 "@type": "koral:rewrite",
1530 "src": "Kustvakt",
1531 "operation": "operation:injection",
1532 "scope": "foundry"
1533 }
1534 ]
1535 },
1536 "idn": "Baum_2227",
1537 "rewrites": [
1538 {
1539 "@type": "koral:rewrite",
1540 "src": "Kustvakt",
1541 "operation": "operation:injection",
1542 "scope": "idn"
1543 }
1544 ]
1545 },
1546 "collection": {
1547 "@type": "koral:docGroup",
1548 "operation": "operation:and",
1549 "operands": [
1550 {
1551 "@type": "koral:doc",
1552 "match": "match:eq",
1553 "type": "type:regex",
1554 "value": "CC-BY.*",
1555 "key": "availability"
1556 },
1557 {
1558 "@type": "koral:doc",
1559 "match": "match:eq",
1560 "type":"type:text",
1561 "value": "Goethe",
1562 "key": "author"
1563 }
1564 ],
1565 "rewrites": [
1566 {
1567 "@type": "koral:rewrite",
1568 "src": "Kustvakt",
1569 "operation": "operation:insertion",
1570 "scope": "availability(FREE)"
1571 }
1572 ]
1573 },
1574 "matches": []
1575 };
1576
1577 var vc = vcClass.create().fromJson(kq["collection"]);
1578 expect(vc.toQuery()).toEqual('availability = /CC-BY.*/ & author = "Goethe"');
1579 });
Nils Diewald86dad5b2015-01-28 15:09:07 +00001580
Akron8a670162018-08-28 10:09:13 +02001581 it('shouldn\'t be deserializable from collection with unknown type', function () {
1582 var kq = {
1583 "@type" : "koral:doc",
1584 "match": "match:eq",
1585 "type":"type:failure",
1586 "value": "Goethe",
1587 "key": "author"
1588 };
Akron1bdf5272018-07-24 18:51:30 +02001589
Akron8a670162018-08-28 10:09:13 +02001590 expect(function () {
1591 vcClass.create().fromJson(kq)
1592 }).toThrow(new Error("Unknown value type: string"));
1593 });
1594
1595 it('should return a name', function () {
1596 var vc = vcClass.create();
1597 expect(vc.getName()).toEqual(KorAP.Locale.VC_allCorpora);
1598
1599 vc = vcClass.create().fromJson({"@type" : "koral:docGroupRef", "ref" : "DeReKo"});
1600 expect(vc.getName()).toEqual("DeReKo");
1601
1602 vc = vcClass.create().fromJson({"@type" : "koral:doc", "key" : "author", "value" : "Peter"});
1603 expect(vc.getName()).toEqual(KorAP.Locale.VC_oneCollection);
1604 });
Akrond2474aa2018-08-28 12:06:27 +02001605
1606 it('should check for rewrites', function () {
1607
1608 var vc = vcClass.create().fromJson({
1609 "@type" : "koral:doc",
1610 "key" : "author",
1611 "value" : "Goethe",
1612 "rewrites" : [{
1613 "@type" : "koral:rewrite",
1614 "operation" : "operation:modification",
1615 "src" : "querySerializer",
1616 "scope" : "value"
1617 }]
1618 });
1619 expect(vc.wasRewritten()).toBeTruthy();
1620
1621 var nested = {
1622 "@type" : "koral:docGroup",
1623 "operation" : "operation:or",
1624 "operands" : [
1625 {
1626 "@type" : "koral:doc",
1627 "key" : "author",
1628 "value" : "Goethe"
1629 },
1630 {
1631 "@type" : "koral:docGroup",
1632 "operation" : "operation:and",
1633 "operands" : [
1634 {
1635 "@type": "koral:doc",
1636 "key" : "author",
1637 "value" : "Schiller"
1638 },
1639 {
1640 "@type": "koral:doc",
1641 "key" : "author",
1642 "value" : "Fontane"
1643 }
1644 ]
1645 }
1646 ]
1647 };
1648 vc = vcClass.create().fromJson(nested);
1649 expect(vc.wasRewritten()).toBe(false);
1650
1651 nested["operands"][1]["operands"][1]["rewrites"] = [{
1652 "@type" : "koral:rewrite",
1653 "operation" : "operation:modification",
1654 "src" : "querySerializer",
1655 "scope" : "tree"
1656 }];
1657 vc = vcClass.create().fromJson(nested);
1658 expect(vc.wasRewritten()).toBeTruthy();
1659 });
Akron1bdf5272018-07-24 18:51:30 +02001660 });
1661
1662
Nils Diewald7c8ced22015-04-15 19:21:00 +00001663 describe('KorAP.Operators', function () {
1664 it('should be initializable', function () {
1665 var op = operatorsClass.create(true, false, false);
1666 expect(op.and()).toBeTruthy();
1667 expect(op.or()).not.toBeTruthy();
1668 expect(op.del()).not.toBeTruthy();
1669
1670 op.and(false);
1671 expect(op.and()).not.toBeTruthy();
1672 expect(op.or()).not.toBeTruthy();
1673 expect(op.del()).not.toBeTruthy();
1674
1675 op.or(true);
1676 op.del(true);
1677 expect(op.and()).not.toBeTruthy();
1678 expect(op.or()).toBeTruthy();
1679 expect(op.del()).toBeTruthy();
1680
Akrond141a362018-07-10 18:12:13 +02001681 var e = op.update();
Akron0b489ad2018-02-02 16:49:32 +01001682 expect(e.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001683 expect(e.children[0].getAttribute('class')).toEqual('or');
Akrond141a362018-07-10 18:12:13 +02001684 expect(e.children[0].innerText).toEqual('or');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001685 expect(e.children[1].getAttribute('class')).toEqual('delete');
Akrond141a362018-07-10 18:12:13 +02001686 expect(e.children[1].innerText).toEqual('×');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001687
1688 op.and(true);
1689 op.del(false);
Akrond141a362018-07-10 18:12:13 +02001690 e = op.update();
Nils Diewald7c8ced22015-04-15 19:21:00 +00001691
Akron0b489ad2018-02-02 16:49:32 +01001692 expect(e.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001693 expect(e.children[0].getAttribute('class')).toEqual('and');
Akrond141a362018-07-10 18:12:13 +02001694 expect(e.children[0].innerText).toEqual('and');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001695 expect(e.children[1].getAttribute('class')).toEqual('or');
Akrond141a362018-07-10 18:12:13 +02001696 expect(e.children[1].innerText).toEqual('or');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001697 });
1698 });
1699
1700 describe('KorAP._delete (event)', function () {
1701 var complexVCFactory = buildFactory(vcClass,{
1702 "@type": 'koral:docGroup',
1703 'operation' : 'operation:and',
1704 'operands' : [
Akron712733a2018-04-05 18:17:47 +02001705 {
1706 "@type": 'koral:doc',
1707 "key": 'pubDate',
1708 "match": 'match:eq',
1709 "value": '2014-12-05',
1710 "type": 'type:date'
1711 },
1712 {
1713 "@type" : 'koral:docGroup',
1714 'operation' : 'operation:or',
1715 'operands' : [
1716 {
1717 '@type' : 'koral:doc',
1718 'key' : 'title',
1719 'value' : 'Hello World!'
1720 },
1721 {
1722 '@type' : 'koral:doc',
1723 'key' : 'foo',
1724 'value' : 'bar'
1725 }
1726 ]
1727 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00001728 ]
1729 });
1730
1731 it('should clean on root docs', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00001732 var vc = vcClass.create().fromJson({
Akron712733a2018-04-05 18:17:47 +02001733 "@type": 'koral:doc',
1734 "key": 'pubDate',
1735 "match": 'match:eq',
1736 "value": '2014-12-05',
1737 "type": 'type:date'
Nils Diewald86dad5b2015-01-28 15:09:07 +00001738 });
Nils Diewald7c8ced22015-04-15 19:21:00 +00001739 expect(vc.root().toQuery()).toEqual('pubDate in 2014-12-05');
Akron0b489ad2018-02-02 16:49:32 +01001740 expect(vc.root().element().lastChild.getAttribute('class')).toEqual('operators button-group');
Nils Diewald86dad5b2015-01-28 15:09:07 +00001741
Nils Diewald7c8ced22015-04-15 19:21:00 +00001742 // Clean with delete from root
1743 expect(vc.root().element().lastChild.lastChild.getAttribute('class')).toEqual('delete');
1744 _delOn(vc.root());
1745 expect(vc.root().toQuery()).toEqual('');
Akronebc96662018-08-29 17:36:20 +02001746 expect(vc.root().element().lastChild.lastChild.data).toEqual(KorAP.Locale.EMPTY);
1747 expect(vc.root().element().classList.contains('unspecified')).toEqual(true);
Nils Diewald7c8ced22015-04-15 19:21:00 +00001748 });
Nils Diewald86dad5b2015-01-28 15:09:07 +00001749
Nils Diewald7c8ced22015-04-15 19:21:00 +00001750 it('should remove on nested docs', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00001751 var vc = vcClass.create().fromJson(
Akron712733a2018-04-05 18:17:47 +02001752 {
1753 "@type": 'koral:docGroup',
1754 'operation' : 'operation:and',
1755 'operands' : [
1756 {
1757 "@type": 'koral:doc',
1758 "key": 'pubDate',
1759 "match": 'match:eq',
1760 "value": '2014-12-05',
1761 "type": 'type:date'
1762 },
1763 {
1764 "@type" : 'koral:doc',
1765 'key' : 'foo',
1766 'value' : 'bar'
1767 }
1768 ]
1769 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00001770 );
1771
1772 // Delete with direct element access
1773 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar"');
1774 _delOn(vc.root().getOperand(0));
1775
1776 expect(vc.toQuery()).toEqual('foo = "bar"');
1777 expect(vc.root().ldType()).toEqual('doc');
1778 });
1779
1780 it('should clean on doc groups', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00001781 var vc = vcClass.create().fromJson(
Akron712733a2018-04-05 18:17:47 +02001782 {
1783 "@type": 'koral:docGroup',
1784 'operation' : 'operation:and',
1785 'operands' : [
1786 {
1787 "@type": 'koral:doc',
1788 "key": 'pubDate',
1789 "match": 'match:eq',
1790 "value": '2014-12-05',
1791 "type": 'type:date'
1792 },
1793 {
1794 "@type" : 'koral:doc',
1795 'key' : 'foo',
1796 'value' : 'bar'
1797 }
1798 ]
1799 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00001800 );
1801
1802 // Cleanwith direct element access
1803 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar"');
1804 _delOn(vc.root());
1805 expect(vc.toQuery()).toEqual('');
1806 expect(vc.root().ldType()).toEqual('non');
1807 });
1808
1809 it('should remove on nested doc groups (case of ungrouping 1)', function () {
1810 var vc = complexVCFactory.create();
1811
1812 // Delete with direct element access
1813 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001814 'pubDate in 2014-12-05 & (title = "Hello World!" | foo = "bar")'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001815 );
1816
1817 // Remove hello world:
1818 _delOn(vc.root().getOperand(1).getOperand(0));
1819 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar"');
1820 expect(vc.root().ldType()).toEqual('docGroup');
1821 });
1822
1823 it('should remove on nested doc groups (case of ungrouping 2)', function () {
1824 var vc = complexVCFactory.create();
1825
1826 // Delete with direct element access
1827 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001828 'pubDate in 2014-12-05 & (title = "Hello World!" | foo = "bar")'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001829 );
1830
1831 // Remove bar
1832 _delOn(vc.root().getOperand(1).getOperand(1));
1833 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & title = "Hello World!"');
1834 expect(vc.root().ldType()).toEqual('docGroup');
1835 expect(vc.root().operation()).toEqual('and');
1836 });
1837
1838 it('should remove on nested doc groups (case of root changing)', function () {
1839 var vc = complexVCFactory.create();
1840
1841 // Delete with direct element access
1842 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001843 'pubDate in 2014-12-05 & ' +
1844 '(title = "Hello World!" | foo = "bar")'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001845 );
1846
1847 // Remove bar
1848 _delOn(vc.root().getOperand(0));
1849 expect(vc.toQuery()).toEqual('title = "Hello World!" | foo = "bar"');
1850 expect(vc.root().ldType()).toEqual('docGroup');
1851 expect(vc.root().operation()).toEqual('or');
1852 });
1853
1854 it('should remove on nested doc groups (list flattening)', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00001855 var vc = vcClass.create().fromJson(
Akron712733a2018-04-05 18:17:47 +02001856 {
1857 "@type": 'koral:docGroup',
1858 'operation' : 'operation:or',
1859 'operands' : [
1860 {
1861 "@type": 'koral:doc',
1862 "key": 'pubDate',
1863 "match": 'match:eq',
1864 "value": '2014-12-05',
1865 "type": 'type:date'
1866 },
1867 {
1868 "@type" : 'koral:doc',
1869 'key' : 'foo',
1870 'value' : 'bar'
1871 },
1872 {
1873 "@type": 'koral:docGroup',
1874 'operation' : 'operation:and',
1875 'operands' : [
1876 {
1877 "@type": 'koral:doc',
1878 "key": 'pubDate',
1879 "match": 'match:eq',
1880 "value": '2014-12-05',
1881 "type": 'type:date'
1882 },
1883 {
1884 "@type" : 'koral:docGroup',
1885 'operation' : 'operation:or',
1886 'operands' : [
1887 {
1888 '@type' : 'koral:doc',
1889 'key' : 'title',
1890 'value' : 'Hello World!'
1891 },
1892 {
1893 '@type' : 'koral:doc',
1894 'key' : 'yeah',
1895 'value' : 'juhu'
1896 }
1897 ]
1898 }
1899 ]
1900 }
1901 ]
1902 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00001903 );
1904
1905 // Delete with direct element access
1906 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001907 'pubDate in 2014-12-05 | foo = "bar" | ' +
1908 '(pubDate in 2014-12-05 & ' +
1909 '(title = "Hello World!" | yeah = "juhu"))'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001910 );
1911
1912 expect(vc.root().ldType()).toEqual('docGroup');
1913 expect(vc.root().operation()).toEqual('or');
1914
1915 // Operands and operators
Akronadab5e52018-08-20 13:50:53 +02001916 expect(vc.builder().firstChild.children.length).toEqual(4);
1917 expect(vc.builder().firstChild.lastChild.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001918
1919 // Remove inner group and flatten
1920 _delOn(vc.root().getOperand(2).getOperand(0));
1921
1922 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001923 'pubDate in 2014-12-05 | foo = "bar" | title = "Hello World!" | yeah = "juhu"'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001924 );
1925 expect(vc.root().ldType()).toEqual('docGroup');
1926 expect(vc.root().operation()).toEqual('or');
1927
1928 // Operands and operators
Akronadab5e52018-08-20 13:50:53 +02001929 expect(vc.builder().firstChild.children.length).toEqual(5);
1930 expect(vc.builder().firstChild.lastChild.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001931 });
1932 });
1933
1934 describe('KorAP._add (event)', function () {
1935 var complexVCFactory = buildFactory(vcClass,{
1936 "@type": 'koral:docGroup',
1937 'operation' : 'operation:and',
1938 'operands' : [
Akron712733a2018-04-05 18:17:47 +02001939 {
1940 "@type": 'koral:doc',
1941 "key": 'pubDate',
1942 "match": 'match:eq',
1943 "value": '2014-12-05',
1944 "type": 'type:date'
1945 },
1946 {
1947 "@type" : 'koral:docGroup',
1948 'operation' : 'operation:or',
1949 'operands' : [
1950 {
1951 '@type' : 'koral:doc',
1952 'key' : 'title',
1953 'value' : 'Hello World!'
1954 },
1955 {
1956 '@type' : 'koral:doc',
1957 'key' : 'foo',
1958 'value' : 'bar'
1959 }
1960 ]
1961 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00001962 ]
1963 });
1964
1965 it('should add new unspecified doc with "and"', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00001966 var vc = vcClass.create().fromJson(
Akron712733a2018-04-05 18:17:47 +02001967 {
1968 "@type": 'koral:docGroup',
1969 'operation' : 'operation:and',
1970 'operands' : [
1971 {
1972 "@type": 'koral:doc',
1973 "key": 'pubDate',
1974 "match": 'match:eq',
1975 "value": '2014-12-05',
1976 "type": 'type:date'
1977 },
1978 {
1979 "@type" : 'koral:doc',
1980 'key' : 'foo',
1981 'value' : 'bar'
Akronb19803c2018-08-16 16:39:42 +02001982 },
1983 {
1984 "@type" : "koral:docGroupRef",
1985 "ref" : "myCorpus"
Akron712733a2018-04-05 18:17:47 +02001986 }
1987 ]
1988 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00001989 );
1990
Akronb19803c2018-08-16 16:39:42 +02001991 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar" & referTo "myCorpus"');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001992
Akronadab5e52018-08-20 13:50:53 +02001993 var fc = vc.builder().firstChild;
Nils Diewald7c8ced22015-04-15 19:21:00 +00001994 expect(fc.getAttribute('data-operation')).toEqual('and');
Akronb19803c2018-08-16 16:39:42 +02001995 expect(fc.children.length).toEqual(4);
Akron0b489ad2018-02-02 16:49:32 +01001996 expect(fc.lastChild.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001997 expect(fc.children[0].getAttribute('class')).toEqual('doc');
1998 expect(fc.children[1].getAttribute('class')).toEqual('doc');
Akronb19803c2018-08-16 16:39:42 +02001999 expect(fc.children[2].getAttribute('class')).toEqual('doc groupref');
Nils Diewald7c8ced22015-04-15 19:21:00 +00002000
2001 // add with 'and' in the middle
2002 _andOn(vc.root().getOperand(0));
Akronb19803c2018-08-16 16:39:42 +02002003 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar" & referTo "myCorpus"');
Nils Diewald7c8ced22015-04-15 19:21:00 +00002004
Akronadab5e52018-08-20 13:50:53 +02002005 fc = vc.builder().firstChild;
Nils Diewald7c8ced22015-04-15 19:21:00 +00002006 expect(fc.getAttribute('data-operation')).toEqual('and');
Akronb19803c2018-08-16 16:39:42 +02002007 expect(fc.children.length).toEqual(5);
Akron0b489ad2018-02-02 16:49:32 +01002008 expect(fc.lastChild.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +00002009
2010 expect(fc.children[0].getAttribute('class')).toEqual('doc');
2011 expect(fc.children[1].getAttribute('class')).toEqual('doc unspecified');
2012 expect(fc.children[2].getAttribute('class')).toEqual('doc');
Akronb19803c2018-08-16 16:39:42 +02002013 expect(fc.children[3].getAttribute('class')).toEqual('doc groupref');
2014 expect(fc.children[4].classList.contains('button-group')).toBeTruthy();
2015 expect(fc.children.length).toEqual(5);
2016
2017 _andOn(vc.root().getOperand(3));
2018 expect(fc.children[0].getAttribute('class')).toEqual('doc');
2019 expect(fc.children[1].getAttribute('class')).toEqual('doc unspecified');
2020 expect(fc.children[2].getAttribute('class')).toEqual('doc');
2021 expect(fc.children[3].getAttribute('class')).toEqual('doc groupref');
2022 expect(fc.children[4].getAttribute('class')).toEqual('doc unspecified');
2023 expect(fc.children[5].classList.contains('button-group')).toBeTruthy();
2024 expect(fc.children.length).toEqual(6);
2025
Nils Diewald7c8ced22015-04-15 19:21:00 +00002026 });
2027
Akronb19803c2018-08-16 16:39:42 +02002028
Nils Diewald7c8ced22015-04-15 19:21:00 +00002029 it('should add new unspecified doc with "or"', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00002030 var vc = vcClass.create().fromJson(
Akron712733a2018-04-05 18:17:47 +02002031 {
2032 "@type": 'koral:docGroup',
2033 'operation' : 'operation:and',
2034 'operands' : [
2035 {
2036 "@type": 'koral:doc',
2037 "key": 'pubDate',
2038 "match": 'match:eq',
2039 "value": '2014-12-05',
2040 "type": 'type:date'
2041 },
2042 {
2043 "@type" : 'koral:doc',
2044 'key' : 'foo',
2045 'value' : 'bar'
Akronb19803c2018-08-16 16:39:42 +02002046 },
2047 {
2048 "@type" : "koral:docGroupRef",
2049 "ref" : "myCorpus"
Akron712733a2018-04-05 18:17:47 +02002050 }
2051 ]
2052 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00002053 );
2054
Akronb19803c2018-08-16 16:39:42 +02002055 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar" & referTo "myCorpus"');
Nils Diewald7c8ced22015-04-15 19:21:00 +00002056
Akronadab5e52018-08-20 13:50:53 +02002057 var fc = vc.builder().firstChild;
Akronb19803c2018-08-16 16:39:42 +02002058 expect(fc.children.length).toEqual(4);
Akron0b489ad2018-02-02 16:49:32 +01002059 expect(fc.lastChild.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +00002060 expect(fc.children[0].getAttribute('class')).toEqual('doc');
2061 expect(fc.children[1].getAttribute('class')).toEqual('doc');
Akronb19803c2018-08-16 16:39:42 +02002062 expect(fc.children[2].getAttribute('class')).toEqual('doc groupref');
Nils Diewald7c8ced22015-04-15 19:21:00 +00002063
2064 // add with 'or' in the middle
2065 _orOn(vc.root().getOperand(0));
Akronb19803c2018-08-16 16:39:42 +02002066 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar" & referTo "myCorpus"');
Akronadab5e52018-08-20 13:50:53 +02002067 fc = vc.builder().firstChild;
Nils Diewald7c8ced22015-04-15 19:21:00 +00002068
2069 expect(fc.getAttribute('data-operation')).toEqual('and');
Akronb19803c2018-08-16 16:39:42 +02002070 expect(fc.children.length).toEqual(4);
Nils Diewald7c8ced22015-04-15 19:21:00 +00002071 expect(fc.children[0].getAttribute('class')).toEqual('docGroup');
2072 expect(fc.children[0].getAttribute('data-operation')).toEqual('or');
2073 expect(fc.children[1].getAttribute('class')).toEqual('doc');
Akronb19803c2018-08-16 16:39:42 +02002074 expect(fc.children[2].getAttribute('class')).toEqual('doc groupref');
2075 expect(fc.children[3].getAttribute('class')).toEqual('operators button-group');
Akron0b489ad2018-02-02 16:49:32 +01002076 expect(fc.lastChild.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +00002077
Akronadab5e52018-08-20 13:50:53 +02002078 fc = vc.builder().firstChild.firstChild;
Nils Diewald7c8ced22015-04-15 19:21:00 +00002079 expect(fc.children.length).toEqual(3);
2080 expect(fc.children[0].getAttribute('class')).toEqual('doc');
2081 expect(fc.children[1].getAttribute('class')).toEqual('doc unspecified');
Akron0b489ad2018-02-02 16:49:32 +01002082 expect(fc.children[2].getAttribute('class')).toEqual('operators button-group');
2083 expect(fc.lastChild.getAttribute('class')).toEqual('operators button-group');
Akronb19803c2018-08-16 16:39:42 +02002084
2085 _orOn(vc.root().getOperand(2));
Akronadab5e52018-08-20 13:50:53 +02002086 fc = vc.builder().firstChild;
Akronb19803c2018-08-16 16:39:42 +02002087 expect(fc.children.length).toEqual(4);
2088
2089 expect(fc.children[0].getAttribute('class')).toEqual('docGroup');
2090 expect(fc.children[1].getAttribute('class')).toEqual('doc');
2091 expect(fc.children[2].getAttribute('class')).toEqual('docGroup');
2092 expect(fc.children[3].getAttribute('class')).toEqual('operators button-group');
2093
Akronadab5e52018-08-20 13:50:53 +02002094 fc = vc.builder().firstChild.children[2];
Akronb19803c2018-08-16 16:39:42 +02002095 expect(fc.children[0].getAttribute('class')).toEqual('doc groupref');
2096 expect(fc.children[1].getAttribute('class')).toEqual('doc unspecified');
2097 expect(fc.children[2].getAttribute('class')).toEqual('operators button-group');
2098 expect(fc.lastChild.getAttribute('class')).toEqual('operators button-group');
2099
Nils Diewald7c8ced22015-04-15 19:21:00 +00002100 });
2101
2102 it('should add new unspecified doc with "and" before group', function () {
2103 var vc = demoFactory.create();
2104
2105 // Wrap with direct element access
2106 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02002107 '(Titel = "Baum" & ' +
2108 'Veröffentlichungsort = "hihi" & ' +
2109 '(Titel = "Baum" | ' +
2110 'Veröffentlichungsort = "hihi")) | ' +
2111 'Untertitel ~ "huhu"'
Nils Diewald7c8ced22015-04-15 19:21:00 +00002112 );
2113
2114 expect(vc.root().getOperand(0).ldType()).toEqual('docGroup');
2115 expect(vc.root().getOperand(0).operation()).toEqual('and');
2116 expect(vc.root().getOperand(0).operands().length).toEqual(3);
2117
2118 // Add unspecified on the second doc
2119 var secDoc = vc.root().getOperand(0).getOperand(1);
2120 expect(secDoc.value()).toEqual('hihi');
2121
2122 // Add
2123 _andOn(secDoc);
2124
2125 var fo = vc.root().getOperand(0);
2126
2127 expect(fo.ldType()).toEqual('docGroup');
2128 expect(fo.operation()).toEqual('and');
2129 expect(fo.operands().length).toEqual(4);
2130
2131 expect(fo.getOperand(0).ldType()).toEqual('doc');
2132 expect(fo.getOperand(1).ldType()).toEqual('doc');
2133 expect(fo.getOperand(2).ldType()).toEqual('non');
2134 expect(fo.getOperand(3).ldType()).toEqual('docGroup');
2135 });
2136
2137
2138 it('should remove a doc with an unspecified doc in a nested group', function () {
2139 var vc = demoFactory.create();
2140
2141 // Wrap with direct element access
2142 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02002143 '(Titel = "Baum" & Veröffentlichungsort = "hihi" & (Titel = "Baum" | Veröffentlichungsort = "hihi")) | Untertitel ~ "huhu"'
Nils Diewald7c8ced22015-04-15 19:21:00 +00002144 );
2145
2146 var fo = vc.root().getOperand(0).getOperand(0);
2147 expect(fo.key()).toEqual('Titel');
2148 expect(fo.value()).toEqual('Baum');
2149
2150 // Add unspecified on the root group
2151 _orOn(fo);
2152
2153 fo = vc.root().getOperand(0).getOperand(0);
2154
2155 expect(fo.operation()).toEqual('or');
2156 expect(fo.getOperand(0).ldType()).toEqual('doc');
2157 expect(fo.getOperand(1).ldType()).toEqual('non');
2158
2159 // Delete document
2160 _delOn(fo.getOperand(0));
2161
2162 // The operand is now non
2163 expect(vc.root().getOperand(0).getOperand(0).ldType()).toEqual('non');
2164 expect(vc.root().getOperand(0).getOperand(1).ldType()).toEqual('doc');
2165 expect(vc.root().getOperand(0).getOperand(2).ldType()).toEqual('docGroup');
2166 });
2167
2168
Akron712733a2018-04-05 18:17:47 +02002169 it('should remove an unspecified doc with a doc in a nested group', function () {
Nils Diewald7c8ced22015-04-15 19:21:00 +00002170 var vc = demoFactory.create();
2171
2172 // Wrap with direct element access
2173 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02002174 '(Titel = "Baum" & ' +
2175 'Veröffentlichungsort = "hihi" & ' +
2176 '(Titel = "Baum" ' +
2177 '| Veröffentlichungsort = "hihi")) | ' +
2178 'Untertitel ~ "huhu"'
Nils Diewald7c8ced22015-04-15 19:21:00 +00002179 );
2180
2181 var fo = vc.root().getOperand(0).getOperand(0);
2182 expect(fo.key()).toEqual('Titel');
2183 expect(fo.value()).toEqual('Baum');
2184
2185 // Add unspecified on the root group
2186 _orOn(fo);
2187
2188 fo = vc.root().getOperand(0).getOperand(0);
2189
2190 expect(fo.operation()).toEqual('or');
2191 expect(fo.getOperand(0).ldType()).toEqual('doc');
2192 expect(fo.getOperand(1).ldType()).toEqual('non');
2193
2194 // Delete unspecified doc
2195 _delOn(fo.getOperand(1));
2196
2197 // The operand is now non
2198 fo = vc.root().getOperand(0);
2199 expect(fo.getOperand(0).ldType()).toEqual('doc');
2200 expect(fo.getOperand(0).key()).toEqual('Titel');
2201 expect(fo.getOperand(0).value()).toEqual('Baum');
2202 expect(fo.getOperand(1).ldType()).toEqual('doc');
2203 expect(fo.getOperand(2).ldType()).toEqual('docGroup');
2204 });
2205
2206
2207 it('should add on parent group (case "and")', function () {
2208 var vc = complexVCFactory.create();
2209
2210 // Wrap with direct element access
2211 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02002212 'pubDate in 2014-12-05 & (title = "Hello World!" | foo = "bar")'
Nils Diewald7c8ced22015-04-15 19:21:00 +00002213 );
2214
2215 expect(vc.root().operands().length).toEqual(2);
2216
2217 // Add unspecified on the root group
2218 _andOn(vc.root().getOperand(1));
2219 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02002220 'pubDate in 2014-12-05 & (title = "Hello World!" | foo = "bar")'
Nils Diewald7c8ced22015-04-15 19:21:00 +00002221 );
2222
2223 expect(vc.root().ldType()).toEqual('docGroup');
2224 expect(vc.root().operands().length).toEqual(3);
2225 expect(vc.root().getOperand(0).ldType()).toEqual('doc');
2226 expect(vc.root().getOperand(1).ldType()).toEqual('docGroup');
2227 expect(vc.root().getOperand(1).operation()).toEqual('or');
2228 expect(vc.root().getOperand(2).ldType()).toEqual('non');
2229
2230 // Add another unspecified on the root group
2231 _andOn(vc.root().getOperand(1));
2232
2233 expect(vc.root().operands().length).toEqual(4);
2234 expect(vc.root().getOperand(0).ldType()).toEqual('doc');
2235 expect(vc.root().getOperand(1).ldType()).toEqual('docGroup');
2236 expect(vc.root().getOperand(2).ldType()).toEqual('non');
2237 expect(vc.root().getOperand(3).ldType()).toEqual('non');
2238
2239 // Add another unspecified after the first doc
2240 _andOn(vc.root().getOperand(0));
2241
2242 expect(vc.root().operands().length).toEqual(5);
2243 expect(vc.root().getOperand(0).ldType()).toEqual('doc');
2244 expect(vc.root().getOperand(1).ldType()).toEqual('non');
2245 expect(vc.root().getOperand(2).ldType()).toEqual('docGroup');
2246 expect(vc.root().getOperand(3).ldType()).toEqual('non');
2247 expect(vc.root().getOperand(4).ldType()).toEqual('non');
2248 });
2249
2250 it('should wrap on root', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00002251 var vc = vcClass.create().fromJson(
Akron712733a2018-04-05 18:17:47 +02002252 {
2253 "@type": 'koral:docGroup',
2254 'operation' : 'operation:and',
2255 'operands' : [
2256 {
2257 "@type": 'koral:doc',
2258 "key": 'pubDate',
2259 "match": 'match:eq',
2260 "value": '2014-12-05',
2261 "type": 'type:date'
2262 },
2263 {
2264 "@type" : 'koral:doc',
2265 'key' : 'foo',
2266 'value' : 'bar'
2267 }
2268 ]
2269 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00002270 );
2271
2272 // Wrap on root
2273 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar"');
2274 expect(vc.root().ldType()).toEqual('docGroup');
2275 expect(vc.root().operation()).toEqual('and');
2276 _orOn(vc.root());
2277 expect(vc.root().ldType()).toEqual('docGroup');
2278 expect(vc.root().operation()).toEqual('or');
2279
2280 expect(vc.root().getOperand(0).ldType()).toEqual('docGroup');
2281 expect(vc.root().getOperand(0).operation()).toEqual('and');
2282 });
2283
2284 it('should add on root (case "and")', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00002285 var vc = vcClass.create().fromJson(
Akron712733a2018-04-05 18:17:47 +02002286 {
2287 "@type": 'koral:doc',
2288 "key": 'pubDate',
2289 "match": 'match:eq',
2290 "value": '2014-12-05',
2291 "type": 'type:date'
2292 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00002293 );
2294
2295 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05');
2296 expect(vc.root().ldType()).toEqual('doc');
2297 expect(vc.root().key()).toEqual('pubDate');
2298 expect(vc.root().value()).toEqual('2014-12-05');
2299
2300 // Wrap on root
2301 _andOn(vc.root());
2302 expect(vc.root().ldType()).toEqual('docGroup');
2303 expect(vc.root().operation()).toEqual('and');
2304 });
2305
2306 it('should add on root (case "or")', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00002307 var vc = vcClass.create().fromJson(
Akron712733a2018-04-05 18:17:47 +02002308 {
2309 "@type": 'koral:doc',
2310 "key": 'pubDate',
2311 "match": 'match:eq',
2312 "value": '2014-12-05',
2313 "type": 'type:date'
2314 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00002315 );
2316
2317 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05');
2318 expect(vc.root().key()).toEqual('pubDate');
2319 expect(vc.root().value()).toEqual('2014-12-05');
2320
2321 // Wrap on root
2322 _orOn(vc.root());
2323 expect(vc.root().ldType()).toEqual('docGroup');
2324 expect(vc.root().operation()).toEqual('or');
2325 });
2326
2327 it('should support multiple sub groups per group', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00002328 var vc = vcClass.create().fromJson(
Akron712733a2018-04-05 18:17:47 +02002329 {
2330 "@type": 'koral:docGroup',
2331 'operation' : 'operation:or',
2332 'operands' : [
2333 {
2334 "@type": 'koral:docGroup',
2335 'operation' : 'operation:and',
2336 'operands' : [
2337 {
2338 "@type": 'koral:doc',
2339 "key": 'title',
2340 "value": 't1',
2341 },
2342 {
2343 "@type" : 'koral:doc',
2344 'key' : 'title',
2345 'value' : 't2'
2346 }
2347 ]
2348 },
2349 {
2350 "@type": 'koral:docGroup',
2351 'operation' : 'operation:and',
2352 'operands' : [
2353 {
2354 "@type": 'koral:doc',
2355 "key": 'title',
2356 "value": 't3',
2357 },
2358 {
2359 "@type" : 'koral:doc',
2360 'key' : 'title',
2361 'value' : 't4'
2362 }
2363 ]
2364 }
2365 ]
2366 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00002367 );
2368 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02002369 '(title = "t1" & title = "t2") | ' +
2370 '(title = "t3" & title = "t4")'
Nils Diewald7c8ced22015-04-15 19:21:00 +00002371 );
2372 expect(vc.root().operation()).toEqual('or');
2373 expect(vc.root().getOperand(0).toQuery()).toEqual('title = "t1" & title = "t2"');
2374 expect(vc.root().getOperand(1).toQuery()).toEqual('title = "t3" & title = "t4"');
2375
2376 _andOn(vc.root());
2377
2378 expect(vc.root().operation()).toEqual('and');
2379 expect(vc.root().getOperand(0).ldType()).toEqual('docGroup');
2380 expect(vc.root().getOperand(1).ldType()).toEqual('non');
2381 });
2382 });
2383
Nils Diewald6283d692015-04-23 20:32:53 +00002384
2385 describe('KorAP.Rewrite', function () {
Nils Diewald7c8ced22015-04-15 19:21:00 +00002386 it('should be initializable', function () {
2387 var rewrite = rewriteClass.create({
Akron712733a2018-04-05 18:17:47 +02002388 "@type" : "koral:rewrite",
2389 "operation" : "operation:modification",
2390 "src" : "querySerializer",
2391 "scope" : "tree"
Nils Diewald86dad5b2015-01-28 15:09:07 +00002392 });
Nils Diewald7c8ced22015-04-15 19:21:00 +00002393 expect(rewrite.toString()).toEqual('Modification of "tree" by "querySerializer"');
2394 });
Nils Diewald86dad5b2015-01-28 15:09:07 +00002395
Nils Diewald7c8ced22015-04-15 19:21:00 +00002396 it('should be deserialized by docs', function () {
2397 var doc = docClass.create(
Akron712733a2018-04-05 18:17:47 +02002398 undefined,
2399 {
2400 "@type":"koral:doc",
2401 "key":"Titel",
2402 "value":"Baum",
2403 "match":"match:eq"
2404 });
Nils Diewald7c8ced22015-04-15 19:21:00 +00002405
2406 expect(doc.element().classList.contains('doc')).toBeTruthy();
2407 expect(doc.element().classList.contains('rewritten')).toBe(false);
2408
2409 doc = docClass.create(
Akron712733a2018-04-05 18:17:47 +02002410 undefined,
2411 {
2412 "@type":"koral:doc",
2413 "key":"Titel",
2414 "value":"Baum",
2415 "match":"match:eq",
2416 "rewrites" : [
2417 {
2418 "@type" : "koral:rewrite",
2419 "operation" : "operation:modification",
2420 "src" : "querySerializer",
2421 "scope" : "tree"
2422 }
2423 ]
2424 });
Nils Diewald7c8ced22015-04-15 19:21:00 +00002425
2426 expect(doc.element().classList.contains('doc')).toBeTruthy();
2427 expect(doc.element().classList.contains('rewritten')).toBeTruthy();
2428 });
Nils Diewald6283d692015-04-23 20:32:53 +00002429
Akron76c3dd62018-05-29 20:58:27 +02002430 it('should be described in a title attribute', function () {
2431
2432 doc = docClass.create(
2433 undefined,
2434 {
2435 "@type":"koral:doc",
2436 "key":"Titel",
2437 "value":"Baum",
2438 "match":"match:eq",
2439 "rewrites" : [
2440 {
2441 "@type" : "koral:rewrite",
2442 "operation" : "operation:modification",
2443 "src" : "querySerializer",
2444 "scope" : "tree"
2445 },
2446 {
2447 "@type" : "koral:rewrite",
2448 "operation" : "operation:injection",
2449 "src" : "me"
2450 }
2451 ]
2452 });
2453
2454 expect(doc.element().classList.contains('doc')).toBeTruthy();
2455 expect(doc.element().classList.contains('rewritten')).toBeTruthy();
2456 expect(doc.element().lastChild.getAttribute("title")).toEqual("querySerializer: tree (modification)\nme (injection)");
2457 });
2458
2459
Nils Diewald6283d692015-04-23 20:32:53 +00002460 xit('should be deserialized by docGroups', function () {
2461 var docGroup = docGroupClass.create(
Akron712733a2018-04-05 18:17:47 +02002462 undefined,
2463 {
2464 "@type" : "koral:docGroup",
2465 "operation" : "operation:or",
2466 "operands" : [
2467 {
2468 "@type" : "doc",
2469 "key" : "pubDate",
2470 "type" : "type:date",
2471 "value" : "2014-12-05"
2472 },
2473 {
2474 "@type" : "doc",
2475 "key" : "pubDate",
2476 "type" : "type:date",
2477 "value" : "2014-12-06"
2478 }
2479 ],
2480 "rewrites" : [
2481 {
2482 "@type" : "koral:rewrite",
2483 "operation" : "operation:modification",
2484 "src" : "querySerializer",
2485 "scope" : "tree"
2486 }
2487 ]
2488 }
Nils Diewald6283d692015-04-23 20:32:53 +00002489 );
2490
2491 expect(doc.element().classList.contains('docgroup')).toBeTruthy();
2492 expect(doc.element().classList.contains('rewritten')).toBe(false);
2493 });
Nils Diewald86dad5b2015-01-28 15:09:07 +00002494 });
Nils Diewaldf0c4f112015-05-05 12:56:59 +00002495
2496 describe('KorAP.stringValue', function () {
2497 it('should be initializable', function () {
2498 var sv = stringValClass.create();
2499 expect(sv.regex()).toBe(false);
2500 expect(sv.value()).toBe('');
Nils Diewaldc4c4b832015-05-05 16:00:08 +00002501
2502 sv = stringValClass.create('Baum');
2503 expect(sv.regex()).toBe(false);
2504 expect(sv.value()).toBe('Baum');
2505
2506 sv = stringValClass.create('Baum', false);
2507 expect(sv.regex()).toBe(false);
2508 expect(sv.value()).toBe('Baum');
2509
2510 sv = stringValClass.create('Baum', true);
2511 expect(sv.regex()).toBe(true);
2512 expect(sv.value()).toBe('Baum');
2513 });
2514
2515 it('should be modifiable', function () {
2516 var sv = stringValClass.create();
2517 expect(sv.regex()).toBe(false);
2518 expect(sv.value()).toBe('');
2519
2520 expect(sv.value('Baum')).toBe('Baum');
2521 expect(sv.value()).toBe('Baum');
2522
2523 expect(sv.regex(true)).toBe(true);
2524 expect(sv.regex()).toBe(true);
2525 });
2526
2527 it('should have a toggleble regex value', function () {
2528 var sv = stringValClass.create();
Nils Diewald7991a3f2015-05-19 14:12:37 +00002529
2530 expect(sv.element().firstChild.value).toBe('');
2531 sv.element().firstChild.value = 'der'
2532 expect(sv.element().firstChild.value).toBe('der');
2533
Nils Diewaldc4c4b832015-05-05 16:00:08 +00002534 expect(sv.regex()).toBe(false);
2535
2536 sv.toggleRegex();
Nils Diewald7991a3f2015-05-19 14:12:37 +00002537 expect(sv.element().firstChild.value).toBe('der');
Nils Diewaldc4c4b832015-05-05 16:00:08 +00002538 expect(sv.regex()).toBe(true);
Nils Diewald7991a3f2015-05-19 14:12:37 +00002539 sv.element().firstChild.value = 'derbe'
Nils Diewaldc4c4b832015-05-05 16:00:08 +00002540
2541 sv.toggleRegex();
2542 expect(sv.regex()).toBe(false);
Nils Diewald7991a3f2015-05-19 14:12:37 +00002543 expect(sv.element().firstChild.value).toBe('derbe');
Nils Diewaldc4c4b832015-05-05 16:00:08 +00002544 });
2545
2546 it('should have an element', function () {
2547 var sv = stringValClass.create('der');
2548 expect(sv.element().nodeName).toBe('DIV');
2549 expect(sv.element().firstChild.nodeName).toBe('INPUT');
2550 expect(sv.element().firstChild.value).toBe('der');
2551 });
2552
2553 it('should have a classed element', function () {
2554 var sv = stringValClass.create();
Nils Diewaldc4c4b832015-05-05 16:00:08 +00002555 expect(sv.element().classList.contains('regex')).toBe(false);
2556 expect(sv.regex()).toBe(false);
2557 sv.toggleRegex();
2558 expect(sv.element().classList.contains('regex')).toBe(true);
2559 });
2560
2561 it('should be storable', function () {
2562 var sv = stringValClass.create();
2563 var count = 1;
2564 sv.store = function (value, regex) {
Akron712733a2018-04-05 18:17:47 +02002565 expect(regex).toBe(true);
2566 expect(value).toBe('tree');
Nils Diewaldc4c4b832015-05-05 16:00:08 +00002567 };
2568 sv.regex(true);
2569 sv.value('tree');
2570 sv.element().lastChild.click();
Nils Diewaldf0c4f112015-05-05 12:56:59 +00002571 });
Akron712733a2018-04-05 18:17:47 +02002572
Akronb19803c2018-08-16 16:39:42 +02002573 it('should have a disableoption for regex', function () {
2574 var sv = stringValClass.create(undefined, undefined, true);
2575 var svE = sv.element();
2576 expect(svE.children.length).toEqual(2);
2577
2578 sv = stringValClass.create(undefined, undefined, false);
2579 svE = sv.element();
2580 expect(svE.children.length).toEqual(1);
2581 });
2582
Nils Diewaldf0c4f112015-05-05 12:56:59 +00002583 });
Akrone4961b12017-05-10 21:04:46 +02002584
Akron712733a2018-04-05 18:17:47 +02002585 describe('KorAP.VC.Menu', function () {
Akrone65a88a2018-04-05 19:14:20 +02002586
2587 var vc;
2588
Akron712733a2018-04-05 18:17:47 +02002589 it('should be initializable', function () {
2590
Akrone65a88a2018-04-05 19:14:20 +02002591 vc = vcClass.create([
Akron712733a2018-04-05 18:17:47 +02002592 ['a', 'text'],
2593 ['b', 'string'],
2594 ['c', 'date']
2595 ]).fromJson();
Akronadab5e52018-08-20 13:50:53 +02002596 expect(vc.builder().firstChild.classList.contains('unspecified')).toBeTruthy();
2597 expect(vc.builder().firstChild.firstChild.tagName).toEqual('SPAN');
Akron712733a2018-04-05 18:17:47 +02002598
2599 // Click on unspecified
Akronadab5e52018-08-20 13:50:53 +02002600 vc.builder().firstChild.firstChild.click();
2601 expect(vc.builder().firstChild.firstChild.tagName).toEqual('UL');
Akron712733a2018-04-05 18:17:47 +02002602
Akronadab5e52018-08-20 13:50:53 +02002603 var list = vc.builder().firstChild.firstChild;
Akron3ad46942018-08-22 16:47:14 +02002604 expect(list.getElementsByTagName("LI")[0].innerText).toEqual('referTo');
2605 expect(list.getElementsByTagName("LI")[1].innerText).toEqual('a');
2606 expect(list.getElementsByTagName("LI")[2].innerText).toEqual('b');
2607 expect(list.getElementsByTagName("LI")[3].innerText).toEqual('c');
Akron712733a2018-04-05 18:17:47 +02002608
2609 vc = vcClass.create([
2610 ['d', 'text'],
2611 ['e', 'string'],
2612 ['f', 'date']
2613 ]).fromJson();
Akronadab5e52018-08-20 13:50:53 +02002614 expect(vc.builder().firstChild.classList.contains('unspecified')).toBeTruthy();
2615 expect(vc.builder().firstChild.firstChild.tagName).toEqual('SPAN');
Akron712733a2018-04-05 18:17:47 +02002616
2617 // Click on unspecified
Akronadab5e52018-08-20 13:50:53 +02002618 vc.builder().firstChild.firstChild.click();
2619 expect(vc.builder().firstChild.firstChild.tagName).toEqual('UL');
Akron712733a2018-04-05 18:17:47 +02002620
Akronadab5e52018-08-20 13:50:53 +02002621 list = vc.builder().firstChild.firstChild;
Akron3ad46942018-08-22 16:47:14 +02002622 expect(list.getElementsByTagName("LI")[0].innerText).toEqual('referTo');
2623 expect(list.getElementsByTagName("LI")[1].innerText).toEqual('d');
2624 expect(list.getElementsByTagName("LI")[2].innerText).toEqual('e');
2625 expect(list.getElementsByTagName("LI")[3].innerText).toEqual('f');
Akron31d89942018-04-06 16:44:51 +02002626 // blur
2627 document.body.click();
Akron712733a2018-04-05 18:17:47 +02002628 });
Akrone65a88a2018-04-05 19:14:20 +02002629
2630 // Reinitialize to make tests stable
2631 vc = vcClass.create([
2632 ['d', 'text'],
2633 ['e', 'string'],
2634 ['f', 'date']
2635 ]).fromJson();
2636
2637 it('should be clickable on key', function () {
Akron31d89942018-04-06 16:44:51 +02002638 // Click on unspecified
Akronadab5e52018-08-20 13:50:53 +02002639 vc.builder().firstChild.firstChild.click();
Akrone65a88a2018-04-05 19:14:20 +02002640 // Click on "d"
Akronadab5e52018-08-20 13:50:53 +02002641 vc.builder().firstChild.firstChild.getElementsByTagName("LI")[1].click();
2642 expect(vc.builder().firstChild.firstChild.tagName).toEqual('SPAN');
2643 expect(vc.builder().firstChild.firstChild.innerText).toEqual('d');
2644 expect(vc.builder().firstChild.children[1].innerText).toEqual('eq');
2645 expect(vc.builder().firstChild.children[1].getAttribute('data-type')).toEqual('text');
Akron31d89942018-04-06 16:44:51 +02002646 // blur
2647 document.body.click();
Akrone65a88a2018-04-05 19:14:20 +02002648 });
2649
Akron31d89942018-04-06 16:44:51 +02002650 it('should be clickable on operation for text', function () {
2651 // Click on "d" (or unspecified)
Akronadab5e52018-08-20 13:50:53 +02002652 vc.builder().firstChild.firstChild.click();
Akron31d89942018-04-06 16:44:51 +02002653
2654 // Choose "d"
Akronadab5e52018-08-20 13:50:53 +02002655 vc.builder().firstChild.firstChild.getElementsByTagName("LI")[1].click();
Akron31d89942018-04-06 16:44:51 +02002656
2657 // Click on matchop
Akronadab5e52018-08-20 13:50:53 +02002658 vc.builder().firstChild.children[1].click();
Akron31d89942018-04-06 16:44:51 +02002659
Akronadab5e52018-08-20 13:50:53 +02002660 expect(vc.builder().firstChild.children[1].tagName).toEqual('UL');
Akron31d89942018-04-06 16:44:51 +02002661
Akronadab5e52018-08-20 13:50:53 +02002662 var ul = vc.builder().firstChild.children[1];
Akrone65a88a2018-04-05 19:14:20 +02002663 expect(ul.getElementsByTagName('li')[0].innerText).toEqual("eq");
2664 expect(ul.getElementsByTagName('li')[1].innerText).toEqual("ne");
2665 expect(ul.getElementsByTagName('li')[2].innerText).toEqual("contains");
2666 expect(ul.getElementsByTagName('li')[3].innerText).toEqual("containsnot");
2667 expect(ul.getElementsByTagName('li')[4]).toBeUndefined();
Akron31d89942018-04-06 16:44:51 +02002668
2669 // Choose "contains"
2670 ul.getElementsByTagName('li')[2].click();
Akronadab5e52018-08-20 13:50:53 +02002671 expect(vc.builder().firstChild.children[1].tagName).toEqual("SPAN");
2672 expect(vc.builder().firstChild.children[1].innerText).toEqual("contains");
Akron31d89942018-04-06 16:44:51 +02002673 // blur
2674 document.body.click();
Akrone65a88a2018-04-05 19:14:20 +02002675 })
Akron31d89942018-04-06 16:44:51 +02002676
2677 it('should be clickable on operation for string', function () {
2678 // Click on "d" (or unspecified)
Akronadab5e52018-08-20 13:50:53 +02002679 vc.builder().firstChild.firstChild.click();
Akron31d89942018-04-06 16:44:51 +02002680
2681 // Choose "e"
Akronadab5e52018-08-20 13:50:53 +02002682 vc.builder().firstChild.firstChild.getElementsByTagName("LI")[2].click();
2683
Akron31d89942018-04-06 16:44:51 +02002684 // As a consequence the matchoperator may no longer
2685 // be valid and needs to be re-evaluated
Akronadab5e52018-08-20 13:50:53 +02002686 var fc = vc.builder().firstChild;
Akron31d89942018-04-06 16:44:51 +02002687 expect(fc.firstChild.tagName).toEqual('SPAN');
2688 expect(fc.firstChild.innerText).toEqual('e');
2689 expect(fc.children[1].innerText).toEqual('eq');
2690 expect(fc.children[1].getAttribute('data-type')).toEqual('string');
2691
Akronadab5e52018-08-20 13:50:53 +02002692 vc.builder().firstChild.children[1].click();
Akron31d89942018-04-06 16:44:51 +02002693
Akronadab5e52018-08-20 13:50:53 +02002694 expect(vc.builder().firstChild.children[1].tagName).toEqual('UL');
Akron31d89942018-04-06 16:44:51 +02002695
Akronadab5e52018-08-20 13:50:53 +02002696 var ul = vc.builder().firstChild.children[1];
Akron31d89942018-04-06 16:44:51 +02002697 expect(ul.getElementsByTagName('li')[0].innerText).toEqual("eq");
2698 expect(ul.getElementsByTagName('li')[1].innerText).toEqual("ne");
2699 expect(ul.getElementsByTagName('li')[2]).toBeUndefined();
2700
2701 // Choose "ne"
2702 ul.getElementsByTagName('li')[1].click();
Akronadab5e52018-08-20 13:50:53 +02002703 expect(vc.builder().firstChild.children[1].tagName).toEqual("SPAN");
2704 expect(vc.builder().firstChild.children[1].innerText).toEqual("ne");
Akron8db5e3a2018-05-28 19:25:26 +02002705
2706 // Click on text
Akronebc96662018-08-29 17:36:20 +02002707 expect(vc.builder().firstChild.children[2].innerText).toEqual(KorAP.Locale.EMPTY);
2708 expect(vc.builder().firstChild.children[2].classList.contains('unspecified')).toEqual(true);
Akronadab5e52018-08-20 13:50:53 +02002709 vc.builder().firstChild.children[2].click();
Akron8db5e3a2018-05-28 19:25:26 +02002710
2711 // Blur text element
Akronadab5e52018-08-20 13:50:53 +02002712 expect(vc.builder().firstChild.children[2].firstChild.value).toEqual('');
Akron8db5e3a2018-05-28 19:25:26 +02002713
Akron31d89942018-04-06 16:44:51 +02002714 // blur
2715 document.body.click();
2716 });
2717
2718 it('should be clickable on operation for date', function () {
2719
2720 // Replay matchop check - so it's guaranteed that "ne" is chosen
2721 // Click on "e" (or unspecified)
Akronadab5e52018-08-20 13:50:53 +02002722 vc.builder().firstChild.firstChild.click();
Akron31d89942018-04-06 16:44:51 +02002723 // Rechoose "e"
Akronadab5e52018-08-20 13:50:53 +02002724 vc.builder().firstChild.firstChild.getElementsByTagName("LI")[1].click();
Akron31d89942018-04-06 16:44:51 +02002725 // Click on matchop
Akronadab5e52018-08-20 13:50:53 +02002726 vc.builder().firstChild.children[1].click();
Akron31d89942018-04-06 16:44:51 +02002727 // Choose "ne"
Akronadab5e52018-08-20 13:50:53 +02002728 vc.builder().firstChild.children[1].getElementsByTagName('li')[1].click();
2729 expect(vc.builder().firstChild.children[1].innerText).toEqual("ne");
Akron31d89942018-04-06 16:44:51 +02002730
2731 // Click on "e"
Akronadab5e52018-08-20 13:50:53 +02002732 vc.builder().firstChild.firstChild.click();
Akron31d89942018-04-06 16:44:51 +02002733 // Choose "f"
Akronadab5e52018-08-20 13:50:53 +02002734 vc.builder().firstChild.firstChild.getElementsByTagName("LI")[3].click();
Akron31d89942018-04-06 16:44:51 +02002735
2736 // The matchoperator should still be "ne" as this is valid for dates as well (now)
Akronadab5e52018-08-20 13:50:53 +02002737 var fc = vc.builder().firstChild;
Akron31d89942018-04-06 16:44:51 +02002738 expect(fc.firstChild.tagName).toEqual('SPAN');
2739 expect(fc.firstChild.innerText).toEqual('f');
2740 expect(fc.children[1].innerText).toEqual('ne');
2741 // blur
2742 document.body.click();
2743 });
Akronddc98a72018-04-06 17:33:52 +02002744
2745
2746 // Check json deserialization
2747 it('should be initializable', function () {
2748 vc = vcClass.create([
2749 ['a', 'text'],
2750 ['b', 'string'],
2751 ['c', 'date']
2752 ]).fromJson({
2753 "@type" : "koral:doc",
2754 "key":"a",
2755 "value":"Baum"
2756 });
2757
Akronadab5e52018-08-20 13:50:53 +02002758 expect(vc.builder().firstChild.children[1].getAttribute('data-type')).toEqual('text');
Akronddc98a72018-04-06 17:33:52 +02002759 });
Akron712733a2018-04-05 18:17:47 +02002760 });
2761
2762
Akrone4961b12017-05-10 21:04:46 +02002763 // Check prefix
2764 describe('KorAP.VC.Prefix', function () {
2765
2766 it('should be initializable', function () {
2767 var p = prefixClass.create();
2768 expect(p.element().classList.contains('pref')).toBeTruthy();
2769 expect(p.isSet()).not.toBeTruthy();
2770 });
2771
2772
2773 it('should be clickable', function () {
2774 var vc = vcClass.create([
Akron712733a2018-04-05 18:17:47 +02002775 ['a', null],
2776 ['b', null],
2777 ['c', null]
2778 ]).fromJson();
Akronadab5e52018-08-20 13:50:53 +02002779 expect(vc.builder().firstChild.classList.contains('unspecified')).toBeTruthy();
Akrone4961b12017-05-10 21:04:46 +02002780
2781 // This should open up the menu
Akronadab5e52018-08-20 13:50:53 +02002782 vc.builder().firstChild.firstChild.click();
2783 expect(vc.builder().firstChild.firstChild.tagName).toEqual('UL');
Akrone4961b12017-05-10 21:04:46 +02002784
2785 KorAP._vcKeyMenu._prefix.clear();
2786 KorAP._vcKeyMenu._prefix.add('x');
2787
Akronadab5e52018-08-20 13:50:53 +02002788 var prefElement = vc.builder().querySelector('span.pref');
Akrone4961b12017-05-10 21:04:46 +02002789 expect(prefElement.innerText).toEqual('x');
2790
2791 // This should add key 'x' to VC
2792 prefElement.click();
2793
Akronadab5e52018-08-20 13:50:53 +02002794 expect(vc.builder().firstChild.classList.contains('doc')).toBeTruthy();
2795 expect(vc.builder().firstChild.firstChild.className).toEqual('key');
2796 expect(vc.builder().firstChild.firstChild.innerText).toEqual('x');
Akrone4961b12017-05-10 21:04:46 +02002797 });
2798 });
Nils Diewald2fe12e12015-03-06 16:47:06 +00002799});