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