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