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 |
Akron | 3ad4694 | 2018-08-22 16:47:14 +0200 | [diff] [blame^] | 757 | vc.element().firstChild.getElementsByTagName("LI")[1].click(); |
Akron | 55a343b | 2018-04-06 19:57:36 +0200 | [diff] [blame] | 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 |
Akron | 3ad4694 | 2018-08-22 16:47:14 +0200 | [diff] [blame^] | 815 | vcE.firstChild.getElementsByTagName("LI")[1].click(); |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 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 () { |
Akron | 3ad4694 | 2018-08-22 16:47:14 +0200 | [diff] [blame^] | 825 | var vc = vcClass.create().fromJson({ |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 826 | "@type" : "koral:doc", |
| 827 | "key":"Titel", |
| 828 | "value":"Baum", |
| 829 | "match":"match:eq" |
| 830 | }); |
| 831 | |
| 832 | expect(vc.toQuery()).toEqual("Titel = \"Baum\""); |
| 833 | |
| 834 | var vcE = vc.element(); |
| 835 | expect(vcE.firstChild.children.length).toEqual(4); |
| 836 | |
| 837 | // Click to delete |
| 838 | vcE.firstChild.lastChild.lastChild.click(); |
| 839 | |
| 840 | expect(vcE.firstChild.children.length).toEqual(1); |
| 841 | |
| 842 | expect(vcE.firstChild.textContent).toEqual("⋯"); |
| 843 | vcE.firstChild.firstChild.click(); |
| 844 | |
Akron | 3ad4694 | 2018-08-22 16:47:14 +0200 | [diff] [blame^] | 845 | // Click on referTo |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 846 | vcE.firstChild.getElementsByTagName("LI")[0].click(); |
| 847 | |
Akron | 3ad4694 | 2018-08-22 16:47:14 +0200 | [diff] [blame^] | 848 | expect(vcE.firstChild.firstChild.textContent).toEqual("referTo"); |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 849 | expect(vcE.firstChild.children[1].getAttribute("data-type")).toEqual("string"); |
| 850 | expect(vcE.firstChild.children.length).toEqual(3); |
| 851 | }); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 852 | }); |
| 853 | |
| 854 | describe('KorAP.DocGroup element', function () { |
| 855 | it('should be initializable', function () { |
| 856 | |
| 857 | var docGroup = docGroupClass.create(undefined, { |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 858 | "@type" : "koral:docGroup", |
| 859 | "operation" : "operation:and", |
| 860 | "operands" : [ |
| 861 | { |
| 862 | "@type": 'koral:doc', |
| 863 | "key" : 'author', |
| 864 | "match": 'match:eq', |
| 865 | "value": 'Max Birkendale', |
| 866 | "type": 'type:string' |
| 867 | }, |
| 868 | { |
| 869 | "@type": 'koral:doc', |
| 870 | "key": 'pubDate', |
| 871 | "match": 'match:eq', |
| 872 | "value": '2014-12-05', |
| 873 | "type": 'type:date' |
| 874 | } |
| 875 | ] |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 876 | }); |
| 877 | |
| 878 | expect(docGroup.operation()).toEqual('and'); |
| 879 | var e = docGroup.element(); |
| 880 | expect(e.getAttribute('class')).toEqual('docGroup'); |
| 881 | expect(e.getAttribute('data-operation')).toEqual('and'); |
| 882 | |
| 883 | var first = e.children[0]; |
| 884 | expect(first.getAttribute('class')).toEqual('doc'); |
| 885 | expect(first.children[0].getAttribute('class')).toEqual('key'); |
| 886 | expect(first.children[1].getAttribute('class')).toEqual('match'); |
| 887 | expect(first.children[2].getAttribute('class')).toEqual('value'); |
| 888 | expect(first.children[2].getAttribute('data-type')).toEqual('string'); |
| 889 | expect(first.children[0].firstChild.data).toEqual('author'); |
| 890 | expect(first.children[1].firstChild.data).toEqual('eq'); |
| 891 | expect(first.children[2].firstChild.data).toEqual('Max Birkendale'); |
| 892 | |
| 893 | var second = e.children[1]; |
| 894 | expect(second.getAttribute('class')).toEqual('doc'); |
| 895 | expect(second.children[0].getAttribute('class')).toEqual('key'); |
| 896 | expect(second.children[1].getAttribute('class')).toEqual('match'); |
| 897 | expect(second.children[2].getAttribute('class')).toEqual('value'); |
| 898 | expect(second.children[2].getAttribute('data-type')).toEqual('date'); |
| 899 | expect(second.children[0].firstChild.data).toEqual('pubDate'); |
| 900 | expect(second.children[1].firstChild.data).toEqual('eq'); |
| 901 | expect(second.children[2].firstChild.data).toEqual('2014-12-05'); |
| 902 | }); |
| 903 | |
| 904 | it('should be deserializable with nested groups', function () { |
| 905 | var docGroup = docGroupClass.create(undefined, { |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 906 | "@type" : "koral:docGroup", |
| 907 | "operation" : "operation:or", |
| 908 | "operands" : [ |
| 909 | { |
| 910 | "@type": 'koral:doc', |
| 911 | "key" : 'author', |
| 912 | "match": 'match:eq', |
| 913 | "value": 'Max Birkendale', |
| 914 | "type": 'type:string' |
| 915 | }, |
| 916 | { |
| 917 | "@type" : "koral:docGroup", |
| 918 | "operation" : "operation:and", |
| 919 | "operands" : [ |
| 920 | { |
| 921 | "@type": 'koral:doc', |
| 922 | "key": 'pubDate', |
| 923 | "match": 'match:geq', |
| 924 | "value": '2014-05-12', |
| 925 | "type": 'type:date' |
| 926 | }, |
| 927 | { |
| 928 | "@type": 'koral:doc', |
| 929 | "key": 'pubDate', |
| 930 | "match": 'match:leq', |
| 931 | "value": '2014-12-05', |
| 932 | "type": 'type:date' |
| 933 | } |
| 934 | ] |
| 935 | } |
| 936 | ] |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 937 | }); |
| 938 | |
| 939 | expect(docGroup.operation()).toEqual('or'); |
| 940 | var e = docGroup.element(); |
| 941 | expect(e.getAttribute('class')).toEqual('docGroup'); |
| 942 | expect(e.getAttribute('data-operation')).toEqual('or'); |
| 943 | |
| 944 | expect(e.children[0].getAttribute('class')).toEqual('doc'); |
| 945 | var docop = e.children[0].lastChild; |
Akron | 0b489ad | 2018-02-02 16:49:32 +0100 | [diff] [blame] | 946 | expect(docop.getAttribute('class')).toEqual('operators button-group'); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 947 | expect(docop.children[0].getAttribute('class')).toEqual('and'); |
| 948 | expect(docop.children[1].getAttribute('class')).toEqual('or'); |
| 949 | expect(docop.children[2].getAttribute('class')).toEqual('delete'); |
| 950 | |
| 951 | expect(e.children[1].getAttribute('class')).toEqual('docGroup'); |
| 952 | expect(e.children[1].getAttribute('data-operation')).toEqual('and'); |
| 953 | |
| 954 | // This and-operation can be "or"ed or "delete"d |
| 955 | var secop = e.children[1].children[2]; |
Akron | 0b489ad | 2018-02-02 16:49:32 +0100 | [diff] [blame] | 956 | expect(secop.getAttribute('class')).toEqual('operators button-group'); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 957 | expect(secop.children[0].getAttribute('class')).toEqual('or'); |
| 958 | expect(secop.children[1].getAttribute('class')).toEqual('delete'); |
| 959 | |
| 960 | // This or-operation can be "and"ed or "delete"d |
Akron | 0b489ad | 2018-02-02 16:49:32 +0100 | [diff] [blame] | 961 | expect(e.children[2].getAttribute('class')).toEqual('operators button-group'); |
| 962 | expect(e.lastChild.getAttribute('class')).toEqual('operators button-group'); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 963 | expect(e.lastChild.children[0].getAttribute('class')).toEqual('and'); |
| 964 | expect(e.lastChild.children[1].getAttribute('class')).toEqual('delete'); |
| 965 | }); |
| 966 | }); |
| 967 | |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 968 | describe('KorAP.DocGroupRef element', function () { |
| 969 | it('should be initializable', function () { |
| 970 | var docGroupRef = docGroupRefClass.create(undefined, { |
| 971 | "@type" : "koral:docGroupRef", |
| 972 | "ref" : "@franz/myVC1" |
| 973 | }); |
| 974 | expect(docGroupRef.ref()).toEqual("@franz/myVC1"); |
| 975 | var dgrE = docGroupRef.element(); |
| 976 | |
Akron | 3ad4694 | 2018-08-22 16:47:14 +0200 | [diff] [blame^] | 977 | expect(dgrE.children[0].firstChild.data).toEqual("referTo"); |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 978 | expect(dgrE.children[0].tagName).toEqual("SPAN"); |
| 979 | expect(dgrE.children[0].classList.contains("key")).toBeTruthy(); |
| 980 | expect(dgrE.children[0].classList.contains("fixed")).toBeTruthy(); |
| 981 | expect(dgrE.children[1].firstChild.data).toEqual("@franz/myVC1"); |
| 982 | expect(dgrE.children[1].tagName).toEqual("SPAN"); |
| 983 | expect(dgrE.children[1].classList.contains("value")).toBeTruthy(); |
| 984 | expect(dgrE.children[1].getAttribute("data-type")).toEqual("string"); |
| 985 | }); |
| 986 | |
| 987 | it('should be modifiable on reference', function () { |
| 988 | var docGroupRef = docGroupRefClass.create(undefined, { |
| 989 | "@type" : "koral:docGroupRef", |
| 990 | "ref" : "@franz/myVC1" |
| 991 | }); |
| 992 | var dgrE = docGroupRef.element(); |
| 993 | expect(docGroupRef.toQuery()).toEqual("referTo \"@franz/myVC1\""); |
| 994 | dgrE.children[1].click(); |
| 995 | |
| 996 | var input = dgrE.children[1].firstChild; |
| 997 | expect(input.tagName).toEqual("INPUT"); |
| 998 | input.value = "Versuch"; |
| 999 | |
| 1000 | var event = new KeyboardEvent("keypress", { |
| 1001 | "key" : "[Enter]", |
| 1002 | "keyCode" : 13 |
| 1003 | }); |
| 1004 | |
| 1005 | input.dispatchEvent(event); |
| 1006 | expect(docGroupRef.toQuery()).toEqual("referTo \"Versuch\""); |
| 1007 | }); |
| 1008 | }); |
| 1009 | |
| 1010 | |
Akron | e4961b1 | 2017-05-10 21:04:46 +0200 | [diff] [blame] | 1011 | describe('KorAP.VirtualCorpus', function () { |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1012 | var simpleGroupFactory = buildFactory(docGroupClass, { |
| 1013 | "@type" : "koral:docGroup", |
| 1014 | "operation" : "operation:and", |
| 1015 | "operands" : [ |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 1016 | { |
| 1017 | "@type": 'koral:doc', |
| 1018 | "key" : 'author', |
| 1019 | "match": 'match:eq', |
| 1020 | "value": 'Max Birkendale', |
| 1021 | "type": 'type:string' |
| 1022 | }, |
| 1023 | { |
| 1024 | "@type": 'koral:doc', |
| 1025 | "key": 'pubDate', |
| 1026 | "match": 'match:eq', |
| 1027 | "value": '2014-12-05', |
| 1028 | "type": 'type:date' |
| 1029 | } |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1030 | ] |
| 1031 | }); |
| 1032 | |
| 1033 | var nestedGroupFactory = buildFactory(vcClass, { |
| 1034 | "@type" : "koral:docGroup", |
| 1035 | "operation" : "operation:or", |
| 1036 | "operands" : [ |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 1037 | { |
| 1038 | "@type": 'koral:doc', |
| 1039 | "key" : 'author', |
| 1040 | "match": 'match:eq', |
| 1041 | "value": 'Max Birkendale', |
| 1042 | "type": 'type:string' |
| 1043 | }, |
| 1044 | { |
| 1045 | "@type" : "koral:docGroup", |
| 1046 | "operation" : "operation:and", |
| 1047 | "operands" : [ |
| 1048 | { |
| 1049 | "@type": 'koral:doc', |
| 1050 | "key": 'pubDate', |
| 1051 | "match": 'match:geq', |
| 1052 | "value": '2014-05-12', |
| 1053 | "type": 'type:date' |
| 1054 | }, |
| 1055 | { |
| 1056 | "@type": 'koral:doc', |
| 1057 | "key": 'pubDate', |
| 1058 | "match": 'match:leq', |
| 1059 | "value": '2014-12-05', |
| 1060 | "type": 'type:date' |
| 1061 | } |
| 1062 | ] |
| 1063 | } |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1064 | ] |
| 1065 | }); |
| 1066 | |
| 1067 | var flatGroupFactory = buildFactory(vcClass, { |
| 1068 | "@type" : "koral:docGroup", |
| 1069 | "operation" : "operation:and", |
| 1070 | "operands" : [ |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 1071 | { |
| 1072 | "@type": 'koral:doc', |
| 1073 | "key": 'pubDate', |
| 1074 | "match": 'match:geq', |
| 1075 | "value": '2014-05-12', |
| 1076 | "type": 'type:date' |
| 1077 | }, |
| 1078 | { |
| 1079 | "@type": 'koral:doc', |
| 1080 | "key": 'pubDate', |
| 1081 | "match": 'match:leq', |
| 1082 | "value": '2014-12-05', |
| 1083 | "type": 'type:date' |
| 1084 | }, |
| 1085 | { |
| 1086 | "@type": 'koral:doc', |
| 1087 | "key": 'foo', |
| 1088 | "match": 'match:eq', |
| 1089 | "value": 'bar', |
| 1090 | "type": 'type:string' |
| 1091 | } |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1092 | ] |
| 1093 | }); |
| 1094 | |
| 1095 | it('should be initializable', function () { |
Nils Diewald | 6283d69 | 2015-04-23 20:32:53 +0000 | [diff] [blame] | 1096 | var vc = vcClass.create(); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1097 | expect(vc.element().getAttribute('class')).toEqual('vc'); |
| 1098 | expect(vc.root().element().getAttribute('class')).toEqual('doc unspecified'); |
| 1099 | |
| 1100 | // Not removable |
| 1101 | expect(vc.root().element().lastChild.children.length).toEqual(0); |
| 1102 | }); |
| 1103 | |
| 1104 | it('should be based on a doc', function () { |
Nils Diewald | 6283d69 | 2015-04-23 20:32:53 +0000 | [diff] [blame] | 1105 | var vc = vcClass.create().fromJson({ |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 1106 | "@type" : "koral:doc", |
| 1107 | "key":"Titel", |
| 1108 | "value":"Baum", |
| 1109 | "match":"match:eq" |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1110 | }); |
| 1111 | |
| 1112 | expect(vc.element().getAttribute('class')).toEqual('vc'); |
| 1113 | expect(vc.root().element().getAttribute('class')).toEqual('doc'); |
| 1114 | expect(vc.root().key()).toEqual('Titel'); |
| 1115 | expect(vc.root().value()).toEqual('Baum'); |
| 1116 | expect(vc.root().matchop()).toEqual('eq'); |
| 1117 | |
| 1118 | var docE = vc.root().element(); |
| 1119 | expect(docE.children[0].firstChild.data).toEqual('Titel'); |
| 1120 | expect(docE.children[1].firstChild.data).toEqual('eq'); |
| 1121 | expect(docE.children[1].getAttribute('data-type')).toEqual('string'); |
| 1122 | expect(docE.children[2].firstChild.data).toEqual('Baum'); |
| 1123 | expect(docE.children[2].getAttribute('data-type')).toEqual('string'); |
| 1124 | }); |
| 1125 | |
| 1126 | it('should be based on a docGroup', function () { |
Nils Diewald | 6283d69 | 2015-04-23 20:32:53 +0000 | [diff] [blame] | 1127 | var vc = vcClass.create().fromJson(simpleGroupFactory.create().toJson()); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1128 | |
| 1129 | expect(vc.element().getAttribute('class')).toEqual('vc'); |
| 1130 | expect(vc.root().element().getAttribute('class')).toEqual('docGroup'); |
| 1131 | expect(vc.root().operation()).toEqual('and'); |
| 1132 | |
| 1133 | var docGroup = vc.root(); |
| 1134 | |
| 1135 | var first = docGroup.getOperand(0); |
| 1136 | expect(first.key()).toEqual('author'); |
| 1137 | expect(first.value()).toEqual('Max Birkendale'); |
| 1138 | expect(first.matchop()).toEqual('eq'); |
| 1139 | |
| 1140 | var second = docGroup.getOperand(1); |
| 1141 | expect(second.key()).toEqual('pubDate'); |
| 1142 | expect(second.value()).toEqual('2014-12-05'); |
| 1143 | expect(second.matchop()).toEqual('eq'); |
| 1144 | }); |
| 1145 | |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 1146 | it('should be based on a docGroupRef', function () { |
| 1147 | var vc = vcClass.create().fromJson({ |
| 1148 | "@type" : "koral:docGroupRef", |
| 1149 | "ref":"myCorpus" |
| 1150 | }); |
| 1151 | |
Akron | 3ad4694 | 2018-08-22 16:47:14 +0200 | [diff] [blame^] | 1152 | // iv class="doc groupref"><span class="key fixed">referTo</span><span data-type="string" class="value">myCorpus</span> |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 1153 | var vcE = vc.element(); |
| 1154 | expect(vcE.getAttribute('class')).toEqual('vc'); |
| 1155 | expect(vcE.firstChild.tagName).toEqual('DIV'); |
| 1156 | expect(vcE.firstChild.classList.contains('groupref')).toBeTruthy(); |
| 1157 | |
| 1158 | expect(vcE.firstChild.firstChild.tagName).toEqual('SPAN'); |
| 1159 | expect(vcE.firstChild.firstChild.classList.contains('key')).toBeTruthy(); |
| 1160 | expect(vcE.firstChild.firstChild.classList.contains('fixed')).toBeTruthy(); |
| 1161 | |
Akron | 3ad4694 | 2018-08-22 16:47:14 +0200 | [diff] [blame^] | 1162 | expect(vcE.firstChild.firstChild.textContent).toEqual("referTo"); |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 1163 | |
| 1164 | expect(vcE.firstChild.children[1].tagName).toEqual('SPAN'); |
| 1165 | expect(vcE.firstChild.children[1].classList.contains('value')).toBeTruthy(); |
| 1166 | expect(vcE.firstChild.children[1].getAttribute('data-type')).toEqual('string'); |
| 1167 | expect(vcE.firstChild.children[1].textContent).toEqual("myCorpus"); |
| 1168 | }); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1169 | |
| 1170 | it('should be based on a nested docGroup', function () { |
| 1171 | var vc = nestedGroupFactory.create(); |
| 1172 | |
| 1173 | expect(vc.element().getAttribute('class')).toEqual('vc'); |
| 1174 | expect(vc.element().firstChild.getAttribute('class')).toEqual('docGroup'); |
| 1175 | expect(vc.element().firstChild.children[0].getAttribute('class')).toEqual('doc'); |
| 1176 | var dg = vc.element().firstChild.children[1]; |
| 1177 | expect(dg.getAttribute('class')).toEqual('docGroup'); |
| 1178 | expect(dg.children[0].getAttribute('class')).toEqual('doc'); |
| 1179 | expect(dg.children[1].getAttribute('class')).toEqual('doc'); |
Akron | 0b489ad | 2018-02-02 16:49:32 +0100 | [diff] [blame] | 1180 | expect(dg.children[2].getAttribute('class')).toEqual('operators button-group'); |
| 1181 | expect(vc.element().firstChild.children[2].getAttribute('class')).toEqual('operators button-group'); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1182 | }); |
| 1183 | |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 1184 | it('should be based on a nested docGroupRef', function () { |
| 1185 | var vc = vcClass.create().fromJson({ |
| 1186 | "@type" : "koral:docGroup", |
| 1187 | "operation" : "operation:and", |
| 1188 | "operands" : [{ |
| 1189 | "@type" : "koral:docGroupRef", |
| 1190 | "ref":"myCorpus" |
| 1191 | },{ |
| 1192 | "@type" : "koral:doc", |
| 1193 | "key":"Titel", |
| 1194 | "value":"Baum", |
| 1195 | "match":"match:eq" |
| 1196 | }] |
| 1197 | }); |
| 1198 | |
| 1199 | expect(vc._root.ldType()).toEqual("docGroup"); |
| 1200 | |
| 1201 | expect(vc.toQuery()).toEqual('referTo "myCorpus" & Titel = "Baum"'); |
| 1202 | }); |
| 1203 | |
| 1204 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1205 | it('should be modifiable by deletion in flat docGroups', function () { |
| 1206 | var vc = flatGroupFactory.create(); |
| 1207 | var docGroup = vc.root(); |
| 1208 | |
| 1209 | expect(docGroup.element().getAttribute('class')).toEqual('docGroup'); |
| 1210 | |
| 1211 | var doc = docGroup.getOperand(1); |
| 1212 | expect(doc.key()).toEqual("pubDate"); |
| 1213 | expect(doc.value()).toEqual("2014-12-05"); |
| 1214 | |
| 1215 | // Remove operand 1 |
| 1216 | expect(docGroup.delOperand(doc).update()).not.toBeUndefined(); |
| 1217 | expect(doc._element).toEqual(undefined); |
| 1218 | |
| 1219 | doc = docGroup.getOperand(1); |
| 1220 | expect(doc.key()).toEqual("foo"); |
| 1221 | |
| 1222 | // Remove operand 1 |
| 1223 | expect(docGroup.delOperand(doc).update()).not.toBeUndefined(); |
| 1224 | expect(doc._element).toEqual(undefined); |
| 1225 | |
| 1226 | // Only one operand left ... |
| 1227 | expect(docGroup.getOperand(1)).toBeUndefined(); |
| 1228 | // ... but there shouldn't be a group anymore at all! |
| 1229 | expect(docGroup.getOperand(0)).toBeUndefined(); |
| 1230 | |
| 1231 | var obj = vc.root(); |
| 1232 | expect(obj.ldType()).toEqual("doc"); |
| 1233 | expect(obj.key()).toEqual("pubDate"); |
| 1234 | expect(obj.value()).toEqual("2014-05-12"); |
| 1235 | |
| 1236 | expect(obj.element().getAttribute('class')).toEqual('doc'); |
| 1237 | }); |
| 1238 | |
| 1239 | |
| 1240 | it('should be modifiable by deletion in nested docGroups (root case)', function () { |
| 1241 | var vc = nestedGroupFactory.create(); |
| 1242 | |
| 1243 | expect(vc.toQuery()).toEqual( |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 1244 | '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] | 1245 | ); |
| 1246 | |
| 1247 | var docGroup = vc.root(); |
| 1248 | expect(docGroup.ldType()).toEqual("docGroup"); |
| 1249 | expect(docGroup.operation()).toEqual("or"); |
| 1250 | |
| 1251 | var doc = docGroup.getOperand(0); |
| 1252 | expect(doc.key()).toEqual("author"); |
| 1253 | expect(doc.value()).toEqual("Max Birkendale"); |
| 1254 | |
| 1255 | docGroup = docGroup.getOperand(1); |
| 1256 | expect(docGroup.operation()).toEqual("and"); |
| 1257 | |
| 1258 | doc = docGroup.getOperand(0); |
| 1259 | expect(doc.key()).toEqual("pubDate"); |
| 1260 | expect(doc.matchop()).toEqual("geq"); |
| 1261 | expect(doc.value()).toEqual("2014-05-12"); |
| 1262 | expect(doc.type()).toEqual("date"); |
| 1263 | |
| 1264 | doc = docGroup.getOperand(1); |
| 1265 | expect(doc.key()).toEqual("pubDate"); |
| 1266 | expect(doc.matchop()).toEqual("leq"); |
| 1267 | expect(doc.value()).toEqual("2014-12-05"); |
| 1268 | expect(doc.type()).toEqual("date"); |
| 1269 | |
| 1270 | // Remove first operand so everything becomes root |
| 1271 | expect( |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 1272 | vc.root().delOperand( |
| 1273 | vc.root().getOperand(0) |
| 1274 | ).update().ldType() |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1275 | ).toEqual("docGroup"); |
| 1276 | |
| 1277 | expect(vc.root().ldType()).toEqual("docGroup"); |
| 1278 | expect(vc.root().operation()).toEqual("and"); |
| 1279 | expect(vc.root().getOperand(0).ldType()).toEqual("doc"); |
| 1280 | |
| 1281 | expect(vc.toQuery()).toEqual( |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 1282 | 'pubDate since 2014-05-12 & pubDate until 2014-12-05' |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1283 | ); |
| 1284 | }); |
| 1285 | |
| 1286 | it('should be modifiable by deletion in nested docGroups (resolve group case)', function () { |
| 1287 | var vc = nestedGroupFactory.create(); |
| 1288 | |
| 1289 | // Get nested group |
| 1290 | var firstGroup = vc.root().getOperand(1); |
| 1291 | firstGroup.append(simpleGroupFactory.create({ "operation" : "operation:or" })); |
| 1292 | |
| 1293 | // Structur is now: |
| 1294 | // or(doc, and(doc, doc, or(doc, doc))) |
| 1295 | |
| 1296 | // Get nested or in and |
| 1297 | var orGroup = vc.root().getOperand(1).getOperand(2); |
| 1298 | expect(orGroup.ldType()).toEqual("docGroup"); |
| 1299 | expect(orGroup.operation()).toEqual("or"); |
| 1300 | |
| 1301 | // Remove |
| 1302 | // Structur is now: |
| 1303 | // or(doc, and(doc, doc, doc))) |
| 1304 | expect(orGroup.delOperand(orGroup.getOperand(0)).update().operation()).toEqual("and"); |
| 1305 | expect(vc.root().getOperand(1).operands().length).toEqual(3); |
| 1306 | }); |
| 1307 | |
| 1308 | it('should be modifiable by deletion in nested docGroups (identical group case)', function () { |
| 1309 | var vc = nestedGroupFactory.create(); |
| 1310 | |
| 1311 | // Get nested group |
| 1312 | var firstGroup = vc.root().getOperand(1); |
| 1313 | firstGroup.append(simpleGroupFactory.create({ |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 1314 | "operation" : "operation:or" |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1315 | })); |
| 1316 | var oldAuthor = firstGroup.getOperand(2).getOperand(0); |
| 1317 | oldAuthor.key("title"); |
| 1318 | oldAuthor.value("Der Birnbaum"); |
| 1319 | |
| 1320 | // Structur is now: |
| 1321 | // or(doc, and(doc, doc, or(doc, doc))) |
| 1322 | expect(vc.toQuery()).toEqual( |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 1323 | 'author = "Max Birkendale" | ' + |
| 1324 | '(pubDate since 2014-05-12 & ' + |
| 1325 | 'pubDate until 2014-12-05 & ' + |
| 1326 | '(title = "Der Birnbaum" | ' + |
| 1327 | 'pubDate in 2014-12-05))' |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1328 | ); |
| 1329 | |
| 1330 | var andGroup = vc.root().getOperand(1); |
| 1331 | |
| 1332 | // Get leading docs in and |
| 1333 | var doc1 = andGroup.getOperand(0); |
| 1334 | expect(doc1.ldType()).toEqual("doc"); |
| 1335 | expect(doc1.value()).toEqual("2014-05-12"); |
| 1336 | var doc2 = andGroup.getOperand(1); |
| 1337 | expect(doc2.ldType()).toEqual("doc"); |
| 1338 | expect(doc2.value()).toEqual("2014-12-05"); |
| 1339 | |
| 1340 | // Remove 2 |
| 1341 | expect( |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 1342 | andGroup.delOperand(doc2).update().operation() |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1343 | ).toEqual("and"); |
| 1344 | // Structur is now: |
| 1345 | // or(doc, and(doc, or(doc, doc))) |
| 1346 | |
| 1347 | expect(vc.toQuery()).toEqual( |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 1348 | 'author = "Max Birkendale"' + |
| 1349 | ' | (pubDate since 2014-05-12 & ' + |
| 1350 | '(title = "Der Birnbaum" | pubDate in 2014-12-05))' |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1351 | ); |
| 1352 | |
| 1353 | |
| 1354 | // Remove 1 |
| 1355 | expect(andGroup.delOperand(doc1).update().operation()).toEqual("or"); |
| 1356 | // Structur is now: |
| 1357 | // or(doc, doc, doc) |
| 1358 | |
| 1359 | expect(vc.toQuery()).toEqual( |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 1360 | 'author = "Max Birkendale" | title = "Der Birnbaum" | pubDate in 2014-12-05' |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1361 | ); |
| 1362 | }); |
| 1363 | |
| 1364 | it('should be reducible to unspecification', function () { |
| 1365 | var vc = demoFactory.create(); |
| 1366 | |
| 1367 | expect(vc.toQuery()).toEqual(vc.root().toQuery()); |
| 1368 | expect(vc.toQuery()).toEqual( |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 1369 | '(Titel = "Baum" & Veröffentlichungsort = "hihi" & ' + |
| 1370 | '(Titel = "Baum" | Veröffentlichungsort = "hihi")) ' + |
| 1371 | '| Untertitel ~ "huhu"'); |
Akron | d141a36 | 2018-07-10 18:12:13 +0200 | [diff] [blame] | 1372 | expect(vc.root().element().lastChild.children[0].innerText).toEqual('and'); |
| 1373 | expect(vc.root().element().lastChild.children[1].innerText).toEqual('×'); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1374 | expect(vc.root().delOperand(vc.root().getOperand(0)).update()).not.toBeUndefined(); |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 1375 | expect(vc.toQuery()).toEqual('Untertitel ~ "huhu"'); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1376 | |
| 1377 | var lc = vc.root().element().lastChild; |
Akron | d141a36 | 2018-07-10 18:12:13 +0200 | [diff] [blame] | 1378 | expect(lc.children[0].innerText).toEqual('and'); |
| 1379 | expect(lc.children[1].innerText).toEqual('or'); |
| 1380 | expect(lc.children[2].innerText).toEqual('×'); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1381 | |
| 1382 | // Clean everything |
| 1383 | vc.clean(); |
| 1384 | expect(vc.toQuery()).toEqual(''); |
| 1385 | }); |
| 1386 | |
| 1387 | it('should flatten on import', function () { |
Nils Diewald | 6283d69 | 2015-04-23 20:32:53 +0000 | [diff] [blame] | 1388 | var vc = vcClass.create().fromJson({ |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 1389 | "@type":"koral:docGroup", |
| 1390 | "operation":"operation:or", |
| 1391 | "operands":[ |
| 1392 | { |
| 1393 | "@type":"koral:docGroup", |
| 1394 | "operation":"operation:or", |
| 1395 | "operands":[ |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1396 | { |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 1397 | "@type":"koral:doc", |
| 1398 | "key":"Titel", |
| 1399 | "value":"Baum", |
| 1400 | "match":"match:eq" |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1401 | }, |
| 1402 | { |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 1403 | "@type":"koral:doc", |
| 1404 | "key":"Veröffentlichungsort", |
| 1405 | "value":"hihi", |
| 1406 | "match":"match:eq" |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1407 | }, |
| 1408 | { |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 1409 | "@type":"koral:docGroup", |
| 1410 | "operation":"operation:or", |
| 1411 | "operands":[ |
| 1412 | { |
| 1413 | "@type":"koral:doc", |
| 1414 | "key":"Titel", |
| 1415 | "value":"Baum", |
| 1416 | "match":"match:eq" |
| 1417 | }, |
| 1418 | { |
| 1419 | "@type":"koral:doc", |
| 1420 | "key":"Veröffentlichungsort", |
| 1421 | "value":"hihi", |
| 1422 | "match":"match:eq" |
| 1423 | } |
| 1424 | ] |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1425 | } |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 1426 | ] |
| 1427 | }, |
| 1428 | { |
| 1429 | "@type":"koral:doc", |
| 1430 | "key":"Untertitel", |
| 1431 | "value":"huhu", |
| 1432 | "match":"match:contains" |
| 1433 | } |
| 1434 | ] |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1435 | }); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 1436 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1437 | expect(vc.toQuery()).toEqual( |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 1438 | 'Titel = "Baum" | Veröffentlichungsort = "hihi" | Untertitel ~ "huhu"' |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1439 | ); |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 1440 | }); |
Akron | 1bdf527 | 2018-07-24 18:51:30 +0200 | [diff] [blame] | 1441 | |
| 1442 | it('should be deserializable from collection 1', function () { |
| 1443 | var kq = { |
| 1444 | "matches":["..."], |
| 1445 | "collection":{ |
| 1446 | "@type": "koral:docGroup", |
| 1447 | "operation": "operation:or", |
| 1448 | "operands": [{ |
| 1449 | "@type": "koral:docGroup", |
| 1450 | "operation": "operation:and", |
| 1451 | "operands": [ |
| 1452 | { |
| 1453 | "@type": "koral:doc", |
| 1454 | "key": "title", |
| 1455 | "match": "match:eq", |
| 1456 | "value": "Der Birnbaum", |
| 1457 | "type": "type:string" |
| 1458 | }, |
| 1459 | { |
| 1460 | "@type": "koral:doc", |
| 1461 | "key": "pubPlace", |
| 1462 | "match": "match:eq", |
| 1463 | "value": "Mannheim", |
| 1464 | "type": "type:string" |
| 1465 | }, |
| 1466 | { |
| 1467 | "@type": "koral:docGroup", |
| 1468 | "operation": "operation:or", |
| 1469 | "operands": [ |
| 1470 | { |
| 1471 | "@type": "koral:doc", |
| 1472 | "key": "subTitle", |
| 1473 | "match": "match:eq", |
| 1474 | "value": "Aufzucht und Pflege", |
| 1475 | "type": "type:string" |
| 1476 | }, |
| 1477 | { |
| 1478 | "@type": "koral:doc", |
| 1479 | "key": "subTitle", |
| 1480 | "match": "match:eq", |
| 1481 | "value": "Gedichte", |
| 1482 | "type": "type:string" |
| 1483 | } |
| 1484 | ] |
| 1485 | } |
| 1486 | ] |
| 1487 | },{ |
| 1488 | "@type": "koral:doc", |
| 1489 | "key": "pubDate", |
| 1490 | "match": "match:geq", |
| 1491 | "value": "2015-03-05", |
| 1492 | "type": "type:date", |
| 1493 | "rewrites" : [{ |
| 1494 | "@type" : "koral:rewrite", |
| 1495 | "operation" : "operation:modification", |
| 1496 | "src" : "querySerializer", |
| 1497 | "scope" : "tree" |
| 1498 | }] |
| 1499 | }] |
| 1500 | } |
| 1501 | }; |
| 1502 | |
| 1503 | var vc = vcClass.create().fromJson(kq["collection"]); |
| 1504 | expect(vc.toQuery()).toEqual('(title = "Der Birnbaum" & pubPlace = "Mannheim" & (subTitle = "Aufzucht und Pflege" | subTitle = "Gedichte")) | pubDate since 2015-03-05'); |
| 1505 | }); |
| 1506 | |
| 1507 | it('should be deserializable from collection 2', function () { |
| 1508 | var kq = { |
| 1509 | "@context": "http://korap.ids-mannheim.de/ns/KoralQuery/v0.3/context.jsonld", |
| 1510 | "meta": {}, |
| 1511 | "query": { |
| 1512 | "@type": "koral:token", |
| 1513 | "wrap": { |
| 1514 | "@type": "koral:term", |
| 1515 | "match": "match:eq", |
| 1516 | "layer": "orth", |
| 1517 | "key": "Baum", |
| 1518 | "foundry": "opennlp", |
| 1519 | "rewrites": [ |
| 1520 | { |
| 1521 | "@type": "koral:rewrite", |
| 1522 | "src": "Kustvakt", |
| 1523 | "operation": "operation:injection", |
| 1524 | "scope": "foundry" |
| 1525 | } |
| 1526 | ] |
| 1527 | }, |
| 1528 | "idn": "Baum_2227", |
| 1529 | "rewrites": [ |
| 1530 | { |
| 1531 | "@type": "koral:rewrite", |
| 1532 | "src": "Kustvakt", |
| 1533 | "operation": "operation:injection", |
| 1534 | "scope": "idn" |
| 1535 | } |
| 1536 | ] |
| 1537 | }, |
| 1538 | "collection": { |
| 1539 | "@type": "koral:docGroup", |
| 1540 | "operation": "operation:and", |
| 1541 | "operands": [ |
| 1542 | { |
| 1543 | "@type": "koral:doc", |
| 1544 | "match": "match:eq", |
| 1545 | "type": "type:regex", |
| 1546 | "value": "CC-BY.*", |
| 1547 | "key": "availability" |
| 1548 | }, |
| 1549 | { |
| 1550 | "@type": "koral:doc", |
| 1551 | "match": "match:eq", |
| 1552 | "type":"type:text", |
| 1553 | "value": "Goethe", |
| 1554 | "key": "author" |
| 1555 | } |
| 1556 | ], |
| 1557 | "rewrites": [ |
| 1558 | { |
| 1559 | "@type": "koral:rewrite", |
| 1560 | "src": "Kustvakt", |
| 1561 | "operation": "operation:insertion", |
| 1562 | "scope": "availability(FREE)" |
| 1563 | } |
| 1564 | ] |
| 1565 | }, |
| 1566 | "matches": [] |
| 1567 | }; |
| 1568 | |
| 1569 | var vc = vcClass.create().fromJson(kq["collection"]); |
| 1570 | expect(vc.toQuery()).toEqual('availability = /CC-BY.*/ & author = "Goethe"'); |
| 1571 | }); |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 1572 | }); |
| 1573 | |
Akron | 1bdf527 | 2018-07-24 18:51:30 +0200 | [diff] [blame] | 1574 | it('shouldn\'t be deserializable from collection with unknown type', function () { |
| 1575 | var kq = { |
| 1576 | "@type" : "koral:doc", |
| 1577 | "match": "match:eq", |
| 1578 | "type":"type:failure", |
| 1579 | "value": "Goethe", |
| 1580 | "key": "author" |
| 1581 | }; |
| 1582 | |
| 1583 | expect(function () { |
| 1584 | vcClass.create().fromJson(kq) |
| 1585 | }).toThrow(new Error("Unknown value type: string")); |
Akron | 1bdf527 | 2018-07-24 18:51:30 +0200 | [diff] [blame] | 1586 | }); |
| 1587 | |
| 1588 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1589 | describe('KorAP.Operators', function () { |
| 1590 | it('should be initializable', function () { |
| 1591 | var op = operatorsClass.create(true, false, false); |
| 1592 | expect(op.and()).toBeTruthy(); |
| 1593 | expect(op.or()).not.toBeTruthy(); |
| 1594 | expect(op.del()).not.toBeTruthy(); |
| 1595 | |
| 1596 | op.and(false); |
| 1597 | expect(op.and()).not.toBeTruthy(); |
| 1598 | expect(op.or()).not.toBeTruthy(); |
| 1599 | expect(op.del()).not.toBeTruthy(); |
| 1600 | |
| 1601 | op.or(true); |
| 1602 | op.del(true); |
| 1603 | expect(op.and()).not.toBeTruthy(); |
| 1604 | expect(op.or()).toBeTruthy(); |
| 1605 | expect(op.del()).toBeTruthy(); |
| 1606 | |
Akron | d141a36 | 2018-07-10 18:12:13 +0200 | [diff] [blame] | 1607 | var e = op.update(); |
Akron | 0b489ad | 2018-02-02 16:49:32 +0100 | [diff] [blame] | 1608 | expect(e.getAttribute('class')).toEqual('operators button-group'); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1609 | expect(e.children[0].getAttribute('class')).toEqual('or'); |
Akron | d141a36 | 2018-07-10 18:12:13 +0200 | [diff] [blame] | 1610 | expect(e.children[0].innerText).toEqual('or'); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1611 | expect(e.children[1].getAttribute('class')).toEqual('delete'); |
Akron | d141a36 | 2018-07-10 18:12:13 +0200 | [diff] [blame] | 1612 | expect(e.children[1].innerText).toEqual('×'); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1613 | |
| 1614 | op.and(true); |
| 1615 | op.del(false); |
Akron | d141a36 | 2018-07-10 18:12:13 +0200 | [diff] [blame] | 1616 | e = op.update(); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1617 | |
Akron | 0b489ad | 2018-02-02 16:49:32 +0100 | [diff] [blame] | 1618 | expect(e.getAttribute('class')).toEqual('operators button-group'); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1619 | expect(e.children[0].getAttribute('class')).toEqual('and'); |
Akron | d141a36 | 2018-07-10 18:12:13 +0200 | [diff] [blame] | 1620 | expect(e.children[0].innerText).toEqual('and'); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1621 | expect(e.children[1].getAttribute('class')).toEqual('or'); |
Akron | d141a36 | 2018-07-10 18:12:13 +0200 | [diff] [blame] | 1622 | expect(e.children[1].innerText).toEqual('or'); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1623 | }); |
| 1624 | }); |
| 1625 | |
| 1626 | describe('KorAP._delete (event)', function () { |
| 1627 | var complexVCFactory = buildFactory(vcClass,{ |
| 1628 | "@type": 'koral:docGroup', |
| 1629 | 'operation' : 'operation:and', |
| 1630 | 'operands' : [ |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 1631 | { |
| 1632 | "@type": 'koral:doc', |
| 1633 | "key": 'pubDate', |
| 1634 | "match": 'match:eq', |
| 1635 | "value": '2014-12-05', |
| 1636 | "type": 'type:date' |
| 1637 | }, |
| 1638 | { |
| 1639 | "@type" : 'koral:docGroup', |
| 1640 | 'operation' : 'operation:or', |
| 1641 | 'operands' : [ |
| 1642 | { |
| 1643 | '@type' : 'koral:doc', |
| 1644 | 'key' : 'title', |
| 1645 | 'value' : 'Hello World!' |
| 1646 | }, |
| 1647 | { |
| 1648 | '@type' : 'koral:doc', |
| 1649 | 'key' : 'foo', |
| 1650 | 'value' : 'bar' |
| 1651 | } |
| 1652 | ] |
| 1653 | } |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1654 | ] |
| 1655 | }); |
| 1656 | |
| 1657 | it('should clean on root docs', function () { |
Nils Diewald | 6283d69 | 2015-04-23 20:32:53 +0000 | [diff] [blame] | 1658 | var vc = vcClass.create().fromJson({ |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 1659 | "@type": 'koral:doc', |
| 1660 | "key": 'pubDate', |
| 1661 | "match": 'match:eq', |
| 1662 | "value": '2014-12-05', |
| 1663 | "type": 'type:date' |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 1664 | }); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1665 | expect(vc.root().toQuery()).toEqual('pubDate in 2014-12-05'); |
Akron | 0b489ad | 2018-02-02 16:49:32 +0100 | [diff] [blame] | 1666 | expect(vc.root().element().lastChild.getAttribute('class')).toEqual('operators button-group'); |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 1667 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1668 | // Clean with delete from root |
| 1669 | expect(vc.root().element().lastChild.lastChild.getAttribute('class')).toEqual('delete'); |
| 1670 | _delOn(vc.root()); |
| 1671 | expect(vc.root().toQuery()).toEqual(''); |
| 1672 | expect(vc.root().element().lastChild.lastChild.data).toEqual('⋯'); |
| 1673 | }); |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 1674 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1675 | it('should remove on nested docs', function () { |
Nils Diewald | 6283d69 | 2015-04-23 20:32:53 +0000 | [diff] [blame] | 1676 | var vc = vcClass.create().fromJson( |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 1677 | { |
| 1678 | "@type": 'koral:docGroup', |
| 1679 | 'operation' : 'operation:and', |
| 1680 | 'operands' : [ |
| 1681 | { |
| 1682 | "@type": 'koral:doc', |
| 1683 | "key": 'pubDate', |
| 1684 | "match": 'match:eq', |
| 1685 | "value": '2014-12-05', |
| 1686 | "type": 'type:date' |
| 1687 | }, |
| 1688 | { |
| 1689 | "@type" : 'koral:doc', |
| 1690 | 'key' : 'foo', |
| 1691 | 'value' : 'bar' |
| 1692 | } |
| 1693 | ] |
| 1694 | } |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1695 | ); |
| 1696 | |
| 1697 | // Delete with direct element access |
| 1698 | expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar"'); |
| 1699 | _delOn(vc.root().getOperand(0)); |
| 1700 | |
| 1701 | expect(vc.toQuery()).toEqual('foo = "bar"'); |
| 1702 | expect(vc.root().ldType()).toEqual('doc'); |
| 1703 | }); |
| 1704 | |
| 1705 | it('should clean on doc groups', function () { |
Nils Diewald | 6283d69 | 2015-04-23 20:32:53 +0000 | [diff] [blame] | 1706 | var vc = vcClass.create().fromJson( |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 1707 | { |
| 1708 | "@type": 'koral:docGroup', |
| 1709 | 'operation' : 'operation:and', |
| 1710 | 'operands' : [ |
| 1711 | { |
| 1712 | "@type": 'koral:doc', |
| 1713 | "key": 'pubDate', |
| 1714 | "match": 'match:eq', |
| 1715 | "value": '2014-12-05', |
| 1716 | "type": 'type:date' |
| 1717 | }, |
| 1718 | { |
| 1719 | "@type" : 'koral:doc', |
| 1720 | 'key' : 'foo', |
| 1721 | 'value' : 'bar' |
| 1722 | } |
| 1723 | ] |
| 1724 | } |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1725 | ); |
| 1726 | |
| 1727 | // Cleanwith direct element access |
| 1728 | expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar"'); |
| 1729 | _delOn(vc.root()); |
| 1730 | expect(vc.toQuery()).toEqual(''); |
| 1731 | expect(vc.root().ldType()).toEqual('non'); |
| 1732 | }); |
| 1733 | |
| 1734 | it('should remove on nested doc groups (case of ungrouping 1)', function () { |
| 1735 | var vc = complexVCFactory.create(); |
| 1736 | |
| 1737 | // Delete with direct element access |
| 1738 | expect(vc.toQuery()).toEqual( |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 1739 | 'pubDate in 2014-12-05 & (title = "Hello World!" | foo = "bar")' |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1740 | ); |
| 1741 | |
| 1742 | // Remove hello world: |
| 1743 | _delOn(vc.root().getOperand(1).getOperand(0)); |
| 1744 | expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar"'); |
| 1745 | expect(vc.root().ldType()).toEqual('docGroup'); |
| 1746 | }); |
| 1747 | |
| 1748 | it('should remove on nested doc groups (case of ungrouping 2)', function () { |
| 1749 | var vc = complexVCFactory.create(); |
| 1750 | |
| 1751 | // Delete with direct element access |
| 1752 | expect(vc.toQuery()).toEqual( |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 1753 | 'pubDate in 2014-12-05 & (title = "Hello World!" | foo = "bar")' |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1754 | ); |
| 1755 | |
| 1756 | // Remove bar |
| 1757 | _delOn(vc.root().getOperand(1).getOperand(1)); |
| 1758 | expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & title = "Hello World!"'); |
| 1759 | expect(vc.root().ldType()).toEqual('docGroup'); |
| 1760 | expect(vc.root().operation()).toEqual('and'); |
| 1761 | }); |
| 1762 | |
| 1763 | it('should remove on nested doc groups (case of root changing)', function () { |
| 1764 | var vc = complexVCFactory.create(); |
| 1765 | |
| 1766 | // Delete with direct element access |
| 1767 | expect(vc.toQuery()).toEqual( |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 1768 | 'pubDate in 2014-12-05 & ' + |
| 1769 | '(title = "Hello World!" | foo = "bar")' |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1770 | ); |
| 1771 | |
| 1772 | // Remove bar |
| 1773 | _delOn(vc.root().getOperand(0)); |
| 1774 | expect(vc.toQuery()).toEqual('title = "Hello World!" | foo = "bar"'); |
| 1775 | expect(vc.root().ldType()).toEqual('docGroup'); |
| 1776 | expect(vc.root().operation()).toEqual('or'); |
| 1777 | }); |
| 1778 | |
| 1779 | it('should remove on nested doc groups (list flattening)', function () { |
Nils Diewald | 6283d69 | 2015-04-23 20:32:53 +0000 | [diff] [blame] | 1780 | var vc = vcClass.create().fromJson( |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 1781 | { |
| 1782 | "@type": 'koral:docGroup', |
| 1783 | 'operation' : 'operation:or', |
| 1784 | 'operands' : [ |
| 1785 | { |
| 1786 | "@type": 'koral:doc', |
| 1787 | "key": 'pubDate', |
| 1788 | "match": 'match:eq', |
| 1789 | "value": '2014-12-05', |
| 1790 | "type": 'type:date' |
| 1791 | }, |
| 1792 | { |
| 1793 | "@type" : 'koral:doc', |
| 1794 | 'key' : 'foo', |
| 1795 | 'value' : 'bar' |
| 1796 | }, |
| 1797 | { |
| 1798 | "@type": 'koral:docGroup', |
| 1799 | 'operation' : 'operation:and', |
| 1800 | 'operands' : [ |
| 1801 | { |
| 1802 | "@type": 'koral:doc', |
| 1803 | "key": 'pubDate', |
| 1804 | "match": 'match:eq', |
| 1805 | "value": '2014-12-05', |
| 1806 | "type": 'type:date' |
| 1807 | }, |
| 1808 | { |
| 1809 | "@type" : 'koral:docGroup', |
| 1810 | 'operation' : 'operation:or', |
| 1811 | 'operands' : [ |
| 1812 | { |
| 1813 | '@type' : 'koral:doc', |
| 1814 | 'key' : 'title', |
| 1815 | 'value' : 'Hello World!' |
| 1816 | }, |
| 1817 | { |
| 1818 | '@type' : 'koral:doc', |
| 1819 | 'key' : 'yeah', |
| 1820 | 'value' : 'juhu' |
| 1821 | } |
| 1822 | ] |
| 1823 | } |
| 1824 | ] |
| 1825 | } |
| 1826 | ] |
| 1827 | } |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1828 | ); |
| 1829 | |
| 1830 | // Delete with direct element access |
| 1831 | expect(vc.toQuery()).toEqual( |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 1832 | 'pubDate in 2014-12-05 | foo = "bar" | ' + |
| 1833 | '(pubDate in 2014-12-05 & ' + |
| 1834 | '(title = "Hello World!" | yeah = "juhu"))' |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1835 | ); |
| 1836 | |
| 1837 | expect(vc.root().ldType()).toEqual('docGroup'); |
| 1838 | expect(vc.root().operation()).toEqual('or'); |
| 1839 | |
| 1840 | // Operands and operators |
| 1841 | expect(vc.element().firstChild.children.length).toEqual(4); |
Akron | 0b489ad | 2018-02-02 16:49:32 +0100 | [diff] [blame] | 1842 | expect(vc.element().firstChild.lastChild.getAttribute('class')).toEqual('operators button-group'); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1843 | |
| 1844 | // Remove inner group and flatten |
| 1845 | _delOn(vc.root().getOperand(2).getOperand(0)); |
| 1846 | |
| 1847 | expect(vc.toQuery()).toEqual( |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 1848 | 'pubDate in 2014-12-05 | foo = "bar" | title = "Hello World!" | yeah = "juhu"' |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1849 | ); |
| 1850 | expect(vc.root().ldType()).toEqual('docGroup'); |
| 1851 | expect(vc.root().operation()).toEqual('or'); |
| 1852 | |
| 1853 | // Operands and operators |
| 1854 | expect(vc.element().firstChild.children.length).toEqual(5); |
Akron | 0b489ad | 2018-02-02 16:49:32 +0100 | [diff] [blame] | 1855 | expect(vc.element().firstChild.lastChild.getAttribute('class')).toEqual('operators button-group'); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1856 | }); |
| 1857 | }); |
| 1858 | |
| 1859 | describe('KorAP._add (event)', function () { |
| 1860 | var complexVCFactory = buildFactory(vcClass,{ |
| 1861 | "@type": 'koral:docGroup', |
| 1862 | 'operation' : 'operation:and', |
| 1863 | 'operands' : [ |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 1864 | { |
| 1865 | "@type": 'koral:doc', |
| 1866 | "key": 'pubDate', |
| 1867 | "match": 'match:eq', |
| 1868 | "value": '2014-12-05', |
| 1869 | "type": 'type:date' |
| 1870 | }, |
| 1871 | { |
| 1872 | "@type" : 'koral:docGroup', |
| 1873 | 'operation' : 'operation:or', |
| 1874 | 'operands' : [ |
| 1875 | { |
| 1876 | '@type' : 'koral:doc', |
| 1877 | 'key' : 'title', |
| 1878 | 'value' : 'Hello World!' |
| 1879 | }, |
| 1880 | { |
| 1881 | '@type' : 'koral:doc', |
| 1882 | 'key' : 'foo', |
| 1883 | 'value' : 'bar' |
| 1884 | } |
| 1885 | ] |
| 1886 | } |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1887 | ] |
| 1888 | }); |
| 1889 | |
| 1890 | it('should add new unspecified doc with "and"', function () { |
Nils Diewald | 6283d69 | 2015-04-23 20:32:53 +0000 | [diff] [blame] | 1891 | var vc = vcClass.create().fromJson( |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 1892 | { |
| 1893 | "@type": 'koral:docGroup', |
| 1894 | 'operation' : 'operation:and', |
| 1895 | 'operands' : [ |
| 1896 | { |
| 1897 | "@type": 'koral:doc', |
| 1898 | "key": 'pubDate', |
| 1899 | "match": 'match:eq', |
| 1900 | "value": '2014-12-05', |
| 1901 | "type": 'type:date' |
| 1902 | }, |
| 1903 | { |
| 1904 | "@type" : 'koral:doc', |
| 1905 | 'key' : 'foo', |
| 1906 | 'value' : 'bar' |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 1907 | }, |
| 1908 | { |
| 1909 | "@type" : "koral:docGroupRef", |
| 1910 | "ref" : "myCorpus" |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 1911 | } |
| 1912 | ] |
| 1913 | } |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1914 | ); |
| 1915 | |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 1916 | 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] | 1917 | |
| 1918 | var fc = vc.element().firstChild; |
| 1919 | expect(fc.getAttribute('data-operation')).toEqual('and'); |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 1920 | expect(fc.children.length).toEqual(4); |
Akron | 0b489ad | 2018-02-02 16:49:32 +0100 | [diff] [blame] | 1921 | expect(fc.lastChild.getAttribute('class')).toEqual('operators button-group'); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1922 | expect(fc.children[0].getAttribute('class')).toEqual('doc'); |
| 1923 | expect(fc.children[1].getAttribute('class')).toEqual('doc'); |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 1924 | expect(fc.children[2].getAttribute('class')).toEqual('doc groupref'); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1925 | |
| 1926 | // add with 'and' in the middle |
| 1927 | _andOn(vc.root().getOperand(0)); |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 1928 | 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] | 1929 | |
| 1930 | fc = vc.element().firstChild; |
| 1931 | expect(fc.getAttribute('data-operation')).toEqual('and'); |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 1932 | expect(fc.children.length).toEqual(5); |
Akron | 0b489ad | 2018-02-02 16:49:32 +0100 | [diff] [blame] | 1933 | expect(fc.lastChild.getAttribute('class')).toEqual('operators button-group'); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1934 | |
| 1935 | expect(fc.children[0].getAttribute('class')).toEqual('doc'); |
| 1936 | expect(fc.children[1].getAttribute('class')).toEqual('doc unspecified'); |
| 1937 | expect(fc.children[2].getAttribute('class')).toEqual('doc'); |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 1938 | expect(fc.children[3].getAttribute('class')).toEqual('doc groupref'); |
| 1939 | expect(fc.children[4].classList.contains('button-group')).toBeTruthy(); |
| 1940 | expect(fc.children.length).toEqual(5); |
| 1941 | |
| 1942 | _andOn(vc.root().getOperand(3)); |
| 1943 | expect(fc.children[0].getAttribute('class')).toEqual('doc'); |
| 1944 | expect(fc.children[1].getAttribute('class')).toEqual('doc unspecified'); |
| 1945 | expect(fc.children[2].getAttribute('class')).toEqual('doc'); |
| 1946 | expect(fc.children[3].getAttribute('class')).toEqual('doc groupref'); |
| 1947 | expect(fc.children[4].getAttribute('class')).toEqual('doc unspecified'); |
| 1948 | expect(fc.children[5].classList.contains('button-group')).toBeTruthy(); |
| 1949 | expect(fc.children.length).toEqual(6); |
| 1950 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1951 | }); |
| 1952 | |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 1953 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1954 | it('should add new unspecified doc with "or"', function () { |
Nils Diewald | 6283d69 | 2015-04-23 20:32:53 +0000 | [diff] [blame] | 1955 | var vc = vcClass.create().fromJson( |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 1956 | { |
| 1957 | "@type": 'koral:docGroup', |
| 1958 | 'operation' : 'operation:and', |
| 1959 | 'operands' : [ |
| 1960 | { |
| 1961 | "@type": 'koral:doc', |
| 1962 | "key": 'pubDate', |
| 1963 | "match": 'match:eq', |
| 1964 | "value": '2014-12-05', |
| 1965 | "type": 'type:date' |
| 1966 | }, |
| 1967 | { |
| 1968 | "@type" : 'koral:doc', |
| 1969 | 'key' : 'foo', |
| 1970 | 'value' : 'bar' |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 1971 | }, |
| 1972 | { |
| 1973 | "@type" : "koral:docGroupRef", |
| 1974 | "ref" : "myCorpus" |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 1975 | } |
| 1976 | ] |
| 1977 | } |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1978 | ); |
| 1979 | |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 1980 | 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] | 1981 | |
| 1982 | var fc = vc.element().firstChild; |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 1983 | expect(fc.children.length).toEqual(4); |
Akron | 0b489ad | 2018-02-02 16:49:32 +0100 | [diff] [blame] | 1984 | expect(fc.lastChild.getAttribute('class')).toEqual('operators button-group'); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1985 | expect(fc.children[0].getAttribute('class')).toEqual('doc'); |
| 1986 | expect(fc.children[1].getAttribute('class')).toEqual('doc'); |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 1987 | expect(fc.children[2].getAttribute('class')).toEqual('doc groupref'); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1988 | |
| 1989 | // add with 'or' in the middle |
| 1990 | _orOn(vc.root().getOperand(0)); |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 1991 | 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] | 1992 | fc = vc.element().firstChild; |
| 1993 | |
| 1994 | expect(fc.getAttribute('data-operation')).toEqual('and'); |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 1995 | expect(fc.children.length).toEqual(4); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1996 | expect(fc.children[0].getAttribute('class')).toEqual('docGroup'); |
| 1997 | expect(fc.children[0].getAttribute('data-operation')).toEqual('or'); |
| 1998 | expect(fc.children[1].getAttribute('class')).toEqual('doc'); |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 1999 | expect(fc.children[2].getAttribute('class')).toEqual('doc groupref'); |
| 2000 | expect(fc.children[3].getAttribute('class')).toEqual('operators button-group'); |
Akron | 0b489ad | 2018-02-02 16:49:32 +0100 | [diff] [blame] | 2001 | expect(fc.lastChild.getAttribute('class')).toEqual('operators button-group'); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 2002 | |
| 2003 | fc = vc.element().firstChild.firstChild; |
| 2004 | expect(fc.children.length).toEqual(3); |
| 2005 | expect(fc.children[0].getAttribute('class')).toEqual('doc'); |
| 2006 | expect(fc.children[1].getAttribute('class')).toEqual('doc unspecified'); |
Akron | 0b489ad | 2018-02-02 16:49:32 +0100 | [diff] [blame] | 2007 | expect(fc.children[2].getAttribute('class')).toEqual('operators button-group'); |
| 2008 | expect(fc.lastChild.getAttribute('class')).toEqual('operators button-group'); |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 2009 | |
| 2010 | _orOn(vc.root().getOperand(2)); |
| 2011 | fc = vc.element().firstChild; |
| 2012 | expect(fc.children.length).toEqual(4); |
| 2013 | |
| 2014 | expect(fc.children[0].getAttribute('class')).toEqual('docGroup'); |
| 2015 | expect(fc.children[1].getAttribute('class')).toEqual('doc'); |
| 2016 | expect(fc.children[2].getAttribute('class')).toEqual('docGroup'); |
| 2017 | expect(fc.children[3].getAttribute('class')).toEqual('operators button-group'); |
| 2018 | |
| 2019 | fc = vc.element().firstChild.children[2]; |
| 2020 | expect(fc.children[0].getAttribute('class')).toEqual('doc groupref'); |
| 2021 | expect(fc.children[1].getAttribute('class')).toEqual('doc unspecified'); |
| 2022 | expect(fc.children[2].getAttribute('class')).toEqual('operators button-group'); |
| 2023 | expect(fc.lastChild.getAttribute('class')).toEqual('operators button-group'); |
| 2024 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 2025 | }); |
| 2026 | |
| 2027 | it('should add new unspecified doc with "and" before group', function () { |
| 2028 | var vc = demoFactory.create(); |
| 2029 | |
| 2030 | // Wrap with direct element access |
| 2031 | expect(vc.toQuery()).toEqual( |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 2032 | '(Titel = "Baum" & ' + |
| 2033 | 'Veröffentlichungsort = "hihi" & ' + |
| 2034 | '(Titel = "Baum" | ' + |
| 2035 | 'Veröffentlichungsort = "hihi")) | ' + |
| 2036 | 'Untertitel ~ "huhu"' |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 2037 | ); |
| 2038 | |
| 2039 | expect(vc.root().getOperand(0).ldType()).toEqual('docGroup'); |
| 2040 | expect(vc.root().getOperand(0).operation()).toEqual('and'); |
| 2041 | expect(vc.root().getOperand(0).operands().length).toEqual(3); |
| 2042 | |
| 2043 | // Add unspecified on the second doc |
| 2044 | var secDoc = vc.root().getOperand(0).getOperand(1); |
| 2045 | expect(secDoc.value()).toEqual('hihi'); |
| 2046 | |
| 2047 | // Add |
| 2048 | _andOn(secDoc); |
| 2049 | |
| 2050 | var fo = vc.root().getOperand(0); |
| 2051 | |
| 2052 | expect(fo.ldType()).toEqual('docGroup'); |
| 2053 | expect(fo.operation()).toEqual('and'); |
| 2054 | expect(fo.operands().length).toEqual(4); |
| 2055 | |
| 2056 | expect(fo.getOperand(0).ldType()).toEqual('doc'); |
| 2057 | expect(fo.getOperand(1).ldType()).toEqual('doc'); |
| 2058 | expect(fo.getOperand(2).ldType()).toEqual('non'); |
| 2059 | expect(fo.getOperand(3).ldType()).toEqual('docGroup'); |
| 2060 | }); |
| 2061 | |
| 2062 | |
| 2063 | it('should remove a doc with an unspecified doc in a nested group', function () { |
| 2064 | var vc = demoFactory.create(); |
| 2065 | |
| 2066 | // Wrap with direct element access |
| 2067 | expect(vc.toQuery()).toEqual( |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 2068 | '(Titel = "Baum" & Veröffentlichungsort = "hihi" & (Titel = "Baum" | Veröffentlichungsort = "hihi")) | Untertitel ~ "huhu"' |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 2069 | ); |
| 2070 | |
| 2071 | var fo = vc.root().getOperand(0).getOperand(0); |
| 2072 | expect(fo.key()).toEqual('Titel'); |
| 2073 | expect(fo.value()).toEqual('Baum'); |
| 2074 | |
| 2075 | // Add unspecified on the root group |
| 2076 | _orOn(fo); |
| 2077 | |
| 2078 | fo = vc.root().getOperand(0).getOperand(0); |
| 2079 | |
| 2080 | expect(fo.operation()).toEqual('or'); |
| 2081 | expect(fo.getOperand(0).ldType()).toEqual('doc'); |
| 2082 | expect(fo.getOperand(1).ldType()).toEqual('non'); |
| 2083 | |
| 2084 | // Delete document |
| 2085 | _delOn(fo.getOperand(0)); |
| 2086 | |
| 2087 | // The operand is now non |
| 2088 | expect(vc.root().getOperand(0).getOperand(0).ldType()).toEqual('non'); |
| 2089 | expect(vc.root().getOperand(0).getOperand(1).ldType()).toEqual('doc'); |
| 2090 | expect(vc.root().getOperand(0).getOperand(2).ldType()).toEqual('docGroup'); |
| 2091 | }); |
| 2092 | |
| 2093 | |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 2094 | 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] | 2095 | var vc = demoFactory.create(); |
| 2096 | |
| 2097 | // Wrap with direct element access |
| 2098 | expect(vc.toQuery()).toEqual( |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 2099 | '(Titel = "Baum" & ' + |
| 2100 | 'Veröffentlichungsort = "hihi" & ' + |
| 2101 | '(Titel = "Baum" ' + |
| 2102 | '| Veröffentlichungsort = "hihi")) | ' + |
| 2103 | 'Untertitel ~ "huhu"' |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 2104 | ); |
| 2105 | |
| 2106 | var fo = vc.root().getOperand(0).getOperand(0); |
| 2107 | expect(fo.key()).toEqual('Titel'); |
| 2108 | expect(fo.value()).toEqual('Baum'); |
| 2109 | |
| 2110 | // Add unspecified on the root group |
| 2111 | _orOn(fo); |
| 2112 | |
| 2113 | fo = vc.root().getOperand(0).getOperand(0); |
| 2114 | |
| 2115 | expect(fo.operation()).toEqual('or'); |
| 2116 | expect(fo.getOperand(0).ldType()).toEqual('doc'); |
| 2117 | expect(fo.getOperand(1).ldType()).toEqual('non'); |
| 2118 | |
| 2119 | // Delete unspecified doc |
| 2120 | _delOn(fo.getOperand(1)); |
| 2121 | |
| 2122 | // The operand is now non |
| 2123 | fo = vc.root().getOperand(0); |
| 2124 | expect(fo.getOperand(0).ldType()).toEqual('doc'); |
| 2125 | expect(fo.getOperand(0).key()).toEqual('Titel'); |
| 2126 | expect(fo.getOperand(0).value()).toEqual('Baum'); |
| 2127 | expect(fo.getOperand(1).ldType()).toEqual('doc'); |
| 2128 | expect(fo.getOperand(2).ldType()).toEqual('docGroup'); |
| 2129 | }); |
| 2130 | |
| 2131 | |
| 2132 | it('should add on parent group (case "and")', function () { |
| 2133 | var vc = complexVCFactory.create(); |
| 2134 | |
| 2135 | // Wrap with direct element access |
| 2136 | expect(vc.toQuery()).toEqual( |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 2137 | 'pubDate in 2014-12-05 & (title = "Hello World!" | foo = "bar")' |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 2138 | ); |
| 2139 | |
| 2140 | expect(vc.root().operands().length).toEqual(2); |
| 2141 | |
| 2142 | // Add unspecified on the root group |
| 2143 | _andOn(vc.root().getOperand(1)); |
| 2144 | expect(vc.toQuery()).toEqual( |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 2145 | 'pubDate in 2014-12-05 & (title = "Hello World!" | foo = "bar")' |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 2146 | ); |
| 2147 | |
| 2148 | expect(vc.root().ldType()).toEqual('docGroup'); |
| 2149 | expect(vc.root().operands().length).toEqual(3); |
| 2150 | expect(vc.root().getOperand(0).ldType()).toEqual('doc'); |
| 2151 | expect(vc.root().getOperand(1).ldType()).toEqual('docGroup'); |
| 2152 | expect(vc.root().getOperand(1).operation()).toEqual('or'); |
| 2153 | expect(vc.root().getOperand(2).ldType()).toEqual('non'); |
| 2154 | |
| 2155 | // Add another unspecified on the root group |
| 2156 | _andOn(vc.root().getOperand(1)); |
| 2157 | |
| 2158 | expect(vc.root().operands().length).toEqual(4); |
| 2159 | expect(vc.root().getOperand(0).ldType()).toEqual('doc'); |
| 2160 | expect(vc.root().getOperand(1).ldType()).toEqual('docGroup'); |
| 2161 | expect(vc.root().getOperand(2).ldType()).toEqual('non'); |
| 2162 | expect(vc.root().getOperand(3).ldType()).toEqual('non'); |
| 2163 | |
| 2164 | // Add another unspecified after the first doc |
| 2165 | _andOn(vc.root().getOperand(0)); |
| 2166 | |
| 2167 | expect(vc.root().operands().length).toEqual(5); |
| 2168 | expect(vc.root().getOperand(0).ldType()).toEqual('doc'); |
| 2169 | expect(vc.root().getOperand(1).ldType()).toEqual('non'); |
| 2170 | expect(vc.root().getOperand(2).ldType()).toEqual('docGroup'); |
| 2171 | expect(vc.root().getOperand(3).ldType()).toEqual('non'); |
| 2172 | expect(vc.root().getOperand(4).ldType()).toEqual('non'); |
| 2173 | }); |
| 2174 | |
| 2175 | it('should wrap on root', function () { |
Nils Diewald | 6283d69 | 2015-04-23 20:32:53 +0000 | [diff] [blame] | 2176 | var vc = vcClass.create().fromJson( |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 2177 | { |
| 2178 | "@type": 'koral:docGroup', |
| 2179 | 'operation' : 'operation:and', |
| 2180 | 'operands' : [ |
| 2181 | { |
| 2182 | "@type": 'koral:doc', |
| 2183 | "key": 'pubDate', |
| 2184 | "match": 'match:eq', |
| 2185 | "value": '2014-12-05', |
| 2186 | "type": 'type:date' |
| 2187 | }, |
| 2188 | { |
| 2189 | "@type" : 'koral:doc', |
| 2190 | 'key' : 'foo', |
| 2191 | 'value' : 'bar' |
| 2192 | } |
| 2193 | ] |
| 2194 | } |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 2195 | ); |
| 2196 | |
| 2197 | // Wrap on root |
| 2198 | expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar"'); |
| 2199 | expect(vc.root().ldType()).toEqual('docGroup'); |
| 2200 | expect(vc.root().operation()).toEqual('and'); |
| 2201 | _orOn(vc.root()); |
| 2202 | expect(vc.root().ldType()).toEqual('docGroup'); |
| 2203 | expect(vc.root().operation()).toEqual('or'); |
| 2204 | |
| 2205 | expect(vc.root().getOperand(0).ldType()).toEqual('docGroup'); |
| 2206 | expect(vc.root().getOperand(0).operation()).toEqual('and'); |
| 2207 | }); |
| 2208 | |
| 2209 | it('should add on root (case "and")', function () { |
Nils Diewald | 6283d69 | 2015-04-23 20:32:53 +0000 | [diff] [blame] | 2210 | var vc = vcClass.create().fromJson( |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 2211 | { |
| 2212 | "@type": 'koral:doc', |
| 2213 | "key": 'pubDate', |
| 2214 | "match": 'match:eq', |
| 2215 | "value": '2014-12-05', |
| 2216 | "type": 'type:date' |
| 2217 | } |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 2218 | ); |
| 2219 | |
| 2220 | expect(vc.toQuery()).toEqual('pubDate in 2014-12-05'); |
| 2221 | expect(vc.root().ldType()).toEqual('doc'); |
| 2222 | expect(vc.root().key()).toEqual('pubDate'); |
| 2223 | expect(vc.root().value()).toEqual('2014-12-05'); |
| 2224 | |
| 2225 | // Wrap on root |
| 2226 | _andOn(vc.root()); |
| 2227 | expect(vc.root().ldType()).toEqual('docGroup'); |
| 2228 | expect(vc.root().operation()).toEqual('and'); |
| 2229 | }); |
| 2230 | |
| 2231 | it('should add on root (case "or")', function () { |
Nils Diewald | 6283d69 | 2015-04-23 20:32:53 +0000 | [diff] [blame] | 2232 | var vc = vcClass.create().fromJson( |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 2233 | { |
| 2234 | "@type": 'koral:doc', |
| 2235 | "key": 'pubDate', |
| 2236 | "match": 'match:eq', |
| 2237 | "value": '2014-12-05', |
| 2238 | "type": 'type:date' |
| 2239 | } |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 2240 | ); |
| 2241 | |
| 2242 | expect(vc.toQuery()).toEqual('pubDate in 2014-12-05'); |
| 2243 | expect(vc.root().key()).toEqual('pubDate'); |
| 2244 | expect(vc.root().value()).toEqual('2014-12-05'); |
| 2245 | |
| 2246 | // Wrap on root |
| 2247 | _orOn(vc.root()); |
| 2248 | expect(vc.root().ldType()).toEqual('docGroup'); |
| 2249 | expect(vc.root().operation()).toEqual('or'); |
| 2250 | }); |
| 2251 | |
| 2252 | it('should support multiple sub groups per group', function () { |
Nils Diewald | 6283d69 | 2015-04-23 20:32:53 +0000 | [diff] [blame] | 2253 | var vc = vcClass.create().fromJson( |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 2254 | { |
| 2255 | "@type": 'koral:docGroup', |
| 2256 | 'operation' : 'operation:or', |
| 2257 | 'operands' : [ |
| 2258 | { |
| 2259 | "@type": 'koral:docGroup', |
| 2260 | 'operation' : 'operation:and', |
| 2261 | 'operands' : [ |
| 2262 | { |
| 2263 | "@type": 'koral:doc', |
| 2264 | "key": 'title', |
| 2265 | "value": 't1', |
| 2266 | }, |
| 2267 | { |
| 2268 | "@type" : 'koral:doc', |
| 2269 | 'key' : 'title', |
| 2270 | 'value' : 't2' |
| 2271 | } |
| 2272 | ] |
| 2273 | }, |
| 2274 | { |
| 2275 | "@type": 'koral:docGroup', |
| 2276 | 'operation' : 'operation:and', |
| 2277 | 'operands' : [ |
| 2278 | { |
| 2279 | "@type": 'koral:doc', |
| 2280 | "key": 'title', |
| 2281 | "value": 't3', |
| 2282 | }, |
| 2283 | { |
| 2284 | "@type" : 'koral:doc', |
| 2285 | 'key' : 'title', |
| 2286 | 'value' : 't4' |
| 2287 | } |
| 2288 | ] |
| 2289 | } |
| 2290 | ] |
| 2291 | } |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 2292 | ); |
| 2293 | expect(vc.toQuery()).toEqual( |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 2294 | '(title = "t1" & title = "t2") | ' + |
| 2295 | '(title = "t3" & title = "t4")' |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 2296 | ); |
| 2297 | expect(vc.root().operation()).toEqual('or'); |
| 2298 | expect(vc.root().getOperand(0).toQuery()).toEqual('title = "t1" & title = "t2"'); |
| 2299 | expect(vc.root().getOperand(1).toQuery()).toEqual('title = "t3" & title = "t4"'); |
| 2300 | |
| 2301 | _andOn(vc.root()); |
| 2302 | |
| 2303 | expect(vc.root().operation()).toEqual('and'); |
| 2304 | expect(vc.root().getOperand(0).ldType()).toEqual('docGroup'); |
| 2305 | expect(vc.root().getOperand(1).ldType()).toEqual('non'); |
| 2306 | }); |
| 2307 | }); |
| 2308 | |
Akron | 5c829e9 | 2017-05-12 18:10:00 +0200 | [diff] [blame] | 2309 | // Check class method |
| 2310 | describe('KorAP.VC.checkRewrite', function () { |
| 2311 | |
| 2312 | it('should check for simple rewrites', function () { |
| 2313 | expect(vcClass.checkRewrite( |
| 2314 | { |
| 2315 | "@type" : "koral:doc", |
| 2316 | "rewrites" : [{ |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 2317 | "@type" : "koral:rewrite", |
| 2318 | "operation" : "operation:modification", |
| 2319 | "src" : "querySerializer", |
| 2320 | "scope" : "tree" |
Akron | 5c829e9 | 2017-05-12 18:10:00 +0200 | [diff] [blame] | 2321 | }] |
| 2322 | } |
| 2323 | )).toBeTruthy(); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 2324 | |
Akron | 5c829e9 | 2017-05-12 18:10:00 +0200 | [diff] [blame] | 2325 | var nested = { |
| 2326 | "@type" : "koral:docGroup", |
| 2327 | "operands" : [ |
| 2328 | { |
| 2329 | "@type" : "koral:doc" |
| 2330 | }, |
| 2331 | { |
| 2332 | "@type" : "koral:docGroup", |
| 2333 | "operands" : [ |
| 2334 | { |
| 2335 | "@type": "koral:doc" |
| 2336 | }, |
| 2337 | { |
| 2338 | "@type": "koral:doc" |
| 2339 | } |
| 2340 | ] |
| 2341 | } |
| 2342 | ] |
| 2343 | }; |
| 2344 | |
| 2345 | expect(vcClass.checkRewrite(nested)).toBe(false); |
| 2346 | |
| 2347 | nested["operands"][1]["operands"][1]["rewrites"] = [{ |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 2348 | "@type" : "koral:rewrite", |
| 2349 | "operation" : "operation:modification", |
| 2350 | "src" : "querySerializer", |
| 2351 | "scope" : "tree" |
Akron | 5c829e9 | 2017-05-12 18:10:00 +0200 | [diff] [blame] | 2352 | }]; |
| 2353 | |
| 2354 | expect(vcClass.checkRewrite(nested)).toBeTruthy(); |
| 2355 | }); |
| 2356 | }); |
Nils Diewald | 6283d69 | 2015-04-23 20:32:53 +0000 | [diff] [blame] | 2357 | |
| 2358 | describe('KorAP.Rewrite', function () { |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 2359 | it('should be initializable', function () { |
| 2360 | var rewrite = rewriteClass.create({ |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 2361 | "@type" : "koral:rewrite", |
| 2362 | "operation" : "operation:modification", |
| 2363 | "src" : "querySerializer", |
| 2364 | "scope" : "tree" |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 2365 | }); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 2366 | expect(rewrite.toString()).toEqual('Modification of "tree" by "querySerializer"'); |
| 2367 | }); |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 2368 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 2369 | it('should be deserialized by docs', function () { |
| 2370 | var doc = docClass.create( |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 2371 | undefined, |
| 2372 | { |
| 2373 | "@type":"koral:doc", |
| 2374 | "key":"Titel", |
| 2375 | "value":"Baum", |
| 2376 | "match":"match:eq" |
| 2377 | }); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 2378 | |
| 2379 | expect(doc.element().classList.contains('doc')).toBeTruthy(); |
| 2380 | expect(doc.element().classList.contains('rewritten')).toBe(false); |
| 2381 | |
| 2382 | doc = docClass.create( |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 2383 | undefined, |
| 2384 | { |
| 2385 | "@type":"koral:doc", |
| 2386 | "key":"Titel", |
| 2387 | "value":"Baum", |
| 2388 | "match":"match:eq", |
| 2389 | "rewrites" : [ |
| 2390 | { |
| 2391 | "@type" : "koral:rewrite", |
| 2392 | "operation" : "operation:modification", |
| 2393 | "src" : "querySerializer", |
| 2394 | "scope" : "tree" |
| 2395 | } |
| 2396 | ] |
| 2397 | }); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 2398 | |
| 2399 | expect(doc.element().classList.contains('doc')).toBeTruthy(); |
| 2400 | expect(doc.element().classList.contains('rewritten')).toBeTruthy(); |
| 2401 | }); |
Nils Diewald | 6283d69 | 2015-04-23 20:32:53 +0000 | [diff] [blame] | 2402 | |
Akron | 76c3dd6 | 2018-05-29 20:58:27 +0200 | [diff] [blame] | 2403 | it('should be described in a title attribute', function () { |
| 2404 | |
| 2405 | doc = docClass.create( |
| 2406 | undefined, |
| 2407 | { |
| 2408 | "@type":"koral:doc", |
| 2409 | "key":"Titel", |
| 2410 | "value":"Baum", |
| 2411 | "match":"match:eq", |
| 2412 | "rewrites" : [ |
| 2413 | { |
| 2414 | "@type" : "koral:rewrite", |
| 2415 | "operation" : "operation:modification", |
| 2416 | "src" : "querySerializer", |
| 2417 | "scope" : "tree" |
| 2418 | }, |
| 2419 | { |
| 2420 | "@type" : "koral:rewrite", |
| 2421 | "operation" : "operation:injection", |
| 2422 | "src" : "me" |
| 2423 | } |
| 2424 | ] |
| 2425 | }); |
| 2426 | |
| 2427 | expect(doc.element().classList.contains('doc')).toBeTruthy(); |
| 2428 | expect(doc.element().classList.contains('rewritten')).toBeTruthy(); |
| 2429 | expect(doc.element().lastChild.getAttribute("title")).toEqual("querySerializer: tree (modification)\nme (injection)"); |
| 2430 | }); |
| 2431 | |
| 2432 | |
Nils Diewald | 6283d69 | 2015-04-23 20:32:53 +0000 | [diff] [blame] | 2433 | xit('should be deserialized by docGroups', function () { |
| 2434 | var docGroup = docGroupClass.create( |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 2435 | undefined, |
| 2436 | { |
| 2437 | "@type" : "koral:docGroup", |
| 2438 | "operation" : "operation:or", |
| 2439 | "operands" : [ |
| 2440 | { |
| 2441 | "@type" : "doc", |
| 2442 | "key" : "pubDate", |
| 2443 | "type" : "type:date", |
| 2444 | "value" : "2014-12-05" |
| 2445 | }, |
| 2446 | { |
| 2447 | "@type" : "doc", |
| 2448 | "key" : "pubDate", |
| 2449 | "type" : "type:date", |
| 2450 | "value" : "2014-12-06" |
| 2451 | } |
| 2452 | ], |
| 2453 | "rewrites" : [ |
| 2454 | { |
| 2455 | "@type" : "koral:rewrite", |
| 2456 | "operation" : "operation:modification", |
| 2457 | "src" : "querySerializer", |
| 2458 | "scope" : "tree" |
| 2459 | } |
| 2460 | ] |
| 2461 | } |
Nils Diewald | 6283d69 | 2015-04-23 20:32:53 +0000 | [diff] [blame] | 2462 | ); |
| 2463 | |
| 2464 | expect(doc.element().classList.contains('docgroup')).toBeTruthy(); |
| 2465 | expect(doc.element().classList.contains('rewritten')).toBe(false); |
| 2466 | }); |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 2467 | }); |
Nils Diewald | f0c4f11 | 2015-05-05 12:56:59 +0000 | [diff] [blame] | 2468 | |
| 2469 | describe('KorAP.stringValue', function () { |
| 2470 | it('should be initializable', function () { |
| 2471 | var sv = stringValClass.create(); |
| 2472 | expect(sv.regex()).toBe(false); |
| 2473 | expect(sv.value()).toBe(''); |
Nils Diewald | c4c4b83 | 2015-05-05 16:00:08 +0000 | [diff] [blame] | 2474 | |
| 2475 | sv = stringValClass.create('Baum'); |
| 2476 | expect(sv.regex()).toBe(false); |
| 2477 | expect(sv.value()).toBe('Baum'); |
| 2478 | |
| 2479 | sv = stringValClass.create('Baum', false); |
| 2480 | expect(sv.regex()).toBe(false); |
| 2481 | expect(sv.value()).toBe('Baum'); |
| 2482 | |
| 2483 | sv = stringValClass.create('Baum', true); |
| 2484 | expect(sv.regex()).toBe(true); |
| 2485 | expect(sv.value()).toBe('Baum'); |
| 2486 | }); |
| 2487 | |
| 2488 | it('should be modifiable', function () { |
| 2489 | var sv = stringValClass.create(); |
| 2490 | expect(sv.regex()).toBe(false); |
| 2491 | expect(sv.value()).toBe(''); |
| 2492 | |
| 2493 | expect(sv.value('Baum')).toBe('Baum'); |
| 2494 | expect(sv.value()).toBe('Baum'); |
| 2495 | |
| 2496 | expect(sv.regex(true)).toBe(true); |
| 2497 | expect(sv.regex()).toBe(true); |
| 2498 | }); |
| 2499 | |
| 2500 | it('should have a toggleble regex value', function () { |
| 2501 | var sv = stringValClass.create(); |
Nils Diewald | 7991a3f | 2015-05-19 14:12:37 +0000 | [diff] [blame] | 2502 | |
| 2503 | expect(sv.element().firstChild.value).toBe(''); |
| 2504 | sv.element().firstChild.value = 'der' |
| 2505 | expect(sv.element().firstChild.value).toBe('der'); |
| 2506 | |
Nils Diewald | c4c4b83 | 2015-05-05 16:00:08 +0000 | [diff] [blame] | 2507 | expect(sv.regex()).toBe(false); |
| 2508 | |
| 2509 | sv.toggleRegex(); |
Nils Diewald | 7991a3f | 2015-05-19 14:12:37 +0000 | [diff] [blame] | 2510 | expect(sv.element().firstChild.value).toBe('der'); |
Nils Diewald | c4c4b83 | 2015-05-05 16:00:08 +0000 | [diff] [blame] | 2511 | expect(sv.regex()).toBe(true); |
Nils Diewald | 7991a3f | 2015-05-19 14:12:37 +0000 | [diff] [blame] | 2512 | sv.element().firstChild.value = 'derbe' |
Nils Diewald | c4c4b83 | 2015-05-05 16:00:08 +0000 | [diff] [blame] | 2513 | |
| 2514 | sv.toggleRegex(); |
| 2515 | expect(sv.regex()).toBe(false); |
Nils Diewald | 7991a3f | 2015-05-19 14:12:37 +0000 | [diff] [blame] | 2516 | expect(sv.element().firstChild.value).toBe('derbe'); |
Nils Diewald | c4c4b83 | 2015-05-05 16:00:08 +0000 | [diff] [blame] | 2517 | }); |
| 2518 | |
| 2519 | it('should have an element', function () { |
| 2520 | var sv = stringValClass.create('der'); |
| 2521 | expect(sv.element().nodeName).toBe('DIV'); |
| 2522 | expect(sv.element().firstChild.nodeName).toBe('INPUT'); |
| 2523 | expect(sv.element().firstChild.value).toBe('der'); |
| 2524 | }); |
| 2525 | |
| 2526 | it('should have a classed element', function () { |
| 2527 | var sv = stringValClass.create(); |
Nils Diewald | c4c4b83 | 2015-05-05 16:00:08 +0000 | [diff] [blame] | 2528 | expect(sv.element().classList.contains('regex')).toBe(false); |
| 2529 | expect(sv.regex()).toBe(false); |
| 2530 | sv.toggleRegex(); |
| 2531 | expect(sv.element().classList.contains('regex')).toBe(true); |
| 2532 | }); |
| 2533 | |
| 2534 | it('should be storable', function () { |
| 2535 | var sv = stringValClass.create(); |
| 2536 | var count = 1; |
| 2537 | sv.store = function (value, regex) { |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 2538 | expect(regex).toBe(true); |
| 2539 | expect(value).toBe('tree'); |
Nils Diewald | c4c4b83 | 2015-05-05 16:00:08 +0000 | [diff] [blame] | 2540 | }; |
| 2541 | sv.regex(true); |
| 2542 | sv.value('tree'); |
| 2543 | sv.element().lastChild.click(); |
Nils Diewald | f0c4f11 | 2015-05-05 12:56:59 +0000 | [diff] [blame] | 2544 | }); |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 2545 | |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 2546 | it('should have a disableoption for regex', function () { |
| 2547 | var sv = stringValClass.create(undefined, undefined, true); |
| 2548 | var svE = sv.element(); |
| 2549 | expect(svE.children.length).toEqual(2); |
| 2550 | |
| 2551 | sv = stringValClass.create(undefined, undefined, false); |
| 2552 | svE = sv.element(); |
| 2553 | expect(svE.children.length).toEqual(1); |
| 2554 | }); |
| 2555 | |
Nils Diewald | f0c4f11 | 2015-05-05 12:56:59 +0000 | [diff] [blame] | 2556 | }); |
Akron | e4961b1 | 2017-05-10 21:04:46 +0200 | [diff] [blame] | 2557 | |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 2558 | describe('KorAP.VC.Menu', function () { |
Akron | e65a88a | 2018-04-05 19:14:20 +0200 | [diff] [blame] | 2559 | |
| 2560 | var vc; |
| 2561 | |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 2562 | it('should be initializable', function () { |
| 2563 | |
Akron | e65a88a | 2018-04-05 19:14:20 +0200 | [diff] [blame] | 2564 | vc = vcClass.create([ |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 2565 | ['a', 'text'], |
| 2566 | ['b', 'string'], |
| 2567 | ['c', 'date'] |
| 2568 | ]).fromJson(); |
| 2569 | expect(vc.element().firstChild.classList.contains('unspecified')).toBeTruthy(); |
| 2570 | expect(vc.element().firstChild.firstChild.tagName).toEqual('SPAN'); |
| 2571 | |
| 2572 | // Click on unspecified |
| 2573 | vc.element().firstChild.firstChild.click(); |
| 2574 | expect(vc.element().firstChild.firstChild.tagName).toEqual('UL'); |
| 2575 | |
| 2576 | var list = vc.element().firstChild.firstChild; |
Akron | 3ad4694 | 2018-08-22 16:47:14 +0200 | [diff] [blame^] | 2577 | expect(list.getElementsByTagName("LI")[0].innerText).toEqual('referTo'); |
| 2578 | expect(list.getElementsByTagName("LI")[1].innerText).toEqual('a'); |
| 2579 | expect(list.getElementsByTagName("LI")[2].innerText).toEqual('b'); |
| 2580 | expect(list.getElementsByTagName("LI")[3].innerText).toEqual('c'); |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 2581 | |
| 2582 | vc = vcClass.create([ |
| 2583 | ['d', 'text'], |
| 2584 | ['e', 'string'], |
| 2585 | ['f', 'date'] |
| 2586 | ]).fromJson(); |
| 2587 | expect(vc.element().firstChild.classList.contains('unspecified')).toBeTruthy(); |
| 2588 | expect(vc.element().firstChild.firstChild.tagName).toEqual('SPAN'); |
| 2589 | |
| 2590 | // Click on unspecified |
| 2591 | vc.element().firstChild.firstChild.click(); |
| 2592 | expect(vc.element().firstChild.firstChild.tagName).toEqual('UL'); |
| 2593 | |
| 2594 | list = vc.element().firstChild.firstChild; |
Akron | 3ad4694 | 2018-08-22 16:47:14 +0200 | [diff] [blame^] | 2595 | expect(list.getElementsByTagName("LI")[0].innerText).toEqual('referTo'); |
| 2596 | expect(list.getElementsByTagName("LI")[1].innerText).toEqual('d'); |
| 2597 | expect(list.getElementsByTagName("LI")[2].innerText).toEqual('e'); |
| 2598 | expect(list.getElementsByTagName("LI")[3].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" |
Akron | 3ad4694 | 2018-08-22 16:47:14 +0200 | [diff] [blame^] | 2614 | vc.element().firstChild.firstChild.getElementsByTagName("LI")[1].click(); |
Akron | e65a88a | 2018-04-05 19:14:20 +0200 | [diff] [blame] | 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" |
Akron | 3ad4694 | 2018-08-22 16:47:14 +0200 | [diff] [blame^] | 2628 | vc.element().firstChild.firstChild.getElementsByTagName("LI")[1].click(); |
Akron | 31d8994 | 2018-04-06 16:44:51 +0200 | [diff] [blame] | 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" |
Akron | 3ad4694 | 2018-08-22 16:47:14 +0200 | [diff] [blame^] | 2655 | vc.element().firstChild.firstChild.getElementsByTagName("LI")[2].click(); |
| 2656 | |
Akron | 31d8994 | 2018-04-06 16:44:51 +0200 | [diff] [blame] | 2657 | // As a consequence the matchoperator may no longer |
| 2658 | // be valid and needs to be re-evaluated |
| 2659 | var fc = vc.element().firstChild; |
Akron | 3ad4694 | 2018-08-22 16:47:14 +0200 | [diff] [blame^] | 2660 | |
Akron | 31d8994 | 2018-04-06 16:44:51 +0200 | [diff] [blame] | 2661 | expect(fc.firstChild.tagName).toEqual('SPAN'); |
| 2662 | expect(fc.firstChild.innerText).toEqual('e'); |
| 2663 | expect(fc.children[1].innerText).toEqual('eq'); |
| 2664 | expect(fc.children[1].getAttribute('data-type')).toEqual('string'); |
| 2665 | |
| 2666 | vc.element().firstChild.children[1].click(); |
| 2667 | |
| 2668 | expect(vc.element().firstChild.children[1].tagName).toEqual('UL'); |
| 2669 | |
| 2670 | var ul = vc.element().firstChild.children[1]; |
| 2671 | expect(ul.getElementsByTagName('li')[0].innerText).toEqual("eq"); |
| 2672 | expect(ul.getElementsByTagName('li')[1].innerText).toEqual("ne"); |
| 2673 | expect(ul.getElementsByTagName('li')[2]).toBeUndefined(); |
| 2674 | |
| 2675 | // Choose "ne" |
| 2676 | ul.getElementsByTagName('li')[1].click(); |
| 2677 | expect(vc.element().firstChild.children[1].tagName).toEqual("SPAN"); |
| 2678 | expect(vc.element().firstChild.children[1].innerText).toEqual("ne"); |
Akron | 8db5e3a | 2018-05-28 19:25:26 +0200 | [diff] [blame] | 2679 | |
| 2680 | // Click on text |
| 2681 | expect(vc.element().firstChild.children[2].innerText).toEqual("⋯"); |
| 2682 | vc.element().firstChild.children[2].click(); |
| 2683 | |
| 2684 | // Blur text element |
| 2685 | expect(vc.element().firstChild.children[2].firstChild.value).toEqual(''); |
| 2686 | |
Akron | 31d8994 | 2018-04-06 16:44:51 +0200 | [diff] [blame] | 2687 | // blur |
| 2688 | document.body.click(); |
| 2689 | }); |
| 2690 | |
| 2691 | it('should be clickable on operation for date', function () { |
| 2692 | |
| 2693 | // Replay matchop check - so it's guaranteed that "ne" is chosen |
| 2694 | // Click on "e" (or unspecified) |
| 2695 | vc.element().firstChild.firstChild.click(); |
| 2696 | // Rechoose "e" |
| 2697 | vc.element().firstChild.firstChild.getElementsByTagName("LI")[1].click(); |
| 2698 | // Click on matchop |
| 2699 | vc.element().firstChild.children[1].click(); |
| 2700 | // Choose "ne" |
| 2701 | vc.element().firstChild.children[1].getElementsByTagName('li')[1].click(); |
| 2702 | expect(vc.element().firstChild.children[1].innerText).toEqual("ne"); |
| 2703 | |
| 2704 | // Click on "e" |
| 2705 | vc.element().firstChild.firstChild.click(); |
| 2706 | // Choose "f" |
Akron | 3ad4694 | 2018-08-22 16:47:14 +0200 | [diff] [blame^] | 2707 | vc.element().firstChild.firstChild.getElementsByTagName("LI")[3].click(); |
Akron | 31d8994 | 2018-04-06 16:44:51 +0200 | [diff] [blame] | 2708 | |
| 2709 | // The matchoperator should still be "ne" as this is valid for dates as well (now) |
| 2710 | var fc = vc.element().firstChild; |
| 2711 | expect(fc.firstChild.tagName).toEqual('SPAN'); |
| 2712 | expect(fc.firstChild.innerText).toEqual('f'); |
| 2713 | expect(fc.children[1].innerText).toEqual('ne'); |
| 2714 | // blur |
| 2715 | document.body.click(); |
| 2716 | }); |
Akron | ddc98a7 | 2018-04-06 17:33:52 +0200 | [diff] [blame] | 2717 | |
| 2718 | |
| 2719 | // Check json deserialization |
| 2720 | it('should be initializable', function () { |
| 2721 | vc = vcClass.create([ |
| 2722 | ['a', 'text'], |
| 2723 | ['b', 'string'], |
| 2724 | ['c', 'date'] |
| 2725 | ]).fromJson({ |
| 2726 | "@type" : "koral:doc", |
| 2727 | "key":"a", |
| 2728 | "value":"Baum" |
| 2729 | }); |
| 2730 | |
| 2731 | expect(vc.element().firstChild.children[1].getAttribute('data-type')).toEqual('text'); |
| 2732 | }); |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 2733 | }); |
| 2734 | |
| 2735 | |
Akron | e4961b1 | 2017-05-10 21:04:46 +0200 | [diff] [blame] | 2736 | // Check prefix |
| 2737 | describe('KorAP.VC.Prefix', function () { |
| 2738 | |
| 2739 | it('should be initializable', function () { |
| 2740 | var p = prefixClass.create(); |
| 2741 | expect(p.element().classList.contains('pref')).toBeTruthy(); |
| 2742 | expect(p.isSet()).not.toBeTruthy(); |
| 2743 | }); |
| 2744 | |
| 2745 | |
| 2746 | it('should be clickable', function () { |
| 2747 | var vc = vcClass.create([ |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 2748 | ['a', null], |
| 2749 | ['b', null], |
| 2750 | ['c', null] |
| 2751 | ]).fromJson(); |
Akron | e4961b1 | 2017-05-10 21:04:46 +0200 | [diff] [blame] | 2752 | expect(vc.element().firstChild.classList.contains('unspecified')).toBeTruthy(); |
| 2753 | |
| 2754 | // This should open up the menu |
| 2755 | vc.element().firstChild.firstChild.click(); |
| 2756 | expect(vc.element().firstChild.firstChild.tagName).toEqual('UL'); |
| 2757 | |
| 2758 | KorAP._vcKeyMenu._prefix.clear(); |
| 2759 | KorAP._vcKeyMenu._prefix.add('x'); |
| 2760 | |
| 2761 | var prefElement = vc.element().querySelector('span.pref'); |
| 2762 | expect(prefElement.innerText).toEqual('x'); |
| 2763 | |
| 2764 | // This should add key 'x' to VC |
| 2765 | prefElement.click(); |
| 2766 | |
| 2767 | expect(vc.element().firstChild.classList.contains('doc')).toBeTruthy(); |
| 2768 | expect(vc.element().firstChild.firstChild.className).toEqual('key'); |
| 2769 | expect(vc.element().firstChild.firstChild.innerText).toEqual('x'); |
| 2770 | }); |
| 2771 | }); |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame] | 2772 | }); |