blob: 81e3f8a38a56f4cf78034e05f7b3061997e2d99e [file] [log] [blame]
Nils Diewald6ac292b2015-01-15 21:33:21 +00001/*
Nils Diewald7c8ced22015-04-15 19:21:00 +00002 * Todo: In demoSpec: Create "and" on the last element of the top "or"-Group
3 */
Akrondd5c6d32018-08-17 14:12:58 +02004define([
5 'vc',
6 'vc/doc',
7 'vc/menu',
8 'vc/prefix',
9 'vc/docgroup',
10 'vc/docgroupref',
11 'vc/unspecified',
12 'vc/operators',
13 'vc/rewrite',
14 'vc/stringval'
15], function (vcClass,
16 docClass,
17 menuClass,
18 prefixClass,
19 docGroupClass,
20 docGroupRefClass,
21 unspecifiedClass,
22 operatorsClass,
23 rewriteClass,
24 stringValClass) {
Nils Diewald6ac292b2015-01-15 21:33:21 +000025
Akrondd5c6d32018-08-17 14:12:58 +020026 KorAP._vcKeyMenu = undefined;
27
Nils Diewald6ac292b2015-01-15 21:33:21 +000028
Nils Diewald7c8ced22015-04-15 19:21:00 +000029 // Helper method for building factories
30 buildFactory = function (objClass, defaults) {
31 return {
32 create : function (overwrites) {
Akron712733a2018-04-05 18:17:47 +020033 var newObj = {};
34 for (var prop in defaults) {
35 newObj[prop] = defaults[prop];
36 };
37 for (var prop in overwrites) {
38 newObj[prop] = overwrites[prop];
39 };
40 return objClass.create().fromJson(newObj);
Nils Diewald7c8ced22015-04-15 19:21:00 +000041 }
Nils Diewald0b6c0412014-12-19 03:55:57 +000042 }
Nils Diewald7c8ced22015-04-15 19:21:00 +000043 };
Nils Diewald0b6c0412014-12-19 03:55:57 +000044
Nils Diewald7c8ced22015-04-15 19:21:00 +000045 function _andOn (obj) {
Akrond141a362018-07-10 18:12:13 +020046 KorAP._and.apply(obj);
Nils Diewald7c8ced22015-04-15 19:21:00 +000047 };
Nils Diewald52f7eb12015-01-12 17:30:04 +000048
Nils Diewald7c8ced22015-04-15 19:21:00 +000049 function _orOn (obj) {
Akrond141a362018-07-10 18:12:13 +020050 KorAP._or.apply(obj);
Nils Diewald7c8ced22015-04-15 19:21:00 +000051 };
Nils Diewald52f7eb12015-01-12 17:30:04 +000052
Nils Diewald7c8ced22015-04-15 19:21:00 +000053 function _delOn (obj) {
Akrond141a362018-07-10 18:12:13 +020054 KorAP._delete.apply(obj);
Nils Diewald7c8ced22015-04-15 19:21:00 +000055 };
Nils Diewald52f7eb12015-01-12 17:30:04 +000056
Nils Diewald7c8ced22015-04-15 19:21:00 +000057 var demoFactory = buildFactory(vcClass, {
58 "@type":"koral:docGroup",
59 "operation":"operation:or",
60 "operands":[
Nils Diewaldf219eb82015-01-07 20:15:42 +000061 {
Akron712733a2018-04-05 18:17:47 +020062 "@type":"koral:docGroup",
63 "operation":"operation:and",
64 "operands":[
Nils Diewald7c8ced22015-04-15 19:21:00 +000065 {
66 "@type":"koral:doc",
67 "key":"Titel",
68 "value":"Baum",
69 "match":"match:eq"
70 },
71 {
72 "@type":"koral:doc",
73 "key":"Veröffentlichungsort",
74 "value":"hihi",
75 "match":"match:eq"
76 },
77 {
78 "@type":"koral:docGroup",
79 "operation":"operation:or",
80 "operands":[
81 {
Akron712733a2018-04-05 18:17:47 +020082 "@type":"koral:doc",
83 "key":"Titel",
84 "value":"Baum",
85 "match":"match:eq"
Nils Diewald7c8ced22015-04-15 19:21:00 +000086 },
87 {
Akron712733a2018-04-05 18:17:47 +020088 "@type":"koral:doc",
89 "key":"Veröffentlichungsort",
90 "value":"hihi",
91 "match":"match:eq"
Nils Diewald7c8ced22015-04-15 19:21:00 +000092 }
93 ]
94 }
Akron712733a2018-04-05 18:17:47 +020095 ]
Nils Diewaldf219eb82015-01-07 20:15:42 +000096 },
97 {
Akron712733a2018-04-05 18:17:47 +020098 "@type":"koral:doc",
99 "key":"Untertitel",
100 "value":"huhu",
101 "match":"match:contains"
Nils Diewaldf219eb82015-01-07 20:15:42 +0000102 }
103 ]
104 });
105
Nils Diewald7c8ced22015-04-15 19:21:00 +0000106 describe('KorAP.Doc', function () {
107 // Create example factories
108 var stringFactory = buildFactory(docClass, {
109 "key" : "author",
110 "value" : "Max Birkendale",
Akron31d89942018-04-06 16:44:51 +0200111 "type" : "type:string",
Nils Diewald7c8ced22015-04-15 19:21:00 +0000112 "@type" : "koral:doc"
113 });
114
115 // Create example factories
Akron712733a2018-04-05 18:17:47 +0200116 var textFactory = buildFactory(docClass, {
117 "key" : "author",
118 "value" : "Birkendale",
Akron31d89942018-04-06 16:44:51 +0200119 "type" : "type:string",
Akron712733a2018-04-05 18:17:47 +0200120 "match" : "match:contains",
121 "@type" : "koral:doc"
122 });
123
124 // Create example factories
Nils Diewald7c8ced22015-04-15 19:21:00 +0000125 var dateFactory = buildFactory(docClass, {
126 "key" : "pubDate",
127 "type" : "type:date",
128 "match" : "match:eq",
129 "value" : "2014-11-05",
130 "@type" : "koral:doc"
131 });
132
133 // Create example factories
134 var regexFactory = buildFactory(docClass, {
135 "key" : "title",
136 "type" : "type:regex",
137 "value" : "[^b]ee.+?",
138 "@type" : "koral:doc"
139 });
140
141 it('should be initializable', function () {
142 var doc = docClass.create();
143 expect(doc.matchop()).toEqual('eq');
144 expect(doc.key()).toBeUndefined();
145 expect(doc.value()).toBeUndefined();
146 expect(doc.type()).toEqual("string");
147 });
148
149 it('should be definable', function () {
150
151 // Empty doc
152 var doc = docClass.create();
153
154 // Set values
155 doc.key("title");
Akron8db5e3a2018-05-28 19:25:26 +0200156
Nils Diewald7c8ced22015-04-15 19:21:00 +0000157 doc.value("Der alte Mann");
158 expect(doc.matchop()).toEqual('eq');
159 expect(doc.key()).toEqual("title");
160 expect(doc.type()).toEqual("string");
161 expect(doc.value()).toEqual("Der alte Mann");
162 });
163
164
165 it('should deserialize JSON-LD string', function () {
166 var doc;
167
168 // String default
169 doc = stringFactory.create();
170 expect(doc.matchop()).toEqual('eq');
171 expect(doc.key()).toEqual("author");
172 expect(doc.type()).toEqual("string");
173 expect(doc.value()).toEqual("Max Birkendale");
174
175 // No valid string
176 doc = stringFactory.create({
Akron712733a2018-04-05 18:17:47 +0200177 value : undefined
Nils Diewald7c8ced22015-04-15 19:21:00 +0000178 });
179 expect(doc).toBeUndefined();
180
181 // No valid string
182 doc = stringFactory.create({
Akron712733a2018-04-05 18:17:47 +0200183 value : { "foo" : "bar" }
Nils Diewald7c8ced22015-04-15 19:21:00 +0000184 });
185 expect(doc).toBeUndefined();
186
187 // Change match type
188 doc = stringFactory.create({
Akron712733a2018-04-05 18:17:47 +0200189 "match" : "match:ne"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000190 });
191
192 expect(doc.matchop()).toEqual('ne');
193 expect(doc.key()).toEqual("author");
194 expect(doc.type()).toEqual("string");
195 expect(doc.value()).toEqual("Max Birkendale");
196
197 // Invalid match type
198 doc = stringFactory.create({
Akron712733a2018-04-05 18:17:47 +0200199 "match" : { "foo" : "bar" }
Nils Diewald7c8ced22015-04-15 19:21:00 +0000200 });
201 expect(doc).toBeUndefined();
202 });
203
204 it('should deserialize JSON-LD regex', function () {
205 var doc = regexFactory.create();
206 expect(doc.key()).toEqual("title");
207 expect(doc.type()).toEqual("regex");
208 expect(doc.value()).toEqual("[^b]ee.+?");
209 expect(doc.matchop()).toEqual('eq');
210
211 // change matcher
212 doc = regexFactory.create({
Akron712733a2018-04-05 18:17:47 +0200213 match : "match:ne"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000214 });
215 expect(doc.matchop()).toEqual('ne');
Akronea4e9052017-07-06 16:12:05 +0200216 expect(doc.rewrites()).toBeUndefined();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000217
218 // Invalid matcher
219 doc = regexFactory.create({
Akron712733a2018-04-05 18:17:47 +0200220 match : "match:chook"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000221 });
Akronea4e9052017-07-06 16:12:05 +0200222 expect(doc.matchop()).toEqual('eq');
223 expect(doc.rewrites()).toBeDefined();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000224
225 // Invalid regex
226 doc = regexFactory.create({
Akron712733a2018-04-05 18:17:47 +0200227 value : "[^b"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000228 });
229 expect(doc).toBeUndefined();
230 });
231
232 it('should deserialize JSON-LD date', function () {
233
234 // Normal date
235 doc = dateFactory.create({});
236
237 expect(doc.matchop()).toEqual('eq');
238 expect(doc.key()).toEqual("pubDate");
239 expect(doc.type()).toEqual("date");
240 expect(doc.value()).toEqual("2014-11-05");
241
242 // Short date 1
243 doc = dateFactory.create({
Akron712733a2018-04-05 18:17:47 +0200244 "value" : "2014-11"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000245 });
246
247 expect(doc.matchop()).toEqual('eq');
248 expect(doc.key()).toEqual("pubDate");
249 expect(doc.type()).toEqual("date");
250 expect(doc.value()).toEqual("2014-11");
251
252 // Short date 2
253 doc = dateFactory.create({
Akron712733a2018-04-05 18:17:47 +0200254 "value" : "2014"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000255 });
256
257 expect(doc.matchop()).toEqual('eq');
258 expect(doc.key()).toEqual("pubDate");
259 expect(doc.type()).toEqual("date");
260 expect(doc.value()).toEqual("2014");
261
262 // Invalid date!
263 doc = dateFactory.create({
Akron712733a2018-04-05 18:17:47 +0200264 "value" : "2014-11-050"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000265 });
266 expect(doc).toBeUndefined();
267
268 // Invalid matcher!
269 doc = dateFactory.create({
Akron31d89942018-04-06 16:44:51 +0200270 "match" : "match:contains",
Nils Diewald7c8ced22015-04-15 19:21:00 +0000271 });
Akronea4e9052017-07-06 16:12:05 +0200272 expect(doc).toBeDefined();
273 expect(doc.rewrites()).toBeDefined();
274 expect(doc.matchop()).toEqual('eq');
Nils Diewald7c8ced22015-04-15 19:21:00 +0000275 });
276
277 it('should be serializale to JSON', function () {
278
279 // Empty doc
280 var doc = docClass.create();
281 expect(doc.toJson()).toEqual(jasmine.any(Object));
282
283 // Serialize string
284 doc = stringFactory.create();
285 expect(doc.toJson()).toEqual(jasmine.objectContaining({
Akron712733a2018-04-05 18:17:47 +0200286 "@type" : "koral:doc",
287 "type" : "type:string",
288 "key" : "author",
289 "value" : "Max Birkendale",
290 "match" : "match:eq"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000291 }));
292
293 // Serialize regex
294 doc = regexFactory.create();
295 expect(doc.toJson()).toEqual(jasmine.objectContaining({
Akron712733a2018-04-05 18:17:47 +0200296 "@type" : "koral:doc",
297 "type" : "type:regex",
298 "value" : "[^b]ee.+?",
299 "match" : "match:eq",
300 "key" : 'title'
Nils Diewald7c8ced22015-04-15 19:21:00 +0000301 }));
302
303 doc = regexFactory.create({
Akron712733a2018-04-05 18:17:47 +0200304 match: "match:ne"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000305 });
306 expect(doc.toJson()).toEqual(jasmine.objectContaining({
Akron712733a2018-04-05 18:17:47 +0200307 "@type" : "koral:doc",
308 "type" : "type:regex",
309 "value" : "[^b]ee.+?",
310 "match" : "match:ne",
311 "key" : 'title'
Nils Diewald7c8ced22015-04-15 19:21:00 +0000312 }));
313
314 doc = dateFactory.create();
315 expect(doc.toJson()).toEqual(jasmine.objectContaining({
Akron712733a2018-04-05 18:17:47 +0200316 "@type" : "koral:doc",
317 "type" : "type:date",
318 "value" : "2014-11-05",
319 "match" : "match:eq",
320 "key" : 'pubDate'
Nils Diewald7c8ced22015-04-15 19:21:00 +0000321 }));
322
323 doc = dateFactory.create({
Akron712733a2018-04-05 18:17:47 +0200324 value : "2014"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000325 });
326 expect(doc.toJson()).toEqual(jasmine.objectContaining({
Akron712733a2018-04-05 18:17:47 +0200327 "@type" : "koral:doc",
328 "type" : "type:date",
329 "value" : "2014",
330 "match" : "match:eq",
331 "key" : 'pubDate'
Nils Diewald7c8ced22015-04-15 19:21:00 +0000332 }));
333 });
334
335
336 it('should be serializale to String', function () {
337 // Empty doc
338 var doc = docClass.create();
339 expect(doc.toQuery()).toEqual("");
340
341 // Serialize string
342 doc = stringFactory.create();
343 expect(doc.toQuery()).toEqual('author = "Max Birkendale"');
344
345 // Serialize string with quotes
346 doc = stringFactory.create({ "value" : 'Max "Der Coole" Birkendate'});
347 expect(doc.toQuery()).toEqual('author = "Max \\"Der Coole\\" Birkendate"');
348
349 // Serialize regex
350 doc = regexFactory.create();
351 expect(doc.toQuery()).toEqual('title = /[^b]ee.+?/');
352
353 doc = regexFactory.create({
Akron712733a2018-04-05 18:17:47 +0200354 match: "match:ne"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000355 });
356 expect(doc.toQuery()).toEqual('title != /[^b]ee.+?/');
357
Akron8778f5d2017-06-30 21:25:55 +0200358 doc = regexFactory.create({
Akron712733a2018-04-05 18:17:47 +0200359 value: "WPD/AAA/00001"
Akron8778f5d2017-06-30 21:25:55 +0200360 });
361 expect(doc.toQuery()).toEqual('title = /WPD\\/AAA\\/00001/');
362
Nils Diewald7c8ced22015-04-15 19:21:00 +0000363 doc = dateFactory.create();
364 expect(doc.toQuery()).toEqual('pubDate in 2014-11-05');
365
366 doc = dateFactory.create({
Akron712733a2018-04-05 18:17:47 +0200367 value : "2014"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000368 });
369 expect(doc.toQuery()).toEqual('pubDate in 2014');
370 });
371 });
372
373
374 describe('KorAP.DocGroup', function () {
375 // Create example factories
376 var docFactory = buildFactory(
377 docClass,
Nils Diewaldf219eb82015-01-07 20:15:42 +0000378 {
Akron712733a2018-04-05 18:17:47 +0200379 "@type" : "koral:doc",
380 "match":"match:eq",
381 "key" : "author",
382 "value" : "Max Birkendale"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000383 }
384 );
385
386 var docGroupFactory = buildFactory(
387 docGroupClass, {
Akron712733a2018-04-05 18:17:47 +0200388 "@type" : "koral:docGroup",
389 "operation" : "operation:and",
390 "operands" : [
391 docFactory.create().toJson(),
392 docFactory.create({
393 "key" : "pubDate",
394 "type" : "type:date",
395 "value" : "2014-12-05"
396 }).toJson()
397 ]
Nils Diewald7c8ced22015-04-15 19:21:00 +0000398 });
399
400 it('should be initializable', function () {
401 // Create empty group
402 var docGroup = docGroupClass.create();
403 expect(docGroup.operation()).toEqual('and');
404
405 // Create empty group
406 docGroup = docGroupClass.create();
407 docGroup.operation('or');
408 expect(docGroup.operation()).toEqual('or');
409 });
410
411 it('should be definable', function () {
412
413 // Empty group
414 var docGroup = docGroupClass.create();
415 expect(docGroup.operation()).toEqual('and');
416
417 // Set values
418 docGroup.operation("or");
419 expect(docGroup.operation()).toEqual('or');
420
421 // Set invalid values
422 docGroup.operation("hui");
423 expect(docGroup.operation()).toEqual('or');
424 });
425
426 it('should be deserializable', function () {
427 var docGroup = docGroupFactory.create();
428 expect(docGroup.operation()).toEqual("and");
429 expect(docGroup.operands().length).toEqual(2);
430
431 var op1 = docGroup.getOperand(0);
432 expect(op1.type()).toEqual("string");
433 expect(op1.key()).toEqual("author");
434 expect(op1.value()).toEqual("Max Birkendale");
435 expect(op1.matchop()).toEqual("eq");
436
437 var op2 = docGroup.getOperand(1);
438 expect(op2.type()).toEqual("date");
439 expect(op2.key()).toEqual("pubDate");
440 expect(op2.value()).toEqual("2014-12-05");
441 expect(op2.matchop()).toEqual("eq");
442
443 // Append empty group
444 var newGroup = docGroup.append(docGroupClass.create());
445 newGroup.operation('or');
446 newGroup.append(docFactory.create());
447 newGroup.append(docFactory.create({
Akron712733a2018-04-05 18:17:47 +0200448 "type" : "type:regex",
449 "key" : "title",
450 "value" : "^e.+?$",
451 "match" : "match:ne"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000452 }));
453
454 expect(docGroup.operation()).toEqual("and");
455 expect(docGroup.operands().length).toEqual(3);
456
457 var op1 = docGroup.getOperand(0);
458 expect(op1.ldType()).toEqual("doc");
459 expect(op1.type()).toEqual("string");
460 expect(op1.key()).toEqual("author");
461 expect(op1.value()).toEqual("Max Birkendale");
462 expect(op1.matchop()).toEqual("eq");
463
464 var op2 = docGroup.getOperand(1);
465 expect(op2.ldType()).toEqual("doc");
466 expect(op2.type()).toEqual("date");
467 expect(op2.key()).toEqual("pubDate");
468 expect(op2.value()).toEqual("2014-12-05");
469 expect(op2.matchop()).toEqual("eq");
470
471 var op3 = docGroup.getOperand(2);
472 expect(op3.ldType()).toEqual("docGroup");
473 expect(op3.operation()).toEqual("or");
474
475 var op4 = op3.getOperand(0);
476 expect(op4.ldType()).toEqual("doc");
477 expect(op4.type()).toEqual("string");
478 expect(op4.key()).toEqual("author");
479 expect(op4.value()).toEqual("Max Birkendale");
480 expect(op4.matchop()).toEqual("eq");
481
482 var op5 = op3.getOperand(1);
483 expect(op5.ldType()).toEqual("doc");
484 expect(op5.type()).toEqual("regex");
485 expect(op5.key()).toEqual("title");
486 expect(op5.value()).toEqual("^e.+?$");
487 expect(op5.matchop()).toEqual("ne");
488 });
489
490 it('should be serializable to JSON', function () {
491 var docGroup = docGroupFactory.create();
492
493 expect(docGroup.toJson()).toEqual(jasmine.objectContaining({
Akron712733a2018-04-05 18:17:47 +0200494 "@type" : "koral:docGroup",
495 "operation" : "operation:and",
496 "operands" : [
497 {
498 "@type": 'koral:doc',
499 "key" : 'author',
500 "match": 'match:eq',
501 "value": 'Max Birkendale',
502 "type": 'type:string'
503 },
504 {
505 "@type": 'koral:doc',
506 "key": 'pubDate',
507 "match": 'match:eq',
508 "value": '2014-12-05',
509 "type": 'type:date'
510 }
511 ]
Nils Diewald7c8ced22015-04-15 19:21:00 +0000512 }));
513 });
Nils Diewalde15b7a22015-01-09 21:50:21 +0000514
Nils Diewald7c8ced22015-04-15 19:21:00 +0000515 it('should be serializable to String', function () {
516 var docGroup = docGroupFactory.create();
517 expect(docGroup.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +0200518 'author = "Max Birkendale" & pubDate in 2014-12-05'
Nils Diewald7c8ced22015-04-15 19:21:00 +0000519 );
Nils Diewald52f7eb12015-01-12 17:30:04 +0000520
Nils Diewald7c8ced22015-04-15 19:21:00 +0000521 docGroup = docGroupFactory.create({
Akron712733a2018-04-05 18:17:47 +0200522 "@type" : "koral:docGroup",
523 "operation" : "operation:or",
524 "operands" : [
525 {
526 "@type": 'koral:doc',
527 "key" : 'author',
528 "match": 'match:eq',
529 "value": 'Max Birkendale',
530 "type": 'type:string'
531 },
532 {
533 "@type" : "koral:docGroup",
534 "operation" : "operation:and",
535 "operands" : [
536 {
537 "@type": 'koral:doc',
538 "key": 'pubDate',
539 "match": 'match:geq',
540 "value": '2014-05-12',
541 "type": 'type:date'
542 },
543 {
544 "@type": 'koral:doc',
545 "key": 'pubDate',
546 "match": 'match:leq',
547 "value": '2014-12-05',
548 "type": 'type:date'
549 },
550 {
551 "@type": 'koral:doc',
552 "key": 'foo',
553 "match": 'match:ne',
554 "value": '[a]?bar',
555 "type": 'type:regex'
556 }
557 ]
558 }
559 ]
Nils Diewald7c8ced22015-04-15 19:21:00 +0000560 });
561 expect(docGroup.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +0200562 'author = "Max Birkendale" | ' +
563 '(pubDate since 2014-05-12 & ' +
564 'pubDate until 2014-12-05 & foo != /[a]?bar/)'
Nils Diewald7c8ced22015-04-15 19:21:00 +0000565 );
566 });
567 });
568
Akronb19803c2018-08-16 16:39:42 +0200569 describe('KorAP.DocGroupRef', function () {
570 // Create example factories
571 var docRefFactory = buildFactory(
572 docGroupRefClass,
573 {
574 "@type" : "koral:docGroupRef",
575 "ref" : "@max/myCorpus"
576 }
577 );
578
579 it('should be initializable', function () {
580 var vcRef = docGroupRefClass.create();
581 expect(vcRef.ref()).toBeUndefined();
582 });
583
584 it('should be definable', function () {
585 var vcRef = docGroupRefClass.create();
586 vcRef.ref("@peter/mycorpus");
587 expect(vcRef.ref()).toEqual("@peter/mycorpus");
588 vcRef.ref("@peter/mycorpus2");
589 expect(vcRef.ref()).toEqual("@peter/mycorpus2");
590 });
591
592 it('should deserialize JSON-LD string', function () {
593 var vcRef = docRefFactory.create();
594 expect(vcRef.ref()).toEqual("@max/myCorpus");
595 });
596
597 it('should serialize to JSON-LD', function () {
598 var vcRef = docRefFactory.create();
599 expect(vcRef.toJson()).toEqual(jasmine.objectContaining({
600 "@type" : "koral:docGroupRef",
601 "ref":"@max/myCorpus"
602 }));
603
604 vcRef.ref("@peter/myCorpus2");
605 expect(vcRef.toJson()).toEqual(jasmine.objectContaining({
606 "@type" : "koral:docGroupRef",
607 "ref":"@peter/myCorpus2"
608 }));
609 });
610
611 it('should serialize to a query', function () {
612 var vcRef = docRefFactory.create();
613 expect(vcRef.toQuery()).toEqual(
614 "referTo \"@max/myCorpus\""
615 );
616
617 vcRef.ref("@peter/myCorpus2");
618 expect(vcRef.toQuery()).toEqual(
619 "referTo \"@peter/myCorpus2\""
620 );
621 });
622 });
623
624
Nils Diewald7c8ced22015-04-15 19:21:00 +0000625 describe('KorAP.UnspecifiedDoc', function () {
626 it('should be initializable', function () {
627 var doc = unspecifiedClass.create();
628 var docElement = doc.element();
629 expect(docElement.getAttribute('class')).toEqual('doc unspecified');
630 expect(docElement.firstChild.firstChild.data).toEqual('⋯');
631 expect(docElement.lastChild.lastChild.data).toEqual('⋯');
632 expect(doc.toQuery()).toEqual('');
633
634 // Only removable
635 expect(docElement.lastChild.children.length).toEqual(0);
636 });
637
Akrond141a362018-07-10 18:12:13 +0200638 it('should be removable, when no root', function () {
Nils Diewald7c8ced22015-04-15 19:21:00 +0000639 var docGroup = docGroupClass.create();
640 docGroup.operation('or');
641 expect(docGroup.operation()).toEqual('or');
642
643 docGroup.append({
Akron712733a2018-04-05 18:17:47 +0200644 "@type": 'koral:doc',
645 "key": 'pubDate',
646 "match": 'match:eq',
647 "value": '2014-12-05',
648 "type": 'type:date'
Nils Diewald7c8ced22015-04-15 19:21:00 +0000649 });
650
651 // Add unspecified object
652 docGroup.append();
653
Akrond141a362018-07-10 18:12:13 +0200654 var parent = document.createElement('div');
655 parent.appendChild(docGroup.element());
656
Nils Diewald7c8ced22015-04-15 19:21:00 +0000657 expect(docGroup.element().getAttribute('class')).toEqual('docGroup');
658 expect(docGroup.element().children[0].getAttribute('class')).toEqual('doc');
659
660 var unspec = docGroup.element().children[1];
661 expect(unspec.getAttribute('class')).toEqual('doc unspecified');
662
Akronb19803c2018-08-16 16:39:42 +0200663 // Only unspec and delete
664 expect(unspec.children.length).toEqual(2);
665
Nils Diewald7c8ced22015-04-15 19:21:00 +0000666 // Removable
667 expect(unspec.lastChild.children.length).toEqual(1);
668 expect(unspec.lastChild.children[0].getAttribute('class')).toEqual('delete');
669 });
670
Akrond141a362018-07-10 18:12:13 +0200671
Nils Diewald7c8ced22015-04-15 19:21:00 +0000672 it('should be replaceable by a doc', function () {
673 var doc = unspecifiedClass.create();
674 expect(doc.ldType()).toEqual("non");
675 // No parent, therefor not updateable
676 expect(doc.key("baum")).toBeNull();
677
678 var docGroup = docGroupClass.create();
679 docGroup.operation('or');
680 expect(docGroup.operation()).toEqual('or');
681
682 docGroup.append({
Akron712733a2018-04-05 18:17:47 +0200683 "@type": 'koral:doc',
684 "key": 'pubDate',
685 "match": 'match:eq',
686 "value": '2014-12-05',
687 "type": 'type:date'
Nils Diewald7c8ced22015-04-15 19:21:00 +0000688 });
689
690 expect(docGroup.toQuery()).toEqual("pubDate in 2014-12-05");
691 docGroup.append();
692
693 expect(docGroup.getOperand(0).ldType()).toEqual("doc");
694 expect(docGroup.getOperand(1).ldType()).toEqual("non");
695
696 var op = docGroup.getOperand(1).element().lastChild;
Akron0b489ad2018-02-02 16:49:32 +0100697 expect(op.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +0000698 expect(op.children[0].getAttribute('class')).toEqual('delete');
699 expect(op.children.length).toEqual(1);
700
701 // Replace unspecified doc
702 expect(docGroup.getOperand(1).key("name")).not.toBeNull();
703 expect(docGroup.getOperand(1).ldType()).toEqual("doc");
704 expect(docGroup.getOperand(1).key()).toEqual("name");
Akron55a343b2018-04-06 19:57:36 +0200705 expect(docGroup.getOperand(1).value()).toBeUndefined();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000706
Akronb19803c2018-08-16 16:39:42 +0200707 expect(docGroup.getOperand(1).element().children.length).toEqual(4);
708
Nils Diewald7c8ced22015-04-15 19:21:00 +0000709 op = docGroup.getOperand(1).element().lastChild;
Akron0b489ad2018-02-02 16:49:32 +0100710 expect(op.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +0000711 expect(op.children[0].getAttribute('class')).toEqual('and');
712 expect(op.children[1].getAttribute('class')).toEqual('or');
713 expect(op.children[2].getAttribute('class')).toEqual('delete');
Akronb19803c2018-08-16 16:39:42 +0200714
Nils Diewald7c8ced22015-04-15 19:21:00 +0000715 expect(op.children.length).toEqual(3);
716
717 docGroup.getOperand(1).value("Pachelbel");
718 expect(docGroup.getOperand(1).value()).toEqual("Pachelbel");
719 expect(docGroup.getOperand(1).type()).toEqual("string");
720 expect(docGroup.getOperand(1).matchop()).toEqual("eq");
721
722 // Specified!
723 expect(docGroup.toQuery()).toEqual('pubDate in 2014-12-05 | name = "Pachelbel"');
724 });
Akronb19803c2018-08-16 16:39:42 +0200725
Nils Diewald7c8ced22015-04-15 19:21:00 +0000726 it('should be replaceable on root', function () {
Nils Diewald6283d692015-04-23 20:32:53 +0000727 var vc = vcClass.create();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000728 expect(vc.toQuery()).toEqual("");
729
730 expect(vc.root().ldType()).toEqual("non");
731
732 // No operators on root
733 op = vc.root().element().lastChild;
734 expect(op.lastChild.textContent).toEqual('⋯');
735
736 // Replace
737 expect(vc.root().key("baum")).not.toBeNull();
738 expect(vc.root().ldType()).toEqual("doc");
739
740 op = vc.root().element().lastChild;
Akron0b489ad2018-02-02 16:49:32 +0100741 expect(op.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +0000742 expect(op.children[0].getAttribute('class')).toEqual('and');
743 expect(op.children[1].getAttribute('class')).toEqual('or');
744 expect(op.children[2].getAttribute('class')).toEqual('delete');
745 expect(op.children.length).toEqual(3);
746 });
Akron55a343b2018-04-06 19:57:36 +0200747
748 it('should be clickable', function () {
749 var vc = vcClass.create([
750 ["pubDate", "date"]
751 ]);
752 expect(vc.toQuery()).toEqual("");
753 expect(vc.element().firstChild.textContent).toEqual("⋯");
754 vc.element().firstChild.firstChild.click();
755
756 // Click on pubDate
Akron3ad46942018-08-22 16:47:14 +0200757 vc.element().firstChild.getElementsByTagName("LI")[1].click();
Akron55a343b2018-04-06 19:57:36 +0200758
759 expect(vc.element().firstChild.firstChild.textContent).toEqual("pubDate");
760 expect(vc.element().firstChild.children[1].getAttribute("data-type")).toEqual("date");
761 });
Nils Diewald7c8ced22015-04-15 19:21:00 +0000762 });
763
764 describe('KorAP.Doc element', function () {
765 it('should be initializable', function () {
766 var docElement = docClass.create(undefined, {
Akron712733a2018-04-05 18:17:47 +0200767 "@type" : "koral:doc",
768 "key":"Titel",
769 "value":"Baum",
770 "match":"match:eq"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000771 });
772 expect(docElement.key()).toEqual('Titel');
773 expect(docElement.matchop()).toEqual('eq');
774 expect(docElement.value()).toEqual('Baum');
775
776 var docE = docElement.element();
777 expect(docE.children[0].firstChild.data).toEqual('Titel');
778 expect(docE.children[1].firstChild.data).toEqual('eq');
779 expect(docE.children[1].getAttribute('data-type')).toEqual('string');
780 expect(docE.children[2].firstChild.data).toEqual('Baum');
781 expect(docE.children[2].getAttribute('data-type')).toEqual('string');
782
783 expect(docElement.toJson()).toEqual(jasmine.objectContaining({
Akron712733a2018-04-05 18:17:47 +0200784 "@type" : "koral:doc",
785 "key":"Titel",
786 "value":"Baum",
787 "match":"match:eq"
Nils Diewald7c8ced22015-04-15 19:21:00 +0000788 }));
789 });
Akronb19803c2018-08-16 16:39:42 +0200790
791
792 it('should be replacable by unspecified', function () {
793 var vc = vcClass.create([
794 ["pubDate", "date"]
795 ]).fromJson({
796 "@type" : "koral:doc",
797 "key":"Titel",
798 "value":"Baum",
799 "match":"match:eq"
800 });
801 expect(vc.toQuery()).toEqual("Titel = \"Baum\"");
802
803 var vcE = vc.element();
804 expect(vcE.firstChild.children.length).toEqual(4);
805
806 // Click to delete
807 vcE.firstChild.lastChild.lastChild.click();
808
809 expect(vcE.firstChild.children.length).toEqual(1);
810
811 expect(vcE.firstChild.textContent).toEqual("⋯");
812 vcE.firstChild.firstChild.click();
813
814 // Click on pubDate
Akron3ad46942018-08-22 16:47:14 +0200815 vcE.firstChild.getElementsByTagName("LI")[1].click();
Akronb19803c2018-08-16 16:39:42 +0200816
817 expect(vcE.firstChild.firstChild.textContent).toEqual("pubDate");
818 expect(vcE.firstChild.children[1].getAttribute("data-type")).toEqual("date");
819
820 expect(vcE.firstChild.children.length).toEqual(4);
821 });
822
823
824 it('should be replaceable by a docGroupRef', function () {
Akron3ad46942018-08-22 16:47:14 +0200825 var vc = vcClass.create().fromJson({
Akronb19803c2018-08-16 16:39:42 +0200826 "@type" : "koral:doc",
827 "key":"Titel",
828 "value":"Baum",
829 "match":"match:eq"
830 });
831
832 expect(vc.toQuery()).toEqual("Titel = \"Baum\"");
833
834 var vcE = vc.element();
835 expect(vcE.firstChild.children.length).toEqual(4);
836
837 // Click to delete
838 vcE.firstChild.lastChild.lastChild.click();
839
840 expect(vcE.firstChild.children.length).toEqual(1);
841
842 expect(vcE.firstChild.textContent).toEqual("⋯");
843 vcE.firstChild.firstChild.click();
844
Akron3ad46942018-08-22 16:47:14 +0200845 // Click on referTo
Akronb19803c2018-08-16 16:39:42 +0200846 vcE.firstChild.getElementsByTagName("LI")[0].click();
847
Akron3ad46942018-08-22 16:47:14 +0200848 expect(vcE.firstChild.firstChild.textContent).toEqual("referTo");
Akronb19803c2018-08-16 16:39:42 +0200849 expect(vcE.firstChild.children[1].getAttribute("data-type")).toEqual("string");
850 expect(vcE.firstChild.children.length).toEqual(3);
851 });
Nils Diewald7c8ced22015-04-15 19:21:00 +0000852 });
853
854 describe('KorAP.DocGroup element', function () {
855 it('should be initializable', function () {
856
857 var docGroup = docGroupClass.create(undefined, {
Akron712733a2018-04-05 18:17:47 +0200858 "@type" : "koral:docGroup",
859 "operation" : "operation:and",
860 "operands" : [
861 {
862 "@type": 'koral:doc',
863 "key" : 'author',
864 "match": 'match:eq',
865 "value": 'Max Birkendale',
866 "type": 'type:string'
867 },
868 {
869 "@type": 'koral:doc',
870 "key": 'pubDate',
871 "match": 'match:eq',
872 "value": '2014-12-05',
873 "type": 'type:date'
874 }
875 ]
Nils Diewald7c8ced22015-04-15 19:21:00 +0000876 });
877
878 expect(docGroup.operation()).toEqual('and');
879 var e = docGroup.element();
880 expect(e.getAttribute('class')).toEqual('docGroup');
881 expect(e.getAttribute('data-operation')).toEqual('and');
882
883 var first = e.children[0];
884 expect(first.getAttribute('class')).toEqual('doc');
885 expect(first.children[0].getAttribute('class')).toEqual('key');
886 expect(first.children[1].getAttribute('class')).toEqual('match');
887 expect(first.children[2].getAttribute('class')).toEqual('value');
888 expect(first.children[2].getAttribute('data-type')).toEqual('string');
889 expect(first.children[0].firstChild.data).toEqual('author');
890 expect(first.children[1].firstChild.data).toEqual('eq');
891 expect(first.children[2].firstChild.data).toEqual('Max Birkendale');
892
893 var second = e.children[1];
894 expect(second.getAttribute('class')).toEqual('doc');
895 expect(second.children[0].getAttribute('class')).toEqual('key');
896 expect(second.children[1].getAttribute('class')).toEqual('match');
897 expect(second.children[2].getAttribute('class')).toEqual('value');
898 expect(second.children[2].getAttribute('data-type')).toEqual('date');
899 expect(second.children[0].firstChild.data).toEqual('pubDate');
900 expect(second.children[1].firstChild.data).toEqual('eq');
901 expect(second.children[2].firstChild.data).toEqual('2014-12-05');
902 });
903
904 it('should be deserializable with nested groups', function () {
905 var docGroup = docGroupClass.create(undefined, {
Akron712733a2018-04-05 18:17:47 +0200906 "@type" : "koral:docGroup",
907 "operation" : "operation:or",
908 "operands" : [
909 {
910 "@type": 'koral:doc',
911 "key" : 'author',
912 "match": 'match:eq',
913 "value": 'Max Birkendale',
914 "type": 'type:string'
915 },
916 {
917 "@type" : "koral:docGroup",
918 "operation" : "operation:and",
919 "operands" : [
920 {
921 "@type": 'koral:doc',
922 "key": 'pubDate',
923 "match": 'match:geq',
924 "value": '2014-05-12',
925 "type": 'type:date'
926 },
927 {
928 "@type": 'koral:doc',
929 "key": 'pubDate',
930 "match": 'match:leq',
931 "value": '2014-12-05',
932 "type": 'type:date'
933 }
934 ]
935 }
936 ]
Nils Diewald7c8ced22015-04-15 19:21:00 +0000937 });
938
939 expect(docGroup.operation()).toEqual('or');
940 var e = docGroup.element();
941 expect(e.getAttribute('class')).toEqual('docGroup');
942 expect(e.getAttribute('data-operation')).toEqual('or');
943
944 expect(e.children[0].getAttribute('class')).toEqual('doc');
945 var docop = e.children[0].lastChild;
Akron0b489ad2018-02-02 16:49:32 +0100946 expect(docop.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +0000947 expect(docop.children[0].getAttribute('class')).toEqual('and');
948 expect(docop.children[1].getAttribute('class')).toEqual('or');
949 expect(docop.children[2].getAttribute('class')).toEqual('delete');
950
951 expect(e.children[1].getAttribute('class')).toEqual('docGroup');
952 expect(e.children[1].getAttribute('data-operation')).toEqual('and');
953
954 // This and-operation can be "or"ed or "delete"d
955 var secop = e.children[1].children[2];
Akron0b489ad2018-02-02 16:49:32 +0100956 expect(secop.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +0000957 expect(secop.children[0].getAttribute('class')).toEqual('or');
958 expect(secop.children[1].getAttribute('class')).toEqual('delete');
959
960 // This or-operation can be "and"ed or "delete"d
Akron0b489ad2018-02-02 16:49:32 +0100961 expect(e.children[2].getAttribute('class')).toEqual('operators button-group');
962 expect(e.lastChild.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +0000963 expect(e.lastChild.children[0].getAttribute('class')).toEqual('and');
964 expect(e.lastChild.children[1].getAttribute('class')).toEqual('delete');
965 });
966 });
967
Akronb19803c2018-08-16 16:39:42 +0200968 describe('KorAP.DocGroupRef element', function () {
969 it('should be initializable', function () {
970 var docGroupRef = docGroupRefClass.create(undefined, {
971 "@type" : "koral:docGroupRef",
972 "ref" : "@franz/myVC1"
973 });
974 expect(docGroupRef.ref()).toEqual("@franz/myVC1");
975 var dgrE = docGroupRef.element();
976
Akron3ad46942018-08-22 16:47:14 +0200977 expect(dgrE.children[0].firstChild.data).toEqual("referTo");
Akronb19803c2018-08-16 16:39:42 +0200978 expect(dgrE.children[0].tagName).toEqual("SPAN");
979 expect(dgrE.children[0].classList.contains("key")).toBeTruthy();
980 expect(dgrE.children[0].classList.contains("fixed")).toBeTruthy();
981 expect(dgrE.children[1].firstChild.data).toEqual("@franz/myVC1");
982 expect(dgrE.children[1].tagName).toEqual("SPAN");
983 expect(dgrE.children[1].classList.contains("value")).toBeTruthy();
984 expect(dgrE.children[1].getAttribute("data-type")).toEqual("string");
985 });
986
987 it('should be modifiable on reference', function () {
988 var docGroupRef = docGroupRefClass.create(undefined, {
989 "@type" : "koral:docGroupRef",
990 "ref" : "@franz/myVC1"
991 });
992 var dgrE = docGroupRef.element();
993 expect(docGroupRef.toQuery()).toEqual("referTo \"@franz/myVC1\"");
994 dgrE.children[1].click();
995
996 var input = dgrE.children[1].firstChild;
997 expect(input.tagName).toEqual("INPUT");
998 input.value = "Versuch";
999
1000 var event = new KeyboardEvent("keypress", {
1001 "key" : "[Enter]",
1002 "keyCode" : 13
1003 });
1004
1005 input.dispatchEvent(event);
1006 expect(docGroupRef.toQuery()).toEqual("referTo \"Versuch\"");
1007 });
1008 });
1009
1010
Akrone4961b12017-05-10 21:04:46 +02001011 describe('KorAP.VirtualCorpus', function () {
Nils Diewald7c8ced22015-04-15 19:21:00 +00001012 var simpleGroupFactory = buildFactory(docGroupClass, {
1013 "@type" : "koral:docGroup",
1014 "operation" : "operation:and",
1015 "operands" : [
Akron712733a2018-04-05 18:17:47 +02001016 {
1017 "@type": 'koral:doc',
1018 "key" : 'author',
1019 "match": 'match:eq',
1020 "value": 'Max Birkendale',
1021 "type": 'type:string'
1022 },
1023 {
1024 "@type": 'koral:doc',
1025 "key": 'pubDate',
1026 "match": 'match:eq',
1027 "value": '2014-12-05',
1028 "type": 'type:date'
1029 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00001030 ]
1031 });
1032
1033 var nestedGroupFactory = buildFactory(vcClass, {
1034 "@type" : "koral:docGroup",
1035 "operation" : "operation:or",
1036 "operands" : [
Akron712733a2018-04-05 18:17:47 +02001037 {
1038 "@type": 'koral:doc',
1039 "key" : 'author',
1040 "match": 'match:eq',
1041 "value": 'Max Birkendale',
1042 "type": 'type:string'
1043 },
1044 {
1045 "@type" : "koral:docGroup",
1046 "operation" : "operation:and",
1047 "operands" : [
1048 {
1049 "@type": 'koral:doc',
1050 "key": 'pubDate',
1051 "match": 'match:geq',
1052 "value": '2014-05-12',
1053 "type": 'type:date'
1054 },
1055 {
1056 "@type": 'koral:doc',
1057 "key": 'pubDate',
1058 "match": 'match:leq',
1059 "value": '2014-12-05',
1060 "type": 'type:date'
1061 }
1062 ]
1063 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00001064 ]
1065 });
1066
1067 var flatGroupFactory = buildFactory(vcClass, {
1068 "@type" : "koral:docGroup",
1069 "operation" : "operation:and",
1070 "operands" : [
Akron712733a2018-04-05 18:17:47 +02001071 {
1072 "@type": 'koral:doc',
1073 "key": 'pubDate',
1074 "match": 'match:geq',
1075 "value": '2014-05-12',
1076 "type": 'type:date'
1077 },
1078 {
1079 "@type": 'koral:doc',
1080 "key": 'pubDate',
1081 "match": 'match:leq',
1082 "value": '2014-12-05',
1083 "type": 'type:date'
1084 },
1085 {
1086 "@type": 'koral:doc',
1087 "key": 'foo',
1088 "match": 'match:eq',
1089 "value": 'bar',
1090 "type": 'type:string'
1091 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00001092 ]
1093 });
1094
1095 it('should be initializable', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00001096 var vc = vcClass.create();
Nils Diewald7c8ced22015-04-15 19:21:00 +00001097 expect(vc.element().getAttribute('class')).toEqual('vc');
1098 expect(vc.root().element().getAttribute('class')).toEqual('doc unspecified');
1099
1100 // Not removable
1101 expect(vc.root().element().lastChild.children.length).toEqual(0);
1102 });
1103
1104 it('should be based on a doc', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00001105 var vc = vcClass.create().fromJson({
Akron712733a2018-04-05 18:17:47 +02001106 "@type" : "koral:doc",
1107 "key":"Titel",
1108 "value":"Baum",
1109 "match":"match:eq"
Nils Diewald7c8ced22015-04-15 19:21:00 +00001110 });
1111
1112 expect(vc.element().getAttribute('class')).toEqual('vc');
1113 expect(vc.root().element().getAttribute('class')).toEqual('doc');
1114 expect(vc.root().key()).toEqual('Titel');
1115 expect(vc.root().value()).toEqual('Baum');
1116 expect(vc.root().matchop()).toEqual('eq');
1117
1118 var docE = vc.root().element();
1119 expect(docE.children[0].firstChild.data).toEqual('Titel');
1120 expect(docE.children[1].firstChild.data).toEqual('eq');
1121 expect(docE.children[1].getAttribute('data-type')).toEqual('string');
1122 expect(docE.children[2].firstChild.data).toEqual('Baum');
1123 expect(docE.children[2].getAttribute('data-type')).toEqual('string');
1124 });
1125
1126 it('should be based on a docGroup', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00001127 var vc = vcClass.create().fromJson(simpleGroupFactory.create().toJson());
Nils Diewald7c8ced22015-04-15 19:21:00 +00001128
1129 expect(vc.element().getAttribute('class')).toEqual('vc');
1130 expect(vc.root().element().getAttribute('class')).toEqual('docGroup');
1131 expect(vc.root().operation()).toEqual('and');
1132
1133 var docGroup = vc.root();
1134
1135 var first = docGroup.getOperand(0);
1136 expect(first.key()).toEqual('author');
1137 expect(first.value()).toEqual('Max Birkendale');
1138 expect(first.matchop()).toEqual('eq');
1139
1140 var second = docGroup.getOperand(1);
1141 expect(second.key()).toEqual('pubDate');
1142 expect(second.value()).toEqual('2014-12-05');
1143 expect(second.matchop()).toEqual('eq');
1144 });
1145
Akronb19803c2018-08-16 16:39:42 +02001146 it('should be based on a docGroupRef', function () {
1147 var vc = vcClass.create().fromJson({
1148 "@type" : "koral:docGroupRef",
1149 "ref":"myCorpus"
1150 });
1151
Akron3ad46942018-08-22 16:47:14 +02001152 // iv class="doc groupref"><span class="key fixed">referTo</span><span data-type="string" class="value">myCorpus</span>
Akronb19803c2018-08-16 16:39:42 +02001153 var vcE = vc.element();
1154 expect(vcE.getAttribute('class')).toEqual('vc');
1155 expect(vcE.firstChild.tagName).toEqual('DIV');
1156 expect(vcE.firstChild.classList.contains('groupref')).toBeTruthy();
1157
1158 expect(vcE.firstChild.firstChild.tagName).toEqual('SPAN');
1159 expect(vcE.firstChild.firstChild.classList.contains('key')).toBeTruthy();
1160 expect(vcE.firstChild.firstChild.classList.contains('fixed')).toBeTruthy();
1161
Akron3ad46942018-08-22 16:47:14 +02001162 expect(vcE.firstChild.firstChild.textContent).toEqual("referTo");
Akronb19803c2018-08-16 16:39:42 +02001163
1164 expect(vcE.firstChild.children[1].tagName).toEqual('SPAN');
1165 expect(vcE.firstChild.children[1].classList.contains('value')).toBeTruthy();
1166 expect(vcE.firstChild.children[1].getAttribute('data-type')).toEqual('string');
1167 expect(vcE.firstChild.children[1].textContent).toEqual("myCorpus");
1168 });
Nils Diewald7c8ced22015-04-15 19:21:00 +00001169
1170 it('should be based on a nested docGroup', function () {
1171 var vc = nestedGroupFactory.create();
1172
1173 expect(vc.element().getAttribute('class')).toEqual('vc');
1174 expect(vc.element().firstChild.getAttribute('class')).toEqual('docGroup');
1175 expect(vc.element().firstChild.children[0].getAttribute('class')).toEqual('doc');
1176 var dg = vc.element().firstChild.children[1];
1177 expect(dg.getAttribute('class')).toEqual('docGroup');
1178 expect(dg.children[0].getAttribute('class')).toEqual('doc');
1179 expect(dg.children[1].getAttribute('class')).toEqual('doc');
Akron0b489ad2018-02-02 16:49:32 +01001180 expect(dg.children[2].getAttribute('class')).toEqual('operators button-group');
1181 expect(vc.element().firstChild.children[2].getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001182 });
1183
Akronb19803c2018-08-16 16:39:42 +02001184 it('should be based on a nested docGroupRef', function () {
1185 var vc = vcClass.create().fromJson({
1186 "@type" : "koral:docGroup",
1187 "operation" : "operation:and",
1188 "operands" : [{
1189 "@type" : "koral:docGroupRef",
1190 "ref":"myCorpus"
1191 },{
1192 "@type" : "koral:doc",
1193 "key":"Titel",
1194 "value":"Baum",
1195 "match":"match:eq"
1196 }]
1197 });
1198
1199 expect(vc._root.ldType()).toEqual("docGroup");
1200
1201 expect(vc.toQuery()).toEqual('referTo "myCorpus" & Titel = "Baum"');
1202 });
1203
1204
Nils Diewald7c8ced22015-04-15 19:21:00 +00001205 it('should be modifiable by deletion in flat docGroups', function () {
1206 var vc = flatGroupFactory.create();
1207 var docGroup = vc.root();
1208
1209 expect(docGroup.element().getAttribute('class')).toEqual('docGroup');
1210
1211 var doc = docGroup.getOperand(1);
1212 expect(doc.key()).toEqual("pubDate");
1213 expect(doc.value()).toEqual("2014-12-05");
1214
1215 // Remove operand 1
1216 expect(docGroup.delOperand(doc).update()).not.toBeUndefined();
1217 expect(doc._element).toEqual(undefined);
1218
1219 doc = docGroup.getOperand(1);
1220 expect(doc.key()).toEqual("foo");
1221
1222 // Remove operand 1
1223 expect(docGroup.delOperand(doc).update()).not.toBeUndefined();
1224 expect(doc._element).toEqual(undefined);
1225
1226 // Only one operand left ...
1227 expect(docGroup.getOperand(1)).toBeUndefined();
1228 // ... but there shouldn't be a group anymore at all!
1229 expect(docGroup.getOperand(0)).toBeUndefined();
1230
1231 var obj = vc.root();
1232 expect(obj.ldType()).toEqual("doc");
1233 expect(obj.key()).toEqual("pubDate");
1234 expect(obj.value()).toEqual("2014-05-12");
1235
1236 expect(obj.element().getAttribute('class')).toEqual('doc');
1237 });
1238
1239
1240 it('should be modifiable by deletion in nested docGroups (root case)', function () {
1241 var vc = nestedGroupFactory.create();
1242
1243 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001244 'author = "Max Birkendale" | (pubDate since 2014-05-12 & pubDate until 2014-12-05)'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001245 );
1246
1247 var docGroup = vc.root();
1248 expect(docGroup.ldType()).toEqual("docGroup");
1249 expect(docGroup.operation()).toEqual("or");
1250
1251 var doc = docGroup.getOperand(0);
1252 expect(doc.key()).toEqual("author");
1253 expect(doc.value()).toEqual("Max Birkendale");
1254
1255 docGroup = docGroup.getOperand(1);
1256 expect(docGroup.operation()).toEqual("and");
1257
1258 doc = docGroup.getOperand(0);
1259 expect(doc.key()).toEqual("pubDate");
1260 expect(doc.matchop()).toEqual("geq");
1261 expect(doc.value()).toEqual("2014-05-12");
1262 expect(doc.type()).toEqual("date");
1263
1264 doc = docGroup.getOperand(1);
1265 expect(doc.key()).toEqual("pubDate");
1266 expect(doc.matchop()).toEqual("leq");
1267 expect(doc.value()).toEqual("2014-12-05");
1268 expect(doc.type()).toEqual("date");
1269
1270 // Remove first operand so everything becomes root
1271 expect(
Akron712733a2018-04-05 18:17:47 +02001272 vc.root().delOperand(
1273 vc.root().getOperand(0)
1274 ).update().ldType()
Nils Diewald7c8ced22015-04-15 19:21:00 +00001275 ).toEqual("docGroup");
1276
1277 expect(vc.root().ldType()).toEqual("docGroup");
1278 expect(vc.root().operation()).toEqual("and");
1279 expect(vc.root().getOperand(0).ldType()).toEqual("doc");
1280
1281 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001282 'pubDate since 2014-05-12 & pubDate until 2014-12-05'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001283 );
1284 });
1285
1286 it('should be modifiable by deletion in nested docGroups (resolve group case)', function () {
1287 var vc = nestedGroupFactory.create();
1288
1289 // Get nested group
1290 var firstGroup = vc.root().getOperand(1);
1291 firstGroup.append(simpleGroupFactory.create({ "operation" : "operation:or" }));
1292
1293 // Structur is now:
1294 // or(doc, and(doc, doc, or(doc, doc)))
1295
1296 // Get nested or in and
1297 var orGroup = vc.root().getOperand(1).getOperand(2);
1298 expect(orGroup.ldType()).toEqual("docGroup");
1299 expect(orGroup.operation()).toEqual("or");
1300
1301 // Remove
1302 // Structur is now:
1303 // or(doc, and(doc, doc, doc)))
1304 expect(orGroup.delOperand(orGroup.getOperand(0)).update().operation()).toEqual("and");
1305 expect(vc.root().getOperand(1).operands().length).toEqual(3);
1306 });
1307
1308 it('should be modifiable by deletion in nested docGroups (identical group case)', function () {
1309 var vc = nestedGroupFactory.create();
1310
1311 // Get nested group
1312 var firstGroup = vc.root().getOperand(1);
1313 firstGroup.append(simpleGroupFactory.create({
Akron712733a2018-04-05 18:17:47 +02001314 "operation" : "operation:or"
Nils Diewald7c8ced22015-04-15 19:21:00 +00001315 }));
1316 var oldAuthor = firstGroup.getOperand(2).getOperand(0);
1317 oldAuthor.key("title");
1318 oldAuthor.value("Der Birnbaum");
1319
1320 // Structur is now:
1321 // or(doc, and(doc, doc, or(doc, doc)))
1322 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001323 'author = "Max Birkendale" | ' +
1324 '(pubDate since 2014-05-12 & ' +
1325 'pubDate until 2014-12-05 & ' +
1326 '(title = "Der Birnbaum" | ' +
1327 'pubDate in 2014-12-05))'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001328 );
1329
1330 var andGroup = vc.root().getOperand(1);
1331
1332 // Get leading docs in and
1333 var doc1 = andGroup.getOperand(0);
1334 expect(doc1.ldType()).toEqual("doc");
1335 expect(doc1.value()).toEqual("2014-05-12");
1336 var doc2 = andGroup.getOperand(1);
1337 expect(doc2.ldType()).toEqual("doc");
1338 expect(doc2.value()).toEqual("2014-12-05");
1339
1340 // Remove 2
1341 expect(
Akron712733a2018-04-05 18:17:47 +02001342 andGroup.delOperand(doc2).update().operation()
Nils Diewald7c8ced22015-04-15 19:21:00 +00001343 ).toEqual("and");
1344 // Structur is now:
1345 // or(doc, and(doc, or(doc, doc)))
1346
1347 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001348 'author = "Max Birkendale"' +
1349 ' | (pubDate since 2014-05-12 & ' +
1350 '(title = "Der Birnbaum" | pubDate in 2014-12-05))'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001351 );
1352
1353
1354 // Remove 1
1355 expect(andGroup.delOperand(doc1).update().operation()).toEqual("or");
1356 // Structur is now:
1357 // or(doc, doc, doc)
1358
1359 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001360 'author = "Max Birkendale" | title = "Der Birnbaum" | pubDate in 2014-12-05'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001361 );
1362 });
1363
1364 it('should be reducible to unspecification', function () {
1365 var vc = demoFactory.create();
1366
1367 expect(vc.toQuery()).toEqual(vc.root().toQuery());
1368 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001369 '(Titel = "Baum" & Veröffentlichungsort = "hihi" & ' +
1370 '(Titel = "Baum" | Veröffentlichungsort = "hihi")) ' +
1371 '| Untertitel ~ "huhu"');
Akrond141a362018-07-10 18:12:13 +02001372 expect(vc.root().element().lastChild.children[0].innerText).toEqual('and');
1373 expect(vc.root().element().lastChild.children[1].innerText).toEqual('×');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001374 expect(vc.root().delOperand(vc.root().getOperand(0)).update()).not.toBeUndefined();
Akron712733a2018-04-05 18:17:47 +02001375 expect(vc.toQuery()).toEqual('Untertitel ~ "huhu"');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001376
1377 var lc = vc.root().element().lastChild;
Akrond141a362018-07-10 18:12:13 +02001378 expect(lc.children[0].innerText).toEqual('and');
1379 expect(lc.children[1].innerText).toEqual('or');
1380 expect(lc.children[2].innerText).toEqual('×');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001381
1382 // Clean everything
1383 vc.clean();
1384 expect(vc.toQuery()).toEqual('');
1385 });
1386
1387 it('should flatten on import', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00001388 var vc = vcClass.create().fromJson({
Akron712733a2018-04-05 18:17:47 +02001389 "@type":"koral:docGroup",
1390 "operation":"operation:or",
1391 "operands":[
1392 {
1393 "@type":"koral:docGroup",
1394 "operation":"operation:or",
1395 "operands":[
Nils Diewald7c8ced22015-04-15 19:21:00 +00001396 {
Akron712733a2018-04-05 18:17:47 +02001397 "@type":"koral:doc",
1398 "key":"Titel",
1399 "value":"Baum",
1400 "match":"match:eq"
Nils Diewald7c8ced22015-04-15 19:21:00 +00001401 },
1402 {
Akron712733a2018-04-05 18:17:47 +02001403 "@type":"koral:doc",
1404 "key":"Veröffentlichungsort",
1405 "value":"hihi",
1406 "match":"match:eq"
Nils Diewald7c8ced22015-04-15 19:21:00 +00001407 },
1408 {
Akron712733a2018-04-05 18:17:47 +02001409 "@type":"koral:docGroup",
1410 "operation":"operation:or",
1411 "operands":[
1412 {
1413 "@type":"koral:doc",
1414 "key":"Titel",
1415 "value":"Baum",
1416 "match":"match:eq"
1417 },
1418 {
1419 "@type":"koral:doc",
1420 "key":"Veröffentlichungsort",
1421 "value":"hihi",
1422 "match":"match:eq"
1423 }
1424 ]
Nils Diewald7c8ced22015-04-15 19:21:00 +00001425 }
Akron712733a2018-04-05 18:17:47 +02001426 ]
1427 },
1428 {
1429 "@type":"koral:doc",
1430 "key":"Untertitel",
1431 "value":"huhu",
1432 "match":"match:contains"
1433 }
1434 ]
Nils Diewald7c8ced22015-04-15 19:21:00 +00001435 });
Nils Diewaldfda29d92015-01-22 17:28:01 +00001436
Nils Diewald7c8ced22015-04-15 19:21:00 +00001437 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001438 'Titel = "Baum" | Veröffentlichungsort = "hihi" | Untertitel ~ "huhu"'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001439 );
Nils Diewald86dad5b2015-01-28 15:09:07 +00001440 });
Akron1bdf5272018-07-24 18:51:30 +02001441
1442 it('should be deserializable from collection 1', function () {
1443 var kq = {
1444 "matches":["..."],
1445 "collection":{
1446 "@type": "koral:docGroup",
1447 "operation": "operation:or",
1448 "operands": [{
1449 "@type": "koral:docGroup",
1450 "operation": "operation:and",
1451 "operands": [
1452 {
1453 "@type": "koral:doc",
1454 "key": "title",
1455 "match": "match:eq",
1456 "value": "Der Birnbaum",
1457 "type": "type:string"
1458 },
1459 {
1460 "@type": "koral:doc",
1461 "key": "pubPlace",
1462 "match": "match:eq",
1463 "value": "Mannheim",
1464 "type": "type:string"
1465 },
1466 {
1467 "@type": "koral:docGroup",
1468 "operation": "operation:or",
1469 "operands": [
1470 {
1471 "@type": "koral:doc",
1472 "key": "subTitle",
1473 "match": "match:eq",
1474 "value": "Aufzucht und Pflege",
1475 "type": "type:string"
1476 },
1477 {
1478 "@type": "koral:doc",
1479 "key": "subTitle",
1480 "match": "match:eq",
1481 "value": "Gedichte",
1482 "type": "type:string"
1483 }
1484 ]
1485 }
1486 ]
1487 },{
1488 "@type": "koral:doc",
1489 "key": "pubDate",
1490 "match": "match:geq",
1491 "value": "2015-03-05",
1492 "type": "type:date",
1493 "rewrites" : [{
1494 "@type" : "koral:rewrite",
1495 "operation" : "operation:modification",
1496 "src" : "querySerializer",
1497 "scope" : "tree"
1498 }]
1499 }]
1500 }
1501 };
1502
1503 var vc = vcClass.create().fromJson(kq["collection"]);
1504 expect(vc.toQuery()).toEqual('(title = "Der Birnbaum" & pubPlace = "Mannheim" & (subTitle = "Aufzucht und Pflege" | subTitle = "Gedichte")) | pubDate since 2015-03-05');
1505 });
1506
1507 it('should be deserializable from collection 2', function () {
1508 var kq = {
1509 "@context": "http://korap.ids-mannheim.de/ns/KoralQuery/v0.3/context.jsonld",
1510 "meta": {},
1511 "query": {
1512 "@type": "koral:token",
1513 "wrap": {
1514 "@type": "koral:term",
1515 "match": "match:eq",
1516 "layer": "orth",
1517 "key": "Baum",
1518 "foundry": "opennlp",
1519 "rewrites": [
1520 {
1521 "@type": "koral:rewrite",
1522 "src": "Kustvakt",
1523 "operation": "operation:injection",
1524 "scope": "foundry"
1525 }
1526 ]
1527 },
1528 "idn": "Baum_2227",
1529 "rewrites": [
1530 {
1531 "@type": "koral:rewrite",
1532 "src": "Kustvakt",
1533 "operation": "operation:injection",
1534 "scope": "idn"
1535 }
1536 ]
1537 },
1538 "collection": {
1539 "@type": "koral:docGroup",
1540 "operation": "operation:and",
1541 "operands": [
1542 {
1543 "@type": "koral:doc",
1544 "match": "match:eq",
1545 "type": "type:regex",
1546 "value": "CC-BY.*",
1547 "key": "availability"
1548 },
1549 {
1550 "@type": "koral:doc",
1551 "match": "match:eq",
1552 "type":"type:text",
1553 "value": "Goethe",
1554 "key": "author"
1555 }
1556 ],
1557 "rewrites": [
1558 {
1559 "@type": "koral:rewrite",
1560 "src": "Kustvakt",
1561 "operation": "operation:insertion",
1562 "scope": "availability(FREE)"
1563 }
1564 ]
1565 },
1566 "matches": []
1567 };
1568
1569 var vc = vcClass.create().fromJson(kq["collection"]);
1570 expect(vc.toQuery()).toEqual('availability = /CC-BY.*/ & author = "Goethe"');
1571 });
Nils Diewald86dad5b2015-01-28 15:09:07 +00001572
Akron8a670162018-08-28 10:09:13 +02001573 it('shouldn\'t be deserializable from collection with unknown type', function () {
1574 var kq = {
1575 "@type" : "koral:doc",
1576 "match": "match:eq",
1577 "type":"type:failure",
1578 "value": "Goethe",
1579 "key": "author"
1580 };
Akron1bdf5272018-07-24 18:51:30 +02001581
Akron8a670162018-08-28 10:09:13 +02001582 expect(function () {
1583 vcClass.create().fromJson(kq)
1584 }).toThrow(new Error("Unknown value type: string"));
1585 });
1586
1587 it('should return a name', function () {
1588 var vc = vcClass.create();
1589 expect(vc.getName()).toEqual(KorAP.Locale.VC_allCorpora);
1590
1591 vc = vcClass.create().fromJson({"@type" : "koral:docGroupRef", "ref" : "DeReKo"});
1592 expect(vc.getName()).toEqual("DeReKo");
1593
1594 vc = vcClass.create().fromJson({"@type" : "koral:doc", "key" : "author", "value" : "Peter"});
1595 expect(vc.getName()).toEqual(KorAP.Locale.VC_oneCollection);
1596 });
Akron1bdf5272018-07-24 18:51:30 +02001597 });
1598
1599
Nils Diewald7c8ced22015-04-15 19:21:00 +00001600 describe('KorAP.Operators', function () {
1601 it('should be initializable', function () {
1602 var op = operatorsClass.create(true, false, false);
1603 expect(op.and()).toBeTruthy();
1604 expect(op.or()).not.toBeTruthy();
1605 expect(op.del()).not.toBeTruthy();
1606
1607 op.and(false);
1608 expect(op.and()).not.toBeTruthy();
1609 expect(op.or()).not.toBeTruthy();
1610 expect(op.del()).not.toBeTruthy();
1611
1612 op.or(true);
1613 op.del(true);
1614 expect(op.and()).not.toBeTruthy();
1615 expect(op.or()).toBeTruthy();
1616 expect(op.del()).toBeTruthy();
1617
Akrond141a362018-07-10 18:12:13 +02001618 var e = op.update();
Akron0b489ad2018-02-02 16:49:32 +01001619 expect(e.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001620 expect(e.children[0].getAttribute('class')).toEqual('or');
Akrond141a362018-07-10 18:12:13 +02001621 expect(e.children[0].innerText).toEqual('or');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001622 expect(e.children[1].getAttribute('class')).toEqual('delete');
Akrond141a362018-07-10 18:12:13 +02001623 expect(e.children[1].innerText).toEqual('×');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001624
1625 op.and(true);
1626 op.del(false);
Akrond141a362018-07-10 18:12:13 +02001627 e = op.update();
Nils Diewald7c8ced22015-04-15 19:21:00 +00001628
Akron0b489ad2018-02-02 16:49:32 +01001629 expect(e.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001630 expect(e.children[0].getAttribute('class')).toEqual('and');
Akrond141a362018-07-10 18:12:13 +02001631 expect(e.children[0].innerText).toEqual('and');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001632 expect(e.children[1].getAttribute('class')).toEqual('or');
Akrond141a362018-07-10 18:12:13 +02001633 expect(e.children[1].innerText).toEqual('or');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001634 });
1635 });
1636
1637 describe('KorAP._delete (event)', function () {
1638 var complexVCFactory = buildFactory(vcClass,{
1639 "@type": 'koral:docGroup',
1640 'operation' : 'operation:and',
1641 'operands' : [
Akron712733a2018-04-05 18:17:47 +02001642 {
1643 "@type": 'koral:doc',
1644 "key": 'pubDate',
1645 "match": 'match:eq',
1646 "value": '2014-12-05',
1647 "type": 'type:date'
1648 },
1649 {
1650 "@type" : 'koral:docGroup',
1651 'operation' : 'operation:or',
1652 'operands' : [
1653 {
1654 '@type' : 'koral:doc',
1655 'key' : 'title',
1656 'value' : 'Hello World!'
1657 },
1658 {
1659 '@type' : 'koral:doc',
1660 'key' : 'foo',
1661 'value' : 'bar'
1662 }
1663 ]
1664 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00001665 ]
1666 });
1667
1668 it('should clean on root docs', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00001669 var vc = vcClass.create().fromJson({
Akron712733a2018-04-05 18:17:47 +02001670 "@type": 'koral:doc',
1671 "key": 'pubDate',
1672 "match": 'match:eq',
1673 "value": '2014-12-05',
1674 "type": 'type:date'
Nils Diewald86dad5b2015-01-28 15:09:07 +00001675 });
Nils Diewald7c8ced22015-04-15 19:21:00 +00001676 expect(vc.root().toQuery()).toEqual('pubDate in 2014-12-05');
Akron0b489ad2018-02-02 16:49:32 +01001677 expect(vc.root().element().lastChild.getAttribute('class')).toEqual('operators button-group');
Nils Diewald86dad5b2015-01-28 15:09:07 +00001678
Nils Diewald7c8ced22015-04-15 19:21:00 +00001679 // Clean with delete from root
1680 expect(vc.root().element().lastChild.lastChild.getAttribute('class')).toEqual('delete');
1681 _delOn(vc.root());
1682 expect(vc.root().toQuery()).toEqual('');
1683 expect(vc.root().element().lastChild.lastChild.data).toEqual('⋯');
1684 });
Nils Diewald86dad5b2015-01-28 15:09:07 +00001685
Nils Diewald7c8ced22015-04-15 19:21:00 +00001686 it('should remove on nested docs', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00001687 var vc = vcClass.create().fromJson(
Akron712733a2018-04-05 18:17:47 +02001688 {
1689 "@type": 'koral:docGroup',
1690 'operation' : 'operation:and',
1691 'operands' : [
1692 {
1693 "@type": 'koral:doc',
1694 "key": 'pubDate',
1695 "match": 'match:eq',
1696 "value": '2014-12-05',
1697 "type": 'type:date'
1698 },
1699 {
1700 "@type" : 'koral:doc',
1701 'key' : 'foo',
1702 'value' : 'bar'
1703 }
1704 ]
1705 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00001706 );
1707
1708 // Delete with direct element access
1709 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar"');
1710 _delOn(vc.root().getOperand(0));
1711
1712 expect(vc.toQuery()).toEqual('foo = "bar"');
1713 expect(vc.root().ldType()).toEqual('doc');
1714 });
1715
1716 it('should clean on doc groups', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00001717 var vc = vcClass.create().fromJson(
Akron712733a2018-04-05 18:17:47 +02001718 {
1719 "@type": 'koral:docGroup',
1720 'operation' : 'operation:and',
1721 'operands' : [
1722 {
1723 "@type": 'koral:doc',
1724 "key": 'pubDate',
1725 "match": 'match:eq',
1726 "value": '2014-12-05',
1727 "type": 'type:date'
1728 },
1729 {
1730 "@type" : 'koral:doc',
1731 'key' : 'foo',
1732 'value' : 'bar'
1733 }
1734 ]
1735 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00001736 );
1737
1738 // Cleanwith direct element access
1739 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar"');
1740 _delOn(vc.root());
1741 expect(vc.toQuery()).toEqual('');
1742 expect(vc.root().ldType()).toEqual('non');
1743 });
1744
1745 it('should remove on nested doc groups (case of ungrouping 1)', function () {
1746 var vc = complexVCFactory.create();
1747
1748 // Delete with direct element access
1749 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001750 'pubDate in 2014-12-05 & (title = "Hello World!" | foo = "bar")'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001751 );
1752
1753 // Remove hello world:
1754 _delOn(vc.root().getOperand(1).getOperand(0));
1755 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar"');
1756 expect(vc.root().ldType()).toEqual('docGroup');
1757 });
1758
1759 it('should remove on nested doc groups (case of ungrouping 2)', function () {
1760 var vc = complexVCFactory.create();
1761
1762 // Delete with direct element access
1763 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001764 'pubDate in 2014-12-05 & (title = "Hello World!" | foo = "bar")'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001765 );
1766
1767 // Remove bar
1768 _delOn(vc.root().getOperand(1).getOperand(1));
1769 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & title = "Hello World!"');
1770 expect(vc.root().ldType()).toEqual('docGroup');
1771 expect(vc.root().operation()).toEqual('and');
1772 });
1773
1774 it('should remove on nested doc groups (case of root changing)', function () {
1775 var vc = complexVCFactory.create();
1776
1777 // Delete with direct element access
1778 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001779 'pubDate in 2014-12-05 & ' +
1780 '(title = "Hello World!" | foo = "bar")'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001781 );
1782
1783 // Remove bar
1784 _delOn(vc.root().getOperand(0));
1785 expect(vc.toQuery()).toEqual('title = "Hello World!" | foo = "bar"');
1786 expect(vc.root().ldType()).toEqual('docGroup');
1787 expect(vc.root().operation()).toEqual('or');
1788 });
1789
1790 it('should remove on nested doc groups (list flattening)', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00001791 var vc = vcClass.create().fromJson(
Akron712733a2018-04-05 18:17:47 +02001792 {
1793 "@type": 'koral:docGroup',
1794 'operation' : 'operation:or',
1795 'operands' : [
1796 {
1797 "@type": 'koral:doc',
1798 "key": 'pubDate',
1799 "match": 'match:eq',
1800 "value": '2014-12-05',
1801 "type": 'type:date'
1802 },
1803 {
1804 "@type" : 'koral:doc',
1805 'key' : 'foo',
1806 'value' : 'bar'
1807 },
1808 {
1809 "@type": 'koral:docGroup',
1810 'operation' : 'operation:and',
1811 'operands' : [
1812 {
1813 "@type": 'koral:doc',
1814 "key": 'pubDate',
1815 "match": 'match:eq',
1816 "value": '2014-12-05',
1817 "type": 'type:date'
1818 },
1819 {
1820 "@type" : 'koral:docGroup',
1821 'operation' : 'operation:or',
1822 'operands' : [
1823 {
1824 '@type' : 'koral:doc',
1825 'key' : 'title',
1826 'value' : 'Hello World!'
1827 },
1828 {
1829 '@type' : 'koral:doc',
1830 'key' : 'yeah',
1831 'value' : 'juhu'
1832 }
1833 ]
1834 }
1835 ]
1836 }
1837 ]
1838 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00001839 );
1840
1841 // Delete with direct element access
1842 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001843 'pubDate in 2014-12-05 | foo = "bar" | ' +
1844 '(pubDate in 2014-12-05 & ' +
1845 '(title = "Hello World!" | yeah = "juhu"))'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001846 );
1847
1848 expect(vc.root().ldType()).toEqual('docGroup');
1849 expect(vc.root().operation()).toEqual('or');
1850
1851 // Operands and operators
1852 expect(vc.element().firstChild.children.length).toEqual(4);
Akron0b489ad2018-02-02 16:49:32 +01001853 expect(vc.element().firstChild.lastChild.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001854
1855 // Remove inner group and flatten
1856 _delOn(vc.root().getOperand(2).getOperand(0));
1857
1858 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02001859 'pubDate in 2014-12-05 | foo = "bar" | title = "Hello World!" | yeah = "juhu"'
Nils Diewald7c8ced22015-04-15 19:21:00 +00001860 );
1861 expect(vc.root().ldType()).toEqual('docGroup');
1862 expect(vc.root().operation()).toEqual('or');
1863
1864 // Operands and operators
1865 expect(vc.element().firstChild.children.length).toEqual(5);
Akron0b489ad2018-02-02 16:49:32 +01001866 expect(vc.element().firstChild.lastChild.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001867 });
1868 });
1869
1870 describe('KorAP._add (event)', function () {
1871 var complexVCFactory = buildFactory(vcClass,{
1872 "@type": 'koral:docGroup',
1873 'operation' : 'operation:and',
1874 'operands' : [
Akron712733a2018-04-05 18:17:47 +02001875 {
1876 "@type": 'koral:doc',
1877 "key": 'pubDate',
1878 "match": 'match:eq',
1879 "value": '2014-12-05',
1880 "type": 'type:date'
1881 },
1882 {
1883 "@type" : 'koral:docGroup',
1884 'operation' : 'operation:or',
1885 'operands' : [
1886 {
1887 '@type' : 'koral:doc',
1888 'key' : 'title',
1889 'value' : 'Hello World!'
1890 },
1891 {
1892 '@type' : 'koral:doc',
1893 'key' : 'foo',
1894 'value' : 'bar'
1895 }
1896 ]
1897 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00001898 ]
1899 });
1900
1901 it('should add new unspecified doc with "and"', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00001902 var vc = vcClass.create().fromJson(
Akron712733a2018-04-05 18:17:47 +02001903 {
1904 "@type": 'koral:docGroup',
1905 'operation' : 'operation:and',
1906 'operands' : [
1907 {
1908 "@type": 'koral:doc',
1909 "key": 'pubDate',
1910 "match": 'match:eq',
1911 "value": '2014-12-05',
1912 "type": 'type:date'
1913 },
1914 {
1915 "@type" : 'koral:doc',
1916 'key' : 'foo',
1917 'value' : 'bar'
Akronb19803c2018-08-16 16:39:42 +02001918 },
1919 {
1920 "@type" : "koral:docGroupRef",
1921 "ref" : "myCorpus"
Akron712733a2018-04-05 18:17:47 +02001922 }
1923 ]
1924 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00001925 );
1926
Akronb19803c2018-08-16 16:39:42 +02001927 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar" & referTo "myCorpus"');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001928
1929 var fc = vc.element().firstChild;
1930 expect(fc.getAttribute('data-operation')).toEqual('and');
Akronb19803c2018-08-16 16:39:42 +02001931 expect(fc.children.length).toEqual(4);
Akron0b489ad2018-02-02 16:49:32 +01001932 expect(fc.lastChild.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001933 expect(fc.children[0].getAttribute('class')).toEqual('doc');
1934 expect(fc.children[1].getAttribute('class')).toEqual('doc');
Akronb19803c2018-08-16 16:39:42 +02001935 expect(fc.children[2].getAttribute('class')).toEqual('doc groupref');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001936
1937 // add with 'and' in the middle
1938 _andOn(vc.root().getOperand(0));
Akronb19803c2018-08-16 16:39:42 +02001939 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar" & referTo "myCorpus"');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001940
1941 fc = vc.element().firstChild;
1942 expect(fc.getAttribute('data-operation')).toEqual('and');
Akronb19803c2018-08-16 16:39:42 +02001943 expect(fc.children.length).toEqual(5);
Akron0b489ad2018-02-02 16:49:32 +01001944 expect(fc.lastChild.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001945
1946 expect(fc.children[0].getAttribute('class')).toEqual('doc');
1947 expect(fc.children[1].getAttribute('class')).toEqual('doc unspecified');
1948 expect(fc.children[2].getAttribute('class')).toEqual('doc');
Akronb19803c2018-08-16 16:39:42 +02001949 expect(fc.children[3].getAttribute('class')).toEqual('doc groupref');
1950 expect(fc.children[4].classList.contains('button-group')).toBeTruthy();
1951 expect(fc.children.length).toEqual(5);
1952
1953 _andOn(vc.root().getOperand(3));
1954 expect(fc.children[0].getAttribute('class')).toEqual('doc');
1955 expect(fc.children[1].getAttribute('class')).toEqual('doc unspecified');
1956 expect(fc.children[2].getAttribute('class')).toEqual('doc');
1957 expect(fc.children[3].getAttribute('class')).toEqual('doc groupref');
1958 expect(fc.children[4].getAttribute('class')).toEqual('doc unspecified');
1959 expect(fc.children[5].classList.contains('button-group')).toBeTruthy();
1960 expect(fc.children.length).toEqual(6);
1961
Nils Diewald7c8ced22015-04-15 19:21:00 +00001962 });
1963
Akronb19803c2018-08-16 16:39:42 +02001964
Nils Diewald7c8ced22015-04-15 19:21:00 +00001965 it('should add new unspecified doc with "or"', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00001966 var vc = vcClass.create().fromJson(
Akron712733a2018-04-05 18:17:47 +02001967 {
1968 "@type": 'koral:docGroup',
1969 'operation' : 'operation:and',
1970 'operands' : [
1971 {
1972 "@type": 'koral:doc',
1973 "key": 'pubDate',
1974 "match": 'match:eq',
1975 "value": '2014-12-05',
1976 "type": 'type:date'
1977 },
1978 {
1979 "@type" : 'koral:doc',
1980 'key' : 'foo',
1981 'value' : 'bar'
Akronb19803c2018-08-16 16:39:42 +02001982 },
1983 {
1984 "@type" : "koral:docGroupRef",
1985 "ref" : "myCorpus"
Akron712733a2018-04-05 18:17:47 +02001986 }
1987 ]
1988 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00001989 );
1990
Akronb19803c2018-08-16 16:39:42 +02001991 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar" & referTo "myCorpus"');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001992
1993 var fc = vc.element().firstChild;
Akronb19803c2018-08-16 16:39:42 +02001994 expect(fc.children.length).toEqual(4);
Akron0b489ad2018-02-02 16:49:32 +01001995 expect(fc.lastChild.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001996 expect(fc.children[0].getAttribute('class')).toEqual('doc');
1997 expect(fc.children[1].getAttribute('class')).toEqual('doc');
Akronb19803c2018-08-16 16:39:42 +02001998 expect(fc.children[2].getAttribute('class')).toEqual('doc groupref');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001999
2000 // add with 'or' in the middle
2001 _orOn(vc.root().getOperand(0));
Akronb19803c2018-08-16 16:39:42 +02002002 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar" & referTo "myCorpus"');
Nils Diewald7c8ced22015-04-15 19:21:00 +00002003 fc = vc.element().firstChild;
2004
2005 expect(fc.getAttribute('data-operation')).toEqual('and');
Akronb19803c2018-08-16 16:39:42 +02002006 expect(fc.children.length).toEqual(4);
Nils Diewald7c8ced22015-04-15 19:21:00 +00002007 expect(fc.children[0].getAttribute('class')).toEqual('docGroup');
2008 expect(fc.children[0].getAttribute('data-operation')).toEqual('or');
2009 expect(fc.children[1].getAttribute('class')).toEqual('doc');
Akronb19803c2018-08-16 16:39:42 +02002010 expect(fc.children[2].getAttribute('class')).toEqual('doc groupref');
2011 expect(fc.children[3].getAttribute('class')).toEqual('operators button-group');
Akron0b489ad2018-02-02 16:49:32 +01002012 expect(fc.lastChild.getAttribute('class')).toEqual('operators button-group');
Nils Diewald7c8ced22015-04-15 19:21:00 +00002013
2014 fc = vc.element().firstChild.firstChild;
2015 expect(fc.children.length).toEqual(3);
2016 expect(fc.children[0].getAttribute('class')).toEqual('doc');
2017 expect(fc.children[1].getAttribute('class')).toEqual('doc unspecified');
Akron0b489ad2018-02-02 16:49:32 +01002018 expect(fc.children[2].getAttribute('class')).toEqual('operators button-group');
2019 expect(fc.lastChild.getAttribute('class')).toEqual('operators button-group');
Akronb19803c2018-08-16 16:39:42 +02002020
2021 _orOn(vc.root().getOperand(2));
2022 fc = vc.element().firstChild;
2023 expect(fc.children.length).toEqual(4);
2024
2025 expect(fc.children[0].getAttribute('class')).toEqual('docGroup');
2026 expect(fc.children[1].getAttribute('class')).toEqual('doc');
2027 expect(fc.children[2].getAttribute('class')).toEqual('docGroup');
2028 expect(fc.children[3].getAttribute('class')).toEqual('operators button-group');
2029
2030 fc = vc.element().firstChild.children[2];
2031 expect(fc.children[0].getAttribute('class')).toEqual('doc groupref');
2032 expect(fc.children[1].getAttribute('class')).toEqual('doc unspecified');
2033 expect(fc.children[2].getAttribute('class')).toEqual('operators button-group');
2034 expect(fc.lastChild.getAttribute('class')).toEqual('operators button-group');
2035
Nils Diewald7c8ced22015-04-15 19:21:00 +00002036 });
2037
2038 it('should add new unspecified doc with "and" before group', function () {
2039 var vc = demoFactory.create();
2040
2041 // Wrap with direct element access
2042 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02002043 '(Titel = "Baum" & ' +
2044 'Veröffentlichungsort = "hihi" & ' +
2045 '(Titel = "Baum" | ' +
2046 'Veröffentlichungsort = "hihi")) | ' +
2047 'Untertitel ~ "huhu"'
Nils Diewald7c8ced22015-04-15 19:21:00 +00002048 );
2049
2050 expect(vc.root().getOperand(0).ldType()).toEqual('docGroup');
2051 expect(vc.root().getOperand(0).operation()).toEqual('and');
2052 expect(vc.root().getOperand(0).operands().length).toEqual(3);
2053
2054 // Add unspecified on the second doc
2055 var secDoc = vc.root().getOperand(0).getOperand(1);
2056 expect(secDoc.value()).toEqual('hihi');
2057
2058 // Add
2059 _andOn(secDoc);
2060
2061 var fo = vc.root().getOperand(0);
2062
2063 expect(fo.ldType()).toEqual('docGroup');
2064 expect(fo.operation()).toEqual('and');
2065 expect(fo.operands().length).toEqual(4);
2066
2067 expect(fo.getOperand(0).ldType()).toEqual('doc');
2068 expect(fo.getOperand(1).ldType()).toEqual('doc');
2069 expect(fo.getOperand(2).ldType()).toEqual('non');
2070 expect(fo.getOperand(3).ldType()).toEqual('docGroup');
2071 });
2072
2073
2074 it('should remove a doc with an unspecified doc in a nested group', function () {
2075 var vc = demoFactory.create();
2076
2077 // Wrap with direct element access
2078 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02002079 '(Titel = "Baum" & Veröffentlichungsort = "hihi" & (Titel = "Baum" | Veröffentlichungsort = "hihi")) | Untertitel ~ "huhu"'
Nils Diewald7c8ced22015-04-15 19:21:00 +00002080 );
2081
2082 var fo = vc.root().getOperand(0).getOperand(0);
2083 expect(fo.key()).toEqual('Titel');
2084 expect(fo.value()).toEqual('Baum');
2085
2086 // Add unspecified on the root group
2087 _orOn(fo);
2088
2089 fo = vc.root().getOperand(0).getOperand(0);
2090
2091 expect(fo.operation()).toEqual('or');
2092 expect(fo.getOperand(0).ldType()).toEqual('doc');
2093 expect(fo.getOperand(1).ldType()).toEqual('non');
2094
2095 // Delete document
2096 _delOn(fo.getOperand(0));
2097
2098 // The operand is now non
2099 expect(vc.root().getOperand(0).getOperand(0).ldType()).toEqual('non');
2100 expect(vc.root().getOperand(0).getOperand(1).ldType()).toEqual('doc');
2101 expect(vc.root().getOperand(0).getOperand(2).ldType()).toEqual('docGroup');
2102 });
2103
2104
Akron712733a2018-04-05 18:17:47 +02002105 it('should remove an unspecified doc with a doc in a nested group', function () {
Nils Diewald7c8ced22015-04-15 19:21:00 +00002106 var vc = demoFactory.create();
2107
2108 // Wrap with direct element access
2109 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02002110 '(Titel = "Baum" & ' +
2111 'Veröffentlichungsort = "hihi" & ' +
2112 '(Titel = "Baum" ' +
2113 '| Veröffentlichungsort = "hihi")) | ' +
2114 'Untertitel ~ "huhu"'
Nils Diewald7c8ced22015-04-15 19:21:00 +00002115 );
2116
2117 var fo = vc.root().getOperand(0).getOperand(0);
2118 expect(fo.key()).toEqual('Titel');
2119 expect(fo.value()).toEqual('Baum');
2120
2121 // Add unspecified on the root group
2122 _orOn(fo);
2123
2124 fo = vc.root().getOperand(0).getOperand(0);
2125
2126 expect(fo.operation()).toEqual('or');
2127 expect(fo.getOperand(0).ldType()).toEqual('doc');
2128 expect(fo.getOperand(1).ldType()).toEqual('non');
2129
2130 // Delete unspecified doc
2131 _delOn(fo.getOperand(1));
2132
2133 // The operand is now non
2134 fo = vc.root().getOperand(0);
2135 expect(fo.getOperand(0).ldType()).toEqual('doc');
2136 expect(fo.getOperand(0).key()).toEqual('Titel');
2137 expect(fo.getOperand(0).value()).toEqual('Baum');
2138 expect(fo.getOperand(1).ldType()).toEqual('doc');
2139 expect(fo.getOperand(2).ldType()).toEqual('docGroup');
2140 });
2141
2142
2143 it('should add on parent group (case "and")', function () {
2144 var vc = complexVCFactory.create();
2145
2146 // Wrap with direct element access
2147 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02002148 'pubDate in 2014-12-05 & (title = "Hello World!" | foo = "bar")'
Nils Diewald7c8ced22015-04-15 19:21:00 +00002149 );
2150
2151 expect(vc.root().operands().length).toEqual(2);
2152
2153 // Add unspecified on the root group
2154 _andOn(vc.root().getOperand(1));
2155 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02002156 'pubDate in 2014-12-05 & (title = "Hello World!" | foo = "bar")'
Nils Diewald7c8ced22015-04-15 19:21:00 +00002157 );
2158
2159 expect(vc.root().ldType()).toEqual('docGroup');
2160 expect(vc.root().operands().length).toEqual(3);
2161 expect(vc.root().getOperand(0).ldType()).toEqual('doc');
2162 expect(vc.root().getOperand(1).ldType()).toEqual('docGroup');
2163 expect(vc.root().getOperand(1).operation()).toEqual('or');
2164 expect(vc.root().getOperand(2).ldType()).toEqual('non');
2165
2166 // Add another unspecified on the root group
2167 _andOn(vc.root().getOperand(1));
2168
2169 expect(vc.root().operands().length).toEqual(4);
2170 expect(vc.root().getOperand(0).ldType()).toEqual('doc');
2171 expect(vc.root().getOperand(1).ldType()).toEqual('docGroup');
2172 expect(vc.root().getOperand(2).ldType()).toEqual('non');
2173 expect(vc.root().getOperand(3).ldType()).toEqual('non');
2174
2175 // Add another unspecified after the first doc
2176 _andOn(vc.root().getOperand(0));
2177
2178 expect(vc.root().operands().length).toEqual(5);
2179 expect(vc.root().getOperand(0).ldType()).toEqual('doc');
2180 expect(vc.root().getOperand(1).ldType()).toEqual('non');
2181 expect(vc.root().getOperand(2).ldType()).toEqual('docGroup');
2182 expect(vc.root().getOperand(3).ldType()).toEqual('non');
2183 expect(vc.root().getOperand(4).ldType()).toEqual('non');
2184 });
2185
2186 it('should wrap on root', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00002187 var vc = vcClass.create().fromJson(
Akron712733a2018-04-05 18:17:47 +02002188 {
2189 "@type": 'koral:docGroup',
2190 'operation' : 'operation:and',
2191 'operands' : [
2192 {
2193 "@type": 'koral:doc',
2194 "key": 'pubDate',
2195 "match": 'match:eq',
2196 "value": '2014-12-05',
2197 "type": 'type:date'
2198 },
2199 {
2200 "@type" : 'koral:doc',
2201 'key' : 'foo',
2202 'value' : 'bar'
2203 }
2204 ]
2205 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00002206 );
2207
2208 // Wrap on root
2209 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar"');
2210 expect(vc.root().ldType()).toEqual('docGroup');
2211 expect(vc.root().operation()).toEqual('and');
2212 _orOn(vc.root());
2213 expect(vc.root().ldType()).toEqual('docGroup');
2214 expect(vc.root().operation()).toEqual('or');
2215
2216 expect(vc.root().getOperand(0).ldType()).toEqual('docGroup');
2217 expect(vc.root().getOperand(0).operation()).toEqual('and');
2218 });
2219
2220 it('should add on root (case "and")', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00002221 var vc = vcClass.create().fromJson(
Akron712733a2018-04-05 18:17:47 +02002222 {
2223 "@type": 'koral:doc',
2224 "key": 'pubDate',
2225 "match": 'match:eq',
2226 "value": '2014-12-05',
2227 "type": 'type:date'
2228 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00002229 );
2230
2231 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05');
2232 expect(vc.root().ldType()).toEqual('doc');
2233 expect(vc.root().key()).toEqual('pubDate');
2234 expect(vc.root().value()).toEqual('2014-12-05');
2235
2236 // Wrap on root
2237 _andOn(vc.root());
2238 expect(vc.root().ldType()).toEqual('docGroup');
2239 expect(vc.root().operation()).toEqual('and');
2240 });
2241
2242 it('should add on root (case "or")', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00002243 var vc = vcClass.create().fromJson(
Akron712733a2018-04-05 18:17:47 +02002244 {
2245 "@type": 'koral:doc',
2246 "key": 'pubDate',
2247 "match": 'match:eq',
2248 "value": '2014-12-05',
2249 "type": 'type:date'
2250 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00002251 );
2252
2253 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05');
2254 expect(vc.root().key()).toEqual('pubDate');
2255 expect(vc.root().value()).toEqual('2014-12-05');
2256
2257 // Wrap on root
2258 _orOn(vc.root());
2259 expect(vc.root().ldType()).toEqual('docGroup');
2260 expect(vc.root().operation()).toEqual('or');
2261 });
2262
2263 it('should support multiple sub groups per group', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00002264 var vc = vcClass.create().fromJson(
Akron712733a2018-04-05 18:17:47 +02002265 {
2266 "@type": 'koral:docGroup',
2267 'operation' : 'operation:or',
2268 'operands' : [
2269 {
2270 "@type": 'koral:docGroup',
2271 'operation' : 'operation:and',
2272 'operands' : [
2273 {
2274 "@type": 'koral:doc',
2275 "key": 'title',
2276 "value": 't1',
2277 },
2278 {
2279 "@type" : 'koral:doc',
2280 'key' : 'title',
2281 'value' : 't2'
2282 }
2283 ]
2284 },
2285 {
2286 "@type": 'koral:docGroup',
2287 'operation' : 'operation:and',
2288 'operands' : [
2289 {
2290 "@type": 'koral:doc',
2291 "key": 'title',
2292 "value": 't3',
2293 },
2294 {
2295 "@type" : 'koral:doc',
2296 'key' : 'title',
2297 'value' : 't4'
2298 }
2299 ]
2300 }
2301 ]
2302 }
Nils Diewald7c8ced22015-04-15 19:21:00 +00002303 );
2304 expect(vc.toQuery()).toEqual(
Akron712733a2018-04-05 18:17:47 +02002305 '(title = "t1" & title = "t2") | ' +
2306 '(title = "t3" & title = "t4")'
Nils Diewald7c8ced22015-04-15 19:21:00 +00002307 );
2308 expect(vc.root().operation()).toEqual('or');
2309 expect(vc.root().getOperand(0).toQuery()).toEqual('title = "t1" & title = "t2"');
2310 expect(vc.root().getOperand(1).toQuery()).toEqual('title = "t3" & title = "t4"');
2311
2312 _andOn(vc.root());
2313
2314 expect(vc.root().operation()).toEqual('and');
2315 expect(vc.root().getOperand(0).ldType()).toEqual('docGroup');
2316 expect(vc.root().getOperand(1).ldType()).toEqual('non');
2317 });
2318 });
2319
Akron5c829e92017-05-12 18:10:00 +02002320 // Check class method
2321 describe('KorAP.VC.checkRewrite', function () {
2322
2323 it('should check for simple rewrites', function () {
2324 expect(vcClass.checkRewrite(
2325 {
2326 "@type" : "koral:doc",
2327 "rewrites" : [{
Akron712733a2018-04-05 18:17:47 +02002328 "@type" : "koral:rewrite",
2329 "operation" : "operation:modification",
2330 "src" : "querySerializer",
2331 "scope" : "tree"
Akron5c829e92017-05-12 18:10:00 +02002332 }]
2333 }
2334 )).toBeTruthy();
Nils Diewald7c8ced22015-04-15 19:21:00 +00002335
Akron5c829e92017-05-12 18:10:00 +02002336 var nested = {
2337 "@type" : "koral:docGroup",
2338 "operands" : [
2339 {
2340 "@type" : "koral:doc"
2341 },
2342 {
2343 "@type" : "koral:docGroup",
2344 "operands" : [
2345 {
2346 "@type": "koral:doc"
2347 },
2348 {
2349 "@type": "koral:doc"
2350 }
2351 ]
2352 }
2353 ]
2354 };
2355
2356 expect(vcClass.checkRewrite(nested)).toBe(false);
2357
2358 nested["operands"][1]["operands"][1]["rewrites"] = [{
Akron712733a2018-04-05 18:17:47 +02002359 "@type" : "koral:rewrite",
2360 "operation" : "operation:modification",
2361 "src" : "querySerializer",
2362 "scope" : "tree"
Akron5c829e92017-05-12 18:10:00 +02002363 }];
2364
2365 expect(vcClass.checkRewrite(nested)).toBeTruthy();
2366 });
2367 });
Nils Diewald6283d692015-04-23 20:32:53 +00002368
2369 describe('KorAP.Rewrite', function () {
Nils Diewald7c8ced22015-04-15 19:21:00 +00002370 it('should be initializable', function () {
2371 var rewrite = rewriteClass.create({
Akron712733a2018-04-05 18:17:47 +02002372 "@type" : "koral:rewrite",
2373 "operation" : "operation:modification",
2374 "src" : "querySerializer",
2375 "scope" : "tree"
Nils Diewald86dad5b2015-01-28 15:09:07 +00002376 });
Nils Diewald7c8ced22015-04-15 19:21:00 +00002377 expect(rewrite.toString()).toEqual('Modification of "tree" by "querySerializer"');
2378 });
Nils Diewald86dad5b2015-01-28 15:09:07 +00002379
Nils Diewald7c8ced22015-04-15 19:21:00 +00002380 it('should be deserialized by docs', function () {
2381 var doc = docClass.create(
Akron712733a2018-04-05 18:17:47 +02002382 undefined,
2383 {
2384 "@type":"koral:doc",
2385 "key":"Titel",
2386 "value":"Baum",
2387 "match":"match:eq"
2388 });
Nils Diewald7c8ced22015-04-15 19:21:00 +00002389
2390 expect(doc.element().classList.contains('doc')).toBeTruthy();
2391 expect(doc.element().classList.contains('rewritten')).toBe(false);
2392
2393 doc = docClass.create(
Akron712733a2018-04-05 18:17:47 +02002394 undefined,
2395 {
2396 "@type":"koral:doc",
2397 "key":"Titel",
2398 "value":"Baum",
2399 "match":"match:eq",
2400 "rewrites" : [
2401 {
2402 "@type" : "koral:rewrite",
2403 "operation" : "operation:modification",
2404 "src" : "querySerializer",
2405 "scope" : "tree"
2406 }
2407 ]
2408 });
Nils Diewald7c8ced22015-04-15 19:21:00 +00002409
2410 expect(doc.element().classList.contains('doc')).toBeTruthy();
2411 expect(doc.element().classList.contains('rewritten')).toBeTruthy();
2412 });
Nils Diewald6283d692015-04-23 20:32:53 +00002413
Akron76c3dd62018-05-29 20:58:27 +02002414 it('should be described in a title attribute', function () {
2415
2416 doc = docClass.create(
2417 undefined,
2418 {
2419 "@type":"koral:doc",
2420 "key":"Titel",
2421 "value":"Baum",
2422 "match":"match:eq",
2423 "rewrites" : [
2424 {
2425 "@type" : "koral:rewrite",
2426 "operation" : "operation:modification",
2427 "src" : "querySerializer",
2428 "scope" : "tree"
2429 },
2430 {
2431 "@type" : "koral:rewrite",
2432 "operation" : "operation:injection",
2433 "src" : "me"
2434 }
2435 ]
2436 });
2437
2438 expect(doc.element().classList.contains('doc')).toBeTruthy();
2439 expect(doc.element().classList.contains('rewritten')).toBeTruthy();
2440 expect(doc.element().lastChild.getAttribute("title")).toEqual("querySerializer: tree (modification)\nme (injection)");
2441 });
2442
2443
Nils Diewald6283d692015-04-23 20:32:53 +00002444 xit('should be deserialized by docGroups', function () {
2445 var docGroup = docGroupClass.create(
Akron712733a2018-04-05 18:17:47 +02002446 undefined,
2447 {
2448 "@type" : "koral:docGroup",
2449 "operation" : "operation:or",
2450 "operands" : [
2451 {
2452 "@type" : "doc",
2453 "key" : "pubDate",
2454 "type" : "type:date",
2455 "value" : "2014-12-05"
2456 },
2457 {
2458 "@type" : "doc",
2459 "key" : "pubDate",
2460 "type" : "type:date",
2461 "value" : "2014-12-06"
2462 }
2463 ],
2464 "rewrites" : [
2465 {
2466 "@type" : "koral:rewrite",
2467 "operation" : "operation:modification",
2468 "src" : "querySerializer",
2469 "scope" : "tree"
2470 }
2471 ]
2472 }
Nils Diewald6283d692015-04-23 20:32:53 +00002473 );
2474
2475 expect(doc.element().classList.contains('docgroup')).toBeTruthy();
2476 expect(doc.element().classList.contains('rewritten')).toBe(false);
2477 });
Nils Diewald86dad5b2015-01-28 15:09:07 +00002478 });
Nils Diewaldf0c4f112015-05-05 12:56:59 +00002479
2480 describe('KorAP.stringValue', function () {
2481 it('should be initializable', function () {
2482 var sv = stringValClass.create();
2483 expect(sv.regex()).toBe(false);
2484 expect(sv.value()).toBe('');
Nils Diewaldc4c4b832015-05-05 16:00:08 +00002485
2486 sv = stringValClass.create('Baum');
2487 expect(sv.regex()).toBe(false);
2488 expect(sv.value()).toBe('Baum');
2489
2490 sv = stringValClass.create('Baum', false);
2491 expect(sv.regex()).toBe(false);
2492 expect(sv.value()).toBe('Baum');
2493
2494 sv = stringValClass.create('Baum', true);
2495 expect(sv.regex()).toBe(true);
2496 expect(sv.value()).toBe('Baum');
2497 });
2498
2499 it('should be modifiable', function () {
2500 var sv = stringValClass.create();
2501 expect(sv.regex()).toBe(false);
2502 expect(sv.value()).toBe('');
2503
2504 expect(sv.value('Baum')).toBe('Baum');
2505 expect(sv.value()).toBe('Baum');
2506
2507 expect(sv.regex(true)).toBe(true);
2508 expect(sv.regex()).toBe(true);
2509 });
2510
2511 it('should have a toggleble regex value', function () {
2512 var sv = stringValClass.create();
Nils Diewald7991a3f2015-05-19 14:12:37 +00002513
2514 expect(sv.element().firstChild.value).toBe('');
2515 sv.element().firstChild.value = 'der'
2516 expect(sv.element().firstChild.value).toBe('der');
2517
Nils Diewaldc4c4b832015-05-05 16:00:08 +00002518 expect(sv.regex()).toBe(false);
2519
2520 sv.toggleRegex();
Nils Diewald7991a3f2015-05-19 14:12:37 +00002521 expect(sv.element().firstChild.value).toBe('der');
Nils Diewaldc4c4b832015-05-05 16:00:08 +00002522 expect(sv.regex()).toBe(true);
Nils Diewald7991a3f2015-05-19 14:12:37 +00002523 sv.element().firstChild.value = 'derbe'
Nils Diewaldc4c4b832015-05-05 16:00:08 +00002524
2525 sv.toggleRegex();
2526 expect(sv.regex()).toBe(false);
Nils Diewald7991a3f2015-05-19 14:12:37 +00002527 expect(sv.element().firstChild.value).toBe('derbe');
Nils Diewaldc4c4b832015-05-05 16:00:08 +00002528 });
2529
2530 it('should have an element', function () {
2531 var sv = stringValClass.create('der');
2532 expect(sv.element().nodeName).toBe('DIV');
2533 expect(sv.element().firstChild.nodeName).toBe('INPUT');
2534 expect(sv.element().firstChild.value).toBe('der');
2535 });
2536
2537 it('should have a classed element', function () {
2538 var sv = stringValClass.create();
Nils Diewaldc4c4b832015-05-05 16:00:08 +00002539 expect(sv.element().classList.contains('regex')).toBe(false);
2540 expect(sv.regex()).toBe(false);
2541 sv.toggleRegex();
2542 expect(sv.element().classList.contains('regex')).toBe(true);
2543 });
2544
2545 it('should be storable', function () {
2546 var sv = stringValClass.create();
2547 var count = 1;
2548 sv.store = function (value, regex) {
Akron712733a2018-04-05 18:17:47 +02002549 expect(regex).toBe(true);
2550 expect(value).toBe('tree');
Nils Diewaldc4c4b832015-05-05 16:00:08 +00002551 };
2552 sv.regex(true);
2553 sv.value('tree');
2554 sv.element().lastChild.click();
Nils Diewaldf0c4f112015-05-05 12:56:59 +00002555 });
Akron712733a2018-04-05 18:17:47 +02002556
Akronb19803c2018-08-16 16:39:42 +02002557 it('should have a disableoption for regex', function () {
2558 var sv = stringValClass.create(undefined, undefined, true);
2559 var svE = sv.element();
2560 expect(svE.children.length).toEqual(2);
2561
2562 sv = stringValClass.create(undefined, undefined, false);
2563 svE = sv.element();
2564 expect(svE.children.length).toEqual(1);
2565 });
2566
Nils Diewaldf0c4f112015-05-05 12:56:59 +00002567 });
Akrone4961b12017-05-10 21:04:46 +02002568
Akron712733a2018-04-05 18:17:47 +02002569 describe('KorAP.VC.Menu', function () {
Akrone65a88a2018-04-05 19:14:20 +02002570
2571 var vc;
2572
Akron712733a2018-04-05 18:17:47 +02002573 it('should be initializable', function () {
2574
Akrone65a88a2018-04-05 19:14:20 +02002575 vc = vcClass.create([
Akron712733a2018-04-05 18:17:47 +02002576 ['a', 'text'],
2577 ['b', 'string'],
2578 ['c', 'date']
2579 ]).fromJson();
2580 expect(vc.element().firstChild.classList.contains('unspecified')).toBeTruthy();
2581 expect(vc.element().firstChild.firstChild.tagName).toEqual('SPAN');
2582
2583 // Click on unspecified
2584 vc.element().firstChild.firstChild.click();
2585 expect(vc.element().firstChild.firstChild.tagName).toEqual('UL');
2586
2587 var list = vc.element().firstChild.firstChild;
Akron3ad46942018-08-22 16:47:14 +02002588 expect(list.getElementsByTagName("LI")[0].innerText).toEqual('referTo');
2589 expect(list.getElementsByTagName("LI")[1].innerText).toEqual('a');
2590 expect(list.getElementsByTagName("LI")[2].innerText).toEqual('b');
2591 expect(list.getElementsByTagName("LI")[3].innerText).toEqual('c');
Akron712733a2018-04-05 18:17:47 +02002592
2593 vc = vcClass.create([
2594 ['d', 'text'],
2595 ['e', 'string'],
2596 ['f', 'date']
2597 ]).fromJson();
2598 expect(vc.element().firstChild.classList.contains('unspecified')).toBeTruthy();
2599 expect(vc.element().firstChild.firstChild.tagName).toEqual('SPAN');
2600
2601 // Click on unspecified
2602 vc.element().firstChild.firstChild.click();
2603 expect(vc.element().firstChild.firstChild.tagName).toEqual('UL');
2604
2605 list = vc.element().firstChild.firstChild;
Akron3ad46942018-08-22 16:47:14 +02002606 expect(list.getElementsByTagName("LI")[0].innerText).toEqual('referTo');
2607 expect(list.getElementsByTagName("LI")[1].innerText).toEqual('d');
2608 expect(list.getElementsByTagName("LI")[2].innerText).toEqual('e');
2609 expect(list.getElementsByTagName("LI")[3].innerText).toEqual('f');
Akron31d89942018-04-06 16:44:51 +02002610 // blur
2611 document.body.click();
Akron712733a2018-04-05 18:17:47 +02002612 });
Akrone65a88a2018-04-05 19:14:20 +02002613
2614 // Reinitialize to make tests stable
2615 vc = vcClass.create([
2616 ['d', 'text'],
2617 ['e', 'string'],
2618 ['f', 'date']
2619 ]).fromJson();
2620
2621 it('should be clickable on key', function () {
Akron31d89942018-04-06 16:44:51 +02002622 // Click on unspecified
2623 vc.element().firstChild.firstChild.click();
Akrone65a88a2018-04-05 19:14:20 +02002624 // Click on "d"
Akron3ad46942018-08-22 16:47:14 +02002625 vc.element().firstChild.firstChild.getElementsByTagName("LI")[1].click();
Akrone65a88a2018-04-05 19:14:20 +02002626 expect(vc.element().firstChild.firstChild.tagName).toEqual('SPAN');
2627 expect(vc.element().firstChild.firstChild.innerText).toEqual('d');
2628 expect(vc.element().firstChild.children[1].innerText).toEqual('eq');
2629 expect(vc.element().firstChild.children[1].getAttribute('data-type')).toEqual('text');
Akron31d89942018-04-06 16:44:51 +02002630 // blur
2631 document.body.click();
Akrone65a88a2018-04-05 19:14:20 +02002632 });
2633
Akron31d89942018-04-06 16:44:51 +02002634 it('should be clickable on operation for text', function () {
2635 // Click on "d" (or unspecified)
2636 vc.element().firstChild.firstChild.click();
2637
2638 // Choose "d"
Akron3ad46942018-08-22 16:47:14 +02002639 vc.element().firstChild.firstChild.getElementsByTagName("LI")[1].click();
Akron31d89942018-04-06 16:44:51 +02002640
2641 // Click on matchop
Akrone65a88a2018-04-05 19:14:20 +02002642 vc.element().firstChild.children[1].click();
Akron31d89942018-04-06 16:44:51 +02002643
Akrone65a88a2018-04-05 19:14:20 +02002644 expect(vc.element().firstChild.children[1].tagName).toEqual('UL');
Akron31d89942018-04-06 16:44:51 +02002645
Akrone65a88a2018-04-05 19:14:20 +02002646 var ul = vc.element().firstChild.children[1];
2647 expect(ul.getElementsByTagName('li')[0].innerText).toEqual("eq");
2648 expect(ul.getElementsByTagName('li')[1].innerText).toEqual("ne");
2649 expect(ul.getElementsByTagName('li')[2].innerText).toEqual("contains");
2650 expect(ul.getElementsByTagName('li')[3].innerText).toEqual("containsnot");
2651 expect(ul.getElementsByTagName('li')[4]).toBeUndefined();
Akron31d89942018-04-06 16:44:51 +02002652
2653 // Choose "contains"
2654 ul.getElementsByTagName('li')[2].click();
2655 expect(vc.element().firstChild.children[1].tagName).toEqual("SPAN");
2656 expect(vc.element().firstChild.children[1].innerText).toEqual("contains");
2657 // blur
2658 document.body.click();
Akrone65a88a2018-04-05 19:14:20 +02002659 })
Akron31d89942018-04-06 16:44:51 +02002660
2661 it('should be clickable on operation for string', function () {
2662 // Click on "d" (or unspecified)
2663 vc.element().firstChild.firstChild.click();
2664
2665 // Choose "e"
Akron3ad46942018-08-22 16:47:14 +02002666 vc.element().firstChild.firstChild.getElementsByTagName("LI")[2].click();
2667
Akron31d89942018-04-06 16:44:51 +02002668 // As a consequence the matchoperator may no longer
2669 // be valid and needs to be re-evaluated
2670 var fc = vc.element().firstChild;
Akron3ad46942018-08-22 16:47:14 +02002671
Akron31d89942018-04-06 16:44:51 +02002672 expect(fc.firstChild.tagName).toEqual('SPAN');
2673 expect(fc.firstChild.innerText).toEqual('e');
2674 expect(fc.children[1].innerText).toEqual('eq');
2675 expect(fc.children[1].getAttribute('data-type')).toEqual('string');
2676
2677 vc.element().firstChild.children[1].click();
2678
2679 expect(vc.element().firstChild.children[1].tagName).toEqual('UL');
2680
2681 var ul = vc.element().firstChild.children[1];
2682 expect(ul.getElementsByTagName('li')[0].innerText).toEqual("eq");
2683 expect(ul.getElementsByTagName('li')[1].innerText).toEqual("ne");
2684 expect(ul.getElementsByTagName('li')[2]).toBeUndefined();
2685
2686 // Choose "ne"
2687 ul.getElementsByTagName('li')[1].click();
2688 expect(vc.element().firstChild.children[1].tagName).toEqual("SPAN");
2689 expect(vc.element().firstChild.children[1].innerText).toEqual("ne");
Akron8db5e3a2018-05-28 19:25:26 +02002690
2691 // Click on text
2692 expect(vc.element().firstChild.children[2].innerText).toEqual("⋯");
2693 vc.element().firstChild.children[2].click();
2694
2695 // Blur text element
2696 expect(vc.element().firstChild.children[2].firstChild.value).toEqual('');
2697
Akron31d89942018-04-06 16:44:51 +02002698 // blur
2699 document.body.click();
2700 });
2701
2702 it('should be clickable on operation for date', function () {
2703
2704 // Replay matchop check - so it's guaranteed that "ne" is chosen
2705 // Click on "e" (or unspecified)
2706 vc.element().firstChild.firstChild.click();
2707 // Rechoose "e"
2708 vc.element().firstChild.firstChild.getElementsByTagName("LI")[1].click();
2709 // Click on matchop
2710 vc.element().firstChild.children[1].click();
2711 // Choose "ne"
2712 vc.element().firstChild.children[1].getElementsByTagName('li')[1].click();
2713 expect(vc.element().firstChild.children[1].innerText).toEqual("ne");
2714
2715 // Click on "e"
2716 vc.element().firstChild.firstChild.click();
2717 // Choose "f"
Akron3ad46942018-08-22 16:47:14 +02002718 vc.element().firstChild.firstChild.getElementsByTagName("LI")[3].click();
Akron31d89942018-04-06 16:44:51 +02002719
2720 // The matchoperator should still be "ne" as this is valid for dates as well (now)
2721 var fc = vc.element().firstChild;
2722 expect(fc.firstChild.tagName).toEqual('SPAN');
2723 expect(fc.firstChild.innerText).toEqual('f');
2724 expect(fc.children[1].innerText).toEqual('ne');
2725 // blur
2726 document.body.click();
2727 });
Akronddc98a72018-04-06 17:33:52 +02002728
2729
2730 // Check json deserialization
2731 it('should be initializable', function () {
2732 vc = vcClass.create([
2733 ['a', 'text'],
2734 ['b', 'string'],
2735 ['c', 'date']
2736 ]).fromJson({
2737 "@type" : "koral:doc",
2738 "key":"a",
2739 "value":"Baum"
2740 });
2741
2742 expect(vc.element().firstChild.children[1].getAttribute('data-type')).toEqual('text');
2743 });
Akron712733a2018-04-05 18:17:47 +02002744 });
2745
2746
Akrone4961b12017-05-10 21:04:46 +02002747 // Check prefix
2748 describe('KorAP.VC.Prefix', function () {
2749
2750 it('should be initializable', function () {
2751 var p = prefixClass.create();
2752 expect(p.element().classList.contains('pref')).toBeTruthy();
2753 expect(p.isSet()).not.toBeTruthy();
2754 });
2755
2756
2757 it('should be clickable', function () {
2758 var vc = vcClass.create([
Akron712733a2018-04-05 18:17:47 +02002759 ['a', null],
2760 ['b', null],
2761 ['c', null]
2762 ]).fromJson();
Akrone4961b12017-05-10 21:04:46 +02002763 expect(vc.element().firstChild.classList.contains('unspecified')).toBeTruthy();
2764
2765 // This should open up the menu
2766 vc.element().firstChild.firstChild.click();
2767 expect(vc.element().firstChild.firstChild.tagName).toEqual('UL');
2768
2769 KorAP._vcKeyMenu._prefix.clear();
2770 KorAP._vcKeyMenu._prefix.add('x');
2771
2772 var prefElement = vc.element().querySelector('span.pref');
2773 expect(prefElement.innerText).toEqual('x');
2774
2775 // This should add key 'x' to VC
2776 prefElement.click();
2777
2778 expect(vc.element().firstChild.classList.contains('doc')).toBeTruthy();
2779 expect(vc.element().firstChild.firstChild.className).toEqual('key');
2780 expect(vc.element().firstChild.firstChild.innerText).toEqual('x');
2781 });
2782 });
Nils Diewald2fe12e12015-03-06 16:47:06 +00002783});