Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 1 | // Regarding async: |
| 2 | // http://stackoverflow.com/questions/16423156/getting-requirejs-to-work-with-jasmine |
| 3 | |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 4 | var available = [ |
| 5 | 'base/s=spans', |
| 6 | 'corenlp/c=spans', |
| 7 | 'corenlp/ne=tokens', |
| 8 | 'corenlp/p=tokens', |
| 9 | 'corenlp/s=spans', |
| 10 | 'glemm/l=tokens', |
| 11 | 'mate/l=tokens', |
| 12 | 'mate/m=tokens', |
| 13 | 'mate/p=tokens', |
| 14 | 'opennlp/p=tokens', |
| 15 | 'opennlp/s=spans', |
| 16 | 'tt/l=tokens', |
| 17 | 'tt/p=tokens', |
| 18 | 'tt/s=spans' |
| 19 | ]; |
| 20 | |
| 21 | var match = { |
| 22 | 'corpusID' : 'WPD', |
| 23 | 'docID' : 'UUU', |
| 24 | 'textID' : '01912', |
| 25 | 'matchID' : 'p121-122', |
Akron | 0a6768f | 2016-07-13 18:00:43 +0200 | [diff] [blame] | 26 | 'textSigle' : 'WPD/UUU/01912', |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 27 | 'available' : available |
| 28 | }; |
| 29 | |
hebasta | 999d6c1 | 2018-04-23 12:44:59 +0200 | [diff] [blame] | 30 | |
| 31 | var fields = [ |
| 32 | { |
| 33 | "@type": "koral:field", |
| 34 | "key": "author", |
| 35 | "type": "type:text", |
| 36 | "value": "Sprachpfleger, u.a." |
| 37 | }, |
| 38 | { |
| 39 | "@type": "koral:field", |
| 40 | "key": "textClass", |
| 41 | "type": "type:keywords", |
| 42 | "value": ["kultur", "film"] |
| 43 | }, |
| 44 | { |
| 45 | "@type":"koral:field", |
| 46 | "key":"foundries", |
| 47 | "type":"type:string", |
| 48 | "value":[ |
| 49 | "corenlp", |
| 50 | "corenlp\/constituency", |
| 51 | "corenlp\/morpho", |
| 52 | "corenlp\/sentences", |
| 53 | "dereko", |
| 54 | "dereko\/structure", |
| 55 | "dereko\/structure\/base-sentences-paragraphs-pagebreaks", |
| 56 | "opennlp", |
| 57 | "opennlp\/morpho", |
| 58 | "opennlp\/sentences" |
| 59 | ] |
| 60 | } |
| 61 | ]; |
| 62 | |
| 63 | |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 64 | var snippet = "<span title=\"cnx/l:meist\">" + |
Akron | 4e47d0b | 2017-07-03 17:58:37 +0200 | [diff] [blame] | 65 | " <span title=\"cnx/p:ADV\">" + |
| 66 | " <span title=\"cnx/syn:@PREMOD\">" + |
| 67 | " <span title=\"mate/l:meist\">" + |
| 68 | " <span title=\"mate/l:meist\">" + |
| 69 | " <span title=\"mate/p:ADV\">" + |
| 70 | " <span title=\"opennlp/p:ADV\">meist</span>" + |
| 71 | " </span>" + |
| 72 | " </span>" + |
| 73 | " </span>" + |
| 74 | " </span>" + |
| 75 | " </span>" + |
| 76 | "</span>" + |
| 77 | "<span title=\"cnx/l:deutlich\">" + |
| 78 | " <span title=\"cnx/p:A\">" + |
| 79 | " <span title=\"cnx/syn:@PREMOD\">" + |
| 80 | " <span title=\"mate/l:deutlich\">" + |
| 81 | " <span title=\"mate/m:degree:pos\">" + |
| 82 | " <span title=\"mate/p:ADJD\">" + |
| 83 | " <span title=\"opennlp/p:ADJD\">deutlich</span>" + |
| 84 | " </span>" + |
| 85 | " </span>" + |
| 86 | " </span>" + |
| 87 | " </span>" + |
| 88 | " </span>" + |
| 89 | "</span>" + |
| 90 | "<span title=\"cnx/l:fähig\">" + |
| 91 | " <span title=\"cnx/l:leistung\">" + |
| 92 | " <span title=\"cnx/p:A\">" + |
| 93 | " <span title=\"cnx/p:ADJA\">" + |
| 94 | " <span title=\"cnx/syn:@NH\">" + |
| 95 | " <span title=\"mate/l:leistungsfähig\">" + |
| 96 | " <span title=\"mate/m:degree:comp\">" + |
| 97 | " <span title=\"mate/p:ADJD\">" + |
| 98 | " <span title=\"opennlp/p:ADJD\">leistungsfähiger</span>" + |
| 99 | " </span>" + |
| 100 | " </span>" + |
| 101 | " </span>" + |
| 102 | " </span>" + |
| 103 | " </span>" + |
| 104 | " </span>" + |
| 105 | " </span>" + |
| 106 | "</span>"; |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 107 | |
| 108 | var treeSnippet = |
| 109 | "<span class=\"context-left\"></span>" + |
| 110 | "<span class=\"match\">" + |
| 111 | " <span title=\"xip/c:MC\">" + |
| 112 | " <span title=\"xip/c:TOP\">" + |
| 113 | " <span title=\"xip/c:PP\">" + |
| 114 | " <span title=\"xip/c:PREP\">Mit</span>" + |
| 115 | " <span title=\"xip/c:NP\">" + |
| 116 | " <span title=\"xip/c:DET\">dieser</span>" + |
| 117 | " <span title=\"xip/c:NPA\">" + |
| 118 | " <span title=\"xip/c:NOUN\">Methode</span>" + |
| 119 | " </span>" + |
| 120 | " </span>" + |
| 121 | " </span>" + |
| 122 | " <span title=\"xip/c:VERB\">ist</span>" + |
Akron | 98a933f | 2016-08-11 00:19:17 +0200 | [diff] [blame] | 123 | " <mark>" + |
| 124 | " <span title=\"xip/c:NP\">" + |
| 125 | " <span title=\"xip/c:PRON\">es</span>" + |
| 126 | " </span>" + |
| 127 | " <span title=\"xip/c:AP\">" + |
| 128 | " <span title=\"xip/c:ADV\">nun</span>" + |
| 129 | " <span title=\"xip/c:ADJ\">möglich</span>" + |
| 130 | " </span>" + |
| 131 | " </mark>" + |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 132 | " <span title=\"xip/c:ADV\">z. B.</span>" + |
| 133 | " <span title=\"xip/c:NPA\">" + |
| 134 | " <span title=\"xip/c:NP\">" + |
| 135 | " <span title=\"xip/c:NOUN\">Voice</span>" + |
| 136 | " </span>" + |
| 137 | " </span>" + "(" + |
| 138 | " <span title=\"xip/c:INS\">" + |
| 139 | " <span title=\"xip/c:NPA\">" + |
| 140 | " <span title=\"xip/c:NP\">" + |
| 141 | " <span title=\"xip/c:NOUN\">Sprache</span>" + |
| 142 | " </span>" + |
| 143 | " </span>" + |
| 144 | " </span>" + ")" + |
| 145 | " <span title=\"xip/c:VERB\">bevorzugt</span>" + |
| 146 | " <span title=\"xip/c:PP\">" + |
| 147 | " <span title=\"xip/c:PREP\">in</span>" + |
| 148 | " <span title=\"xip/c:NP\">" + |
| 149 | " <span title=\"xip/c:PRON\">der</span>" + |
| 150 | " </span>" + |
| 151 | " <span title=\"xip/c:NPA\">" + |
| 152 | " <span title=\"xip/c:NP\">" + |
| 153 | " <span title=\"xip/c:NOUN\">Bridge</span>" + |
| 154 | " </span>" + |
| 155 | " </span>" + |
| 156 | " </span>" + |
| 157 | " <span title=\"xip/c:INFC\">" + |
| 158 | " <span title=\"xip/c:INS\">" + |
| 159 | " <span title=\"xip/c:VERB\">weiterzugeben</span>" + |
| 160 | " </span>" + |
| 161 | " </span>" + |
| 162 | " </span>" + |
| 163 | " </span>" + |
| 164 | "</span>" + |
| 165 | "<span class=\"context-right\"></span>"; |
| 166 | |
| 167 | |
| 168 | function matchElementFactory () { |
| 169 | var me = document.createElement('li'); |
| 170 | |
| 171 | me.setAttribute( |
| 172 | 'data-available-info', |
| 173 | 'base/s=spans corenlp/c=spans corenlp/ne=tokens corenlp/p=tokens' + |
| 174 | ' corenlp/s=spans glemm/l=tokens mate/l=tokens mate/m=tokens' + |
| 175 | ' mate/p=tokens opennlp/p=tokens opennlp/s=spans tt/l=tokens' + |
| 176 | ' tt/p=tokens tt/s=spans'); |
| 177 | |
| 178 | me.setAttribute('data-corpus-id', 'WPD'); |
| 179 | me.setAttribute('data-doc-id', 'FFF'); |
| 180 | me.setAttribute('data-text-id', '01460'); |
Akron | 0a6768f | 2016-07-13 18:00:43 +0200 | [diff] [blame] | 181 | me.setAttribute('data-text-sigle', 'WPD/FFF/01460'); |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 182 | me.setAttribute('data-match-id', 'p119-120'); |
| 183 | me.innerHTML = '<div><div class="snippet">check</div></div><p class="ref">me</p>'; |
| 184 | return me; |
| 185 | }; |
| 186 | |
Akron | cdb0baa | 2016-11-07 01:52:11 +0100 | [diff] [blame] | 187 | function matchElementReal () { |
| 188 | var me = document.createElement('em'); |
| 189 | me.innerHTML = |
| 190 | '<li data-match-id="p85183-85184"' + |
| 191 | ' data-text-sigle="GOE/AGI/00000"' + |
| 192 | ' data-available-info="base/s=spans corenlp/c=spans corenlp/p=tokens corenlp/s=spans dereko/s=spans malt/d=rels opennlp/p=tokens opennlp/s=spans tt/l=tokens tt/p=tokens tt/s=spans"' + |
| 193 | ' data-info="{"UID":0,"author":"Goethe, Johann Wolfgang von","corpusID":null,"corpusSigle":"GOE","docID":null,"docSigle":"GOE\/AGI","layerInfos":"base\/s=spans corenlp\/c=spans corenlp\/p=tokens corenlp\/s=spans dereko\/s=spans malt\/d=rels opennlp\/p=tokens opennlp\/s=spans tt\/l=tokens tt\/p=tokens tt\/s=spans","matchID":"match-GOE\/AGI\/00000-p85183-85184","pubDate":"1982","pubPlace":"München","subTitle":"Auch ich in Arkadien!","textID":null,"textSigle":"GOE\/AGI\/00000","title":"Italienische Reise"}"' + |
| 194 | ' id="GOE/AGI/00000#p85183-85184">' + |
| 195 | '<div>' + |
| 196 | '<div class="flag"></div>' + |
| 197 | '<div class="snippet startMore endMore"><span class="context-left"><span class="more"></span>keine großen Flächen, aber sanft gegeneinander laufende Berg- und Hügelrücken, durchgängig mit Weizen und Gerste bestellt, die eine ununterbrochene Masse von Fruchtbarkeit dem Auge darbieten. der diesen Pflanzen geeignete Boden wird so genutzt und so geschont, daß man nirgends einen </span><span class="match"><mark>Baum</mark></span><span class="context-right"> sieht, ja, alle die kleinen Ortschaften und Wohnungen liegen auf Rücken der Hügel, wo eine hinstreichende Reihe Kalkfelsen den Boden ohnehin unbrauchbar macht. dort wohnen die Weiber das ganze Jahr, mit Spinnen und Weben beschäftigt, die Männer hingegen bringen zur<span class="more"></span></span></div>' + |
| 198 | '</div>' + |
| 199 | '<p class="ref"><strong>Italienische Reise</strong> von Goethe, Johann Wolfgang von (<time datetime="1982">1982</time>) <span class="sigle">[GOE/AGI/00000]</span> </p>' + |
| 200 | '</li>'; |
| 201 | return me.firstChild; |
| 202 | }; |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 203 | |
hebasta | 999d6c1 | 2018-04-23 12:44:59 +0200 | [diff] [blame] | 204 | |
Akron | f2279c4 | 2017-12-21 13:48:46 +0100 | [diff] [blame] | 205 | define(['match', 'hint/foundries/cnx', 'hint/foundries/mate'], function () { |
Nils Diewald | 5814133 | 2015-04-07 16:18:45 +0000 | [diff] [blame] | 206 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 207 | // Override getMatchInfo API call |
| 208 | KorAP.API.getMatchInfo = function (x, param, cb) { |
| 209 | if (param['spans'] === undefined || param['spans'] === false) |
| 210 | cb({ "snippet": snippet }); |
| 211 | else |
| 212 | cb({ "snippet": treeSnippet }); |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 213 | }; |
Akron | 671fdb9 | 2017-09-12 18:09:46 +0200 | [diff] [blame] | 214 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 215 | describe('KorAP.InfoLayer', function () { |
| 216 | |
| 217 | var infoClass = require('match/infolayer'); |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 218 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 219 | it('should be initializable', function () { |
| 220 | expect( |
Akron | 671fdb9 | 2017-09-12 18:09:46 +0200 | [diff] [blame] | 221 | function() { infoClass.create() } |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 222 | ).toThrow(new Error("Missing parameters")); |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 223 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 224 | expect( |
Akron | 671fdb9 | 2017-09-12 18:09:46 +0200 | [diff] [blame] | 225 | function() { infoClass.create("base") } |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 226 | ).toThrow(new Error("Missing parameters")); |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 227 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 228 | var layer = infoClass.create("base", "s"); |
| 229 | expect(layer).toBeTruthy(); |
| 230 | expect(layer.foundry).toEqual("base"); |
| 231 | expect(layer.layer).toEqual("s"); |
| 232 | expect(layer.type).toEqual("tokens"); |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 233 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 234 | layer = infoClass.create("cnx", "syn", "spans"); |
| 235 | expect(layer).toBeTruthy(); |
| 236 | expect(layer.foundry).toEqual("cnx"); |
| 237 | expect(layer.layer).toEqual("syn"); |
| 238 | expect(layer.type).toEqual("spans"); |
Nils Diewald | 5814133 | 2015-04-07 16:18:45 +0000 | [diff] [blame] | 239 | }); |
| 240 | }); |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 241 | |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 242 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 243 | describe('KorAP.Match', function () { |
| 244 | var match = { |
| 245 | 'corpusID' : 'WPD', |
| 246 | 'docID' : 'UUU', |
| 247 | 'textID' : '01912', |
| 248 | 'matchID' : 'p121-122', |
Akron | 0a6768f | 2016-07-13 18:00:43 +0200 | [diff] [blame] | 249 | 'textSigle' : 'WPD/UUU/01912', |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 250 | 'available' : available |
| 251 | }; |
| 252 | |
| 253 | var matchClass = require('match'); |
| 254 | |
| 255 | it('should be initializable by Object', function () { |
| 256 | expect(function() { |
Akron | 671fdb9 | 2017-09-12 18:09:46 +0200 | [diff] [blame] | 257 | matchClass.create() |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 258 | }).toThrow(new Error('Missing parameters')); |
| 259 | |
| 260 | expect(matchClass.create(match)).toBeTruthy(); |
| 261 | |
| 262 | var m = matchClass.create(match); |
Akron | 0a6768f | 2016-07-13 18:00:43 +0200 | [diff] [blame] | 263 | expect(m.textSigle).toEqual("WPD/UUU/01912"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 264 | expect(m.matchID).toEqual("p121-122"); |
| 265 | |
| 266 | // /corpus/WPD/UUU.01912/p121-122/matchInfo?spans=false&foundry=* |
| 267 | var m = matchClass.create(match); |
| 268 | |
| 269 | // Spans: |
| 270 | var spans = m.getSpans(); |
| 271 | expect(spans[0].foundry).toEqual("base"); |
| 272 | expect(spans[0].layer).toEqual("s"); |
| 273 | |
| 274 | expect(spans[1].foundry).toEqual("corenlp"); |
| 275 | expect(spans[1].layer).toEqual("c"); |
| 276 | |
| 277 | expect(spans[2].foundry).toEqual("corenlp"); |
| 278 | expect(spans[2].layer).toEqual("s"); |
| 279 | |
| 280 | expect(spans[spans.length-1].foundry).toEqual("tt"); |
| 281 | expect(spans[spans.length-1].layer).toEqual("s"); |
| 282 | |
| 283 | // Tokens: |
| 284 | var tokens = m.getTokens(); |
| 285 | expect(tokens[0].foundry).toEqual("corenlp"); |
| 286 | expect(tokens[0].layer).toEqual("ne"); |
| 287 | |
| 288 | expect(tokens[1].foundry).toEqual("corenlp"); |
| 289 | expect(tokens[1].layer).toEqual("p"); |
| 290 | |
| 291 | expect(tokens[tokens.length-1].foundry).toEqual("tt"); |
| 292 | expect(tokens[tokens.length-1].layer).toEqual("p"); |
Nils Diewald | 5814133 | 2015-04-07 16:18:45 +0000 | [diff] [blame] | 293 | }); |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 294 | |
| 295 | |
Akron | cdb0baa | 2016-11-07 01:52:11 +0100 | [diff] [blame] | 296 | it('should be initializable by Node 1', function () { |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 297 | var m = matchClass.create(matchElementFactory()); |
Akron | 0a6768f | 2016-07-13 18:00:43 +0200 | [diff] [blame] | 298 | expect(m.textSigle).toEqual("WPD/FFF/01460"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 299 | expect(m.matchID).toEqual("p119-120"); |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 300 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 301 | // Spans: |
| 302 | var spans = m.getSpans(); |
| 303 | expect(spans[0].foundry).toEqual("base"); |
| 304 | expect(spans[0].layer).toEqual("s"); |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 305 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 306 | expect(spans[1].foundry).toEqual("corenlp"); |
| 307 | expect(spans[1].layer).toEqual("c"); |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 308 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 309 | expect(spans[2].foundry).toEqual("corenlp"); |
| 310 | expect(spans[2].layer).toEqual("s"); |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 311 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 312 | expect(spans[spans.length-1].foundry).toEqual("tt"); |
| 313 | expect(spans[spans.length-1].layer).toEqual("s"); |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 314 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 315 | // Tokens: |
| 316 | var tokens = m.getTokens(); |
| 317 | expect(tokens[0].foundry).toEqual("corenlp"); |
| 318 | expect(tokens[0].layer).toEqual("ne"); |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 319 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 320 | expect(tokens[1].foundry).toEqual("corenlp"); |
| 321 | expect(tokens[1].layer).toEqual("p"); |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 322 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 323 | expect(tokens[tokens.length-1].foundry).toEqual("tt"); |
| 324 | expect(tokens[tokens.length-1].layer).toEqual("p"); |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 325 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 326 | }); |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 327 | |
Akron | cdb0baa | 2016-11-07 01:52:11 +0100 | [diff] [blame] | 328 | it('should be initializable by Node 2', function () { |
| 329 | var ele = matchElementReal(); |
| 330 | var m = matchClass.create(ele); |
| 331 | expect(m.textSigle).toEqual("GOE/AGI/00000"); |
| 332 | expect(m.matchID).toEqual("p85183-85184"); |
| 333 | }); |
| 334 | |
| 335 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 336 | it('should react to gui actions', function () { |
| 337 | var e = matchElementFactory(); |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 338 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 339 | expect(e.classList.contains('active')).toBe(false); |
| 340 | expect(e["_match"]).toBe(undefined); |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 341 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 342 | var m = matchClass.create(e); |
| 343 | |
| 344 | expect(e.classList.contains('active')).toBe(false); |
| 345 | expect(e["_match"]).not.toBe(undefined); |
| 346 | |
| 347 | // Open the match |
| 348 | m.open(); |
| 349 | |
| 350 | expect(e.classList.contains('active')).toBe(true); |
| 351 | expect(e["_match"]).not.toBe(undefined); |
| 352 | |
Akron | d141a36 | 2018-07-10 18:12:13 +0200 | [diff] [blame] | 353 | actions = e.querySelector("p.ref > div.action.bottom").children; |
| 354 | |
Akron | c296ca2 | 2018-04-24 16:35:26 +0200 | [diff] [blame] | 355 | expect(actions[0].getAttribute("class")).toEqual("meta"); |
| 356 | expect(actions[1].getAttribute("class")).toEqual("info"); |
| 357 | expect(actions[2].getAttribute("class")).toEqual("tree"); |
| 358 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 359 | // Close the match |
| 360 | m.close(); |
| 361 | expect(e.classList.contains('active')).toBe(false); |
| 362 | expect(e["_match"]).not.toBe(undefined); |
Nils Diewald | 5814133 | 2015-04-07 16:18:45 +0000 | [diff] [blame] | 363 | }); |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 364 | |
Akron | c296ca2 | 2018-04-24 16:35:26 +0200 | [diff] [blame] | 365 | it('should open tree menu', function () { |
| 366 | var e = matchElementFactory(); |
| 367 | var m = matchClass.create(e); |
| 368 | m.open(); |
| 369 | var relation = e.querySelector("p.ref > div.action.bottom > span:nth-of-type(3)"); |
| 370 | expect(relation.getAttribute("class")).toEqual("tree"); |
Akron | 52ed22d | 2018-07-11 17:05:19 +0200 | [diff] [blame] | 371 | expect(document.getElementsByClassName("button-group-list").length).toEqual(0); |
Akron | c296ca2 | 2018-04-24 16:35:26 +0200 | [diff] [blame] | 372 | |
| 373 | expect(document.activeElement.tagName).toEqual("BODY"); |
| 374 | |
| 375 | // Show menu |
| 376 | relation.click(); |
Akron | 52ed22d | 2018-07-11 17:05:19 +0200 | [diff] [blame] | 377 | expect(document.getElementsByClassName("button-group-list").length).toEqual(1); |
Akron | c296ca2 | 2018-04-24 16:35:26 +0200 | [diff] [blame] | 378 | |
| 379 | expect(document.activeElement.tagName).toEqual("UL"); |
| 380 | |
| 381 | // Choose first tree |
Akron | 52ed22d | 2018-07-11 17:05:19 +0200 | [diff] [blame] | 382 | document.getElementsByClassName("button-group-list")[0].getElementsByTagName("li")[1].click(); |
Akron | c296ca2 | 2018-04-24 16:35:26 +0200 | [diff] [blame] | 383 | expect(e.querySelector("div.matchinfo div.matchtree h6 span").innerText).toEqual("corenlp"); |
| 384 | |
| 385 | // This should blur the focus |
| 386 | expect(document.activeElement.tagName).toEqual("BODY"); |
| 387 | }); |
| 388 | |
| 389 | }); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 390 | |
| 391 | describe('KorAP.MatchInfo', function () { |
| 392 | |
| 393 | var matchClass = require('match'); |
| 394 | |
| 395 | var m = matchClass.create(match); |
| 396 | var info = m.info(); |
| 397 | |
| 398 | it('should contain a valid info', function () { |
| 399 | expect(m._info).toEqual(info); |
| 400 | }); |
| 401 | |
| 402 | var table1, table2; |
| 403 | |
| 404 | // Async preparation |
| 405 | it('should fail to load a table async', function (done) { |
| 406 | expect(info).toBeTruthy(); |
| 407 | |
Akron | 5b1a6af | 2018-02-05 15:41:16 +0100 | [diff] [blame] | 408 | info.getTableData([], function (tablen) { |
Akron | 671fdb9 | 2017-09-12 18:09:46 +0200 | [diff] [blame] | 409 | table1 = tablen; |
| 410 | done(); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 411 | }); |
| 412 | }); |
| 413 | |
Akron | 671fdb9 | 2017-09-12 18:09:46 +0200 | [diff] [blame] | 414 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 415 | it('should\'nt be parsable (async)', function () { |
| 416 | expect(table1).not.toBeTruthy(); |
| 417 | }); |
| 418 | |
Akron | 671fdb9 | 2017-09-12 18:09:46 +0200 | [diff] [blame] | 419 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 420 | it('should load a working table async', function(done) { |
| 421 | expect(info).toBeTruthy(); |
Akron | 5b1a6af | 2018-02-05 15:41:16 +0100 | [diff] [blame] | 422 | info.getTableData(undefined, function (tablem) { |
Akron | 671fdb9 | 2017-09-12 18:09:46 +0200 | [diff] [blame] | 423 | table2 = tablem; |
| 424 | done(); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 425 | }); |
| 426 | }); |
| 427 | |
Akron | 671fdb9 | 2017-09-12 18:09:46 +0200 | [diff] [blame] | 428 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 429 | it('should parse into a table (async)', function () { |
| 430 | expect(table2).toBeTruthy(); |
| 431 | |
| 432 | expect(table2.length()).toBe(3); |
| 433 | |
| 434 | expect(table2.getToken(0)).toBe("meist"); |
| 435 | expect(table2.getToken(1)).toBe("deutlich"); |
| 436 | expect(table2.getToken(2)).toBe("leistungsfähiger"); |
| 437 | |
| 438 | expect(table2.getValue(0, "cnx", "p")[0]).toBe("ADV"); |
| 439 | expect(table2.getValue(0, "cnx", "syn")[0]).toBe("@PREMOD"); |
Akron | 916ec25 | 2016-11-10 17:06:32 +0100 | [diff] [blame] | 440 | expect(table2.getValue(0, "mate", "l")[0]).toBe("meist"); |
| 441 | expect(table2.getValue(0, "mate", "l")[1]).toBeUndefined(); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 442 | |
| 443 | expect(table2.getValue(2, "cnx", "l")[0]).toBe("fähig"); |
| 444 | expect(table2.getValue(2, "cnx", "l")[1]).toBe("leistung"); |
| 445 | }); |
| 446 | |
Akron | 671fdb9 | 2017-09-12 18:09:46 +0200 | [diff] [blame] | 447 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 448 | it('should parse into a table view', function () { |
| 449 | var matchElement = matchElementFactory(); |
| 450 | expect(matchElement.tagName).toEqual('LI'); |
| 451 | |
| 452 | // Match |
| 453 | expect(matchElement.children[0].tagName).toEqual('DIV'); |
| 454 | |
| 455 | // snippet |
| 456 | expect(matchElement.children[0].children[0].tagName).toEqual('DIV'); |
| 457 | expect(matchElement.children[0].children[0].classList.contains('snippet')).toBeTruthy(); |
| 458 | expect(matchElement.children[0].children[0].firstChild.nodeValue).toEqual('check'); |
| 459 | |
| 460 | // reference |
| 461 | expect(matchElement.children[1].classList.contains('ref')).toBeTruthy(); |
| 462 | expect(matchElement.children[1].firstChild.nodeValue).toEqual('me'); |
| 463 | |
| 464 | // not yet |
| 465 | expect(matchElement.children[0].children[1]).toBe(undefined); |
| 466 | |
| 467 | var info = matchClass.create(matchElement).info(); |
Akron | 5b1a6af | 2018-02-05 15:41:16 +0100 | [diff] [blame] | 468 | info.showTable(); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 469 | |
| 470 | // Match |
| 471 | expect(matchElement.children[0].tagName).toEqual('DIV'); |
| 472 | |
| 473 | // snippet |
| 474 | expect(matchElement.children[0].children[0].tagName).toEqual('DIV'); |
Akron | 5b1a6af | 2018-02-05 15:41:16 +0100 | [diff] [blame] | 475 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 476 | expect(matchElement.children[0].children[0].classList.contains('snippet')).toBeTruthy(); |
Akron | 5b1a6af | 2018-02-05 15:41:16 +0100 | [diff] [blame] | 477 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 478 | expect(matchElement.children[0].children[0].firstChild.nodeValue).toEqual('check'); |
| 479 | |
| 480 | // reference |
Akron | 5b1a6af | 2018-02-05 15:41:16 +0100 | [diff] [blame] | 481 | expect(matchElement.lastChild.classList.contains('ref')).toBeTruthy(); |
| 482 | expect(matchElement.lastChild.firstChild.nodeValue).toEqual('me'); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 483 | |
| 484 | // now |
Akron | 5b1a6af | 2018-02-05 15:41:16 +0100 | [diff] [blame] | 485 | var infotable = matchElement.children[1]; |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 486 | expect(infotable.tagName).toEqual('DIV'); |
Akron | aa7fce5 | 2017-06-30 21:15:18 +0200 | [diff] [blame] | 487 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 488 | expect(infotable.classList.contains('matchinfo')).toBeTruthy(); |
| 489 | |
| 490 | expect(infotable.children[0].classList.contains('matchtable')).toBeTruthy(); |
Akron | 5b1a6af | 2018-02-05 15:41:16 +0100 | [diff] [blame] | 491 | // expect(infotable.children[1].classList.contains('addtree')).toBeTruthy(); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 492 | }); |
| 493 | |
Akron | 671fdb9 | 2017-09-12 18:09:46 +0200 | [diff] [blame] | 494 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 495 | var tree; |
| 496 | it('should parse into a tree (async) 1', function (done) { |
| 497 | var info = matchClass.create(match).info(); |
| 498 | expect(info).toBeTruthy(); |
Akron | 5b1a6af | 2018-02-05 15:41:16 +0100 | [diff] [blame] | 499 | info.getTreeData(undefined, undefined, "spans", function (treem) { |
Akron | 671fdb9 | 2017-09-12 18:09:46 +0200 | [diff] [blame] | 500 | tree = treem; |
| 501 | done(); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 502 | }); |
| 503 | }); |
| 504 | |
Akron | 671fdb9 | 2017-09-12 18:09:46 +0200 | [diff] [blame] | 505 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 506 | it('should parse into a tree (async) 2', function () { |
| 507 | expect(tree).toBeTruthy(); |
| 508 | expect(tree.nodes()).toEqual(49); |
| 509 | }); |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 510 | |
Akron | 671fdb9 | 2017-09-12 18:09:46 +0200 | [diff] [blame] | 511 | |
Akron | 98a933f | 2016-08-11 00:19:17 +0200 | [diff] [blame] | 512 | var matchElement, info; |
Akron | 5b1a6af | 2018-02-05 15:41:16 +0100 | [diff] [blame] | 513 | |
Akron | 98a933f | 2016-08-11 00:19:17 +0200 | [diff] [blame] | 514 | // var info, matchElement; |
| 515 | it('should parse into a tree view', function () { |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 516 | matchElement = matchElementFactory(); |
| 517 | expect(matchElement.tagName).toEqual('LI'); |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 518 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 519 | info = matchClass.create(matchElement).info(); |
Akron | 5b1a6af | 2018-02-05 15:41:16 +0100 | [diff] [blame] | 520 | info.showTable(); |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 521 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 522 | // Match |
| 523 | expect(matchElement.children[0].tagName).toEqual('DIV'); |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 524 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 525 | // snippet |
| 526 | expect(matchElement.children[0].children[0].tagName).toEqual('DIV'); |
| 527 | expect(matchElement.children[0].children[0].classList.contains('snippet')).toBeTruthy(); |
| 528 | expect(matchElement.children[0].children[0].firstChild.nodeValue).toEqual('check'); |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 529 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 530 | // reference |
Akron | 5b1a6af | 2018-02-05 15:41:16 +0100 | [diff] [blame] | 531 | expect(matchElement.lastChild.classList.contains('ref')).toBeTruthy(); |
| 532 | expect(matchElement.lastChild.firstChild.nodeValue).toEqual('me'); |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 533 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 534 | // now |
Akron | 5b1a6af | 2018-02-05 15:41:16 +0100 | [diff] [blame] | 535 | var infotable = matchElement.children[1]; |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 536 | expect(infotable.tagName).toEqual('DIV'); |
| 537 | expect(infotable.classList.contains('matchinfo')).toBeTruthy(); |
| 538 | expect(infotable.children[0].classList.contains('matchtable')).toBeTruthy(); |
Akron | 5b1a6af | 2018-02-05 15:41:16 +0100 | [diff] [blame] | 539 | // expect(infotable.children[1].classList.contains('addtree')).toBeTruthy(); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 540 | }); |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 541 | |
Akron | 671fdb9 | 2017-09-12 18:09:46 +0200 | [diff] [blame] | 542 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 543 | it('should add a tree view async 1', function (done) { |
| 544 | expect(info).toBeTruthy(); |
Akron | 5b1a6af | 2018-02-05 15:41:16 +0100 | [diff] [blame] | 545 | info.showTree('mate', 'beebop', "spans", function () { |
Akron | 671fdb9 | 2017-09-12 18:09:46 +0200 | [diff] [blame] | 546 | done(); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 547 | }); |
| 548 | }); |
| 549 | |
Akron | 671fdb9 | 2017-09-12 18:09:46 +0200 | [diff] [blame] | 550 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 551 | it('should add a tree view async 2', function () { |
| 552 | // With added tree |
Akron | 5b1a6af | 2018-02-05 15:41:16 +0100 | [diff] [blame] | 553 | var infotable = matchElement.children[1]; |
| 554 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 555 | expect(infotable.tagName).toEqual('DIV'); |
| 556 | expect(infotable.classList.contains('matchinfo')).toBeTruthy(); |
| 557 | expect(infotable.children[0].classList.contains('matchtable')).toBeTruthy(); |
| 558 | expect(infotable.children[1].classList.contains('addtree')).toBe(false); |
| 559 | |
| 560 | var tree = infotable.children[1]; |
| 561 | expect(tree.tagName).toEqual('DIV'); |
| 562 | expect(tree.classList.contains('matchtree')).toBeTruthy(); |
| 563 | expect(tree.children[0].tagName).toEqual('H6'); |
| 564 | expect(tree.children[0].children[0].tagName).toEqual('SPAN'); |
| 565 | expect(tree.children[0].children[0].firstChild.nodeValue).toEqual('mate'); |
| 566 | expect(tree.children[0].children[1].tagName).toEqual('SPAN'); |
| 567 | expect(tree.children[0].children[1].firstChild.nodeValue).toEqual('beebop'); |
| 568 | |
| 569 | expect(tree.children[1].tagName).toEqual('DIV'); |
Nils Diewald | 5814133 | 2015-04-07 16:18:45 +0000 | [diff] [blame] | 570 | }); |
| 571 | }); |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 572 | |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 573 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 574 | describe('KorAP.MatchTable', function () { |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 575 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 576 | var matchClass = require('match'); |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 577 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 578 | var table; |
| 579 | it('should be retrieved async', function (done) { |
| 580 | var info = matchClass.create(match).info(); |
| 581 | expect(info).toBeTruthy(); |
Akron | 5b1a6af | 2018-02-05 15:41:16 +0100 | [diff] [blame] | 582 | info.getTableData(undefined, function (x) { |
Akron | 671fdb9 | 2017-09-12 18:09:46 +0200 | [diff] [blame] | 583 | table = x; |
| 584 | done(); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 585 | }); |
| 586 | }); |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 587 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 588 | it('should be rendered async', function () { |
Akron | 5b1a6af | 2018-02-05 15:41:16 +0100 | [diff] [blame] | 589 | |
| 590 | var e = table.element().firstChild; |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 591 | expect(e.nodeName).toBe('TABLE'); |
| 592 | expect(e.children[0].nodeName).toBe('THEAD'); |
| 593 | var tr = e.children[0].children[0]; |
| 594 | expect(tr.nodeName).toBe('TR'); |
| 595 | expect(tr.children[0].nodeName).toBe('TH'); |
Nils Diewald | 5814133 | 2015-04-07 16:18:45 +0000 | [diff] [blame] | 596 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 597 | expect(tr.children[0].firstChild.nodeValue).toBe('Foundry'); |
| 598 | expect(tr.children[1].firstChild.nodeValue).toBe('Layer'); |
| 599 | expect(tr.children[2].firstChild.nodeValue).toBe('meist'); |
| 600 | expect(tr.children[3].firstChild.nodeValue).toBe('deutlich'); |
| 601 | expect(tr.children[4].firstChild.nodeValue).toBe('leistungsfähiger'); |
| 602 | |
| 603 | // first row |
| 604 | tr = e.children[1].children[0]; |
| 605 | expect(tr.nodeName).toBe('TR'); |
| 606 | expect(tr.getAttribute('tabindex')).toEqual('0'); |
| 607 | expect(tr.children[0].nodeName).toBe('TH'); |
| 608 | expect(tr.children[0].firstChild.nodeValue).toEqual('cnx'); |
| 609 | expect(tr.children[1].firstChild.nodeValue).toEqual('l'); |
| 610 | expect(tr.children[2].firstChild.nodeValue).toEqual('meist'); |
| 611 | expect(tr.children[3].firstChild.nodeValue).toEqual('deutlich'); |
Akron | 47774c4 | 2017-07-03 20:14:55 +0200 | [diff] [blame] | 612 | expect(tr.children[4].firstChild.firstChild.nodeValue).toEqual('fähig'); |
| 613 | expect(tr.children[4].lastChild.firstChild.nodeValue).toEqual('leistung'); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 614 | |
| 615 | // second row |
| 616 | tr = e.children[1].children[1]; |
| 617 | expect(tr.nodeName).toBe('TR'); |
| 618 | expect(tr.getAttribute('tabindex')).toEqual('0'); |
| 619 | expect(tr.children[0].nodeName).toBe('TH'); |
| 620 | expect(tr.children[0].firstChild.nodeValue).toEqual('cnx'); |
| 621 | expect(tr.children[1].firstChild.nodeValue).toEqual('p'); |
| 622 | expect(tr.children[2].firstChild.nodeValue).toEqual('ADV'); |
| 623 | expect(tr.children[3].firstChild.nodeValue).toEqual('A'); |
Akron | 47774c4 | 2017-07-03 20:14:55 +0200 | [diff] [blame] | 624 | expect(tr.children[4].firstChild.firstChild.nodeValue).toEqual('A'); |
| 625 | expect(tr.children[4].lastChild.firstChild.nodeValue).toEqual('ADJA'); |
Akron | f2279c4 | 2017-12-21 13:48:46 +0100 | [diff] [blame] | 626 | |
| 627 | expect(tr.children[4].firstChild.getAttribute("title")).toEqual('Adjective'); |
| 628 | expect(tr.children[2].getAttribute("title")).toEqual('Adverb'); |
| 629 | |
Nils Diewald | 5814133 | 2015-04-07 16:18:45 +0000 | [diff] [blame] | 630 | }); |
| 631 | }); |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 632 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 633 | describe('KorAP.MatchTree', function () { |
| 634 | var tree; |
| 635 | var matchClass = require('match'); |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 636 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 637 | it('should be rendered async 1', function (done) { |
| 638 | var info = matchClass.create(match).info(); |
| 639 | expect(info).toBeTruthy(); |
Akron | 5b1a6af | 2018-02-05 15:41:16 +0100 | [diff] [blame] | 640 | info.getTreeData(undefined, undefined, "spans", function (y) { |
Akron | 671fdb9 | 2017-09-12 18:09:46 +0200 | [diff] [blame] | 641 | tree = y; |
| 642 | done(); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 643 | }); |
| 644 | }); |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 645 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 646 | it('should be rendered async 2', function () { |
| 647 | var e = tree.element(); |
| 648 | expect(e.nodeName).toEqual('svg'); |
| 649 | expect(e.getElementsByTagName('g').length).toEqual(48); |
Nils Diewald | 5814133 | 2015-04-07 16:18:45 +0000 | [diff] [blame] | 650 | }); |
| 651 | }); |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 652 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 653 | |
| 654 | describe('KorAP.MatchTreeItem', function () { |
| 655 | var matchTreeItemClass = require('match/treeitem'); |
| 656 | it('should be initializable', function () { |
| 657 | var mi = matchTreeItemClass.create(['cnx/c', 'cnx', 'c']) |
| 658 | expect(mi.element().firstChild.nodeValue).toEqual('cnx/c'); |
| 659 | expect(mi.lcField()).toEqual(' cnx/c'); |
| 660 | expect(mi.foundry()).toEqual('cnx'); |
| 661 | expect(mi.layer()).toEqual('c'); |
| 662 | }); |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 663 | }); |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 664 | |
| 665 | |
Akron | 671fdb9 | 2017-09-12 18:09:46 +0200 | [diff] [blame] | 666 | describe('KorAP.MatchRelation', function () { |
Akron | 41387d2 | 2018-02-02 18:10:06 +0100 | [diff] [blame] | 667 | var relClass = require('match/treearc') |
Akron | 671fdb9 | 2017-09-12 18:09:46 +0200 | [diff] [blame] | 668 | |
| 669 | var relExample = "<span class=\"context-left\"></span>" + |
| 670 | "<span class=\"match\">" + |
| 671 | " <span xml:id=\"token-GOE/AGA/01784-p199\">" + |
| 672 | " <span xlink:title=\"malt/d:ADV\" " + |
| 673 | " xlink:type=\"simple\" " + |
| 674 | " xlink:href=\"#token-GOE/AGA/01784-p199\">dann</span>" + |
| 675 | " </span>" + |
| 676 | " zog " + |
| 677 | " <span xlink:title=\"malt/d:SUBJ\" " + |
| 678 | " xlink:type=\"simple\" " + |
| 679 | " xlink:href=\"#token-GOE/AGA/01784-p199\">ich</span>" + |
| 680 | " <span xml:id=\"token-GOE/AGA/01784-p202\">" + |
| 681 | " <span xlink:title=\"malt/d:OBJA\" " + |
| 682 | " xlink:type=\"simple\" " + |
| 683 | " xlink:href=\"#token-GOE/AGA/01784-p199\">mich</span>" + |
| 684 | " </span>" + |
| 685 | "</span>" + |
| 686 | "<span class=\"context-right\"></span>"; |
| 687 | |
| 688 | |
| 689 | it('should be initializable', function () { |
| 690 | var tree = relClass.create(); |
| 691 | expect(tree.size()).toBe(0); |
| 692 | }); |
| 693 | |
| 694 | it('should be parse string data', function () { |
| 695 | var tree = relClass.create(relExample); |
| 696 | expect(tree.size()).toBe(4); |
| 697 | }); |
| 698 | |
| 699 | |
| 700 | }); |
| 701 | |
| 702 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 703 | describe('KorAP.MatchTreeMenu', function () { |
Akron | 52ed22d | 2018-07-11 17:05:19 +0200 | [diff] [blame] | 704 | var matchTreeMenu = require('buttongroup/menu'); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 705 | var matchTreeItem = require('match/treeitem'); |
| 706 | |
| 707 | it('should be initializable', function () { |
Akron | 5b1a6af | 2018-02-05 15:41:16 +0100 | [diff] [blame] | 708 | var menu = matchTreeMenu.create([ |
Akron | 671fdb9 | 2017-09-12 18:09:46 +0200 | [diff] [blame] | 709 | ['cnx/c', 'cnx', 'c'], |
| 710 | ['xip/c', 'xip', 'c'] |
Akron | 52ed22d | 2018-07-11 17:05:19 +0200 | [diff] [blame] | 711 | ], matchTreeItem); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 712 | |
| 713 | expect(menu.itemClass()).toEqual(matchTreeItem); |
| 714 | expect(menu.element().nodeName).toEqual('UL'); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 715 | expect(menu.element().classList.contains('visible')).toBeFalsy(); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 716 | expect(menu.limit()).toEqual(6); |
| 717 | menu.show(); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 718 | expect(menu.element().classList.contains('visible')).toBeTruthy(); |
Akron | c1457bf | 2015-06-11 19:24:00 +0200 | [diff] [blame] | 719 | expect(menu.item(0).active()).toBe(false); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 720 | }); |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 721 | }); |
hebasta | 999d6c1 | 2018-04-23 12:44:59 +0200 | [diff] [blame] | 722 | |
| 723 | //Test display and sorting of meta information |
| 724 | describe('KorAP.Meta', function(){ |
| 725 | |
| 726 | var metaClass = require("match/meta"); |
| 727 | var met = metaClass.create(match, fields); |
| 728 | var mel = met.element(); |
| 729 | |
| 730 | // Meta information should be parsed into a list |
| 731 | it('should parse in a meta view', function(){ |
| 732 | expect(mel.tagName).toEqual('DL'); |
| 733 | expect(mel.children[0].tagName).toEqual('DIV'); |
| 734 | expect(mel.children[0].children[0].tagName).toEqual('DT'); |
| 735 | expect(mel.children[0].children[0].attributes[0].name).toEqual('title'); |
| 736 | expect(mel.children[0].children[1].tagName).toEqual('DD'); |
| 737 | |
| 738 | expect(mel.children[0].children[0].firstChild.nodeValue).toEqual('author'); |
| 739 | expect(mel.children[0].children[1].firstChild.nodeValue).toEqual('Sprachpfleger, u.a.'); |
| 740 | expect(mel.children[0].children[0].attributes[0].value).toEqual('author'); |
| 741 | }); |
| 742 | |
| 743 | |
| 744 | /* The keywords in the meta information list should be formatted to be able |
| 745 | to chose each keyword separately in the corpusByMatch assistant. */ |
| 746 | it('keywords should be formatted', function(){ |
| 747 | |
| 748 | //type:string or type:keyword should b not relevant |
| 749 | expect(mel.children[1].children[1].classList.contains('metakeyvalues')).toBeTruthy; |
| 750 | expect(mel.children[1].children[1].children[0].tagName).toEqual('DIV'); |
| 751 | expect(mel.children[1].children[1].children[0].firstChild.nodeValue).toEqual('corenlp'); |
| 752 | expect(mel.children[1].children[1].children[1].tagName).toEqual('DIV'); |
| 753 | expect(mel.children[1].children[1].children[1].firstChild.nodeValue).toEqual('corenlp\/constituency'); |
| 754 | |
| 755 | expect(mel.children[2].children[1].classList.contains('metakeyvalues')).toBeTruthy; |
| 756 | expect(mel.children[2].children[1].children[0].tagName).toEqual('DIV'); |
| 757 | expect(mel.children[2].children[1].children[0].firstChild.nodeValue).toEqual('kultur'); |
| 758 | expect(mel.children[2].children[1].children[1].tagName).toEqual('DIV'); |
| 759 | expect(mel.children[2].children[1].children[1].firstChild.nodeValue).toEqual('film'); |
| 760 | }); |
| 761 | |
| 762 | |
| 763 | // Meta information should be sorted alphabetically |
| 764 | it('should be alphabetically sorted', function(){ |
| 765 | var a = mel.children[0].children[0].firstChild.nodeValue; |
| 766 | var b = mel.children[1].children[0].firstChild.nodeValue; |
| 767 | var c = mel.children[2].children[0].firstChild.nodeValue; |
| 768 | expect(a.localeCompare(b)).toBe(-1); |
| 769 | expect(b.localeCompare(c)).toBe(-1); |
| 770 | }); |
| 771 | |
| 772 | }); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 773 | // table = view.toTable(); |
| 774 | // table.sortBy(''); |
| 775 | // table.element(); |
| 776 | // tree = view.toTree(); |
| 777 | // tree.element(); |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 778 | }); |