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