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