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")); |
Akron | 1bdf527 | 2018-07-24 18:51:30 +0200 | [diff] [blame] | 1362 | }); |
| 1363 | |
| 1364 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1365 | describe('KorAP.Operators', function () { |
| 1366 | it('should be initializable', function () { |
| 1367 | var op = operatorsClass.create(true, false, false); |
| 1368 | expect(op.and()).toBeTruthy(); |
| 1369 | expect(op.or()).not.toBeTruthy(); |
| 1370 | expect(op.del()).not.toBeTruthy(); |
| 1371 | |
| 1372 | op.and(false); |
| 1373 | expect(op.and()).not.toBeTruthy(); |
| 1374 | expect(op.or()).not.toBeTruthy(); |
| 1375 | expect(op.del()).not.toBeTruthy(); |
| 1376 | |
| 1377 | op.or(true); |
| 1378 | op.del(true); |
| 1379 | expect(op.and()).not.toBeTruthy(); |
| 1380 | expect(op.or()).toBeTruthy(); |
| 1381 | expect(op.del()).toBeTruthy(); |
| 1382 | |
Akron | d141a36 | 2018-07-10 18:12:13 +0200 | [diff] [blame] | 1383 | var e = op.update(); |
Akron | 0b489ad | 2018-02-02 16:49:32 +0100 | [diff] [blame] | 1384 | expect(e.getAttribute('class')).toEqual('operators button-group'); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1385 | expect(e.children[0].getAttribute('class')).toEqual('or'); |
Akron | d141a36 | 2018-07-10 18:12:13 +0200 | [diff] [blame] | 1386 | expect(e.children[0].innerText).toEqual('or'); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1387 | expect(e.children[1].getAttribute('class')).toEqual('delete'); |
Akron | d141a36 | 2018-07-10 18:12:13 +0200 | [diff] [blame] | 1388 | expect(e.children[1].innerText).toEqual('×'); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1389 | |
| 1390 | op.and(true); |
| 1391 | op.del(false); |
Akron | d141a36 | 2018-07-10 18:12:13 +0200 | [diff] [blame] | 1392 | e = op.update(); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1393 | |
Akron | 0b489ad | 2018-02-02 16:49:32 +0100 | [diff] [blame] | 1394 | expect(e.getAttribute('class')).toEqual('operators button-group'); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1395 | expect(e.children[0].getAttribute('class')).toEqual('and'); |
Akron | d141a36 | 2018-07-10 18:12:13 +0200 | [diff] [blame] | 1396 | expect(e.children[0].innerText).toEqual('and'); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1397 | expect(e.children[1].getAttribute('class')).toEqual('or'); |
Akron | d141a36 | 2018-07-10 18:12:13 +0200 | [diff] [blame] | 1398 | expect(e.children[1].innerText).toEqual('or'); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1399 | }); |
| 1400 | }); |
| 1401 | |
| 1402 | describe('KorAP._delete (event)', function () { |
| 1403 | var complexVCFactory = buildFactory(vcClass,{ |
| 1404 | "@type": 'koral:docGroup', |
| 1405 | 'operation' : 'operation:and', |
| 1406 | 'operands' : [ |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 1407 | { |
| 1408 | "@type": 'koral:doc', |
| 1409 | "key": 'pubDate', |
| 1410 | "match": 'match:eq', |
| 1411 | "value": '2014-12-05', |
| 1412 | "type": 'type:date' |
| 1413 | }, |
| 1414 | { |
| 1415 | "@type" : 'koral:docGroup', |
| 1416 | 'operation' : 'operation:or', |
| 1417 | 'operands' : [ |
| 1418 | { |
| 1419 | '@type' : 'koral:doc', |
| 1420 | 'key' : 'title', |
| 1421 | 'value' : 'Hello World!' |
| 1422 | }, |
| 1423 | { |
| 1424 | '@type' : 'koral:doc', |
| 1425 | 'key' : 'foo', |
| 1426 | 'value' : 'bar' |
| 1427 | } |
| 1428 | ] |
| 1429 | } |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1430 | ] |
| 1431 | }); |
| 1432 | |
| 1433 | it('should clean on root docs', function () { |
Nils Diewald | 6283d69 | 2015-04-23 20:32:53 +0000 | [diff] [blame] | 1434 | var vc = vcClass.create().fromJson({ |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 1435 | "@type": 'koral:doc', |
| 1436 | "key": 'pubDate', |
| 1437 | "match": 'match:eq', |
| 1438 | "value": '2014-12-05', |
| 1439 | "type": 'type:date' |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 1440 | }); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1441 | expect(vc.root().toQuery()).toEqual('pubDate in 2014-12-05'); |
Akron | 0b489ad | 2018-02-02 16:49:32 +0100 | [diff] [blame] | 1442 | expect(vc.root().element().lastChild.getAttribute('class')).toEqual('operators button-group'); |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 1443 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1444 | // Clean with delete from root |
| 1445 | expect(vc.root().element().lastChild.lastChild.getAttribute('class')).toEqual('delete'); |
| 1446 | _delOn(vc.root()); |
| 1447 | expect(vc.root().toQuery()).toEqual(''); |
| 1448 | expect(vc.root().element().lastChild.lastChild.data).toEqual('⋯'); |
| 1449 | }); |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 1450 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1451 | it('should remove on nested docs', function () { |
Nils Diewald | 6283d69 | 2015-04-23 20:32:53 +0000 | [diff] [blame] | 1452 | var vc = vcClass.create().fromJson( |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 1453 | { |
| 1454 | "@type": 'koral:docGroup', |
| 1455 | 'operation' : 'operation:and', |
| 1456 | 'operands' : [ |
| 1457 | { |
| 1458 | "@type": 'koral:doc', |
| 1459 | "key": 'pubDate', |
| 1460 | "match": 'match:eq', |
| 1461 | "value": '2014-12-05', |
| 1462 | "type": 'type:date' |
| 1463 | }, |
| 1464 | { |
| 1465 | "@type" : 'koral:doc', |
| 1466 | 'key' : 'foo', |
| 1467 | 'value' : 'bar' |
| 1468 | } |
| 1469 | ] |
| 1470 | } |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1471 | ); |
| 1472 | |
| 1473 | // Delete with direct element access |
| 1474 | expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar"'); |
| 1475 | _delOn(vc.root().getOperand(0)); |
| 1476 | |
| 1477 | expect(vc.toQuery()).toEqual('foo = "bar"'); |
| 1478 | expect(vc.root().ldType()).toEqual('doc'); |
| 1479 | }); |
| 1480 | |
| 1481 | it('should clean on doc groups', function () { |
Nils Diewald | 6283d69 | 2015-04-23 20:32:53 +0000 | [diff] [blame] | 1482 | var vc = vcClass.create().fromJson( |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 1483 | { |
| 1484 | "@type": 'koral:docGroup', |
| 1485 | 'operation' : 'operation:and', |
| 1486 | 'operands' : [ |
| 1487 | { |
| 1488 | "@type": 'koral:doc', |
| 1489 | "key": 'pubDate', |
| 1490 | "match": 'match:eq', |
| 1491 | "value": '2014-12-05', |
| 1492 | "type": 'type:date' |
| 1493 | }, |
| 1494 | { |
| 1495 | "@type" : 'koral:doc', |
| 1496 | 'key' : 'foo', |
| 1497 | 'value' : 'bar' |
| 1498 | } |
| 1499 | ] |
| 1500 | } |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1501 | ); |
| 1502 | |
| 1503 | // Cleanwith direct element access |
| 1504 | expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar"'); |
| 1505 | _delOn(vc.root()); |
| 1506 | expect(vc.toQuery()).toEqual(''); |
| 1507 | expect(vc.root().ldType()).toEqual('non'); |
| 1508 | }); |
| 1509 | |
| 1510 | it('should remove on nested doc groups (case of ungrouping 1)', function () { |
| 1511 | var vc = complexVCFactory.create(); |
| 1512 | |
| 1513 | // Delete with direct element access |
| 1514 | expect(vc.toQuery()).toEqual( |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 1515 | 'pubDate in 2014-12-05 & (title = "Hello World!" | foo = "bar")' |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1516 | ); |
| 1517 | |
| 1518 | // Remove hello world: |
| 1519 | _delOn(vc.root().getOperand(1).getOperand(0)); |
| 1520 | expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar"'); |
| 1521 | expect(vc.root().ldType()).toEqual('docGroup'); |
| 1522 | }); |
| 1523 | |
| 1524 | it('should remove on nested doc groups (case of ungrouping 2)', function () { |
| 1525 | var vc = complexVCFactory.create(); |
| 1526 | |
| 1527 | // Delete with direct element access |
| 1528 | expect(vc.toQuery()).toEqual( |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 1529 | 'pubDate in 2014-12-05 & (title = "Hello World!" | foo = "bar")' |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1530 | ); |
| 1531 | |
| 1532 | // Remove bar |
| 1533 | _delOn(vc.root().getOperand(1).getOperand(1)); |
| 1534 | expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & title = "Hello World!"'); |
| 1535 | expect(vc.root().ldType()).toEqual('docGroup'); |
| 1536 | expect(vc.root().operation()).toEqual('and'); |
| 1537 | }); |
| 1538 | |
| 1539 | it('should remove on nested doc groups (case of root changing)', function () { |
| 1540 | var vc = complexVCFactory.create(); |
| 1541 | |
| 1542 | // Delete with direct element access |
| 1543 | expect(vc.toQuery()).toEqual( |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 1544 | 'pubDate in 2014-12-05 & ' + |
| 1545 | '(title = "Hello World!" | foo = "bar")' |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1546 | ); |
| 1547 | |
| 1548 | // Remove bar |
| 1549 | _delOn(vc.root().getOperand(0)); |
| 1550 | expect(vc.toQuery()).toEqual('title = "Hello World!" | foo = "bar"'); |
| 1551 | expect(vc.root().ldType()).toEqual('docGroup'); |
| 1552 | expect(vc.root().operation()).toEqual('or'); |
| 1553 | }); |
| 1554 | |
| 1555 | it('should remove on nested doc groups (list flattening)', function () { |
Nils Diewald | 6283d69 | 2015-04-23 20:32:53 +0000 | [diff] [blame] | 1556 | var vc = vcClass.create().fromJson( |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 1557 | { |
| 1558 | "@type": 'koral:docGroup', |
| 1559 | 'operation' : 'operation:or', |
| 1560 | 'operands' : [ |
| 1561 | { |
| 1562 | "@type": 'koral:doc', |
| 1563 | "key": 'pubDate', |
| 1564 | "match": 'match:eq', |
| 1565 | "value": '2014-12-05', |
| 1566 | "type": 'type:date' |
| 1567 | }, |
| 1568 | { |
| 1569 | "@type" : 'koral:doc', |
| 1570 | 'key' : 'foo', |
| 1571 | 'value' : 'bar' |
| 1572 | }, |
| 1573 | { |
| 1574 | "@type": 'koral:docGroup', |
| 1575 | 'operation' : 'operation:and', |
| 1576 | 'operands' : [ |
| 1577 | { |
| 1578 | "@type": 'koral:doc', |
| 1579 | "key": 'pubDate', |
| 1580 | "match": 'match:eq', |
| 1581 | "value": '2014-12-05', |
| 1582 | "type": 'type:date' |
| 1583 | }, |
| 1584 | { |
| 1585 | "@type" : 'koral:docGroup', |
| 1586 | 'operation' : 'operation:or', |
| 1587 | 'operands' : [ |
| 1588 | { |
| 1589 | '@type' : 'koral:doc', |
| 1590 | 'key' : 'title', |
| 1591 | 'value' : 'Hello World!' |
| 1592 | }, |
| 1593 | { |
| 1594 | '@type' : 'koral:doc', |
| 1595 | 'key' : 'yeah', |
| 1596 | 'value' : 'juhu' |
| 1597 | } |
| 1598 | ] |
| 1599 | } |
| 1600 | ] |
| 1601 | } |
| 1602 | ] |
| 1603 | } |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1604 | ); |
| 1605 | |
| 1606 | // Delete with direct element access |
| 1607 | expect(vc.toQuery()).toEqual( |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 1608 | 'pubDate in 2014-12-05 | foo = "bar" | ' + |
| 1609 | '(pubDate in 2014-12-05 & ' + |
| 1610 | '(title = "Hello World!" | yeah = "juhu"))' |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1611 | ); |
| 1612 | |
| 1613 | expect(vc.root().ldType()).toEqual('docGroup'); |
| 1614 | expect(vc.root().operation()).toEqual('or'); |
| 1615 | |
| 1616 | // Operands and operators |
| 1617 | expect(vc.element().firstChild.children.length).toEqual(4); |
Akron | 0b489ad | 2018-02-02 16:49:32 +0100 | [diff] [blame] | 1618 | expect(vc.element().firstChild.lastChild.getAttribute('class')).toEqual('operators button-group'); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1619 | |
| 1620 | // Remove inner group and flatten |
| 1621 | _delOn(vc.root().getOperand(2).getOperand(0)); |
| 1622 | |
| 1623 | expect(vc.toQuery()).toEqual( |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 1624 | 'pubDate in 2014-12-05 | foo = "bar" | title = "Hello World!" | yeah = "juhu"' |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1625 | ); |
| 1626 | expect(vc.root().ldType()).toEqual('docGroup'); |
| 1627 | expect(vc.root().operation()).toEqual('or'); |
| 1628 | |
| 1629 | // Operands and operators |
| 1630 | expect(vc.element().firstChild.children.length).toEqual(5); |
Akron | 0b489ad | 2018-02-02 16:49:32 +0100 | [diff] [blame] | 1631 | expect(vc.element().firstChild.lastChild.getAttribute('class')).toEqual('operators button-group'); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1632 | }); |
| 1633 | }); |
| 1634 | |
| 1635 | describe('KorAP._add (event)', function () { |
| 1636 | var complexVCFactory = buildFactory(vcClass,{ |
| 1637 | "@type": 'koral:docGroup', |
| 1638 | 'operation' : 'operation:and', |
| 1639 | 'operands' : [ |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 1640 | { |
| 1641 | "@type": 'koral:doc', |
| 1642 | "key": 'pubDate', |
| 1643 | "match": 'match:eq', |
| 1644 | "value": '2014-12-05', |
| 1645 | "type": 'type:date' |
| 1646 | }, |
| 1647 | { |
| 1648 | "@type" : 'koral:docGroup', |
| 1649 | 'operation' : 'operation:or', |
| 1650 | 'operands' : [ |
| 1651 | { |
| 1652 | '@type' : 'koral:doc', |
| 1653 | 'key' : 'title', |
| 1654 | 'value' : 'Hello World!' |
| 1655 | }, |
| 1656 | { |
| 1657 | '@type' : 'koral:doc', |
| 1658 | 'key' : 'foo', |
| 1659 | 'value' : 'bar' |
| 1660 | } |
| 1661 | ] |
| 1662 | } |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1663 | ] |
| 1664 | }); |
| 1665 | |
| 1666 | it('should add new unspecified doc with "and"', function () { |
Nils Diewald | 6283d69 | 2015-04-23 20:32:53 +0000 | [diff] [blame] | 1667 | var vc = vcClass.create().fromJson( |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 1668 | { |
| 1669 | "@type": 'koral:docGroup', |
| 1670 | 'operation' : 'operation:and', |
| 1671 | 'operands' : [ |
| 1672 | { |
| 1673 | "@type": 'koral:doc', |
| 1674 | "key": 'pubDate', |
| 1675 | "match": 'match:eq', |
| 1676 | "value": '2014-12-05', |
| 1677 | "type": 'type:date' |
| 1678 | }, |
| 1679 | { |
| 1680 | "@type" : 'koral:doc', |
| 1681 | 'key' : 'foo', |
| 1682 | 'value' : 'bar' |
| 1683 | } |
| 1684 | ] |
| 1685 | } |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1686 | ); |
| 1687 | |
| 1688 | expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar"'); |
| 1689 | |
| 1690 | var fc = vc.element().firstChild; |
| 1691 | expect(fc.getAttribute('data-operation')).toEqual('and'); |
| 1692 | expect(fc.children.length).toEqual(3); |
Akron | 0b489ad | 2018-02-02 16:49:32 +0100 | [diff] [blame] | 1693 | expect(fc.lastChild.getAttribute('class')).toEqual('operators button-group'); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1694 | expect(fc.children[0].getAttribute('class')).toEqual('doc'); |
| 1695 | expect(fc.children[1].getAttribute('class')).toEqual('doc'); |
| 1696 | |
| 1697 | // add with 'and' in the middle |
| 1698 | _andOn(vc.root().getOperand(0)); |
| 1699 | expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar"'); |
| 1700 | |
| 1701 | fc = vc.element().firstChild; |
| 1702 | expect(fc.getAttribute('data-operation')).toEqual('and'); |
| 1703 | expect(fc.children.length).toEqual(4); |
Akron | 0b489ad | 2018-02-02 16:49:32 +0100 | [diff] [blame] | 1704 | expect(fc.lastChild.getAttribute('class')).toEqual('operators button-group'); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1705 | |
| 1706 | expect(fc.children[0].getAttribute('class')).toEqual('doc'); |
| 1707 | expect(fc.children[1].getAttribute('class')).toEqual('doc unspecified'); |
| 1708 | expect(fc.children[2].getAttribute('class')).toEqual('doc'); |
| 1709 | }); |
| 1710 | |
| 1711 | it('should add new unspecified doc with "or"', function () { |
Nils Diewald | 6283d69 | 2015-04-23 20:32:53 +0000 | [diff] [blame] | 1712 | var vc = vcClass.create().fromJson( |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 1713 | { |
| 1714 | "@type": 'koral:docGroup', |
| 1715 | 'operation' : 'operation:and', |
| 1716 | 'operands' : [ |
| 1717 | { |
| 1718 | "@type": 'koral:doc', |
| 1719 | "key": 'pubDate', |
| 1720 | "match": 'match:eq', |
| 1721 | "value": '2014-12-05', |
| 1722 | "type": 'type:date' |
| 1723 | }, |
| 1724 | { |
| 1725 | "@type" : 'koral:doc', |
| 1726 | 'key' : 'foo', |
| 1727 | 'value' : 'bar' |
| 1728 | } |
| 1729 | ] |
| 1730 | } |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1731 | ); |
| 1732 | |
| 1733 | expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar"'); |
| 1734 | |
| 1735 | var fc = vc.element().firstChild; |
| 1736 | expect(fc.children.length).toEqual(3); |
Akron | 0b489ad | 2018-02-02 16:49:32 +0100 | [diff] [blame] | 1737 | expect(fc.lastChild.getAttribute('class')).toEqual('operators button-group'); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1738 | expect(fc.children[0].getAttribute('class')).toEqual('doc'); |
| 1739 | expect(fc.children[1].getAttribute('class')).toEqual('doc'); |
| 1740 | |
| 1741 | // add with 'or' in the middle |
| 1742 | _orOn(vc.root().getOperand(0)); |
| 1743 | expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar"'); |
| 1744 | fc = vc.element().firstChild; |
| 1745 | |
| 1746 | expect(fc.getAttribute('data-operation')).toEqual('and'); |
| 1747 | expect(fc.children.length).toEqual(3); |
| 1748 | expect(fc.children[0].getAttribute('class')).toEqual('docGroup'); |
| 1749 | expect(fc.children[0].getAttribute('data-operation')).toEqual('or'); |
| 1750 | expect(fc.children[1].getAttribute('class')).toEqual('doc'); |
Akron | 0b489ad | 2018-02-02 16:49:32 +0100 | [diff] [blame] | 1751 | expect(fc.children[2].getAttribute('class')).toEqual('operators button-group'); |
| 1752 | expect(fc.lastChild.getAttribute('class')).toEqual('operators button-group'); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1753 | |
| 1754 | fc = vc.element().firstChild.firstChild; |
| 1755 | expect(fc.children.length).toEqual(3); |
| 1756 | expect(fc.children[0].getAttribute('class')).toEqual('doc'); |
| 1757 | expect(fc.children[1].getAttribute('class')).toEqual('doc unspecified'); |
Akron | 0b489ad | 2018-02-02 16:49:32 +0100 | [diff] [blame] | 1758 | expect(fc.children[2].getAttribute('class')).toEqual('operators button-group'); |
| 1759 | expect(fc.lastChild.getAttribute('class')).toEqual('operators button-group'); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1760 | }); |
| 1761 | |
| 1762 | it('should add new unspecified doc with "and" before group', function () { |
| 1763 | var vc = demoFactory.create(); |
| 1764 | |
| 1765 | // Wrap with direct element access |
| 1766 | expect(vc.toQuery()).toEqual( |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 1767 | '(Titel = "Baum" & ' + |
| 1768 | 'Veröffentlichungsort = "hihi" & ' + |
| 1769 | '(Titel = "Baum" | ' + |
| 1770 | 'Veröffentlichungsort = "hihi")) | ' + |
| 1771 | 'Untertitel ~ "huhu"' |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1772 | ); |
| 1773 | |
| 1774 | expect(vc.root().getOperand(0).ldType()).toEqual('docGroup'); |
| 1775 | expect(vc.root().getOperand(0).operation()).toEqual('and'); |
| 1776 | expect(vc.root().getOperand(0).operands().length).toEqual(3); |
| 1777 | |
| 1778 | // Add unspecified on the second doc |
| 1779 | var secDoc = vc.root().getOperand(0).getOperand(1); |
| 1780 | expect(secDoc.value()).toEqual('hihi'); |
| 1781 | |
| 1782 | // Add |
| 1783 | _andOn(secDoc); |
| 1784 | |
| 1785 | var fo = vc.root().getOperand(0); |
| 1786 | |
| 1787 | expect(fo.ldType()).toEqual('docGroup'); |
| 1788 | expect(fo.operation()).toEqual('and'); |
| 1789 | expect(fo.operands().length).toEqual(4); |
| 1790 | |
| 1791 | expect(fo.getOperand(0).ldType()).toEqual('doc'); |
| 1792 | expect(fo.getOperand(1).ldType()).toEqual('doc'); |
| 1793 | expect(fo.getOperand(2).ldType()).toEqual('non'); |
| 1794 | expect(fo.getOperand(3).ldType()).toEqual('docGroup'); |
| 1795 | }); |
| 1796 | |
| 1797 | |
| 1798 | it('should remove a doc with an unspecified doc in a nested group', function () { |
| 1799 | var vc = demoFactory.create(); |
| 1800 | |
| 1801 | // Wrap with direct element access |
| 1802 | expect(vc.toQuery()).toEqual( |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 1803 | '(Titel = "Baum" & Veröffentlichungsort = "hihi" & (Titel = "Baum" | Veröffentlichungsort = "hihi")) | Untertitel ~ "huhu"' |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1804 | ); |
| 1805 | |
| 1806 | var fo = vc.root().getOperand(0).getOperand(0); |
| 1807 | expect(fo.key()).toEqual('Titel'); |
| 1808 | expect(fo.value()).toEqual('Baum'); |
| 1809 | |
| 1810 | // Add unspecified on the root group |
| 1811 | _orOn(fo); |
| 1812 | |
| 1813 | fo = vc.root().getOperand(0).getOperand(0); |
| 1814 | |
| 1815 | expect(fo.operation()).toEqual('or'); |
| 1816 | expect(fo.getOperand(0).ldType()).toEqual('doc'); |
| 1817 | expect(fo.getOperand(1).ldType()).toEqual('non'); |
| 1818 | |
| 1819 | // Delete document |
| 1820 | _delOn(fo.getOperand(0)); |
| 1821 | |
| 1822 | // The operand is now non |
| 1823 | expect(vc.root().getOperand(0).getOperand(0).ldType()).toEqual('non'); |
| 1824 | expect(vc.root().getOperand(0).getOperand(1).ldType()).toEqual('doc'); |
| 1825 | expect(vc.root().getOperand(0).getOperand(2).ldType()).toEqual('docGroup'); |
| 1826 | }); |
| 1827 | |
| 1828 | |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 1829 | 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] | 1830 | var vc = demoFactory.create(); |
| 1831 | |
| 1832 | // Wrap with direct element access |
| 1833 | expect(vc.toQuery()).toEqual( |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 1834 | '(Titel = "Baum" & ' + |
| 1835 | 'Veröffentlichungsort = "hihi" & ' + |
| 1836 | '(Titel = "Baum" ' + |
| 1837 | '| Veröffentlichungsort = "hihi")) | ' + |
| 1838 | 'Untertitel ~ "huhu"' |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1839 | ); |
| 1840 | |
| 1841 | var fo = vc.root().getOperand(0).getOperand(0); |
| 1842 | expect(fo.key()).toEqual('Titel'); |
| 1843 | expect(fo.value()).toEqual('Baum'); |
| 1844 | |
| 1845 | // Add unspecified on the root group |
| 1846 | _orOn(fo); |
| 1847 | |
| 1848 | fo = vc.root().getOperand(0).getOperand(0); |
| 1849 | |
| 1850 | expect(fo.operation()).toEqual('or'); |
| 1851 | expect(fo.getOperand(0).ldType()).toEqual('doc'); |
| 1852 | expect(fo.getOperand(1).ldType()).toEqual('non'); |
| 1853 | |
| 1854 | // Delete unspecified doc |
| 1855 | _delOn(fo.getOperand(1)); |
| 1856 | |
| 1857 | // The operand is now non |
| 1858 | fo = vc.root().getOperand(0); |
| 1859 | expect(fo.getOperand(0).ldType()).toEqual('doc'); |
| 1860 | expect(fo.getOperand(0).key()).toEqual('Titel'); |
| 1861 | expect(fo.getOperand(0).value()).toEqual('Baum'); |
| 1862 | expect(fo.getOperand(1).ldType()).toEqual('doc'); |
| 1863 | expect(fo.getOperand(2).ldType()).toEqual('docGroup'); |
| 1864 | }); |
| 1865 | |
| 1866 | |
| 1867 | it('should add on parent group (case "and")', function () { |
| 1868 | var vc = complexVCFactory.create(); |
| 1869 | |
| 1870 | // Wrap with direct element access |
| 1871 | expect(vc.toQuery()).toEqual( |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 1872 | 'pubDate in 2014-12-05 & (title = "Hello World!" | foo = "bar")' |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1873 | ); |
| 1874 | |
| 1875 | expect(vc.root().operands().length).toEqual(2); |
| 1876 | |
| 1877 | // Add unspecified on the root group |
| 1878 | _andOn(vc.root().getOperand(1)); |
| 1879 | expect(vc.toQuery()).toEqual( |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 1880 | 'pubDate in 2014-12-05 & (title = "Hello World!" | foo = "bar")' |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1881 | ); |
| 1882 | |
| 1883 | expect(vc.root().ldType()).toEqual('docGroup'); |
| 1884 | expect(vc.root().operands().length).toEqual(3); |
| 1885 | expect(vc.root().getOperand(0).ldType()).toEqual('doc'); |
| 1886 | expect(vc.root().getOperand(1).ldType()).toEqual('docGroup'); |
| 1887 | expect(vc.root().getOperand(1).operation()).toEqual('or'); |
| 1888 | expect(vc.root().getOperand(2).ldType()).toEqual('non'); |
| 1889 | |
| 1890 | // Add another unspecified on the root group |
| 1891 | _andOn(vc.root().getOperand(1)); |
| 1892 | |
| 1893 | expect(vc.root().operands().length).toEqual(4); |
| 1894 | expect(vc.root().getOperand(0).ldType()).toEqual('doc'); |
| 1895 | expect(vc.root().getOperand(1).ldType()).toEqual('docGroup'); |
| 1896 | expect(vc.root().getOperand(2).ldType()).toEqual('non'); |
| 1897 | expect(vc.root().getOperand(3).ldType()).toEqual('non'); |
| 1898 | |
| 1899 | // Add another unspecified after the first doc |
| 1900 | _andOn(vc.root().getOperand(0)); |
| 1901 | |
| 1902 | expect(vc.root().operands().length).toEqual(5); |
| 1903 | expect(vc.root().getOperand(0).ldType()).toEqual('doc'); |
| 1904 | expect(vc.root().getOperand(1).ldType()).toEqual('non'); |
| 1905 | expect(vc.root().getOperand(2).ldType()).toEqual('docGroup'); |
| 1906 | expect(vc.root().getOperand(3).ldType()).toEqual('non'); |
| 1907 | expect(vc.root().getOperand(4).ldType()).toEqual('non'); |
| 1908 | }); |
| 1909 | |
| 1910 | it('should wrap on root', function () { |
Nils Diewald | 6283d69 | 2015-04-23 20:32:53 +0000 | [diff] [blame] | 1911 | var vc = vcClass.create().fromJson( |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 1912 | { |
| 1913 | "@type": 'koral:docGroup', |
| 1914 | 'operation' : 'operation:and', |
| 1915 | 'operands' : [ |
| 1916 | { |
| 1917 | "@type": 'koral:doc', |
| 1918 | "key": 'pubDate', |
| 1919 | "match": 'match:eq', |
| 1920 | "value": '2014-12-05', |
| 1921 | "type": 'type:date' |
| 1922 | }, |
| 1923 | { |
| 1924 | "@type" : 'koral:doc', |
| 1925 | 'key' : 'foo', |
| 1926 | 'value' : 'bar' |
| 1927 | } |
| 1928 | ] |
| 1929 | } |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1930 | ); |
| 1931 | |
| 1932 | // Wrap on root |
| 1933 | expect(vc.toQuery()).toEqual('pubDate in 2014-12-05 & foo = "bar"'); |
| 1934 | expect(vc.root().ldType()).toEqual('docGroup'); |
| 1935 | expect(vc.root().operation()).toEqual('and'); |
| 1936 | _orOn(vc.root()); |
| 1937 | expect(vc.root().ldType()).toEqual('docGroup'); |
| 1938 | expect(vc.root().operation()).toEqual('or'); |
| 1939 | |
| 1940 | expect(vc.root().getOperand(0).ldType()).toEqual('docGroup'); |
| 1941 | expect(vc.root().getOperand(0).operation()).toEqual('and'); |
| 1942 | }); |
| 1943 | |
| 1944 | it('should add on root (case "and")', function () { |
Nils Diewald | 6283d69 | 2015-04-23 20:32:53 +0000 | [diff] [blame] | 1945 | var vc = vcClass.create().fromJson( |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 1946 | { |
| 1947 | "@type": 'koral:doc', |
| 1948 | "key": 'pubDate', |
| 1949 | "match": 'match:eq', |
| 1950 | "value": '2014-12-05', |
| 1951 | "type": 'type:date' |
| 1952 | } |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1953 | ); |
| 1954 | |
| 1955 | expect(vc.toQuery()).toEqual('pubDate in 2014-12-05'); |
| 1956 | expect(vc.root().ldType()).toEqual('doc'); |
| 1957 | expect(vc.root().key()).toEqual('pubDate'); |
| 1958 | expect(vc.root().value()).toEqual('2014-12-05'); |
| 1959 | |
| 1960 | // Wrap on root |
| 1961 | _andOn(vc.root()); |
| 1962 | expect(vc.root().ldType()).toEqual('docGroup'); |
| 1963 | expect(vc.root().operation()).toEqual('and'); |
| 1964 | }); |
| 1965 | |
| 1966 | it('should add on root (case "or")', function () { |
Nils Diewald | 6283d69 | 2015-04-23 20:32:53 +0000 | [diff] [blame] | 1967 | var vc = vcClass.create().fromJson( |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 1968 | { |
| 1969 | "@type": 'koral:doc', |
| 1970 | "key": 'pubDate', |
| 1971 | "match": 'match:eq', |
| 1972 | "value": '2014-12-05', |
| 1973 | "type": 'type:date' |
| 1974 | } |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1975 | ); |
| 1976 | |
| 1977 | expect(vc.toQuery()).toEqual('pubDate in 2014-12-05'); |
| 1978 | expect(vc.root().key()).toEqual('pubDate'); |
| 1979 | expect(vc.root().value()).toEqual('2014-12-05'); |
| 1980 | |
| 1981 | // Wrap on root |
| 1982 | _orOn(vc.root()); |
| 1983 | expect(vc.root().ldType()).toEqual('docGroup'); |
| 1984 | expect(vc.root().operation()).toEqual('or'); |
| 1985 | }); |
| 1986 | |
| 1987 | it('should support multiple sub groups per group', function () { |
Nils Diewald | 6283d69 | 2015-04-23 20:32:53 +0000 | [diff] [blame] | 1988 | var vc = vcClass.create().fromJson( |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 1989 | { |
| 1990 | "@type": 'koral:docGroup', |
| 1991 | 'operation' : 'operation:or', |
| 1992 | 'operands' : [ |
| 1993 | { |
| 1994 | "@type": 'koral:docGroup', |
| 1995 | 'operation' : 'operation:and', |
| 1996 | 'operands' : [ |
| 1997 | { |
| 1998 | "@type": 'koral:doc', |
| 1999 | "key": 'title', |
| 2000 | "value": 't1', |
| 2001 | }, |
| 2002 | { |
| 2003 | "@type" : 'koral:doc', |
| 2004 | 'key' : 'title', |
| 2005 | 'value' : 't2' |
| 2006 | } |
| 2007 | ] |
| 2008 | }, |
| 2009 | { |
| 2010 | "@type": 'koral:docGroup', |
| 2011 | 'operation' : 'operation:and', |
| 2012 | 'operands' : [ |
| 2013 | { |
| 2014 | "@type": 'koral:doc', |
| 2015 | "key": 'title', |
| 2016 | "value": 't3', |
| 2017 | }, |
| 2018 | { |
| 2019 | "@type" : 'koral:doc', |
| 2020 | 'key' : 'title', |
| 2021 | 'value' : 't4' |
| 2022 | } |
| 2023 | ] |
| 2024 | } |
| 2025 | ] |
| 2026 | } |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 2027 | ); |
| 2028 | expect(vc.toQuery()).toEqual( |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 2029 | '(title = "t1" & title = "t2") | ' + |
| 2030 | '(title = "t3" & title = "t4")' |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 2031 | ); |
| 2032 | expect(vc.root().operation()).toEqual('or'); |
| 2033 | expect(vc.root().getOperand(0).toQuery()).toEqual('title = "t1" & title = "t2"'); |
| 2034 | expect(vc.root().getOperand(1).toQuery()).toEqual('title = "t3" & title = "t4"'); |
| 2035 | |
| 2036 | _andOn(vc.root()); |
| 2037 | |
| 2038 | expect(vc.root().operation()).toEqual('and'); |
| 2039 | expect(vc.root().getOperand(0).ldType()).toEqual('docGroup'); |
| 2040 | expect(vc.root().getOperand(1).ldType()).toEqual('non'); |
| 2041 | }); |
| 2042 | }); |
| 2043 | |
Akron | 5c829e9 | 2017-05-12 18:10:00 +0200 | [diff] [blame] | 2044 | // Check class method |
| 2045 | describe('KorAP.VC.checkRewrite', function () { |
| 2046 | |
| 2047 | it('should check for simple rewrites', function () { |
| 2048 | expect(vcClass.checkRewrite( |
| 2049 | { |
| 2050 | "@type" : "koral:doc", |
| 2051 | "rewrites" : [{ |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 2052 | "@type" : "koral:rewrite", |
| 2053 | "operation" : "operation:modification", |
| 2054 | "src" : "querySerializer", |
| 2055 | "scope" : "tree" |
Akron | 5c829e9 | 2017-05-12 18:10:00 +0200 | [diff] [blame] | 2056 | }] |
| 2057 | } |
| 2058 | )).toBeTruthy(); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 2059 | |
Akron | 5c829e9 | 2017-05-12 18:10:00 +0200 | [diff] [blame] | 2060 | var nested = { |
| 2061 | "@type" : "koral:docGroup", |
| 2062 | "operands" : [ |
| 2063 | { |
| 2064 | "@type" : "koral:doc" |
| 2065 | }, |
| 2066 | { |
| 2067 | "@type" : "koral:docGroup", |
| 2068 | "operands" : [ |
| 2069 | { |
| 2070 | "@type": "koral:doc" |
| 2071 | }, |
| 2072 | { |
| 2073 | "@type": "koral:doc" |
| 2074 | } |
| 2075 | ] |
| 2076 | } |
| 2077 | ] |
| 2078 | }; |
| 2079 | |
| 2080 | expect(vcClass.checkRewrite(nested)).toBe(false); |
| 2081 | |
| 2082 | nested["operands"][1]["operands"][1]["rewrites"] = [{ |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 2083 | "@type" : "koral:rewrite", |
| 2084 | "operation" : "operation:modification", |
| 2085 | "src" : "querySerializer", |
| 2086 | "scope" : "tree" |
Akron | 5c829e9 | 2017-05-12 18:10:00 +0200 | [diff] [blame] | 2087 | }]; |
| 2088 | |
| 2089 | expect(vcClass.checkRewrite(nested)).toBeTruthy(); |
| 2090 | }); |
| 2091 | }); |
Nils Diewald | 6283d69 | 2015-04-23 20:32:53 +0000 | [diff] [blame] | 2092 | |
| 2093 | describe('KorAP.Rewrite', function () { |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 2094 | it('should be initializable', function () { |
| 2095 | var rewrite = rewriteClass.create({ |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 2096 | "@type" : "koral:rewrite", |
| 2097 | "operation" : "operation:modification", |
| 2098 | "src" : "querySerializer", |
| 2099 | "scope" : "tree" |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 2100 | }); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 2101 | expect(rewrite.toString()).toEqual('Modification of "tree" by "querySerializer"'); |
| 2102 | }); |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 2103 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 2104 | it('should be deserialized by docs', function () { |
| 2105 | var doc = docClass.create( |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 2106 | undefined, |
| 2107 | { |
| 2108 | "@type":"koral:doc", |
| 2109 | "key":"Titel", |
| 2110 | "value":"Baum", |
| 2111 | "match":"match:eq" |
| 2112 | }); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 2113 | |
| 2114 | expect(doc.element().classList.contains('doc')).toBeTruthy(); |
| 2115 | expect(doc.element().classList.contains('rewritten')).toBe(false); |
| 2116 | |
| 2117 | doc = docClass.create( |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 2118 | undefined, |
| 2119 | { |
| 2120 | "@type":"koral:doc", |
| 2121 | "key":"Titel", |
| 2122 | "value":"Baum", |
| 2123 | "match":"match:eq", |
| 2124 | "rewrites" : [ |
| 2125 | { |
| 2126 | "@type" : "koral:rewrite", |
| 2127 | "operation" : "operation:modification", |
| 2128 | "src" : "querySerializer", |
| 2129 | "scope" : "tree" |
| 2130 | } |
| 2131 | ] |
| 2132 | }); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 2133 | |
| 2134 | expect(doc.element().classList.contains('doc')).toBeTruthy(); |
| 2135 | expect(doc.element().classList.contains('rewritten')).toBeTruthy(); |
| 2136 | }); |
Nils Diewald | 6283d69 | 2015-04-23 20:32:53 +0000 | [diff] [blame] | 2137 | |
Akron | 76c3dd6 | 2018-05-29 20:58:27 +0200 | [diff] [blame] | 2138 | it('should be described in a title attribute', function () { |
| 2139 | |
| 2140 | doc = docClass.create( |
| 2141 | undefined, |
| 2142 | { |
| 2143 | "@type":"koral:doc", |
| 2144 | "key":"Titel", |
| 2145 | "value":"Baum", |
| 2146 | "match":"match:eq", |
| 2147 | "rewrites" : [ |
| 2148 | { |
| 2149 | "@type" : "koral:rewrite", |
| 2150 | "operation" : "operation:modification", |
| 2151 | "src" : "querySerializer", |
| 2152 | "scope" : "tree" |
| 2153 | }, |
| 2154 | { |
| 2155 | "@type" : "koral:rewrite", |
| 2156 | "operation" : "operation:injection", |
| 2157 | "src" : "me" |
| 2158 | } |
| 2159 | ] |
| 2160 | }); |
| 2161 | |
| 2162 | expect(doc.element().classList.contains('doc')).toBeTruthy(); |
| 2163 | expect(doc.element().classList.contains('rewritten')).toBeTruthy(); |
| 2164 | expect(doc.element().lastChild.getAttribute("title")).toEqual("querySerializer: tree (modification)\nme (injection)"); |
| 2165 | }); |
| 2166 | |
| 2167 | |
Nils Diewald | 6283d69 | 2015-04-23 20:32:53 +0000 | [diff] [blame] | 2168 | xit('should be deserialized by docGroups', function () { |
| 2169 | var docGroup = docGroupClass.create( |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 2170 | undefined, |
| 2171 | { |
| 2172 | "@type" : "koral:docGroup", |
| 2173 | "operation" : "operation:or", |
| 2174 | "operands" : [ |
| 2175 | { |
| 2176 | "@type" : "doc", |
| 2177 | "key" : "pubDate", |
| 2178 | "type" : "type:date", |
| 2179 | "value" : "2014-12-05" |
| 2180 | }, |
| 2181 | { |
| 2182 | "@type" : "doc", |
| 2183 | "key" : "pubDate", |
| 2184 | "type" : "type:date", |
| 2185 | "value" : "2014-12-06" |
| 2186 | } |
| 2187 | ], |
| 2188 | "rewrites" : [ |
| 2189 | { |
| 2190 | "@type" : "koral:rewrite", |
| 2191 | "operation" : "operation:modification", |
| 2192 | "src" : "querySerializer", |
| 2193 | "scope" : "tree" |
| 2194 | } |
| 2195 | ] |
| 2196 | } |
Nils Diewald | 6283d69 | 2015-04-23 20:32:53 +0000 | [diff] [blame] | 2197 | ); |
| 2198 | |
| 2199 | expect(doc.element().classList.contains('docgroup')).toBeTruthy(); |
| 2200 | expect(doc.element().classList.contains('rewritten')).toBe(false); |
| 2201 | }); |
Nils Diewald | 86dad5b | 2015-01-28 15:09:07 +0000 | [diff] [blame] | 2202 | }); |
Nils Diewald | f0c4f11 | 2015-05-05 12:56:59 +0000 | [diff] [blame] | 2203 | |
| 2204 | describe('KorAP.stringValue', function () { |
| 2205 | it('should be initializable', function () { |
| 2206 | var sv = stringValClass.create(); |
| 2207 | expect(sv.regex()).toBe(false); |
| 2208 | expect(sv.value()).toBe(''); |
Nils Diewald | c4c4b83 | 2015-05-05 16:00:08 +0000 | [diff] [blame] | 2209 | |
| 2210 | sv = stringValClass.create('Baum'); |
| 2211 | expect(sv.regex()).toBe(false); |
| 2212 | expect(sv.value()).toBe('Baum'); |
| 2213 | |
| 2214 | sv = stringValClass.create('Baum', false); |
| 2215 | expect(sv.regex()).toBe(false); |
| 2216 | expect(sv.value()).toBe('Baum'); |
| 2217 | |
| 2218 | sv = stringValClass.create('Baum', true); |
| 2219 | expect(sv.regex()).toBe(true); |
| 2220 | expect(sv.value()).toBe('Baum'); |
| 2221 | }); |
| 2222 | |
| 2223 | it('should be modifiable', function () { |
| 2224 | var sv = stringValClass.create(); |
| 2225 | expect(sv.regex()).toBe(false); |
| 2226 | expect(sv.value()).toBe(''); |
| 2227 | |
| 2228 | expect(sv.value('Baum')).toBe('Baum'); |
| 2229 | expect(sv.value()).toBe('Baum'); |
| 2230 | |
| 2231 | expect(sv.regex(true)).toBe(true); |
| 2232 | expect(sv.regex()).toBe(true); |
| 2233 | }); |
| 2234 | |
| 2235 | it('should have a toggleble regex value', function () { |
| 2236 | var sv = stringValClass.create(); |
Nils Diewald | 7991a3f | 2015-05-19 14:12:37 +0000 | [diff] [blame] | 2237 | |
| 2238 | expect(sv.element().firstChild.value).toBe(''); |
| 2239 | sv.element().firstChild.value = 'der' |
| 2240 | expect(sv.element().firstChild.value).toBe('der'); |
| 2241 | |
Nils Diewald | c4c4b83 | 2015-05-05 16:00:08 +0000 | [diff] [blame] | 2242 | expect(sv.regex()).toBe(false); |
| 2243 | |
| 2244 | sv.toggleRegex(); |
Nils Diewald | 7991a3f | 2015-05-19 14:12:37 +0000 | [diff] [blame] | 2245 | expect(sv.element().firstChild.value).toBe('der'); |
Nils Diewald | c4c4b83 | 2015-05-05 16:00:08 +0000 | [diff] [blame] | 2246 | expect(sv.regex()).toBe(true); |
Nils Diewald | 7991a3f | 2015-05-19 14:12:37 +0000 | [diff] [blame] | 2247 | sv.element().firstChild.value = 'derbe' |
Nils Diewald | c4c4b83 | 2015-05-05 16:00:08 +0000 | [diff] [blame] | 2248 | |
| 2249 | sv.toggleRegex(); |
| 2250 | expect(sv.regex()).toBe(false); |
Nils Diewald | 7991a3f | 2015-05-19 14:12:37 +0000 | [diff] [blame] | 2251 | expect(sv.element().firstChild.value).toBe('derbe'); |
Nils Diewald | c4c4b83 | 2015-05-05 16:00:08 +0000 | [diff] [blame] | 2252 | }); |
| 2253 | |
| 2254 | it('should have an element', function () { |
| 2255 | var sv = stringValClass.create('der'); |
| 2256 | expect(sv.element().nodeName).toBe('DIV'); |
| 2257 | expect(sv.element().firstChild.nodeName).toBe('INPUT'); |
| 2258 | expect(sv.element().firstChild.value).toBe('der'); |
| 2259 | }); |
| 2260 | |
| 2261 | it('should have a classed element', function () { |
| 2262 | var sv = stringValClass.create(); |
Nils Diewald | c4c4b83 | 2015-05-05 16:00:08 +0000 | [diff] [blame] | 2263 | expect(sv.element().classList.contains('regex')).toBe(false); |
| 2264 | expect(sv.regex()).toBe(false); |
| 2265 | sv.toggleRegex(); |
| 2266 | expect(sv.element().classList.contains('regex')).toBe(true); |
| 2267 | }); |
| 2268 | |
| 2269 | it('should be storable', function () { |
| 2270 | var sv = stringValClass.create(); |
| 2271 | var count = 1; |
| 2272 | sv.store = function (value, regex) { |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 2273 | expect(regex).toBe(true); |
| 2274 | expect(value).toBe('tree'); |
Nils Diewald | c4c4b83 | 2015-05-05 16:00:08 +0000 | [diff] [blame] | 2275 | }; |
| 2276 | sv.regex(true); |
| 2277 | sv.value('tree'); |
| 2278 | sv.element().lastChild.click(); |
Nils Diewald | f0c4f11 | 2015-05-05 12:56:59 +0000 | [diff] [blame] | 2279 | }); |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 2280 | |
Nils Diewald | f0c4f11 | 2015-05-05 12:56:59 +0000 | [diff] [blame] | 2281 | }); |
Akron | e4961b1 | 2017-05-10 21:04:46 +0200 | [diff] [blame] | 2282 | |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 2283 | describe('KorAP.VC.Menu', function () { |
Akron | e65a88a | 2018-04-05 19:14:20 +0200 | [diff] [blame] | 2284 | |
| 2285 | var vc; |
| 2286 | |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 2287 | it('should be initializable', function () { |
| 2288 | |
Akron | e65a88a | 2018-04-05 19:14:20 +0200 | [diff] [blame] | 2289 | vc = vcClass.create([ |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 2290 | ['a', 'text'], |
| 2291 | ['b', 'string'], |
| 2292 | ['c', 'date'] |
| 2293 | ]).fromJson(); |
| 2294 | expect(vc.element().firstChild.classList.contains('unspecified')).toBeTruthy(); |
| 2295 | expect(vc.element().firstChild.firstChild.tagName).toEqual('SPAN'); |
| 2296 | |
| 2297 | // Click on unspecified |
| 2298 | vc.element().firstChild.firstChild.click(); |
| 2299 | expect(vc.element().firstChild.firstChild.tagName).toEqual('UL'); |
| 2300 | |
| 2301 | var list = vc.element().firstChild.firstChild; |
| 2302 | expect(list.getElementsByTagName("LI")[0].innerText).toEqual('a'); |
| 2303 | expect(list.getElementsByTagName("LI")[1].innerText).toEqual('b'); |
| 2304 | expect(list.getElementsByTagName("LI")[2].innerText).toEqual('c'); |
| 2305 | |
| 2306 | vc = vcClass.create([ |
| 2307 | ['d', 'text'], |
| 2308 | ['e', 'string'], |
| 2309 | ['f', 'date'] |
| 2310 | ]).fromJson(); |
| 2311 | expect(vc.element().firstChild.classList.contains('unspecified')).toBeTruthy(); |
| 2312 | expect(vc.element().firstChild.firstChild.tagName).toEqual('SPAN'); |
| 2313 | |
| 2314 | // Click on unspecified |
| 2315 | vc.element().firstChild.firstChild.click(); |
| 2316 | expect(vc.element().firstChild.firstChild.tagName).toEqual('UL'); |
| 2317 | |
| 2318 | list = vc.element().firstChild.firstChild; |
| 2319 | expect(list.getElementsByTagName("LI")[0].innerText).toEqual('d'); |
| 2320 | expect(list.getElementsByTagName("LI")[1].innerText).toEqual('e'); |
| 2321 | expect(list.getElementsByTagName("LI")[2].innerText).toEqual('f'); |
Akron | 31d8994 | 2018-04-06 16:44:51 +0200 | [diff] [blame] | 2322 | // blur |
| 2323 | document.body.click(); |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 2324 | }); |
Akron | e65a88a | 2018-04-05 19:14:20 +0200 | [diff] [blame] | 2325 | |
| 2326 | // Reinitialize to make tests stable |
| 2327 | vc = vcClass.create([ |
| 2328 | ['d', 'text'], |
| 2329 | ['e', 'string'], |
| 2330 | ['f', 'date'] |
| 2331 | ]).fromJson(); |
| 2332 | |
| 2333 | it('should be clickable on key', function () { |
Akron | 31d8994 | 2018-04-06 16:44:51 +0200 | [diff] [blame] | 2334 | // Click on unspecified |
| 2335 | vc.element().firstChild.firstChild.click(); |
Akron | e65a88a | 2018-04-05 19:14:20 +0200 | [diff] [blame] | 2336 | // Click on "d" |
| 2337 | vc.element().firstChild.firstChild.getElementsByTagName("LI")[0].click(); |
| 2338 | expect(vc.element().firstChild.firstChild.tagName).toEqual('SPAN'); |
| 2339 | expect(vc.element().firstChild.firstChild.innerText).toEqual('d'); |
| 2340 | expect(vc.element().firstChild.children[1].innerText).toEqual('eq'); |
| 2341 | expect(vc.element().firstChild.children[1].getAttribute('data-type')).toEqual('text'); |
Akron | 31d8994 | 2018-04-06 16:44:51 +0200 | [diff] [blame] | 2342 | // blur |
| 2343 | document.body.click(); |
Akron | e65a88a | 2018-04-05 19:14:20 +0200 | [diff] [blame] | 2344 | }); |
| 2345 | |
Akron | 31d8994 | 2018-04-06 16:44:51 +0200 | [diff] [blame] | 2346 | it('should be clickable on operation for text', function () { |
| 2347 | // Click on "d" (or unspecified) |
| 2348 | vc.element().firstChild.firstChild.click(); |
| 2349 | |
| 2350 | // Choose "d" |
| 2351 | vc.element().firstChild.firstChild.getElementsByTagName("LI")[0].click(); |
| 2352 | |
| 2353 | // Click on matchop |
Akron | e65a88a | 2018-04-05 19:14:20 +0200 | [diff] [blame] | 2354 | vc.element().firstChild.children[1].click(); |
Akron | 31d8994 | 2018-04-06 16:44:51 +0200 | [diff] [blame] | 2355 | |
Akron | e65a88a | 2018-04-05 19:14:20 +0200 | [diff] [blame] | 2356 | expect(vc.element().firstChild.children[1].tagName).toEqual('UL'); |
Akron | 31d8994 | 2018-04-06 16:44:51 +0200 | [diff] [blame] | 2357 | |
Akron | e65a88a | 2018-04-05 19:14:20 +0200 | [diff] [blame] | 2358 | var ul = vc.element().firstChild.children[1]; |
| 2359 | expect(ul.getElementsByTagName('li')[0].innerText).toEqual("eq"); |
| 2360 | expect(ul.getElementsByTagName('li')[1].innerText).toEqual("ne"); |
| 2361 | expect(ul.getElementsByTagName('li')[2].innerText).toEqual("contains"); |
| 2362 | expect(ul.getElementsByTagName('li')[3].innerText).toEqual("containsnot"); |
| 2363 | expect(ul.getElementsByTagName('li')[4]).toBeUndefined(); |
Akron | 31d8994 | 2018-04-06 16:44:51 +0200 | [diff] [blame] | 2364 | |
| 2365 | // Choose "contains" |
| 2366 | ul.getElementsByTagName('li')[2].click(); |
| 2367 | expect(vc.element().firstChild.children[1].tagName).toEqual("SPAN"); |
| 2368 | expect(vc.element().firstChild.children[1].innerText).toEqual("contains"); |
| 2369 | // blur |
| 2370 | document.body.click(); |
Akron | e65a88a | 2018-04-05 19:14:20 +0200 | [diff] [blame] | 2371 | }) |
Akron | 31d8994 | 2018-04-06 16:44:51 +0200 | [diff] [blame] | 2372 | |
| 2373 | it('should be clickable on operation for string', function () { |
| 2374 | // Click on "d" (or unspecified) |
| 2375 | vc.element().firstChild.firstChild.click(); |
| 2376 | |
| 2377 | // Choose "e" |
| 2378 | vc.element().firstChild.firstChild.getElementsByTagName("LI")[1].click(); |
| 2379 | |
| 2380 | // As a consequence the matchoperator may no longer |
| 2381 | // be valid and needs to be re-evaluated |
| 2382 | var fc = vc.element().firstChild; |
| 2383 | expect(fc.firstChild.tagName).toEqual('SPAN'); |
| 2384 | expect(fc.firstChild.innerText).toEqual('e'); |
| 2385 | expect(fc.children[1].innerText).toEqual('eq'); |
| 2386 | expect(fc.children[1].getAttribute('data-type')).toEqual('string'); |
| 2387 | |
| 2388 | vc.element().firstChild.children[1].click(); |
| 2389 | |
| 2390 | expect(vc.element().firstChild.children[1].tagName).toEqual('UL'); |
| 2391 | |
| 2392 | var ul = vc.element().firstChild.children[1]; |
| 2393 | expect(ul.getElementsByTagName('li')[0].innerText).toEqual("eq"); |
| 2394 | expect(ul.getElementsByTagName('li')[1].innerText).toEqual("ne"); |
| 2395 | expect(ul.getElementsByTagName('li')[2]).toBeUndefined(); |
| 2396 | |
| 2397 | // Choose "ne" |
| 2398 | ul.getElementsByTagName('li')[1].click(); |
| 2399 | expect(vc.element().firstChild.children[1].tagName).toEqual("SPAN"); |
| 2400 | expect(vc.element().firstChild.children[1].innerText).toEqual("ne"); |
Akron | 8db5e3a | 2018-05-28 19:25:26 +0200 | [diff] [blame] | 2401 | |
| 2402 | // Click on text |
| 2403 | expect(vc.element().firstChild.children[2].innerText).toEqual("⋯"); |
| 2404 | vc.element().firstChild.children[2].click(); |
| 2405 | |
| 2406 | // Blur text element |
| 2407 | expect(vc.element().firstChild.children[2].firstChild.value).toEqual(''); |
| 2408 | |
Akron | 31d8994 | 2018-04-06 16:44:51 +0200 | [diff] [blame] | 2409 | // blur |
| 2410 | document.body.click(); |
| 2411 | }); |
| 2412 | |
| 2413 | it('should be clickable on operation for date', function () { |
| 2414 | |
| 2415 | // Replay matchop check - so it's guaranteed that "ne" is chosen |
| 2416 | // Click on "e" (or unspecified) |
| 2417 | vc.element().firstChild.firstChild.click(); |
| 2418 | // Rechoose "e" |
| 2419 | vc.element().firstChild.firstChild.getElementsByTagName("LI")[1].click(); |
| 2420 | // Click on matchop |
| 2421 | vc.element().firstChild.children[1].click(); |
| 2422 | // Choose "ne" |
| 2423 | vc.element().firstChild.children[1].getElementsByTagName('li')[1].click(); |
| 2424 | expect(vc.element().firstChild.children[1].innerText).toEqual("ne"); |
| 2425 | |
| 2426 | // Click on "e" |
| 2427 | vc.element().firstChild.firstChild.click(); |
| 2428 | // Choose "f" |
| 2429 | vc.element().firstChild.firstChild.getElementsByTagName("LI")[2].click(); |
| 2430 | |
| 2431 | // The matchoperator should still be "ne" as this is valid for dates as well (now) |
| 2432 | var fc = vc.element().firstChild; |
| 2433 | expect(fc.firstChild.tagName).toEqual('SPAN'); |
| 2434 | expect(fc.firstChild.innerText).toEqual('f'); |
| 2435 | expect(fc.children[1].innerText).toEqual('ne'); |
| 2436 | // blur |
| 2437 | document.body.click(); |
| 2438 | }); |
Akron | ddc98a7 | 2018-04-06 17:33:52 +0200 | [diff] [blame] | 2439 | |
| 2440 | |
| 2441 | // Check json deserialization |
| 2442 | it('should be initializable', function () { |
| 2443 | vc = vcClass.create([ |
| 2444 | ['a', 'text'], |
| 2445 | ['b', 'string'], |
| 2446 | ['c', 'date'] |
| 2447 | ]).fromJson({ |
| 2448 | "@type" : "koral:doc", |
| 2449 | "key":"a", |
| 2450 | "value":"Baum" |
| 2451 | }); |
| 2452 | |
| 2453 | expect(vc.element().firstChild.children[1].getAttribute('data-type')).toEqual('text'); |
| 2454 | }); |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 2455 | }); |
| 2456 | |
| 2457 | |
Akron | e4961b1 | 2017-05-10 21:04:46 +0200 | [diff] [blame] | 2458 | // Check prefix |
| 2459 | describe('KorAP.VC.Prefix', function () { |
| 2460 | |
| 2461 | it('should be initializable', function () { |
| 2462 | var p = prefixClass.create(); |
| 2463 | expect(p.element().classList.contains('pref')).toBeTruthy(); |
| 2464 | expect(p.isSet()).not.toBeTruthy(); |
| 2465 | }); |
| 2466 | |
| 2467 | |
| 2468 | it('should be clickable', function () { |
| 2469 | var vc = vcClass.create([ |
Akron | 712733a | 2018-04-05 18:17:47 +0200 | [diff] [blame] | 2470 | ['a', null], |
| 2471 | ['b', null], |
| 2472 | ['c', null] |
| 2473 | ]).fromJson(); |
Akron | e4961b1 | 2017-05-10 21:04:46 +0200 | [diff] [blame] | 2474 | expect(vc.element().firstChild.classList.contains('unspecified')).toBeTruthy(); |
| 2475 | |
| 2476 | // This should open up the menu |
| 2477 | vc.element().firstChild.firstChild.click(); |
| 2478 | expect(vc.element().firstChild.firstChild.tagName).toEqual('UL'); |
| 2479 | |
| 2480 | KorAP._vcKeyMenu._prefix.clear(); |
| 2481 | KorAP._vcKeyMenu._prefix.add('x'); |
| 2482 | |
| 2483 | var prefElement = vc.element().querySelector('span.pref'); |
| 2484 | expect(prefElement.innerText).toEqual('x'); |
| 2485 | |
| 2486 | // This should add key 'x' to VC |
| 2487 | prefElement.click(); |
| 2488 | |
| 2489 | expect(vc.element().firstChild.classList.contains('doc')).toBeTruthy(); |
| 2490 | expect(vc.element().firstChild.firstChild.className).toEqual('key'); |
| 2491 | expect(vc.element().firstChild.firstChild.innerText).toEqual('x'); |
| 2492 | }); |
| 2493 | }); |
Nils Diewald | 2fe12e1 | 2015-03-06 16:47:06 +0000 | [diff] [blame] | 2494 | }); |