blob: 32a9e368e8a5786db69e55bd9b27d0145ae6101e [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');
Akron2f979122018-07-25 17:00:23 +0200110
111 expect(descL.children[1].children[0].firstChild.nodeValue).toEqual('tokens');
112 expect(descL.children[1].children[1].firstChild.nodeValue).toEqual(new Number(2323).toLocaleString());
113 expect(descL.children[1].children[0].attributes[0].value).toEqual('tokens');
114 });
hebasta5e4d7542018-06-19 16:57:36 +0200115
hebasta47d03a42018-06-25 10:31:58 +0200116
hebasta6c8f09d2018-07-24 13:21:36 +0200117 it('should display corpus statistic after creating a corpus statistic view', function(){
118 statView = corpStatVClass.create(vc);
119 //corpStatVClass.show(vc);
120
hebasta47d03a42018-06-25 10:31:58 +0200121 var testDiv = document.createElement('div');
hebasta6c8f09d2018-07-24 13:21:36 +0200122 testDiv.appendChild(statView.show());
123 //statClass.showCorpStat(testDiv, vc);
hebasta47d03a42018-06-25 10:31:58 +0200124
125 expect(testDiv.children[0].tagName).toEqual('DIV');
126 expect(testDiv.children[0].getAttribute("class")).toEqual('stattable');
127 expect(testDiv.children[0].children[0].tagName).toEqual('DL');
128 expect(testDiv.children[0].children[0].children[0].children[0].firstChild.nodeValue).toEqual('documents');
129 expect(testDiv.children[0].children[0].children[0].children[1].firstChild.nodeValue).toEqual('12');
hebasta6c8f09d2018-07-24 13:21:36 +0200130
hebasta47d03a42018-06-25 10:31:58 +0200131 });
132
hebasta5e4d7542018-06-19 16:57:36 +0200133 });
hebasta47d03a42018-06-25 10:31:58 +0200134
hebasta5e4d7542018-06-19 16:57:36 +0200135});