blob: 792dc3e85b251182cda406d265df73ca715b5638 [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 */
4define(['vc'], function () {
Nils Diewald6ac292b2015-01-15 21:33:21 +00005
Nils Diewald7c8ced22015-04-15 19:21:00 +00006 var vcClass = require('vc');
7 var docClass = require('vc/doc');
8 var docGroupClass = require('vc/docgroup');
9 var unspecifiedClass = require('vc/unspecified');
10 var operatorsClass = require('vc/operators');
11 var rewriteClass = require('vc/rewrite');
Nils Diewald6ac292b2015-01-15 21:33:21 +000012
Nils Diewald7c8ced22015-04-15 19:21:00 +000013 // Helper method for building factories
14 buildFactory = function (objClass, defaults) {
15 return {
16 create : function (overwrites) {
17 var newObj = {};
18 for (var prop in defaults) {
19 newObj[prop] = defaults[prop];
20 };
21 for (var prop in overwrites) {
22 newObj[prop] = overwrites[prop];
23 };
Nils Diewald6283d692015-04-23 20:32:53 +000024 return objClass.create().fromJson(newObj);
Nils Diewald7c8ced22015-04-15 19:21:00 +000025 }
Nils Diewald0b6c0412014-12-19 03:55:57 +000026 }
Nils Diewald7c8ced22015-04-15 19:21:00 +000027 };
Nils Diewald0b6c0412014-12-19 03:55:57 +000028
Nils Diewald7c8ced22015-04-15 19:21:00 +000029 function _andOn (obj) {
30 KorAP._and.bind(obj.element().lastChild.firstChild).apply();
31 };
Nils Diewald52f7eb12015-01-12 17:30:04 +000032
Nils Diewald7c8ced22015-04-15 19:21:00 +000033 function _orOn (obj) {
34 KorAP._or.bind(obj.element().lastChild.firstChild).apply();
35 };
Nils Diewald52f7eb12015-01-12 17:30:04 +000036
Nils Diewald7c8ced22015-04-15 19:21:00 +000037 function _delOn (obj) {
38 KorAP._delete.bind(obj.element().lastChild.firstChild).apply();
39 };
Nils Diewald52f7eb12015-01-12 17:30:04 +000040
Nils Diewald7c8ced22015-04-15 19:21:00 +000041 var demoFactory = buildFactory(vcClass, {
42 "@type":"koral:docGroup",
43 "operation":"operation:or",
44 "operands":[
Nils Diewaldf219eb82015-01-07 20:15:42 +000045 {
Nils Diewald7c8ced22015-04-15 19:21:00 +000046 "@type":"koral:docGroup",
47 "operation":"operation:and",
48 "operands":[
49 {
50 "@type":"koral:doc",
51 "key":"Titel",
52 "value":"Baum",
53 "match":"match:eq"
54 },
55 {
56 "@type":"koral:doc",
57 "key":"Veröffentlichungsort",
58 "value":"hihi",
59 "match":"match:eq"
60 },
61 {
62 "@type":"koral:docGroup",
63 "operation":"operation:or",
64 "operands":[
65 {
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 }
79 ]
Nils Diewaldf219eb82015-01-07 20:15:42 +000080 },
81 {
Nils Diewald7c8ced22015-04-15 19:21:00 +000082 "@type":"koral:doc",
83 "key":"Untertitel",
84 "value":"huhu",
85 "match":"match:eq"
Nils Diewaldf219eb82015-01-07 20:15:42 +000086 }
87 ]
88 });
89
Nils Diewald7c8ced22015-04-15 19:21:00 +000090 describe('KorAP.Doc', function () {
91 // Create example factories
92 var stringFactory = buildFactory(docClass, {
93 "key" : "author",
94 "value" : "Max Birkendale",
95 "@type" : "koral:doc"
96 });
97
98 // Create example factories
99 var dateFactory = buildFactory(docClass, {
100 "key" : "pubDate",
101 "type" : "type:date",
102 "match" : "match:eq",
103 "value" : "2014-11-05",
104 "@type" : "koral:doc"
105 });
106
107 // Create example factories
108 var regexFactory = buildFactory(docClass, {
109 "key" : "title",
110 "type" : "type:regex",
111 "value" : "[^b]ee.+?",
112 "@type" : "koral:doc"
113 });
114
115 it('should be initializable', function () {
116 var doc = docClass.create();
117 expect(doc.matchop()).toEqual('eq');
118 expect(doc.key()).toBeUndefined();
119 expect(doc.value()).toBeUndefined();
120 expect(doc.type()).toEqual("string");
121 });
122
123 it('should be definable', function () {
124
125 // Empty doc
126 var doc = docClass.create();
127
128 // Set values
129 doc.key("title");
130 doc.value("Der alte Mann");
131 expect(doc.matchop()).toEqual('eq');
132 expect(doc.key()).toEqual("title");
133 expect(doc.type()).toEqual("string");
134 expect(doc.value()).toEqual("Der alte Mann");
135 });
136
137
138 it('should deserialize JSON-LD string', function () {
139 var doc;
140
141 // String default
142 doc = stringFactory.create();
143 expect(doc.matchop()).toEqual('eq');
144 expect(doc.key()).toEqual("author");
145 expect(doc.type()).toEqual("string");
146 expect(doc.value()).toEqual("Max Birkendale");
147
148 // No valid string
149 doc = stringFactory.create({
150 value : undefined
151 });
152 expect(doc).toBeUndefined();
153
154 // No valid string
155 doc = stringFactory.create({
156 value : { "foo" : "bar" }
157 });
158 expect(doc).toBeUndefined();
159
160 // Change match type
161 doc = stringFactory.create({
162 "match" : "match:ne"
163 });
164
165 expect(doc.matchop()).toEqual('ne');
166 expect(doc.key()).toEqual("author");
167 expect(doc.type()).toEqual("string");
168 expect(doc.value()).toEqual("Max Birkendale");
169
170 // Invalid match type
171 doc = stringFactory.create({
172 "match" : { "foo" : "bar" }
173 });
174 expect(doc).toBeUndefined();
175 });
176
177 it('should deserialize JSON-LD regex', function () {
178 var doc = regexFactory.create();
179 expect(doc.key()).toEqual("title");
180 expect(doc.type()).toEqual("regex");
181 expect(doc.value()).toEqual("[^b]ee.+?");
182 expect(doc.matchop()).toEqual('eq');
183
184 // change matcher
185 doc = regexFactory.create({
186 match : "match:ne"
187 });
188 expect(doc.matchop()).toEqual('ne');
189
190 // Invalid matcher
191 doc = regexFactory.create({
192 match : "match:chook"
193 });
194 expect(doc).toBeUndefined();
195
196 // Invalid regex
197 doc = regexFactory.create({
198 value : "[^b"
199 });
200 expect(doc).toBeUndefined();
201 });
202
203 it('should deserialize JSON-LD date', function () {
204
205 // Normal date
206 doc = dateFactory.create({});
207
208 expect(doc.matchop()).toEqual('eq');
209 expect(doc.key()).toEqual("pubDate");
210 expect(doc.type()).toEqual("date");
211 expect(doc.value()).toEqual("2014-11-05");
212
213 // Short date 1
214 doc = dateFactory.create({
215 "value" : "2014-11"
216 });
217
218 expect(doc.matchop()).toEqual('eq');
219 expect(doc.key()).toEqual("pubDate");
220 expect(doc.type()).toEqual("date");
221 expect(doc.value()).toEqual("2014-11");
222
223 // Short date 2
224 doc = dateFactory.create({
225 "value" : "2014"
226 });
227
228 expect(doc.matchop()).toEqual('eq');
229 expect(doc.key()).toEqual("pubDate");
230 expect(doc.type()).toEqual("date");
231 expect(doc.value()).toEqual("2014");
232
233 // Invalid date!
234 doc = dateFactory.create({
235 "value" : "2014-11-050"
236 });
237 expect(doc).toBeUndefined();
238
239 // Invalid matcher!
240 doc = dateFactory.create({
241 "match" : "match:ne",
242 });
243 expect(doc).toBeUndefined();
244 });
245
246 it('should be serializale to JSON', function () {
247
248 // Empty doc
249 var doc = docClass.create();
250 expect(doc.toJson()).toEqual(jasmine.any(Object));
251
252 // Serialize string
253 doc = stringFactory.create();
254 expect(doc.toJson()).toEqual(jasmine.objectContaining({
255 "@type" : "koral:doc",
256 "type" : "type:string",
257 "key" : "author",
258 "value" : "Max Birkendale",
259 "match" : "match:eq"
260 }));
261
262 // Serialize regex
263 doc = regexFactory.create();
264 expect(doc.toJson()).toEqual(jasmine.objectContaining({
265 "@type" : "koral:doc",
266 "type" : "type:regex",
267 "value" : "[^b]ee.+?",
268 "match" : "match:eq",
269 "key" : 'title'
270 }));
271
272 doc = regexFactory.create({
273 match: "match:ne"
274 });
275 expect(doc.toJson()).toEqual(jasmine.objectContaining({
276 "@type" : "koral:doc",
277 "type" : "type:regex",
278 "value" : "[^b]ee.+?",
279 "match" : "match:ne",
280 "key" : 'title'
281 }));
282
283 doc = dateFactory.create();
284 expect(doc.toJson()).toEqual(jasmine.objectContaining({
285 "@type" : "koral:doc",
286 "type" : "type:date",
287 "value" : "2014-11-05",
288 "match" : "match:eq",
289 "key" : 'pubDate'
290 }));
291
292 doc = dateFactory.create({
293 value : "2014"
294 });
295 expect(doc.toJson()).toEqual(jasmine.objectContaining({
296 "@type" : "koral:doc",
297 "type" : "type:date",
298 "value" : "2014",
299 "match" : "match:eq",
300 "key" : 'pubDate'
301 }));
302 });
303
304
305 it('should be serializale to String', function () {
306 // Empty doc
307 var doc = docClass.create();
308 expect(doc.toQuery()).toEqual("");
309
310 // Serialize string
311 doc = stringFactory.create();
312 expect(doc.toQuery()).toEqual('author = "Max Birkendale"');
313
314 // Serialize string with quotes
315 doc = stringFactory.create({ "value" : 'Max "Der Coole" Birkendate'});
316 expect(doc.toQuery()).toEqual('author = "Max \\"Der Coole\\" Birkendate"');
317
318 // Serialize regex
319 doc = regexFactory.create();
320 expect(doc.toQuery()).toEqual('title = /[^b]ee.+?/');
321
322 doc = regexFactory.create({
323 match: "match:ne"
324 });
325 expect(doc.toQuery()).toEqual('title != /[^b]ee.+?/');
326
327 doc = dateFactory.create();
328 expect(doc.toQuery()).toEqual('pubDate in 2014-11-05');
329
330 doc = dateFactory.create({
331 value : "2014"
332 });
333 expect(doc.toQuery()).toEqual('pubDate in 2014');
334 });
335 });
336
337
338 describe('KorAP.DocGroup', function () {
339 // Create example factories
340 var docFactory = buildFactory(
341 docClass,
Nils Diewaldf219eb82015-01-07 20:15:42 +0000342 {
Nils Diewald7c8ced22015-04-15 19:21:00 +0000343 "@type" : "koral:doc",
344 "match":"match:eq",
345 "key" : "author",
346 "value" : "Max Birkendale"
347 }
348 );
349
350 var docGroupFactory = buildFactory(
351 docGroupClass, {
352 "@type" : "koral:docGroup",
353 "operation" : "operation:and",
354 "operands" : [
355 docFactory.create().toJson(),
356 docFactory.create({
357 "key" : "pubDate",
358 "type" : "type:date",
359 "value" : "2014-12-05"
360 }).toJson()
361 ]
362 });
363
364 it('should be initializable', function () {
365 // Create empty group
366 var docGroup = docGroupClass.create();
367 expect(docGroup.operation()).toEqual('and');
368
369 // Create empty group
370 docGroup = docGroupClass.create();
371 docGroup.operation('or');
372 expect(docGroup.operation()).toEqual('or');
373 });
374
375 it('should be definable', function () {
376
377 // Empty group
378 var docGroup = docGroupClass.create();
379 expect(docGroup.operation()).toEqual('and');
380
381 // Set values
382 docGroup.operation("or");
383 expect(docGroup.operation()).toEqual('or');
384
385 // Set invalid values
386 docGroup.operation("hui");
387 expect(docGroup.operation()).toEqual('or');
388 });
389
390 it('should be deserializable', function () {
391 var docGroup = docGroupFactory.create();
392 expect(docGroup.operation()).toEqual("and");
393 expect(docGroup.operands().length).toEqual(2);
394
395 var op1 = docGroup.getOperand(0);
396 expect(op1.type()).toEqual("string");
397 expect(op1.key()).toEqual("author");
398 expect(op1.value()).toEqual("Max Birkendale");
399 expect(op1.matchop()).toEqual("eq");
400
401 var op2 = docGroup.getOperand(1);
402 expect(op2.type()).toEqual("date");
403 expect(op2.key()).toEqual("pubDate");
404 expect(op2.value()).toEqual("2014-12-05");
405 expect(op2.matchop()).toEqual("eq");
406
407 // Append empty group
408 var newGroup = docGroup.append(docGroupClass.create());
409 newGroup.operation('or');
410 newGroup.append(docFactory.create());
411 newGroup.append(docFactory.create({
412 "type" : "type:regex",
413 "key" : "title",
414 "value" : "^e.+?$",
415 "match" : "match:ne"
416 }));
417
418 expect(docGroup.operation()).toEqual("and");
419 expect(docGroup.operands().length).toEqual(3);
420
421 var op1 = docGroup.getOperand(0);
422 expect(op1.ldType()).toEqual("doc");
423 expect(op1.type()).toEqual("string");
424 expect(op1.key()).toEqual("author");
425 expect(op1.value()).toEqual("Max Birkendale");
426 expect(op1.matchop()).toEqual("eq");
427
428 var op2 = docGroup.getOperand(1);
429 expect(op2.ldType()).toEqual("doc");
430 expect(op2.type()).toEqual("date");
431 expect(op2.key()).toEqual("pubDate");
432 expect(op2.value()).toEqual("2014-12-05");
433 expect(op2.matchop()).toEqual("eq");
434
435 var op3 = docGroup.getOperand(2);
436 expect(op3.ldType()).toEqual("docGroup");
437 expect(op3.operation()).toEqual("or");
438
439 var op4 = op3.getOperand(0);
440 expect(op4.ldType()).toEqual("doc");
441 expect(op4.type()).toEqual("string");
442 expect(op4.key()).toEqual("author");
443 expect(op4.value()).toEqual("Max Birkendale");
444 expect(op4.matchop()).toEqual("eq");
445
446 var op5 = op3.getOperand(1);
447 expect(op5.ldType()).toEqual("doc");
448 expect(op5.type()).toEqual("regex");
449 expect(op5.key()).toEqual("title");
450 expect(op5.value()).toEqual("^e.+?$");
451 expect(op5.matchop()).toEqual("ne");
452 });
453
454 it('should be serializable to JSON', function () {
455 var docGroup = docGroupFactory.create();
456
457 expect(docGroup.toJson()).toEqual(jasmine.objectContaining({
Nils Diewald2fe12e12015-03-06 16:47:06 +0000458 "@type" : "koral:docGroup",
Nils Diewaldf219eb82015-01-07 20:15:42 +0000459 "operation" : "operation:and",
460 "operands" : [
461 {
Nils Diewald2fe12e12015-03-06 16:47:06 +0000462 "@type": 'koral:doc',
Nils Diewald7c8ced22015-04-15 19:21:00 +0000463 "key" : 'author',
464 "match": 'match:eq',
465 "value": 'Max Birkendale',
466 "type": 'type:string'
Nils Diewaldf219eb82015-01-07 20:15:42 +0000467 },
468 {
Nils Diewald2fe12e12015-03-06 16:47:06 +0000469 "@type": 'koral:doc',
Nils Diewaldf219eb82015-01-07 20:15:42 +0000470 "key": 'pubDate',
Nils Diewalde15b7a22015-01-09 21:50:21 +0000471 "match": 'match:eq',
472 "value": '2014-12-05',
473 "type": 'type:date'
Nils Diewalde15b7a22015-01-09 21:50:21 +0000474 }
475 ]
Nils Diewald7c8ced22015-04-15 19:21:00 +0000476 }));
477 });
Nils Diewalde15b7a22015-01-09 21:50:21 +0000478
Nils Diewald7c8ced22015-04-15 19:21:00 +0000479 it('should be serializable to String', function () {
480 var docGroup = docGroupFactory.create();
481 expect(docGroup.toQuery()).toEqual(
482 'author = "Max Birkendale" & pubDate in 2014-12-05'
483 );
Nils Diewald52f7eb12015-01-12 17:30:04 +0000484
Nils Diewald7c8ced22015-04-15 19:21:00 +0000485 docGroup = docGroupFactory.create({
486 "@type" : "koral:docGroup",
487 "operation" : "operation:or",
488 "operands" : [
Nils Diewalde15b7a22015-01-09 21:50:21 +0000489 {
Nils Diewald2fe12e12015-03-06 16:47:06 +0000490 "@type": 'koral:doc',
Nils Diewald7c8ced22015-04-15 19:21:00 +0000491 "key" : 'author',
Nils Diewalde15b7a22015-01-09 21:50:21 +0000492 "match": 'match:eq',
Nils Diewald7c8ced22015-04-15 19:21:00 +0000493 "value": 'Max Birkendale',
494 "type": 'type:string'
Nils Diewalde15b7a22015-01-09 21:50:21 +0000495 },
496 {
Nils Diewald7c8ced22015-04-15 19:21:00 +0000497 "@type" : "koral:docGroup",
498 "operation" : "operation:and",
499 "operands" : [
Nils Diewalde15b7a22015-01-09 21:50:21 +0000500 {
Nils Diewald2fe12e12015-03-06 16:47:06 +0000501 "@type": 'koral:doc',
Nils Diewalde15b7a22015-01-09 21:50:21 +0000502 "key": 'pubDate',
Nils Diewald7c8ced22015-04-15 19:21:00 +0000503 "match": 'match:geq',
504 "value": '2014-05-12',
505 "type": 'type:date'
506 },
507 {
508 "@type": 'koral:doc',
509 "key": 'pubDate',
510 "match": 'match:leq',
Nils Diewalde15b7a22015-01-09 21:50:21 +0000511 "value": '2014-12-05',
512 "type": 'type:date'
513 },
514 {
Nils Diewald7c8ced22015-04-15 19:21:00 +0000515 "@type": 'koral:doc',
516 "key": 'foo',
517 "match": 'match:ne',
518 "value": '[a]?bar',
519 "type": 'type:regex'
520 }
521 ]
522 }
523 ]
524 });
525 expect(docGroup.toQuery()).toEqual(
526 'author = "Max Birkendale" | ' +
527 '(pubDate since 2014-05-12 & ' +
528 'pubDate until 2014-12-05 & foo != /[a]?bar/)'
529 );
530 });
531 });
532
533 describe('KorAP.UnspecifiedDoc', function () {
534 it('should be initializable', function () {
535 var doc = unspecifiedClass.create();
536 var docElement = doc.element();
537 expect(docElement.getAttribute('class')).toEqual('doc unspecified');
538 expect(docElement.firstChild.firstChild.data).toEqual('⋯');
539 expect(docElement.lastChild.lastChild.data).toEqual('⋯');
540 expect(doc.toQuery()).toEqual('');
541
542 // Only removable
543 expect(docElement.lastChild.children.length).toEqual(0);
544 });
545
546 it('should be removable, when no root', function () {
547 var docGroup = docGroupClass.create();
548 docGroup.operation('or');
549 expect(docGroup.operation()).toEqual('or');
550
551 docGroup.append({
552 "@type": 'koral:doc',
553 "key": 'pubDate',
554 "match": 'match:eq',
555 "value": '2014-12-05',
556 "type": 'type:date'
557 });
558
559 // Add unspecified object
560 docGroup.append();
561
562 expect(docGroup.element().getAttribute('class')).toEqual('docGroup');
563 expect(docGroup.element().children[0].getAttribute('class')).toEqual('doc');
564
565 var unspec = docGroup.element().children[1];
566 expect(unspec.getAttribute('class')).toEqual('doc unspecified');
567
568 // Removable
569 expect(unspec.lastChild.children.length).toEqual(1);
570 expect(unspec.lastChild.children[0].getAttribute('class')).toEqual('delete');
571 });
572
573 it('should be replaceable by a doc', function () {
574 var doc = unspecifiedClass.create();
575 expect(doc.ldType()).toEqual("non");
576 // No parent, therefor not updateable
577 expect(doc.key("baum")).toBeNull();
578
579 var docGroup = docGroupClass.create();
580 docGroup.operation('or');
581 expect(docGroup.operation()).toEqual('or');
582
583 docGroup.append({
584 "@type": 'koral:doc',
585 "key": 'pubDate',
586 "match": 'match:eq',
587 "value": '2014-12-05',
588 "type": 'type:date'
589 });
590
591 expect(docGroup.toQuery()).toEqual("pubDate in 2014-12-05");
592 docGroup.append();
593
594 expect(docGroup.getOperand(0).ldType()).toEqual("doc");
595 expect(docGroup.getOperand(1).ldType()).toEqual("non");
596
597 var op = docGroup.getOperand(1).element().lastChild;
598 expect(op.getAttribute('class')).toEqual('operators');
599 expect(op.children[0].getAttribute('class')).toEqual('delete');
600 expect(op.children.length).toEqual(1);
601
602 // Replace unspecified doc
603 expect(docGroup.getOperand(1).key("name")).not.toBeNull();
604 expect(docGroup.getOperand(1).ldType()).toEqual("doc");
605 expect(docGroup.getOperand(1).key()).toEqual("name");
606 expect(docGroup.getOperand(1).value()).toEqual("");
607
608 op = docGroup.getOperand(1).element().lastChild;
609 expect(op.getAttribute('class')).toEqual('operators');
610 expect(op.children[0].getAttribute('class')).toEqual('and');
611 expect(op.children[1].getAttribute('class')).toEqual('or');
612 expect(op.children[2].getAttribute('class')).toEqual('delete');
613 expect(op.children.length).toEqual(3);
614
615 docGroup.getOperand(1).value("Pachelbel");
616 expect(docGroup.getOperand(1).value()).toEqual("Pachelbel");
617 expect(docGroup.getOperand(1).type()).toEqual("string");
618 expect(docGroup.getOperand(1).matchop()).toEqual("eq");
619
620 // Specified!
621 expect(docGroup.toQuery()).toEqual('pubDate in 2014-12-05 | name = "Pachelbel"');
622 });
623
624 it('should be replaceable on root', function () {
Nils Diewald6283d692015-04-23 20:32:53 +0000625 var vc = vcClass.create();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000626 expect(vc.toQuery()).toEqual("");
627
628 expect(vc.root().ldType()).toEqual("non");
629
630 // No operators on root
631 op = vc.root().element().lastChild;
632 expect(op.lastChild.textContent).toEqual('⋯');
633
634 // Replace
635 expect(vc.root().key("baum")).not.toBeNull();
636 expect(vc.root().ldType()).toEqual("doc");
637
638 op = vc.root().element().lastChild;
639 expect(op.getAttribute('class')).toEqual('operators');
640 expect(op.children[0].getAttribute('class')).toEqual('and');
641 expect(op.children[1].getAttribute('class')).toEqual('or');
642 expect(op.children[2].getAttribute('class')).toEqual('delete');
643 expect(op.children.length).toEqual(3);
644 });
645 });
646
647 describe('KorAP.Doc element', function () {
648 it('should be initializable', function () {
649 var docElement = docClass.create(undefined, {
650 "@type" : "koral:doc",
651 "key":"Titel",
652 "value":"Baum",
653 "match":"match:eq"
654 });
655 expect(docElement.key()).toEqual('Titel');
656 expect(docElement.matchop()).toEqual('eq');
657 expect(docElement.value()).toEqual('Baum');
658
659 var docE = docElement.element();
660 expect(docE.children[0].firstChild.data).toEqual('Titel');
661 expect(docE.children[1].firstChild.data).toEqual('eq');
662 expect(docE.children[1].getAttribute('data-type')).toEqual('string');
663 expect(docE.children[2].firstChild.data).toEqual('Baum');
664 expect(docE.children[2].getAttribute('data-type')).toEqual('string');
665
666 expect(docElement.toJson()).toEqual(jasmine.objectContaining({
667 "@type" : "koral:doc",
668 "key":"Titel",
669 "value":"Baum",
670 "match":"match:eq"
671 }));
672 });
673 });
674
675 describe('KorAP.DocGroup element', function () {
676 it('should be initializable', function () {
677
678 var docGroup = docGroupClass.create(undefined, {
679 "@type" : "koral:docGroup",
680 "operation" : "operation:and",
681 "operands" : [
682 {
683 "@type": 'koral:doc',
684 "key" : 'author',
685 "match": 'match:eq',
686 "value": 'Max Birkendale',
687 "type": 'type:string'
688 },
689 {
690 "@type": 'koral:doc',
691 "key": 'pubDate',
692 "match": 'match:eq',
693 "value": '2014-12-05',
694 "type": 'type:date'
695 }
696 ]
697 });
698
699 expect(docGroup.operation()).toEqual('and');
700 var e = docGroup.element();
701 expect(e.getAttribute('class')).toEqual('docGroup');
702 expect(e.getAttribute('data-operation')).toEqual('and');
703
704 var first = e.children[0];
705 expect(first.getAttribute('class')).toEqual('doc');
706 expect(first.children[0].getAttribute('class')).toEqual('key');
707 expect(first.children[1].getAttribute('class')).toEqual('match');
708 expect(first.children[2].getAttribute('class')).toEqual('value');
709 expect(first.children[2].getAttribute('data-type')).toEqual('string');
710 expect(first.children[0].firstChild.data).toEqual('author');
711 expect(first.children[1].firstChild.data).toEqual('eq');
712 expect(first.children[2].firstChild.data).toEqual('Max Birkendale');
713
714 var second = e.children[1];
715 expect(second.getAttribute('class')).toEqual('doc');
716 expect(second.children[0].getAttribute('class')).toEqual('key');
717 expect(second.children[1].getAttribute('class')).toEqual('match');
718 expect(second.children[2].getAttribute('class')).toEqual('value');
719 expect(second.children[2].getAttribute('data-type')).toEqual('date');
720 expect(second.children[0].firstChild.data).toEqual('pubDate');
721 expect(second.children[1].firstChild.data).toEqual('eq');
722 expect(second.children[2].firstChild.data).toEqual('2014-12-05');
723 });
724
725 it('should be deserializable with nested groups', function () {
726 var docGroup = docGroupClass.create(undefined, {
727 "@type" : "koral:docGroup",
728 "operation" : "operation:or",
729 "operands" : [
730 {
731 "@type": 'koral:doc',
732 "key" : 'author',
733 "match": 'match:eq',
734 "value": 'Max Birkendale',
735 "type": 'type:string'
736 },
737 {
738 "@type" : "koral:docGroup",
739 "operation" : "operation:and",
740 "operands" : [
741 {
742 "@type": 'koral:doc',
743 "key": 'pubDate',
744 "match": 'match:geq',
745 "value": '2014-05-12',
746 "type": 'type:date'
747 },
748 {
749 "@type": 'koral:doc',
750 "key": 'pubDate',
751 "match": 'match:leq',
752 "value": '2014-12-05',
753 "type": 'type:date'
754 }
755 ]
756 }
757 ]
758 });
759
760 expect(docGroup.operation()).toEqual('or');
761 var e = docGroup.element();
762 expect(e.getAttribute('class')).toEqual('docGroup');
763 expect(e.getAttribute('data-operation')).toEqual('or');
764
765 expect(e.children[0].getAttribute('class')).toEqual('doc');
766 var docop = e.children[0].lastChild;
767 expect(docop.getAttribute('class')).toEqual('operators');
768 expect(docop.children[0].getAttribute('class')).toEqual('and');
769 expect(docop.children[1].getAttribute('class')).toEqual('or');
770 expect(docop.children[2].getAttribute('class')).toEqual('delete');
771
772 expect(e.children[1].getAttribute('class')).toEqual('docGroup');
773 expect(e.children[1].getAttribute('data-operation')).toEqual('and');
774
775 // This and-operation can be "or"ed or "delete"d
776 var secop = e.children[1].children[2];
777 expect(secop.getAttribute('class')).toEqual('operators');
778 expect(secop.children[0].getAttribute('class')).toEqual('or');
779 expect(secop.children[1].getAttribute('class')).toEqual('delete');
780
781 // This or-operation can be "and"ed or "delete"d
782 expect(e.children[2].getAttribute('class')).toEqual('operators');
783 expect(e.lastChild.getAttribute('class')).toEqual('operators');
784 expect(e.lastChild.children[0].getAttribute('class')).toEqual('and');
785 expect(e.lastChild.children[1].getAttribute('class')).toEqual('delete');
786 });
787 });
788
789 describe('KorAP.VirtualCollection', function () {
790 var simpleGroupFactory = buildFactory(docGroupClass, {
791 "@type" : "koral:docGroup",
792 "operation" : "operation:and",
793 "operands" : [
794 {
795 "@type": 'koral:doc',
796 "key" : 'author',
797 "match": 'match:eq',
798 "value": 'Max Birkendale',
799 "type": 'type:string'
800 },
801 {
802 "@type": 'koral:doc',
803 "key": 'pubDate',
804 "match": 'match:eq',
805 "value": '2014-12-05',
806 "type": 'type:date'
807 }
808 ]
809 });
810
811 var nestedGroupFactory = buildFactory(vcClass, {
812 "@type" : "koral:docGroup",
813 "operation" : "operation:or",
814 "operands" : [
815 {
816 "@type": 'koral:doc',
817 "key" : 'author',
818 "match": 'match:eq',
819 "value": 'Max Birkendale',
820 "type": 'type:string'
821 },
822 {
823 "@type" : "koral:docGroup",
824 "operation" : "operation:and",
825 "operands" : [
826 {
827 "@type": 'koral:doc',
828 "key": 'pubDate',
829 "match": 'match:geq',
830 "value": '2014-05-12',
831 "type": 'type:date'
832 },
833 {
834 "@type": 'koral:doc',
835 "key": 'pubDate',
836 "match": 'match:leq',
837 "value": '2014-12-05',
838 "type": 'type:date'
839 }
840 ]
841 }
842 ]
843 });
844
845 var flatGroupFactory = buildFactory(vcClass, {
846 "@type" : "koral:docGroup",
847 "operation" : "operation:and",
848 "operands" : [
849 {
850 "@type": 'koral:doc',
851 "key": 'pubDate',
852 "match": 'match:geq',
853 "value": '2014-05-12',
854 "type": 'type:date'
855 },
856 {
857 "@type": 'koral:doc',
858 "key": 'pubDate',
859 "match": 'match:leq',
860 "value": '2014-12-05',
861 "type": 'type:date'
862 },
863 {
864 "@type": 'koral:doc',
865 "key": 'foo',
866 "match": 'match:eq',
867 "value": 'bar',
868 "type": 'type:string'
869 }
870 ]
871 });
872
873 it('should be initializable', function () {
Nils Diewald6283d692015-04-23 20:32:53 +0000874 var vc = vcClass.create();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000875 expect(vc.element().getAttribute('class')).toEqual('vc');
876 expect(vc.root().element().getAttribute('class')).toEqual('doc unspecified');
877
878 // Not removable
879 expect(vc.root().element().lastChild.children.length).toEqual(0);
880 });
881
882 it('should be based on a doc', function () {
Nils Diewald6283d692015-04-23 20:32:53 +0000883 var vc = vcClass.create().fromJson({
Nils Diewald7c8ced22015-04-15 19:21:00 +0000884 "@type" : "koral:doc",
885 "key":"Titel",
886 "value":"Baum",
887 "match":"match:eq"
888 });
889
890 expect(vc.element().getAttribute('class')).toEqual('vc');
891 expect(vc.root().element().getAttribute('class')).toEqual('doc');
892 expect(vc.root().key()).toEqual('Titel');
893 expect(vc.root().value()).toEqual('Baum');
894 expect(vc.root().matchop()).toEqual('eq');
895
896 var docE = vc.root().element();
897 expect(docE.children[0].firstChild.data).toEqual('Titel');
898 expect(docE.children[1].firstChild.data).toEqual('eq');
899 expect(docE.children[1].getAttribute('data-type')).toEqual('string');
900 expect(docE.children[2].firstChild.data).toEqual('Baum');
901 expect(docE.children[2].getAttribute('data-type')).toEqual('string');
902 });
903
904 it('should be based on a docGroup', function () {
Nils Diewald6283d692015-04-23 20:32:53 +0000905 var vc = vcClass.create().fromJson(simpleGroupFactory.create().toJson());
Nils Diewald7c8ced22015-04-15 19:21:00 +0000906
907 expect(vc.element().getAttribute('class')).toEqual('vc');
908 expect(vc.root().element().getAttribute('class')).toEqual('docGroup');
909 expect(vc.root().operation()).toEqual('and');
910
911 var docGroup = vc.root();
912
913 var first = docGroup.getOperand(0);
914 expect(first.key()).toEqual('author');
915 expect(first.value()).toEqual('Max Birkendale');
916 expect(first.matchop()).toEqual('eq');
917
918 var second = docGroup.getOperand(1);
919 expect(second.key()).toEqual('pubDate');
920 expect(second.value()).toEqual('2014-12-05');
921 expect(second.matchop()).toEqual('eq');
922 });
923
924
925 it('should be based on a nested docGroup', function () {
926 var vc = nestedGroupFactory.create();
927
928 expect(vc.element().getAttribute('class')).toEqual('vc');
929 expect(vc.element().firstChild.getAttribute('class')).toEqual('docGroup');
930 expect(vc.element().firstChild.children[0].getAttribute('class')).toEqual('doc');
931 var dg = vc.element().firstChild.children[1];
932 expect(dg.getAttribute('class')).toEqual('docGroup');
933 expect(dg.children[0].getAttribute('class')).toEqual('doc');
934 expect(dg.children[1].getAttribute('class')).toEqual('doc');
935 expect(dg.children[2].getAttribute('class')).toEqual('operators');
936 expect(vc.element().firstChild.children[2].getAttribute('class')).toEqual('operators');
937 });
938
939 it('should be modifiable by deletion in flat docGroups', function () {
940 var vc = flatGroupFactory.create();
941 var docGroup = vc.root();
942
943 expect(docGroup.element().getAttribute('class')).toEqual('docGroup');
944
945 var doc = docGroup.getOperand(1);
946 expect(doc.key()).toEqual("pubDate");
947 expect(doc.value()).toEqual("2014-12-05");
948
949 // Remove operand 1
950 expect(docGroup.delOperand(doc).update()).not.toBeUndefined();
951 expect(doc._element).toEqual(undefined);
952
953 doc = docGroup.getOperand(1);
954 expect(doc.key()).toEqual("foo");
955
956 // Remove operand 1
957 expect(docGroup.delOperand(doc).update()).not.toBeUndefined();
958 expect(doc._element).toEqual(undefined);
959
960 // Only one operand left ...
961 expect(docGroup.getOperand(1)).toBeUndefined();
962 // ... but there shouldn't be a group anymore at all!
963 expect(docGroup.getOperand(0)).toBeUndefined();
964
965 var obj = vc.root();
966 expect(obj.ldType()).toEqual("doc");
967 expect(obj.key()).toEqual("pubDate");
968 expect(obj.value()).toEqual("2014-05-12");
969
970 expect(obj.element().getAttribute('class')).toEqual('doc');
971 });
972
973
974 it('should be modifiable by deletion in nested docGroups (root case)', function () {
975 var vc = nestedGroupFactory.create();
976
977 expect(vc.toQuery()).toEqual(
978 'author = "Max Birkendale" | (pubDate since 2014-05-12 & pubDate until 2014-12-05)'
979 );
980
981 var docGroup = vc.root();
982 expect(docGroup.ldType()).toEqual("docGroup");
983 expect(docGroup.operation()).toEqual("or");
984
985 var doc = docGroup.getOperand(0);
986 expect(doc.key()).toEqual("author");
987 expect(doc.value()).toEqual("Max Birkendale");
988
989 docGroup = docGroup.getOperand(1);
990 expect(docGroup.operation()).toEqual("and");
991
992 doc = docGroup.getOperand(0);
993 expect(doc.key()).toEqual("pubDate");
994 expect(doc.matchop()).toEqual("geq");
995 expect(doc.value()).toEqual("2014-05-12");
996 expect(doc.type()).toEqual("date");
997
998 doc = docGroup.getOperand(1);
999 expect(doc.key()).toEqual("pubDate");
1000 expect(doc.matchop()).toEqual("leq");
1001 expect(doc.value()).toEqual("2014-12-05");
1002 expect(doc.type()).toEqual("date");
1003
1004 // Remove first operand so everything becomes root
1005 expect(
1006 vc.root().delOperand(
1007 vc.root().getOperand(0)
1008 ).update().ldType()
1009 ).toEqual("docGroup");
1010
1011 expect(vc.root().ldType()).toEqual("docGroup");
1012 expect(vc.root().operation()).toEqual("and");
1013 expect(vc.root().getOperand(0).ldType()).toEqual("doc");
1014
1015 expect(vc.toQuery()).toEqual(
1016 'pubDate since 2014-05-12 & pubDate until 2014-12-05'
1017 );
1018 });
1019
1020 it('should be modifiable by deletion in nested docGroups (resolve group case)', function () {
1021 var vc = nestedGroupFactory.create();
1022
1023 // Get nested group
1024 var firstGroup = vc.root().getOperand(1);
1025 firstGroup.append(simpleGroupFactory.create({ "operation" : "operation:or" }));
1026
1027 // Structur is now:
1028 // or(doc, and(doc, doc, or(doc, doc)))
1029
1030 // Get nested or in and
1031 var orGroup = vc.root().getOperand(1).getOperand(2);
1032 expect(orGroup.ldType()).toEqual("docGroup");
1033 expect(orGroup.operation()).toEqual("or");
1034
1035 // Remove
1036 // Structur is now:
1037 // or(doc, and(doc, doc, doc)))
1038 expect(orGroup.delOperand(orGroup.getOperand(0)).update().operation()).toEqual("and");
1039 expect(vc.root().getOperand(1).operands().length).toEqual(3);
1040 });
1041
1042 it('should be modifiable by deletion in nested docGroups (identical group case)', function () {
1043 var vc = nestedGroupFactory.create();
1044
1045 // Get nested group
1046 var firstGroup = vc.root().getOperand(1);
1047 firstGroup.append(simpleGroupFactory.create({
1048 "operation" : "operation:or"
1049 }));
1050 var oldAuthor = firstGroup.getOperand(2).getOperand(0);
1051 oldAuthor.key("title");
1052 oldAuthor.value("Der Birnbaum");
1053
1054 // Structur is now:
1055 // or(doc, and(doc, doc, or(doc, doc)))
1056 expect(vc.toQuery()).toEqual(
1057 'author = "Max Birkendale" | ' +
1058 '(pubDate since 2014-05-12 & ' +
1059 'pubDate until 2014-12-05 & ' +
1060 '(title = "Der Birnbaum" | ' +
1061 'pubDate in 2014-12-05))'
1062 );
1063
1064 var andGroup = vc.root().getOperand(1);
1065
1066 // Get leading docs in and
1067 var doc1 = andGroup.getOperand(0);
1068 expect(doc1.ldType()).toEqual("doc");
1069 expect(doc1.value()).toEqual("2014-05-12");
1070 var doc2 = andGroup.getOperand(1);
1071 expect(doc2.ldType()).toEqual("doc");
1072 expect(doc2.value()).toEqual("2014-12-05");
1073
1074 // Remove 2
1075 expect(
1076 andGroup.delOperand(doc2).update().operation()
1077 ).toEqual("and");
1078 // Structur is now:
1079 // or(doc, and(doc, or(doc, doc)))
1080
1081 expect(vc.toQuery()).toEqual(
1082 'author = "Max Birkendale"' +
1083 ' | (pubDate since 2014-05-12 & ' +
1084 '(title = "Der Birnbaum" | pubDate in 2014-12-05))'
1085 );
1086
1087
1088 // Remove 1
1089 expect(andGroup.delOperand(doc1).update().operation()).toEqual("or");
1090 // Structur is now:
1091 // or(doc, doc, doc)
1092
1093 expect(vc.toQuery()).toEqual(
1094 'author = "Max Birkendale" | title = "Der Birnbaum" | pubDate in 2014-12-05'
1095 );
1096 });
1097
1098 it('should be reducible to unspecification', function () {
1099 var vc = demoFactory.create();
1100
1101 expect(vc.toQuery()).toEqual(vc.root().toQuery());
1102 expect(vc.toQuery()).toEqual(
1103 '(Titel = "Baum" & Veröffentlichungsort = "hihi" & ' +
1104 '(Titel = "Baum" | Veröffentlichungsort = "hihi")) ' +
1105 '| Untertitel = "huhu"');
1106 expect(vc.root().element().lastChild.children[0].firstChild.nodeValue).toEqual('and');
1107 expect(vc.root().element().lastChild.children[1].firstChild.nodeValue).toEqual('×');
1108 expect(vc.root().delOperand(vc.root().getOperand(0)).update()).not.toBeUndefined();
1109 expect(vc.toQuery()).toEqual('Untertitel = "huhu"');
1110
1111 var lc = vc.root().element().lastChild;
1112 expect(lc.children[0].firstChild.nodeValue).toEqual('and');
1113 expect(lc.children[1].firstChild.nodeValue).toEqual('or');
1114 expect(lc.children[2].firstChild.nodeValue).toEqual('×');
1115
1116 // Clean everything
1117 vc.clean();
1118 expect(vc.toQuery()).toEqual('');
1119 });
1120
1121 it('should flatten on import', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00001122 var vc = vcClass.create().fromJson({
Nils Diewald7c8ced22015-04-15 19:21:00 +00001123 "@type":"koral:docGroup",
1124 "operation":"operation:or",
1125 "operands":[
1126 {
1127 "@type":"koral:docGroup",
1128 "operation":"operation:or",
1129 "operands":[
1130 {
1131 "@type":"koral:doc",
1132 "key":"Titel",
1133 "value":"Baum",
1134 "match":"match:eq"
1135 },
1136 {
1137 "@type":"koral:doc",
1138 "key":"Veröffentlichungsort",
1139 "value":"hihi",
1140 "match":"match:eq"
1141 },
1142 {
1143 "@type":"koral:docGroup",
1144 "operation":"operation:or",
1145 "operands":[
Nils Diewalde15b7a22015-01-09 21:50:21 +00001146 {
Nils Diewald7c8ced22015-04-15 19:21:00 +00001147 "@type":"koral:doc",
1148 "key":"Titel",
1149 "value":"Baum",
1150 "match":"match:eq"
Nils Diewalde15b7a22015-01-09 21:50:21 +00001151 },
1152 {
Nils Diewald7c8ced22015-04-15 19:21:00 +00001153 "@type":"koral:doc",
1154 "key":"Veröffentlichungsort",
1155 "value":"hihi",
1156 "match":"match:eq"
Nils Diewalde15b7a22015-01-09 21:50:21 +00001157 }
1158 ]
Nils Diewald7c8ced22015-04-15 19:21:00 +00001159 }
Nils Diewald6ac292b2015-01-15 21:33:21 +00001160 ]
1161 },
1162 {
Nils Diewald7c8ced22015-04-15 19:21:00 +00001163 "@type":"koral:doc",
1164 "key":"Untertitel",
1165 "value":"huhu",
1166 "match":"match:eq"
Nils Diewald6ac292b2015-01-15 21:33:21 +00001167 }
1168 ]
Nils Diewald7c8ced22015-04-15 19:21:00 +00001169 });
Nils Diewaldfda29d92015-01-22 17:28:01 +00001170
Nils Diewald7c8ced22015-04-15 19:21:00 +00001171 expect(vc.toQuery()).toEqual(
1172 'Titel = "Baum" | Veröffentlichungsort = "hihi" | Untertitel = "huhu"'
1173 );
Nils Diewald86dad5b2015-01-28 15:09:07 +00001174 });
Nils Diewald86dad5b2015-01-28 15:09:07 +00001175 });
1176
Nils Diewald7c8ced22015-04-15 19:21:00 +00001177 describe('KorAP.Operators', function () {
1178 it('should be initializable', function () {
1179 var op = operatorsClass.create(true, false, false);
1180 expect(op.and()).toBeTruthy();
1181 expect(op.or()).not.toBeTruthy();
1182 expect(op.del()).not.toBeTruthy();
1183
1184 op.and(false);
1185 expect(op.and()).not.toBeTruthy();
1186 expect(op.or()).not.toBeTruthy();
1187 expect(op.del()).not.toBeTruthy();
1188
1189 op.or(true);
1190 op.del(true);
1191 expect(op.and()).not.toBeTruthy();
1192 expect(op.or()).toBeTruthy();
1193 expect(op.del()).toBeTruthy();
1194
1195 var e = op.element();
1196 expect(e.getAttribute('class')).toEqual('operators');
1197 expect(e.children[0].getAttribute('class')).toEqual('or');
1198 expect(e.children[0].firstChild.data).toEqual('or');
1199 expect(e.children[1].getAttribute('class')).toEqual('delete');
1200 expect(e.children[1].firstChild.data).toEqual('×');
1201
1202 op.and(true);
1203 op.del(false);
1204 op.update();
1205
1206 e = op.element();
1207 expect(e.getAttribute('class')).toEqual('operators');
1208 expect(e.children[0].getAttribute('class')).toEqual('and');
1209 expect(e.children[0].firstChild.data).toEqual('and');
1210 expect(e.children[1].getAttribute('class')).toEqual('or');
1211 expect(e.children[1].firstChild.data).toEqual('or');
1212 });
1213 });
1214
1215 describe('KorAP._delete (event)', function () {
1216 var complexVCFactory = buildFactory(vcClass,{
1217 "@type": 'koral:docGroup',
1218 'operation' : 'operation:and',
1219 'operands' : [
1220 {
1221 "@type": 'koral:doc',
1222 "key": 'pubDate',
1223 "match": 'match:eq',
1224 "value": '2014-12-05',
1225 "type": 'type:date'
1226 },
1227 {
1228 "@type" : 'koral:docGroup',
1229 'operation' : 'operation:or',
1230 'operands' : [
1231 {
1232 '@type' : 'koral:doc',
1233 'key' : 'title',
1234 'value' : 'Hello World!'
1235 },
1236 {
1237 '@type' : 'koral:doc',
1238 'key' : 'foo',
1239 'value' : 'bar'
1240 }
1241 ]
1242 }
1243 ]
1244 });
1245
1246 it('should clean on root docs', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00001247 var vc = vcClass.create().fromJson({
Nils Diewald7c8ced22015-04-15 19:21:00 +00001248 "@type": 'koral:doc',
1249 "key": 'pubDate',
1250 "match": 'match:eq',
1251 "value": '2014-12-05',
1252 "type": 'type:date'
Nils Diewald86dad5b2015-01-28 15:09:07 +00001253 });
Nils Diewald7c8ced22015-04-15 19:21:00 +00001254 expect(vc.root().toQuery()).toEqual('pubDate in 2014-12-05');
1255 expect(vc.root().element().lastChild.getAttribute('class')).toEqual('operators');
Nils Diewald86dad5b2015-01-28 15:09:07 +00001256
Nils Diewald7c8ced22015-04-15 19:21:00 +00001257 // Clean with delete from root
1258 expect(vc.root().element().lastChild.lastChild.getAttribute('class')).toEqual('delete');
1259 _delOn(vc.root());
1260 expect(vc.root().toQuery()).toEqual('');
1261 expect(vc.root().element().lastChild.lastChild.data).toEqual('⋯');
1262 });
Nils Diewald86dad5b2015-01-28 15:09:07 +00001263
Nils Diewald7c8ced22015-04-15 19:21:00 +00001264 it('should remove on nested docs', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00001265 var vc = vcClass.create().fromJson(
Nils Diewald7c8ced22015-04-15 19:21:00 +00001266 {
1267 "@type": 'koral:docGroup',
1268 'operation' : 'operation:and',
1269 'operands' : [
1270 {
1271 "@type": 'koral:doc',
1272 "key": 'pubDate',
1273 "match": 'match:eq',
1274 "value": '2014-12-05',
1275 "type": 'type:date'
1276 },
1277 {
1278 "@type" : 'koral:doc',
1279 'key' : 'foo',
1280 'value' : 'bar'
1281 }
1282 ]
1283 }
1284 );
1285
1286 // Delete with direct element access
1287 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar"');
1288 _delOn(vc.root().getOperand(0));
1289
1290 expect(vc.toQuery()).toEqual('foo = "bar"');
1291 expect(vc.root().ldType()).toEqual('doc');
1292 });
1293
1294 it('should clean on doc groups', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00001295 var vc = vcClass.create().fromJson(
Nils Diewald7c8ced22015-04-15 19:21:00 +00001296 {
1297 "@type": 'koral:docGroup',
1298 'operation' : 'operation:and',
1299 'operands' : [
1300 {
1301 "@type": 'koral:doc',
1302 "key": 'pubDate',
1303 "match": 'match:eq',
1304 "value": '2014-12-05',
1305 "type": 'type:date'
1306 },
1307 {
1308 "@type" : 'koral:doc',
1309 'key' : 'foo',
1310 'value' : 'bar'
1311 }
1312 ]
1313 }
1314 );
1315
1316 // Cleanwith direct element access
1317 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar"');
1318 _delOn(vc.root());
1319 expect(vc.toQuery()).toEqual('');
1320 expect(vc.root().ldType()).toEqual('non');
1321 });
1322
1323 it('should remove on nested doc groups (case of ungrouping 1)', function () {
1324 var vc = complexVCFactory.create();
1325
1326 // Delete with direct element access
1327 expect(vc.toQuery()).toEqual(
1328 'pubDate in 2014-12-05 & (title = "Hello World!" | foo = "bar")'
1329 );
1330
1331 // Remove hello world:
1332 _delOn(vc.root().getOperand(1).getOperand(0));
1333 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar"');
1334 expect(vc.root().ldType()).toEqual('docGroup');
1335 });
1336
1337 it('should remove on nested doc groups (case of ungrouping 2)', function () {
1338 var vc = complexVCFactory.create();
1339
1340 // Delete with direct element access
1341 expect(vc.toQuery()).toEqual(
1342 'pubDate in 2014-12-05 & (title = "Hello World!" | foo = "bar")'
1343 );
1344
1345 // Remove bar
1346 _delOn(vc.root().getOperand(1).getOperand(1));
1347 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & title = "Hello World!"');
1348 expect(vc.root().ldType()).toEqual('docGroup');
1349 expect(vc.root().operation()).toEqual('and');
1350 });
1351
1352 it('should remove on nested doc groups (case of root changing)', function () {
1353 var vc = complexVCFactory.create();
1354
1355 // Delete with direct element access
1356 expect(vc.toQuery()).toEqual(
1357 'pubDate in 2014-12-05 & ' +
1358 '(title = "Hello World!" | foo = "bar")'
1359 );
1360
1361 // Remove bar
1362 _delOn(vc.root().getOperand(0));
1363 expect(vc.toQuery()).toEqual('title = "Hello World!" | foo = "bar"');
1364 expect(vc.root().ldType()).toEqual('docGroup');
1365 expect(vc.root().operation()).toEqual('or');
1366 });
1367
1368 it('should remove on nested doc groups (list flattening)', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00001369 var vc = vcClass.create().fromJson(
Nils Diewald7c8ced22015-04-15 19:21:00 +00001370 {
1371 "@type": 'koral:docGroup',
1372 'operation' : 'operation:or',
1373 'operands' : [
1374 {
1375 "@type": 'koral:doc',
1376 "key": 'pubDate',
1377 "match": 'match:eq',
1378 "value": '2014-12-05',
1379 "type": 'type:date'
1380 },
1381 {
1382 "@type" : 'koral:doc',
1383 'key' : 'foo',
1384 'value' : 'bar'
1385 },
1386 {
1387 "@type": 'koral:docGroup',
1388 'operation' : 'operation:and',
1389 'operands' : [
1390 {
1391 "@type": 'koral:doc',
1392 "key": 'pubDate',
1393 "match": 'match:eq',
1394 "value": '2014-12-05',
1395 "type": 'type:date'
1396 },
1397 {
1398 "@type" : 'koral:docGroup',
1399 'operation' : 'operation:or',
1400 'operands' : [
1401 {
1402 '@type' : 'koral:doc',
1403 'key' : 'title',
1404 'value' : 'Hello World!'
1405 },
1406 {
1407 '@type' : 'koral:doc',
1408 'key' : 'yeah',
1409 'value' : 'juhu'
1410 }
1411 ]
1412 }
1413 ]
1414 }
1415 ]
1416 }
1417 );
1418
1419 // Delete with direct element access
1420 expect(vc.toQuery()).toEqual(
1421 'pubDate in 2014-12-05 | foo = "bar" | ' +
1422 '(pubDate in 2014-12-05 & ' +
1423 '(title = "Hello World!" | yeah = "juhu"))'
1424 );
1425
1426 expect(vc.root().ldType()).toEqual('docGroup');
1427 expect(vc.root().operation()).toEqual('or');
1428
1429 // Operands and operators
1430 expect(vc.element().firstChild.children.length).toEqual(4);
1431 expect(vc.element().firstChild.lastChild.getAttribute('class')).toEqual('operators');
1432
1433 // Remove inner group and flatten
1434 _delOn(vc.root().getOperand(2).getOperand(0));
1435
1436 expect(vc.toQuery()).toEqual(
1437 'pubDate in 2014-12-05 | foo = "bar" | title = "Hello World!" | yeah = "juhu"'
1438 );
1439 expect(vc.root().ldType()).toEqual('docGroup');
1440 expect(vc.root().operation()).toEqual('or');
1441
1442 // Operands and operators
1443 expect(vc.element().firstChild.children.length).toEqual(5);
1444 expect(vc.element().firstChild.lastChild.getAttribute('class')).toEqual('operators');
1445 });
1446 });
1447
1448 describe('KorAP._add (event)', function () {
1449 var complexVCFactory = buildFactory(vcClass,{
1450 "@type": 'koral:docGroup',
1451 'operation' : 'operation:and',
1452 'operands' : [
1453 {
1454 "@type": 'koral:doc',
1455 "key": 'pubDate',
1456 "match": 'match:eq',
1457 "value": '2014-12-05',
1458 "type": 'type:date'
1459 },
1460 {
1461 "@type" : 'koral:docGroup',
1462 'operation' : 'operation:or',
1463 'operands' : [
1464 {
1465 '@type' : 'koral:doc',
1466 'key' : 'title',
1467 'value' : 'Hello World!'
1468 },
1469 {
1470 '@type' : 'koral:doc',
1471 'key' : 'foo',
1472 'value' : 'bar'
1473 }
1474 ]
1475 }
1476 ]
1477 });
1478
1479 it('should add new unspecified doc with "and"', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00001480 var vc = vcClass.create().fromJson(
Nils Diewald7c8ced22015-04-15 19:21:00 +00001481 {
1482 "@type": 'koral:docGroup',
1483 'operation' : 'operation:and',
1484 'operands' : [
1485 {
1486 "@type": 'koral:doc',
1487 "key": 'pubDate',
1488 "match": 'match:eq',
1489 "value": '2014-12-05',
1490 "type": 'type:date'
1491 },
1492 {
1493 "@type" : 'koral:doc',
1494 'key' : 'foo',
1495 'value' : 'bar'
1496 }
1497 ]
1498 }
1499 );
1500
1501 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar"');
1502
1503 var fc = vc.element().firstChild;
1504 expect(fc.getAttribute('data-operation')).toEqual('and');
1505 expect(fc.children.length).toEqual(3);
1506 expect(fc.lastChild.getAttribute('class')).toEqual('operators');
1507 expect(fc.children[0].getAttribute('class')).toEqual('doc');
1508 expect(fc.children[1].getAttribute('class')).toEqual('doc');
1509
1510 // add with 'and' in the middle
1511 _andOn(vc.root().getOperand(0));
1512 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar"');
1513
1514 fc = vc.element().firstChild;
1515 expect(fc.getAttribute('data-operation')).toEqual('and');
1516 expect(fc.children.length).toEqual(4);
1517 expect(fc.lastChild.getAttribute('class')).toEqual('operators');
1518
1519 expect(fc.children[0].getAttribute('class')).toEqual('doc');
1520 expect(fc.children[1].getAttribute('class')).toEqual('doc unspecified');
1521 expect(fc.children[2].getAttribute('class')).toEqual('doc');
1522 });
1523
1524 it('should add new unspecified doc with "or"', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00001525 var vc = vcClass.create().fromJson(
Nils Diewald7c8ced22015-04-15 19:21:00 +00001526 {
1527 "@type": 'koral:docGroup',
1528 'operation' : 'operation:and',
1529 'operands' : [
1530 {
1531 "@type": 'koral:doc',
1532 "key": 'pubDate',
1533 "match": 'match:eq',
1534 "value": '2014-12-05',
1535 "type": 'type:date'
1536 },
1537 {
1538 "@type" : 'koral:doc',
1539 'key' : 'foo',
1540 'value' : 'bar'
1541 }
1542 ]
1543 }
1544 );
1545
1546 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar"');
1547
1548 var fc = vc.element().firstChild;
1549 expect(fc.children.length).toEqual(3);
1550 expect(fc.lastChild.getAttribute('class')).toEqual('operators');
1551 expect(fc.children[0].getAttribute('class')).toEqual('doc');
1552 expect(fc.children[1].getAttribute('class')).toEqual('doc');
1553
1554 // add with 'or' in the middle
1555 _orOn(vc.root().getOperand(0));
1556 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar"');
1557 fc = vc.element().firstChild;
1558
1559 expect(fc.getAttribute('data-operation')).toEqual('and');
1560 expect(fc.children.length).toEqual(3);
1561 expect(fc.children[0].getAttribute('class')).toEqual('docGroup');
1562 expect(fc.children[0].getAttribute('data-operation')).toEqual('or');
1563 expect(fc.children[1].getAttribute('class')).toEqual('doc');
1564 expect(fc.children[2].getAttribute('class')).toEqual('operators');
1565 expect(fc.lastChild.getAttribute('class')).toEqual('operators');
1566
1567 fc = vc.element().firstChild.firstChild;
1568 expect(fc.children.length).toEqual(3);
1569 expect(fc.children[0].getAttribute('class')).toEqual('doc');
1570 expect(fc.children[1].getAttribute('class')).toEqual('doc unspecified');
1571 expect(fc.children[2].getAttribute('class')).toEqual('operators');
1572 expect(fc.lastChild.getAttribute('class')).toEqual('operators');
1573 });
1574
1575 it('should add new unspecified doc with "and" before group', function () {
1576 var vc = demoFactory.create();
1577
1578 // Wrap with direct element access
1579 expect(vc.toQuery()).toEqual(
1580 '(Titel = "Baum" & ' +
1581 'Veröffentlichungsort = "hihi" & ' +
1582 '(Titel = "Baum" | ' +
1583 'Veröffentlichungsort = "hihi")) | ' +
1584 'Untertitel = "huhu"'
1585 );
1586
1587 expect(vc.root().getOperand(0).ldType()).toEqual('docGroup');
1588 expect(vc.root().getOperand(0).operation()).toEqual('and');
1589 expect(vc.root().getOperand(0).operands().length).toEqual(3);
1590
1591 // Add unspecified on the second doc
1592 var secDoc = vc.root().getOperand(0).getOperand(1);
1593 expect(secDoc.value()).toEqual('hihi');
1594
1595 // Add
1596 _andOn(secDoc);
1597
1598 var fo = vc.root().getOperand(0);
1599
1600 expect(fo.ldType()).toEqual('docGroup');
1601 expect(fo.operation()).toEqual('and');
1602 expect(fo.operands().length).toEqual(4);
1603
1604 expect(fo.getOperand(0).ldType()).toEqual('doc');
1605 expect(fo.getOperand(1).ldType()).toEqual('doc');
1606 expect(fo.getOperand(2).ldType()).toEqual('non');
1607 expect(fo.getOperand(3).ldType()).toEqual('docGroup');
1608 });
1609
1610
1611 it('should remove a doc with an unspecified doc in a nested group', function () {
1612 var vc = demoFactory.create();
1613
1614 // Wrap with direct element access
1615 expect(vc.toQuery()).toEqual(
1616 '(Titel = "Baum" & Veröffentlichungsort = "hihi" & (Titel = "Baum" | Veröffentlichungsort = "hihi")) | Untertitel = "huhu"'
1617 );
1618
1619 var fo = vc.root().getOperand(0).getOperand(0);
1620 expect(fo.key()).toEqual('Titel');
1621 expect(fo.value()).toEqual('Baum');
1622
1623 // Add unspecified on the root group
1624 _orOn(fo);
1625
1626 fo = vc.root().getOperand(0).getOperand(0);
1627
1628 expect(fo.operation()).toEqual('or');
1629 expect(fo.getOperand(0).ldType()).toEqual('doc');
1630 expect(fo.getOperand(1).ldType()).toEqual('non');
1631
1632 // Delete document
1633 _delOn(fo.getOperand(0));
1634
1635 // The operand is now non
1636 expect(vc.root().getOperand(0).getOperand(0).ldType()).toEqual('non');
1637 expect(vc.root().getOperand(0).getOperand(1).ldType()).toEqual('doc');
1638 expect(vc.root().getOperand(0).getOperand(2).ldType()).toEqual('docGroup');
1639 });
1640
1641
1642 it('should remove an unspecified doc with an doc in a nested group', function () {
1643 var vc = demoFactory.create();
1644
1645 // Wrap with direct element access
1646 expect(vc.toQuery()).toEqual(
1647 '(Titel = "Baum" & ' +
1648 'Veröffentlichungsort = "hihi" & ' +
1649 '(Titel = "Baum" ' +
1650 '| Veröffentlichungsort = "hihi")) | ' +
1651 'Untertitel = "huhu"'
1652 );
1653
1654 var fo = vc.root().getOperand(0).getOperand(0);
1655 expect(fo.key()).toEqual('Titel');
1656 expect(fo.value()).toEqual('Baum');
1657
1658 // Add unspecified on the root group
1659 _orOn(fo);
1660
1661 fo = vc.root().getOperand(0).getOperand(0);
1662
1663 expect(fo.operation()).toEqual('or');
1664 expect(fo.getOperand(0).ldType()).toEqual('doc');
1665 expect(fo.getOperand(1).ldType()).toEqual('non');
1666
1667 // Delete unspecified doc
1668 _delOn(fo.getOperand(1));
1669
1670 // The operand is now non
1671 fo = vc.root().getOperand(0);
1672 expect(fo.getOperand(0).ldType()).toEqual('doc');
1673 expect(fo.getOperand(0).key()).toEqual('Titel');
1674 expect(fo.getOperand(0).value()).toEqual('Baum');
1675 expect(fo.getOperand(1).ldType()).toEqual('doc');
1676 expect(fo.getOperand(2).ldType()).toEqual('docGroup');
1677 });
1678
1679
1680 it('should add on parent group (case "and")', function () {
1681 var vc = complexVCFactory.create();
1682
1683 // Wrap with direct element access
1684 expect(vc.toQuery()).toEqual(
1685 'pubDate in 2014-12-05 & (title = "Hello World!" | foo = "bar")'
1686 );
1687
1688 expect(vc.root().operands().length).toEqual(2);
1689
1690 // Add unspecified on the root group
1691 _andOn(vc.root().getOperand(1));
1692 expect(vc.toQuery()).toEqual(
1693 'pubDate in 2014-12-05 & (title = "Hello World!" | foo = "bar")'
1694 );
1695
1696 expect(vc.root().ldType()).toEqual('docGroup');
1697 expect(vc.root().operands().length).toEqual(3);
1698 expect(vc.root().getOperand(0).ldType()).toEqual('doc');
1699 expect(vc.root().getOperand(1).ldType()).toEqual('docGroup');
1700 expect(vc.root().getOperand(1).operation()).toEqual('or');
1701 expect(vc.root().getOperand(2).ldType()).toEqual('non');
1702
1703 // Add another unspecified on the root group
1704 _andOn(vc.root().getOperand(1));
1705
1706 expect(vc.root().operands().length).toEqual(4);
1707 expect(vc.root().getOperand(0).ldType()).toEqual('doc');
1708 expect(vc.root().getOperand(1).ldType()).toEqual('docGroup');
1709 expect(vc.root().getOperand(2).ldType()).toEqual('non');
1710 expect(vc.root().getOperand(3).ldType()).toEqual('non');
1711
1712 // Add another unspecified after the first doc
1713 _andOn(vc.root().getOperand(0));
1714
1715 expect(vc.root().operands().length).toEqual(5);
1716 expect(vc.root().getOperand(0).ldType()).toEqual('doc');
1717 expect(vc.root().getOperand(1).ldType()).toEqual('non');
1718 expect(vc.root().getOperand(2).ldType()).toEqual('docGroup');
1719 expect(vc.root().getOperand(3).ldType()).toEqual('non');
1720 expect(vc.root().getOperand(4).ldType()).toEqual('non');
1721 });
1722
1723 it('should wrap on root', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00001724 var vc = vcClass.create().fromJson(
Nils Diewald7c8ced22015-04-15 19:21:00 +00001725 {
1726 "@type": 'koral:docGroup',
1727 'operation' : 'operation:and',
1728 'operands' : [
1729 {
1730 "@type": 'koral:doc',
1731 "key": 'pubDate',
1732 "match": 'match:eq',
1733 "value": '2014-12-05',
1734 "type": 'type:date'
1735 },
1736 {
1737 "@type" : 'koral:doc',
1738 'key' : 'foo',
1739 'value' : 'bar'
1740 }
1741 ]
1742 }
1743 );
1744
1745 // Wrap on root
1746 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar"');
1747 expect(vc.root().ldType()).toEqual('docGroup');
1748 expect(vc.root().operation()).toEqual('and');
1749 _orOn(vc.root());
1750 expect(vc.root().ldType()).toEqual('docGroup');
1751 expect(vc.root().operation()).toEqual('or');
1752
1753 expect(vc.root().getOperand(0).ldType()).toEqual('docGroup');
1754 expect(vc.root().getOperand(0).operation()).toEqual('and');
1755 });
1756
1757 it('should add on root (case "and")', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00001758 var vc = vcClass.create().fromJson(
Nils Diewald7c8ced22015-04-15 19:21:00 +00001759 {
1760 "@type": 'koral:doc',
1761 "key": 'pubDate',
1762 "match": 'match:eq',
1763 "value": '2014-12-05',
1764 "type": 'type:date'
1765 }
1766 );
1767
1768 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05');
1769 expect(vc.root().ldType()).toEqual('doc');
1770 expect(vc.root().key()).toEqual('pubDate');
1771 expect(vc.root().value()).toEqual('2014-12-05');
1772
1773 // Wrap on root
1774 _andOn(vc.root());
1775 expect(vc.root().ldType()).toEqual('docGroup');
1776 expect(vc.root().operation()).toEqual('and');
1777 });
1778
1779 it('should add on root (case "or")', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00001780 var vc = vcClass.create().fromJson(
Nils Diewald7c8ced22015-04-15 19:21:00 +00001781 {
1782 "@type": 'koral:doc',
1783 "key": 'pubDate',
1784 "match": 'match:eq',
1785 "value": '2014-12-05',
1786 "type": 'type:date'
1787 }
1788 );
1789
1790 expect(vc.toQuery()).toEqual('pubDate in 2014-12-05');
1791 expect(vc.root().key()).toEqual('pubDate');
1792 expect(vc.root().value()).toEqual('2014-12-05');
1793
1794 // Wrap on root
1795 _orOn(vc.root());
1796 expect(vc.root().ldType()).toEqual('docGroup');
1797 expect(vc.root().operation()).toEqual('or');
1798 });
1799
1800 it('should support multiple sub groups per group', function () {
Nils Diewald6283d692015-04-23 20:32:53 +00001801 var vc = vcClass.create().fromJson(
Nils Diewald7c8ced22015-04-15 19:21:00 +00001802 {
1803 "@type": 'koral:docGroup',
1804 'operation' : 'operation:or',
1805 'operands' : [
1806 {
1807 "@type": 'koral:docGroup',
1808 'operation' : 'operation:and',
1809 'operands' : [
1810 {
1811 "@type": 'koral:doc',
1812 "key": 'title',
1813 "value": 't1',
1814 },
1815 {
1816 "@type" : 'koral:doc',
1817 'key' : 'title',
1818 'value' : 't2'
1819 }
1820 ]
1821 },
1822 {
1823 "@type": 'koral:docGroup',
1824 'operation' : 'operation:and',
1825 'operands' : [
1826 {
1827 "@type": 'koral:doc',
1828 "key": 'title',
1829 "value": 't3',
1830 },
1831 {
1832 "@type" : 'koral:doc',
1833 'key' : 'title',
1834 'value' : 't4'
1835 }
1836 ]
1837 }
1838 ]
1839 }
1840 );
1841 expect(vc.toQuery()).toEqual(
1842 '(title = "t1" & title = "t2") | ' +
1843 '(title = "t3" & title = "t4")'
1844 );
1845 expect(vc.root().operation()).toEqual('or');
1846 expect(vc.root().getOperand(0).toQuery()).toEqual('title = "t1" & title = "t2"');
1847 expect(vc.root().getOperand(1).toQuery()).toEqual('title = "t3" & title = "t4"');
1848
1849 _andOn(vc.root());
1850
1851 expect(vc.root().operation()).toEqual('and');
1852 expect(vc.root().getOperand(0).ldType()).toEqual('docGroup');
1853 expect(vc.root().getOperand(1).ldType()).toEqual('non');
1854 });
1855 });
1856
Nils Diewald7c8ced22015-04-15 19:21:00 +00001857
Nils Diewald6283d692015-04-23 20:32:53 +00001858
1859 describe('KorAP.Rewrite', function () {
Nils Diewald7c8ced22015-04-15 19:21:00 +00001860 it('should be initializable', function () {
1861 var rewrite = rewriteClass.create({
1862 "@type" : "koral:rewrite",
1863 "operation" : "operation:modification",
1864 "src" : "querySerializer",
1865 "scope" : "tree"
Nils Diewald86dad5b2015-01-28 15:09:07 +00001866 });
Nils Diewald7c8ced22015-04-15 19:21:00 +00001867 expect(rewrite.toString()).toEqual('Modification of "tree" by "querySerializer"');
1868 });
Nils Diewald86dad5b2015-01-28 15:09:07 +00001869
Nils Diewald7c8ced22015-04-15 19:21:00 +00001870 it('should be deserialized by docs', function () {
1871 var doc = docClass.create(
1872 undefined,
1873 {
1874 "@type":"koral:doc",
1875 "key":"Titel",
1876 "value":"Baum",
1877 "match":"match:eq"
1878 });
1879
1880 expect(doc.element().classList.contains('doc')).toBeTruthy();
1881 expect(doc.element().classList.contains('rewritten')).toBe(false);
1882
1883 doc = docClass.create(
1884 undefined,
1885 {
1886 "@type":"koral:doc",
1887 "key":"Titel",
1888 "value":"Baum",
1889 "match":"match:eq",
1890 "rewrites" : [
1891 {
1892 "@type" : "koral:rewrite",
1893 "operation" : "operation:modification",
1894 "src" : "querySerializer",
1895 "scope" : "tree"
1896 }
1897 ]
1898 });
1899
1900 expect(doc.element().classList.contains('doc')).toBeTruthy();
1901 expect(doc.element().classList.contains('rewritten')).toBeTruthy();
1902 });
Nils Diewald6283d692015-04-23 20:32:53 +00001903
1904 xit('should be deserialized by docGroups', function () {
1905 var docGroup = docGroupClass.create(
1906 undefined,
1907 {
1908 "@type" : "koral:docGroup",
1909 "operation" : "operation:or",
1910 "operands" : [
1911 {
1912 "@type" : "doc",
1913 "key" : "pubDate",
1914 "type" : "type:date",
1915 "value" : "2014-12-05"
1916 },
1917 {
1918 "@type" : "doc",
1919 "key" : "pubDate",
1920 "type" : "type:date",
1921 "value" : "2014-12-06"
1922 }
1923 ],
1924 "rewrites" : [
1925 {
1926 "@type" : "koral:rewrite",
1927 "operation" : "operation:modification",
1928 "src" : "querySerializer",
1929 "scope" : "tree"
1930 }
1931 ]
1932 }
1933 );
1934
1935 expect(doc.element().classList.contains('docgroup')).toBeTruthy();
1936 expect(doc.element().classList.contains('rewritten')).toBe(false);
1937 });
Nils Diewald86dad5b2015-01-28 15:09:07 +00001938 });
Nils Diewald7c8ced22015-04-15 19:21:00 +00001939 /*
1940 describe('KorAP.DocKey', function () {
1941 it('should be initializable', function () {
Nils Diewald2fe12e12015-03-06 16:47:06 +00001942 var docKey = KorAP.DocKey.create();
1943 expect(docKey.toString()).toEqual('...');
Nils Diewald7c8ced22015-04-15 19:21:00 +00001944 });
1945 });
1946 */
Nils Diewald2fe12e12015-03-06 16:47:06 +00001947});