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