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"); |
Akron | 55a343b | 2018-04-06 19:57:36 +0200 | [diff] [blame] | 628 | expect(docGroup.getOperand(1).value()).toBeUndefined(); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 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 | }); |
Akron | 55a343b | 2018-04-06 19:57:36 +0200 | [diff] [blame] | 667 | |
| 668 | it('should be clickable', function () { |
| 669 | var vc = vcClass.create([ |
| 670 | ["pubDate", "date"] |
| 671 | ]); |
| 672 | expect(vc.toQuery()).toEqual(""); |
| 673 | expect(vc.element().firstChild.textContent).toEqual("⋯"); |
| 674 | vc.element().firstChild.firstChild.click(); |
| 675 | |
| 676 | // Click on pubDate |
| 677 | vc.element().firstChild.getElementsByTagName("LI")[0].click(); |
| 678 | |
| 679 | expect(vc.element().firstChild.firstChild.textContent).toEqual("pubDate"); |
| 680 | expect(vc.element().firstChild.children[1].getAttribute("data-type")).toEqual("date"); |
| 681 | }); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 682 | }); |
| 683 | |
| 684 | describe('KorAP.Doc element', function () { |
| 685 | it('should be initializable', function () { |
| 686 | var docElement = docClass.create(undefined, { |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 687 | "@type" : "koral:doc", |
| 688 | "key":"Titel", |
| 689 | "value":"Baum", |
| 690 | "match":"match:eq" |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 691 | }); |
| 692 | expect(docElement.key()).toEqual('Titel'); |
| 693 | expect(docElement.matchop()).toEqual('eq'); |
| 694 | expect(docElement.value()).toEqual('Baum'); |
| 695 | |
| 696 | var docE = docElement.element(); |
| 697 | expect(docE.children[0].firstChild.data).toEqual('Titel'); |
| 698 | expect(docE.children[1].firstChild.data).toEqual('eq'); |
| 699 | expect(docE.children[1].getAttribute('data-type')).toEqual('string'); |
| 700 | expect(docE.children[2].firstChild.data).toEqual('Baum'); |
| 701 | expect(docE.children[2].getAttribute('data-type')).toEqual('string'); |
| 702 | |
| 703 | expect(docElement.toJson()).toEqual(jasmine.objectContaining({ |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 704 | "@type" : "koral:doc", |
| 705 | "key":"Titel", |
| 706 | "value":"Baum", |
| 707 | "match":"match:eq" |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 708 | })); |
| 709 | }); |
| 710 | }); |
| 711 | |
| 712 | describe('KorAP.DocGroup element', function () { |
| 713 | it('should be initializable', function () { |
| 714 | |
| 715 | var docGroup = docGroupClass.create(undefined, { |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 716 | "@type" : "koral:docGroup", |
| 717 | "operation" : "operation:and", |
| 718 | "operands" : [ |
| 719 | { |
| 720 | "@type": 'koral:doc', |
| 721 | "key" : 'author', |
| 722 | "match": 'match:eq', |
| 723 | "value": 'Max Birkendale', |
| 724 | "type": 'type:string' |
| 725 | }, |
| 726 | { |
| 727 | "@type": 'koral:doc', |
| 728 | "key": 'pubDate', |
| 729 | "match": 'match:eq', |
| 730 | "value": '2014-12-05', |
| 731 | "type": 'type:date' |
| 732 | } |
| 733 | ] |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 734 | }); |
| 735 | |
| 736 | expect(docGroup.operation()).toEqual('and'); |
| 737 | var e = docGroup.element(); |
| 738 | expect(e.getAttribute('class')).toEqual('docGroup'); |
| 739 | expect(e.getAttribute('data-operation')).toEqual('and'); |
| 740 | |
| 741 | var first = e.children[0]; |
| 742 | expect(first.getAttribute('class')).toEqual('doc'); |
| 743 | expect(first.children[0].getAttribute('class')).toEqual('key'); |
| 744 | expect(first.children[1].getAttribute('class')).toEqual('match'); |
| 745 | expect(first.children[2].getAttribute('class')).toEqual('value'); |
| 746 | expect(first.children[2].getAttribute('data-type')).toEqual('string'); |
| 747 | expect(first.children[0].firstChild.data).toEqual('author'); |
| 748 | expect(first.children[1].firstChild.data).toEqual('eq'); |
| 749 | expect(first.children[2].firstChild.data).toEqual('Max Birkendale'); |
| 750 | |
| 751 | var second = e.children[1]; |
| 752 | expect(second.getAttribute('class')).toEqual('doc'); |
| 753 | expect(second.children[0].getAttribute('class')).toEqual('key'); |
| 754 | expect(second.children[1].getAttribute('class')).toEqual('match'); |
| 755 | expect(second.children[2].getAttribute('class')).toEqual('value'); |
| 756 | expect(second.children[2].getAttribute('data-type')).toEqual('date'); |
| 757 | expect(second.children[0].firstChild.data).toEqual('pubDate'); |
| 758 | expect(second.children[1].firstChild.data).toEqual('eq'); |
| 759 | expect(second.children[2].firstChild.data).toEqual('2014-12-05'); |
| 760 | }); |
| 761 | |
| 762 | it('should be deserializable with nested groups', function () { |
| 763 | var docGroup = docGroupClass.create(undefined, { |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 764 | "@type" : "koral:docGroup", |
| 765 | "operation" : "operation:or", |
| 766 | "operands" : [ |
| 767 | { |
| 768 | "@type": 'koral:doc', |
| 769 | "key" : 'author', |
| 770 | "match": 'match:eq', |
| 771 | "value": 'Max Birkendale', |
| 772 | "type": 'type:string' |
| 773 | }, |
| 774 | { |
| 775 | "@type" : "koral:docGroup", |
| 776 | "operation" : "operation:and", |
| 777 | "operands" : [ |
| 778 | { |
| 779 | "@type": 'koral:doc', |
| 780 | "key": 'pubDate', |
| 781 | "match": 'match:geq', |
| 782 | "value": '2014-05-12', |
| 783 | "type": 'type:date' |
| 784 | }, |
| 785 | { |
| 786 | "@type": 'koral:doc', |
| 787 | "key": 'pubDate', |
| 788 | "match": 'match:leq', |
| 789 | "value": '2014-12-05', |
| 790 | "type": 'type:date' |
| 791 | } |
| 792 | ] |
| 793 | } |
| 794 | ] |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 795 | }); |
| 796 | |
| 797 | expect(docGroup.operation()).toEqual('or'); |
| 798 | var e = docGroup.element(); |
| 799 | expect(e.getAttribute('class')).toEqual('docGroup'); |
| 800 | expect(e.getAttribute('data-operation')).toEqual('or'); |
| 801 | |
| 802 | expect(e.children[0].getAttribute('class')).toEqual('doc'); |
| 803 | var docop = e.children[0].lastChild; |
Akron | 0b489ad | 2018-02-02 16:49:32 +0100 | [diff] [blame] | 804 | expect(docop.getAttribute('class')).toEqual('operators button-group'); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 805 | expect(docop.children[0].getAttribute('class')).toEqual('and'); |
| 806 | expect(docop.children[1].getAttribute('class')).toEqual('or'); |
| 807 | expect(docop.children[2].getAttribute('class')).toEqual('delete'); |
| 808 | |
| 809 | expect(e.children[1].getAttribute('class')).toEqual('docGroup'); |
| 810 | expect(e.children[1].getAttribute('data-operation')).toEqual('and'); |
| 811 | |
| 812 | // This and-operation can be "or"ed or "delete"d |
| 813 | var secop = e.children[1].children[2]; |
Akron | 0b489ad | 2018-02-02 16:49:32 +0100 | [diff] [blame] | 814 | expect(secop.getAttribute('class')).toEqual('operators button-group'); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 815 | expect(secop.children[0].getAttribute('class')).toEqual('or'); |
| 816 | expect(secop.children[1].getAttribute('class')).toEqual('delete'); |
| 817 | |
| 818 | // This or-operation can be "and"ed or "delete"d |
Akron | 0b489ad | 2018-02-02 16:49:32 +0100 | [diff] [blame] | 819 | expect(e.children[2].getAttribute('class')).toEqual('operators button-group'); |
| 820 | expect(e.lastChild.getAttribute('class')).toEqual('operators button-group'); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 821 | expect(e.lastChild.children[0].getAttribute('class')).toEqual('and'); |
| 822 | expect(e.lastChild.children[1].getAttribute('class')).toEqual('delete'); |
| 823 | }); |
| 824 | }); |
| 825 | |
Akron | e4961b1 | 2017-05-10 21:04:46 +0200 | [diff] [blame] | 826 | describe('KorAP.VirtualCorpus', function () { |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 827 | var simpleGroupFactory = buildFactory(docGroupClass, { |
| 828 | "@type" : "koral:docGroup", |
| 829 | "operation" : "operation:and", |
| 830 | "operands" : [ |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 831 | { |
| 832 | "@type": 'koral:doc', |
| 833 | "key" : 'author', |
| 834 | "match": 'match:eq', |
| 835 | "value": 'Max Birkendale', |
| 836 | "type": 'type:string' |
| 837 | }, |
| 838 | { |
| 839 | "@type": 'koral:doc', |
| 840 | "key": 'pubDate', |
| 841 | "match": 'match:eq', |
| 842 | "value": '2014-12-05', |
| 843 | "type": 'type:date' |
| 844 | } |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 845 | ] |
| 846 | }); |
| 847 | |
| 848 | var nestedGroupFactory = buildFactory(vcClass, { |
| 849 | "@type" : "koral:docGroup", |
| 850 | "operation" : "operation:or", |
| 851 | "operands" : [ |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 852 | { |
| 853 | "@type": 'koral:doc', |
| 854 | "key" : 'author', |
| 855 | "match": 'match:eq', |
| 856 | "value": 'Max Birkendale', |
| 857 | "type": 'type:string' |
| 858 | }, |
| 859 | { |
| 860 | "@type" : "koral:docGroup", |
| 861 | "operation" : "operation:and", |
| 862 | "operands" : [ |
| 863 | { |
| 864 | "@type": 'koral:doc', |
| 865 | "key": 'pubDate', |
| 866 | "match": 'match:geq', |
| 867 | "value": '2014-05-12', |
| 868 | "type": 'type:date' |
| 869 | }, |
| 870 | { |
| 871 | "@type": 'koral:doc', |
| 872 | "key": 'pubDate', |
| 873 | "match": 'match:leq', |
| 874 | "value": '2014-12-05', |
| 875 | "type": 'type:date' |
| 876 | } |
| 877 | ] |
| 878 | } |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 879 | ] |
| 880 | }); |
| 881 | |
| 882 | var flatGroupFactory = buildFactory(vcClass, { |
| 883 | "@type" : "koral:docGroup", |
| 884 | "operation" : "operation:and", |
| 885 | "operands" : [ |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 886 | { |
| 887 | "@type": 'koral:doc', |
| 888 | "key": 'pubDate', |
| 889 | "match": 'match:geq', |
| 890 | "value": '2014-05-12', |
| 891 | "type": 'type:date' |
| 892 | }, |
| 893 | { |
| 894 | "@type": 'koral:doc', |
| 895 | "key": 'pubDate', |
| 896 | "match": 'match:leq', |
| 897 | "value": '2014-12-05', |
| 898 | "type": 'type:date' |
| 899 | }, |
| 900 | { |
| 901 | "@type": 'koral:doc', |
| 902 | "key": 'foo', |
| 903 | "match": 'match:eq', |
| 904 | "value": 'bar', |
| 905 | "type": 'type:string' |
| 906 | } |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 907 | ] |
| 908 | }); |
| 909 | |
| 910 | it('should be initializable', function () { |
Nils Diewald | 6283d69 | 2015-04-23 20:32:53 +0000 | [diff] [blame] | 911 | var vc = vcClass.create(); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 912 | expect(vc.element().getAttribute('class')).toEqual('vc'); |
| 913 | expect(vc.root().element().getAttribute('class')).toEqual('doc unspecified'); |
| 914 | |
| 915 | // Not removable |
| 916 | expect(vc.root().element().lastChild.children.length).toEqual(0); |
| 917 | }); |
| 918 | |
| 919 | it('should be based on a doc', function () { |
Nils Diewald | 6283d69 | 2015-04-23 20:32:53 +0000 | [diff] [blame] | 920 | var vc = vcClass.create().fromJson({ |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 921 | "@type" : "koral:doc", |
| 922 | "key":"Titel", |
| 923 | "value":"Baum", |
| 924 | "match":"match:eq" |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 925 | }); |
| 926 | |
| 927 | expect(vc.element().getAttribute('class')).toEqual('vc'); |
| 928 | expect(vc.root().element().getAttribute('class')).toEqual('doc'); |
| 929 | expect(vc.root().key()).toEqual('Titel'); |
| 930 | expect(vc.root().value()).toEqual('Baum'); |
| 931 | expect(vc.root().matchop()).toEqual('eq'); |
| 932 | |
| 933 | var docE = vc.root().element(); |
| 934 | expect(docE.children[0].firstChild.data).toEqual('Titel'); |
| 935 | expect(docE.children[1].firstChild.data).toEqual('eq'); |
| 936 | expect(docE.children[1].getAttribute('data-type')).toEqual('string'); |
| 937 | expect(docE.children[2].firstChild.data).toEqual('Baum'); |
| 938 | expect(docE.children[2].getAttribute('data-type')).toEqual('string'); |
| 939 | }); |
| 940 | |
| 941 | it('should be based on a docGroup', function () { |
Nils Diewald | 6283d69 | 2015-04-23 20:32:53 +0000 | [diff] [blame] | 942 | var vc = vcClass.create().fromJson(simpleGroupFactory.create().toJson()); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 943 | |
| 944 | expect(vc.element().getAttribute('class')).toEqual('vc'); |
| 945 | expect(vc.root().element().getAttribute('class')).toEqual('docGroup'); |
| 946 | expect(vc.root().operation()).toEqual('and'); |
| 947 | |
| 948 | var docGroup = vc.root(); |
| 949 | |
| 950 | var first = docGroup.getOperand(0); |
| 951 | expect(first.key()).toEqual('author'); |
| 952 | expect(first.value()).toEqual('Max Birkendale'); |
| 953 | expect(first.matchop()).toEqual('eq'); |
| 954 | |
| 955 | var second = docGroup.getOperand(1); |
| 956 | expect(second.key()).toEqual('pubDate'); |
| 957 | expect(second.value()).toEqual('2014-12-05'); |
| 958 | expect(second.matchop()).toEqual('eq'); |
| 959 | }); |
| 960 | |
| 961 | |
| 962 | it('should be based on a nested docGroup', function () { |
| 963 | var vc = nestedGroupFactory.create(); |
| 964 | |
| 965 | expect(vc.element().getAttribute('class')).toEqual('vc'); |
| 966 | expect(vc.element().firstChild.getAttribute('class')).toEqual('docGroup'); |
| 967 | expect(vc.element().firstChild.children[0].getAttribute('class')).toEqual('doc'); |
| 968 | var dg = vc.element().firstChild.children[1]; |
| 969 | expect(dg.getAttribute('class')).toEqual('docGroup'); |
| 970 | expect(dg.children[0].getAttribute('class')).toEqual('doc'); |
| 971 | expect(dg.children[1].getAttribute('class')).toEqual('doc'); |
Akron | 0b489ad | 2018-02-02 16:49:32 +0100 | [diff] [blame] | 972 | expect(dg.children[2].getAttribute('class')).toEqual('operators button-group'); |
| 973 | expect(vc.element().firstChild.children[2].getAttribute('class')).toEqual('operators button-group'); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 974 | }); |
| 975 | |
| 976 | it('should be modifiable by deletion in flat docGroups', function () { |
| 977 | var vc = flatGroupFactory.create(); |
| 978 | var docGroup = vc.root(); |
| 979 | |
| 980 | expect(docGroup.element().getAttribute('class')).toEqual('docGroup'); |
| 981 | |
| 982 | var doc = docGroup.getOperand(1); |
| 983 | expect(doc.key()).toEqual("pubDate"); |
| 984 | expect(doc.value()).toEqual("2014-12-05"); |
| 985 | |
| 986 | // Remove operand 1 |
| 987 | expect(docGroup.delOperand(doc).update()).not.toBeUndefined(); |
| 988 | expect(doc._element).toEqual(undefined); |
| 989 | |
| 990 | doc = docGroup.getOperand(1); |
| 991 | expect(doc.key()).toEqual("foo"); |
| 992 | |
| 993 | // Remove operand 1 |
| 994 | expect(docGroup.delOperand(doc).update()).not.toBeUndefined(); |
| 995 | expect(doc._element).toEqual(undefined); |
| 996 | |
| 997 | // Only one operand left ... |
| 998 | expect(docGroup.getOperand(1)).toBeUndefined(); |
| 999 | // ... but there shouldn't be a group anymore at all! |
| 1000 | expect(docGroup.getOperand(0)).toBeUndefined(); |
| 1001 | |
| 1002 | var obj = vc.root(); |
| 1003 | expect(obj.ldType()).toEqual("doc"); |
| 1004 | expect(obj.key()).toEqual("pubDate"); |
| 1005 | expect(obj.value()).toEqual("2014-05-12"); |
| 1006 | |
| 1007 | expect(obj.element().getAttribute('class')).toEqual('doc'); |
| 1008 | }); |
| 1009 | |
| 1010 | |
| 1011 | it('should be modifiable by deletion in nested docGroups (root case)', function () { |
| 1012 | var vc = nestedGroupFactory.create(); |
| 1013 | |
| 1014 | expect(vc.toQuery()).toEqual( |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 1015 | '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] | 1016 | ); |
| 1017 | |
| 1018 | var docGroup = vc.root(); |
| 1019 | expect(docGroup.ldType()).toEqual("docGroup"); |
| 1020 | expect(docGroup.operation()).toEqual("or"); |
| 1021 | |
| 1022 | var doc = docGroup.getOperand(0); |
| 1023 | expect(doc.key()).toEqual("author"); |
| 1024 | expect(doc.value()).toEqual("Max Birkendale"); |
| 1025 | |
| 1026 | docGroup = docGroup.getOperand(1); |
| 1027 | expect(docGroup.operation()).toEqual("and"); |
| 1028 | |
| 1029 | doc = docGroup.getOperand(0); |
| 1030 | expect(doc.key()).toEqual("pubDate"); |
| 1031 | expect(doc.matchop()).toEqual("geq"); |
| 1032 | expect(doc.value()).toEqual("2014-05-12"); |
| 1033 | expect(doc.type()).toEqual("date"); |
| 1034 | |
| 1035 | doc = docGroup.getOperand(1); |
| 1036 | expect(doc.key()).toEqual("pubDate"); |
| 1037 | expect(doc.matchop()).toEqual("leq"); |
| 1038 | expect(doc.value()).toEqual("2014-12-05"); |
| 1039 | expect(doc.type()).toEqual("date"); |
| 1040 | |
| 1041 | // Remove first operand so everything becomes root |
| 1042 | expect( |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 1043 | vc.root().delOperand( |
| 1044 | vc.root().getOperand(0) |
| 1045 | ).update().ldType() |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1046 | ).toEqual("docGroup"); |
| 1047 | |
| 1048 | expect(vc.root().ldType()).toEqual("docGroup"); |
| 1049 | expect(vc.root().operation()).toEqual("and"); |
| 1050 | expect(vc.root().getOperand(0).ldType()).toEqual("doc"); |
| 1051 | |
| 1052 | expect(vc.toQuery()).toEqual( |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 1053 | 'pubDate since 2014-05-12 & pubDate until 2014-12-05' |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1054 | ); |
| 1055 | }); |
| 1056 | |
| 1057 | it('should be modifiable by deletion in nested docGroups (resolve group case)', function () { |
| 1058 | var vc = nestedGroupFactory.create(); |
| 1059 | |
| 1060 | // Get nested group |
| 1061 | var firstGroup = vc.root().getOperand(1); |
| 1062 | firstGroup.append(simpleGroupFactory.create({ "operation" : "operation:or" })); |
| 1063 | |
| 1064 | // Structur is now: |
| 1065 | // or(doc, and(doc, doc, or(doc, doc))) |
| 1066 | |
| 1067 | // Get nested or in and |
| 1068 | var orGroup = vc.root().getOperand(1).getOperand(2); |
| 1069 | expect(orGroup.ldType()).toEqual("docGroup"); |
| 1070 | expect(orGroup.operation()).toEqual("or"); |
| 1071 | |
| 1072 | // Remove |
| 1073 | // Structur is now: |
| 1074 | // or(doc, and(doc, doc, doc))) |
| 1075 | expect(orGroup.delOperand(orGroup.getOperand(0)).update().operation()).toEqual("and"); |
| 1076 | expect(vc.root().getOperand(1).operands().length).toEqual(3); |
| 1077 | }); |
| 1078 | |
| 1079 | it('should be modifiable by deletion in nested docGroups (identical group case)', function () { |
| 1080 | var vc = nestedGroupFactory.create(); |
| 1081 | |
| 1082 | // Get nested group |
| 1083 | var firstGroup = vc.root().getOperand(1); |
| 1084 | firstGroup.append(simpleGroupFactory.create({ |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 1085 | "operation" : "operation:or" |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1086 | })); |
| 1087 | var oldAuthor = firstGroup.getOperand(2).getOperand(0); |
| 1088 | oldAuthor.key("title"); |
| 1089 | oldAuthor.value("Der Birnbaum"); |
| 1090 | |
| 1091 | // Structur is now: |
| 1092 | // or(doc, and(doc, doc, or(doc, doc))) |
| 1093 | expect(vc.toQuery()).toEqual( |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 1094 | 'author = "Max Birkendale" | ' + |
| 1095 | '(pubDate since 2014-05-12 & ' + |
| 1096 | 'pubDate until 2014-12-05 & ' + |
| 1097 | '(title = "Der Birnbaum" | ' + |
| 1098 | 'pubDate in 2014-12-05))' |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1099 | ); |
| 1100 | |
| 1101 | var andGroup = vc.root().getOperand(1); |
| 1102 | |
| 1103 | // Get leading docs in and |
| 1104 | var doc1 = andGroup.getOperand(0); |
| 1105 | expect(doc1.ldType()).toEqual("doc"); |
| 1106 | expect(doc1.value()).toEqual("2014-05-12"); |
| 1107 | var doc2 = andGroup.getOperand(1); |
| 1108 | expect(doc2.ldType()).toEqual("doc"); |
| 1109 | expect(doc2.value()).toEqual("2014-12-05"); |
| 1110 | |
| 1111 | // Remove 2 |
| 1112 | expect( |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 1113 | andGroup.delOperand(doc2).update().operation() |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1114 | ).toEqual("and"); |
| 1115 | // Structur is now: |
| 1116 | // or(doc, and(doc, or(doc, doc))) |
| 1117 | |
| 1118 | expect(vc.toQuery()).toEqual( |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 1119 | 'author = "Max Birkendale"' + |
| 1120 | ' | (pubDate since 2014-05-12 & ' + |
| 1121 | '(title = "Der Birnbaum" | pubDate in 2014-12-05))' |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1122 | ); |
| 1123 | |
| 1124 | |
| 1125 | // Remove 1 |
| 1126 | expect(andGroup.delOperand(doc1).update().operation()).toEqual("or"); |
| 1127 | // Structur is now: |
| 1128 | // or(doc, doc, doc) |
| 1129 | |
| 1130 | expect(vc.toQuery()).toEqual( |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 1131 | 'author = "Max Birkendale" | title = "Der Birnbaum" | pubDate in 2014-12-05' |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1132 | ); |
| 1133 | }); |
| 1134 | |
| 1135 | it('should be reducible to unspecification', function () { |
| 1136 | var vc = demoFactory.create(); |
| 1137 | |
| 1138 | expect(vc.toQuery()).toEqual(vc.root().toQuery()); |
| 1139 | expect(vc.toQuery()).toEqual( |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 1140 | '(Titel = "Baum" & Veröffentlichungsort = "hihi" & ' + |
| 1141 | '(Titel = "Baum" | Veröffentlichungsort = "hihi")) ' + |
| 1142 | '| Untertitel ~ "huhu"'); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1143 | expect(vc.root().element().lastChild.children[0].firstChild.nodeValue).toEqual('and'); |
| 1144 | expect(vc.root().element().lastChild.children[1].firstChild.nodeValue).toEqual('×'); |
| 1145 | expect(vc.root().delOperand(vc.root().getOperand(0)).update()).not.toBeUndefined(); |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 1146 | expect(vc.toQuery()).toEqual('Untertitel ~ "huhu"'); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1147 | |
| 1148 | var lc = vc.root().element().lastChild; |
| 1149 | expect(lc.children[0].firstChild.nodeValue).toEqual('and'); |
| 1150 | expect(lc.children[1].firstChild.nodeValue).toEqual('or'); |
| 1151 | expect(lc.children[2].firstChild.nodeValue).toEqual('×'); |
| 1152 | |
| 1153 | // Clean everything |
| 1154 | vc.clean(); |
| 1155 | expect(vc.toQuery()).toEqual(''); |
| 1156 | }); |
| 1157 | |
| 1158 | it('should flatten on import', function () { |
Nils Diewald | 6283d69 | 2015-04-23 20:32:53 +0000 | [diff] [blame] | 1159 | var vc = vcClass.create().fromJson({ |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 1160 | "@type":"koral:docGroup", |
| 1161 | "operation":"operation:or", |
| 1162 | "operands":[ |
| 1163 | { |
| 1164 | "@type":"koral:docGroup", |
| 1165 | "operation":"operation:or", |
| 1166 | "operands":[ |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1167 | { |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 1168 | "@type":"koral:doc", |
| 1169 | "key":"Titel", |
| 1170 | "value":"Baum", |
| 1171 | "match":"match:eq" |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1172 | }, |
| 1173 | { |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 1174 | "@type":"koral:doc", |
| 1175 | "key":"Veröffentlichungsort", |
| 1176 | "value":"hihi", |
| 1177 | "match":"match:eq" |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1178 | }, |
| 1179 | { |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 1180 | "@type":"koral:docGroup", |
| 1181 | "operation":"operation:or", |
| 1182 | "operands":[ |
| 1183 | { |
| 1184 | "@type":"koral:doc", |
| 1185 | "key":"Titel", |
| 1186 | "value":"Baum", |
| 1187 | "match":"match:eq" |
| 1188 | }, |
| 1189 | { |
| 1190 | "@type":"koral:doc", |
| 1191 | "key":"Veröffentlichungsort", |
| 1192 | "value":"hihi", |
| 1193 | "match":"match:eq" |
| 1194 | } |
| 1195 | ] |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1196 | } |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 1197 | ] |
| 1198 | }, |
| 1199 | { |
| 1200 | "@type":"koral:doc", |
| 1201 | "key":"Untertitel", |
| 1202 | "value":"huhu", |
| 1203 | "match":"match:contains" |
| 1204 | } |
| 1205 | ] |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1206 | }); |
Nils Diewald | fda29d9 | 2015-01-22 17:28:01 +0000 | [diff] [blame] | 1207 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1208 | expect(vc.toQuery()).toEqual( |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 1209 | 'Titel = "Baum" | Veröffentlichungsort = "hihi" | Untertitel ~ "huhu"' |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1210 | ); |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 1211 | }); |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 1212 | }); |
| 1213 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1214 | describe('KorAP.Operators', function () { |
| 1215 | it('should be initializable', function () { |
| 1216 | var op = operatorsClass.create(true, false, false); |
| 1217 | expect(op.and()).toBeTruthy(); |
| 1218 | expect(op.or()).not.toBeTruthy(); |
| 1219 | expect(op.del()).not.toBeTruthy(); |
| 1220 | |
| 1221 | op.and(false); |
| 1222 | expect(op.and()).not.toBeTruthy(); |
| 1223 | expect(op.or()).not.toBeTruthy(); |
| 1224 | expect(op.del()).not.toBeTruthy(); |
| 1225 | |
| 1226 | op.or(true); |
| 1227 | op.del(true); |
| 1228 | expect(op.and()).not.toBeTruthy(); |
| 1229 | expect(op.or()).toBeTruthy(); |
| 1230 | expect(op.del()).toBeTruthy(); |
| 1231 | |
| 1232 | var e = op.element(); |
Akron | 0b489ad | 2018-02-02 16:49:32 +0100 | [diff] [blame] | 1233 | expect(e.getAttribute('class')).toEqual('operators button-group'); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1234 | expect(e.children[0].getAttribute('class')).toEqual('or'); |
| 1235 | expect(e.children[0].firstChild.data).toEqual('or'); |
| 1236 | expect(e.children[1].getAttribute('class')).toEqual('delete'); |
| 1237 | expect(e.children[1].firstChild.data).toEqual('×'); |
| 1238 | |
| 1239 | op.and(true); |
| 1240 | op.del(false); |
| 1241 | op.update(); |
| 1242 | |
| 1243 | e = op.element(); |
Akron | 0b489ad | 2018-02-02 16:49:32 +0100 | [diff] [blame] | 1244 | expect(e.getAttribute('class')).toEqual('operators button-group'); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1245 | expect(e.children[0].getAttribute('class')).toEqual('and'); |
| 1246 | expect(e.children[0].firstChild.data).toEqual('and'); |
| 1247 | expect(e.children[1].getAttribute('class')).toEqual('or'); |
| 1248 | expect(e.children[1].firstChild.data).toEqual('or'); |
| 1249 | }); |
| 1250 | }); |
| 1251 | |
| 1252 | describe('KorAP._delete (event)', function () { |
| 1253 | var complexVCFactory = buildFactory(vcClass,{ |
| 1254 | "@type": 'koral:docGroup', |
| 1255 | 'operation' : 'operation:and', |
| 1256 | 'operands' : [ |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 1257 | { |
| 1258 | "@type": 'koral:doc', |
| 1259 | "key": 'pubDate', |
| 1260 | "match": 'match:eq', |
| 1261 | "value": '2014-12-05', |
| 1262 | "type": 'type:date' |
| 1263 | }, |
| 1264 | { |
| 1265 | "@type" : 'koral:docGroup', |
| 1266 | 'operation' : 'operation:or', |
| 1267 | 'operands' : [ |
| 1268 | { |
| 1269 | '@type' : 'koral:doc', |
| 1270 | 'key' : 'title', |
| 1271 | 'value' : 'Hello World!' |
| 1272 | }, |
| 1273 | { |
| 1274 | '@type' : 'koral:doc', |
| 1275 | 'key' : 'foo', |
| 1276 | 'value' : 'bar' |
| 1277 | } |
| 1278 | ] |
| 1279 | } |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1280 | ] |
| 1281 | }); |
| 1282 | |
| 1283 | it('should clean on root docs', function () { |
Nils Diewald | 6283d69 | 2015-04-23 20:32:53 +0000 | [diff] [blame] | 1284 | var vc = vcClass.create().fromJson({ |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 1285 | "@type": 'koral:doc', |
| 1286 | "key": 'pubDate', |
| 1287 | "match": 'match:eq', |
| 1288 | "value": '2014-12-05', |
| 1289 | "type": 'type:date' |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 1290 | }); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1291 | expect(vc.root().toQuery()).toEqual('pubDate in 2014-12-05'); |
Akron | 0b489ad | 2018-02-02 16:49:32 +0100 | [diff] [blame] | 1292 | expect(vc.root().element().lastChild.getAttribute('class')).toEqual('operators button-group'); |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 1293 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1294 | // Clean with delete from root |
| 1295 | expect(vc.root().element().lastChild.lastChild.getAttribute('class')).toEqual('delete'); |
| 1296 | _delOn(vc.root()); |
| 1297 | expect(vc.root().toQuery()).toEqual(''); |
| 1298 | expect(vc.root().element().lastChild.lastChild.data).toEqual('⋯'); |
| 1299 | }); |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 1300 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1301 | it('should remove on nested docs', function () { |
Nils Diewald | 6283d69 | 2015-04-23 20:32:53 +0000 | [diff] [blame] | 1302 | var vc = vcClass.create().fromJson( |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 1303 | { |
| 1304 | "@type": 'koral:docGroup', |
| 1305 | 'operation' : 'operation:and', |
| 1306 | 'operands' : [ |
| 1307 | { |
| 1308 | "@type": 'koral:doc', |
| 1309 | "key": 'pubDate', |
| 1310 | "match": 'match:eq', |
| 1311 | "value": '2014-12-05', |
| 1312 | "type": 'type:date' |
| 1313 | }, |
| 1314 | { |
| 1315 | "@type" : 'koral:doc', |
| 1316 | 'key' : 'foo', |
| 1317 | 'value' : 'bar' |
| 1318 | } |
| 1319 | ] |
| 1320 | } |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1321 | ); |
| 1322 | |
| 1323 | // Delete with direct element access |
| 1324 | expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar"'); |
| 1325 | _delOn(vc.root().getOperand(0)); |
| 1326 | |
| 1327 | expect(vc.toQuery()).toEqual('foo = "bar"'); |
| 1328 | expect(vc.root().ldType()).toEqual('doc'); |
| 1329 | }); |
| 1330 | |
| 1331 | it('should clean on doc groups', function () { |
Nils Diewald | 6283d69 | 2015-04-23 20:32:53 +0000 | [diff] [blame] | 1332 | var vc = vcClass.create().fromJson( |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 1333 | { |
| 1334 | "@type": 'koral:docGroup', |
| 1335 | 'operation' : 'operation:and', |
| 1336 | 'operands' : [ |
| 1337 | { |
| 1338 | "@type": 'koral:doc', |
| 1339 | "key": 'pubDate', |
| 1340 | "match": 'match:eq', |
| 1341 | "value": '2014-12-05', |
| 1342 | "type": 'type:date' |
| 1343 | }, |
| 1344 | { |
| 1345 | "@type" : 'koral:doc', |
| 1346 | 'key' : 'foo', |
| 1347 | 'value' : 'bar' |
| 1348 | } |
| 1349 | ] |
| 1350 | } |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1351 | ); |
| 1352 | |
| 1353 | // Cleanwith direct element access |
| 1354 | expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar"'); |
| 1355 | _delOn(vc.root()); |
| 1356 | expect(vc.toQuery()).toEqual(''); |
| 1357 | expect(vc.root().ldType()).toEqual('non'); |
| 1358 | }); |
| 1359 | |
| 1360 | it('should remove on nested doc groups (case of ungrouping 1)', function () { |
| 1361 | var vc = complexVCFactory.create(); |
| 1362 | |
| 1363 | // Delete with direct element access |
| 1364 | expect(vc.toQuery()).toEqual( |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 1365 | 'pubDate in 2014-12-05 & (title = "Hello World!" | foo = "bar")' |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1366 | ); |
| 1367 | |
| 1368 | // Remove hello world: |
| 1369 | _delOn(vc.root().getOperand(1).getOperand(0)); |
| 1370 | expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar"'); |
| 1371 | expect(vc.root().ldType()).toEqual('docGroup'); |
| 1372 | }); |
| 1373 | |
| 1374 | it('should remove on nested doc groups (case of ungrouping 2)', 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 & (title = "Hello World!" | foo = "bar")' |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1380 | ); |
| 1381 | |
| 1382 | // Remove bar |
| 1383 | _delOn(vc.root().getOperand(1).getOperand(1)); |
| 1384 | expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & title = "Hello World!"'); |
| 1385 | expect(vc.root().ldType()).toEqual('docGroup'); |
| 1386 | expect(vc.root().operation()).toEqual('and'); |
| 1387 | }); |
| 1388 | |
| 1389 | it('should remove on nested doc groups (case of root changing)', function () { |
| 1390 | var vc = complexVCFactory.create(); |
| 1391 | |
| 1392 | // Delete with direct element access |
| 1393 | expect(vc.toQuery()).toEqual( |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 1394 | 'pubDate in 2014-12-05 & ' + |
| 1395 | '(title = "Hello World!" | foo = "bar")' |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1396 | ); |
| 1397 | |
| 1398 | // Remove bar |
| 1399 | _delOn(vc.root().getOperand(0)); |
| 1400 | expect(vc.toQuery()).toEqual('title = "Hello World!" | foo = "bar"'); |
| 1401 | expect(vc.root().ldType()).toEqual('docGroup'); |
| 1402 | expect(vc.root().operation()).toEqual('or'); |
| 1403 | }); |
| 1404 | |
| 1405 | it('should remove on nested doc groups (list flattening)', function () { |
Nils Diewald | 6283d69 | 2015-04-23 20:32:53 +0000 | [diff] [blame] | 1406 | var vc = vcClass.create().fromJson( |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 1407 | { |
| 1408 | "@type": 'koral:docGroup', |
| 1409 | 'operation' : 'operation:or', |
| 1410 | 'operands' : [ |
| 1411 | { |
| 1412 | "@type": 'koral:doc', |
| 1413 | "key": 'pubDate', |
| 1414 | "match": 'match:eq', |
| 1415 | "value": '2014-12-05', |
| 1416 | "type": 'type:date' |
| 1417 | }, |
| 1418 | { |
| 1419 | "@type" : 'koral:doc', |
| 1420 | 'key' : 'foo', |
| 1421 | 'value' : 'bar' |
| 1422 | }, |
| 1423 | { |
| 1424 | "@type": 'koral:docGroup', |
| 1425 | 'operation' : 'operation:and', |
| 1426 | 'operands' : [ |
| 1427 | { |
| 1428 | "@type": 'koral:doc', |
| 1429 | "key": 'pubDate', |
| 1430 | "match": 'match:eq', |
| 1431 | "value": '2014-12-05', |
| 1432 | "type": 'type:date' |
| 1433 | }, |
| 1434 | { |
| 1435 | "@type" : 'koral:docGroup', |
| 1436 | 'operation' : 'operation:or', |
| 1437 | 'operands' : [ |
| 1438 | { |
| 1439 | '@type' : 'koral:doc', |
| 1440 | 'key' : 'title', |
| 1441 | 'value' : 'Hello World!' |
| 1442 | }, |
| 1443 | { |
| 1444 | '@type' : 'koral:doc', |
| 1445 | 'key' : 'yeah', |
| 1446 | 'value' : 'juhu' |
| 1447 | } |
| 1448 | ] |
| 1449 | } |
| 1450 | ] |
| 1451 | } |
| 1452 | ] |
| 1453 | } |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1454 | ); |
| 1455 | |
| 1456 | // Delete with direct element access |
| 1457 | expect(vc.toQuery()).toEqual( |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 1458 | 'pubDate in 2014-12-05 | foo = "bar" | ' + |
| 1459 | '(pubDate in 2014-12-05 & ' + |
| 1460 | '(title = "Hello World!" | yeah = "juhu"))' |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1461 | ); |
| 1462 | |
| 1463 | expect(vc.root().ldType()).toEqual('docGroup'); |
| 1464 | expect(vc.root().operation()).toEqual('or'); |
| 1465 | |
| 1466 | // Operands and operators |
| 1467 | expect(vc.element().firstChild.children.length).toEqual(4); |
Akron | 0b489ad | 2018-02-02 16:49:32 +0100 | [diff] [blame] | 1468 | expect(vc.element().firstChild.lastChild.getAttribute('class')).toEqual('operators button-group'); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1469 | |
| 1470 | // Remove inner group and flatten |
| 1471 | _delOn(vc.root().getOperand(2).getOperand(0)); |
| 1472 | |
| 1473 | expect(vc.toQuery()).toEqual( |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 1474 | 'pubDate in 2014-12-05 | foo = "bar" | title = "Hello World!" | yeah = "juhu"' |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1475 | ); |
| 1476 | expect(vc.root().ldType()).toEqual('docGroup'); |
| 1477 | expect(vc.root().operation()).toEqual('or'); |
| 1478 | |
| 1479 | // Operands and operators |
| 1480 | expect(vc.element().firstChild.children.length).toEqual(5); |
Akron | 0b489ad | 2018-02-02 16:49:32 +0100 | [diff] [blame] | 1481 | expect(vc.element().firstChild.lastChild.getAttribute('class')).toEqual('operators button-group'); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1482 | }); |
| 1483 | }); |
| 1484 | |
| 1485 | describe('KorAP._add (event)', function () { |
| 1486 | var complexVCFactory = buildFactory(vcClass,{ |
| 1487 | "@type": 'koral:docGroup', |
| 1488 | 'operation' : 'operation:and', |
| 1489 | 'operands' : [ |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 1490 | { |
| 1491 | "@type": 'koral:doc', |
| 1492 | "key": 'pubDate', |
| 1493 | "match": 'match:eq', |
| 1494 | "value": '2014-12-05', |
| 1495 | "type": 'type:date' |
| 1496 | }, |
| 1497 | { |
| 1498 | "@type" : 'koral:docGroup', |
| 1499 | 'operation' : 'operation:or', |
| 1500 | 'operands' : [ |
| 1501 | { |
| 1502 | '@type' : 'koral:doc', |
| 1503 | 'key' : 'title', |
| 1504 | 'value' : 'Hello World!' |
| 1505 | }, |
| 1506 | { |
| 1507 | '@type' : 'koral:doc', |
| 1508 | 'key' : 'foo', |
| 1509 | 'value' : 'bar' |
| 1510 | } |
| 1511 | ] |
| 1512 | } |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1513 | ] |
| 1514 | }); |
| 1515 | |
| 1516 | it('should add new unspecified doc with "and"', function () { |
Nils Diewald | 6283d69 | 2015-04-23 20:32:53 +0000 | [diff] [blame] | 1517 | var vc = vcClass.create().fromJson( |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 1518 | { |
| 1519 | "@type": 'koral:docGroup', |
| 1520 | 'operation' : 'operation:and', |
| 1521 | 'operands' : [ |
| 1522 | { |
| 1523 | "@type": 'koral:doc', |
| 1524 | "key": 'pubDate', |
| 1525 | "match": 'match:eq', |
| 1526 | "value": '2014-12-05', |
| 1527 | "type": 'type:date' |
| 1528 | }, |
| 1529 | { |
| 1530 | "@type" : 'koral:doc', |
| 1531 | 'key' : 'foo', |
| 1532 | 'value' : 'bar' |
| 1533 | } |
| 1534 | ] |
| 1535 | } |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1536 | ); |
| 1537 | |
| 1538 | expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar"'); |
| 1539 | |
| 1540 | var fc = vc.element().firstChild; |
| 1541 | expect(fc.getAttribute('data-operation')).toEqual('and'); |
| 1542 | expect(fc.children.length).toEqual(3); |
Akron | 0b489ad | 2018-02-02 16:49:32 +0100 | [diff] [blame] | 1543 | expect(fc.lastChild.getAttribute('class')).toEqual('operators button-group'); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1544 | expect(fc.children[0].getAttribute('class')).toEqual('doc'); |
| 1545 | expect(fc.children[1].getAttribute('class')).toEqual('doc'); |
| 1546 | |
| 1547 | // add with 'and' in the middle |
| 1548 | _andOn(vc.root().getOperand(0)); |
| 1549 | expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar"'); |
| 1550 | |
| 1551 | fc = vc.element().firstChild; |
| 1552 | expect(fc.getAttribute('data-operation')).toEqual('and'); |
| 1553 | expect(fc.children.length).toEqual(4); |
Akron | 0b489ad | 2018-02-02 16:49:32 +0100 | [diff] [blame] | 1554 | expect(fc.lastChild.getAttribute('class')).toEqual('operators button-group'); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1555 | |
| 1556 | expect(fc.children[0].getAttribute('class')).toEqual('doc'); |
| 1557 | expect(fc.children[1].getAttribute('class')).toEqual('doc unspecified'); |
| 1558 | expect(fc.children[2].getAttribute('class')).toEqual('doc'); |
| 1559 | }); |
| 1560 | |
| 1561 | it('should add new unspecified doc with "or"', function () { |
Nils Diewald | 6283d69 | 2015-04-23 20:32:53 +0000 | [diff] [blame] | 1562 | var vc = vcClass.create().fromJson( |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 1563 | { |
| 1564 | "@type": 'koral:docGroup', |
| 1565 | 'operation' : 'operation:and', |
| 1566 | 'operands' : [ |
| 1567 | { |
| 1568 | "@type": 'koral:doc', |
| 1569 | "key": 'pubDate', |
| 1570 | "match": 'match:eq', |
| 1571 | "value": '2014-12-05', |
| 1572 | "type": 'type:date' |
| 1573 | }, |
| 1574 | { |
| 1575 | "@type" : 'koral:doc', |
| 1576 | 'key' : 'foo', |
| 1577 | 'value' : 'bar' |
| 1578 | } |
| 1579 | ] |
| 1580 | } |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1581 | ); |
| 1582 | |
| 1583 | expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar"'); |
| 1584 | |
| 1585 | var fc = vc.element().firstChild; |
| 1586 | expect(fc.children.length).toEqual(3); |
Akron | 0b489ad | 2018-02-02 16:49:32 +0100 | [diff] [blame] | 1587 | expect(fc.lastChild.getAttribute('class')).toEqual('operators button-group'); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1588 | expect(fc.children[0].getAttribute('class')).toEqual('doc'); |
| 1589 | expect(fc.children[1].getAttribute('class')).toEqual('doc'); |
| 1590 | |
| 1591 | // add with 'or' in the middle |
| 1592 | _orOn(vc.root().getOperand(0)); |
| 1593 | expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar"'); |
| 1594 | fc = vc.element().firstChild; |
| 1595 | |
| 1596 | expect(fc.getAttribute('data-operation')).toEqual('and'); |
| 1597 | expect(fc.children.length).toEqual(3); |
| 1598 | expect(fc.children[0].getAttribute('class')).toEqual('docGroup'); |
| 1599 | expect(fc.children[0].getAttribute('data-operation')).toEqual('or'); |
| 1600 | expect(fc.children[1].getAttribute('class')).toEqual('doc'); |
Akron | 0b489ad | 2018-02-02 16:49:32 +0100 | [diff] [blame] | 1601 | expect(fc.children[2].getAttribute('class')).toEqual('operators button-group'); |
| 1602 | expect(fc.lastChild.getAttribute('class')).toEqual('operators button-group'); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1603 | |
| 1604 | fc = vc.element().firstChild.firstChild; |
| 1605 | expect(fc.children.length).toEqual(3); |
| 1606 | expect(fc.children[0].getAttribute('class')).toEqual('doc'); |
| 1607 | expect(fc.children[1].getAttribute('class')).toEqual('doc unspecified'); |
Akron | 0b489ad | 2018-02-02 16:49:32 +0100 | [diff] [blame] | 1608 | expect(fc.children[2].getAttribute('class')).toEqual('operators button-group'); |
| 1609 | expect(fc.lastChild.getAttribute('class')).toEqual('operators button-group'); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1610 | }); |
| 1611 | |
| 1612 | it('should add new unspecified doc with "and" before group', function () { |
| 1613 | var vc = demoFactory.create(); |
| 1614 | |
| 1615 | // Wrap with direct element access |
| 1616 | expect(vc.toQuery()).toEqual( |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 1617 | '(Titel = "Baum" & ' + |
| 1618 | 'Veröffentlichungsort = "hihi" & ' + |
| 1619 | '(Titel = "Baum" | ' + |
| 1620 | 'Veröffentlichungsort = "hihi")) | ' + |
| 1621 | 'Untertitel ~ "huhu"' |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1622 | ); |
| 1623 | |
| 1624 | expect(vc.root().getOperand(0).ldType()).toEqual('docGroup'); |
| 1625 | expect(vc.root().getOperand(0).operation()).toEqual('and'); |
| 1626 | expect(vc.root().getOperand(0).operands().length).toEqual(3); |
| 1627 | |
| 1628 | // Add unspecified on the second doc |
| 1629 | var secDoc = vc.root().getOperand(0).getOperand(1); |
| 1630 | expect(secDoc.value()).toEqual('hihi'); |
| 1631 | |
| 1632 | // Add |
| 1633 | _andOn(secDoc); |
| 1634 | |
| 1635 | var fo = vc.root().getOperand(0); |
| 1636 | |
| 1637 | expect(fo.ldType()).toEqual('docGroup'); |
| 1638 | expect(fo.operation()).toEqual('and'); |
| 1639 | expect(fo.operands().length).toEqual(4); |
| 1640 | |
| 1641 | expect(fo.getOperand(0).ldType()).toEqual('doc'); |
| 1642 | expect(fo.getOperand(1).ldType()).toEqual('doc'); |
| 1643 | expect(fo.getOperand(2).ldType()).toEqual('non'); |
| 1644 | expect(fo.getOperand(3).ldType()).toEqual('docGroup'); |
| 1645 | }); |
| 1646 | |
| 1647 | |
| 1648 | it('should remove a doc with an unspecified doc in a nested group', function () { |
| 1649 | var vc = demoFactory.create(); |
| 1650 | |
| 1651 | // Wrap with direct element access |
| 1652 | expect(vc.toQuery()).toEqual( |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 1653 | '(Titel = "Baum" & Veröffentlichungsort = "hihi" & (Titel = "Baum" | Veröffentlichungsort = "hihi")) | Untertitel ~ "huhu"' |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1654 | ); |
| 1655 | |
| 1656 | var fo = vc.root().getOperand(0).getOperand(0); |
| 1657 | expect(fo.key()).toEqual('Titel'); |
| 1658 | expect(fo.value()).toEqual('Baum'); |
| 1659 | |
| 1660 | // Add unspecified on the root group |
| 1661 | _orOn(fo); |
| 1662 | |
| 1663 | fo = vc.root().getOperand(0).getOperand(0); |
| 1664 | |
| 1665 | expect(fo.operation()).toEqual('or'); |
| 1666 | expect(fo.getOperand(0).ldType()).toEqual('doc'); |
| 1667 | expect(fo.getOperand(1).ldType()).toEqual('non'); |
| 1668 | |
| 1669 | // Delete document |
| 1670 | _delOn(fo.getOperand(0)); |
| 1671 | |
| 1672 | // The operand is now non |
| 1673 | expect(vc.root().getOperand(0).getOperand(0).ldType()).toEqual('non'); |
| 1674 | expect(vc.root().getOperand(0).getOperand(1).ldType()).toEqual('doc'); |
| 1675 | expect(vc.root().getOperand(0).getOperand(2).ldType()).toEqual('docGroup'); |
| 1676 | }); |
| 1677 | |
| 1678 | |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 1679 | 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] | 1680 | var vc = demoFactory.create(); |
| 1681 | |
| 1682 | // Wrap with direct element access |
| 1683 | expect(vc.toQuery()).toEqual( |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 1684 | '(Titel = "Baum" & ' + |
| 1685 | 'Veröffentlichungsort = "hihi" & ' + |
| 1686 | '(Titel = "Baum" ' + |
| 1687 | '| Veröffentlichungsort = "hihi")) | ' + |
| 1688 | 'Untertitel ~ "huhu"' |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1689 | ); |
| 1690 | |
| 1691 | var fo = vc.root().getOperand(0).getOperand(0); |
| 1692 | expect(fo.key()).toEqual('Titel'); |
| 1693 | expect(fo.value()).toEqual('Baum'); |
| 1694 | |
| 1695 | // Add unspecified on the root group |
| 1696 | _orOn(fo); |
| 1697 | |
| 1698 | fo = vc.root().getOperand(0).getOperand(0); |
| 1699 | |
| 1700 | expect(fo.operation()).toEqual('or'); |
| 1701 | expect(fo.getOperand(0).ldType()).toEqual('doc'); |
| 1702 | expect(fo.getOperand(1).ldType()).toEqual('non'); |
| 1703 | |
| 1704 | // Delete unspecified doc |
| 1705 | _delOn(fo.getOperand(1)); |
| 1706 | |
| 1707 | // The operand is now non |
| 1708 | fo = vc.root().getOperand(0); |
| 1709 | expect(fo.getOperand(0).ldType()).toEqual('doc'); |
| 1710 | expect(fo.getOperand(0).key()).toEqual('Titel'); |
| 1711 | expect(fo.getOperand(0).value()).toEqual('Baum'); |
| 1712 | expect(fo.getOperand(1).ldType()).toEqual('doc'); |
| 1713 | expect(fo.getOperand(2).ldType()).toEqual('docGroup'); |
| 1714 | }); |
| 1715 | |
| 1716 | |
| 1717 | it('should add on parent group (case "and")', function () { |
| 1718 | var vc = complexVCFactory.create(); |
| 1719 | |
| 1720 | // Wrap with direct element access |
| 1721 | expect(vc.toQuery()).toEqual( |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 1722 | 'pubDate in 2014-12-05 & (title = "Hello World!" | foo = "bar")' |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1723 | ); |
| 1724 | |
| 1725 | expect(vc.root().operands().length).toEqual(2); |
| 1726 | |
| 1727 | // Add unspecified on the root group |
| 1728 | _andOn(vc.root().getOperand(1)); |
| 1729 | expect(vc.toQuery()).toEqual( |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 1730 | 'pubDate in 2014-12-05 & (title = "Hello World!" | foo = "bar")' |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1731 | ); |
| 1732 | |
| 1733 | expect(vc.root().ldType()).toEqual('docGroup'); |
| 1734 | expect(vc.root().operands().length).toEqual(3); |
| 1735 | expect(vc.root().getOperand(0).ldType()).toEqual('doc'); |
| 1736 | expect(vc.root().getOperand(1).ldType()).toEqual('docGroup'); |
| 1737 | expect(vc.root().getOperand(1).operation()).toEqual('or'); |
| 1738 | expect(vc.root().getOperand(2).ldType()).toEqual('non'); |
| 1739 | |
| 1740 | // Add another unspecified on the root group |
| 1741 | _andOn(vc.root().getOperand(1)); |
| 1742 | |
| 1743 | expect(vc.root().operands().length).toEqual(4); |
| 1744 | expect(vc.root().getOperand(0).ldType()).toEqual('doc'); |
| 1745 | expect(vc.root().getOperand(1).ldType()).toEqual('docGroup'); |
| 1746 | expect(vc.root().getOperand(2).ldType()).toEqual('non'); |
| 1747 | expect(vc.root().getOperand(3).ldType()).toEqual('non'); |
| 1748 | |
| 1749 | // Add another unspecified after the first doc |
| 1750 | _andOn(vc.root().getOperand(0)); |
| 1751 | |
| 1752 | expect(vc.root().operands().length).toEqual(5); |
| 1753 | expect(vc.root().getOperand(0).ldType()).toEqual('doc'); |
| 1754 | expect(vc.root().getOperand(1).ldType()).toEqual('non'); |
| 1755 | expect(vc.root().getOperand(2).ldType()).toEqual('docGroup'); |
| 1756 | expect(vc.root().getOperand(3).ldType()).toEqual('non'); |
| 1757 | expect(vc.root().getOperand(4).ldType()).toEqual('non'); |
| 1758 | }); |
| 1759 | |
| 1760 | it('should wrap on root', function () { |
Nils Diewald | 6283d69 | 2015-04-23 20:32:53 +0000 | [diff] [blame] | 1761 | var vc = vcClass.create().fromJson( |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 1762 | { |
| 1763 | "@type": 'koral:docGroup', |
| 1764 | 'operation' : 'operation:and', |
| 1765 | 'operands' : [ |
| 1766 | { |
| 1767 | "@type": 'koral:doc', |
| 1768 | "key": 'pubDate', |
| 1769 | "match": 'match:eq', |
| 1770 | "value": '2014-12-05', |
| 1771 | "type": 'type:date' |
| 1772 | }, |
| 1773 | { |
| 1774 | "@type" : 'koral:doc', |
| 1775 | 'key' : 'foo', |
| 1776 | 'value' : 'bar' |
| 1777 | } |
| 1778 | ] |
| 1779 | } |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1780 | ); |
| 1781 | |
| 1782 | // Wrap on root |
| 1783 | expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar"'); |
| 1784 | expect(vc.root().ldType()).toEqual('docGroup'); |
| 1785 | expect(vc.root().operation()).toEqual('and'); |
| 1786 | _orOn(vc.root()); |
| 1787 | expect(vc.root().ldType()).toEqual('docGroup'); |
| 1788 | expect(vc.root().operation()).toEqual('or'); |
| 1789 | |
| 1790 | expect(vc.root().getOperand(0).ldType()).toEqual('docGroup'); |
| 1791 | expect(vc.root().getOperand(0).operation()).toEqual('and'); |
| 1792 | }); |
| 1793 | |
| 1794 | it('should add on root (case "and")', function () { |
Nils Diewald | 6283d69 | 2015-04-23 20:32:53 +0000 | [diff] [blame] | 1795 | var vc = vcClass.create().fromJson( |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 1796 | { |
| 1797 | "@type": 'koral:doc', |
| 1798 | "key": 'pubDate', |
| 1799 | "match": 'match:eq', |
| 1800 | "value": '2014-12-05', |
| 1801 | "type": 'type:date' |
| 1802 | } |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1803 | ); |
| 1804 | |
| 1805 | expect(vc.toQuery()).toEqual('pubDate in 2014-12-05'); |
| 1806 | expect(vc.root().ldType()).toEqual('doc'); |
| 1807 | expect(vc.root().key()).toEqual('pubDate'); |
| 1808 | expect(vc.root().value()).toEqual('2014-12-05'); |
| 1809 | |
| 1810 | // Wrap on root |
| 1811 | _andOn(vc.root()); |
| 1812 | expect(vc.root().ldType()).toEqual('docGroup'); |
| 1813 | expect(vc.root().operation()).toEqual('and'); |
| 1814 | }); |
| 1815 | |
| 1816 | it('should add on root (case "or")', function () { |
Nils Diewald | 6283d69 | 2015-04-23 20:32:53 +0000 | [diff] [blame] | 1817 | var vc = vcClass.create().fromJson( |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 1818 | { |
| 1819 | "@type": 'koral:doc', |
| 1820 | "key": 'pubDate', |
| 1821 | "match": 'match:eq', |
| 1822 | "value": '2014-12-05', |
| 1823 | "type": 'type:date' |
| 1824 | } |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1825 | ); |
| 1826 | |
| 1827 | expect(vc.toQuery()).toEqual('pubDate in 2014-12-05'); |
| 1828 | expect(vc.root().key()).toEqual('pubDate'); |
| 1829 | expect(vc.root().value()).toEqual('2014-12-05'); |
| 1830 | |
| 1831 | // Wrap on root |
| 1832 | _orOn(vc.root()); |
| 1833 | expect(vc.root().ldType()).toEqual('docGroup'); |
| 1834 | expect(vc.root().operation()).toEqual('or'); |
| 1835 | }); |
| 1836 | |
| 1837 | it('should support multiple sub groups per group', function () { |
Nils Diewald | 6283d69 | 2015-04-23 20:32:53 +0000 | [diff] [blame] | 1838 | var vc = vcClass.create().fromJson( |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 1839 | { |
| 1840 | "@type": 'koral:docGroup', |
| 1841 | 'operation' : 'operation:or', |
| 1842 | 'operands' : [ |
| 1843 | { |
| 1844 | "@type": 'koral:docGroup', |
| 1845 | 'operation' : 'operation:and', |
| 1846 | 'operands' : [ |
| 1847 | { |
| 1848 | "@type": 'koral:doc', |
| 1849 | "key": 'title', |
| 1850 | "value": 't1', |
| 1851 | }, |
| 1852 | { |
| 1853 | "@type" : 'koral:doc', |
| 1854 | 'key' : 'title', |
| 1855 | 'value' : 't2' |
| 1856 | } |
| 1857 | ] |
| 1858 | }, |
| 1859 | { |
| 1860 | "@type": 'koral:docGroup', |
| 1861 | 'operation' : 'operation:and', |
| 1862 | 'operands' : [ |
| 1863 | { |
| 1864 | "@type": 'koral:doc', |
| 1865 | "key": 'title', |
| 1866 | "value": 't3', |
| 1867 | }, |
| 1868 | { |
| 1869 | "@type" : 'koral:doc', |
| 1870 | 'key' : 'title', |
| 1871 | 'value' : 't4' |
| 1872 | } |
| 1873 | ] |
| 1874 | } |
| 1875 | ] |
| 1876 | } |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1877 | ); |
| 1878 | expect(vc.toQuery()).toEqual( |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 1879 | '(title = "t1" & title = "t2") | ' + |
| 1880 | '(title = "t3" & title = "t4")' |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1881 | ); |
| 1882 | expect(vc.root().operation()).toEqual('or'); |
| 1883 | expect(vc.root().getOperand(0).toQuery()).toEqual('title = "t1" & title = "t2"'); |
| 1884 | expect(vc.root().getOperand(1).toQuery()).toEqual('title = "t3" & title = "t4"'); |
| 1885 | |
| 1886 | _andOn(vc.root()); |
| 1887 | |
| 1888 | expect(vc.root().operation()).toEqual('and'); |
| 1889 | expect(vc.root().getOperand(0).ldType()).toEqual('docGroup'); |
| 1890 | expect(vc.root().getOperand(1).ldType()).toEqual('non'); |
| 1891 | }); |
| 1892 | }); |
| 1893 | |
Akron | 5c829e9 | 2017-05-12 18:10:00 +0200 | [diff] [blame] | 1894 | // Check class method |
| 1895 | describe('KorAP.VC.checkRewrite', function () { |
| 1896 | |
| 1897 | it('should check for simple rewrites', function () { |
| 1898 | expect(vcClass.checkRewrite( |
| 1899 | { |
| 1900 | "@type" : "koral:doc", |
| 1901 | "rewrites" : [{ |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 1902 | "@type" : "koral:rewrite", |
| 1903 | "operation" : "operation:modification", |
| 1904 | "src" : "querySerializer", |
| 1905 | "scope" : "tree" |
Akron | 5c829e9 | 2017-05-12 18:10:00 +0200 | [diff] [blame] | 1906 | }] |
| 1907 | } |
| 1908 | )).toBeTruthy(); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1909 | |
Akron | 5c829e9 | 2017-05-12 18:10:00 +0200 | [diff] [blame] | 1910 | var nested = { |
| 1911 | "@type" : "koral:docGroup", |
| 1912 | "operands" : [ |
| 1913 | { |
| 1914 | "@type" : "koral:doc" |
| 1915 | }, |
| 1916 | { |
| 1917 | "@type" : "koral:docGroup", |
| 1918 | "operands" : [ |
| 1919 | { |
| 1920 | "@type": "koral:doc" |
| 1921 | }, |
| 1922 | { |
| 1923 | "@type": "koral:doc" |
| 1924 | } |
| 1925 | ] |
| 1926 | } |
| 1927 | ] |
| 1928 | }; |
| 1929 | |
| 1930 | expect(vcClass.checkRewrite(nested)).toBe(false); |
| 1931 | |
| 1932 | nested["operands"][1]["operands"][1]["rewrites"] = [{ |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 1933 | "@type" : "koral:rewrite", |
| 1934 | "operation" : "operation:modification", |
| 1935 | "src" : "querySerializer", |
| 1936 | "scope" : "tree" |
Akron | 5c829e9 | 2017-05-12 18:10:00 +0200 | [diff] [blame] | 1937 | }]; |
| 1938 | |
| 1939 | expect(vcClass.checkRewrite(nested)).toBeTruthy(); |
| 1940 | }); |
| 1941 | }); |
Nils Diewald | 6283d69 | 2015-04-23 20:32:53 +0000 | [diff] [blame] | 1942 | |
| 1943 | describe('KorAP.Rewrite', function () { |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1944 | it('should be initializable', function () { |
| 1945 | var rewrite = rewriteClass.create({ |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 1946 | "@type" : "koral:rewrite", |
| 1947 | "operation" : "operation:modification", |
| 1948 | "src" : "querySerializer", |
| 1949 | "scope" : "tree" |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 1950 | }); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1951 | expect(rewrite.toString()).toEqual('Modification of "tree" by "querySerializer"'); |
| 1952 | }); |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 1953 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1954 | it('should be deserialized by docs', function () { |
| 1955 | var doc = docClass.create( |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 1956 | undefined, |
| 1957 | { |
| 1958 | "@type":"koral:doc", |
| 1959 | "key":"Titel", |
| 1960 | "value":"Baum", |
| 1961 | "match":"match:eq" |
| 1962 | }); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1963 | |
| 1964 | expect(doc.element().classList.contains('doc')).toBeTruthy(); |
| 1965 | expect(doc.element().classList.contains('rewritten')).toBe(false); |
| 1966 | |
| 1967 | doc = docClass.create( |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 1968 | undefined, |
| 1969 | { |
| 1970 | "@type":"koral:doc", |
| 1971 | "key":"Titel", |
| 1972 | "value":"Baum", |
| 1973 | "match":"match:eq", |
| 1974 | "rewrites" : [ |
| 1975 | { |
| 1976 | "@type" : "koral:rewrite", |
| 1977 | "operation" : "operation:modification", |
| 1978 | "src" : "querySerializer", |
| 1979 | "scope" : "tree" |
| 1980 | } |
| 1981 | ] |
| 1982 | }); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1983 | |
| 1984 | expect(doc.element().classList.contains('doc')).toBeTruthy(); |
| 1985 | expect(doc.element().classList.contains('rewritten')).toBeTruthy(); |
| 1986 | }); |
Nils Diewald | 6283d69 | 2015-04-23 20:32:53 +0000 | [diff] [blame] | 1987 | |
| 1988 | xit('should be deserialized by docGroups', function () { |
| 1989 | var docGroup = docGroupClass.create( |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 1990 | undefined, |
| 1991 | { |
| 1992 | "@type" : "koral:docGroup", |
| 1993 | "operation" : "operation:or", |
| 1994 | "operands" : [ |
| 1995 | { |
| 1996 | "@type" : "doc", |
| 1997 | "key" : "pubDate", |
| 1998 | "type" : "type:date", |
| 1999 | "value" : "2014-12-05" |
| 2000 | }, |
| 2001 | { |
| 2002 | "@type" : "doc", |
| 2003 | "key" : "pubDate", |
| 2004 | "type" : "type:date", |
| 2005 | "value" : "2014-12-06" |
| 2006 | } |
| 2007 | ], |
| 2008 | "rewrites" : [ |
| 2009 | { |
| 2010 | "@type" : "koral:rewrite", |
| 2011 | "operation" : "operation:modification", |
| 2012 | "src" : "querySerializer", |
| 2013 | "scope" : "tree" |
| 2014 | } |
| 2015 | ] |
| 2016 | } |
Nils Diewald | 6283d69 | 2015-04-23 20:32:53 +0000 | [diff] [blame] | 2017 | ); |
| 2018 | |
| 2019 | expect(doc.element().classList.contains('docgroup')).toBeTruthy(); |
| 2020 | expect(doc.element().classList.contains('rewritten')).toBe(false); |
| 2021 | }); |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 2022 | }); |
Nils Diewald | f0c4f11 | 2015-05-05 12:56:59 +0000 | [diff] [blame] | 2023 | |
| 2024 | describe('KorAP.stringValue', function () { |
| 2025 | it('should be initializable', function () { |
| 2026 | var sv = stringValClass.create(); |
| 2027 | expect(sv.regex()).toBe(false); |
| 2028 | expect(sv.value()).toBe(''); |
Nils Diewald | c4c4b83 | 2015-05-05 16:00:08 +0000 | [diff] [blame] | 2029 | |
| 2030 | sv = stringValClass.create('Baum'); |
| 2031 | expect(sv.regex()).toBe(false); |
| 2032 | expect(sv.value()).toBe('Baum'); |
| 2033 | |
| 2034 | sv = stringValClass.create('Baum', false); |
| 2035 | expect(sv.regex()).toBe(false); |
| 2036 | expect(sv.value()).toBe('Baum'); |
| 2037 | |
| 2038 | sv = stringValClass.create('Baum', true); |
| 2039 | expect(sv.regex()).toBe(true); |
| 2040 | expect(sv.value()).toBe('Baum'); |
| 2041 | }); |
| 2042 | |
| 2043 | it('should be modifiable', function () { |
| 2044 | var sv = stringValClass.create(); |
| 2045 | expect(sv.regex()).toBe(false); |
| 2046 | expect(sv.value()).toBe(''); |
| 2047 | |
| 2048 | expect(sv.value('Baum')).toBe('Baum'); |
| 2049 | expect(sv.value()).toBe('Baum'); |
| 2050 | |
| 2051 | expect(sv.regex(true)).toBe(true); |
| 2052 | expect(sv.regex()).toBe(true); |
| 2053 | }); |
| 2054 | |
| 2055 | it('should have a toggleble regex value', function () { |
| 2056 | var sv = stringValClass.create(); |
Nils Diewald | 7991a3f | 2015-05-19 14:12:37 +0000 | [diff] [blame] | 2057 | |
| 2058 | expect(sv.element().firstChild.value).toBe(''); |
| 2059 | sv.element().firstChild.value = 'der' |
| 2060 | expect(sv.element().firstChild.value).toBe('der'); |
| 2061 | |
Nils Diewald | c4c4b83 | 2015-05-05 16:00:08 +0000 | [diff] [blame] | 2062 | expect(sv.regex()).toBe(false); |
| 2063 | |
| 2064 | sv.toggleRegex(); |
Nils Diewald | 7991a3f | 2015-05-19 14:12:37 +0000 | [diff] [blame] | 2065 | expect(sv.element().firstChild.value).toBe('der'); |
Nils Diewald | c4c4b83 | 2015-05-05 16:00:08 +0000 | [diff] [blame] | 2066 | expect(sv.regex()).toBe(true); |
Nils Diewald | 7991a3f | 2015-05-19 14:12:37 +0000 | [diff] [blame] | 2067 | sv.element().firstChild.value = 'derbe' |
Nils Diewald | c4c4b83 | 2015-05-05 16:00:08 +0000 | [diff] [blame] | 2068 | |
| 2069 | sv.toggleRegex(); |
| 2070 | expect(sv.regex()).toBe(false); |
Nils Diewald | 7991a3f | 2015-05-19 14:12:37 +0000 | [diff] [blame] | 2071 | expect(sv.element().firstChild.value).toBe('derbe'); |
Nils Diewald | c4c4b83 | 2015-05-05 16:00:08 +0000 | [diff] [blame] | 2072 | }); |
| 2073 | |
| 2074 | it('should have an element', function () { |
| 2075 | var sv = stringValClass.create('der'); |
| 2076 | expect(sv.element().nodeName).toBe('DIV'); |
| 2077 | expect(sv.element().firstChild.nodeName).toBe('INPUT'); |
| 2078 | expect(sv.element().firstChild.value).toBe('der'); |
| 2079 | }); |
| 2080 | |
| 2081 | it('should have a classed element', function () { |
| 2082 | var sv = stringValClass.create(); |
Nils Diewald | c4c4b83 | 2015-05-05 16:00:08 +0000 | [diff] [blame] | 2083 | expect(sv.element().classList.contains('regex')).toBe(false); |
| 2084 | expect(sv.regex()).toBe(false); |
| 2085 | sv.toggleRegex(); |
| 2086 | expect(sv.element().classList.contains('regex')).toBe(true); |
| 2087 | }); |
| 2088 | |
| 2089 | it('should be storable', function () { |
| 2090 | var sv = stringValClass.create(); |
| 2091 | var count = 1; |
| 2092 | sv.store = function (value, regex) { |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 2093 | expect(regex).toBe(true); |
| 2094 | expect(value).toBe('tree'); |
Nils Diewald | c4c4b83 | 2015-05-05 16:00:08 +0000 | [diff] [blame] | 2095 | }; |
| 2096 | sv.regex(true); |
| 2097 | sv.value('tree'); |
| 2098 | sv.element().lastChild.click(); |
Nils Diewald | f0c4f11 | 2015-05-05 12:56:59 +0000 | [diff] [blame] | 2099 | }); |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 2100 | |
Nils Diewald | f0c4f11 | 2015-05-05 12:56:59 +0000 | [diff] [blame] | 2101 | }); |
Akron | e4961b1 | 2017-05-10 21:04:46 +0200 | [diff] [blame] | 2102 | |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 2103 | describe('KorAP.VC.Menu', function () { |
Akron | e65a88a | 2018-04-05 19:14:20 +0200 | [diff] [blame] | 2104 | |
| 2105 | var vc; |
| 2106 | |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 2107 | it('should be initializable', function () { |
| 2108 | |
Akron | e65a88a | 2018-04-05 19:14:20 +0200 | [diff] [blame] | 2109 | vc = vcClass.create([ |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 2110 | ['a', 'text'], |
| 2111 | ['b', 'string'], |
| 2112 | ['c', 'date'] |
| 2113 | ]).fromJson(); |
| 2114 | expect(vc.element().firstChild.classList.contains('unspecified')).toBeTruthy(); |
| 2115 | expect(vc.element().firstChild.firstChild.tagName).toEqual('SPAN'); |
| 2116 | |
| 2117 | // Click on unspecified |
| 2118 | vc.element().firstChild.firstChild.click(); |
| 2119 | expect(vc.element().firstChild.firstChild.tagName).toEqual('UL'); |
| 2120 | |
| 2121 | var list = vc.element().firstChild.firstChild; |
| 2122 | expect(list.getElementsByTagName("LI")[0].innerText).toEqual('a'); |
| 2123 | expect(list.getElementsByTagName("LI")[1].innerText).toEqual('b'); |
| 2124 | expect(list.getElementsByTagName("LI")[2].innerText).toEqual('c'); |
| 2125 | |
| 2126 | vc = vcClass.create([ |
| 2127 | ['d', 'text'], |
| 2128 | ['e', 'string'], |
| 2129 | ['f', 'date'] |
| 2130 | ]).fromJson(); |
| 2131 | expect(vc.element().firstChild.classList.contains('unspecified')).toBeTruthy(); |
| 2132 | expect(vc.element().firstChild.firstChild.tagName).toEqual('SPAN'); |
| 2133 | |
| 2134 | // Click on unspecified |
| 2135 | vc.element().firstChild.firstChild.click(); |
| 2136 | expect(vc.element().firstChild.firstChild.tagName).toEqual('UL'); |
| 2137 | |
| 2138 | list = vc.element().firstChild.firstChild; |
| 2139 | expect(list.getElementsByTagName("LI")[0].innerText).toEqual('d'); |
| 2140 | expect(list.getElementsByTagName("LI")[1].innerText).toEqual('e'); |
| 2141 | expect(list.getElementsByTagName("LI")[2].innerText).toEqual('f'); |
Akron | 31d8994 | 2018-04-06 16:44:51 +0200 | [diff] [blame] | 2142 | // blur |
| 2143 | document.body.click(); |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 2144 | }); |
Akron | e65a88a | 2018-04-05 19:14:20 +0200 | [diff] [blame] | 2145 | |
| 2146 | // Reinitialize to make tests stable |
| 2147 | vc = vcClass.create([ |
| 2148 | ['d', 'text'], |
| 2149 | ['e', 'string'], |
| 2150 | ['f', 'date'] |
| 2151 | ]).fromJson(); |
| 2152 | |
| 2153 | it('should be clickable on key', function () { |
Akron | 31d8994 | 2018-04-06 16:44:51 +0200 | [diff] [blame] | 2154 | // Click on unspecified |
| 2155 | vc.element().firstChild.firstChild.click(); |
Akron | e65a88a | 2018-04-05 19:14:20 +0200 | [diff] [blame] | 2156 | // Click on "d" |
| 2157 | vc.element().firstChild.firstChild.getElementsByTagName("LI")[0].click(); |
| 2158 | expect(vc.element().firstChild.firstChild.tagName).toEqual('SPAN'); |
| 2159 | expect(vc.element().firstChild.firstChild.innerText).toEqual('d'); |
| 2160 | expect(vc.element().firstChild.children[1].innerText).toEqual('eq'); |
| 2161 | expect(vc.element().firstChild.children[1].getAttribute('data-type')).toEqual('text'); |
Akron | 31d8994 | 2018-04-06 16:44:51 +0200 | [diff] [blame] | 2162 | // blur |
| 2163 | document.body.click(); |
Akron | e65a88a | 2018-04-05 19:14:20 +0200 | [diff] [blame] | 2164 | }); |
| 2165 | |
Akron | 31d8994 | 2018-04-06 16:44:51 +0200 | [diff] [blame] | 2166 | it('should be clickable on operation for text', function () { |
| 2167 | // Click on "d" (or unspecified) |
| 2168 | vc.element().firstChild.firstChild.click(); |
| 2169 | |
| 2170 | // Choose "d" |
| 2171 | vc.element().firstChild.firstChild.getElementsByTagName("LI")[0].click(); |
| 2172 | |
| 2173 | // Click on matchop |
Akron | e65a88a | 2018-04-05 19:14:20 +0200 | [diff] [blame] | 2174 | vc.element().firstChild.children[1].click(); |
Akron | 31d8994 | 2018-04-06 16:44:51 +0200 | [diff] [blame] | 2175 | |
Akron | e65a88a | 2018-04-05 19:14:20 +0200 | [diff] [blame] | 2176 | expect(vc.element().firstChild.children[1].tagName).toEqual('UL'); |
Akron | 31d8994 | 2018-04-06 16:44:51 +0200 | [diff] [blame] | 2177 | |
Akron | e65a88a | 2018-04-05 19:14:20 +0200 | [diff] [blame] | 2178 | var ul = vc.element().firstChild.children[1]; |
| 2179 | expect(ul.getElementsByTagName('li')[0].innerText).toEqual("eq"); |
| 2180 | expect(ul.getElementsByTagName('li')[1].innerText).toEqual("ne"); |
| 2181 | expect(ul.getElementsByTagName('li')[2].innerText).toEqual("contains"); |
| 2182 | expect(ul.getElementsByTagName('li')[3].innerText).toEqual("containsnot"); |
| 2183 | expect(ul.getElementsByTagName('li')[4]).toBeUndefined(); |
Akron | 31d8994 | 2018-04-06 16:44:51 +0200 | [diff] [blame] | 2184 | |
| 2185 | // Choose "contains" |
| 2186 | ul.getElementsByTagName('li')[2].click(); |
| 2187 | expect(vc.element().firstChild.children[1].tagName).toEqual("SPAN"); |
| 2188 | expect(vc.element().firstChild.children[1].innerText).toEqual("contains"); |
| 2189 | // blur |
| 2190 | document.body.click(); |
Akron | e65a88a | 2018-04-05 19:14:20 +0200 | [diff] [blame] | 2191 | }) |
Akron | 31d8994 | 2018-04-06 16:44:51 +0200 | [diff] [blame] | 2192 | |
| 2193 | it('should be clickable on operation for string', function () { |
| 2194 | // Click on "d" (or unspecified) |
| 2195 | vc.element().firstChild.firstChild.click(); |
| 2196 | |
| 2197 | // Choose "e" |
| 2198 | vc.element().firstChild.firstChild.getElementsByTagName("LI")[1].click(); |
| 2199 | |
| 2200 | // As a consequence the matchoperator may no longer |
| 2201 | // be valid and needs to be re-evaluated |
| 2202 | var fc = vc.element().firstChild; |
| 2203 | expect(fc.firstChild.tagName).toEqual('SPAN'); |
| 2204 | expect(fc.firstChild.innerText).toEqual('e'); |
| 2205 | expect(fc.children[1].innerText).toEqual('eq'); |
| 2206 | expect(fc.children[1].getAttribute('data-type')).toEqual('string'); |
| 2207 | |
| 2208 | vc.element().firstChild.children[1].click(); |
| 2209 | |
| 2210 | expect(vc.element().firstChild.children[1].tagName).toEqual('UL'); |
| 2211 | |
| 2212 | var ul = vc.element().firstChild.children[1]; |
| 2213 | expect(ul.getElementsByTagName('li')[0].innerText).toEqual("eq"); |
| 2214 | expect(ul.getElementsByTagName('li')[1].innerText).toEqual("ne"); |
| 2215 | expect(ul.getElementsByTagName('li')[2]).toBeUndefined(); |
| 2216 | |
| 2217 | // Choose "ne" |
| 2218 | ul.getElementsByTagName('li')[1].click(); |
| 2219 | expect(vc.element().firstChild.children[1].tagName).toEqual("SPAN"); |
| 2220 | expect(vc.element().firstChild.children[1].innerText).toEqual("ne"); |
| 2221 | // blur |
| 2222 | document.body.click(); |
| 2223 | }); |
| 2224 | |
| 2225 | it('should be clickable on operation for date', function () { |
| 2226 | |
| 2227 | // Replay matchop check - so it's guaranteed that "ne" is chosen |
| 2228 | // Click on "e" (or unspecified) |
| 2229 | vc.element().firstChild.firstChild.click(); |
| 2230 | // Rechoose "e" |
| 2231 | vc.element().firstChild.firstChild.getElementsByTagName("LI")[1].click(); |
| 2232 | // Click on matchop |
| 2233 | vc.element().firstChild.children[1].click(); |
| 2234 | // Choose "ne" |
| 2235 | vc.element().firstChild.children[1].getElementsByTagName('li')[1].click(); |
| 2236 | expect(vc.element().firstChild.children[1].innerText).toEqual("ne"); |
| 2237 | |
| 2238 | // Click on "e" |
| 2239 | vc.element().firstChild.firstChild.click(); |
| 2240 | // Choose "f" |
| 2241 | vc.element().firstChild.firstChild.getElementsByTagName("LI")[2].click(); |
| 2242 | |
| 2243 | // The matchoperator should still be "ne" as this is valid for dates as well (now) |
| 2244 | var fc = vc.element().firstChild; |
| 2245 | expect(fc.firstChild.tagName).toEqual('SPAN'); |
| 2246 | expect(fc.firstChild.innerText).toEqual('f'); |
| 2247 | expect(fc.children[1].innerText).toEqual('ne'); |
| 2248 | // blur |
| 2249 | document.body.click(); |
| 2250 | }); |
Akron | ddc98a7 | 2018-04-06 17:33:52 +0200 | [diff] [blame] | 2251 | |
| 2252 | |
| 2253 | // Check json deserialization |
| 2254 | it('should be initializable', function () { |
| 2255 | vc = vcClass.create([ |
| 2256 | ['a', 'text'], |
| 2257 | ['b', 'string'], |
| 2258 | ['c', 'date'] |
| 2259 | ]).fromJson({ |
| 2260 | "@type" : "koral:doc", |
| 2261 | "key":"a", |
| 2262 | "value":"Baum" |
| 2263 | }); |
| 2264 | |
| 2265 | expect(vc.element().firstChild.children[1].getAttribute('data-type')).toEqual('text'); |
| 2266 | }); |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 2267 | }); |
| 2268 | |
| 2269 | |
Akron | e4961b1 | 2017-05-10 21:04:46 +0200 | [diff] [blame] | 2270 | // Check prefix |
| 2271 | describe('KorAP.VC.Prefix', function () { |
| 2272 | |
| 2273 | it('should be initializable', function () { |
| 2274 | var p = prefixClass.create(); |
| 2275 | expect(p.element().classList.contains('pref')).toBeTruthy(); |
| 2276 | expect(p.isSet()).not.toBeTruthy(); |
| 2277 | }); |
| 2278 | |
| 2279 | |
| 2280 | it('should be clickable', function () { |
| 2281 | var vc = vcClass.create([ |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 2282 | ['a', null], |
| 2283 | ['b', null], |
| 2284 | ['c', null] |
| 2285 | ]).fromJson(); |
Akron | e4961b1 | 2017-05-10 21:04:46 +0200 | [diff] [blame] | 2286 | expect(vc.element().firstChild.classList.contains('unspecified')).toBeTruthy(); |
| 2287 | |
| 2288 | // This should open up the menu |
| 2289 | vc.element().firstChild.firstChild.click(); |
| 2290 | expect(vc.element().firstChild.firstChild.tagName).toEqual('UL'); |
| 2291 | |
| 2292 | KorAP._vcKeyMenu._prefix.clear(); |
| 2293 | KorAP._vcKeyMenu._prefix.add('x'); |
| 2294 | |
| 2295 | var prefElement = vc.element().querySelector('span.pref'); |
| 2296 | expect(prefElement.innerText).toEqual('x'); |
| 2297 | |
| 2298 | // This should add key 'x' to VC |
| 2299 | prefElement.click(); |
| 2300 | |
| 2301 | expect(vc.element().firstChild.classList.contains('doc')).toBeTruthy(); |
| 2302 | expect(vc.element().firstChild.firstChild.className).toEqual('key'); |
| 2303 | expect(vc.element().firstChild.firstChild.innerText).toEqual('x'); |
| 2304 | }); |
| 2305 | }); |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame] | 2306 | }); |