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