blob: 5a4111ba26a1cdac7956a2f961132cf267f56233 [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
hebasta999d6c12018-04-23 12:44:59 +020030
31var fields = [
32 {
33 "@type": "koral:field",
34 "key": "author",
35 "type": "type:text",
36 "value": "Sprachpfleger, u.a."
37 },
38 {
39 "@type": "koral:field",
40 "key": "textClass",
41 "type": "type:keywords",
42 "value": ["kultur", "film"]
43 },
44 {
45 "@type":"koral:field",
46 "key":"foundries",
47 "type":"type:string",
48 "value":[
49 "corenlp",
50 "corenlp\/constituency",
51 "corenlp\/morpho",
52 "corenlp\/sentences",
53 "dereko",
54 "dereko\/structure",
55 "dereko\/structure\/base-sentences-paragraphs-pagebreaks",
56 "opennlp",
57 "opennlp\/morpho",
58 "opennlp\/sentences"
59 ]
60 }
61];
62
63
Nils Diewalda297f062015-04-02 00:23:46 +000064var snippet = "<span title=\"cnx/l:meist\">" +
Akron4e47d0b2017-07-03 17:58:37 +020065 " <span title=\"cnx/p:ADV\">" +
66 " <span title=\"cnx/syn:@PREMOD\">" +
67 " <span title=\"mate/l:meist\">" +
68 " <span title=\"mate/l:meist\">" +
69 " <span title=\"mate/p:ADV\">" +
70 " <span title=\"opennlp/p:ADV\">meist</span>" +
71 " </span>" +
72 " </span>" +
73 " </span>" +
74 " </span>" +
75 " </span>" +
76 "</span>" +
77 "<span title=\"cnx/l:deutlich\">" +
78 " <span title=\"cnx/p:A\">" +
79 " <span title=\"cnx/syn:@PREMOD\">" +
80 " <span title=\"mate/l:deutlich\">" +
81 " <span title=\"mate/m:degree:pos\">" +
82 " <span title=\"mate/p:ADJD\">" +
83 " <span title=\"opennlp/p:ADJD\">deutlich</span>" +
84 " </span>" +
85 " </span>" +
86 " </span>" +
87 " </span>" +
88 " </span>" +
89 "</span>" +
90 "<span title=\"cnx/l:fähig\">" +
91 " <span title=\"cnx/l:leistung\">" +
92 " <span title=\"cnx/p:A\">" +
93 " <span title=\"cnx/p:ADJA\">" +
94 " <span title=\"cnx/syn:@NH\">" +
95 " <span title=\"mate/l:leistungsfähig\">" +
96 " <span title=\"mate/m:degree:comp\">" +
97 " <span title=\"mate/p:ADJD\">" +
98 " <span title=\"opennlp/p:ADJD\">leistungsfähiger</span>" +
99 " </span>" +
100 " </span>" +
101 " </span>" +
102 " </span>" +
103 " </span>" +
104 " </span>" +
105 " </span>" +
106 "</span>";
Nils Diewalda297f062015-04-02 00:23:46 +0000107
108var treeSnippet =
109 "<span class=\"context-left\"></span>" +
110 "<span class=\"match\">" +
111 " <span title=\"xip/c:MC\">" +
112 " <span title=\"xip/c:TOP\">" +
113 " <span title=\"xip/c:PP\">" +
114 " <span title=\"xip/c:PREP\">Mit</span>" +
115 " <span title=\"xip/c:NP\">" +
116 " <span title=\"xip/c:DET\">dieser</span>" +
117 " <span title=\"xip/c:NPA\">" +
118 " <span title=\"xip/c:NOUN\">Methode</span>" +
119 " </span>" +
120 " </span>" +
121 " </span>" +
122 " <span title=\"xip/c:VERB\">ist</span>" +
Akron98a933f2016-08-11 00:19:17 +0200123 " <mark>" +
124 " <span title=\"xip/c:NP\">" +
125 " <span title=\"xip/c:PRON\">es</span>" +
126 " </span>" +
127 " <span title=\"xip/c:AP\">" +
128 " <span title=\"xip/c:ADV\">nun</span>" +
129 " <span title=\"xip/c:ADJ\">möglich</span>" +
130 " </span>" +
131 " </mark>" +
Nils Diewalda297f062015-04-02 00:23:46 +0000132 " <span title=\"xip/c:ADV\">z. B.</span>" +
133 " <span title=\"xip/c:NPA\">" +
134 " <span title=\"xip/c:NP\">" +
135 " <span title=\"xip/c:NOUN\">Voice</span>" +
136 " </span>" +
137 " </span>" + "(" +
138 " <span title=\"xip/c:INS\">" +
139 " <span title=\"xip/c:NPA\">" +
140 " <span title=\"xip/c:NP\">" +
141 " <span title=\"xip/c:NOUN\">Sprache</span>" +
142 " </span>" +
143 " </span>" +
144 " </span>" + ")" +
145 " <span title=\"xip/c:VERB\">bevorzugt</span>" +
146 " <span title=\"xip/c:PP\">" +
147 " <span title=\"xip/c:PREP\">in</span>" +
148 " <span title=\"xip/c:NP\">" +
149 " <span title=\"xip/c:PRON\">der</span>" +
150 " </span>" +
151 " <span title=\"xip/c:NPA\">" +
152 " <span title=\"xip/c:NP\">" +
153 " <span title=\"xip/c:NOUN\">Bridge</span>" +
154 " </span>" +
155 " </span>" +
156 " </span>" +
157 " <span title=\"xip/c:INFC\">" +
158 " <span title=\"xip/c:INS\">" +
159 " <span title=\"xip/c:VERB\">weiterzugeben</span>" +
160 " </span>" +
161 " </span>" +
162 " </span>" +
163 " </span>" +
164 "</span>" +
165 "<span class=\"context-right\"></span>";
166
167
168function matchElementFactory () {
169 var me = document.createElement('li');
170
171 me.setAttribute(
172 'data-available-info',
173 'base/s=spans corenlp/c=spans corenlp/ne=tokens corenlp/p=tokens' +
174 ' corenlp/s=spans glemm/l=tokens mate/l=tokens mate/m=tokens' +
175 ' mate/p=tokens opennlp/p=tokens opennlp/s=spans tt/l=tokens' +
176 ' tt/p=tokens tt/s=spans');
177
178 me.setAttribute('data-corpus-id', 'WPD');
179 me.setAttribute('data-doc-id', 'FFF');
180 me.setAttribute('data-text-id', '01460');
Akron0a6768f2016-07-13 18:00:43 +0200181 me.setAttribute('data-text-sigle', 'WPD/FFF/01460');
Nils Diewalda297f062015-04-02 00:23:46 +0000182 me.setAttribute('data-match-id', 'p119-120');
183 me.innerHTML = '<div><div class="snippet">check</div></div><p class="ref">me</p>';
184 return me;
185};
186
Akroncdb0baa2016-11-07 01:52:11 +0100187function matchElementReal () {
188 var me = document.createElement('em');
189 me.innerHTML =
190 '<li data-match-id="p85183-85184"' +
191 ' data-text-sigle="GOE/AGI/00000"' +
192 ' 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"' +
193 ' 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;}"' +
194 ' id="GOE/AGI/00000#p85183-85184">' +
195 '<div>' +
196 '<div class="flag"></div>' +
197 '<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>' +
198 '</div>' +
199 '<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>' +
200 '</li>';
201 return me.firstChild;
202};
Nils Diewalda297f062015-04-02 00:23:46 +0000203
hebasta999d6c12018-04-23 12:44:59 +0200204
Akronf2279c42017-12-21 13:48:46 +0100205define(['match', 'hint/foundries/cnx', 'hint/foundries/mate'], function () {
Nils Diewald58141332015-04-07 16:18:45 +0000206
Nils Diewald7c8ced22015-04-15 19:21:00 +0000207 // Override getMatchInfo API call
208 KorAP.API.getMatchInfo = function (x, param, cb) {
209 if (param['spans'] === undefined || param['spans'] === false)
210 cb({ "snippet": snippet });
211 else
212 cb({ "snippet": treeSnippet });
Nils Diewalda297f062015-04-02 00:23:46 +0000213 };
Akron671fdb92017-09-12 18:09:46 +0200214
Nils Diewald7c8ced22015-04-15 19:21:00 +0000215 describe('KorAP.InfoLayer', function () {
216
217 var infoClass = require('match/infolayer');
Nils Diewalda297f062015-04-02 00:23:46 +0000218
Nils Diewald7c8ced22015-04-15 19:21:00 +0000219 it('should be initializable', function () {
220 expect(
Akron671fdb92017-09-12 18:09:46 +0200221 function() { infoClass.create() }
Nils Diewald7c8ced22015-04-15 19:21:00 +0000222 ).toThrow(new Error("Missing parameters"));
Nils Diewalda297f062015-04-02 00:23:46 +0000223
Nils Diewald7c8ced22015-04-15 19:21:00 +0000224 expect(
Akron671fdb92017-09-12 18:09:46 +0200225 function() { infoClass.create("base") }
Nils Diewald7c8ced22015-04-15 19:21:00 +0000226 ).toThrow(new Error("Missing parameters"));
Nils Diewalda297f062015-04-02 00:23:46 +0000227
Nils Diewald7c8ced22015-04-15 19:21:00 +0000228 var layer = infoClass.create("base", "s");
229 expect(layer).toBeTruthy();
230 expect(layer.foundry).toEqual("base");
231 expect(layer.layer).toEqual("s");
232 expect(layer.type).toEqual("tokens");
Nils Diewalda297f062015-04-02 00:23:46 +0000233
Nils Diewald7c8ced22015-04-15 19:21:00 +0000234 layer = infoClass.create("cnx", "syn", "spans");
235 expect(layer).toBeTruthy();
236 expect(layer.foundry).toEqual("cnx");
237 expect(layer.layer).toEqual("syn");
238 expect(layer.type).toEqual("spans");
Nils Diewald58141332015-04-07 16:18:45 +0000239 });
240 });
Nils Diewalda297f062015-04-02 00:23:46 +0000241
Nils Diewalda297f062015-04-02 00:23:46 +0000242
Nils Diewald7c8ced22015-04-15 19:21:00 +0000243 describe('KorAP.Match', function () {
244 var match = {
245 'corpusID' : 'WPD',
246 'docID' : 'UUU',
247 'textID' : '01912',
248 'matchID' : 'p121-122',
Akron0a6768f2016-07-13 18:00:43 +0200249 'textSigle' : 'WPD/UUU/01912',
Nils Diewald7c8ced22015-04-15 19:21:00 +0000250 'available' : available
251 };
252
253 var matchClass = require('match');
254
255 it('should be initializable by Object', function () {
256 expect(function() {
Akron671fdb92017-09-12 18:09:46 +0200257 matchClass.create()
Nils Diewald7c8ced22015-04-15 19:21:00 +0000258 }).toThrow(new Error('Missing parameters'));
259
260 expect(matchClass.create(match)).toBeTruthy();
261
262 var m = matchClass.create(match);
Akron0a6768f2016-07-13 18:00:43 +0200263 expect(m.textSigle).toEqual("WPD/UUU/01912");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000264 expect(m.matchID).toEqual("p121-122");
265
266 // /corpus/WPD/UUU.01912/p121-122/matchInfo?spans=false&foundry=*
267 var m = matchClass.create(match);
268
269 // Spans:
270 var spans = m.getSpans();
271 expect(spans[0].foundry).toEqual("base");
272 expect(spans[0].layer).toEqual("s");
273
274 expect(spans[1].foundry).toEqual("corenlp");
275 expect(spans[1].layer).toEqual("c");
276
277 expect(spans[2].foundry).toEqual("corenlp");
278 expect(spans[2].layer).toEqual("s");
279
280 expect(spans[spans.length-1].foundry).toEqual("tt");
281 expect(spans[spans.length-1].layer).toEqual("s");
282
283 // Tokens:
284 var tokens = m.getTokens();
285 expect(tokens[0].foundry).toEqual("corenlp");
286 expect(tokens[0].layer).toEqual("ne");
287
288 expect(tokens[1].foundry).toEqual("corenlp");
289 expect(tokens[1].layer).toEqual("p");
290
291 expect(tokens[tokens.length-1].foundry).toEqual("tt");
292 expect(tokens[tokens.length-1].layer).toEqual("p");
Nils Diewald58141332015-04-07 16:18:45 +0000293 });
Nils Diewalda297f062015-04-02 00:23:46 +0000294
295
Akroncdb0baa2016-11-07 01:52:11 +0100296 it('should be initializable by Node 1', function () {
Nils Diewald7c8ced22015-04-15 19:21:00 +0000297 var m = matchClass.create(matchElementFactory());
Akron0a6768f2016-07-13 18:00:43 +0200298 expect(m.textSigle).toEqual("WPD/FFF/01460");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000299 expect(m.matchID).toEqual("p119-120");
Nils Diewalda297f062015-04-02 00:23:46 +0000300
Nils Diewald7c8ced22015-04-15 19:21:00 +0000301 // Spans:
302 var spans = m.getSpans();
303 expect(spans[0].foundry).toEqual("base");
304 expect(spans[0].layer).toEqual("s");
Nils Diewalda297f062015-04-02 00:23:46 +0000305
Nils Diewald7c8ced22015-04-15 19:21:00 +0000306 expect(spans[1].foundry).toEqual("corenlp");
307 expect(spans[1].layer).toEqual("c");
Nils Diewalda297f062015-04-02 00:23:46 +0000308
Nils Diewald7c8ced22015-04-15 19:21:00 +0000309 expect(spans[2].foundry).toEqual("corenlp");
310 expect(spans[2].layer).toEqual("s");
Nils Diewalda297f062015-04-02 00:23:46 +0000311
Nils Diewald7c8ced22015-04-15 19:21:00 +0000312 expect(spans[spans.length-1].foundry).toEqual("tt");
313 expect(spans[spans.length-1].layer).toEqual("s");
Nils Diewalda297f062015-04-02 00:23:46 +0000314
Nils Diewald7c8ced22015-04-15 19:21:00 +0000315 // Tokens:
316 var tokens = m.getTokens();
317 expect(tokens[0].foundry).toEqual("corenlp");
318 expect(tokens[0].layer).toEqual("ne");
Nils Diewalda297f062015-04-02 00:23:46 +0000319
Nils Diewald7c8ced22015-04-15 19:21:00 +0000320 expect(tokens[1].foundry).toEqual("corenlp");
321 expect(tokens[1].layer).toEqual("p");
Nils Diewalda297f062015-04-02 00:23:46 +0000322
Nils Diewald7c8ced22015-04-15 19:21:00 +0000323 expect(tokens[tokens.length-1].foundry).toEqual("tt");
324 expect(tokens[tokens.length-1].layer).toEqual("p");
Nils Diewalda297f062015-04-02 00:23:46 +0000325
Nils Diewald7c8ced22015-04-15 19:21:00 +0000326 });
Nils Diewalda297f062015-04-02 00:23:46 +0000327
Akroncdb0baa2016-11-07 01:52:11 +0100328 it('should be initializable by Node 2', function () {
329 var ele = matchElementReal();
330 var m = matchClass.create(ele);
331 expect(m.textSigle).toEqual("GOE/AGI/00000");
332 expect(m.matchID).toEqual("p85183-85184");
333 });
334
335
Nils Diewald7c8ced22015-04-15 19:21:00 +0000336 it('should react to gui actions', function () {
337 var e = matchElementFactory();
Nils Diewalda297f062015-04-02 00:23:46 +0000338
Nils Diewald7c8ced22015-04-15 19:21:00 +0000339 expect(e.classList.contains('active')).toBe(false);
340 expect(e["_match"]).toBe(undefined);
Nils Diewalda297f062015-04-02 00:23:46 +0000341
Nils Diewald7c8ced22015-04-15 19:21:00 +0000342 var m = matchClass.create(e);
343
344 expect(e.classList.contains('active')).toBe(false);
345 expect(e["_match"]).not.toBe(undefined);
346
347 // Open the match
348 m.open();
349
350 expect(e.classList.contains('active')).toBe(true);
351 expect(e["_match"]).not.toBe(undefined);
352
Akronc296ca22018-04-24 16:35:26 +0200353 actions = e.querySelector("p.ref > div.action.bottom").getElementsByTagName("span");
354 expect(actions[0].getAttribute("class")).toEqual("meta");
355 expect(actions[1].getAttribute("class")).toEqual("info");
356 expect(actions[2].getAttribute("class")).toEqual("tree");
357
Nils Diewald7c8ced22015-04-15 19:21:00 +0000358 // Close the match
359 m.close();
360 expect(e.classList.contains('active')).toBe(false);
361 expect(e["_match"]).not.toBe(undefined);
Nils Diewald58141332015-04-07 16:18:45 +0000362 });
Nils Diewalda297f062015-04-02 00:23:46 +0000363
Akronc296ca22018-04-24 16:35:26 +0200364 it('should open tree menu', function () {
365 var e = matchElementFactory();
366 var m = matchClass.create(e);
367 m.open();
368 var relation = e.querySelector("p.ref > div.action.bottom > span:nth-of-type(3)");
369 expect(relation.getAttribute("class")).toEqual("tree");
370 expect(document.getElementById("treeMenu")).toBeNull();
371
372 expect(document.activeElement.tagName).toEqual("BODY");
373
374 // Show menu
375 relation.click();
376 expect(document.getElementById("treeMenu")).toBeTruthy();
377
378 expect(document.activeElement.tagName).toEqual("UL");
379
380 // Choose first tree
381 document.getElementById("treeMenu").getElementsByTagName("li")[1].click();
382 expect(e.querySelector("div.matchinfo div.matchtree h6 span").innerText).toEqual("corenlp");
383
384 // This should blur the focus
385 expect(document.activeElement.tagName).toEqual("BODY");
386 });
387
388 });
Nils Diewald7c8ced22015-04-15 19:21:00 +0000389
390 describe('KorAP.MatchInfo', function () {
391
392 var matchClass = require('match');
393
394 var m = matchClass.create(match);
395 var info = m.info();
396
397 it('should contain a valid info', function () {
398 expect(m._info).toEqual(info);
399 });
400
401 var table1, table2;
402
403 // Async preparation
404 it('should fail to load a table async', function (done) {
405 expect(info).toBeTruthy();
406
Akron5b1a6af2018-02-05 15:41:16 +0100407 info.getTableData([], function (tablen) {
Akron671fdb92017-09-12 18:09:46 +0200408 table1 = tablen;
409 done();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000410 });
411 });
412
Akron671fdb92017-09-12 18:09:46 +0200413
Nils Diewald7c8ced22015-04-15 19:21:00 +0000414 it('should\'nt be parsable (async)', function () {
415 expect(table1).not.toBeTruthy();
416 });
417
Akron671fdb92017-09-12 18:09:46 +0200418
Nils Diewald7c8ced22015-04-15 19:21:00 +0000419 it('should load a working table async', function(done) {
420 expect(info).toBeTruthy();
Akron5b1a6af2018-02-05 15:41:16 +0100421 info.getTableData(undefined, function (tablem) {
Akron671fdb92017-09-12 18:09:46 +0200422 table2 = tablem;
423 done();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000424 });
425 });
426
Akron671fdb92017-09-12 18:09:46 +0200427
Nils Diewald7c8ced22015-04-15 19:21:00 +0000428 it('should parse into a table (async)', function () {
429 expect(table2).toBeTruthy();
430
431 expect(table2.length()).toBe(3);
432
433 expect(table2.getToken(0)).toBe("meist");
434 expect(table2.getToken(1)).toBe("deutlich");
435 expect(table2.getToken(2)).toBe("leistungsfähiger");
436
437 expect(table2.getValue(0, "cnx", "p")[0]).toBe("ADV");
438 expect(table2.getValue(0, "cnx", "syn")[0]).toBe("@PREMOD");
Akron916ec252016-11-10 17:06:32 +0100439 expect(table2.getValue(0, "mate", "l")[0]).toBe("meist");
440 expect(table2.getValue(0, "mate", "l")[1]).toBeUndefined();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000441
442 expect(table2.getValue(2, "cnx", "l")[0]).toBe("fähig");
443 expect(table2.getValue(2, "cnx", "l")[1]).toBe("leistung");
444 });
445
Akron671fdb92017-09-12 18:09:46 +0200446
Nils Diewald7c8ced22015-04-15 19:21:00 +0000447 it('should parse into a table view', function () {
448 var matchElement = matchElementFactory();
449 expect(matchElement.tagName).toEqual('LI');
450
451 // Match
452 expect(matchElement.children[0].tagName).toEqual('DIV');
453
454 // snippet
455 expect(matchElement.children[0].children[0].tagName).toEqual('DIV');
456 expect(matchElement.children[0].children[0].classList.contains('snippet')).toBeTruthy();
457 expect(matchElement.children[0].children[0].firstChild.nodeValue).toEqual('check');
458
459 // reference
460 expect(matchElement.children[1].classList.contains('ref')).toBeTruthy();
461 expect(matchElement.children[1].firstChild.nodeValue).toEqual('me');
462
463 // not yet
464 expect(matchElement.children[0].children[1]).toBe(undefined);
465
466 var info = matchClass.create(matchElement).info();
Akron5b1a6af2018-02-05 15:41:16 +0100467 info.showTable();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000468
469 // Match
470 expect(matchElement.children[0].tagName).toEqual('DIV');
471
472 // snippet
473 expect(matchElement.children[0].children[0].tagName).toEqual('DIV');
Akron5b1a6af2018-02-05 15:41:16 +0100474
Nils Diewald7c8ced22015-04-15 19:21:00 +0000475 expect(matchElement.children[0].children[0].classList.contains('snippet')).toBeTruthy();
Akron5b1a6af2018-02-05 15:41:16 +0100476
Nils Diewald7c8ced22015-04-15 19:21:00 +0000477 expect(matchElement.children[0].children[0].firstChild.nodeValue).toEqual('check');
478
479 // reference
Akron5b1a6af2018-02-05 15:41:16 +0100480 expect(matchElement.lastChild.classList.contains('ref')).toBeTruthy();
481 expect(matchElement.lastChild.firstChild.nodeValue).toEqual('me');
Nils Diewald7c8ced22015-04-15 19:21:00 +0000482
483 // now
Akron5b1a6af2018-02-05 15:41:16 +0100484 var infotable = matchElement.children[1];
Nils Diewald7c8ced22015-04-15 19:21:00 +0000485 expect(infotable.tagName).toEqual('DIV');
Akronaa7fce52017-06-30 21:15:18 +0200486
Nils Diewald7c8ced22015-04-15 19:21:00 +0000487 expect(infotable.classList.contains('matchinfo')).toBeTruthy();
488
489 expect(infotable.children[0].classList.contains('matchtable')).toBeTruthy();
Akron5b1a6af2018-02-05 15:41:16 +0100490 // expect(infotable.children[1].classList.contains('addtree')).toBeTruthy();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000491 });
492
Akron671fdb92017-09-12 18:09:46 +0200493
Nils Diewald7c8ced22015-04-15 19:21:00 +0000494 var tree;
495 it('should parse into a tree (async) 1', function (done) {
496 var info = matchClass.create(match).info();
497 expect(info).toBeTruthy();
Akron5b1a6af2018-02-05 15:41:16 +0100498 info.getTreeData(undefined, undefined, "spans", function (treem) {
Akron671fdb92017-09-12 18:09:46 +0200499 tree = treem;
500 done();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000501 });
502 });
503
Akron671fdb92017-09-12 18:09:46 +0200504
Nils Diewald7c8ced22015-04-15 19:21:00 +0000505 it('should parse into a tree (async) 2', function () {
506 expect(tree).toBeTruthy();
507 expect(tree.nodes()).toEqual(49);
508 });
Nils Diewalda297f062015-04-02 00:23:46 +0000509
Akron671fdb92017-09-12 18:09:46 +0200510
Akron98a933f2016-08-11 00:19:17 +0200511 var matchElement, info;
Akron5b1a6af2018-02-05 15:41:16 +0100512
Akron98a933f2016-08-11 00:19:17 +0200513 // var info, matchElement;
514 it('should parse into a tree view', function () {
Nils Diewald7c8ced22015-04-15 19:21:00 +0000515 matchElement = matchElementFactory();
516 expect(matchElement.tagName).toEqual('LI');
Nils Diewalda297f062015-04-02 00:23:46 +0000517
Nils Diewald7c8ced22015-04-15 19:21:00 +0000518 info = matchClass.create(matchElement).info();
Akron5b1a6af2018-02-05 15:41:16 +0100519 info.showTable();
Nils Diewalda297f062015-04-02 00:23:46 +0000520
Nils Diewald7c8ced22015-04-15 19:21:00 +0000521 // Match
522 expect(matchElement.children[0].tagName).toEqual('DIV');
Nils Diewalda297f062015-04-02 00:23:46 +0000523
Nils Diewald7c8ced22015-04-15 19:21:00 +0000524 // snippet
525 expect(matchElement.children[0].children[0].tagName).toEqual('DIV');
526 expect(matchElement.children[0].children[0].classList.contains('snippet')).toBeTruthy();
527 expect(matchElement.children[0].children[0].firstChild.nodeValue).toEqual('check');
Nils Diewalda297f062015-04-02 00:23:46 +0000528
Nils Diewald7c8ced22015-04-15 19:21:00 +0000529 // reference
Akron5b1a6af2018-02-05 15:41:16 +0100530 expect(matchElement.lastChild.classList.contains('ref')).toBeTruthy();
531 expect(matchElement.lastChild.firstChild.nodeValue).toEqual('me');
Nils Diewalda297f062015-04-02 00:23:46 +0000532
Nils Diewald7c8ced22015-04-15 19:21:00 +0000533 // now
Akron5b1a6af2018-02-05 15:41:16 +0100534 var infotable = matchElement.children[1];
Nils Diewald7c8ced22015-04-15 19:21:00 +0000535 expect(infotable.tagName).toEqual('DIV');
536 expect(infotable.classList.contains('matchinfo')).toBeTruthy();
537 expect(infotable.children[0].classList.contains('matchtable')).toBeTruthy();
Akron5b1a6af2018-02-05 15:41:16 +0100538 // expect(infotable.children[1].classList.contains('addtree')).toBeTruthy();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000539 });
Nils Diewalda297f062015-04-02 00:23:46 +0000540
Akron671fdb92017-09-12 18:09:46 +0200541
Nils Diewald7c8ced22015-04-15 19:21:00 +0000542 it('should add a tree view async 1', function (done) {
543 expect(info).toBeTruthy();
Akron5b1a6af2018-02-05 15:41:16 +0100544 info.showTree('mate', 'beebop', "spans", function () {
Akron671fdb92017-09-12 18:09:46 +0200545 done();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000546 });
547 });
548
Akron671fdb92017-09-12 18:09:46 +0200549
Nils Diewald7c8ced22015-04-15 19:21:00 +0000550 it('should add a tree view async 2', function () {
551 // With added tree
Akron5b1a6af2018-02-05 15:41:16 +0100552 var infotable = matchElement.children[1];
553
Nils Diewald7c8ced22015-04-15 19:21:00 +0000554 expect(infotable.tagName).toEqual('DIV');
555 expect(infotable.classList.contains('matchinfo')).toBeTruthy();
556 expect(infotable.children[0].classList.contains('matchtable')).toBeTruthy();
557 expect(infotable.children[1].classList.contains('addtree')).toBe(false);
558
559 var tree = infotable.children[1];
560 expect(tree.tagName).toEqual('DIV');
561 expect(tree.classList.contains('matchtree')).toBeTruthy();
562 expect(tree.children[0].tagName).toEqual('H6');
563 expect(tree.children[0].children[0].tagName).toEqual('SPAN');
564 expect(tree.children[0].children[0].firstChild.nodeValue).toEqual('mate');
565 expect(tree.children[0].children[1].tagName).toEqual('SPAN');
566 expect(tree.children[0].children[1].firstChild.nodeValue).toEqual('beebop');
567
568 expect(tree.children[1].tagName).toEqual('DIV');
Nils Diewald58141332015-04-07 16:18:45 +0000569 });
570 });
Nils Diewalda297f062015-04-02 00:23:46 +0000571
Nils Diewalda297f062015-04-02 00:23:46 +0000572
Nils Diewald7c8ced22015-04-15 19:21:00 +0000573 describe('KorAP.MatchTable', function () {
Nils Diewalda297f062015-04-02 00:23:46 +0000574
Nils Diewald7c8ced22015-04-15 19:21:00 +0000575 var matchClass = require('match');
Nils Diewalda297f062015-04-02 00:23:46 +0000576
Nils Diewald7c8ced22015-04-15 19:21:00 +0000577 var table;
578 it('should be retrieved async', function (done) {
579 var info = matchClass.create(match).info();
580 expect(info).toBeTruthy();
Akron5b1a6af2018-02-05 15:41:16 +0100581 info.getTableData(undefined, function (x) {
Akron671fdb92017-09-12 18:09:46 +0200582 table = x;
583 done();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000584 });
585 });
Nils Diewalda297f062015-04-02 00:23:46 +0000586
Nils Diewald7c8ced22015-04-15 19:21:00 +0000587 it('should be rendered async', function () {
Akron5b1a6af2018-02-05 15:41:16 +0100588
589 var e = table.element().firstChild;
Nils Diewald7c8ced22015-04-15 19:21:00 +0000590 expect(e.nodeName).toBe('TABLE');
591 expect(e.children[0].nodeName).toBe('THEAD');
592 var tr = e.children[0].children[0];
593 expect(tr.nodeName).toBe('TR');
594 expect(tr.children[0].nodeName).toBe('TH');
Nils Diewald58141332015-04-07 16:18:45 +0000595
Nils Diewald7c8ced22015-04-15 19:21:00 +0000596 expect(tr.children[0].firstChild.nodeValue).toBe('Foundry');
597 expect(tr.children[1].firstChild.nodeValue).toBe('Layer');
598 expect(tr.children[2].firstChild.nodeValue).toBe('meist');
599 expect(tr.children[3].firstChild.nodeValue).toBe('deutlich');
600 expect(tr.children[4].firstChild.nodeValue).toBe('leistungsfähiger');
601
602 // first row
603 tr = e.children[1].children[0];
604 expect(tr.nodeName).toBe('TR');
605 expect(tr.getAttribute('tabindex')).toEqual('0');
606 expect(tr.children[0].nodeName).toBe('TH');
607 expect(tr.children[0].firstChild.nodeValue).toEqual('cnx');
608 expect(tr.children[1].firstChild.nodeValue).toEqual('l');
609 expect(tr.children[2].firstChild.nodeValue).toEqual('meist');
610 expect(tr.children[3].firstChild.nodeValue).toEqual('deutlich');
Akron47774c42017-07-03 20:14:55 +0200611 expect(tr.children[4].firstChild.firstChild.nodeValue).toEqual('fähig');
612 expect(tr.children[4].lastChild.firstChild.nodeValue).toEqual('leistung');
Nils Diewald7c8ced22015-04-15 19:21:00 +0000613
614 // second row
615 tr = e.children[1].children[1];
616 expect(tr.nodeName).toBe('TR');
617 expect(tr.getAttribute('tabindex')).toEqual('0');
618 expect(tr.children[0].nodeName).toBe('TH');
619 expect(tr.children[0].firstChild.nodeValue).toEqual('cnx');
620 expect(tr.children[1].firstChild.nodeValue).toEqual('p');
621 expect(tr.children[2].firstChild.nodeValue).toEqual('ADV');
622 expect(tr.children[3].firstChild.nodeValue).toEqual('A');
Akron47774c42017-07-03 20:14:55 +0200623 expect(tr.children[4].firstChild.firstChild.nodeValue).toEqual('A');
624 expect(tr.children[4].lastChild.firstChild.nodeValue).toEqual('ADJA');
Akronf2279c42017-12-21 13:48:46 +0100625
626 expect(tr.children[4].firstChild.getAttribute("title")).toEqual('Adjective');
627 expect(tr.children[2].getAttribute("title")).toEqual('Adverb');
628
Nils Diewald58141332015-04-07 16:18:45 +0000629 });
630 });
Nils Diewalda297f062015-04-02 00:23:46 +0000631
Nils Diewald7c8ced22015-04-15 19:21:00 +0000632 describe('KorAP.MatchTree', function () {
633 var tree;
634 var matchClass = require('match');
Nils Diewalda297f062015-04-02 00:23:46 +0000635
Nils Diewald7c8ced22015-04-15 19:21:00 +0000636 it('should be rendered async 1', function (done) {
637 var info = matchClass.create(match).info();
638 expect(info).toBeTruthy();
Akron5b1a6af2018-02-05 15:41:16 +0100639 info.getTreeData(undefined, undefined, "spans", function (y) {
Akron671fdb92017-09-12 18:09:46 +0200640 tree = y;
641 done();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000642 });
643 });
Nils Diewalda297f062015-04-02 00:23:46 +0000644
Nils Diewald7c8ced22015-04-15 19:21:00 +0000645 it('should be rendered async 2', function () {
646 var e = tree.element();
647 expect(e.nodeName).toEqual('svg');
648 expect(e.getElementsByTagName('g').length).toEqual(48);
Nils Diewald58141332015-04-07 16:18:45 +0000649 });
650 });
Nils Diewalda297f062015-04-02 00:23:46 +0000651
Nils Diewald7c8ced22015-04-15 19:21:00 +0000652
653 describe('KorAP.MatchTreeItem', function () {
654 var matchTreeItemClass = require('match/treeitem');
655 it('should be initializable', function () {
656 var mi = matchTreeItemClass.create(['cnx/c', 'cnx', 'c'])
657 expect(mi.element().firstChild.nodeValue).toEqual('cnx/c');
658 expect(mi.lcField()).toEqual(' cnx/c');
659 expect(mi.foundry()).toEqual('cnx');
660 expect(mi.layer()).toEqual('c');
661 });
Nils Diewalda297f062015-04-02 00:23:46 +0000662 });
Nils Diewalda297f062015-04-02 00:23:46 +0000663
664
Akron671fdb92017-09-12 18:09:46 +0200665 describe('KorAP.MatchRelation', function () {
Akron41387d22018-02-02 18:10:06 +0100666 var relClass = require('match/treearc')
Akron671fdb92017-09-12 18:09:46 +0200667
668 var relExample = "<span class=\"context-left\"></span>" +
669 "<span class=\"match\">" +
670 " <span xml:id=\"token-GOE/AGA/01784-p199\">" +
671 " <span xlink:title=\"malt/d:ADV\" " +
672 " xlink:type=\"simple\" " +
673 " xlink:href=\"#token-GOE/AGA/01784-p199\">dann</span>" +
674 " </span>" +
675 " zog " +
676 " <span xlink:title=\"malt/d:SUBJ\" " +
677 " xlink:type=\"simple\" " +
678 " xlink:href=\"#token-GOE/AGA/01784-p199\">ich</span>" +
679 " <span xml:id=\"token-GOE/AGA/01784-p202\">" +
680 " <span xlink:title=\"malt/d:OBJA\" " +
681 " xlink:type=\"simple\" " +
682 " xlink:href=\"#token-GOE/AGA/01784-p199\">mich</span>" +
683 " </span>" +
684 "</span>" +
685 "<span class=\"context-right\"></span>";
686
687
688 it('should be initializable', function () {
689 var tree = relClass.create();
690 expect(tree.size()).toBe(0);
691 });
692
693 it('should be parse string data', function () {
694 var tree = relClass.create(relExample);
695 expect(tree.size()).toBe(4);
696 });
697
698
699 });
700
701
Nils Diewald7c8ced22015-04-15 19:21:00 +0000702 describe('KorAP.MatchTreeMenu', function () {
703 var matchTreeMenu = require('match/treemenu');
704 var matchTreeItem = require('match/treeitem');
705
706 it('should be initializable', function () {
Akron5b1a6af2018-02-05 15:41:16 +0100707 var menu = matchTreeMenu.create([
Akron671fdb92017-09-12 18:09:46 +0200708 ['cnx/c', 'cnx', 'c'],
709 ['xip/c', 'xip', 'c']
Nils Diewald7c8ced22015-04-15 19:21:00 +0000710 ]);
711
712 expect(menu.itemClass()).toEqual(matchTreeItem);
713 expect(menu.element().nodeName).toEqual('UL');
Akronaba7a5a2016-08-15 21:58:33 +0200714 expect(menu.element().classList.contains('visible')).toBeFalsy();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000715 expect(menu.limit()).toEqual(6);
716 menu.show();
Akronaba7a5a2016-08-15 21:58:33 +0200717 expect(menu.element().classList.contains('visible')).toBeTruthy();
Akronc1457bf2015-06-11 19:24:00 +0200718 expect(menu.item(0).active()).toBe(false);
Nils Diewald7c8ced22015-04-15 19:21:00 +0000719 });
Nils Diewalda297f062015-04-02 00:23:46 +0000720 });
hebasta999d6c12018-04-23 12:44:59 +0200721
722 //Test display and sorting of meta information
723 describe('KorAP.Meta', function(){
724
725 var metaClass = require("match/meta");
726 var met = metaClass.create(match, fields);
727 var mel = met.element();
728
729 // Meta information should be parsed into a list
730 it('should parse in a meta view', function(){
731 expect(mel.tagName).toEqual('DL');
732 expect(mel.children[0].tagName).toEqual('DIV');
733 expect(mel.children[0].children[0].tagName).toEqual('DT');
734 expect(mel.children[0].children[0].attributes[0].name).toEqual('title');
735 expect(mel.children[0].children[1].tagName).toEqual('DD');
736
737 expect(mel.children[0].children[0].firstChild.nodeValue).toEqual('author');
738 expect(mel.children[0].children[1].firstChild.nodeValue).toEqual('Sprachpfleger, u.a.');
739 expect(mel.children[0].children[0].attributes[0].value).toEqual('author');
740 });
741
742
743 /* The keywords in the meta information list should be formatted to be able
744 to chose each keyword separately in the corpusByMatch assistant. */
745 it('keywords should be formatted', function(){
746
747 //type:string or type:keyword should b not relevant
748 expect(mel.children[1].children[1].classList.contains('metakeyvalues')).toBeTruthy;
749 expect(mel.children[1].children[1].children[0].tagName).toEqual('DIV');
750 expect(mel.children[1].children[1].children[0].firstChild.nodeValue).toEqual('corenlp');
751 expect(mel.children[1].children[1].children[1].tagName).toEqual('DIV');
752 expect(mel.children[1].children[1].children[1].firstChild.nodeValue).toEqual('corenlp\/constituency');
753
754 expect(mel.children[2].children[1].classList.contains('metakeyvalues')).toBeTruthy;
755 expect(mel.children[2].children[1].children[0].tagName).toEqual('DIV');
756 expect(mel.children[2].children[1].children[0].firstChild.nodeValue).toEqual('kultur');
757 expect(mel.children[2].children[1].children[1].tagName).toEqual('DIV');
758 expect(mel.children[2].children[1].children[1].firstChild.nodeValue).toEqual('film');
759 });
760
761
762 // Meta information should be sorted alphabetically
763 it('should be alphabetically sorted', function(){
764 var a = mel.children[0].children[0].firstChild.nodeValue;
765 var b = mel.children[1].children[0].firstChild.nodeValue;
766 var c = mel.children[2].children[0].firstChild.nodeValue;
767 expect(a.localeCompare(b)).toBe(-1);
768 expect(b.localeCompare(c)).toBe(-1);
769 });
770
771});
Nils Diewald7c8ced22015-04-15 19:21:00 +0000772 // table = view.toTable();
773 // table.sortBy('');
774 // table.element();
775 // tree = view.toTree();
776 // tree.element();
Nils Diewalda297f062015-04-02 00:23:46 +0000777});