blob: e442ee26c6ef1dcf1490f616bcafa8596ae819de [file] [log] [blame]
hebasta5e4d7542018-06-19 16:57:36 +02001/**
2 * Test suite for corpus statistic
3 *
4 * @author Helge Stallkamp
5 */
6
7
hebasta6c8f09d2018-07-24 13:21:36 +02008define(['vc', 'vc/statistic', 'view/corpstatv'], function(vcClass, statClass, corpStatVClass){
hebasta47d03a42018-06-25 10:31:58 +02009
10 var json = {
11 "@type":"koral:docGroup",
12 "operation":"operation:or",
13 "operands":[
14 {
15 "@type":"koral:docGroup",
16 "operation":"operation:and",
17 "operands":[
18 {
19 "@type":"koral:doc",
20 "key":"title",
21 "value":"Der Birnbaum",
22 "match":"match:eq"
23 },
24 {
25 "@type":"koral:doc",
26 "key":"pubPlace",
27 "value":"Mannheim",
28 "type" : "type:regex",
29 "match":"match:contains"
30 },
31 {
32 "@type":"koral:docGroup",
33 "operation":"operation:or",
34 "operands":[
35 {
36 "@type":"koral:doc",
37 "key":"subTitle",
38 "value":"Aufzucht und Pflege",
39 "match":"match:eq"
40 },
41 {
42 "@type":"koral:doc",
43 "key":"subTitle",
44 "value":"Gedichte",
45 "match":"match:eq",
46 "rewrites" : [
47 {
48 "@type": "koral:rewrite",
49 "src" : "policy",
50 "operation" : "operation:injection",
51 }
52 ]
53 }
54 ]
55 }
56 ]
57 },
58 {
59 "@type":"koral:doc",
60 "key":"pubDate",
61 "type":"type:date",
62 "value":"2015-03-05",
63 "match":"match:geq"
64 }
65 ]
66 };
hebasta5e4d7542018-06-19 16:57:36 +020067
hebasta47d03a42018-06-25 10:31:58 +020068 var preDefinedStat={
69 "documents":12,
70 "tokens":2323,
71 "sentences":343434,
72 "paragraphs":45454545
73 };
74
75 KorAP.API.getCorpStat = function(collQu, cb){
76 return cb(preDefinedStat);
77 };
78
hebasta4c92eec2018-06-29 10:11:15 +020079
hebasta47d03a42018-06-25 10:31:58 +020080 describe('KorAP.CorpusStat', function(){
81
82 var vc = vcClass.create([
83 ['title', 'string'],
84 ['subTitle', 'string'],
85 ['pubDate', 'date'],
86 ['author', 'text']
87 ]).fromJson(json);
88
hebasta6c8f09d2018-07-24 13:21:36 +020089 vcEl = vc.element();
hebasta47d03a42018-06-25 10:31:58 +020090
hebasta5e4d7542018-06-19 16:57:36 +020091 var stat = statClass.create(preDefinedStat);
92 var descL = stat.element();
93
hebasta4c92eec2018-06-29 10:11:15 +020094
hebasta5e4d7542018-06-19 16:57:36 +020095 it('should be initiable', function(){
hebasta5e4d7542018-06-19 16:57:36 +020096 expect( function() { statClass.create() }).toThrow(new Error("Missing parameter"));
97 });
98
99
100 it('should be parsed in a statistic view and displayed as HTML Description List', function(){
101 expect(descL.tagName).toEqual('DL');
102 expect(descL.children[0].tagName).toEqual('DIV');
103 expect(descL.children[0].children[0].tagName).toEqual('DT');
104 expect(descL.children[0].children[0].attributes[0].name).toEqual('title');
105 expect(descL.children[0].children[1].tagName).toEqual('DD');
106
107 expect(descL.children[0].children[0].firstChild.nodeValue).toEqual('documents');
108 expect(descL.children[0].children[1].firstChild.nodeValue).toEqual('12');
109 expect(descL.children[0].children[0].attributes[0].value).toEqual('documents');
hebasta5e4d7542018-06-19 16:57:36 +0200110 });
111
hebasta47d03a42018-06-25 10:31:58 +0200112
hebasta6c8f09d2018-07-24 13:21:36 +0200113 it('should display corpus statistic after creating a corpus statistic view', function(){
114 statView = corpStatVClass.create(vc);
115 //corpStatVClass.show(vc);
116
hebasta47d03a42018-06-25 10:31:58 +0200117 var testDiv = document.createElement('div');
hebasta6c8f09d2018-07-24 13:21:36 +0200118 testDiv.appendChild(statView.show());
119 //statClass.showCorpStat(testDiv, vc);
hebasta47d03a42018-06-25 10:31:58 +0200120
121 expect(testDiv.children[0].tagName).toEqual('DIV');
122 expect(testDiv.children[0].getAttribute("class")).toEqual('stattable');
123 expect(testDiv.children[0].children[0].tagName).toEqual('DL');
124 expect(testDiv.children[0].children[0].children[0].children[0].firstChild.nodeValue).toEqual('documents');
125 expect(testDiv.children[0].children[0].children[0].children[1].firstChild.nodeValue).toEqual('12');
hebasta6c8f09d2018-07-24 13:21:36 +0200126
hebasta47d03a42018-06-25 10:31:58 +0200127 });
128
hebasta5e4d7542018-06-19 16:57:36 +0200129 });
hebasta47d03a42018-06-25 10:31:58 +0200130
hebasta5e4d7542018-06-19 16:57:36 +0200131});