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