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