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 | 1bdf527 | 2018-07-24 18:51:30 +0200 | [diff] [blame] | 1735 | }); |
| 1736 | |
| 1737 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1738 | describe('KorAP.Operators', function () { |
| 1739 | it('should be initializable', function () { |
| 1740 | var op = operatorsClass.create(true, false, false); |
| 1741 | expect(op.and()).toBeTruthy(); |
| 1742 | expect(op.or()).not.toBeTruthy(); |
| 1743 | expect(op.del()).not.toBeTruthy(); |
| 1744 | |
| 1745 | op.and(false); |
| 1746 | expect(op.and()).not.toBeTruthy(); |
| 1747 | expect(op.or()).not.toBeTruthy(); |
| 1748 | expect(op.del()).not.toBeTruthy(); |
| 1749 | |
| 1750 | op.or(true); |
| 1751 | op.del(true); |
| 1752 | expect(op.and()).not.toBeTruthy(); |
| 1753 | expect(op.or()).toBeTruthy(); |
| 1754 | expect(op.del()).toBeTruthy(); |
| 1755 | |
Akron | d141a36 | 2018-07-10 18:12:13 +0200 | [diff] [blame] | 1756 | var e = op.update(); |
Akron | 0b489ad | 2018-02-02 16:49:32 +0100 | [diff] [blame] | 1757 | expect(e.getAttribute('class')).toEqual('operators button-group'); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1758 | expect(e.children[0].getAttribute('class')).toEqual('or'); |
Akron | d141a36 | 2018-07-10 18:12:13 +0200 | [diff] [blame] | 1759 | expect(e.children[0].innerText).toEqual('or'); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1760 | expect(e.children[1].getAttribute('class')).toEqual('delete'); |
Akron | d141a36 | 2018-07-10 18:12:13 +0200 | [diff] [blame] | 1761 | expect(e.children[1].innerText).toEqual('×'); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1762 | |
| 1763 | op.and(true); |
| 1764 | op.del(false); |
Akron | d141a36 | 2018-07-10 18:12:13 +0200 | [diff] [blame] | 1765 | e = op.update(); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1766 | |
Akron | 0b489ad | 2018-02-02 16:49:32 +0100 | [diff] [blame] | 1767 | expect(e.getAttribute('class')).toEqual('operators button-group'); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1768 | expect(e.children[0].getAttribute('class')).toEqual('and'); |
Akron | d141a36 | 2018-07-10 18:12:13 +0200 | [diff] [blame] | 1769 | expect(e.children[0].innerText).toEqual('and'); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1770 | expect(e.children[1].getAttribute('class')).toEqual('or'); |
Akron | d141a36 | 2018-07-10 18:12:13 +0200 | [diff] [blame] | 1771 | expect(e.children[1].innerText).toEqual('or'); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1772 | }); |
| 1773 | }); |
| 1774 | |
| 1775 | describe('KorAP._delete (event)', function () { |
| 1776 | var complexVCFactory = buildFactory(vcClass,{ |
| 1777 | "@type": 'koral:docGroup', |
| 1778 | 'operation' : 'operation:and', |
| 1779 | 'operands' : [ |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 1780 | { |
| 1781 | "@type": 'koral:doc', |
| 1782 | "key": 'pubDate', |
| 1783 | "match": 'match:eq', |
| 1784 | "value": '2014-12-05', |
| 1785 | "type": 'type:date' |
| 1786 | }, |
| 1787 | { |
| 1788 | "@type" : 'koral:docGroup', |
| 1789 | 'operation' : 'operation:or', |
| 1790 | 'operands' : [ |
| 1791 | { |
| 1792 | '@type' : 'koral:doc', |
| 1793 | 'key' : 'title', |
| 1794 | 'value' : 'Hello World!' |
| 1795 | }, |
| 1796 | { |
| 1797 | '@type' : 'koral:doc', |
| 1798 | 'key' : 'foo', |
| 1799 | 'value' : 'bar' |
| 1800 | } |
| 1801 | ] |
| 1802 | } |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1803 | ] |
| 1804 | }); |
| 1805 | |
| 1806 | it('should clean on root docs', function () { |
Nils Diewald | 6283d69 | 2015-04-23 20:32:53 +0000 | [diff] [blame] | 1807 | var vc = vcClass.create().fromJson({ |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 1808 | "@type": 'koral:doc', |
| 1809 | "key": 'pubDate', |
| 1810 | "match": 'match:eq', |
| 1811 | "value": '2014-12-05', |
| 1812 | "type": 'type:date' |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 1813 | }); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1814 | expect(vc.root().toQuery()).toEqual('pubDate in 2014-12-05'); |
Akron | 0b489ad | 2018-02-02 16:49:32 +0100 | [diff] [blame] | 1815 | expect(vc.root().element().lastChild.getAttribute('class')).toEqual('operators button-group'); |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 1816 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1817 | // Clean with delete from root |
| 1818 | expect(vc.root().element().lastChild.lastChild.getAttribute('class')).toEqual('delete'); |
| 1819 | _delOn(vc.root()); |
| 1820 | expect(vc.root().toQuery()).toEqual(''); |
Akron | ebc9666 | 2018-08-29 17:36:20 +0200 | [diff] [blame] | 1821 | expect(vc.root().element().lastChild.lastChild.data).toEqual(KorAP.Locale.EMPTY); |
| 1822 | expect(vc.root().element().classList.contains('unspecified')).toEqual(true); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1823 | }); |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 1824 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1825 | it('should remove on nested docs', function () { |
Nils Diewald | 6283d69 | 2015-04-23 20:32:53 +0000 | [diff] [blame] | 1826 | var vc = vcClass.create().fromJson( |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 1827 | { |
| 1828 | "@type": 'koral:docGroup', |
| 1829 | 'operation' : 'operation:and', |
| 1830 | 'operands' : [ |
| 1831 | { |
| 1832 | "@type": 'koral:doc', |
| 1833 | "key": 'pubDate', |
| 1834 | "match": 'match:eq', |
| 1835 | "value": '2014-12-05', |
| 1836 | "type": 'type:date' |
| 1837 | }, |
| 1838 | { |
| 1839 | "@type" : 'koral:doc', |
| 1840 | 'key' : 'foo', |
| 1841 | 'value' : 'bar' |
| 1842 | } |
| 1843 | ] |
| 1844 | } |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1845 | ); |
| 1846 | |
| 1847 | // Delete with direct element access |
| 1848 | expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar"'); |
| 1849 | _delOn(vc.root().getOperand(0)); |
| 1850 | |
| 1851 | expect(vc.toQuery()).toEqual('foo = "bar"'); |
| 1852 | expect(vc.root().ldType()).toEqual('doc'); |
| 1853 | }); |
| 1854 | |
| 1855 | it('should clean on doc groups', function () { |
Nils Diewald | 6283d69 | 2015-04-23 20:32:53 +0000 | [diff] [blame] | 1856 | var vc = vcClass.create().fromJson( |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 1857 | { |
| 1858 | "@type": 'koral:docGroup', |
| 1859 | 'operation' : 'operation:and', |
| 1860 | 'operands' : [ |
| 1861 | { |
| 1862 | "@type": 'koral:doc', |
| 1863 | "key": 'pubDate', |
| 1864 | "match": 'match:eq', |
| 1865 | "value": '2014-12-05', |
| 1866 | "type": 'type:date' |
| 1867 | }, |
| 1868 | { |
| 1869 | "@type" : 'koral:doc', |
| 1870 | 'key' : 'foo', |
| 1871 | 'value' : 'bar' |
| 1872 | } |
| 1873 | ] |
| 1874 | } |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1875 | ); |
| 1876 | |
| 1877 | // Cleanwith direct element access |
| 1878 | expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar"'); |
| 1879 | _delOn(vc.root()); |
| 1880 | expect(vc.toQuery()).toEqual(''); |
| 1881 | expect(vc.root().ldType()).toEqual('non'); |
| 1882 | }); |
| 1883 | |
| 1884 | it('should remove on nested doc groups (case of ungrouping 1)', function () { |
| 1885 | var vc = complexVCFactory.create(); |
| 1886 | |
| 1887 | // Delete with direct element access |
| 1888 | expect(vc.toQuery()).toEqual( |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 1889 | 'pubDate in 2014-12-05 & (title = "Hello World!" | foo = "bar")' |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1890 | ); |
| 1891 | |
| 1892 | // Remove hello world: |
| 1893 | _delOn(vc.root().getOperand(1).getOperand(0)); |
| 1894 | expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar"'); |
| 1895 | expect(vc.root().ldType()).toEqual('docGroup'); |
| 1896 | }); |
| 1897 | |
| 1898 | it('should remove on nested doc groups (case of ungrouping 2)', function () { |
| 1899 | var vc = complexVCFactory.create(); |
| 1900 | |
| 1901 | // Delete with direct element access |
| 1902 | expect(vc.toQuery()).toEqual( |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 1903 | 'pubDate in 2014-12-05 & (title = "Hello World!" | foo = "bar")' |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1904 | ); |
| 1905 | |
| 1906 | // Remove bar |
| 1907 | _delOn(vc.root().getOperand(1).getOperand(1)); |
| 1908 | expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & title = "Hello World!"'); |
| 1909 | expect(vc.root().ldType()).toEqual('docGroup'); |
| 1910 | expect(vc.root().operation()).toEqual('and'); |
| 1911 | }); |
| 1912 | |
| 1913 | it('should remove on nested doc groups (case of root changing)', function () { |
| 1914 | var vc = complexVCFactory.create(); |
| 1915 | |
| 1916 | // Delete with direct element access |
| 1917 | expect(vc.toQuery()).toEqual( |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 1918 | 'pubDate in 2014-12-05 & ' + |
| 1919 | '(title = "Hello World!" | foo = "bar")' |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1920 | ); |
| 1921 | |
| 1922 | // Remove bar |
| 1923 | _delOn(vc.root().getOperand(0)); |
| 1924 | expect(vc.toQuery()).toEqual('title = "Hello World!" | foo = "bar"'); |
| 1925 | expect(vc.root().ldType()).toEqual('docGroup'); |
| 1926 | expect(vc.root().operation()).toEqual('or'); |
| 1927 | }); |
| 1928 | |
| 1929 | it('should remove on nested doc groups (list flattening)', function () { |
Nils Diewald | 6283d69 | 2015-04-23 20:32:53 +0000 | [diff] [blame] | 1930 | var vc = vcClass.create().fromJson( |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 1931 | { |
| 1932 | "@type": 'koral:docGroup', |
| 1933 | 'operation' : 'operation:or', |
| 1934 | 'operands' : [ |
| 1935 | { |
| 1936 | "@type": 'koral:doc', |
| 1937 | "key": 'pubDate', |
| 1938 | "match": 'match:eq', |
| 1939 | "value": '2014-12-05', |
| 1940 | "type": 'type:date' |
| 1941 | }, |
| 1942 | { |
| 1943 | "@type" : 'koral:doc', |
| 1944 | 'key' : 'foo', |
| 1945 | 'value' : 'bar' |
| 1946 | }, |
| 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:docGroup', |
| 1960 | 'operation' : 'operation:or', |
| 1961 | 'operands' : [ |
| 1962 | { |
| 1963 | '@type' : 'koral:doc', |
| 1964 | 'key' : 'title', |
| 1965 | 'value' : 'Hello World!' |
| 1966 | }, |
| 1967 | { |
| 1968 | '@type' : 'koral:doc', |
| 1969 | 'key' : 'yeah', |
| 1970 | 'value' : 'juhu' |
| 1971 | } |
| 1972 | ] |
| 1973 | } |
| 1974 | ] |
| 1975 | } |
| 1976 | ] |
| 1977 | } |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1978 | ); |
| 1979 | |
| 1980 | // Delete with direct element access |
| 1981 | expect(vc.toQuery()).toEqual( |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 1982 | 'pubDate in 2014-12-05 | foo = "bar" | ' + |
| 1983 | '(pubDate in 2014-12-05 & ' + |
| 1984 | '(title = "Hello World!" | yeah = "juhu"))' |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1985 | ); |
| 1986 | |
| 1987 | expect(vc.root().ldType()).toEqual('docGroup'); |
| 1988 | expect(vc.root().operation()).toEqual('or'); |
| 1989 | |
| 1990 | // Operands and operators |
Akron | adab5e5 | 2018-08-20 13:50:53 +0200 | [diff] [blame] | 1991 | expect(vc.builder().firstChild.children.length).toEqual(4); |
| 1992 | expect(vc.builder().firstChild.lastChild.getAttribute('class')).toEqual('operators button-group'); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1993 | |
| 1994 | // Remove inner group and flatten |
| 1995 | _delOn(vc.root().getOperand(2).getOperand(0)); |
| 1996 | |
| 1997 | expect(vc.toQuery()).toEqual( |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 1998 | 'pubDate in 2014-12-05 | foo = "bar" | title = "Hello World!" | yeah = "juhu"' |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1999 | ); |
| 2000 | expect(vc.root().ldType()).toEqual('docGroup'); |
| 2001 | expect(vc.root().operation()).toEqual('or'); |
| 2002 | |
| 2003 | // Operands and operators |
Akron | adab5e5 | 2018-08-20 13:50:53 +0200 | [diff] [blame] | 2004 | expect(vc.builder().firstChild.children.length).toEqual(5); |
| 2005 | expect(vc.builder().firstChild.lastChild.getAttribute('class')).toEqual('operators button-group'); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 2006 | }); |
| 2007 | }); |
| 2008 | |
| 2009 | describe('KorAP._add (event)', function () { |
| 2010 | var complexVCFactory = buildFactory(vcClass,{ |
| 2011 | "@type": 'koral:docGroup', |
| 2012 | 'operation' : 'operation:and', |
| 2013 | 'operands' : [ |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 2014 | { |
| 2015 | "@type": 'koral:doc', |
| 2016 | "key": 'pubDate', |
| 2017 | "match": 'match:eq', |
| 2018 | "value": '2014-12-05', |
| 2019 | "type": 'type:date' |
| 2020 | }, |
| 2021 | { |
| 2022 | "@type" : 'koral:docGroup', |
| 2023 | 'operation' : 'operation:or', |
| 2024 | 'operands' : [ |
| 2025 | { |
| 2026 | '@type' : 'koral:doc', |
| 2027 | 'key' : 'title', |
| 2028 | 'value' : 'Hello World!' |
| 2029 | }, |
| 2030 | { |
| 2031 | '@type' : 'koral:doc', |
| 2032 | 'key' : 'foo', |
| 2033 | 'value' : 'bar' |
| 2034 | } |
| 2035 | ] |
| 2036 | } |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 2037 | ] |
| 2038 | }); |
| 2039 | |
| 2040 | it('should add new unspecified doc with "and"', function () { |
Nils Diewald | 6283d69 | 2015-04-23 20:32:53 +0000 | [diff] [blame] | 2041 | var vc = vcClass.create().fromJson( |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 2042 | { |
| 2043 | "@type": 'koral:docGroup', |
| 2044 | 'operation' : 'operation:and', |
| 2045 | 'operands' : [ |
| 2046 | { |
| 2047 | "@type": 'koral:doc', |
| 2048 | "key": 'pubDate', |
| 2049 | "match": 'match:eq', |
| 2050 | "value": '2014-12-05', |
| 2051 | "type": 'type:date' |
| 2052 | }, |
| 2053 | { |
| 2054 | "@type" : 'koral:doc', |
| 2055 | 'key' : 'foo', |
| 2056 | 'value' : 'bar' |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 2057 | }, |
| 2058 | { |
| 2059 | "@type" : "koral:docGroupRef", |
| 2060 | "ref" : "myCorpus" |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 2061 | } |
| 2062 | ] |
| 2063 | } |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 2064 | ); |
| 2065 | |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 2066 | 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] | 2067 | |
Akron | adab5e5 | 2018-08-20 13:50:53 +0200 | [diff] [blame] | 2068 | var fc = vc.builder().firstChild; |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 2069 | expect(fc.getAttribute('data-operation')).toEqual('and'); |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 2070 | expect(fc.children.length).toEqual(4); |
Akron | 0b489ad | 2018-02-02 16:49:32 +0100 | [diff] [blame] | 2071 | expect(fc.lastChild.getAttribute('class')).toEqual('operators button-group'); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 2072 | expect(fc.children[0].getAttribute('class')).toEqual('doc'); |
| 2073 | expect(fc.children[1].getAttribute('class')).toEqual('doc'); |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 2074 | expect(fc.children[2].getAttribute('class')).toEqual('doc groupref'); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 2075 | |
| 2076 | // add with 'and' in the middle |
| 2077 | _andOn(vc.root().getOperand(0)); |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 2078 | 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] | 2079 | |
Akron | adab5e5 | 2018-08-20 13:50:53 +0200 | [diff] [blame] | 2080 | fc = vc.builder().firstChild; |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 2081 | expect(fc.getAttribute('data-operation')).toEqual('and'); |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 2082 | expect(fc.children.length).toEqual(5); |
Akron | 0b489ad | 2018-02-02 16:49:32 +0100 | [diff] [blame] | 2083 | expect(fc.lastChild.getAttribute('class')).toEqual('operators button-group'); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 2084 | |
| 2085 | expect(fc.children[0].getAttribute('class')).toEqual('doc'); |
| 2086 | expect(fc.children[1].getAttribute('class')).toEqual('doc unspecified'); |
| 2087 | expect(fc.children[2].getAttribute('class')).toEqual('doc'); |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 2088 | expect(fc.children[3].getAttribute('class')).toEqual('doc groupref'); |
| 2089 | expect(fc.children[4].classList.contains('button-group')).toBeTruthy(); |
| 2090 | expect(fc.children.length).toEqual(5); |
| 2091 | |
| 2092 | _andOn(vc.root().getOperand(3)); |
| 2093 | expect(fc.children[0].getAttribute('class')).toEqual('doc'); |
| 2094 | expect(fc.children[1].getAttribute('class')).toEqual('doc unspecified'); |
| 2095 | expect(fc.children[2].getAttribute('class')).toEqual('doc'); |
| 2096 | expect(fc.children[3].getAttribute('class')).toEqual('doc groupref'); |
| 2097 | expect(fc.children[4].getAttribute('class')).toEqual('doc unspecified'); |
| 2098 | expect(fc.children[5].classList.contains('button-group')).toBeTruthy(); |
| 2099 | expect(fc.children.length).toEqual(6); |
| 2100 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 2101 | }); |
| 2102 | |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 2103 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 2104 | it('should add new unspecified doc with "or"', function () { |
Nils Diewald | 6283d69 | 2015-04-23 20:32:53 +0000 | [diff] [blame] | 2105 | var vc = vcClass.create().fromJson( |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 2106 | { |
| 2107 | "@type": 'koral:docGroup', |
| 2108 | 'operation' : 'operation:and', |
| 2109 | 'operands' : [ |
| 2110 | { |
| 2111 | "@type": 'koral:doc', |
| 2112 | "key": 'pubDate', |
| 2113 | "match": 'match:eq', |
| 2114 | "value": '2014-12-05', |
| 2115 | "type": 'type:date' |
| 2116 | }, |
| 2117 | { |
| 2118 | "@type" : 'koral:doc', |
| 2119 | 'key' : 'foo', |
| 2120 | 'value' : 'bar' |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 2121 | }, |
| 2122 | { |
| 2123 | "@type" : "koral:docGroupRef", |
| 2124 | "ref" : "myCorpus" |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 2125 | } |
| 2126 | ] |
| 2127 | } |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 2128 | ); |
| 2129 | |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 2130 | 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] | 2131 | |
Akron | adab5e5 | 2018-08-20 13:50:53 +0200 | [diff] [blame] | 2132 | var fc = vc.builder().firstChild; |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 2133 | expect(fc.children.length).toEqual(4); |
Akron | 0b489ad | 2018-02-02 16:49:32 +0100 | [diff] [blame] | 2134 | expect(fc.lastChild.getAttribute('class')).toEqual('operators button-group'); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 2135 | expect(fc.children[0].getAttribute('class')).toEqual('doc'); |
| 2136 | expect(fc.children[1].getAttribute('class')).toEqual('doc'); |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 2137 | expect(fc.children[2].getAttribute('class')).toEqual('doc groupref'); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 2138 | |
| 2139 | // add with 'or' in the middle |
| 2140 | _orOn(vc.root().getOperand(0)); |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 2141 | expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar" & referTo "myCorpus"'); |
Akron | adab5e5 | 2018-08-20 13:50:53 +0200 | [diff] [blame] | 2142 | fc = vc.builder().firstChild; |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 2143 | |
| 2144 | expect(fc.getAttribute('data-operation')).toEqual('and'); |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 2145 | expect(fc.children.length).toEqual(4); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 2146 | expect(fc.children[0].getAttribute('class')).toEqual('docGroup'); |
| 2147 | expect(fc.children[0].getAttribute('data-operation')).toEqual('or'); |
| 2148 | expect(fc.children[1].getAttribute('class')).toEqual('doc'); |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 2149 | expect(fc.children[2].getAttribute('class')).toEqual('doc groupref'); |
| 2150 | expect(fc.children[3].getAttribute('class')).toEqual('operators button-group'); |
Akron | 0b489ad | 2018-02-02 16:49:32 +0100 | [diff] [blame] | 2151 | expect(fc.lastChild.getAttribute('class')).toEqual('operators button-group'); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 2152 | |
Akron | adab5e5 | 2018-08-20 13:50:53 +0200 | [diff] [blame] | 2153 | fc = vc.builder().firstChild.firstChild; |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 2154 | expect(fc.children.length).toEqual(3); |
| 2155 | expect(fc.children[0].getAttribute('class')).toEqual('doc'); |
| 2156 | expect(fc.children[1].getAttribute('class')).toEqual('doc unspecified'); |
Akron | 0b489ad | 2018-02-02 16:49:32 +0100 | [diff] [blame] | 2157 | expect(fc.children[2].getAttribute('class')).toEqual('operators button-group'); |
| 2158 | expect(fc.lastChild.getAttribute('class')).toEqual('operators button-group'); |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 2159 | |
| 2160 | _orOn(vc.root().getOperand(2)); |
Akron | adab5e5 | 2018-08-20 13:50:53 +0200 | [diff] [blame] | 2161 | fc = vc.builder().firstChild; |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 2162 | expect(fc.children.length).toEqual(4); |
| 2163 | |
| 2164 | expect(fc.children[0].getAttribute('class')).toEqual('docGroup'); |
| 2165 | expect(fc.children[1].getAttribute('class')).toEqual('doc'); |
| 2166 | expect(fc.children[2].getAttribute('class')).toEqual('docGroup'); |
| 2167 | expect(fc.children[3].getAttribute('class')).toEqual('operators button-group'); |
| 2168 | |
Akron | adab5e5 | 2018-08-20 13:50:53 +0200 | [diff] [blame] | 2169 | fc = vc.builder().firstChild.children[2]; |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 2170 | expect(fc.children[0].getAttribute('class')).toEqual('doc groupref'); |
| 2171 | expect(fc.children[1].getAttribute('class')).toEqual('doc unspecified'); |
| 2172 | expect(fc.children[2].getAttribute('class')).toEqual('operators button-group'); |
| 2173 | expect(fc.lastChild.getAttribute('class')).toEqual('operators button-group'); |
| 2174 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 2175 | }); |
| 2176 | |
| 2177 | it('should add new unspecified doc with "and" before group', function () { |
| 2178 | var vc = demoFactory.create(); |
| 2179 | |
| 2180 | // Wrap with direct element access |
| 2181 | expect(vc.toQuery()).toEqual( |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 2182 | '(Titel = "Baum" & ' + |
| 2183 | 'Veröffentlichungsort = "hihi" & ' + |
| 2184 | '(Titel = "Baum" | ' + |
| 2185 | 'Veröffentlichungsort = "hihi")) | ' + |
| 2186 | 'Untertitel ~ "huhu"' |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 2187 | ); |
| 2188 | |
| 2189 | expect(vc.root().getOperand(0).ldType()).toEqual('docGroup'); |
| 2190 | expect(vc.root().getOperand(0).operation()).toEqual('and'); |
| 2191 | expect(vc.root().getOperand(0).operands().length).toEqual(3); |
| 2192 | |
| 2193 | // Add unspecified on the second doc |
| 2194 | var secDoc = vc.root().getOperand(0).getOperand(1); |
| 2195 | expect(secDoc.value()).toEqual('hihi'); |
| 2196 | |
| 2197 | // Add |
| 2198 | _andOn(secDoc); |
| 2199 | |
| 2200 | var fo = vc.root().getOperand(0); |
| 2201 | |
| 2202 | expect(fo.ldType()).toEqual('docGroup'); |
| 2203 | expect(fo.operation()).toEqual('and'); |
| 2204 | expect(fo.operands().length).toEqual(4); |
| 2205 | |
| 2206 | expect(fo.getOperand(0).ldType()).toEqual('doc'); |
| 2207 | expect(fo.getOperand(1).ldType()).toEqual('doc'); |
| 2208 | expect(fo.getOperand(2).ldType()).toEqual('non'); |
| 2209 | expect(fo.getOperand(3).ldType()).toEqual('docGroup'); |
| 2210 | }); |
| 2211 | |
| 2212 | |
| 2213 | it('should remove a doc with an unspecified doc in a nested group', function () { |
| 2214 | var vc = demoFactory.create(); |
| 2215 | |
| 2216 | // Wrap with direct element access |
| 2217 | expect(vc.toQuery()).toEqual( |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 2218 | '(Titel = "Baum" & Veröffentlichungsort = "hihi" & (Titel = "Baum" | Veröffentlichungsort = "hihi")) | Untertitel ~ "huhu"' |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 2219 | ); |
| 2220 | |
| 2221 | var fo = vc.root().getOperand(0).getOperand(0); |
| 2222 | expect(fo.key()).toEqual('Titel'); |
| 2223 | expect(fo.value()).toEqual('Baum'); |
| 2224 | |
| 2225 | // Add unspecified on the root group |
| 2226 | _orOn(fo); |
| 2227 | |
| 2228 | fo = vc.root().getOperand(0).getOperand(0); |
| 2229 | |
| 2230 | expect(fo.operation()).toEqual('or'); |
| 2231 | expect(fo.getOperand(0).ldType()).toEqual('doc'); |
| 2232 | expect(fo.getOperand(1).ldType()).toEqual('non'); |
| 2233 | |
| 2234 | // Delete document |
| 2235 | _delOn(fo.getOperand(0)); |
| 2236 | |
| 2237 | // The operand is now non |
| 2238 | expect(vc.root().getOperand(0).getOperand(0).ldType()).toEqual('non'); |
| 2239 | expect(vc.root().getOperand(0).getOperand(1).ldType()).toEqual('doc'); |
| 2240 | expect(vc.root().getOperand(0).getOperand(2).ldType()).toEqual('docGroup'); |
| 2241 | }); |
| 2242 | |
| 2243 | |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 2244 | 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] | 2245 | var vc = demoFactory.create(); |
| 2246 | |
| 2247 | // Wrap with direct element access |
| 2248 | expect(vc.toQuery()).toEqual( |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 2249 | '(Titel = "Baum" & ' + |
| 2250 | 'Veröffentlichungsort = "hihi" & ' + |
| 2251 | '(Titel = "Baum" ' + |
| 2252 | '| Veröffentlichungsort = "hihi")) | ' + |
| 2253 | 'Untertitel ~ "huhu"' |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 2254 | ); |
| 2255 | |
| 2256 | var fo = vc.root().getOperand(0).getOperand(0); |
| 2257 | expect(fo.key()).toEqual('Titel'); |
| 2258 | expect(fo.value()).toEqual('Baum'); |
| 2259 | |
| 2260 | // Add unspecified on the root group |
| 2261 | _orOn(fo); |
| 2262 | |
| 2263 | fo = vc.root().getOperand(0).getOperand(0); |
| 2264 | |
| 2265 | expect(fo.operation()).toEqual('or'); |
| 2266 | expect(fo.getOperand(0).ldType()).toEqual('doc'); |
| 2267 | expect(fo.getOperand(1).ldType()).toEqual('non'); |
| 2268 | |
| 2269 | // Delete unspecified doc |
| 2270 | _delOn(fo.getOperand(1)); |
| 2271 | |
| 2272 | // The operand is now non |
| 2273 | fo = vc.root().getOperand(0); |
| 2274 | expect(fo.getOperand(0).ldType()).toEqual('doc'); |
| 2275 | expect(fo.getOperand(0).key()).toEqual('Titel'); |
| 2276 | expect(fo.getOperand(0).value()).toEqual('Baum'); |
| 2277 | expect(fo.getOperand(1).ldType()).toEqual('doc'); |
| 2278 | expect(fo.getOperand(2).ldType()).toEqual('docGroup'); |
| 2279 | }); |
| 2280 | |
| 2281 | |
| 2282 | it('should add on parent group (case "and")', function () { |
| 2283 | var vc = complexVCFactory.create(); |
| 2284 | |
| 2285 | // Wrap with direct element access |
| 2286 | expect(vc.toQuery()).toEqual( |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 2287 | 'pubDate in 2014-12-05 & (title = "Hello World!" | foo = "bar")' |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 2288 | ); |
| 2289 | |
| 2290 | expect(vc.root().operands().length).toEqual(2); |
| 2291 | |
| 2292 | // Add unspecified on the root group |
| 2293 | _andOn(vc.root().getOperand(1)); |
| 2294 | expect(vc.toQuery()).toEqual( |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 2295 | 'pubDate in 2014-12-05 & (title = "Hello World!" | foo = "bar")' |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 2296 | ); |
| 2297 | |
| 2298 | expect(vc.root().ldType()).toEqual('docGroup'); |
| 2299 | expect(vc.root().operands().length).toEqual(3); |
| 2300 | expect(vc.root().getOperand(0).ldType()).toEqual('doc'); |
| 2301 | expect(vc.root().getOperand(1).ldType()).toEqual('docGroup'); |
| 2302 | expect(vc.root().getOperand(1).operation()).toEqual('or'); |
| 2303 | expect(vc.root().getOperand(2).ldType()).toEqual('non'); |
| 2304 | |
| 2305 | // Add another unspecified on the root group |
| 2306 | _andOn(vc.root().getOperand(1)); |
| 2307 | |
| 2308 | expect(vc.root().operands().length).toEqual(4); |
| 2309 | expect(vc.root().getOperand(0).ldType()).toEqual('doc'); |
| 2310 | expect(vc.root().getOperand(1).ldType()).toEqual('docGroup'); |
| 2311 | expect(vc.root().getOperand(2).ldType()).toEqual('non'); |
| 2312 | expect(vc.root().getOperand(3).ldType()).toEqual('non'); |
| 2313 | |
| 2314 | // Add another unspecified after the first doc |
| 2315 | _andOn(vc.root().getOperand(0)); |
| 2316 | |
| 2317 | expect(vc.root().operands().length).toEqual(5); |
| 2318 | expect(vc.root().getOperand(0).ldType()).toEqual('doc'); |
| 2319 | expect(vc.root().getOperand(1).ldType()).toEqual('non'); |
| 2320 | expect(vc.root().getOperand(2).ldType()).toEqual('docGroup'); |
| 2321 | expect(vc.root().getOperand(3).ldType()).toEqual('non'); |
| 2322 | expect(vc.root().getOperand(4).ldType()).toEqual('non'); |
| 2323 | }); |
| 2324 | |
| 2325 | it('should wrap on root', function () { |
Nils Diewald | 6283d69 | 2015-04-23 20:32:53 +0000 | [diff] [blame] | 2326 | var vc = vcClass.create().fromJson( |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 2327 | { |
| 2328 | "@type": 'koral:docGroup', |
| 2329 | 'operation' : 'operation:and', |
| 2330 | 'operands' : [ |
| 2331 | { |
| 2332 | "@type": 'koral:doc', |
| 2333 | "key": 'pubDate', |
| 2334 | "match": 'match:eq', |
| 2335 | "value": '2014-12-05', |
| 2336 | "type": 'type:date' |
| 2337 | }, |
| 2338 | { |
| 2339 | "@type" : 'koral:doc', |
| 2340 | 'key' : 'foo', |
| 2341 | 'value' : 'bar' |
| 2342 | } |
| 2343 | ] |
| 2344 | } |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 2345 | ); |
| 2346 | |
| 2347 | // Wrap on root |
| 2348 | expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar"'); |
| 2349 | expect(vc.root().ldType()).toEqual('docGroup'); |
| 2350 | expect(vc.root().operation()).toEqual('and'); |
| 2351 | _orOn(vc.root()); |
| 2352 | expect(vc.root().ldType()).toEqual('docGroup'); |
| 2353 | expect(vc.root().operation()).toEqual('or'); |
| 2354 | |
| 2355 | expect(vc.root().getOperand(0).ldType()).toEqual('docGroup'); |
| 2356 | expect(vc.root().getOperand(0).operation()).toEqual('and'); |
| 2357 | }); |
| 2358 | |
| 2359 | it('should add on root (case "and")', function () { |
Nils Diewald | 6283d69 | 2015-04-23 20:32:53 +0000 | [diff] [blame] | 2360 | var vc = vcClass.create().fromJson( |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 2361 | { |
| 2362 | "@type": 'koral:doc', |
| 2363 | "key": 'pubDate', |
| 2364 | "match": 'match:eq', |
| 2365 | "value": '2014-12-05', |
| 2366 | "type": 'type:date' |
| 2367 | } |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 2368 | ); |
| 2369 | |
| 2370 | expect(vc.toQuery()).toEqual('pubDate in 2014-12-05'); |
| 2371 | expect(vc.root().ldType()).toEqual('doc'); |
| 2372 | expect(vc.root().key()).toEqual('pubDate'); |
| 2373 | expect(vc.root().value()).toEqual('2014-12-05'); |
| 2374 | |
| 2375 | // Wrap on root |
| 2376 | _andOn(vc.root()); |
| 2377 | expect(vc.root().ldType()).toEqual('docGroup'); |
| 2378 | expect(vc.root().operation()).toEqual('and'); |
| 2379 | }); |
| 2380 | |
| 2381 | it('should add on root (case "or")', function () { |
Nils Diewald | 6283d69 | 2015-04-23 20:32:53 +0000 | [diff] [blame] | 2382 | var vc = vcClass.create().fromJson( |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 2383 | { |
| 2384 | "@type": 'koral:doc', |
| 2385 | "key": 'pubDate', |
| 2386 | "match": 'match:eq', |
| 2387 | "value": '2014-12-05', |
| 2388 | "type": 'type:date' |
| 2389 | } |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 2390 | ); |
| 2391 | |
| 2392 | expect(vc.toQuery()).toEqual('pubDate in 2014-12-05'); |
| 2393 | expect(vc.root().key()).toEqual('pubDate'); |
| 2394 | expect(vc.root().value()).toEqual('2014-12-05'); |
| 2395 | |
| 2396 | // Wrap on root |
| 2397 | _orOn(vc.root()); |
| 2398 | expect(vc.root().ldType()).toEqual('docGroup'); |
| 2399 | expect(vc.root().operation()).toEqual('or'); |
| 2400 | }); |
| 2401 | |
| 2402 | it('should support multiple sub groups per group', function () { |
Nils Diewald | 6283d69 | 2015-04-23 20:32:53 +0000 | [diff] [blame] | 2403 | var vc = vcClass.create().fromJson( |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 2404 | { |
| 2405 | "@type": 'koral:docGroup', |
| 2406 | 'operation' : 'operation:or', |
| 2407 | 'operands' : [ |
| 2408 | { |
| 2409 | "@type": 'koral:docGroup', |
| 2410 | 'operation' : 'operation:and', |
| 2411 | 'operands' : [ |
| 2412 | { |
| 2413 | "@type": 'koral:doc', |
| 2414 | "key": 'title', |
| 2415 | "value": 't1', |
| 2416 | }, |
| 2417 | { |
| 2418 | "@type" : 'koral:doc', |
| 2419 | 'key' : 'title', |
| 2420 | 'value' : 't2' |
| 2421 | } |
| 2422 | ] |
| 2423 | }, |
| 2424 | { |
| 2425 | "@type": 'koral:docGroup', |
| 2426 | 'operation' : 'operation:and', |
| 2427 | 'operands' : [ |
| 2428 | { |
| 2429 | "@type": 'koral:doc', |
| 2430 | "key": 'title', |
| 2431 | "value": 't3', |
| 2432 | }, |
| 2433 | { |
| 2434 | "@type" : 'koral:doc', |
| 2435 | 'key' : 'title', |
| 2436 | 'value' : 't4' |
| 2437 | } |
| 2438 | ] |
| 2439 | } |
| 2440 | ] |
| 2441 | } |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 2442 | ); |
| 2443 | expect(vc.toQuery()).toEqual( |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 2444 | '(title = "t1" & title = "t2") | ' + |
| 2445 | '(title = "t3" & title = "t4")' |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 2446 | ); |
| 2447 | expect(vc.root().operation()).toEqual('or'); |
| 2448 | expect(vc.root().getOperand(0).toQuery()).toEqual('title = "t1" & title = "t2"'); |
| 2449 | expect(vc.root().getOperand(1).toQuery()).toEqual('title = "t3" & title = "t4"'); |
| 2450 | |
| 2451 | _andOn(vc.root()); |
| 2452 | |
| 2453 | expect(vc.root().operation()).toEqual('and'); |
| 2454 | expect(vc.root().getOperand(0).ldType()).toEqual('docGroup'); |
| 2455 | expect(vc.root().getOperand(1).ldType()).toEqual('non'); |
| 2456 | }); |
| 2457 | }); |
| 2458 | |
Nils Diewald | 6283d69 | 2015-04-23 20:32:53 +0000 | [diff] [blame] | 2459 | |
| 2460 | describe('KorAP.Rewrite', function () { |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 2461 | it('should be initializable', function () { |
| 2462 | var rewrite = rewriteClass.create({ |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 2463 | "@type" : "koral:rewrite", |
| 2464 | "operation" : "operation:modification", |
| 2465 | "src" : "querySerializer", |
| 2466 | "scope" : "tree" |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 2467 | }); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 2468 | expect(rewrite.toString()).toEqual('Modification of "tree" by "querySerializer"'); |
| 2469 | }); |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 2470 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 2471 | it('should be deserialized by docs', function () { |
| 2472 | var doc = docClass.create( |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 2473 | undefined, |
| 2474 | { |
| 2475 | "@type":"koral:doc", |
| 2476 | "key":"Titel", |
| 2477 | "value":"Baum", |
| 2478 | "match":"match:eq" |
| 2479 | }); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 2480 | |
| 2481 | expect(doc.element().classList.contains('doc')).toBeTruthy(); |
| 2482 | expect(doc.element().classList.contains('rewritten')).toBe(false); |
| 2483 | |
| 2484 | doc = docClass.create( |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 2485 | undefined, |
| 2486 | { |
| 2487 | "@type":"koral:doc", |
| 2488 | "key":"Titel", |
| 2489 | "value":"Baum", |
| 2490 | "match":"match:eq", |
| 2491 | "rewrites" : [ |
| 2492 | { |
| 2493 | "@type" : "koral:rewrite", |
| 2494 | "operation" : "operation:modification", |
| 2495 | "src" : "querySerializer", |
| 2496 | "scope" : "tree" |
| 2497 | } |
| 2498 | ] |
| 2499 | }); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 2500 | |
| 2501 | expect(doc.element().classList.contains('doc')).toBeTruthy(); |
| 2502 | expect(doc.element().classList.contains('rewritten')).toBeTruthy(); |
| 2503 | }); |
Nils Diewald | 6283d69 | 2015-04-23 20:32:53 +0000 | [diff] [blame] | 2504 | |
Akron | 76c3dd6 | 2018-05-29 20:58:27 +0200 | [diff] [blame] | 2505 | it('should be described in a title attribute', function () { |
| 2506 | |
| 2507 | doc = docClass.create( |
| 2508 | undefined, |
| 2509 | { |
| 2510 | "@type":"koral:doc", |
| 2511 | "key":"Titel", |
| 2512 | "value":"Baum", |
| 2513 | "match":"match:eq", |
| 2514 | "rewrites" : [ |
| 2515 | { |
| 2516 | "@type" : "koral:rewrite", |
| 2517 | "operation" : "operation:modification", |
| 2518 | "src" : "querySerializer", |
| 2519 | "scope" : "tree" |
| 2520 | }, |
| 2521 | { |
| 2522 | "@type" : "koral:rewrite", |
| 2523 | "operation" : "operation:injection", |
| 2524 | "src" : "me" |
| 2525 | } |
| 2526 | ] |
| 2527 | }); |
| 2528 | |
| 2529 | expect(doc.element().classList.contains('doc')).toBeTruthy(); |
| 2530 | expect(doc.element().classList.contains('rewritten')).toBeTruthy(); |
| 2531 | expect(doc.element().lastChild.getAttribute("title")).toEqual("querySerializer: tree (modification)\nme (injection)"); |
| 2532 | }); |
| 2533 | |
| 2534 | |
Nils Diewald | 6283d69 | 2015-04-23 20:32:53 +0000 | [diff] [blame] | 2535 | xit('should be deserialized by docGroups', function () { |
| 2536 | var docGroup = docGroupClass.create( |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 2537 | undefined, |
| 2538 | { |
| 2539 | "@type" : "koral:docGroup", |
| 2540 | "operation" : "operation:or", |
| 2541 | "operands" : [ |
| 2542 | { |
| 2543 | "@type" : "doc", |
| 2544 | "key" : "pubDate", |
| 2545 | "type" : "type:date", |
| 2546 | "value" : "2014-12-05" |
| 2547 | }, |
| 2548 | { |
| 2549 | "@type" : "doc", |
| 2550 | "key" : "pubDate", |
| 2551 | "type" : "type:date", |
| 2552 | "value" : "2014-12-06" |
| 2553 | } |
| 2554 | ], |
| 2555 | "rewrites" : [ |
| 2556 | { |
| 2557 | "@type" : "koral:rewrite", |
| 2558 | "operation" : "operation:modification", |
| 2559 | "src" : "querySerializer", |
| 2560 | "scope" : "tree" |
| 2561 | } |
| 2562 | ] |
| 2563 | } |
Nils Diewald | 6283d69 | 2015-04-23 20:32:53 +0000 | [diff] [blame] | 2564 | ); |
| 2565 | |
| 2566 | expect(doc.element().classList.contains('docgroup')).toBeTruthy(); |
| 2567 | expect(doc.element().classList.contains('rewritten')).toBe(false); |
| 2568 | }); |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 2569 | }); |
Nils Diewald | f0c4f11 | 2015-05-05 12:56:59 +0000 | [diff] [blame] | 2570 | |
| 2571 | describe('KorAP.stringValue', function () { |
| 2572 | it('should be initializable', function () { |
| 2573 | var sv = stringValClass.create(); |
| 2574 | expect(sv.regex()).toBe(false); |
| 2575 | expect(sv.value()).toBe(''); |
Nils Diewald | c4c4b83 | 2015-05-05 16:00:08 +0000 | [diff] [blame] | 2576 | |
| 2577 | sv = stringValClass.create('Baum'); |
| 2578 | expect(sv.regex()).toBe(false); |
| 2579 | expect(sv.value()).toBe('Baum'); |
| 2580 | |
| 2581 | sv = stringValClass.create('Baum', false); |
| 2582 | expect(sv.regex()).toBe(false); |
| 2583 | expect(sv.value()).toBe('Baum'); |
| 2584 | |
| 2585 | sv = stringValClass.create('Baum', true); |
| 2586 | expect(sv.regex()).toBe(true); |
| 2587 | expect(sv.value()).toBe('Baum'); |
| 2588 | }); |
| 2589 | |
| 2590 | it('should be modifiable', function () { |
| 2591 | var sv = stringValClass.create(); |
| 2592 | expect(sv.regex()).toBe(false); |
| 2593 | expect(sv.value()).toBe(''); |
| 2594 | |
| 2595 | expect(sv.value('Baum')).toBe('Baum'); |
| 2596 | expect(sv.value()).toBe('Baum'); |
| 2597 | |
| 2598 | expect(sv.regex(true)).toBe(true); |
| 2599 | expect(sv.regex()).toBe(true); |
| 2600 | }); |
| 2601 | |
| 2602 | it('should have a toggleble regex value', function () { |
| 2603 | var sv = stringValClass.create(); |
Nils Diewald | 7991a3f | 2015-05-19 14:12:37 +0000 | [diff] [blame] | 2604 | |
| 2605 | expect(sv.element().firstChild.value).toBe(''); |
| 2606 | sv.element().firstChild.value = 'der' |
| 2607 | expect(sv.element().firstChild.value).toBe('der'); |
| 2608 | |
Nils Diewald | c4c4b83 | 2015-05-05 16:00:08 +0000 | [diff] [blame] | 2609 | expect(sv.regex()).toBe(false); |
| 2610 | |
| 2611 | sv.toggleRegex(); |
Nils Diewald | 7991a3f | 2015-05-19 14:12:37 +0000 | [diff] [blame] | 2612 | expect(sv.element().firstChild.value).toBe('der'); |
Nils Diewald | c4c4b83 | 2015-05-05 16:00:08 +0000 | [diff] [blame] | 2613 | expect(sv.regex()).toBe(true); |
Nils Diewald | 7991a3f | 2015-05-19 14:12:37 +0000 | [diff] [blame] | 2614 | sv.element().firstChild.value = 'derbe' |
Nils Diewald | c4c4b83 | 2015-05-05 16:00:08 +0000 | [diff] [blame] | 2615 | |
| 2616 | sv.toggleRegex(); |
| 2617 | expect(sv.regex()).toBe(false); |
Nils Diewald | 7991a3f | 2015-05-19 14:12:37 +0000 | [diff] [blame] | 2618 | expect(sv.element().firstChild.value).toBe('derbe'); |
Nils Diewald | c4c4b83 | 2015-05-05 16:00:08 +0000 | [diff] [blame] | 2619 | }); |
| 2620 | |
| 2621 | it('should have an element', function () { |
| 2622 | var sv = stringValClass.create('der'); |
| 2623 | expect(sv.element().nodeName).toBe('DIV'); |
| 2624 | expect(sv.element().firstChild.nodeName).toBe('INPUT'); |
| 2625 | expect(sv.element().firstChild.value).toBe('der'); |
| 2626 | }); |
| 2627 | |
| 2628 | it('should have a classed element', function () { |
| 2629 | var sv = stringValClass.create(); |
Nils Diewald | c4c4b83 | 2015-05-05 16:00:08 +0000 | [diff] [blame] | 2630 | expect(sv.element().classList.contains('regex')).toBe(false); |
| 2631 | expect(sv.regex()).toBe(false); |
| 2632 | sv.toggleRegex(); |
| 2633 | expect(sv.element().classList.contains('regex')).toBe(true); |
| 2634 | }); |
| 2635 | |
| 2636 | it('should be storable', function () { |
| 2637 | var sv = stringValClass.create(); |
| 2638 | var count = 1; |
| 2639 | sv.store = function (value, regex) { |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 2640 | expect(regex).toBe(true); |
| 2641 | expect(value).toBe('tree'); |
Nils Diewald | c4c4b83 | 2015-05-05 16:00:08 +0000 | [diff] [blame] | 2642 | }; |
| 2643 | sv.regex(true); |
| 2644 | sv.value('tree'); |
| 2645 | sv.element().lastChild.click(); |
Nils Diewald | f0c4f11 | 2015-05-05 12:56:59 +0000 | [diff] [blame] | 2646 | }); |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 2647 | |
Akron | b19803c | 2018-08-16 16:39:42 +0200 | [diff] [blame] | 2648 | it('should have a disableoption for regex', function () { |
| 2649 | var sv = stringValClass.create(undefined, undefined, true); |
| 2650 | var svE = sv.element(); |
| 2651 | expect(svE.children.length).toEqual(2); |
| 2652 | |
| 2653 | sv = stringValClass.create(undefined, undefined, false); |
| 2654 | svE = sv.element(); |
| 2655 | expect(svE.children.length).toEqual(1); |
| 2656 | }); |
| 2657 | |
Nils Diewald | f0c4f11 | 2015-05-05 12:56:59 +0000 | [diff] [blame] | 2658 | }); |
Akron | e4961b1 | 2017-05-10 21:04:46 +0200 | [diff] [blame] | 2659 | |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 2660 | describe('KorAP.VC.Menu', function () { |
Akron | e65a88a | 2018-04-05 19:14:20 +0200 | [diff] [blame] | 2661 | |
| 2662 | var vc; |
| 2663 | |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 2664 | it('should be initializable', function () { |
| 2665 | |
Akron | e65a88a | 2018-04-05 19:14:20 +0200 | [diff] [blame] | 2666 | vc = vcClass.create([ |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 2667 | ['a', 'text'], |
| 2668 | ['b', 'string'], |
| 2669 | ['c', 'date'] |
| 2670 | ]).fromJson(); |
Akron | adab5e5 | 2018-08-20 13:50:53 +0200 | [diff] [blame] | 2671 | expect(vc.builder().firstChild.classList.contains('unspecified')).toBeTruthy(); |
| 2672 | expect(vc.builder().firstChild.firstChild.tagName).toEqual('SPAN'); |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 2673 | |
| 2674 | // Click on unspecified |
Akron | adab5e5 | 2018-08-20 13:50:53 +0200 | [diff] [blame] | 2675 | vc.builder().firstChild.firstChild.click(); |
| 2676 | expect(vc.builder().firstChild.firstChild.tagName).toEqual('UL'); |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 2677 | |
Akron | adab5e5 | 2018-08-20 13:50:53 +0200 | [diff] [blame] | 2678 | var list = vc.builder().firstChild.firstChild; |
Akron | 3ad4694 | 2018-08-22 16:47:14 +0200 | [diff] [blame] | 2679 | expect(list.getElementsByTagName("LI")[0].innerText).toEqual('referTo'); |
| 2680 | expect(list.getElementsByTagName("LI")[1].innerText).toEqual('a'); |
| 2681 | expect(list.getElementsByTagName("LI")[2].innerText).toEqual('b'); |
| 2682 | expect(list.getElementsByTagName("LI")[3].innerText).toEqual('c'); |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 2683 | |
| 2684 | vc = vcClass.create([ |
| 2685 | ['d', 'text'], |
| 2686 | ['e', 'string'], |
| 2687 | ['f', 'date'] |
| 2688 | ]).fromJson(); |
Akron | adab5e5 | 2018-08-20 13:50:53 +0200 | [diff] [blame] | 2689 | expect(vc.builder().firstChild.classList.contains('unspecified')).toBeTruthy(); |
| 2690 | expect(vc.builder().firstChild.firstChild.tagName).toEqual('SPAN'); |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 2691 | |
| 2692 | // Click on unspecified |
Akron | adab5e5 | 2018-08-20 13:50:53 +0200 | [diff] [blame] | 2693 | vc.builder().firstChild.firstChild.click(); |
| 2694 | expect(vc.builder().firstChild.firstChild.tagName).toEqual('UL'); |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 2695 | |
Akron | adab5e5 | 2018-08-20 13:50:53 +0200 | [diff] [blame] | 2696 | list = vc.builder().firstChild.firstChild; |
Akron | 3ad4694 | 2018-08-22 16:47:14 +0200 | [diff] [blame] | 2697 | expect(list.getElementsByTagName("LI")[0].innerText).toEqual('referTo'); |
| 2698 | expect(list.getElementsByTagName("LI")[1].innerText).toEqual('d'); |
| 2699 | expect(list.getElementsByTagName("LI")[2].innerText).toEqual('e'); |
| 2700 | expect(list.getElementsByTagName("LI")[3].innerText).toEqual('f'); |
Akron | 31d8994 | 2018-04-06 16:44:51 +0200 | [diff] [blame] | 2701 | // blur |
| 2702 | document.body.click(); |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 2703 | }); |
Akron | e65a88a | 2018-04-05 19:14:20 +0200 | [diff] [blame] | 2704 | |
| 2705 | // Reinitialize to make tests stable |
| 2706 | vc = vcClass.create([ |
| 2707 | ['d', 'text'], |
| 2708 | ['e', 'string'], |
| 2709 | ['f', 'date'] |
| 2710 | ]).fromJson(); |
| 2711 | |
| 2712 | it('should be clickable on key', function () { |
Akron | 31d8994 | 2018-04-06 16:44:51 +0200 | [diff] [blame] | 2713 | // Click on unspecified |
Akron | adab5e5 | 2018-08-20 13:50:53 +0200 | [diff] [blame] | 2714 | vc.builder().firstChild.firstChild.click(); |
Akron | e65a88a | 2018-04-05 19:14:20 +0200 | [diff] [blame] | 2715 | // Click on "d" |
Akron | adab5e5 | 2018-08-20 13:50:53 +0200 | [diff] [blame] | 2716 | vc.builder().firstChild.firstChild.getElementsByTagName("LI")[1].click(); |
| 2717 | expect(vc.builder().firstChild.firstChild.tagName).toEqual('SPAN'); |
| 2718 | expect(vc.builder().firstChild.firstChild.innerText).toEqual('d'); |
| 2719 | expect(vc.builder().firstChild.children[1].innerText).toEqual('eq'); |
| 2720 | expect(vc.builder().firstChild.children[1].getAttribute('data-type')).toEqual('text'); |
Akron | 31d8994 | 2018-04-06 16:44:51 +0200 | [diff] [blame] | 2721 | // blur |
| 2722 | document.body.click(); |
Akron | e65a88a | 2018-04-05 19:14:20 +0200 | [diff] [blame] | 2723 | }); |
| 2724 | |
Akron | 31d8994 | 2018-04-06 16:44:51 +0200 | [diff] [blame] | 2725 | it('should be clickable on operation for text', function () { |
| 2726 | // Click on "d" (or unspecified) |
Akron | adab5e5 | 2018-08-20 13:50:53 +0200 | [diff] [blame] | 2727 | vc.builder().firstChild.firstChild.click(); |
Akron | 31d8994 | 2018-04-06 16:44:51 +0200 | [diff] [blame] | 2728 | |
| 2729 | // Choose "d" |
Akron | adab5e5 | 2018-08-20 13:50:53 +0200 | [diff] [blame] | 2730 | vc.builder().firstChild.firstChild.getElementsByTagName("LI")[1].click(); |
Akron | 31d8994 | 2018-04-06 16:44:51 +0200 | [diff] [blame] | 2731 | |
| 2732 | // Click on matchop |
Akron | adab5e5 | 2018-08-20 13:50:53 +0200 | [diff] [blame] | 2733 | vc.builder().firstChild.children[1].click(); |
Akron | 31d8994 | 2018-04-06 16:44:51 +0200 | [diff] [blame] | 2734 | |
Akron | adab5e5 | 2018-08-20 13:50:53 +0200 | [diff] [blame] | 2735 | expect(vc.builder().firstChild.children[1].tagName).toEqual('UL'); |
Akron | 31d8994 | 2018-04-06 16:44:51 +0200 | [diff] [blame] | 2736 | |
Akron | adab5e5 | 2018-08-20 13:50:53 +0200 | [diff] [blame] | 2737 | var ul = vc.builder().firstChild.children[1]; |
Akron | e65a88a | 2018-04-05 19:14:20 +0200 | [diff] [blame] | 2738 | expect(ul.getElementsByTagName('li')[0].innerText).toEqual("eq"); |
| 2739 | expect(ul.getElementsByTagName('li')[1].innerText).toEqual("ne"); |
| 2740 | expect(ul.getElementsByTagName('li')[2].innerText).toEqual("contains"); |
| 2741 | expect(ul.getElementsByTagName('li')[3].innerText).toEqual("containsnot"); |
| 2742 | expect(ul.getElementsByTagName('li')[4]).toBeUndefined(); |
Akron | 31d8994 | 2018-04-06 16:44:51 +0200 | [diff] [blame] | 2743 | |
| 2744 | // Choose "contains" |
| 2745 | ul.getElementsByTagName('li')[2].click(); |
Akron | adab5e5 | 2018-08-20 13:50:53 +0200 | [diff] [blame] | 2746 | expect(vc.builder().firstChild.children[1].tagName).toEqual("SPAN"); |
| 2747 | expect(vc.builder().firstChild.children[1].innerText).toEqual("contains"); |
Akron | 31d8994 | 2018-04-06 16:44:51 +0200 | [diff] [blame] | 2748 | // blur |
| 2749 | document.body.click(); |
Akron | e65a88a | 2018-04-05 19:14:20 +0200 | [diff] [blame] | 2750 | }) |
Akron | 31d8994 | 2018-04-06 16:44:51 +0200 | [diff] [blame] | 2751 | |
| 2752 | it('should be clickable on operation for string', function () { |
| 2753 | // Click on "d" (or unspecified) |
Akron | adab5e5 | 2018-08-20 13:50:53 +0200 | [diff] [blame] | 2754 | vc.builder().firstChild.firstChild.click(); |
Akron | 31d8994 | 2018-04-06 16:44:51 +0200 | [diff] [blame] | 2755 | |
| 2756 | // Choose "e" |
Akron | adab5e5 | 2018-08-20 13:50:53 +0200 | [diff] [blame] | 2757 | vc.builder().firstChild.firstChild.getElementsByTagName("LI")[2].click(); |
| 2758 | |
Akron | 31d8994 | 2018-04-06 16:44:51 +0200 | [diff] [blame] | 2759 | // As a consequence the matchoperator may no longer |
| 2760 | // be valid and needs to be re-evaluated |
Akron | adab5e5 | 2018-08-20 13:50:53 +0200 | [diff] [blame] | 2761 | var fc = vc.builder().firstChild; |
Akron | 31d8994 | 2018-04-06 16:44:51 +0200 | [diff] [blame] | 2762 | expect(fc.firstChild.tagName).toEqual('SPAN'); |
| 2763 | expect(fc.firstChild.innerText).toEqual('e'); |
| 2764 | expect(fc.children[1].innerText).toEqual('eq'); |
| 2765 | expect(fc.children[1].getAttribute('data-type')).toEqual('string'); |
| 2766 | |
Akron | adab5e5 | 2018-08-20 13:50:53 +0200 | [diff] [blame] | 2767 | vc.builder().firstChild.children[1].click(); |
Akron | 31d8994 | 2018-04-06 16:44:51 +0200 | [diff] [blame] | 2768 | |
Akron | adab5e5 | 2018-08-20 13:50:53 +0200 | [diff] [blame] | 2769 | expect(vc.builder().firstChild.children[1].tagName).toEqual('UL'); |
Akron | 31d8994 | 2018-04-06 16:44:51 +0200 | [diff] [blame] | 2770 | |
Akron | adab5e5 | 2018-08-20 13:50:53 +0200 | [diff] [blame] | 2771 | var ul = vc.builder().firstChild.children[1]; |
Akron | 31d8994 | 2018-04-06 16:44:51 +0200 | [diff] [blame] | 2772 | expect(ul.getElementsByTagName('li')[0].innerText).toEqual("eq"); |
| 2773 | expect(ul.getElementsByTagName('li')[1].innerText).toEqual("ne"); |
| 2774 | expect(ul.getElementsByTagName('li')[2]).toBeUndefined(); |
| 2775 | |
| 2776 | // Choose "ne" |
| 2777 | ul.getElementsByTagName('li')[1].click(); |
Akron | adab5e5 | 2018-08-20 13:50:53 +0200 | [diff] [blame] | 2778 | expect(vc.builder().firstChild.children[1].tagName).toEqual("SPAN"); |
| 2779 | expect(vc.builder().firstChild.children[1].innerText).toEqual("ne"); |
Akron | 8db5e3a | 2018-05-28 19:25:26 +0200 | [diff] [blame] | 2780 | |
| 2781 | // Click on text |
Akron | ebc9666 | 2018-08-29 17:36:20 +0200 | [diff] [blame] | 2782 | expect(vc.builder().firstChild.children[2].innerText).toEqual(KorAP.Locale.EMPTY); |
| 2783 | expect(vc.builder().firstChild.children[2].classList.contains('unspecified')).toEqual(true); |
Akron | adab5e5 | 2018-08-20 13:50:53 +0200 | [diff] [blame] | 2784 | vc.builder().firstChild.children[2].click(); |
Akron | 8db5e3a | 2018-05-28 19:25:26 +0200 | [diff] [blame] | 2785 | |
| 2786 | // Blur text element |
Akron | adab5e5 | 2018-08-20 13:50:53 +0200 | [diff] [blame] | 2787 | expect(vc.builder().firstChild.children[2].firstChild.value).toEqual(''); |
Akron | 8db5e3a | 2018-05-28 19:25:26 +0200 | [diff] [blame] | 2788 | |
Akron | 31d8994 | 2018-04-06 16:44:51 +0200 | [diff] [blame] | 2789 | // blur |
| 2790 | document.body.click(); |
| 2791 | }); |
| 2792 | |
| 2793 | it('should be clickable on operation for date', function () { |
| 2794 | |
| 2795 | // Replay matchop check - so it's guaranteed that "ne" is chosen |
| 2796 | // Click on "e" (or unspecified) |
Akron | adab5e5 | 2018-08-20 13:50:53 +0200 | [diff] [blame] | 2797 | vc.builder().firstChild.firstChild.click(); |
Akron | 31d8994 | 2018-04-06 16:44:51 +0200 | [diff] [blame] | 2798 | // Rechoose "e" |
Akron | adab5e5 | 2018-08-20 13:50:53 +0200 | [diff] [blame] | 2799 | vc.builder().firstChild.firstChild.getElementsByTagName("LI")[1].click(); |
Akron | 31d8994 | 2018-04-06 16:44:51 +0200 | [diff] [blame] | 2800 | // Click on matchop |
Akron | adab5e5 | 2018-08-20 13:50:53 +0200 | [diff] [blame] | 2801 | vc.builder().firstChild.children[1].click(); |
Akron | 31d8994 | 2018-04-06 16:44:51 +0200 | [diff] [blame] | 2802 | // Choose "ne" |
Akron | adab5e5 | 2018-08-20 13:50:53 +0200 | [diff] [blame] | 2803 | vc.builder().firstChild.children[1].getElementsByTagName('li')[1].click(); |
| 2804 | expect(vc.builder().firstChild.children[1].innerText).toEqual("ne"); |
Akron | 31d8994 | 2018-04-06 16:44:51 +0200 | [diff] [blame] | 2805 | |
| 2806 | // Click on "e" |
Akron | adab5e5 | 2018-08-20 13:50:53 +0200 | [diff] [blame] | 2807 | vc.builder().firstChild.firstChild.click(); |
Akron | 31d8994 | 2018-04-06 16:44:51 +0200 | [diff] [blame] | 2808 | // Choose "f" |
Akron | adab5e5 | 2018-08-20 13:50:53 +0200 | [diff] [blame] | 2809 | vc.builder().firstChild.firstChild.getElementsByTagName("LI")[3].click(); |
Akron | 31d8994 | 2018-04-06 16:44:51 +0200 | [diff] [blame] | 2810 | |
| 2811 | // 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] | 2812 | var fc = vc.builder().firstChild; |
Akron | 31d8994 | 2018-04-06 16:44:51 +0200 | [diff] [blame] | 2813 | expect(fc.firstChild.tagName).toEqual('SPAN'); |
| 2814 | expect(fc.firstChild.innerText).toEqual('f'); |
| 2815 | expect(fc.children[1].innerText).toEqual('ne'); |
| 2816 | // blur |
| 2817 | document.body.click(); |
| 2818 | }); |
Akron | ddc98a7 | 2018-04-06 17:33:52 +0200 | [diff] [blame] | 2819 | |
| 2820 | |
| 2821 | // Check json deserialization |
| 2822 | it('should be initializable', function () { |
| 2823 | vc = vcClass.create([ |
| 2824 | ['a', 'text'], |
| 2825 | ['b', 'string'], |
| 2826 | ['c', 'date'] |
| 2827 | ]).fromJson({ |
| 2828 | "@type" : "koral:doc", |
| 2829 | "key":"a", |
| 2830 | "value":"Baum" |
| 2831 | }); |
| 2832 | |
Akron | adab5e5 | 2018-08-20 13:50:53 +0200 | [diff] [blame] | 2833 | expect(vc.builder().firstChild.children[1].getAttribute('data-type')).toEqual('text'); |
Akron | ddc98a7 | 2018-04-06 17:33:52 +0200 | [diff] [blame] | 2834 | }); |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 2835 | }); |
| 2836 | |
| 2837 | |
Akron | e4961b1 | 2017-05-10 21:04:46 +0200 | [diff] [blame] | 2838 | // Check prefix |
| 2839 | describe('KorAP.VC.Prefix', function () { |
| 2840 | |
| 2841 | it('should be initializable', function () { |
| 2842 | var p = prefixClass.create(); |
| 2843 | expect(p.element().classList.contains('pref')).toBeTruthy(); |
| 2844 | expect(p.isSet()).not.toBeTruthy(); |
| 2845 | }); |
| 2846 | |
| 2847 | |
| 2848 | it('should be clickable', function () { |
| 2849 | var vc = vcClass.create([ |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 2850 | ['a', null], |
| 2851 | ['b', null], |
| 2852 | ['c', null] |
| 2853 | ]).fromJson(); |
Akron | adab5e5 | 2018-08-20 13:50:53 +0200 | [diff] [blame] | 2854 | expect(vc.builder().firstChild.classList.contains('unspecified')).toBeTruthy(); |
Akron | e4961b1 | 2017-05-10 21:04:46 +0200 | [diff] [blame] | 2855 | |
| 2856 | // This should open up the menu |
Akron | adab5e5 | 2018-08-20 13:50:53 +0200 | [diff] [blame] | 2857 | vc.builder().firstChild.firstChild.click(); |
| 2858 | expect(vc.builder().firstChild.firstChild.tagName).toEqual('UL'); |
Akron | e4961b1 | 2017-05-10 21:04:46 +0200 | [diff] [blame] | 2859 | |
| 2860 | KorAP._vcKeyMenu._prefix.clear(); |
| 2861 | KorAP._vcKeyMenu._prefix.add('x'); |
| 2862 | |
Akron | adab5e5 | 2018-08-20 13:50:53 +0200 | [diff] [blame] | 2863 | var prefElement = vc.builder().querySelector('span.pref'); |
Akron | e4961b1 | 2017-05-10 21:04:46 +0200 | [diff] [blame] | 2864 | expect(prefElement.innerText).toEqual('x'); |
| 2865 | |
| 2866 | // This should add key 'x' to VC |
| 2867 | prefElement.click(); |
| 2868 | |
Akron | adab5e5 | 2018-08-20 13:50:53 +0200 | [diff] [blame] | 2869 | expect(vc.builder().firstChild.classList.contains('doc')).toBeTruthy(); |
| 2870 | expect(vc.builder().firstChild.firstChild.className).toEqual('key'); |
| 2871 | expect(vc.builder().firstChild.firstChild.innerText).toEqual('x'); |
Akron | e4961b1 | 2017-05-10 21:04:46 +0200 | [diff] [blame] | 2872 | }); |
| 2873 | }); |
Akron | 68d2832 | 2018-08-27 15:02:42 +0200 | [diff] [blame] | 2874 | |
Akron | 889ec29 | 2018-11-19 17:56:01 +0100 | [diff] [blame] | 2875 | // Check fragment handling for corpusByMatch helper |
Akron | 68d2832 | 2018-08-27 15:02:42 +0200 | [diff] [blame] | 2876 | describe('KorAP.VC.Fragment', function () { |
| 2877 | it('should be initializable', function () { |
| 2878 | var f = fragmentClass.create(); |
| 2879 | var e = f.element(); |
| 2880 | expect(e.classList.contains('vc')).toBeTruthy(); |
| 2881 | expect(e.classList.contains('fragment')).toBeTruthy(); |
Akron | d45a170 | 2018-11-19 18:15:17 +0100 | [diff] [blame] | 2882 | expect(e.firstChild.children.length).toEqual(0); |
Akron | 68d2832 | 2018-08-27 15:02:42 +0200 | [diff] [blame] | 2883 | }); |
| 2884 | |
| 2885 | it('should be expansable', function () { |
| 2886 | var f = fragmentClass.create(); |
| 2887 | f.add("author", "Peter"); |
| 2888 | |
Akron | d45a170 | 2018-11-19 18:15:17 +0100 | [diff] [blame] | 2889 | var root = f.element().lastChild.firstChild; |
Akron | 68d2832 | 2018-08-27 15:02:42 +0200 | [diff] [blame] | 2890 | |
| 2891 | expect(root.classList.contains("doc")).toBeTruthy(); |
| 2892 | expect(root.children[0].tagName).toEqual("SPAN"); |
| 2893 | expect(root.children[0].textContent).toEqual("author"); |
| 2894 | expect(root.children[1].tagName).toEqual("SPAN"); |
| 2895 | expect(root.children[1].textContent).toEqual("eq"); |
| 2896 | expect(root.children[2].tagName).toEqual("SPAN"); |
| 2897 | expect(root.children[2].textContent).toEqual("Peter"); |
| 2898 | |
| 2899 | f.add("title", "Example"); |
| 2900 | |
Akron | d45a170 | 2018-11-19 18:15:17 +0100 | [diff] [blame] | 2901 | root = f.element().lastChild.firstChild; |
Akron | 68d2832 | 2018-08-27 15:02:42 +0200 | [diff] [blame] | 2902 | |
| 2903 | expect(root.classList.contains("docGroup")).toBeTruthy(); |
| 2904 | |
| 2905 | var doc = root.children[0]; |
| 2906 | |
| 2907 | expect(doc.children[0].tagName).toEqual("SPAN"); |
| 2908 | expect(doc.children[0].textContent).toEqual("author"); |
| 2909 | expect(doc.children[1].tagName).toEqual("SPAN"); |
| 2910 | expect(doc.children[1].textContent).toEqual("eq"); |
| 2911 | expect(doc.children[2].tagName).toEqual("SPAN"); |
| 2912 | expect(doc.children[2].textContent).toEqual("Peter"); |
| 2913 | |
| 2914 | doc = root.children[1]; |
| 2915 | |
| 2916 | expect(doc.children[0].tagName).toEqual("SPAN"); |
| 2917 | expect(doc.children[0].textContent).toEqual("title"); |
| 2918 | expect(doc.children[1].tagName).toEqual("SPAN"); |
| 2919 | expect(doc.children[1].textContent).toEqual("eq"); |
| 2920 | expect(doc.children[2].tagName).toEqual("SPAN"); |
| 2921 | expect(doc.children[2].textContent).toEqual("Example"); |
| 2922 | }); |
| 2923 | |
| 2924 | |
| 2925 | it('should be reducible', function () { |
| 2926 | var f = fragmentClass.create(); |
Akron | d45a170 | 2018-11-19 18:15:17 +0100 | [diff] [blame] | 2927 | expect(f.element().lastChild.children.length).toEqual(0); |
Akron | 889ec29 | 2018-11-19 17:56:01 +0100 | [diff] [blame] | 2928 | |
Akron | 68d2832 | 2018-08-27 15:02:42 +0200 | [diff] [blame] | 2929 | f.add("author", "Peter"); |
| 2930 | f.add("title", "Example"); |
| 2931 | |
Akron | d45a170 | 2018-11-19 18:15:17 +0100 | [diff] [blame] | 2932 | expect(f.element().lastChild.children.length).toEqual(1); |
Akron | 889ec29 | 2018-11-19 17:56:01 +0100 | [diff] [blame] | 2933 | |
Akron | d45a170 | 2018-11-19 18:15:17 +0100 | [diff] [blame] | 2934 | var root = f.element().lastChild.firstChild; |
Akron | 889ec29 | 2018-11-19 17:56:01 +0100 | [diff] [blame] | 2935 | |
Akron | 68d2832 | 2018-08-27 15:02:42 +0200 | [diff] [blame] | 2936 | expect(root.classList.contains("docGroup")).toBeTruthy(); |
| 2937 | |
| 2938 | expect(root.children.length).toEqual(2); |
| 2939 | |
| 2940 | f.remove("author","Peter"); |
| 2941 | |
Akron | d45a170 | 2018-11-19 18:15:17 +0100 | [diff] [blame] | 2942 | root = f.element().lastChild.firstChild; |
Akron | 68d2832 | 2018-08-27 15:02:42 +0200 | [diff] [blame] | 2943 | expect(root.classList.contains("doc")).toBeTruthy(); |
| 2944 | |
| 2945 | expect(root.children[0].tagName).toEqual("SPAN"); |
| 2946 | expect(root.children[0].textContent).toEqual("title"); |
| 2947 | expect(root.children[1].tagName).toEqual("SPAN"); |
| 2948 | expect(root.children[1].textContent).toEqual("eq"); |
| 2949 | expect(root.children[2].tagName).toEqual("SPAN"); |
| 2950 | expect(root.children[2].textContent).toEqual("Example"); |
Akron | 889ec29 | 2018-11-19 17:56:01 +0100 | [diff] [blame] | 2951 | |
| 2952 | f.remove("title","Example"); |
| 2953 | |
Akron | d45a170 | 2018-11-19 18:15:17 +0100 | [diff] [blame] | 2954 | expect(f.element().lastChild.children.length).toEqual(0); |
Akron | 68d2832 | 2018-08-27 15:02:42 +0200 | [diff] [blame] | 2955 | }); |
| 2956 | }); |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame] | 2957 | }); |