blob: 61c3099943f8194ed0e09c66e54e4d6452d4f863 [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',
Akron68d28322018-08-27 15:02:42 +020014 'vc/stringval',
15 'vc/fragment'
Akrondd5c6d32018-08-17 14:12:58 +020016], function (vcClass,
17 docClass,
18 menuClass,
19 prefixClass,
20 docGroupClass,
21 docGroupRefClass,
22 unspecifiedClass,
23 operatorsClass,
24 rewriteClass,
Akron68d28322018-08-27 15:02:42 +020025 stringValClass,
26 fragmentClass) {
Nils Diewald6ac292b2015-01-15 21:33:21 +000027
Akrondd5c6d32018-08-17 14:12:58 +020028 KorAP._vcKeyMenu = undefined;
29
Nils Diewald6ac292b2015-01-15 21:33:21 +000030
Nils Diewald7c8ced22015-04-15 19:21:00 +000031 // Helper method for building factories
32 buildFactory = function (objClass, defaults) {
33 return {
34 create : function (overwrites) {
Akron712733a2018-04-05 18:17:47 +020035 var newObj = {};
36 for (var prop in defaults) {
37 newObj[prop] = defaults[prop];
38 };
39 for (var prop in overwrites) {
40 newObj[prop] = overwrites[prop];
41 };
42 return objClass.create().fromJson(newObj);
Nils Diewald7c8ced22015-04-15 19:21:00 +000043 }
Nils Diewald0b6c0412014-12-19 03:55:57 +000044 }
Nils Diewald7c8ced22015-04-15 19:21:00 +000045 };
Nils Diewald0b6c0412014-12-19 03:55:57 +000046
Nils Diewald7c8ced22015-04-15 19:21:00 +000047 function _andOn (obj) {
Akrond141a362018-07-10 18:12:13 +020048 KorAP._and.apply(obj);
Nils Diewald7c8ced22015-04-15 19:21:00 +000049 };
Nils Diewald52f7eb12015-01-12 17:30:04 +000050
Nils Diewald7c8ced22015-04-15 19:21:00 +000051 function _orOn (obj) {
Akrond141a362018-07-10 18:12:13 +020052 KorAP._or.apply(obj);
Nils Diewald7c8ced22015-04-15 19:21:00 +000053 };
Nils Diewald52f7eb12015-01-12 17:30:04 +000054
Nils Diewald7c8ced22015-04-15 19:21:00 +000055 function _delOn (obj) {
Akrond141a362018-07-10 18:12:13 +020056 KorAP._delete.apply(obj);
Nils Diewald7c8ced22015-04-15 19:21:00 +000057 };
Nils Diewald52f7eb12015-01-12 17:30:04 +000058
Nils Diewald7c8ced22015-04-15 19:21:00 +000059 var demoFactory = buildFactory(vcClass, {
60 "@type":"koral:docGroup",
61 "operation":"operation:or",
62 "operands":[
Nils Diewaldf219eb82015-01-07 20:15:42 +000063 {
Akron712733a2018-04-05 18:17:47 +020064 "@type":"koral:docGroup",
65 "operation":"operation:and",
66 "operands":[
Nils Diewald7c8ced22015-04-15 19:21:00 +000067 {
68 "@type":"koral:doc",
69 "key":"Titel",
70 "value":"Baum",
71 "match":"match:eq"
72 },
73 {
74 "@type":"koral:doc",
75 "key":"Veröffentlichungsort",
76 "value":"hihi",
77 "match":"match:eq"
78 },
79 {
80 "@type":"koral:docGroup",
81 "operation":"operation:or",
82 "operands":[
83 {
Akron712733a2018-04-05 18:17:47 +020084 "@type":"koral:doc",
85 "key":"Titel",
86 "value":"Baum",
87 "match":"match:eq"
Nils Diewald7c8ced22015-04-15 19:21:00 +000088 },
89 {
Akron712733a2018-04-05 18:17:47 +020090 "@type":"koral:doc",
91 "key":"Veröffentlichungsort",
92 "value":"hihi",
93 "match":"match:eq"
Nils Diewald7c8ced22015-04-15 19:21:00 +000094 }
95 ]
96 }
Akron712733a2018-04-05 18:17:47 +020097 ]
Nils Diewaldf219eb82015-01-07 20:15:42 +000098 },
99 {
Akron712733a2018-04-05 18:17:47 +0200100 "@type":"koral:doc",
101 "key":"Untertitel",
102 "value":"huhu",
103 "match":"match:contains"
Nils Diewaldf219eb82015-01-07 20:15:42 +0000104 }
105 ]
106 });
107
Nils Diewald7c8ced22015-04-15 19:21:00 +0000108 describe('KorAP.Doc', function () {
109 // Create example factories
110 var stringFactory = buildFactory(docClass, {
111 "key" : "author",
112 "value" : "Max Birkendale",
Akron31d89942018-04-06 16:44:51 +0200113 "type" : "type:string",
Nils Diewald7c8ced22015-04-15 19:21:00 +0000114 "@type" : "koral:doc"
115 });
116
117 // Create example factories
Akron712733a2018-04-05 18:17:47 +0200118 var textFactory = buildFactory(docClass, {
119 "key" : "author",
120 "value" : "Birkendale",
Akron31d89942018-04-06 16:44:51 +0200121 "type" : "type:string",
Akron712733a2018-04-05 18:17:47 +0200122 "match" : "match:contains",
123 "@type" : "koral:doc"
124 });
125
126 // Create example factories
Nils Diewald7c8ced22015-04-15 19:21:00 +0000127 var dateFactory = buildFactory(docClass, {
128 "key" : "pubDate",
129 "type" : "type:date",
130 "match" : "match:eq",
131 "value" : "2014-11-05",
132 "@type" : "koral:doc"
133 });
134
135 // Create example factories
136 var regexFactory = buildFactory(docClass, {
137 "key" : "title",
138 "type" : "type:regex",
139 "value" : "[^b]ee.+?",
140 "@type" : "koral:doc"
141 });
142
143 it('should be initializable', function () {
144 var doc = docClass.create();
145 expect(doc.matchop()).toEqual('eq');
146 expect(doc.key()).toBeUndefined();
147 expect(doc.value()).toBeUndefined();
148 expect(doc.type()).toEqual("string");
149 });
150
151 it('should be definable', function () {
152
153 // Empty doc
154 var doc = docClass.create();
155
156 // Set values
157 doc.key("title");
Akron8db5e3a2018-05-28 19:25:26 +0200158
Nils Diewald7c8ced22015-04-15 19:21:00 +0000159 doc.value("Der alte Mann");
160 expect(doc.matchop()).toEqual('eq');
161 expect(doc.key()).toEqual("title");
162 expect(doc.type()).toEqual("string");
163 expect(doc.value()).toEqual("Der alte Mann");
164 });
165
166
167 it('should deserialize JSON-LD string', function () {
168 var doc;
169
170 // String default
171 doc = stringFactory.create();
172 expect(doc.matchop()).toEqual('eq');
173 expect(doc.key()).toEqual("author");
174 expect(doc.type()).toEqual("string");
175 expect(doc.value()).toEqual("Max Birkendale");
176
177 // No valid string
178 doc = stringFactory.create({
Akron712733a2018-04-05 18:17:47 +0200179 value : undefined
Nils Diewald7c8ced22015-04-15 19:21:00 +0000180 });
181 expect(doc).toBeUndefined();
182
183 // No valid string
184 doc = stringFactory.create({
Akron712733a2018-04-05 18:17:47 +0200185 value : { "foo" : "bar" }
Nils Diewald7c8ced22015-04-15 19:21:00 +0000186 });
187 expect(doc).toBeUndefined();
188
189 // Change match type
190 doc = stringFactory.create({
Akron712733a2018-04-05 18:17:47 +0200191 "match" : "match:ne"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000192 });
193
194 expect(doc.matchop()).toEqual('ne');
195 expect(doc.key()).toEqual("author");
196 expect(doc.type()).toEqual("string");
197 expect(doc.value()).toEqual("Max Birkendale");
198
199 // Invalid match type
200 doc = stringFactory.create({
Akron712733a2018-04-05 18:17:47 +0200201 "match" : { "foo" : "bar" }
Nils Diewald7c8ced22015-04-15 19:21:00 +0000202 });
203 expect(doc).toBeUndefined();
204 });
205
206 it('should deserialize JSON-LD regex', function () {
207 var doc = regexFactory.create();
208 expect(doc.key()).toEqual("title");
209 expect(doc.type()).toEqual("regex");
210 expect(doc.value()).toEqual("[^b]ee.+?");
211 expect(doc.matchop()).toEqual('eq');
212
213 // change matcher
214 doc = regexFactory.create({
Akron712733a2018-04-05 18:17:47 +0200215 match : "match:ne"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000216 });
217 expect(doc.matchop()).toEqual('ne');
Akronea4e9052017-07-06 16:12:05 +0200218 expect(doc.rewrites()).toBeUndefined();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000219
220 // Invalid matcher
221 doc = regexFactory.create({
Akron712733a2018-04-05 18:17:47 +0200222 match : "match:chook"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000223 });
Akronea4e9052017-07-06 16:12:05 +0200224 expect(doc.matchop()).toEqual('eq');
225 expect(doc.rewrites()).toBeDefined();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000226
227 // Invalid regex
228 doc = regexFactory.create({
Akron712733a2018-04-05 18:17:47 +0200229 value : "[^b"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000230 });
231 expect(doc).toBeUndefined();
232 });
233
234 it('should deserialize JSON-LD date', function () {
235
236 // Normal date
237 doc = dateFactory.create({});
238
239 expect(doc.matchop()).toEqual('eq');
240 expect(doc.key()).toEqual("pubDate");
241 expect(doc.type()).toEqual("date");
242 expect(doc.value()).toEqual("2014-11-05");
243
244 // Short date 1
245 doc = dateFactory.create({
Akron712733a2018-04-05 18:17:47 +0200246 "value" : "2014-11"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000247 });
248
249 expect(doc.matchop()).toEqual('eq');
250 expect(doc.key()).toEqual("pubDate");
251 expect(doc.type()).toEqual("date");
252 expect(doc.value()).toEqual("2014-11");
253
254 // Short date 2
255 doc = dateFactory.create({
Akron712733a2018-04-05 18:17:47 +0200256 "value" : "2014"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000257 });
258
259 expect(doc.matchop()).toEqual('eq');
260 expect(doc.key()).toEqual("pubDate");
261 expect(doc.type()).toEqual("date");
262 expect(doc.value()).toEqual("2014");
263
264 // Invalid date!
265 doc = dateFactory.create({
Akron712733a2018-04-05 18:17:47 +0200266 "value" : "2014-11-050"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000267 });
268 expect(doc).toBeUndefined();
269
270 // Invalid matcher!
271 doc = dateFactory.create({
Akron31d89942018-04-06 16:44:51 +0200272 "match" : "match:contains",
Nils Diewald7c8ced22015-04-15 19:21:00 +0000273 });
Akronea4e9052017-07-06 16:12:05 +0200274 expect(doc).toBeDefined();
275 expect(doc.rewrites()).toBeDefined();
276 expect(doc.matchop()).toEqual('eq');
Nils Diewald7c8ced22015-04-15 19:21:00 +0000277 });
278
279 it('should be serializale to JSON', function () {
280
281 // Empty doc
282 var doc = docClass.create();
283 expect(doc.toJson()).toEqual(jasmine.any(Object));
284
285 // Serialize string
286 doc = stringFactory.create();
287 expect(doc.toJson()).toEqual(jasmine.objectContaining({
Akron712733a2018-04-05 18:17:47 +0200288 "@type" : "koral:doc",
289 "type" : "type:string",
290 "key" : "author",
291 "value" : "Max Birkendale",
292 "match" : "match:eq"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000293 }));
294
295 // Serialize regex
296 doc = regexFactory.create();
297 expect(doc.toJson()).toEqual(jasmine.objectContaining({
Akron712733a2018-04-05 18:17:47 +0200298 "@type" : "koral:doc",
299 "type" : "type:regex",
300 "value" : "[^b]ee.+?",
301 "match" : "match:eq",
302 "key" : 'title'
Nils Diewald7c8ced22015-04-15 19:21:00 +0000303 }));
304
305 doc = regexFactory.create({
Akron712733a2018-04-05 18:17:47 +0200306 match: "match:ne"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000307 });
308 expect(doc.toJson()).toEqual(jasmine.objectContaining({
Akron712733a2018-04-05 18:17:47 +0200309 "@type" : "koral:doc",
310 "type" : "type:regex",
311 "value" : "[^b]ee.+?",
312 "match" : "match:ne",
313 "key" : 'title'
Nils Diewald7c8ced22015-04-15 19:21:00 +0000314 }));
315
316 doc = dateFactory.create();
317 expect(doc.toJson()).toEqual(jasmine.objectContaining({
Akron712733a2018-04-05 18:17:47 +0200318 "@type" : "koral:doc",
319 "type" : "type:date",
320 "value" : "2014-11-05",
321 "match" : "match:eq",
322 "key" : 'pubDate'
Nils Diewald7c8ced22015-04-15 19:21:00 +0000323 }));
324
325 doc = dateFactory.create({
Akron712733a2018-04-05 18:17:47 +0200326 value : "2014"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000327 });
328 expect(doc.toJson()).toEqual(jasmine.objectContaining({
Akron712733a2018-04-05 18:17:47 +0200329 "@type" : "koral:doc",
330 "type" : "type:date",
331 "value" : "2014",
332 "match" : "match:eq",
333 "key" : 'pubDate'
Nils Diewald7c8ced22015-04-15 19:21:00 +0000334 }));
335 });
336
337
338 it('should be serializale to String', function () {
339 // Empty doc
340 var doc = docClass.create();
Akronebc96662018-08-29 17:36:20 +0200341
Nils Diewald7c8ced22015-04-15 19:21:00 +0000342 expect(doc.toQuery()).toEqual("");
343
344 // Serialize string
345 doc = stringFactory.create();
346 expect(doc.toQuery()).toEqual('author = "Max Birkendale"');
347
348 // Serialize string with quotes
349 doc = stringFactory.create({ "value" : 'Max "Der Coole" Birkendate'});
350 expect(doc.toQuery()).toEqual('author = "Max \\"Der Coole\\" Birkendate"');
351
352 // Serialize regex
353 doc = regexFactory.create();
354 expect(doc.toQuery()).toEqual('title = /[^b]ee.+?/');
355
356 doc = regexFactory.create({
Akron712733a2018-04-05 18:17:47 +0200357 match: "match:ne"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000358 });
359 expect(doc.toQuery()).toEqual('title != /[^b]ee.+?/');
360
Akron8778f5d2017-06-30 21:25:55 +0200361 doc = regexFactory.create({
Akron712733a2018-04-05 18:17:47 +0200362 value: "WPD/AAA/00001"
Akron8778f5d2017-06-30 21:25:55 +0200363 });
364 expect(doc.toQuery()).toEqual('title = /WPD\\/AAA\\/00001/');
365
Nils Diewald7c8ced22015-04-15 19:21:00 +0000366 doc = dateFactory.create();
367 expect(doc.toQuery()).toEqual('pubDate in 2014-11-05');
368
369 doc = dateFactory.create({
Akron712733a2018-04-05 18:17:47 +0200370 value : "2014"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000371 });
372 expect(doc.toQuery()).toEqual('pubDate in 2014');
373 });
374 });
375
376
377 describe('KorAP.DocGroup', function () {
378 // Create example factories
379 var docFactory = buildFactory(
380 docClass,
Nils Diewaldf219eb82015-01-07 20:15:42 +0000381 {
Akron712733a2018-04-05 18:17:47 +0200382 "@type" : "koral:doc",
383 "match":"match:eq",
384 "key" : "author",
385 "value" : "Max Birkendale"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000386 }
387 );
388
389 var docGroupFactory = buildFactory(
390 docGroupClass, {
Akron712733a2018-04-05 18:17:47 +0200391 "@type" : "koral:docGroup",
392 "operation" : "operation:and",
393 "operands" : [
394 docFactory.create().toJson(),
395 docFactory.create({
396 "key" : "pubDate",
397 "type" : "type:date",
398 "value" : "2014-12-05"
399 }).toJson()
400 ]
Nils Diewald7c8ced22015-04-15 19:21:00 +0000401 });
402
403 it('should be initializable', function () {
404 // Create empty group
405 var docGroup = docGroupClass.create();
406 expect(docGroup.operation()).toEqual('and');
407
408 // Create empty group
409 docGroup = docGroupClass.create();
410 docGroup.operation('or');
411 expect(docGroup.operation()).toEqual('or');
412 });
413
414 it('should be definable', function () {
415
416 // Empty group
417 var docGroup = docGroupClass.create();
418 expect(docGroup.operation()).toEqual('and');
419
420 // Set values
421 docGroup.operation("or");
422 expect(docGroup.operation()).toEqual('or');
423
424 // Set invalid values
425 docGroup.operation("hui");
426 expect(docGroup.operation()).toEqual('or');
427 });
428
429 it('should be deserializable', function () {
Akronadab5e52018-08-20 13:50:53 +0200430
431 // Reset list
432 KorAP._vcKeyMenu = menuClass.create([['referTo','ref']]);
433
Nils Diewald7c8ced22015-04-15 19:21:00 +0000434 var docGroup = docGroupFactory.create();
435 expect(docGroup.operation()).toEqual("and");
436 expect(docGroup.operands().length).toEqual(2);
437
438 var op1 = docGroup.getOperand(0);
439 expect(op1.type()).toEqual("string");
440 expect(op1.key()).toEqual("author");
441 expect(op1.value()).toEqual("Max Birkendale");
442 expect(op1.matchop()).toEqual("eq");
443
444 var op2 = docGroup.getOperand(1);
445 expect(op2.type()).toEqual("date");
446 expect(op2.key()).toEqual("pubDate");
447 expect(op2.value()).toEqual("2014-12-05");
448 expect(op2.matchop()).toEqual("eq");
449
450 // Append empty group
451 var newGroup = docGroup.append(docGroupClass.create());
452 newGroup.operation('or');
453 newGroup.append(docFactory.create());
454 newGroup.append(docFactory.create({
Akron712733a2018-04-05 18:17:47 +0200455 "type" : "type:regex",
456 "key" : "title",
457 "value" : "^e.+?$",
458 "match" : "match:ne"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000459 }));
460
461 expect(docGroup.operation()).toEqual("and");
462 expect(docGroup.operands().length).toEqual(3);
463
464 var op1 = docGroup.getOperand(0);
465 expect(op1.ldType()).toEqual("doc");
466 expect(op1.type()).toEqual("string");
467 expect(op1.key()).toEqual("author");
468 expect(op1.value()).toEqual("Max Birkendale");
469 expect(op1.matchop()).toEqual("eq");
470
471 var op2 = docGroup.getOperand(1);
472 expect(op2.ldType()).toEqual("doc");
473 expect(op2.type()).toEqual("date");
474 expect(op2.key()).toEqual("pubDate");
475 expect(op2.value()).toEqual("2014-12-05");
476 expect(op2.matchop()).toEqual("eq");
477
478 var op3 = docGroup.getOperand(2);
479 expect(op3.ldType()).toEqual("docGroup");
480 expect(op3.operation()).toEqual("or");
Akronadab5e52018-08-20 13:50:53 +0200481
Nils Diewald7c8ced22015-04-15 19:21:00 +0000482 var op4 = op3.getOperand(0);
483 expect(op4.ldType()).toEqual("doc");
484 expect(op4.type()).toEqual("string");
485 expect(op4.key()).toEqual("author");
486 expect(op4.value()).toEqual("Max Birkendale");
487 expect(op4.matchop()).toEqual("eq");
488
489 var op5 = op3.getOperand(1);
490 expect(op5.ldType()).toEqual("doc");
491 expect(op5.type()).toEqual("regex");
492 expect(op5.key()).toEqual("title");
493 expect(op5.value()).toEqual("^e.+?$");
494 expect(op5.matchop()).toEqual("ne");
495 });
496
497 it('should be serializable to JSON', function () {
498 var docGroup = docGroupFactory.create();
499
500 expect(docGroup.toJson()).toEqual(jasmine.objectContaining({
Akron712733a2018-04-05 18:17:47 +0200501 "@type" : "koral:docGroup",
502 "operation" : "operation:and",
503 "operands" : [
504 {
505 "@type": 'koral:doc',
506 "key" : 'author',
507 "match": 'match:eq',
508 "value": 'Max Birkendale',
509 "type": 'type:string'
510 },
511 {
512 "@type": 'koral:doc',
513 "key": 'pubDate',
514 "match": 'match:eq',
515 "value": '2014-12-05',
516 "type": 'type:date'
517 }
518 ]
Nils Diewald7c8ced22015-04-15 19:21:00 +0000519 }));
520 });
Nils Diewalde15b7a22015-01-09 21:50:21 +0000521
Nils Diewald7c8ced22015-04-15 19:21:00 +0000522 it('should be serializable to String', function () {
523 var docGroup = docGroupFactory.create();
524 expect(docGroup.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +0200525 'author = "Max Birkendale" & pubDate in 2014-12-05'
Nils Diewald7c8ced22015-04-15 19:21:00 +0000526 );
Nils Diewald52f7eb12015-01-12 17:30:04 +0000527
Nils Diewald7c8ced22015-04-15 19:21:00 +0000528 docGroup = docGroupFactory.create({
Akron712733a2018-04-05 18:17:47 +0200529 "@type" : "koral:docGroup",
530 "operation" : "operation:or",
531 "operands" : [
532 {
533 "@type": 'koral:doc',
534 "key" : 'author',
535 "match": 'match:eq',
536 "value": 'Max Birkendale',
537 "type": 'type:string'
538 },
539 {
540 "@type" : "koral:docGroup",
541 "operation" : "operation:and",
542 "operands" : [
543 {
544 "@type": 'koral:doc',
545 "key": 'pubDate',
546 "match": 'match:geq',
547 "value": '2014-05-12',
548 "type": 'type:date'
549 },
550 {
551 "@type": 'koral:doc',
552 "key": 'pubDate',
553 "match": 'match:leq',
554 "value": '2014-12-05',
555 "type": 'type:date'
556 },
557 {
558 "@type": 'koral:doc',
559 "key": 'foo',
560 "match": 'match:ne',
561 "value": '[a]?bar',
562 "type": 'type:regex'
563 }
564 ]
565 }
566 ]
Nils Diewald7c8ced22015-04-15 19:21:00 +0000567 });
568 expect(docGroup.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +0200569 'author = "Max Birkendale" | ' +
570 '(pubDate since 2014-05-12 & ' +
571 'pubDate until 2014-12-05 & foo != /[a]?bar/)'
Nils Diewald7c8ced22015-04-15 19:21:00 +0000572 );
573 });
574 });
575
Akronb19803c2018-08-16 16:39:42 +0200576 describe('KorAP.DocGroupRef', function () {
577 // Create example factories
578 var docRefFactory = buildFactory(
579 docGroupRefClass,
580 {
581 "@type" : "koral:docGroupRef",
582 "ref" : "@max/myCorpus"
583 }
584 );
585
586 it('should be initializable', function () {
587 var vcRef = docGroupRefClass.create();
588 expect(vcRef.ref()).toBeUndefined();
589 });
590
591 it('should be definable', function () {
592 var vcRef = docGroupRefClass.create();
593 vcRef.ref("@peter/mycorpus");
594 expect(vcRef.ref()).toEqual("@peter/mycorpus");
595 vcRef.ref("@peter/mycorpus2");
596 expect(vcRef.ref()).toEqual("@peter/mycorpus2");
597 });
598
599 it('should deserialize JSON-LD string', function () {
600 var vcRef = docRefFactory.create();
601 expect(vcRef.ref()).toEqual("@max/myCorpus");
602 });
603
604 it('should serialize to JSON-LD', function () {
605 var vcRef = docRefFactory.create();
606 expect(vcRef.toJson()).toEqual(jasmine.objectContaining({
607 "@type" : "koral:docGroupRef",
608 "ref":"@max/myCorpus"
609 }));
610
611 vcRef.ref("@peter/myCorpus2");
612 expect(vcRef.toJson()).toEqual(jasmine.objectContaining({
613 "@type" : "koral:docGroupRef",
614 "ref":"@peter/myCorpus2"
615 }));
616 });
617
618 it('should serialize to a query', function () {
619 var vcRef = docRefFactory.create();
620 expect(vcRef.toQuery()).toEqual(
621 "referTo \"@max/myCorpus\""
622 );
623
624 vcRef.ref("@peter/myCorpus2");
625 expect(vcRef.toQuery()).toEqual(
626 "referTo \"@peter/myCorpus2\""
627 );
628 });
629 });
630
631
Nils Diewald7c8ced22015-04-15 19:21:00 +0000632 describe('KorAP.UnspecifiedDoc', function () {
633 it('should be initializable', function () {
634 var doc = unspecifiedClass.create();
635 var docElement = doc.element();
636 expect(docElement.getAttribute('class')).toEqual('doc unspecified');
Akronebc96662018-08-29 17:36:20 +0200637 expect(docElement.firstChild.firstChild.data).toEqual(KorAP.Locale.EMPTY);
638 expect(docElement.lastChild.lastChild.data).toEqual(KorAP.Locale.EMPTY);
Nils Diewald7c8ced22015-04-15 19:21:00 +0000639 expect(doc.toQuery()).toEqual('');
640
641 // Only removable
642 expect(docElement.lastChild.children.length).toEqual(0);
643 });
644
Akrond141a362018-07-10 18:12:13 +0200645 it('should be removable, when no root', function () {
Nils Diewald7c8ced22015-04-15 19:21:00 +0000646 var docGroup = docGroupClass.create();
647 docGroup.operation('or');
648 expect(docGroup.operation()).toEqual('or');
649
650 docGroup.append({
Akron712733a2018-04-05 18:17:47 +0200651 "@type": 'koral:doc',
652 "key": 'pubDate',
653 "match": 'match:eq',
654 "value": '2014-12-05',
655 "type": 'type:date'
Nils Diewald7c8ced22015-04-15 19:21:00 +0000656 });
657
658 // Add unspecified object
659 docGroup.append();
660
Akrond141a362018-07-10 18:12:13 +0200661 var parent = document.createElement('div');
662 parent.appendChild(docGroup.element());
663
Nils Diewald7c8ced22015-04-15 19:21:00 +0000664 expect(docGroup.element().getAttribute('class')).toEqual('docGroup');
665 expect(docGroup.element().children[0].getAttribute('class')).toEqual('doc');
666
667 var unspec = docGroup.element().children[1];
668 expect(unspec.getAttribute('class')).toEqual('doc unspecified');
669
Akronb19803c2018-08-16 16:39:42 +0200670 // Only unspec and delete
671 expect(unspec.children.length).toEqual(2);
672
Nils Diewald7c8ced22015-04-15 19:21:00 +0000673 // Removable
674 expect(unspec.lastChild.children.length).toEqual(1);
675 expect(unspec.lastChild.children[0].getAttribute('class')).toEqual('delete');
676 });
677
Akrond141a362018-07-10 18:12:13 +0200678
Nils Diewald7c8ced22015-04-15 19:21:00 +0000679 it('should be replaceable by a doc', function () {
680 var doc = unspecifiedClass.create();
681 expect(doc.ldType()).toEqual("non");
682 // No parent, therefor not updateable
683 expect(doc.key("baum")).toBeNull();
684
685 var docGroup = docGroupClass.create();
686 docGroup.operation('or');
687 expect(docGroup.operation()).toEqual('or');
688
689 docGroup.append({
Akron712733a2018-04-05 18:17:47 +0200690 "@type": 'koral:doc',
691 "key": 'pubDate',
692 "match": 'match:eq',
693 "value": '2014-12-05',
694 "type": 'type:date'
Nils Diewald7c8ced22015-04-15 19:21:00 +0000695 });
696
697 expect(docGroup.toQuery()).toEqual("pubDate in 2014-12-05");
698 docGroup.append();
699
700 expect(docGroup.getOperand(0).ldType()).toEqual("doc");
701 expect(docGroup.getOperand(1).ldType()).toEqual("non");
702
703 var op = docGroup.getOperand(1).element().lastChild;
Akron0b489ad2018-02-02 16:49:32 +0100704 expect(op.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +0000705 expect(op.children[0].getAttribute('class')).toEqual('delete');
706 expect(op.children.length).toEqual(1);
707
708 // Replace unspecified doc
709 expect(docGroup.getOperand(1).key("name")).not.toBeNull();
710 expect(docGroup.getOperand(1).ldType()).toEqual("doc");
711 expect(docGroup.getOperand(1).key()).toEqual("name");
Akron55a343b2018-04-06 19:57:36 +0200712 expect(docGroup.getOperand(1).value()).toBeUndefined();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000713
Akronb19803c2018-08-16 16:39:42 +0200714 expect(docGroup.getOperand(1).element().children.length).toEqual(4);
715
Nils Diewald7c8ced22015-04-15 19:21:00 +0000716 op = docGroup.getOperand(1).element().lastChild;
Akron0b489ad2018-02-02 16:49:32 +0100717 expect(op.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +0000718 expect(op.children[0].getAttribute('class')).toEqual('and');
719 expect(op.children[1].getAttribute('class')).toEqual('or');
720 expect(op.children[2].getAttribute('class')).toEqual('delete');
Akronb19803c2018-08-16 16:39:42 +0200721
Nils Diewald7c8ced22015-04-15 19:21:00 +0000722 expect(op.children.length).toEqual(3);
723
724 docGroup.getOperand(1).value("Pachelbel");
725 expect(docGroup.getOperand(1).value()).toEqual("Pachelbel");
726 expect(docGroup.getOperand(1).type()).toEqual("string");
727 expect(docGroup.getOperand(1).matchop()).toEqual("eq");
728
729 // Specified!
730 expect(docGroup.toQuery()).toEqual('pubDate in 2014-12-05 | name = "Pachelbel"');
731 });
Akronb19803c2018-08-16 16:39:42 +0200732
Nils Diewald7c8ced22015-04-15 19:21:00 +0000733 it('should be replaceable on root', function () {
Nils Diewald6283d692015-04-23 20:32:53 +0000734 var vc = vcClass.create();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000735 expect(vc.toQuery()).toEqual("");
736
737 expect(vc.root().ldType()).toEqual("non");
738
739 // No operators on root
740 op = vc.root().element().lastChild;
Akronebc96662018-08-29 17:36:20 +0200741 expect(op.lastChild.textContent).toEqual(KorAP.Locale.EMPTY);
Nils Diewald7c8ced22015-04-15 19:21:00 +0000742
743 // Replace
744 expect(vc.root().key("baum")).not.toBeNull();
745 expect(vc.root().ldType()).toEqual("doc");
746
747 op = vc.root().element().lastChild;
Akron0b489ad2018-02-02 16:49:32 +0100748 expect(op.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +0000749 expect(op.children[0].getAttribute('class')).toEqual('and');
750 expect(op.children[1].getAttribute('class')).toEqual('or');
751 expect(op.children[2].getAttribute('class')).toEqual('delete');
752 expect(op.children.length).toEqual(3);
753 });
Akron55a343b2018-04-06 19:57:36 +0200754
755 it('should be clickable', function () {
756 var vc = vcClass.create([
757 ["pubDate", "date"]
758 ]);
759 expect(vc.toQuery()).toEqual("");
Akronebc96662018-08-29 17:36:20 +0200760 expect(vc.builder().firstChild.textContent).toEqual(KorAP.Locale.EMPTY);
761 expect(vc.builder().firstChild.classList.contains('unspecified')).toEqual(true);
Akronadab5e52018-08-20 13:50:53 +0200762 vc.builder().firstChild.firstChild.click();
Akron55a343b2018-04-06 19:57:36 +0200763
764 // Click on pubDate
Akron3ad46942018-08-22 16:47:14 +0200765 vc.element().firstChild.getElementsByTagName("LI")[1].click();
Akronadab5e52018-08-20 13:50:53 +0200766 expect(vc.builder().firstChild.firstChild.textContent).toEqual("pubDate");
767 expect(vc.builder().firstChild.children[1].getAttribute("data-type")).toEqual("date");
Akron55a343b2018-04-06 19:57:36 +0200768 });
Nils Diewald7c8ced22015-04-15 19:21:00 +0000769 });
770
771 describe('KorAP.Doc element', function () {
772 it('should be initializable', function () {
773 var docElement = docClass.create(undefined, {
Akron712733a2018-04-05 18:17:47 +0200774 "@type" : "koral:doc",
775 "key":"Titel",
776 "value":"Baum",
777 "match":"match:eq"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000778 });
779 expect(docElement.key()).toEqual('Titel');
780 expect(docElement.matchop()).toEqual('eq');
781 expect(docElement.value()).toEqual('Baum');
782
783 var docE = docElement.element();
784 expect(docE.children[0].firstChild.data).toEqual('Titel');
785 expect(docE.children[1].firstChild.data).toEqual('eq');
786 expect(docE.children[1].getAttribute('data-type')).toEqual('string');
787 expect(docE.children[2].firstChild.data).toEqual('Baum');
788 expect(docE.children[2].getAttribute('data-type')).toEqual('string');
789
790 expect(docElement.toJson()).toEqual(jasmine.objectContaining({
Akron712733a2018-04-05 18:17:47 +0200791 "@type" : "koral:doc",
792 "key":"Titel",
793 "value":"Baum",
794 "match":"match:eq"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000795 }));
796 });
Akronb19803c2018-08-16 16:39:42 +0200797
798
799 it('should be replacable by unspecified', function () {
800 var vc = vcClass.create([
801 ["pubDate", "date"]
802 ]).fromJson({
803 "@type" : "koral:doc",
804 "key":"Titel",
805 "value":"Baum",
806 "match":"match:eq"
807 });
808 expect(vc.toQuery()).toEqual("Titel = \"Baum\"");
809
Akronadab5e52018-08-20 13:50:53 +0200810 var vcE = vc.builder();
Akronb19803c2018-08-16 16:39:42 +0200811 expect(vcE.firstChild.children.length).toEqual(4);
812
813 // Click to delete
814 vcE.firstChild.lastChild.lastChild.click();
815
816 expect(vcE.firstChild.children.length).toEqual(1);
817
Akronebc96662018-08-29 17:36:20 +0200818 expect(vcE.firstChild.textContent).toEqual(KorAP.Locale.EMPTY);
819 expect(vcE.firstChild.classList.contains("unspecified")).toBeTruthy();
Akronb19803c2018-08-16 16:39:42 +0200820 vcE.firstChild.firstChild.click();
821
822 // Click on pubDate
Akron3ad46942018-08-22 16:47:14 +0200823 vcE.firstChild.getElementsByTagName("LI")[1].click();
Akronb19803c2018-08-16 16:39:42 +0200824
825 expect(vcE.firstChild.firstChild.textContent).toEqual("pubDate");
826 expect(vcE.firstChild.children[1].getAttribute("data-type")).toEqual("date");
827
828 expect(vcE.firstChild.children.length).toEqual(4);
829 });
830
831
Akron587e4d92018-08-31 12:44:26 +0200832 it('should be replaceable by docGroupRef with deletion', function () {
Akron3ad46942018-08-22 16:47:14 +0200833 var vc = vcClass.create().fromJson({
Akronb19803c2018-08-16 16:39:42 +0200834 "@type" : "koral:doc",
835 "key":"Titel",
836 "value":"Baum",
837 "match":"match:eq"
838 });
839
840 expect(vc.toQuery()).toEqual("Titel = \"Baum\"");
841
Akronadab5e52018-08-20 13:50:53 +0200842 var vcE = vc.builder();
Akronb19803c2018-08-16 16:39:42 +0200843 expect(vcE.firstChild.children.length).toEqual(4);
844
845 // Click to delete
846 vcE.firstChild.lastChild.lastChild.click();
847
848 expect(vcE.firstChild.children.length).toEqual(1);
849
Akronebc96662018-08-29 17:36:20 +0200850 expect(vcE.firstChild.textContent).toEqual(KorAP.Locale.EMPTY);
851 expect(vcE.firstChild.classList.contains('unspecified')).toEqual(true);
Akronb19803c2018-08-16 16:39:42 +0200852 vcE.firstChild.firstChild.click();
853
Akron3ad46942018-08-22 16:47:14 +0200854 // Click on referTo
Akronb19803c2018-08-16 16:39:42 +0200855 vcE.firstChild.getElementsByTagName("LI")[0].click();
856
Akron3ad46942018-08-22 16:47:14 +0200857 expect(vcE.firstChild.firstChild.textContent).toEqual("referTo");
Akronb19803c2018-08-16 16:39:42 +0200858 expect(vcE.firstChild.children[1].getAttribute("data-type")).toEqual("string");
Akron587e4d92018-08-31 12:44:26 +0200859
Akronb19803c2018-08-16 16:39:42 +0200860 expect(vcE.firstChild.children.length).toEqual(3);
Akron62ac95b2018-08-30 18:08:25 +0200861 expect(vcE.firstChild.children[1].classList.contains("unspecified")).toBeTruthy();
Akronb19803c2018-08-16 16:39:42 +0200862 });
Akron587e4d92018-08-31 12:44:26 +0200863
864
865 it('should be replaceable by docGroupRef on root', function () {
866 var vc = vcClass.create().fromJson({
867 "@type" : "koral:doc",
868 "key":"Titel",
869 "value":"Baum",
870 "match":"match:eq"
871 });
872
873 expect(vc.toQuery()).toEqual("Titel = \"Baum\"");
874
875 var vcE = vc.builder();
876 expect(vcE.firstChild.children.length).toEqual(4);
877
878 // Click on the key
879 vcE.firstChild.firstChild.click();
880
881 expect(vcE.firstChild.getElementsByTagName("LI")[0].textContent).toEqual("referTo");
882
883 // Click on referTo
884 vcE.firstChild.getElementsByTagName("LI")[0].click();
885
886 // Now it's a referTo element
887 expect(vcE.firstChild.firstChild.textContent).toEqual("referTo");
888 expect(vcE.firstChild.children.length).toEqual(3);
889 expect(vcE.firstChild.children[1].classList.contains("unspecified")).toBeTruthy();
890 });
891
892 it('should be replaceable by docGroupRef nested', function () {
893 var vc = vcClass.create().fromJson({
894 "@type" : "koral:docGroup",
895 "operation" : "operation:and",
896 "operands" : [
897 {
898 "@type": 'koral:doc',
899 "key" : 'author',
900 "match": 'match:eq',
901 "value": 'Max Birkendale',
902 "type": 'type:string'
903 },
904 {
905 "@type": 'koral:doc',
906 "key": 'pubDate',
907 "match": 'match:eq',
908 "value": '2014-12-05',
909 "type": 'type:date'
910 }
911 ]
912 });
913
914 expect(vc.toQuery()).toEqual("author = \"Max Birkendale\" & pubDate in 2014-12-05");
915
916 var vcE = vc.builder();
917
918 // First doc
919 var doc = vcE.firstChild.firstChild;
920 expect(doc.children.length).toEqual(4);
921
922 // Click on the key
923 doc.firstChild.click();
924
925 expect(doc.getElementsByTagName("LI")[0].textContent).toEqual("referTo");
926
927 // Click on referTo
928 vcE.firstChild.getElementsByTagName("LI")[0].click();
929
930 // Now it's a referTo element
931 expect(vcE.firstChild.firstChild.firstChild.textContent).toEqual("referTo");
932 expect(vcE.firstChild.firstChild.children.length).toEqual(3);
933 expect(vcE.firstChild.firstChild.children[1].classList.contains("unspecified")).toBeTruthy();
934 });
Nils Diewald7c8ced22015-04-15 19:21:00 +0000935 });
936
937 describe('KorAP.DocGroup element', function () {
938 it('should be initializable', function () {
939
940 var docGroup = docGroupClass.create(undefined, {
Akron712733a2018-04-05 18:17:47 +0200941 "@type" : "koral:docGroup",
942 "operation" : "operation:and",
943 "operands" : [
944 {
945 "@type": 'koral:doc',
946 "key" : 'author',
947 "match": 'match:eq',
948 "value": 'Max Birkendale',
949 "type": 'type:string'
950 },
951 {
952 "@type": 'koral:doc',
953 "key": 'pubDate',
954 "match": 'match:eq',
955 "value": '2014-12-05',
956 "type": 'type:date'
957 }
958 ]
Nils Diewald7c8ced22015-04-15 19:21:00 +0000959 });
960
961 expect(docGroup.operation()).toEqual('and');
962 var e = docGroup.element();
963 expect(e.getAttribute('class')).toEqual('docGroup');
964 expect(e.getAttribute('data-operation')).toEqual('and');
965
966 var first = e.children[0];
967 expect(first.getAttribute('class')).toEqual('doc');
968 expect(first.children[0].getAttribute('class')).toEqual('key');
969 expect(first.children[1].getAttribute('class')).toEqual('match');
970 expect(first.children[2].getAttribute('class')).toEqual('value');
971 expect(first.children[2].getAttribute('data-type')).toEqual('string');
972 expect(first.children[0].firstChild.data).toEqual('author');
973 expect(first.children[1].firstChild.data).toEqual('eq');
974 expect(first.children[2].firstChild.data).toEqual('Max Birkendale');
975
976 var second = e.children[1];
977 expect(second.getAttribute('class')).toEqual('doc');
978 expect(second.children[0].getAttribute('class')).toEqual('key');
979 expect(second.children[1].getAttribute('class')).toEqual('match');
980 expect(second.children[2].getAttribute('class')).toEqual('value');
981 expect(second.children[2].getAttribute('data-type')).toEqual('date');
982 expect(second.children[0].firstChild.data).toEqual('pubDate');
983 expect(second.children[1].firstChild.data).toEqual('eq');
984 expect(second.children[2].firstChild.data).toEqual('2014-12-05');
985 });
986
987 it('should be deserializable with nested groups', function () {
988 var docGroup = docGroupClass.create(undefined, {
Akron712733a2018-04-05 18:17:47 +0200989 "@type" : "koral:docGroup",
990 "operation" : "operation:or",
991 "operands" : [
992 {
993 "@type": 'koral:doc',
994 "key" : 'author',
995 "match": 'match:eq',
996 "value": 'Max Birkendale',
997 "type": 'type:string'
998 },
999 {
1000 "@type" : "koral:docGroup",
1001 "operation" : "operation:and",
1002 "operands" : [
1003 {
1004 "@type": 'koral:doc',
1005 "key": 'pubDate',
1006 "match": 'match:geq',
1007 "value": '2014-05-12',
1008 "type": 'type:date'
1009 },
1010 {
1011 "@type": 'koral:doc',
1012 "key": 'pubDate',
1013 "match": 'match:leq',
1014 "value": '2014-12-05',
1015 "type": 'type:date'
1016 }
1017 ]
1018 }
1019 ]
Nils Diewald7c8ced22015-04-15 19:21:00 +00001020 });
1021
1022 expect(docGroup.operation()).toEqual('or');
1023 var e = docGroup.element();
1024 expect(e.getAttribute('class')).toEqual('docGroup');
1025 expect(e.getAttribute('data-operation')).toEqual('or');
1026
1027 expect(e.children[0].getAttribute('class')).toEqual('doc');
1028 var docop = e.children[0].lastChild;
Akron0b489ad2018-02-02 16:49:32 +01001029 expect(docop.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001030 expect(docop.children[0].getAttribute('class')).toEqual('and');
1031 expect(docop.children[1].getAttribute('class')).toEqual('or');
1032 expect(docop.children[2].getAttribute('class')).toEqual('delete');
1033
1034 expect(e.children[1].getAttribute('class')).toEqual('docGroup');
1035 expect(e.children[1].getAttribute('data-operation')).toEqual('and');
1036
1037 // This and-operation can be "or"ed or "delete"d
1038 var secop = e.children[1].children[2];
Akron0b489ad2018-02-02 16:49:32 +01001039 expect(secop.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001040 expect(secop.children[0].getAttribute('class')).toEqual('or');
1041 expect(secop.children[1].getAttribute('class')).toEqual('delete');
1042
1043 // This or-operation can be "and"ed or "delete"d
Akron0b489ad2018-02-02 16:49:32 +01001044 expect(e.children[2].getAttribute('class')).toEqual('operators button-group');
1045 expect(e.lastChild.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001046 expect(e.lastChild.children[0].getAttribute('class')).toEqual('and');
1047 expect(e.lastChild.children[1].getAttribute('class')).toEqual('delete');
1048 });
1049 });
1050
Akronb19803c2018-08-16 16:39:42 +02001051 describe('KorAP.DocGroupRef element', function () {
1052 it('should be initializable', function () {
1053 var docGroupRef = docGroupRefClass.create(undefined, {
1054 "@type" : "koral:docGroupRef",
1055 "ref" : "@franz/myVC1"
1056 });
1057 expect(docGroupRef.ref()).toEqual("@franz/myVC1");
1058 var dgrE = docGroupRef.element();
1059
Akron3ad46942018-08-22 16:47:14 +02001060 expect(dgrE.children[0].firstChild.data).toEqual("referTo");
Akronb19803c2018-08-16 16:39:42 +02001061 expect(dgrE.children[0].tagName).toEqual("SPAN");
1062 expect(dgrE.children[0].classList.contains("key")).toBeTruthy();
1063 expect(dgrE.children[0].classList.contains("fixed")).toBeTruthy();
1064 expect(dgrE.children[1].firstChild.data).toEqual("@franz/myVC1");
1065 expect(dgrE.children[1].tagName).toEqual("SPAN");
1066 expect(dgrE.children[1].classList.contains("value")).toBeTruthy();
1067 expect(dgrE.children[1].getAttribute("data-type")).toEqual("string");
1068 });
1069
1070 it('should be modifiable on reference', function () {
1071 var docGroupRef = docGroupRefClass.create(undefined, {
1072 "@type" : "koral:docGroupRef",
1073 "ref" : "@franz/myVC1"
1074 });
1075 var dgrE = docGroupRef.element();
1076 expect(docGroupRef.toQuery()).toEqual("referTo \"@franz/myVC1\"");
1077 dgrE.children[1].click();
1078
1079 var input = dgrE.children[1].firstChild;
1080 expect(input.tagName).toEqual("INPUT");
1081 input.value = "Versuch";
1082
1083 var event = new KeyboardEvent("keypress", {
1084 "key" : "[Enter]",
1085 "keyCode" : 13
1086 });
1087
1088 input.dispatchEvent(event);
1089 expect(docGroupRef.toQuery()).toEqual("referTo \"Versuch\"");
1090 });
1091 });
1092
1093
Akrone4961b12017-05-10 21:04:46 +02001094 describe('KorAP.VirtualCorpus', function () {
Nils Diewald7c8ced22015-04-15 19:21:00 +00001095 var simpleGroupFactory = buildFactory(docGroupClass, {
1096 "@type" : "koral:docGroup",
1097 "operation" : "operation:and",
1098 "operands" : [
Akron712733a2018-04-05 18:17:47 +02001099 {
1100 "@type": 'koral:doc',
1101 "key" : 'author',
1102 "match": 'match:eq',
1103 "value": 'Max Birkendale',
1104 "type": 'type:string'
1105 },
1106 {
1107 "@type": 'koral:doc',
1108 "key": 'pubDate',
1109 "match": 'match:eq',
1110 "value": '2014-12-05',
1111 "type": 'type:date'
1112 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00001113 ]
1114 });
1115
1116 var nestedGroupFactory = buildFactory(vcClass, {
1117 "@type" : "koral:docGroup",
1118 "operation" : "operation:or",
1119 "operands" : [
Akron712733a2018-04-05 18:17:47 +02001120 {
1121 "@type": 'koral:doc',
1122 "key" : 'author',
1123 "match": 'match:eq',
1124 "value": 'Max Birkendale',
1125 "type": 'type:string'
1126 },
1127 {
1128 "@type" : "koral:docGroup",
1129 "operation" : "operation:and",
1130 "operands" : [
1131 {
1132 "@type": 'koral:doc',
1133 "key": 'pubDate',
1134 "match": 'match:geq',
1135 "value": '2014-05-12',
1136 "type": 'type:date'
1137 },
1138 {
1139 "@type": 'koral:doc',
1140 "key": 'pubDate',
1141 "match": 'match:leq',
1142 "value": '2014-12-05',
1143 "type": 'type:date'
1144 }
1145 ]
1146 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00001147 ]
1148 });
1149
1150 var flatGroupFactory = buildFactory(vcClass, {
1151 "@type" : "koral:docGroup",
1152 "operation" : "operation:and",
1153 "operands" : [
Akron712733a2018-04-05 18:17:47 +02001154 {
1155 "@type": 'koral:doc',
1156 "key": 'pubDate',
1157 "match": 'match:geq',
1158 "value": '2014-05-12',
1159 "type": 'type:date'
1160 },
1161 {
1162 "@type": 'koral:doc',
1163 "key": 'pubDate',
1164 "match": 'match:leq',
1165 "value": '2014-12-05',
1166 "type": 'type:date'
1167 },
1168 {
1169 "@type": 'koral:doc',
1170 "key": 'foo',
1171 "match": 'match:eq',
1172 "value": 'bar',
1173 "type": 'type:string'
1174 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00001175 ]
1176 });
1177
1178 it('should be initializable', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00001179 var vc = vcClass.create();
Nils Diewald7c8ced22015-04-15 19:21:00 +00001180 expect(vc.element().getAttribute('class')).toEqual('vc');
1181 expect(vc.root().element().getAttribute('class')).toEqual('doc unspecified');
1182
1183 // Not removable
1184 expect(vc.root().element().lastChild.children.length).toEqual(0);
1185 });
1186
1187 it('should be based on a doc', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00001188 var vc = vcClass.create().fromJson({
Akron712733a2018-04-05 18:17:47 +02001189 "@type" : "koral:doc",
1190 "key":"Titel",
1191 "value":"Baum",
1192 "match":"match:eq"
Nils Diewald7c8ced22015-04-15 19:21:00 +00001193 });
1194
1195 expect(vc.element().getAttribute('class')).toEqual('vc');
1196 expect(vc.root().element().getAttribute('class')).toEqual('doc');
1197 expect(vc.root().key()).toEqual('Titel');
1198 expect(vc.root().value()).toEqual('Baum');
1199 expect(vc.root().matchop()).toEqual('eq');
1200
1201 var docE = vc.root().element();
1202 expect(docE.children[0].firstChild.data).toEqual('Titel');
1203 expect(docE.children[1].firstChild.data).toEqual('eq');
1204 expect(docE.children[1].getAttribute('data-type')).toEqual('string');
1205 expect(docE.children[2].firstChild.data).toEqual('Baum');
1206 expect(docE.children[2].getAttribute('data-type')).toEqual('string');
1207 });
1208
1209 it('should be based on a docGroup', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00001210 var vc = vcClass.create().fromJson(simpleGroupFactory.create().toJson());
Nils Diewald7c8ced22015-04-15 19:21:00 +00001211
1212 expect(vc.element().getAttribute('class')).toEqual('vc');
1213 expect(vc.root().element().getAttribute('class')).toEqual('docGroup');
1214 expect(vc.root().operation()).toEqual('and');
1215
1216 var docGroup = vc.root();
1217
1218 var first = docGroup.getOperand(0);
1219 expect(first.key()).toEqual('author');
1220 expect(first.value()).toEqual('Max Birkendale');
1221 expect(first.matchop()).toEqual('eq');
1222
1223 var second = docGroup.getOperand(1);
1224 expect(second.key()).toEqual('pubDate');
1225 expect(second.value()).toEqual('2014-12-05');
1226 expect(second.matchop()).toEqual('eq');
1227 });
1228
Akronb19803c2018-08-16 16:39:42 +02001229 it('should be based on a docGroupRef', function () {
1230 var vc = vcClass.create().fromJson({
1231 "@type" : "koral:docGroupRef",
1232 "ref":"myCorpus"
1233 });
1234
Akronadab5e52018-08-20 13:50:53 +02001235 // iv class="doc groupref"><span class="key fixed">@referTo</span><span data-type="string" class="value">myCorpus</span>
1236 var vcE = vc.builder();
1237 expect(vcE.getAttribute('class')).toEqual('builder');
Akronb19803c2018-08-16 16:39:42 +02001238 expect(vcE.firstChild.tagName).toEqual('DIV');
1239 expect(vcE.firstChild.classList.contains('groupref')).toBeTruthy();
1240
1241 expect(vcE.firstChild.firstChild.tagName).toEqual('SPAN');
1242 expect(vcE.firstChild.firstChild.classList.contains('key')).toBeTruthy();
1243 expect(vcE.firstChild.firstChild.classList.contains('fixed')).toBeTruthy();
1244
Akron3ad46942018-08-22 16:47:14 +02001245 expect(vcE.firstChild.firstChild.textContent).toEqual("referTo");
Akronb19803c2018-08-16 16:39:42 +02001246
1247 expect(vcE.firstChild.children[1].tagName).toEqual('SPAN');
1248 expect(vcE.firstChild.children[1].classList.contains('value')).toBeTruthy();
1249 expect(vcE.firstChild.children[1].getAttribute('data-type')).toEqual('string');
1250 expect(vcE.firstChild.children[1].textContent).toEqual("myCorpus");
1251 });
Nils Diewald7c8ced22015-04-15 19:21:00 +00001252
1253 it('should be based on a nested docGroup', function () {
1254 var vc = nestedGroupFactory.create();
1255
Akronadab5e52018-08-20 13:50:53 +02001256 expect(vc.builder().getAttribute('class')).toEqual('builder');
1257 expect(vc.builder().firstChild.getAttribute('class')).toEqual('docGroup');
1258 expect(vc.builder().firstChild.children[0].getAttribute('class')).toEqual('doc');
1259 var dg = vc.builder().firstChild.children[1];
Nils Diewald7c8ced22015-04-15 19:21:00 +00001260 expect(dg.getAttribute('class')).toEqual('docGroup');
1261 expect(dg.children[0].getAttribute('class')).toEqual('doc');
1262 expect(dg.children[1].getAttribute('class')).toEqual('doc');
Akron0b489ad2018-02-02 16:49:32 +01001263 expect(dg.children[2].getAttribute('class')).toEqual('operators button-group');
Akronadab5e52018-08-20 13:50:53 +02001264 expect(vc.builder().firstChild.children[2].getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001265 });
1266
Akronb19803c2018-08-16 16:39:42 +02001267 it('should be based on a nested docGroupRef', function () {
1268 var vc = vcClass.create().fromJson({
1269 "@type" : "koral:docGroup",
1270 "operation" : "operation:and",
1271 "operands" : [{
1272 "@type" : "koral:docGroupRef",
1273 "ref":"myCorpus"
1274 },{
1275 "@type" : "koral:doc",
1276 "key":"Titel",
1277 "value":"Baum",
1278 "match":"match:eq"
1279 }]
1280 });
1281
1282 expect(vc._root.ldType()).toEqual("docGroup");
1283
1284 expect(vc.toQuery()).toEqual('referTo "myCorpus" & Titel = "Baum"');
1285 });
1286
1287
Nils Diewald7c8ced22015-04-15 19:21:00 +00001288 it('should be modifiable by deletion in flat docGroups', function () {
1289 var vc = flatGroupFactory.create();
1290 var docGroup = vc.root();
1291
1292 expect(docGroup.element().getAttribute('class')).toEqual('docGroup');
1293
1294 var doc = docGroup.getOperand(1);
1295 expect(doc.key()).toEqual("pubDate");
1296 expect(doc.value()).toEqual("2014-12-05");
1297
1298 // Remove operand 1
1299 expect(docGroup.delOperand(doc).update()).not.toBeUndefined();
1300 expect(doc._element).toEqual(undefined);
1301
1302 doc = docGroup.getOperand(1);
1303 expect(doc.key()).toEqual("foo");
1304
1305 // Remove operand 1
1306 expect(docGroup.delOperand(doc).update()).not.toBeUndefined();
1307 expect(doc._element).toEqual(undefined);
1308
1309 // Only one operand left ...
1310 expect(docGroup.getOperand(1)).toBeUndefined();
1311 // ... but there shouldn't be a group anymore at all!
1312 expect(docGroup.getOperand(0)).toBeUndefined();
1313
1314 var obj = vc.root();
1315 expect(obj.ldType()).toEqual("doc");
1316 expect(obj.key()).toEqual("pubDate");
1317 expect(obj.value()).toEqual("2014-05-12");
1318
1319 expect(obj.element().getAttribute('class')).toEqual('doc');
1320 });
1321
1322
1323 it('should be modifiable by deletion in nested docGroups (root case)', function () {
1324 var vc = nestedGroupFactory.create();
1325
1326 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001327 'author = "Max Birkendale" | (pubDate since 2014-05-12 & pubDate until 2014-12-05)'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001328 );
1329
1330 var docGroup = vc.root();
1331 expect(docGroup.ldType()).toEqual("docGroup");
1332 expect(docGroup.operation()).toEqual("or");
1333
1334 var doc = docGroup.getOperand(0);
1335 expect(doc.key()).toEqual("author");
1336 expect(doc.value()).toEqual("Max Birkendale");
1337
1338 docGroup = docGroup.getOperand(1);
1339 expect(docGroup.operation()).toEqual("and");
1340
1341 doc = docGroup.getOperand(0);
1342 expect(doc.key()).toEqual("pubDate");
1343 expect(doc.matchop()).toEqual("geq");
1344 expect(doc.value()).toEqual("2014-05-12");
1345 expect(doc.type()).toEqual("date");
1346
1347 doc = docGroup.getOperand(1);
1348 expect(doc.key()).toEqual("pubDate");
1349 expect(doc.matchop()).toEqual("leq");
1350 expect(doc.value()).toEqual("2014-12-05");
1351 expect(doc.type()).toEqual("date");
1352
1353 // Remove first operand so everything becomes root
1354 expect(
Akron712733a2018-04-05 18:17:47 +02001355 vc.root().delOperand(
1356 vc.root().getOperand(0)
1357 ).update().ldType()
Nils Diewald7c8ced22015-04-15 19:21:00 +00001358 ).toEqual("docGroup");
1359
1360 expect(vc.root().ldType()).toEqual("docGroup");
1361 expect(vc.root().operation()).toEqual("and");
1362 expect(vc.root().getOperand(0).ldType()).toEqual("doc");
1363
1364 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001365 'pubDate since 2014-05-12 & pubDate until 2014-12-05'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001366 );
1367 });
1368
1369 it('should be modifiable by deletion in nested docGroups (resolve group case)', function () {
1370 var vc = nestedGroupFactory.create();
1371
1372 // Get nested group
1373 var firstGroup = vc.root().getOperand(1);
1374 firstGroup.append(simpleGroupFactory.create({ "operation" : "operation:or" }));
1375
1376 // Structur is now:
1377 // or(doc, and(doc, doc, or(doc, doc)))
1378
1379 // Get nested or in and
1380 var orGroup = vc.root().getOperand(1).getOperand(2);
1381 expect(orGroup.ldType()).toEqual("docGroup");
1382 expect(orGroup.operation()).toEqual("or");
1383
1384 // Remove
1385 // Structur is now:
1386 // or(doc, and(doc, doc, doc)))
1387 expect(orGroup.delOperand(orGroup.getOperand(0)).update().operation()).toEqual("and");
1388 expect(vc.root().getOperand(1).operands().length).toEqual(3);
1389 });
1390
1391 it('should be modifiable by deletion in nested docGroups (identical group case)', function () {
1392 var vc = nestedGroupFactory.create();
1393
1394 // Get nested group
1395 var firstGroup = vc.root().getOperand(1);
1396 firstGroup.append(simpleGroupFactory.create({
Akron712733a2018-04-05 18:17:47 +02001397 "operation" : "operation:or"
Nils Diewald7c8ced22015-04-15 19:21:00 +00001398 }));
1399 var oldAuthor = firstGroup.getOperand(2).getOperand(0);
1400 oldAuthor.key("title");
1401 oldAuthor.value("Der Birnbaum");
1402
1403 // Structur is now:
1404 // or(doc, and(doc, doc, or(doc, doc)))
1405 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001406 'author = "Max Birkendale" | ' +
1407 '(pubDate since 2014-05-12 & ' +
1408 'pubDate until 2014-12-05 & ' +
1409 '(title = "Der Birnbaum" | ' +
1410 'pubDate in 2014-12-05))'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001411 );
1412
1413 var andGroup = vc.root().getOperand(1);
1414
1415 // Get leading docs in and
1416 var doc1 = andGroup.getOperand(0);
1417 expect(doc1.ldType()).toEqual("doc");
1418 expect(doc1.value()).toEqual("2014-05-12");
1419 var doc2 = andGroup.getOperand(1);
1420 expect(doc2.ldType()).toEqual("doc");
1421 expect(doc2.value()).toEqual("2014-12-05");
1422
1423 // Remove 2
1424 expect(
Akron712733a2018-04-05 18:17:47 +02001425 andGroup.delOperand(doc2).update().operation()
Nils Diewald7c8ced22015-04-15 19:21:00 +00001426 ).toEqual("and");
1427 // Structur is now:
1428 // or(doc, and(doc, or(doc, doc)))
1429
1430 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001431 'author = "Max Birkendale"' +
1432 ' | (pubDate since 2014-05-12 & ' +
1433 '(title = "Der Birnbaum" | pubDate in 2014-12-05))'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001434 );
1435
1436
1437 // Remove 1
1438 expect(andGroup.delOperand(doc1).update().operation()).toEqual("or");
1439 // Structur is now:
1440 // or(doc, doc, doc)
1441
1442 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001443 'author = "Max Birkendale" | title = "Der Birnbaum" | pubDate in 2014-12-05'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001444 );
1445 });
1446
1447 it('should be reducible to unspecification', function () {
1448 var vc = demoFactory.create();
1449
1450 expect(vc.toQuery()).toEqual(vc.root().toQuery());
1451 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001452 '(Titel = "Baum" & Veröffentlichungsort = "hihi" & ' +
1453 '(Titel = "Baum" | Veröffentlichungsort = "hihi")) ' +
1454 '| Untertitel ~ "huhu"');
Akrond141a362018-07-10 18:12:13 +02001455 expect(vc.root().element().lastChild.children[0].innerText).toEqual('and');
1456 expect(vc.root().element().lastChild.children[1].innerText).toEqual('×');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001457 expect(vc.root().delOperand(vc.root().getOperand(0)).update()).not.toBeUndefined();
Akron712733a2018-04-05 18:17:47 +02001458 expect(vc.toQuery()).toEqual('Untertitel ~ "huhu"');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001459
1460 var lc = vc.root().element().lastChild;
Akrond141a362018-07-10 18:12:13 +02001461 expect(lc.children[0].innerText).toEqual('and');
1462 expect(lc.children[1].innerText).toEqual('or');
1463 expect(lc.children[2].innerText).toEqual('×');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001464
1465 // Clean everything
1466 vc.clean();
1467 expect(vc.toQuery()).toEqual('');
1468 });
1469
1470 it('should flatten on import', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00001471 var vc = vcClass.create().fromJson({
Akron712733a2018-04-05 18:17:47 +02001472 "@type":"koral:docGroup",
1473 "operation":"operation:or",
1474 "operands":[
1475 {
1476 "@type":"koral:docGroup",
1477 "operation":"operation:or",
1478 "operands":[
Nils Diewald7c8ced22015-04-15 19:21:00 +00001479 {
Akron712733a2018-04-05 18:17:47 +02001480 "@type":"koral:doc",
1481 "key":"Titel",
1482 "value":"Baum",
1483 "match":"match:eq"
Nils Diewald7c8ced22015-04-15 19:21:00 +00001484 },
1485 {
Akron712733a2018-04-05 18:17:47 +02001486 "@type":"koral:doc",
1487 "key":"Veröffentlichungsort",
1488 "value":"hihi",
1489 "match":"match:eq"
Nils Diewald7c8ced22015-04-15 19:21:00 +00001490 },
1491 {
Akron712733a2018-04-05 18:17:47 +02001492 "@type":"koral:docGroup",
1493 "operation":"operation:or",
1494 "operands":[
1495 {
1496 "@type":"koral:doc",
1497 "key":"Titel",
1498 "value":"Baum",
1499 "match":"match:eq"
1500 },
1501 {
1502 "@type":"koral:doc",
1503 "key":"Veröffentlichungsort",
1504 "value":"hihi",
1505 "match":"match:eq"
1506 }
1507 ]
Nils Diewald7c8ced22015-04-15 19:21:00 +00001508 }
Akron712733a2018-04-05 18:17:47 +02001509 ]
1510 },
1511 {
1512 "@type":"koral:doc",
1513 "key":"Untertitel",
1514 "value":"huhu",
1515 "match":"match:contains"
1516 }
1517 ]
Nils Diewald7c8ced22015-04-15 19:21:00 +00001518 });
Nils Diewaldfda29d92015-01-22 17:28:01 +00001519
Nils Diewald7c8ced22015-04-15 19:21:00 +00001520 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001521 'Titel = "Baum" | Veröffentlichungsort = "hihi" | Untertitel ~ "huhu"'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001522 );
Nils Diewald86dad5b2015-01-28 15:09:07 +00001523 });
Akron1bdf5272018-07-24 18:51:30 +02001524
1525 it('should be deserializable from collection 1', function () {
1526 var kq = {
1527 "matches":["..."],
1528 "collection":{
1529 "@type": "koral:docGroup",
1530 "operation": "operation:or",
1531 "operands": [{
1532 "@type": "koral:docGroup",
1533 "operation": "operation:and",
1534 "operands": [
1535 {
1536 "@type": "koral:doc",
1537 "key": "title",
1538 "match": "match:eq",
1539 "value": "Der Birnbaum",
1540 "type": "type:string"
1541 },
1542 {
1543 "@type": "koral:doc",
1544 "key": "pubPlace",
1545 "match": "match:eq",
1546 "value": "Mannheim",
1547 "type": "type:string"
1548 },
1549 {
1550 "@type": "koral:docGroup",
1551 "operation": "operation:or",
1552 "operands": [
1553 {
1554 "@type": "koral:doc",
1555 "key": "subTitle",
1556 "match": "match:eq",
1557 "value": "Aufzucht und Pflege",
1558 "type": "type:string"
1559 },
1560 {
1561 "@type": "koral:doc",
1562 "key": "subTitle",
1563 "match": "match:eq",
1564 "value": "Gedichte",
1565 "type": "type:string"
1566 }
1567 ]
1568 }
1569 ]
1570 },{
1571 "@type": "koral:doc",
1572 "key": "pubDate",
1573 "match": "match:geq",
1574 "value": "2015-03-05",
1575 "type": "type:date",
1576 "rewrites" : [{
1577 "@type" : "koral:rewrite",
1578 "operation" : "operation:modification",
1579 "src" : "querySerializer",
1580 "scope" : "tree"
1581 }]
1582 }]
1583 }
1584 };
1585
1586 var vc = vcClass.create().fromJson(kq["collection"]);
1587 expect(vc.toQuery()).toEqual('(title = "Der Birnbaum" & pubPlace = "Mannheim" & (subTitle = "Aufzucht und Pflege" | subTitle = "Gedichte")) | pubDate since 2015-03-05');
1588 });
1589
1590 it('should be deserializable from collection 2', function () {
1591 var kq = {
1592 "@context": "http://korap.ids-mannheim.de/ns/KoralQuery/v0.3/context.jsonld",
1593 "meta": {},
1594 "query": {
1595 "@type": "koral:token",
1596 "wrap": {
1597 "@type": "koral:term",
1598 "match": "match:eq",
1599 "layer": "orth",
1600 "key": "Baum",
1601 "foundry": "opennlp",
1602 "rewrites": [
1603 {
1604 "@type": "koral:rewrite",
1605 "src": "Kustvakt",
1606 "operation": "operation:injection",
1607 "scope": "foundry"
1608 }
1609 ]
1610 },
1611 "idn": "Baum_2227",
1612 "rewrites": [
1613 {
1614 "@type": "koral:rewrite",
1615 "src": "Kustvakt",
1616 "operation": "operation:injection",
1617 "scope": "idn"
1618 }
1619 ]
1620 },
1621 "collection": {
1622 "@type": "koral:docGroup",
1623 "operation": "operation:and",
1624 "operands": [
1625 {
1626 "@type": "koral:doc",
1627 "match": "match:eq",
1628 "type": "type:regex",
1629 "value": "CC-BY.*",
1630 "key": "availability"
1631 },
1632 {
1633 "@type": "koral:doc",
1634 "match": "match:eq",
1635 "type":"type:text",
1636 "value": "Goethe",
1637 "key": "author"
1638 }
1639 ],
1640 "rewrites": [
1641 {
1642 "@type": "koral:rewrite",
1643 "src": "Kustvakt",
1644 "operation": "operation:insertion",
1645 "scope": "availability(FREE)"
1646 }
1647 ]
1648 },
1649 "matches": []
1650 };
1651
1652 var vc = vcClass.create().fromJson(kq["collection"]);
1653 expect(vc.toQuery()).toEqual('availability = /CC-BY.*/ & author = "Goethe"');
1654 });
Nils Diewald86dad5b2015-01-28 15:09:07 +00001655
Akron8a670162018-08-28 10:09:13 +02001656 it('shouldn\'t be deserializable from collection with unknown type', function () {
1657 var kq = {
1658 "@type" : "koral:doc",
1659 "match": "match:eq",
1660 "type":"type:failure",
1661 "value": "Goethe",
1662 "key": "author"
1663 };
Akron1bdf5272018-07-24 18:51:30 +02001664
Akron8a670162018-08-28 10:09:13 +02001665 expect(function () {
1666 vcClass.create().fromJson(kq)
1667 }).toThrow(new Error("Unknown value type: string"));
1668 });
1669
1670 it('should return a name', function () {
1671 var vc = vcClass.create();
1672 expect(vc.getName()).toEqual(KorAP.Locale.VC_allCorpora);
1673
1674 vc = vcClass.create().fromJson({"@type" : "koral:docGroupRef", "ref" : "DeReKo"});
1675 expect(vc.getName()).toEqual("DeReKo");
1676
1677 vc = vcClass.create().fromJson({"@type" : "koral:doc", "key" : "author", "value" : "Peter"});
1678 expect(vc.getName()).toEqual(KorAP.Locale.VC_oneCollection);
1679 });
Akrond2474aa2018-08-28 12:06:27 +02001680
1681 it('should check for rewrites', function () {
1682
1683 var vc = vcClass.create().fromJson({
1684 "@type" : "koral:doc",
1685 "key" : "author",
1686 "value" : "Goethe",
1687 "rewrites" : [{
1688 "@type" : "koral:rewrite",
1689 "operation" : "operation:modification",
1690 "src" : "querySerializer",
1691 "scope" : "value"
1692 }]
1693 });
1694 expect(vc.wasRewritten()).toBeTruthy();
1695
1696 var nested = {
1697 "@type" : "koral:docGroup",
1698 "operation" : "operation:or",
1699 "operands" : [
1700 {
1701 "@type" : "koral:doc",
1702 "key" : "author",
1703 "value" : "Goethe"
1704 },
1705 {
1706 "@type" : "koral:docGroup",
1707 "operation" : "operation:and",
1708 "operands" : [
1709 {
1710 "@type": "koral:doc",
1711 "key" : "author",
1712 "value" : "Schiller"
1713 },
1714 {
1715 "@type": "koral:doc",
1716 "key" : "author",
1717 "value" : "Fontane"
1718 }
1719 ]
1720 }
1721 ]
1722 };
1723 vc = vcClass.create().fromJson(nested);
1724 expect(vc.wasRewritten()).toBe(false);
1725
1726 nested["operands"][1]["operands"][1]["rewrites"] = [{
1727 "@type" : "koral:rewrite",
1728 "operation" : "operation:modification",
1729 "src" : "querySerializer",
1730 "scope" : "tree"
1731 }];
1732 vc = vcClass.create().fromJson(nested);
1733 expect(vc.wasRewritten()).toBeTruthy();
1734 });
Akron1bdf5272018-07-24 18:51:30 +02001735 });
1736
1737
Nils Diewald7c8ced22015-04-15 19:21:00 +00001738 describe('KorAP.Operators', function () {
1739 it('should be initializable', function () {
1740 var op = operatorsClass.create(true, false, false);
1741 expect(op.and()).toBeTruthy();
1742 expect(op.or()).not.toBeTruthy();
1743 expect(op.del()).not.toBeTruthy();
1744
1745 op.and(false);
1746 expect(op.and()).not.toBeTruthy();
1747 expect(op.or()).not.toBeTruthy();
1748 expect(op.del()).not.toBeTruthy();
1749
1750 op.or(true);
1751 op.del(true);
1752 expect(op.and()).not.toBeTruthy();
1753 expect(op.or()).toBeTruthy();
1754 expect(op.del()).toBeTruthy();
1755
Akrond141a362018-07-10 18:12:13 +02001756 var e = op.update();
Akron0b489ad2018-02-02 16:49:32 +01001757 expect(e.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001758 expect(e.children[0].getAttribute('class')).toEqual('or');
Akrond141a362018-07-10 18:12:13 +02001759 expect(e.children[0].innerText).toEqual('or');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001760 expect(e.children[1].getAttribute('class')).toEqual('delete');
Akrond141a362018-07-10 18:12:13 +02001761 expect(e.children[1].innerText).toEqual('×');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001762
1763 op.and(true);
1764 op.del(false);
Akrond141a362018-07-10 18:12:13 +02001765 e = op.update();
Nils Diewald7c8ced22015-04-15 19:21:00 +00001766
Akron0b489ad2018-02-02 16:49:32 +01001767 expect(e.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001768 expect(e.children[0].getAttribute('class')).toEqual('and');
Akrond141a362018-07-10 18:12:13 +02001769 expect(e.children[0].innerText).toEqual('and');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001770 expect(e.children[1].getAttribute('class')).toEqual('or');
Akrond141a362018-07-10 18:12:13 +02001771 expect(e.children[1].innerText).toEqual('or');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001772 });
1773 });
1774
1775 describe('KorAP._delete (event)', function () {
1776 var complexVCFactory = buildFactory(vcClass,{
1777 "@type": 'koral:docGroup',
1778 'operation' : 'operation:and',
1779 'operands' : [
Akron712733a2018-04-05 18:17:47 +02001780 {
1781 "@type": 'koral:doc',
1782 "key": 'pubDate',
1783 "match": 'match:eq',
1784 "value": '2014-12-05',
1785 "type": 'type:date'
1786 },
1787 {
1788 "@type" : 'koral:docGroup',
1789 'operation' : 'operation:or',
1790 'operands' : [
1791 {
1792 '@type' : 'koral:doc',
1793 'key' : 'title',
1794 'value' : 'Hello World!'
1795 },
1796 {
1797 '@type' : 'koral:doc',
1798 'key' : 'foo',
1799 'value' : 'bar'
1800 }
1801 ]
1802 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00001803 ]
1804 });
1805
1806 it('should clean on root docs', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00001807 var vc = vcClass.create().fromJson({
Akron712733a2018-04-05 18:17:47 +02001808 "@type": 'koral:doc',
1809 "key": 'pubDate',
1810 "match": 'match:eq',
1811 "value": '2014-12-05',
1812 "type": 'type:date'
Nils Diewald86dad5b2015-01-28 15:09:07 +00001813 });
Nils Diewald7c8ced22015-04-15 19:21:00 +00001814 expect(vc.root().toQuery()).toEqual('pubDate in 2014-12-05');
Akron0b489ad2018-02-02 16:49:32 +01001815 expect(vc.root().element().lastChild.getAttribute('class')).toEqual('operators button-group');
Nils Diewald86dad5b2015-01-28 15:09:07 +00001816
Nils Diewald7c8ced22015-04-15 19:21:00 +00001817 // Clean with delete from root
1818 expect(vc.root().element().lastChild.lastChild.getAttribute('class')).toEqual('delete');
1819 _delOn(vc.root());
1820 expect(vc.root().toQuery()).toEqual('');
Akronebc96662018-08-29 17:36:20 +02001821 expect(vc.root().element().lastChild.lastChild.data).toEqual(KorAP.Locale.EMPTY);
1822 expect(vc.root().element().classList.contains('unspecified')).toEqual(true);
Nils Diewald7c8ced22015-04-15 19:21:00 +00001823 });
Nils Diewald86dad5b2015-01-28 15:09:07 +00001824
Nils Diewald7c8ced22015-04-15 19:21:00 +00001825 it('should remove on nested docs', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00001826 var vc = vcClass.create().fromJson(
Akron712733a2018-04-05 18:17:47 +02001827 {
1828 "@type": 'koral:docGroup',
1829 'operation' : 'operation:and',
1830 'operands' : [
1831 {
1832 "@type": 'koral:doc',
1833 "key": 'pubDate',
1834 "match": 'match:eq',
1835 "value": '2014-12-05',
1836 "type": 'type:date'
1837 },
1838 {
1839 "@type" : 'koral:doc',
1840 'key' : 'foo',
1841 'value' : 'bar'
1842 }
1843 ]
1844 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00001845 );
1846
1847 // Delete with direct element access
1848 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar"');
1849 _delOn(vc.root().getOperand(0));
1850
1851 expect(vc.toQuery()).toEqual('foo = "bar"');
1852 expect(vc.root().ldType()).toEqual('doc');
1853 });
1854
1855 it('should clean on doc groups', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00001856 var vc = vcClass.create().fromJson(
Akron712733a2018-04-05 18:17:47 +02001857 {
1858 "@type": 'koral:docGroup',
1859 'operation' : 'operation:and',
1860 'operands' : [
1861 {
1862 "@type": 'koral:doc',
1863 "key": 'pubDate',
1864 "match": 'match:eq',
1865 "value": '2014-12-05',
1866 "type": 'type:date'
1867 },
1868 {
1869 "@type" : 'koral:doc',
1870 'key' : 'foo',
1871 'value' : 'bar'
1872 }
1873 ]
1874 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00001875 );
1876
1877 // Cleanwith direct element access
1878 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar"');
1879 _delOn(vc.root());
1880 expect(vc.toQuery()).toEqual('');
1881 expect(vc.root().ldType()).toEqual('non');
1882 });
1883
1884 it('should remove on nested doc groups (case of ungrouping 1)', function () {
1885 var vc = complexVCFactory.create();
1886
1887 // Delete with direct element access
1888 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001889 'pubDate in 2014-12-05 & (title = "Hello World!" | foo = "bar")'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001890 );
1891
1892 // Remove hello world:
1893 _delOn(vc.root().getOperand(1).getOperand(0));
1894 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar"');
1895 expect(vc.root().ldType()).toEqual('docGroup');
1896 });
1897
1898 it('should remove on nested doc groups (case of ungrouping 2)', function () {
1899 var vc = complexVCFactory.create();
1900
1901 // Delete with direct element access
1902 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001903 'pubDate in 2014-12-05 & (title = "Hello World!" | foo = "bar")'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001904 );
1905
1906 // Remove bar
1907 _delOn(vc.root().getOperand(1).getOperand(1));
1908 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & title = "Hello World!"');
1909 expect(vc.root().ldType()).toEqual('docGroup');
1910 expect(vc.root().operation()).toEqual('and');
1911 });
1912
1913 it('should remove on nested doc groups (case of root changing)', function () {
1914 var vc = complexVCFactory.create();
1915
1916 // Delete with direct element access
1917 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001918 'pubDate in 2014-12-05 & ' +
1919 '(title = "Hello World!" | foo = "bar")'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001920 );
1921
1922 // Remove bar
1923 _delOn(vc.root().getOperand(0));
1924 expect(vc.toQuery()).toEqual('title = "Hello World!" | foo = "bar"');
1925 expect(vc.root().ldType()).toEqual('docGroup');
1926 expect(vc.root().operation()).toEqual('or');
1927 });
1928
1929 it('should remove on nested doc groups (list flattening)', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00001930 var vc = vcClass.create().fromJson(
Akron712733a2018-04-05 18:17:47 +02001931 {
1932 "@type": 'koral:docGroup',
1933 'operation' : 'operation:or',
1934 'operands' : [
1935 {
1936 "@type": 'koral:doc',
1937 "key": 'pubDate',
1938 "match": 'match:eq',
1939 "value": '2014-12-05',
1940 "type": 'type:date'
1941 },
1942 {
1943 "@type" : 'koral:doc',
1944 'key' : 'foo',
1945 'value' : 'bar'
1946 },
1947 {
1948 "@type": 'koral:docGroup',
1949 'operation' : 'operation:and',
1950 'operands' : [
1951 {
1952 "@type": 'koral:doc',
1953 "key": 'pubDate',
1954 "match": 'match:eq',
1955 "value": '2014-12-05',
1956 "type": 'type:date'
1957 },
1958 {
1959 "@type" : 'koral:docGroup',
1960 'operation' : 'operation:or',
1961 'operands' : [
1962 {
1963 '@type' : 'koral:doc',
1964 'key' : 'title',
1965 'value' : 'Hello World!'
1966 },
1967 {
1968 '@type' : 'koral:doc',
1969 'key' : 'yeah',
1970 'value' : 'juhu'
1971 }
1972 ]
1973 }
1974 ]
1975 }
1976 ]
1977 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00001978 );
1979
1980 // Delete with direct element access
1981 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001982 'pubDate in 2014-12-05 | foo = "bar" | ' +
1983 '(pubDate in 2014-12-05 & ' +
1984 '(title = "Hello World!" | yeah = "juhu"))'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001985 );
1986
1987 expect(vc.root().ldType()).toEqual('docGroup');
1988 expect(vc.root().operation()).toEqual('or');
1989
1990 // Operands and operators
Akronadab5e52018-08-20 13:50:53 +02001991 expect(vc.builder().firstChild.children.length).toEqual(4);
1992 expect(vc.builder().firstChild.lastChild.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001993
1994 // Remove inner group and flatten
1995 _delOn(vc.root().getOperand(2).getOperand(0));
1996
1997 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001998 'pubDate in 2014-12-05 | foo = "bar" | title = "Hello World!" | yeah = "juhu"'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001999 );
2000 expect(vc.root().ldType()).toEqual('docGroup');
2001 expect(vc.root().operation()).toEqual('or');
2002
2003 // Operands and operators
Akronadab5e52018-08-20 13:50:53 +02002004 expect(vc.builder().firstChild.children.length).toEqual(5);
2005 expect(vc.builder().firstChild.lastChild.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +00002006 });
2007 });
2008
2009 describe('KorAP._add (event)', function () {
2010 var complexVCFactory = buildFactory(vcClass,{
2011 "@type": 'koral:docGroup',
2012 'operation' : 'operation:and',
2013 'operands' : [
Akron712733a2018-04-05 18:17:47 +02002014 {
2015 "@type": 'koral:doc',
2016 "key": 'pubDate',
2017 "match": 'match:eq',
2018 "value": '2014-12-05',
2019 "type": 'type:date'
2020 },
2021 {
2022 "@type" : 'koral:docGroup',
2023 'operation' : 'operation:or',
2024 'operands' : [
2025 {
2026 '@type' : 'koral:doc',
2027 'key' : 'title',
2028 'value' : 'Hello World!'
2029 },
2030 {
2031 '@type' : 'koral:doc',
2032 'key' : 'foo',
2033 'value' : 'bar'
2034 }
2035 ]
2036 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00002037 ]
2038 });
2039
2040 it('should add new unspecified doc with "and"', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00002041 var vc = vcClass.create().fromJson(
Akron712733a2018-04-05 18:17:47 +02002042 {
2043 "@type": 'koral:docGroup',
2044 'operation' : 'operation:and',
2045 'operands' : [
2046 {
2047 "@type": 'koral:doc',
2048 "key": 'pubDate',
2049 "match": 'match:eq',
2050 "value": '2014-12-05',
2051 "type": 'type:date'
2052 },
2053 {
2054 "@type" : 'koral:doc',
2055 'key' : 'foo',
2056 'value' : 'bar'
Akronb19803c2018-08-16 16:39:42 +02002057 },
2058 {
2059 "@type" : "koral:docGroupRef",
2060 "ref" : "myCorpus"
Akron712733a2018-04-05 18:17:47 +02002061 }
2062 ]
2063 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00002064 );
2065
Akronb19803c2018-08-16 16:39:42 +02002066 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar" & referTo "myCorpus"');
Nils Diewald7c8ced22015-04-15 19:21:00 +00002067
Akronadab5e52018-08-20 13:50:53 +02002068 var fc = vc.builder().firstChild;
Nils Diewald7c8ced22015-04-15 19:21:00 +00002069 expect(fc.getAttribute('data-operation')).toEqual('and');
Akronb19803c2018-08-16 16:39:42 +02002070 expect(fc.children.length).toEqual(4);
Akron0b489ad2018-02-02 16:49:32 +01002071 expect(fc.lastChild.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +00002072 expect(fc.children[0].getAttribute('class')).toEqual('doc');
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');
Nils Diewald7c8ced22015-04-15 19:21:00 +00002075
2076 // add with 'and' in the middle
2077 _andOn(vc.root().getOperand(0));
Akronb19803c2018-08-16 16:39:42 +02002078 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar" & referTo "myCorpus"');
Nils Diewald7c8ced22015-04-15 19:21:00 +00002079
Akronadab5e52018-08-20 13:50:53 +02002080 fc = vc.builder().firstChild;
Nils Diewald7c8ced22015-04-15 19:21:00 +00002081 expect(fc.getAttribute('data-operation')).toEqual('and');
Akronb19803c2018-08-16 16:39:42 +02002082 expect(fc.children.length).toEqual(5);
Akron0b489ad2018-02-02 16:49:32 +01002083 expect(fc.lastChild.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +00002084
2085 expect(fc.children[0].getAttribute('class')).toEqual('doc');
2086 expect(fc.children[1].getAttribute('class')).toEqual('doc unspecified');
2087 expect(fc.children[2].getAttribute('class')).toEqual('doc');
Akronb19803c2018-08-16 16:39:42 +02002088 expect(fc.children[3].getAttribute('class')).toEqual('doc groupref');
2089 expect(fc.children[4].classList.contains('button-group')).toBeTruthy();
2090 expect(fc.children.length).toEqual(5);
2091
2092 _andOn(vc.root().getOperand(3));
2093 expect(fc.children[0].getAttribute('class')).toEqual('doc');
2094 expect(fc.children[1].getAttribute('class')).toEqual('doc unspecified');
2095 expect(fc.children[2].getAttribute('class')).toEqual('doc');
2096 expect(fc.children[3].getAttribute('class')).toEqual('doc groupref');
2097 expect(fc.children[4].getAttribute('class')).toEqual('doc unspecified');
2098 expect(fc.children[5].classList.contains('button-group')).toBeTruthy();
2099 expect(fc.children.length).toEqual(6);
2100
Nils Diewald7c8ced22015-04-15 19:21:00 +00002101 });
2102
Akronb19803c2018-08-16 16:39:42 +02002103
Nils Diewald7c8ced22015-04-15 19:21:00 +00002104 it('should add new unspecified doc with "or"', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00002105 var vc = vcClass.create().fromJson(
Akron712733a2018-04-05 18:17:47 +02002106 {
2107 "@type": 'koral:docGroup',
2108 'operation' : 'operation:and',
2109 'operands' : [
2110 {
2111 "@type": 'koral:doc',
2112 "key": 'pubDate',
2113 "match": 'match:eq',
2114 "value": '2014-12-05',
2115 "type": 'type:date'
2116 },
2117 {
2118 "@type" : 'koral:doc',
2119 'key' : 'foo',
2120 'value' : 'bar'
Akronb19803c2018-08-16 16:39:42 +02002121 },
2122 {
2123 "@type" : "koral:docGroupRef",
2124 "ref" : "myCorpus"
Akron712733a2018-04-05 18:17:47 +02002125 }
2126 ]
2127 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00002128 );
2129
Akronb19803c2018-08-16 16:39:42 +02002130 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar" & referTo "myCorpus"');
Nils Diewald7c8ced22015-04-15 19:21:00 +00002131
Akronadab5e52018-08-20 13:50:53 +02002132 var fc = vc.builder().firstChild;
Akronb19803c2018-08-16 16:39:42 +02002133 expect(fc.children.length).toEqual(4);
Akron0b489ad2018-02-02 16:49:32 +01002134 expect(fc.lastChild.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +00002135 expect(fc.children[0].getAttribute('class')).toEqual('doc');
2136 expect(fc.children[1].getAttribute('class')).toEqual('doc');
Akronb19803c2018-08-16 16:39:42 +02002137 expect(fc.children[2].getAttribute('class')).toEqual('doc groupref');
Nils Diewald7c8ced22015-04-15 19:21:00 +00002138
2139 // add with 'or' in the middle
2140 _orOn(vc.root().getOperand(0));
Akronb19803c2018-08-16 16:39:42 +02002141 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar" & referTo "myCorpus"');
Akronadab5e52018-08-20 13:50:53 +02002142 fc = vc.builder().firstChild;
Nils Diewald7c8ced22015-04-15 19:21:00 +00002143
2144 expect(fc.getAttribute('data-operation')).toEqual('and');
Akronb19803c2018-08-16 16:39:42 +02002145 expect(fc.children.length).toEqual(4);
Nils Diewald7c8ced22015-04-15 19:21:00 +00002146 expect(fc.children[0].getAttribute('class')).toEqual('docGroup');
2147 expect(fc.children[0].getAttribute('data-operation')).toEqual('or');
2148 expect(fc.children[1].getAttribute('class')).toEqual('doc');
Akronb19803c2018-08-16 16:39:42 +02002149 expect(fc.children[2].getAttribute('class')).toEqual('doc groupref');
2150 expect(fc.children[3].getAttribute('class')).toEqual('operators button-group');
Akron0b489ad2018-02-02 16:49:32 +01002151 expect(fc.lastChild.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +00002152
Akronadab5e52018-08-20 13:50:53 +02002153 fc = vc.builder().firstChild.firstChild;
Nils Diewald7c8ced22015-04-15 19:21:00 +00002154 expect(fc.children.length).toEqual(3);
2155 expect(fc.children[0].getAttribute('class')).toEqual('doc');
2156 expect(fc.children[1].getAttribute('class')).toEqual('doc unspecified');
Akron0b489ad2018-02-02 16:49:32 +01002157 expect(fc.children[2].getAttribute('class')).toEqual('operators button-group');
2158 expect(fc.lastChild.getAttribute('class')).toEqual('operators button-group');
Akronb19803c2018-08-16 16:39:42 +02002159
2160 _orOn(vc.root().getOperand(2));
Akronadab5e52018-08-20 13:50:53 +02002161 fc = vc.builder().firstChild;
Akronb19803c2018-08-16 16:39:42 +02002162 expect(fc.children.length).toEqual(4);
2163
2164 expect(fc.children[0].getAttribute('class')).toEqual('docGroup');
2165 expect(fc.children[1].getAttribute('class')).toEqual('doc');
2166 expect(fc.children[2].getAttribute('class')).toEqual('docGroup');
2167 expect(fc.children[3].getAttribute('class')).toEqual('operators button-group');
2168
Akronadab5e52018-08-20 13:50:53 +02002169 fc = vc.builder().firstChild.children[2];
Akronb19803c2018-08-16 16:39:42 +02002170 expect(fc.children[0].getAttribute('class')).toEqual('doc groupref');
2171 expect(fc.children[1].getAttribute('class')).toEqual('doc unspecified');
2172 expect(fc.children[2].getAttribute('class')).toEqual('operators button-group');
2173 expect(fc.lastChild.getAttribute('class')).toEqual('operators button-group');
2174
Nils Diewald7c8ced22015-04-15 19:21:00 +00002175 });
2176
2177 it('should add new unspecified doc with "and" before group', function () {
2178 var vc = demoFactory.create();
2179
2180 // Wrap with direct element access
2181 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02002182 '(Titel = "Baum" & ' +
2183 'Veröffentlichungsort = "hihi" & ' +
2184 '(Titel = "Baum" | ' +
2185 'Veröffentlichungsort = "hihi")) | ' +
2186 'Untertitel ~ "huhu"'
Nils Diewald7c8ced22015-04-15 19:21:00 +00002187 );
2188
2189 expect(vc.root().getOperand(0).ldType()).toEqual('docGroup');
2190 expect(vc.root().getOperand(0).operation()).toEqual('and');
2191 expect(vc.root().getOperand(0).operands().length).toEqual(3);
2192
2193 // Add unspecified on the second doc
2194 var secDoc = vc.root().getOperand(0).getOperand(1);
2195 expect(secDoc.value()).toEqual('hihi');
2196
2197 // Add
2198 _andOn(secDoc);
2199
2200 var fo = vc.root().getOperand(0);
2201
2202 expect(fo.ldType()).toEqual('docGroup');
2203 expect(fo.operation()).toEqual('and');
2204 expect(fo.operands().length).toEqual(4);
2205
2206 expect(fo.getOperand(0).ldType()).toEqual('doc');
2207 expect(fo.getOperand(1).ldType()).toEqual('doc');
2208 expect(fo.getOperand(2).ldType()).toEqual('non');
2209 expect(fo.getOperand(3).ldType()).toEqual('docGroup');
2210 });
2211
2212
2213 it('should remove a doc with an unspecified doc in a nested group', function () {
2214 var vc = demoFactory.create();
2215
2216 // Wrap with direct element access
2217 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02002218 '(Titel = "Baum" & Veröffentlichungsort = "hihi" & (Titel = "Baum" | Veröffentlichungsort = "hihi")) | Untertitel ~ "huhu"'
Nils Diewald7c8ced22015-04-15 19:21:00 +00002219 );
2220
2221 var fo = vc.root().getOperand(0).getOperand(0);
2222 expect(fo.key()).toEqual('Titel');
2223 expect(fo.value()).toEqual('Baum');
2224
2225 // Add unspecified on the root group
2226 _orOn(fo);
2227
2228 fo = vc.root().getOperand(0).getOperand(0);
2229
2230 expect(fo.operation()).toEqual('or');
2231 expect(fo.getOperand(0).ldType()).toEqual('doc');
2232 expect(fo.getOperand(1).ldType()).toEqual('non');
2233
2234 // Delete document
2235 _delOn(fo.getOperand(0));
2236
2237 // The operand is now non
2238 expect(vc.root().getOperand(0).getOperand(0).ldType()).toEqual('non');
2239 expect(vc.root().getOperand(0).getOperand(1).ldType()).toEqual('doc');
2240 expect(vc.root().getOperand(0).getOperand(2).ldType()).toEqual('docGroup');
2241 });
2242
2243
Akron712733a2018-04-05 18:17:47 +02002244 it('should remove an unspecified doc with a doc in a nested group', function () {
Nils Diewald7c8ced22015-04-15 19:21:00 +00002245 var vc = demoFactory.create();
2246
2247 // Wrap with direct element access
2248 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02002249 '(Titel = "Baum" & ' +
2250 'Veröffentlichungsort = "hihi" & ' +
2251 '(Titel = "Baum" ' +
2252 '| Veröffentlichungsort = "hihi")) | ' +
2253 'Untertitel ~ "huhu"'
Nils Diewald7c8ced22015-04-15 19:21:00 +00002254 );
2255
2256 var fo = vc.root().getOperand(0).getOperand(0);
2257 expect(fo.key()).toEqual('Titel');
2258 expect(fo.value()).toEqual('Baum');
2259
2260 // Add unspecified on the root group
2261 _orOn(fo);
2262
2263 fo = vc.root().getOperand(0).getOperand(0);
2264
2265 expect(fo.operation()).toEqual('or');
2266 expect(fo.getOperand(0).ldType()).toEqual('doc');
2267 expect(fo.getOperand(1).ldType()).toEqual('non');
2268
2269 // Delete unspecified doc
2270 _delOn(fo.getOperand(1));
2271
2272 // The operand is now non
2273 fo = vc.root().getOperand(0);
2274 expect(fo.getOperand(0).ldType()).toEqual('doc');
2275 expect(fo.getOperand(0).key()).toEqual('Titel');
2276 expect(fo.getOperand(0).value()).toEqual('Baum');
2277 expect(fo.getOperand(1).ldType()).toEqual('doc');
2278 expect(fo.getOperand(2).ldType()).toEqual('docGroup');
2279 });
2280
2281
2282 it('should add on parent group (case "and")', function () {
2283 var vc = complexVCFactory.create();
2284
2285 // Wrap with direct element access
2286 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02002287 'pubDate in 2014-12-05 & (title = "Hello World!" | foo = "bar")'
Nils Diewald7c8ced22015-04-15 19:21:00 +00002288 );
2289
2290 expect(vc.root().operands().length).toEqual(2);
2291
2292 // Add unspecified on the root group
2293 _andOn(vc.root().getOperand(1));
2294 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02002295 'pubDate in 2014-12-05 & (title = "Hello World!" | foo = "bar")'
Nils Diewald7c8ced22015-04-15 19:21:00 +00002296 );
2297
2298 expect(vc.root().ldType()).toEqual('docGroup');
2299 expect(vc.root().operands().length).toEqual(3);
2300 expect(vc.root().getOperand(0).ldType()).toEqual('doc');
2301 expect(vc.root().getOperand(1).ldType()).toEqual('docGroup');
2302 expect(vc.root().getOperand(1).operation()).toEqual('or');
2303 expect(vc.root().getOperand(2).ldType()).toEqual('non');
2304
2305 // Add another unspecified on the root group
2306 _andOn(vc.root().getOperand(1));
2307
2308 expect(vc.root().operands().length).toEqual(4);
2309 expect(vc.root().getOperand(0).ldType()).toEqual('doc');
2310 expect(vc.root().getOperand(1).ldType()).toEqual('docGroup');
2311 expect(vc.root().getOperand(2).ldType()).toEqual('non');
2312 expect(vc.root().getOperand(3).ldType()).toEqual('non');
2313
2314 // Add another unspecified after the first doc
2315 _andOn(vc.root().getOperand(0));
2316
2317 expect(vc.root().operands().length).toEqual(5);
2318 expect(vc.root().getOperand(0).ldType()).toEqual('doc');
2319 expect(vc.root().getOperand(1).ldType()).toEqual('non');
2320 expect(vc.root().getOperand(2).ldType()).toEqual('docGroup');
2321 expect(vc.root().getOperand(3).ldType()).toEqual('non');
2322 expect(vc.root().getOperand(4).ldType()).toEqual('non');
2323 });
2324
2325 it('should wrap on root', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00002326 var vc = vcClass.create().fromJson(
Akron712733a2018-04-05 18:17:47 +02002327 {
2328 "@type": 'koral:docGroup',
2329 'operation' : 'operation:and',
2330 'operands' : [
2331 {
2332 "@type": 'koral:doc',
2333 "key": 'pubDate',
2334 "match": 'match:eq',
2335 "value": '2014-12-05',
2336 "type": 'type:date'
2337 },
2338 {
2339 "@type" : 'koral:doc',
2340 'key' : 'foo',
2341 'value' : 'bar'
2342 }
2343 ]
2344 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00002345 );
2346
2347 // Wrap on root
2348 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar"');
2349 expect(vc.root().ldType()).toEqual('docGroup');
2350 expect(vc.root().operation()).toEqual('and');
2351 _orOn(vc.root());
2352 expect(vc.root().ldType()).toEqual('docGroup');
2353 expect(vc.root().operation()).toEqual('or');
2354
2355 expect(vc.root().getOperand(0).ldType()).toEqual('docGroup');
2356 expect(vc.root().getOperand(0).operation()).toEqual('and');
2357 });
2358
2359 it('should add on root (case "and")', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00002360 var vc = vcClass.create().fromJson(
Akron712733a2018-04-05 18:17:47 +02002361 {
2362 "@type": 'koral:doc',
2363 "key": 'pubDate',
2364 "match": 'match:eq',
2365 "value": '2014-12-05',
2366 "type": 'type:date'
2367 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00002368 );
2369
2370 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05');
2371 expect(vc.root().ldType()).toEqual('doc');
2372 expect(vc.root().key()).toEqual('pubDate');
2373 expect(vc.root().value()).toEqual('2014-12-05');
2374
2375 // Wrap on root
2376 _andOn(vc.root());
2377 expect(vc.root().ldType()).toEqual('docGroup');
2378 expect(vc.root().operation()).toEqual('and');
2379 });
2380
2381 it('should add on root (case "or")', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00002382 var vc = vcClass.create().fromJson(
Akron712733a2018-04-05 18:17:47 +02002383 {
2384 "@type": 'koral:doc',
2385 "key": 'pubDate',
2386 "match": 'match:eq',
2387 "value": '2014-12-05',
2388 "type": 'type:date'
2389 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00002390 );
2391
2392 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05');
2393 expect(vc.root().key()).toEqual('pubDate');
2394 expect(vc.root().value()).toEqual('2014-12-05');
2395
2396 // Wrap on root
2397 _orOn(vc.root());
2398 expect(vc.root().ldType()).toEqual('docGroup');
2399 expect(vc.root().operation()).toEqual('or');
2400 });
2401
2402 it('should support multiple sub groups per group', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00002403 var vc = vcClass.create().fromJson(
Akron712733a2018-04-05 18:17:47 +02002404 {
2405 "@type": 'koral:docGroup',
2406 'operation' : 'operation:or',
2407 'operands' : [
2408 {
2409 "@type": 'koral:docGroup',
2410 'operation' : 'operation:and',
2411 'operands' : [
2412 {
2413 "@type": 'koral:doc',
2414 "key": 'title',
2415 "value": 't1',
2416 },
2417 {
2418 "@type" : 'koral:doc',
2419 'key' : 'title',
2420 'value' : 't2'
2421 }
2422 ]
2423 },
2424 {
2425 "@type": 'koral:docGroup',
2426 'operation' : 'operation:and',
2427 'operands' : [
2428 {
2429 "@type": 'koral:doc',
2430 "key": 'title',
2431 "value": 't3',
2432 },
2433 {
2434 "@type" : 'koral:doc',
2435 'key' : 'title',
2436 'value' : 't4'
2437 }
2438 ]
2439 }
2440 ]
2441 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00002442 );
2443 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02002444 '(title = "t1" & title = "t2") | ' +
2445 '(title = "t3" & title = "t4")'
Nils Diewald7c8ced22015-04-15 19:21:00 +00002446 );
2447 expect(vc.root().operation()).toEqual('or');
2448 expect(vc.root().getOperand(0).toQuery()).toEqual('title = "t1" & title = "t2"');
2449 expect(vc.root().getOperand(1).toQuery()).toEqual('title = "t3" & title = "t4"');
2450
2451 _andOn(vc.root());
2452
2453 expect(vc.root().operation()).toEqual('and');
2454 expect(vc.root().getOperand(0).ldType()).toEqual('docGroup');
2455 expect(vc.root().getOperand(1).ldType()).toEqual('non');
2456 });
2457 });
2458
Nils Diewald6283d692015-04-23 20:32:53 +00002459
2460 describe('KorAP.Rewrite', function () {
Nils Diewald7c8ced22015-04-15 19:21:00 +00002461 it('should be initializable', function () {
2462 var rewrite = rewriteClass.create({
Akron712733a2018-04-05 18:17:47 +02002463 "@type" : "koral:rewrite",
2464 "operation" : "operation:modification",
2465 "src" : "querySerializer",
2466 "scope" : "tree"
Nils Diewald86dad5b2015-01-28 15:09:07 +00002467 });
Nils Diewald7c8ced22015-04-15 19:21:00 +00002468 expect(rewrite.toString()).toEqual('Modification of "tree" by "querySerializer"');
2469 });
Nils Diewald86dad5b2015-01-28 15:09:07 +00002470
Nils Diewald7c8ced22015-04-15 19:21:00 +00002471 it('should be deserialized by docs', function () {
2472 var doc = docClass.create(
Akron712733a2018-04-05 18:17:47 +02002473 undefined,
2474 {
2475 "@type":"koral:doc",
2476 "key":"Titel",
2477 "value":"Baum",
2478 "match":"match:eq"
2479 });
Nils Diewald7c8ced22015-04-15 19:21:00 +00002480
2481 expect(doc.element().classList.contains('doc')).toBeTruthy();
2482 expect(doc.element().classList.contains('rewritten')).toBe(false);
2483
2484 doc = docClass.create(
Akron712733a2018-04-05 18:17:47 +02002485 undefined,
2486 {
2487 "@type":"koral:doc",
2488 "key":"Titel",
2489 "value":"Baum",
2490 "match":"match:eq",
2491 "rewrites" : [
2492 {
2493 "@type" : "koral:rewrite",
2494 "operation" : "operation:modification",
2495 "src" : "querySerializer",
2496 "scope" : "tree"
2497 }
2498 ]
2499 });
Nils Diewald7c8ced22015-04-15 19:21:00 +00002500
2501 expect(doc.element().classList.contains('doc')).toBeTruthy();
2502 expect(doc.element().classList.contains('rewritten')).toBeTruthy();
2503 });
Nils Diewald6283d692015-04-23 20:32:53 +00002504
Akron76c3dd62018-05-29 20:58:27 +02002505 it('should be described in a title attribute', function () {
2506
2507 doc = docClass.create(
2508 undefined,
2509 {
2510 "@type":"koral:doc",
2511 "key":"Titel",
2512 "value":"Baum",
2513 "match":"match:eq",
2514 "rewrites" : [
2515 {
2516 "@type" : "koral:rewrite",
2517 "operation" : "operation:modification",
2518 "src" : "querySerializer",
2519 "scope" : "tree"
2520 },
2521 {
2522 "@type" : "koral:rewrite",
2523 "operation" : "operation:injection",
2524 "src" : "me"
2525 }
2526 ]
2527 });
2528
2529 expect(doc.element().classList.contains('doc')).toBeTruthy();
2530 expect(doc.element().classList.contains('rewritten')).toBeTruthy();
2531 expect(doc.element().lastChild.getAttribute("title")).toEqual("querySerializer: tree (modification)\nme (injection)");
2532 });
2533
2534
Nils Diewald6283d692015-04-23 20:32:53 +00002535 xit('should be deserialized by docGroups', function () {
2536 var docGroup = docGroupClass.create(
Akron712733a2018-04-05 18:17:47 +02002537 undefined,
2538 {
2539 "@type" : "koral:docGroup",
2540 "operation" : "operation:or",
2541 "operands" : [
2542 {
2543 "@type" : "doc",
2544 "key" : "pubDate",
2545 "type" : "type:date",
2546 "value" : "2014-12-05"
2547 },
2548 {
2549 "@type" : "doc",
2550 "key" : "pubDate",
2551 "type" : "type:date",
2552 "value" : "2014-12-06"
2553 }
2554 ],
2555 "rewrites" : [
2556 {
2557 "@type" : "koral:rewrite",
2558 "operation" : "operation:modification",
2559 "src" : "querySerializer",
2560 "scope" : "tree"
2561 }
2562 ]
2563 }
Nils Diewald6283d692015-04-23 20:32:53 +00002564 );
2565
2566 expect(doc.element().classList.contains('docgroup')).toBeTruthy();
2567 expect(doc.element().classList.contains('rewritten')).toBe(false);
2568 });
Nils Diewald86dad5b2015-01-28 15:09:07 +00002569 });
Nils Diewaldf0c4f112015-05-05 12:56:59 +00002570
2571 describe('KorAP.stringValue', function () {
2572 it('should be initializable', function () {
2573 var sv = stringValClass.create();
2574 expect(sv.regex()).toBe(false);
2575 expect(sv.value()).toBe('');
Nils Diewaldc4c4b832015-05-05 16:00:08 +00002576
2577 sv = stringValClass.create('Baum');
2578 expect(sv.regex()).toBe(false);
2579 expect(sv.value()).toBe('Baum');
2580
2581 sv = stringValClass.create('Baum', false);
2582 expect(sv.regex()).toBe(false);
2583 expect(sv.value()).toBe('Baum');
2584
2585 sv = stringValClass.create('Baum', true);
2586 expect(sv.regex()).toBe(true);
2587 expect(sv.value()).toBe('Baum');
2588 });
2589
2590 it('should be modifiable', function () {
2591 var sv = stringValClass.create();
2592 expect(sv.regex()).toBe(false);
2593 expect(sv.value()).toBe('');
2594
2595 expect(sv.value('Baum')).toBe('Baum');
2596 expect(sv.value()).toBe('Baum');
2597
2598 expect(sv.regex(true)).toBe(true);
2599 expect(sv.regex()).toBe(true);
2600 });
2601
2602 it('should have a toggleble regex value', function () {
2603 var sv = stringValClass.create();
Nils Diewald7991a3f2015-05-19 14:12:37 +00002604
2605 expect(sv.element().firstChild.value).toBe('');
2606 sv.element().firstChild.value = 'der'
2607 expect(sv.element().firstChild.value).toBe('der');
2608
Nils Diewaldc4c4b832015-05-05 16:00:08 +00002609 expect(sv.regex()).toBe(false);
2610
2611 sv.toggleRegex();
Nils Diewald7991a3f2015-05-19 14:12:37 +00002612 expect(sv.element().firstChild.value).toBe('der');
Nils Diewaldc4c4b832015-05-05 16:00:08 +00002613 expect(sv.regex()).toBe(true);
Nils Diewald7991a3f2015-05-19 14:12:37 +00002614 sv.element().firstChild.value = 'derbe'
Nils Diewaldc4c4b832015-05-05 16:00:08 +00002615
2616 sv.toggleRegex();
2617 expect(sv.regex()).toBe(false);
Nils Diewald7991a3f2015-05-19 14:12:37 +00002618 expect(sv.element().firstChild.value).toBe('derbe');
Nils Diewaldc4c4b832015-05-05 16:00:08 +00002619 });
2620
2621 it('should have an element', function () {
2622 var sv = stringValClass.create('der');
2623 expect(sv.element().nodeName).toBe('DIV');
2624 expect(sv.element().firstChild.nodeName).toBe('INPUT');
2625 expect(sv.element().firstChild.value).toBe('der');
2626 });
2627
2628 it('should have a classed element', function () {
2629 var sv = stringValClass.create();
Nils Diewaldc4c4b832015-05-05 16:00:08 +00002630 expect(sv.element().classList.contains('regex')).toBe(false);
2631 expect(sv.regex()).toBe(false);
2632 sv.toggleRegex();
2633 expect(sv.element().classList.contains('regex')).toBe(true);
2634 });
2635
2636 it('should be storable', function () {
2637 var sv = stringValClass.create();
2638 var count = 1;
2639 sv.store = function (value, regex) {
Akron712733a2018-04-05 18:17:47 +02002640 expect(regex).toBe(true);
2641 expect(value).toBe('tree');
Nils Diewaldc4c4b832015-05-05 16:00:08 +00002642 };
2643 sv.regex(true);
2644 sv.value('tree');
2645 sv.element().lastChild.click();
Nils Diewaldf0c4f112015-05-05 12:56:59 +00002646 });
Akron712733a2018-04-05 18:17:47 +02002647
Akronb19803c2018-08-16 16:39:42 +02002648 it('should have a disableoption for regex', function () {
2649 var sv = stringValClass.create(undefined, undefined, true);
2650 var svE = sv.element();
2651 expect(svE.children.length).toEqual(2);
2652
2653 sv = stringValClass.create(undefined, undefined, false);
2654 svE = sv.element();
2655 expect(svE.children.length).toEqual(1);
2656 });
2657
Nils Diewaldf0c4f112015-05-05 12:56:59 +00002658 });
Akrone4961b12017-05-10 21:04:46 +02002659
Akron712733a2018-04-05 18:17:47 +02002660 describe('KorAP.VC.Menu', function () {
Akrone65a88a2018-04-05 19:14:20 +02002661
2662 var vc;
2663
Akron712733a2018-04-05 18:17:47 +02002664 it('should be initializable', function () {
2665
Akrone65a88a2018-04-05 19:14:20 +02002666 vc = vcClass.create([
Akron712733a2018-04-05 18:17:47 +02002667 ['a', 'text'],
2668 ['b', 'string'],
2669 ['c', 'date']
2670 ]).fromJson();
Akronadab5e52018-08-20 13:50:53 +02002671 expect(vc.builder().firstChild.classList.contains('unspecified')).toBeTruthy();
2672 expect(vc.builder().firstChild.firstChild.tagName).toEqual('SPAN');
Akron712733a2018-04-05 18:17:47 +02002673
2674 // Click on unspecified
Akronadab5e52018-08-20 13:50:53 +02002675 vc.builder().firstChild.firstChild.click();
2676 expect(vc.builder().firstChild.firstChild.tagName).toEqual('UL');
Akron712733a2018-04-05 18:17:47 +02002677
Akronadab5e52018-08-20 13:50:53 +02002678 var list = vc.builder().firstChild.firstChild;
Akron3ad46942018-08-22 16:47:14 +02002679 expect(list.getElementsByTagName("LI")[0].innerText).toEqual('referTo');
2680 expect(list.getElementsByTagName("LI")[1].innerText).toEqual('a');
2681 expect(list.getElementsByTagName("LI")[2].innerText).toEqual('b');
2682 expect(list.getElementsByTagName("LI")[3].innerText).toEqual('c');
Akron712733a2018-04-05 18:17:47 +02002683
2684 vc = vcClass.create([
2685 ['d', 'text'],
2686 ['e', 'string'],
2687 ['f', 'date']
2688 ]).fromJson();
Akronadab5e52018-08-20 13:50:53 +02002689 expect(vc.builder().firstChild.classList.contains('unspecified')).toBeTruthy();
2690 expect(vc.builder().firstChild.firstChild.tagName).toEqual('SPAN');
Akron712733a2018-04-05 18:17:47 +02002691
2692 // Click on unspecified
Akronadab5e52018-08-20 13:50:53 +02002693 vc.builder().firstChild.firstChild.click();
2694 expect(vc.builder().firstChild.firstChild.tagName).toEqual('UL');
Akron712733a2018-04-05 18:17:47 +02002695
Akronadab5e52018-08-20 13:50:53 +02002696 list = vc.builder().firstChild.firstChild;
Akron3ad46942018-08-22 16:47:14 +02002697 expect(list.getElementsByTagName("LI")[0].innerText).toEqual('referTo');
2698 expect(list.getElementsByTagName("LI")[1].innerText).toEqual('d');
2699 expect(list.getElementsByTagName("LI")[2].innerText).toEqual('e');
2700 expect(list.getElementsByTagName("LI")[3].innerText).toEqual('f');
Akron31d89942018-04-06 16:44:51 +02002701 // blur
2702 document.body.click();
Akron712733a2018-04-05 18:17:47 +02002703 });
Akrone65a88a2018-04-05 19:14:20 +02002704
2705 // Reinitialize to make tests stable
2706 vc = vcClass.create([
2707 ['d', 'text'],
2708 ['e', 'string'],
2709 ['f', 'date']
2710 ]).fromJson();
2711
2712 it('should be clickable on key', function () {
Akron31d89942018-04-06 16:44:51 +02002713 // Click on unspecified
Akronadab5e52018-08-20 13:50:53 +02002714 vc.builder().firstChild.firstChild.click();
Akrone65a88a2018-04-05 19:14:20 +02002715 // Click on "d"
Akronadab5e52018-08-20 13:50:53 +02002716 vc.builder().firstChild.firstChild.getElementsByTagName("LI")[1].click();
2717 expect(vc.builder().firstChild.firstChild.tagName).toEqual('SPAN');
2718 expect(vc.builder().firstChild.firstChild.innerText).toEqual('d');
2719 expect(vc.builder().firstChild.children[1].innerText).toEqual('eq');
2720 expect(vc.builder().firstChild.children[1].getAttribute('data-type')).toEqual('text');
Akron31d89942018-04-06 16:44:51 +02002721 // blur
2722 document.body.click();
Akrone65a88a2018-04-05 19:14:20 +02002723 });
2724
Akron31d89942018-04-06 16:44:51 +02002725 it('should be clickable on operation for text', function () {
2726 // Click on "d" (or unspecified)
Akronadab5e52018-08-20 13:50:53 +02002727 vc.builder().firstChild.firstChild.click();
Akron31d89942018-04-06 16:44:51 +02002728
2729 // Choose "d"
Akronadab5e52018-08-20 13:50:53 +02002730 vc.builder().firstChild.firstChild.getElementsByTagName("LI")[1].click();
Akron31d89942018-04-06 16:44:51 +02002731
2732 // Click on matchop
Akronadab5e52018-08-20 13:50:53 +02002733 vc.builder().firstChild.children[1].click();
Akron31d89942018-04-06 16:44:51 +02002734
Akronadab5e52018-08-20 13:50:53 +02002735 expect(vc.builder().firstChild.children[1].tagName).toEqual('UL');
Akron31d89942018-04-06 16:44:51 +02002736
Akronadab5e52018-08-20 13:50:53 +02002737 var ul = vc.builder().firstChild.children[1];
Akrone65a88a2018-04-05 19:14:20 +02002738 expect(ul.getElementsByTagName('li')[0].innerText).toEqual("eq");
2739 expect(ul.getElementsByTagName('li')[1].innerText).toEqual("ne");
2740 expect(ul.getElementsByTagName('li')[2].innerText).toEqual("contains");
2741 expect(ul.getElementsByTagName('li')[3].innerText).toEqual("containsnot");
2742 expect(ul.getElementsByTagName('li')[4]).toBeUndefined();
Akron31d89942018-04-06 16:44:51 +02002743
2744 // Choose "contains"
2745 ul.getElementsByTagName('li')[2].click();
Akronadab5e52018-08-20 13:50:53 +02002746 expect(vc.builder().firstChild.children[1].tagName).toEqual("SPAN");
2747 expect(vc.builder().firstChild.children[1].innerText).toEqual("contains");
Akron31d89942018-04-06 16:44:51 +02002748 // blur
2749 document.body.click();
Akrone65a88a2018-04-05 19:14:20 +02002750 })
Akron31d89942018-04-06 16:44:51 +02002751
2752 it('should be clickable on operation for string', function () {
2753 // Click on "d" (or unspecified)
Akronadab5e52018-08-20 13:50:53 +02002754 vc.builder().firstChild.firstChild.click();
Akron31d89942018-04-06 16:44:51 +02002755
2756 // Choose "e"
Akronadab5e52018-08-20 13:50:53 +02002757 vc.builder().firstChild.firstChild.getElementsByTagName("LI")[2].click();
2758
Akron31d89942018-04-06 16:44:51 +02002759 // As a consequence the matchoperator may no longer
2760 // be valid and needs to be re-evaluated
Akronadab5e52018-08-20 13:50:53 +02002761 var fc = vc.builder().firstChild;
Akron31d89942018-04-06 16:44:51 +02002762 expect(fc.firstChild.tagName).toEqual('SPAN');
2763 expect(fc.firstChild.innerText).toEqual('e');
2764 expect(fc.children[1].innerText).toEqual('eq');
2765 expect(fc.children[1].getAttribute('data-type')).toEqual('string');
2766
Akronadab5e52018-08-20 13:50:53 +02002767 vc.builder().firstChild.children[1].click();
Akron31d89942018-04-06 16:44:51 +02002768
Akronadab5e52018-08-20 13:50:53 +02002769 expect(vc.builder().firstChild.children[1].tagName).toEqual('UL');
Akron31d89942018-04-06 16:44:51 +02002770
Akronadab5e52018-08-20 13:50:53 +02002771 var ul = vc.builder().firstChild.children[1];
Akron31d89942018-04-06 16:44:51 +02002772 expect(ul.getElementsByTagName('li')[0].innerText).toEqual("eq");
2773 expect(ul.getElementsByTagName('li')[1].innerText).toEqual("ne");
2774 expect(ul.getElementsByTagName('li')[2]).toBeUndefined();
2775
2776 // Choose "ne"
2777 ul.getElementsByTagName('li')[1].click();
Akronadab5e52018-08-20 13:50:53 +02002778 expect(vc.builder().firstChild.children[1].tagName).toEqual("SPAN");
2779 expect(vc.builder().firstChild.children[1].innerText).toEqual("ne");
Akron8db5e3a2018-05-28 19:25:26 +02002780
2781 // Click on text
Akronebc96662018-08-29 17:36:20 +02002782 expect(vc.builder().firstChild.children[2].innerText).toEqual(KorAP.Locale.EMPTY);
2783 expect(vc.builder().firstChild.children[2].classList.contains('unspecified')).toEqual(true);
Akronadab5e52018-08-20 13:50:53 +02002784 vc.builder().firstChild.children[2].click();
Akron8db5e3a2018-05-28 19:25:26 +02002785
2786 // Blur text element
Akronadab5e52018-08-20 13:50:53 +02002787 expect(vc.builder().firstChild.children[2].firstChild.value).toEqual('');
Akron8db5e3a2018-05-28 19:25:26 +02002788
Akron31d89942018-04-06 16:44:51 +02002789 // blur
2790 document.body.click();
2791 });
2792
2793 it('should be clickable on operation for date', function () {
2794
2795 // Replay matchop check - so it's guaranteed that "ne" is chosen
2796 // Click on "e" (or unspecified)
Akronadab5e52018-08-20 13:50:53 +02002797 vc.builder().firstChild.firstChild.click();
Akron31d89942018-04-06 16:44:51 +02002798 // Rechoose "e"
Akronadab5e52018-08-20 13:50:53 +02002799 vc.builder().firstChild.firstChild.getElementsByTagName("LI")[1].click();
Akron31d89942018-04-06 16:44:51 +02002800 // Click on matchop
Akronadab5e52018-08-20 13:50:53 +02002801 vc.builder().firstChild.children[1].click();
Akron31d89942018-04-06 16:44:51 +02002802 // Choose "ne"
Akronadab5e52018-08-20 13:50:53 +02002803 vc.builder().firstChild.children[1].getElementsByTagName('li')[1].click();
2804 expect(vc.builder().firstChild.children[1].innerText).toEqual("ne");
Akron31d89942018-04-06 16:44:51 +02002805
2806 // Click on "e"
Akronadab5e52018-08-20 13:50:53 +02002807 vc.builder().firstChild.firstChild.click();
Akron31d89942018-04-06 16:44:51 +02002808 // Choose "f"
Akronadab5e52018-08-20 13:50:53 +02002809 vc.builder().firstChild.firstChild.getElementsByTagName("LI")[3].click();
Akron31d89942018-04-06 16:44:51 +02002810
2811 // The matchoperator should still be "ne" as this is valid for dates as well (now)
Akronadab5e52018-08-20 13:50:53 +02002812 var fc = vc.builder().firstChild;
Akron31d89942018-04-06 16:44:51 +02002813 expect(fc.firstChild.tagName).toEqual('SPAN');
2814 expect(fc.firstChild.innerText).toEqual('f');
2815 expect(fc.children[1].innerText).toEqual('ne');
2816 // blur
2817 document.body.click();
2818 });
Akronddc98a72018-04-06 17:33:52 +02002819
2820
2821 // Check json deserialization
2822 it('should be initializable', function () {
2823 vc = vcClass.create([
2824 ['a', 'text'],
2825 ['b', 'string'],
2826 ['c', 'date']
2827 ]).fromJson({
2828 "@type" : "koral:doc",
2829 "key":"a",
2830 "value":"Baum"
2831 });
2832
Akronadab5e52018-08-20 13:50:53 +02002833 expect(vc.builder().firstChild.children[1].getAttribute('data-type')).toEqual('text');
Akronddc98a72018-04-06 17:33:52 +02002834 });
Akron712733a2018-04-05 18:17:47 +02002835 });
2836
2837
Akrone4961b12017-05-10 21:04:46 +02002838 // Check prefix
2839 describe('KorAP.VC.Prefix', function () {
2840
2841 it('should be initializable', function () {
2842 var p = prefixClass.create();
2843 expect(p.element().classList.contains('pref')).toBeTruthy();
2844 expect(p.isSet()).not.toBeTruthy();
2845 });
2846
2847
2848 it('should be clickable', function () {
2849 var vc = vcClass.create([
Akron712733a2018-04-05 18:17:47 +02002850 ['a', null],
2851 ['b', null],
2852 ['c', null]
2853 ]).fromJson();
Akronadab5e52018-08-20 13:50:53 +02002854 expect(vc.builder().firstChild.classList.contains('unspecified')).toBeTruthy();
Akrone4961b12017-05-10 21:04:46 +02002855
2856 // This should open up the menu
Akronadab5e52018-08-20 13:50:53 +02002857 vc.builder().firstChild.firstChild.click();
2858 expect(vc.builder().firstChild.firstChild.tagName).toEqual('UL');
Akrone4961b12017-05-10 21:04:46 +02002859
2860 KorAP._vcKeyMenu._prefix.clear();
2861 KorAP._vcKeyMenu._prefix.add('x');
2862
Akronadab5e52018-08-20 13:50:53 +02002863 var prefElement = vc.builder().querySelector('span.pref');
Akrone4961b12017-05-10 21:04:46 +02002864 expect(prefElement.innerText).toEqual('x');
2865
2866 // This should add key 'x' to VC
2867 prefElement.click();
2868
Akronadab5e52018-08-20 13:50:53 +02002869 expect(vc.builder().firstChild.classList.contains('doc')).toBeTruthy();
2870 expect(vc.builder().firstChild.firstChild.className).toEqual('key');
2871 expect(vc.builder().firstChild.firstChild.innerText).toEqual('x');
Akrone4961b12017-05-10 21:04:46 +02002872 });
2873 });
Akron68d28322018-08-27 15:02:42 +02002874
Akron889ec292018-11-19 17:56:01 +01002875 // Check fragment handling for corpusByMatch helper
Akron68d28322018-08-27 15:02:42 +02002876 describe('KorAP.VC.Fragment', function () {
2877 it('should be initializable', function () {
2878 var f = fragmentClass.create();
2879 var e = f.element();
2880 expect(e.classList.contains('vc')).toBeTruthy();
2881 expect(e.classList.contains('fragment')).toBeTruthy();
2882 expect(e.children.length).toEqual(0);
2883 });
2884
2885 it('should be expansable', function () {
2886 var f = fragmentClass.create();
2887 f.add("author", "Peter");
2888
2889 var root = f.element().firstChild;
2890
2891 expect(root.classList.contains("doc")).toBeTruthy();
2892 expect(root.children[0].tagName).toEqual("SPAN");
2893 expect(root.children[0].textContent).toEqual("author");
2894 expect(root.children[1].tagName).toEqual("SPAN");
2895 expect(root.children[1].textContent).toEqual("eq");
2896 expect(root.children[2].tagName).toEqual("SPAN");
2897 expect(root.children[2].textContent).toEqual("Peter");
2898
2899 f.add("title", "Example");
2900
2901 root = f.element().firstChild;
2902
2903 expect(root.classList.contains("docGroup")).toBeTruthy();
2904
2905 var doc = root.children[0];
2906
2907 expect(doc.children[0].tagName).toEqual("SPAN");
2908 expect(doc.children[0].textContent).toEqual("author");
2909 expect(doc.children[1].tagName).toEqual("SPAN");
2910 expect(doc.children[1].textContent).toEqual("eq");
2911 expect(doc.children[2].tagName).toEqual("SPAN");
2912 expect(doc.children[2].textContent).toEqual("Peter");
2913
2914 doc = root.children[1];
2915
2916 expect(doc.children[0].tagName).toEqual("SPAN");
2917 expect(doc.children[0].textContent).toEqual("title");
2918 expect(doc.children[1].tagName).toEqual("SPAN");
2919 expect(doc.children[1].textContent).toEqual("eq");
2920 expect(doc.children[2].tagName).toEqual("SPAN");
2921 expect(doc.children[2].textContent).toEqual("Example");
2922 });
2923
2924
2925 it('should be reducible', function () {
2926 var f = fragmentClass.create();
Akron889ec292018-11-19 17:56:01 +01002927 expect(f.element().children.length).toEqual(0);
2928
Akron68d28322018-08-27 15:02:42 +02002929 f.add("author", "Peter");
2930 f.add("title", "Example");
2931
Akron889ec292018-11-19 17:56:01 +01002932 expect(f.element().children.length).toEqual(1);
2933
Akron68d28322018-08-27 15:02:42 +02002934 var root = f.element().firstChild;
Akron889ec292018-11-19 17:56:01 +01002935
Akron68d28322018-08-27 15:02:42 +02002936 expect(root.classList.contains("docGroup")).toBeTruthy();
2937
2938 expect(root.children.length).toEqual(2);
2939
2940 f.remove("author","Peter");
2941
2942 root = f.element().firstChild;
2943 expect(root.classList.contains("doc")).toBeTruthy();
2944
2945 expect(root.children[0].tagName).toEqual("SPAN");
2946 expect(root.children[0].textContent).toEqual("title");
2947 expect(root.children[1].tagName).toEqual("SPAN");
2948 expect(root.children[1].textContent).toEqual("eq");
2949 expect(root.children[2].tagName).toEqual("SPAN");
2950 expect(root.children[2].textContent).toEqual("Example");
Akron889ec292018-11-19 17:56:01 +01002951
2952 f.remove("title","Example");
2953
2954 expect(f.element().children.length).toEqual(0);
Akron68d28322018-08-27 15:02:42 +02002955 });
2956 });
Nils Diewald2fe12e12015-03-06 16:47:06 +00002957});