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