hebasta | 7639ddd | 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 | f3f91a7 | 2018-06-25 10:31:58 +0200 | [diff] [blame] | 8 | define(['vc', 'vc/statistic'], function(vcClass, statClass){ |
| 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 | 7639ddd | 2018-06-19 16:57:36 +0200 | [diff] [blame] | 67 | |
hebasta | f3f91a7 | 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 | |
| 79 | |
| 80 | |
| 81 | describe('KorAP.CorpusStat', function(){ |
| 82 | |
| 83 | var vc = vcClass.create([ |
| 84 | ['title', 'string'], |
| 85 | ['subTitle', 'string'], |
| 86 | ['pubDate', 'date'], |
| 87 | ['author', 'text'] |
| 88 | ]).fromJson(json); |
| 89 | |
| 90 | vcEl = vc.element(); |
| 91 | |
hebasta | 7639ddd | 2018-06-19 16:57:36 +0200 | [diff] [blame] | 92 | var stat = statClass.create(preDefinedStat); |
| 93 | var descL = stat.element(); |
| 94 | |
hebasta | f3f91a7 | 2018-06-25 10:31:58 +0200 | [diff] [blame] | 95 | it('statButton should only be added if doc is specified', function(){ |
| 96 | expect(vcEl.children[1].id).not.toBe(null); |
| 97 | vc2 = vcClass.create().fromJson(); |
| 98 | expect(vc2.element().children[1]).toBeUndefined(); |
| 99 | }); |
| 100 | |
| 101 | |
hebasta | 7639ddd | 2018-06-19 16:57:36 +0200 | [diff] [blame] | 102 | it('should be initiable', function(){ |
| 103 | expect(stat._visibleStat).toEqual(false); |
| 104 | expect( function() { statClass.create() }).toThrow(new Error("Missing parameter")); |
| 105 | }); |
| 106 | |
| 107 | |
| 108 | it('should be parsed in a statistic view and displayed as HTML Description List', function(){ |
| 109 | expect(descL.tagName).toEqual('DL'); |
| 110 | expect(descL.children[0].tagName).toEqual('DIV'); |
| 111 | expect(descL.children[0].children[0].tagName).toEqual('DT'); |
| 112 | expect(descL.children[0].children[0].attributes[0].name).toEqual('title'); |
| 113 | expect(descL.children[0].children[1].tagName).toEqual('DD'); |
| 114 | |
| 115 | expect(descL.children[0].children[0].firstChild.nodeValue).toEqual('documents'); |
| 116 | expect(descL.children[0].children[1].firstChild.nodeValue).toEqual('12'); |
| 117 | expect(descL.children[0].children[0].attributes[0].value).toEqual('documents'); |
hebasta | 7639ddd | 2018-06-19 16:57:36 +0200 | [diff] [blame] | 118 | }); |
| 119 | |
hebasta | f3f91a7 | 2018-06-25 10:31:58 +0200 | [diff] [blame] | 120 | |
| 121 | it('should display corpus statistic and close Button', function(){ |
| 122 | |
| 123 | var testDiv = document.createElement('div'); |
| 124 | statClass.showCorpStat(testDiv, vc); |
| 125 | |
| 126 | expect(testDiv.children[0].tagName).toEqual('DIV'); |
| 127 | expect(testDiv.children[0].getAttribute("class")).toEqual('stattable'); |
| 128 | expect(testDiv.children[0].children[0].tagName).toEqual('DL'); |
| 129 | expect(testDiv.children[0].children[0].children[0].children[0].firstChild.nodeValue).toEqual('documents'); |
| 130 | expect(testDiv.children[0].children[0].children[0].children[1].firstChild.nodeValue).toEqual('12'); |
| 131 | expect(testDiv.children[0].children[1].classList).toContain('action'); |
| 132 | expect(testDiv.children[0].children[1].children[0].classList).toContain('close'); |
| 133 | }); |
| 134 | |
hebasta | 7639ddd | 2018-06-19 16:57:36 +0200 | [diff] [blame] | 135 | }); |
hebasta | f3f91a7 | 2018-06-25 10:31:58 +0200 | [diff] [blame] | 136 | |
hebasta | 7639ddd | 2018-06-19 16:57:36 +0200 | [diff] [blame] | 137 | }); |