blob: 2010adff4522734097c91f18c815e8f83dd26089 [file] [log] [blame]
Nils Diewald0b6c0412014-12-19 03:55:57 +00001// Helper method for building factories
2buildFactory = function (objClass, defaults) {
3 return {
4 create : function (overwrites) {
5 var newObj = {};
6 for (var prop in defaults) {
7 newObj[prop] = defaults[prop];
8 };
9 for (var prop in overwrites) {
10 newObj[prop] = overwrites[prop];
11 };
12 return objClass.create().fromJson(newObj);
13 }
14 }
15};
16
17describe('KorAP.Doc', function () {
18
19 // Create example factories
20 var stringFactory = buildFactory(KorAP.Doc, {
21 "key" : "author",
22 "value" : "Max Birkendale",
23 "@type" : "korap:doc"
24 });
25
26 // Create example factories
27 var dateFactory = buildFactory(KorAP.Doc, {
28 "key" : "pubDate",
29 "type" : "type:date",
30 "match" : "match:eq",
31 "value" : "2014-11-05",
32 "@type" : "korap:doc"
33 });
34
35 // Create example factories
36 var regexFactory = buildFactory(KorAP.Doc, {
37 "key" : "title",
38 "type" : "type:regex",
39 "value" : "[^b]ee.+?",
40 "@type" : "korap:doc"
41 });
42
43 it('should be initializable', function () {
44 var doc = KorAP.Doc.create();
45 expect(doc.matchop()).toEqual('eq');
46 expect(doc.key()).toBeUndefined();
47 expect(doc.value()).toBeUndefined();
48 expect(doc.type()).toEqual("string");
49 });
50
51 it('should be definable', function () {
52
53 // Empty doc
54 var doc = KorAP.Doc.create();
55
56 // Set values
57 doc.key("title");
58 doc.value("Der alte Mann");
59 expect(doc.matchop()).toEqual('eq');
60 expect(doc.key()).toEqual("title");
61 expect(doc.type()).toEqual("string");
62 expect(doc.value()).toEqual("Der alte Mann");
63 });
64
65
66 it('should deserialize JSON-LD string', function () {
67 var doc;
68
69 // String default
70 doc = stringFactory.create();
71 expect(doc.matchop()).toEqual('eq');
72 expect(doc.key()).toEqual("author");
73 expect(doc.type()).toEqual("string");
74 expect(doc.value()).toEqual("Max Birkendale");
75
76 // No valid string
77 doc = stringFactory.create({
78 value : undefined
79 });
80 expect(doc).toBeUndefined();
81
82 // No valid string
83 doc = stringFactory.create({
84 value : { "foo" : "bar" }
85 });
86 expect(doc).toBeUndefined();
87
88 // Change match type
89 doc = stringFactory.create({
90 "match" : "match:ne"
91 });
92
93 expect(doc.matchop()).toEqual('ne');
94 expect(doc.key()).toEqual("author");
95 expect(doc.type()).toEqual("string");
96 expect(doc.value()).toEqual("Max Birkendale");
97
98
99 // Invalid match type
100 doc = stringFactory.create({
101 "match" : { "foo" : "bar" }
102 });
103 expect(doc).toBeUndefined();
104 });
105
106 it('should deserialize JSON-LD regex', function () {
107 var doc = regexFactory.create();
108 expect(doc.key()).toEqual("title");
109 expect(doc.type()).toEqual("regex");
110 expect(doc.value()).toEqual("[^b]ee.+?");
111 expect(doc.matchop()).toEqual('eq');
112
113 // change matcher
114 doc = regexFactory.create({
115 match : "match:ne"
116 });
117 expect(doc.matchop()).toEqual('ne');
118
119 // Invalid matcher
120 doc = regexFactory.create({
121 match : "match:chook"
122 });
123 expect(doc).toBeUndefined();
124
125 // Invalid regex
126 doc = regexFactory.create({
127 value : "[^b"
128 });
129 expect(doc).toBeUndefined();
130 });
131
132 it('should deserialize JSON-LD date', function () {
133
134 // Normal date
135 doc = dateFactory.create({});
136
137 expect(doc.matchop()).toEqual('eq');
138 expect(doc.key()).toEqual("pubDate");
139 expect(doc.type()).toEqual("date");
140 expect(doc.value()).toEqual("2014-11-05");
141
142 // Short date 1
143 doc = dateFactory.create({
144 "value" : "2014-11"
145 });
146
147 expect(doc.matchop()).toEqual('eq');
148 expect(doc.key()).toEqual("pubDate");
149 expect(doc.type()).toEqual("date");
150 expect(doc.value()).toEqual("2014-11");
151
152 // Short date 2
153 doc = dateFactory.create({
154 "value" : "2014"
155 });
156
157 expect(doc.matchop()).toEqual('eq');
158 expect(doc.key()).toEqual("pubDate");
159 expect(doc.type()).toEqual("date");
160 expect(doc.value()).toEqual("2014");
161
162 // Invalid date!
163 doc = dateFactory.create({
164 "value" : "2014-11-050"
165 });
166 expect(doc).toBeUndefined();
167
168 // Invalid matcher!
169 doc = dateFactory.create({
170 "match" : "match:ne",
171 });
172 expect(doc).toBeUndefined();
173 });
174
175 it('should be serializale', function () {
176
177 // Empty doc
178 var doc = KorAP.Doc.create();
179 expect(doc.toJson()).toEqual(jasmine.any(Object));
180
181 // Serialize string
182 doc = stringFactory.create();
183 expect(doc.toJson()).toEqual(jasmine.objectContaining({
184 "@type" : "korap:doc",
185 "type" : "type:string",
186 "key" : "author",
187 "value" : "Max Birkendale",
188 "match" : "match:eq"
189 }));
190
191 // Serialize regex
192 doc = regexFactory.create();
193 expect(doc.toJson()).toEqual(jasmine.objectContaining({
194 "@type" : "korap:doc",
195 "type" : "type:regex",
196 "value" : "[^b]ee.+?",
197 "match" : "match:eq",
198 "key" : 'title'
199 }));
200
201 doc = regexFactory.create({
202 match: "match:ne"
203 });
204 expect(doc.toJson()).toEqual(jasmine.objectContaining({
205 "@type" : "korap:doc",
206 "type" : "type:regex",
207 "value" : "[^b]ee.+?",
208 "match" : "match:ne",
209 "key" : 'title'
210 }));
211
212 doc = dateFactory.create();
213 expect(doc.toJson()).toEqual(jasmine.objectContaining({
214 "@type" : "korap:doc",
215 "type" : "type:date",
216 "value" : "2014-11-05",
217 "match" : "match:eq",
218 "key" : 'pubDate'
219 }));
220
221 doc = dateFactory.create({
222 value : "2014"
223 });
224 expect(doc.toJson()).toEqual(jasmine.objectContaining({
225 "@type" : "korap:doc",
226 "type" : "type:date",
227 "value" : "2014",
228 "match" : "match:eq",
229 "key" : 'pubDate'
230 }));
231 });
232});
233
234
235describe('KorAP.DocGroup', function () {
236 // Create example factories
237 var docFactory = buildFactory(
238 KorAP.Doc,
239 {
240 "@type" : "korap:doc",
241 "match":"match:eq",
242 "key" : "author",
243 "value" : "Max Birkendale"
244 }
245 );
246
247 var docGroupFactory = buildFactory(
248 KorAP.DocGroup, {
249 "@type" : "korap:docGroup",
250 "operation" : "operation:and",
251 "operands" : [
252 docFactory.create().toJson(),
253 docFactory.create({
254 "key" : "pubDate",
255 "type" : "type:date",
256 "value" : "2014-12-05"
257 }).toJson()
258 ]
259 });
260
Nils Diewald0b6c0412014-12-19 03:55:57 +0000261
Nils Diewald8f4e2542014-12-19 04:42:09 +0000262 it('should be initializable', function () {
Nils Diewald0b6c0412014-12-19 03:55:57 +0000263 // Create empty group
264 var docGroup = KorAP.DocGroup.create();
265 expect(docGroup.operation()).toEqual('and');
266
267 // Create empty group
Nils Diewald8f4e2542014-12-19 04:42:09 +0000268 docGroup = KorAP.DocGroup.create();
269 docGroup.operation('or');
Nils Diewald0b6c0412014-12-19 03:55:57 +0000270 expect(docGroup.operation()).toEqual('or');
271 });
272
273 it('should be definable', function () {
274
275 // Empty group
276 var docGroup = KorAP.DocGroup.create();
277 expect(docGroup.operation()).toEqual('and');
278
279 // Set values
280 docGroup.operation("or");
281 expect(docGroup.operation()).toEqual('or');
282
283 // Set invalid values
284 docGroup.operation("hui");
285 expect(docGroup.operation()).toEqual('or');
286 });
287
288 it('should be deserializable', function () {
289 var docGroup = docGroupFactory.create();
290 expect(docGroup.operation()).toEqual("and");
291 expect(docGroup.operands().length).toEqual(2);
292
293 var op1 = docGroup.getOperand(0);
294 expect(op1.type()).toEqual("string");
295 expect(op1.key()).toEqual("author");
296 expect(op1.value()).toEqual("Max Birkendale");
297 expect(op1.matchop()).toEqual("eq");
298
299 var op2 = docGroup.getOperand(1);
300 expect(op2.type()).toEqual("date");
301 expect(op2.key()).toEqual("pubDate");
302 expect(op2.value()).toEqual("2014-12-05");
303 expect(op2.matchop()).toEqual("eq");
304
305 // Create empty group
Nils Diewald966abf12014-12-20 02:27:45 +0000306 var newGroup = docGroup.append(KorAP.DocGroup.create());
Nils Diewald8f4e2542014-12-19 04:42:09 +0000307 newGroup.operation('or');
Nils Diewald966abf12014-12-20 02:27:45 +0000308 newGroup.append(docFactory.create());
309 newGroup.append(docFactory.create({
Nils Diewald0b6c0412014-12-19 03:55:57 +0000310 "type" : "type:regex",
311 "key" : "title",
312 "value" : "^e.+?$",
313 "match" : "match:ne"
314 }));
315
316 expect(docGroup.operation()).toEqual("and");
317 expect(docGroup.operands().length).toEqual(3);
318
319 var op1 = docGroup.getOperand(0);
320 expect(op1.ldType()).toEqual("doc");
321 expect(op1.type()).toEqual("string");
322 expect(op1.key()).toEqual("author");
323 expect(op1.value()).toEqual("Max Birkendale");
324 expect(op1.matchop()).toEqual("eq");
325
326 var op2 = docGroup.getOperand(1);
327 expect(op2.ldType()).toEqual("doc");
328 expect(op2.type()).toEqual("date");
329 expect(op2.key()).toEqual("pubDate");
330 expect(op2.value()).toEqual("2014-12-05");
331 expect(op2.matchop()).toEqual("eq");
332
333 var op3 = docGroup.getOperand(2);
334 expect(op3.ldType()).toEqual("docGroup");
335 expect(op3.operation()).toEqual("or");
336
337 var op4 = op3.getOperand(0);
338 expect(op4.ldType()).toEqual("doc");
339 expect(op4.type()).toEqual("string");
340 expect(op4.key()).toEqual("author");
341 expect(op4.value()).toEqual("Max Birkendale");
342 expect(op4.matchop()).toEqual("eq");
343
344 var op5 = op3.getOperand(1);
345 expect(op5.ldType()).toEqual("doc");
346 expect(op5.type()).toEqual("regex");
347 expect(op5.key()).toEqual("title");
348 expect(op5.value()).toEqual("^e.+?$");
349 expect(op5.matchop()).toEqual("ne");
350 });
351
352 it('should be serializable', function () {
353 var docGroup = docGroupFactory.create();
354
355 expect(docGroup.toJson()).toEqual(jasmine.objectContaining({
356 "@type" : "korap:docGroup",
357 "operation" : "operation:and",
358 "operands" : [
359 {
360 "@type": 'korap:doc',
361 "key" : 'author',
362 "match": 'match:eq',
363 "value": 'Max Birkendale',
364 "type": 'type:string'
365 },
366 {
367 "@type": 'korap:doc',
368 "key": 'pubDate',
369 "match": 'match:eq',
370 "value": '2014-12-05',
371 "type": 'type:date'
372 }
373 ]
374 }));
375 });
376});
377
Nils Diewald966abf12014-12-20 02:27:45 +0000378describe('KorAP.UnspecifiedDoc', function () {
379 it('should be initializable', function () {
380 var docElement = KorAP.UnspecifiedDoc.create().element();
381 expect(docElement.getAttribute('class')).toEqual('unspecified');
382 expect(docElement.firstChild.firstChild.data).toEqual('⋯');
383 expect(docElement.lastChild.getAttribute('class')).toEqual('operators');
384
385 // Not removable
386 expect(docElement.lastChild.children.length).toEqual(0);
387 });
388
389 it('should be removable, when no root', function () {
390 var docGroup = KorAP.DocGroup.create();
391 docGroup.operation('or');
392 expect(docGroup.operation()).toEqual('or');
393
394 docGroup.append({
395 "@type": 'korap:doc',
396 "key": 'pubDate',
397 "match": 'match:eq',
398 "value": '2014-12-05',
399 "type": 'type:date'
400 });
401
402 expect(docGroup.element().getAttribute('class')).toEqual('docGroup');
403 expect(docGroup.element().children[0].getAttribute('class')).toEqual('doc');
404
405 // Add unspecified object
406 docGroup.append();
407 var unspec = docGroup.element().children[1];
408 expect(unspec.getAttribute('class')).toEqual('unspecified');
409
410 // Removable
411 expect(unspec.lastChild.children.length).toEqual(1);
412 expect(unspec.lastChild.children[0].getAttribute('class')).toEqual('delete');
413 });
414});
415
Nils Diewald8f4e2542014-12-19 04:42:09 +0000416describe('KorAP.Doc element', function () {
Nils Diewald0b6c0412014-12-19 03:55:57 +0000417 it('should be initializable', function () {
Nils Diewald8f4e2542014-12-19 04:42:09 +0000418 var docElement = KorAP.Doc.create(undefined, {
Nils Diewald0b6c0412014-12-19 03:55:57 +0000419 "@type" : "korap:doc",
420 "key":"Titel",
421 "value":"Baum",
422 "match":"match:eq"
423 });
424 expect(docElement.key()).toEqual('Titel');
425 expect(docElement.matchop()).toEqual('eq');
426 expect(docElement.value()).toEqual('Baum');
427
428 var docE = docElement.element();
429 expect(docE.children[0].firstChild.data).toEqual('Titel');
430 expect(docE.children[1].firstChild.data).toEqual('eq');
431 expect(docE.children[1].getAttribute('data-type')).toEqual('string');
432 expect(docE.children[2].firstChild.data).toEqual('Baum');
433 expect(docE.children[2].getAttribute('data-type')).toEqual('string');
434
435 expect(docElement.toJson()).toEqual(jasmine.objectContaining({
436 "@type" : "korap:doc",
437 "key":"Titel",
438 "value":"Baum",
439 "match":"match:eq"
440 }));
441 });
442});
443
Nils Diewald8f4e2542014-12-19 04:42:09 +0000444describe('KorAP.DocGroup element', function () {
Nils Diewald0b6c0412014-12-19 03:55:57 +0000445 it('should be initializable', function () {
446
Nils Diewald8f4e2542014-12-19 04:42:09 +0000447 var docGroup = KorAP.DocGroup.create(undefined, {
Nils Diewald0b6c0412014-12-19 03:55:57 +0000448 "@type" : "korap:docGroup",
449 "operation" : "operation:and",
450 "operands" : [
451 {
452 "@type": 'korap:doc',
453 "key" : 'author',
454 "match": 'match:eq',
455 "value": 'Max Birkendale',
456 "type": 'type:string'
457 },
458 {
459 "@type": 'korap:doc',
460 "key": 'pubDate',
461 "match": 'match:eq',
462 "value": '2014-12-05',
463 "type": 'type:date'
464 }
465 ]
466 });
467
Nils Diewald8f4e2542014-12-19 04:42:09 +0000468 expect(docGroup.operation()).toEqual('and');
469 var e = docGroup.element();
Nils Diewald0b6c0412014-12-19 03:55:57 +0000470 expect(e.getAttribute('class')).toEqual('docGroup');
471 expect(e.getAttribute('data-operation')).toEqual('and');
472
473 var first = e.children[0];
474 expect(first.getAttribute('class')).toEqual('doc');
475 expect(first.children[0].getAttribute('class')).toEqual('key');
476 expect(first.children[1].getAttribute('class')).toEqual('match');
477 expect(first.children[2].getAttribute('class')).toEqual('value');
478 expect(first.children[2].getAttribute('data-type')).toEqual('string');
479 expect(first.children[0].firstChild.data).toEqual('author');
480 expect(first.children[1].firstChild.data).toEqual('eq');
481 expect(first.children[2].firstChild.data).toEqual('Max Birkendale');
482
483 var second = e.children[1];
484 expect(second.getAttribute('class')).toEqual('doc');
485 expect(second.children[0].getAttribute('class')).toEqual('key');
486 expect(second.children[1].getAttribute('class')).toEqual('match');
487 expect(second.children[2].getAttribute('class')).toEqual('value');
488 expect(second.children[2].getAttribute('data-type')).toEqual('date');
489 expect(second.children[0].firstChild.data).toEqual('pubDate');
490 expect(second.children[1].firstChild.data).toEqual('eq');
491 expect(second.children[2].firstChild.data).toEqual('2014-12-05');
492
493 });
494
495 it('should be deserializable with nested groups', function () {
Nils Diewald8f4e2542014-12-19 04:42:09 +0000496 var docGroup = KorAP.DocGroup.create(undefined, {
Nils Diewald0b6c0412014-12-19 03:55:57 +0000497 "@type" : "korap:docGroup",
498 "operation" : "operation:or",
499 "operands" : [
500 {
501 "@type": 'korap:doc',
502 "key" : 'author',
503 "match": 'match:eq',
504 "value": 'Max Birkendale',
505 "type": 'type:string'
506 },
507 {
508 "@type" : "korap:docGroup",
509 "operation" : "operation:and",
510 "operands" : [
511 {
512 "@type": 'korap:doc',
513 "key": 'pubDate',
514 "match": 'match:geq',
515 "value": '2014-05-12',
516 "type": 'type:date'
517 },
518 {
519 "@type": 'korap:doc',
520 "key": 'pubDate',
521 "match": 'match:leq',
522 "value": '2014-12-05',
523 "type": 'type:date'
524 }
525 ]
526 }
527 ]
528 });
529
Nils Diewald8f4e2542014-12-19 04:42:09 +0000530 expect(docGroup.operation()).toEqual('or');
531 var e = docGroup.element();
Nils Diewald0b6c0412014-12-19 03:55:57 +0000532 expect(e.getAttribute('class')).toEqual('docGroup');
533 expect(e.getAttribute('data-operation')).toEqual('or');
534
Nils Diewald966abf12014-12-20 02:27:45 +0000535 expect(e.children[0].getAttribute('class')).toEqual('doc');
536 var docop = e.children[0].lastChild;
537 expect(docop.getAttribute('class')).toEqual('operators');
538 expect(docop.children[0].getAttribute('class')).toEqual('and');
539 expect(docop.children[1].getAttribute('class')).toEqual('or');
540 expect(docop.children[2].getAttribute('class')).toEqual('delete');
541
542 expect(e.children[1].getAttribute('class')).toEqual('docGroup');
543 expect(e.children[1].getAttribute('data-operation')).toEqual('and');
544
545 // This and-operation can be "or"ed or "delete"d
546 var secop = e.children[1].children[2];
547 expect(secop.getAttribute('class')).toEqual('operators');
548 expect(secop.children[0].getAttribute('class')).toEqual('or');
549 expect(secop.children[1].getAttribute('class')).toEqual('delete');
550
551 // This or-operation can be "and"ed or "delete"d
552 expect(e.children[2].getAttribute('class')).toEqual('operators');
553 expect(e.lastChild.getAttribute('class')).toEqual('operators');
554 expect(e.lastChild.children[0].getAttribute('class')).toEqual('and');
555 expect(e.lastChild.children[1].getAttribute('class')).toEqual('delete');
Nils Diewald0b6c0412014-12-19 03:55:57 +0000556
557 });
558});
559
560describe('KorAP.VirtualCollection', function () {
561 it('should be initializable', function () {
562 var vc = KorAP.VirtualCollection.render();
563 expect(vc.element().getAttribute('class')).toEqual('vc');
Nils Diewald966abf12014-12-20 02:27:45 +0000564 expect(vc.root().element().getAttribute('class')).toEqual('unspecified');
565
566 // Not removable
567 expect(vc.root().element().lastChild.children.length).toEqual(0);
Nils Diewald0b6c0412014-12-19 03:55:57 +0000568 });
569
570 it('should be based on a doc', function () {
571 var vc = KorAP.VirtualCollection.render({
572 "@type" : "korap:doc",
573 "key":"Titel",
574 "value":"Baum",
575 "match":"match:eq"
576 });
577
578 expect(vc.element().getAttribute('class')).toEqual('vc');
579 expect(vc.root().element().getAttribute('class')).toEqual('doc');
580 expect(vc.root().key()).toEqual('Titel');
581 expect(vc.root().value()).toEqual('Baum');
582 expect(vc.root().matchop()).toEqual('eq');
583
584 var docE = vc.root().element();
585 expect(docE.children[0].firstChild.data).toEqual('Titel');
586 expect(docE.children[1].firstChild.data).toEqual('eq');
587 expect(docE.children[1].getAttribute('data-type')).toEqual('string');
588 expect(docE.children[2].firstChild.data).toEqual('Baum');
589 expect(docE.children[2].getAttribute('data-type')).toEqual('string');
590 });
591
592 it('should be based on a docGroup', function () {
593 var vc = KorAP.VirtualCollection.render({
594 "@type" : "korap:docGroup",
595 "operation" : "operation:and",
596 "operands" : [
597 {
598 "@type": 'korap:doc',
599 "key" : 'author',
600 "match": 'match:eq',
601 "value": 'Max Birkendale',
602 "type": 'type:string'
603 },
604 {
605 "@type": 'korap:doc',
606 "key": 'pubDate',
607 "match": 'match:eq',
608 "value": '2014-12-05',
609 "type": 'type:date'
610 }
611 ]
612 });
613
614 expect(vc.element().getAttribute('class')).toEqual('vc');
615 expect(vc.root().element().getAttribute('class')).toEqual('docGroup');
616 expect(vc.root().operation()).toEqual('and');
617
618 var docGroup = vc.root();
619
620 var first = docGroup.getOperand(0);
621 expect(first.key()).toEqual('author');
622 expect(first.value()).toEqual('Max Birkendale');
623 expect(first.matchop()).toEqual('eq');
624
625 var second = docGroup.getOperand(1);
626 expect(second.key()).toEqual('pubDate');
627 expect(second.value()).toEqual('2014-12-05');
628 expect(second.matchop()).toEqual('eq');
629 });
630
Nils Diewald966abf12014-12-20 02:27:45 +0000631 it('should be based on a nested docGroup', function () {
632 var vc = KorAP.VirtualCollection.render({
633 "@type" : "korap:docGroup",
Nils Diewald0297ba12015-01-05 21:56:12 +0000634 "operation" : "operation:and",
635 "operands" : [
636 {
637 "@type": 'korap:doc',
638 "key": 'pubDate',
639 "match": 'match:geq',
640 "value": '2014-05-12',
641 "type": 'type:date'
642 },
643 {
644 "@type": 'korap:doc',
645 "key": 'pubDate',
646 "match": 'match:leq',
647 "value": '2014-12-05',
648 "type": 'type:date'
649 },
650 {
651 "@type": 'korap:doc',
652 "key": 'foo',
653 "match": 'match:eq',
654 "value": 'bar',
655 "type": 'type:string'
656 }
657 ]
658 });
659
660 var docGroup = vc.root();
661 var doc = docGroup.getOperand(1);
662 expect(doc.key()).toEqual("pubDate");
663 expect(docGroup.delOperand(doc)).toEqual(true);
664 doc = docGroup.getOperand(1);
665 expect(doc.key()).toEqual("foo");
666 });
667
668 it('should be modifiable', function () {
669 var vc = KorAP.VirtualCollection.render();
670
671 var vc = KorAP.VirtualCollection.render({
672 "@type" : "korap:docGroup",
673 "operation" : "operation:and",
Nils Diewald966abf12014-12-20 02:27:45 +0000674 "operands" : [
675 {
676 "@type": 'korap:doc',
677 "key" : 'author',
678 "match": 'match:eq',
679 "value": 'Max Birkendale',
680 "type": 'type:string'
681 },
682 {
Nils Diewald0297ba12015-01-05 21:56:12 +0000683 "@type": 'korap:doc',
684 "key": 'pubDate',
685 "match": 'match:eq',
686 "value": '2014-12-05',
687 "type": 'type:date'
Nils Diewald966abf12014-12-20 02:27:45 +0000688 }
689 ]
690 });
Nils Diewald0297ba12015-01-05 21:56:12 +0000691
Nils Diewald966abf12014-12-20 02:27:45 +0000692 expect(vc.element().getAttribute('class')).toEqual('vc');
Nils Diewald0297ba12015-01-05 21:56:12 +0000693 expect(vc.root().element().getAttribute('class')).toEqual('docGroup');
694 expect(vc.root().operation()).toEqual('and');
695 });
Nils Diewald0b6c0412014-12-19 03:55:57 +0000696});
697
698describe('KorAP.Operators', function () {
699 it('should be initializable', function () {
700 var op = KorAP.Operators.create(true, false, false);
701 expect(op.and()).toBeTruthy();
702 expect(op.or()).not.toBeTruthy();
703 expect(op.del()).not.toBeTruthy();
704
705 op.and(false);
706 expect(op.and()).not.toBeTruthy();
707 expect(op.or()).not.toBeTruthy();
708 expect(op.del()).not.toBeTruthy();
709
710 op.or(true);
711 op.del(true);
712 expect(op.and()).not.toBeTruthy();
713 expect(op.or()).toBeTruthy();
714 expect(op.del()).toBeTruthy();
715
716 var e = op.element();
717 expect(e.getAttribute('class')).toEqual('operators');
718 expect(e.children[0].getAttribute('class')).toEqual('or');
719 expect(e.children[0].firstChild.data).toEqual('or');
720 expect(e.children[1].getAttribute('class')).toEqual('delete');
721 expect(e.children[1].firstChild.data).toEqual('×');
722
723 op.and(true);
724 op.del(false);
725 op.update();
726
727 e = op.element();
728 expect(e.getAttribute('class')).toEqual('operators');
729 expect(e.children[0].getAttribute('class')).toEqual('and');
730 expect(e.children[0].firstChild.data).toEqual('and');
731 expect(e.children[1].getAttribute('class')).toEqual('or');
732 expect(e.children[1].firstChild.data).toEqual('or');
733 });
734});