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 | |
| 30 | var snippet = "<span title=\"cnx/l:meist\">" + |
| 31 | " <span title=\"cnx/p:ADV\">" + |
| 32 | " <span title=\"cnx/syn:@PREMOD\">" + |
| 33 | " <span title=\"mate/l:meist\">" + |
Akron | 916ec25 | 2016-11-10 17:06:32 +0100 | [diff] [blame] | 34 | " <span title=\"mate/l:meist\">" + |
| 35 | " <span title=\"mate/p:ADV\">" + |
| 36 | " <span title=\"opennlp/p:ADV\">meist</span>" + |
| 37 | " </span>" + |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 38 | " </span>" + |
| 39 | " </span>" + |
| 40 | " </span>" + |
| 41 | " </span>" + |
| 42 | "</span>" + |
| 43 | "<span title=\"cnx/l:deutlich\">" + |
| 44 | " <span title=\"cnx/p:A\">" + |
| 45 | " <span title=\"cnx/syn:@PREMOD\">" + |
| 46 | " <span title=\"mate/l:deutlich\">" + |
| 47 | " <span title=\"mate/m:degree:pos\">" + |
| 48 | " <span title=\"mate/p:ADJD\">" + |
| 49 | " <span title=\"opennlp/p:ADJD\">deutlich</span>" + |
| 50 | " </span>" + |
| 51 | " </span>" + |
| 52 | " </span>" + |
| 53 | " </span>" + |
| 54 | " </span>" + |
| 55 | "</span>" + |
| 56 | "<span title=\"cnx/l:fähig\">" + |
| 57 | " <span title=\"cnx/l:leistung\">" + |
| 58 | " <span title=\"cnx/p:A\">" + |
| 59 | " <span title=\"cnx/syn:@NH\">" + |
| 60 | " <span title=\"mate/l:leistungsfähig\">" + |
| 61 | " <span title=\"mate/m:degree:comp\">" + |
| 62 | " <span title=\"mate/p:ADJD\">" + |
| 63 | " <span title=\"opennlp/p:ADJD\">leistungsfähiger</span>" + |
| 64 | " </span>" + |
| 65 | " </span>" + |
| 66 | " </span>" + |
| 67 | " </span>" + |
| 68 | " </span>" + |
| 69 | " </span>" + |
| 70 | "</span>"; |
| 71 | |
| 72 | var treeSnippet = |
| 73 | "<span class=\"context-left\"></span>" + |
| 74 | "<span class=\"match\">" + |
| 75 | " <span title=\"xip/c:MC\">" + |
| 76 | " <span title=\"xip/c:TOP\">" + |
| 77 | " <span title=\"xip/c:PP\">" + |
| 78 | " <span title=\"xip/c:PREP\">Mit</span>" + |
| 79 | " <span title=\"xip/c:NP\">" + |
| 80 | " <span title=\"xip/c:DET\">dieser</span>" + |
| 81 | " <span title=\"xip/c:NPA\">" + |
| 82 | " <span title=\"xip/c:NOUN\">Methode</span>" + |
| 83 | " </span>" + |
| 84 | " </span>" + |
| 85 | " </span>" + |
| 86 | " <span title=\"xip/c:VERB\">ist</span>" + |
Akron | 98a933f | 2016-08-11 00:19:17 +0200 | [diff] [blame] | 87 | " <mark>" + |
| 88 | " <span title=\"xip/c:NP\">" + |
| 89 | " <span title=\"xip/c:PRON\">es</span>" + |
| 90 | " </span>" + |
| 91 | " <span title=\"xip/c:AP\">" + |
| 92 | " <span title=\"xip/c:ADV\">nun</span>" + |
| 93 | " <span title=\"xip/c:ADJ\">möglich</span>" + |
| 94 | " </span>" + |
| 95 | " </mark>" + |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 96 | " <span title=\"xip/c:ADV\">z. B.</span>" + |
| 97 | " <span title=\"xip/c:NPA\">" + |
| 98 | " <span title=\"xip/c:NP\">" + |
| 99 | " <span title=\"xip/c:NOUN\">Voice</span>" + |
| 100 | " </span>" + |
| 101 | " </span>" + "(" + |
| 102 | " <span title=\"xip/c:INS\">" + |
| 103 | " <span title=\"xip/c:NPA\">" + |
| 104 | " <span title=\"xip/c:NP\">" + |
| 105 | " <span title=\"xip/c:NOUN\">Sprache</span>" + |
| 106 | " </span>" + |
| 107 | " </span>" + |
| 108 | " </span>" + ")" + |
| 109 | " <span title=\"xip/c:VERB\">bevorzugt</span>" + |
| 110 | " <span title=\"xip/c:PP\">" + |
| 111 | " <span title=\"xip/c:PREP\">in</span>" + |
| 112 | " <span title=\"xip/c:NP\">" + |
| 113 | " <span title=\"xip/c:PRON\">der</span>" + |
| 114 | " </span>" + |
| 115 | " <span title=\"xip/c:NPA\">" + |
| 116 | " <span title=\"xip/c:NP\">" + |
| 117 | " <span title=\"xip/c:NOUN\">Bridge</span>" + |
| 118 | " </span>" + |
| 119 | " </span>" + |
| 120 | " </span>" + |
| 121 | " <span title=\"xip/c:INFC\">" + |
| 122 | " <span title=\"xip/c:INS\">" + |
| 123 | " <span title=\"xip/c:VERB\">weiterzugeben</span>" + |
| 124 | " </span>" + |
| 125 | " </span>" + |
| 126 | " </span>" + |
| 127 | " </span>" + |
| 128 | "</span>" + |
| 129 | "<span class=\"context-right\"></span>"; |
| 130 | |
| 131 | |
| 132 | function matchElementFactory () { |
| 133 | var me = document.createElement('li'); |
| 134 | |
| 135 | me.setAttribute( |
| 136 | 'data-available-info', |
| 137 | 'base/s=spans corenlp/c=spans corenlp/ne=tokens corenlp/p=tokens' + |
| 138 | ' corenlp/s=spans glemm/l=tokens mate/l=tokens mate/m=tokens' + |
| 139 | ' mate/p=tokens opennlp/p=tokens opennlp/s=spans tt/l=tokens' + |
| 140 | ' tt/p=tokens tt/s=spans'); |
| 141 | |
| 142 | me.setAttribute('data-corpus-id', 'WPD'); |
| 143 | me.setAttribute('data-doc-id', 'FFF'); |
| 144 | me.setAttribute('data-text-id', '01460'); |
Akron | 0a6768f | 2016-07-13 18:00:43 +0200 | [diff] [blame] | 145 | me.setAttribute('data-text-sigle', 'WPD/FFF/01460'); |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 146 | me.setAttribute('data-match-id', 'p119-120'); |
| 147 | me.innerHTML = '<div><div class="snippet">check</div></div><p class="ref">me</p>'; |
| 148 | return me; |
| 149 | }; |
| 150 | |
Akron | cdb0baa | 2016-11-07 01:52:11 +0100 | [diff] [blame] | 151 | function matchElementReal () { |
| 152 | var me = document.createElement('em'); |
| 153 | me.innerHTML = |
| 154 | '<li data-match-id="p85183-85184"' + |
| 155 | ' data-text-sigle="GOE/AGI/00000"' + |
| 156 | ' 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"' + |
| 157 | ' 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"}"' + |
| 158 | ' id="GOE/AGI/00000#p85183-85184">' + |
| 159 | '<div>' + |
| 160 | '<div class="flag"></div>' + |
| 161 | '<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>' + |
| 162 | '</div>' + |
| 163 | '<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>' + |
| 164 | '</li>'; |
| 165 | return me.firstChild; |
| 166 | }; |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 167 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 168 | define(['match'], function () { |
Nils Diewald | 5814133 | 2015-04-07 16:18:45 +0000 | [diff] [blame] | 169 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 170 | // Override getMatchInfo API call |
| 171 | KorAP.API.getMatchInfo = function (x, param, cb) { |
| 172 | if (param['spans'] === undefined || param['spans'] === false) |
| 173 | cb({ "snippet": snippet }); |
| 174 | else |
| 175 | cb({ "snippet": treeSnippet }); |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 176 | }; |
| 177 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 178 | describe('KorAP.InfoLayer', function () { |
| 179 | |
| 180 | var infoClass = require('match/infolayer'); |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 181 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 182 | it('should be initializable', function () { |
| 183 | expect( |
| 184 | function() { infoClass.create() } |
| 185 | ).toThrow(new Error("Missing parameters")); |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 186 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 187 | expect( |
| 188 | function() { infoClass.create("base") } |
| 189 | ).toThrow(new Error("Missing parameters")); |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 190 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 191 | var layer = infoClass.create("base", "s"); |
| 192 | expect(layer).toBeTruthy(); |
| 193 | expect(layer.foundry).toEqual("base"); |
| 194 | expect(layer.layer).toEqual("s"); |
| 195 | expect(layer.type).toEqual("tokens"); |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 196 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 197 | layer = infoClass.create("cnx", "syn", "spans"); |
| 198 | expect(layer).toBeTruthy(); |
| 199 | expect(layer.foundry).toEqual("cnx"); |
| 200 | expect(layer.layer).toEqual("syn"); |
| 201 | expect(layer.type).toEqual("spans"); |
Nils Diewald | 5814133 | 2015-04-07 16:18:45 +0000 | [diff] [blame] | 202 | }); |
| 203 | }); |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 204 | |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 205 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 206 | describe('KorAP.Match', function () { |
| 207 | var match = { |
| 208 | 'corpusID' : 'WPD', |
| 209 | 'docID' : 'UUU', |
| 210 | 'textID' : '01912', |
| 211 | 'matchID' : 'p121-122', |
Akron | 0a6768f | 2016-07-13 18:00:43 +0200 | [diff] [blame] | 212 | 'textSigle' : 'WPD/UUU/01912', |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 213 | 'available' : available |
| 214 | }; |
| 215 | |
| 216 | var matchClass = require('match'); |
| 217 | |
| 218 | it('should be initializable by Object', function () { |
| 219 | expect(function() { |
Akron | e4961b1 | 2017-05-10 21:04:46 +0200 | [diff] [blame] | 220 | matchClass.create() |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 221 | }).toThrow(new Error('Missing parameters')); |
| 222 | |
| 223 | expect(matchClass.create(match)).toBeTruthy(); |
| 224 | |
| 225 | var m = matchClass.create(match); |
Akron | 0a6768f | 2016-07-13 18:00:43 +0200 | [diff] [blame] | 226 | expect(m.textSigle).toEqual("WPD/UUU/01912"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 227 | expect(m.matchID).toEqual("p121-122"); |
| 228 | |
| 229 | // /corpus/WPD/UUU.01912/p121-122/matchInfo?spans=false&foundry=* |
| 230 | var m = matchClass.create(match); |
| 231 | |
| 232 | // Spans: |
| 233 | var spans = m.getSpans(); |
| 234 | expect(spans[0].foundry).toEqual("base"); |
| 235 | expect(spans[0].layer).toEqual("s"); |
| 236 | |
| 237 | expect(spans[1].foundry).toEqual("corenlp"); |
| 238 | expect(spans[1].layer).toEqual("c"); |
| 239 | |
| 240 | expect(spans[2].foundry).toEqual("corenlp"); |
| 241 | expect(spans[2].layer).toEqual("s"); |
| 242 | |
| 243 | expect(spans[spans.length-1].foundry).toEqual("tt"); |
| 244 | expect(spans[spans.length-1].layer).toEqual("s"); |
| 245 | |
| 246 | // Tokens: |
| 247 | var tokens = m.getTokens(); |
| 248 | expect(tokens[0].foundry).toEqual("corenlp"); |
| 249 | expect(tokens[0].layer).toEqual("ne"); |
| 250 | |
| 251 | expect(tokens[1].foundry).toEqual("corenlp"); |
| 252 | expect(tokens[1].layer).toEqual("p"); |
| 253 | |
| 254 | expect(tokens[tokens.length-1].foundry).toEqual("tt"); |
| 255 | expect(tokens[tokens.length-1].layer).toEqual("p"); |
Nils Diewald | 5814133 | 2015-04-07 16:18:45 +0000 | [diff] [blame] | 256 | }); |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 257 | |
| 258 | |
Akron | cdb0baa | 2016-11-07 01:52:11 +0100 | [diff] [blame] | 259 | it('should be initializable by Node 1', function () { |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 260 | var m = matchClass.create(matchElementFactory()); |
Akron | 0a6768f | 2016-07-13 18:00:43 +0200 | [diff] [blame] | 261 | expect(m.textSigle).toEqual("WPD/FFF/01460"); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 262 | expect(m.matchID).toEqual("p119-120"); |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 263 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 264 | // Spans: |
| 265 | var spans = m.getSpans(); |
| 266 | expect(spans[0].foundry).toEqual("base"); |
| 267 | expect(spans[0].layer).toEqual("s"); |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 268 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 269 | expect(spans[1].foundry).toEqual("corenlp"); |
| 270 | expect(spans[1].layer).toEqual("c"); |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 271 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 272 | expect(spans[2].foundry).toEqual("corenlp"); |
| 273 | expect(spans[2].layer).toEqual("s"); |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 274 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 275 | expect(spans[spans.length-1].foundry).toEqual("tt"); |
| 276 | expect(spans[spans.length-1].layer).toEqual("s"); |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 277 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 278 | // Tokens: |
| 279 | var tokens = m.getTokens(); |
| 280 | expect(tokens[0].foundry).toEqual("corenlp"); |
| 281 | expect(tokens[0].layer).toEqual("ne"); |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 282 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 283 | expect(tokens[1].foundry).toEqual("corenlp"); |
| 284 | expect(tokens[1].layer).toEqual("p"); |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 285 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 286 | expect(tokens[tokens.length-1].foundry).toEqual("tt"); |
| 287 | expect(tokens[tokens.length-1].layer).toEqual("p"); |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 288 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 289 | }); |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 290 | |
Akron | cdb0baa | 2016-11-07 01:52:11 +0100 | [diff] [blame] | 291 | it('should be initializable by Node 2', function () { |
| 292 | var ele = matchElementReal(); |
| 293 | var m = matchClass.create(ele); |
| 294 | expect(m.textSigle).toEqual("GOE/AGI/00000"); |
| 295 | expect(m.matchID).toEqual("p85183-85184"); |
| 296 | }); |
| 297 | |
| 298 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 299 | it('should react to gui actions', function () { |
| 300 | var e = matchElementFactory(); |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 301 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 302 | expect(e.classList.contains('active')).toBe(false); |
| 303 | expect(e["_match"]).toBe(undefined); |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 304 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 305 | var m = matchClass.create(e); |
| 306 | |
| 307 | expect(e.classList.contains('active')).toBe(false); |
| 308 | expect(e["_match"]).not.toBe(undefined); |
| 309 | |
| 310 | // Open the match |
| 311 | m.open(); |
| 312 | |
| 313 | expect(e.classList.contains('active')).toBe(true); |
| 314 | expect(e["_match"]).not.toBe(undefined); |
| 315 | |
| 316 | // Close the match |
| 317 | m.close(); |
| 318 | expect(e.classList.contains('active')).toBe(false); |
| 319 | expect(e["_match"]).not.toBe(undefined); |
| 320 | |
Nils Diewald | 5814133 | 2015-04-07 16:18:45 +0000 | [diff] [blame] | 321 | }); |
| 322 | }); |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 323 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 324 | |
| 325 | describe('KorAP.MatchInfo', function () { |
| 326 | |
| 327 | var matchClass = require('match'); |
| 328 | |
| 329 | var m = matchClass.create(match); |
| 330 | var info = m.info(); |
| 331 | |
| 332 | it('should contain a valid info', function () { |
| 333 | expect(m._info).toEqual(info); |
| 334 | }); |
| 335 | |
| 336 | var table1, table2; |
| 337 | |
| 338 | // Async preparation |
| 339 | it('should fail to load a table async', function (done) { |
| 340 | expect(info).toBeTruthy(); |
| 341 | |
| 342 | info.getTable([], function (tablen) { |
Akron | 916ec25 | 2016-11-10 17:06:32 +0100 | [diff] [blame] | 343 | table1 = tablen; |
| 344 | done(); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 345 | }); |
| 346 | }); |
| 347 | |
| 348 | it('should\'nt be parsable (async)', function () { |
| 349 | expect(table1).not.toBeTruthy(); |
| 350 | }); |
| 351 | |
| 352 | it('should load a working table async', function(done) { |
| 353 | expect(info).toBeTruthy(); |
| 354 | info.getTable(undefined, function (tablem) { |
Akron | 916ec25 | 2016-11-10 17:06:32 +0100 | [diff] [blame] | 355 | table2 = tablem; |
| 356 | done(); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 357 | }); |
| 358 | }); |
| 359 | |
| 360 | it('should parse into a table (async)', function () { |
| 361 | expect(table2).toBeTruthy(); |
| 362 | |
| 363 | expect(table2.length()).toBe(3); |
| 364 | |
| 365 | expect(table2.getToken(0)).toBe("meist"); |
| 366 | expect(table2.getToken(1)).toBe("deutlich"); |
| 367 | expect(table2.getToken(2)).toBe("leistungsfähiger"); |
| 368 | |
| 369 | expect(table2.getValue(0, "cnx", "p")[0]).toBe("ADV"); |
| 370 | expect(table2.getValue(0, "cnx", "syn")[0]).toBe("@PREMOD"); |
Akron | 916ec25 | 2016-11-10 17:06:32 +0100 | [diff] [blame] | 371 | expect(table2.getValue(0, "mate", "l")[0]).toBe("meist"); |
| 372 | expect(table2.getValue(0, "mate", "l")[1]).toBeUndefined(); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 373 | |
| 374 | expect(table2.getValue(2, "cnx", "l")[0]).toBe("fähig"); |
| 375 | expect(table2.getValue(2, "cnx", "l")[1]).toBe("leistung"); |
Akron | 916ec25 | 2016-11-10 17:06:32 +0100 | [diff] [blame] | 376 | |
| 377 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 378 | }); |
| 379 | |
| 380 | it('should parse into a table view', function () { |
| 381 | var matchElement = matchElementFactory(); |
| 382 | expect(matchElement.tagName).toEqual('LI'); |
| 383 | |
| 384 | // Match |
| 385 | expect(matchElement.children[0].tagName).toEqual('DIV'); |
| 386 | |
| 387 | // snippet |
| 388 | expect(matchElement.children[0].children[0].tagName).toEqual('DIV'); |
| 389 | expect(matchElement.children[0].children[0].classList.contains('snippet')).toBeTruthy(); |
| 390 | expect(matchElement.children[0].children[0].firstChild.nodeValue).toEqual('check'); |
| 391 | |
| 392 | // reference |
| 393 | expect(matchElement.children[1].classList.contains('ref')).toBeTruthy(); |
| 394 | expect(matchElement.children[1].firstChild.nodeValue).toEqual('me'); |
| 395 | |
| 396 | // not yet |
| 397 | expect(matchElement.children[0].children[1]).toBe(undefined); |
| 398 | |
| 399 | var info = matchClass.create(matchElement).info(); |
| 400 | info.toggle(); |
| 401 | |
| 402 | // Match |
| 403 | expect(matchElement.children[0].tagName).toEqual('DIV'); |
| 404 | |
| 405 | // snippet |
| 406 | expect(matchElement.children[0].children[0].tagName).toEqual('DIV'); |
| 407 | expect(matchElement.children[0].children[0].classList.contains('snippet')).toBeTruthy(); |
| 408 | expect(matchElement.children[0].children[0].firstChild.nodeValue).toEqual('check'); |
| 409 | |
| 410 | // reference |
| 411 | expect(matchElement.children[1].classList.contains('ref')).toBeTruthy(); |
| 412 | expect(matchElement.children[1].firstChild.nodeValue).toEqual('me'); |
| 413 | |
| 414 | // now |
Akron | aa7fce5 | 2017-06-30 21:15:18 +0200 | [diff] [blame] | 415 | var infotable = matchElement.children[2]; |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 416 | expect(infotable.tagName).toEqual('DIV'); |
Akron | aa7fce5 | 2017-06-30 21:15:18 +0200 | [diff] [blame] | 417 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 418 | expect(infotable.classList.contains('matchinfo')).toBeTruthy(); |
| 419 | |
| 420 | expect(infotable.children[0].classList.contains('matchtable')).toBeTruthy(); |
| 421 | expect(infotable.children[1].classList.contains('addtree')).toBeTruthy(); |
| 422 | }); |
| 423 | |
| 424 | var tree; |
| 425 | it('should parse into a tree (async) 1', function (done) { |
| 426 | var info = matchClass.create(match).info(); |
| 427 | expect(info).toBeTruthy(); |
| 428 | info.getTree(undefined, undefined, function (treem) { |
Akron | 98a933f | 2016-08-11 00:19:17 +0200 | [diff] [blame] | 429 | tree = treem; |
| 430 | done(); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 431 | }); |
| 432 | }); |
| 433 | |
| 434 | it('should parse into a tree (async) 2', function () { |
| 435 | expect(tree).toBeTruthy(); |
| 436 | expect(tree.nodes()).toEqual(49); |
| 437 | }); |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 438 | |
Akron | 98a933f | 2016-08-11 00:19:17 +0200 | [diff] [blame] | 439 | var matchElement, info; |
| 440 | // var info, matchElement; |
| 441 | it('should parse into a tree view', function () { |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 442 | matchElement = matchElementFactory(); |
| 443 | expect(matchElement.tagName).toEqual('LI'); |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 444 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 445 | info = matchClass.create(matchElement).info(); |
| 446 | info.toggle(); |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 447 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 448 | // Match |
| 449 | expect(matchElement.children[0].tagName).toEqual('DIV'); |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 450 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 451 | // snippet |
| 452 | expect(matchElement.children[0].children[0].tagName).toEqual('DIV'); |
| 453 | expect(matchElement.children[0].children[0].classList.contains('snippet')).toBeTruthy(); |
| 454 | expect(matchElement.children[0].children[0].firstChild.nodeValue).toEqual('check'); |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 455 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 456 | // reference |
| 457 | expect(matchElement.children[1].classList.contains('ref')).toBeTruthy(); |
| 458 | expect(matchElement.children[1].firstChild.nodeValue).toEqual('me'); |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 459 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 460 | // now |
Akron | aa7fce5 | 2017-06-30 21:15:18 +0200 | [diff] [blame] | 461 | var infotable = matchElement.children[2]; |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 462 | expect(infotable.tagName).toEqual('DIV'); |
| 463 | expect(infotable.classList.contains('matchinfo')).toBeTruthy(); |
| 464 | expect(infotable.children[0].classList.contains('matchtable')).toBeTruthy(); |
| 465 | expect(infotable.children[1].classList.contains('addtree')).toBeTruthy(); |
| 466 | }); |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 467 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 468 | it('should add a tree view async 1', function (done) { |
| 469 | expect(info).toBeTruthy(); |
| 470 | info.addTree('mate', 'beebop', function () { |
Akron | 98a933f | 2016-08-11 00:19:17 +0200 | [diff] [blame] | 471 | done(); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 472 | }); |
| 473 | }); |
| 474 | |
| 475 | it('should add a tree view async 2', function () { |
| 476 | // With added tree |
Akron | aa7fce5 | 2017-06-30 21:15:18 +0200 | [diff] [blame] | 477 | var infotable = matchElement.children[2]; |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 478 | expect(infotable.tagName).toEqual('DIV'); |
| 479 | expect(infotable.classList.contains('matchinfo')).toBeTruthy(); |
| 480 | expect(infotable.children[0].classList.contains('matchtable')).toBeTruthy(); |
| 481 | expect(infotable.children[1].classList.contains('addtree')).toBe(false); |
| 482 | |
| 483 | var tree = infotable.children[1]; |
| 484 | expect(tree.tagName).toEqual('DIV'); |
| 485 | expect(tree.classList.contains('matchtree')).toBeTruthy(); |
| 486 | expect(tree.children[0].tagName).toEqual('H6'); |
| 487 | expect(tree.children[0].children[0].tagName).toEqual('SPAN'); |
| 488 | expect(tree.children[0].children[0].firstChild.nodeValue).toEqual('mate'); |
| 489 | expect(tree.children[0].children[1].tagName).toEqual('SPAN'); |
| 490 | expect(tree.children[0].children[1].firstChild.nodeValue).toEqual('beebop'); |
| 491 | |
| 492 | expect(tree.children[1].tagName).toEqual('DIV'); |
Nils Diewald | 5814133 | 2015-04-07 16:18:45 +0000 | [diff] [blame] | 493 | }); |
| 494 | }); |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 495 | |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 496 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 497 | describe('KorAP.MatchTable', function () { |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 498 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 499 | var matchClass = require('match'); |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 500 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 501 | var table; |
| 502 | it('should be retrieved async', function (done) { |
| 503 | var info = matchClass.create(match).info(); |
| 504 | expect(info).toBeTruthy(); |
| 505 | info.getTable(undefined, function (x) { |
| 506 | table = x; |
| 507 | done(); |
| 508 | }); |
| 509 | }); |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 510 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 511 | it('should be rendered async', function () { |
| 512 | var e = table.element(); |
| 513 | |
| 514 | expect(e.nodeName).toBe('TABLE'); |
| 515 | expect(e.children[0].nodeName).toBe('THEAD'); |
| 516 | var tr = e.children[0].children[0]; |
| 517 | expect(tr.nodeName).toBe('TR'); |
| 518 | expect(tr.children[0].nodeName).toBe('TH'); |
Nils Diewald | 5814133 | 2015-04-07 16:18:45 +0000 | [diff] [blame] | 519 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 520 | expect(tr.children[0].firstChild.nodeValue).toBe('Foundry'); |
| 521 | expect(tr.children[1].firstChild.nodeValue).toBe('Layer'); |
| 522 | expect(tr.children[2].firstChild.nodeValue).toBe('meist'); |
| 523 | expect(tr.children[3].firstChild.nodeValue).toBe('deutlich'); |
| 524 | expect(tr.children[4].firstChild.nodeValue).toBe('leistungsfähiger'); |
| 525 | |
| 526 | // first row |
| 527 | tr = e.children[1].children[0]; |
| 528 | expect(tr.nodeName).toBe('TR'); |
| 529 | expect(tr.getAttribute('tabindex')).toEqual('0'); |
| 530 | expect(tr.children[0].nodeName).toBe('TH'); |
| 531 | expect(tr.children[0].firstChild.nodeValue).toEqual('cnx'); |
| 532 | expect(tr.children[1].firstChild.nodeValue).toEqual('l'); |
| 533 | expect(tr.children[2].firstChild.nodeValue).toEqual('meist'); |
| 534 | expect(tr.children[3].firstChild.nodeValue).toEqual('deutlich'); |
| 535 | expect(tr.children[4].firstChild.nodeValue).toEqual('fähig'); |
| 536 | expect(tr.children[4].lastChild.nodeValue).toEqual('leistung'); |
| 537 | |
| 538 | // second row |
| 539 | tr = e.children[1].children[1]; |
| 540 | expect(tr.nodeName).toBe('TR'); |
| 541 | expect(tr.getAttribute('tabindex')).toEqual('0'); |
| 542 | expect(tr.children[0].nodeName).toBe('TH'); |
| 543 | expect(tr.children[0].firstChild.nodeValue).toEqual('cnx'); |
| 544 | expect(tr.children[1].firstChild.nodeValue).toEqual('p'); |
| 545 | expect(tr.children[2].firstChild.nodeValue).toEqual('ADV'); |
| 546 | expect(tr.children[3].firstChild.nodeValue).toEqual('A'); |
| 547 | expect(tr.children[4].firstChild.nodeValue).toEqual('A'); |
Nils Diewald | 5814133 | 2015-04-07 16:18:45 +0000 | [diff] [blame] | 548 | }); |
| 549 | }); |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 550 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 551 | describe('KorAP.MatchTree', function () { |
| 552 | var tree; |
| 553 | var matchClass = require('match'); |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 554 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 555 | it('should be rendered async 1', function (done) { |
| 556 | var info = matchClass.create(match).info(); |
| 557 | expect(info).toBeTruthy(); |
| 558 | info.getTree(undefined, undefined, function (y) { |
| 559 | tree = y; |
| 560 | done(); |
| 561 | }); |
| 562 | }); |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 563 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 564 | it('should be rendered async 2', function () { |
| 565 | var e = tree.element(); |
| 566 | expect(e.nodeName).toEqual('svg'); |
| 567 | expect(e.getElementsByTagName('g').length).toEqual(48); |
Nils Diewald | 5814133 | 2015-04-07 16:18:45 +0000 | [diff] [blame] | 568 | }); |
| 569 | }); |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 570 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 571 | |
| 572 | describe('KorAP.MatchTreeItem', function () { |
| 573 | var matchTreeItemClass = require('match/treeitem'); |
| 574 | it('should be initializable', function () { |
| 575 | var mi = matchTreeItemClass.create(['cnx/c', 'cnx', 'c']) |
| 576 | expect(mi.element().firstChild.nodeValue).toEqual('cnx/c'); |
| 577 | expect(mi.lcField()).toEqual(' cnx/c'); |
| 578 | expect(mi.foundry()).toEqual('cnx'); |
| 579 | expect(mi.layer()).toEqual('c'); |
| 580 | }); |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 581 | }); |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 582 | |
| 583 | |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 584 | describe('KorAP.MatchTreeMenu', function () { |
| 585 | var matchTreeMenu = require('match/treemenu'); |
| 586 | var matchTreeItem = require('match/treeitem'); |
| 587 | |
| 588 | it('should be initializable', function () { |
| 589 | var menu = matchTreeMenu.create(undefined, [ |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 590 | ['cnx/c', 'cnx', 'c'], |
| 591 | ['xip/c', 'xip', 'c'] |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 592 | ]); |
| 593 | |
| 594 | expect(menu.itemClass()).toEqual(matchTreeItem); |
| 595 | expect(menu.element().nodeName).toEqual('UL'); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 596 | expect(menu.element().classList.contains('visible')).toBeFalsy(); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 597 | expect(menu.limit()).toEqual(6); |
| 598 | menu.show(); |
Akron | aba7a5a | 2016-08-15 21:58:33 +0200 | [diff] [blame] | 599 | expect(menu.element().classList.contains('visible')).toBeTruthy(); |
Akron | c1457bf | 2015-06-11 19:24:00 +0200 | [diff] [blame] | 600 | expect(menu.item(0).active()).toBe(false); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 601 | }); |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 602 | }); |
Nils Diewald | 7c8ced2 | 2015-04-15 19:21:00 +0000 | [diff] [blame] | 603 | |
| 604 | // table = view.toTable(); |
| 605 | // table.sortBy(''); |
| 606 | // table.element(); |
| 607 | // tree = view.toTree(); |
| 608 | // tree.element(); |
| 609 | |
Nils Diewald | a297f06 | 2015-04-02 00:23:46 +0000 | [diff] [blame] | 610 | }); |