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 | |
Akron | 8a67016 | 2018-08-28 10:09:13 +0200 | [diff] [blame^] | 1573 | it('shouldn\'t be deserializable from collection with unknown type', function () { |
| 1574 | var kq = { |
| 1575 | "@type" : "koral:doc", |
| 1576 | "match": "match:eq", |
| 1577 | "type":"type:failure", |
| 1578 | "value": "Goethe", |
| 1579 | "key": "author" |
| 1580 | }; |
Akron | 1bdf527 | 2018-07-24 18:51:30 +0200 | [diff] [blame] | 1581 | |
Akron | 8a67016 | 2018-08-28 10:09:13 +0200 | [diff] [blame^] | 1582 | expect(function () { |
| 1583 | vcClass.create().fromJson(kq) |
| 1584 | }).toThrow(new Error("Unknown value type: string")); |
| 1585 | }); |
| 1586 | |
| 1587 | it('should return a name', function () { |
| 1588 | var vc = vcClass.create(); |
| 1589 | expect(vc.getName()).toEqual(KorAP.Locale.VC_allCorpora); |
| 1590 | |
| 1591 | vc = vcClass.create().fromJson({"@type" : "koral:docGroupRef", "ref" : "DeReKo"}); |
| 1592 | expect(vc.getName()).toEqual("DeReKo"); |
| 1593 | |
| 1594 | vc = vcClass.create().fromJson({"@type" : "koral:doc", "key" : "author", "value" : "Peter"}); |
| 1595 | expect(vc.getName()).toEqual(KorAP.Locale.VC_oneCollection); |
| 1596 | }); |
Akron | 1bdf527 | 2018-07-24 18:51:30 +0200 | [diff] [blame] | 1597 | }); |
| 1598 | |
| 1599 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1600 | describe('KorAP.Operators', function () { |
| 1601 | it('should be initializable', function () { |
| 1602 | var op = operatorsClass.create(true, false, false); |
| 1603 | expect(op.and()).toBeTruthy(); |
| 1604 | expect(op.or()).not.toBeTruthy(); |
| 1605 | expect(op.del()).not.toBeTruthy(); |
| 1606 | |
| 1607 | op.and(false); |
| 1608 | expect(op.and()).not.toBeTruthy(); |
| 1609 | expect(op.or()).not.toBeTruthy(); |
| 1610 | expect(op.del()).not.toBeTruthy(); |
| 1611 | |
| 1612 | op.or(true); |
| 1613 | op.del(true); |
| 1614 | expect(op.and()).not.toBeTruthy(); |
| 1615 | expect(op.or()).toBeTruthy(); |
| 1616 | expect(op.del()).toBeTruthy(); |
| 1617 | |
Akron | d141a36 | 2018-07-10 18:12:13 +0200 | [diff] [blame] | 1618 | var e = op.update(); |
Akron | 0b489ad | 2018-02-02 16:49:32 +0100 | [diff] [blame] | 1619 | expect(e.getAttribute('class')).toEqual('operators button-group'); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1620 | expect(e.children[0].getAttribute('class')).toEqual('or'); |
Akron | d141a36 | 2018-07-10 18:12:13 +0200 | [diff] [blame] | 1621 | expect(e.children[0].innerText).toEqual('or'); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1622 | expect(e.children[1].getAttribute('class')).toEqual('delete'); |
Akron | d141a36 | 2018-07-10 18:12:13 +0200 | [diff] [blame] | 1623 | expect(e.children[1].innerText).toEqual('×'); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1624 | |
| 1625 | op.and(true); |
| 1626 | op.del(false); |
Akron | d141a36 | 2018-07-10 18:12:13 +0200 | [diff] [blame] | 1627 | e = op.update(); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1628 | |
Akron | 0b489ad | 2018-02-02 16:49:32 +0100 | [diff] [blame] | 1629 | expect(e.getAttribute('class')).toEqual('operators button-group'); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1630 | expect(e.children[0].getAttribute('class')).toEqual('and'); |
Akron | d141a36 | 2018-07-10 18:12:13 +0200 | [diff] [blame] | 1631 | expect(e.children[0].innerText).toEqual('and'); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1632 | expect(e.children[1].getAttribute('class')).toEqual('or'); |
Akron | d141a36 | 2018-07-10 18:12:13 +0200 | [diff] [blame] | 1633 | expect(e.children[1].innerText).toEqual('or'); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1634 | }); |
| 1635 | }); |
| 1636 | |
| 1637 | describe('KorAP._delete (event)', function () { |
| 1638 | var complexVCFactory = buildFactory(vcClass,{ |
| 1639 | "@type": 'koral:docGroup', |
| 1640 | 'operation' : 'operation:and', |
| 1641 | 'operands' : [ |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 1642 | { |
| 1643 | "@type": 'koral:doc', |
| 1644 | "key": 'pubDate', |
| 1645 | "match": 'match:eq', |
| 1646 | "value": '2014-12-05', |
| 1647 | "type": 'type:date' |
| 1648 | }, |
| 1649 | { |
| 1650 | "@type" : 'koral:docGroup', |
| 1651 | 'operation' : 'operation:or', |
| 1652 | 'operands' : [ |
| 1653 | { |
| 1654 | '@type' : 'koral:doc', |
| 1655 | 'key' : 'title', |
| 1656 | 'value' : 'Hello World!' |
| 1657 | }, |
| 1658 | { |
| 1659 | '@type' : 'koral:doc', |
| 1660 | 'key' : 'foo', |
| 1661 | 'value' : 'bar' |
| 1662 | } |
| 1663 | ] |
| 1664 | } |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1665 | ] |
| 1666 | }); |
| 1667 | |
| 1668 | it('should clean on root docs', function () { |
Nils Diewald | 6283d69 | 2015-04-23 20:32:53 +0000 | [diff] [blame] | 1669 | var vc = vcClass.create().fromJson({ |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 1670 | "@type": 'koral:doc', |
| 1671 | "key": 'pubDate', |
| 1672 | "match": 'match:eq', |
| 1673 | "value": '2014-12-05', |
| 1674 | "type": 'type:date' |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 1675 | }); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1676 | expect(vc.root().toQuery()).toEqual('pubDate in 2014-12-05'); |
Akron | 0b489ad | 2018-02-02 16:49:32 +0100 | [diff] [blame] | 1677 | expect(vc.root().element().lastChild.getAttribute('class')).toEqual('operators button-group'); |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 1678 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1679 | // Clean with delete from root |
| 1680 | expect(vc.root().element().lastChild.lastChild.getAttribute('class')).toEqual('delete'); |
| 1681 | _delOn(vc.root()); |
| 1682 | expect(vc.root().toQuery()).toEqual(''); |
| 1683 | expect(vc.root().element().lastChild.lastChild.data).toEqual('⋯'); |
| 1684 | }); |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 1685 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1686 | it('should remove on nested docs', function () { |
Nils Diewald | 6283d69 | 2015-04-23 20:32:53 +0000 | [diff] [blame] | 1687 | var vc = vcClass.create().fromJson( |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 1688 | { |
| 1689 | "@type": 'koral:docGroup', |
| 1690 | 'operation' : 'operation:and', |
| 1691 | 'operands' : [ |
| 1692 | { |
| 1693 | "@type": 'koral:doc', |
| 1694 | "key": 'pubDate', |
| 1695 | "match": 'match:eq', |
| 1696 | "value": '2014-12-05', |
| 1697 | "type": 'type:date' |
| 1698 | }, |
| 1699 | { |
| 1700 | "@type" : 'koral:doc', |
| 1701 | 'key' : 'foo', |
| 1702 | 'value' : 'bar' |
| 1703 | } |
| 1704 | ] |
| 1705 | } |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1706 | ); |
| 1707 | |
| 1708 | // Delete with direct element access |
| 1709 | expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar"'); |
| 1710 | _delOn(vc.root().getOperand(0)); |
| 1711 | |
| 1712 | expect(vc.toQuery()).toEqual('foo = "bar"'); |
| 1713 | expect(vc.root().ldType()).toEqual('doc'); |
| 1714 | }); |
| 1715 | |
| 1716 | it('should clean on doc groups', function () { |
Nils Diewald | 6283d69 | 2015-04-23 20:32:53 +0000 | [diff] [blame] | 1717 | var vc = vcClass.create().fromJson( |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 1718 | { |
| 1719 | "@type": 'koral:docGroup', |
| 1720 | 'operation' : 'operation:and', |
| 1721 | 'operands' : [ |
| 1722 | { |
| 1723 | "@type": 'koral:doc', |
| 1724 | "key": 'pubDate', |
| 1725 | "match": 'match:eq', |
| 1726 | "value": '2014-12-05', |
| 1727 | "type": 'type:date' |
| 1728 | }, |
| 1729 | { |
| 1730 | "@type" : 'koral:doc', |
| 1731 | 'key' : 'foo', |
| 1732 | 'value' : 'bar' |
| 1733 | } |
| 1734 | ] |
| 1735 | } |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1736 | ); |
| 1737 | |
| 1738 | // Cleanwith direct element access |
| 1739 | expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar"'); |
| 1740 | _delOn(vc.root()); |
| 1741 | expect(vc.toQuery()).toEqual(''); |
| 1742 | expect(vc.root().ldType()).toEqual('non'); |
| 1743 | }); |
| 1744 | |
| 1745 | it('should remove on nested doc groups (case of ungrouping 1)', function () { |
| 1746 | var vc = complexVCFactory.create(); |
| 1747 | |
| 1748 | // Delete with direct element access |
| 1749 | expect(vc.toQuery()).toEqual( |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 1750 | 'pubDate in 2014-12-05 & (title = "Hello World!" | foo = "bar")' |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1751 | ); |
| 1752 | |
| 1753 | // Remove hello world: |
| 1754 | _delOn(vc.root().getOperand(1).getOperand(0)); |
| 1755 | expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar"'); |
| 1756 | expect(vc.root().ldType()).toEqual('docGroup'); |
| 1757 | }); |
| 1758 | |
| 1759 | it('should remove on nested doc groups (case of ungrouping 2)', function () { |
| 1760 | var vc = complexVCFactory.create(); |
| 1761 | |
| 1762 | // Delete with direct element access |
| 1763 | expect(vc.toQuery()).toEqual( |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 1764 | 'pubDate in 2014-12-05 & (title = "Hello World!" | foo = "bar")' |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1765 | ); |
| 1766 | |
| 1767 | // Remove bar |
| 1768 | _delOn(vc.root().getOperand(1).getOperand(1)); |
| 1769 | expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & title = "Hello World!"'); |
| 1770 | expect(vc.root().ldType()).toEqual('docGroup'); |
| 1771 | expect(vc.root().operation()).toEqual('and'); |
| 1772 | }); |
| 1773 | |
| 1774 | it('should remove on nested doc groups (case of root changing)', function () { |
| 1775 | var vc = complexVCFactory.create(); |
| 1776 | |
| 1777 | // Delete with direct element access |
| 1778 | expect(vc.toQuery()).toEqual( |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 1779 | 'pubDate in 2014-12-05 & ' + |
| 1780 | '(title = "Hello World!" | foo = "bar")' |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1781 | ); |
| 1782 | |
| 1783 | // Remove bar |
| 1784 | _delOn(vc.root().getOperand(0)); |
| 1785 | expect(vc.toQuery()).toEqual('title = "Hello World!" | foo = "bar"'); |
| 1786 | expect(vc.root().ldType()).toEqual('docGroup'); |
| 1787 | expect(vc.root().operation()).toEqual('or'); |
| 1788 | }); |
| 1789 | |
| 1790 | it('should remove on nested doc groups (list flattening)', function () { |
Nils Diewald | 6283d69 | 2015-04-23 20:32:53 +0000 | [diff] [blame] | 1791 | var vc = vcClass.create().fromJson( |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 1792 | { |
| 1793 | "@type": 'koral:docGroup', |
| 1794 | 'operation' : 'operation:or', |
| 1795 | 'operands' : [ |
| 1796 | { |
| 1797 | "@type": 'koral:doc', |
| 1798 | "key": 'pubDate', |
| 1799 | "match": 'match:eq', |
| 1800 | "value": '2014-12-05', |
| 1801 | "type": 'type:date' |
| 1802 | }, |
| 1803 | { |
| 1804 | "@type" : 'koral:doc', |
| 1805 | 'key' : 'foo', |
| 1806 | 'value' : 'bar' |
| 1807 | }, |
| 1808 | { |
| 1809 | "@type": 'koral:docGroup', |
| 1810 | 'operation' : 'operation:and', |
| 1811 | 'operands' : [ |
| 1812 | { |
| 1813 | "@type": 'koral:doc', |
| 1814 | "key": 'pubDate', |
| 1815 | "match": 'match:eq', |
| 1816 | "value": '2014-12-05', |
| 1817 | "type": 'type:date' |
| 1818 | }, |
| 1819 | { |
| 1820 | "@type" : 'koral:docGroup', |
| 1821 | 'operation' : 'operation:or', |
| 1822 | 'operands' : [ |
| 1823 | { |
| 1824 | '@type' : 'koral:doc', |
| 1825 | 'key' : 'title', |
| 1826 | 'value' : 'Hello World!' |
| 1827 | }, |
| 1828 | { |
| 1829 | '@type' : 'koral:doc', |
| 1830 | 'key' : 'yeah', |
| 1831 | 'value' : 'juhu' |
| 1832 | } |
| 1833 | ] |
| 1834 | } |
| 1835 | ] |
| 1836 | } |
| 1837 | ] |
| 1838 | } |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1839 | ); |
| 1840 | |
| 1841 | // Delete with direct element access |
| 1842 | expect(vc.toQuery()).toEqual( |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 1843 | 'pubDate in 2014-12-05 | foo = "bar" | ' + |
| 1844 | '(pubDate in 2014-12-05 & ' + |
| 1845 | '(title = "Hello World!" | yeah = "juhu"))' |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1846 | ); |
| 1847 | |
| 1848 | expect(vc.root().ldType()).toEqual('docGroup'); |
| 1849 | expect(vc.root().operation()).toEqual('or'); |
| 1850 | |
| 1851 | // Operands and operators |
| 1852 | expect(vc.element().firstChild.children.length).toEqual(4); |
Akron | 0b489ad | 2018-02-02 16:49:32 +0100 | [diff] [blame] | 1853 | expect(vc.element().firstChild.lastChild.getAttribute('class')).toEqual('operators button-group'); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1854 | |
| 1855 | // Remove inner group and flatten |
| 1856 | _delOn(vc.root().getOperand(2).getOperand(0)); |
| 1857 | |
| 1858 | expect(vc.toQuery()).toEqual( |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 1859 | 'pubDate in 2014-12-05 | foo = "bar" | title = "Hello World!" | yeah = "juhu"' |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1860 | ); |
| 1861 | expect(vc.root().ldType()).toEqual('docGroup'); |
| 1862 | expect(vc.root().operation()).toEqual('or'); |
| 1863 | |
| 1864 | // Operands and operators |
| 1865 | expect(vc.element().firstChild.children.length).toEqual(5); |
Akron | 0b489ad | 2018-02-02 16:49:32 +0100 | [diff] [blame] | 1866 | expect(vc.element().firstChild.lastChild.getAttribute('class')).toEqual('operators button-group'); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1867 | }); |
| 1868 | }); |
| 1869 | |
| 1870 | describe('KorAP._add (event)', function () { |
| 1871 | var complexVCFactory = buildFactory(vcClass,{ |
| 1872 | "@type": 'koral:docGroup', |
| 1873 | 'operation' : 'operation:and', |
| 1874 | 'operands' : [ |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 1875 | { |
| 1876 | "@type": 'koral:doc', |
| 1877 | "key": 'pubDate', |
| 1878 | "match": 'match:eq', |
| 1879 | "value": '2014-12-05', |
| 1880 | "type": 'type:date' |
| 1881 | }, |
| 1882 | { |
| 1883 | "@type" : 'koral:docGroup', |
| 1884 | 'operation' : 'operation:or', |
| 1885 | 'operands' : [ |
| 1886 | { |
| 1887 | '@type' : 'koral:doc', |
| 1888 | 'key' : 'title', |
| 1889 | 'value' : 'Hello World!' |
| 1890 | }, |
| 1891 | { |
| 1892 | '@type' : 'koral:doc', |
| 1893 | 'key' : 'foo', |
| 1894 | 'value' : 'bar' |
| 1895 | } |
| 1896 | ] |
| 1897 | } |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1898 | ] |
| 1899 | }); |
| 1900 | |
| 1901 | it('should add new unspecified doc with "and"', function () { |
Nils Diewald | 6283d69 | 2015-04-23 20:32:53 +0000 | [diff] [blame] | 1902 | var vc = vcClass.create().fromJson( |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 1903 | { |
| 1904 | "@type": 'koral:docGroup', |
| 1905 | 'operation' : 'operation:and', |
| 1906 | 'operands' : [ |
| 1907 | { |
| 1908 | "@type": 'koral:doc', |
| 1909 | "key": 'pubDate', |
| 1910 | "match": 'match:eq', |
| 1911 | "value": '2014-12-05', |
| 1912 | "type": 'type:date' |
| 1913 | }, |
| 1914 | { |
| 1915 | "@type" : 'koral:doc', |
| 1916 | 'key' : 'foo', |
| 1917 | 'value' : 'bar' |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 1918 | }, |
| 1919 | { |
| 1920 | "@type" : "koral:docGroupRef", |
| 1921 | "ref" : "myCorpus" |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 1922 | } |
| 1923 | ] |
| 1924 | } |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1925 | ); |
| 1926 | |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 1927 | 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] | 1928 | |
| 1929 | var fc = vc.element().firstChild; |
| 1930 | expect(fc.getAttribute('data-operation')).toEqual('and'); |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 1931 | expect(fc.children.length).toEqual(4); |
Akron | 0b489ad | 2018-02-02 16:49:32 +0100 | [diff] [blame] | 1932 | expect(fc.lastChild.getAttribute('class')).toEqual('operators button-group'); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1933 | expect(fc.children[0].getAttribute('class')).toEqual('doc'); |
| 1934 | expect(fc.children[1].getAttribute('class')).toEqual('doc'); |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 1935 | expect(fc.children[2].getAttribute('class')).toEqual('doc groupref'); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1936 | |
| 1937 | // add with 'and' in the middle |
| 1938 | _andOn(vc.root().getOperand(0)); |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 1939 | 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] | 1940 | |
| 1941 | fc = vc.element().firstChild; |
| 1942 | expect(fc.getAttribute('data-operation')).toEqual('and'); |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 1943 | expect(fc.children.length).toEqual(5); |
Akron | 0b489ad | 2018-02-02 16:49:32 +0100 | [diff] [blame] | 1944 | expect(fc.lastChild.getAttribute('class')).toEqual('operators button-group'); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1945 | |
| 1946 | expect(fc.children[0].getAttribute('class')).toEqual('doc'); |
| 1947 | expect(fc.children[1].getAttribute('class')).toEqual('doc unspecified'); |
| 1948 | expect(fc.children[2].getAttribute('class')).toEqual('doc'); |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 1949 | expect(fc.children[3].getAttribute('class')).toEqual('doc groupref'); |
| 1950 | expect(fc.children[4].classList.contains('button-group')).toBeTruthy(); |
| 1951 | expect(fc.children.length).toEqual(5); |
| 1952 | |
| 1953 | _andOn(vc.root().getOperand(3)); |
| 1954 | expect(fc.children[0].getAttribute('class')).toEqual('doc'); |
| 1955 | expect(fc.children[1].getAttribute('class')).toEqual('doc unspecified'); |
| 1956 | expect(fc.children[2].getAttribute('class')).toEqual('doc'); |
| 1957 | expect(fc.children[3].getAttribute('class')).toEqual('doc groupref'); |
| 1958 | expect(fc.children[4].getAttribute('class')).toEqual('doc unspecified'); |
| 1959 | expect(fc.children[5].classList.contains('button-group')).toBeTruthy(); |
| 1960 | expect(fc.children.length).toEqual(6); |
| 1961 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1962 | }); |
| 1963 | |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 1964 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1965 | it('should add new unspecified doc with "or"', function () { |
Nils Diewald | 6283d69 | 2015-04-23 20:32:53 +0000 | [diff] [blame] | 1966 | var vc = vcClass.create().fromJson( |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 1967 | { |
| 1968 | "@type": 'koral:docGroup', |
| 1969 | 'operation' : 'operation:and', |
| 1970 | 'operands' : [ |
| 1971 | { |
| 1972 | "@type": 'koral:doc', |
| 1973 | "key": 'pubDate', |
| 1974 | "match": 'match:eq', |
| 1975 | "value": '2014-12-05', |
| 1976 | "type": 'type:date' |
| 1977 | }, |
| 1978 | { |
| 1979 | "@type" : 'koral:doc', |
| 1980 | 'key' : 'foo', |
| 1981 | 'value' : 'bar' |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 1982 | }, |
| 1983 | { |
| 1984 | "@type" : "koral:docGroupRef", |
| 1985 | "ref" : "myCorpus" |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 1986 | } |
| 1987 | ] |
| 1988 | } |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1989 | ); |
| 1990 | |
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 | |
| 1993 | var fc = vc.element().firstChild; |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 1994 | expect(fc.children.length).toEqual(4); |
Akron | 0b489ad | 2018-02-02 16:49:32 +0100 | [diff] [blame] | 1995 | expect(fc.lastChild.getAttribute('class')).toEqual('operators button-group'); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1996 | expect(fc.children[0].getAttribute('class')).toEqual('doc'); |
| 1997 | expect(fc.children[1].getAttribute('class')).toEqual('doc'); |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 1998 | expect(fc.children[2].getAttribute('class')).toEqual('doc groupref'); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1999 | |
| 2000 | // add with 'or' in the middle |
| 2001 | _orOn(vc.root().getOperand(0)); |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 2002 | 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] | 2003 | fc = vc.element().firstChild; |
| 2004 | |
| 2005 | expect(fc.getAttribute('data-operation')).toEqual('and'); |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 2006 | expect(fc.children.length).toEqual(4); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 2007 | expect(fc.children[0].getAttribute('class')).toEqual('docGroup'); |
| 2008 | expect(fc.children[0].getAttribute('data-operation')).toEqual('or'); |
| 2009 | expect(fc.children[1].getAttribute('class')).toEqual('doc'); |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 2010 | expect(fc.children[2].getAttribute('class')).toEqual('doc groupref'); |
| 2011 | expect(fc.children[3].getAttribute('class')).toEqual('operators button-group'); |
Akron | 0b489ad | 2018-02-02 16:49:32 +0100 | [diff] [blame] | 2012 | expect(fc.lastChild.getAttribute('class')).toEqual('operators button-group'); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 2013 | |
| 2014 | fc = vc.element().firstChild.firstChild; |
| 2015 | expect(fc.children.length).toEqual(3); |
| 2016 | expect(fc.children[0].getAttribute('class')).toEqual('doc'); |
| 2017 | expect(fc.children[1].getAttribute('class')).toEqual('doc unspecified'); |
Akron | 0b489ad | 2018-02-02 16:49:32 +0100 | [diff] [blame] | 2018 | expect(fc.children[2].getAttribute('class')).toEqual('operators button-group'); |
| 2019 | expect(fc.lastChild.getAttribute('class')).toEqual('operators button-group'); |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 2020 | |
| 2021 | _orOn(vc.root().getOperand(2)); |
| 2022 | fc = vc.element().firstChild; |
| 2023 | expect(fc.children.length).toEqual(4); |
| 2024 | |
| 2025 | expect(fc.children[0].getAttribute('class')).toEqual('docGroup'); |
| 2026 | expect(fc.children[1].getAttribute('class')).toEqual('doc'); |
| 2027 | expect(fc.children[2].getAttribute('class')).toEqual('docGroup'); |
| 2028 | expect(fc.children[3].getAttribute('class')).toEqual('operators button-group'); |
| 2029 | |
| 2030 | fc = vc.element().firstChild.children[2]; |
| 2031 | expect(fc.children[0].getAttribute('class')).toEqual('doc groupref'); |
| 2032 | expect(fc.children[1].getAttribute('class')).toEqual('doc unspecified'); |
| 2033 | expect(fc.children[2].getAttribute('class')).toEqual('operators button-group'); |
| 2034 | expect(fc.lastChild.getAttribute('class')).toEqual('operators button-group'); |
| 2035 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 2036 | }); |
| 2037 | |
| 2038 | it('should add new unspecified doc with "and" before group', function () { |
| 2039 | var vc = demoFactory.create(); |
| 2040 | |
| 2041 | // Wrap with direct element access |
| 2042 | expect(vc.toQuery()).toEqual( |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 2043 | '(Titel = "Baum" & ' + |
| 2044 | 'Veröffentlichungsort = "hihi" & ' + |
| 2045 | '(Titel = "Baum" | ' + |
| 2046 | 'Veröffentlichungsort = "hihi")) | ' + |
| 2047 | 'Untertitel ~ "huhu"' |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 2048 | ); |
| 2049 | |
| 2050 | expect(vc.root().getOperand(0).ldType()).toEqual('docGroup'); |
| 2051 | expect(vc.root().getOperand(0).operation()).toEqual('and'); |
| 2052 | expect(vc.root().getOperand(0).operands().length).toEqual(3); |
| 2053 | |
| 2054 | // Add unspecified on the second doc |
| 2055 | var secDoc = vc.root().getOperand(0).getOperand(1); |
| 2056 | expect(secDoc.value()).toEqual('hihi'); |
| 2057 | |
| 2058 | // Add |
| 2059 | _andOn(secDoc); |
| 2060 | |
| 2061 | var fo = vc.root().getOperand(0); |
| 2062 | |
| 2063 | expect(fo.ldType()).toEqual('docGroup'); |
| 2064 | expect(fo.operation()).toEqual('and'); |
| 2065 | expect(fo.operands().length).toEqual(4); |
| 2066 | |
| 2067 | expect(fo.getOperand(0).ldType()).toEqual('doc'); |
| 2068 | expect(fo.getOperand(1).ldType()).toEqual('doc'); |
| 2069 | expect(fo.getOperand(2).ldType()).toEqual('non'); |
| 2070 | expect(fo.getOperand(3).ldType()).toEqual('docGroup'); |
| 2071 | }); |
| 2072 | |
| 2073 | |
| 2074 | it('should remove a doc with an unspecified doc in a nested group', function () { |
| 2075 | var vc = demoFactory.create(); |
| 2076 | |
| 2077 | // Wrap with direct element access |
| 2078 | expect(vc.toQuery()).toEqual( |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 2079 | '(Titel = "Baum" & Veröffentlichungsort = "hihi" & (Titel = "Baum" | Veröffentlichungsort = "hihi")) | Untertitel ~ "huhu"' |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 2080 | ); |
| 2081 | |
| 2082 | var fo = vc.root().getOperand(0).getOperand(0); |
| 2083 | expect(fo.key()).toEqual('Titel'); |
| 2084 | expect(fo.value()).toEqual('Baum'); |
| 2085 | |
| 2086 | // Add unspecified on the root group |
| 2087 | _orOn(fo); |
| 2088 | |
| 2089 | fo = vc.root().getOperand(0).getOperand(0); |
| 2090 | |
| 2091 | expect(fo.operation()).toEqual('or'); |
| 2092 | expect(fo.getOperand(0).ldType()).toEqual('doc'); |
| 2093 | expect(fo.getOperand(1).ldType()).toEqual('non'); |
| 2094 | |
| 2095 | // Delete document |
| 2096 | _delOn(fo.getOperand(0)); |
| 2097 | |
| 2098 | // The operand is now non |
| 2099 | expect(vc.root().getOperand(0).getOperand(0).ldType()).toEqual('non'); |
| 2100 | expect(vc.root().getOperand(0).getOperand(1).ldType()).toEqual('doc'); |
| 2101 | expect(vc.root().getOperand(0).getOperand(2).ldType()).toEqual('docGroup'); |
| 2102 | }); |
| 2103 | |
| 2104 | |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 2105 | 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] | 2106 | var vc = demoFactory.create(); |
| 2107 | |
| 2108 | // Wrap with direct element access |
| 2109 | expect(vc.toQuery()).toEqual( |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 2110 | '(Titel = "Baum" & ' + |
| 2111 | 'Veröffentlichungsort = "hihi" & ' + |
| 2112 | '(Titel = "Baum" ' + |
| 2113 | '| Veröffentlichungsort = "hihi")) | ' + |
| 2114 | 'Untertitel ~ "huhu"' |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 2115 | ); |
| 2116 | |
| 2117 | var fo = vc.root().getOperand(0).getOperand(0); |
| 2118 | expect(fo.key()).toEqual('Titel'); |
| 2119 | expect(fo.value()).toEqual('Baum'); |
| 2120 | |
| 2121 | // Add unspecified on the root group |
| 2122 | _orOn(fo); |
| 2123 | |
| 2124 | fo = vc.root().getOperand(0).getOperand(0); |
| 2125 | |
| 2126 | expect(fo.operation()).toEqual('or'); |
| 2127 | expect(fo.getOperand(0).ldType()).toEqual('doc'); |
| 2128 | expect(fo.getOperand(1).ldType()).toEqual('non'); |
| 2129 | |
| 2130 | // Delete unspecified doc |
| 2131 | _delOn(fo.getOperand(1)); |
| 2132 | |
| 2133 | // The operand is now non |
| 2134 | fo = vc.root().getOperand(0); |
| 2135 | expect(fo.getOperand(0).ldType()).toEqual('doc'); |
| 2136 | expect(fo.getOperand(0).key()).toEqual('Titel'); |
| 2137 | expect(fo.getOperand(0).value()).toEqual('Baum'); |
| 2138 | expect(fo.getOperand(1).ldType()).toEqual('doc'); |
| 2139 | expect(fo.getOperand(2).ldType()).toEqual('docGroup'); |
| 2140 | }); |
| 2141 | |
| 2142 | |
| 2143 | it('should add on parent group (case "and")', function () { |
| 2144 | var vc = complexVCFactory.create(); |
| 2145 | |
| 2146 | // Wrap with direct element access |
| 2147 | expect(vc.toQuery()).toEqual( |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 2148 | 'pubDate in 2014-12-05 & (title = "Hello World!" | foo = "bar")' |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 2149 | ); |
| 2150 | |
| 2151 | expect(vc.root().operands().length).toEqual(2); |
| 2152 | |
| 2153 | // Add unspecified on the root group |
| 2154 | _andOn(vc.root().getOperand(1)); |
| 2155 | expect(vc.toQuery()).toEqual( |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 2156 | 'pubDate in 2014-12-05 & (title = "Hello World!" | foo = "bar")' |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 2157 | ); |
| 2158 | |
| 2159 | expect(vc.root().ldType()).toEqual('docGroup'); |
| 2160 | expect(vc.root().operands().length).toEqual(3); |
| 2161 | expect(vc.root().getOperand(0).ldType()).toEqual('doc'); |
| 2162 | expect(vc.root().getOperand(1).ldType()).toEqual('docGroup'); |
| 2163 | expect(vc.root().getOperand(1).operation()).toEqual('or'); |
| 2164 | expect(vc.root().getOperand(2).ldType()).toEqual('non'); |
| 2165 | |
| 2166 | // Add another unspecified on the root group |
| 2167 | _andOn(vc.root().getOperand(1)); |
| 2168 | |
| 2169 | expect(vc.root().operands().length).toEqual(4); |
| 2170 | expect(vc.root().getOperand(0).ldType()).toEqual('doc'); |
| 2171 | expect(vc.root().getOperand(1).ldType()).toEqual('docGroup'); |
| 2172 | expect(vc.root().getOperand(2).ldType()).toEqual('non'); |
| 2173 | expect(vc.root().getOperand(3).ldType()).toEqual('non'); |
| 2174 | |
| 2175 | // Add another unspecified after the first doc |
| 2176 | _andOn(vc.root().getOperand(0)); |
| 2177 | |
| 2178 | expect(vc.root().operands().length).toEqual(5); |
| 2179 | expect(vc.root().getOperand(0).ldType()).toEqual('doc'); |
| 2180 | expect(vc.root().getOperand(1).ldType()).toEqual('non'); |
| 2181 | expect(vc.root().getOperand(2).ldType()).toEqual('docGroup'); |
| 2182 | expect(vc.root().getOperand(3).ldType()).toEqual('non'); |
| 2183 | expect(vc.root().getOperand(4).ldType()).toEqual('non'); |
| 2184 | }); |
| 2185 | |
| 2186 | it('should wrap on root', function () { |
Nils Diewald | 6283d69 | 2015-04-23 20:32:53 +0000 | [diff] [blame] | 2187 | var vc = vcClass.create().fromJson( |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 2188 | { |
| 2189 | "@type": 'koral:docGroup', |
| 2190 | 'operation' : 'operation:and', |
| 2191 | 'operands' : [ |
| 2192 | { |
| 2193 | "@type": 'koral:doc', |
| 2194 | "key": 'pubDate', |
| 2195 | "match": 'match:eq', |
| 2196 | "value": '2014-12-05', |
| 2197 | "type": 'type:date' |
| 2198 | }, |
| 2199 | { |
| 2200 | "@type" : 'koral:doc', |
| 2201 | 'key' : 'foo', |
| 2202 | 'value' : 'bar' |
| 2203 | } |
| 2204 | ] |
| 2205 | } |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 2206 | ); |
| 2207 | |
| 2208 | // Wrap on root |
| 2209 | expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar"'); |
| 2210 | expect(vc.root().ldType()).toEqual('docGroup'); |
| 2211 | expect(vc.root().operation()).toEqual('and'); |
| 2212 | _orOn(vc.root()); |
| 2213 | expect(vc.root().ldType()).toEqual('docGroup'); |
| 2214 | expect(vc.root().operation()).toEqual('or'); |
| 2215 | |
| 2216 | expect(vc.root().getOperand(0).ldType()).toEqual('docGroup'); |
| 2217 | expect(vc.root().getOperand(0).operation()).toEqual('and'); |
| 2218 | }); |
| 2219 | |
| 2220 | it('should add on root (case "and")', function () { |
Nils Diewald | 6283d69 | 2015-04-23 20:32:53 +0000 | [diff] [blame] | 2221 | var vc = vcClass.create().fromJson( |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 2222 | { |
| 2223 | "@type": 'koral:doc', |
| 2224 | "key": 'pubDate', |
| 2225 | "match": 'match:eq', |
| 2226 | "value": '2014-12-05', |
| 2227 | "type": 'type:date' |
| 2228 | } |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 2229 | ); |
| 2230 | |
| 2231 | expect(vc.toQuery()).toEqual('pubDate in 2014-12-05'); |
| 2232 | expect(vc.root().ldType()).toEqual('doc'); |
| 2233 | expect(vc.root().key()).toEqual('pubDate'); |
| 2234 | expect(vc.root().value()).toEqual('2014-12-05'); |
| 2235 | |
| 2236 | // Wrap on root |
| 2237 | _andOn(vc.root()); |
| 2238 | expect(vc.root().ldType()).toEqual('docGroup'); |
| 2239 | expect(vc.root().operation()).toEqual('and'); |
| 2240 | }); |
| 2241 | |
| 2242 | it('should add on root (case "or")', function () { |
Nils Diewald | 6283d69 | 2015-04-23 20:32:53 +0000 | [diff] [blame] | 2243 | var vc = vcClass.create().fromJson( |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 2244 | { |
| 2245 | "@type": 'koral:doc', |
| 2246 | "key": 'pubDate', |
| 2247 | "match": 'match:eq', |
| 2248 | "value": '2014-12-05', |
| 2249 | "type": 'type:date' |
| 2250 | } |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 2251 | ); |
| 2252 | |
| 2253 | expect(vc.toQuery()).toEqual('pubDate in 2014-12-05'); |
| 2254 | expect(vc.root().key()).toEqual('pubDate'); |
| 2255 | expect(vc.root().value()).toEqual('2014-12-05'); |
| 2256 | |
| 2257 | // Wrap on root |
| 2258 | _orOn(vc.root()); |
| 2259 | expect(vc.root().ldType()).toEqual('docGroup'); |
| 2260 | expect(vc.root().operation()).toEqual('or'); |
| 2261 | }); |
| 2262 | |
| 2263 | it('should support multiple sub groups per group', function () { |
Nils Diewald | 6283d69 | 2015-04-23 20:32:53 +0000 | [diff] [blame] | 2264 | var vc = vcClass.create().fromJson( |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 2265 | { |
| 2266 | "@type": 'koral:docGroup', |
| 2267 | 'operation' : 'operation:or', |
| 2268 | 'operands' : [ |
| 2269 | { |
| 2270 | "@type": 'koral:docGroup', |
| 2271 | 'operation' : 'operation:and', |
| 2272 | 'operands' : [ |
| 2273 | { |
| 2274 | "@type": 'koral:doc', |
| 2275 | "key": 'title', |
| 2276 | "value": 't1', |
| 2277 | }, |
| 2278 | { |
| 2279 | "@type" : 'koral:doc', |
| 2280 | 'key' : 'title', |
| 2281 | 'value' : 't2' |
| 2282 | } |
| 2283 | ] |
| 2284 | }, |
| 2285 | { |
| 2286 | "@type": 'koral:docGroup', |
| 2287 | 'operation' : 'operation:and', |
| 2288 | 'operands' : [ |
| 2289 | { |
| 2290 | "@type": 'koral:doc', |
| 2291 | "key": 'title', |
| 2292 | "value": 't3', |
| 2293 | }, |
| 2294 | { |
| 2295 | "@type" : 'koral:doc', |
| 2296 | 'key' : 'title', |
| 2297 | 'value' : 't4' |
| 2298 | } |
| 2299 | ] |
| 2300 | } |
| 2301 | ] |
| 2302 | } |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 2303 | ); |
| 2304 | expect(vc.toQuery()).toEqual( |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 2305 | '(title = "t1" & title = "t2") | ' + |
| 2306 | '(title = "t3" & title = "t4")' |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 2307 | ); |
| 2308 | expect(vc.root().operation()).toEqual('or'); |
| 2309 | expect(vc.root().getOperand(0).toQuery()).toEqual('title = "t1" & title = "t2"'); |
| 2310 | expect(vc.root().getOperand(1).toQuery()).toEqual('title = "t3" & title = "t4"'); |
| 2311 | |
| 2312 | _andOn(vc.root()); |
| 2313 | |
| 2314 | expect(vc.root().operation()).toEqual('and'); |
| 2315 | expect(vc.root().getOperand(0).ldType()).toEqual('docGroup'); |
| 2316 | expect(vc.root().getOperand(1).ldType()).toEqual('non'); |
| 2317 | }); |
| 2318 | }); |
| 2319 | |
Akron | 5c829e9 | 2017-05-12 18:10:00 +0200 | [diff] [blame] | 2320 | // Check class method |
| 2321 | describe('KorAP.VC.checkRewrite', function () { |
| 2322 | |
| 2323 | it('should check for simple rewrites', function () { |
| 2324 | expect(vcClass.checkRewrite( |
| 2325 | { |
| 2326 | "@type" : "koral:doc", |
| 2327 | "rewrites" : [{ |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 2328 | "@type" : "koral:rewrite", |
| 2329 | "operation" : "operation:modification", |
| 2330 | "src" : "querySerializer", |
| 2331 | "scope" : "tree" |
Akron | 5c829e9 | 2017-05-12 18:10:00 +0200 | [diff] [blame] | 2332 | }] |
| 2333 | } |
| 2334 | )).toBeTruthy(); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 2335 | |
Akron | 5c829e9 | 2017-05-12 18:10:00 +0200 | [diff] [blame] | 2336 | var nested = { |
| 2337 | "@type" : "koral:docGroup", |
| 2338 | "operands" : [ |
| 2339 | { |
| 2340 | "@type" : "koral:doc" |
| 2341 | }, |
| 2342 | { |
| 2343 | "@type" : "koral:docGroup", |
| 2344 | "operands" : [ |
| 2345 | { |
| 2346 | "@type": "koral:doc" |
| 2347 | }, |
| 2348 | { |
| 2349 | "@type": "koral:doc" |
| 2350 | } |
| 2351 | ] |
| 2352 | } |
| 2353 | ] |
| 2354 | }; |
| 2355 | |
| 2356 | expect(vcClass.checkRewrite(nested)).toBe(false); |
| 2357 | |
| 2358 | nested["operands"][1]["operands"][1]["rewrites"] = [{ |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 2359 | "@type" : "koral:rewrite", |
| 2360 | "operation" : "operation:modification", |
| 2361 | "src" : "querySerializer", |
| 2362 | "scope" : "tree" |
Akron | 5c829e9 | 2017-05-12 18:10:00 +0200 | [diff] [blame] | 2363 | }]; |
| 2364 | |
| 2365 | expect(vcClass.checkRewrite(nested)).toBeTruthy(); |
| 2366 | }); |
| 2367 | }); |
Nils Diewald | 6283d69 | 2015-04-23 20:32:53 +0000 | [diff] [blame] | 2368 | |
| 2369 | describe('KorAP.Rewrite', function () { |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 2370 | it('should be initializable', function () { |
| 2371 | var rewrite = rewriteClass.create({ |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 2372 | "@type" : "koral:rewrite", |
| 2373 | "operation" : "operation:modification", |
| 2374 | "src" : "querySerializer", |
| 2375 | "scope" : "tree" |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 2376 | }); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 2377 | expect(rewrite.toString()).toEqual('Modification of "tree" by "querySerializer"'); |
| 2378 | }); |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 2379 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 2380 | it('should be deserialized by docs', function () { |
| 2381 | var doc = docClass.create( |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 2382 | undefined, |
| 2383 | { |
| 2384 | "@type":"koral:doc", |
| 2385 | "key":"Titel", |
| 2386 | "value":"Baum", |
| 2387 | "match":"match:eq" |
| 2388 | }); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 2389 | |
| 2390 | expect(doc.element().classList.contains('doc')).toBeTruthy(); |
| 2391 | expect(doc.element().classList.contains('rewritten')).toBe(false); |
| 2392 | |
| 2393 | doc = docClass.create( |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 2394 | undefined, |
| 2395 | { |
| 2396 | "@type":"koral:doc", |
| 2397 | "key":"Titel", |
| 2398 | "value":"Baum", |
| 2399 | "match":"match:eq", |
| 2400 | "rewrites" : [ |
| 2401 | { |
| 2402 | "@type" : "koral:rewrite", |
| 2403 | "operation" : "operation:modification", |
| 2404 | "src" : "querySerializer", |
| 2405 | "scope" : "tree" |
| 2406 | } |
| 2407 | ] |
| 2408 | }); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 2409 | |
| 2410 | expect(doc.element().classList.contains('doc')).toBeTruthy(); |
| 2411 | expect(doc.element().classList.contains('rewritten')).toBeTruthy(); |
| 2412 | }); |
Nils Diewald | 6283d69 | 2015-04-23 20:32:53 +0000 | [diff] [blame] | 2413 | |
Akron | 76c3dd6 | 2018-05-29 20:58:27 +0200 | [diff] [blame] | 2414 | it('should be described in a title attribute', function () { |
| 2415 | |
| 2416 | doc = docClass.create( |
| 2417 | undefined, |
| 2418 | { |
| 2419 | "@type":"koral:doc", |
| 2420 | "key":"Titel", |
| 2421 | "value":"Baum", |
| 2422 | "match":"match:eq", |
| 2423 | "rewrites" : [ |
| 2424 | { |
| 2425 | "@type" : "koral:rewrite", |
| 2426 | "operation" : "operation:modification", |
| 2427 | "src" : "querySerializer", |
| 2428 | "scope" : "tree" |
| 2429 | }, |
| 2430 | { |
| 2431 | "@type" : "koral:rewrite", |
| 2432 | "operation" : "operation:injection", |
| 2433 | "src" : "me" |
| 2434 | } |
| 2435 | ] |
| 2436 | }); |
| 2437 | |
| 2438 | expect(doc.element().classList.contains('doc')).toBeTruthy(); |
| 2439 | expect(doc.element().classList.contains('rewritten')).toBeTruthy(); |
| 2440 | expect(doc.element().lastChild.getAttribute("title")).toEqual("querySerializer: tree (modification)\nme (injection)"); |
| 2441 | }); |
| 2442 | |
| 2443 | |
Nils Diewald | 6283d69 | 2015-04-23 20:32:53 +0000 | [diff] [blame] | 2444 | xit('should be deserialized by docGroups', function () { |
| 2445 | var docGroup = docGroupClass.create( |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 2446 | undefined, |
| 2447 | { |
| 2448 | "@type" : "koral:docGroup", |
| 2449 | "operation" : "operation:or", |
| 2450 | "operands" : [ |
| 2451 | { |
| 2452 | "@type" : "doc", |
| 2453 | "key" : "pubDate", |
| 2454 | "type" : "type:date", |
| 2455 | "value" : "2014-12-05" |
| 2456 | }, |
| 2457 | { |
| 2458 | "@type" : "doc", |
| 2459 | "key" : "pubDate", |
| 2460 | "type" : "type:date", |
| 2461 | "value" : "2014-12-06" |
| 2462 | } |
| 2463 | ], |
| 2464 | "rewrites" : [ |
| 2465 | { |
| 2466 | "@type" : "koral:rewrite", |
| 2467 | "operation" : "operation:modification", |
| 2468 | "src" : "querySerializer", |
| 2469 | "scope" : "tree" |
| 2470 | } |
| 2471 | ] |
| 2472 | } |
Nils Diewald | 6283d69 | 2015-04-23 20:32:53 +0000 | [diff] [blame] | 2473 | ); |
| 2474 | |
| 2475 | expect(doc.element().classList.contains('docgroup')).toBeTruthy(); |
| 2476 | expect(doc.element().classList.contains('rewritten')).toBe(false); |
| 2477 | }); |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 2478 | }); |
Nils Diewald | f0c4f11 | 2015-05-05 12:56:59 +0000 | [diff] [blame] | 2479 | |
| 2480 | describe('KorAP.stringValue', function () { |
| 2481 | it('should be initializable', function () { |
| 2482 | var sv = stringValClass.create(); |
| 2483 | expect(sv.regex()).toBe(false); |
| 2484 | expect(sv.value()).toBe(''); |
Nils Diewald | c4c4b83 | 2015-05-05 16:00:08 +0000 | [diff] [blame] | 2485 | |
| 2486 | sv = stringValClass.create('Baum'); |
| 2487 | expect(sv.regex()).toBe(false); |
| 2488 | expect(sv.value()).toBe('Baum'); |
| 2489 | |
| 2490 | sv = stringValClass.create('Baum', false); |
| 2491 | expect(sv.regex()).toBe(false); |
| 2492 | expect(sv.value()).toBe('Baum'); |
| 2493 | |
| 2494 | sv = stringValClass.create('Baum', true); |
| 2495 | expect(sv.regex()).toBe(true); |
| 2496 | expect(sv.value()).toBe('Baum'); |
| 2497 | }); |
| 2498 | |
| 2499 | it('should be modifiable', function () { |
| 2500 | var sv = stringValClass.create(); |
| 2501 | expect(sv.regex()).toBe(false); |
| 2502 | expect(sv.value()).toBe(''); |
| 2503 | |
| 2504 | expect(sv.value('Baum')).toBe('Baum'); |
| 2505 | expect(sv.value()).toBe('Baum'); |
| 2506 | |
| 2507 | expect(sv.regex(true)).toBe(true); |
| 2508 | expect(sv.regex()).toBe(true); |
| 2509 | }); |
| 2510 | |
| 2511 | it('should have a toggleble regex value', function () { |
| 2512 | var sv = stringValClass.create(); |
Nils Diewald | 7991a3f | 2015-05-19 14:12:37 +0000 | [diff] [blame] | 2513 | |
| 2514 | expect(sv.element().firstChild.value).toBe(''); |
| 2515 | sv.element().firstChild.value = 'der' |
| 2516 | expect(sv.element().firstChild.value).toBe('der'); |
| 2517 | |
Nils Diewald | c4c4b83 | 2015-05-05 16:00:08 +0000 | [diff] [blame] | 2518 | expect(sv.regex()).toBe(false); |
| 2519 | |
| 2520 | sv.toggleRegex(); |
Nils Diewald | 7991a3f | 2015-05-19 14:12:37 +0000 | [diff] [blame] | 2521 | expect(sv.element().firstChild.value).toBe('der'); |
Nils Diewald | c4c4b83 | 2015-05-05 16:00:08 +0000 | [diff] [blame] | 2522 | expect(sv.regex()).toBe(true); |
Nils Diewald | 7991a3f | 2015-05-19 14:12:37 +0000 | [diff] [blame] | 2523 | sv.element().firstChild.value = 'derbe' |
Nils Diewald | c4c4b83 | 2015-05-05 16:00:08 +0000 | [diff] [blame] | 2524 | |
| 2525 | sv.toggleRegex(); |
| 2526 | expect(sv.regex()).toBe(false); |
Nils Diewald | 7991a3f | 2015-05-19 14:12:37 +0000 | [diff] [blame] | 2527 | expect(sv.element().firstChild.value).toBe('derbe'); |
Nils Diewald | c4c4b83 | 2015-05-05 16:00:08 +0000 | [diff] [blame] | 2528 | }); |
| 2529 | |
| 2530 | it('should have an element', function () { |
| 2531 | var sv = stringValClass.create('der'); |
| 2532 | expect(sv.element().nodeName).toBe('DIV'); |
| 2533 | expect(sv.element().firstChild.nodeName).toBe('INPUT'); |
| 2534 | expect(sv.element().firstChild.value).toBe('der'); |
| 2535 | }); |
| 2536 | |
| 2537 | it('should have a classed element', function () { |
| 2538 | var sv = stringValClass.create(); |
Nils Diewald | c4c4b83 | 2015-05-05 16:00:08 +0000 | [diff] [blame] | 2539 | expect(sv.element().classList.contains('regex')).toBe(false); |
| 2540 | expect(sv.regex()).toBe(false); |
| 2541 | sv.toggleRegex(); |
| 2542 | expect(sv.element().classList.contains('regex')).toBe(true); |
| 2543 | }); |
| 2544 | |
| 2545 | it('should be storable', function () { |
| 2546 | var sv = stringValClass.create(); |
| 2547 | var count = 1; |
| 2548 | sv.store = function (value, regex) { |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 2549 | expect(regex).toBe(true); |
| 2550 | expect(value).toBe('tree'); |
Nils Diewald | c4c4b83 | 2015-05-05 16:00:08 +0000 | [diff] [blame] | 2551 | }; |
| 2552 | sv.regex(true); |
| 2553 | sv.value('tree'); |
| 2554 | sv.element().lastChild.click(); |
Nils Diewald | f0c4f11 | 2015-05-05 12:56:59 +0000 | [diff] [blame] | 2555 | }); |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 2556 | |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 2557 | it('should have a disableoption for regex', function () { |
| 2558 | var sv = stringValClass.create(undefined, undefined, true); |
| 2559 | var svE = sv.element(); |
| 2560 | expect(svE.children.length).toEqual(2); |
| 2561 | |
| 2562 | sv = stringValClass.create(undefined, undefined, false); |
| 2563 | svE = sv.element(); |
| 2564 | expect(svE.children.length).toEqual(1); |
| 2565 | }); |
| 2566 | |
Nils Diewald | f0c4f11 | 2015-05-05 12:56:59 +0000 | [diff] [blame] | 2567 | }); |
Akron | e4961b1 | 2017-05-10 21:04:46 +0200 | [diff] [blame] | 2568 | |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 2569 | describe('KorAP.VC.Menu', function () { |
Akron | e65a88a | 2018-04-05 19:14:20 +0200 | [diff] [blame] | 2570 | |
| 2571 | var vc; |
| 2572 | |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 2573 | it('should be initializable', function () { |
| 2574 | |
Akron | e65a88a | 2018-04-05 19:14:20 +0200 | [diff] [blame] | 2575 | vc = vcClass.create([ |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 2576 | ['a', 'text'], |
| 2577 | ['b', 'string'], |
| 2578 | ['c', 'date'] |
| 2579 | ]).fromJson(); |
| 2580 | expect(vc.element().firstChild.classList.contains('unspecified')).toBeTruthy(); |
| 2581 | expect(vc.element().firstChild.firstChild.tagName).toEqual('SPAN'); |
| 2582 | |
| 2583 | // Click on unspecified |
| 2584 | vc.element().firstChild.firstChild.click(); |
| 2585 | expect(vc.element().firstChild.firstChild.tagName).toEqual('UL'); |
| 2586 | |
| 2587 | var list = vc.element().firstChild.firstChild; |
Akron | 3ad4694 | 2018-08-22 16:47:14 +0200 | [diff] [blame] | 2588 | expect(list.getElementsByTagName("LI")[0].innerText).toEqual('referTo'); |
| 2589 | expect(list.getElementsByTagName("LI")[1].innerText).toEqual('a'); |
| 2590 | expect(list.getElementsByTagName("LI")[2].innerText).toEqual('b'); |
| 2591 | expect(list.getElementsByTagName("LI")[3].innerText).toEqual('c'); |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 2592 | |
| 2593 | vc = vcClass.create([ |
| 2594 | ['d', 'text'], |
| 2595 | ['e', 'string'], |
| 2596 | ['f', 'date'] |
| 2597 | ]).fromJson(); |
| 2598 | expect(vc.element().firstChild.classList.contains('unspecified')).toBeTruthy(); |
| 2599 | expect(vc.element().firstChild.firstChild.tagName).toEqual('SPAN'); |
| 2600 | |
| 2601 | // Click on unspecified |
| 2602 | vc.element().firstChild.firstChild.click(); |
| 2603 | expect(vc.element().firstChild.firstChild.tagName).toEqual('UL'); |
| 2604 | |
| 2605 | list = vc.element().firstChild.firstChild; |
Akron | 3ad4694 | 2018-08-22 16:47:14 +0200 | [diff] [blame] | 2606 | expect(list.getElementsByTagName("LI")[0].innerText).toEqual('referTo'); |
| 2607 | expect(list.getElementsByTagName("LI")[1].innerText).toEqual('d'); |
| 2608 | expect(list.getElementsByTagName("LI")[2].innerText).toEqual('e'); |
| 2609 | expect(list.getElementsByTagName("LI")[3].innerText).toEqual('f'); |
Akron | 31d8994 | 2018-04-06 16:44:51 +0200 | [diff] [blame] | 2610 | // blur |
| 2611 | document.body.click(); |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 2612 | }); |
Akron | e65a88a | 2018-04-05 19:14:20 +0200 | [diff] [blame] | 2613 | |
| 2614 | // Reinitialize to make tests stable |
| 2615 | vc = vcClass.create([ |
| 2616 | ['d', 'text'], |
| 2617 | ['e', 'string'], |
| 2618 | ['f', 'date'] |
| 2619 | ]).fromJson(); |
| 2620 | |
| 2621 | it('should be clickable on key', function () { |
Akron | 31d8994 | 2018-04-06 16:44:51 +0200 | [diff] [blame] | 2622 | // Click on unspecified |
| 2623 | vc.element().firstChild.firstChild.click(); |
Akron | e65a88a | 2018-04-05 19:14:20 +0200 | [diff] [blame] | 2624 | // Click on "d" |
Akron | 3ad4694 | 2018-08-22 16:47:14 +0200 | [diff] [blame] | 2625 | vc.element().firstChild.firstChild.getElementsByTagName("LI")[1].click(); |
Akron | e65a88a | 2018-04-05 19:14:20 +0200 | [diff] [blame] | 2626 | expect(vc.element().firstChild.firstChild.tagName).toEqual('SPAN'); |
| 2627 | expect(vc.element().firstChild.firstChild.innerText).toEqual('d'); |
| 2628 | expect(vc.element().firstChild.children[1].innerText).toEqual('eq'); |
| 2629 | expect(vc.element().firstChild.children[1].getAttribute('data-type')).toEqual('text'); |
Akron | 31d8994 | 2018-04-06 16:44:51 +0200 | [diff] [blame] | 2630 | // blur |
| 2631 | document.body.click(); |
Akron | e65a88a | 2018-04-05 19:14:20 +0200 | [diff] [blame] | 2632 | }); |
| 2633 | |
Akron | 31d8994 | 2018-04-06 16:44:51 +0200 | [diff] [blame] | 2634 | it('should be clickable on operation for text', function () { |
| 2635 | // Click on "d" (or unspecified) |
| 2636 | vc.element().firstChild.firstChild.click(); |
| 2637 | |
| 2638 | // Choose "d" |
Akron | 3ad4694 | 2018-08-22 16:47:14 +0200 | [diff] [blame] | 2639 | vc.element().firstChild.firstChild.getElementsByTagName("LI")[1].click(); |
Akron | 31d8994 | 2018-04-06 16:44:51 +0200 | [diff] [blame] | 2640 | |
| 2641 | // Click on matchop |
Akron | e65a88a | 2018-04-05 19:14:20 +0200 | [diff] [blame] | 2642 | vc.element().firstChild.children[1].click(); |
Akron | 31d8994 | 2018-04-06 16:44:51 +0200 | [diff] [blame] | 2643 | |
Akron | e65a88a | 2018-04-05 19:14:20 +0200 | [diff] [blame] | 2644 | expect(vc.element().firstChild.children[1].tagName).toEqual('UL'); |
Akron | 31d8994 | 2018-04-06 16:44:51 +0200 | [diff] [blame] | 2645 | |
Akron | e65a88a | 2018-04-05 19:14:20 +0200 | [diff] [blame] | 2646 | var ul = vc.element().firstChild.children[1]; |
| 2647 | expect(ul.getElementsByTagName('li')[0].innerText).toEqual("eq"); |
| 2648 | expect(ul.getElementsByTagName('li')[1].innerText).toEqual("ne"); |
| 2649 | expect(ul.getElementsByTagName('li')[2].innerText).toEqual("contains"); |
| 2650 | expect(ul.getElementsByTagName('li')[3].innerText).toEqual("containsnot"); |
| 2651 | expect(ul.getElementsByTagName('li')[4]).toBeUndefined(); |
Akron | 31d8994 | 2018-04-06 16:44:51 +0200 | [diff] [blame] | 2652 | |
| 2653 | // Choose "contains" |
| 2654 | ul.getElementsByTagName('li')[2].click(); |
| 2655 | expect(vc.element().firstChild.children[1].tagName).toEqual("SPAN"); |
| 2656 | expect(vc.element().firstChild.children[1].innerText).toEqual("contains"); |
| 2657 | // blur |
| 2658 | document.body.click(); |
Akron | e65a88a | 2018-04-05 19:14:20 +0200 | [diff] [blame] | 2659 | }) |
Akron | 31d8994 | 2018-04-06 16:44:51 +0200 | [diff] [blame] | 2660 | |
| 2661 | it('should be clickable on operation for string', function () { |
| 2662 | // Click on "d" (or unspecified) |
| 2663 | vc.element().firstChild.firstChild.click(); |
| 2664 | |
| 2665 | // Choose "e" |
Akron | 3ad4694 | 2018-08-22 16:47:14 +0200 | [diff] [blame] | 2666 | vc.element().firstChild.firstChild.getElementsByTagName("LI")[2].click(); |
| 2667 | |
Akron | 31d8994 | 2018-04-06 16:44:51 +0200 | [diff] [blame] | 2668 | // As a consequence the matchoperator may no longer |
| 2669 | // be valid and needs to be re-evaluated |
| 2670 | var fc = vc.element().firstChild; |
Akron | 3ad4694 | 2018-08-22 16:47:14 +0200 | [diff] [blame] | 2671 | |
Akron | 31d8994 | 2018-04-06 16:44:51 +0200 | [diff] [blame] | 2672 | expect(fc.firstChild.tagName).toEqual('SPAN'); |
| 2673 | expect(fc.firstChild.innerText).toEqual('e'); |
| 2674 | expect(fc.children[1].innerText).toEqual('eq'); |
| 2675 | expect(fc.children[1].getAttribute('data-type')).toEqual('string'); |
| 2676 | |
| 2677 | vc.element().firstChild.children[1].click(); |
| 2678 | |
| 2679 | expect(vc.element().firstChild.children[1].tagName).toEqual('UL'); |
| 2680 | |
| 2681 | var ul = vc.element().firstChild.children[1]; |
| 2682 | expect(ul.getElementsByTagName('li')[0].innerText).toEqual("eq"); |
| 2683 | expect(ul.getElementsByTagName('li')[1].innerText).toEqual("ne"); |
| 2684 | expect(ul.getElementsByTagName('li')[2]).toBeUndefined(); |
| 2685 | |
| 2686 | // Choose "ne" |
| 2687 | ul.getElementsByTagName('li')[1].click(); |
| 2688 | expect(vc.element().firstChild.children[1].tagName).toEqual("SPAN"); |
| 2689 | expect(vc.element().firstChild.children[1].innerText).toEqual("ne"); |
Akron | 8db5e3a | 2018-05-28 19:25:26 +0200 | [diff] [blame] | 2690 | |
| 2691 | // Click on text |
| 2692 | expect(vc.element().firstChild.children[2].innerText).toEqual("⋯"); |
| 2693 | vc.element().firstChild.children[2].click(); |
| 2694 | |
| 2695 | // Blur text element |
| 2696 | expect(vc.element().firstChild.children[2].firstChild.value).toEqual(''); |
| 2697 | |
Akron | 31d8994 | 2018-04-06 16:44:51 +0200 | [diff] [blame] | 2698 | // blur |
| 2699 | document.body.click(); |
| 2700 | }); |
| 2701 | |
| 2702 | it('should be clickable on operation for date', function () { |
| 2703 | |
| 2704 | // Replay matchop check - so it's guaranteed that "ne" is chosen |
| 2705 | // Click on "e" (or unspecified) |
| 2706 | vc.element().firstChild.firstChild.click(); |
| 2707 | // Rechoose "e" |
| 2708 | vc.element().firstChild.firstChild.getElementsByTagName("LI")[1].click(); |
| 2709 | // Click on matchop |
| 2710 | vc.element().firstChild.children[1].click(); |
| 2711 | // Choose "ne" |
| 2712 | vc.element().firstChild.children[1].getElementsByTagName('li')[1].click(); |
| 2713 | expect(vc.element().firstChild.children[1].innerText).toEqual("ne"); |
| 2714 | |
| 2715 | // Click on "e" |
| 2716 | vc.element().firstChild.firstChild.click(); |
| 2717 | // Choose "f" |
Akron | 3ad4694 | 2018-08-22 16:47:14 +0200 | [diff] [blame] | 2718 | vc.element().firstChild.firstChild.getElementsByTagName("LI")[3].click(); |
Akron | 31d8994 | 2018-04-06 16:44:51 +0200 | [diff] [blame] | 2719 | |
| 2720 | // The matchoperator should still be "ne" as this is valid for dates as well (now) |
| 2721 | var fc = vc.element().firstChild; |
| 2722 | expect(fc.firstChild.tagName).toEqual('SPAN'); |
| 2723 | expect(fc.firstChild.innerText).toEqual('f'); |
| 2724 | expect(fc.children[1].innerText).toEqual('ne'); |
| 2725 | // blur |
| 2726 | document.body.click(); |
| 2727 | }); |
Akron | ddc98a7 | 2018-04-06 17:33:52 +0200 | [diff] [blame] | 2728 | |
| 2729 | |
| 2730 | // Check json deserialization |
| 2731 | it('should be initializable', function () { |
| 2732 | vc = vcClass.create([ |
| 2733 | ['a', 'text'], |
| 2734 | ['b', 'string'], |
| 2735 | ['c', 'date'] |
| 2736 | ]).fromJson({ |
| 2737 | "@type" : "koral:doc", |
| 2738 | "key":"a", |
| 2739 | "value":"Baum" |
| 2740 | }); |
| 2741 | |
| 2742 | expect(vc.element().firstChild.children[1].getAttribute('data-type')).toEqual('text'); |
| 2743 | }); |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 2744 | }); |
| 2745 | |
| 2746 | |
Akron | e4961b1 | 2017-05-10 21:04:46 +0200 | [diff] [blame] | 2747 | // Check prefix |
| 2748 | describe('KorAP.VC.Prefix', function () { |
| 2749 | |
| 2750 | it('should be initializable', function () { |
| 2751 | var p = prefixClass.create(); |
| 2752 | expect(p.element().classList.contains('pref')).toBeTruthy(); |
| 2753 | expect(p.isSet()).not.toBeTruthy(); |
| 2754 | }); |
| 2755 | |
| 2756 | |
| 2757 | it('should be clickable', function () { |
| 2758 | var vc = vcClass.create([ |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 2759 | ['a', null], |
| 2760 | ['b', null], |
| 2761 | ['c', null] |
| 2762 | ]).fromJson(); |
Akron | e4961b1 | 2017-05-10 21:04:46 +0200 | [diff] [blame] | 2763 | expect(vc.element().firstChild.classList.contains('unspecified')).toBeTruthy(); |
| 2764 | |
| 2765 | // This should open up the menu |
| 2766 | vc.element().firstChild.firstChild.click(); |
| 2767 | expect(vc.element().firstChild.firstChild.tagName).toEqual('UL'); |
| 2768 | |
| 2769 | KorAP._vcKeyMenu._prefix.clear(); |
| 2770 | KorAP._vcKeyMenu._prefix.add('x'); |
| 2771 | |
| 2772 | var prefElement = vc.element().querySelector('span.pref'); |
| 2773 | expect(prefElement.innerText).toEqual('x'); |
| 2774 | |
| 2775 | // This should add key 'x' to VC |
| 2776 | prefElement.click(); |
| 2777 | |
| 2778 | expect(vc.element().firstChild.classList.contains('doc')).toBeTruthy(); |
| 2779 | expect(vc.element().firstChild.firstChild.className).toEqual('key'); |
| 2780 | expect(vc.element().firstChild.firstChild.innerText).toEqual('x'); |
| 2781 | }); |
| 2782 | }); |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame] | 2783 | }); |