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