hebasta | 5e4d754 | 2018-06-19 16:57:36 +0200 | [diff] [blame] | 1 | /** |
| 2 | * Test suite for corpus statistic |
| 3 | * |
| 4 | * @author Helge Stallkamp |
Akron | 18a99c0 | 2018-08-20 12:55:14 +0200 | [diff] [blame] | 5 | * @author Nils Diewald |
hebasta | 5e4d754 | 2018-06-19 16:57:36 +0200 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | |
hebasta | 6c8f09d | 2018-07-24 13:21:36 +0200 | [diff] [blame] | 9 | define(['vc', 'vc/statistic', 'view/corpstatv'], function(vcClass, statClass, corpStatVClass){ |
hebasta | a0282be | 2018-12-05 16:58:00 +0100 | [diff] [blame] | 10 | |
hebasta | 47d03a4 | 2018-06-25 10:31:58 +0200 | [diff] [blame] | 11 | var json = { |
Akron | 18a99c0 | 2018-08-20 12:55:14 +0200 | [diff] [blame] | 12 | "@type":"koral:docGroup", |
| 13 | "operation":"operation:or", |
| 14 | "operands":[ |
| 15 | { |
| 16 | "@type":"koral:docGroup", |
| 17 | "operation":"operation:and", |
| 18 | "operands":[ |
| 19 | { |
| 20 | "@type":"koral:doc", |
| 21 | "key":"title", |
| 22 | "value":"Der Birnbaum", |
| 23 | "match":"match:eq" |
| 24 | }, |
| 25 | { |
| 26 | "@type":"koral:doc", |
| 27 | "key":"pubPlace", |
| 28 | "value":"Mannheim", |
| 29 | "type" : "type:regex", |
| 30 | "match":"match:contains" |
| 31 | }, |
| 32 | { |
| 33 | "@type":"koral:docGroup", |
| 34 | "operation":"operation:or", |
| 35 | "operands":[ |
| 36 | { |
| 37 | "@type":"koral:doc", |
| 38 | "key":"subTitle", |
| 39 | "value":"Aufzucht und Pflege", |
| 40 | "match":"match:eq" |
| 41 | }, |
| 42 | { |
| 43 | "@type":"koral:doc", |
| 44 | "key":"subTitle", |
| 45 | "value":"Gedichte", |
| 46 | "match":"match:eq", |
| 47 | "rewrites" : [ |
| 48 | { |
| 49 | "@type": "koral:rewrite", |
| 50 | "src" : "policy", |
| 51 | "operation" : "operation:injection", |
| 52 | } |
| 53 | ] |
| 54 | } |
| 55 | ] |
| 56 | } |
| 57 | ] |
| 58 | }, |
| 59 | { |
| 60 | "@type":"koral:doc", |
| 61 | "key":"pubDate", |
| 62 | "type":"type:date", |
| 63 | "value":"2015-03-05", |
| 64 | "match":"match:geq" |
| 65 | } |
| 66 | ] |
| 67 | }; |
hebasta | 5e4d754 | 2018-06-19 16:57:36 +0200 | [diff] [blame] | 68 | |
hebasta | 47d03a4 | 2018-06-25 10:31:58 +0200 | [diff] [blame] | 69 | var preDefinedStat={ |
Akron | 18a99c0 | 2018-08-20 12:55:14 +0200 | [diff] [blame] | 70 | "documents":12, |
| 71 | "tokens":2323, |
| 72 | "sentences":343434, |
| 73 | "paragraphs":45454545 |
hebasta | 47d03a4 | 2018-06-25 10:31:58 +0200 | [diff] [blame] | 74 | }; |
| 75 | |
| 76 | KorAP.API.getCorpStat = function(collQu, cb){ |
| 77 | return cb(preDefinedStat); |
Akron | 18a99c0 | 2018-08-20 12:55:14 +0200 | [diff] [blame] | 78 | }; |
| 79 | |
hebasta | a0282be | 2018-12-05 16:58:00 +0100 | [diff] [blame] | 80 | |
| 81 | generateCorpusDocGr = function(){ |
| 82 | let vc = vcClass.create().fromJson({ |
| 83 | "@type" : 'koral:docGroup', |
| 84 | 'operation' : 'operation:or', |
| 85 | 'operands' : [ |
| 86 | { |
| 87 | '@type' : 'koral:doc', |
| 88 | 'key' : 'title', |
| 89 | 'match': 'match:eq', |
| 90 | 'value' : 'Hello World!' |
| 91 | }, |
| 92 | { |
| 93 | '@type' : 'koral:doc', |
| 94 | 'match': 'match:eq', |
| 95 | 'key' : 'foo', |
| 96 | 'value' : 'bar' |
| 97 | } |
| 98 | ] |
| 99 | }); |
| 100 | return vc; |
| 101 | } |
| 102 | |
hebasta | de595b4 | 2019-02-05 13:53:10 +0100 | [diff] [blame] | 103 | /** |
| 104 | * Generate corpus doc group with more entries |
| 105 | */ |
| 106 | generateBCorpusDocGr = function(){ |
| 107 | let vc = vcClass.create().fromJson({ |
| 108 | "@type": "koral:docGroup", |
| 109 | "operation": "operation:or", |
| 110 | "operands": [{ |
| 111 | "@type" : 'koral:docGroup', |
| 112 | 'operation' : 'operation:or', |
| 113 | 'operands' : [ |
| 114 | { |
| 115 | '@type' : 'koral:doc', |
| 116 | 'key' : 'title', |
| 117 | 'match': 'match:eq', |
| 118 | 'value' : 'Hello World!' |
| 119 | }, |
| 120 | { |
| 121 | '@type' : 'koral:doc', |
| 122 | 'match': 'match:eq', |
| 123 | 'key' : 'foo', |
| 124 | 'value' : 'bar' |
| 125 | } |
| 126 | ] |
| 127 | }, |
| 128 | { |
| 129 | '@type' : 'koral:doc', |
| 130 | 'match': 'match:eq', |
| 131 | 'key' : 'author', |
| 132 | 'value' : 'Goethe' |
| 133 | } |
| 134 | ] |
| 135 | }); |
| 136 | |
| 137 | return vc; |
| 138 | } |
| 139 | |
hebasta | a0282be | 2018-12-05 16:58:00 +0100 | [diff] [blame] | 140 | generateCorpusDoc = function(){ |
| 141 | let vc= vcClass.create().fromJson({ |
| 142 | '@type' : 'koral:doc', |
| 143 | 'key' : 'title', |
| 144 | 'match': 'match:eq', |
| 145 | 'value' : 'Hello World!', |
| 146 | 'type' : 'type:string' |
| 147 | }); |
| 148 | return vc; |
| 149 | }; |
| 150 | |
| 151 | |
| 152 | /** |
| 153 | * Generate vc with docgroupref |
| 154 | */ |
| 155 | generateCorpusRef = function(){ |
| 156 | let vc = vcClass.create().fromJson({ |
| 157 | "@type" : "koral:docGroupRef", |
| 158 | "ref" : "@max/myCorpus" |
| 159 | }); |
| 160 | return vc; |
| 161 | }; |
| 162 | |
| 163 | |
| 164 | /** |
| 165 | * Checks is corpus statistic is active |
| 166 | */ |
| 167 | checkStatActive = function(view, div){ |
| 168 | // corpus statistic exists, it is active and reloadStatButton is shown |
| 169 | if ((view.firstChild.classList.contains("stattable") === true) |
hebasta | 48842cf | 2018-12-11 12:57:38 +0100 | [diff] [blame] | 170 | && (view.firstChild.classList.contains("stdisabled") === false) |
hebasta | a0282be | 2018-12-05 16:58:00 +0100 | [diff] [blame] | 171 | && (div.getElementsByClassName("reloadStatB").length == 0) ) { |
| 172 | return true; |
| 173 | } |
| 174 | return false; |
| 175 | }; |
| 176 | |
| 177 | |
| 178 | /** |
| 179 | * Checks if corpus statistic is disabled |
| 180 | */ |
| 181 | checkStatDisabled = function(view, div){ |
| 182 | if ((view.firstChild.classList.contains("stattable") === true) |
hebasta | 48842cf | 2018-12-11 12:57:38 +0100 | [diff] [blame] | 183 | && (view.firstChild.classList.contains("stdisabled") === true) |
hebasta | a0282be | 2018-12-05 16:58:00 +0100 | [diff] [blame] | 184 | && (div.getElementsByClassName("reloadStatB").length === 1) ) { |
| 185 | return true; |
| 186 | } |
| 187 | return false; |
| 188 | }; |
| 189 | |
| 190 | |
| 191 | describe('KorAP.CorpusStat', function(){ |
hebasta | 47d03a4 | 2018-06-25 10:31:58 +0200 | [diff] [blame] | 192 | |
hebasta | 5e4d754 | 2018-06-19 16:57:36 +0200 | [diff] [blame] | 193 | it('should be initiable', function(){ |
Akron | 18a99c0 | 2018-08-20 12:55:14 +0200 | [diff] [blame] | 194 | var stat = statClass.create(preDefinedStat); |
hebasta | 5e4d754 | 2018-06-19 16:57:36 +0200 | [diff] [blame] | 195 | expect( function() { statClass.create() }).toThrow(new Error("Missing parameter")); |
| 196 | }); |
| 197 | |
| 198 | |
Akron | 18a99c0 | 2018-08-20 12:55:14 +0200 | [diff] [blame] | 199 | it('should be parsed in a statistic view and displayed as HTML Description List', function(){ |
| 200 | var stat = statClass.create(preDefinedStat); |
hebasta | a0282be | 2018-12-05 16:58:00 +0100 | [diff] [blame] | 201 | var descL = stat.element(); |
hebasta | 5e4d754 | 2018-06-19 16:57:36 +0200 | [diff] [blame] | 202 | expect(descL.tagName).toEqual('DL'); |
| 203 | expect(descL.children[0].tagName).toEqual('DIV'); |
| 204 | expect(descL.children[0].children[0].tagName).toEqual('DT'); |
| 205 | expect(descL.children[0].children[0].attributes[0].name).toEqual('title'); |
| 206 | expect(descL.children[0].children[1].tagName).toEqual('DD'); |
Akron | 18a99c0 | 2018-08-20 12:55:14 +0200 | [diff] [blame] | 207 | |
hebasta | 5e4d754 | 2018-06-19 16:57:36 +0200 | [diff] [blame] | 208 | expect(descL.children[0].children[0].firstChild.nodeValue).toEqual('documents'); |
| 209 | expect(descL.children[0].children[1].firstChild.nodeValue).toEqual('12'); |
| 210 | expect(descL.children[0].children[0].attributes[0].value).toEqual('documents'); |
Akron | 2f97912 | 2018-07-25 17:00:23 +0200 | [diff] [blame] | 211 | |
| 212 | expect(descL.children[1].children[0].firstChild.nodeValue).toEqual('tokens'); |
| 213 | expect(descL.children[1].children[1].firstChild.nodeValue).toEqual(new Number(2323).toLocaleString()); |
| 214 | expect(descL.children[1].children[0].attributes[0].value).toEqual('tokens'); |
| 215 | }); |
hebasta | 5e4d754 | 2018-06-19 16:57:36 +0200 | [diff] [blame] | 216 | |
hebasta | 47d03a4 | 2018-06-25 10:31:58 +0200 | [diff] [blame] | 217 | |
hebasta | 6c8f09d | 2018-07-24 13:21:36 +0200 | [diff] [blame] | 218 | it('should display corpus statistic after creating a corpus statistic view', function(){ |
Akron | 18a99c0 | 2018-08-20 12:55:14 +0200 | [diff] [blame] | 219 | var vc = vcClass.create([ |
| 220 | ['title', 'string'], |
| 221 | ['subTitle', 'string'], |
| 222 | ['pubDate', 'date'], |
| 223 | ['author', 'text'] |
| 224 | ]).fromJson(json); |
| 225 | |
hebasta | a0282be | 2018-12-05 16:58:00 +0100 | [diff] [blame] | 226 | KorAP.vc = vc; |
| 227 | |
Akron | 18a99c0 | 2018-08-20 12:55:14 +0200 | [diff] [blame] | 228 | statView = corpStatVClass.create(vc); |
hebasta | a0282be | 2018-12-05 16:58:00 +0100 | [diff] [blame] | 229 | // corpStatVClass.show(vc); |
Akron | 18a99c0 | 2018-08-20 12:55:14 +0200 | [diff] [blame] | 230 | |
hebasta | 47d03a4 | 2018-06-25 10:31:58 +0200 | [diff] [blame] | 231 | var testDiv = document.createElement('div'); |
hebasta | 6c8f09d | 2018-07-24 13:21:36 +0200 | [diff] [blame] | 232 | testDiv.appendChild(statView.show()); |
hebasta | a0282be | 2018-12-05 16:58:00 +0100 | [diff] [blame] | 233 | // statClass.showCorpStat(testDiv, vc); |
hebasta | 47d03a4 | 2018-06-25 10:31:58 +0200 | [diff] [blame] | 234 | |
| 235 | expect(testDiv.children[0].tagName).toEqual('DIV'); |
| 236 | expect(testDiv.children[0].getAttribute("class")).toEqual('stattable'); |
| 237 | expect(testDiv.children[0].children[0].tagName).toEqual('DL'); |
| 238 | expect(testDiv.children[0].children[0].children[0].children[0].firstChild.nodeValue).toEqual('documents'); |
| 239 | expect(testDiv.children[0].children[0].children[0].children[1].firstChild.nodeValue).toEqual('12'); |
hebasta | 47d03a4 | 2018-06-25 10:31:58 +0200 | [diff] [blame] | 240 | }); |
Akron | 18a99c0 | 2018-08-20 12:55:14 +0200 | [diff] [blame] | 241 | |
| 242 | it('should display the statistics button in a panel', function () { |
| 243 | var vc = vcClass.create([ |
| 244 | ['title', 'string'], |
| 245 | ['subTitle', 'string'], |
| 246 | ['pubDate', 'date'], |
| 247 | ['author', 'text'] |
| 248 | ]).fromJson(json); |
| 249 | |
| 250 | var show = document.createElement('div'); |
| 251 | |
| 252 | show.appendChild(vc.element()); |
| 253 | |
| 254 | var panel = show.firstChild.lastChild.firstChild; |
| 255 | expect(panel.classList.contains('panel')).toBeTruthy(); |
| 256 | expect(panel.classList.contains('vcinfo')).toBeTruthy(); |
| 257 | expect(panel.lastChild.classList.contains('button-group')).toBeTruthy(); |
| 258 | expect(panel.lastChild.classList.contains('vcinfo')).toBeTruthy(); |
| 259 | expect(panel.lastChild.children[0].tagName).toEqual('SPAN'); |
| 260 | expect(panel.lastChild.children[0].textContent).toEqual('Statistics'); |
| 261 | }); |
| 262 | |
| 263 | |
| 264 | it('should display the statistics button in a panel after VC modification', function () { |
| 265 | |
| 266 | var vc = vcClass.create([ |
| 267 | ['title', 'string'], |
| 268 | ['subTitle', 'string'], |
| 269 | ['pubDate', 'date'], |
| 270 | ['author', 'text'] |
| 271 | ]).fromJson(json); |
| 272 | |
| 273 | var show = document.createElement('div'); |
| 274 | |
| 275 | show.appendChild(vc.element()); |
| 276 | |
| 277 | expect(show.querySelector(".statistic").tagName).toEqual("SPAN"); |
| 278 | |
Akron | adab5e5 | 2018-08-20 13:50:53 +0200 | [diff] [blame] | 279 | var and = vc.builder().lastChild.firstChild; |
Akron | 18a99c0 | 2018-08-20 12:55:14 +0200 | [diff] [blame] | 280 | |
| 281 | // Click on and() in VC |
| 282 | and.click(); |
| 283 | |
| 284 | // Check that statistics is there |
| 285 | expect(show.querySelector(".statistic").tagName).toEqual("SPAN"); |
| 286 | }); |
| 287 | |
| 288 | |
| 289 | it('should display and hide corpus statistics view in the panel', function () { |
| 290 | |
| 291 | var vc = vcClass.create([ |
| 292 | ['title', 'string'], |
| 293 | ['subTitle', 'string'], |
| 294 | ['pubDate', 'date'], |
| 295 | ['author', 'text'] |
| 296 | ]).fromJson(json); |
| 297 | |
| 298 | var show = document.createElement('div'); |
| 299 | |
| 300 | show.appendChild(vc.element()); |
| 301 | |
| 302 | var panel = show.firstChild.lastChild.firstChild; |
| 303 | |
| 304 | // Show statistics |
| 305 | panel.lastChild.children[0].click(); |
| 306 | |
| 307 | // Statistics view |
| 308 | var viewE = panel.firstChild.firstChild; |
| 309 | |
| 310 | expect(viewE.tagName).toEqual("DIV"); |
| 311 | expect(viewE.classList.contains("view")).toBeTruthy(); |
| 312 | expect(viewE.classList.contains("vcstatistic")).toBeTruthy(); |
| 313 | |
| 314 | expect(viewE.firstChild.classList.contains("stattable")).toBeTruthy(); |
| 315 | expect(viewE.firstChild.firstChild.tagName).toEqual("DL"); |
| 316 | |
| 317 | // List of statistic values |
| 318 | var dl = viewE.firstChild.firstChild.firstChild; |
| 319 | expect(dl.firstChild.tagName).toEqual("DT"); |
| 320 | expect(dl.firstChild.textContent).toEqual("documents"); |
| 321 | expect(dl.lastChild.tagName).toEqual("DD"); |
| 322 | expect(dl.lastChild.textContent).toEqual("12"); |
| 323 | |
| 324 | expect(viewE.children.length).toEqual(2); |
| 325 | |
| 326 | expect(viewE.lastChild.classList.contains("button-group")).toBeTruthy(); |
| 327 | expect(viewE.lastChild.children.length).toEqual(1); |
| 328 | expect(viewE.lastChild.firstChild.tagName).toEqual("SPAN"); |
| 329 | expect(viewE.lastChild.firstChild.textContent).toEqual("Close"); |
| 330 | |
| 331 | // Close view |
| 332 | viewE.lastChild.firstChild.firstChild.click(); |
| 333 | |
| 334 | // Is gone |
| 335 | expect(panel.firstChild.children.length).toEqual(0); |
| 336 | |
| 337 | // Show statistics |
| 338 | panel.lastChild.children[0].click(); |
| 339 | |
| 340 | // Is there |
| 341 | expect(panel.firstChild.children.length).toEqual(1); |
| 342 | |
| 343 | // Only show once |
| 344 | panel.lastChild.children[0].click(); |
| 345 | expect(panel.firstChild.children.length).toEqual(1); |
| 346 | }); |
hebasta | a0282be | 2018-12-05 16:58:00 +0100 | [diff] [blame] | 347 | |
| 348 | |
| 349 | }); |
| 350 | |
| 351 | |
| 352 | |
| 353 | /** |
| 354 | * Test disabling and reload of corpus statistic if vc is changed |
| 355 | * in vc builder through user-interaction |
| 356 | */ |
| 357 | describe ('KorAP.CorpusStat.Disable', function(){ |
hebasta | de595b4 | 2019-02-05 13:53:10 +0100 | [diff] [blame] | 358 | |
hebasta | de595b4 | 2019-02-05 13:53:10 +0100 | [diff] [blame] | 359 | |
hebasta | a0282be | 2018-12-05 16:58:00 +0100 | [diff] [blame] | 360 | /** |
| 361 | * If the user defines a new vc, the statistic should be disabled, |
| 362 | * because it is out-of-date. |
| 363 | * |
| 364 | * The user can choose to display an up-to-date corpus statistic. Here it is tested |
| 365 | * if corpus statistic is disabled after a valid change of corpus statistic and if the corpus statistic is updatable. |
| 366 | */ |
| 367 | it ('should disable the corpus statistic if corpus definition is changed and display a functional reload button', function(){ |
| 368 | |
| 369 | KorAP.vc = generateCorpusDocGr(); |
| 370 | |
| 371 | //Show corpus statistic |
| 372 | let show = document.createElement('div'); |
| 373 | show.appendChild(KorAP.vc.element()); |
| 374 | let panel = show.firstChild.lastChild.firstChild; |
| 375 | panel.lastChild.children[0].click(); |
| 376 | let view = panel.firstChild.firstChild; |
| 377 | |
| 378 | //corpus statistic is active |
| 379 | expect(checkStatActive(view, show)).toBe(true); |
| 380 | |
| 381 | //change vc, a line in vc builder is deleted |
| 382 | KorAP._delete.apply(KorAP.vc.root().getOperand(0)); |
| 383 | expect(checkStatDisabled(view,show)).toBe(true); |
| 384 | |
| 385 | //click at reload button |
| 386 | let rlbutton = show.getElementsByClassName("refresh").item(0); |
| 387 | rlbutton.click(); |
| 388 | |
| 389 | expect(checkStatActive(view,show)).toBe(true); |
| 390 | }); |
| 391 | |
| 392 | |
| 393 | it('should disable corpus statistic if entries in vc builder are deleted', function(){ |
| 394 | KorAP.vc = generateCorpusDocGr(); |
| 395 | |
| 396 | // create corpus builder and corpus statistic; |
| 397 | let show = document.createElement('div'); |
| 398 | show.appendChild(KorAP.vc.element()); |
| 399 | let panel = show.firstChild.lastChild.firstChild; |
| 400 | panel.lastChild.children[0].click(); |
| 401 | let view = panel.firstChild.firstChild; |
| 402 | |
| 403 | expect(checkStatActive(view, show)).toBe(true); |
| 404 | |
| 405 | //delete foo=bar |
| 406 | KorAP._delete.apply(KorAP.vc.root().getOperand(1)); |
| 407 | expect(checkStatDisabled(view, show)).toBe(true); |
| 408 | |
| 409 | //refresh corpus statistic |
| 410 | let rlbutton = show.getElementsByClassName("refresh").item(0); |
| 411 | rlbutton.click(); |
| 412 | expect(checkStatActive(view,show)).toBe(true); |
hebasta | 3f4be92 | 2018-12-11 10:41:46 +0100 | [diff] [blame] | 413 | |
hebasta | a0282be | 2018-12-05 16:58:00 +0100 | [diff] [blame] | 414 | KorAP._delete.apply(KorAP.vc.root()); |
hebasta | 3f4be92 | 2018-12-11 10:41:46 +0100 | [diff] [blame] | 415 | view = panel.firstChild.firstChild; |
| 416 | expect(checkStatDisabled(view, show)).toBe(true); |
hebasta | de595b4 | 2019-02-05 13:53:10 +0100 | [diff] [blame] | 417 | |
| 418 | KorAP.vc = generateBCorpusDocGr(); |
| 419 | // create corpus builder and corpus statistic; |
| 420 | show = document.createElement('div'); |
| 421 | show.appendChild(KorAP.vc.element()); |
| 422 | panel = show.firstChild.lastChild.firstChild; |
| 423 | panel.lastChild.children[0].click(); |
| 424 | view = panel.firstChild.firstChild; |
| 425 | |
| 426 | expect(checkStatActive(view, show)).toBe(true); |
| 427 | KorAP._delete.apply(KorAP.vc.root().getOperand(1)); |
| 428 | view = panel.firstChild.firstChild; |
| 429 | expect(checkStatDisabled(view, show)).toBe(true); |
| 430 | |
hebasta | a0282be | 2018-12-05 16:58:00 +0100 | [diff] [blame] | 431 | }); |
| 432 | |
| 433 | |
| 434 | it('should disable corpus statistic if key, matchoperator or value is changed', function(){ |
| 435 | /* |
| 436 | * Doc change of key, match operator and value |
| 437 | */ |
| 438 | KorAP.vc= generateCorpusDoc(); |
| 439 | // show vc builder and open corpus statistic |
| 440 | let show = document.createElement('div'); |
| 441 | show.appendChild(KorAP.vc.element()); |
| 442 | let panel = show.firstChild.lastChild.firstChild; |
| 443 | panel.lastChild.children[0].click(); |
| 444 | let view = panel.firstChild.firstChild; |
| 445 | expect(checkStatActive(view, show)).toBe(true); |
| 446 | |
| 447 | KorAP.vc.root().matchop("ne").update(); |
| 448 | expect(checkStatDisabled(view, show)).toBe(true); |
| 449 | |
| 450 | let rlbutton = show.getElementsByClassName("refresh").item(0); |
| 451 | rlbutton.click(); |
| 452 | |
| 453 | view = panel.firstChild.firstChild; |
| 454 | expect(checkStatActive(view, show)).toBe(true); |
| 455 | KorAP.vc.root().value("Hello tester").update(); |
| 456 | expect(checkStatDisabled(view, show)).toBe(true); |
| 457 | |
| 458 | //refresh corpus statistic |
| 459 | rlbutton = show.getElementsByClassName("refresh").item(0); |
| 460 | rlbutton.click(); |
| 461 | view = panel.firstChild.firstChild; |
| 462 | expect(checkStatActive(view, show)).toBe(true); |
| 463 | |
| 464 | KorAP.vc.root().key("author").update(); |
| 465 | expect(checkStatDisabled(view, show)).toBe(true); |
| 466 | |
| 467 | |
| 468 | /* |
| 469 | * DocGroupRef change of value... |
| 470 | */ |
| 471 | KorAP.vc = generateCorpusRef(); |
| 472 | show = document.createElement('div'); |
| 473 | show.appendChild(KorAP.vc.element()); |
| 474 | panel = show.firstChild.lastChild.firstChild; |
| 475 | panel.lastChild.children[0].click(); |
| 476 | view = panel.firstChild.firstChild; |
| 477 | expect(checkStatActive(view, show)).toBe(true); |
| 478 | |
| 479 | KorAP.vc.root().ref("@anton/secondCorpus").update(); |
| 480 | expect(checkStatDisabled(view, show)).toBe(true); |
| 481 | }); |
| 482 | |
| 483 | |
| 484 | it('should not disable corpus statistic if docgroup definition is incomplete', function(){ |
| 485 | |
| 486 | KorAP.vc = generateCorpusDocGr(); |
| 487 | |
| 488 | //Show corpus statistic |
| 489 | let show = document.createElement('div'); |
| 490 | show.appendChild(KorAP.vc.element()); |
| 491 | let panel = show.firstChild.lastChild.firstChild; |
| 492 | panel.lastChild.children[0].click(); |
| 493 | let view = panel.firstChild.firstChild; |
| 494 | |
| 495 | expect(checkStatActive(view, show)).toBe(true); |
| 496 | |
| 497 | KorAP._and.apply(KorAP.vc.root()); |
| 498 | |
| 499 | let andbuild = show.getElementsByClassName("builder"); |
| 500 | expect(andbuild[0].firstChild.classList.contains('docGroup')).toBeTruthy(); |
| 501 | expect(andbuild[0].firstChild.getAttribute("data-operation")).toEqual("and"); |
| 502 | expect(checkStatActive(view, show)).toBe(true); |
| 503 | }); |
| 504 | |
| 505 | |
| 506 | it('should not disable corpus statistic if doc/docref definition is incomplete', function(){ |
| 507 | |
| 508 | /* |
| 509 | * DOC incomplete |
| 510 | */ |
| 511 | KorAP.vc = vcClass.create().fromJson(); |
| 512 | expect(KorAP.vc.builder().firstChild.classList.contains('unspecified')).toBeTruthy(); |
| 513 | |
| 514 | // show vc builder and open corpus statistic |
| 515 | let show = document.createElement('div'); |
| 516 | show.appendChild(KorAP.vc.element()); |
| 517 | let panel = show.firstChild.lastChild.firstChild; |
| 518 | panel.lastChild.children[0].click(); |
| 519 | let view = panel.firstChild.firstChild; |
| 520 | |
| 521 | // corpus statistic should be shown and be up-to-date, reload button is not shown |
| 522 | expect(checkStatActive(view, show)).toBe(true); |
| 523 | |
| 524 | // open the menu |
| 525 | KorAP.vc.builder().firstChild.firstChild.click(); |
| 526 | KorAP._vcKeyMenu._prefix.add("author"); |
| 527 | let prefElement = KorAP.vc.builder().querySelector('span.pref'); |
| 528 | // add key 'author' to VC |
| 529 | prefElement.click(); |
| 530 | |
| 531 | expect(checkStatActive(view, show)).toBe(true); |
| 532 | |
| 533 | |
| 534 | /* |
| 535 | * DOCREF incomplete |
| 536 | */ |
| 537 | KorAP.vc = vcClass.create().fromJson(); |
| 538 | expect(KorAP.vc.builder().firstChild.classList.contains('unspecified')).toBeTruthy(); |
| 539 | |
| 540 | // show vc builder and open corpus statistic |
| 541 | show = document.createElement('div'); |
| 542 | show.appendChild(KorAP.vc.element()); |
| 543 | panel = show.firstChild.lastChild.firstChild; |
| 544 | panel.lastChild.children[0].click(); |
| 545 | view = panel.firstChild.firstChild; |
| 546 | expect(checkStatActive(view, show)).toBe(true); |
| 547 | |
| 548 | KorAP.vc.builder().firstChild.firstChild.click(); |
| 549 | KorAP._vcKeyMenu._prefix.add("referTo"); |
| 550 | prefElement = KorAP.vc.builder().querySelector('span.pref'); |
| 551 | prefElement.click(); |
| 552 | expect(checkStatActive(view, show)).toBe(true); |
| 553 | }); |
| 554 | }); |
hebasta | 5e4d754 | 2018-06-19 16:57:36 +0200 | [diff] [blame] | 555 | }); |