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