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