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