blob: dc2186d48f6c02aba22d8cf2805f213c5740ca6b [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\">" +
Akron4e47d0b2017-07-03 17:58:37 +020031 " <span title=\"cnx/p:ADV\">" +
32 " <span title=\"cnx/syn:@PREMOD\">" +
33 " <span title=\"mate/l:meist\">" +
34 " <span title=\"mate/l:meist\">" +
35 " <span title=\"mate/p:ADV\">" +
36 " <span title=\"opennlp/p:ADV\">meist</span>" +
37 " </span>" +
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/p:ADJA\">" +
60 " <span title=\"cnx/syn:@NH\">" +
61 " <span title=\"mate/l:leistungsfähig\">" +
62 " <span title=\"mate/m:degree:comp\">" +
63 " <span title=\"mate/p:ADJD\">" +
64 " <span title=\"opennlp/p:ADJD\">leistungsfähiger</span>" +
65 " </span>" +
66 " </span>" +
67 " </span>" +
68 " </span>" +
69 " </span>" +
70 " </span>" +
71 " </span>" +
72 "</span>";
Nils Diewalda297f062015-04-02 00:23:46 +000073
74var treeSnippet =
75 "<span class=\"context-left\"></span>" +
76 "<span class=\"match\">" +
77 " <span title=\"xip/c:MC\">" +
78 " <span title=\"xip/c:TOP\">" +
79 " <span title=\"xip/c:PP\">" +
80 " <span title=\"xip/c:PREP\">Mit</span>" +
81 " <span title=\"xip/c:NP\">" +
82 " <span title=\"xip/c:DET\">dieser</span>" +
83 " <span title=\"xip/c:NPA\">" +
84 " <span title=\"xip/c:NOUN\">Methode</span>" +
85 " </span>" +
86 " </span>" +
87 " </span>" +
88 " <span title=\"xip/c:VERB\">ist</span>" +
Akron98a933f2016-08-11 00:19:17 +020089 " <mark>" +
90 " <span title=\"xip/c:NP\">" +
91 " <span title=\"xip/c:PRON\">es</span>" +
92 " </span>" +
93 " <span title=\"xip/c:AP\">" +
94 " <span title=\"xip/c:ADV\">nun</span>" +
95 " <span title=\"xip/c:ADJ\">möglich</span>" +
96 " </span>" +
97 " </mark>" +
Nils Diewalda297f062015-04-02 00:23:46 +000098 " <span title=\"xip/c:ADV\">z. B.</span>" +
99 " <span title=\"xip/c:NPA\">" +
100 " <span title=\"xip/c:NP\">" +
101 " <span title=\"xip/c:NOUN\">Voice</span>" +
102 " </span>" +
103 " </span>" + "(" +
104 " <span title=\"xip/c:INS\">" +
105 " <span title=\"xip/c:NPA\">" +
106 " <span title=\"xip/c:NP\">" +
107 " <span title=\"xip/c:NOUN\">Sprache</span>" +
108 " </span>" +
109 " </span>" +
110 " </span>" + ")" +
111 " <span title=\"xip/c:VERB\">bevorzugt</span>" +
112 " <span title=\"xip/c:PP\">" +
113 " <span title=\"xip/c:PREP\">in</span>" +
114 " <span title=\"xip/c:NP\">" +
115 " <span title=\"xip/c:PRON\">der</span>" +
116 " </span>" +
117 " <span title=\"xip/c:NPA\">" +
118 " <span title=\"xip/c:NP\">" +
119 " <span title=\"xip/c:NOUN\">Bridge</span>" +
120 " </span>" +
121 " </span>" +
122 " </span>" +
123 " <span title=\"xip/c:INFC\">" +
124 " <span title=\"xip/c:INS\">" +
125 " <span title=\"xip/c:VERB\">weiterzugeben</span>" +
126 " </span>" +
127 " </span>" +
128 " </span>" +
129 " </span>" +
130 "</span>" +
131 "<span class=\"context-right\"></span>";
132
133
134function matchElementFactory () {
135 var me = document.createElement('li');
136
137 me.setAttribute(
138 'data-available-info',
139 'base/s=spans corenlp/c=spans corenlp/ne=tokens corenlp/p=tokens' +
140 ' corenlp/s=spans glemm/l=tokens mate/l=tokens mate/m=tokens' +
141 ' mate/p=tokens opennlp/p=tokens opennlp/s=spans tt/l=tokens' +
142 ' tt/p=tokens tt/s=spans');
143
144 me.setAttribute('data-corpus-id', 'WPD');
145 me.setAttribute('data-doc-id', 'FFF');
146 me.setAttribute('data-text-id', '01460');
Akron0a6768f2016-07-13 18:00:43 +0200147 me.setAttribute('data-text-sigle', 'WPD/FFF/01460');
Nils Diewalda297f062015-04-02 00:23:46 +0000148 me.setAttribute('data-match-id', 'p119-120');
149 me.innerHTML = '<div><div class="snippet">check</div></div><p class="ref">me</p>';
150 return me;
151};
152
Akroncdb0baa2016-11-07 01:52:11 +0100153function matchElementReal () {
154 var me = document.createElement('em');
155 me.innerHTML =
156 '<li data-match-id="p85183-85184"' +
157 ' data-text-sigle="GOE/AGI/00000"' +
158 ' 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"' +
159 ' 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;}"' +
160 ' id="GOE/AGI/00000#p85183-85184">' +
161 '<div>' +
162 '<div class="flag"></div>' +
163 '<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>' +
164 '</div>' +
165 '<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>' +
166 '</li>';
167 return me.firstChild;
168};
Nils Diewalda297f062015-04-02 00:23:46 +0000169
Nils Diewald7c8ced22015-04-15 19:21:00 +0000170define(['match'], function () {
Nils Diewald58141332015-04-07 16:18:45 +0000171
Nils Diewald7c8ced22015-04-15 19:21:00 +0000172 // Override getMatchInfo API call
173 KorAP.API.getMatchInfo = function (x, param, cb) {
174 if (param['spans'] === undefined || param['spans'] === false)
175 cb({ "snippet": snippet });
176 else
177 cb({ "snippet": treeSnippet });
Nils Diewalda297f062015-04-02 00:23:46 +0000178 };
179
Nils Diewald7c8ced22015-04-15 19:21:00 +0000180 describe('KorAP.InfoLayer', function () {
181
182 var infoClass = require('match/infolayer');
Nils Diewalda297f062015-04-02 00:23:46 +0000183
Nils Diewald7c8ced22015-04-15 19:21:00 +0000184 it('should be initializable', function () {
185 expect(
186 function() { infoClass.create() }
187 ).toThrow(new Error("Missing parameters"));
Nils Diewalda297f062015-04-02 00:23:46 +0000188
Nils Diewald7c8ced22015-04-15 19:21:00 +0000189 expect(
190 function() { infoClass.create("base") }
191 ).toThrow(new Error("Missing parameters"));
Nils Diewalda297f062015-04-02 00:23:46 +0000192
Nils Diewald7c8ced22015-04-15 19:21:00 +0000193 var layer = infoClass.create("base", "s");
194 expect(layer).toBeTruthy();
195 expect(layer.foundry).toEqual("base");
196 expect(layer.layer).toEqual("s");
197 expect(layer.type).toEqual("tokens");
Nils Diewalda297f062015-04-02 00:23:46 +0000198
Nils Diewald7c8ced22015-04-15 19:21:00 +0000199 layer = infoClass.create("cnx", "syn", "spans");
200 expect(layer).toBeTruthy();
201 expect(layer.foundry).toEqual("cnx");
202 expect(layer.layer).toEqual("syn");
203 expect(layer.type).toEqual("spans");
Nils Diewald58141332015-04-07 16:18:45 +0000204 });
205 });
Nils Diewalda297f062015-04-02 00:23:46 +0000206
Nils Diewalda297f062015-04-02 00:23:46 +0000207
Nils Diewald7c8ced22015-04-15 19:21:00 +0000208 describe('KorAP.Match', function () {
209 var match = {
210 'corpusID' : 'WPD',
211 'docID' : 'UUU',
212 'textID' : '01912',
213 'matchID' : 'p121-122',
Akron0a6768f2016-07-13 18:00:43 +0200214 'textSigle' : 'WPD/UUU/01912',
Nils Diewald7c8ced22015-04-15 19:21:00 +0000215 'available' : available
216 };
217
218 var matchClass = require('match');
219
220 it('should be initializable by Object', function () {
221 expect(function() {
Akrone4961b12017-05-10 21:04:46 +0200222 matchClass.create()
Nils Diewald7c8ced22015-04-15 19:21:00 +0000223 }).toThrow(new Error('Missing parameters'));
224
225 expect(matchClass.create(match)).toBeTruthy();
226
227 var m = matchClass.create(match);
Akron0a6768f2016-07-13 18:00:43 +0200228 expect(m.textSigle).toEqual("WPD/UUU/01912");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000229 expect(m.matchID).toEqual("p121-122");
230
231 // /corpus/WPD/UUU.01912/p121-122/matchInfo?spans=false&foundry=*
232 var m = matchClass.create(match);
233
234 // Spans:
235 var spans = m.getSpans();
236 expect(spans[0].foundry).toEqual("base");
237 expect(spans[0].layer).toEqual("s");
238
239 expect(spans[1].foundry).toEqual("corenlp");
240 expect(spans[1].layer).toEqual("c");
241
242 expect(spans[2].foundry).toEqual("corenlp");
243 expect(spans[2].layer).toEqual("s");
244
245 expect(spans[spans.length-1].foundry).toEqual("tt");
246 expect(spans[spans.length-1].layer).toEqual("s");
247
248 // Tokens:
249 var tokens = m.getTokens();
250 expect(tokens[0].foundry).toEqual("corenlp");
251 expect(tokens[0].layer).toEqual("ne");
252
253 expect(tokens[1].foundry).toEqual("corenlp");
254 expect(tokens[1].layer).toEqual("p");
255
256 expect(tokens[tokens.length-1].foundry).toEqual("tt");
257 expect(tokens[tokens.length-1].layer).toEqual("p");
Nils Diewald58141332015-04-07 16:18:45 +0000258 });
Nils Diewalda297f062015-04-02 00:23:46 +0000259
260
Akroncdb0baa2016-11-07 01:52:11 +0100261 it('should be initializable by Node 1', function () {
Nils Diewald7c8ced22015-04-15 19:21:00 +0000262 var m = matchClass.create(matchElementFactory());
Akron0a6768f2016-07-13 18:00:43 +0200263 expect(m.textSigle).toEqual("WPD/FFF/01460");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000264 expect(m.matchID).toEqual("p119-120");
Nils Diewalda297f062015-04-02 00:23:46 +0000265
Nils Diewald7c8ced22015-04-15 19:21:00 +0000266 // Spans:
267 var spans = m.getSpans();
268 expect(spans[0].foundry).toEqual("base");
269 expect(spans[0].layer).toEqual("s");
Nils Diewalda297f062015-04-02 00:23:46 +0000270
Nils Diewald7c8ced22015-04-15 19:21:00 +0000271 expect(spans[1].foundry).toEqual("corenlp");
272 expect(spans[1].layer).toEqual("c");
Nils Diewalda297f062015-04-02 00:23:46 +0000273
Nils Diewald7c8ced22015-04-15 19:21:00 +0000274 expect(spans[2].foundry).toEqual("corenlp");
275 expect(spans[2].layer).toEqual("s");
Nils Diewalda297f062015-04-02 00:23:46 +0000276
Nils Diewald7c8ced22015-04-15 19:21:00 +0000277 expect(spans[spans.length-1].foundry).toEqual("tt");
278 expect(spans[spans.length-1].layer).toEqual("s");
Nils Diewalda297f062015-04-02 00:23:46 +0000279
Nils Diewald7c8ced22015-04-15 19:21:00 +0000280 // Tokens:
281 var tokens = m.getTokens();
282 expect(tokens[0].foundry).toEqual("corenlp");
283 expect(tokens[0].layer).toEqual("ne");
Nils Diewalda297f062015-04-02 00:23:46 +0000284
Nils Diewald7c8ced22015-04-15 19:21:00 +0000285 expect(tokens[1].foundry).toEqual("corenlp");
286 expect(tokens[1].layer).toEqual("p");
Nils Diewalda297f062015-04-02 00:23:46 +0000287
Nils Diewald7c8ced22015-04-15 19:21:00 +0000288 expect(tokens[tokens.length-1].foundry).toEqual("tt");
289 expect(tokens[tokens.length-1].layer).toEqual("p");
Nils Diewalda297f062015-04-02 00:23:46 +0000290
Nils Diewald7c8ced22015-04-15 19:21:00 +0000291 });
Nils Diewalda297f062015-04-02 00:23:46 +0000292
Akroncdb0baa2016-11-07 01:52:11 +0100293 it('should be initializable by Node 2', function () {
294 var ele = matchElementReal();
295 var m = matchClass.create(ele);
296 expect(m.textSigle).toEqual("GOE/AGI/00000");
297 expect(m.matchID).toEqual("p85183-85184");
298 });
299
300
Nils Diewald7c8ced22015-04-15 19:21:00 +0000301 it('should react to gui actions', function () {
302 var e = matchElementFactory();
Nils Diewalda297f062015-04-02 00:23:46 +0000303
Nils Diewald7c8ced22015-04-15 19:21:00 +0000304 expect(e.classList.contains('active')).toBe(false);
305 expect(e["_match"]).toBe(undefined);
Nils Diewalda297f062015-04-02 00:23:46 +0000306
Nils Diewald7c8ced22015-04-15 19:21:00 +0000307 var m = matchClass.create(e);
308
309 expect(e.classList.contains('active')).toBe(false);
310 expect(e["_match"]).not.toBe(undefined);
311
312 // Open the match
313 m.open();
314
315 expect(e.classList.contains('active')).toBe(true);
316 expect(e["_match"]).not.toBe(undefined);
317
318 // Close the match
319 m.close();
320 expect(e.classList.contains('active')).toBe(false);
321 expect(e["_match"]).not.toBe(undefined);
322
Nils Diewald58141332015-04-07 16:18:45 +0000323 });
324 });
Nils Diewalda297f062015-04-02 00:23:46 +0000325
Nils Diewald7c8ced22015-04-15 19:21:00 +0000326
327 describe('KorAP.MatchInfo', function () {
328
329 var matchClass = require('match');
330
331 var m = matchClass.create(match);
332 var info = m.info();
333
334 it('should contain a valid info', function () {
335 expect(m._info).toEqual(info);
336 });
337
338 var table1, table2;
339
340 // Async preparation
341 it('should fail to load a table async', function (done) {
342 expect(info).toBeTruthy();
343
344 info.getTable([], function (tablen) {
Akron916ec252016-11-10 17:06:32 +0100345 table1 = tablen;
346 done();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000347 });
348 });
349
350 it('should\'nt be parsable (async)', function () {
351 expect(table1).not.toBeTruthy();
352 });
353
354 it('should load a working table async', function(done) {
355 expect(info).toBeTruthy();
356 info.getTable(undefined, function (tablem) {
Akron916ec252016-11-10 17:06:32 +0100357 table2 = tablem;
358 done();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000359 });
360 });
361
362 it('should parse into a table (async)', function () {
363 expect(table2).toBeTruthy();
364
365 expect(table2.length()).toBe(3);
366
367 expect(table2.getToken(0)).toBe("meist");
368 expect(table2.getToken(1)).toBe("deutlich");
369 expect(table2.getToken(2)).toBe("leistungsfähiger");
370
371 expect(table2.getValue(0, "cnx", "p")[0]).toBe("ADV");
372 expect(table2.getValue(0, "cnx", "syn")[0]).toBe("@PREMOD");
Akron916ec252016-11-10 17:06:32 +0100373 expect(table2.getValue(0, "mate", "l")[0]).toBe("meist");
374 expect(table2.getValue(0, "mate", "l")[1]).toBeUndefined();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000375
376 expect(table2.getValue(2, "cnx", "l")[0]).toBe("fähig");
377 expect(table2.getValue(2, "cnx", "l")[1]).toBe("leistung");
Akron916ec252016-11-10 17:06:32 +0100378
379
Nils Diewald7c8ced22015-04-15 19:21:00 +0000380 });
381
382 it('should parse into a table view', function () {
383 var matchElement = matchElementFactory();
384 expect(matchElement.tagName).toEqual('LI');
385
386 // Match
387 expect(matchElement.children[0].tagName).toEqual('DIV');
388
389 // snippet
390 expect(matchElement.children[0].children[0].tagName).toEqual('DIV');
391 expect(matchElement.children[0].children[0].classList.contains('snippet')).toBeTruthy();
392 expect(matchElement.children[0].children[0].firstChild.nodeValue).toEqual('check');
393
394 // reference
395 expect(matchElement.children[1].classList.contains('ref')).toBeTruthy();
396 expect(matchElement.children[1].firstChild.nodeValue).toEqual('me');
397
398 // not yet
399 expect(matchElement.children[0].children[1]).toBe(undefined);
400
401 var info = matchClass.create(matchElement).info();
402 info.toggle();
403
404 // Match
405 expect(matchElement.children[0].tagName).toEqual('DIV');
406
407 // snippet
408 expect(matchElement.children[0].children[0].tagName).toEqual('DIV');
409 expect(matchElement.children[0].children[0].classList.contains('snippet')).toBeTruthy();
410 expect(matchElement.children[0].children[0].firstChild.nodeValue).toEqual('check');
411
412 // reference
413 expect(matchElement.children[1].classList.contains('ref')).toBeTruthy();
414 expect(matchElement.children[1].firstChild.nodeValue).toEqual('me');
415
416 // now
Akronaa7fce52017-06-30 21:15:18 +0200417 var infotable = matchElement.children[2];
Nils Diewald7c8ced22015-04-15 19:21:00 +0000418 expect(infotable.tagName).toEqual('DIV');
Akronaa7fce52017-06-30 21:15:18 +0200419
Nils Diewald7c8ced22015-04-15 19:21:00 +0000420 expect(infotable.classList.contains('matchinfo')).toBeTruthy();
421
422 expect(infotable.children[0].classList.contains('matchtable')).toBeTruthy();
423 expect(infotable.children[1].classList.contains('addtree')).toBeTruthy();
424 });
425
426 var tree;
427 it('should parse into a tree (async) 1', function (done) {
428 var info = matchClass.create(match).info();
429 expect(info).toBeTruthy();
430 info.getTree(undefined, undefined, function (treem) {
Akron98a933f2016-08-11 00:19:17 +0200431 tree = treem;
432 done();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000433 });
434 });
435
436 it('should parse into a tree (async) 2', function () {
437 expect(tree).toBeTruthy();
438 expect(tree.nodes()).toEqual(49);
439 });
Nils Diewalda297f062015-04-02 00:23:46 +0000440
Akron98a933f2016-08-11 00:19:17 +0200441 var matchElement, info;
442 // var info, matchElement;
443 it('should parse into a tree view', function () {
Nils Diewald7c8ced22015-04-15 19:21:00 +0000444 matchElement = matchElementFactory();
445 expect(matchElement.tagName).toEqual('LI');
Nils Diewalda297f062015-04-02 00:23:46 +0000446
Nils Diewald7c8ced22015-04-15 19:21:00 +0000447 info = matchClass.create(matchElement).info();
448 info.toggle();
Nils Diewalda297f062015-04-02 00:23:46 +0000449
Nils Diewald7c8ced22015-04-15 19:21:00 +0000450 // Match
451 expect(matchElement.children[0].tagName).toEqual('DIV');
Nils Diewalda297f062015-04-02 00:23:46 +0000452
Nils Diewald7c8ced22015-04-15 19:21:00 +0000453 // snippet
454 expect(matchElement.children[0].children[0].tagName).toEqual('DIV');
455 expect(matchElement.children[0].children[0].classList.contains('snippet')).toBeTruthy();
456 expect(matchElement.children[0].children[0].firstChild.nodeValue).toEqual('check');
Nils Diewalda297f062015-04-02 00:23:46 +0000457
Nils Diewald7c8ced22015-04-15 19:21:00 +0000458 // reference
459 expect(matchElement.children[1].classList.contains('ref')).toBeTruthy();
460 expect(matchElement.children[1].firstChild.nodeValue).toEqual('me');
Nils Diewalda297f062015-04-02 00:23:46 +0000461
Nils Diewald7c8ced22015-04-15 19:21:00 +0000462 // now
Akronaa7fce52017-06-30 21:15:18 +0200463 var infotable = matchElement.children[2];
Nils Diewald7c8ced22015-04-15 19:21:00 +0000464 expect(infotable.tagName).toEqual('DIV');
465 expect(infotable.classList.contains('matchinfo')).toBeTruthy();
466 expect(infotable.children[0].classList.contains('matchtable')).toBeTruthy();
467 expect(infotable.children[1].classList.contains('addtree')).toBeTruthy();
468 });
Nils Diewalda297f062015-04-02 00:23:46 +0000469
Nils Diewald7c8ced22015-04-15 19:21:00 +0000470 it('should add a tree view async 1', function (done) {
471 expect(info).toBeTruthy();
472 info.addTree('mate', 'beebop', function () {
Akron98a933f2016-08-11 00:19:17 +0200473 done();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000474 });
475 });
476
477 it('should add a tree view async 2', function () {
478 // With added tree
Akronaa7fce52017-06-30 21:15:18 +0200479 var infotable = matchElement.children[2];
Nils Diewald7c8ced22015-04-15 19:21:00 +0000480 expect(infotable.tagName).toEqual('DIV');
481 expect(infotable.classList.contains('matchinfo')).toBeTruthy();
482 expect(infotable.children[0].classList.contains('matchtable')).toBeTruthy();
483 expect(infotable.children[1].classList.contains('addtree')).toBe(false);
484
485 var tree = infotable.children[1];
486 expect(tree.tagName).toEqual('DIV');
487 expect(tree.classList.contains('matchtree')).toBeTruthy();
488 expect(tree.children[0].tagName).toEqual('H6');
489 expect(tree.children[0].children[0].tagName).toEqual('SPAN');
490 expect(tree.children[0].children[0].firstChild.nodeValue).toEqual('mate');
491 expect(tree.children[0].children[1].tagName).toEqual('SPAN');
492 expect(tree.children[0].children[1].firstChild.nodeValue).toEqual('beebop');
493
494 expect(tree.children[1].tagName).toEqual('DIV');
Nils Diewald58141332015-04-07 16:18:45 +0000495 });
496 });
Nils Diewalda297f062015-04-02 00:23:46 +0000497
Nils Diewalda297f062015-04-02 00:23:46 +0000498
Nils Diewald7c8ced22015-04-15 19:21:00 +0000499 describe('KorAP.MatchTable', function () {
Nils Diewalda297f062015-04-02 00:23:46 +0000500
Nils Diewald7c8ced22015-04-15 19:21:00 +0000501 var matchClass = require('match');
Nils Diewalda297f062015-04-02 00:23:46 +0000502
Nils Diewald7c8ced22015-04-15 19:21:00 +0000503 var table;
504 it('should be retrieved async', function (done) {
505 var info = matchClass.create(match).info();
506 expect(info).toBeTruthy();
507 info.getTable(undefined, function (x) {
508 table = x;
509 done();
510 });
511 });
Nils Diewalda297f062015-04-02 00:23:46 +0000512
Nils Diewald7c8ced22015-04-15 19:21:00 +0000513 it('should be rendered async', function () {
514 var e = table.element();
515
516 expect(e.nodeName).toBe('TABLE');
517 expect(e.children[0].nodeName).toBe('THEAD');
518 var tr = e.children[0].children[0];
519 expect(tr.nodeName).toBe('TR');
520 expect(tr.children[0].nodeName).toBe('TH');
Nils Diewald58141332015-04-07 16:18:45 +0000521
Nils Diewald7c8ced22015-04-15 19:21:00 +0000522 expect(tr.children[0].firstChild.nodeValue).toBe('Foundry');
523 expect(tr.children[1].firstChild.nodeValue).toBe('Layer');
524 expect(tr.children[2].firstChild.nodeValue).toBe('meist');
525 expect(tr.children[3].firstChild.nodeValue).toBe('deutlich');
526 expect(tr.children[4].firstChild.nodeValue).toBe('leistungsfähiger');
527
528 // first row
529 tr = e.children[1].children[0];
530 expect(tr.nodeName).toBe('TR');
531 expect(tr.getAttribute('tabindex')).toEqual('0');
532 expect(tr.children[0].nodeName).toBe('TH');
533 expect(tr.children[0].firstChild.nodeValue).toEqual('cnx');
534 expect(tr.children[1].firstChild.nodeValue).toEqual('l');
535 expect(tr.children[2].firstChild.nodeValue).toEqual('meist');
536 expect(tr.children[3].firstChild.nodeValue).toEqual('deutlich');
537 expect(tr.children[4].firstChild.nodeValue).toEqual('fähig');
538 expect(tr.children[4].lastChild.nodeValue).toEqual('leistung');
539
540 // second row
541 tr = e.children[1].children[1];
542 expect(tr.nodeName).toBe('TR');
543 expect(tr.getAttribute('tabindex')).toEqual('0');
544 expect(tr.children[0].nodeName).toBe('TH');
545 expect(tr.children[0].firstChild.nodeValue).toEqual('cnx');
546 expect(tr.children[1].firstChild.nodeValue).toEqual('p');
547 expect(tr.children[2].firstChild.nodeValue).toEqual('ADV');
548 expect(tr.children[3].firstChild.nodeValue).toEqual('A');
549 expect(tr.children[4].firstChild.nodeValue).toEqual('A');
Nils Diewald58141332015-04-07 16:18:45 +0000550 });
551 });
Nils Diewalda297f062015-04-02 00:23:46 +0000552
Nils Diewald7c8ced22015-04-15 19:21:00 +0000553 describe('KorAP.MatchTree', function () {
554 var tree;
555 var matchClass = require('match');
Nils Diewalda297f062015-04-02 00:23:46 +0000556
Nils Diewald7c8ced22015-04-15 19:21:00 +0000557 it('should be rendered async 1', function (done) {
558 var info = matchClass.create(match).info();
559 expect(info).toBeTruthy();
560 info.getTree(undefined, undefined, function (y) {
561 tree = y;
562 done();
563 });
564 });
Nils Diewalda297f062015-04-02 00:23:46 +0000565
Nils Diewald7c8ced22015-04-15 19:21:00 +0000566 it('should be rendered async 2', function () {
567 var e = tree.element();
568 expect(e.nodeName).toEqual('svg');
569 expect(e.getElementsByTagName('g').length).toEqual(48);
Nils Diewald58141332015-04-07 16:18:45 +0000570 });
571 });
Nils Diewalda297f062015-04-02 00:23:46 +0000572
Nils Diewald7c8ced22015-04-15 19:21:00 +0000573
574 describe('KorAP.MatchTreeItem', function () {
575 var matchTreeItemClass = require('match/treeitem');
576 it('should be initializable', function () {
577 var mi = matchTreeItemClass.create(['cnx/c', 'cnx', 'c'])
578 expect(mi.element().firstChild.nodeValue).toEqual('cnx/c');
579 expect(mi.lcField()).toEqual(' cnx/c');
580 expect(mi.foundry()).toEqual('cnx');
581 expect(mi.layer()).toEqual('c');
582 });
Nils Diewalda297f062015-04-02 00:23:46 +0000583 });
Nils Diewalda297f062015-04-02 00:23:46 +0000584
585
Nils Diewald7c8ced22015-04-15 19:21:00 +0000586 describe('KorAP.MatchTreeMenu', function () {
587 var matchTreeMenu = require('match/treemenu');
588 var matchTreeItem = require('match/treeitem');
589
590 it('should be initializable', function () {
591 var menu = matchTreeMenu.create(undefined, [
Akronaba7a5a2016-08-15 21:58:33 +0200592 ['cnx/c', 'cnx', 'c'],
593 ['xip/c', 'xip', 'c']
Nils Diewald7c8ced22015-04-15 19:21:00 +0000594 ]);
595
596 expect(menu.itemClass()).toEqual(matchTreeItem);
597 expect(menu.element().nodeName).toEqual('UL');
Akronaba7a5a2016-08-15 21:58:33 +0200598 expect(menu.element().classList.contains('visible')).toBeFalsy();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000599 expect(menu.limit()).toEqual(6);
600 menu.show();
Akronaba7a5a2016-08-15 21:58:33 +0200601 expect(menu.element().classList.contains('visible')).toBeTruthy();
Akronc1457bf2015-06-11 19:24:00 +0200602 expect(menu.item(0).active()).toBe(false);
Nils Diewald7c8ced22015-04-15 19:21:00 +0000603 });
Nils Diewalda297f062015-04-02 00:23:46 +0000604 });
Nils Diewald7c8ced22015-04-15 19:21:00 +0000605
606 // table = view.toTable();
607 // table.sortBy('');
608 // table.element();
609 // tree = view.toTree();
610 // tree.element();
611
Nils Diewalda297f062015-04-02 00:23:46 +0000612});