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