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