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 | */ |
Akron | dd5c6d3 | 2018-08-17 14:12:58 +0200 | [diff] [blame] | 4 | define([ |
| 5 | 'vc', |
| 6 | 'vc/doc', |
| 7 | 'vc/menu', |
| 8 | 'vc/prefix', |
| 9 | 'vc/docgroup', |
| 10 | 'vc/docgroupref', |
| 11 | 'vc/unspecified', |
| 12 | 'vc/operators', |
| 13 | 'vc/rewrite', |
| 14 | 'vc/stringval' |
| 15 | ], function (vcClass, |
| 16 | docClass, |
| 17 | menuClass, |
| 18 | prefixClass, |
| 19 | docGroupClass, |
| 20 | docGroupRefClass, |
| 21 | unspecifiedClass, |
| 22 | operatorsClass, |
| 23 | rewriteClass, |
| 24 | stringValClass) { |
Nils Diewald | 6ac292b | 2015-01-15 21:33:21 +0000 | [diff] [blame] | 25 | |
Akron | dd5c6d3 | 2018-08-17 14:12:58 +0200 | [diff] [blame] | 26 | KorAP._vcKeyMenu = undefined; |
| 27 | |
Nils Diewald | 6ac292b | 2015-01-15 21:33:21 +0000 | [diff] [blame] | 28 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 29 | // Helper method for building factories |
| 30 | buildFactory = function (objClass, defaults) { |
| 31 | return { |
| 32 | create : function (overwrites) { |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 33 | var newObj = {}; |
| 34 | for (var prop in defaults) { |
| 35 | newObj[prop] = defaults[prop]; |
| 36 | }; |
| 37 | for (var prop in overwrites) { |
| 38 | newObj[prop] = overwrites[prop]; |
| 39 | }; |
| 40 | return objClass.create().fromJson(newObj); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 41 | } |
Nils Diewald | 0b6c041 | 2014-12-19 03:55:57 +0000 | [diff] [blame] | 42 | } |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 43 | }; |
Nils Diewald | 0b6c041 | 2014-12-19 03:55:57 +0000 | [diff] [blame] | 44 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 45 | function _andOn (obj) { |
Akron | d141a36 | 2018-07-10 18:12:13 +0200 | [diff] [blame] | 46 | KorAP._and.apply(obj); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 47 | }; |
Nils Diewald | 52f7eb1 | 2015-01-12 17:30:04 +0000 | [diff] [blame] | 48 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 49 | function _orOn (obj) { |
Akron | d141a36 | 2018-07-10 18:12:13 +0200 | [diff] [blame] | 50 | KorAP._or.apply(obj); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 51 | }; |
Nils Diewald | 52f7eb1 | 2015-01-12 17:30:04 +0000 | [diff] [blame] | 52 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 53 | function _delOn (obj) { |
Akron | d141a36 | 2018-07-10 18:12:13 +0200 | [diff] [blame] | 54 | KorAP._delete.apply(obj); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 55 | }; |
Nils Diewald | 52f7eb1 | 2015-01-12 17:30:04 +0000 | [diff] [blame] | 56 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 57 | var demoFactory = buildFactory(vcClass, { |
| 58 | "@type":"koral:docGroup", |
| 59 | "operation":"operation:or", |
| 60 | "operands":[ |
Nils Diewald | f219eb8 | 2015-01-07 20:15:42 +0000 | [diff] [blame] | 61 | { |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 62 | "@type":"koral:docGroup", |
| 63 | "operation":"operation:and", |
| 64 | "operands":[ |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 65 | { |
| 66 | "@type":"koral:doc", |
| 67 | "key":"Titel", |
| 68 | "value":"Baum", |
| 69 | "match":"match:eq" |
| 70 | }, |
| 71 | { |
| 72 | "@type":"koral:doc", |
| 73 | "key":"Veröffentlichungsort", |
| 74 | "value":"hihi", |
| 75 | "match":"match:eq" |
| 76 | }, |
| 77 | { |
| 78 | "@type":"koral:docGroup", |
| 79 | "operation":"operation:or", |
| 80 | "operands":[ |
| 81 | { |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 82 | "@type":"koral:doc", |
| 83 | "key":"Titel", |
| 84 | "value":"Baum", |
| 85 | "match":"match:eq" |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 86 | }, |
| 87 | { |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 88 | "@type":"koral:doc", |
| 89 | "key":"Veröffentlichungsort", |
| 90 | "value":"hihi", |
| 91 | "match":"match:eq" |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 92 | } |
| 93 | ] |
| 94 | } |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 95 | ] |
Nils Diewald | f219eb8 | 2015-01-07 20:15:42 +0000 | [diff] [blame] | 96 | }, |
| 97 | { |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 98 | "@type":"koral:doc", |
| 99 | "key":"Untertitel", |
| 100 | "value":"huhu", |
| 101 | "match":"match:contains" |
Nils Diewald | f219eb8 | 2015-01-07 20:15:42 +0000 | [diff] [blame] | 102 | } |
| 103 | ] |
| 104 | }); |
| 105 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 106 | describe('KorAP.Doc', function () { |
| 107 | // Create example factories |
| 108 | var stringFactory = buildFactory(docClass, { |
| 109 | "key" : "author", |
| 110 | "value" : "Max Birkendale", |
Akron | 31d8994 | 2018-04-06 16:44:51 +0200 | [diff] [blame] | 111 | "type" : "type:string", |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 112 | "@type" : "koral:doc" |
| 113 | }); |
| 114 | |
| 115 | // Create example factories |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 116 | var textFactory = buildFactory(docClass, { |
| 117 | "key" : "author", |
| 118 | "value" : "Birkendale", |
Akron | 31d8994 | 2018-04-06 16:44:51 +0200 | [diff] [blame] | 119 | "type" : "type:string", |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 120 | "match" : "match:contains", |
| 121 | "@type" : "koral:doc" |
| 122 | }); |
| 123 | |
| 124 | // Create example factories |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 125 | var dateFactory = buildFactory(docClass, { |
| 126 | "key" : "pubDate", |
| 127 | "type" : "type:date", |
| 128 | "match" : "match:eq", |
| 129 | "value" : "2014-11-05", |
| 130 | "@type" : "koral:doc" |
| 131 | }); |
| 132 | |
| 133 | // Create example factories |
| 134 | var regexFactory = buildFactory(docClass, { |
| 135 | "key" : "title", |
| 136 | "type" : "type:regex", |
| 137 | "value" : "[^b]ee.+?", |
| 138 | "@type" : "koral:doc" |
| 139 | }); |
| 140 | |
| 141 | it('should be initializable', function () { |
| 142 | var doc = docClass.create(); |
| 143 | expect(doc.matchop()).toEqual('eq'); |
| 144 | expect(doc.key()).toBeUndefined(); |
| 145 | expect(doc.value()).toBeUndefined(); |
| 146 | expect(doc.type()).toEqual("string"); |
| 147 | }); |
| 148 | |
| 149 | it('should be definable', function () { |
| 150 | |
| 151 | // Empty doc |
| 152 | var doc = docClass.create(); |
| 153 | |
| 154 | // Set values |
| 155 | doc.key("title"); |
Akron | 8db5e3a | 2018-05-28 19:25:26 +0200 | [diff] [blame] | 156 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 157 | doc.value("Der alte Mann"); |
| 158 | expect(doc.matchop()).toEqual('eq'); |
| 159 | expect(doc.key()).toEqual("title"); |
| 160 | expect(doc.type()).toEqual("string"); |
| 161 | expect(doc.value()).toEqual("Der alte Mann"); |
| 162 | }); |
| 163 | |
| 164 | |
| 165 | it('should deserialize JSON-LD string', function () { |
| 166 | var doc; |
| 167 | |
| 168 | // String default |
| 169 | doc = stringFactory.create(); |
| 170 | expect(doc.matchop()).toEqual('eq'); |
| 171 | expect(doc.key()).toEqual("author"); |
| 172 | expect(doc.type()).toEqual("string"); |
| 173 | expect(doc.value()).toEqual("Max Birkendale"); |
| 174 | |
| 175 | // No valid string |
| 176 | doc = stringFactory.create({ |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 177 | value : undefined |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 178 | }); |
| 179 | expect(doc).toBeUndefined(); |
| 180 | |
| 181 | // No valid string |
| 182 | doc = stringFactory.create({ |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 183 | value : { "foo" : "bar" } |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 184 | }); |
| 185 | expect(doc).toBeUndefined(); |
| 186 | |
| 187 | // Change match type |
| 188 | doc = stringFactory.create({ |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 189 | "match" : "match:ne" |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 190 | }); |
| 191 | |
| 192 | expect(doc.matchop()).toEqual('ne'); |
| 193 | expect(doc.key()).toEqual("author"); |
| 194 | expect(doc.type()).toEqual("string"); |
| 195 | expect(doc.value()).toEqual("Max Birkendale"); |
| 196 | |
| 197 | // Invalid match type |
| 198 | doc = stringFactory.create({ |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 199 | "match" : { "foo" : "bar" } |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 200 | }); |
| 201 | expect(doc).toBeUndefined(); |
| 202 | }); |
| 203 | |
| 204 | it('should deserialize JSON-LD regex', function () { |
| 205 | var doc = regexFactory.create(); |
| 206 | expect(doc.key()).toEqual("title"); |
| 207 | expect(doc.type()).toEqual("regex"); |
| 208 | expect(doc.value()).toEqual("[^b]ee.+?"); |
| 209 | expect(doc.matchop()).toEqual('eq'); |
| 210 | |
| 211 | // change matcher |
| 212 | doc = regexFactory.create({ |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 213 | match : "match:ne" |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 214 | }); |
| 215 | expect(doc.matchop()).toEqual('ne'); |
Akron | ea4e905 | 2017-07-06 16:12:05 +0200 | [diff] [blame] | 216 | expect(doc.rewrites()).toBeUndefined(); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 217 | |
| 218 | // Invalid matcher |
| 219 | doc = regexFactory.create({ |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 220 | match : "match:chook" |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 221 | }); |
Akron | ea4e905 | 2017-07-06 16:12:05 +0200 | [diff] [blame] | 222 | expect(doc.matchop()).toEqual('eq'); |
| 223 | expect(doc.rewrites()).toBeDefined(); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 224 | |
| 225 | // Invalid regex |
| 226 | doc = regexFactory.create({ |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 227 | value : "[^b" |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 228 | }); |
| 229 | expect(doc).toBeUndefined(); |
| 230 | }); |
| 231 | |
| 232 | it('should deserialize JSON-LD date', function () { |
| 233 | |
| 234 | // Normal date |
| 235 | doc = dateFactory.create({}); |
| 236 | |
| 237 | expect(doc.matchop()).toEqual('eq'); |
| 238 | expect(doc.key()).toEqual("pubDate"); |
| 239 | expect(doc.type()).toEqual("date"); |
| 240 | expect(doc.value()).toEqual("2014-11-05"); |
| 241 | |
| 242 | // Short date 1 |
| 243 | doc = dateFactory.create({ |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 244 | "value" : "2014-11" |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 245 | }); |
| 246 | |
| 247 | expect(doc.matchop()).toEqual('eq'); |
| 248 | expect(doc.key()).toEqual("pubDate"); |
| 249 | expect(doc.type()).toEqual("date"); |
| 250 | expect(doc.value()).toEqual("2014-11"); |
| 251 | |
| 252 | // Short date 2 |
| 253 | doc = dateFactory.create({ |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 254 | "value" : "2014" |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 255 | }); |
| 256 | |
| 257 | expect(doc.matchop()).toEqual('eq'); |
| 258 | expect(doc.key()).toEqual("pubDate"); |
| 259 | expect(doc.type()).toEqual("date"); |
| 260 | expect(doc.value()).toEqual("2014"); |
| 261 | |
| 262 | // Invalid date! |
| 263 | doc = dateFactory.create({ |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 264 | "value" : "2014-11-050" |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 265 | }); |
| 266 | expect(doc).toBeUndefined(); |
| 267 | |
| 268 | // Invalid matcher! |
| 269 | doc = dateFactory.create({ |
Akron | 31d8994 | 2018-04-06 16:44:51 +0200 | [diff] [blame] | 270 | "match" : "match:contains", |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 271 | }); |
Akron | ea4e905 | 2017-07-06 16:12:05 +0200 | [diff] [blame] | 272 | expect(doc).toBeDefined(); |
| 273 | expect(doc.rewrites()).toBeDefined(); |
| 274 | expect(doc.matchop()).toEqual('eq'); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 275 | }); |
| 276 | |
| 277 | it('should be serializale to JSON', function () { |
| 278 | |
| 279 | // Empty doc |
| 280 | var doc = docClass.create(); |
| 281 | expect(doc.toJson()).toEqual(jasmine.any(Object)); |
| 282 | |
| 283 | // Serialize string |
| 284 | doc = stringFactory.create(); |
| 285 | expect(doc.toJson()).toEqual(jasmine.objectContaining({ |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 286 | "@type" : "koral:doc", |
| 287 | "type" : "type:string", |
| 288 | "key" : "author", |
| 289 | "value" : "Max Birkendale", |
| 290 | "match" : "match:eq" |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 291 | })); |
| 292 | |
| 293 | // Serialize regex |
| 294 | doc = regexFactory.create(); |
| 295 | expect(doc.toJson()).toEqual(jasmine.objectContaining({ |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 296 | "@type" : "koral:doc", |
| 297 | "type" : "type:regex", |
| 298 | "value" : "[^b]ee.+?", |
| 299 | "match" : "match:eq", |
| 300 | "key" : 'title' |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 301 | })); |
| 302 | |
| 303 | doc = regexFactory.create({ |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 304 | match: "match:ne" |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 305 | }); |
| 306 | expect(doc.toJson()).toEqual(jasmine.objectContaining({ |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 307 | "@type" : "koral:doc", |
| 308 | "type" : "type:regex", |
| 309 | "value" : "[^b]ee.+?", |
| 310 | "match" : "match:ne", |
| 311 | "key" : 'title' |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 312 | })); |
| 313 | |
| 314 | doc = dateFactory.create(); |
| 315 | expect(doc.toJson()).toEqual(jasmine.objectContaining({ |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 316 | "@type" : "koral:doc", |
| 317 | "type" : "type:date", |
| 318 | "value" : "2014-11-05", |
| 319 | "match" : "match:eq", |
| 320 | "key" : 'pubDate' |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 321 | })); |
| 322 | |
| 323 | doc = dateFactory.create({ |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 324 | value : "2014" |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 325 | }); |
| 326 | expect(doc.toJson()).toEqual(jasmine.objectContaining({ |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 327 | "@type" : "koral:doc", |
| 328 | "type" : "type:date", |
| 329 | "value" : "2014", |
| 330 | "match" : "match:eq", |
| 331 | "key" : 'pubDate' |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 332 | })); |
| 333 | }); |
| 334 | |
| 335 | |
| 336 | it('should be serializale to String', function () { |
| 337 | // Empty doc |
| 338 | var doc = docClass.create(); |
| 339 | expect(doc.toQuery()).toEqual(""); |
| 340 | |
| 341 | // Serialize string |
| 342 | doc = stringFactory.create(); |
| 343 | expect(doc.toQuery()).toEqual('author = "Max Birkendale"'); |
| 344 | |
| 345 | // Serialize string with quotes |
| 346 | doc = stringFactory.create({ "value" : 'Max "Der Coole" Birkendate'}); |
| 347 | expect(doc.toQuery()).toEqual('author = "Max \\"Der Coole\\" Birkendate"'); |
| 348 | |
| 349 | // Serialize regex |
| 350 | doc = regexFactory.create(); |
| 351 | expect(doc.toQuery()).toEqual('title = /[^b]ee.+?/'); |
| 352 | |
| 353 | doc = regexFactory.create({ |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 354 | match: "match:ne" |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 355 | }); |
| 356 | expect(doc.toQuery()).toEqual('title != /[^b]ee.+?/'); |
| 357 | |
Akron | 8778f5d | 2017-06-30 21:25:55 +0200 | [diff] [blame] | 358 | doc = regexFactory.create({ |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 359 | value: "WPD/AAA/00001" |
Akron | 8778f5d | 2017-06-30 21:25:55 +0200 | [diff] [blame] | 360 | }); |
| 361 | expect(doc.toQuery()).toEqual('title = /WPD\\/AAA\\/00001/'); |
| 362 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 363 | doc = dateFactory.create(); |
| 364 | expect(doc.toQuery()).toEqual('pubDate in 2014-11-05'); |
| 365 | |
| 366 | doc = dateFactory.create({ |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 367 | value : "2014" |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 368 | }); |
| 369 | expect(doc.toQuery()).toEqual('pubDate in 2014'); |
| 370 | }); |
| 371 | }); |
| 372 | |
| 373 | |
| 374 | describe('KorAP.DocGroup', function () { |
| 375 | // Create example factories |
| 376 | var docFactory = buildFactory( |
| 377 | docClass, |
Nils Diewald | f219eb8 | 2015-01-07 20:15:42 +0000 | [diff] [blame] | 378 | { |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 379 | "@type" : "koral:doc", |
| 380 | "match":"match:eq", |
| 381 | "key" : "author", |
| 382 | "value" : "Max Birkendale" |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 383 | } |
| 384 | ); |
| 385 | |
| 386 | var docGroupFactory = buildFactory( |
| 387 | docGroupClass, { |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 388 | "@type" : "koral:docGroup", |
| 389 | "operation" : "operation:and", |
| 390 | "operands" : [ |
| 391 | docFactory.create().toJson(), |
| 392 | docFactory.create({ |
| 393 | "key" : "pubDate", |
| 394 | "type" : "type:date", |
| 395 | "value" : "2014-12-05" |
| 396 | }).toJson() |
| 397 | ] |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 398 | }); |
| 399 | |
| 400 | it('should be initializable', function () { |
| 401 | // Create empty group |
| 402 | var docGroup = docGroupClass.create(); |
| 403 | expect(docGroup.operation()).toEqual('and'); |
| 404 | |
| 405 | // Create empty group |
| 406 | docGroup = docGroupClass.create(); |
| 407 | docGroup.operation('or'); |
| 408 | expect(docGroup.operation()).toEqual('or'); |
| 409 | }); |
| 410 | |
| 411 | it('should be definable', function () { |
| 412 | |
| 413 | // Empty group |
| 414 | var docGroup = docGroupClass.create(); |
| 415 | expect(docGroup.operation()).toEqual('and'); |
| 416 | |
| 417 | // Set values |
| 418 | docGroup.operation("or"); |
| 419 | expect(docGroup.operation()).toEqual('or'); |
| 420 | |
| 421 | // Set invalid values |
| 422 | docGroup.operation("hui"); |
| 423 | expect(docGroup.operation()).toEqual('or'); |
| 424 | }); |
| 425 | |
| 426 | it('should be deserializable', function () { |
| 427 | var docGroup = docGroupFactory.create(); |
| 428 | expect(docGroup.operation()).toEqual("and"); |
| 429 | expect(docGroup.operands().length).toEqual(2); |
| 430 | |
| 431 | var op1 = docGroup.getOperand(0); |
| 432 | expect(op1.type()).toEqual("string"); |
| 433 | expect(op1.key()).toEqual("author"); |
| 434 | expect(op1.value()).toEqual("Max Birkendale"); |
| 435 | expect(op1.matchop()).toEqual("eq"); |
| 436 | |
| 437 | var op2 = docGroup.getOperand(1); |
| 438 | expect(op2.type()).toEqual("date"); |
| 439 | expect(op2.key()).toEqual("pubDate"); |
| 440 | expect(op2.value()).toEqual("2014-12-05"); |
| 441 | expect(op2.matchop()).toEqual("eq"); |
| 442 | |
| 443 | // Append empty group |
| 444 | var newGroup = docGroup.append(docGroupClass.create()); |
| 445 | newGroup.operation('or'); |
| 446 | newGroup.append(docFactory.create()); |
| 447 | newGroup.append(docFactory.create({ |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 448 | "type" : "type:regex", |
| 449 | "key" : "title", |
| 450 | "value" : "^e.+?$", |
| 451 | "match" : "match:ne" |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 452 | })); |
| 453 | |
| 454 | expect(docGroup.operation()).toEqual("and"); |
| 455 | expect(docGroup.operands().length).toEqual(3); |
| 456 | |
| 457 | var op1 = docGroup.getOperand(0); |
| 458 | expect(op1.ldType()).toEqual("doc"); |
| 459 | expect(op1.type()).toEqual("string"); |
| 460 | expect(op1.key()).toEqual("author"); |
| 461 | expect(op1.value()).toEqual("Max Birkendale"); |
| 462 | expect(op1.matchop()).toEqual("eq"); |
| 463 | |
| 464 | var op2 = docGroup.getOperand(1); |
| 465 | expect(op2.ldType()).toEqual("doc"); |
| 466 | expect(op2.type()).toEqual("date"); |
| 467 | expect(op2.key()).toEqual("pubDate"); |
| 468 | expect(op2.value()).toEqual("2014-12-05"); |
| 469 | expect(op2.matchop()).toEqual("eq"); |
| 470 | |
| 471 | var op3 = docGroup.getOperand(2); |
| 472 | expect(op3.ldType()).toEqual("docGroup"); |
| 473 | expect(op3.operation()).toEqual("or"); |
| 474 | |
| 475 | var op4 = op3.getOperand(0); |
| 476 | expect(op4.ldType()).toEqual("doc"); |
| 477 | expect(op4.type()).toEqual("string"); |
| 478 | expect(op4.key()).toEqual("author"); |
| 479 | expect(op4.value()).toEqual("Max Birkendale"); |
| 480 | expect(op4.matchop()).toEqual("eq"); |
| 481 | |
| 482 | var op5 = op3.getOperand(1); |
| 483 | expect(op5.ldType()).toEqual("doc"); |
| 484 | expect(op5.type()).toEqual("regex"); |
| 485 | expect(op5.key()).toEqual("title"); |
| 486 | expect(op5.value()).toEqual("^e.+?$"); |
| 487 | expect(op5.matchop()).toEqual("ne"); |
| 488 | }); |
| 489 | |
| 490 | it('should be serializable to JSON', function () { |
| 491 | var docGroup = docGroupFactory.create(); |
| 492 | |
| 493 | expect(docGroup.toJson()).toEqual(jasmine.objectContaining({ |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 494 | "@type" : "koral:docGroup", |
| 495 | "operation" : "operation:and", |
| 496 | "operands" : [ |
| 497 | { |
| 498 | "@type": 'koral:doc', |
| 499 | "key" : 'author', |
| 500 | "match": 'match:eq', |
| 501 | "value": 'Max Birkendale', |
| 502 | "type": 'type:string' |
| 503 | }, |
| 504 | { |
| 505 | "@type": 'koral:doc', |
| 506 | "key": 'pubDate', |
| 507 | "match": 'match:eq', |
| 508 | "value": '2014-12-05', |
| 509 | "type": 'type:date' |
| 510 | } |
| 511 | ] |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 512 | })); |
| 513 | }); |
Nils Diewald | e15b7a2 | 2015-01-09 21:50:21 +0000 | [diff] [blame] | 514 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 515 | it('should be serializable to String', function () { |
| 516 | var docGroup = docGroupFactory.create(); |
| 517 | expect(docGroup.toQuery()).toEqual( |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 518 | 'author = "Max Birkendale" & pubDate in 2014-12-05' |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 519 | ); |
Nils Diewald | 52f7eb1 | 2015-01-12 17:30:04 +0000 | [diff] [blame] | 520 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 521 | docGroup = docGroupFactory.create({ |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 522 | "@type" : "koral:docGroup", |
| 523 | "operation" : "operation:or", |
| 524 | "operands" : [ |
| 525 | { |
| 526 | "@type": 'koral:doc', |
| 527 | "key" : 'author', |
| 528 | "match": 'match:eq', |
| 529 | "value": 'Max Birkendale', |
| 530 | "type": 'type:string' |
| 531 | }, |
| 532 | { |
| 533 | "@type" : "koral:docGroup", |
| 534 | "operation" : "operation:and", |
| 535 | "operands" : [ |
| 536 | { |
| 537 | "@type": 'koral:doc', |
| 538 | "key": 'pubDate', |
| 539 | "match": 'match:geq', |
| 540 | "value": '2014-05-12', |
| 541 | "type": 'type:date' |
| 542 | }, |
| 543 | { |
| 544 | "@type": 'koral:doc', |
| 545 | "key": 'pubDate', |
| 546 | "match": 'match:leq', |
| 547 | "value": '2014-12-05', |
| 548 | "type": 'type:date' |
| 549 | }, |
| 550 | { |
| 551 | "@type": 'koral:doc', |
| 552 | "key": 'foo', |
| 553 | "match": 'match:ne', |
| 554 | "value": '[a]?bar', |
| 555 | "type": 'type:regex' |
| 556 | } |
| 557 | ] |
| 558 | } |
| 559 | ] |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 560 | }); |
| 561 | expect(docGroup.toQuery()).toEqual( |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 562 | 'author = "Max Birkendale" | ' + |
| 563 | '(pubDate since 2014-05-12 & ' + |
| 564 | 'pubDate until 2014-12-05 & foo != /[a]?bar/)' |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 565 | ); |
| 566 | }); |
| 567 | }); |
| 568 | |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 569 | describe('KorAP.DocGroupRef', function () { |
| 570 | // Create example factories |
| 571 | var docRefFactory = buildFactory( |
| 572 | docGroupRefClass, |
| 573 | { |
| 574 | "@type" : "koral:docGroupRef", |
| 575 | "ref" : "@max/myCorpus" |
| 576 | } |
| 577 | ); |
| 578 | |
| 579 | it('should be initializable', function () { |
| 580 | var vcRef = docGroupRefClass.create(); |
| 581 | expect(vcRef.ref()).toBeUndefined(); |
| 582 | }); |
| 583 | |
| 584 | it('should be definable', function () { |
| 585 | var vcRef = docGroupRefClass.create(); |
| 586 | vcRef.ref("@peter/mycorpus"); |
| 587 | expect(vcRef.ref()).toEqual("@peter/mycorpus"); |
| 588 | vcRef.ref("@peter/mycorpus2"); |
| 589 | expect(vcRef.ref()).toEqual("@peter/mycorpus2"); |
| 590 | }); |
| 591 | |
| 592 | it('should deserialize JSON-LD string', function () { |
| 593 | var vcRef = docRefFactory.create(); |
| 594 | expect(vcRef.ref()).toEqual("@max/myCorpus"); |
| 595 | }); |
| 596 | |
| 597 | it('should serialize to JSON-LD', function () { |
| 598 | var vcRef = docRefFactory.create(); |
| 599 | expect(vcRef.toJson()).toEqual(jasmine.objectContaining({ |
| 600 | "@type" : "koral:docGroupRef", |
| 601 | "ref":"@max/myCorpus" |
| 602 | })); |
| 603 | |
| 604 | vcRef.ref("@peter/myCorpus2"); |
| 605 | expect(vcRef.toJson()).toEqual(jasmine.objectContaining({ |
| 606 | "@type" : "koral:docGroupRef", |
| 607 | "ref":"@peter/myCorpus2" |
| 608 | })); |
| 609 | }); |
| 610 | |
| 611 | it('should serialize to a query', function () { |
| 612 | var vcRef = docRefFactory.create(); |
| 613 | expect(vcRef.toQuery()).toEqual( |
| 614 | "referTo \"@max/myCorpus\"" |
| 615 | ); |
| 616 | |
| 617 | vcRef.ref("@peter/myCorpus2"); |
| 618 | expect(vcRef.toQuery()).toEqual( |
| 619 | "referTo \"@peter/myCorpus2\"" |
| 620 | ); |
| 621 | }); |
| 622 | }); |
| 623 | |
| 624 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 625 | describe('KorAP.UnspecifiedDoc', function () { |
| 626 | it('should be initializable', function () { |
| 627 | var doc = unspecifiedClass.create(); |
| 628 | var docElement = doc.element(); |
| 629 | expect(docElement.getAttribute('class')).toEqual('doc unspecified'); |
| 630 | expect(docElement.firstChild.firstChild.data).toEqual('⋯'); |
| 631 | expect(docElement.lastChild.lastChild.data).toEqual('⋯'); |
| 632 | expect(doc.toQuery()).toEqual(''); |
| 633 | |
| 634 | // Only removable |
| 635 | expect(docElement.lastChild.children.length).toEqual(0); |
| 636 | }); |
| 637 | |
Akron | d141a36 | 2018-07-10 18:12:13 +0200 | [diff] [blame] | 638 | it('should be removable, when no root', function () { |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 639 | var docGroup = docGroupClass.create(); |
| 640 | docGroup.operation('or'); |
| 641 | expect(docGroup.operation()).toEqual('or'); |
| 642 | |
| 643 | docGroup.append({ |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 644 | "@type": 'koral:doc', |
| 645 | "key": 'pubDate', |
| 646 | "match": 'match:eq', |
| 647 | "value": '2014-12-05', |
| 648 | "type": 'type:date' |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 649 | }); |
| 650 | |
| 651 | // Add unspecified object |
| 652 | docGroup.append(); |
| 653 | |
Akron | d141a36 | 2018-07-10 18:12:13 +0200 | [diff] [blame] | 654 | var parent = document.createElement('div'); |
| 655 | parent.appendChild(docGroup.element()); |
| 656 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 657 | expect(docGroup.element().getAttribute('class')).toEqual('docGroup'); |
| 658 | expect(docGroup.element().children[0].getAttribute('class')).toEqual('doc'); |
| 659 | |
| 660 | var unspec = docGroup.element().children[1]; |
| 661 | expect(unspec.getAttribute('class')).toEqual('doc unspecified'); |
| 662 | |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 663 | // Only unspec and delete |
| 664 | expect(unspec.children.length).toEqual(2); |
| 665 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 666 | // Removable |
| 667 | expect(unspec.lastChild.children.length).toEqual(1); |
| 668 | expect(unspec.lastChild.children[0].getAttribute('class')).toEqual('delete'); |
| 669 | }); |
| 670 | |
Akron | d141a36 | 2018-07-10 18:12:13 +0200 | [diff] [blame] | 671 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 672 | it('should be replaceable by a doc', function () { |
| 673 | var doc = unspecifiedClass.create(); |
| 674 | expect(doc.ldType()).toEqual("non"); |
| 675 | // No parent, therefor not updateable |
| 676 | expect(doc.key("baum")).toBeNull(); |
| 677 | |
| 678 | var docGroup = docGroupClass.create(); |
| 679 | docGroup.operation('or'); |
| 680 | expect(docGroup.operation()).toEqual('or'); |
| 681 | |
| 682 | docGroup.append({ |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 683 | "@type": 'koral:doc', |
| 684 | "key": 'pubDate', |
| 685 | "match": 'match:eq', |
| 686 | "value": '2014-12-05', |
| 687 | "type": 'type:date' |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 688 | }); |
| 689 | |
| 690 | expect(docGroup.toQuery()).toEqual("pubDate in 2014-12-05"); |
| 691 | docGroup.append(); |
| 692 | |
| 693 | expect(docGroup.getOperand(0).ldType()).toEqual("doc"); |
| 694 | expect(docGroup.getOperand(1).ldType()).toEqual("non"); |
| 695 | |
| 696 | var op = docGroup.getOperand(1).element().lastChild; |
Akron | 0b489ad | 2018-02-02 16:49:32 +0100 | [diff] [blame] | 697 | expect(op.getAttribute('class')).toEqual('operators button-group'); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 698 | expect(op.children[0].getAttribute('class')).toEqual('delete'); |
| 699 | expect(op.children.length).toEqual(1); |
| 700 | |
| 701 | // Replace unspecified doc |
| 702 | expect(docGroup.getOperand(1).key("name")).not.toBeNull(); |
| 703 | expect(docGroup.getOperand(1).ldType()).toEqual("doc"); |
| 704 | expect(docGroup.getOperand(1).key()).toEqual("name"); |
Akron | 55a343b | 2018-04-06 19:57:36 +0200 | [diff] [blame] | 705 | expect(docGroup.getOperand(1).value()).toBeUndefined(); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 706 | |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 707 | expect(docGroup.getOperand(1).element().children.length).toEqual(4); |
| 708 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 709 | op = docGroup.getOperand(1).element().lastChild; |
Akron | 0b489ad | 2018-02-02 16:49:32 +0100 | [diff] [blame] | 710 | expect(op.getAttribute('class')).toEqual('operators button-group'); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 711 | expect(op.children[0].getAttribute('class')).toEqual('and'); |
| 712 | expect(op.children[1].getAttribute('class')).toEqual('or'); |
| 713 | expect(op.children[2].getAttribute('class')).toEqual('delete'); |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 714 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 715 | expect(op.children.length).toEqual(3); |
| 716 | |
| 717 | docGroup.getOperand(1).value("Pachelbel"); |
| 718 | expect(docGroup.getOperand(1).value()).toEqual("Pachelbel"); |
| 719 | expect(docGroup.getOperand(1).type()).toEqual("string"); |
| 720 | expect(docGroup.getOperand(1).matchop()).toEqual("eq"); |
| 721 | |
| 722 | // Specified! |
| 723 | expect(docGroup.toQuery()).toEqual('pubDate in 2014-12-05 | name = "Pachelbel"'); |
| 724 | }); |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 725 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 726 | it('should be replaceable on root', function () { |
Nils Diewald | 6283d69 | 2015-04-23 20:32:53 +0000 | [diff] [blame] | 727 | var vc = vcClass.create(); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 728 | expect(vc.toQuery()).toEqual(""); |
| 729 | |
| 730 | expect(vc.root().ldType()).toEqual("non"); |
| 731 | |
| 732 | // No operators on root |
| 733 | op = vc.root().element().lastChild; |
| 734 | expect(op.lastChild.textContent).toEqual('⋯'); |
| 735 | |
| 736 | // Replace |
| 737 | expect(vc.root().key("baum")).not.toBeNull(); |
| 738 | expect(vc.root().ldType()).toEqual("doc"); |
| 739 | |
| 740 | op = vc.root().element().lastChild; |
Akron | 0b489ad | 2018-02-02 16:49:32 +0100 | [diff] [blame] | 741 | expect(op.getAttribute('class')).toEqual('operators button-group'); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 742 | expect(op.children[0].getAttribute('class')).toEqual('and'); |
| 743 | expect(op.children[1].getAttribute('class')).toEqual('or'); |
| 744 | expect(op.children[2].getAttribute('class')).toEqual('delete'); |
| 745 | expect(op.children.length).toEqual(3); |
| 746 | }); |
Akron | 55a343b | 2018-04-06 19:57:36 +0200 | [diff] [blame] | 747 | |
| 748 | it('should be clickable', function () { |
| 749 | var vc = vcClass.create([ |
| 750 | ["pubDate", "date"] |
| 751 | ]); |
| 752 | expect(vc.toQuery()).toEqual(""); |
| 753 | expect(vc.element().firstChild.textContent).toEqual("⋯"); |
| 754 | vc.element().firstChild.firstChild.click(); |
| 755 | |
| 756 | // Click on pubDate |
| 757 | vc.element().firstChild.getElementsByTagName("LI")[0].click(); |
| 758 | |
| 759 | expect(vc.element().firstChild.firstChild.textContent).toEqual("pubDate"); |
| 760 | expect(vc.element().firstChild.children[1].getAttribute("data-type")).toEqual("date"); |
| 761 | }); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 762 | }); |
| 763 | |
| 764 | describe('KorAP.Doc element', function () { |
| 765 | it('should be initializable', function () { |
| 766 | var docElement = docClass.create(undefined, { |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 767 | "@type" : "koral:doc", |
| 768 | "key":"Titel", |
| 769 | "value":"Baum", |
| 770 | "match":"match:eq" |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 771 | }); |
| 772 | expect(docElement.key()).toEqual('Titel'); |
| 773 | expect(docElement.matchop()).toEqual('eq'); |
| 774 | expect(docElement.value()).toEqual('Baum'); |
| 775 | |
| 776 | var docE = docElement.element(); |
| 777 | expect(docE.children[0].firstChild.data).toEqual('Titel'); |
| 778 | expect(docE.children[1].firstChild.data).toEqual('eq'); |
| 779 | expect(docE.children[1].getAttribute('data-type')).toEqual('string'); |
| 780 | expect(docE.children[2].firstChild.data).toEqual('Baum'); |
| 781 | expect(docE.children[2].getAttribute('data-type')).toEqual('string'); |
| 782 | |
| 783 | expect(docElement.toJson()).toEqual(jasmine.objectContaining({ |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 784 | "@type" : "koral:doc", |
| 785 | "key":"Titel", |
| 786 | "value":"Baum", |
| 787 | "match":"match:eq" |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 788 | })); |
| 789 | }); |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 790 | |
| 791 | |
| 792 | it('should be replacable by unspecified', function () { |
| 793 | var vc = vcClass.create([ |
| 794 | ["pubDate", "date"] |
| 795 | ]).fromJson({ |
| 796 | "@type" : "koral:doc", |
| 797 | "key":"Titel", |
| 798 | "value":"Baum", |
| 799 | "match":"match:eq" |
| 800 | }); |
| 801 | expect(vc.toQuery()).toEqual("Titel = \"Baum\""); |
| 802 | |
| 803 | var vcE = vc.element(); |
| 804 | expect(vcE.firstChild.children.length).toEqual(4); |
| 805 | |
| 806 | // Click to delete |
| 807 | vcE.firstChild.lastChild.lastChild.click(); |
| 808 | |
| 809 | expect(vcE.firstChild.children.length).toEqual(1); |
| 810 | |
| 811 | expect(vcE.firstChild.textContent).toEqual("⋯"); |
| 812 | vcE.firstChild.firstChild.click(); |
| 813 | |
| 814 | // Click on pubDate |
| 815 | vcE.firstChild.getElementsByTagName("LI")[0].click(); |
| 816 | |
| 817 | expect(vcE.firstChild.firstChild.textContent).toEqual("pubDate"); |
| 818 | expect(vcE.firstChild.children[1].getAttribute("data-type")).toEqual("date"); |
| 819 | |
| 820 | expect(vcE.firstChild.children.length).toEqual(4); |
| 821 | }); |
| 822 | |
| 823 | |
| 824 | it('should be replaceable by a docGroupRef', function () { |
| 825 | var vc = vcClass.create([ |
| 826 | ["@referTo", "ref"] |
| 827 | ]).fromJson({ |
| 828 | "@type" : "koral:doc", |
| 829 | "key":"Titel", |
| 830 | "value":"Baum", |
| 831 | "match":"match:eq" |
| 832 | }); |
| 833 | |
| 834 | expect(vc.toQuery()).toEqual("Titel = \"Baum\""); |
| 835 | |
| 836 | var vcE = vc.element(); |
| 837 | expect(vcE.firstChild.children.length).toEqual(4); |
| 838 | |
| 839 | // Click to delete |
| 840 | vcE.firstChild.lastChild.lastChild.click(); |
| 841 | |
| 842 | expect(vcE.firstChild.children.length).toEqual(1); |
| 843 | |
| 844 | expect(vcE.firstChild.textContent).toEqual("⋯"); |
| 845 | vcE.firstChild.firstChild.click(); |
| 846 | |
| 847 | // Click on @referTo |
| 848 | vcE.firstChild.getElementsByTagName("LI")[0].click(); |
| 849 | |
| 850 | expect(vcE.firstChild.firstChild.textContent).toEqual("@referTo"); |
| 851 | expect(vcE.firstChild.children[1].getAttribute("data-type")).toEqual("string"); |
| 852 | expect(vcE.firstChild.children.length).toEqual(3); |
| 853 | }); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 854 | }); |
| 855 | |
| 856 | describe('KorAP.DocGroup element', function () { |
| 857 | it('should be initializable', function () { |
| 858 | |
| 859 | var docGroup = docGroupClass.create(undefined, { |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 860 | "@type" : "koral:docGroup", |
| 861 | "operation" : "operation:and", |
| 862 | "operands" : [ |
| 863 | { |
| 864 | "@type": 'koral:doc', |
| 865 | "key" : 'author', |
| 866 | "match": 'match:eq', |
| 867 | "value": 'Max Birkendale', |
| 868 | "type": 'type:string' |
| 869 | }, |
| 870 | { |
| 871 | "@type": 'koral:doc', |
| 872 | "key": 'pubDate', |
| 873 | "match": 'match:eq', |
| 874 | "value": '2014-12-05', |
| 875 | "type": 'type:date' |
| 876 | } |
| 877 | ] |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 878 | }); |
| 879 | |
| 880 | expect(docGroup.operation()).toEqual('and'); |
| 881 | var e = docGroup.element(); |
| 882 | expect(e.getAttribute('class')).toEqual('docGroup'); |
| 883 | expect(e.getAttribute('data-operation')).toEqual('and'); |
| 884 | |
| 885 | var first = e.children[0]; |
| 886 | expect(first.getAttribute('class')).toEqual('doc'); |
| 887 | expect(first.children[0].getAttribute('class')).toEqual('key'); |
| 888 | expect(first.children[1].getAttribute('class')).toEqual('match'); |
| 889 | expect(first.children[2].getAttribute('class')).toEqual('value'); |
| 890 | expect(first.children[2].getAttribute('data-type')).toEqual('string'); |
| 891 | expect(first.children[0].firstChild.data).toEqual('author'); |
| 892 | expect(first.children[1].firstChild.data).toEqual('eq'); |
| 893 | expect(first.children[2].firstChild.data).toEqual('Max Birkendale'); |
| 894 | |
| 895 | var second = e.children[1]; |
| 896 | expect(second.getAttribute('class')).toEqual('doc'); |
| 897 | expect(second.children[0].getAttribute('class')).toEqual('key'); |
| 898 | expect(second.children[1].getAttribute('class')).toEqual('match'); |
| 899 | expect(second.children[2].getAttribute('class')).toEqual('value'); |
| 900 | expect(second.children[2].getAttribute('data-type')).toEqual('date'); |
| 901 | expect(second.children[0].firstChild.data).toEqual('pubDate'); |
| 902 | expect(second.children[1].firstChild.data).toEqual('eq'); |
| 903 | expect(second.children[2].firstChild.data).toEqual('2014-12-05'); |
| 904 | }); |
| 905 | |
| 906 | it('should be deserializable with nested groups', function () { |
| 907 | var docGroup = docGroupClass.create(undefined, { |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 908 | "@type" : "koral:docGroup", |
| 909 | "operation" : "operation:or", |
| 910 | "operands" : [ |
| 911 | { |
| 912 | "@type": 'koral:doc', |
| 913 | "key" : 'author', |
| 914 | "match": 'match:eq', |
| 915 | "value": 'Max Birkendale', |
| 916 | "type": 'type:string' |
| 917 | }, |
| 918 | { |
| 919 | "@type" : "koral:docGroup", |
| 920 | "operation" : "operation:and", |
| 921 | "operands" : [ |
| 922 | { |
| 923 | "@type": 'koral:doc', |
| 924 | "key": 'pubDate', |
| 925 | "match": 'match:geq', |
| 926 | "value": '2014-05-12', |
| 927 | "type": 'type:date' |
| 928 | }, |
| 929 | { |
| 930 | "@type": 'koral:doc', |
| 931 | "key": 'pubDate', |
| 932 | "match": 'match:leq', |
| 933 | "value": '2014-12-05', |
| 934 | "type": 'type:date' |
| 935 | } |
| 936 | ] |
| 937 | } |
| 938 | ] |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 939 | }); |
| 940 | |
| 941 | expect(docGroup.operation()).toEqual('or'); |
| 942 | var e = docGroup.element(); |
| 943 | expect(e.getAttribute('class')).toEqual('docGroup'); |
| 944 | expect(e.getAttribute('data-operation')).toEqual('or'); |
| 945 | |
| 946 | expect(e.children[0].getAttribute('class')).toEqual('doc'); |
| 947 | var docop = e.children[0].lastChild; |
Akron | 0b489ad | 2018-02-02 16:49:32 +0100 | [diff] [blame] | 948 | expect(docop.getAttribute('class')).toEqual('operators button-group'); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 949 | expect(docop.children[0].getAttribute('class')).toEqual('and'); |
| 950 | expect(docop.children[1].getAttribute('class')).toEqual('or'); |
| 951 | expect(docop.children[2].getAttribute('class')).toEqual('delete'); |
| 952 | |
| 953 | expect(e.children[1].getAttribute('class')).toEqual('docGroup'); |
| 954 | expect(e.children[1].getAttribute('data-operation')).toEqual('and'); |
| 955 | |
| 956 | // This and-operation can be "or"ed or "delete"d |
| 957 | var secop = e.children[1].children[2]; |
Akron | 0b489ad | 2018-02-02 16:49:32 +0100 | [diff] [blame] | 958 | expect(secop.getAttribute('class')).toEqual('operators button-group'); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 959 | expect(secop.children[0].getAttribute('class')).toEqual('or'); |
| 960 | expect(secop.children[1].getAttribute('class')).toEqual('delete'); |
| 961 | |
| 962 | // This or-operation can be "and"ed or "delete"d |
Akron | 0b489ad | 2018-02-02 16:49:32 +0100 | [diff] [blame] | 963 | expect(e.children[2].getAttribute('class')).toEqual('operators button-group'); |
| 964 | expect(e.lastChild.getAttribute('class')).toEqual('operators button-group'); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 965 | expect(e.lastChild.children[0].getAttribute('class')).toEqual('and'); |
| 966 | expect(e.lastChild.children[1].getAttribute('class')).toEqual('delete'); |
| 967 | }); |
| 968 | }); |
| 969 | |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 970 | describe('KorAP.DocGroupRef element', function () { |
| 971 | it('should be initializable', function () { |
| 972 | var docGroupRef = docGroupRefClass.create(undefined, { |
| 973 | "@type" : "koral:docGroupRef", |
| 974 | "ref" : "@franz/myVC1" |
| 975 | }); |
| 976 | expect(docGroupRef.ref()).toEqual("@franz/myVC1"); |
| 977 | var dgrE = docGroupRef.element(); |
| 978 | |
| 979 | expect(dgrE.children[0].firstChild.data).toEqual("@referTo"); |
| 980 | expect(dgrE.children[0].tagName).toEqual("SPAN"); |
| 981 | expect(dgrE.children[0].classList.contains("key")).toBeTruthy(); |
| 982 | expect(dgrE.children[0].classList.contains("fixed")).toBeTruthy(); |
| 983 | expect(dgrE.children[1].firstChild.data).toEqual("@franz/myVC1"); |
| 984 | expect(dgrE.children[1].tagName).toEqual("SPAN"); |
| 985 | expect(dgrE.children[1].classList.contains("value")).toBeTruthy(); |
| 986 | expect(dgrE.children[1].getAttribute("data-type")).toEqual("string"); |
| 987 | }); |
| 988 | |
| 989 | it('should be modifiable on reference', function () { |
| 990 | var docGroupRef = docGroupRefClass.create(undefined, { |
| 991 | "@type" : "koral:docGroupRef", |
| 992 | "ref" : "@franz/myVC1" |
| 993 | }); |
| 994 | var dgrE = docGroupRef.element(); |
| 995 | expect(docGroupRef.toQuery()).toEqual("referTo \"@franz/myVC1\""); |
| 996 | dgrE.children[1].click(); |
| 997 | |
| 998 | var input = dgrE.children[1].firstChild; |
| 999 | expect(input.tagName).toEqual("INPUT"); |
| 1000 | input.value = "Versuch"; |
| 1001 | |
| 1002 | var event = new KeyboardEvent("keypress", { |
| 1003 | "key" : "[Enter]", |
| 1004 | "keyCode" : 13 |
| 1005 | }); |
| 1006 | |
| 1007 | input.dispatchEvent(event); |
| 1008 | expect(docGroupRef.toQuery()).toEqual("referTo \"Versuch\""); |
| 1009 | }); |
| 1010 | }); |
| 1011 | |
| 1012 | |
Akron | e4961b1 | 2017-05-10 21:04:46 +0200 | [diff] [blame] | 1013 | describe('KorAP.VirtualCorpus', function () { |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1014 | var simpleGroupFactory = buildFactory(docGroupClass, { |
| 1015 | "@type" : "koral:docGroup", |
| 1016 | "operation" : "operation:and", |
| 1017 | "operands" : [ |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 1018 | { |
| 1019 | "@type": 'koral:doc', |
| 1020 | "key" : 'author', |
| 1021 | "match": 'match:eq', |
| 1022 | "value": 'Max Birkendale', |
| 1023 | "type": 'type:string' |
| 1024 | }, |
| 1025 | { |
| 1026 | "@type": 'koral:doc', |
| 1027 | "key": 'pubDate', |
| 1028 | "match": 'match:eq', |
| 1029 | "value": '2014-12-05', |
| 1030 | "type": 'type:date' |
| 1031 | } |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1032 | ] |
| 1033 | }); |
| 1034 | |
| 1035 | var nestedGroupFactory = buildFactory(vcClass, { |
| 1036 | "@type" : "koral:docGroup", |
| 1037 | "operation" : "operation:or", |
| 1038 | "operands" : [ |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 1039 | { |
| 1040 | "@type": 'koral:doc', |
| 1041 | "key" : 'author', |
| 1042 | "match": 'match:eq', |
| 1043 | "value": 'Max Birkendale', |
| 1044 | "type": 'type:string' |
| 1045 | }, |
| 1046 | { |
| 1047 | "@type" : "koral:docGroup", |
| 1048 | "operation" : "operation:and", |
| 1049 | "operands" : [ |
| 1050 | { |
| 1051 | "@type": 'koral:doc', |
| 1052 | "key": 'pubDate', |
| 1053 | "match": 'match:geq', |
| 1054 | "value": '2014-05-12', |
| 1055 | "type": 'type:date' |
| 1056 | }, |
| 1057 | { |
| 1058 | "@type": 'koral:doc', |
| 1059 | "key": 'pubDate', |
| 1060 | "match": 'match:leq', |
| 1061 | "value": '2014-12-05', |
| 1062 | "type": 'type:date' |
| 1063 | } |
| 1064 | ] |
| 1065 | } |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1066 | ] |
| 1067 | }); |
| 1068 | |
| 1069 | var flatGroupFactory = buildFactory(vcClass, { |
| 1070 | "@type" : "koral:docGroup", |
| 1071 | "operation" : "operation:and", |
| 1072 | "operands" : [ |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 1073 | { |
| 1074 | "@type": 'koral:doc', |
| 1075 | "key": 'pubDate', |
| 1076 | "match": 'match:geq', |
| 1077 | "value": '2014-05-12', |
| 1078 | "type": 'type:date' |
| 1079 | }, |
| 1080 | { |
| 1081 | "@type": 'koral:doc', |
| 1082 | "key": 'pubDate', |
| 1083 | "match": 'match:leq', |
| 1084 | "value": '2014-12-05', |
| 1085 | "type": 'type:date' |
| 1086 | }, |
| 1087 | { |
| 1088 | "@type": 'koral:doc', |
| 1089 | "key": 'foo', |
| 1090 | "match": 'match:eq', |
| 1091 | "value": 'bar', |
| 1092 | "type": 'type:string' |
| 1093 | } |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1094 | ] |
| 1095 | }); |
| 1096 | |
| 1097 | it('should be initializable', function () { |
Nils Diewald | 6283d69 | 2015-04-23 20:32:53 +0000 | [diff] [blame] | 1098 | var vc = vcClass.create(); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1099 | expect(vc.element().getAttribute('class')).toEqual('vc'); |
| 1100 | expect(vc.root().element().getAttribute('class')).toEqual('doc unspecified'); |
| 1101 | |
| 1102 | // Not removable |
| 1103 | expect(vc.root().element().lastChild.children.length).toEqual(0); |
| 1104 | }); |
| 1105 | |
| 1106 | it('should be based on a doc', function () { |
Nils Diewald | 6283d69 | 2015-04-23 20:32:53 +0000 | [diff] [blame] | 1107 | var vc = vcClass.create().fromJson({ |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 1108 | "@type" : "koral:doc", |
| 1109 | "key":"Titel", |
| 1110 | "value":"Baum", |
| 1111 | "match":"match:eq" |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1112 | }); |
| 1113 | |
| 1114 | expect(vc.element().getAttribute('class')).toEqual('vc'); |
| 1115 | expect(vc.root().element().getAttribute('class')).toEqual('doc'); |
| 1116 | expect(vc.root().key()).toEqual('Titel'); |
| 1117 | expect(vc.root().value()).toEqual('Baum'); |
| 1118 | expect(vc.root().matchop()).toEqual('eq'); |
| 1119 | |
| 1120 | var docE = vc.root().element(); |
| 1121 | expect(docE.children[0].firstChild.data).toEqual('Titel'); |
| 1122 | expect(docE.children[1].firstChild.data).toEqual('eq'); |
| 1123 | expect(docE.children[1].getAttribute('data-type')).toEqual('string'); |
| 1124 | expect(docE.children[2].firstChild.data).toEqual('Baum'); |
| 1125 | expect(docE.children[2].getAttribute('data-type')).toEqual('string'); |
| 1126 | }); |
| 1127 | |
| 1128 | it('should be based on a docGroup', function () { |
Nils Diewald | 6283d69 | 2015-04-23 20:32:53 +0000 | [diff] [blame] | 1129 | var vc = vcClass.create().fromJson(simpleGroupFactory.create().toJson()); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1130 | |
| 1131 | expect(vc.element().getAttribute('class')).toEqual('vc'); |
| 1132 | expect(vc.root().element().getAttribute('class')).toEqual('docGroup'); |
| 1133 | expect(vc.root().operation()).toEqual('and'); |
| 1134 | |
| 1135 | var docGroup = vc.root(); |
| 1136 | |
| 1137 | var first = docGroup.getOperand(0); |
| 1138 | expect(first.key()).toEqual('author'); |
| 1139 | expect(first.value()).toEqual('Max Birkendale'); |
| 1140 | expect(first.matchop()).toEqual('eq'); |
| 1141 | |
| 1142 | var second = docGroup.getOperand(1); |
| 1143 | expect(second.key()).toEqual('pubDate'); |
| 1144 | expect(second.value()).toEqual('2014-12-05'); |
| 1145 | expect(second.matchop()).toEqual('eq'); |
| 1146 | }); |
| 1147 | |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 1148 | it('should be based on a docGroupRef', function () { |
| 1149 | var vc = vcClass.create().fromJson({ |
| 1150 | "@type" : "koral:docGroupRef", |
| 1151 | "ref":"myCorpus" |
| 1152 | }); |
| 1153 | |
| 1154 | // iv class="doc groupref"><span class="key fixed">@referTo</span><span data-type="string" class="value">myCorpus</span> |
| 1155 | var vcE = vc.element(); |
| 1156 | expect(vcE.getAttribute('class')).toEqual('vc'); |
| 1157 | expect(vcE.firstChild.tagName).toEqual('DIV'); |
| 1158 | expect(vcE.firstChild.classList.contains('groupref')).toBeTruthy(); |
| 1159 | |
| 1160 | expect(vcE.firstChild.firstChild.tagName).toEqual('SPAN'); |
| 1161 | expect(vcE.firstChild.firstChild.classList.contains('key')).toBeTruthy(); |
| 1162 | expect(vcE.firstChild.firstChild.classList.contains('fixed')).toBeTruthy(); |
| 1163 | |
| 1164 | expect(vcE.firstChild.firstChild.textContent).toEqual("@referTo"); |
| 1165 | |
| 1166 | expect(vcE.firstChild.children[1].tagName).toEqual('SPAN'); |
| 1167 | expect(vcE.firstChild.children[1].classList.contains('value')).toBeTruthy(); |
| 1168 | expect(vcE.firstChild.children[1].getAttribute('data-type')).toEqual('string'); |
| 1169 | expect(vcE.firstChild.children[1].textContent).toEqual("myCorpus"); |
| 1170 | }); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1171 | |
| 1172 | it('should be based on a nested docGroup', function () { |
| 1173 | var vc = nestedGroupFactory.create(); |
| 1174 | |
| 1175 | expect(vc.element().getAttribute('class')).toEqual('vc'); |
| 1176 | expect(vc.element().firstChild.getAttribute('class')).toEqual('docGroup'); |
| 1177 | expect(vc.element().firstChild.children[0].getAttribute('class')).toEqual('doc'); |
| 1178 | var dg = vc.element().firstChild.children[1]; |
| 1179 | expect(dg.getAttribute('class')).toEqual('docGroup'); |
| 1180 | expect(dg.children[0].getAttribute('class')).toEqual('doc'); |
| 1181 | expect(dg.children[1].getAttribute('class')).toEqual('doc'); |
Akron | 0b489ad | 2018-02-02 16:49:32 +0100 | [diff] [blame] | 1182 | expect(dg.children[2].getAttribute('class')).toEqual('operators button-group'); |
| 1183 | expect(vc.element().firstChild.children[2].getAttribute('class')).toEqual('operators button-group'); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1184 | }); |
| 1185 | |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 1186 | it('should be based on a nested docGroupRef', function () { |
| 1187 | var vc = vcClass.create().fromJson({ |
| 1188 | "@type" : "koral:docGroup", |
| 1189 | "operation" : "operation:and", |
| 1190 | "operands" : [{ |
| 1191 | "@type" : "koral:docGroupRef", |
| 1192 | "ref":"myCorpus" |
| 1193 | },{ |
| 1194 | "@type" : "koral:doc", |
| 1195 | "key":"Titel", |
| 1196 | "value":"Baum", |
| 1197 | "match":"match:eq" |
| 1198 | }] |
| 1199 | }); |
| 1200 | |
| 1201 | expect(vc._root.ldType()).toEqual("docGroup"); |
| 1202 | |
| 1203 | expect(vc.toQuery()).toEqual('referTo "myCorpus" & Titel = "Baum"'); |
| 1204 | }); |
| 1205 | |
| 1206 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1207 | it('should be modifiable by deletion in flat docGroups', function () { |
| 1208 | var vc = flatGroupFactory.create(); |
| 1209 | var docGroup = vc.root(); |
| 1210 | |
| 1211 | expect(docGroup.element().getAttribute('class')).toEqual('docGroup'); |
| 1212 | |
| 1213 | var doc = docGroup.getOperand(1); |
| 1214 | expect(doc.key()).toEqual("pubDate"); |
| 1215 | expect(doc.value()).toEqual("2014-12-05"); |
| 1216 | |
| 1217 | // Remove operand 1 |
| 1218 | expect(docGroup.delOperand(doc).update()).not.toBeUndefined(); |
| 1219 | expect(doc._element).toEqual(undefined); |
| 1220 | |
| 1221 | doc = docGroup.getOperand(1); |
| 1222 | expect(doc.key()).toEqual("foo"); |
| 1223 | |
| 1224 | // Remove operand 1 |
| 1225 | expect(docGroup.delOperand(doc).update()).not.toBeUndefined(); |
| 1226 | expect(doc._element).toEqual(undefined); |
| 1227 | |
| 1228 | // Only one operand left ... |
| 1229 | expect(docGroup.getOperand(1)).toBeUndefined(); |
| 1230 | // ... but there shouldn't be a group anymore at all! |
| 1231 | expect(docGroup.getOperand(0)).toBeUndefined(); |
| 1232 | |
| 1233 | var obj = vc.root(); |
| 1234 | expect(obj.ldType()).toEqual("doc"); |
| 1235 | expect(obj.key()).toEqual("pubDate"); |
| 1236 | expect(obj.value()).toEqual("2014-05-12"); |
| 1237 | |
| 1238 | expect(obj.element().getAttribute('class')).toEqual('doc'); |
| 1239 | }); |
| 1240 | |
| 1241 | |
| 1242 | it('should be modifiable by deletion in nested docGroups (root case)', function () { |
| 1243 | var vc = nestedGroupFactory.create(); |
| 1244 | |
| 1245 | expect(vc.toQuery()).toEqual( |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 1246 | '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] | 1247 | ); |
| 1248 | |
| 1249 | var docGroup = vc.root(); |
| 1250 | expect(docGroup.ldType()).toEqual("docGroup"); |
| 1251 | expect(docGroup.operation()).toEqual("or"); |
| 1252 | |
| 1253 | var doc = docGroup.getOperand(0); |
| 1254 | expect(doc.key()).toEqual("author"); |
| 1255 | expect(doc.value()).toEqual("Max Birkendale"); |
| 1256 | |
| 1257 | docGroup = docGroup.getOperand(1); |
| 1258 | expect(docGroup.operation()).toEqual("and"); |
| 1259 | |
| 1260 | doc = docGroup.getOperand(0); |
| 1261 | expect(doc.key()).toEqual("pubDate"); |
| 1262 | expect(doc.matchop()).toEqual("geq"); |
| 1263 | expect(doc.value()).toEqual("2014-05-12"); |
| 1264 | expect(doc.type()).toEqual("date"); |
| 1265 | |
| 1266 | doc = docGroup.getOperand(1); |
| 1267 | expect(doc.key()).toEqual("pubDate"); |
| 1268 | expect(doc.matchop()).toEqual("leq"); |
| 1269 | expect(doc.value()).toEqual("2014-12-05"); |
| 1270 | expect(doc.type()).toEqual("date"); |
| 1271 | |
| 1272 | // Remove first operand so everything becomes root |
| 1273 | expect( |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 1274 | vc.root().delOperand( |
| 1275 | vc.root().getOperand(0) |
| 1276 | ).update().ldType() |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1277 | ).toEqual("docGroup"); |
| 1278 | |
| 1279 | expect(vc.root().ldType()).toEqual("docGroup"); |
| 1280 | expect(vc.root().operation()).toEqual("and"); |
| 1281 | expect(vc.root().getOperand(0).ldType()).toEqual("doc"); |
| 1282 | |
| 1283 | expect(vc.toQuery()).toEqual( |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 1284 | 'pubDate since 2014-05-12 & pubDate until 2014-12-05' |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1285 | ); |
| 1286 | }); |
| 1287 | |
| 1288 | it('should be modifiable by deletion in nested docGroups (resolve group case)', function () { |
| 1289 | var vc = nestedGroupFactory.create(); |
| 1290 | |
| 1291 | // Get nested group |
| 1292 | var firstGroup = vc.root().getOperand(1); |
| 1293 | firstGroup.append(simpleGroupFactory.create({ "operation" : "operation:or" })); |
| 1294 | |
| 1295 | // Structur is now: |
| 1296 | // or(doc, and(doc, doc, or(doc, doc))) |
| 1297 | |
| 1298 | // Get nested or in and |
| 1299 | var orGroup = vc.root().getOperand(1).getOperand(2); |
| 1300 | expect(orGroup.ldType()).toEqual("docGroup"); |
| 1301 | expect(orGroup.operation()).toEqual("or"); |
| 1302 | |
| 1303 | // Remove |
| 1304 | // Structur is now: |
| 1305 | // or(doc, and(doc, doc, doc))) |
| 1306 | expect(orGroup.delOperand(orGroup.getOperand(0)).update().operation()).toEqual("and"); |
| 1307 | expect(vc.root().getOperand(1).operands().length).toEqual(3); |
| 1308 | }); |
| 1309 | |
| 1310 | it('should be modifiable by deletion in nested docGroups (identical group case)', function () { |
| 1311 | var vc = nestedGroupFactory.create(); |
| 1312 | |
| 1313 | // Get nested group |
| 1314 | var firstGroup = vc.root().getOperand(1); |
| 1315 | firstGroup.append(simpleGroupFactory.create({ |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 1316 | "operation" : "operation:or" |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1317 | })); |
| 1318 | var oldAuthor = firstGroup.getOperand(2).getOperand(0); |
| 1319 | oldAuthor.key("title"); |
| 1320 | oldAuthor.value("Der Birnbaum"); |
| 1321 | |
| 1322 | // Structur is now: |
| 1323 | // or(doc, and(doc, doc, or(doc, doc))) |
| 1324 | expect(vc.toQuery()).toEqual( |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 1325 | 'author = "Max Birkendale" | ' + |
| 1326 | '(pubDate since 2014-05-12 & ' + |
| 1327 | 'pubDate until 2014-12-05 & ' + |
| 1328 | '(title = "Der Birnbaum" | ' + |
| 1329 | 'pubDate in 2014-12-05))' |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1330 | ); |
| 1331 | |
| 1332 | var andGroup = vc.root().getOperand(1); |
| 1333 | |
| 1334 | // Get leading docs in and |
| 1335 | var doc1 = andGroup.getOperand(0); |
| 1336 | expect(doc1.ldType()).toEqual("doc"); |
| 1337 | expect(doc1.value()).toEqual("2014-05-12"); |
| 1338 | var doc2 = andGroup.getOperand(1); |
| 1339 | expect(doc2.ldType()).toEqual("doc"); |
| 1340 | expect(doc2.value()).toEqual("2014-12-05"); |
| 1341 | |
| 1342 | // Remove 2 |
| 1343 | expect( |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 1344 | andGroup.delOperand(doc2).update().operation() |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1345 | ).toEqual("and"); |
| 1346 | // Structur is now: |
| 1347 | // or(doc, and(doc, or(doc, doc))) |
| 1348 | |
| 1349 | expect(vc.toQuery()).toEqual( |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 1350 | 'author = "Max Birkendale"' + |
| 1351 | ' | (pubDate since 2014-05-12 & ' + |
| 1352 | '(title = "Der Birnbaum" | pubDate in 2014-12-05))' |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1353 | ); |
| 1354 | |
| 1355 | |
| 1356 | // Remove 1 |
| 1357 | expect(andGroup.delOperand(doc1).update().operation()).toEqual("or"); |
| 1358 | // Structur is now: |
| 1359 | // or(doc, doc, doc) |
| 1360 | |
| 1361 | expect(vc.toQuery()).toEqual( |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 1362 | 'author = "Max Birkendale" | title = "Der Birnbaum" | pubDate in 2014-12-05' |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1363 | ); |
| 1364 | }); |
| 1365 | |
| 1366 | it('should be reducible to unspecification', function () { |
| 1367 | var vc = demoFactory.create(); |
| 1368 | |
| 1369 | expect(vc.toQuery()).toEqual(vc.root().toQuery()); |
| 1370 | expect(vc.toQuery()).toEqual( |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 1371 | '(Titel = "Baum" & Veröffentlichungsort = "hihi" & ' + |
| 1372 | '(Titel = "Baum" | Veröffentlichungsort = "hihi")) ' + |
| 1373 | '| Untertitel ~ "huhu"'); |
Akron | d141a36 | 2018-07-10 18:12:13 +0200 | [diff] [blame] | 1374 | expect(vc.root().element().lastChild.children[0].innerText).toEqual('and'); |
| 1375 | expect(vc.root().element().lastChild.children[1].innerText).toEqual('×'); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1376 | expect(vc.root().delOperand(vc.root().getOperand(0)).update()).not.toBeUndefined(); |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 1377 | expect(vc.toQuery()).toEqual('Untertitel ~ "huhu"'); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1378 | |
| 1379 | var lc = vc.root().element().lastChild; |
Akron | d141a36 | 2018-07-10 18:12:13 +0200 | [diff] [blame] | 1380 | expect(lc.children[0].innerText).toEqual('and'); |
| 1381 | expect(lc.children[1].innerText).toEqual('or'); |
| 1382 | expect(lc.children[2].innerText).toEqual('×'); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1383 | |
| 1384 | // Clean everything |
| 1385 | vc.clean(); |
| 1386 | expect(vc.toQuery()).toEqual(''); |
| 1387 | }); |
| 1388 | |
| 1389 | it('should flatten on import', function () { |
Nils Diewald | 6283d69 | 2015-04-23 20:32:53 +0000 | [diff] [blame] | 1390 | var vc = vcClass.create().fromJson({ |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 1391 | "@type":"koral:docGroup", |
| 1392 | "operation":"operation:or", |
| 1393 | "operands":[ |
| 1394 | { |
| 1395 | "@type":"koral:docGroup", |
| 1396 | "operation":"operation:or", |
| 1397 | "operands":[ |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1398 | { |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 1399 | "@type":"koral:doc", |
| 1400 | "key":"Titel", |
| 1401 | "value":"Baum", |
| 1402 | "match":"match:eq" |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1403 | }, |
| 1404 | { |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 1405 | "@type":"koral:doc", |
| 1406 | "key":"Veröffentlichungsort", |
| 1407 | "value":"hihi", |
| 1408 | "match":"match:eq" |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1409 | }, |
| 1410 | { |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 1411 | "@type":"koral:docGroup", |
| 1412 | "operation":"operation:or", |
| 1413 | "operands":[ |
| 1414 | { |
| 1415 | "@type":"koral:doc", |
| 1416 | "key":"Titel", |
| 1417 | "value":"Baum", |
| 1418 | "match":"match:eq" |
| 1419 | }, |
| 1420 | { |
| 1421 | "@type":"koral:doc", |
| 1422 | "key":"Veröffentlichungsort", |
| 1423 | "value":"hihi", |
| 1424 | "match":"match:eq" |
| 1425 | } |
| 1426 | ] |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1427 | } |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 1428 | ] |
| 1429 | }, |
| 1430 | { |
| 1431 | "@type":"koral:doc", |
| 1432 | "key":"Untertitel", |
| 1433 | "value":"huhu", |
| 1434 | "match":"match:contains" |
| 1435 | } |
| 1436 | ] |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1437 | }); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 1438 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1439 | expect(vc.toQuery()).toEqual( |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 1440 | 'Titel = "Baum" | Veröffentlichungsort = "hihi" | Untertitel ~ "huhu"' |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1441 | ); |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 1442 | }); |
Akron | 1bdf527 | 2018-07-24 18:51:30 +0200 | [diff] [blame] | 1443 | |
| 1444 | it('should be deserializable from collection 1', function () { |
| 1445 | var kq = { |
| 1446 | "matches":["..."], |
| 1447 | "collection":{ |
| 1448 | "@type": "koral:docGroup", |
| 1449 | "operation": "operation:or", |
| 1450 | "operands": [{ |
| 1451 | "@type": "koral:docGroup", |
| 1452 | "operation": "operation:and", |
| 1453 | "operands": [ |
| 1454 | { |
| 1455 | "@type": "koral:doc", |
| 1456 | "key": "title", |
| 1457 | "match": "match:eq", |
| 1458 | "value": "Der Birnbaum", |
| 1459 | "type": "type:string" |
| 1460 | }, |
| 1461 | { |
| 1462 | "@type": "koral:doc", |
| 1463 | "key": "pubPlace", |
| 1464 | "match": "match:eq", |
| 1465 | "value": "Mannheim", |
| 1466 | "type": "type:string" |
| 1467 | }, |
| 1468 | { |
| 1469 | "@type": "koral:docGroup", |
| 1470 | "operation": "operation:or", |
| 1471 | "operands": [ |
| 1472 | { |
| 1473 | "@type": "koral:doc", |
| 1474 | "key": "subTitle", |
| 1475 | "match": "match:eq", |
| 1476 | "value": "Aufzucht und Pflege", |
| 1477 | "type": "type:string" |
| 1478 | }, |
| 1479 | { |
| 1480 | "@type": "koral:doc", |
| 1481 | "key": "subTitle", |
| 1482 | "match": "match:eq", |
| 1483 | "value": "Gedichte", |
| 1484 | "type": "type:string" |
| 1485 | } |
| 1486 | ] |
| 1487 | } |
| 1488 | ] |
| 1489 | },{ |
| 1490 | "@type": "koral:doc", |
| 1491 | "key": "pubDate", |
| 1492 | "match": "match:geq", |
| 1493 | "value": "2015-03-05", |
| 1494 | "type": "type:date", |
| 1495 | "rewrites" : [{ |
| 1496 | "@type" : "koral:rewrite", |
| 1497 | "operation" : "operation:modification", |
| 1498 | "src" : "querySerializer", |
| 1499 | "scope" : "tree" |
| 1500 | }] |
| 1501 | }] |
| 1502 | } |
| 1503 | }; |
| 1504 | |
| 1505 | var vc = vcClass.create().fromJson(kq["collection"]); |
| 1506 | expect(vc.toQuery()).toEqual('(title = "Der Birnbaum" & pubPlace = "Mannheim" & (subTitle = "Aufzucht und Pflege" | subTitle = "Gedichte")) | pubDate since 2015-03-05'); |
| 1507 | }); |
| 1508 | |
| 1509 | it('should be deserializable from collection 2', function () { |
| 1510 | var kq = { |
| 1511 | "@context": "http://korap.ids-mannheim.de/ns/KoralQuery/v0.3/context.jsonld", |
| 1512 | "meta": {}, |
| 1513 | "query": { |
| 1514 | "@type": "koral:token", |
| 1515 | "wrap": { |
| 1516 | "@type": "koral:term", |
| 1517 | "match": "match:eq", |
| 1518 | "layer": "orth", |
| 1519 | "key": "Baum", |
| 1520 | "foundry": "opennlp", |
| 1521 | "rewrites": [ |
| 1522 | { |
| 1523 | "@type": "koral:rewrite", |
| 1524 | "src": "Kustvakt", |
| 1525 | "operation": "operation:injection", |
| 1526 | "scope": "foundry" |
| 1527 | } |
| 1528 | ] |
| 1529 | }, |
| 1530 | "idn": "Baum_2227", |
| 1531 | "rewrites": [ |
| 1532 | { |
| 1533 | "@type": "koral:rewrite", |
| 1534 | "src": "Kustvakt", |
| 1535 | "operation": "operation:injection", |
| 1536 | "scope": "idn" |
| 1537 | } |
| 1538 | ] |
| 1539 | }, |
| 1540 | "collection": { |
| 1541 | "@type": "koral:docGroup", |
| 1542 | "operation": "operation:and", |
| 1543 | "operands": [ |
| 1544 | { |
| 1545 | "@type": "koral:doc", |
| 1546 | "match": "match:eq", |
| 1547 | "type": "type:regex", |
| 1548 | "value": "CC-BY.*", |
| 1549 | "key": "availability" |
| 1550 | }, |
| 1551 | { |
| 1552 | "@type": "koral:doc", |
| 1553 | "match": "match:eq", |
| 1554 | "type":"type:text", |
| 1555 | "value": "Goethe", |
| 1556 | "key": "author" |
| 1557 | } |
| 1558 | ], |
| 1559 | "rewrites": [ |
| 1560 | { |
| 1561 | "@type": "koral:rewrite", |
| 1562 | "src": "Kustvakt", |
| 1563 | "operation": "operation:insertion", |
| 1564 | "scope": "availability(FREE)" |
| 1565 | } |
| 1566 | ] |
| 1567 | }, |
| 1568 | "matches": [] |
| 1569 | }; |
| 1570 | |
| 1571 | var vc = vcClass.create().fromJson(kq["collection"]); |
| 1572 | expect(vc.toQuery()).toEqual('availability = /CC-BY.*/ & author = "Goethe"'); |
| 1573 | }); |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 1574 | }); |
| 1575 | |
Akron | 1bdf527 | 2018-07-24 18:51:30 +0200 | [diff] [blame] | 1576 | it('shouldn\'t be deserializable from collection with unknown type', function () { |
| 1577 | var kq = { |
| 1578 | "@type" : "koral:doc", |
| 1579 | "match": "match:eq", |
| 1580 | "type":"type:failure", |
| 1581 | "value": "Goethe", |
| 1582 | "key": "author" |
| 1583 | }; |
| 1584 | |
| 1585 | expect(function () { |
| 1586 | vcClass.create().fromJson(kq) |
| 1587 | }).toThrow(new Error("Unknown value type: string")); |
Akron | 1bdf527 | 2018-07-24 18:51:30 +0200 | [diff] [blame] | 1588 | }); |
| 1589 | |
| 1590 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1591 | describe('KorAP.Operators', function () { |
| 1592 | it('should be initializable', function () { |
| 1593 | var op = operatorsClass.create(true, false, false); |
| 1594 | expect(op.and()).toBeTruthy(); |
| 1595 | expect(op.or()).not.toBeTruthy(); |
| 1596 | expect(op.del()).not.toBeTruthy(); |
| 1597 | |
| 1598 | op.and(false); |
| 1599 | expect(op.and()).not.toBeTruthy(); |
| 1600 | expect(op.or()).not.toBeTruthy(); |
| 1601 | expect(op.del()).not.toBeTruthy(); |
| 1602 | |
| 1603 | op.or(true); |
| 1604 | op.del(true); |
| 1605 | expect(op.and()).not.toBeTruthy(); |
| 1606 | expect(op.or()).toBeTruthy(); |
| 1607 | expect(op.del()).toBeTruthy(); |
| 1608 | |
Akron | d141a36 | 2018-07-10 18:12:13 +0200 | [diff] [blame] | 1609 | var e = op.update(); |
Akron | 0b489ad | 2018-02-02 16:49:32 +0100 | [diff] [blame] | 1610 | expect(e.getAttribute('class')).toEqual('operators button-group'); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1611 | expect(e.children[0].getAttribute('class')).toEqual('or'); |
Akron | d141a36 | 2018-07-10 18:12:13 +0200 | [diff] [blame] | 1612 | expect(e.children[0].innerText).toEqual('or'); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1613 | expect(e.children[1].getAttribute('class')).toEqual('delete'); |
Akron | d141a36 | 2018-07-10 18:12:13 +0200 | [diff] [blame] | 1614 | expect(e.children[1].innerText).toEqual('×'); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1615 | |
| 1616 | op.and(true); |
| 1617 | op.del(false); |
Akron | d141a36 | 2018-07-10 18:12:13 +0200 | [diff] [blame] | 1618 | e = op.update(); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1619 | |
Akron | 0b489ad | 2018-02-02 16:49:32 +0100 | [diff] [blame] | 1620 | expect(e.getAttribute('class')).toEqual('operators button-group'); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1621 | expect(e.children[0].getAttribute('class')).toEqual('and'); |
Akron | d141a36 | 2018-07-10 18:12:13 +0200 | [diff] [blame] | 1622 | expect(e.children[0].innerText).toEqual('and'); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1623 | expect(e.children[1].getAttribute('class')).toEqual('or'); |
Akron | d141a36 | 2018-07-10 18:12:13 +0200 | [diff] [blame] | 1624 | expect(e.children[1].innerText).toEqual('or'); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1625 | }); |
| 1626 | }); |
| 1627 | |
| 1628 | describe('KorAP._delete (event)', function () { |
| 1629 | var complexVCFactory = buildFactory(vcClass,{ |
| 1630 | "@type": 'koral:docGroup', |
| 1631 | 'operation' : 'operation:and', |
| 1632 | 'operands' : [ |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 1633 | { |
| 1634 | "@type": 'koral:doc', |
| 1635 | "key": 'pubDate', |
| 1636 | "match": 'match:eq', |
| 1637 | "value": '2014-12-05', |
| 1638 | "type": 'type:date' |
| 1639 | }, |
| 1640 | { |
| 1641 | "@type" : 'koral:docGroup', |
| 1642 | 'operation' : 'operation:or', |
| 1643 | 'operands' : [ |
| 1644 | { |
| 1645 | '@type' : 'koral:doc', |
| 1646 | 'key' : 'title', |
| 1647 | 'value' : 'Hello World!' |
| 1648 | }, |
| 1649 | { |
| 1650 | '@type' : 'koral:doc', |
| 1651 | 'key' : 'foo', |
| 1652 | 'value' : 'bar' |
| 1653 | } |
| 1654 | ] |
| 1655 | } |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1656 | ] |
| 1657 | }); |
| 1658 | |
| 1659 | it('should clean on root docs', function () { |
Nils Diewald | 6283d69 | 2015-04-23 20:32:53 +0000 | [diff] [blame] | 1660 | var vc = vcClass.create().fromJson({ |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 1661 | "@type": 'koral:doc', |
| 1662 | "key": 'pubDate', |
| 1663 | "match": 'match:eq', |
| 1664 | "value": '2014-12-05', |
| 1665 | "type": 'type:date' |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 1666 | }); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1667 | expect(vc.root().toQuery()).toEqual('pubDate in 2014-12-05'); |
Akron | 0b489ad | 2018-02-02 16:49:32 +0100 | [diff] [blame] | 1668 | expect(vc.root().element().lastChild.getAttribute('class')).toEqual('operators button-group'); |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 1669 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1670 | // Clean with delete from root |
| 1671 | expect(vc.root().element().lastChild.lastChild.getAttribute('class')).toEqual('delete'); |
| 1672 | _delOn(vc.root()); |
| 1673 | expect(vc.root().toQuery()).toEqual(''); |
| 1674 | expect(vc.root().element().lastChild.lastChild.data).toEqual('⋯'); |
| 1675 | }); |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 1676 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1677 | it('should remove on nested docs', function () { |
Nils Diewald | 6283d69 | 2015-04-23 20:32:53 +0000 | [diff] [blame] | 1678 | var vc = vcClass.create().fromJson( |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 1679 | { |
| 1680 | "@type": 'koral:docGroup', |
| 1681 | 'operation' : 'operation:and', |
| 1682 | 'operands' : [ |
| 1683 | { |
| 1684 | "@type": 'koral:doc', |
| 1685 | "key": 'pubDate', |
| 1686 | "match": 'match:eq', |
| 1687 | "value": '2014-12-05', |
| 1688 | "type": 'type:date' |
| 1689 | }, |
| 1690 | { |
| 1691 | "@type" : 'koral:doc', |
| 1692 | 'key' : 'foo', |
| 1693 | 'value' : 'bar' |
| 1694 | } |
| 1695 | ] |
| 1696 | } |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1697 | ); |
| 1698 | |
| 1699 | // Delete with direct element access |
| 1700 | expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar"'); |
| 1701 | _delOn(vc.root().getOperand(0)); |
| 1702 | |
| 1703 | expect(vc.toQuery()).toEqual('foo = "bar"'); |
| 1704 | expect(vc.root().ldType()).toEqual('doc'); |
| 1705 | }); |
| 1706 | |
| 1707 | it('should clean on doc groups', function () { |
Nils Diewald | 6283d69 | 2015-04-23 20:32:53 +0000 | [diff] [blame] | 1708 | var vc = vcClass.create().fromJson( |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 1709 | { |
| 1710 | "@type": 'koral:docGroup', |
| 1711 | 'operation' : 'operation:and', |
| 1712 | 'operands' : [ |
| 1713 | { |
| 1714 | "@type": 'koral:doc', |
| 1715 | "key": 'pubDate', |
| 1716 | "match": 'match:eq', |
| 1717 | "value": '2014-12-05', |
| 1718 | "type": 'type:date' |
| 1719 | }, |
| 1720 | { |
| 1721 | "@type" : 'koral:doc', |
| 1722 | 'key' : 'foo', |
| 1723 | 'value' : 'bar' |
| 1724 | } |
| 1725 | ] |
| 1726 | } |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1727 | ); |
| 1728 | |
| 1729 | // Cleanwith direct element access |
| 1730 | expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar"'); |
| 1731 | _delOn(vc.root()); |
| 1732 | expect(vc.toQuery()).toEqual(''); |
| 1733 | expect(vc.root().ldType()).toEqual('non'); |
| 1734 | }); |
| 1735 | |
| 1736 | it('should remove on nested doc groups (case of ungrouping 1)', function () { |
| 1737 | var vc = complexVCFactory.create(); |
| 1738 | |
| 1739 | // Delete with direct element access |
| 1740 | expect(vc.toQuery()).toEqual( |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 1741 | 'pubDate in 2014-12-05 & (title = "Hello World!" | foo = "bar")' |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1742 | ); |
| 1743 | |
| 1744 | // Remove hello world: |
| 1745 | _delOn(vc.root().getOperand(1).getOperand(0)); |
| 1746 | expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar"'); |
| 1747 | expect(vc.root().ldType()).toEqual('docGroup'); |
| 1748 | }); |
| 1749 | |
| 1750 | it('should remove on nested doc groups (case of ungrouping 2)', function () { |
| 1751 | var vc = complexVCFactory.create(); |
| 1752 | |
| 1753 | // Delete with direct element access |
| 1754 | expect(vc.toQuery()).toEqual( |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 1755 | 'pubDate in 2014-12-05 & (title = "Hello World!" | foo = "bar")' |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1756 | ); |
| 1757 | |
| 1758 | // Remove bar |
| 1759 | _delOn(vc.root().getOperand(1).getOperand(1)); |
| 1760 | expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & title = "Hello World!"'); |
| 1761 | expect(vc.root().ldType()).toEqual('docGroup'); |
| 1762 | expect(vc.root().operation()).toEqual('and'); |
| 1763 | }); |
| 1764 | |
| 1765 | it('should remove on nested doc groups (case of root changing)', function () { |
| 1766 | var vc = complexVCFactory.create(); |
| 1767 | |
| 1768 | // Delete with direct element access |
| 1769 | expect(vc.toQuery()).toEqual( |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 1770 | 'pubDate in 2014-12-05 & ' + |
| 1771 | '(title = "Hello World!" | foo = "bar")' |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1772 | ); |
| 1773 | |
| 1774 | // Remove bar |
| 1775 | _delOn(vc.root().getOperand(0)); |
| 1776 | expect(vc.toQuery()).toEqual('title = "Hello World!" | foo = "bar"'); |
| 1777 | expect(vc.root().ldType()).toEqual('docGroup'); |
| 1778 | expect(vc.root().operation()).toEqual('or'); |
| 1779 | }); |
| 1780 | |
| 1781 | it('should remove on nested doc groups (list flattening)', function () { |
Nils Diewald | 6283d69 | 2015-04-23 20:32:53 +0000 | [diff] [blame] | 1782 | var vc = vcClass.create().fromJson( |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 1783 | { |
| 1784 | "@type": 'koral:docGroup', |
| 1785 | 'operation' : 'operation:or', |
| 1786 | 'operands' : [ |
| 1787 | { |
| 1788 | "@type": 'koral:doc', |
| 1789 | "key": 'pubDate', |
| 1790 | "match": 'match:eq', |
| 1791 | "value": '2014-12-05', |
| 1792 | "type": 'type:date' |
| 1793 | }, |
| 1794 | { |
| 1795 | "@type" : 'koral:doc', |
| 1796 | 'key' : 'foo', |
| 1797 | 'value' : 'bar' |
| 1798 | }, |
| 1799 | { |
| 1800 | "@type": 'koral:docGroup', |
| 1801 | 'operation' : 'operation:and', |
| 1802 | 'operands' : [ |
| 1803 | { |
| 1804 | "@type": 'koral:doc', |
| 1805 | "key": 'pubDate', |
| 1806 | "match": 'match:eq', |
| 1807 | "value": '2014-12-05', |
| 1808 | "type": 'type:date' |
| 1809 | }, |
| 1810 | { |
| 1811 | "@type" : 'koral:docGroup', |
| 1812 | 'operation' : 'operation:or', |
| 1813 | 'operands' : [ |
| 1814 | { |
| 1815 | '@type' : 'koral:doc', |
| 1816 | 'key' : 'title', |
| 1817 | 'value' : 'Hello World!' |
| 1818 | }, |
| 1819 | { |
| 1820 | '@type' : 'koral:doc', |
| 1821 | 'key' : 'yeah', |
| 1822 | 'value' : 'juhu' |
| 1823 | } |
| 1824 | ] |
| 1825 | } |
| 1826 | ] |
| 1827 | } |
| 1828 | ] |
| 1829 | } |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1830 | ); |
| 1831 | |
| 1832 | // Delete with direct element access |
| 1833 | expect(vc.toQuery()).toEqual( |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 1834 | 'pubDate in 2014-12-05 | foo = "bar" | ' + |
| 1835 | '(pubDate in 2014-12-05 & ' + |
| 1836 | '(title = "Hello World!" | yeah = "juhu"))' |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1837 | ); |
| 1838 | |
| 1839 | expect(vc.root().ldType()).toEqual('docGroup'); |
| 1840 | expect(vc.root().operation()).toEqual('or'); |
| 1841 | |
| 1842 | // Operands and operators |
| 1843 | expect(vc.element().firstChild.children.length).toEqual(4); |
Akron | 0b489ad | 2018-02-02 16:49:32 +0100 | [diff] [blame] | 1844 | expect(vc.element().firstChild.lastChild.getAttribute('class')).toEqual('operators button-group'); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1845 | |
| 1846 | // Remove inner group and flatten |
| 1847 | _delOn(vc.root().getOperand(2).getOperand(0)); |
| 1848 | |
| 1849 | expect(vc.toQuery()).toEqual( |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 1850 | 'pubDate in 2014-12-05 | foo = "bar" | title = "Hello World!" | yeah = "juhu"' |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1851 | ); |
| 1852 | expect(vc.root().ldType()).toEqual('docGroup'); |
| 1853 | expect(vc.root().operation()).toEqual('or'); |
| 1854 | |
| 1855 | // Operands and operators |
| 1856 | expect(vc.element().firstChild.children.length).toEqual(5); |
Akron | 0b489ad | 2018-02-02 16:49:32 +0100 | [diff] [blame] | 1857 | expect(vc.element().firstChild.lastChild.getAttribute('class')).toEqual('operators button-group'); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1858 | }); |
| 1859 | }); |
| 1860 | |
| 1861 | describe('KorAP._add (event)', function () { |
| 1862 | var complexVCFactory = buildFactory(vcClass,{ |
| 1863 | "@type": 'koral:docGroup', |
| 1864 | 'operation' : 'operation:and', |
| 1865 | 'operands' : [ |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 1866 | { |
| 1867 | "@type": 'koral:doc', |
| 1868 | "key": 'pubDate', |
| 1869 | "match": 'match:eq', |
| 1870 | "value": '2014-12-05', |
| 1871 | "type": 'type:date' |
| 1872 | }, |
| 1873 | { |
| 1874 | "@type" : 'koral:docGroup', |
| 1875 | 'operation' : 'operation:or', |
| 1876 | 'operands' : [ |
| 1877 | { |
| 1878 | '@type' : 'koral:doc', |
| 1879 | 'key' : 'title', |
| 1880 | 'value' : 'Hello World!' |
| 1881 | }, |
| 1882 | { |
| 1883 | '@type' : 'koral:doc', |
| 1884 | 'key' : 'foo', |
| 1885 | 'value' : 'bar' |
| 1886 | } |
| 1887 | ] |
| 1888 | } |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1889 | ] |
| 1890 | }); |
| 1891 | |
| 1892 | it('should add new unspecified doc with "and"', function () { |
Nils Diewald | 6283d69 | 2015-04-23 20:32:53 +0000 | [diff] [blame] | 1893 | var vc = vcClass.create().fromJson( |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 1894 | { |
| 1895 | "@type": 'koral:docGroup', |
| 1896 | 'operation' : 'operation:and', |
| 1897 | 'operands' : [ |
| 1898 | { |
| 1899 | "@type": 'koral:doc', |
| 1900 | "key": 'pubDate', |
| 1901 | "match": 'match:eq', |
| 1902 | "value": '2014-12-05', |
| 1903 | "type": 'type:date' |
| 1904 | }, |
| 1905 | { |
| 1906 | "@type" : 'koral:doc', |
| 1907 | 'key' : 'foo', |
| 1908 | 'value' : 'bar' |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 1909 | }, |
| 1910 | { |
| 1911 | "@type" : "koral:docGroupRef", |
| 1912 | "ref" : "myCorpus" |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 1913 | } |
| 1914 | ] |
| 1915 | } |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1916 | ); |
| 1917 | |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 1918 | expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar" & referTo "myCorpus"'); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1919 | |
| 1920 | var fc = vc.element().firstChild; |
| 1921 | expect(fc.getAttribute('data-operation')).toEqual('and'); |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 1922 | expect(fc.children.length).toEqual(4); |
Akron | 0b489ad | 2018-02-02 16:49:32 +0100 | [diff] [blame] | 1923 | expect(fc.lastChild.getAttribute('class')).toEqual('operators button-group'); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1924 | expect(fc.children[0].getAttribute('class')).toEqual('doc'); |
| 1925 | expect(fc.children[1].getAttribute('class')).toEqual('doc'); |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 1926 | expect(fc.children[2].getAttribute('class')).toEqual('doc groupref'); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1927 | |
| 1928 | // add with 'and' in the middle |
| 1929 | _andOn(vc.root().getOperand(0)); |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 1930 | expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar" & referTo "myCorpus"'); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1931 | |
| 1932 | fc = vc.element().firstChild; |
| 1933 | expect(fc.getAttribute('data-operation')).toEqual('and'); |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 1934 | expect(fc.children.length).toEqual(5); |
Akron | 0b489ad | 2018-02-02 16:49:32 +0100 | [diff] [blame] | 1935 | expect(fc.lastChild.getAttribute('class')).toEqual('operators button-group'); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1936 | |
| 1937 | expect(fc.children[0].getAttribute('class')).toEqual('doc'); |
| 1938 | expect(fc.children[1].getAttribute('class')).toEqual('doc unspecified'); |
| 1939 | expect(fc.children[2].getAttribute('class')).toEqual('doc'); |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 1940 | expect(fc.children[3].getAttribute('class')).toEqual('doc groupref'); |
| 1941 | expect(fc.children[4].classList.contains('button-group')).toBeTruthy(); |
| 1942 | expect(fc.children.length).toEqual(5); |
| 1943 | |
| 1944 | _andOn(vc.root().getOperand(3)); |
| 1945 | expect(fc.children[0].getAttribute('class')).toEqual('doc'); |
| 1946 | expect(fc.children[1].getAttribute('class')).toEqual('doc unspecified'); |
| 1947 | expect(fc.children[2].getAttribute('class')).toEqual('doc'); |
| 1948 | expect(fc.children[3].getAttribute('class')).toEqual('doc groupref'); |
| 1949 | expect(fc.children[4].getAttribute('class')).toEqual('doc unspecified'); |
| 1950 | expect(fc.children[5].classList.contains('button-group')).toBeTruthy(); |
| 1951 | expect(fc.children.length).toEqual(6); |
| 1952 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1953 | }); |
| 1954 | |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 1955 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1956 | it('should add new unspecified doc with "or"', function () { |
Nils Diewald | 6283d69 | 2015-04-23 20:32:53 +0000 | [diff] [blame] | 1957 | var vc = vcClass.create().fromJson( |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 1958 | { |
| 1959 | "@type": 'koral:docGroup', |
| 1960 | 'operation' : 'operation:and', |
| 1961 | 'operands' : [ |
| 1962 | { |
| 1963 | "@type": 'koral:doc', |
| 1964 | "key": 'pubDate', |
| 1965 | "match": 'match:eq', |
| 1966 | "value": '2014-12-05', |
| 1967 | "type": 'type:date' |
| 1968 | }, |
| 1969 | { |
| 1970 | "@type" : 'koral:doc', |
| 1971 | 'key' : 'foo', |
| 1972 | 'value' : 'bar' |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 1973 | }, |
| 1974 | { |
| 1975 | "@type" : "koral:docGroupRef", |
| 1976 | "ref" : "myCorpus" |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 1977 | } |
| 1978 | ] |
| 1979 | } |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1980 | ); |
| 1981 | |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 1982 | expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar" & referTo "myCorpus"'); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1983 | |
| 1984 | var fc = vc.element().firstChild; |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 1985 | expect(fc.children.length).toEqual(4); |
Akron | 0b489ad | 2018-02-02 16:49:32 +0100 | [diff] [blame] | 1986 | expect(fc.lastChild.getAttribute('class')).toEqual('operators button-group'); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1987 | expect(fc.children[0].getAttribute('class')).toEqual('doc'); |
| 1988 | expect(fc.children[1].getAttribute('class')).toEqual('doc'); |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 1989 | expect(fc.children[2].getAttribute('class')).toEqual('doc groupref'); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1990 | |
| 1991 | // add with 'or' in the middle |
| 1992 | _orOn(vc.root().getOperand(0)); |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 1993 | expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar" & referTo "myCorpus"'); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1994 | fc = vc.element().firstChild; |
| 1995 | |
| 1996 | expect(fc.getAttribute('data-operation')).toEqual('and'); |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 1997 | expect(fc.children.length).toEqual(4); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1998 | expect(fc.children[0].getAttribute('class')).toEqual('docGroup'); |
| 1999 | expect(fc.children[0].getAttribute('data-operation')).toEqual('or'); |
| 2000 | expect(fc.children[1].getAttribute('class')).toEqual('doc'); |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 2001 | expect(fc.children[2].getAttribute('class')).toEqual('doc groupref'); |
| 2002 | expect(fc.children[3].getAttribute('class')).toEqual('operators button-group'); |
Akron | 0b489ad | 2018-02-02 16:49:32 +0100 | [diff] [blame] | 2003 | expect(fc.lastChild.getAttribute('class')).toEqual('operators button-group'); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 2004 | |
| 2005 | fc = vc.element().firstChild.firstChild; |
| 2006 | expect(fc.children.length).toEqual(3); |
| 2007 | expect(fc.children[0].getAttribute('class')).toEqual('doc'); |
| 2008 | expect(fc.children[1].getAttribute('class')).toEqual('doc unspecified'); |
Akron | 0b489ad | 2018-02-02 16:49:32 +0100 | [diff] [blame] | 2009 | expect(fc.children[2].getAttribute('class')).toEqual('operators button-group'); |
| 2010 | expect(fc.lastChild.getAttribute('class')).toEqual('operators button-group'); |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 2011 | |
| 2012 | _orOn(vc.root().getOperand(2)); |
| 2013 | fc = vc.element().firstChild; |
| 2014 | expect(fc.children.length).toEqual(4); |
| 2015 | |
| 2016 | expect(fc.children[0].getAttribute('class')).toEqual('docGroup'); |
| 2017 | expect(fc.children[1].getAttribute('class')).toEqual('doc'); |
| 2018 | expect(fc.children[2].getAttribute('class')).toEqual('docGroup'); |
| 2019 | expect(fc.children[3].getAttribute('class')).toEqual('operators button-group'); |
| 2020 | |
| 2021 | fc = vc.element().firstChild.children[2]; |
| 2022 | expect(fc.children[0].getAttribute('class')).toEqual('doc groupref'); |
| 2023 | expect(fc.children[1].getAttribute('class')).toEqual('doc unspecified'); |
| 2024 | expect(fc.children[2].getAttribute('class')).toEqual('operators button-group'); |
| 2025 | expect(fc.lastChild.getAttribute('class')).toEqual('operators button-group'); |
| 2026 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 2027 | }); |
| 2028 | |
| 2029 | it('should add new unspecified doc with "and" before group', function () { |
| 2030 | var vc = demoFactory.create(); |
| 2031 | |
| 2032 | // Wrap with direct element access |
| 2033 | expect(vc.toQuery()).toEqual( |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 2034 | '(Titel = "Baum" & ' + |
| 2035 | 'Veröffentlichungsort = "hihi" & ' + |
| 2036 | '(Titel = "Baum" | ' + |
| 2037 | 'Veröffentlichungsort = "hihi")) | ' + |
| 2038 | 'Untertitel ~ "huhu"' |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 2039 | ); |
| 2040 | |
| 2041 | expect(vc.root().getOperand(0).ldType()).toEqual('docGroup'); |
| 2042 | expect(vc.root().getOperand(0).operation()).toEqual('and'); |
| 2043 | expect(vc.root().getOperand(0).operands().length).toEqual(3); |
| 2044 | |
| 2045 | // Add unspecified on the second doc |
| 2046 | var secDoc = vc.root().getOperand(0).getOperand(1); |
| 2047 | expect(secDoc.value()).toEqual('hihi'); |
| 2048 | |
| 2049 | // Add |
| 2050 | _andOn(secDoc); |
| 2051 | |
| 2052 | var fo = vc.root().getOperand(0); |
| 2053 | |
| 2054 | expect(fo.ldType()).toEqual('docGroup'); |
| 2055 | expect(fo.operation()).toEqual('and'); |
| 2056 | expect(fo.operands().length).toEqual(4); |
| 2057 | |
| 2058 | expect(fo.getOperand(0).ldType()).toEqual('doc'); |
| 2059 | expect(fo.getOperand(1).ldType()).toEqual('doc'); |
| 2060 | expect(fo.getOperand(2).ldType()).toEqual('non'); |
| 2061 | expect(fo.getOperand(3).ldType()).toEqual('docGroup'); |
| 2062 | }); |
| 2063 | |
| 2064 | |
| 2065 | it('should remove a doc with an unspecified doc in a nested group', function () { |
| 2066 | var vc = demoFactory.create(); |
| 2067 | |
| 2068 | // Wrap with direct element access |
| 2069 | expect(vc.toQuery()).toEqual( |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 2070 | '(Titel = "Baum" & Veröffentlichungsort = "hihi" & (Titel = "Baum" | Veröffentlichungsort = "hihi")) | Untertitel ~ "huhu"' |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 2071 | ); |
| 2072 | |
| 2073 | var fo = vc.root().getOperand(0).getOperand(0); |
| 2074 | expect(fo.key()).toEqual('Titel'); |
| 2075 | expect(fo.value()).toEqual('Baum'); |
| 2076 | |
| 2077 | // Add unspecified on the root group |
| 2078 | _orOn(fo); |
| 2079 | |
| 2080 | fo = vc.root().getOperand(0).getOperand(0); |
| 2081 | |
| 2082 | expect(fo.operation()).toEqual('or'); |
| 2083 | expect(fo.getOperand(0).ldType()).toEqual('doc'); |
| 2084 | expect(fo.getOperand(1).ldType()).toEqual('non'); |
| 2085 | |
| 2086 | // Delete document |
| 2087 | _delOn(fo.getOperand(0)); |
| 2088 | |
| 2089 | // The operand is now non |
| 2090 | expect(vc.root().getOperand(0).getOperand(0).ldType()).toEqual('non'); |
| 2091 | expect(vc.root().getOperand(0).getOperand(1).ldType()).toEqual('doc'); |
| 2092 | expect(vc.root().getOperand(0).getOperand(2).ldType()).toEqual('docGroup'); |
| 2093 | }); |
| 2094 | |
| 2095 | |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 2096 | 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] | 2097 | var vc = demoFactory.create(); |
| 2098 | |
| 2099 | // Wrap with direct element access |
| 2100 | expect(vc.toQuery()).toEqual( |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 2101 | '(Titel = "Baum" & ' + |
| 2102 | 'Veröffentlichungsort = "hihi" & ' + |
| 2103 | '(Titel = "Baum" ' + |
| 2104 | '| Veröffentlichungsort = "hihi")) | ' + |
| 2105 | 'Untertitel ~ "huhu"' |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 2106 | ); |
| 2107 | |
| 2108 | var fo = vc.root().getOperand(0).getOperand(0); |
| 2109 | expect(fo.key()).toEqual('Titel'); |
| 2110 | expect(fo.value()).toEqual('Baum'); |
| 2111 | |
| 2112 | // Add unspecified on the root group |
| 2113 | _orOn(fo); |
| 2114 | |
| 2115 | fo = vc.root().getOperand(0).getOperand(0); |
| 2116 | |
| 2117 | expect(fo.operation()).toEqual('or'); |
| 2118 | expect(fo.getOperand(0).ldType()).toEqual('doc'); |
| 2119 | expect(fo.getOperand(1).ldType()).toEqual('non'); |
| 2120 | |
| 2121 | // Delete unspecified doc |
| 2122 | _delOn(fo.getOperand(1)); |
| 2123 | |
| 2124 | // The operand is now non |
| 2125 | fo = vc.root().getOperand(0); |
| 2126 | expect(fo.getOperand(0).ldType()).toEqual('doc'); |
| 2127 | expect(fo.getOperand(0).key()).toEqual('Titel'); |
| 2128 | expect(fo.getOperand(0).value()).toEqual('Baum'); |
| 2129 | expect(fo.getOperand(1).ldType()).toEqual('doc'); |
| 2130 | expect(fo.getOperand(2).ldType()).toEqual('docGroup'); |
| 2131 | }); |
| 2132 | |
| 2133 | |
| 2134 | it('should add on parent group (case "and")', function () { |
| 2135 | var vc = complexVCFactory.create(); |
| 2136 | |
| 2137 | // Wrap with direct element access |
| 2138 | expect(vc.toQuery()).toEqual( |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 2139 | 'pubDate in 2014-12-05 & (title = "Hello World!" | foo = "bar")' |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 2140 | ); |
| 2141 | |
| 2142 | expect(vc.root().operands().length).toEqual(2); |
| 2143 | |
| 2144 | // Add unspecified on the root group |
| 2145 | _andOn(vc.root().getOperand(1)); |
| 2146 | expect(vc.toQuery()).toEqual( |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 2147 | 'pubDate in 2014-12-05 & (title = "Hello World!" | foo = "bar")' |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 2148 | ); |
| 2149 | |
| 2150 | expect(vc.root().ldType()).toEqual('docGroup'); |
| 2151 | expect(vc.root().operands().length).toEqual(3); |
| 2152 | expect(vc.root().getOperand(0).ldType()).toEqual('doc'); |
| 2153 | expect(vc.root().getOperand(1).ldType()).toEqual('docGroup'); |
| 2154 | expect(vc.root().getOperand(1).operation()).toEqual('or'); |
| 2155 | expect(vc.root().getOperand(2).ldType()).toEqual('non'); |
| 2156 | |
| 2157 | // Add another unspecified on the root group |
| 2158 | _andOn(vc.root().getOperand(1)); |
| 2159 | |
| 2160 | expect(vc.root().operands().length).toEqual(4); |
| 2161 | expect(vc.root().getOperand(0).ldType()).toEqual('doc'); |
| 2162 | expect(vc.root().getOperand(1).ldType()).toEqual('docGroup'); |
| 2163 | expect(vc.root().getOperand(2).ldType()).toEqual('non'); |
| 2164 | expect(vc.root().getOperand(3).ldType()).toEqual('non'); |
| 2165 | |
| 2166 | // Add another unspecified after the first doc |
| 2167 | _andOn(vc.root().getOperand(0)); |
| 2168 | |
| 2169 | expect(vc.root().operands().length).toEqual(5); |
| 2170 | expect(vc.root().getOperand(0).ldType()).toEqual('doc'); |
| 2171 | expect(vc.root().getOperand(1).ldType()).toEqual('non'); |
| 2172 | expect(vc.root().getOperand(2).ldType()).toEqual('docGroup'); |
| 2173 | expect(vc.root().getOperand(3).ldType()).toEqual('non'); |
| 2174 | expect(vc.root().getOperand(4).ldType()).toEqual('non'); |
| 2175 | }); |
| 2176 | |
| 2177 | it('should wrap on root', function () { |
Nils Diewald | 6283d69 | 2015-04-23 20:32:53 +0000 | [diff] [blame] | 2178 | var vc = vcClass.create().fromJson( |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 2179 | { |
| 2180 | "@type": 'koral:docGroup', |
| 2181 | 'operation' : 'operation:and', |
| 2182 | 'operands' : [ |
| 2183 | { |
| 2184 | "@type": 'koral:doc', |
| 2185 | "key": 'pubDate', |
| 2186 | "match": 'match:eq', |
| 2187 | "value": '2014-12-05', |
| 2188 | "type": 'type:date' |
| 2189 | }, |
| 2190 | { |
| 2191 | "@type" : 'koral:doc', |
| 2192 | 'key' : 'foo', |
| 2193 | 'value' : 'bar' |
| 2194 | } |
| 2195 | ] |
| 2196 | } |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 2197 | ); |
| 2198 | |
| 2199 | // Wrap on root |
| 2200 | expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar"'); |
| 2201 | expect(vc.root().ldType()).toEqual('docGroup'); |
| 2202 | expect(vc.root().operation()).toEqual('and'); |
| 2203 | _orOn(vc.root()); |
| 2204 | expect(vc.root().ldType()).toEqual('docGroup'); |
| 2205 | expect(vc.root().operation()).toEqual('or'); |
| 2206 | |
| 2207 | expect(vc.root().getOperand(0).ldType()).toEqual('docGroup'); |
| 2208 | expect(vc.root().getOperand(0).operation()).toEqual('and'); |
| 2209 | }); |
| 2210 | |
| 2211 | it('should add on root (case "and")', function () { |
Nils Diewald | 6283d69 | 2015-04-23 20:32:53 +0000 | [diff] [blame] | 2212 | var vc = vcClass.create().fromJson( |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 2213 | { |
| 2214 | "@type": 'koral:doc', |
| 2215 | "key": 'pubDate', |
| 2216 | "match": 'match:eq', |
| 2217 | "value": '2014-12-05', |
| 2218 | "type": 'type:date' |
| 2219 | } |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 2220 | ); |
| 2221 | |
| 2222 | expect(vc.toQuery()).toEqual('pubDate in 2014-12-05'); |
| 2223 | expect(vc.root().ldType()).toEqual('doc'); |
| 2224 | expect(vc.root().key()).toEqual('pubDate'); |
| 2225 | expect(vc.root().value()).toEqual('2014-12-05'); |
| 2226 | |
| 2227 | // Wrap on root |
| 2228 | _andOn(vc.root()); |
| 2229 | expect(vc.root().ldType()).toEqual('docGroup'); |
| 2230 | expect(vc.root().operation()).toEqual('and'); |
| 2231 | }); |
| 2232 | |
| 2233 | it('should add on root (case "or")', function () { |
Nils Diewald | 6283d69 | 2015-04-23 20:32:53 +0000 | [diff] [blame] | 2234 | var vc = vcClass.create().fromJson( |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 2235 | { |
| 2236 | "@type": 'koral:doc', |
| 2237 | "key": 'pubDate', |
| 2238 | "match": 'match:eq', |
| 2239 | "value": '2014-12-05', |
| 2240 | "type": 'type:date' |
| 2241 | } |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 2242 | ); |
| 2243 | |
| 2244 | expect(vc.toQuery()).toEqual('pubDate in 2014-12-05'); |
| 2245 | expect(vc.root().key()).toEqual('pubDate'); |
| 2246 | expect(vc.root().value()).toEqual('2014-12-05'); |
| 2247 | |
| 2248 | // Wrap on root |
| 2249 | _orOn(vc.root()); |
| 2250 | expect(vc.root().ldType()).toEqual('docGroup'); |
| 2251 | expect(vc.root().operation()).toEqual('or'); |
| 2252 | }); |
| 2253 | |
| 2254 | it('should support multiple sub groups per group', function () { |
Nils Diewald | 6283d69 | 2015-04-23 20:32:53 +0000 | [diff] [blame] | 2255 | var vc = vcClass.create().fromJson( |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 2256 | { |
| 2257 | "@type": 'koral:docGroup', |
| 2258 | 'operation' : 'operation:or', |
| 2259 | 'operands' : [ |
| 2260 | { |
| 2261 | "@type": 'koral:docGroup', |
| 2262 | 'operation' : 'operation:and', |
| 2263 | 'operands' : [ |
| 2264 | { |
| 2265 | "@type": 'koral:doc', |
| 2266 | "key": 'title', |
| 2267 | "value": 't1', |
| 2268 | }, |
| 2269 | { |
| 2270 | "@type" : 'koral:doc', |
| 2271 | 'key' : 'title', |
| 2272 | 'value' : 't2' |
| 2273 | } |
| 2274 | ] |
| 2275 | }, |
| 2276 | { |
| 2277 | "@type": 'koral:docGroup', |
| 2278 | 'operation' : 'operation:and', |
| 2279 | 'operands' : [ |
| 2280 | { |
| 2281 | "@type": 'koral:doc', |
| 2282 | "key": 'title', |
| 2283 | "value": 't3', |
| 2284 | }, |
| 2285 | { |
| 2286 | "@type" : 'koral:doc', |
| 2287 | 'key' : 'title', |
| 2288 | 'value' : 't4' |
| 2289 | } |
| 2290 | ] |
| 2291 | } |
| 2292 | ] |
| 2293 | } |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 2294 | ); |
| 2295 | expect(vc.toQuery()).toEqual( |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 2296 | '(title = "t1" & title = "t2") | ' + |
| 2297 | '(title = "t3" & title = "t4")' |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 2298 | ); |
| 2299 | expect(vc.root().operation()).toEqual('or'); |
| 2300 | expect(vc.root().getOperand(0).toQuery()).toEqual('title = "t1" & title = "t2"'); |
| 2301 | expect(vc.root().getOperand(1).toQuery()).toEqual('title = "t3" & title = "t4"'); |
| 2302 | |
| 2303 | _andOn(vc.root()); |
| 2304 | |
| 2305 | expect(vc.root().operation()).toEqual('and'); |
| 2306 | expect(vc.root().getOperand(0).ldType()).toEqual('docGroup'); |
| 2307 | expect(vc.root().getOperand(1).ldType()).toEqual('non'); |
| 2308 | }); |
| 2309 | }); |
| 2310 | |
Akron | 5c829e9 | 2017-05-12 18:10:00 +0200 | [diff] [blame] | 2311 | // Check class method |
| 2312 | describe('KorAP.VC.checkRewrite', function () { |
| 2313 | |
| 2314 | it('should check for simple rewrites', function () { |
| 2315 | expect(vcClass.checkRewrite( |
| 2316 | { |
| 2317 | "@type" : "koral:doc", |
| 2318 | "rewrites" : [{ |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 2319 | "@type" : "koral:rewrite", |
| 2320 | "operation" : "operation:modification", |
| 2321 | "src" : "querySerializer", |
| 2322 | "scope" : "tree" |
Akron | 5c829e9 | 2017-05-12 18:10:00 +0200 | [diff] [blame] | 2323 | }] |
| 2324 | } |
| 2325 | )).toBeTruthy(); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 2326 | |
Akron | 5c829e9 | 2017-05-12 18:10:00 +0200 | [diff] [blame] | 2327 | var nested = { |
| 2328 | "@type" : "koral:docGroup", |
| 2329 | "operands" : [ |
| 2330 | { |
| 2331 | "@type" : "koral:doc" |
| 2332 | }, |
| 2333 | { |
| 2334 | "@type" : "koral:docGroup", |
| 2335 | "operands" : [ |
| 2336 | { |
| 2337 | "@type": "koral:doc" |
| 2338 | }, |
| 2339 | { |
| 2340 | "@type": "koral:doc" |
| 2341 | } |
| 2342 | ] |
| 2343 | } |
| 2344 | ] |
| 2345 | }; |
| 2346 | |
| 2347 | expect(vcClass.checkRewrite(nested)).toBe(false); |
| 2348 | |
| 2349 | nested["operands"][1]["operands"][1]["rewrites"] = [{ |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 2350 | "@type" : "koral:rewrite", |
| 2351 | "operation" : "operation:modification", |
| 2352 | "src" : "querySerializer", |
| 2353 | "scope" : "tree" |
Akron | 5c829e9 | 2017-05-12 18:10:00 +0200 | [diff] [blame] | 2354 | }]; |
| 2355 | |
| 2356 | expect(vcClass.checkRewrite(nested)).toBeTruthy(); |
| 2357 | }); |
| 2358 | }); |
Nils Diewald | 6283d69 | 2015-04-23 20:32:53 +0000 | [diff] [blame] | 2359 | |
| 2360 | describe('KorAP.Rewrite', function () { |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 2361 | it('should be initializable', function () { |
| 2362 | var rewrite = rewriteClass.create({ |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 2363 | "@type" : "koral:rewrite", |
| 2364 | "operation" : "operation:modification", |
| 2365 | "src" : "querySerializer", |
| 2366 | "scope" : "tree" |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 2367 | }); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 2368 | expect(rewrite.toString()).toEqual('Modification of "tree" by "querySerializer"'); |
| 2369 | }); |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 2370 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 2371 | it('should be deserialized by docs', function () { |
| 2372 | var doc = docClass.create( |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 2373 | undefined, |
| 2374 | { |
| 2375 | "@type":"koral:doc", |
| 2376 | "key":"Titel", |
| 2377 | "value":"Baum", |
| 2378 | "match":"match:eq" |
| 2379 | }); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 2380 | |
| 2381 | expect(doc.element().classList.contains('doc')).toBeTruthy(); |
| 2382 | expect(doc.element().classList.contains('rewritten')).toBe(false); |
| 2383 | |
| 2384 | doc = docClass.create( |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 2385 | undefined, |
| 2386 | { |
| 2387 | "@type":"koral:doc", |
| 2388 | "key":"Titel", |
| 2389 | "value":"Baum", |
| 2390 | "match":"match:eq", |
| 2391 | "rewrites" : [ |
| 2392 | { |
| 2393 | "@type" : "koral:rewrite", |
| 2394 | "operation" : "operation:modification", |
| 2395 | "src" : "querySerializer", |
| 2396 | "scope" : "tree" |
| 2397 | } |
| 2398 | ] |
| 2399 | }); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 2400 | |
| 2401 | expect(doc.element().classList.contains('doc')).toBeTruthy(); |
| 2402 | expect(doc.element().classList.contains('rewritten')).toBeTruthy(); |
| 2403 | }); |
Nils Diewald | 6283d69 | 2015-04-23 20:32:53 +0000 | [diff] [blame] | 2404 | |
Akron | 76c3dd6 | 2018-05-29 20:58:27 +0200 | [diff] [blame] | 2405 | it('should be described in a title attribute', function () { |
| 2406 | |
| 2407 | doc = docClass.create( |
| 2408 | undefined, |
| 2409 | { |
| 2410 | "@type":"koral:doc", |
| 2411 | "key":"Titel", |
| 2412 | "value":"Baum", |
| 2413 | "match":"match:eq", |
| 2414 | "rewrites" : [ |
| 2415 | { |
| 2416 | "@type" : "koral:rewrite", |
| 2417 | "operation" : "operation:modification", |
| 2418 | "src" : "querySerializer", |
| 2419 | "scope" : "tree" |
| 2420 | }, |
| 2421 | { |
| 2422 | "@type" : "koral:rewrite", |
| 2423 | "operation" : "operation:injection", |
| 2424 | "src" : "me" |
| 2425 | } |
| 2426 | ] |
| 2427 | }); |
| 2428 | |
| 2429 | expect(doc.element().classList.contains('doc')).toBeTruthy(); |
| 2430 | expect(doc.element().classList.contains('rewritten')).toBeTruthy(); |
| 2431 | expect(doc.element().lastChild.getAttribute("title")).toEqual("querySerializer: tree (modification)\nme (injection)"); |
| 2432 | }); |
| 2433 | |
| 2434 | |
Nils Diewald | 6283d69 | 2015-04-23 20:32:53 +0000 | [diff] [blame] | 2435 | xit('should be deserialized by docGroups', function () { |
| 2436 | var docGroup = docGroupClass.create( |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 2437 | undefined, |
| 2438 | { |
| 2439 | "@type" : "koral:docGroup", |
| 2440 | "operation" : "operation:or", |
| 2441 | "operands" : [ |
| 2442 | { |
| 2443 | "@type" : "doc", |
| 2444 | "key" : "pubDate", |
| 2445 | "type" : "type:date", |
| 2446 | "value" : "2014-12-05" |
| 2447 | }, |
| 2448 | { |
| 2449 | "@type" : "doc", |
| 2450 | "key" : "pubDate", |
| 2451 | "type" : "type:date", |
| 2452 | "value" : "2014-12-06" |
| 2453 | } |
| 2454 | ], |
| 2455 | "rewrites" : [ |
| 2456 | { |
| 2457 | "@type" : "koral:rewrite", |
| 2458 | "operation" : "operation:modification", |
| 2459 | "src" : "querySerializer", |
| 2460 | "scope" : "tree" |
| 2461 | } |
| 2462 | ] |
| 2463 | } |
Nils Diewald | 6283d69 | 2015-04-23 20:32:53 +0000 | [diff] [blame] | 2464 | ); |
| 2465 | |
| 2466 | expect(doc.element().classList.contains('docgroup')).toBeTruthy(); |
| 2467 | expect(doc.element().classList.contains('rewritten')).toBe(false); |
| 2468 | }); |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 2469 | }); |
Nils Diewald | f0c4f11 | 2015-05-05 12:56:59 +0000 | [diff] [blame] | 2470 | |
| 2471 | describe('KorAP.stringValue', function () { |
| 2472 | it('should be initializable', function () { |
| 2473 | var sv = stringValClass.create(); |
| 2474 | expect(sv.regex()).toBe(false); |
| 2475 | expect(sv.value()).toBe(''); |
Nils Diewald | c4c4b83 | 2015-05-05 16:00:08 +0000 | [diff] [blame] | 2476 | |
| 2477 | sv = stringValClass.create('Baum'); |
| 2478 | expect(sv.regex()).toBe(false); |
| 2479 | expect(sv.value()).toBe('Baum'); |
| 2480 | |
| 2481 | sv = stringValClass.create('Baum', false); |
| 2482 | expect(sv.regex()).toBe(false); |
| 2483 | expect(sv.value()).toBe('Baum'); |
| 2484 | |
| 2485 | sv = stringValClass.create('Baum', true); |
| 2486 | expect(sv.regex()).toBe(true); |
| 2487 | expect(sv.value()).toBe('Baum'); |
| 2488 | }); |
| 2489 | |
| 2490 | it('should be modifiable', function () { |
| 2491 | var sv = stringValClass.create(); |
| 2492 | expect(sv.regex()).toBe(false); |
| 2493 | expect(sv.value()).toBe(''); |
| 2494 | |
| 2495 | expect(sv.value('Baum')).toBe('Baum'); |
| 2496 | expect(sv.value()).toBe('Baum'); |
| 2497 | |
| 2498 | expect(sv.regex(true)).toBe(true); |
| 2499 | expect(sv.regex()).toBe(true); |
| 2500 | }); |
| 2501 | |
| 2502 | it('should have a toggleble regex value', function () { |
| 2503 | var sv = stringValClass.create(); |
Nils Diewald | 7991a3f | 2015-05-19 14:12:37 +0000 | [diff] [blame] | 2504 | |
| 2505 | expect(sv.element().firstChild.value).toBe(''); |
| 2506 | sv.element().firstChild.value = 'der' |
| 2507 | expect(sv.element().firstChild.value).toBe('der'); |
| 2508 | |
Nils Diewald | c4c4b83 | 2015-05-05 16:00:08 +0000 | [diff] [blame] | 2509 | expect(sv.regex()).toBe(false); |
| 2510 | |
| 2511 | sv.toggleRegex(); |
Nils Diewald | 7991a3f | 2015-05-19 14:12:37 +0000 | [diff] [blame] | 2512 | expect(sv.element().firstChild.value).toBe('der'); |
Nils Diewald | c4c4b83 | 2015-05-05 16:00:08 +0000 | [diff] [blame] | 2513 | expect(sv.regex()).toBe(true); |
Nils Diewald | 7991a3f | 2015-05-19 14:12:37 +0000 | [diff] [blame] | 2514 | sv.element().firstChild.value = 'derbe' |
Nils Diewald | c4c4b83 | 2015-05-05 16:00:08 +0000 | [diff] [blame] | 2515 | |
| 2516 | sv.toggleRegex(); |
| 2517 | expect(sv.regex()).toBe(false); |
Nils Diewald | 7991a3f | 2015-05-19 14:12:37 +0000 | [diff] [blame] | 2518 | expect(sv.element().firstChild.value).toBe('derbe'); |
Nils Diewald | c4c4b83 | 2015-05-05 16:00:08 +0000 | [diff] [blame] | 2519 | }); |
| 2520 | |
| 2521 | it('should have an element', function () { |
| 2522 | var sv = stringValClass.create('der'); |
| 2523 | expect(sv.element().nodeName).toBe('DIV'); |
| 2524 | expect(sv.element().firstChild.nodeName).toBe('INPUT'); |
| 2525 | expect(sv.element().firstChild.value).toBe('der'); |
| 2526 | }); |
| 2527 | |
| 2528 | it('should have a classed element', function () { |
| 2529 | var sv = stringValClass.create(); |
Nils Diewald | c4c4b83 | 2015-05-05 16:00:08 +0000 | [diff] [blame] | 2530 | expect(sv.element().classList.contains('regex')).toBe(false); |
| 2531 | expect(sv.regex()).toBe(false); |
| 2532 | sv.toggleRegex(); |
| 2533 | expect(sv.element().classList.contains('regex')).toBe(true); |
| 2534 | }); |
| 2535 | |
| 2536 | it('should be storable', function () { |
| 2537 | var sv = stringValClass.create(); |
| 2538 | var count = 1; |
| 2539 | sv.store = function (value, regex) { |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 2540 | expect(regex).toBe(true); |
| 2541 | expect(value).toBe('tree'); |
Nils Diewald | c4c4b83 | 2015-05-05 16:00:08 +0000 | [diff] [blame] | 2542 | }; |
| 2543 | sv.regex(true); |
| 2544 | sv.value('tree'); |
| 2545 | sv.element().lastChild.click(); |
Nils Diewald | f0c4f11 | 2015-05-05 12:56:59 +0000 | [diff] [blame] | 2546 | }); |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 2547 | |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 2548 | it('should have a disableoption for regex', function () { |
| 2549 | var sv = stringValClass.create(undefined, undefined, true); |
| 2550 | var svE = sv.element(); |
| 2551 | expect(svE.children.length).toEqual(2); |
| 2552 | |
| 2553 | sv = stringValClass.create(undefined, undefined, false); |
| 2554 | svE = sv.element(); |
| 2555 | expect(svE.children.length).toEqual(1); |
| 2556 | }); |
| 2557 | |
Nils Diewald | f0c4f11 | 2015-05-05 12:56:59 +0000 | [diff] [blame] | 2558 | }); |
Akron | e4961b1 | 2017-05-10 21:04:46 +0200 | [diff] [blame] | 2559 | |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 2560 | describe('KorAP.VC.Menu', function () { |
Akron | e65a88a | 2018-04-05 19:14:20 +0200 | [diff] [blame] | 2561 | |
| 2562 | var vc; |
| 2563 | |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 2564 | it('should be initializable', function () { |
| 2565 | |
Akron | e65a88a | 2018-04-05 19:14:20 +0200 | [diff] [blame] | 2566 | vc = vcClass.create([ |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 2567 | ['a', 'text'], |
| 2568 | ['b', 'string'], |
| 2569 | ['c', 'date'] |
| 2570 | ]).fromJson(); |
| 2571 | expect(vc.element().firstChild.classList.contains('unspecified')).toBeTruthy(); |
| 2572 | expect(vc.element().firstChild.firstChild.tagName).toEqual('SPAN'); |
| 2573 | |
| 2574 | // Click on unspecified |
| 2575 | vc.element().firstChild.firstChild.click(); |
| 2576 | expect(vc.element().firstChild.firstChild.tagName).toEqual('UL'); |
| 2577 | |
| 2578 | var list = vc.element().firstChild.firstChild; |
| 2579 | expect(list.getElementsByTagName("LI")[0].innerText).toEqual('a'); |
| 2580 | expect(list.getElementsByTagName("LI")[1].innerText).toEqual('b'); |
| 2581 | expect(list.getElementsByTagName("LI")[2].innerText).toEqual('c'); |
| 2582 | |
| 2583 | vc = vcClass.create([ |
| 2584 | ['d', 'text'], |
| 2585 | ['e', 'string'], |
| 2586 | ['f', 'date'] |
| 2587 | ]).fromJson(); |
| 2588 | expect(vc.element().firstChild.classList.contains('unspecified')).toBeTruthy(); |
| 2589 | expect(vc.element().firstChild.firstChild.tagName).toEqual('SPAN'); |
| 2590 | |
| 2591 | // Click on unspecified |
| 2592 | vc.element().firstChild.firstChild.click(); |
| 2593 | expect(vc.element().firstChild.firstChild.tagName).toEqual('UL'); |
| 2594 | |
| 2595 | list = vc.element().firstChild.firstChild; |
| 2596 | expect(list.getElementsByTagName("LI")[0].innerText).toEqual('d'); |
| 2597 | expect(list.getElementsByTagName("LI")[1].innerText).toEqual('e'); |
| 2598 | expect(list.getElementsByTagName("LI")[2].innerText).toEqual('f'); |
Akron | 31d8994 | 2018-04-06 16:44:51 +0200 | [diff] [blame] | 2599 | // blur |
| 2600 | document.body.click(); |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 2601 | }); |
Akron | e65a88a | 2018-04-05 19:14:20 +0200 | [diff] [blame] | 2602 | |
| 2603 | // Reinitialize to make tests stable |
| 2604 | vc = vcClass.create([ |
| 2605 | ['d', 'text'], |
| 2606 | ['e', 'string'], |
| 2607 | ['f', 'date'] |
| 2608 | ]).fromJson(); |
| 2609 | |
| 2610 | it('should be clickable on key', function () { |
Akron | 31d8994 | 2018-04-06 16:44:51 +0200 | [diff] [blame] | 2611 | // Click on unspecified |
| 2612 | vc.element().firstChild.firstChild.click(); |
Akron | e65a88a | 2018-04-05 19:14:20 +0200 | [diff] [blame] | 2613 | // Click on "d" |
| 2614 | vc.element().firstChild.firstChild.getElementsByTagName("LI")[0].click(); |
| 2615 | expect(vc.element().firstChild.firstChild.tagName).toEqual('SPAN'); |
| 2616 | expect(vc.element().firstChild.firstChild.innerText).toEqual('d'); |
| 2617 | expect(vc.element().firstChild.children[1].innerText).toEqual('eq'); |
| 2618 | expect(vc.element().firstChild.children[1].getAttribute('data-type')).toEqual('text'); |
Akron | 31d8994 | 2018-04-06 16:44:51 +0200 | [diff] [blame] | 2619 | // blur |
| 2620 | document.body.click(); |
Akron | e65a88a | 2018-04-05 19:14:20 +0200 | [diff] [blame] | 2621 | }); |
| 2622 | |
Akron | 31d8994 | 2018-04-06 16:44:51 +0200 | [diff] [blame] | 2623 | it('should be clickable on operation for text', function () { |
| 2624 | // Click on "d" (or unspecified) |
| 2625 | vc.element().firstChild.firstChild.click(); |
| 2626 | |
| 2627 | // Choose "d" |
| 2628 | vc.element().firstChild.firstChild.getElementsByTagName("LI")[0].click(); |
| 2629 | |
| 2630 | // Click on matchop |
Akron | e65a88a | 2018-04-05 19:14:20 +0200 | [diff] [blame] | 2631 | vc.element().firstChild.children[1].click(); |
Akron | 31d8994 | 2018-04-06 16:44:51 +0200 | [diff] [blame] | 2632 | |
Akron | e65a88a | 2018-04-05 19:14:20 +0200 | [diff] [blame] | 2633 | expect(vc.element().firstChild.children[1].tagName).toEqual('UL'); |
Akron | 31d8994 | 2018-04-06 16:44:51 +0200 | [diff] [blame] | 2634 | |
Akron | e65a88a | 2018-04-05 19:14:20 +0200 | [diff] [blame] | 2635 | var ul = vc.element().firstChild.children[1]; |
| 2636 | expect(ul.getElementsByTagName('li')[0].innerText).toEqual("eq"); |
| 2637 | expect(ul.getElementsByTagName('li')[1].innerText).toEqual("ne"); |
| 2638 | expect(ul.getElementsByTagName('li')[2].innerText).toEqual("contains"); |
| 2639 | expect(ul.getElementsByTagName('li')[3].innerText).toEqual("containsnot"); |
| 2640 | expect(ul.getElementsByTagName('li')[4]).toBeUndefined(); |
Akron | 31d8994 | 2018-04-06 16:44:51 +0200 | [diff] [blame] | 2641 | |
| 2642 | // Choose "contains" |
| 2643 | ul.getElementsByTagName('li')[2].click(); |
| 2644 | expect(vc.element().firstChild.children[1].tagName).toEqual("SPAN"); |
| 2645 | expect(vc.element().firstChild.children[1].innerText).toEqual("contains"); |
| 2646 | // blur |
| 2647 | document.body.click(); |
Akron | e65a88a | 2018-04-05 19:14:20 +0200 | [diff] [blame] | 2648 | }) |
Akron | 31d8994 | 2018-04-06 16:44:51 +0200 | [diff] [blame] | 2649 | |
| 2650 | it('should be clickable on operation for string', function () { |
| 2651 | // Click on "d" (or unspecified) |
| 2652 | vc.element().firstChild.firstChild.click(); |
| 2653 | |
| 2654 | // Choose "e" |
| 2655 | vc.element().firstChild.firstChild.getElementsByTagName("LI")[1].click(); |
| 2656 | |
| 2657 | // As a consequence the matchoperator may no longer |
| 2658 | // be valid and needs to be re-evaluated |
| 2659 | var fc = vc.element().firstChild; |
| 2660 | expect(fc.firstChild.tagName).toEqual('SPAN'); |
| 2661 | expect(fc.firstChild.innerText).toEqual('e'); |
| 2662 | expect(fc.children[1].innerText).toEqual('eq'); |
| 2663 | expect(fc.children[1].getAttribute('data-type')).toEqual('string'); |
| 2664 | |
| 2665 | vc.element().firstChild.children[1].click(); |
| 2666 | |
| 2667 | expect(vc.element().firstChild.children[1].tagName).toEqual('UL'); |
| 2668 | |
| 2669 | var ul = vc.element().firstChild.children[1]; |
| 2670 | expect(ul.getElementsByTagName('li')[0].innerText).toEqual("eq"); |
| 2671 | expect(ul.getElementsByTagName('li')[1].innerText).toEqual("ne"); |
| 2672 | expect(ul.getElementsByTagName('li')[2]).toBeUndefined(); |
| 2673 | |
| 2674 | // Choose "ne" |
| 2675 | ul.getElementsByTagName('li')[1].click(); |
| 2676 | expect(vc.element().firstChild.children[1].tagName).toEqual("SPAN"); |
| 2677 | expect(vc.element().firstChild.children[1].innerText).toEqual("ne"); |
Akron | 8db5e3a | 2018-05-28 19:25:26 +0200 | [diff] [blame] | 2678 | |
| 2679 | // Click on text |
| 2680 | expect(vc.element().firstChild.children[2].innerText).toEqual("⋯"); |
| 2681 | vc.element().firstChild.children[2].click(); |
| 2682 | |
| 2683 | // Blur text element |
| 2684 | expect(vc.element().firstChild.children[2].firstChild.value).toEqual(''); |
| 2685 | |
Akron | 31d8994 | 2018-04-06 16:44:51 +0200 | [diff] [blame] | 2686 | // blur |
| 2687 | document.body.click(); |
| 2688 | }); |
| 2689 | |
| 2690 | it('should be clickable on operation for date', function () { |
| 2691 | |
| 2692 | // Replay matchop check - so it's guaranteed that "ne" is chosen |
| 2693 | // Click on "e" (or unspecified) |
| 2694 | vc.element().firstChild.firstChild.click(); |
| 2695 | // Rechoose "e" |
| 2696 | vc.element().firstChild.firstChild.getElementsByTagName("LI")[1].click(); |
| 2697 | // Click on matchop |
| 2698 | vc.element().firstChild.children[1].click(); |
| 2699 | // Choose "ne" |
| 2700 | vc.element().firstChild.children[1].getElementsByTagName('li')[1].click(); |
| 2701 | expect(vc.element().firstChild.children[1].innerText).toEqual("ne"); |
| 2702 | |
| 2703 | // Click on "e" |
| 2704 | vc.element().firstChild.firstChild.click(); |
| 2705 | // Choose "f" |
| 2706 | vc.element().firstChild.firstChild.getElementsByTagName("LI")[2].click(); |
| 2707 | |
| 2708 | // The matchoperator should still be "ne" as this is valid for dates as well (now) |
| 2709 | var fc = vc.element().firstChild; |
| 2710 | expect(fc.firstChild.tagName).toEqual('SPAN'); |
| 2711 | expect(fc.firstChild.innerText).toEqual('f'); |
| 2712 | expect(fc.children[1].innerText).toEqual('ne'); |
| 2713 | // blur |
| 2714 | document.body.click(); |
| 2715 | }); |
Akron | ddc98a7 | 2018-04-06 17:33:52 +0200 | [diff] [blame] | 2716 | |
| 2717 | |
| 2718 | // Check json deserialization |
| 2719 | it('should be initializable', function () { |
| 2720 | vc = vcClass.create([ |
| 2721 | ['a', 'text'], |
| 2722 | ['b', 'string'], |
| 2723 | ['c', 'date'] |
| 2724 | ]).fromJson({ |
| 2725 | "@type" : "koral:doc", |
| 2726 | "key":"a", |
| 2727 | "value":"Baum" |
| 2728 | }); |
| 2729 | |
| 2730 | expect(vc.element().firstChild.children[1].getAttribute('data-type')).toEqual('text'); |
| 2731 | }); |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 2732 | }); |
| 2733 | |
| 2734 | |
Akron | e4961b1 | 2017-05-10 21:04:46 +0200 | [diff] [blame] | 2735 | // Check prefix |
| 2736 | describe('KorAP.VC.Prefix', function () { |
| 2737 | |
| 2738 | it('should be initializable', function () { |
| 2739 | var p = prefixClass.create(); |
| 2740 | expect(p.element().classList.contains('pref')).toBeTruthy(); |
| 2741 | expect(p.isSet()).not.toBeTruthy(); |
| 2742 | }); |
| 2743 | |
| 2744 | |
| 2745 | it('should be clickable', function () { |
| 2746 | var vc = vcClass.create([ |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 2747 | ['a', null], |
| 2748 | ['b', null], |
| 2749 | ['c', null] |
| 2750 | ]).fromJson(); |
Akron | e4961b1 | 2017-05-10 21:04:46 +0200 | [diff] [blame] | 2751 | expect(vc.element().firstChild.classList.contains('unspecified')).toBeTruthy(); |
| 2752 | |
| 2753 | // This should open up the menu |
| 2754 | vc.element().firstChild.firstChild.click(); |
| 2755 | expect(vc.element().firstChild.firstChild.tagName).toEqual('UL'); |
| 2756 | |
| 2757 | KorAP._vcKeyMenu._prefix.clear(); |
| 2758 | KorAP._vcKeyMenu._prefix.add('x'); |
| 2759 | |
| 2760 | var prefElement = vc.element().querySelector('span.pref'); |
| 2761 | expect(prefElement.innerText).toEqual('x'); |
| 2762 | |
| 2763 | // This should add key 'x' to VC |
| 2764 | prefElement.click(); |
| 2765 | |
| 2766 | expect(vc.element().firstChild.classList.contains('doc')).toBeTruthy(); |
| 2767 | expect(vc.element().firstChild.firstChild.className).toEqual('key'); |
| 2768 | expect(vc.element().firstChild.firstChild.innerText).toEqual('x'); |
| 2769 | }); |
| 2770 | }); |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame] | 2771 | }); |