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