blob: 1b1ea01cfd92d406a1f7cb1fd1abaf78ec9c483f [file] [log] [blame]
Nils Diewald6ac292b2015-01-15 21:33:21 +00001/*
Nils Diewald7c8ced22015-04-15 19:21:00 +00002 * Todo: In demoSpec: Create "and" on the last element of the top "or"-Group
3 */
Akrondd5c6d32018-08-17 14:12:58 +02004define([
5 'vc',
6 'vc/doc',
7 'vc/menu',
8 'vc/prefix',
9 'vc/docgroup',
10 'vc/docgroupref',
11 'vc/unspecified',
12 'vc/operators',
13 'vc/rewrite',
14 'vc/stringval'
15], function (vcClass,
16 docClass,
17 menuClass,
18 prefixClass,
19 docGroupClass,
20 docGroupRefClass,
21 unspecifiedClass,
22 operatorsClass,
23 rewriteClass,
24 stringValClass) {
Nils Diewald6ac292b2015-01-15 21:33:21 +000025
Akrondd5c6d32018-08-17 14:12:58 +020026 KorAP._vcKeyMenu = undefined;
27
Nils Diewald6ac292b2015-01-15 21:33:21 +000028
Nils Diewald7c8ced22015-04-15 19:21:00 +000029 // Helper method for building factories
30 buildFactory = function (objClass, defaults) {
31 return {
32 create : function (overwrites) {
Akron712733a2018-04-05 18:17:47 +020033 var newObj = {};
34 for (var prop in defaults) {
35 newObj[prop] = defaults[prop];
36 };
37 for (var prop in overwrites) {
38 newObj[prop] = overwrites[prop];
39 };
40 return objClass.create().fromJson(newObj);
Nils Diewald7c8ced22015-04-15 19:21:00 +000041 }
Nils Diewald0b6c0412014-12-19 03:55:57 +000042 }
Nils Diewald7c8ced22015-04-15 19:21:00 +000043 };
Nils Diewald0b6c0412014-12-19 03:55:57 +000044
Nils Diewald7c8ced22015-04-15 19:21:00 +000045 function _andOn (obj) {
Akrond141a362018-07-10 18:12:13 +020046 KorAP._and.apply(obj);
Nils Diewald7c8ced22015-04-15 19:21:00 +000047 };
Nils Diewald52f7eb12015-01-12 17:30:04 +000048
Nils Diewald7c8ced22015-04-15 19:21:00 +000049 function _orOn (obj) {
Akrond141a362018-07-10 18:12:13 +020050 KorAP._or.apply(obj);
Nils Diewald7c8ced22015-04-15 19:21:00 +000051 };
Nils Diewald52f7eb12015-01-12 17:30:04 +000052
Nils Diewald7c8ced22015-04-15 19:21:00 +000053 function _delOn (obj) {
Akrond141a362018-07-10 18:12:13 +020054 KorAP._delete.apply(obj);
Nils Diewald7c8ced22015-04-15 19:21:00 +000055 };
Nils Diewald52f7eb12015-01-12 17:30:04 +000056
Nils Diewald7c8ced22015-04-15 19:21:00 +000057 var demoFactory = buildFactory(vcClass, {
58 "@type":"koral:docGroup",
59 "operation":"operation:or",
60 "operands":[
Nils Diewaldf219eb82015-01-07 20:15:42 +000061 {
Akron712733a2018-04-05 18:17:47 +020062 "@type":"koral:docGroup",
63 "operation":"operation:and",
64 "operands":[
Nils Diewald7c8ced22015-04-15 19:21:00 +000065 {
66 "@type":"koral:doc",
67 "key":"Titel",
68 "value":"Baum",
69 "match":"match:eq"
70 },
71 {
72 "@type":"koral:doc",
73 "key":"Veröffentlichungsort",
74 "value":"hihi",
75 "match":"match:eq"
76 },
77 {
78 "@type":"koral:docGroup",
79 "operation":"operation:or",
80 "operands":[
81 {
Akron712733a2018-04-05 18:17:47 +020082 "@type":"koral:doc",
83 "key":"Titel",
84 "value":"Baum",
85 "match":"match:eq"
Nils Diewald7c8ced22015-04-15 19:21:00 +000086 },
87 {
Akron712733a2018-04-05 18:17:47 +020088 "@type":"koral:doc",
89 "key":"Veröffentlichungsort",
90 "value":"hihi",
91 "match":"match:eq"
Nils Diewald7c8ced22015-04-15 19:21:00 +000092 }
93 ]
94 }
Akron712733a2018-04-05 18:17:47 +020095 ]
Nils Diewaldf219eb82015-01-07 20:15:42 +000096 },
97 {
Akron712733a2018-04-05 18:17:47 +020098 "@type":"koral:doc",
99 "key":"Untertitel",
100 "value":"huhu",
101 "match":"match:contains"
Nils Diewaldf219eb82015-01-07 20:15:42 +0000102 }
103 ]
104 });
105
Nils Diewald7c8ced22015-04-15 19:21:00 +0000106 describe('KorAP.Doc', function () {
107 // Create example factories
108 var stringFactory = buildFactory(docClass, {
109 "key" : "author",
110 "value" : "Max Birkendale",
Akron31d89942018-04-06 16:44:51 +0200111 "type" : "type:string",
Nils Diewald7c8ced22015-04-15 19:21:00 +0000112 "@type" : "koral:doc"
113 });
114
115 // Create example factories
Akron712733a2018-04-05 18:17:47 +0200116 var textFactory = buildFactory(docClass, {
117 "key" : "author",
118 "value" : "Birkendale",
Akron31d89942018-04-06 16:44:51 +0200119 "type" : "type:string",
Akron712733a2018-04-05 18:17:47 +0200120 "match" : "match:contains",
121 "@type" : "koral:doc"
122 });
123
124 // Create example factories
Nils Diewald7c8ced22015-04-15 19:21:00 +0000125 var dateFactory = buildFactory(docClass, {
126 "key" : "pubDate",
127 "type" : "type:date",
128 "match" : "match:eq",
129 "value" : "2014-11-05",
130 "@type" : "koral:doc"
131 });
132
133 // Create example factories
134 var regexFactory = buildFactory(docClass, {
135 "key" : "title",
136 "type" : "type:regex",
137 "value" : "[^b]ee.+?",
138 "@type" : "koral:doc"
139 });
140
141 it('should be initializable', function () {
142 var doc = docClass.create();
143 expect(doc.matchop()).toEqual('eq');
144 expect(doc.key()).toBeUndefined();
145 expect(doc.value()).toBeUndefined();
146 expect(doc.type()).toEqual("string");
147 });
148
149 it('should be definable', function () {
150
151 // Empty doc
152 var doc = docClass.create();
153
154 // Set values
155 doc.key("title");
Akron8db5e3a2018-05-28 19:25:26 +0200156
Nils Diewald7c8ced22015-04-15 19:21:00 +0000157 doc.value("Der alte Mann");
158 expect(doc.matchop()).toEqual('eq');
159 expect(doc.key()).toEqual("title");
160 expect(doc.type()).toEqual("string");
161 expect(doc.value()).toEqual("Der alte Mann");
162 });
163
164
165 it('should deserialize JSON-LD string', function () {
166 var doc;
167
168 // String default
169 doc = stringFactory.create();
170 expect(doc.matchop()).toEqual('eq');
171 expect(doc.key()).toEqual("author");
172 expect(doc.type()).toEqual("string");
173 expect(doc.value()).toEqual("Max Birkendale");
174
175 // No valid string
176 doc = stringFactory.create({
Akron712733a2018-04-05 18:17:47 +0200177 value : undefined
Nils Diewald7c8ced22015-04-15 19:21:00 +0000178 });
179 expect(doc).toBeUndefined();
180
181 // No valid string
182 doc = stringFactory.create({
Akron712733a2018-04-05 18:17:47 +0200183 value : { "foo" : "bar" }
Nils Diewald7c8ced22015-04-15 19:21:00 +0000184 });
185 expect(doc).toBeUndefined();
186
187 // Change match type
188 doc = stringFactory.create({
Akron712733a2018-04-05 18:17:47 +0200189 "match" : "match:ne"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000190 });
191
192 expect(doc.matchop()).toEqual('ne');
193 expect(doc.key()).toEqual("author");
194 expect(doc.type()).toEqual("string");
195 expect(doc.value()).toEqual("Max Birkendale");
196
197 // Invalid match type
198 doc = stringFactory.create({
Akron712733a2018-04-05 18:17:47 +0200199 "match" : { "foo" : "bar" }
Nils Diewald7c8ced22015-04-15 19:21:00 +0000200 });
201 expect(doc).toBeUndefined();
202 });
203
204 it('should deserialize JSON-LD regex', function () {
205 var doc = regexFactory.create();
206 expect(doc.key()).toEqual("title");
207 expect(doc.type()).toEqual("regex");
208 expect(doc.value()).toEqual("[^b]ee.+?");
209 expect(doc.matchop()).toEqual('eq');
210
211 // change matcher
212 doc = regexFactory.create({
Akron712733a2018-04-05 18:17:47 +0200213 match : "match:ne"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000214 });
215 expect(doc.matchop()).toEqual('ne');
Akronea4e9052017-07-06 16:12:05 +0200216 expect(doc.rewrites()).toBeUndefined();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000217
218 // Invalid matcher
219 doc = regexFactory.create({
Akron712733a2018-04-05 18:17:47 +0200220 match : "match:chook"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000221 });
Akronea4e9052017-07-06 16:12:05 +0200222 expect(doc.matchop()).toEqual('eq');
223 expect(doc.rewrites()).toBeDefined();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000224
225 // Invalid regex
226 doc = regexFactory.create({
Akron712733a2018-04-05 18:17:47 +0200227 value : "[^b"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000228 });
229 expect(doc).toBeUndefined();
230 });
231
232 it('should deserialize JSON-LD date', function () {
233
234 // Normal date
235 doc = dateFactory.create({});
236
237 expect(doc.matchop()).toEqual('eq');
238 expect(doc.key()).toEqual("pubDate");
239 expect(doc.type()).toEqual("date");
240 expect(doc.value()).toEqual("2014-11-05");
241
242 // Short date 1
243 doc = dateFactory.create({
Akron712733a2018-04-05 18:17:47 +0200244 "value" : "2014-11"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000245 });
246
247 expect(doc.matchop()).toEqual('eq');
248 expect(doc.key()).toEqual("pubDate");
249 expect(doc.type()).toEqual("date");
250 expect(doc.value()).toEqual("2014-11");
251
252 // Short date 2
253 doc = dateFactory.create({
Akron712733a2018-04-05 18:17:47 +0200254 "value" : "2014"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000255 });
256
257 expect(doc.matchop()).toEqual('eq');
258 expect(doc.key()).toEqual("pubDate");
259 expect(doc.type()).toEqual("date");
260 expect(doc.value()).toEqual("2014");
261
262 // Invalid date!
263 doc = dateFactory.create({
Akron712733a2018-04-05 18:17:47 +0200264 "value" : "2014-11-050"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000265 });
266 expect(doc).toBeUndefined();
267
268 // Invalid matcher!
269 doc = dateFactory.create({
Akron31d89942018-04-06 16:44:51 +0200270 "match" : "match:contains",
Nils Diewald7c8ced22015-04-15 19:21:00 +0000271 });
Akronea4e9052017-07-06 16:12:05 +0200272 expect(doc).toBeDefined();
273 expect(doc.rewrites()).toBeDefined();
274 expect(doc.matchop()).toEqual('eq');
Nils Diewald7c8ced22015-04-15 19:21:00 +0000275 });
276
277 it('should be serializale to JSON', function () {
278
279 // Empty doc
280 var doc = docClass.create();
281 expect(doc.toJson()).toEqual(jasmine.any(Object));
282
283 // Serialize string
284 doc = stringFactory.create();
285 expect(doc.toJson()).toEqual(jasmine.objectContaining({
Akron712733a2018-04-05 18:17:47 +0200286 "@type" : "koral:doc",
287 "type" : "type:string",
288 "key" : "author",
289 "value" : "Max Birkendale",
290 "match" : "match:eq"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000291 }));
292
293 // Serialize regex
294 doc = regexFactory.create();
295 expect(doc.toJson()).toEqual(jasmine.objectContaining({
Akron712733a2018-04-05 18:17:47 +0200296 "@type" : "koral:doc",
297 "type" : "type:regex",
298 "value" : "[^b]ee.+?",
299 "match" : "match:eq",
300 "key" : 'title'
Nils Diewald7c8ced22015-04-15 19:21:00 +0000301 }));
302
303 doc = regexFactory.create({
Akron712733a2018-04-05 18:17:47 +0200304 match: "match:ne"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000305 });
306 expect(doc.toJson()).toEqual(jasmine.objectContaining({
Akron712733a2018-04-05 18:17:47 +0200307 "@type" : "koral:doc",
308 "type" : "type:regex",
309 "value" : "[^b]ee.+?",
310 "match" : "match:ne",
311 "key" : 'title'
Nils Diewald7c8ced22015-04-15 19:21:00 +0000312 }));
313
314 doc = dateFactory.create();
315 expect(doc.toJson()).toEqual(jasmine.objectContaining({
Akron712733a2018-04-05 18:17:47 +0200316 "@type" : "koral:doc",
317 "type" : "type:date",
318 "value" : "2014-11-05",
319 "match" : "match:eq",
320 "key" : 'pubDate'
Nils Diewald7c8ced22015-04-15 19:21:00 +0000321 }));
322
323 doc = dateFactory.create({
Akron712733a2018-04-05 18:17:47 +0200324 value : "2014"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000325 });
326 expect(doc.toJson()).toEqual(jasmine.objectContaining({
Akron712733a2018-04-05 18:17:47 +0200327 "@type" : "koral:doc",
328 "type" : "type:date",
329 "value" : "2014",
330 "match" : "match:eq",
331 "key" : 'pubDate'
Nils Diewald7c8ced22015-04-15 19:21:00 +0000332 }));
333 });
334
335
336 it('should be serializale to String', function () {
337 // Empty doc
338 var doc = docClass.create();
Akronebc96662018-08-29 17:36:20 +0200339
Nils Diewald7c8ced22015-04-15 19:21:00 +0000340 expect(doc.toQuery()).toEqual("");
341
342 // Serialize string
343 doc = stringFactory.create();
344 expect(doc.toQuery()).toEqual('author = "Max Birkendale"');
345
346 // Serialize string with quotes
347 doc = stringFactory.create({ "value" : 'Max "Der Coole" Birkendate'});
348 expect(doc.toQuery()).toEqual('author = "Max \\"Der Coole\\" Birkendate"');
349
350 // Serialize regex
351 doc = regexFactory.create();
352 expect(doc.toQuery()).toEqual('title = /[^b]ee.+?/');
353
354 doc = regexFactory.create({
Akron712733a2018-04-05 18:17:47 +0200355 match: "match:ne"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000356 });
357 expect(doc.toQuery()).toEqual('title != /[^b]ee.+?/');
358
Akron8778f5d2017-06-30 21:25:55 +0200359 doc = regexFactory.create({
Akron712733a2018-04-05 18:17:47 +0200360 value: "WPD/AAA/00001"
Akron8778f5d2017-06-30 21:25:55 +0200361 });
362 expect(doc.toQuery()).toEqual('title = /WPD\\/AAA\\/00001/');
363
Nils Diewald7c8ced22015-04-15 19:21:00 +0000364 doc = dateFactory.create();
365 expect(doc.toQuery()).toEqual('pubDate in 2014-11-05');
366
367 doc = dateFactory.create({
Akron712733a2018-04-05 18:17:47 +0200368 value : "2014"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000369 });
370 expect(doc.toQuery()).toEqual('pubDate in 2014');
371 });
372 });
373
374
375 describe('KorAP.DocGroup', function () {
376 // Create example factories
377 var docFactory = buildFactory(
378 docClass,
Nils Diewaldf219eb82015-01-07 20:15:42 +0000379 {
Akron712733a2018-04-05 18:17:47 +0200380 "@type" : "koral:doc",
381 "match":"match:eq",
382 "key" : "author",
383 "value" : "Max Birkendale"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000384 }
385 );
386
387 var docGroupFactory = buildFactory(
388 docGroupClass, {
Akron712733a2018-04-05 18:17:47 +0200389 "@type" : "koral:docGroup",
390 "operation" : "operation:and",
391 "operands" : [
392 docFactory.create().toJson(),
393 docFactory.create({
394 "key" : "pubDate",
395 "type" : "type:date",
396 "value" : "2014-12-05"
397 }).toJson()
398 ]
Nils Diewald7c8ced22015-04-15 19:21:00 +0000399 });
400
401 it('should be initializable', function () {
402 // Create empty group
403 var docGroup = docGroupClass.create();
404 expect(docGroup.operation()).toEqual('and');
405
406 // Create empty group
407 docGroup = docGroupClass.create();
408 docGroup.operation('or');
409 expect(docGroup.operation()).toEqual('or');
410 });
411
412 it('should be definable', function () {
413
414 // Empty group
415 var docGroup = docGroupClass.create();
416 expect(docGroup.operation()).toEqual('and');
417
418 // Set values
419 docGroup.operation("or");
420 expect(docGroup.operation()).toEqual('or');
421
422 // Set invalid values
423 docGroup.operation("hui");
424 expect(docGroup.operation()).toEqual('or');
425 });
426
427 it('should be deserializable', function () {
Akronadab5e52018-08-20 13:50:53 +0200428
429 // Reset list
430 KorAP._vcKeyMenu = menuClass.create([['referTo','ref']]);
431
Nils Diewald7c8ced22015-04-15 19:21:00 +0000432 var docGroup = docGroupFactory.create();
433 expect(docGroup.operation()).toEqual("and");
434 expect(docGroup.operands().length).toEqual(2);
435
436 var op1 = docGroup.getOperand(0);
437 expect(op1.type()).toEqual("string");
438 expect(op1.key()).toEqual("author");
439 expect(op1.value()).toEqual("Max Birkendale");
440 expect(op1.matchop()).toEqual("eq");
441
442 var op2 = docGroup.getOperand(1);
443 expect(op2.type()).toEqual("date");
444 expect(op2.key()).toEqual("pubDate");
445 expect(op2.value()).toEqual("2014-12-05");
446 expect(op2.matchop()).toEqual("eq");
447
448 // Append empty group
449 var newGroup = docGroup.append(docGroupClass.create());
450 newGroup.operation('or');
451 newGroup.append(docFactory.create());
452 newGroup.append(docFactory.create({
Akron712733a2018-04-05 18:17:47 +0200453 "type" : "type:regex",
454 "key" : "title",
455 "value" : "^e.+?$",
456 "match" : "match:ne"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000457 }));
458
459 expect(docGroup.operation()).toEqual("and");
460 expect(docGroup.operands().length).toEqual(3);
461
462 var op1 = docGroup.getOperand(0);
463 expect(op1.ldType()).toEqual("doc");
464 expect(op1.type()).toEqual("string");
465 expect(op1.key()).toEqual("author");
466 expect(op1.value()).toEqual("Max Birkendale");
467 expect(op1.matchop()).toEqual("eq");
468
469 var op2 = docGroup.getOperand(1);
470 expect(op2.ldType()).toEqual("doc");
471 expect(op2.type()).toEqual("date");
472 expect(op2.key()).toEqual("pubDate");
473 expect(op2.value()).toEqual("2014-12-05");
474 expect(op2.matchop()).toEqual("eq");
475
476 var op3 = docGroup.getOperand(2);
477 expect(op3.ldType()).toEqual("docGroup");
478 expect(op3.operation()).toEqual("or");
Akronadab5e52018-08-20 13:50:53 +0200479
Nils Diewald7c8ced22015-04-15 19:21:00 +0000480 var op4 = op3.getOperand(0);
481 expect(op4.ldType()).toEqual("doc");
482 expect(op4.type()).toEqual("string");
483 expect(op4.key()).toEqual("author");
484 expect(op4.value()).toEqual("Max Birkendale");
485 expect(op4.matchop()).toEqual("eq");
486
487 var op5 = op3.getOperand(1);
488 expect(op5.ldType()).toEqual("doc");
489 expect(op5.type()).toEqual("regex");
490 expect(op5.key()).toEqual("title");
491 expect(op5.value()).toEqual("^e.+?$");
492 expect(op5.matchop()).toEqual("ne");
493 });
494
495 it('should be serializable to JSON', function () {
496 var docGroup = docGroupFactory.create();
497
498 expect(docGroup.toJson()).toEqual(jasmine.objectContaining({
Akron712733a2018-04-05 18:17:47 +0200499 "@type" : "koral:docGroup",
500 "operation" : "operation:and",
501 "operands" : [
502 {
503 "@type": 'koral:doc',
504 "key" : 'author',
505 "match": 'match:eq',
506 "value": 'Max Birkendale',
507 "type": 'type:string'
508 },
509 {
510 "@type": 'koral:doc',
511 "key": 'pubDate',
512 "match": 'match:eq',
513 "value": '2014-12-05',
514 "type": 'type:date'
515 }
516 ]
Nils Diewald7c8ced22015-04-15 19:21:00 +0000517 }));
518 });
Nils Diewalde15b7a22015-01-09 21:50:21 +0000519
Nils Diewald7c8ced22015-04-15 19:21:00 +0000520 it('should be serializable to String', function () {
521 var docGroup = docGroupFactory.create();
522 expect(docGroup.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +0200523 'author = "Max Birkendale" & pubDate in 2014-12-05'
Nils Diewald7c8ced22015-04-15 19:21:00 +0000524 );
Nils Diewald52f7eb12015-01-12 17:30:04 +0000525
Nils Diewald7c8ced22015-04-15 19:21:00 +0000526 docGroup = docGroupFactory.create({
Akron712733a2018-04-05 18:17:47 +0200527 "@type" : "koral:docGroup",
528 "operation" : "operation:or",
529 "operands" : [
530 {
531 "@type": 'koral:doc',
532 "key" : 'author',
533 "match": 'match:eq',
534 "value": 'Max Birkendale',
535 "type": 'type:string'
536 },
537 {
538 "@type" : "koral:docGroup",
539 "operation" : "operation:and",
540 "operands" : [
541 {
542 "@type": 'koral:doc',
543 "key": 'pubDate',
544 "match": 'match:geq',
545 "value": '2014-05-12',
546 "type": 'type:date'
547 },
548 {
549 "@type": 'koral:doc',
550 "key": 'pubDate',
551 "match": 'match:leq',
552 "value": '2014-12-05',
553 "type": 'type:date'
554 },
555 {
556 "@type": 'koral:doc',
557 "key": 'foo',
558 "match": 'match:ne',
559 "value": '[a]?bar',
560 "type": 'type:regex'
561 }
562 ]
563 }
564 ]
Nils Diewald7c8ced22015-04-15 19:21:00 +0000565 });
566 expect(docGroup.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +0200567 'author = "Max Birkendale" | ' +
568 '(pubDate since 2014-05-12 & ' +
569 'pubDate until 2014-12-05 & foo != /[a]?bar/)'
Nils Diewald7c8ced22015-04-15 19:21:00 +0000570 );
571 });
572 });
573
Akronb19803c2018-08-16 16:39:42 +0200574 describe('KorAP.DocGroupRef', function () {
575 // Create example factories
576 var docRefFactory = buildFactory(
577 docGroupRefClass,
578 {
579 "@type" : "koral:docGroupRef",
580 "ref" : "@max/myCorpus"
581 }
582 );
583
584 it('should be initializable', function () {
585 var vcRef = docGroupRefClass.create();
586 expect(vcRef.ref()).toBeUndefined();
587 });
588
589 it('should be definable', function () {
590 var vcRef = docGroupRefClass.create();
591 vcRef.ref("@peter/mycorpus");
592 expect(vcRef.ref()).toEqual("@peter/mycorpus");
593 vcRef.ref("@peter/mycorpus2");
594 expect(vcRef.ref()).toEqual("@peter/mycorpus2");
595 });
596
597 it('should deserialize JSON-LD string', function () {
598 var vcRef = docRefFactory.create();
599 expect(vcRef.ref()).toEqual("@max/myCorpus");
600 });
601
602 it('should serialize to JSON-LD', function () {
603 var vcRef = docRefFactory.create();
604 expect(vcRef.toJson()).toEqual(jasmine.objectContaining({
605 "@type" : "koral:docGroupRef",
606 "ref":"@max/myCorpus"
607 }));
608
609 vcRef.ref("@peter/myCorpus2");
610 expect(vcRef.toJson()).toEqual(jasmine.objectContaining({
611 "@type" : "koral:docGroupRef",
612 "ref":"@peter/myCorpus2"
613 }));
614 });
615
616 it('should serialize to a query', function () {
617 var vcRef = docRefFactory.create();
618 expect(vcRef.toQuery()).toEqual(
619 "referTo \"@max/myCorpus\""
620 );
621
622 vcRef.ref("@peter/myCorpus2");
623 expect(vcRef.toQuery()).toEqual(
624 "referTo \"@peter/myCorpus2\""
625 );
626 });
627 });
628
629
Nils Diewald7c8ced22015-04-15 19:21:00 +0000630 describe('KorAP.UnspecifiedDoc', function () {
631 it('should be initializable', function () {
632 var doc = unspecifiedClass.create();
633 var docElement = doc.element();
634 expect(docElement.getAttribute('class')).toEqual('doc unspecified');
Akronebc96662018-08-29 17:36:20 +0200635 expect(docElement.firstChild.firstChild.data).toEqual(KorAP.Locale.EMPTY);
636 expect(docElement.lastChild.lastChild.data).toEqual(KorAP.Locale.EMPTY);
Nils Diewald7c8ced22015-04-15 19:21:00 +0000637 expect(doc.toQuery()).toEqual('');
638
639 // Only removable
640 expect(docElement.lastChild.children.length).toEqual(0);
641 });
642
Akrond141a362018-07-10 18:12:13 +0200643 it('should be removable, when no root', function () {
Nils Diewald7c8ced22015-04-15 19:21:00 +0000644 var docGroup = docGroupClass.create();
645 docGroup.operation('or');
646 expect(docGroup.operation()).toEqual('or');
647
648 docGroup.append({
Akron712733a2018-04-05 18:17:47 +0200649 "@type": 'koral:doc',
650 "key": 'pubDate',
651 "match": 'match:eq',
652 "value": '2014-12-05',
653 "type": 'type:date'
Nils Diewald7c8ced22015-04-15 19:21:00 +0000654 });
655
656 // Add unspecified object
657 docGroup.append();
658
Akrond141a362018-07-10 18:12:13 +0200659 var parent = document.createElement('div');
660 parent.appendChild(docGroup.element());
661
Nils Diewald7c8ced22015-04-15 19:21:00 +0000662 expect(docGroup.element().getAttribute('class')).toEqual('docGroup');
663 expect(docGroup.element().children[0].getAttribute('class')).toEqual('doc');
664
665 var unspec = docGroup.element().children[1];
666 expect(unspec.getAttribute('class')).toEqual('doc unspecified');
667
Akronb19803c2018-08-16 16:39:42 +0200668 // Only unspec and delete
669 expect(unspec.children.length).toEqual(2);
670
Nils Diewald7c8ced22015-04-15 19:21:00 +0000671 // Removable
672 expect(unspec.lastChild.children.length).toEqual(1);
673 expect(unspec.lastChild.children[0].getAttribute('class')).toEqual('delete');
674 });
675
Akrond141a362018-07-10 18:12:13 +0200676
Nils Diewald7c8ced22015-04-15 19:21:00 +0000677 it('should be replaceable by a doc', function () {
678 var doc = unspecifiedClass.create();
679 expect(doc.ldType()).toEqual("non");
680 // No parent, therefor not updateable
681 expect(doc.key("baum")).toBeNull();
682
683 var docGroup = docGroupClass.create();
684 docGroup.operation('or');
685 expect(docGroup.operation()).toEqual('or');
686
687 docGroup.append({
Akron712733a2018-04-05 18:17:47 +0200688 "@type": 'koral:doc',
689 "key": 'pubDate',
690 "match": 'match:eq',
691 "value": '2014-12-05',
692 "type": 'type:date'
Nils Diewald7c8ced22015-04-15 19:21:00 +0000693 });
694
695 expect(docGroup.toQuery()).toEqual("pubDate in 2014-12-05");
696 docGroup.append();
697
698 expect(docGroup.getOperand(0).ldType()).toEqual("doc");
699 expect(docGroup.getOperand(1).ldType()).toEqual("non");
700
701 var op = docGroup.getOperand(1).element().lastChild;
Akron0b489ad2018-02-02 16:49:32 +0100702 expect(op.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +0000703 expect(op.children[0].getAttribute('class')).toEqual('delete');
704 expect(op.children.length).toEqual(1);
705
706 // Replace unspecified doc
707 expect(docGroup.getOperand(1).key("name")).not.toBeNull();
708 expect(docGroup.getOperand(1).ldType()).toEqual("doc");
709 expect(docGroup.getOperand(1).key()).toEqual("name");
Akron55a343b2018-04-06 19:57:36 +0200710 expect(docGroup.getOperand(1).value()).toBeUndefined();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000711
Akronb19803c2018-08-16 16:39:42 +0200712 expect(docGroup.getOperand(1).element().children.length).toEqual(4);
713
Nils Diewald7c8ced22015-04-15 19:21:00 +0000714 op = docGroup.getOperand(1).element().lastChild;
Akron0b489ad2018-02-02 16:49:32 +0100715 expect(op.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +0000716 expect(op.children[0].getAttribute('class')).toEqual('and');
717 expect(op.children[1].getAttribute('class')).toEqual('or');
718 expect(op.children[2].getAttribute('class')).toEqual('delete');
Akronb19803c2018-08-16 16:39:42 +0200719
Nils Diewald7c8ced22015-04-15 19:21:00 +0000720 expect(op.children.length).toEqual(3);
721
722 docGroup.getOperand(1).value("Pachelbel");
723 expect(docGroup.getOperand(1).value()).toEqual("Pachelbel");
724 expect(docGroup.getOperand(1).type()).toEqual("string");
725 expect(docGroup.getOperand(1).matchop()).toEqual("eq");
726
727 // Specified!
728 expect(docGroup.toQuery()).toEqual('pubDate in 2014-12-05 | name = "Pachelbel"');
729 });
Akronb19803c2018-08-16 16:39:42 +0200730
Nils Diewald7c8ced22015-04-15 19:21:00 +0000731 it('should be replaceable on root', function () {
Nils Diewald6283d692015-04-23 20:32:53 +0000732 var vc = vcClass.create();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000733 expect(vc.toQuery()).toEqual("");
734
735 expect(vc.root().ldType()).toEqual("non");
736
737 // No operators on root
738 op = vc.root().element().lastChild;
Akronebc96662018-08-29 17:36:20 +0200739 expect(op.lastChild.textContent).toEqual(KorAP.Locale.EMPTY);
Nils Diewald7c8ced22015-04-15 19:21:00 +0000740
741 // Replace
742 expect(vc.root().key("baum")).not.toBeNull();
743 expect(vc.root().ldType()).toEqual("doc");
744
745 op = vc.root().element().lastChild;
Akron0b489ad2018-02-02 16:49:32 +0100746 expect(op.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +0000747 expect(op.children[0].getAttribute('class')).toEqual('and');
748 expect(op.children[1].getAttribute('class')).toEqual('or');
749 expect(op.children[2].getAttribute('class')).toEqual('delete');
750 expect(op.children.length).toEqual(3);
751 });
Akron55a343b2018-04-06 19:57:36 +0200752
753 it('should be clickable', function () {
754 var vc = vcClass.create([
755 ["pubDate", "date"]
756 ]);
757 expect(vc.toQuery()).toEqual("");
Akronebc96662018-08-29 17:36:20 +0200758 expect(vc.builder().firstChild.textContent).toEqual(KorAP.Locale.EMPTY);
759 expect(vc.builder().firstChild.classList.contains('unspecified')).toEqual(true);
Akronadab5e52018-08-20 13:50:53 +0200760 vc.builder().firstChild.firstChild.click();
Akron55a343b2018-04-06 19:57:36 +0200761
762 // Click on pubDate
Akron3ad46942018-08-22 16:47:14 +0200763 vc.element().firstChild.getElementsByTagName("LI")[1].click();
Akronadab5e52018-08-20 13:50:53 +0200764 expect(vc.builder().firstChild.firstChild.textContent).toEqual("pubDate");
765 expect(vc.builder().firstChild.children[1].getAttribute("data-type")).toEqual("date");
Akron55a343b2018-04-06 19:57:36 +0200766 });
Nils Diewald7c8ced22015-04-15 19:21:00 +0000767 });
768
769 describe('KorAP.Doc element', function () {
770 it('should be initializable', function () {
771 var docElement = docClass.create(undefined, {
Akron712733a2018-04-05 18:17:47 +0200772 "@type" : "koral:doc",
773 "key":"Titel",
774 "value":"Baum",
775 "match":"match:eq"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000776 });
777 expect(docElement.key()).toEqual('Titel');
778 expect(docElement.matchop()).toEqual('eq');
779 expect(docElement.value()).toEqual('Baum');
780
781 var docE = docElement.element();
782 expect(docE.children[0].firstChild.data).toEqual('Titel');
783 expect(docE.children[1].firstChild.data).toEqual('eq');
784 expect(docE.children[1].getAttribute('data-type')).toEqual('string');
785 expect(docE.children[2].firstChild.data).toEqual('Baum');
786 expect(docE.children[2].getAttribute('data-type')).toEqual('string');
787
788 expect(docElement.toJson()).toEqual(jasmine.objectContaining({
Akron712733a2018-04-05 18:17:47 +0200789 "@type" : "koral:doc",
790 "key":"Titel",
791 "value":"Baum",
792 "match":"match:eq"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000793 }));
794 });
Akronb19803c2018-08-16 16:39:42 +0200795
796
797 it('should be replacable by unspecified', function () {
798 var vc = vcClass.create([
799 ["pubDate", "date"]
800 ]).fromJson({
801 "@type" : "koral:doc",
802 "key":"Titel",
803 "value":"Baum",
804 "match":"match:eq"
805 });
806 expect(vc.toQuery()).toEqual("Titel = \"Baum\"");
807
Akronadab5e52018-08-20 13:50:53 +0200808 var vcE = vc.builder();
Akronb19803c2018-08-16 16:39:42 +0200809 expect(vcE.firstChild.children.length).toEqual(4);
810
811 // Click to delete
812 vcE.firstChild.lastChild.lastChild.click();
813
814 expect(vcE.firstChild.children.length).toEqual(1);
815
Akronebc96662018-08-29 17:36:20 +0200816 expect(vcE.firstChild.textContent).toEqual(KorAP.Locale.EMPTY);
817 expect(vcE.firstChild.classList.contains("unspecified")).toBeTruthy();
Akronb19803c2018-08-16 16:39:42 +0200818 vcE.firstChild.firstChild.click();
819
820 // Click on pubDate
Akron3ad46942018-08-22 16:47:14 +0200821 vcE.firstChild.getElementsByTagName("LI")[1].click();
Akronb19803c2018-08-16 16:39:42 +0200822
823 expect(vcE.firstChild.firstChild.textContent).toEqual("pubDate");
824 expect(vcE.firstChild.children[1].getAttribute("data-type")).toEqual("date");
825
826 expect(vcE.firstChild.children.length).toEqual(4);
827 });
828
829
830 it('should be replaceable by a docGroupRef', function () {
Akron3ad46942018-08-22 16:47:14 +0200831 var vc = vcClass.create().fromJson({
Akronb19803c2018-08-16 16:39:42 +0200832 "@type" : "koral:doc",
833 "key":"Titel",
834 "value":"Baum",
835 "match":"match:eq"
836 });
837
838 expect(vc.toQuery()).toEqual("Titel = \"Baum\"");
839
Akronadab5e52018-08-20 13:50:53 +0200840 var vcE = vc.builder();
Akronb19803c2018-08-16 16:39:42 +0200841 expect(vcE.firstChild.children.length).toEqual(4);
842
843 // Click to delete
844 vcE.firstChild.lastChild.lastChild.click();
845
846 expect(vcE.firstChild.children.length).toEqual(1);
847
Akronebc96662018-08-29 17:36:20 +0200848 expect(vcE.firstChild.textContent).toEqual(KorAP.Locale.EMPTY);
849 expect(vcE.firstChild.classList.contains('unspecified')).toEqual(true);
Akronb19803c2018-08-16 16:39:42 +0200850 vcE.firstChild.firstChild.click();
851
Akron3ad46942018-08-22 16:47:14 +0200852 // Click on referTo
Akronb19803c2018-08-16 16:39:42 +0200853 vcE.firstChild.getElementsByTagName("LI")[0].click();
854
Akron3ad46942018-08-22 16:47:14 +0200855 expect(vcE.firstChild.firstChild.textContent).toEqual("referTo");
Akronb19803c2018-08-16 16:39:42 +0200856 expect(vcE.firstChild.children[1].getAttribute("data-type")).toEqual("string");
857 expect(vcE.firstChild.children.length).toEqual(3);
858 });
Nils Diewald7c8ced22015-04-15 19:21:00 +0000859 });
860
861 describe('KorAP.DocGroup element', function () {
862 it('should be initializable', function () {
863
864 var docGroup = docGroupClass.create(undefined, {
Akron712733a2018-04-05 18:17:47 +0200865 "@type" : "koral:docGroup",
866 "operation" : "operation:and",
867 "operands" : [
868 {
869 "@type": 'koral:doc',
870 "key" : 'author',
871 "match": 'match:eq',
872 "value": 'Max Birkendale',
873 "type": 'type:string'
874 },
875 {
876 "@type": 'koral:doc',
877 "key": 'pubDate',
878 "match": 'match:eq',
879 "value": '2014-12-05',
880 "type": 'type:date'
881 }
882 ]
Nils Diewald7c8ced22015-04-15 19:21:00 +0000883 });
884
885 expect(docGroup.operation()).toEqual('and');
886 var e = docGroup.element();
887 expect(e.getAttribute('class')).toEqual('docGroup');
888 expect(e.getAttribute('data-operation')).toEqual('and');
889
890 var first = e.children[0];
891 expect(first.getAttribute('class')).toEqual('doc');
892 expect(first.children[0].getAttribute('class')).toEqual('key');
893 expect(first.children[1].getAttribute('class')).toEqual('match');
894 expect(first.children[2].getAttribute('class')).toEqual('value');
895 expect(first.children[2].getAttribute('data-type')).toEqual('string');
896 expect(first.children[0].firstChild.data).toEqual('author');
897 expect(first.children[1].firstChild.data).toEqual('eq');
898 expect(first.children[2].firstChild.data).toEqual('Max Birkendale');
899
900 var second = e.children[1];
901 expect(second.getAttribute('class')).toEqual('doc');
902 expect(second.children[0].getAttribute('class')).toEqual('key');
903 expect(second.children[1].getAttribute('class')).toEqual('match');
904 expect(second.children[2].getAttribute('class')).toEqual('value');
905 expect(second.children[2].getAttribute('data-type')).toEqual('date');
906 expect(second.children[0].firstChild.data).toEqual('pubDate');
907 expect(second.children[1].firstChild.data).toEqual('eq');
908 expect(second.children[2].firstChild.data).toEqual('2014-12-05');
909 });
910
911 it('should be deserializable with nested groups', function () {
912 var docGroup = docGroupClass.create(undefined, {
Akron712733a2018-04-05 18:17:47 +0200913 "@type" : "koral:docGroup",
914 "operation" : "operation:or",
915 "operands" : [
916 {
917 "@type": 'koral:doc',
918 "key" : 'author',
919 "match": 'match:eq',
920 "value": 'Max Birkendale',
921 "type": 'type:string'
922 },
923 {
924 "@type" : "koral:docGroup",
925 "operation" : "operation:and",
926 "operands" : [
927 {
928 "@type": 'koral:doc',
929 "key": 'pubDate',
930 "match": 'match:geq',
931 "value": '2014-05-12',
932 "type": 'type:date'
933 },
934 {
935 "@type": 'koral:doc',
936 "key": 'pubDate',
937 "match": 'match:leq',
938 "value": '2014-12-05',
939 "type": 'type:date'
940 }
941 ]
942 }
943 ]
Nils Diewald7c8ced22015-04-15 19:21:00 +0000944 });
945
946 expect(docGroup.operation()).toEqual('or');
947 var e = docGroup.element();
948 expect(e.getAttribute('class')).toEqual('docGroup');
949 expect(e.getAttribute('data-operation')).toEqual('or');
950
951 expect(e.children[0].getAttribute('class')).toEqual('doc');
952 var docop = e.children[0].lastChild;
Akron0b489ad2018-02-02 16:49:32 +0100953 expect(docop.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +0000954 expect(docop.children[0].getAttribute('class')).toEqual('and');
955 expect(docop.children[1].getAttribute('class')).toEqual('or');
956 expect(docop.children[2].getAttribute('class')).toEqual('delete');
957
958 expect(e.children[1].getAttribute('class')).toEqual('docGroup');
959 expect(e.children[1].getAttribute('data-operation')).toEqual('and');
960
961 // This and-operation can be "or"ed or "delete"d
962 var secop = e.children[1].children[2];
Akron0b489ad2018-02-02 16:49:32 +0100963 expect(secop.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +0000964 expect(secop.children[0].getAttribute('class')).toEqual('or');
965 expect(secop.children[1].getAttribute('class')).toEqual('delete');
966
967 // This or-operation can be "and"ed or "delete"d
Akron0b489ad2018-02-02 16:49:32 +0100968 expect(e.children[2].getAttribute('class')).toEqual('operators button-group');
969 expect(e.lastChild.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +0000970 expect(e.lastChild.children[0].getAttribute('class')).toEqual('and');
971 expect(e.lastChild.children[1].getAttribute('class')).toEqual('delete');
972 });
973 });
974
Akronb19803c2018-08-16 16:39:42 +0200975 describe('KorAP.DocGroupRef element', function () {
976 it('should be initializable', function () {
977 var docGroupRef = docGroupRefClass.create(undefined, {
978 "@type" : "koral:docGroupRef",
979 "ref" : "@franz/myVC1"
980 });
981 expect(docGroupRef.ref()).toEqual("@franz/myVC1");
982 var dgrE = docGroupRef.element();
983
Akron3ad46942018-08-22 16:47:14 +0200984 expect(dgrE.children[0].firstChild.data).toEqual("referTo");
Akronb19803c2018-08-16 16:39:42 +0200985 expect(dgrE.children[0].tagName).toEqual("SPAN");
986 expect(dgrE.children[0].classList.contains("key")).toBeTruthy();
987 expect(dgrE.children[0].classList.contains("fixed")).toBeTruthy();
988 expect(dgrE.children[1].firstChild.data).toEqual("@franz/myVC1");
989 expect(dgrE.children[1].tagName).toEqual("SPAN");
990 expect(dgrE.children[1].classList.contains("value")).toBeTruthy();
991 expect(dgrE.children[1].getAttribute("data-type")).toEqual("string");
992 });
993
994 it('should be modifiable on reference', function () {
995 var docGroupRef = docGroupRefClass.create(undefined, {
996 "@type" : "koral:docGroupRef",
997 "ref" : "@franz/myVC1"
998 });
999 var dgrE = docGroupRef.element();
1000 expect(docGroupRef.toQuery()).toEqual("referTo \"@franz/myVC1\"");
1001 dgrE.children[1].click();
1002
1003 var input = dgrE.children[1].firstChild;
1004 expect(input.tagName).toEqual("INPUT");
1005 input.value = "Versuch";
1006
1007 var event = new KeyboardEvent("keypress", {
1008 "key" : "[Enter]",
1009 "keyCode" : 13
1010 });
1011
1012 input.dispatchEvent(event);
1013 expect(docGroupRef.toQuery()).toEqual("referTo \"Versuch\"");
1014 });
1015 });
1016
1017
Akrone4961b12017-05-10 21:04:46 +02001018 describe('KorAP.VirtualCorpus', function () {
Nils Diewald7c8ced22015-04-15 19:21:00 +00001019 var simpleGroupFactory = buildFactory(docGroupClass, {
1020 "@type" : "koral:docGroup",
1021 "operation" : "operation:and",
1022 "operands" : [
Akron712733a2018-04-05 18:17:47 +02001023 {
1024 "@type": 'koral:doc',
1025 "key" : 'author',
1026 "match": 'match:eq',
1027 "value": 'Max Birkendale',
1028 "type": 'type:string'
1029 },
1030 {
1031 "@type": 'koral:doc',
1032 "key": 'pubDate',
1033 "match": 'match:eq',
1034 "value": '2014-12-05',
1035 "type": 'type:date'
1036 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00001037 ]
1038 });
1039
1040 var nestedGroupFactory = buildFactory(vcClass, {
1041 "@type" : "koral:docGroup",
1042 "operation" : "operation:or",
1043 "operands" : [
Akron712733a2018-04-05 18:17:47 +02001044 {
1045 "@type": 'koral:doc',
1046 "key" : 'author',
1047 "match": 'match:eq',
1048 "value": 'Max Birkendale',
1049 "type": 'type:string'
1050 },
1051 {
1052 "@type" : "koral:docGroup",
1053 "operation" : "operation:and",
1054 "operands" : [
1055 {
1056 "@type": 'koral:doc',
1057 "key": 'pubDate',
1058 "match": 'match:geq',
1059 "value": '2014-05-12',
1060 "type": 'type:date'
1061 },
1062 {
1063 "@type": 'koral:doc',
1064 "key": 'pubDate',
1065 "match": 'match:leq',
1066 "value": '2014-12-05',
1067 "type": 'type:date'
1068 }
1069 ]
1070 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00001071 ]
1072 });
1073
1074 var flatGroupFactory = buildFactory(vcClass, {
1075 "@type" : "koral:docGroup",
1076 "operation" : "operation:and",
1077 "operands" : [
Akron712733a2018-04-05 18:17:47 +02001078 {
1079 "@type": 'koral:doc',
1080 "key": 'pubDate',
1081 "match": 'match:geq',
1082 "value": '2014-05-12',
1083 "type": 'type:date'
1084 },
1085 {
1086 "@type": 'koral:doc',
1087 "key": 'pubDate',
1088 "match": 'match:leq',
1089 "value": '2014-12-05',
1090 "type": 'type:date'
1091 },
1092 {
1093 "@type": 'koral:doc',
1094 "key": 'foo',
1095 "match": 'match:eq',
1096 "value": 'bar',
1097 "type": 'type:string'
1098 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00001099 ]
1100 });
1101
1102 it('should be initializable', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00001103 var vc = vcClass.create();
Nils Diewald7c8ced22015-04-15 19:21:00 +00001104 expect(vc.element().getAttribute('class')).toEqual('vc');
1105 expect(vc.root().element().getAttribute('class')).toEqual('doc unspecified');
1106
1107 // Not removable
1108 expect(vc.root().element().lastChild.children.length).toEqual(0);
1109 });
1110
1111 it('should be based on a doc', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00001112 var vc = vcClass.create().fromJson({
Akron712733a2018-04-05 18:17:47 +02001113 "@type" : "koral:doc",
1114 "key":"Titel",
1115 "value":"Baum",
1116 "match":"match:eq"
Nils Diewald7c8ced22015-04-15 19:21:00 +00001117 });
1118
1119 expect(vc.element().getAttribute('class')).toEqual('vc');
1120 expect(vc.root().element().getAttribute('class')).toEqual('doc');
1121 expect(vc.root().key()).toEqual('Titel');
1122 expect(vc.root().value()).toEqual('Baum');
1123 expect(vc.root().matchop()).toEqual('eq');
1124
1125 var docE = vc.root().element();
1126 expect(docE.children[0].firstChild.data).toEqual('Titel');
1127 expect(docE.children[1].firstChild.data).toEqual('eq');
1128 expect(docE.children[1].getAttribute('data-type')).toEqual('string');
1129 expect(docE.children[2].firstChild.data).toEqual('Baum');
1130 expect(docE.children[2].getAttribute('data-type')).toEqual('string');
1131 });
1132
1133 it('should be based on a docGroup', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00001134 var vc = vcClass.create().fromJson(simpleGroupFactory.create().toJson());
Nils Diewald7c8ced22015-04-15 19:21:00 +00001135
1136 expect(vc.element().getAttribute('class')).toEqual('vc');
1137 expect(vc.root().element().getAttribute('class')).toEqual('docGroup');
1138 expect(vc.root().operation()).toEqual('and');
1139
1140 var docGroup = vc.root();
1141
1142 var first = docGroup.getOperand(0);
1143 expect(first.key()).toEqual('author');
1144 expect(first.value()).toEqual('Max Birkendale');
1145 expect(first.matchop()).toEqual('eq');
1146
1147 var second = docGroup.getOperand(1);
1148 expect(second.key()).toEqual('pubDate');
1149 expect(second.value()).toEqual('2014-12-05');
1150 expect(second.matchop()).toEqual('eq');
1151 });
1152
Akronb19803c2018-08-16 16:39:42 +02001153 it('should be based on a docGroupRef', function () {
1154 var vc = vcClass.create().fromJson({
1155 "@type" : "koral:docGroupRef",
1156 "ref":"myCorpus"
1157 });
1158
Akronadab5e52018-08-20 13:50:53 +02001159 // iv class="doc groupref"><span class="key fixed">@referTo</span><span data-type="string" class="value">myCorpus</span>
1160 var vcE = vc.builder();
1161 expect(vcE.getAttribute('class')).toEqual('builder');
Akronb19803c2018-08-16 16:39:42 +02001162 expect(vcE.firstChild.tagName).toEqual('DIV');
1163 expect(vcE.firstChild.classList.contains('groupref')).toBeTruthy();
1164
1165 expect(vcE.firstChild.firstChild.tagName).toEqual('SPAN');
1166 expect(vcE.firstChild.firstChild.classList.contains('key')).toBeTruthy();
1167 expect(vcE.firstChild.firstChild.classList.contains('fixed')).toBeTruthy();
1168
Akron3ad46942018-08-22 16:47:14 +02001169 expect(vcE.firstChild.firstChild.textContent).toEqual("referTo");
Akronb19803c2018-08-16 16:39:42 +02001170
1171 expect(vcE.firstChild.children[1].tagName).toEqual('SPAN');
1172 expect(vcE.firstChild.children[1].classList.contains('value')).toBeTruthy();
1173 expect(vcE.firstChild.children[1].getAttribute('data-type')).toEqual('string');
1174 expect(vcE.firstChild.children[1].textContent).toEqual("myCorpus");
1175 });
Nils Diewald7c8ced22015-04-15 19:21:00 +00001176
1177 it('should be based on a nested docGroup', function () {
1178 var vc = nestedGroupFactory.create();
1179
Akronadab5e52018-08-20 13:50:53 +02001180 expect(vc.builder().getAttribute('class')).toEqual('builder');
1181 expect(vc.builder().firstChild.getAttribute('class')).toEqual('docGroup');
1182 expect(vc.builder().firstChild.children[0].getAttribute('class')).toEqual('doc');
1183 var dg = vc.builder().firstChild.children[1];
Nils Diewald7c8ced22015-04-15 19:21:00 +00001184 expect(dg.getAttribute('class')).toEqual('docGroup');
1185 expect(dg.children[0].getAttribute('class')).toEqual('doc');
1186 expect(dg.children[1].getAttribute('class')).toEqual('doc');
Akron0b489ad2018-02-02 16:49:32 +01001187 expect(dg.children[2].getAttribute('class')).toEqual('operators button-group');
Akronadab5e52018-08-20 13:50:53 +02001188 expect(vc.builder().firstChild.children[2].getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001189 });
1190
Akronb19803c2018-08-16 16:39:42 +02001191 it('should be based on a nested docGroupRef', function () {
1192 var vc = vcClass.create().fromJson({
1193 "@type" : "koral:docGroup",
1194 "operation" : "operation:and",
1195 "operands" : [{
1196 "@type" : "koral:docGroupRef",
1197 "ref":"myCorpus"
1198 },{
1199 "@type" : "koral:doc",
1200 "key":"Titel",
1201 "value":"Baum",
1202 "match":"match:eq"
1203 }]
1204 });
1205
1206 expect(vc._root.ldType()).toEqual("docGroup");
1207
1208 expect(vc.toQuery()).toEqual('referTo "myCorpus" & Titel = "Baum"');
1209 });
1210
1211
Nils Diewald7c8ced22015-04-15 19:21:00 +00001212 it('should be modifiable by deletion in flat docGroups', function () {
1213 var vc = flatGroupFactory.create();
1214 var docGroup = vc.root();
1215
1216 expect(docGroup.element().getAttribute('class')).toEqual('docGroup');
1217
1218 var doc = docGroup.getOperand(1);
1219 expect(doc.key()).toEqual("pubDate");
1220 expect(doc.value()).toEqual("2014-12-05");
1221
1222 // Remove operand 1
1223 expect(docGroup.delOperand(doc).update()).not.toBeUndefined();
1224 expect(doc._element).toEqual(undefined);
1225
1226 doc = docGroup.getOperand(1);
1227 expect(doc.key()).toEqual("foo");
1228
1229 // Remove operand 1
1230 expect(docGroup.delOperand(doc).update()).not.toBeUndefined();
1231 expect(doc._element).toEqual(undefined);
1232
1233 // Only one operand left ...
1234 expect(docGroup.getOperand(1)).toBeUndefined();
1235 // ... but there shouldn't be a group anymore at all!
1236 expect(docGroup.getOperand(0)).toBeUndefined();
1237
1238 var obj = vc.root();
1239 expect(obj.ldType()).toEqual("doc");
1240 expect(obj.key()).toEqual("pubDate");
1241 expect(obj.value()).toEqual("2014-05-12");
1242
1243 expect(obj.element().getAttribute('class')).toEqual('doc');
1244 });
1245
1246
1247 it('should be modifiable by deletion in nested docGroups (root case)', function () {
1248 var vc = nestedGroupFactory.create();
1249
1250 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001251 'author = "Max Birkendale" | (pubDate since 2014-05-12 & pubDate until 2014-12-05)'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001252 );
1253
1254 var docGroup = vc.root();
1255 expect(docGroup.ldType()).toEqual("docGroup");
1256 expect(docGroup.operation()).toEqual("or");
1257
1258 var doc = docGroup.getOperand(0);
1259 expect(doc.key()).toEqual("author");
1260 expect(doc.value()).toEqual("Max Birkendale");
1261
1262 docGroup = docGroup.getOperand(1);
1263 expect(docGroup.operation()).toEqual("and");
1264
1265 doc = docGroup.getOperand(0);
1266 expect(doc.key()).toEqual("pubDate");
1267 expect(doc.matchop()).toEqual("geq");
1268 expect(doc.value()).toEqual("2014-05-12");
1269 expect(doc.type()).toEqual("date");
1270
1271 doc = docGroup.getOperand(1);
1272 expect(doc.key()).toEqual("pubDate");
1273 expect(doc.matchop()).toEqual("leq");
1274 expect(doc.value()).toEqual("2014-12-05");
1275 expect(doc.type()).toEqual("date");
1276
1277 // Remove first operand so everything becomes root
1278 expect(
Akron712733a2018-04-05 18:17:47 +02001279 vc.root().delOperand(
1280 vc.root().getOperand(0)
1281 ).update().ldType()
Nils Diewald7c8ced22015-04-15 19:21:00 +00001282 ).toEqual("docGroup");
1283
1284 expect(vc.root().ldType()).toEqual("docGroup");
1285 expect(vc.root().operation()).toEqual("and");
1286 expect(vc.root().getOperand(0).ldType()).toEqual("doc");
1287
1288 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001289 'pubDate since 2014-05-12 & pubDate until 2014-12-05'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001290 );
1291 });
1292
1293 it('should be modifiable by deletion in nested docGroups (resolve group case)', function () {
1294 var vc = nestedGroupFactory.create();
1295
1296 // Get nested group
1297 var firstGroup = vc.root().getOperand(1);
1298 firstGroup.append(simpleGroupFactory.create({ "operation" : "operation:or" }));
1299
1300 // Structur is now:
1301 // or(doc, and(doc, doc, or(doc, doc)))
1302
1303 // Get nested or in and
1304 var orGroup = vc.root().getOperand(1).getOperand(2);
1305 expect(orGroup.ldType()).toEqual("docGroup");
1306 expect(orGroup.operation()).toEqual("or");
1307
1308 // Remove
1309 // Structur is now:
1310 // or(doc, and(doc, doc, doc)))
1311 expect(orGroup.delOperand(orGroup.getOperand(0)).update().operation()).toEqual("and");
1312 expect(vc.root().getOperand(1).operands().length).toEqual(3);
1313 });
1314
1315 it('should be modifiable by deletion in nested docGroups (identical group case)', function () {
1316 var vc = nestedGroupFactory.create();
1317
1318 // Get nested group
1319 var firstGroup = vc.root().getOperand(1);
1320 firstGroup.append(simpleGroupFactory.create({
Akron712733a2018-04-05 18:17:47 +02001321 "operation" : "operation:or"
Nils Diewald7c8ced22015-04-15 19:21:00 +00001322 }));
1323 var oldAuthor = firstGroup.getOperand(2).getOperand(0);
1324 oldAuthor.key("title");
1325 oldAuthor.value("Der Birnbaum");
1326
1327 // Structur is now:
1328 // or(doc, and(doc, doc, or(doc, doc)))
1329 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001330 'author = "Max Birkendale" | ' +
1331 '(pubDate since 2014-05-12 & ' +
1332 'pubDate until 2014-12-05 & ' +
1333 '(title = "Der Birnbaum" | ' +
1334 'pubDate in 2014-12-05))'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001335 );
1336
1337 var andGroup = vc.root().getOperand(1);
1338
1339 // Get leading docs in and
1340 var doc1 = andGroup.getOperand(0);
1341 expect(doc1.ldType()).toEqual("doc");
1342 expect(doc1.value()).toEqual("2014-05-12");
1343 var doc2 = andGroup.getOperand(1);
1344 expect(doc2.ldType()).toEqual("doc");
1345 expect(doc2.value()).toEqual("2014-12-05");
1346
1347 // Remove 2
1348 expect(
Akron712733a2018-04-05 18:17:47 +02001349 andGroup.delOperand(doc2).update().operation()
Nils Diewald7c8ced22015-04-15 19:21:00 +00001350 ).toEqual("and");
1351 // Structur is now:
1352 // or(doc, and(doc, or(doc, doc)))
1353
1354 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001355 'author = "Max Birkendale"' +
1356 ' | (pubDate since 2014-05-12 & ' +
1357 '(title = "Der Birnbaum" | pubDate in 2014-12-05))'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001358 );
1359
1360
1361 // Remove 1
1362 expect(andGroup.delOperand(doc1).update().operation()).toEqual("or");
1363 // Structur is now:
1364 // or(doc, doc, doc)
1365
1366 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001367 'author = "Max Birkendale" | title = "Der Birnbaum" | pubDate in 2014-12-05'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001368 );
1369 });
1370
1371 it('should be reducible to unspecification', function () {
1372 var vc = demoFactory.create();
1373
1374 expect(vc.toQuery()).toEqual(vc.root().toQuery());
1375 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001376 '(Titel = "Baum" & Veröffentlichungsort = "hihi" & ' +
1377 '(Titel = "Baum" | Veröffentlichungsort = "hihi")) ' +
1378 '| Untertitel ~ "huhu"');
Akrond141a362018-07-10 18:12:13 +02001379 expect(vc.root().element().lastChild.children[0].innerText).toEqual('and');
1380 expect(vc.root().element().lastChild.children[1].innerText).toEqual('×');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001381 expect(vc.root().delOperand(vc.root().getOperand(0)).update()).not.toBeUndefined();
Akron712733a2018-04-05 18:17:47 +02001382 expect(vc.toQuery()).toEqual('Untertitel ~ "huhu"');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001383
1384 var lc = vc.root().element().lastChild;
Akrond141a362018-07-10 18:12:13 +02001385 expect(lc.children[0].innerText).toEqual('and');
1386 expect(lc.children[1].innerText).toEqual('or');
1387 expect(lc.children[2].innerText).toEqual('×');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001388
1389 // Clean everything
1390 vc.clean();
1391 expect(vc.toQuery()).toEqual('');
1392 });
1393
1394 it('should flatten on import', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00001395 var vc = vcClass.create().fromJson({
Akron712733a2018-04-05 18:17:47 +02001396 "@type":"koral:docGroup",
1397 "operation":"operation:or",
1398 "operands":[
1399 {
1400 "@type":"koral:docGroup",
1401 "operation":"operation:or",
1402 "operands":[
Nils Diewald7c8ced22015-04-15 19:21:00 +00001403 {
Akron712733a2018-04-05 18:17:47 +02001404 "@type":"koral:doc",
1405 "key":"Titel",
1406 "value":"Baum",
1407 "match":"match:eq"
Nils Diewald7c8ced22015-04-15 19:21:00 +00001408 },
1409 {
Akron712733a2018-04-05 18:17:47 +02001410 "@type":"koral:doc",
1411 "key":"Veröffentlichungsort",
1412 "value":"hihi",
1413 "match":"match:eq"
Nils Diewald7c8ced22015-04-15 19:21:00 +00001414 },
1415 {
Akron712733a2018-04-05 18:17:47 +02001416 "@type":"koral:docGroup",
1417 "operation":"operation:or",
1418 "operands":[
1419 {
1420 "@type":"koral:doc",
1421 "key":"Titel",
1422 "value":"Baum",
1423 "match":"match:eq"
1424 },
1425 {
1426 "@type":"koral:doc",
1427 "key":"Veröffentlichungsort",
1428 "value":"hihi",
1429 "match":"match:eq"
1430 }
1431 ]
Nils Diewald7c8ced22015-04-15 19:21:00 +00001432 }
Akron712733a2018-04-05 18:17:47 +02001433 ]
1434 },
1435 {
1436 "@type":"koral:doc",
1437 "key":"Untertitel",
1438 "value":"huhu",
1439 "match":"match:contains"
1440 }
1441 ]
Nils Diewald7c8ced22015-04-15 19:21:00 +00001442 });
Nils Diewaldfda29d92015-01-22 17:28:01 +00001443
Nils Diewald7c8ced22015-04-15 19:21:00 +00001444 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001445 'Titel = "Baum" | Veröffentlichungsort = "hihi" | Untertitel ~ "huhu"'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001446 );
Nils Diewald86dad5b2015-01-28 15:09:07 +00001447 });
Akron1bdf5272018-07-24 18:51:30 +02001448
1449 it('should be deserializable from collection 1', function () {
1450 var kq = {
1451 "matches":["..."],
1452 "collection":{
1453 "@type": "koral:docGroup",
1454 "operation": "operation:or",
1455 "operands": [{
1456 "@type": "koral:docGroup",
1457 "operation": "operation:and",
1458 "operands": [
1459 {
1460 "@type": "koral:doc",
1461 "key": "title",
1462 "match": "match:eq",
1463 "value": "Der Birnbaum",
1464 "type": "type:string"
1465 },
1466 {
1467 "@type": "koral:doc",
1468 "key": "pubPlace",
1469 "match": "match:eq",
1470 "value": "Mannheim",
1471 "type": "type:string"
1472 },
1473 {
1474 "@type": "koral:docGroup",
1475 "operation": "operation:or",
1476 "operands": [
1477 {
1478 "@type": "koral:doc",
1479 "key": "subTitle",
1480 "match": "match:eq",
1481 "value": "Aufzucht und Pflege",
1482 "type": "type:string"
1483 },
1484 {
1485 "@type": "koral:doc",
1486 "key": "subTitle",
1487 "match": "match:eq",
1488 "value": "Gedichte",
1489 "type": "type:string"
1490 }
1491 ]
1492 }
1493 ]
1494 },{
1495 "@type": "koral:doc",
1496 "key": "pubDate",
1497 "match": "match:geq",
1498 "value": "2015-03-05",
1499 "type": "type:date",
1500 "rewrites" : [{
1501 "@type" : "koral:rewrite",
1502 "operation" : "operation:modification",
1503 "src" : "querySerializer",
1504 "scope" : "tree"
1505 }]
1506 }]
1507 }
1508 };
1509
1510 var vc = vcClass.create().fromJson(kq["collection"]);
1511 expect(vc.toQuery()).toEqual('(title = "Der Birnbaum" & pubPlace = "Mannheim" & (subTitle = "Aufzucht und Pflege" | subTitle = "Gedichte")) | pubDate since 2015-03-05');
1512 });
1513
1514 it('should be deserializable from collection 2', function () {
1515 var kq = {
1516 "@context": "http://korap.ids-mannheim.de/ns/KoralQuery/v0.3/context.jsonld",
1517 "meta": {},
1518 "query": {
1519 "@type": "koral:token",
1520 "wrap": {
1521 "@type": "koral:term",
1522 "match": "match:eq",
1523 "layer": "orth",
1524 "key": "Baum",
1525 "foundry": "opennlp",
1526 "rewrites": [
1527 {
1528 "@type": "koral:rewrite",
1529 "src": "Kustvakt",
1530 "operation": "operation:injection",
1531 "scope": "foundry"
1532 }
1533 ]
1534 },
1535 "idn": "Baum_2227",
1536 "rewrites": [
1537 {
1538 "@type": "koral:rewrite",
1539 "src": "Kustvakt",
1540 "operation": "operation:injection",
1541 "scope": "idn"
1542 }
1543 ]
1544 },
1545 "collection": {
1546 "@type": "koral:docGroup",
1547 "operation": "operation:and",
1548 "operands": [
1549 {
1550 "@type": "koral:doc",
1551 "match": "match:eq",
1552 "type": "type:regex",
1553 "value": "CC-BY.*",
1554 "key": "availability"
1555 },
1556 {
1557 "@type": "koral:doc",
1558 "match": "match:eq",
1559 "type":"type:text",
1560 "value": "Goethe",
1561 "key": "author"
1562 }
1563 ],
1564 "rewrites": [
1565 {
1566 "@type": "koral:rewrite",
1567 "src": "Kustvakt",
1568 "operation": "operation:insertion",
1569 "scope": "availability(FREE)"
1570 }
1571 ]
1572 },
1573 "matches": []
1574 };
1575
1576 var vc = vcClass.create().fromJson(kq["collection"]);
1577 expect(vc.toQuery()).toEqual('availability = /CC-BY.*/ & author = "Goethe"');
1578 });
Nils Diewald86dad5b2015-01-28 15:09:07 +00001579
Akron8a670162018-08-28 10:09:13 +02001580 it('shouldn\'t be deserializable from collection with unknown type', function () {
1581 var kq = {
1582 "@type" : "koral:doc",
1583 "match": "match:eq",
1584 "type":"type:failure",
1585 "value": "Goethe",
1586 "key": "author"
1587 };
Akron1bdf5272018-07-24 18:51:30 +02001588
Akron8a670162018-08-28 10:09:13 +02001589 expect(function () {
1590 vcClass.create().fromJson(kq)
1591 }).toThrow(new Error("Unknown value type: string"));
1592 });
1593
1594 it('should return a name', function () {
1595 var vc = vcClass.create();
1596 expect(vc.getName()).toEqual(KorAP.Locale.VC_allCorpora);
1597
1598 vc = vcClass.create().fromJson({"@type" : "koral:docGroupRef", "ref" : "DeReKo"});
1599 expect(vc.getName()).toEqual("DeReKo");
1600
1601 vc = vcClass.create().fromJson({"@type" : "koral:doc", "key" : "author", "value" : "Peter"});
1602 expect(vc.getName()).toEqual(KorAP.Locale.VC_oneCollection);
1603 });
Akrond2474aa2018-08-28 12:06:27 +02001604
1605 it('should check for rewrites', function () {
1606
1607 var vc = vcClass.create().fromJson({
1608 "@type" : "koral:doc",
1609 "key" : "author",
1610 "value" : "Goethe",
1611 "rewrites" : [{
1612 "@type" : "koral:rewrite",
1613 "operation" : "operation:modification",
1614 "src" : "querySerializer",
1615 "scope" : "value"
1616 }]
1617 });
1618 expect(vc.wasRewritten()).toBeTruthy();
1619
1620 var nested = {
1621 "@type" : "koral:docGroup",
1622 "operation" : "operation:or",
1623 "operands" : [
1624 {
1625 "@type" : "koral:doc",
1626 "key" : "author",
1627 "value" : "Goethe"
1628 },
1629 {
1630 "@type" : "koral:docGroup",
1631 "operation" : "operation:and",
1632 "operands" : [
1633 {
1634 "@type": "koral:doc",
1635 "key" : "author",
1636 "value" : "Schiller"
1637 },
1638 {
1639 "@type": "koral:doc",
1640 "key" : "author",
1641 "value" : "Fontane"
1642 }
1643 ]
1644 }
1645 ]
1646 };
1647 vc = vcClass.create().fromJson(nested);
1648 expect(vc.wasRewritten()).toBe(false);
1649
1650 nested["operands"][1]["operands"][1]["rewrites"] = [{
1651 "@type" : "koral:rewrite",
1652 "operation" : "operation:modification",
1653 "src" : "querySerializer",
1654 "scope" : "tree"
1655 }];
1656 vc = vcClass.create().fromJson(nested);
1657 expect(vc.wasRewritten()).toBeTruthy();
1658 });
Akron1bdf5272018-07-24 18:51:30 +02001659 });
1660
1661
Nils Diewald7c8ced22015-04-15 19:21:00 +00001662 describe('KorAP.Operators', function () {
1663 it('should be initializable', function () {
1664 var op = operatorsClass.create(true, false, false);
1665 expect(op.and()).toBeTruthy();
1666 expect(op.or()).not.toBeTruthy();
1667 expect(op.del()).not.toBeTruthy();
1668
1669 op.and(false);
1670 expect(op.and()).not.toBeTruthy();
1671 expect(op.or()).not.toBeTruthy();
1672 expect(op.del()).not.toBeTruthy();
1673
1674 op.or(true);
1675 op.del(true);
1676 expect(op.and()).not.toBeTruthy();
1677 expect(op.or()).toBeTruthy();
1678 expect(op.del()).toBeTruthy();
1679
Akrond141a362018-07-10 18:12:13 +02001680 var e = op.update();
Akron0b489ad2018-02-02 16:49:32 +01001681 expect(e.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001682 expect(e.children[0].getAttribute('class')).toEqual('or');
Akrond141a362018-07-10 18:12:13 +02001683 expect(e.children[0].innerText).toEqual('or');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001684 expect(e.children[1].getAttribute('class')).toEqual('delete');
Akrond141a362018-07-10 18:12:13 +02001685 expect(e.children[1].innerText).toEqual('×');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001686
1687 op.and(true);
1688 op.del(false);
Akrond141a362018-07-10 18:12:13 +02001689 e = op.update();
Nils Diewald7c8ced22015-04-15 19:21:00 +00001690
Akron0b489ad2018-02-02 16:49:32 +01001691 expect(e.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001692 expect(e.children[0].getAttribute('class')).toEqual('and');
Akrond141a362018-07-10 18:12:13 +02001693 expect(e.children[0].innerText).toEqual('and');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001694 expect(e.children[1].getAttribute('class')).toEqual('or');
Akrond141a362018-07-10 18:12:13 +02001695 expect(e.children[1].innerText).toEqual('or');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001696 });
1697 });
1698
1699 describe('KorAP._delete (event)', function () {
1700 var complexVCFactory = buildFactory(vcClass,{
1701 "@type": 'koral:docGroup',
1702 'operation' : 'operation:and',
1703 'operands' : [
Akron712733a2018-04-05 18:17:47 +02001704 {
1705 "@type": 'koral:doc',
1706 "key": 'pubDate',
1707 "match": 'match:eq',
1708 "value": '2014-12-05',
1709 "type": 'type:date'
1710 },
1711 {
1712 "@type" : 'koral:docGroup',
1713 'operation' : 'operation:or',
1714 'operands' : [
1715 {
1716 '@type' : 'koral:doc',
1717 'key' : 'title',
1718 'value' : 'Hello World!'
1719 },
1720 {
1721 '@type' : 'koral:doc',
1722 'key' : 'foo',
1723 'value' : 'bar'
1724 }
1725 ]
1726 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00001727 ]
1728 });
1729
1730 it('should clean on root docs', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00001731 var vc = vcClass.create().fromJson({
Akron712733a2018-04-05 18:17:47 +02001732 "@type": 'koral:doc',
1733 "key": 'pubDate',
1734 "match": 'match:eq',
1735 "value": '2014-12-05',
1736 "type": 'type:date'
Nils Diewald86dad5b2015-01-28 15:09:07 +00001737 });
Nils Diewald7c8ced22015-04-15 19:21:00 +00001738 expect(vc.root().toQuery()).toEqual('pubDate in 2014-12-05');
Akron0b489ad2018-02-02 16:49:32 +01001739 expect(vc.root().element().lastChild.getAttribute('class')).toEqual('operators button-group');
Nils Diewald86dad5b2015-01-28 15:09:07 +00001740
Nils Diewald7c8ced22015-04-15 19:21:00 +00001741 // Clean with delete from root
1742 expect(vc.root().element().lastChild.lastChild.getAttribute('class')).toEqual('delete');
1743 _delOn(vc.root());
1744 expect(vc.root().toQuery()).toEqual('');
Akronebc96662018-08-29 17:36:20 +02001745 expect(vc.root().element().lastChild.lastChild.data).toEqual(KorAP.Locale.EMPTY);
1746 expect(vc.root().element().classList.contains('unspecified')).toEqual(true);
Nils Diewald7c8ced22015-04-15 19:21:00 +00001747 });
Nils Diewald86dad5b2015-01-28 15:09:07 +00001748
Nils Diewald7c8ced22015-04-15 19:21:00 +00001749 it('should remove on nested docs', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00001750 var vc = vcClass.create().fromJson(
Akron712733a2018-04-05 18:17:47 +02001751 {
1752 "@type": 'koral:docGroup',
1753 'operation' : 'operation:and',
1754 'operands' : [
1755 {
1756 "@type": 'koral:doc',
1757 "key": 'pubDate',
1758 "match": 'match:eq',
1759 "value": '2014-12-05',
1760 "type": 'type:date'
1761 },
1762 {
1763 "@type" : 'koral:doc',
1764 'key' : 'foo',
1765 'value' : 'bar'
1766 }
1767 ]
1768 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00001769 );
1770
1771 // Delete with direct element access
1772 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar"');
1773 _delOn(vc.root().getOperand(0));
1774
1775 expect(vc.toQuery()).toEqual('foo = "bar"');
1776 expect(vc.root().ldType()).toEqual('doc');
1777 });
1778
1779 it('should clean on doc groups', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00001780 var vc = vcClass.create().fromJson(
Akron712733a2018-04-05 18:17:47 +02001781 {
1782 "@type": 'koral:docGroup',
1783 'operation' : 'operation:and',
1784 'operands' : [
1785 {
1786 "@type": 'koral:doc',
1787 "key": 'pubDate',
1788 "match": 'match:eq',
1789 "value": '2014-12-05',
1790 "type": 'type:date'
1791 },
1792 {
1793 "@type" : 'koral:doc',
1794 'key' : 'foo',
1795 'value' : 'bar'
1796 }
1797 ]
1798 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00001799 );
1800
1801 // Cleanwith direct element access
1802 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar"');
1803 _delOn(vc.root());
1804 expect(vc.toQuery()).toEqual('');
1805 expect(vc.root().ldType()).toEqual('non');
1806 });
1807
1808 it('should remove on nested doc groups (case of ungrouping 1)', function () {
1809 var vc = complexVCFactory.create();
1810
1811 // Delete with direct element access
1812 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001813 'pubDate in 2014-12-05 & (title = "Hello World!" | foo = "bar")'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001814 );
1815
1816 // Remove hello world:
1817 _delOn(vc.root().getOperand(1).getOperand(0));
1818 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar"');
1819 expect(vc.root().ldType()).toEqual('docGroup');
1820 });
1821
1822 it('should remove on nested doc groups (case of ungrouping 2)', function () {
1823 var vc = complexVCFactory.create();
1824
1825 // Delete with direct element access
1826 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001827 'pubDate in 2014-12-05 & (title = "Hello World!" | foo = "bar")'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001828 );
1829
1830 // Remove bar
1831 _delOn(vc.root().getOperand(1).getOperand(1));
1832 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & title = "Hello World!"');
1833 expect(vc.root().ldType()).toEqual('docGroup');
1834 expect(vc.root().operation()).toEqual('and');
1835 });
1836
1837 it('should remove on nested doc groups (case of root changing)', function () {
1838 var vc = complexVCFactory.create();
1839
1840 // Delete with direct element access
1841 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001842 'pubDate in 2014-12-05 & ' +
1843 '(title = "Hello World!" | foo = "bar")'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001844 );
1845
1846 // Remove bar
1847 _delOn(vc.root().getOperand(0));
1848 expect(vc.toQuery()).toEqual('title = "Hello World!" | foo = "bar"');
1849 expect(vc.root().ldType()).toEqual('docGroup');
1850 expect(vc.root().operation()).toEqual('or');
1851 });
1852
1853 it('should remove on nested doc groups (list flattening)', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00001854 var vc = vcClass.create().fromJson(
Akron712733a2018-04-05 18:17:47 +02001855 {
1856 "@type": 'koral:docGroup',
1857 'operation' : 'operation:or',
1858 'operands' : [
1859 {
1860 "@type": 'koral:doc',
1861 "key": 'pubDate',
1862 "match": 'match:eq',
1863 "value": '2014-12-05',
1864 "type": 'type:date'
1865 },
1866 {
1867 "@type" : 'koral:doc',
1868 'key' : 'foo',
1869 'value' : 'bar'
1870 },
1871 {
1872 "@type": 'koral:docGroup',
1873 'operation' : 'operation:and',
1874 'operands' : [
1875 {
1876 "@type": 'koral:doc',
1877 "key": 'pubDate',
1878 "match": 'match:eq',
1879 "value": '2014-12-05',
1880 "type": 'type:date'
1881 },
1882 {
1883 "@type" : 'koral:docGroup',
1884 'operation' : 'operation:or',
1885 'operands' : [
1886 {
1887 '@type' : 'koral:doc',
1888 'key' : 'title',
1889 'value' : 'Hello World!'
1890 },
1891 {
1892 '@type' : 'koral:doc',
1893 'key' : 'yeah',
1894 'value' : 'juhu'
1895 }
1896 ]
1897 }
1898 ]
1899 }
1900 ]
1901 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00001902 );
1903
1904 // Delete with direct element access
1905 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001906 'pubDate in 2014-12-05 | foo = "bar" | ' +
1907 '(pubDate in 2014-12-05 & ' +
1908 '(title = "Hello World!" | yeah = "juhu"))'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001909 );
1910
1911 expect(vc.root().ldType()).toEqual('docGroup');
1912 expect(vc.root().operation()).toEqual('or');
1913
1914 // Operands and operators
Akronadab5e52018-08-20 13:50:53 +02001915 expect(vc.builder().firstChild.children.length).toEqual(4);
1916 expect(vc.builder().firstChild.lastChild.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001917
1918 // Remove inner group and flatten
1919 _delOn(vc.root().getOperand(2).getOperand(0));
1920
1921 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001922 'pubDate in 2014-12-05 | foo = "bar" | title = "Hello World!" | yeah = "juhu"'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001923 );
1924 expect(vc.root().ldType()).toEqual('docGroup');
1925 expect(vc.root().operation()).toEqual('or');
1926
1927 // Operands and operators
Akronadab5e52018-08-20 13:50:53 +02001928 expect(vc.builder().firstChild.children.length).toEqual(5);
1929 expect(vc.builder().firstChild.lastChild.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001930 });
1931 });
1932
1933 describe('KorAP._add (event)', function () {
1934 var complexVCFactory = buildFactory(vcClass,{
1935 "@type": 'koral:docGroup',
1936 'operation' : 'operation:and',
1937 'operands' : [
Akron712733a2018-04-05 18:17:47 +02001938 {
1939 "@type": 'koral:doc',
1940 "key": 'pubDate',
1941 "match": 'match:eq',
1942 "value": '2014-12-05',
1943 "type": 'type:date'
1944 },
1945 {
1946 "@type" : 'koral:docGroup',
1947 'operation' : 'operation:or',
1948 'operands' : [
1949 {
1950 '@type' : 'koral:doc',
1951 'key' : 'title',
1952 'value' : 'Hello World!'
1953 },
1954 {
1955 '@type' : 'koral:doc',
1956 'key' : 'foo',
1957 'value' : 'bar'
1958 }
1959 ]
1960 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00001961 ]
1962 });
1963
1964 it('should add new unspecified doc with "and"', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00001965 var vc = vcClass.create().fromJson(
Akron712733a2018-04-05 18:17:47 +02001966 {
1967 "@type": 'koral:docGroup',
1968 'operation' : 'operation:and',
1969 'operands' : [
1970 {
1971 "@type": 'koral:doc',
1972 "key": 'pubDate',
1973 "match": 'match:eq',
1974 "value": '2014-12-05',
1975 "type": 'type:date'
1976 },
1977 {
1978 "@type" : 'koral:doc',
1979 'key' : 'foo',
1980 'value' : 'bar'
Akronb19803c2018-08-16 16:39:42 +02001981 },
1982 {
1983 "@type" : "koral:docGroupRef",
1984 "ref" : "myCorpus"
Akron712733a2018-04-05 18:17:47 +02001985 }
1986 ]
1987 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00001988 );
1989
Akronb19803c2018-08-16 16:39:42 +02001990 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar" & referTo "myCorpus"');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001991
Akronadab5e52018-08-20 13:50:53 +02001992 var fc = vc.builder().firstChild;
Nils Diewald7c8ced22015-04-15 19:21:00 +00001993 expect(fc.getAttribute('data-operation')).toEqual('and');
Akronb19803c2018-08-16 16:39:42 +02001994 expect(fc.children.length).toEqual(4);
Akron0b489ad2018-02-02 16:49:32 +01001995 expect(fc.lastChild.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001996 expect(fc.children[0].getAttribute('class')).toEqual('doc');
1997 expect(fc.children[1].getAttribute('class')).toEqual('doc');
Akronb19803c2018-08-16 16:39:42 +02001998 expect(fc.children[2].getAttribute('class')).toEqual('doc groupref');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001999
2000 // add with 'and' in the middle
2001 _andOn(vc.root().getOperand(0));
Akronb19803c2018-08-16 16:39:42 +02002002 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar" & referTo "myCorpus"');
Nils Diewald7c8ced22015-04-15 19:21:00 +00002003
Akronadab5e52018-08-20 13:50:53 +02002004 fc = vc.builder().firstChild;
Nils Diewald7c8ced22015-04-15 19:21:00 +00002005 expect(fc.getAttribute('data-operation')).toEqual('and');
Akronb19803c2018-08-16 16:39:42 +02002006 expect(fc.children.length).toEqual(5);
Akron0b489ad2018-02-02 16:49:32 +01002007 expect(fc.lastChild.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +00002008
2009 expect(fc.children[0].getAttribute('class')).toEqual('doc');
2010 expect(fc.children[1].getAttribute('class')).toEqual('doc unspecified');
2011 expect(fc.children[2].getAttribute('class')).toEqual('doc');
Akronb19803c2018-08-16 16:39:42 +02002012 expect(fc.children[3].getAttribute('class')).toEqual('doc groupref');
2013 expect(fc.children[4].classList.contains('button-group')).toBeTruthy();
2014 expect(fc.children.length).toEqual(5);
2015
2016 _andOn(vc.root().getOperand(3));
2017 expect(fc.children[0].getAttribute('class')).toEqual('doc');
2018 expect(fc.children[1].getAttribute('class')).toEqual('doc unspecified');
2019 expect(fc.children[2].getAttribute('class')).toEqual('doc');
2020 expect(fc.children[3].getAttribute('class')).toEqual('doc groupref');
2021 expect(fc.children[4].getAttribute('class')).toEqual('doc unspecified');
2022 expect(fc.children[5].classList.contains('button-group')).toBeTruthy();
2023 expect(fc.children.length).toEqual(6);
2024
Nils Diewald7c8ced22015-04-15 19:21:00 +00002025 });
2026
Akronb19803c2018-08-16 16:39:42 +02002027
Nils Diewald7c8ced22015-04-15 19:21:00 +00002028 it('should add new unspecified doc with "or"', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00002029 var vc = vcClass.create().fromJson(
Akron712733a2018-04-05 18:17:47 +02002030 {
2031 "@type": 'koral:docGroup',
2032 'operation' : 'operation:and',
2033 'operands' : [
2034 {
2035 "@type": 'koral:doc',
2036 "key": 'pubDate',
2037 "match": 'match:eq',
2038 "value": '2014-12-05',
2039 "type": 'type:date'
2040 },
2041 {
2042 "@type" : 'koral:doc',
2043 'key' : 'foo',
2044 'value' : 'bar'
Akronb19803c2018-08-16 16:39:42 +02002045 },
2046 {
2047 "@type" : "koral:docGroupRef",
2048 "ref" : "myCorpus"
Akron712733a2018-04-05 18:17:47 +02002049 }
2050 ]
2051 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00002052 );
2053
Akronb19803c2018-08-16 16:39:42 +02002054 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar" & referTo "myCorpus"');
Nils Diewald7c8ced22015-04-15 19:21:00 +00002055
Akronadab5e52018-08-20 13:50:53 +02002056 var fc = vc.builder().firstChild;
Akronb19803c2018-08-16 16:39:42 +02002057 expect(fc.children.length).toEqual(4);
Akron0b489ad2018-02-02 16:49:32 +01002058 expect(fc.lastChild.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +00002059 expect(fc.children[0].getAttribute('class')).toEqual('doc');
2060 expect(fc.children[1].getAttribute('class')).toEqual('doc');
Akronb19803c2018-08-16 16:39:42 +02002061 expect(fc.children[2].getAttribute('class')).toEqual('doc groupref');
Nils Diewald7c8ced22015-04-15 19:21:00 +00002062
2063 // add with 'or' in the middle
2064 _orOn(vc.root().getOperand(0));
Akronb19803c2018-08-16 16:39:42 +02002065 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar" & referTo "myCorpus"');
Akronadab5e52018-08-20 13:50:53 +02002066 fc = vc.builder().firstChild;
Nils Diewald7c8ced22015-04-15 19:21:00 +00002067
2068 expect(fc.getAttribute('data-operation')).toEqual('and');
Akronb19803c2018-08-16 16:39:42 +02002069 expect(fc.children.length).toEqual(4);
Nils Diewald7c8ced22015-04-15 19:21:00 +00002070 expect(fc.children[0].getAttribute('class')).toEqual('docGroup');
2071 expect(fc.children[0].getAttribute('data-operation')).toEqual('or');
2072 expect(fc.children[1].getAttribute('class')).toEqual('doc');
Akronb19803c2018-08-16 16:39:42 +02002073 expect(fc.children[2].getAttribute('class')).toEqual('doc groupref');
2074 expect(fc.children[3].getAttribute('class')).toEqual('operators button-group');
Akron0b489ad2018-02-02 16:49:32 +01002075 expect(fc.lastChild.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +00002076
Akronadab5e52018-08-20 13:50:53 +02002077 fc = vc.builder().firstChild.firstChild;
Nils Diewald7c8ced22015-04-15 19:21:00 +00002078 expect(fc.children.length).toEqual(3);
2079 expect(fc.children[0].getAttribute('class')).toEqual('doc');
2080 expect(fc.children[1].getAttribute('class')).toEqual('doc unspecified');
Akron0b489ad2018-02-02 16:49:32 +01002081 expect(fc.children[2].getAttribute('class')).toEqual('operators button-group');
2082 expect(fc.lastChild.getAttribute('class')).toEqual('operators button-group');
Akronb19803c2018-08-16 16:39:42 +02002083
2084 _orOn(vc.root().getOperand(2));
Akronadab5e52018-08-20 13:50:53 +02002085 fc = vc.builder().firstChild;
Akronb19803c2018-08-16 16:39:42 +02002086 expect(fc.children.length).toEqual(4);
2087
2088 expect(fc.children[0].getAttribute('class')).toEqual('docGroup');
2089 expect(fc.children[1].getAttribute('class')).toEqual('doc');
2090 expect(fc.children[2].getAttribute('class')).toEqual('docGroup');
2091 expect(fc.children[3].getAttribute('class')).toEqual('operators button-group');
2092
Akronadab5e52018-08-20 13:50:53 +02002093 fc = vc.builder().firstChild.children[2];
Akronb19803c2018-08-16 16:39:42 +02002094 expect(fc.children[0].getAttribute('class')).toEqual('doc groupref');
2095 expect(fc.children[1].getAttribute('class')).toEqual('doc unspecified');
2096 expect(fc.children[2].getAttribute('class')).toEqual('operators button-group');
2097 expect(fc.lastChild.getAttribute('class')).toEqual('operators button-group');
2098
Nils Diewald7c8ced22015-04-15 19:21:00 +00002099 });
2100
2101 it('should add new unspecified doc with "and" before group', function () {
2102 var vc = demoFactory.create();
2103
2104 // Wrap with direct element access
2105 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02002106 '(Titel = "Baum" & ' +
2107 'Veröffentlichungsort = "hihi" & ' +
2108 '(Titel = "Baum" | ' +
2109 'Veröffentlichungsort = "hihi")) | ' +
2110 'Untertitel ~ "huhu"'
Nils Diewald7c8ced22015-04-15 19:21:00 +00002111 );
2112
2113 expect(vc.root().getOperand(0).ldType()).toEqual('docGroup');
2114 expect(vc.root().getOperand(0).operation()).toEqual('and');
2115 expect(vc.root().getOperand(0).operands().length).toEqual(3);
2116
2117 // Add unspecified on the second doc
2118 var secDoc = vc.root().getOperand(0).getOperand(1);
2119 expect(secDoc.value()).toEqual('hihi');
2120
2121 // Add
2122 _andOn(secDoc);
2123
2124 var fo = vc.root().getOperand(0);
2125
2126 expect(fo.ldType()).toEqual('docGroup');
2127 expect(fo.operation()).toEqual('and');
2128 expect(fo.operands().length).toEqual(4);
2129
2130 expect(fo.getOperand(0).ldType()).toEqual('doc');
2131 expect(fo.getOperand(1).ldType()).toEqual('doc');
2132 expect(fo.getOperand(2).ldType()).toEqual('non');
2133 expect(fo.getOperand(3).ldType()).toEqual('docGroup');
2134 });
2135
2136
2137 it('should remove a doc with an unspecified doc in a nested group', function () {
2138 var vc = demoFactory.create();
2139
2140 // Wrap with direct element access
2141 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02002142 '(Titel = "Baum" & Veröffentlichungsort = "hihi" & (Titel = "Baum" | Veröffentlichungsort = "hihi")) | Untertitel ~ "huhu"'
Nils Diewald7c8ced22015-04-15 19:21:00 +00002143 );
2144
2145 var fo = vc.root().getOperand(0).getOperand(0);
2146 expect(fo.key()).toEqual('Titel');
2147 expect(fo.value()).toEqual('Baum');
2148
2149 // Add unspecified on the root group
2150 _orOn(fo);
2151
2152 fo = vc.root().getOperand(0).getOperand(0);
2153
2154 expect(fo.operation()).toEqual('or');
2155 expect(fo.getOperand(0).ldType()).toEqual('doc');
2156 expect(fo.getOperand(1).ldType()).toEqual('non');
2157
2158 // Delete document
2159 _delOn(fo.getOperand(0));
2160
2161 // The operand is now non
2162 expect(vc.root().getOperand(0).getOperand(0).ldType()).toEqual('non');
2163 expect(vc.root().getOperand(0).getOperand(1).ldType()).toEqual('doc');
2164 expect(vc.root().getOperand(0).getOperand(2).ldType()).toEqual('docGroup');
2165 });
2166
2167
Akron712733a2018-04-05 18:17:47 +02002168 it('should remove an unspecified doc with a doc in a nested group', function () {
Nils Diewald7c8ced22015-04-15 19:21:00 +00002169 var vc = demoFactory.create();
2170
2171 // Wrap with direct element access
2172 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02002173 '(Titel = "Baum" & ' +
2174 'Veröffentlichungsort = "hihi" & ' +
2175 '(Titel = "Baum" ' +
2176 '| Veröffentlichungsort = "hihi")) | ' +
2177 'Untertitel ~ "huhu"'
Nils Diewald7c8ced22015-04-15 19:21:00 +00002178 );
2179
2180 var fo = vc.root().getOperand(0).getOperand(0);
2181 expect(fo.key()).toEqual('Titel');
2182 expect(fo.value()).toEqual('Baum');
2183
2184 // Add unspecified on the root group
2185 _orOn(fo);
2186
2187 fo = vc.root().getOperand(0).getOperand(0);
2188
2189 expect(fo.operation()).toEqual('or');
2190 expect(fo.getOperand(0).ldType()).toEqual('doc');
2191 expect(fo.getOperand(1).ldType()).toEqual('non');
2192
2193 // Delete unspecified doc
2194 _delOn(fo.getOperand(1));
2195
2196 // The operand is now non
2197 fo = vc.root().getOperand(0);
2198 expect(fo.getOperand(0).ldType()).toEqual('doc');
2199 expect(fo.getOperand(0).key()).toEqual('Titel');
2200 expect(fo.getOperand(0).value()).toEqual('Baum');
2201 expect(fo.getOperand(1).ldType()).toEqual('doc');
2202 expect(fo.getOperand(2).ldType()).toEqual('docGroup');
2203 });
2204
2205
2206 it('should add on parent group (case "and")', function () {
2207 var vc = complexVCFactory.create();
2208
2209 // Wrap with direct element access
2210 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02002211 'pubDate in 2014-12-05 & (title = "Hello World!" | foo = "bar")'
Nils Diewald7c8ced22015-04-15 19:21:00 +00002212 );
2213
2214 expect(vc.root().operands().length).toEqual(2);
2215
2216 // Add unspecified on the root group
2217 _andOn(vc.root().getOperand(1));
2218 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02002219 'pubDate in 2014-12-05 & (title = "Hello World!" | foo = "bar")'
Nils Diewald7c8ced22015-04-15 19:21:00 +00002220 );
2221
2222 expect(vc.root().ldType()).toEqual('docGroup');
2223 expect(vc.root().operands().length).toEqual(3);
2224 expect(vc.root().getOperand(0).ldType()).toEqual('doc');
2225 expect(vc.root().getOperand(1).ldType()).toEqual('docGroup');
2226 expect(vc.root().getOperand(1).operation()).toEqual('or');
2227 expect(vc.root().getOperand(2).ldType()).toEqual('non');
2228
2229 // Add another unspecified on the root group
2230 _andOn(vc.root().getOperand(1));
2231
2232 expect(vc.root().operands().length).toEqual(4);
2233 expect(vc.root().getOperand(0).ldType()).toEqual('doc');
2234 expect(vc.root().getOperand(1).ldType()).toEqual('docGroup');
2235 expect(vc.root().getOperand(2).ldType()).toEqual('non');
2236 expect(vc.root().getOperand(3).ldType()).toEqual('non');
2237
2238 // Add another unspecified after the first doc
2239 _andOn(vc.root().getOperand(0));
2240
2241 expect(vc.root().operands().length).toEqual(5);
2242 expect(vc.root().getOperand(0).ldType()).toEqual('doc');
2243 expect(vc.root().getOperand(1).ldType()).toEqual('non');
2244 expect(vc.root().getOperand(2).ldType()).toEqual('docGroup');
2245 expect(vc.root().getOperand(3).ldType()).toEqual('non');
2246 expect(vc.root().getOperand(4).ldType()).toEqual('non');
2247 });
2248
2249 it('should wrap on root', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00002250 var vc = vcClass.create().fromJson(
Akron712733a2018-04-05 18:17:47 +02002251 {
2252 "@type": 'koral:docGroup',
2253 'operation' : 'operation:and',
2254 'operands' : [
2255 {
2256 "@type": 'koral:doc',
2257 "key": 'pubDate',
2258 "match": 'match:eq',
2259 "value": '2014-12-05',
2260 "type": 'type:date'
2261 },
2262 {
2263 "@type" : 'koral:doc',
2264 'key' : 'foo',
2265 'value' : 'bar'
2266 }
2267 ]
2268 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00002269 );
2270
2271 // Wrap on root
2272 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar"');
2273 expect(vc.root().ldType()).toEqual('docGroup');
2274 expect(vc.root().operation()).toEqual('and');
2275 _orOn(vc.root());
2276 expect(vc.root().ldType()).toEqual('docGroup');
2277 expect(vc.root().operation()).toEqual('or');
2278
2279 expect(vc.root().getOperand(0).ldType()).toEqual('docGroup');
2280 expect(vc.root().getOperand(0).operation()).toEqual('and');
2281 });
2282
2283 it('should add on root (case "and")', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00002284 var vc = vcClass.create().fromJson(
Akron712733a2018-04-05 18:17:47 +02002285 {
2286 "@type": 'koral:doc',
2287 "key": 'pubDate',
2288 "match": 'match:eq',
2289 "value": '2014-12-05',
2290 "type": 'type:date'
2291 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00002292 );
2293
2294 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05');
2295 expect(vc.root().ldType()).toEqual('doc');
2296 expect(vc.root().key()).toEqual('pubDate');
2297 expect(vc.root().value()).toEqual('2014-12-05');
2298
2299 // Wrap on root
2300 _andOn(vc.root());
2301 expect(vc.root().ldType()).toEqual('docGroup');
2302 expect(vc.root().operation()).toEqual('and');
2303 });
2304
2305 it('should add on root (case "or")', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00002306 var vc = vcClass.create().fromJson(
Akron712733a2018-04-05 18:17:47 +02002307 {
2308 "@type": 'koral:doc',
2309 "key": 'pubDate',
2310 "match": 'match:eq',
2311 "value": '2014-12-05',
2312 "type": 'type:date'
2313 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00002314 );
2315
2316 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05');
2317 expect(vc.root().key()).toEqual('pubDate');
2318 expect(vc.root().value()).toEqual('2014-12-05');
2319
2320 // Wrap on root
2321 _orOn(vc.root());
2322 expect(vc.root().ldType()).toEqual('docGroup');
2323 expect(vc.root().operation()).toEqual('or');
2324 });
2325
2326 it('should support multiple sub groups per group', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00002327 var vc = vcClass.create().fromJson(
Akron712733a2018-04-05 18:17:47 +02002328 {
2329 "@type": 'koral:docGroup',
2330 'operation' : 'operation:or',
2331 'operands' : [
2332 {
2333 "@type": 'koral:docGroup',
2334 'operation' : 'operation:and',
2335 'operands' : [
2336 {
2337 "@type": 'koral:doc',
2338 "key": 'title',
2339 "value": 't1',
2340 },
2341 {
2342 "@type" : 'koral:doc',
2343 'key' : 'title',
2344 'value' : 't2'
2345 }
2346 ]
2347 },
2348 {
2349 "@type": 'koral:docGroup',
2350 'operation' : 'operation:and',
2351 'operands' : [
2352 {
2353 "@type": 'koral:doc',
2354 "key": 'title',
2355 "value": 't3',
2356 },
2357 {
2358 "@type" : 'koral:doc',
2359 'key' : 'title',
2360 'value' : 't4'
2361 }
2362 ]
2363 }
2364 ]
2365 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00002366 );
2367 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02002368 '(title = "t1" & title = "t2") | ' +
2369 '(title = "t3" & title = "t4")'
Nils Diewald7c8ced22015-04-15 19:21:00 +00002370 );
2371 expect(vc.root().operation()).toEqual('or');
2372 expect(vc.root().getOperand(0).toQuery()).toEqual('title = "t1" & title = "t2"');
2373 expect(vc.root().getOperand(1).toQuery()).toEqual('title = "t3" & title = "t4"');
2374
2375 _andOn(vc.root());
2376
2377 expect(vc.root().operation()).toEqual('and');
2378 expect(vc.root().getOperand(0).ldType()).toEqual('docGroup');
2379 expect(vc.root().getOperand(1).ldType()).toEqual('non');
2380 });
2381 });
2382
Nils Diewald6283d692015-04-23 20:32:53 +00002383
2384 describe('KorAP.Rewrite', function () {
Nils Diewald7c8ced22015-04-15 19:21:00 +00002385 it('should be initializable', function () {
2386 var rewrite = rewriteClass.create({
Akron712733a2018-04-05 18:17:47 +02002387 "@type" : "koral:rewrite",
2388 "operation" : "operation:modification",
2389 "src" : "querySerializer",
2390 "scope" : "tree"
Nils Diewald86dad5b2015-01-28 15:09:07 +00002391 });
Nils Diewald7c8ced22015-04-15 19:21:00 +00002392 expect(rewrite.toString()).toEqual('Modification of "tree" by "querySerializer"');
2393 });
Nils Diewald86dad5b2015-01-28 15:09:07 +00002394
Nils Diewald7c8ced22015-04-15 19:21:00 +00002395 it('should be deserialized by docs', function () {
2396 var doc = docClass.create(
Akron712733a2018-04-05 18:17:47 +02002397 undefined,
2398 {
2399 "@type":"koral:doc",
2400 "key":"Titel",
2401 "value":"Baum",
2402 "match":"match:eq"
2403 });
Nils Diewald7c8ced22015-04-15 19:21:00 +00002404
2405 expect(doc.element().classList.contains('doc')).toBeTruthy();
2406 expect(doc.element().classList.contains('rewritten')).toBe(false);
2407
2408 doc = docClass.create(
Akron712733a2018-04-05 18:17:47 +02002409 undefined,
2410 {
2411 "@type":"koral:doc",
2412 "key":"Titel",
2413 "value":"Baum",
2414 "match":"match:eq",
2415 "rewrites" : [
2416 {
2417 "@type" : "koral:rewrite",
2418 "operation" : "operation:modification",
2419 "src" : "querySerializer",
2420 "scope" : "tree"
2421 }
2422 ]
2423 });
Nils Diewald7c8ced22015-04-15 19:21:00 +00002424
2425 expect(doc.element().classList.contains('doc')).toBeTruthy();
2426 expect(doc.element().classList.contains('rewritten')).toBeTruthy();
2427 });
Nils Diewald6283d692015-04-23 20:32:53 +00002428
Akron76c3dd62018-05-29 20:58:27 +02002429 it('should be described in a title attribute', function () {
2430
2431 doc = docClass.create(
2432 undefined,
2433 {
2434 "@type":"koral:doc",
2435 "key":"Titel",
2436 "value":"Baum",
2437 "match":"match:eq",
2438 "rewrites" : [
2439 {
2440 "@type" : "koral:rewrite",
2441 "operation" : "operation:modification",
2442 "src" : "querySerializer",
2443 "scope" : "tree"
2444 },
2445 {
2446 "@type" : "koral:rewrite",
2447 "operation" : "operation:injection",
2448 "src" : "me"
2449 }
2450 ]
2451 });
2452
2453 expect(doc.element().classList.contains('doc')).toBeTruthy();
2454 expect(doc.element().classList.contains('rewritten')).toBeTruthy();
2455 expect(doc.element().lastChild.getAttribute("title")).toEqual("querySerializer: tree (modification)\nme (injection)");
2456 });
2457
2458
Nils Diewald6283d692015-04-23 20:32:53 +00002459 xit('should be deserialized by docGroups', function () {
2460 var docGroup = docGroupClass.create(
Akron712733a2018-04-05 18:17:47 +02002461 undefined,
2462 {
2463 "@type" : "koral:docGroup",
2464 "operation" : "operation:or",
2465 "operands" : [
2466 {
2467 "@type" : "doc",
2468 "key" : "pubDate",
2469 "type" : "type:date",
2470 "value" : "2014-12-05"
2471 },
2472 {
2473 "@type" : "doc",
2474 "key" : "pubDate",
2475 "type" : "type:date",
2476 "value" : "2014-12-06"
2477 }
2478 ],
2479 "rewrites" : [
2480 {
2481 "@type" : "koral:rewrite",
2482 "operation" : "operation:modification",
2483 "src" : "querySerializer",
2484 "scope" : "tree"
2485 }
2486 ]
2487 }
Nils Diewald6283d692015-04-23 20:32:53 +00002488 );
2489
2490 expect(doc.element().classList.contains('docgroup')).toBeTruthy();
2491 expect(doc.element().classList.contains('rewritten')).toBe(false);
2492 });
Nils Diewald86dad5b2015-01-28 15:09:07 +00002493 });
Nils Diewaldf0c4f112015-05-05 12:56:59 +00002494
2495 describe('KorAP.stringValue', function () {
2496 it('should be initializable', function () {
2497 var sv = stringValClass.create();
2498 expect(sv.regex()).toBe(false);
2499 expect(sv.value()).toBe('');
Nils Diewaldc4c4b832015-05-05 16:00:08 +00002500
2501 sv = stringValClass.create('Baum');
2502 expect(sv.regex()).toBe(false);
2503 expect(sv.value()).toBe('Baum');
2504
2505 sv = stringValClass.create('Baum', false);
2506 expect(sv.regex()).toBe(false);
2507 expect(sv.value()).toBe('Baum');
2508
2509 sv = stringValClass.create('Baum', true);
2510 expect(sv.regex()).toBe(true);
2511 expect(sv.value()).toBe('Baum');
2512 });
2513
2514 it('should be modifiable', function () {
2515 var sv = stringValClass.create();
2516 expect(sv.regex()).toBe(false);
2517 expect(sv.value()).toBe('');
2518
2519 expect(sv.value('Baum')).toBe('Baum');
2520 expect(sv.value()).toBe('Baum');
2521
2522 expect(sv.regex(true)).toBe(true);
2523 expect(sv.regex()).toBe(true);
2524 });
2525
2526 it('should have a toggleble regex value', function () {
2527 var sv = stringValClass.create();
Nils Diewald7991a3f2015-05-19 14:12:37 +00002528
2529 expect(sv.element().firstChild.value).toBe('');
2530 sv.element().firstChild.value = 'der'
2531 expect(sv.element().firstChild.value).toBe('der');
2532
Nils Diewaldc4c4b832015-05-05 16:00:08 +00002533 expect(sv.regex()).toBe(false);
2534
2535 sv.toggleRegex();
Nils Diewald7991a3f2015-05-19 14:12:37 +00002536 expect(sv.element().firstChild.value).toBe('der');
Nils Diewaldc4c4b832015-05-05 16:00:08 +00002537 expect(sv.regex()).toBe(true);
Nils Diewald7991a3f2015-05-19 14:12:37 +00002538 sv.element().firstChild.value = 'derbe'
Nils Diewaldc4c4b832015-05-05 16:00:08 +00002539
2540 sv.toggleRegex();
2541 expect(sv.regex()).toBe(false);
Nils Diewald7991a3f2015-05-19 14:12:37 +00002542 expect(sv.element().firstChild.value).toBe('derbe');
Nils Diewaldc4c4b832015-05-05 16:00:08 +00002543 });
2544
2545 it('should have an element', function () {
2546 var sv = stringValClass.create('der');
2547 expect(sv.element().nodeName).toBe('DIV');
2548 expect(sv.element().firstChild.nodeName).toBe('INPUT');
2549 expect(sv.element().firstChild.value).toBe('der');
2550 });
2551
2552 it('should have a classed element', function () {
2553 var sv = stringValClass.create();
Nils Diewaldc4c4b832015-05-05 16:00:08 +00002554 expect(sv.element().classList.contains('regex')).toBe(false);
2555 expect(sv.regex()).toBe(false);
2556 sv.toggleRegex();
2557 expect(sv.element().classList.contains('regex')).toBe(true);
2558 });
2559
2560 it('should be storable', function () {
2561 var sv = stringValClass.create();
2562 var count = 1;
2563 sv.store = function (value, regex) {
Akron712733a2018-04-05 18:17:47 +02002564 expect(regex).toBe(true);
2565 expect(value).toBe('tree');
Nils Diewaldc4c4b832015-05-05 16:00:08 +00002566 };
2567 sv.regex(true);
2568 sv.value('tree');
2569 sv.element().lastChild.click();
Nils Diewaldf0c4f112015-05-05 12:56:59 +00002570 });
Akron712733a2018-04-05 18:17:47 +02002571
Akronb19803c2018-08-16 16:39:42 +02002572 it('should have a disableoption for regex', function () {
2573 var sv = stringValClass.create(undefined, undefined, true);
2574 var svE = sv.element();
2575 expect(svE.children.length).toEqual(2);
2576
2577 sv = stringValClass.create(undefined, undefined, false);
2578 svE = sv.element();
2579 expect(svE.children.length).toEqual(1);
2580 });
2581
Nils Diewaldf0c4f112015-05-05 12:56:59 +00002582 });
Akrone4961b12017-05-10 21:04:46 +02002583
Akron712733a2018-04-05 18:17:47 +02002584 describe('KorAP.VC.Menu', function () {
Akrone65a88a2018-04-05 19:14:20 +02002585
2586 var vc;
2587
Akron712733a2018-04-05 18:17:47 +02002588 it('should be initializable', function () {
2589
Akrone65a88a2018-04-05 19:14:20 +02002590 vc = vcClass.create([
Akron712733a2018-04-05 18:17:47 +02002591 ['a', 'text'],
2592 ['b', 'string'],
2593 ['c', 'date']
2594 ]).fromJson();
Akronadab5e52018-08-20 13:50:53 +02002595 expect(vc.builder().firstChild.classList.contains('unspecified')).toBeTruthy();
2596 expect(vc.builder().firstChild.firstChild.tagName).toEqual('SPAN');
Akron712733a2018-04-05 18:17:47 +02002597
2598 // Click on unspecified
Akronadab5e52018-08-20 13:50:53 +02002599 vc.builder().firstChild.firstChild.click();
2600 expect(vc.builder().firstChild.firstChild.tagName).toEqual('UL');
Akron712733a2018-04-05 18:17:47 +02002601
Akronadab5e52018-08-20 13:50:53 +02002602 var list = vc.builder().firstChild.firstChild;
Akron3ad46942018-08-22 16:47:14 +02002603 expect(list.getElementsByTagName("LI")[0].innerText).toEqual('referTo');
2604 expect(list.getElementsByTagName("LI")[1].innerText).toEqual('a');
2605 expect(list.getElementsByTagName("LI")[2].innerText).toEqual('b');
2606 expect(list.getElementsByTagName("LI")[3].innerText).toEqual('c');
Akron712733a2018-04-05 18:17:47 +02002607
2608 vc = vcClass.create([
2609 ['d', 'text'],
2610 ['e', 'string'],
2611 ['f', 'date']
2612 ]).fromJson();
Akronadab5e52018-08-20 13:50:53 +02002613 expect(vc.builder().firstChild.classList.contains('unspecified')).toBeTruthy();
2614 expect(vc.builder().firstChild.firstChild.tagName).toEqual('SPAN');
Akron712733a2018-04-05 18:17:47 +02002615
2616 // Click on unspecified
Akronadab5e52018-08-20 13:50:53 +02002617 vc.builder().firstChild.firstChild.click();
2618 expect(vc.builder().firstChild.firstChild.tagName).toEqual('UL');
Akron712733a2018-04-05 18:17:47 +02002619
Akronadab5e52018-08-20 13:50:53 +02002620 list = vc.builder().firstChild.firstChild;
Akron3ad46942018-08-22 16:47:14 +02002621 expect(list.getElementsByTagName("LI")[0].innerText).toEqual('referTo');
2622 expect(list.getElementsByTagName("LI")[1].innerText).toEqual('d');
2623 expect(list.getElementsByTagName("LI")[2].innerText).toEqual('e');
2624 expect(list.getElementsByTagName("LI")[3].innerText).toEqual('f');
Akron31d89942018-04-06 16:44:51 +02002625 // blur
2626 document.body.click();
Akron712733a2018-04-05 18:17:47 +02002627 });
Akrone65a88a2018-04-05 19:14:20 +02002628
2629 // Reinitialize to make tests stable
2630 vc = vcClass.create([
2631 ['d', 'text'],
2632 ['e', 'string'],
2633 ['f', 'date']
2634 ]).fromJson();
2635
2636 it('should be clickable on key', function () {
Akron31d89942018-04-06 16:44:51 +02002637 // Click on unspecified
Akronadab5e52018-08-20 13:50:53 +02002638 vc.builder().firstChild.firstChild.click();
Akrone65a88a2018-04-05 19:14:20 +02002639 // Click on "d"
Akronadab5e52018-08-20 13:50:53 +02002640 vc.builder().firstChild.firstChild.getElementsByTagName("LI")[1].click();
2641 expect(vc.builder().firstChild.firstChild.tagName).toEqual('SPAN');
2642 expect(vc.builder().firstChild.firstChild.innerText).toEqual('d');
2643 expect(vc.builder().firstChild.children[1].innerText).toEqual('eq');
2644 expect(vc.builder().firstChild.children[1].getAttribute('data-type')).toEqual('text');
Akron31d89942018-04-06 16:44:51 +02002645 // blur
2646 document.body.click();
Akrone65a88a2018-04-05 19:14:20 +02002647 });
2648
Akron31d89942018-04-06 16:44:51 +02002649 it('should be clickable on operation for text', function () {
2650 // Click on "d" (or unspecified)
Akronadab5e52018-08-20 13:50:53 +02002651 vc.builder().firstChild.firstChild.click();
Akron31d89942018-04-06 16:44:51 +02002652
2653 // Choose "d"
Akronadab5e52018-08-20 13:50:53 +02002654 vc.builder().firstChild.firstChild.getElementsByTagName("LI")[1].click();
Akron31d89942018-04-06 16:44:51 +02002655
2656 // Click on matchop
Akronadab5e52018-08-20 13:50:53 +02002657 vc.builder().firstChild.children[1].click();
Akron31d89942018-04-06 16:44:51 +02002658
Akronadab5e52018-08-20 13:50:53 +02002659 expect(vc.builder().firstChild.children[1].tagName).toEqual('UL');
Akron31d89942018-04-06 16:44:51 +02002660
Akronadab5e52018-08-20 13:50:53 +02002661 var ul = vc.builder().firstChild.children[1];
Akrone65a88a2018-04-05 19:14:20 +02002662 expect(ul.getElementsByTagName('li')[0].innerText).toEqual("eq");
2663 expect(ul.getElementsByTagName('li')[1].innerText).toEqual("ne");
2664 expect(ul.getElementsByTagName('li')[2].innerText).toEqual("contains");
2665 expect(ul.getElementsByTagName('li')[3].innerText).toEqual("containsnot");
2666 expect(ul.getElementsByTagName('li')[4]).toBeUndefined();
Akron31d89942018-04-06 16:44:51 +02002667
2668 // Choose "contains"
2669 ul.getElementsByTagName('li')[2].click();
Akronadab5e52018-08-20 13:50:53 +02002670 expect(vc.builder().firstChild.children[1].tagName).toEqual("SPAN");
2671 expect(vc.builder().firstChild.children[1].innerText).toEqual("contains");
Akron31d89942018-04-06 16:44:51 +02002672 // blur
2673 document.body.click();
Akrone65a88a2018-04-05 19:14:20 +02002674 })
Akron31d89942018-04-06 16:44:51 +02002675
2676 it('should be clickable on operation for string', function () {
2677 // Click on "d" (or unspecified)
Akronadab5e52018-08-20 13:50:53 +02002678 vc.builder().firstChild.firstChild.click();
Akron31d89942018-04-06 16:44:51 +02002679
2680 // Choose "e"
Akronadab5e52018-08-20 13:50:53 +02002681 vc.builder().firstChild.firstChild.getElementsByTagName("LI")[2].click();
2682
Akron31d89942018-04-06 16:44:51 +02002683 // As a consequence the matchoperator may no longer
2684 // be valid and needs to be re-evaluated
Akronadab5e52018-08-20 13:50:53 +02002685 var fc = vc.builder().firstChild;
Akron31d89942018-04-06 16:44:51 +02002686 expect(fc.firstChild.tagName).toEqual('SPAN');
2687 expect(fc.firstChild.innerText).toEqual('e');
2688 expect(fc.children[1].innerText).toEqual('eq');
2689 expect(fc.children[1].getAttribute('data-type')).toEqual('string');
2690
Akronadab5e52018-08-20 13:50:53 +02002691 vc.builder().firstChild.children[1].click();
Akron31d89942018-04-06 16:44:51 +02002692
Akronadab5e52018-08-20 13:50:53 +02002693 expect(vc.builder().firstChild.children[1].tagName).toEqual('UL');
Akron31d89942018-04-06 16:44:51 +02002694
Akronadab5e52018-08-20 13:50:53 +02002695 var ul = vc.builder().firstChild.children[1];
Akron31d89942018-04-06 16:44:51 +02002696 expect(ul.getElementsByTagName('li')[0].innerText).toEqual("eq");
2697 expect(ul.getElementsByTagName('li')[1].innerText).toEqual("ne");
2698 expect(ul.getElementsByTagName('li')[2]).toBeUndefined();
2699
2700 // Choose "ne"
2701 ul.getElementsByTagName('li')[1].click();
Akronadab5e52018-08-20 13:50:53 +02002702 expect(vc.builder().firstChild.children[1].tagName).toEqual("SPAN");
2703 expect(vc.builder().firstChild.children[1].innerText).toEqual("ne");
Akron8db5e3a2018-05-28 19:25:26 +02002704
2705 // Click on text
Akronebc96662018-08-29 17:36:20 +02002706 expect(vc.builder().firstChild.children[2].innerText).toEqual(KorAP.Locale.EMPTY);
2707 expect(vc.builder().firstChild.children[2].classList.contains('unspecified')).toEqual(true);
Akronadab5e52018-08-20 13:50:53 +02002708 vc.builder().firstChild.children[2].click();
Akron8db5e3a2018-05-28 19:25:26 +02002709
2710 // Blur text element
Akronadab5e52018-08-20 13:50:53 +02002711 expect(vc.builder().firstChild.children[2].firstChild.value).toEqual('');
Akron8db5e3a2018-05-28 19:25:26 +02002712
Akron31d89942018-04-06 16:44:51 +02002713 // blur
2714 document.body.click();
2715 });
2716
2717 it('should be clickable on operation for date', function () {
2718
2719 // Replay matchop check - so it's guaranteed that "ne" is chosen
2720 // Click on "e" (or unspecified)
Akronadab5e52018-08-20 13:50:53 +02002721 vc.builder().firstChild.firstChild.click();
Akron31d89942018-04-06 16:44:51 +02002722 // Rechoose "e"
Akronadab5e52018-08-20 13:50:53 +02002723 vc.builder().firstChild.firstChild.getElementsByTagName("LI")[1].click();
Akron31d89942018-04-06 16:44:51 +02002724 // Click on matchop
Akronadab5e52018-08-20 13:50:53 +02002725 vc.builder().firstChild.children[1].click();
Akron31d89942018-04-06 16:44:51 +02002726 // Choose "ne"
Akronadab5e52018-08-20 13:50:53 +02002727 vc.builder().firstChild.children[1].getElementsByTagName('li')[1].click();
2728 expect(vc.builder().firstChild.children[1].innerText).toEqual("ne");
Akron31d89942018-04-06 16:44:51 +02002729
2730 // Click on "e"
Akronadab5e52018-08-20 13:50:53 +02002731 vc.builder().firstChild.firstChild.click();
Akron31d89942018-04-06 16:44:51 +02002732 // Choose "f"
Akronadab5e52018-08-20 13:50:53 +02002733 vc.builder().firstChild.firstChild.getElementsByTagName("LI")[3].click();
Akron31d89942018-04-06 16:44:51 +02002734
2735 // The matchoperator should still be "ne" as this is valid for dates as well (now)
Akronadab5e52018-08-20 13:50:53 +02002736 var fc = vc.builder().firstChild;
Akron31d89942018-04-06 16:44:51 +02002737 expect(fc.firstChild.tagName).toEqual('SPAN');
2738 expect(fc.firstChild.innerText).toEqual('f');
2739 expect(fc.children[1].innerText).toEqual('ne');
2740 // blur
2741 document.body.click();
2742 });
Akronddc98a72018-04-06 17:33:52 +02002743
2744
2745 // Check json deserialization
2746 it('should be initializable', function () {
2747 vc = vcClass.create([
2748 ['a', 'text'],
2749 ['b', 'string'],
2750 ['c', 'date']
2751 ]).fromJson({
2752 "@type" : "koral:doc",
2753 "key":"a",
2754 "value":"Baum"
2755 });
2756
Akronadab5e52018-08-20 13:50:53 +02002757 expect(vc.builder().firstChild.children[1].getAttribute('data-type')).toEqual('text');
Akronddc98a72018-04-06 17:33:52 +02002758 });
Akron712733a2018-04-05 18:17:47 +02002759 });
2760
2761
Akrone4961b12017-05-10 21:04:46 +02002762 // Check prefix
2763 describe('KorAP.VC.Prefix', function () {
2764
2765 it('should be initializable', function () {
2766 var p = prefixClass.create();
2767 expect(p.element().classList.contains('pref')).toBeTruthy();
2768 expect(p.isSet()).not.toBeTruthy();
2769 });
2770
2771
2772 it('should be clickable', function () {
2773 var vc = vcClass.create([
Akron712733a2018-04-05 18:17:47 +02002774 ['a', null],
2775 ['b', null],
2776 ['c', null]
2777 ]).fromJson();
Akronadab5e52018-08-20 13:50:53 +02002778 expect(vc.builder().firstChild.classList.contains('unspecified')).toBeTruthy();
Akrone4961b12017-05-10 21:04:46 +02002779
2780 // This should open up the menu
Akronadab5e52018-08-20 13:50:53 +02002781 vc.builder().firstChild.firstChild.click();
2782 expect(vc.builder().firstChild.firstChild.tagName).toEqual('UL');
Akrone4961b12017-05-10 21:04:46 +02002783
2784 KorAP._vcKeyMenu._prefix.clear();
2785 KorAP._vcKeyMenu._prefix.add('x');
2786
Akronadab5e52018-08-20 13:50:53 +02002787 var prefElement = vc.builder().querySelector('span.pref');
Akrone4961b12017-05-10 21:04:46 +02002788 expect(prefElement.innerText).toEqual('x');
2789
2790 // This should add key 'x' to VC
2791 prefElement.click();
2792
Akronadab5e52018-08-20 13:50:53 +02002793 expect(vc.builder().firstChild.classList.contains('doc')).toBeTruthy();
2794 expect(vc.builder().firstChild.firstChild.className).toEqual('key');
2795 expect(vc.builder().firstChild.firstChild.innerText).toEqual('x');
Akrone4961b12017-05-10 21:04:46 +02002796 });
2797 });
Nils Diewald2fe12e12015-03-06 16:47:06 +00002798});