blob: 09c8da7dc2a190447224328262041a51fa8b55c9 [file] [log] [blame]
Nils Diewald7c8ced22015-04-15 19:21:00 +00001// Regarding async:
2// http://stackoverflow.com/questions/16423156/getting-requirejs-to-work-with-jasmine
3
Nils Diewalda297f062015-04-02 00:23:46 +00004var 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
21var match = {
22 'corpusID' : 'WPD',
23 'docID' : 'UUU',
24 'textID' : '01912',
25 'matchID' : 'p121-122',
Akron0a6768f2016-07-13 18:00:43 +020026 'textSigle' : 'WPD/UUU/01912',
Nils Diewalda297f062015-04-02 00:23:46 +000027 'available' : available
28};
29
30var snippet = "<span title=\"cnx/l:meist\">" +
31 " <span title=\"cnx/p:ADV\">" +
32 " <span title=\"cnx/syn:@PREMOD\">" +
33 " <span title=\"mate/l:meist\">" +
Akron916ec252016-11-10 17:06:32 +010034 " <span title=\"mate/l:meist\">" +
35 " <span title=\"mate/p:ADV\">" +
36 " <span title=\"opennlp/p:ADV\">meist</span>" +
37 " </span>" +
Nils Diewalda297f062015-04-02 00:23:46 +000038 " </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
72var 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>" +
Akron98a933f2016-08-11 00:19:17 +020087 " <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 Diewalda297f062015-04-02 00:23:46 +000096 " <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
132function 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');
Akron0a6768f2016-07-13 18:00:43 +0200145 me.setAttribute('data-text-sigle', 'WPD/FFF/01460');
Nils Diewalda297f062015-04-02 00:23:46 +0000146 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
Akroncdb0baa2016-11-07 01:52:11 +0100151function 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="{&quot;UID&quot;:0,&quot;author&quot;:&quot;Goethe, Johann Wolfgang von&quot;,&quot;corpusID&quot;:null,&quot;corpusSigle&quot;:&quot;GOE&quot;,&quot;docID&quot;:null,&quot;docSigle&quot;:&quot;GOE\/AGI&quot;,&quot;layerInfos&quot;:&quot;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&quot;,&quot;matchID&quot;:&quot;match-GOE\/AGI\/00000-p85183-85184&quot;,&quot;pubDate&quot;:&quot;1982&quot;,&quot;pubPlace&quot;:&quot;München&quot;,&quot;subTitle&quot;:&quot;Auch ich in Arkadien!&quot;,&quot;textID&quot;:null,&quot;textSigle&quot;:&quot;GOE\/AGI\/00000&quot;,&quot;title&quot;:&quot;Italienische Reise&quot;}"' +
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 Diewalda297f062015-04-02 00:23:46 +0000167
Nils Diewald7c8ced22015-04-15 19:21:00 +0000168define(['match'], function () {
Nils Diewald58141332015-04-07 16:18:45 +0000169
Nils Diewald7c8ced22015-04-15 19:21:00 +0000170 // 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 Diewalda297f062015-04-02 00:23:46 +0000176 };
177
Nils Diewald7c8ced22015-04-15 19:21:00 +0000178 describe('KorAP.InfoLayer', function () {
179
180 var infoClass = require('match/infolayer');
Nils Diewalda297f062015-04-02 00:23:46 +0000181
Nils Diewald7c8ced22015-04-15 19:21:00 +0000182 it('should be initializable', function () {
183 expect(
184 function() { infoClass.create() }
185 ).toThrow(new Error("Missing parameters"));
Nils Diewalda297f062015-04-02 00:23:46 +0000186
Nils Diewald7c8ced22015-04-15 19:21:00 +0000187 expect(
188 function() { infoClass.create("base") }
189 ).toThrow(new Error("Missing parameters"));
Nils Diewalda297f062015-04-02 00:23:46 +0000190
Nils Diewald7c8ced22015-04-15 19:21:00 +0000191 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 Diewalda297f062015-04-02 00:23:46 +0000196
Nils Diewald7c8ced22015-04-15 19:21:00 +0000197 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 Diewald58141332015-04-07 16:18:45 +0000202 });
203 });
Nils Diewalda297f062015-04-02 00:23:46 +0000204
Nils Diewalda297f062015-04-02 00:23:46 +0000205
Nils Diewald7c8ced22015-04-15 19:21:00 +0000206 describe('KorAP.Match', function () {
207 var match = {
208 'corpusID' : 'WPD',
209 'docID' : 'UUU',
210 'textID' : '01912',
211 'matchID' : 'p121-122',
Akron0a6768f2016-07-13 18:00:43 +0200212 'textSigle' : 'WPD/UUU/01912',
Nils Diewald7c8ced22015-04-15 19:21:00 +0000213 'available' : available
214 };
215
216 var matchClass = require('match');
217
218 it('should be initializable by Object', function () {
219 expect(function() {
220 matchClass.create()
221 }).toThrow(new Error('Missing parameters'));
222
223 expect(matchClass.create(match)).toBeTruthy();
224
225 var m = matchClass.create(match);
Akron0a6768f2016-07-13 18:00:43 +0200226 expect(m.textSigle).toEqual("WPD/UUU/01912");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000227 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 Diewald58141332015-04-07 16:18:45 +0000256 });
Nils Diewalda297f062015-04-02 00:23:46 +0000257
258
Akroncdb0baa2016-11-07 01:52:11 +0100259 it('should be initializable by Node 1', function () {
Nils Diewald7c8ced22015-04-15 19:21:00 +0000260 var m = matchClass.create(matchElementFactory());
Akron0a6768f2016-07-13 18:00:43 +0200261 expect(m.textSigle).toEqual("WPD/FFF/01460");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000262 expect(m.matchID).toEqual("p119-120");
Nils Diewalda297f062015-04-02 00:23:46 +0000263
Nils Diewald7c8ced22015-04-15 19:21:00 +0000264 // Spans:
265 var spans = m.getSpans();
266 expect(spans[0].foundry).toEqual("base");
267 expect(spans[0].layer).toEqual("s");
Nils Diewalda297f062015-04-02 00:23:46 +0000268
Nils Diewald7c8ced22015-04-15 19:21:00 +0000269 expect(spans[1].foundry).toEqual("corenlp");
270 expect(spans[1].layer).toEqual("c");
Nils Diewalda297f062015-04-02 00:23:46 +0000271
Nils Diewald7c8ced22015-04-15 19:21:00 +0000272 expect(spans[2].foundry).toEqual("corenlp");
273 expect(spans[2].layer).toEqual("s");
Nils Diewalda297f062015-04-02 00:23:46 +0000274
Nils Diewald7c8ced22015-04-15 19:21:00 +0000275 expect(spans[spans.length-1].foundry).toEqual("tt");
276 expect(spans[spans.length-1].layer).toEqual("s");
Nils Diewalda297f062015-04-02 00:23:46 +0000277
Nils Diewald7c8ced22015-04-15 19:21:00 +0000278 // Tokens:
279 var tokens = m.getTokens();
280 expect(tokens[0].foundry).toEqual("corenlp");
281 expect(tokens[0].layer).toEqual("ne");
Nils Diewalda297f062015-04-02 00:23:46 +0000282
Nils Diewald7c8ced22015-04-15 19:21:00 +0000283 expect(tokens[1].foundry).toEqual("corenlp");
284 expect(tokens[1].layer).toEqual("p");
Nils Diewalda297f062015-04-02 00:23:46 +0000285
Nils Diewald7c8ced22015-04-15 19:21:00 +0000286 expect(tokens[tokens.length-1].foundry).toEqual("tt");
287 expect(tokens[tokens.length-1].layer).toEqual("p");
Nils Diewalda297f062015-04-02 00:23:46 +0000288
Nils Diewald7c8ced22015-04-15 19:21:00 +0000289 });
Nils Diewalda297f062015-04-02 00:23:46 +0000290
Akroncdb0baa2016-11-07 01:52:11 +0100291 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 Diewald7c8ced22015-04-15 19:21:00 +0000299 it('should react to gui actions', function () {
300 var e = matchElementFactory();
Nils Diewalda297f062015-04-02 00:23:46 +0000301
Nils Diewald7c8ced22015-04-15 19:21:00 +0000302 expect(e.classList.contains('active')).toBe(false);
303 expect(e["_match"]).toBe(undefined);
Nils Diewalda297f062015-04-02 00:23:46 +0000304
Nils Diewald7c8ced22015-04-15 19:21:00 +0000305 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 Diewald58141332015-04-07 16:18:45 +0000321 });
322 });
Nils Diewalda297f062015-04-02 00:23:46 +0000323
Nils Diewald7c8ced22015-04-15 19:21:00 +0000324
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) {
Akron916ec252016-11-10 17:06:32 +0100343 table1 = tablen;
344 done();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000345 });
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) {
Akron916ec252016-11-10 17:06:32 +0100355 table2 = tablem;
356 done();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000357 });
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");
Akron916ec252016-11-10 17:06:32 +0100371 expect(table2.getValue(0, "mate", "l")[0]).toBe("meist");
372 expect(table2.getValue(0, "mate", "l")[1]).toBeUndefined();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000373
374 expect(table2.getValue(2, "cnx", "l")[0]).toBe("fähig");
375 expect(table2.getValue(2, "cnx", "l")[1]).toBe("leistung");
Akron916ec252016-11-10 17:06:32 +0100376
377
Nils Diewald7c8ced22015-04-15 19:21:00 +0000378 });
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
415 var infotable = matchElement.children[0].children[1];
416 expect(infotable.tagName).toEqual('DIV');
417 expect(infotable.classList.contains('matchinfo')).toBeTruthy();
418
419 expect(infotable.children[0].classList.contains('matchtable')).toBeTruthy();
420 expect(infotable.children[1].classList.contains('addtree')).toBeTruthy();
421 });
422
423 var tree;
424 it('should parse into a tree (async) 1', function (done) {
425 var info = matchClass.create(match).info();
426 expect(info).toBeTruthy();
427 info.getTree(undefined, undefined, function (treem) {
Akron98a933f2016-08-11 00:19:17 +0200428 tree = treem;
429 done();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000430 });
431 });
432
433 it('should parse into a tree (async) 2', function () {
434 expect(tree).toBeTruthy();
435 expect(tree.nodes()).toEqual(49);
436 });
Nils Diewalda297f062015-04-02 00:23:46 +0000437
Akron98a933f2016-08-11 00:19:17 +0200438 var matchElement, info;
439 // var info, matchElement;
440 it('should parse into a tree view', function () {
Nils Diewald7c8ced22015-04-15 19:21:00 +0000441 matchElement = matchElementFactory();
442 expect(matchElement.tagName).toEqual('LI');
Nils Diewalda297f062015-04-02 00:23:46 +0000443
Nils Diewald7c8ced22015-04-15 19:21:00 +0000444 info = matchClass.create(matchElement).info();
445 info.toggle();
Nils Diewalda297f062015-04-02 00:23:46 +0000446
Nils Diewald7c8ced22015-04-15 19:21:00 +0000447 // Match
448 expect(matchElement.children[0].tagName).toEqual('DIV');
Nils Diewalda297f062015-04-02 00:23:46 +0000449
Nils Diewald7c8ced22015-04-15 19:21:00 +0000450 // snippet
451 expect(matchElement.children[0].children[0].tagName).toEqual('DIV');
452 expect(matchElement.children[0].children[0].classList.contains('snippet')).toBeTruthy();
453 expect(matchElement.children[0].children[0].firstChild.nodeValue).toEqual('check');
Nils Diewalda297f062015-04-02 00:23:46 +0000454
Nils Diewald7c8ced22015-04-15 19:21:00 +0000455 // reference
456 expect(matchElement.children[1].classList.contains('ref')).toBeTruthy();
457 expect(matchElement.children[1].firstChild.nodeValue).toEqual('me');
Nils Diewalda297f062015-04-02 00:23:46 +0000458
Nils Diewald7c8ced22015-04-15 19:21:00 +0000459 // now
460 var infotable = matchElement.children[0].children[1];
461 expect(infotable.tagName).toEqual('DIV');
462 expect(infotable.classList.contains('matchinfo')).toBeTruthy();
463 expect(infotable.children[0].classList.contains('matchtable')).toBeTruthy();
464 expect(infotable.children[1].classList.contains('addtree')).toBeTruthy();
465 });
Nils Diewalda297f062015-04-02 00:23:46 +0000466
Nils Diewald7c8ced22015-04-15 19:21:00 +0000467 it('should add a tree view async 1', function (done) {
468 expect(info).toBeTruthy();
469 info.addTree('mate', 'beebop', function () {
Akron98a933f2016-08-11 00:19:17 +0200470 done();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000471 });
472 });
473
474 it('should add a tree view async 2', function () {
475 // With added tree
476 var infotable = matchElement.children[0].children[1];
477 expect(infotable.tagName).toEqual('DIV');
478 expect(infotable.classList.contains('matchinfo')).toBeTruthy();
479 expect(infotable.children[0].classList.contains('matchtable')).toBeTruthy();
480 expect(infotable.children[1].classList.contains('addtree')).toBe(false);
481
482 var tree = infotable.children[1];
483 expect(tree.tagName).toEqual('DIV');
484 expect(tree.classList.contains('matchtree')).toBeTruthy();
485 expect(tree.children[0].tagName).toEqual('H6');
486 expect(tree.children[0].children[0].tagName).toEqual('SPAN');
487 expect(tree.children[0].children[0].firstChild.nodeValue).toEqual('mate');
488 expect(tree.children[0].children[1].tagName).toEqual('SPAN');
489 expect(tree.children[0].children[1].firstChild.nodeValue).toEqual('beebop');
490
491 expect(tree.children[1].tagName).toEqual('DIV');
Nils Diewald58141332015-04-07 16:18:45 +0000492 });
493 });
Nils Diewalda297f062015-04-02 00:23:46 +0000494
Nils Diewalda297f062015-04-02 00:23:46 +0000495
Nils Diewald7c8ced22015-04-15 19:21:00 +0000496 describe('KorAP.MatchTable', function () {
Nils Diewalda297f062015-04-02 00:23:46 +0000497
Nils Diewald7c8ced22015-04-15 19:21:00 +0000498 var matchClass = require('match');
Nils Diewalda297f062015-04-02 00:23:46 +0000499
Nils Diewald7c8ced22015-04-15 19:21:00 +0000500 var table;
501 it('should be retrieved async', function (done) {
502 var info = matchClass.create(match).info();
503 expect(info).toBeTruthy();
504 info.getTable(undefined, function (x) {
505 table = x;
506 done();
507 });
508 });
Nils Diewalda297f062015-04-02 00:23:46 +0000509
Nils Diewald7c8ced22015-04-15 19:21:00 +0000510 it('should be rendered async', function () {
511 var e = table.element();
512
513 expect(e.nodeName).toBe('TABLE');
514 expect(e.children[0].nodeName).toBe('THEAD');
515 var tr = e.children[0].children[0];
516 expect(tr.nodeName).toBe('TR');
517 expect(tr.children[0].nodeName).toBe('TH');
Nils Diewald58141332015-04-07 16:18:45 +0000518
Nils Diewald7c8ced22015-04-15 19:21:00 +0000519 expect(tr.children[0].firstChild.nodeValue).toBe('Foundry');
520 expect(tr.children[1].firstChild.nodeValue).toBe('Layer');
521 expect(tr.children[2].firstChild.nodeValue).toBe('meist');
522 expect(tr.children[3].firstChild.nodeValue).toBe('deutlich');
523 expect(tr.children[4].firstChild.nodeValue).toBe('leistungsfähiger');
524
525 // first row
526 tr = e.children[1].children[0];
527 expect(tr.nodeName).toBe('TR');
528 expect(tr.getAttribute('tabindex')).toEqual('0');
529 expect(tr.children[0].nodeName).toBe('TH');
530 expect(tr.children[0].firstChild.nodeValue).toEqual('cnx');
531 expect(tr.children[1].firstChild.nodeValue).toEqual('l');
532 expect(tr.children[2].firstChild.nodeValue).toEqual('meist');
533 expect(tr.children[3].firstChild.nodeValue).toEqual('deutlich');
534 expect(tr.children[4].firstChild.nodeValue).toEqual('fähig');
535 expect(tr.children[4].lastChild.nodeValue).toEqual('leistung');
536
537 // second row
538 tr = e.children[1].children[1];
539 expect(tr.nodeName).toBe('TR');
540 expect(tr.getAttribute('tabindex')).toEqual('0');
541 expect(tr.children[0].nodeName).toBe('TH');
542 expect(tr.children[0].firstChild.nodeValue).toEqual('cnx');
543 expect(tr.children[1].firstChild.nodeValue).toEqual('p');
544 expect(tr.children[2].firstChild.nodeValue).toEqual('ADV');
545 expect(tr.children[3].firstChild.nodeValue).toEqual('A');
546 expect(tr.children[4].firstChild.nodeValue).toEqual('A');
Nils Diewald58141332015-04-07 16:18:45 +0000547 });
548 });
Nils Diewalda297f062015-04-02 00:23:46 +0000549
Nils Diewald7c8ced22015-04-15 19:21:00 +0000550 describe('KorAP.MatchTree', function () {
551 var tree;
552 var matchClass = require('match');
Nils Diewalda297f062015-04-02 00:23:46 +0000553
Nils Diewald7c8ced22015-04-15 19:21:00 +0000554 it('should be rendered async 1', function (done) {
555 var info = matchClass.create(match).info();
556 expect(info).toBeTruthy();
557 info.getTree(undefined, undefined, function (y) {
558 tree = y;
559 done();
560 });
561 });
Nils Diewalda297f062015-04-02 00:23:46 +0000562
Nils Diewald7c8ced22015-04-15 19:21:00 +0000563 it('should be rendered async 2', function () {
564 var e = tree.element();
565 expect(e.nodeName).toEqual('svg');
566 expect(e.getElementsByTagName('g').length).toEqual(48);
Nils Diewald58141332015-04-07 16:18:45 +0000567 });
568 });
Nils Diewalda297f062015-04-02 00:23:46 +0000569
Nils Diewald7c8ced22015-04-15 19:21:00 +0000570
571 describe('KorAP.MatchTreeItem', function () {
572 var matchTreeItemClass = require('match/treeitem');
573 it('should be initializable', function () {
574 var mi = matchTreeItemClass.create(['cnx/c', 'cnx', 'c'])
575 expect(mi.element().firstChild.nodeValue).toEqual('cnx/c');
576 expect(mi.lcField()).toEqual(' cnx/c');
577 expect(mi.foundry()).toEqual('cnx');
578 expect(mi.layer()).toEqual('c');
579 });
Nils Diewalda297f062015-04-02 00:23:46 +0000580 });
Nils Diewalda297f062015-04-02 00:23:46 +0000581
582
Nils Diewald7c8ced22015-04-15 19:21:00 +0000583 describe('KorAP.MatchTreeMenu', function () {
584 var matchTreeMenu = require('match/treemenu');
585 var matchTreeItem = require('match/treeitem');
586
587 it('should be initializable', function () {
588 var menu = matchTreeMenu.create(undefined, [
Akronaba7a5a2016-08-15 21:58:33 +0200589 ['cnx/c', 'cnx', 'c'],
590 ['xip/c', 'xip', 'c']
Nils Diewald7c8ced22015-04-15 19:21:00 +0000591 ]);
592
593 expect(menu.itemClass()).toEqual(matchTreeItem);
594 expect(menu.element().nodeName).toEqual('UL');
Akronaba7a5a2016-08-15 21:58:33 +0200595 expect(menu.element().classList.contains('visible')).toBeFalsy();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000596 expect(menu.limit()).toEqual(6);
597 menu.show();
Akronaba7a5a2016-08-15 21:58:33 +0200598 expect(menu.element().classList.contains('visible')).toBeTruthy();
Akronc1457bf2015-06-11 19:24:00 +0200599 expect(menu.item(0).active()).toBe(false);
Nils Diewald7c8ced22015-04-15 19:21:00 +0000600 });
Nils Diewalda297f062015-04-02 00:23:46 +0000601 });
Nils Diewald7c8ced22015-04-15 19:21:00 +0000602
603 // table = view.toTable();
604 // table.sortBy('');
605 // table.element();
606 // tree = view.toTree();
607 // tree.element();
608
Nils Diewalda297f062015-04-02 00:23:46 +0000609});