blob: f8747237caccd7032bf36d5ecfd9e029bdeee539 [file] [log] [blame]
Nils Diewald6ac292b2015-01-15 21:33:21 +00001/*
Nils Diewald7c8ced22015-04-15 19:21:00 +00002 * Todo: In demoSpec: Create "and" on the last element of the top "or"-Group
3 */
Akrondd5c6d32018-08-17 14:12:58 +02004define([
5 'vc',
6 'vc/doc',
7 'vc/menu',
8 'vc/prefix',
9 'vc/docgroup',
10 'vc/docgroupref',
11 'vc/unspecified',
12 'vc/operators',
13 'vc/rewrite',
14 'vc/stringval'
15], function (vcClass,
16 docClass,
17 menuClass,
18 prefixClass,
19 docGroupClass,
20 docGroupRefClass,
21 unspecifiedClass,
22 operatorsClass,
23 rewriteClass,
24 stringValClass) {
Nils Diewald6ac292b2015-01-15 21:33:21 +000025
Akrondd5c6d32018-08-17 14:12:58 +020026 KorAP._vcKeyMenu = undefined;
27
Nils Diewald6ac292b2015-01-15 21:33:21 +000028
Nils Diewald7c8ced22015-04-15 19:21:00 +000029 // Helper method for building factories
30 buildFactory = function (objClass, defaults) {
31 return {
32 create : function (overwrites) {
Akron712733a2018-04-05 18:17:47 +020033 var newObj = {};
34 for (var prop in defaults) {
35 newObj[prop] = defaults[prop];
36 };
37 for (var prop in overwrites) {
38 newObj[prop] = overwrites[prop];
39 };
40 return objClass.create().fromJson(newObj);
Nils Diewald7c8ced22015-04-15 19:21:00 +000041 }
Nils Diewald0b6c0412014-12-19 03:55:57 +000042 }
Nils Diewald7c8ced22015-04-15 19:21:00 +000043 };
Nils Diewald0b6c0412014-12-19 03:55:57 +000044
Nils Diewald7c8ced22015-04-15 19:21:00 +000045 function _andOn (obj) {
Akrond141a362018-07-10 18:12:13 +020046 KorAP._and.apply(obj);
Nils Diewald7c8ced22015-04-15 19:21:00 +000047 };
Nils Diewald52f7eb12015-01-12 17:30:04 +000048
Nils Diewald7c8ced22015-04-15 19:21:00 +000049 function _orOn (obj) {
Akrond141a362018-07-10 18:12:13 +020050 KorAP._or.apply(obj);
Nils Diewald7c8ced22015-04-15 19:21:00 +000051 };
Nils Diewald52f7eb12015-01-12 17:30:04 +000052
Nils Diewald7c8ced22015-04-15 19:21:00 +000053 function _delOn (obj) {
Akrond141a362018-07-10 18:12:13 +020054 KorAP._delete.apply(obj);
Nils Diewald7c8ced22015-04-15 19:21:00 +000055 };
Nils Diewald52f7eb12015-01-12 17:30:04 +000056
Nils Diewald7c8ced22015-04-15 19:21:00 +000057 var demoFactory = buildFactory(vcClass, {
58 "@type":"koral:docGroup",
59 "operation":"operation:or",
60 "operands":[
Nils Diewaldf219eb82015-01-07 20:15:42 +000061 {
Akron712733a2018-04-05 18:17:47 +020062 "@type":"koral:docGroup",
63 "operation":"operation:and",
64 "operands":[
Nils Diewald7c8ced22015-04-15 19:21:00 +000065 {
66 "@type":"koral:doc",
67 "key":"Titel",
68 "value":"Baum",
69 "match":"match:eq"
70 },
71 {
72 "@type":"koral:doc",
73 "key":"Veröffentlichungsort",
74 "value":"hihi",
75 "match":"match:eq"
76 },
77 {
78 "@type":"koral:docGroup",
79 "operation":"operation:or",
80 "operands":[
81 {
Akron712733a2018-04-05 18:17:47 +020082 "@type":"koral:doc",
83 "key":"Titel",
84 "value":"Baum",
85 "match":"match:eq"
Nils Diewald7c8ced22015-04-15 19:21:00 +000086 },
87 {
Akron712733a2018-04-05 18:17:47 +020088 "@type":"koral:doc",
89 "key":"Veröffentlichungsort",
90 "value":"hihi",
91 "match":"match:eq"
Nils Diewald7c8ced22015-04-15 19:21:00 +000092 }
93 ]
94 }
Akron712733a2018-04-05 18:17:47 +020095 ]
Nils Diewaldf219eb82015-01-07 20:15:42 +000096 },
97 {
Akron712733a2018-04-05 18:17:47 +020098 "@type":"koral:doc",
99 "key":"Untertitel",
100 "value":"huhu",
101 "match":"match:contains"
Nils Diewaldf219eb82015-01-07 20:15:42 +0000102 }
103 ]
104 });
105
Nils Diewald7c8ced22015-04-15 19:21:00 +0000106 describe('KorAP.Doc', function () {
107 // Create example factories
108 var stringFactory = buildFactory(docClass, {
109 "key" : "author",
110 "value" : "Max Birkendale",
Akron31d89942018-04-06 16:44:51 +0200111 "type" : "type:string",
Nils Diewald7c8ced22015-04-15 19:21:00 +0000112 "@type" : "koral:doc"
113 });
114
115 // Create example factories
Akron712733a2018-04-05 18:17:47 +0200116 var textFactory = buildFactory(docClass, {
117 "key" : "author",
118 "value" : "Birkendale",
Akron31d89942018-04-06 16:44:51 +0200119 "type" : "type:string",
Akron712733a2018-04-05 18:17:47 +0200120 "match" : "match:contains",
121 "@type" : "koral:doc"
122 });
123
124 // Create example factories
Nils Diewald7c8ced22015-04-15 19:21:00 +0000125 var dateFactory = buildFactory(docClass, {
126 "key" : "pubDate",
127 "type" : "type:date",
128 "match" : "match:eq",
129 "value" : "2014-11-05",
130 "@type" : "koral:doc"
131 });
132
133 // Create example factories
134 var regexFactory = buildFactory(docClass, {
135 "key" : "title",
136 "type" : "type:regex",
137 "value" : "[^b]ee.+?",
138 "@type" : "koral:doc"
139 });
140
141 it('should be initializable', function () {
142 var doc = docClass.create();
143 expect(doc.matchop()).toEqual('eq');
144 expect(doc.key()).toBeUndefined();
145 expect(doc.value()).toBeUndefined();
146 expect(doc.type()).toEqual("string");
147 });
148
149 it('should be definable', function () {
150
151 // Empty doc
152 var doc = docClass.create();
153
154 // Set values
155 doc.key("title");
Akron8db5e3a2018-05-28 19:25:26 +0200156
Nils Diewald7c8ced22015-04-15 19:21:00 +0000157 doc.value("Der alte Mann");
158 expect(doc.matchop()).toEqual('eq');
159 expect(doc.key()).toEqual("title");
160 expect(doc.type()).toEqual("string");
161 expect(doc.value()).toEqual("Der alte Mann");
162 });
163
164
165 it('should deserialize JSON-LD string', function () {
166 var doc;
167
168 // String default
169 doc = stringFactory.create();
170 expect(doc.matchop()).toEqual('eq');
171 expect(doc.key()).toEqual("author");
172 expect(doc.type()).toEqual("string");
173 expect(doc.value()).toEqual("Max Birkendale");
174
175 // No valid string
176 doc = stringFactory.create({
Akron712733a2018-04-05 18:17:47 +0200177 value : undefined
Nils Diewald7c8ced22015-04-15 19:21:00 +0000178 });
179 expect(doc).toBeUndefined();
180
181 // No valid string
182 doc = stringFactory.create({
Akron712733a2018-04-05 18:17:47 +0200183 value : { "foo" : "bar" }
Nils Diewald7c8ced22015-04-15 19:21:00 +0000184 });
185 expect(doc).toBeUndefined();
186
187 // Change match type
188 doc = stringFactory.create({
Akron712733a2018-04-05 18:17:47 +0200189 "match" : "match:ne"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000190 });
191
192 expect(doc.matchop()).toEqual('ne');
193 expect(doc.key()).toEqual("author");
194 expect(doc.type()).toEqual("string");
195 expect(doc.value()).toEqual("Max Birkendale");
196
197 // Invalid match type
198 doc = stringFactory.create({
Akron712733a2018-04-05 18:17:47 +0200199 "match" : { "foo" : "bar" }
Nils Diewald7c8ced22015-04-15 19:21:00 +0000200 });
201 expect(doc).toBeUndefined();
202 });
203
204 it('should deserialize JSON-LD regex', function () {
205 var doc = regexFactory.create();
206 expect(doc.key()).toEqual("title");
207 expect(doc.type()).toEqual("regex");
208 expect(doc.value()).toEqual("[^b]ee.+?");
209 expect(doc.matchop()).toEqual('eq');
210
211 // change matcher
212 doc = regexFactory.create({
Akron712733a2018-04-05 18:17:47 +0200213 match : "match:ne"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000214 });
215 expect(doc.matchop()).toEqual('ne');
Akronea4e9052017-07-06 16:12:05 +0200216 expect(doc.rewrites()).toBeUndefined();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000217
218 // Invalid matcher
219 doc = regexFactory.create({
Akron712733a2018-04-05 18:17:47 +0200220 match : "match:chook"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000221 });
Akronea4e9052017-07-06 16:12:05 +0200222 expect(doc.matchop()).toEqual('eq');
223 expect(doc.rewrites()).toBeDefined();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000224
225 // Invalid regex
226 doc = regexFactory.create({
Akron712733a2018-04-05 18:17:47 +0200227 value : "[^b"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000228 });
229 expect(doc).toBeUndefined();
230 });
231
232 it('should deserialize JSON-LD date', function () {
233
234 // Normal date
235 doc = dateFactory.create({});
236
237 expect(doc.matchop()).toEqual('eq');
238 expect(doc.key()).toEqual("pubDate");
239 expect(doc.type()).toEqual("date");
240 expect(doc.value()).toEqual("2014-11-05");
241
242 // Short date 1
243 doc = dateFactory.create({
Akron712733a2018-04-05 18:17:47 +0200244 "value" : "2014-11"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000245 });
246
247 expect(doc.matchop()).toEqual('eq');
248 expect(doc.key()).toEqual("pubDate");
249 expect(doc.type()).toEqual("date");
250 expect(doc.value()).toEqual("2014-11");
251
252 // Short date 2
253 doc = dateFactory.create({
Akron712733a2018-04-05 18:17:47 +0200254 "value" : "2014"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000255 });
256
257 expect(doc.matchop()).toEqual('eq');
258 expect(doc.key()).toEqual("pubDate");
259 expect(doc.type()).toEqual("date");
260 expect(doc.value()).toEqual("2014");
261
262 // Invalid date!
263 doc = dateFactory.create({
Akron712733a2018-04-05 18:17:47 +0200264 "value" : "2014-11-050"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000265 });
266 expect(doc).toBeUndefined();
267
268 // Invalid matcher!
269 doc = dateFactory.create({
Akron31d89942018-04-06 16:44:51 +0200270 "match" : "match:contains",
Nils Diewald7c8ced22015-04-15 19:21:00 +0000271 });
Akronea4e9052017-07-06 16:12:05 +0200272 expect(doc).toBeDefined();
273 expect(doc.rewrites()).toBeDefined();
274 expect(doc.matchop()).toEqual('eq');
Nils Diewald7c8ced22015-04-15 19:21:00 +0000275 });
276
277 it('should be serializale to JSON', function () {
278
279 // Empty doc
280 var doc = docClass.create();
281 expect(doc.toJson()).toEqual(jasmine.any(Object));
282
283 // Serialize string
284 doc = stringFactory.create();
285 expect(doc.toJson()).toEqual(jasmine.objectContaining({
Akron712733a2018-04-05 18:17:47 +0200286 "@type" : "koral:doc",
287 "type" : "type:string",
288 "key" : "author",
289 "value" : "Max Birkendale",
290 "match" : "match:eq"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000291 }));
292
293 // Serialize regex
294 doc = regexFactory.create();
295 expect(doc.toJson()).toEqual(jasmine.objectContaining({
Akron712733a2018-04-05 18:17:47 +0200296 "@type" : "koral:doc",
297 "type" : "type:regex",
298 "value" : "[^b]ee.+?",
299 "match" : "match:eq",
300 "key" : 'title'
Nils Diewald7c8ced22015-04-15 19:21:00 +0000301 }));
302
303 doc = regexFactory.create({
Akron712733a2018-04-05 18:17:47 +0200304 match: "match:ne"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000305 });
306 expect(doc.toJson()).toEqual(jasmine.objectContaining({
Akron712733a2018-04-05 18:17:47 +0200307 "@type" : "koral:doc",
308 "type" : "type:regex",
309 "value" : "[^b]ee.+?",
310 "match" : "match:ne",
311 "key" : 'title'
Nils Diewald7c8ced22015-04-15 19:21:00 +0000312 }));
313
314 doc = dateFactory.create();
315 expect(doc.toJson()).toEqual(jasmine.objectContaining({
Akron712733a2018-04-05 18:17:47 +0200316 "@type" : "koral:doc",
317 "type" : "type:date",
318 "value" : "2014-11-05",
319 "match" : "match:eq",
320 "key" : 'pubDate'
Nils Diewald7c8ced22015-04-15 19:21:00 +0000321 }));
322
323 doc = dateFactory.create({
Akron712733a2018-04-05 18:17:47 +0200324 value : "2014"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000325 });
326 expect(doc.toJson()).toEqual(jasmine.objectContaining({
Akron712733a2018-04-05 18:17:47 +0200327 "@type" : "koral:doc",
328 "type" : "type:date",
329 "value" : "2014",
330 "match" : "match:eq",
331 "key" : 'pubDate'
Nils Diewald7c8ced22015-04-15 19:21:00 +0000332 }));
333 });
334
335
336 it('should be serializale to String', function () {
337 // Empty doc
338 var doc = docClass.create();
339 expect(doc.toQuery()).toEqual("");
340
341 // Serialize string
342 doc = stringFactory.create();
343 expect(doc.toQuery()).toEqual('author = "Max Birkendale"');
344
345 // Serialize string with quotes
346 doc = stringFactory.create({ "value" : 'Max "Der Coole" Birkendate'});
347 expect(doc.toQuery()).toEqual('author = "Max \\"Der Coole\\" Birkendate"');
348
349 // Serialize regex
350 doc = regexFactory.create();
351 expect(doc.toQuery()).toEqual('title = /[^b]ee.+?/');
352
353 doc = regexFactory.create({
Akron712733a2018-04-05 18:17:47 +0200354 match: "match:ne"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000355 });
356 expect(doc.toQuery()).toEqual('title != /[^b]ee.+?/');
357
Akron8778f5d2017-06-30 21:25:55 +0200358 doc = regexFactory.create({
Akron712733a2018-04-05 18:17:47 +0200359 value: "WPD/AAA/00001"
Akron8778f5d2017-06-30 21:25:55 +0200360 });
361 expect(doc.toQuery()).toEqual('title = /WPD\\/AAA\\/00001/');
362
Nils Diewald7c8ced22015-04-15 19:21:00 +0000363 doc = dateFactory.create();
364 expect(doc.toQuery()).toEqual('pubDate in 2014-11-05');
365
366 doc = dateFactory.create({
Akron712733a2018-04-05 18:17:47 +0200367 value : "2014"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000368 });
369 expect(doc.toQuery()).toEqual('pubDate in 2014');
370 });
371 });
372
373
374 describe('KorAP.DocGroup', function () {
375 // Create example factories
376 var docFactory = buildFactory(
377 docClass,
Nils Diewaldf219eb82015-01-07 20:15:42 +0000378 {
Akron712733a2018-04-05 18:17:47 +0200379 "@type" : "koral:doc",
380 "match":"match:eq",
381 "key" : "author",
382 "value" : "Max Birkendale"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000383 }
384 );
385
386 var docGroupFactory = buildFactory(
387 docGroupClass, {
Akron712733a2018-04-05 18:17:47 +0200388 "@type" : "koral:docGroup",
389 "operation" : "operation:and",
390 "operands" : [
391 docFactory.create().toJson(),
392 docFactory.create({
393 "key" : "pubDate",
394 "type" : "type:date",
395 "value" : "2014-12-05"
396 }).toJson()
397 ]
Nils Diewald7c8ced22015-04-15 19:21:00 +0000398 });
399
400 it('should be initializable', function () {
401 // Create empty group
402 var docGroup = docGroupClass.create();
403 expect(docGroup.operation()).toEqual('and');
404
405 // Create empty group
406 docGroup = docGroupClass.create();
407 docGroup.operation('or');
408 expect(docGroup.operation()).toEqual('or');
409 });
410
411 it('should be definable', function () {
412
413 // Empty group
414 var docGroup = docGroupClass.create();
415 expect(docGroup.operation()).toEqual('and');
416
417 // Set values
418 docGroup.operation("or");
419 expect(docGroup.operation()).toEqual('or');
420
421 // Set invalid values
422 docGroup.operation("hui");
423 expect(docGroup.operation()).toEqual('or');
424 });
425
426 it('should be deserializable', function () {
427 var docGroup = docGroupFactory.create();
428 expect(docGroup.operation()).toEqual("and");
429 expect(docGroup.operands().length).toEqual(2);
430
431 var op1 = docGroup.getOperand(0);
432 expect(op1.type()).toEqual("string");
433 expect(op1.key()).toEqual("author");
434 expect(op1.value()).toEqual("Max Birkendale");
435 expect(op1.matchop()).toEqual("eq");
436
437 var op2 = docGroup.getOperand(1);
438 expect(op2.type()).toEqual("date");
439 expect(op2.key()).toEqual("pubDate");
440 expect(op2.value()).toEqual("2014-12-05");
441 expect(op2.matchop()).toEqual("eq");
442
443 // Append empty group
444 var newGroup = docGroup.append(docGroupClass.create());
445 newGroup.operation('or');
446 newGroup.append(docFactory.create());
447 newGroup.append(docFactory.create({
Akron712733a2018-04-05 18:17:47 +0200448 "type" : "type:regex",
449 "key" : "title",
450 "value" : "^e.+?$",
451 "match" : "match:ne"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000452 }));
453
454 expect(docGroup.operation()).toEqual("and");
455 expect(docGroup.operands().length).toEqual(3);
456
457 var op1 = docGroup.getOperand(0);
458 expect(op1.ldType()).toEqual("doc");
459 expect(op1.type()).toEqual("string");
460 expect(op1.key()).toEqual("author");
461 expect(op1.value()).toEqual("Max Birkendale");
462 expect(op1.matchop()).toEqual("eq");
463
464 var op2 = docGroup.getOperand(1);
465 expect(op2.ldType()).toEqual("doc");
466 expect(op2.type()).toEqual("date");
467 expect(op2.key()).toEqual("pubDate");
468 expect(op2.value()).toEqual("2014-12-05");
469 expect(op2.matchop()).toEqual("eq");
470
471 var op3 = docGroup.getOperand(2);
472 expect(op3.ldType()).toEqual("docGroup");
473 expect(op3.operation()).toEqual("or");
474
475 var op4 = op3.getOperand(0);
476 expect(op4.ldType()).toEqual("doc");
477 expect(op4.type()).toEqual("string");
478 expect(op4.key()).toEqual("author");
479 expect(op4.value()).toEqual("Max Birkendale");
480 expect(op4.matchop()).toEqual("eq");
481
482 var op5 = op3.getOperand(1);
483 expect(op5.ldType()).toEqual("doc");
484 expect(op5.type()).toEqual("regex");
485 expect(op5.key()).toEqual("title");
486 expect(op5.value()).toEqual("^e.+?$");
487 expect(op5.matchop()).toEqual("ne");
488 });
489
490 it('should be serializable to JSON', function () {
491 var docGroup = docGroupFactory.create();
492
493 expect(docGroup.toJson()).toEqual(jasmine.objectContaining({
Akron712733a2018-04-05 18:17:47 +0200494 "@type" : "koral:docGroup",
495 "operation" : "operation:and",
496 "operands" : [
497 {
498 "@type": 'koral:doc',
499 "key" : 'author',
500 "match": 'match:eq',
501 "value": 'Max Birkendale',
502 "type": 'type:string'
503 },
504 {
505 "@type": 'koral:doc',
506 "key": 'pubDate',
507 "match": 'match:eq',
508 "value": '2014-12-05',
509 "type": 'type:date'
510 }
511 ]
Nils Diewald7c8ced22015-04-15 19:21:00 +0000512 }));
513 });
Nils Diewalde15b7a22015-01-09 21:50:21 +0000514
Nils Diewald7c8ced22015-04-15 19:21:00 +0000515 it('should be serializable to String', function () {
516 var docGroup = docGroupFactory.create();
517 expect(docGroup.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +0200518 'author = "Max Birkendale" & pubDate in 2014-12-05'
Nils Diewald7c8ced22015-04-15 19:21:00 +0000519 );
Nils Diewald52f7eb12015-01-12 17:30:04 +0000520
Nils Diewald7c8ced22015-04-15 19:21:00 +0000521 docGroup = docGroupFactory.create({
Akron712733a2018-04-05 18:17:47 +0200522 "@type" : "koral:docGroup",
523 "operation" : "operation:or",
524 "operands" : [
525 {
526 "@type": 'koral:doc',
527 "key" : 'author',
528 "match": 'match:eq',
529 "value": 'Max Birkendale',
530 "type": 'type:string'
531 },
532 {
533 "@type" : "koral:docGroup",
534 "operation" : "operation:and",
535 "operands" : [
536 {
537 "@type": 'koral:doc',
538 "key": 'pubDate',
539 "match": 'match:geq',
540 "value": '2014-05-12',
541 "type": 'type:date'
542 },
543 {
544 "@type": 'koral:doc',
545 "key": 'pubDate',
546 "match": 'match:leq',
547 "value": '2014-12-05',
548 "type": 'type:date'
549 },
550 {
551 "@type": 'koral:doc',
552 "key": 'foo',
553 "match": 'match:ne',
554 "value": '[a]?bar',
555 "type": 'type:regex'
556 }
557 ]
558 }
559 ]
Nils Diewald7c8ced22015-04-15 19:21:00 +0000560 });
561 expect(docGroup.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +0200562 'author = "Max Birkendale" | ' +
563 '(pubDate since 2014-05-12 & ' +
564 'pubDate until 2014-12-05 & foo != /[a]?bar/)'
Nils Diewald7c8ced22015-04-15 19:21:00 +0000565 );
566 });
567 });
568
Akronb19803c2018-08-16 16:39:42 +0200569 describe('KorAP.DocGroupRef', function () {
570 // Create example factories
571 var docRefFactory = buildFactory(
572 docGroupRefClass,
573 {
574 "@type" : "koral:docGroupRef",
575 "ref" : "@max/myCorpus"
576 }
577 );
578
579 it('should be initializable', function () {
580 var vcRef = docGroupRefClass.create();
581 expect(vcRef.ref()).toBeUndefined();
582 });
583
584 it('should be definable', function () {
585 var vcRef = docGroupRefClass.create();
586 vcRef.ref("@peter/mycorpus");
587 expect(vcRef.ref()).toEqual("@peter/mycorpus");
588 vcRef.ref("@peter/mycorpus2");
589 expect(vcRef.ref()).toEqual("@peter/mycorpus2");
590 });
591
592 it('should deserialize JSON-LD string', function () {
593 var vcRef = docRefFactory.create();
594 expect(vcRef.ref()).toEqual("@max/myCorpus");
595 });
596
597 it('should serialize to JSON-LD', function () {
598 var vcRef = docRefFactory.create();
599 expect(vcRef.toJson()).toEqual(jasmine.objectContaining({
600 "@type" : "koral:docGroupRef",
601 "ref":"@max/myCorpus"
602 }));
603
604 vcRef.ref("@peter/myCorpus2");
605 expect(vcRef.toJson()).toEqual(jasmine.objectContaining({
606 "@type" : "koral:docGroupRef",
607 "ref":"@peter/myCorpus2"
608 }));
609 });
610
611 it('should serialize to a query', function () {
612 var vcRef = docRefFactory.create();
613 expect(vcRef.toQuery()).toEqual(
614 "referTo \"@max/myCorpus\""
615 );
616
617 vcRef.ref("@peter/myCorpus2");
618 expect(vcRef.toQuery()).toEqual(
619 "referTo \"@peter/myCorpus2\""
620 );
621 });
622 });
623
624
Nils Diewald7c8ced22015-04-15 19:21:00 +0000625 describe('KorAP.UnspecifiedDoc', function () {
626 it('should be initializable', function () {
627 var doc = unspecifiedClass.create();
628 var docElement = doc.element();
629 expect(docElement.getAttribute('class')).toEqual('doc unspecified');
630 expect(docElement.firstChild.firstChild.data).toEqual('⋯');
631 expect(docElement.lastChild.lastChild.data).toEqual('⋯');
632 expect(doc.toQuery()).toEqual('');
633
634 // Only removable
635 expect(docElement.lastChild.children.length).toEqual(0);
636 });
637
Akrond141a362018-07-10 18:12:13 +0200638 it('should be removable, when no root', function () {
Nils Diewald7c8ced22015-04-15 19:21:00 +0000639 var docGroup = docGroupClass.create();
640 docGroup.operation('or');
641 expect(docGroup.operation()).toEqual('or');
642
643 docGroup.append({
Akron712733a2018-04-05 18:17:47 +0200644 "@type": 'koral:doc',
645 "key": 'pubDate',
646 "match": 'match:eq',
647 "value": '2014-12-05',
648 "type": 'type:date'
Nils Diewald7c8ced22015-04-15 19:21:00 +0000649 });
650
651 // Add unspecified object
652 docGroup.append();
653
Akrond141a362018-07-10 18:12:13 +0200654 var parent = document.createElement('div');
655 parent.appendChild(docGroup.element());
656
Nils Diewald7c8ced22015-04-15 19:21:00 +0000657 expect(docGroup.element().getAttribute('class')).toEqual('docGroup');
658 expect(docGroup.element().children[0].getAttribute('class')).toEqual('doc');
659
660 var unspec = docGroup.element().children[1];
661 expect(unspec.getAttribute('class')).toEqual('doc unspecified');
662
Akronb19803c2018-08-16 16:39:42 +0200663 // Only unspec and delete
664 expect(unspec.children.length).toEqual(2);
665
Nils Diewald7c8ced22015-04-15 19:21:00 +0000666 // Removable
667 expect(unspec.lastChild.children.length).toEqual(1);
668 expect(unspec.lastChild.children[0].getAttribute('class')).toEqual('delete');
669 });
670
Akrond141a362018-07-10 18:12:13 +0200671
Nils Diewald7c8ced22015-04-15 19:21:00 +0000672 it('should be replaceable by a doc', function () {
673 var doc = unspecifiedClass.create();
674 expect(doc.ldType()).toEqual("non");
675 // No parent, therefor not updateable
676 expect(doc.key("baum")).toBeNull();
677
678 var docGroup = docGroupClass.create();
679 docGroup.operation('or');
680 expect(docGroup.operation()).toEqual('or');
681
682 docGroup.append({
Akron712733a2018-04-05 18:17:47 +0200683 "@type": 'koral:doc',
684 "key": 'pubDate',
685 "match": 'match:eq',
686 "value": '2014-12-05',
687 "type": 'type:date'
Nils Diewald7c8ced22015-04-15 19:21:00 +0000688 });
689
690 expect(docGroup.toQuery()).toEqual("pubDate in 2014-12-05");
691 docGroup.append();
692
693 expect(docGroup.getOperand(0).ldType()).toEqual("doc");
694 expect(docGroup.getOperand(1).ldType()).toEqual("non");
695
696 var op = docGroup.getOperand(1).element().lastChild;
Akron0b489ad2018-02-02 16:49:32 +0100697 expect(op.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +0000698 expect(op.children[0].getAttribute('class')).toEqual('delete');
699 expect(op.children.length).toEqual(1);
700
701 // Replace unspecified doc
702 expect(docGroup.getOperand(1).key("name")).not.toBeNull();
703 expect(docGroup.getOperand(1).ldType()).toEqual("doc");
704 expect(docGroup.getOperand(1).key()).toEqual("name");
Akron55a343b2018-04-06 19:57:36 +0200705 expect(docGroup.getOperand(1).value()).toBeUndefined();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000706
Akronb19803c2018-08-16 16:39:42 +0200707 expect(docGroup.getOperand(1).element().children.length).toEqual(4);
708
Nils Diewald7c8ced22015-04-15 19:21:00 +0000709 op = docGroup.getOperand(1).element().lastChild;
Akron0b489ad2018-02-02 16:49:32 +0100710 expect(op.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +0000711 expect(op.children[0].getAttribute('class')).toEqual('and');
712 expect(op.children[1].getAttribute('class')).toEqual('or');
713 expect(op.children[2].getAttribute('class')).toEqual('delete');
Akronb19803c2018-08-16 16:39:42 +0200714
Nils Diewald7c8ced22015-04-15 19:21:00 +0000715 expect(op.children.length).toEqual(3);
716
717 docGroup.getOperand(1).value("Pachelbel");
718 expect(docGroup.getOperand(1).value()).toEqual("Pachelbel");
719 expect(docGroup.getOperand(1).type()).toEqual("string");
720 expect(docGroup.getOperand(1).matchop()).toEqual("eq");
721
722 // Specified!
723 expect(docGroup.toQuery()).toEqual('pubDate in 2014-12-05 | name = "Pachelbel"');
724 });
Akronb19803c2018-08-16 16:39:42 +0200725
Nils Diewald7c8ced22015-04-15 19:21:00 +0000726 it('should be replaceable on root', function () {
Nils Diewald6283d692015-04-23 20:32:53 +0000727 var vc = vcClass.create();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000728 expect(vc.toQuery()).toEqual("");
729
730 expect(vc.root().ldType()).toEqual("non");
731
732 // No operators on root
733 op = vc.root().element().lastChild;
734 expect(op.lastChild.textContent).toEqual('⋯');
735
736 // Replace
737 expect(vc.root().key("baum")).not.toBeNull();
738 expect(vc.root().ldType()).toEqual("doc");
739
740 op = vc.root().element().lastChild;
Akron0b489ad2018-02-02 16:49:32 +0100741 expect(op.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +0000742 expect(op.children[0].getAttribute('class')).toEqual('and');
743 expect(op.children[1].getAttribute('class')).toEqual('or');
744 expect(op.children[2].getAttribute('class')).toEqual('delete');
745 expect(op.children.length).toEqual(3);
746 });
Akron55a343b2018-04-06 19:57:36 +0200747
748 it('should be clickable', function () {
749 var vc = vcClass.create([
750 ["pubDate", "date"]
751 ]);
752 expect(vc.toQuery()).toEqual("");
753 expect(vc.element().firstChild.textContent).toEqual("⋯");
754 vc.element().firstChild.firstChild.click();
755
756 // Click on pubDate
Akron3ad46942018-08-22 16:47:14 +0200757 vc.element().firstChild.getElementsByTagName("LI")[1].click();
Akron55a343b2018-04-06 19:57:36 +0200758
759 expect(vc.element().firstChild.firstChild.textContent).toEqual("pubDate");
760 expect(vc.element().firstChild.children[1].getAttribute("data-type")).toEqual("date");
761 });
Nils Diewald7c8ced22015-04-15 19:21:00 +0000762 });
763
764 describe('KorAP.Doc element', function () {
765 it('should be initializable', function () {
766 var docElement = docClass.create(undefined, {
Akron712733a2018-04-05 18:17:47 +0200767 "@type" : "koral:doc",
768 "key":"Titel",
769 "value":"Baum",
770 "match":"match:eq"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000771 });
772 expect(docElement.key()).toEqual('Titel');
773 expect(docElement.matchop()).toEqual('eq');
774 expect(docElement.value()).toEqual('Baum');
775
776 var docE = docElement.element();
777 expect(docE.children[0].firstChild.data).toEqual('Titel');
778 expect(docE.children[1].firstChild.data).toEqual('eq');
779 expect(docE.children[1].getAttribute('data-type')).toEqual('string');
780 expect(docE.children[2].firstChild.data).toEqual('Baum');
781 expect(docE.children[2].getAttribute('data-type')).toEqual('string');
782
783 expect(docElement.toJson()).toEqual(jasmine.objectContaining({
Akron712733a2018-04-05 18:17:47 +0200784 "@type" : "koral:doc",
785 "key":"Titel",
786 "value":"Baum",
787 "match":"match:eq"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000788 }));
789 });
Akronb19803c2018-08-16 16:39:42 +0200790
791
792 it('should be replacable by unspecified', function () {
793 var vc = vcClass.create([
794 ["pubDate", "date"]
795 ]).fromJson({
796 "@type" : "koral:doc",
797 "key":"Titel",
798 "value":"Baum",
799 "match":"match:eq"
800 });
801 expect(vc.toQuery()).toEqual("Titel = \"Baum\"");
802
803 var vcE = vc.element();
804 expect(vcE.firstChild.children.length).toEqual(4);
805
806 // Click to delete
807 vcE.firstChild.lastChild.lastChild.click();
808
809 expect(vcE.firstChild.children.length).toEqual(1);
810
811 expect(vcE.firstChild.textContent).toEqual("⋯");
812 vcE.firstChild.firstChild.click();
813
814 // Click on pubDate
Akron3ad46942018-08-22 16:47:14 +0200815 vcE.firstChild.getElementsByTagName("LI")[1].click();
Akronb19803c2018-08-16 16:39:42 +0200816
817 expect(vcE.firstChild.firstChild.textContent).toEqual("pubDate");
818 expect(vcE.firstChild.children[1].getAttribute("data-type")).toEqual("date");
819
820 expect(vcE.firstChild.children.length).toEqual(4);
821 });
822
823
824 it('should be replaceable by a docGroupRef', function () {
Akron3ad46942018-08-22 16:47:14 +0200825 var vc = vcClass.create().fromJson({
Akronb19803c2018-08-16 16:39:42 +0200826 "@type" : "koral:doc",
827 "key":"Titel",
828 "value":"Baum",
829 "match":"match:eq"
830 });
831
832 expect(vc.toQuery()).toEqual("Titel = \"Baum\"");
833
834 var vcE = vc.element();
835 expect(vcE.firstChild.children.length).toEqual(4);
836
837 // Click to delete
838 vcE.firstChild.lastChild.lastChild.click();
839
840 expect(vcE.firstChild.children.length).toEqual(1);
841
842 expect(vcE.firstChild.textContent).toEqual("⋯");
843 vcE.firstChild.firstChild.click();
844
Akron3ad46942018-08-22 16:47:14 +0200845 // Click on referTo
Akronb19803c2018-08-16 16:39:42 +0200846 vcE.firstChild.getElementsByTagName("LI")[0].click();
847
Akron3ad46942018-08-22 16:47:14 +0200848 expect(vcE.firstChild.firstChild.textContent).toEqual("referTo");
Akronb19803c2018-08-16 16:39:42 +0200849 expect(vcE.firstChild.children[1].getAttribute("data-type")).toEqual("string");
850 expect(vcE.firstChild.children.length).toEqual(3);
851 });
Nils Diewald7c8ced22015-04-15 19:21:00 +0000852 });
853
854 describe('KorAP.DocGroup element', function () {
855 it('should be initializable', function () {
856
857 var docGroup = docGroupClass.create(undefined, {
Akron712733a2018-04-05 18:17:47 +0200858 "@type" : "koral:docGroup",
859 "operation" : "operation:and",
860 "operands" : [
861 {
862 "@type": 'koral:doc',
863 "key" : 'author',
864 "match": 'match:eq',
865 "value": 'Max Birkendale',
866 "type": 'type:string'
867 },
868 {
869 "@type": 'koral:doc',
870 "key": 'pubDate',
871 "match": 'match:eq',
872 "value": '2014-12-05',
873 "type": 'type:date'
874 }
875 ]
Nils Diewald7c8ced22015-04-15 19:21:00 +0000876 });
877
878 expect(docGroup.operation()).toEqual('and');
879 var e = docGroup.element();
880 expect(e.getAttribute('class')).toEqual('docGroup');
881 expect(e.getAttribute('data-operation')).toEqual('and');
882
883 var first = e.children[0];
884 expect(first.getAttribute('class')).toEqual('doc');
885 expect(first.children[0].getAttribute('class')).toEqual('key');
886 expect(first.children[1].getAttribute('class')).toEqual('match');
887 expect(first.children[2].getAttribute('class')).toEqual('value');
888 expect(first.children[2].getAttribute('data-type')).toEqual('string');
889 expect(first.children[0].firstChild.data).toEqual('author');
890 expect(first.children[1].firstChild.data).toEqual('eq');
891 expect(first.children[2].firstChild.data).toEqual('Max Birkendale');
892
893 var second = e.children[1];
894 expect(second.getAttribute('class')).toEqual('doc');
895 expect(second.children[0].getAttribute('class')).toEqual('key');
896 expect(second.children[1].getAttribute('class')).toEqual('match');
897 expect(second.children[2].getAttribute('class')).toEqual('value');
898 expect(second.children[2].getAttribute('data-type')).toEqual('date');
899 expect(second.children[0].firstChild.data).toEqual('pubDate');
900 expect(second.children[1].firstChild.data).toEqual('eq');
901 expect(second.children[2].firstChild.data).toEqual('2014-12-05');
902 });
903
904 it('should be deserializable with nested groups', function () {
905 var docGroup = docGroupClass.create(undefined, {
Akron712733a2018-04-05 18:17:47 +0200906 "@type" : "koral:docGroup",
907 "operation" : "operation:or",
908 "operands" : [
909 {
910 "@type": 'koral:doc',
911 "key" : 'author',
912 "match": 'match:eq',
913 "value": 'Max Birkendale',
914 "type": 'type:string'
915 },
916 {
917 "@type" : "koral:docGroup",
918 "operation" : "operation:and",
919 "operands" : [
920 {
921 "@type": 'koral:doc',
922 "key": 'pubDate',
923 "match": 'match:geq',
924 "value": '2014-05-12',
925 "type": 'type:date'
926 },
927 {
928 "@type": 'koral:doc',
929 "key": 'pubDate',
930 "match": 'match:leq',
931 "value": '2014-12-05',
932 "type": 'type:date'
933 }
934 ]
935 }
936 ]
Nils Diewald7c8ced22015-04-15 19:21:00 +0000937 });
938
939 expect(docGroup.operation()).toEqual('or');
940 var e = docGroup.element();
941 expect(e.getAttribute('class')).toEqual('docGroup');
942 expect(e.getAttribute('data-operation')).toEqual('or');
943
944 expect(e.children[0].getAttribute('class')).toEqual('doc');
945 var docop = e.children[0].lastChild;
Akron0b489ad2018-02-02 16:49:32 +0100946 expect(docop.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +0000947 expect(docop.children[0].getAttribute('class')).toEqual('and');
948 expect(docop.children[1].getAttribute('class')).toEqual('or');
949 expect(docop.children[2].getAttribute('class')).toEqual('delete');
950
951 expect(e.children[1].getAttribute('class')).toEqual('docGroup');
952 expect(e.children[1].getAttribute('data-operation')).toEqual('and');
953
954 // This and-operation can be "or"ed or "delete"d
955 var secop = e.children[1].children[2];
Akron0b489ad2018-02-02 16:49:32 +0100956 expect(secop.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +0000957 expect(secop.children[0].getAttribute('class')).toEqual('or');
958 expect(secop.children[1].getAttribute('class')).toEqual('delete');
959
960 // This or-operation can be "and"ed or "delete"d
Akron0b489ad2018-02-02 16:49:32 +0100961 expect(e.children[2].getAttribute('class')).toEqual('operators button-group');
962 expect(e.lastChild.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +0000963 expect(e.lastChild.children[0].getAttribute('class')).toEqual('and');
964 expect(e.lastChild.children[1].getAttribute('class')).toEqual('delete');
965 });
966 });
967
Akronb19803c2018-08-16 16:39:42 +0200968 describe('KorAP.DocGroupRef element', function () {
969 it('should be initializable', function () {
970 var docGroupRef = docGroupRefClass.create(undefined, {
971 "@type" : "koral:docGroupRef",
972 "ref" : "@franz/myVC1"
973 });
974 expect(docGroupRef.ref()).toEqual("@franz/myVC1");
975 var dgrE = docGroupRef.element();
976
Akron3ad46942018-08-22 16:47:14 +0200977 expect(dgrE.children[0].firstChild.data).toEqual("referTo");
Akronb19803c2018-08-16 16:39:42 +0200978 expect(dgrE.children[0].tagName).toEqual("SPAN");
979 expect(dgrE.children[0].classList.contains("key")).toBeTruthy();
980 expect(dgrE.children[0].classList.contains("fixed")).toBeTruthy();
981 expect(dgrE.children[1].firstChild.data).toEqual("@franz/myVC1");
982 expect(dgrE.children[1].tagName).toEqual("SPAN");
983 expect(dgrE.children[1].classList.contains("value")).toBeTruthy();
984 expect(dgrE.children[1].getAttribute("data-type")).toEqual("string");
985 });
986
987 it('should be modifiable on reference', function () {
988 var docGroupRef = docGroupRefClass.create(undefined, {
989 "@type" : "koral:docGroupRef",
990 "ref" : "@franz/myVC1"
991 });
992 var dgrE = docGroupRef.element();
993 expect(docGroupRef.toQuery()).toEqual("referTo \"@franz/myVC1\"");
994 dgrE.children[1].click();
995
996 var input = dgrE.children[1].firstChild;
997 expect(input.tagName).toEqual("INPUT");
998 input.value = "Versuch";
999
1000 var event = new KeyboardEvent("keypress", {
1001 "key" : "[Enter]",
1002 "keyCode" : 13
1003 });
1004
1005 input.dispatchEvent(event);
1006 expect(docGroupRef.toQuery()).toEqual("referTo \"Versuch\"");
1007 });
1008 });
1009
1010
Akrone4961b12017-05-10 21:04:46 +02001011 describe('KorAP.VirtualCorpus', function () {
Nils Diewald7c8ced22015-04-15 19:21:00 +00001012 var simpleGroupFactory = buildFactory(docGroupClass, {
1013 "@type" : "koral:docGroup",
1014 "operation" : "operation:and",
1015 "operands" : [
Akron712733a2018-04-05 18:17:47 +02001016 {
1017 "@type": 'koral:doc',
1018 "key" : 'author',
1019 "match": 'match:eq',
1020 "value": 'Max Birkendale',
1021 "type": 'type:string'
1022 },
1023 {
1024 "@type": 'koral:doc',
1025 "key": 'pubDate',
1026 "match": 'match:eq',
1027 "value": '2014-12-05',
1028 "type": 'type:date'
1029 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00001030 ]
1031 });
1032
1033 var nestedGroupFactory = buildFactory(vcClass, {
1034 "@type" : "koral:docGroup",
1035 "operation" : "operation:or",
1036 "operands" : [
Akron712733a2018-04-05 18:17:47 +02001037 {
1038 "@type": 'koral:doc',
1039 "key" : 'author',
1040 "match": 'match:eq',
1041 "value": 'Max Birkendale',
1042 "type": 'type:string'
1043 },
1044 {
1045 "@type" : "koral:docGroup",
1046 "operation" : "operation:and",
1047 "operands" : [
1048 {
1049 "@type": 'koral:doc',
1050 "key": 'pubDate',
1051 "match": 'match:geq',
1052 "value": '2014-05-12',
1053 "type": 'type:date'
1054 },
1055 {
1056 "@type": 'koral:doc',
1057 "key": 'pubDate',
1058 "match": 'match:leq',
1059 "value": '2014-12-05',
1060 "type": 'type:date'
1061 }
1062 ]
1063 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00001064 ]
1065 });
1066
1067 var flatGroupFactory = buildFactory(vcClass, {
1068 "@type" : "koral:docGroup",
1069 "operation" : "operation:and",
1070 "operands" : [
Akron712733a2018-04-05 18:17:47 +02001071 {
1072 "@type": 'koral:doc',
1073 "key": 'pubDate',
1074 "match": 'match:geq',
1075 "value": '2014-05-12',
1076 "type": 'type:date'
1077 },
1078 {
1079 "@type": 'koral:doc',
1080 "key": 'pubDate',
1081 "match": 'match:leq',
1082 "value": '2014-12-05',
1083 "type": 'type:date'
1084 },
1085 {
1086 "@type": 'koral:doc',
1087 "key": 'foo',
1088 "match": 'match:eq',
1089 "value": 'bar',
1090 "type": 'type:string'
1091 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00001092 ]
1093 });
1094
1095 it('should be initializable', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00001096 var vc = vcClass.create();
Nils Diewald7c8ced22015-04-15 19:21:00 +00001097 expect(vc.element().getAttribute('class')).toEqual('vc');
1098 expect(vc.root().element().getAttribute('class')).toEqual('doc unspecified');
1099
1100 // Not removable
1101 expect(vc.root().element().lastChild.children.length).toEqual(0);
1102 });
1103
1104 it('should be based on a doc', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00001105 var vc = vcClass.create().fromJson({
Akron712733a2018-04-05 18:17:47 +02001106 "@type" : "koral:doc",
1107 "key":"Titel",
1108 "value":"Baum",
1109 "match":"match:eq"
Nils Diewald7c8ced22015-04-15 19:21:00 +00001110 });
1111
1112 expect(vc.element().getAttribute('class')).toEqual('vc');
1113 expect(vc.root().element().getAttribute('class')).toEqual('doc');
1114 expect(vc.root().key()).toEqual('Titel');
1115 expect(vc.root().value()).toEqual('Baum');
1116 expect(vc.root().matchop()).toEqual('eq');
1117
1118 var docE = vc.root().element();
1119 expect(docE.children[0].firstChild.data).toEqual('Titel');
1120 expect(docE.children[1].firstChild.data).toEqual('eq');
1121 expect(docE.children[1].getAttribute('data-type')).toEqual('string');
1122 expect(docE.children[2].firstChild.data).toEqual('Baum');
1123 expect(docE.children[2].getAttribute('data-type')).toEqual('string');
1124 });
1125
1126 it('should be based on a docGroup', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00001127 var vc = vcClass.create().fromJson(simpleGroupFactory.create().toJson());
Nils Diewald7c8ced22015-04-15 19:21:00 +00001128
1129 expect(vc.element().getAttribute('class')).toEqual('vc');
1130 expect(vc.root().element().getAttribute('class')).toEqual('docGroup');
1131 expect(vc.root().operation()).toEqual('and');
1132
1133 var docGroup = vc.root();
1134
1135 var first = docGroup.getOperand(0);
1136 expect(first.key()).toEqual('author');
1137 expect(first.value()).toEqual('Max Birkendale');
1138 expect(first.matchop()).toEqual('eq');
1139
1140 var second = docGroup.getOperand(1);
1141 expect(second.key()).toEqual('pubDate');
1142 expect(second.value()).toEqual('2014-12-05');
1143 expect(second.matchop()).toEqual('eq');
1144 });
1145
Akronb19803c2018-08-16 16:39:42 +02001146 it('should be based on a docGroupRef', function () {
1147 var vc = vcClass.create().fromJson({
1148 "@type" : "koral:docGroupRef",
1149 "ref":"myCorpus"
1150 });
1151
Akron3ad46942018-08-22 16:47:14 +02001152 // iv class="doc groupref"><span class="key fixed">referTo</span><span data-type="string" class="value">myCorpus</span>
Akronb19803c2018-08-16 16:39:42 +02001153 var vcE = vc.element();
1154 expect(vcE.getAttribute('class')).toEqual('vc');
1155 expect(vcE.firstChild.tagName).toEqual('DIV');
1156 expect(vcE.firstChild.classList.contains('groupref')).toBeTruthy();
1157
1158 expect(vcE.firstChild.firstChild.tagName).toEqual('SPAN');
1159 expect(vcE.firstChild.firstChild.classList.contains('key')).toBeTruthy();
1160 expect(vcE.firstChild.firstChild.classList.contains('fixed')).toBeTruthy();
1161
Akron3ad46942018-08-22 16:47:14 +02001162 expect(vcE.firstChild.firstChild.textContent).toEqual("referTo");
Akronb19803c2018-08-16 16:39:42 +02001163
1164 expect(vcE.firstChild.children[1].tagName).toEqual('SPAN');
1165 expect(vcE.firstChild.children[1].classList.contains('value')).toBeTruthy();
1166 expect(vcE.firstChild.children[1].getAttribute('data-type')).toEqual('string');
1167 expect(vcE.firstChild.children[1].textContent).toEqual("myCorpus");
1168 });
Nils Diewald7c8ced22015-04-15 19:21:00 +00001169
1170 it('should be based on a nested docGroup', function () {
1171 var vc = nestedGroupFactory.create();
1172
1173 expect(vc.element().getAttribute('class')).toEqual('vc');
1174 expect(vc.element().firstChild.getAttribute('class')).toEqual('docGroup');
1175 expect(vc.element().firstChild.children[0].getAttribute('class')).toEqual('doc');
1176 var dg = vc.element().firstChild.children[1];
1177 expect(dg.getAttribute('class')).toEqual('docGroup');
1178 expect(dg.children[0].getAttribute('class')).toEqual('doc');
1179 expect(dg.children[1].getAttribute('class')).toEqual('doc');
Akron0b489ad2018-02-02 16:49:32 +01001180 expect(dg.children[2].getAttribute('class')).toEqual('operators button-group');
1181 expect(vc.element().firstChild.children[2].getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001182 });
1183
Akronb19803c2018-08-16 16:39:42 +02001184 it('should be based on a nested docGroupRef', function () {
1185 var vc = vcClass.create().fromJson({
1186 "@type" : "koral:docGroup",
1187 "operation" : "operation:and",
1188 "operands" : [{
1189 "@type" : "koral:docGroupRef",
1190 "ref":"myCorpus"
1191 },{
1192 "@type" : "koral:doc",
1193 "key":"Titel",
1194 "value":"Baum",
1195 "match":"match:eq"
1196 }]
1197 });
1198
1199 expect(vc._root.ldType()).toEqual("docGroup");
1200
1201 expect(vc.toQuery()).toEqual('referTo "myCorpus" & Titel = "Baum"');
1202 });
1203
1204
Nils Diewald7c8ced22015-04-15 19:21:00 +00001205 it('should be modifiable by deletion in flat docGroups', function () {
1206 var vc = flatGroupFactory.create();
1207 var docGroup = vc.root();
1208
1209 expect(docGroup.element().getAttribute('class')).toEqual('docGroup');
1210
1211 var doc = docGroup.getOperand(1);
1212 expect(doc.key()).toEqual("pubDate");
1213 expect(doc.value()).toEqual("2014-12-05");
1214
1215 // Remove operand 1
1216 expect(docGroup.delOperand(doc).update()).not.toBeUndefined();
1217 expect(doc._element).toEqual(undefined);
1218
1219 doc = docGroup.getOperand(1);
1220 expect(doc.key()).toEqual("foo");
1221
1222 // Remove operand 1
1223 expect(docGroup.delOperand(doc).update()).not.toBeUndefined();
1224 expect(doc._element).toEqual(undefined);
1225
1226 // Only one operand left ...
1227 expect(docGroup.getOperand(1)).toBeUndefined();
1228 // ... but there shouldn't be a group anymore at all!
1229 expect(docGroup.getOperand(0)).toBeUndefined();
1230
1231 var obj = vc.root();
1232 expect(obj.ldType()).toEqual("doc");
1233 expect(obj.key()).toEqual("pubDate");
1234 expect(obj.value()).toEqual("2014-05-12");
1235
1236 expect(obj.element().getAttribute('class')).toEqual('doc');
1237 });
1238
1239
1240 it('should be modifiable by deletion in nested docGroups (root case)', function () {
1241 var vc = nestedGroupFactory.create();
1242
1243 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001244 'author = "Max Birkendale" | (pubDate since 2014-05-12 & pubDate until 2014-12-05)'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001245 );
1246
1247 var docGroup = vc.root();
1248 expect(docGroup.ldType()).toEqual("docGroup");
1249 expect(docGroup.operation()).toEqual("or");
1250
1251 var doc = docGroup.getOperand(0);
1252 expect(doc.key()).toEqual("author");
1253 expect(doc.value()).toEqual("Max Birkendale");
1254
1255 docGroup = docGroup.getOperand(1);
1256 expect(docGroup.operation()).toEqual("and");
1257
1258 doc = docGroup.getOperand(0);
1259 expect(doc.key()).toEqual("pubDate");
1260 expect(doc.matchop()).toEqual("geq");
1261 expect(doc.value()).toEqual("2014-05-12");
1262 expect(doc.type()).toEqual("date");
1263
1264 doc = docGroup.getOperand(1);
1265 expect(doc.key()).toEqual("pubDate");
1266 expect(doc.matchop()).toEqual("leq");
1267 expect(doc.value()).toEqual("2014-12-05");
1268 expect(doc.type()).toEqual("date");
1269
1270 // Remove first operand so everything becomes root
1271 expect(
Akron712733a2018-04-05 18:17:47 +02001272 vc.root().delOperand(
1273 vc.root().getOperand(0)
1274 ).update().ldType()
Nils Diewald7c8ced22015-04-15 19:21:00 +00001275 ).toEqual("docGroup");
1276
1277 expect(vc.root().ldType()).toEqual("docGroup");
1278 expect(vc.root().operation()).toEqual("and");
1279 expect(vc.root().getOperand(0).ldType()).toEqual("doc");
1280
1281 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001282 'pubDate since 2014-05-12 & pubDate until 2014-12-05'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001283 );
1284 });
1285
1286 it('should be modifiable by deletion in nested docGroups (resolve group case)', function () {
1287 var vc = nestedGroupFactory.create();
1288
1289 // Get nested group
1290 var firstGroup = vc.root().getOperand(1);
1291 firstGroup.append(simpleGroupFactory.create({ "operation" : "operation:or" }));
1292
1293 // Structur is now:
1294 // or(doc, and(doc, doc, or(doc, doc)))
1295
1296 // Get nested or in and
1297 var orGroup = vc.root().getOperand(1).getOperand(2);
1298 expect(orGroup.ldType()).toEqual("docGroup");
1299 expect(orGroup.operation()).toEqual("or");
1300
1301 // Remove
1302 // Structur is now:
1303 // or(doc, and(doc, doc, doc)))
1304 expect(orGroup.delOperand(orGroup.getOperand(0)).update().operation()).toEqual("and");
1305 expect(vc.root().getOperand(1).operands().length).toEqual(3);
1306 });
1307
1308 it('should be modifiable by deletion in nested docGroups (identical group case)', function () {
1309 var vc = nestedGroupFactory.create();
1310
1311 // Get nested group
1312 var firstGroup = vc.root().getOperand(1);
1313 firstGroup.append(simpleGroupFactory.create({
Akron712733a2018-04-05 18:17:47 +02001314 "operation" : "operation:or"
Nils Diewald7c8ced22015-04-15 19:21:00 +00001315 }));
1316 var oldAuthor = firstGroup.getOperand(2).getOperand(0);
1317 oldAuthor.key("title");
1318 oldAuthor.value("Der Birnbaum");
1319
1320 // Structur is now:
1321 // or(doc, and(doc, doc, or(doc, doc)))
1322 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001323 'author = "Max Birkendale" | ' +
1324 '(pubDate since 2014-05-12 & ' +
1325 'pubDate until 2014-12-05 & ' +
1326 '(title = "Der Birnbaum" | ' +
1327 'pubDate in 2014-12-05))'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001328 );
1329
1330 var andGroup = vc.root().getOperand(1);
1331
1332 // Get leading docs in and
1333 var doc1 = andGroup.getOperand(0);
1334 expect(doc1.ldType()).toEqual("doc");
1335 expect(doc1.value()).toEqual("2014-05-12");
1336 var doc2 = andGroup.getOperand(1);
1337 expect(doc2.ldType()).toEqual("doc");
1338 expect(doc2.value()).toEqual("2014-12-05");
1339
1340 // Remove 2
1341 expect(
Akron712733a2018-04-05 18:17:47 +02001342 andGroup.delOperand(doc2).update().operation()
Nils Diewald7c8ced22015-04-15 19:21:00 +00001343 ).toEqual("and");
1344 // Structur is now:
1345 // or(doc, and(doc, or(doc, doc)))
1346
1347 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001348 'author = "Max Birkendale"' +
1349 ' | (pubDate since 2014-05-12 & ' +
1350 '(title = "Der Birnbaum" | pubDate in 2014-12-05))'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001351 );
1352
1353
1354 // Remove 1
1355 expect(andGroup.delOperand(doc1).update().operation()).toEqual("or");
1356 // Structur is now:
1357 // or(doc, doc, doc)
1358
1359 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001360 'author = "Max Birkendale" | title = "Der Birnbaum" | pubDate in 2014-12-05'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001361 );
1362 });
1363
1364 it('should be reducible to unspecification', function () {
1365 var vc = demoFactory.create();
1366
1367 expect(vc.toQuery()).toEqual(vc.root().toQuery());
1368 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001369 '(Titel = "Baum" & Veröffentlichungsort = "hihi" & ' +
1370 '(Titel = "Baum" | Veröffentlichungsort = "hihi")) ' +
1371 '| Untertitel ~ "huhu"');
Akrond141a362018-07-10 18:12:13 +02001372 expect(vc.root().element().lastChild.children[0].innerText).toEqual('and');
1373 expect(vc.root().element().lastChild.children[1].innerText).toEqual('×');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001374 expect(vc.root().delOperand(vc.root().getOperand(0)).update()).not.toBeUndefined();
Akron712733a2018-04-05 18:17:47 +02001375 expect(vc.toQuery()).toEqual('Untertitel ~ "huhu"');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001376
1377 var lc = vc.root().element().lastChild;
Akrond141a362018-07-10 18:12:13 +02001378 expect(lc.children[0].innerText).toEqual('and');
1379 expect(lc.children[1].innerText).toEqual('or');
1380 expect(lc.children[2].innerText).toEqual('×');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001381
1382 // Clean everything
1383 vc.clean();
1384 expect(vc.toQuery()).toEqual('');
1385 });
1386
1387 it('should flatten on import', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00001388 var vc = vcClass.create().fromJson({
Akron712733a2018-04-05 18:17:47 +02001389 "@type":"koral:docGroup",
1390 "operation":"operation:or",
1391 "operands":[
1392 {
1393 "@type":"koral:docGroup",
1394 "operation":"operation:or",
1395 "operands":[
Nils Diewald7c8ced22015-04-15 19:21:00 +00001396 {
Akron712733a2018-04-05 18:17:47 +02001397 "@type":"koral:doc",
1398 "key":"Titel",
1399 "value":"Baum",
1400 "match":"match:eq"
Nils Diewald7c8ced22015-04-15 19:21:00 +00001401 },
1402 {
Akron712733a2018-04-05 18:17:47 +02001403 "@type":"koral:doc",
1404 "key":"Veröffentlichungsort",
1405 "value":"hihi",
1406 "match":"match:eq"
Nils Diewald7c8ced22015-04-15 19:21:00 +00001407 },
1408 {
Akron712733a2018-04-05 18:17:47 +02001409 "@type":"koral:docGroup",
1410 "operation":"operation:or",
1411 "operands":[
1412 {
1413 "@type":"koral:doc",
1414 "key":"Titel",
1415 "value":"Baum",
1416 "match":"match:eq"
1417 },
1418 {
1419 "@type":"koral:doc",
1420 "key":"Veröffentlichungsort",
1421 "value":"hihi",
1422 "match":"match:eq"
1423 }
1424 ]
Nils Diewald7c8ced22015-04-15 19:21:00 +00001425 }
Akron712733a2018-04-05 18:17:47 +02001426 ]
1427 },
1428 {
1429 "@type":"koral:doc",
1430 "key":"Untertitel",
1431 "value":"huhu",
1432 "match":"match:contains"
1433 }
1434 ]
Nils Diewald7c8ced22015-04-15 19:21:00 +00001435 });
Nils Diewaldfda29d92015-01-22 17:28:01 +00001436
Nils Diewald7c8ced22015-04-15 19:21:00 +00001437 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001438 'Titel = "Baum" | Veröffentlichungsort = "hihi" | Untertitel ~ "huhu"'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001439 );
Nils Diewald86dad5b2015-01-28 15:09:07 +00001440 });
Akron1bdf5272018-07-24 18:51:30 +02001441
1442 it('should be deserializable from collection 1', function () {
1443 var kq = {
1444 "matches":["..."],
1445 "collection":{
1446 "@type": "koral:docGroup",
1447 "operation": "operation:or",
1448 "operands": [{
1449 "@type": "koral:docGroup",
1450 "operation": "operation:and",
1451 "operands": [
1452 {
1453 "@type": "koral:doc",
1454 "key": "title",
1455 "match": "match:eq",
1456 "value": "Der Birnbaum",
1457 "type": "type:string"
1458 },
1459 {
1460 "@type": "koral:doc",
1461 "key": "pubPlace",
1462 "match": "match:eq",
1463 "value": "Mannheim",
1464 "type": "type:string"
1465 },
1466 {
1467 "@type": "koral:docGroup",
1468 "operation": "operation:or",
1469 "operands": [
1470 {
1471 "@type": "koral:doc",
1472 "key": "subTitle",
1473 "match": "match:eq",
1474 "value": "Aufzucht und Pflege",
1475 "type": "type:string"
1476 },
1477 {
1478 "@type": "koral:doc",
1479 "key": "subTitle",
1480 "match": "match:eq",
1481 "value": "Gedichte",
1482 "type": "type:string"
1483 }
1484 ]
1485 }
1486 ]
1487 },{
1488 "@type": "koral:doc",
1489 "key": "pubDate",
1490 "match": "match:geq",
1491 "value": "2015-03-05",
1492 "type": "type:date",
1493 "rewrites" : [{
1494 "@type" : "koral:rewrite",
1495 "operation" : "operation:modification",
1496 "src" : "querySerializer",
1497 "scope" : "tree"
1498 }]
1499 }]
1500 }
1501 };
1502
1503 var vc = vcClass.create().fromJson(kq["collection"]);
1504 expect(vc.toQuery()).toEqual('(title = "Der Birnbaum" & pubPlace = "Mannheim" & (subTitle = "Aufzucht und Pflege" | subTitle = "Gedichte")) | pubDate since 2015-03-05');
1505 });
1506
1507 it('should be deserializable from collection 2', function () {
1508 var kq = {
1509 "@context": "http://korap.ids-mannheim.de/ns/KoralQuery/v0.3/context.jsonld",
1510 "meta": {},
1511 "query": {
1512 "@type": "koral:token",
1513 "wrap": {
1514 "@type": "koral:term",
1515 "match": "match:eq",
1516 "layer": "orth",
1517 "key": "Baum",
1518 "foundry": "opennlp",
1519 "rewrites": [
1520 {
1521 "@type": "koral:rewrite",
1522 "src": "Kustvakt",
1523 "operation": "operation:injection",
1524 "scope": "foundry"
1525 }
1526 ]
1527 },
1528 "idn": "Baum_2227",
1529 "rewrites": [
1530 {
1531 "@type": "koral:rewrite",
1532 "src": "Kustvakt",
1533 "operation": "operation:injection",
1534 "scope": "idn"
1535 }
1536 ]
1537 },
1538 "collection": {
1539 "@type": "koral:docGroup",
1540 "operation": "operation:and",
1541 "operands": [
1542 {
1543 "@type": "koral:doc",
1544 "match": "match:eq",
1545 "type": "type:regex",
1546 "value": "CC-BY.*",
1547 "key": "availability"
1548 },
1549 {
1550 "@type": "koral:doc",
1551 "match": "match:eq",
1552 "type":"type:text",
1553 "value": "Goethe",
1554 "key": "author"
1555 }
1556 ],
1557 "rewrites": [
1558 {
1559 "@type": "koral:rewrite",
1560 "src": "Kustvakt",
1561 "operation": "operation:insertion",
1562 "scope": "availability(FREE)"
1563 }
1564 ]
1565 },
1566 "matches": []
1567 };
1568
1569 var vc = vcClass.create().fromJson(kq["collection"]);
1570 expect(vc.toQuery()).toEqual('availability = /CC-BY.*/ & author = "Goethe"');
1571 });
Nils Diewald86dad5b2015-01-28 15:09:07 +00001572 });
1573
Akron1bdf5272018-07-24 18:51:30 +02001574 it('shouldn\'t be deserializable from collection with unknown type', function () {
1575 var kq = {
1576 "@type" : "koral:doc",
1577 "match": "match:eq",
1578 "type":"type:failure",
1579 "value": "Goethe",
1580 "key": "author"
1581 };
1582
1583 expect(function () {
1584 vcClass.create().fromJson(kq)
1585 }).toThrow(new Error("Unknown value type: string"));
Akron1bdf5272018-07-24 18:51:30 +02001586 });
1587
1588
Nils Diewald7c8ced22015-04-15 19:21:00 +00001589 describe('KorAP.Operators', function () {
1590 it('should be initializable', function () {
1591 var op = operatorsClass.create(true, false, false);
1592 expect(op.and()).toBeTruthy();
1593 expect(op.or()).not.toBeTruthy();
1594 expect(op.del()).not.toBeTruthy();
1595
1596 op.and(false);
1597 expect(op.and()).not.toBeTruthy();
1598 expect(op.or()).not.toBeTruthy();
1599 expect(op.del()).not.toBeTruthy();
1600
1601 op.or(true);
1602 op.del(true);
1603 expect(op.and()).not.toBeTruthy();
1604 expect(op.or()).toBeTruthy();
1605 expect(op.del()).toBeTruthy();
1606
Akrond141a362018-07-10 18:12:13 +02001607 var e = op.update();
Akron0b489ad2018-02-02 16:49:32 +01001608 expect(e.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001609 expect(e.children[0].getAttribute('class')).toEqual('or');
Akrond141a362018-07-10 18:12:13 +02001610 expect(e.children[0].innerText).toEqual('or');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001611 expect(e.children[1].getAttribute('class')).toEqual('delete');
Akrond141a362018-07-10 18:12:13 +02001612 expect(e.children[1].innerText).toEqual('×');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001613
1614 op.and(true);
1615 op.del(false);
Akrond141a362018-07-10 18:12:13 +02001616 e = op.update();
Nils Diewald7c8ced22015-04-15 19:21:00 +00001617
Akron0b489ad2018-02-02 16:49:32 +01001618 expect(e.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001619 expect(e.children[0].getAttribute('class')).toEqual('and');
Akrond141a362018-07-10 18:12:13 +02001620 expect(e.children[0].innerText).toEqual('and');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001621 expect(e.children[1].getAttribute('class')).toEqual('or');
Akrond141a362018-07-10 18:12:13 +02001622 expect(e.children[1].innerText).toEqual('or');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001623 });
1624 });
1625
1626 describe('KorAP._delete (event)', function () {
1627 var complexVCFactory = buildFactory(vcClass,{
1628 "@type": 'koral:docGroup',
1629 'operation' : 'operation:and',
1630 'operands' : [
Akron712733a2018-04-05 18:17:47 +02001631 {
1632 "@type": 'koral:doc',
1633 "key": 'pubDate',
1634 "match": 'match:eq',
1635 "value": '2014-12-05',
1636 "type": 'type:date'
1637 },
1638 {
1639 "@type" : 'koral:docGroup',
1640 'operation' : 'operation:or',
1641 'operands' : [
1642 {
1643 '@type' : 'koral:doc',
1644 'key' : 'title',
1645 'value' : 'Hello World!'
1646 },
1647 {
1648 '@type' : 'koral:doc',
1649 'key' : 'foo',
1650 'value' : 'bar'
1651 }
1652 ]
1653 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00001654 ]
1655 });
1656
1657 it('should clean on root docs', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00001658 var vc = vcClass.create().fromJson({
Akron712733a2018-04-05 18:17:47 +02001659 "@type": 'koral:doc',
1660 "key": 'pubDate',
1661 "match": 'match:eq',
1662 "value": '2014-12-05',
1663 "type": 'type:date'
Nils Diewald86dad5b2015-01-28 15:09:07 +00001664 });
Nils Diewald7c8ced22015-04-15 19:21:00 +00001665 expect(vc.root().toQuery()).toEqual('pubDate in 2014-12-05');
Akron0b489ad2018-02-02 16:49:32 +01001666 expect(vc.root().element().lastChild.getAttribute('class')).toEqual('operators button-group');
Nils Diewald86dad5b2015-01-28 15:09:07 +00001667
Nils Diewald7c8ced22015-04-15 19:21:00 +00001668 // Clean with delete from root
1669 expect(vc.root().element().lastChild.lastChild.getAttribute('class')).toEqual('delete');
1670 _delOn(vc.root());
1671 expect(vc.root().toQuery()).toEqual('');
1672 expect(vc.root().element().lastChild.lastChild.data).toEqual('⋯');
1673 });
Nils Diewald86dad5b2015-01-28 15:09:07 +00001674
Nils Diewald7c8ced22015-04-15 19:21:00 +00001675 it('should remove on nested docs', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00001676 var vc = vcClass.create().fromJson(
Akron712733a2018-04-05 18:17:47 +02001677 {
1678 "@type": 'koral:docGroup',
1679 'operation' : 'operation:and',
1680 'operands' : [
1681 {
1682 "@type": 'koral:doc',
1683 "key": 'pubDate',
1684 "match": 'match:eq',
1685 "value": '2014-12-05',
1686 "type": 'type:date'
1687 },
1688 {
1689 "@type" : 'koral:doc',
1690 'key' : 'foo',
1691 'value' : 'bar'
1692 }
1693 ]
1694 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00001695 );
1696
1697 // Delete with direct element access
1698 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar"');
1699 _delOn(vc.root().getOperand(0));
1700
1701 expect(vc.toQuery()).toEqual('foo = "bar"');
1702 expect(vc.root().ldType()).toEqual('doc');
1703 });
1704
1705 it('should clean on doc groups', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00001706 var vc = vcClass.create().fromJson(
Akron712733a2018-04-05 18:17:47 +02001707 {
1708 "@type": 'koral:docGroup',
1709 'operation' : 'operation:and',
1710 'operands' : [
1711 {
1712 "@type": 'koral:doc',
1713 "key": 'pubDate',
1714 "match": 'match:eq',
1715 "value": '2014-12-05',
1716 "type": 'type:date'
1717 },
1718 {
1719 "@type" : 'koral:doc',
1720 'key' : 'foo',
1721 'value' : 'bar'
1722 }
1723 ]
1724 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00001725 );
1726
1727 // Cleanwith direct element access
1728 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar"');
1729 _delOn(vc.root());
1730 expect(vc.toQuery()).toEqual('');
1731 expect(vc.root().ldType()).toEqual('non');
1732 });
1733
1734 it('should remove on nested doc groups (case of ungrouping 1)', function () {
1735 var vc = complexVCFactory.create();
1736
1737 // Delete with direct element access
1738 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001739 'pubDate in 2014-12-05 & (title = "Hello World!" | foo = "bar")'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001740 );
1741
1742 // Remove hello world:
1743 _delOn(vc.root().getOperand(1).getOperand(0));
1744 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar"');
1745 expect(vc.root().ldType()).toEqual('docGroup');
1746 });
1747
1748 it('should remove on nested doc groups (case of ungrouping 2)', function () {
1749 var vc = complexVCFactory.create();
1750
1751 // Delete with direct element access
1752 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001753 'pubDate in 2014-12-05 & (title = "Hello World!" | foo = "bar")'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001754 );
1755
1756 // Remove bar
1757 _delOn(vc.root().getOperand(1).getOperand(1));
1758 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & title = "Hello World!"');
1759 expect(vc.root().ldType()).toEqual('docGroup');
1760 expect(vc.root().operation()).toEqual('and');
1761 });
1762
1763 it('should remove on nested doc groups (case of root changing)', function () {
1764 var vc = complexVCFactory.create();
1765
1766 // Delete with direct element access
1767 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001768 'pubDate in 2014-12-05 & ' +
1769 '(title = "Hello World!" | foo = "bar")'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001770 );
1771
1772 // Remove bar
1773 _delOn(vc.root().getOperand(0));
1774 expect(vc.toQuery()).toEqual('title = "Hello World!" | foo = "bar"');
1775 expect(vc.root().ldType()).toEqual('docGroup');
1776 expect(vc.root().operation()).toEqual('or');
1777 });
1778
1779 it('should remove on nested doc groups (list flattening)', 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:or',
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 "@type": 'koral:docGroup',
1799 'operation' : 'operation:and',
1800 'operands' : [
1801 {
1802 "@type": 'koral:doc',
1803 "key": 'pubDate',
1804 "match": 'match:eq',
1805 "value": '2014-12-05',
1806 "type": 'type:date'
1807 },
1808 {
1809 "@type" : 'koral:docGroup',
1810 'operation' : 'operation:or',
1811 'operands' : [
1812 {
1813 '@type' : 'koral:doc',
1814 'key' : 'title',
1815 'value' : 'Hello World!'
1816 },
1817 {
1818 '@type' : 'koral:doc',
1819 'key' : 'yeah',
1820 'value' : 'juhu'
1821 }
1822 ]
1823 }
1824 ]
1825 }
1826 ]
1827 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00001828 );
1829
1830 // Delete with direct element access
1831 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001832 'pubDate in 2014-12-05 | foo = "bar" | ' +
1833 '(pubDate in 2014-12-05 & ' +
1834 '(title = "Hello World!" | yeah = "juhu"))'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001835 );
1836
1837 expect(vc.root().ldType()).toEqual('docGroup');
1838 expect(vc.root().operation()).toEqual('or');
1839
1840 // Operands and operators
1841 expect(vc.element().firstChild.children.length).toEqual(4);
Akron0b489ad2018-02-02 16:49:32 +01001842 expect(vc.element().firstChild.lastChild.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001843
1844 // Remove inner group and flatten
1845 _delOn(vc.root().getOperand(2).getOperand(0));
1846
1847 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001848 'pubDate in 2014-12-05 | foo = "bar" | title = "Hello World!" | yeah = "juhu"'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001849 );
1850 expect(vc.root().ldType()).toEqual('docGroup');
1851 expect(vc.root().operation()).toEqual('or');
1852
1853 // Operands and operators
1854 expect(vc.element().firstChild.children.length).toEqual(5);
Akron0b489ad2018-02-02 16:49:32 +01001855 expect(vc.element().firstChild.lastChild.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001856 });
1857 });
1858
1859 describe('KorAP._add (event)', function () {
1860 var complexVCFactory = buildFactory(vcClass,{
1861 "@type": 'koral:docGroup',
1862 'operation' : 'operation:and',
1863 'operands' : [
Akron712733a2018-04-05 18:17:47 +02001864 {
1865 "@type": 'koral:doc',
1866 "key": 'pubDate',
1867 "match": 'match:eq',
1868 "value": '2014-12-05',
1869 "type": 'type:date'
1870 },
1871 {
1872 "@type" : 'koral:docGroup',
1873 'operation' : 'operation:or',
1874 'operands' : [
1875 {
1876 '@type' : 'koral:doc',
1877 'key' : 'title',
1878 'value' : 'Hello World!'
1879 },
1880 {
1881 '@type' : 'koral:doc',
1882 'key' : 'foo',
1883 'value' : 'bar'
1884 }
1885 ]
1886 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00001887 ]
1888 });
1889
1890 it('should add new unspecified doc with "and"', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00001891 var vc = vcClass.create().fromJson(
Akron712733a2018-04-05 18:17:47 +02001892 {
1893 "@type": 'koral:docGroup',
1894 'operation' : 'operation:and',
1895 'operands' : [
1896 {
1897 "@type": 'koral:doc',
1898 "key": 'pubDate',
1899 "match": 'match:eq',
1900 "value": '2014-12-05',
1901 "type": 'type:date'
1902 },
1903 {
1904 "@type" : 'koral:doc',
1905 'key' : 'foo',
1906 'value' : 'bar'
Akronb19803c2018-08-16 16:39:42 +02001907 },
1908 {
1909 "@type" : "koral:docGroupRef",
1910 "ref" : "myCorpus"
Akron712733a2018-04-05 18:17:47 +02001911 }
1912 ]
1913 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00001914 );
1915
Akronb19803c2018-08-16 16:39:42 +02001916 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar" & referTo "myCorpus"');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001917
1918 var fc = vc.element().firstChild;
1919 expect(fc.getAttribute('data-operation')).toEqual('and');
Akronb19803c2018-08-16 16:39:42 +02001920 expect(fc.children.length).toEqual(4);
Akron0b489ad2018-02-02 16:49:32 +01001921 expect(fc.lastChild.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001922 expect(fc.children[0].getAttribute('class')).toEqual('doc');
1923 expect(fc.children[1].getAttribute('class')).toEqual('doc');
Akronb19803c2018-08-16 16:39:42 +02001924 expect(fc.children[2].getAttribute('class')).toEqual('doc groupref');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001925
1926 // add with 'and' in the middle
1927 _andOn(vc.root().getOperand(0));
Akronb19803c2018-08-16 16:39:42 +02001928 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar" & referTo "myCorpus"');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001929
1930 fc = vc.element().firstChild;
1931 expect(fc.getAttribute('data-operation')).toEqual('and');
Akronb19803c2018-08-16 16:39:42 +02001932 expect(fc.children.length).toEqual(5);
Akron0b489ad2018-02-02 16:49:32 +01001933 expect(fc.lastChild.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001934
1935 expect(fc.children[0].getAttribute('class')).toEqual('doc');
1936 expect(fc.children[1].getAttribute('class')).toEqual('doc unspecified');
1937 expect(fc.children[2].getAttribute('class')).toEqual('doc');
Akronb19803c2018-08-16 16:39:42 +02001938 expect(fc.children[3].getAttribute('class')).toEqual('doc groupref');
1939 expect(fc.children[4].classList.contains('button-group')).toBeTruthy();
1940 expect(fc.children.length).toEqual(5);
1941
1942 _andOn(vc.root().getOperand(3));
1943 expect(fc.children[0].getAttribute('class')).toEqual('doc');
1944 expect(fc.children[1].getAttribute('class')).toEqual('doc unspecified');
1945 expect(fc.children[2].getAttribute('class')).toEqual('doc');
1946 expect(fc.children[3].getAttribute('class')).toEqual('doc groupref');
1947 expect(fc.children[4].getAttribute('class')).toEqual('doc unspecified');
1948 expect(fc.children[5].classList.contains('button-group')).toBeTruthy();
1949 expect(fc.children.length).toEqual(6);
1950
Nils Diewald7c8ced22015-04-15 19:21:00 +00001951 });
1952
Akronb19803c2018-08-16 16:39:42 +02001953
Nils Diewald7c8ced22015-04-15 19:21:00 +00001954 it('should add new unspecified doc with "or"', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00001955 var vc = vcClass.create().fromJson(
Akron712733a2018-04-05 18:17:47 +02001956 {
1957 "@type": 'koral:docGroup',
1958 'operation' : 'operation:and',
1959 'operands' : [
1960 {
1961 "@type": 'koral:doc',
1962 "key": 'pubDate',
1963 "match": 'match:eq',
1964 "value": '2014-12-05',
1965 "type": 'type:date'
1966 },
1967 {
1968 "@type" : 'koral:doc',
1969 'key' : 'foo',
1970 'value' : 'bar'
Akronb19803c2018-08-16 16:39:42 +02001971 },
1972 {
1973 "@type" : "koral:docGroupRef",
1974 "ref" : "myCorpus"
Akron712733a2018-04-05 18:17:47 +02001975 }
1976 ]
1977 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00001978 );
1979
Akronb19803c2018-08-16 16:39:42 +02001980 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar" & referTo "myCorpus"');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001981
1982 var fc = vc.element().firstChild;
Akronb19803c2018-08-16 16:39:42 +02001983 expect(fc.children.length).toEqual(4);
Akron0b489ad2018-02-02 16:49:32 +01001984 expect(fc.lastChild.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001985 expect(fc.children[0].getAttribute('class')).toEqual('doc');
1986 expect(fc.children[1].getAttribute('class')).toEqual('doc');
Akronb19803c2018-08-16 16:39:42 +02001987 expect(fc.children[2].getAttribute('class')).toEqual('doc groupref');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001988
1989 // add with 'or' in the middle
1990 _orOn(vc.root().getOperand(0));
Akronb19803c2018-08-16 16:39:42 +02001991 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar" & referTo "myCorpus"');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001992 fc = vc.element().firstChild;
1993
1994 expect(fc.getAttribute('data-operation')).toEqual('and');
Akronb19803c2018-08-16 16:39:42 +02001995 expect(fc.children.length).toEqual(4);
Nils Diewald7c8ced22015-04-15 19:21:00 +00001996 expect(fc.children[0].getAttribute('class')).toEqual('docGroup');
1997 expect(fc.children[0].getAttribute('data-operation')).toEqual('or');
1998 expect(fc.children[1].getAttribute('class')).toEqual('doc');
Akronb19803c2018-08-16 16:39:42 +02001999 expect(fc.children[2].getAttribute('class')).toEqual('doc groupref');
2000 expect(fc.children[3].getAttribute('class')).toEqual('operators button-group');
Akron0b489ad2018-02-02 16:49:32 +01002001 expect(fc.lastChild.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +00002002
2003 fc = vc.element().firstChild.firstChild;
2004 expect(fc.children.length).toEqual(3);
2005 expect(fc.children[0].getAttribute('class')).toEqual('doc');
2006 expect(fc.children[1].getAttribute('class')).toEqual('doc unspecified');
Akron0b489ad2018-02-02 16:49:32 +01002007 expect(fc.children[2].getAttribute('class')).toEqual('operators button-group');
2008 expect(fc.lastChild.getAttribute('class')).toEqual('operators button-group');
Akronb19803c2018-08-16 16:39:42 +02002009
2010 _orOn(vc.root().getOperand(2));
2011 fc = vc.element().firstChild;
2012 expect(fc.children.length).toEqual(4);
2013
2014 expect(fc.children[0].getAttribute('class')).toEqual('docGroup');
2015 expect(fc.children[1].getAttribute('class')).toEqual('doc');
2016 expect(fc.children[2].getAttribute('class')).toEqual('docGroup');
2017 expect(fc.children[3].getAttribute('class')).toEqual('operators button-group');
2018
2019 fc = vc.element().firstChild.children[2];
2020 expect(fc.children[0].getAttribute('class')).toEqual('doc groupref');
2021 expect(fc.children[1].getAttribute('class')).toEqual('doc unspecified');
2022 expect(fc.children[2].getAttribute('class')).toEqual('operators button-group');
2023 expect(fc.lastChild.getAttribute('class')).toEqual('operators button-group');
2024
Nils Diewald7c8ced22015-04-15 19:21:00 +00002025 });
2026
2027 it('should add new unspecified doc with "and" before group', function () {
2028 var vc = demoFactory.create();
2029
2030 // Wrap with direct element access
2031 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02002032 '(Titel = "Baum" & ' +
2033 'Veröffentlichungsort = "hihi" & ' +
2034 '(Titel = "Baum" | ' +
2035 'Veröffentlichungsort = "hihi")) | ' +
2036 'Untertitel ~ "huhu"'
Nils Diewald7c8ced22015-04-15 19:21:00 +00002037 );
2038
2039 expect(vc.root().getOperand(0).ldType()).toEqual('docGroup');
2040 expect(vc.root().getOperand(0).operation()).toEqual('and');
2041 expect(vc.root().getOperand(0).operands().length).toEqual(3);
2042
2043 // Add unspecified on the second doc
2044 var secDoc = vc.root().getOperand(0).getOperand(1);
2045 expect(secDoc.value()).toEqual('hihi');
2046
2047 // Add
2048 _andOn(secDoc);
2049
2050 var fo = vc.root().getOperand(0);
2051
2052 expect(fo.ldType()).toEqual('docGroup');
2053 expect(fo.operation()).toEqual('and');
2054 expect(fo.operands().length).toEqual(4);
2055
2056 expect(fo.getOperand(0).ldType()).toEqual('doc');
2057 expect(fo.getOperand(1).ldType()).toEqual('doc');
2058 expect(fo.getOperand(2).ldType()).toEqual('non');
2059 expect(fo.getOperand(3).ldType()).toEqual('docGroup');
2060 });
2061
2062
2063 it('should remove a doc with an unspecified doc in a nested group', function () {
2064 var vc = demoFactory.create();
2065
2066 // Wrap with direct element access
2067 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02002068 '(Titel = "Baum" & Veröffentlichungsort = "hihi" & (Titel = "Baum" | Veröffentlichungsort = "hihi")) | Untertitel ~ "huhu"'
Nils Diewald7c8ced22015-04-15 19:21:00 +00002069 );
2070
2071 var fo = vc.root().getOperand(0).getOperand(0);
2072 expect(fo.key()).toEqual('Titel');
2073 expect(fo.value()).toEqual('Baum');
2074
2075 // Add unspecified on the root group
2076 _orOn(fo);
2077
2078 fo = vc.root().getOperand(0).getOperand(0);
2079
2080 expect(fo.operation()).toEqual('or');
2081 expect(fo.getOperand(0).ldType()).toEqual('doc');
2082 expect(fo.getOperand(1).ldType()).toEqual('non');
2083
2084 // Delete document
2085 _delOn(fo.getOperand(0));
2086
2087 // The operand is now non
2088 expect(vc.root().getOperand(0).getOperand(0).ldType()).toEqual('non');
2089 expect(vc.root().getOperand(0).getOperand(1).ldType()).toEqual('doc');
2090 expect(vc.root().getOperand(0).getOperand(2).ldType()).toEqual('docGroup');
2091 });
2092
2093
Akron712733a2018-04-05 18:17:47 +02002094 it('should remove an unspecified doc with a doc in a nested group', function () {
Nils Diewald7c8ced22015-04-15 19:21:00 +00002095 var vc = demoFactory.create();
2096
2097 // Wrap with direct element access
2098 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02002099 '(Titel = "Baum" & ' +
2100 'Veröffentlichungsort = "hihi" & ' +
2101 '(Titel = "Baum" ' +
2102 '| Veröffentlichungsort = "hihi")) | ' +
2103 'Untertitel ~ "huhu"'
Nils Diewald7c8ced22015-04-15 19:21:00 +00002104 );
2105
2106 var fo = vc.root().getOperand(0).getOperand(0);
2107 expect(fo.key()).toEqual('Titel');
2108 expect(fo.value()).toEqual('Baum');
2109
2110 // Add unspecified on the root group
2111 _orOn(fo);
2112
2113 fo = vc.root().getOperand(0).getOperand(0);
2114
2115 expect(fo.operation()).toEqual('or');
2116 expect(fo.getOperand(0).ldType()).toEqual('doc');
2117 expect(fo.getOperand(1).ldType()).toEqual('non');
2118
2119 // Delete unspecified doc
2120 _delOn(fo.getOperand(1));
2121
2122 // The operand is now non
2123 fo = vc.root().getOperand(0);
2124 expect(fo.getOperand(0).ldType()).toEqual('doc');
2125 expect(fo.getOperand(0).key()).toEqual('Titel');
2126 expect(fo.getOperand(0).value()).toEqual('Baum');
2127 expect(fo.getOperand(1).ldType()).toEqual('doc');
2128 expect(fo.getOperand(2).ldType()).toEqual('docGroup');
2129 });
2130
2131
2132 it('should add on parent group (case "and")', function () {
2133 var vc = complexVCFactory.create();
2134
2135 // Wrap with direct element access
2136 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02002137 'pubDate in 2014-12-05 & (title = "Hello World!" | foo = "bar")'
Nils Diewald7c8ced22015-04-15 19:21:00 +00002138 );
2139
2140 expect(vc.root().operands().length).toEqual(2);
2141
2142 // Add unspecified on the root group
2143 _andOn(vc.root().getOperand(1));
2144 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02002145 'pubDate in 2014-12-05 & (title = "Hello World!" | foo = "bar")'
Nils Diewald7c8ced22015-04-15 19:21:00 +00002146 );
2147
2148 expect(vc.root().ldType()).toEqual('docGroup');
2149 expect(vc.root().operands().length).toEqual(3);
2150 expect(vc.root().getOperand(0).ldType()).toEqual('doc');
2151 expect(vc.root().getOperand(1).ldType()).toEqual('docGroup');
2152 expect(vc.root().getOperand(1).operation()).toEqual('or');
2153 expect(vc.root().getOperand(2).ldType()).toEqual('non');
2154
2155 // Add another unspecified on the root group
2156 _andOn(vc.root().getOperand(1));
2157
2158 expect(vc.root().operands().length).toEqual(4);
2159 expect(vc.root().getOperand(0).ldType()).toEqual('doc');
2160 expect(vc.root().getOperand(1).ldType()).toEqual('docGroup');
2161 expect(vc.root().getOperand(2).ldType()).toEqual('non');
2162 expect(vc.root().getOperand(3).ldType()).toEqual('non');
2163
2164 // Add another unspecified after the first doc
2165 _andOn(vc.root().getOperand(0));
2166
2167 expect(vc.root().operands().length).toEqual(5);
2168 expect(vc.root().getOperand(0).ldType()).toEqual('doc');
2169 expect(vc.root().getOperand(1).ldType()).toEqual('non');
2170 expect(vc.root().getOperand(2).ldType()).toEqual('docGroup');
2171 expect(vc.root().getOperand(3).ldType()).toEqual('non');
2172 expect(vc.root().getOperand(4).ldType()).toEqual('non');
2173 });
2174
2175 it('should wrap on root', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00002176 var vc = vcClass.create().fromJson(
Akron712733a2018-04-05 18:17:47 +02002177 {
2178 "@type": 'koral:docGroup',
2179 'operation' : 'operation:and',
2180 'operands' : [
2181 {
2182 "@type": 'koral:doc',
2183 "key": 'pubDate',
2184 "match": 'match:eq',
2185 "value": '2014-12-05',
2186 "type": 'type:date'
2187 },
2188 {
2189 "@type" : 'koral:doc',
2190 'key' : 'foo',
2191 'value' : 'bar'
2192 }
2193 ]
2194 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00002195 );
2196
2197 // Wrap on root
2198 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar"');
2199 expect(vc.root().ldType()).toEqual('docGroup');
2200 expect(vc.root().operation()).toEqual('and');
2201 _orOn(vc.root());
2202 expect(vc.root().ldType()).toEqual('docGroup');
2203 expect(vc.root().operation()).toEqual('or');
2204
2205 expect(vc.root().getOperand(0).ldType()).toEqual('docGroup');
2206 expect(vc.root().getOperand(0).operation()).toEqual('and');
2207 });
2208
2209 it('should add on root (case "and")', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00002210 var vc = vcClass.create().fromJson(
Akron712733a2018-04-05 18:17:47 +02002211 {
2212 "@type": 'koral:doc',
2213 "key": 'pubDate',
2214 "match": 'match:eq',
2215 "value": '2014-12-05',
2216 "type": 'type:date'
2217 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00002218 );
2219
2220 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05');
2221 expect(vc.root().ldType()).toEqual('doc');
2222 expect(vc.root().key()).toEqual('pubDate');
2223 expect(vc.root().value()).toEqual('2014-12-05');
2224
2225 // Wrap on root
2226 _andOn(vc.root());
2227 expect(vc.root().ldType()).toEqual('docGroup');
2228 expect(vc.root().operation()).toEqual('and');
2229 });
2230
2231 it('should add on root (case "or")', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00002232 var vc = vcClass.create().fromJson(
Akron712733a2018-04-05 18:17:47 +02002233 {
2234 "@type": 'koral:doc',
2235 "key": 'pubDate',
2236 "match": 'match:eq',
2237 "value": '2014-12-05',
2238 "type": 'type:date'
2239 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00002240 );
2241
2242 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05');
2243 expect(vc.root().key()).toEqual('pubDate');
2244 expect(vc.root().value()).toEqual('2014-12-05');
2245
2246 // Wrap on root
2247 _orOn(vc.root());
2248 expect(vc.root().ldType()).toEqual('docGroup');
2249 expect(vc.root().operation()).toEqual('or');
2250 });
2251
2252 it('should support multiple sub groups per group', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00002253 var vc = vcClass.create().fromJson(
Akron712733a2018-04-05 18:17:47 +02002254 {
2255 "@type": 'koral:docGroup',
2256 'operation' : 'operation:or',
2257 'operands' : [
2258 {
2259 "@type": 'koral:docGroup',
2260 'operation' : 'operation:and',
2261 'operands' : [
2262 {
2263 "@type": 'koral:doc',
2264 "key": 'title',
2265 "value": 't1',
2266 },
2267 {
2268 "@type" : 'koral:doc',
2269 'key' : 'title',
2270 'value' : 't2'
2271 }
2272 ]
2273 },
2274 {
2275 "@type": 'koral:docGroup',
2276 'operation' : 'operation:and',
2277 'operands' : [
2278 {
2279 "@type": 'koral:doc',
2280 "key": 'title',
2281 "value": 't3',
2282 },
2283 {
2284 "@type" : 'koral:doc',
2285 'key' : 'title',
2286 'value' : 't4'
2287 }
2288 ]
2289 }
2290 ]
2291 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00002292 );
2293 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02002294 '(title = "t1" & title = "t2") | ' +
2295 '(title = "t3" & title = "t4")'
Nils Diewald7c8ced22015-04-15 19:21:00 +00002296 );
2297 expect(vc.root().operation()).toEqual('or');
2298 expect(vc.root().getOperand(0).toQuery()).toEqual('title = "t1" & title = "t2"');
2299 expect(vc.root().getOperand(1).toQuery()).toEqual('title = "t3" & title = "t4"');
2300
2301 _andOn(vc.root());
2302
2303 expect(vc.root().operation()).toEqual('and');
2304 expect(vc.root().getOperand(0).ldType()).toEqual('docGroup');
2305 expect(vc.root().getOperand(1).ldType()).toEqual('non');
2306 });
2307 });
2308
Akron5c829e92017-05-12 18:10:00 +02002309 // Check class method
2310 describe('KorAP.VC.checkRewrite', function () {
2311
2312 it('should check for simple rewrites', function () {
2313 expect(vcClass.checkRewrite(
2314 {
2315 "@type" : "koral:doc",
2316 "rewrites" : [{
Akron712733a2018-04-05 18:17:47 +02002317 "@type" : "koral:rewrite",
2318 "operation" : "operation:modification",
2319 "src" : "querySerializer",
2320 "scope" : "tree"
Akron5c829e92017-05-12 18:10:00 +02002321 }]
2322 }
2323 )).toBeTruthy();
Nils Diewald7c8ced22015-04-15 19:21:00 +00002324
Akron5c829e92017-05-12 18:10:00 +02002325 var nested = {
2326 "@type" : "koral:docGroup",
2327 "operands" : [
2328 {
2329 "@type" : "koral:doc"
2330 },
2331 {
2332 "@type" : "koral:docGroup",
2333 "operands" : [
2334 {
2335 "@type": "koral:doc"
2336 },
2337 {
2338 "@type": "koral:doc"
2339 }
2340 ]
2341 }
2342 ]
2343 };
2344
2345 expect(vcClass.checkRewrite(nested)).toBe(false);
2346
2347 nested["operands"][1]["operands"][1]["rewrites"] = [{
Akron712733a2018-04-05 18:17:47 +02002348 "@type" : "koral:rewrite",
2349 "operation" : "operation:modification",
2350 "src" : "querySerializer",
2351 "scope" : "tree"
Akron5c829e92017-05-12 18:10:00 +02002352 }];
2353
2354 expect(vcClass.checkRewrite(nested)).toBeTruthy();
2355 });
2356 });
Nils Diewald6283d692015-04-23 20:32:53 +00002357
2358 describe('KorAP.Rewrite', function () {
Nils Diewald7c8ced22015-04-15 19:21:00 +00002359 it('should be initializable', function () {
2360 var rewrite = rewriteClass.create({
Akron712733a2018-04-05 18:17:47 +02002361 "@type" : "koral:rewrite",
2362 "operation" : "operation:modification",
2363 "src" : "querySerializer",
2364 "scope" : "tree"
Nils Diewald86dad5b2015-01-28 15:09:07 +00002365 });
Nils Diewald7c8ced22015-04-15 19:21:00 +00002366 expect(rewrite.toString()).toEqual('Modification of "tree" by "querySerializer"');
2367 });
Nils Diewald86dad5b2015-01-28 15:09:07 +00002368
Nils Diewald7c8ced22015-04-15 19:21:00 +00002369 it('should be deserialized by docs', function () {
2370 var doc = docClass.create(
Akron712733a2018-04-05 18:17:47 +02002371 undefined,
2372 {
2373 "@type":"koral:doc",
2374 "key":"Titel",
2375 "value":"Baum",
2376 "match":"match:eq"
2377 });
Nils Diewald7c8ced22015-04-15 19:21:00 +00002378
2379 expect(doc.element().classList.contains('doc')).toBeTruthy();
2380 expect(doc.element().classList.contains('rewritten')).toBe(false);
2381
2382 doc = docClass.create(
Akron712733a2018-04-05 18:17:47 +02002383 undefined,
2384 {
2385 "@type":"koral:doc",
2386 "key":"Titel",
2387 "value":"Baum",
2388 "match":"match:eq",
2389 "rewrites" : [
2390 {
2391 "@type" : "koral:rewrite",
2392 "operation" : "operation:modification",
2393 "src" : "querySerializer",
2394 "scope" : "tree"
2395 }
2396 ]
2397 });
Nils Diewald7c8ced22015-04-15 19:21:00 +00002398
2399 expect(doc.element().classList.contains('doc')).toBeTruthy();
2400 expect(doc.element().classList.contains('rewritten')).toBeTruthy();
2401 });
Nils Diewald6283d692015-04-23 20:32:53 +00002402
Akron76c3dd62018-05-29 20:58:27 +02002403 it('should be described in a title attribute', function () {
2404
2405 doc = docClass.create(
2406 undefined,
2407 {
2408 "@type":"koral:doc",
2409 "key":"Titel",
2410 "value":"Baum",
2411 "match":"match:eq",
2412 "rewrites" : [
2413 {
2414 "@type" : "koral:rewrite",
2415 "operation" : "operation:modification",
2416 "src" : "querySerializer",
2417 "scope" : "tree"
2418 },
2419 {
2420 "@type" : "koral:rewrite",
2421 "operation" : "operation:injection",
2422 "src" : "me"
2423 }
2424 ]
2425 });
2426
2427 expect(doc.element().classList.contains('doc')).toBeTruthy();
2428 expect(doc.element().classList.contains('rewritten')).toBeTruthy();
2429 expect(doc.element().lastChild.getAttribute("title")).toEqual("querySerializer: tree (modification)\nme (injection)");
2430 });
2431
2432
Nils Diewald6283d692015-04-23 20:32:53 +00002433 xit('should be deserialized by docGroups', function () {
2434 var docGroup = docGroupClass.create(
Akron712733a2018-04-05 18:17:47 +02002435 undefined,
2436 {
2437 "@type" : "koral:docGroup",
2438 "operation" : "operation:or",
2439 "operands" : [
2440 {
2441 "@type" : "doc",
2442 "key" : "pubDate",
2443 "type" : "type:date",
2444 "value" : "2014-12-05"
2445 },
2446 {
2447 "@type" : "doc",
2448 "key" : "pubDate",
2449 "type" : "type:date",
2450 "value" : "2014-12-06"
2451 }
2452 ],
2453 "rewrites" : [
2454 {
2455 "@type" : "koral:rewrite",
2456 "operation" : "operation:modification",
2457 "src" : "querySerializer",
2458 "scope" : "tree"
2459 }
2460 ]
2461 }
Nils Diewald6283d692015-04-23 20:32:53 +00002462 );
2463
2464 expect(doc.element().classList.contains('docgroup')).toBeTruthy();
2465 expect(doc.element().classList.contains('rewritten')).toBe(false);
2466 });
Nils Diewald86dad5b2015-01-28 15:09:07 +00002467 });
Nils Diewaldf0c4f112015-05-05 12:56:59 +00002468
2469 describe('KorAP.stringValue', function () {
2470 it('should be initializable', function () {
2471 var sv = stringValClass.create();
2472 expect(sv.regex()).toBe(false);
2473 expect(sv.value()).toBe('');
Nils Diewaldc4c4b832015-05-05 16:00:08 +00002474
2475 sv = stringValClass.create('Baum');
2476 expect(sv.regex()).toBe(false);
2477 expect(sv.value()).toBe('Baum');
2478
2479 sv = stringValClass.create('Baum', false);
2480 expect(sv.regex()).toBe(false);
2481 expect(sv.value()).toBe('Baum');
2482
2483 sv = stringValClass.create('Baum', true);
2484 expect(sv.regex()).toBe(true);
2485 expect(sv.value()).toBe('Baum');
2486 });
2487
2488 it('should be modifiable', function () {
2489 var sv = stringValClass.create();
2490 expect(sv.regex()).toBe(false);
2491 expect(sv.value()).toBe('');
2492
2493 expect(sv.value('Baum')).toBe('Baum');
2494 expect(sv.value()).toBe('Baum');
2495
2496 expect(sv.regex(true)).toBe(true);
2497 expect(sv.regex()).toBe(true);
2498 });
2499
2500 it('should have a toggleble regex value', function () {
2501 var sv = stringValClass.create();
Nils Diewald7991a3f2015-05-19 14:12:37 +00002502
2503 expect(sv.element().firstChild.value).toBe('');
2504 sv.element().firstChild.value = 'der'
2505 expect(sv.element().firstChild.value).toBe('der');
2506
Nils Diewaldc4c4b832015-05-05 16:00:08 +00002507 expect(sv.regex()).toBe(false);
2508
2509 sv.toggleRegex();
Nils Diewald7991a3f2015-05-19 14:12:37 +00002510 expect(sv.element().firstChild.value).toBe('der');
Nils Diewaldc4c4b832015-05-05 16:00:08 +00002511 expect(sv.regex()).toBe(true);
Nils Diewald7991a3f2015-05-19 14:12:37 +00002512 sv.element().firstChild.value = 'derbe'
Nils Diewaldc4c4b832015-05-05 16:00:08 +00002513
2514 sv.toggleRegex();
2515 expect(sv.regex()).toBe(false);
Nils Diewald7991a3f2015-05-19 14:12:37 +00002516 expect(sv.element().firstChild.value).toBe('derbe');
Nils Diewaldc4c4b832015-05-05 16:00:08 +00002517 });
2518
2519 it('should have an element', function () {
2520 var sv = stringValClass.create('der');
2521 expect(sv.element().nodeName).toBe('DIV');
2522 expect(sv.element().firstChild.nodeName).toBe('INPUT');
2523 expect(sv.element().firstChild.value).toBe('der');
2524 });
2525
2526 it('should have a classed element', function () {
2527 var sv = stringValClass.create();
Nils Diewaldc4c4b832015-05-05 16:00:08 +00002528 expect(sv.element().classList.contains('regex')).toBe(false);
2529 expect(sv.regex()).toBe(false);
2530 sv.toggleRegex();
2531 expect(sv.element().classList.contains('regex')).toBe(true);
2532 });
2533
2534 it('should be storable', function () {
2535 var sv = stringValClass.create();
2536 var count = 1;
2537 sv.store = function (value, regex) {
Akron712733a2018-04-05 18:17:47 +02002538 expect(regex).toBe(true);
2539 expect(value).toBe('tree');
Nils Diewaldc4c4b832015-05-05 16:00:08 +00002540 };
2541 sv.regex(true);
2542 sv.value('tree');
2543 sv.element().lastChild.click();
Nils Diewaldf0c4f112015-05-05 12:56:59 +00002544 });
Akron712733a2018-04-05 18:17:47 +02002545
Akronb19803c2018-08-16 16:39:42 +02002546 it('should have a disableoption for regex', function () {
2547 var sv = stringValClass.create(undefined, undefined, true);
2548 var svE = sv.element();
2549 expect(svE.children.length).toEqual(2);
2550
2551 sv = stringValClass.create(undefined, undefined, false);
2552 svE = sv.element();
2553 expect(svE.children.length).toEqual(1);
2554 });
2555
Nils Diewaldf0c4f112015-05-05 12:56:59 +00002556 });
Akrone4961b12017-05-10 21:04:46 +02002557
Akron712733a2018-04-05 18:17:47 +02002558 describe('KorAP.VC.Menu', function () {
Akrone65a88a2018-04-05 19:14:20 +02002559
2560 var vc;
2561
Akron712733a2018-04-05 18:17:47 +02002562 it('should be initializable', function () {
2563
Akrone65a88a2018-04-05 19:14:20 +02002564 vc = vcClass.create([
Akron712733a2018-04-05 18:17:47 +02002565 ['a', 'text'],
2566 ['b', 'string'],
2567 ['c', 'date']
2568 ]).fromJson();
2569 expect(vc.element().firstChild.classList.contains('unspecified')).toBeTruthy();
2570 expect(vc.element().firstChild.firstChild.tagName).toEqual('SPAN');
2571
2572 // Click on unspecified
2573 vc.element().firstChild.firstChild.click();
2574 expect(vc.element().firstChild.firstChild.tagName).toEqual('UL');
2575
2576 var list = vc.element().firstChild.firstChild;
Akron3ad46942018-08-22 16:47:14 +02002577 expect(list.getElementsByTagName("LI")[0].innerText).toEqual('referTo');
2578 expect(list.getElementsByTagName("LI")[1].innerText).toEqual('a');
2579 expect(list.getElementsByTagName("LI")[2].innerText).toEqual('b');
2580 expect(list.getElementsByTagName("LI")[3].innerText).toEqual('c');
Akron712733a2018-04-05 18:17:47 +02002581
2582 vc = vcClass.create([
2583 ['d', 'text'],
2584 ['e', 'string'],
2585 ['f', 'date']
2586 ]).fromJson();
2587 expect(vc.element().firstChild.classList.contains('unspecified')).toBeTruthy();
2588 expect(vc.element().firstChild.firstChild.tagName).toEqual('SPAN');
2589
2590 // Click on unspecified
2591 vc.element().firstChild.firstChild.click();
2592 expect(vc.element().firstChild.firstChild.tagName).toEqual('UL');
2593
2594 list = vc.element().firstChild.firstChild;
Akron3ad46942018-08-22 16:47:14 +02002595 expect(list.getElementsByTagName("LI")[0].innerText).toEqual('referTo');
2596 expect(list.getElementsByTagName("LI")[1].innerText).toEqual('d');
2597 expect(list.getElementsByTagName("LI")[2].innerText).toEqual('e');
2598 expect(list.getElementsByTagName("LI")[3].innerText).toEqual('f');
Akron31d89942018-04-06 16:44:51 +02002599 // blur
2600 document.body.click();
Akron712733a2018-04-05 18:17:47 +02002601 });
Akrone65a88a2018-04-05 19:14:20 +02002602
2603 // Reinitialize to make tests stable
2604 vc = vcClass.create([
2605 ['d', 'text'],
2606 ['e', 'string'],
2607 ['f', 'date']
2608 ]).fromJson();
2609
2610 it('should be clickable on key', function () {
Akron31d89942018-04-06 16:44:51 +02002611 // Click on unspecified
2612 vc.element().firstChild.firstChild.click();
Akrone65a88a2018-04-05 19:14:20 +02002613 // Click on "d"
Akron3ad46942018-08-22 16:47:14 +02002614 vc.element().firstChild.firstChild.getElementsByTagName("LI")[1].click();
Akrone65a88a2018-04-05 19:14:20 +02002615 expect(vc.element().firstChild.firstChild.tagName).toEqual('SPAN');
2616 expect(vc.element().firstChild.firstChild.innerText).toEqual('d');
2617 expect(vc.element().firstChild.children[1].innerText).toEqual('eq');
2618 expect(vc.element().firstChild.children[1].getAttribute('data-type')).toEqual('text');
Akron31d89942018-04-06 16:44:51 +02002619 // blur
2620 document.body.click();
Akrone65a88a2018-04-05 19:14:20 +02002621 });
2622
Akron31d89942018-04-06 16:44:51 +02002623 it('should be clickable on operation for text', function () {
2624 // Click on "d" (or unspecified)
2625 vc.element().firstChild.firstChild.click();
2626
2627 // Choose "d"
Akron3ad46942018-08-22 16:47:14 +02002628 vc.element().firstChild.firstChild.getElementsByTagName("LI")[1].click();
Akron31d89942018-04-06 16:44:51 +02002629
2630 // Click on matchop
Akrone65a88a2018-04-05 19:14:20 +02002631 vc.element().firstChild.children[1].click();
Akron31d89942018-04-06 16:44:51 +02002632
Akrone65a88a2018-04-05 19:14:20 +02002633 expect(vc.element().firstChild.children[1].tagName).toEqual('UL');
Akron31d89942018-04-06 16:44:51 +02002634
Akrone65a88a2018-04-05 19:14:20 +02002635 var ul = vc.element().firstChild.children[1];
2636 expect(ul.getElementsByTagName('li')[0].innerText).toEqual("eq");
2637 expect(ul.getElementsByTagName('li')[1].innerText).toEqual("ne");
2638 expect(ul.getElementsByTagName('li')[2].innerText).toEqual("contains");
2639 expect(ul.getElementsByTagName('li')[3].innerText).toEqual("containsnot");
2640 expect(ul.getElementsByTagName('li')[4]).toBeUndefined();
Akron31d89942018-04-06 16:44:51 +02002641
2642 // Choose "contains"
2643 ul.getElementsByTagName('li')[2].click();
2644 expect(vc.element().firstChild.children[1].tagName).toEqual("SPAN");
2645 expect(vc.element().firstChild.children[1].innerText).toEqual("contains");
2646 // blur
2647 document.body.click();
Akrone65a88a2018-04-05 19:14:20 +02002648 })
Akron31d89942018-04-06 16:44:51 +02002649
2650 it('should be clickable on operation for string', function () {
2651 // Click on "d" (or unspecified)
2652 vc.element().firstChild.firstChild.click();
2653
2654 // Choose "e"
Akron3ad46942018-08-22 16:47:14 +02002655 vc.element().firstChild.firstChild.getElementsByTagName("LI")[2].click();
2656
Akron31d89942018-04-06 16:44:51 +02002657 // As a consequence the matchoperator may no longer
2658 // be valid and needs to be re-evaluated
2659 var fc = vc.element().firstChild;
Akron3ad46942018-08-22 16:47:14 +02002660
Akron31d89942018-04-06 16:44:51 +02002661 expect(fc.firstChild.tagName).toEqual('SPAN');
2662 expect(fc.firstChild.innerText).toEqual('e');
2663 expect(fc.children[1].innerText).toEqual('eq');
2664 expect(fc.children[1].getAttribute('data-type')).toEqual('string');
2665
2666 vc.element().firstChild.children[1].click();
2667
2668 expect(vc.element().firstChild.children[1].tagName).toEqual('UL');
2669
2670 var ul = vc.element().firstChild.children[1];
2671 expect(ul.getElementsByTagName('li')[0].innerText).toEqual("eq");
2672 expect(ul.getElementsByTagName('li')[1].innerText).toEqual("ne");
2673 expect(ul.getElementsByTagName('li')[2]).toBeUndefined();
2674
2675 // Choose "ne"
2676 ul.getElementsByTagName('li')[1].click();
2677 expect(vc.element().firstChild.children[1].tagName).toEqual("SPAN");
2678 expect(vc.element().firstChild.children[1].innerText).toEqual("ne");
Akron8db5e3a2018-05-28 19:25:26 +02002679
2680 // Click on text
2681 expect(vc.element().firstChild.children[2].innerText).toEqual("⋯");
2682 vc.element().firstChild.children[2].click();
2683
2684 // Blur text element
2685 expect(vc.element().firstChild.children[2].firstChild.value).toEqual('');
2686
Akron31d89942018-04-06 16:44:51 +02002687 // blur
2688 document.body.click();
2689 });
2690
2691 it('should be clickable on operation for date', function () {
2692
2693 // Replay matchop check - so it's guaranteed that "ne" is chosen
2694 // Click on "e" (or unspecified)
2695 vc.element().firstChild.firstChild.click();
2696 // Rechoose "e"
2697 vc.element().firstChild.firstChild.getElementsByTagName("LI")[1].click();
2698 // Click on matchop
2699 vc.element().firstChild.children[1].click();
2700 // Choose "ne"
2701 vc.element().firstChild.children[1].getElementsByTagName('li')[1].click();
2702 expect(vc.element().firstChild.children[1].innerText).toEqual("ne");
2703
2704 // Click on "e"
2705 vc.element().firstChild.firstChild.click();
2706 // Choose "f"
Akron3ad46942018-08-22 16:47:14 +02002707 vc.element().firstChild.firstChild.getElementsByTagName("LI")[3].click();
Akron31d89942018-04-06 16:44:51 +02002708
2709 // The matchoperator should still be "ne" as this is valid for dates as well (now)
2710 var fc = vc.element().firstChild;
2711 expect(fc.firstChild.tagName).toEqual('SPAN');
2712 expect(fc.firstChild.innerText).toEqual('f');
2713 expect(fc.children[1].innerText).toEqual('ne');
2714 // blur
2715 document.body.click();
2716 });
Akronddc98a72018-04-06 17:33:52 +02002717
2718
2719 // Check json deserialization
2720 it('should be initializable', function () {
2721 vc = vcClass.create([
2722 ['a', 'text'],
2723 ['b', 'string'],
2724 ['c', 'date']
2725 ]).fromJson({
2726 "@type" : "koral:doc",
2727 "key":"a",
2728 "value":"Baum"
2729 });
2730
2731 expect(vc.element().firstChild.children[1].getAttribute('data-type')).toEqual('text');
2732 });
Akron712733a2018-04-05 18:17:47 +02002733 });
2734
2735
Akrone4961b12017-05-10 21:04:46 +02002736 // Check prefix
2737 describe('KorAP.VC.Prefix', function () {
2738
2739 it('should be initializable', function () {
2740 var p = prefixClass.create();
2741 expect(p.element().classList.contains('pref')).toBeTruthy();
2742 expect(p.isSet()).not.toBeTruthy();
2743 });
2744
2745
2746 it('should be clickable', function () {
2747 var vc = vcClass.create([
Akron712733a2018-04-05 18:17:47 +02002748 ['a', null],
2749 ['b', null],
2750 ['c', null]
2751 ]).fromJson();
Akrone4961b12017-05-10 21:04:46 +02002752 expect(vc.element().firstChild.classList.contains('unspecified')).toBeTruthy();
2753
2754 // This should open up the menu
2755 vc.element().firstChild.firstChild.click();
2756 expect(vc.element().firstChild.firstChild.tagName).toEqual('UL');
2757
2758 KorAP._vcKeyMenu._prefix.clear();
2759 KorAP._vcKeyMenu._prefix.add('x');
2760
2761 var prefElement = vc.element().querySelector('span.pref');
2762 expect(prefElement.innerText).toEqual('x');
2763
2764 // This should add key 'x' to VC
2765 prefElement.click();
2766
2767 expect(vc.element().firstChild.classList.contains('doc')).toBeTruthy();
2768 expect(vc.element().firstChild.firstChild.className).toEqual('key');
2769 expect(vc.element().firstChild.firstChild.innerText).toEqual('x');
2770 });
2771 });
Nils Diewald2fe12e12015-03-06 16:47:06 +00002772});