Test for handling statistic/close button and display of corpus statistic
Change-Id: I0980af6e9643270fa7ce315edc02d3de281dfb1a
diff --git a/dev/js/spec/statSpec.js b/dev/js/spec/statSpec.js
index fd5243a..2edc972 100644
--- a/dev/js/spec/statSpec.js
+++ b/dev/js/spec/statSpec.js
@@ -5,22 +5,100 @@
*/
-define(['vc'], function(){
-
-
- describe('KorAP.CorpusStat', function(){
-
- var preDefinedStat={
- "documents":12,
- "tokens":2323,
- "sentences":343434,
- "paragraphs":45454545
- };
+define(['vc', 'vc/statistic'], function(vcClass, statClass){
+
+ var json = {
+ "@type":"koral:docGroup",
+ "operation":"operation:or",
+ "operands":[
+ {
+ "@type":"koral:docGroup",
+ "operation":"operation:and",
+ "operands":[
+ {
+ "@type":"koral:doc",
+ "key":"title",
+ "value":"Der Birnbaum",
+ "match":"match:eq"
+ },
+ {
+ "@type":"koral:doc",
+ "key":"pubPlace",
+ "value":"Mannheim",
+ "type" : "type:regex",
+ "match":"match:contains"
+ },
+ {
+ "@type":"koral:docGroup",
+ "operation":"operation:or",
+ "operands":[
+ {
+ "@type":"koral:doc",
+ "key":"subTitle",
+ "value":"Aufzucht und Pflege",
+ "match":"match:eq"
+ },
+ {
+ "@type":"koral:doc",
+ "key":"subTitle",
+ "value":"Gedichte",
+ "match":"match:eq",
+ "rewrites" : [
+ {
+ "@type": "koral:rewrite",
+ "src" : "policy",
+ "operation" : "operation:injection",
+ }
+ ]
+ }
+ ]
+ }
+ ]
+ },
+ {
+ "@type":"koral:doc",
+ "key":"pubDate",
+ "type":"type:date",
+ "value":"2015-03-05",
+ "match":"match:geq"
+ }
+ ]
+ };
- var statClass = require("vc/statistic");
+ var preDefinedStat={
+ "documents":12,
+ "tokens":2323,
+ "sentences":343434,
+ "paragraphs":45454545
+ };
+
+ KorAP.API.getCorpStat = function(collQu, cb){
+ return cb(preDefinedStat);
+ };
+
+
+
+ describe('KorAP.CorpusStat', function(){
+
+ var vc = vcClass.create([
+ ['title', 'string'],
+ ['subTitle', 'string'],
+ ['pubDate', 'date'],
+ ['author', 'text']
+ ]).fromJson(json);
+
+ vcEl = vc.element();
+
var stat = statClass.create(preDefinedStat);
var descL = stat.element();
+ it('statButton should only be added if doc is specified', function(){
+ expect(vcEl.children[1].id).not.toBe(null);
+ vc2 = vcClass.create().fromJson();
+ expect(vc2.element().children[1]).toBeUndefined();
+ });
+
+
it('should be initiable', function(){
expect(stat._visibleStat).toEqual(false);
expect( function() { statClass.create() }).toThrow(new Error("Missing parameter"));
@@ -37,9 +115,23 @@
expect(descL.children[0].children[0].firstChild.nodeValue).toEqual('documents');
expect(descL.children[0].children[1].firstChild.nodeValue).toEqual('12');
expect(descL.children[0].children[0].attributes[0].value).toEqual('documents');
-
});
-
+
+ it('should display corpus statistic and close Button', function(){
+
+ var testDiv = document.createElement('div');
+ statClass.showCorpStat(testDiv, vc);
+
+ expect(testDiv.children[0].tagName).toEqual('DIV');
+ expect(testDiv.children[0].getAttribute("class")).toEqual('stattable');
+ expect(testDiv.children[0].children[0].tagName).toEqual('DL');
+ expect(testDiv.children[0].children[0].children[0].children[0].firstChild.nodeValue).toEqual('documents');
+ expect(testDiv.children[0].children[0].children[0].children[1].firstChild.nodeValue).toEqual('12');
+ expect(testDiv.children[0].children[1].classList).toContain('action');
+ expect(testDiv.children[0].children[1].children[0].classList).toContain('close');
+ });
+
});
+
});
diff --git a/dev/js/src/vc/statistic.js b/dev/js/src/vc/statistic.js
index 402fb25..a5a2f02 100644
--- a/dev/js/src/vc/statistic.js
+++ b/dev/js/src/vc/statistic.js
@@ -125,8 +125,10 @@
statisticobj = that.create(statistic);
//Removes statistic button when statistic is displayed
- var divStatButton = document.getElementById('dCorpStat');
- divStatButton.parentNode.removeChild(divStatButton);
+ if(document.getElementById('dCorpStat') !== null){
+ var divStatButton = document.getElementById('dCorpStat');
+ divStatButton.parentNode.removeChild(divStatButton);
+ }
statTable.appendChild(statisticobj.element());