blob: e52132c5ce340a9d05ab3794fa84679b8719ec3c [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() {
Akrone4961b12017-05-10 21:04:46 +0200220 matchClass.create()
Nils Diewald7c8ced22015-04-15 19:21:00 +0000221 }).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
Akronaa7fce52017-06-30 21:15:18 +0200415 var infotable = matchElement.children[2];
Nils Diewald7c8ced22015-04-15 19:21:00 +0000416 expect(infotable.tagName).toEqual('DIV');
Akronaa7fce52017-06-30 21:15:18 +0200417
Nils Diewald7c8ced22015-04-15 19:21:00 +0000418 expect(infotable.classList.contains('matchinfo')).toBeTruthy();
419
420 expect(infotable.children[0].classList.contains('matchtable')).toBeTruthy();
421 expect(infotable.children[1].classList.contains('addtree')).toBeTruthy();
422 });
423
424 var tree;
425 it('should parse into a tree (async) 1', function (done) {
426 var info = matchClass.create(match).info();
427 expect(info).toBeTruthy();
428 info.getTree(undefined, undefined, function (treem) {
Akron98a933f2016-08-11 00:19:17 +0200429 tree = treem;
430 done();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000431 });
432 });
433
434 it('should parse into a tree (async) 2', function () {
435 expect(tree).toBeTruthy();
436 expect(tree.nodes()).toEqual(49);
437 });
Nils Diewalda297f062015-04-02 00:23:46 +0000438
Akron98a933f2016-08-11 00:19:17 +0200439 var matchElement, info;
440 // var info, matchElement;
441 it('should parse into a tree view', function () {
Nils Diewald7c8ced22015-04-15 19:21:00 +0000442 matchElement = matchElementFactory();
443 expect(matchElement.tagName).toEqual('LI');
Nils Diewalda297f062015-04-02 00:23:46 +0000444
Nils Diewald7c8ced22015-04-15 19:21:00 +0000445 info = matchClass.create(matchElement).info();
446 info.toggle();
Nils Diewalda297f062015-04-02 00:23:46 +0000447
Nils Diewald7c8ced22015-04-15 19:21:00 +0000448 // Match
449 expect(matchElement.children[0].tagName).toEqual('DIV');
Nils Diewalda297f062015-04-02 00:23:46 +0000450
Nils Diewald7c8ced22015-04-15 19:21:00 +0000451 // snippet
452 expect(matchElement.children[0].children[0].tagName).toEqual('DIV');
453 expect(matchElement.children[0].children[0].classList.contains('snippet')).toBeTruthy();
454 expect(matchElement.children[0].children[0].firstChild.nodeValue).toEqual('check');
Nils Diewalda297f062015-04-02 00:23:46 +0000455
Nils Diewald7c8ced22015-04-15 19:21:00 +0000456 // reference
457 expect(matchElement.children[1].classList.contains('ref')).toBeTruthy();
458 expect(matchElement.children[1].firstChild.nodeValue).toEqual('me');
Nils Diewalda297f062015-04-02 00:23:46 +0000459
Nils Diewald7c8ced22015-04-15 19:21:00 +0000460 // now
Akronaa7fce52017-06-30 21:15:18 +0200461 var infotable = matchElement.children[2];
Nils Diewald7c8ced22015-04-15 19:21:00 +0000462 expect(infotable.tagName).toEqual('DIV');
463 expect(infotable.classList.contains('matchinfo')).toBeTruthy();
464 expect(infotable.children[0].classList.contains('matchtable')).toBeTruthy();
465 expect(infotable.children[1].classList.contains('addtree')).toBeTruthy();
466 });
Nils Diewalda297f062015-04-02 00:23:46 +0000467
Nils Diewald7c8ced22015-04-15 19:21:00 +0000468 it('should add a tree view async 1', function (done) {
469 expect(info).toBeTruthy();
470 info.addTree('mate', 'beebop', function () {
Akron98a933f2016-08-11 00:19:17 +0200471 done();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000472 });
473 });
474
475 it('should add a tree view async 2', function () {
476 // With added tree
Akronaa7fce52017-06-30 21:15:18 +0200477 var infotable = matchElement.children[2];
Nils Diewald7c8ced22015-04-15 19:21:00 +0000478 expect(infotable.tagName).toEqual('DIV');
479 expect(infotable.classList.contains('matchinfo')).toBeTruthy();
480 expect(infotable.children[0].classList.contains('matchtable')).toBeTruthy();
481 expect(infotable.children[1].classList.contains('addtree')).toBe(false);
482
483 var tree = infotable.children[1];
484 expect(tree.tagName).toEqual('DIV');
485 expect(tree.classList.contains('matchtree')).toBeTruthy();
486 expect(tree.children[0].tagName).toEqual('H6');
487 expect(tree.children[0].children[0].tagName).toEqual('SPAN');
488 expect(tree.children[0].children[0].firstChild.nodeValue).toEqual('mate');
489 expect(tree.children[0].children[1].tagName).toEqual('SPAN');
490 expect(tree.children[0].children[1].firstChild.nodeValue).toEqual('beebop');
491
492 expect(tree.children[1].tagName).toEqual('DIV');
Nils Diewald58141332015-04-07 16:18:45 +0000493 });
494 });
Nils Diewalda297f062015-04-02 00:23:46 +0000495
Nils Diewalda297f062015-04-02 00:23:46 +0000496
Nils Diewald7c8ced22015-04-15 19:21:00 +0000497 describe('KorAP.MatchTable', function () {
Nils Diewalda297f062015-04-02 00:23:46 +0000498
Nils Diewald7c8ced22015-04-15 19:21:00 +0000499 var matchClass = require('match');
Nils Diewalda297f062015-04-02 00:23:46 +0000500
Nils Diewald7c8ced22015-04-15 19:21:00 +0000501 var table;
502 it('should be retrieved async', function (done) {
503 var info = matchClass.create(match).info();
504 expect(info).toBeTruthy();
505 info.getTable(undefined, function (x) {
506 table = x;
507 done();
508 });
509 });
Nils Diewalda297f062015-04-02 00:23:46 +0000510
Nils Diewald7c8ced22015-04-15 19:21:00 +0000511 it('should be rendered async', function () {
512 var e = table.element();
513
514 expect(e.nodeName).toBe('TABLE');
515 expect(e.children[0].nodeName).toBe('THEAD');
516 var tr = e.children[0].children[0];
517 expect(tr.nodeName).toBe('TR');
518 expect(tr.children[0].nodeName).toBe('TH');
Nils Diewald58141332015-04-07 16:18:45 +0000519
Nils Diewald7c8ced22015-04-15 19:21:00 +0000520 expect(tr.children[0].firstChild.nodeValue).toBe('Foundry');
521 expect(tr.children[1].firstChild.nodeValue).toBe('Layer');
522 expect(tr.children[2].firstChild.nodeValue).toBe('meist');
523 expect(tr.children[3].firstChild.nodeValue).toBe('deutlich');
524 expect(tr.children[4].firstChild.nodeValue).toBe('leistungsfähiger');
525
526 // first row
527 tr = e.children[1].children[0];
528 expect(tr.nodeName).toBe('TR');
529 expect(tr.getAttribute('tabindex')).toEqual('0');
530 expect(tr.children[0].nodeName).toBe('TH');
531 expect(tr.children[0].firstChild.nodeValue).toEqual('cnx');
532 expect(tr.children[1].firstChild.nodeValue).toEqual('l');
533 expect(tr.children[2].firstChild.nodeValue).toEqual('meist');
534 expect(tr.children[3].firstChild.nodeValue).toEqual('deutlich');
535 expect(tr.children[4].firstChild.nodeValue).toEqual('fähig');
536 expect(tr.children[4].lastChild.nodeValue).toEqual('leistung');
537
538 // second row
539 tr = e.children[1].children[1];
540 expect(tr.nodeName).toBe('TR');
541 expect(tr.getAttribute('tabindex')).toEqual('0');
542 expect(tr.children[0].nodeName).toBe('TH');
543 expect(tr.children[0].firstChild.nodeValue).toEqual('cnx');
544 expect(tr.children[1].firstChild.nodeValue).toEqual('p');
545 expect(tr.children[2].firstChild.nodeValue).toEqual('ADV');
546 expect(tr.children[3].firstChild.nodeValue).toEqual('A');
547 expect(tr.children[4].firstChild.nodeValue).toEqual('A');
Nils Diewald58141332015-04-07 16:18:45 +0000548 });
549 });
Nils Diewalda297f062015-04-02 00:23:46 +0000550
Nils Diewald7c8ced22015-04-15 19:21:00 +0000551 describe('KorAP.MatchTree', function () {
552 var tree;
553 var matchClass = require('match');
Nils Diewalda297f062015-04-02 00:23:46 +0000554
Nils Diewald7c8ced22015-04-15 19:21:00 +0000555 it('should be rendered async 1', function (done) {
556 var info = matchClass.create(match).info();
557 expect(info).toBeTruthy();
558 info.getTree(undefined, undefined, function (y) {
559 tree = y;
560 done();
561 });
562 });
Nils Diewalda297f062015-04-02 00:23:46 +0000563
Nils Diewald7c8ced22015-04-15 19:21:00 +0000564 it('should be rendered async 2', function () {
565 var e = tree.element();
566 expect(e.nodeName).toEqual('svg');
567 expect(e.getElementsByTagName('g').length).toEqual(48);
Nils Diewald58141332015-04-07 16:18:45 +0000568 });
569 });
Nils Diewalda297f062015-04-02 00:23:46 +0000570
Nils Diewald7c8ced22015-04-15 19:21:00 +0000571
572 describe('KorAP.MatchTreeItem', function () {
573 var matchTreeItemClass = require('match/treeitem');
574 it('should be initializable', function () {
575 var mi = matchTreeItemClass.create(['cnx/c', 'cnx', 'c'])
576 expect(mi.element().firstChild.nodeValue).toEqual('cnx/c');
577 expect(mi.lcField()).toEqual(' cnx/c');
578 expect(mi.foundry()).toEqual('cnx');
579 expect(mi.layer()).toEqual('c');
580 });
Nils Diewalda297f062015-04-02 00:23:46 +0000581 });
Nils Diewalda297f062015-04-02 00:23:46 +0000582
583
Nils Diewald7c8ced22015-04-15 19:21:00 +0000584 describe('KorAP.MatchTreeMenu', function () {
585 var matchTreeMenu = require('match/treemenu');
586 var matchTreeItem = require('match/treeitem');
587
588 it('should be initializable', function () {
589 var menu = matchTreeMenu.create(undefined, [
Akronaba7a5a2016-08-15 21:58:33 +0200590 ['cnx/c', 'cnx', 'c'],
591 ['xip/c', 'xip', 'c']
Nils Diewald7c8ced22015-04-15 19:21:00 +0000592 ]);
593
594 expect(menu.itemClass()).toEqual(matchTreeItem);
595 expect(menu.element().nodeName).toEqual('UL');
Akronaba7a5a2016-08-15 21:58:33 +0200596 expect(menu.element().classList.contains('visible')).toBeFalsy();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000597 expect(menu.limit()).toEqual(6);
598 menu.show();
Akronaba7a5a2016-08-15 21:58:33 +0200599 expect(menu.element().classList.contains('visible')).toBeTruthy();
Akronc1457bf2015-06-11 19:24:00 +0200600 expect(menu.item(0).active()).toBe(false);
Nils Diewald7c8ced22015-04-15 19:21:00 +0000601 });
Nils Diewalda297f062015-04-02 00:23:46 +0000602 });
Nils Diewald7c8ced22015-04-15 19:21:00 +0000603
604 // table = view.toTable();
605 // table.sortBy('');
606 // table.element();
607 // tree = view.toTree();
608 // tree.element();
609
Nils Diewalda297f062015-04-02 00:23:46 +0000610});