hebasta | 5e4d754 | 2018-06-19 16:57:36 +0200 | [diff] [blame] | 1 | /** |
| 2 | * Test suite for corpus statistic |
| 3 | * |
| 4 | * @author Helge Stallkamp |
| 5 | */ |
| 6 | |
| 7 | |
hebasta | 6c8f09d | 2018-07-24 13:21:36 +0200 | [diff] [blame^] | 8 | define(['vc', 'vc/statistic', 'view/corpstatv'], function(vcClass, statClass, corpStatVClass){ |
hebasta | 47d03a4 | 2018-06-25 10:31:58 +0200 | [diff] [blame] | 9 | |
| 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 | }; |
hebasta | 5e4d754 | 2018-06-19 16:57:36 +0200 | [diff] [blame] | 67 | |
hebasta | 47d03a4 | 2018-06-25 10:31:58 +0200 | [diff] [blame] | 68 | 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 | |
hebasta | 4c92eec | 2018-06-29 10:11:15 +0200 | [diff] [blame] | 79 | |
hebasta | 47d03a4 | 2018-06-25 10:31:58 +0200 | [diff] [blame] | 80 | 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 | |
hebasta | 6c8f09d | 2018-07-24 13:21:36 +0200 | [diff] [blame^] | 89 | vcEl = vc.element(); |
hebasta | 47d03a4 | 2018-06-25 10:31:58 +0200 | [diff] [blame] | 90 | |
hebasta | 5e4d754 | 2018-06-19 16:57:36 +0200 | [diff] [blame] | 91 | var stat = statClass.create(preDefinedStat); |
| 92 | var descL = stat.element(); |
| 93 | |
hebasta | 4c92eec | 2018-06-29 10:11:15 +0200 | [diff] [blame] | 94 | |
hebasta | 5e4d754 | 2018-06-19 16:57:36 +0200 | [diff] [blame] | 95 | it('should be initiable', function(){ |
hebasta | 5e4d754 | 2018-06-19 16:57:36 +0200 | [diff] [blame] | 96 | 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'); |
hebasta | 5e4d754 | 2018-06-19 16:57:36 +0200 | [diff] [blame] | 110 | }); |
| 111 | |
hebasta | 47d03a4 | 2018-06-25 10:31:58 +0200 | [diff] [blame] | 112 | |
hebasta | 6c8f09d | 2018-07-24 13:21:36 +0200 | [diff] [blame^] | 113 | it('should display corpus statistic after creating a corpus statistic view', function(){ |
| 114 | statView = corpStatVClass.create(vc); |
| 115 | //corpStatVClass.show(vc); |
| 116 | |
hebasta | 47d03a4 | 2018-06-25 10:31:58 +0200 | [diff] [blame] | 117 | var testDiv = document.createElement('div'); |
hebasta | 6c8f09d | 2018-07-24 13:21:36 +0200 | [diff] [blame^] | 118 | testDiv.appendChild(statView.show()); |
| 119 | //statClass.showCorpStat(testDiv, vc); |
hebasta | 47d03a4 | 2018-06-25 10:31:58 +0200 | [diff] [blame] | 120 | |
| 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'); |
hebasta | 6c8f09d | 2018-07-24 13:21:36 +0200 | [diff] [blame^] | 126 | |
hebasta | 47d03a4 | 2018-06-25 10:31:58 +0200 | [diff] [blame] | 127 | }); |
| 128 | |
hebasta | 5e4d754 | 2018-06-19 16:57:36 +0200 | [diff] [blame] | 129 | }); |
hebasta | 47d03a4 | 2018-06-25 10:31:58 +0200 | [diff] [blame] | 130 | |
hebasta | 5e4d754 | 2018-06-19 16:57:36 +0200 | [diff] [blame] | 131 | }); |