hebasta | 8fe7438 | 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 | 0ce20d7 | 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 | 8fe7438 | 2018-06-19 16:57:36 +0200 | [diff] [blame] | 67 | |
hebasta | 0ce20d7 | 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 | 0f0fd33 | 2018-06-29 10:11:15 +0200 | [diff] [blame^] | 79 | |
hebasta | 0ce20d7 | 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 | |
| 89 | vcEl = vc.element(); |
| 90 | |
hebasta | 8fe7438 | 2018-06-19 16:57:36 +0200 | [diff] [blame] | 91 | var stat = statClass.create(preDefinedStat); |
| 92 | var descL = stat.element(); |
| 93 | |
hebasta | 0f0fd33 | 2018-06-29 10:11:15 +0200 | [diff] [blame^] | 94 | |
hebasta | 8fe7438 | 2018-06-19 16:57:36 +0200 | [diff] [blame] | 95 | it('should be initiable', function(){ |
| 96 | expect(stat._visibleStat).toEqual(false); |
| 97 | expect( function() { statClass.create() }).toThrow(new Error("Missing parameter")); |
| 98 | }); |
| 99 | |
| 100 | |
| 101 | it('should be parsed in a statistic view and displayed as HTML Description List', function(){ |
| 102 | expect(descL.tagName).toEqual('DL'); |
| 103 | expect(descL.children[0].tagName).toEqual('DIV'); |
| 104 | expect(descL.children[0].children[0].tagName).toEqual('DT'); |
| 105 | expect(descL.children[0].children[0].attributes[0].name).toEqual('title'); |
| 106 | expect(descL.children[0].children[1].tagName).toEqual('DD'); |
| 107 | |
| 108 | expect(descL.children[0].children[0].firstChild.nodeValue).toEqual('documents'); |
| 109 | expect(descL.children[0].children[1].firstChild.nodeValue).toEqual('12'); |
| 110 | expect(descL.children[0].children[0].attributes[0].value).toEqual('documents'); |
hebasta | 8fe7438 | 2018-06-19 16:57:36 +0200 | [diff] [blame] | 111 | }); |
| 112 | |
hebasta | 0ce20d7 | 2018-06-25 10:31:58 +0200 | [diff] [blame] | 113 | |
| 114 | it('should display corpus statistic and close Button', function(){ |
| 115 | |
| 116 | var testDiv = document.createElement('div'); |
| 117 | statClass.showCorpStat(testDiv, vc); |
| 118 | |
| 119 | expect(testDiv.children[0].tagName).toEqual('DIV'); |
| 120 | expect(testDiv.children[0].getAttribute("class")).toEqual('stattable'); |
| 121 | expect(testDiv.children[0].children[0].tagName).toEqual('DL'); |
| 122 | expect(testDiv.children[0].children[0].children[0].children[0].firstChild.nodeValue).toEqual('documents'); |
| 123 | expect(testDiv.children[0].children[0].children[0].children[1].firstChild.nodeValue).toEqual('12'); |
| 124 | expect(testDiv.children[0].children[1].classList).toContain('action'); |
| 125 | expect(testDiv.children[0].children[1].children[0].classList).toContain('close'); |
| 126 | }); |
| 127 | |
hebasta | 8fe7438 | 2018-06-19 16:57:36 +0200 | [diff] [blame] | 128 | }); |
hebasta | 0ce20d7 | 2018-06-25 10:31:58 +0200 | [diff] [blame] | 129 | |
hebasta | 8fe7438 | 2018-06-19 16:57:36 +0200 | [diff] [blame] | 130 | }); |