blob: 0d1615f331bba0e6d49e1e84bc865824c94fc920 [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
Akrond8692de2018-07-26 13:06:01 +02003define(['match',
4 'view/match/tokentable',
5 'view/match/relations',
6 'panel/match',
7 'match/meta',
8 'match/infolayer',
9 'match/treeitem',
10 'match/treearc',
Akron3bdac532019-03-04 13:24:43 +010011 'match/treehierarchy',
Akrond8692de2018-07-26 13:06:01 +020012 'buttongroup/menu',
Akrona0ea3c32018-12-14 18:33:48 +010013 'match/attachement',
Akrond8692de2018-07-26 13:06:01 +020014 'hint/foundries/cnx',
15 'hint/foundries/mate'], function (
16 matchClass,
17 tableClass,
18 relClass,
19 panelClass,
20 metaClass,
21 infoClass,
22 matchTreeItemClass,
23 matchRelClass,
Akron3bdac532019-03-04 13:24:43 +010024 matchHierClass,
Akrona0ea3c32018-12-14 18:33:48 +010025 matchTreeMenuClass,
26 attachementClass) {
Nils Diewald7c8ced22015-04-15 19:21:00 +000027
Akrond8692de2018-07-26 13:06:01 +020028 var available = [
29 'base/s=spans',
30 'corenlp/c=spans',
31 'corenlp/ne=tokens',
32 'corenlp/p=tokens',
33 'corenlp/s=spans',
34 'glemm/l=tokens',
35 'mate/l=tokens',
36 'mate/m=tokens',
37 'mate/p=tokens',
38 'opennlp/p=tokens',
39 'opennlp/s=spans',
40 'tt/l=tokens',
41 'tt/p=tokens',
42 'tt/s=spans'
43 ];
Nils Diewalda297f062015-04-02 00:23:46 +000044
Akrond8692de2018-07-26 13:06:01 +020045 var match = {
46 'corpusID' : 'WPD',
47 'docID' : 'UUU',
48 'textID' : '01912',
49 'matchID' : 'p121-122',
50 'textSigle' : 'WPD/UUU/01912',
51 'available' : available
Nils Diewalda297f062015-04-02 00:23:46 +000052 };
Akrond8692de2018-07-26 13:06:01 +020053
54
55 var fields = [
56 {
57 "@type": "koral:field",
58 "key": "author",
59 "type": "type:text",
60 "value": "Sprachpfleger, u.a."
61 },
62 {
63 "@type": "koral:field",
64 "key": "textClass",
Akrond45a1702018-11-19 18:15:17 +010065 "type": "type:keywords", // May not be necessary
Akrond8692de2018-07-26 13:06:01 +020066 "value": ["kultur", "film"]
67 },
68 {
69 "@type":"koral:field",
70 "key":"foundries",
71 "type":"type:string",
72 "value":[
73 "corenlp",
74 "corenlp\/constituency",
75 "corenlp\/morpho",
76 "corenlp\/sentences",
77 "dereko",
78 "dereko\/structure",
79 "dereko\/structure\/base-sentences-paragraphs-pagebreaks",
80 "opennlp",
81 "opennlp\/morpho",
82 "opennlp\/sentences"
83 ]
Akrona0ea3c32018-12-14 18:33:48 +010084 },
85 {
86 "@type": "koral:field",
87 "key": "xlink",
88 "type": "type:attachement",
89 "value": "data:application/x.korap-link;title=Cool,https://de.wikipedia.org/wiki/Beispiel"
90 },
Akrond3bb85b2019-02-08 10:15:13 +010091 {
92 "@type": "koral:field",
Akron0f700762022-01-11 17:21:16 +010093 "key": "xlink2",
94 "type": "type:attachement",
Akrond7d3ceb2022-02-07 20:13:09 +010095 "value" : "data:application/x.korap-link;example=%20Das%20war%20einfach;title=Hallo%21,https%3A%2F%2Fwww.test.de",
96 },
97 {
98 "@type": "koral:field",
99 "key": "xlink3",
100 "type": "type:attachement",
101 "value": "data:application/x.korap-link;title=Gingko-Webseite%20an%20der%20Universit%E4t%20Leipzig,http%3A%2F%2Fwww.uni-leipzig.de%2Fgingko%2F"
Akron0f700762022-01-11 17:21:16 +0100102 },
103 {
104 "@type": "koral:field",
Akrond3bb85b2019-02-08 10:15:13 +0100105 "key": "z-reference",
106 "type": "type:attachement",
107 "value": "data:,This is a reference"
Akrond7d3ceb2022-02-07 20:13:09 +0100108 },
Akrond8692de2018-07-26 13:06:01 +0200109 ];
110
111
Akron5dc31172019-05-15 18:43:48 +0200112 var snippet = "<span class=\"context-left\"><\/span>"+
113 "<span class=\"match\">" +
Akron1a780fe2019-05-21 15:59:00 +0200114 "<span class=\"cutted\"><\/span>" +
115 "Außerdem " +
Akron5dc31172019-05-15 18:43:48 +0200116 "<span title=\"cnx/l:meist\">" +
Akrond8692de2018-07-26 13:06:01 +0200117 " <span title=\"cnx/p:ADV\">" +
118 " <span title=\"cnx/syn:@PREMOD\">" +
119 " <span title=\"mate/l:meist\">" +
120 " <span title=\"mate/l:meist\">" +
121 " <span title=\"mate/p:ADV\">" +
122 " <span title=\"opennlp/p:ADV\">meist</span>" +
123 " </span>" +
124 " </span>" +
125 " </span>" +
126 " </span>" +
127 " </span>" +
128 "</span>" +
Akronad1e46a2018-09-19 15:55:40 +0200129 "<mark>" +
Akrond8692de2018-07-26 13:06:01 +0200130 "<span title=\"cnx/l:deutlich\">" +
131 " <span title=\"cnx/p:A\">" +
132 " <span title=\"cnx/syn:@PREMOD\">" +
133 " <span title=\"mate/l:deutlich\">" +
134 " <span title=\"mate/m:degree:pos\">" +
135 " <span title=\"mate/p:ADJD\">" +
136 " <span title=\"opennlp/p:ADJD\">deutlich</span>" +
137 " </span>" +
138 " </span>" +
139 " </span>" +
140 " </span>" +
141 " </span>" +
142 "</span>" +
Akronad1e46a2018-09-19 15:55:40 +0200143 "</mark>" +
Akron158fce12019-12-17 14:43:29 +0100144 "<span title=\"dgd/para:incident\">▮</span>" +
Akrond8692de2018-07-26 13:06:01 +0200145 "<span title=\"cnx/l:fähig\">" +
146 " <span title=\"cnx/l:leistung\">" +
147 " <span title=\"cnx/p:A\">" +
148 " <span title=\"cnx/p:ADJA\">" +
149 " <span title=\"cnx/syn:@NH\">" +
150 " <span title=\"mate/l:leistungsfähig\">" +
151 " <span title=\"mate/m:degree:comp\">" +
152 " <span title=\"mate/p:ADJD\">" +
153 " <span title=\"opennlp/p:ADJD\">leistungsfähiger</span>" +
154 " </span>" +
155 " </span>" +
156 " </span>" +
157 " </span>" +
158 " </span>" +
159 " </span>" +
160 " </span>" +
Akron5dc31172019-05-15 18:43:48 +0200161 "</span>" +
162 " und robust sind auch die anderen Traktoren, die hier der Übersicht wegen keine Erwähnung finden können." +
163 "<span class=\"cutted\"><\/span>" +
Akrond8692de2018-07-26 13:06:01 +0200164 "</span>";
165
166 var treeSnippet =
167 "<span class=\"context-left\"></span>" +
168 "<span class=\"match\">" +
169 " <span title=\"xip/c:MC\">" +
170 " <span title=\"xip/c:TOP\">" +
171 " <span title=\"xip/c:PP\">" +
172 " <span title=\"xip/c:PREP\">Mit</span>" +
173 " <span title=\"xip/c:NP\">" +
174 " <span title=\"xip/c:DET\">dieser</span>" +
175 " <span title=\"xip/c:NPA\">" +
176 " <span title=\"xip/c:NOUN\">Methode</span>" +
177 " </span>" +
178 " </span>" +
179 " </span>" +
180 " <span title=\"xip/c:VERB\">ist</span>" +
181 " <mark>" +
182 " <span title=\"xip/c:NP\">" +
183 " <span title=\"xip/c:PRON\">es</span>" +
184 " </span>" +
185 " <span title=\"xip/c:AP\">" +
186 " <span title=\"xip/c:ADV\">nun</span>" +
187 " <span title=\"xip/c:ADJ\">möglich</span>" +
188 " </span>" +
189 " </mark>" +
190 " <span title=\"xip/c:ADV\">z. B.</span>" +
191 " <span title=\"xip/c:NPA\">" +
192 " <span title=\"xip/c:NP\">" +
193 " <span title=\"xip/c:NOUN\">Voice</span>" +
194 " </span>" +
195 " </span>" + "(" +
196 " <span title=\"xip/c:INS\">" +
197 " <span title=\"xip/c:NPA\">" +
198 " <span title=\"xip/c:NP\">" +
199 " <span title=\"xip/c:NOUN\">Sprache</span>" +
200 " </span>" +
201 " </span>" +
202 " </span>" + ")" +
203 " <span title=\"xip/c:VERB\">bevorzugt</span>" +
204 " <span title=\"xip/c:PP\">" +
205 " <span title=\"xip/c:PREP\">in</span>" +
206 " <span title=\"xip/c:NP\">" +
207 " <span title=\"xip/c:PRON\">der</span>" +
208 " </span>" +
209 " <span title=\"xip/c:NPA\">" +
210 " <span title=\"xip/c:NP\">" +
211 " <span title=\"xip/c:NOUN\">Bridge</span>" +
212 " </span>" +
213 " </span>" +
214 " </span>" +
215 " <span title=\"xip/c:INFC\">" +
216 " <span title=\"xip/c:INS\">" +
217 " <span title=\"xip/c:VERB\">weiterzugeben</span>" +
218 " </span>" +
219 " </span>" +
220 " </span>" +
221 " </span>" +
222 "</span>" +
223 "<span class=\"context-right\"></span>";
224
Akronb7749052022-07-22 18:03:26 +0200225 var snippetDiffToken = "<span class=\"context-left\"><\/span>"+
226 "<span class=\"match\">" +
227 "<span class=\"cutted\"><\/span>" +
228 "Außerdem " +
229 "<span title=\"cnx/l:meist\">" +
230 " <span title=\"cnx/p:ADV\">" +
231 " <span title=\"cnx/syn:@PREMOD\">" +
232 " <span title=\"mate/l:meist\">" +
233 " <span title=\"mate/p:ADV\">" +
234 " <span title=\"opennlp/p:ADV\">Диес</span>" +
235 " </span>" +
236 " </span>" +
237 " </span>" +
238 " </span>" +
239 "</span>" +
240 "<mark>" +
241 "<span title=\"cnx/l:deutlich\">" +
242 " <span title=\"cnx/p:A\">" +
243 " <span title=\"cnx/syn:@PREMOD\">" +
244 " <span title=\"mate/l:deutlich\">" +
245 " <span title=\"mate/m:degree:pos\">" +
246 " <span title=\"mate/p:ADJD\">" +
247 " <span title=\"opennlp/p:ADJD\">ист</span>" +
248 " </span>" +
249 " </span>" +
250 " </span>" +
251 " </span>" +
252 " </span>" +
253 "</span>" +
254 "<span title=\"cnx/l:deutlich\">" +
255 " <span title=\"cnx/p:A\">" +
256 " <span title=\"cnx/syn:@PREMOD\">" +
257 " <span title=\"mate/l:deutlich\">" +
258 " <span title=\"mate/m:degree:pos\">" +
259 " <span title=\"mate/p:ADJD\">" +
260 " <span title=\"opennlp/p:ADJD\">Беиспиел</span>" +
261 " </span>" +
262 " </span>" +
263 " </span>" +
264 " </span>" +
265 " </span>" +
266 "</span>" +
267 "</mark>" +
268 ")" +
269 "<span class=\"cutted\"><\/span>" +
270 "</span>";
271
272
Akron3bdac532019-03-04 13:24:43 +0100273 var treeSnippetHierarchy =
274 "<span class=\"context-left\"><\/span><span class=\"match\"><span title=\"corenlp\/c:MPN\">Leonard Maltin<\/span> schrieb: „<span title=\"corenlp\/c:S\"><span title=\"corenlp\/c:NP\">Plot <span title=\"corenlp\/c:MPN\">contrivance isn‘<mark>t<\/mark> handled badly<\/span><\/span> <span title=\"corenlp\/c:PP\">in above-average programmer<\/span><\/span>“.&lt;<span title=\"corenlp\/c:S\"><span title=\"corenlp\/c:ROOT\"><span title=\"corenlp\/c:NP\">ref&gt;''<span title=\"corenlp\/c:NP\"><span title=\"corenlp\/c:CNP\">Movie &amp;amp; Video<\/span> Guide<\/span><\/span>'', <span title=\"corenlp\/c:VP\">1996 edition, <span title=\"corenlp\/c:NP\"><span title=\"corenlp\/c:CNP\">S. 210<\/span><\/span><\/span>.<\/span><\/span><\/span><span class=\"context-right\"><\/span>";
Akrond8692de2018-07-26 13:06:01 +0200275
Akron158fce12019-12-17 14:43:29 +0100276 function matchElementFactory () {
Akrond8692de2018-07-26 13:06:01 +0200277 var me = document.createElement('li');
278
279 me.setAttribute(
280 'data-available-info',
281 'base/s=spans corenlp/c=spans corenlp/ne=tokens corenlp/p=tokens' +
282 ' corenlp/s=spans glemm/l=tokens mate/l=tokens mate/m=tokens' +
283 ' mate/p=tokens opennlp/p=tokens opennlp/s=spans tt/l=tokens' +
284 ' tt/p=tokens tt/s=spans');
285
286 me.setAttribute('data-corpus-id', 'WPD');
287 me.setAttribute('data-doc-id', 'FFF');
288 me.setAttribute('data-text-id', '01460');
289 me.setAttribute('data-text-sigle', 'WPD/FFF/01460');
290 me.setAttribute('data-match-id', 'p119-120');
291 me.innerHTML = '<div><div class="snippet">check</div></div><p class="ref">me</p>';
292 return me;
293 };
294
295 function matchElementReal () {
296 var me = document.createElement('em');
297 me.innerHTML =
298 '<li data-match-id="p85183-85184"' +
299 ' data-text-sigle="GOE/AGI/00000"' +
300 ' 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"' +
301 ' 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;}"' +
302 ' id="GOE/AGI/00000#p85183-85184">' +
303 '<div>' +
304 '<div class="flag"></div>' +
305 '<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>' +
306 '</div>' +
307 '<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>' +
308 '</li>';
309 return me.firstChild;
310 };
311
312 var beforeAllFunc = function () {
313 // Override getMatchInfo API call
314 KorAP.API.getMatchInfo = function (x, param, cb) {
315 if (param['spans'] === undefined || param['spans'] === false)
316 cb({ "snippet": snippet });
317 else
318 cb({ "snippet": treeSnippet });
319 };
320 };
321
322 var afterAllFunc = function () {
323 KorAP.API.getMatchInfo = undefined;
hebasta87f1b1f2019-07-30 13:03:23 +0200324 KorAP.TreeMenu = undefined;
Akrond8692de2018-07-26 13:06:01 +0200325 var body = document.body;
hebasta87f1b1f2019-07-30 13:03:23 +0200326 var i = body.children.length - 1;
327 while (i >= 0) {
Akrond8692de2018-07-26 13:06:01 +0200328 if (body.children[i].nodeType && body.children[i].nodeType === 1) {
329 if (!body.children[i].classList.contains("jasmine_html-reporter")) {
330 body.removeChild(body.children[i]);
331 };
332 };
hebasta87f1b1f2019-07-30 13:03:23 +0200333 i--;
Akrond8692de2018-07-26 13:06:01 +0200334 };
335 };
Akron671fdb92017-09-12 18:09:46 +0200336
Nils Diewald7c8ced22015-04-15 19:21:00 +0000337 describe('KorAP.InfoLayer', function () {
Akrond8692de2018-07-26 13:06:01 +0200338 beforeAll(beforeAllFunc);
339 afterAll(afterAllFunc);
Nils Diewalda297f062015-04-02 00:23:46 +0000340
Nils Diewald7c8ced22015-04-15 19:21:00 +0000341 it('should be initializable', function () {
342 expect(
Akron671fdb92017-09-12 18:09:46 +0200343 function() { infoClass.create() }
Nils Diewald7c8ced22015-04-15 19:21:00 +0000344 ).toThrow(new Error("Missing parameters"));
Nils Diewalda297f062015-04-02 00:23:46 +0000345
Nils Diewald7c8ced22015-04-15 19:21:00 +0000346 expect(
Akron671fdb92017-09-12 18:09:46 +0200347 function() { infoClass.create("base") }
Nils Diewald7c8ced22015-04-15 19:21:00 +0000348 ).toThrow(new Error("Missing parameters"));
Nils Diewalda297f062015-04-02 00:23:46 +0000349
Nils Diewald7c8ced22015-04-15 19:21:00 +0000350 var layer = infoClass.create("base", "s");
351 expect(layer).toBeTruthy();
352 expect(layer.foundry).toEqual("base");
353 expect(layer.layer).toEqual("s");
354 expect(layer.type).toEqual("tokens");
Nils Diewalda297f062015-04-02 00:23:46 +0000355
Nils Diewald7c8ced22015-04-15 19:21:00 +0000356 layer = infoClass.create("cnx", "syn", "spans");
357 expect(layer).toBeTruthy();
358 expect(layer.foundry).toEqual("cnx");
359 expect(layer.layer).toEqual("syn");
360 expect(layer.type).toEqual("spans");
Nils Diewald58141332015-04-07 16:18:45 +0000361 });
362 });
Nils Diewalda297f062015-04-02 00:23:46 +0000363
Nils Diewalda297f062015-04-02 00:23:46 +0000364
Nils Diewald7c8ced22015-04-15 19:21:00 +0000365 describe('KorAP.Match', function () {
Akrond8692de2018-07-26 13:06:01 +0200366 beforeAll(beforeAllFunc);
367 afterAll(afterAllFunc);
368
Nils Diewald7c8ced22015-04-15 19:21:00 +0000369 var match = {
370 'corpusID' : 'WPD',
371 'docID' : 'UUU',
372 'textID' : '01912',
373 'matchID' : 'p121-122',
Akron0a6768f2016-07-13 18:00:43 +0200374 'textSigle' : 'WPD/UUU/01912',
Nils Diewald7c8ced22015-04-15 19:21:00 +0000375 'available' : available
376 };
377
Nils Diewald7c8ced22015-04-15 19:21:00 +0000378 it('should be initializable by Object', function () {
379 expect(function() {
Akron671fdb92017-09-12 18:09:46 +0200380 matchClass.create()
Nils Diewald7c8ced22015-04-15 19:21:00 +0000381 }).toThrow(new Error('Missing parameters'));
382
383 expect(matchClass.create(match)).toBeTruthy();
384
385 var m = matchClass.create(match);
Akron0a6768f2016-07-13 18:00:43 +0200386 expect(m.textSigle).toEqual("WPD/UUU/01912");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000387 expect(m.matchID).toEqual("p121-122");
388
389 // /corpus/WPD/UUU.01912/p121-122/matchInfo?spans=false&foundry=*
390 var m = matchClass.create(match);
391
392 // Spans:
393 var spans = m.getSpans();
394 expect(spans[0].foundry).toEqual("base");
395 expect(spans[0].layer).toEqual("s");
396
397 expect(spans[1].foundry).toEqual("corenlp");
398 expect(spans[1].layer).toEqual("c");
399
400 expect(spans[2].foundry).toEqual("corenlp");
401 expect(spans[2].layer).toEqual("s");
402
403 expect(spans[spans.length-1].foundry).toEqual("tt");
404 expect(spans[spans.length-1].layer).toEqual("s");
405
406 // Tokens:
407 var tokens = m.getTokens();
408 expect(tokens[0].foundry).toEqual("corenlp");
409 expect(tokens[0].layer).toEqual("ne");
410
411 expect(tokens[1].foundry).toEqual("corenlp");
412 expect(tokens[1].layer).toEqual("p");
413
414 expect(tokens[tokens.length-1].foundry).toEqual("tt");
415 expect(tokens[tokens.length-1].layer).toEqual("p");
Nils Diewald58141332015-04-07 16:18:45 +0000416 });
Nils Diewalda297f062015-04-02 00:23:46 +0000417
418
Akroncdb0baa2016-11-07 01:52:11 +0100419 it('should be initializable by Node 1', function () {
Nils Diewald7c8ced22015-04-15 19:21:00 +0000420 var m = matchClass.create(matchElementFactory());
Akron0a6768f2016-07-13 18:00:43 +0200421 expect(m.textSigle).toEqual("WPD/FFF/01460");
Nils Diewald7c8ced22015-04-15 19:21:00 +0000422 expect(m.matchID).toEqual("p119-120");
Nils Diewalda297f062015-04-02 00:23:46 +0000423
Nils Diewald7c8ced22015-04-15 19:21:00 +0000424 // Spans:
425 var spans = m.getSpans();
426 expect(spans[0].foundry).toEqual("base");
427 expect(spans[0].layer).toEqual("s");
Nils Diewalda297f062015-04-02 00:23:46 +0000428
Nils Diewald7c8ced22015-04-15 19:21:00 +0000429 expect(spans[1].foundry).toEqual("corenlp");
430 expect(spans[1].layer).toEqual("c");
Nils Diewalda297f062015-04-02 00:23:46 +0000431
Nils Diewald7c8ced22015-04-15 19:21:00 +0000432 expect(spans[2].foundry).toEqual("corenlp");
433 expect(spans[2].layer).toEqual("s");
Nils Diewalda297f062015-04-02 00:23:46 +0000434
Nils Diewald7c8ced22015-04-15 19:21:00 +0000435 expect(spans[spans.length-1].foundry).toEqual("tt");
436 expect(spans[spans.length-1].layer).toEqual("s");
Nils Diewalda297f062015-04-02 00:23:46 +0000437
Nils Diewald7c8ced22015-04-15 19:21:00 +0000438 // Tokens:
439 var tokens = m.getTokens();
440 expect(tokens[0].foundry).toEqual("corenlp");
441 expect(tokens[0].layer).toEqual("ne");
Nils Diewalda297f062015-04-02 00:23:46 +0000442
Nils Diewald7c8ced22015-04-15 19:21:00 +0000443 expect(tokens[1].foundry).toEqual("corenlp");
444 expect(tokens[1].layer).toEqual("p");
Nils Diewalda297f062015-04-02 00:23:46 +0000445
Nils Diewald7c8ced22015-04-15 19:21:00 +0000446 expect(tokens[tokens.length-1].foundry).toEqual("tt");
447 expect(tokens[tokens.length-1].layer).toEqual("p");
Nils Diewalda297f062015-04-02 00:23:46 +0000448
Nils Diewald7c8ced22015-04-15 19:21:00 +0000449 });
Nils Diewalda297f062015-04-02 00:23:46 +0000450
Akroncdb0baa2016-11-07 01:52:11 +0100451 it('should be initializable by Node 2', function () {
452 var ele = matchElementReal();
453 var m = matchClass.create(ele);
454 expect(m.textSigle).toEqual("GOE/AGI/00000");
455 expect(m.matchID).toEqual("p85183-85184");
456 });
457
Akron3c390c42020-03-30 09:06:21 +0200458 it('should be initializable when active', function () {
459 var e = matchElementFactory();
460 e.setAttribute('class', 'active');
461
462 expect(e.classList.contains('active')).toBe(true);
463 expect(e["_match"]).toBe(undefined);
464
465 var m = matchClass.create(e);
466
467 expect(e["_match"]).not.toBe(undefined);
468
469 // Open the match
470 m.init();
471
472 expect(e["_match"]).not.toBe(undefined);
473
474 actions = e.querySelector("p.ref > div.action.button-group").children;
475
476 expect(actions[0].getAttribute("class")).toEqual("metatable");
477 expect(actions[1].getAttribute("class")).toEqual("info");
478 expect(actions[2].getAttribute("class")).toEqual("tree");
479
480 // Close the match
481 expect(e.querySelector("div.action.button-group > span.minimize")).toBe(null);
482 });
Akroncdb0baa2016-11-07 01:52:11 +0100483
Nils Diewald7c8ced22015-04-15 19:21:00 +0000484 it('should react to gui actions', function () {
485 var e = matchElementFactory();
Nils Diewalda297f062015-04-02 00:23:46 +0000486
Nils Diewald7c8ced22015-04-15 19:21:00 +0000487 expect(e.classList.contains('active')).toBe(false);
488 expect(e["_match"]).toBe(undefined);
Nils Diewalda297f062015-04-02 00:23:46 +0000489
Nils Diewald7c8ced22015-04-15 19:21:00 +0000490 var m = matchClass.create(e);
491
492 expect(e.classList.contains('active')).toBe(false);
493 expect(e["_match"]).not.toBe(undefined);
hebasta87f1b1f2019-07-30 13:03:23 +0200494
Nils Diewald7c8ced22015-04-15 19:21:00 +0000495 // Open the match
496 m.open();
hebasta87f1b1f2019-07-30 13:03:23 +0200497
Nils Diewald7c8ced22015-04-15 19:21:00 +0000498 expect(e.classList.contains('active')).toBe(true);
499 expect(e["_match"]).not.toBe(undefined);
500
Akronbfe912c2018-07-17 19:30:52 +0200501 actions = e.querySelector("p.ref > div.action.button-group").children;
Akrond141a362018-07-10 18:12:13 +0200502
Akronbfe912c2018-07-17 19:30:52 +0200503 expect(actions[0].getAttribute("class")).toEqual("metatable");
Akronc296ca22018-04-24 16:35:26 +0200504 expect(actions[1].getAttribute("class")).toEqual("info");
505 expect(actions[2].getAttribute("class")).toEqual("tree");
Akron3c390c42020-03-30 09:06:21 +0200506
507 expect(e.querySelector("div.action.button-group > span.minimize")).not.toBe(null);
Akronc296ca22018-04-24 16:35:26 +0200508
Nils Diewald7c8ced22015-04-15 19:21:00 +0000509 // Close the match
Akronec6bb8e2018-08-29 13:07:56 +0200510 m.minimize();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000511 expect(e.classList.contains('active')).toBe(false);
512 expect(e["_match"]).not.toBe(undefined);
Nils Diewald58141332015-04-07 16:18:45 +0000513 });
Akrone57e8802020-10-17 08:23:45 +0200514
515 it('should toggle', function () {
516 var e = matchElementFactory();
517
518 expect(e.classList.contains('active')).toBe(false);
519 expect(e["_match"]).toBe(undefined);
520
521 var m = matchClass.create(e);
522
523 expect(e.classList.contains('active')).toBe(false);
524 expect(e["_match"]).not.toBe(undefined);
525
526 // Open the match
527 m.open();
528
529 expect(e.classList.contains('active')).toBe(true);
530 expect(e["_match"]).not.toBe(undefined);
531
532 m.toggle();
533
534 expect(e.classList.contains('active')).toBe(false);
535 expect(e["_match"]).not.toBe(undefined);
536
537 m.toggle();
538
539 expect(e.classList.contains('active')).toBe(true);
540 expect(e["_match"]).not.toBe(undefined);
541 });
542
Akrond8692de2018-07-26 13:06:01 +0200543 it('should open tree menu', function () {
Akronc296ca22018-04-24 16:35:26 +0200544 var e = matchElementFactory();
545 var m = matchClass.create(e);
546 m.open();
Akronbfe912c2018-07-17 19:30:52 +0200547 var relation = e.querySelector("p.ref > div.action.button-group > span:nth-of-type(3)");
Akronc296ca22018-04-24 16:35:26 +0200548 expect(relation.getAttribute("class")).toEqual("tree");
Akron52ed22d2018-07-11 17:05:19 +0200549 expect(document.getElementsByClassName("button-group-list").length).toEqual(0);
Akronc296ca22018-04-24 16:35:26 +0200550 expect(document.activeElement.tagName).toEqual("BODY");
hebasta87f1b1f2019-07-30 13:03:23 +0200551
Akronc296ca22018-04-24 16:35:26 +0200552 // Show menu
553 relation.click();
Akron52ed22d2018-07-11 17:05:19 +0200554 expect(document.getElementsByClassName("button-group-list").length).toEqual(1);
Akronc296ca22018-04-24 16:35:26 +0200555 expect(document.activeElement.tagName).toEqual("UL");
hebasta87f1b1f2019-07-30 13:03:23 +0200556
Akronc296ca22018-04-24 16:35:26 +0200557 // Choose first tree
Akron52ed22d2018-07-11 17:05:19 +0200558 document.getElementsByClassName("button-group-list")[0].getElementsByTagName("li")[1].click();
Akronc296ca22018-04-24 16:35:26 +0200559 expect(e.querySelector("div.matchinfo div.matchtree h6 span").innerText).toEqual("corenlp");
560
561 // This should blur the focus
562 expect(document.activeElement.tagName).toEqual("BODY");
hebasta87f1b1f2019-07-30 13:03:23 +0200563
Akronc296ca22018-04-24 16:35:26 +0200564 });
565
566 });
Nils Diewald7c8ced22015-04-15 19:21:00 +0000567
Akron7f9a6a32018-07-18 15:05:23 +0200568 describe('KorAP.TableView', function () {
Akrond8692de2018-07-26 13:06:01 +0200569 beforeAll(beforeAllFunc);
570 afterAll(afterAllFunc);
Akron5dc31172019-05-15 18:43:48 +0200571
572 let longString = " und robust sind auch die anderen Traktoren, die hier der Übersicht wegen keine Erwähnung finden können.";
573
Akron7f9a6a32018-07-18 15:05:23 +0200574 var table;
Nils Diewald7c8ced22015-04-15 19:21:00 +0000575
Akron7f9a6a32018-07-18 15:05:23 +0200576 var matchObj = matchClass.create(match);
577 var tableObj = tableClass.create(matchObj);
Nils Diewald7c8ced22015-04-15 19:21:00 +0000578
579 var table1, table2;
580
Nils Diewald7c8ced22015-04-15 19:21:00 +0000581 it('should fail to load a table async', function (done) {
Akron7f9a6a32018-07-18 15:05:23 +0200582 expect(tableObj).toBeTruthy();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000583
Akron7f9a6a32018-07-18 15:05:23 +0200584 tableObj.getData([], function (tablen) {
Akron671fdb92017-09-12 18:09:46 +0200585 table1 = tablen;
586 done();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000587 });
588 });
589
Akron671fdb92017-09-12 18:09:46 +0200590
Akronaeeb8252018-09-19 18:51:00 +0200591 xit('should\'nt be parsable (async)', function () {
Nils Diewald7c8ced22015-04-15 19:21:00 +0000592 expect(table1).not.toBeTruthy();
593 });
594
Nils Diewald7c8ced22015-04-15 19:21:00 +0000595
Nils Diewald7c8ced22015-04-15 19:21:00 +0000596 it('should be retrieved async', function (done) {
Akron7f9a6a32018-07-18 15:05:23 +0200597 expect(tableObj).toBeTruthy();
598 tableObj.getData(undefined, function (x) {
Akron671fdb92017-09-12 18:09:46 +0200599 table = x;
600 done();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000601 });
602 });
Nils Diewalda297f062015-04-02 00:23:46 +0000603
Akron7f9a6a32018-07-18 15:05:23 +0200604 it('should parse into a table (async)', function () {
605 expect(table).toBeTruthy();
Akron5b1a6af2018-02-05 15:41:16 +0100606
Akron158fce12019-12-17 14:43:29 +0100607 expect(table.length()).toBe(8);
Akron7f9a6a32018-07-18 15:05:23 +0200608
Akron1a780fe2019-05-21 15:59:00 +0200609 expect(table.getToken(0)).toBe("");
610 expect(table.getToken(1)).toBe("Außerdem ");
611 expect(table.getToken(2)).toBe("meist");
612 expect(table.getToken(3)).toBe("deutlich");
Akron158fce12019-12-17 14:43:29 +0100613 expect(table.getToken(5)).toBe("leistungsfähiger");
614 expect(table.getToken(6)).toBe(longString);
Akron7f9a6a32018-07-18 15:05:23 +0200615
Akron1a780fe2019-05-21 15:59:00 +0200616 expect(table.getValue(2, "cnx", "p")[0]).toBe("ADV");
617 expect(table.getValue(2, "cnx", "syn")[0]).toBe("@PREMOD");
618 expect(table.getValue(2, "mate", "l")[0]).toBe("meist");
619 expect(table.getValue(2, "mate", "l")[1]).toBeUndefined();
Akron7f9a6a32018-07-18 15:05:23 +0200620
Akron158fce12019-12-17 14:43:29 +0100621 expect(table.getValue(5, "cnx", "l")[0]).toBe("fähig");
622 expect(table.getValue(5, "cnx", "l")[1]).toBe("leistung");
Akron7f9a6a32018-07-18 15:05:23 +0200623 });
Akronb7749052022-07-22 18:03:26 +0200624
Akron7f9a6a32018-07-18 15:05:23 +0200625 it('should be rendered async', function () {
Akron5b1a6af2018-02-05 15:41:16 +0100626 var e = table.element().firstChild;
Nils Diewald7c8ced22015-04-15 19:21:00 +0000627 expect(e.nodeName).toBe('TABLE');
628 expect(e.children[0].nodeName).toBe('THEAD');
629 var tr = e.children[0].children[0];
630 expect(tr.nodeName).toBe('TR');
631 expect(tr.children[0].nodeName).toBe('TH');
Nils Diewald58141332015-04-07 16:18:45 +0000632
Nils Diewald7c8ced22015-04-15 19:21:00 +0000633 expect(tr.children[0].firstChild.nodeValue).toBe('Foundry');
634 expect(tr.children[1].firstChild.nodeValue).toBe('Layer');
Akron1a780fe2019-05-21 15:59:00 +0200635
636 expect(tr.children[2].classList.contains('cutted')).toBeTruthy();
637 expect(tr.children[3].firstChild.nodeValue).toBe('Außerdem ');
638
639
640 expect(tr.children[4].firstChild.nodeValue).toBe('meist');
Akronad1e46a2018-09-19 15:55:40 +0200641 expect(tr.children[4].classList.contains('mark')).toBeFalsy();
Akron1a780fe2019-05-21 15:59:00 +0200642 expect(tr.children[5].firstChild.nodeValue).toBe('deutlich');
643 expect(tr.children[5].classList.contains('mark')).toBeTruthy();
Akron158fce12019-12-17 14:43:29 +0100644 expect(tr.children[6].firstChild.nodeValue).toBe('▮');
645 expect(tr.children[7].firstChild.nodeValue).toBe('leistungsfähiger');
646 expect(tr.children[7].classList.contains('mark')).toBeFalsy();
647 expect(tr.children[7].hasAttribute("title")).toBeFalsy();
648 expect(tr.children[8].firstChild.nodeValue).toBe(longString);
649 expect(tr.children[8].getAttribute("title")).toBe(longString);
650 expect(tr.children[9].classList.contains('cutted')).toBeTruthy();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000651
652 // first row
653 tr = e.children[1].children[0];
654 expect(tr.nodeName).toBe('TR');
655 expect(tr.getAttribute('tabindex')).toEqual('0');
656 expect(tr.children[0].nodeName).toBe('TH');
657 expect(tr.children[0].firstChild.nodeValue).toEqual('cnx');
658 expect(tr.children[1].firstChild.nodeValue).toEqual('l');
Akron1a780fe2019-05-21 15:59:00 +0200659 expect(tr.children[4].firstChild.nodeValue).toEqual('meist');
660 expect(tr.children[5].firstChild.nodeValue).toEqual('deutlich');
Akron158fce12019-12-17 14:43:29 +0100661 expect(tr.children[6].firstChild).toBeNull();
662 expect(tr.children[7].firstChild.firstChild.nodeValue).toEqual('fähig');
663 expect(tr.children[7].lastChild.firstChild.nodeValue).toEqual('leistung');
Nils Diewald7c8ced22015-04-15 19:21:00 +0000664
665 // second row
666 tr = e.children[1].children[1];
667 expect(tr.nodeName).toBe('TR');
668 expect(tr.getAttribute('tabindex')).toEqual('0');
669 expect(tr.children[0].nodeName).toBe('TH');
670 expect(tr.children[0].firstChild.nodeValue).toEqual('cnx');
671 expect(tr.children[1].firstChild.nodeValue).toEqual('p');
Akron1a780fe2019-05-21 15:59:00 +0200672 expect(tr.children[4].firstChild.nodeValue).toEqual('ADV');
673 expect(tr.children[5].firstChild.nodeValue).toEqual('A');
Akron158fce12019-12-17 14:43:29 +0100674 expect(tr.children[6].firstChild).toBeNull();
675 expect(tr.children[7].firstChild.firstChild.nodeValue).toEqual('A');
676 expect(tr.children[7].lastChild.firstChild.nodeValue).toEqual('ADJA');
Akronf2279c42017-12-21 13:48:46 +0100677
Akron158fce12019-12-17 14:43:29 +0100678 expect(tr.children[7].firstChild.getAttribute("title")).toEqual('Adjective');
Akron1a780fe2019-05-21 15:59:00 +0200679 expect(tr.children[4].getAttribute("title")).toEqual('Adverb');
Nils Diewald58141332015-04-07 16:18:45 +0000680 });
Akron7f9a6a32018-07-18 15:05:23 +0200681
682
683 it('should parse into a table view (sync)', function () {
684 var matchElement = matchElementFactory();
685 expect(matchElement.tagName).toEqual('LI');
686
687 // Match
688 expect(matchElement.children[0].tagName).toEqual('DIV');
689
690 // snippet
691 expect(matchElement.children[0].children[0].tagName).toEqual('DIV');
692 expect(matchElement.children[0].children[0].classList.contains('snippet')).toBeTruthy();
693 expect(matchElement.children[0].children[0].firstChild.nodeValue).toEqual('check');
694
695 // reference
696 expect(matchElement.children[1].classList.contains('ref')).toBeTruthy();
697 expect(matchElement.children[1].firstChild.nodeValue).toEqual('me');
698
699 // not yet
700 expect(matchElement.children[0].children[1]).toBe(undefined);
701
702 /*
703 var info = matchClass.create(matchElement).info();
704 info.showTable();
705 */
706 var matchObj = matchClass.create(matchElement);
707 matchObj.open();
708
709 // Match
710 expect(matchElement.children[0].tagName).toEqual('DIV');
711
712 // snippet
713 expect(matchElement.children[0].children[0].tagName).toEqual('DIV');
714
715 expect(matchElement.children[0].children[0].classList.contains('snippet')).toBeTruthy();
716
717 expect(matchElement.children[0].children[0].firstChild.nodeValue).toEqual('check');
718
719 // reference
720
721 expect(matchElement.children[2].classList.contains('ref')).toBeTruthy();
722 expect(matchElement.children[2].childNodes[1].nodeValue).toEqual('me');
723
724 // Add table
725 matchObj.panel.addTable();
726
727 // now
728 var infotable = matchElement.children[1];
729 expect(infotable.tagName).toEqual('DIV');
730
731 expect(infotable.classList.contains('matchinfo')).toBeTruthy();
732
733 expect(infotable.firstChild.firstChild.firstChild.classList.contains('matchtable')).toBeTruthy();
734
735 // expect(infotable.children[1].classList.contains('addtree')).toBeTruthy();
736 });
737
Akron158fce12019-12-17 14:43:29 +0100738 it('should parse into a table view with non-verbal elements (sync)', function () {
739 var matchElement = matchElementFactory();
740 expect(matchElement.tagName).toEqual('LI');
741 });
742
Akronb7749052022-07-22 18:03:26 +0200743 it('should parse into a table with non-latin characters', function () {
744 var matchElement = matchElementFactory();
745 expect(matchElement.tagName).toEqual('LI');
746
747 // Match
748 expect(matchElement.children[0].tagName).toEqual('DIV');
749
750 // snippet
751 expect(matchElement.children[0].children[0].tagName).toEqual('DIV');
752 expect(matchElement.children[0].children[0].classList.contains('snippet')).toBeTruthy();
753 expect(matchElement.children[0].children[0].firstChild.nodeValue).toEqual('check');
754
755 // reference
756 expect(matchElement.children[1].classList.contains('ref')).toBeTruthy();
757 expect(matchElement.children[1].firstChild.nodeValue).toEqual('me');
758
759 // not yet
760 expect(matchElement.children[0].children[1]).toBe(undefined);
761
762 /*
763 var info = matchClass.create(matchElement).info();
764 info.showTable();
765 */
766 var matchObj = matchClass.create(matchElement);
767 matchObj.open();
768
769 // Match
770 expect(matchElement.children[0].tagName).toEqual('DIV');
771
772 // snippet
773 expect(matchElement.children[0].children[0].tagName).toEqual('DIV');
774
775 expect(matchElement.children[0].children[0].classList.contains('snippet')).toBeTruthy();
776
777 expect(matchElement.children[0].children[0].firstChild.nodeValue).toEqual('check');
778
779 // reference
780
781 expect(matchElement.children[2].classList.contains('ref')).toBeTruthy();
782 expect(matchElement.children[2].childNodes[1].nodeValue).toEqual('me');
783
784 // Add table
785 matchObj.panel.addTable();
786
787 // now
788 var infotable = matchElement.children[1];
789 expect(infotable.tagName).toEqual('DIV');
790
791 expect(infotable.classList.contains('matchinfo')).toBeTruthy();
792
793 expect(infotable.firstChild.firstChild.firstChild.classList.contains('matchtable')).toBeTruthy();
794
795 // expect(infotable.children[1].classList.contains('addtree')).toBeTruthy();
796 });
797
798 it('should parse into a table view with all non-latin characters (sync)', function () {
799
800 // Override getMatchInfo API call
801 KorAP.API.getMatchInfo = function (x, param, cb) {
802 cb({ "snippet": snippetDiffToken });
803 };
804
805 var matchElement = matchElementFactory();
806 expect(matchElement.tagName).toEqual('LI');
807
808 // Match
809 expect(matchElement.children[0].tagName).toEqual('DIV');
810
811 var matchObj = matchClass.create(matchElement);
812 matchObj.open();
813
814 // Match
815 expect(matchElement.children[0].tagName).toEqual('DIV');
816
817 // snippet
818 expect(matchElement.children[0].children[0].tagName).toEqual('DIV');
819
820 // Add table
821 matchObj.panel.addTable();
822
823 // now
824 var infotable = matchElement.children[1];
825 expect(infotable.tagName).toEqual('DIV');
826
827 expect(infotable.classList.contains('matchinfo')).toBeTruthy();
828
829 expect(infotable.firstChild.firstChild.firstChild.classList.contains('matchtable')).toBeTruthy();
830
831 let matchTable = infotable.firstChild.firstChild.firstChild;
832 expect(matchTable.querySelectorAll("th:not(.cutted).no-anno")[0].textContent).toEqual('Außerdem ');
833 expect(matchTable.getElementsByTagName('TH')[4].textContent).toEqual('Диес');
834 expect(matchTable.querySelectorAll("tbody tr:nth-child(1) td")[0].classList.contains('not-empty')).toBeFalsy();
835 expect(matchTable.querySelectorAll("tbody tr:nth-child(1) td")[1].classList.contains('not-empty')).toBeFalsy();
836 expect(matchTable.querySelectorAll("tbody tr:nth-child(1) td")[2].classList.contains('not-empty')).toBeFalsy();
837 expect(matchTable.querySelectorAll("tbody tr:nth-child(5) td")[0].classList.contains('not-empty')).toBeFalsy();
838 expect(matchTable.querySelectorAll("tbody tr:nth-child(5) td")[1].classList.contains('not-empty')).toBeFalsy();
839 expect(matchTable.querySelectorAll("tbody tr:nth-child(5) td")[2].classList.contains('not-empty')).toBeTruthy();
840 });
841
Nils Diewald58141332015-04-07 16:18:45 +0000842 });
Nils Diewalda297f062015-04-02 00:23:46 +0000843
Akron7f9a6a32018-07-18 15:05:23 +0200844 describe('KorAP.RelationsView', function () {
Akrond8692de2018-07-26 13:06:01 +0200845 beforeAll(beforeAllFunc);
846 afterAll(afterAllFunc);
847
Nils Diewald7c8ced22015-04-15 19:21:00 +0000848 var tree;
Nils Diewalda297f062015-04-02 00:23:46 +0000849
Nils Diewald7c8ced22015-04-15 19:21:00 +0000850 it('should be rendered async 1', function (done) {
Akron7f9a6a32018-07-18 15:05:23 +0200851 var matchObj = matchClass.create(match);
852 var relObj = relClass.create(matchObj);
853 expect(relObj).toBeTruthy();
854 relObj.getData(undefined, undefined, "spans", function (y) {
Akron671fdb92017-09-12 18:09:46 +0200855 tree = y;
856 done();
Nils Diewald7c8ced22015-04-15 19:21:00 +0000857 });
858 });
Nils Diewalda297f062015-04-02 00:23:46 +0000859
Nils Diewald7c8ced22015-04-15 19:21:00 +0000860 it('should be rendered async 2', function () {
Akron7f9a6a32018-07-18 15:05:23 +0200861 expect(tree).toBeTruthy();
862 expect(tree.nodes()).toEqual(49);
863
Nils Diewald7c8ced22015-04-15 19:21:00 +0000864 var e = tree.element();
865 expect(e.nodeName).toEqual('svg');
866 expect(e.getElementsByTagName('g').length).toEqual(48);
Nils Diewald58141332015-04-07 16:18:45 +0000867 });
Akron7f9a6a32018-07-18 15:05:23 +0200868
869
870 it('should add a tree view async 2', function () {
871 var matchElement = matchElementFactory();
872 var matchObj = matchClass.create(matchElement);
873 matchObj.open();
874 matchObj.panel.addTree('mate', 'beebop', 'spans', function () {
875 done();
876 });
877
878 // With added tree
879 var tree = matchElement.children[1].firstChild.firstChild.firstChild;
880 expect(tree.tagName).toEqual('DIV');
881 expect(tree.classList.contains('matchtree')).toBeTruthy();
882 expect(tree.children[0].tagName).toEqual('H6');
883 expect(tree.children[0].children[0].tagName).toEqual('SPAN');
884 expect(tree.children[0].children[0].firstChild.nodeValue).toEqual('mate');
885 expect(tree.children[0].children[1].tagName).toEqual('SPAN');
886 expect(tree.children[0].children[1].firstChild.nodeValue).toEqual('beebop');
887
888 expect(tree.children[1].tagName).toEqual('DIV');
889 });
890
Akron3bdac532019-03-04 13:24:43 +0100891 it('should make the tree downloadable', function () {
892 var treeClass = matchHierClass.create(treeSnippetHierarchy);
893 var treeElement = treeClass.element();
894 expect(treeElement.tagName).toEqual("svg");
895
896 var base64 = treeClass.toBase64();
897 var str = atob(base64);
898 expect(str).toMatch(new RegExp('<defs><style>path'));
899 expect(str).not.toMatch(new RegExp('&nbsp;'));
900 expect(str).toMatch(new RegExp('&amp;'));
901 });
Nils Diewald58141332015-04-07 16:18:45 +0000902 });
Nils Diewalda297f062015-04-02 00:23:46 +0000903
Nils Diewald7c8ced22015-04-15 19:21:00 +0000904
905 describe('KorAP.MatchTreeItem', function () {
Akrond8692de2018-07-26 13:06:01 +0200906 beforeAll(beforeAllFunc);
907 afterAll(afterAllFunc);
908
Nils Diewald7c8ced22015-04-15 19:21:00 +0000909 it('should be initializable', function () {
910 var mi = matchTreeItemClass.create(['cnx/c', 'cnx', 'c'])
911 expect(mi.element().firstChild.nodeValue).toEqual('cnx/c');
912 expect(mi.lcField()).toEqual(' cnx/c');
913 expect(mi.foundry()).toEqual('cnx');
914 expect(mi.layer()).toEqual('c');
915 });
Nils Diewalda297f062015-04-02 00:23:46 +0000916 });
Nils Diewalda297f062015-04-02 00:23:46 +0000917
918
Akron671fdb92017-09-12 18:09:46 +0200919 describe('KorAP.MatchRelation', function () {
Akrond8692de2018-07-26 13:06:01 +0200920 beforeAll(beforeAllFunc);
921 afterAll(afterAllFunc);
Akron671fdb92017-09-12 18:09:46 +0200922
923 var relExample = "<span class=\"context-left\"></span>" +
924 "<span class=\"match\">" +
925 " <span xml:id=\"token-GOE/AGA/01784-p199\">" +
926 " <span xlink:title=\"malt/d:ADV\" " +
927 " xlink:type=\"simple\" " +
928 " xlink:href=\"#token-GOE/AGA/01784-p199\">dann</span>" +
929 " </span>" +
930 " zog " +
931 " <span xlink:title=\"malt/d:SUBJ\" " +
932 " xlink:type=\"simple\" " +
933 " xlink:href=\"#token-GOE/AGA/01784-p199\">ich</span>" +
934 " <span xml:id=\"token-GOE/AGA/01784-p202\">" +
935 " <span xlink:title=\"malt/d:OBJA\" " +
936 " xlink:type=\"simple\" " +
937 " xlink:href=\"#token-GOE/AGA/01784-p199\">mich</span>" +
938 " </span>" +
939 "</span>" +
940 "<span class=\"context-right\"></span>";
941
942
943 it('should be initializable', function () {
Akrond8692de2018-07-26 13:06:01 +0200944 var tree = matchRelClass.create();
Akron671fdb92017-09-12 18:09:46 +0200945 expect(tree.size()).toBe(0);
946 });
947
948 it('should be parse string data', function () {
Akrond8692de2018-07-26 13:06:01 +0200949 var tree = matchRelClass.create(relExample);
Akron671fdb92017-09-12 18:09:46 +0200950 expect(tree.size()).toBe(4);
951 });
Akron0a785d42020-10-12 17:21:46 +0200952
953 it('should accept missing data', function () {
954 var relExample2 = "<span class=\"context-left\"><\/span>"+
955 "<span class=\"match\">"+
956 "{{"+
957 "<span xml:id=\"token-WUD17\/D95\/09441-p180\">"+
958 "<span xlink:title=\"malt\/d:APP\" xlink:show=\"none\" xlink:href=\"#token-WUD17\/D95\/09441-p179\">Wikiläum<\/span>"+
959 "<\/span>"+
960 "|"+
961 "<span xlink:title=\"malt\/d:APP\" xlink:show=\"none\" xlink:href=\"#token-WUD17\/D95\/09441-p180\">Silber<\/span>"+
962 "|"+
963 "<span xlink:title=\"malt\/d:DET\" xlink:show=\"none\" xlink:href=\"#token-WUD17\/D95\/09441-p183\">Dein<\/span>"+
964 " "+
965 "<span xml:id=\"token-WUD17\/D95\/09441-p183\">"+
966 "<span xlink:title=\"malt\/d:ROOT\" xlink:show=\"none\" xlink:href=\"#token-WUD17\/D95\/09441-p179-196\">Freund<\/span>"+
967 "<\/span>"+
968 " "+
969 "<span xlink:title=\"malt\/d:DET\" xlink:show=\"none\" xlink:href=\"#token-WUD17\/D95\/09441-p185\">der<\/span>"+
970 " "+
971 "<span xml:id=\"token-WUD17\/D95\/09441-p185-186\">"+
972 "<span xml:id=\"token-WUD17\/D95\/09441-p185\">"+
973 "<mark>"+
974 "<span xlink:title=\"malt\/d:GMOD\" xlink:show=\"none\" xlink:href=\"#token-WUD17\/D95\/09441-p183\">Baum<\/span>"+
975 "<\/mark>"+
976 "<\/span>"+
977 "| "+
978 "<span xlink:title=\"malt\/d:APP\" xlink:show=\"none\" xlink:href=\"#token-WUD17\/D95\/09441-p185-186\">09:38<\/span>"+
979 "<\/span>"+
980 ", "+
981 "<span xlink:title=\"malt\/d:ATTR\" xlink:show=\"none\" xlink:href=\"#token-WUD17\/D95\/09441-p188\">22.<\/span>"+
982 " "+
983 "<span xml:id=\"token-WUD17\/D95\/09441-p188\">"+
984 "<span xlink:title=\"malt\/d:APP\" xlink:show=\"none\" xlink:href=\"#token-WUD17\/D95\/09441-p183\">Aug.<\/span>"+
985 "<\/span>"+
986 " "+
987 "<span xml:id=\"token-WUD17\/D95\/09441-p189\">"+
988 "<span xlink:title=\"malt\/d:APP\" xlink:show=\"none\" xlink:href=\"#token-WUD17\/D95\/09441-p188\">2015<\/span>"+
989 "<\/span>"+
990 " ("+
991 "<span xlink:title=\"malt\/d:PAR\" xlink:show=\"none\" xlink:href=\"#token-WUD17\/D95\/09441-p189\">CEST<\/span>"+
992 ")"+
993 "<\/span>"+
994 "<span class=\"context-right\"><\/span>";
995 var tree = matchRelClass.create(relExample2);
996 expect(tree.size()).toBe(18);
997 var treeElement = tree.element();
998 expect(treeElement.tagName).toEqual("svg");
999 tree.show();
1000 expect(treeElement.querySelector("text[text-anchor=\"middle\"]").textContent).toEqual("APP");
1001 });
Akron671fdb92017-09-12 18:09:46 +02001002 });
1003
1004
Nils Diewald7c8ced22015-04-15 19:21:00 +00001005 describe('KorAP.MatchTreeMenu', function () {
Akrond8692de2018-07-26 13:06:01 +02001006 beforeAll(beforeAllFunc);
1007 afterAll(afterAllFunc);
Nils Diewald7c8ced22015-04-15 19:21:00 +00001008
1009 it('should be initializable', function () {
Akrond8692de2018-07-26 13:06:01 +02001010 var menu = matchTreeMenuClass.create([
Akron671fdb92017-09-12 18:09:46 +02001011 ['cnx/c', 'cnx', 'c'],
1012 ['xip/c', 'xip', 'c']
Akrond8692de2018-07-26 13:06:01 +02001013 ], matchTreeItemClass);
Nils Diewald7c8ced22015-04-15 19:21:00 +00001014
Akrond8692de2018-07-26 13:06:01 +02001015 expect(menu.itemClass()).toEqual(matchTreeItemClass);
Nils Diewald7c8ced22015-04-15 19:21:00 +00001016 expect(menu.element().nodeName).toEqual('UL');
Akronaba7a5a2016-08-15 21:58:33 +02001017 expect(menu.element().classList.contains('visible')).toBeFalsy();
Nils Diewald7c8ced22015-04-15 19:21:00 +00001018 expect(menu.limit()).toEqual(6);
1019 menu.show();
Akronaba7a5a2016-08-15 21:58:33 +02001020 expect(menu.element().classList.contains('visible')).toBeTruthy();
Akronc1457bf2015-06-11 19:24:00 +02001021 expect(menu.item(0).active()).toBe(false);
Nils Diewald7c8ced22015-04-15 19:21:00 +00001022 });
Nils Diewalda297f062015-04-02 00:23:46 +00001023 });
hebasta999d6c12018-04-23 12:44:59 +02001024
1025 //Test display and sorting of meta information
1026 describe('KorAP.Meta', function(){
Akrond8692de2018-07-26 13:06:01 +02001027 beforeAll(beforeAllFunc);
1028 afterAll(afterAllFunc);
1029
1030 var met = metaClass.create(match, fields);
hebasta999d6c12018-04-23 12:44:59 +02001031 var mel = met.element();
1032
1033 // Meta information should be parsed into a list
1034 it('should parse in a meta view', function(){
Akronfa32c9d2018-11-20 15:39:18 +01001035 expect(mel.tagName).toEqual('DL');
1036 expect(mel.children[0].tagName).toEqual('DIV');
1037 expect(mel.children[0].children[0].tagName).toEqual('DT');
1038 expect(mel.children[0].children[0].attributes[0].name).toEqual('title');
1039 expect(mel.children[0].children[1].tagName).toEqual('DD');
1040 expect(mel.children[0].children[1].getAttribute('data-type')).toEqual('type:text')
hebasta999d6c12018-04-23 12:44:59 +02001041
Akronfa32c9d2018-11-20 15:39:18 +01001042 expect(mel.children[0].children[0].firstChild.nodeValue).toEqual('author');
1043 expect(mel.children[0].children[1].firstChild.nodeValue).toEqual('Sprachpfleger, u.a.');
1044 expect(mel.children[0].children[0].attributes[0].value).toEqual('author');
hebasta999d6c12018-04-23 12:44:59 +02001045 });
1046
1047
Akronfa32c9d2018-11-20 15:39:18 +01001048 /* The keywords in the meta information list should be formatted to be able
1049 to chose each keyword separately in the corpusByMatch assistant. */
1050 it('keywords should be formatted', function(){
hebasta999d6c12018-04-23 12:44:59 +02001051
Akronfa32c9d2018-11-20 15:39:18 +01001052 //type:string or type:keyword should b not relevant
1053 expect(mel.children[1].children[1].getAttribute('data-type')).toEqual('type:string')
1054 expect(mel.children[1].children[1].classList.contains('metakeyvalues')).toBeTruthy;
1055 expect(mel.children[1].children[1].children[0].tagName).toEqual('DIV');
1056 expect(mel.children[1].children[1].children[0].firstChild.nodeValue).toEqual('corenlp');
1057 expect(mel.children[1].children[1].children[1].tagName).toEqual('DIV');
1058 expect(mel.children[1].children[1].children[1].firstChild.nodeValue).toEqual('corenlp\/constituency');
1059
1060 expect(mel.children[2].children[1].classList.contains('metakeyvalues')).toBeTruthy;
1061 expect(mel.children[2].children[1].children[0].tagName).toEqual('DIV');
1062 expect(mel.children[2].children[1].children[0].firstChild.nodeValue).toEqual('kultur');
1063 expect(mel.children[2].children[1].children[1].tagName).toEqual('DIV');
1064 expect(mel.children[2].children[1].children[1].firstChild.nodeValue).toEqual('film');
hebasta999d6c12018-04-23 12:44:59 +02001065 });
Akrona0ea3c32018-12-14 18:33:48 +01001066
1067 it('attachements should be formatted', function(){
Akron0f700762022-01-11 17:21:16 +01001068 //type:attachement with a link (legacy)
Akrona0ea3c32018-12-14 18:33:48 +01001069 expect(mel.children[3].children[1].getAttribute('data-type')).toEqual('type:attachement')
Akron0f700762022-01-11 17:21:16 +01001070 expect(mel.children[3].children[1].classList.contains('metakeyvalues')).toBeFalsy;
1071 expect(mel.children[3].children[0].firstChild.nodeValue).toEqual('xlink');
1072 expect(mel.children[3].children[1].firstChild.textContent).toEqual('Cool');
1073 expect(mel.children[3].children[1].firstChild.tagName).toEqual('A');
Akrona0ea3c32018-12-14 18:33:48 +01001074 expect(mel.children[3].children[1].firstChild.getAttribute('href')).toEqual('https://de.wikipedia.org/wiki/Beispiel');
Akrond3bb85b2019-02-08 10:15:13 +01001075
Akron0f700762022-01-11 17:21:16 +01001076 //type:attachement with a link (uri encoded)
Akrond3bb85b2019-02-08 10:15:13 +01001077 expect(mel.children[4].children[1].getAttribute('data-type')).toEqual('type:attachement')
Akron0f700762022-01-11 17:21:16 +01001078 expect(mel.children[4].children[1].classList.contains('metakeyvalues')).toBeFalsy;
1079 expect(mel.children[4].children[0].firstChild.nodeValue).toEqual('xlink2');
1080 expect(mel.children[4].children[1].firstChild.textContent).toEqual('Hallo!');
1081 expect(mel.children[4].children[1].firstChild.tagName).toEqual('A');
1082 expect(mel.children[4].children[1].firstChild.getAttribute('href')).toEqual('https://www.test.de');
Akrond7d3ceb2022-02-07 20:13:09 +01001083
Akron0f700762022-01-11 17:21:16 +01001084 //type:attachement with plain text
1085 expect(mel.children[5].children[1].getAttribute('data-type')).toEqual('type:attachement')
1086 expect(mel.children[5].children[1].classList.contains('metakeyvalues')).toBeFalsy;
Akrond7d3ceb2022-02-07 20:13:09 +01001087 expect(mel.children[5].children[0].firstChild.nodeValue).toEqual('xlink3');
1088 expect(mel.children[5].children[1].firstChild.nodeValue).toEqual('[INVALID URI]');
1089
1090 //type:attachement with plain text
1091 expect(mel.children[6].children[1].getAttribute('data-type')).toEqual('type:attachement')
1092 expect(mel.children[6].children[1].classList.contains('metakeyvalues')).toBeFalsy;
1093 expect(mel.children[6].children[0].firstChild.nodeValue).toEqual('z-reference');
1094 expect(mel.children[6].children[1].firstChild.nodeValue).toEqual('This is a reference');
Akrond3bb85b2019-02-08 10:15:13 +01001095 });
Akrona0ea3c32018-12-14 18:33:48 +01001096
1097
hebasta999d6c12018-04-23 12:44:59 +02001098
Akronfa32c9d2018-11-20 15:39:18 +01001099 // Meta information should be sorted alphabetically
1100 it('should be alphabetically sorted', function(){
1101 var a = mel.children[0].children[0].firstChild.nodeValue;
1102 var b = mel.children[1].children[0].firstChild.nodeValue;
1103 var c = mel.children[2].children[0].firstChild.nodeValue;
1104 expect(a.localeCompare(b)).toBe(-1);
1105 expect(b.localeCompare(c)).toBe(-1);
Akrona0ea3c32018-12-14 18:33:48 +01001106 });
1107
1108
1109 it('should handle attachements', function () {
1110 let uri = attachementClass.create("data:text/plain;title=new,Hallo");
1111 expect(uri.contentType).toEqual("text/plain");
1112
1113 expect(uri.payload).toEqual("Hallo");
1114 expect(uri.base64).toBeFalsy();
1115 expect(uri.isLink).toBeFalsy();
1116 expect(uri.param["title"]).toEqual("new");
1117
1118 uri = attachementClass.create("data:application/x.korap-link,https://de.wikipedia.org/wiki/Beispiel");
1119 expect(uri.contentType).toEqual("application/x.korap-link");
1120 expect(uri.payload).toEqual("https://de.wikipedia.org/wiki/Beispiel");
1121 expect(uri.base64).toBeFalsy();
1122 expect(uri.isLink).toBeTruthy();
1123 expect(uri.inline().textContent).toEqual("https://de.wikipedia.org/wiki/Beispiel");
1124 expect(uri.inline().nodeType).toEqual(1);
1125 expect(uri.inline().tagName).toEqual("A");
1126 expect(uri.inline().getAttribute("rel")).toEqual("noopener noreferrer");
1127
1128
1129 uri = attachementClass.create("data:application/x.korap-link;title=Das ist ein Titel,https://de.wikipedia.org/wiki/Beispiel");
1130 expect(uri.contentType).toEqual("application/x.korap-link");
1131 expect(uri.payload).toEqual("https://de.wikipedia.org/wiki/Beispiel");
1132 expect(uri.base64).toBeFalsy();
1133 expect(uri.isLink).toBeTruthy();
1134 expect(uri.inline().textContent).toEqual("Das ist ein Titel");
1135 expect(uri.inline().nodeType).toEqual(1);
1136 expect(uri.inline().tagName).toEqual("A");
1137 expect(uri.inline().getAttribute("rel")).toEqual("noopener noreferrer");
1138
1139
1140 uri = attachementClass.create("data:text/plain;base64,SGVsbG8sIFdvcmxkIQ%3D%3D");
1141 expect(uri.contentType).toEqual("text/plain");
1142 expect(uri.payload).toEqual("Hello, World!");
1143 expect(uri.base64).toBeTruthy();
1144 expect(uri.isLink).toBeFalsy();
1145 expect(uri.inline().nodeType).toEqual(3);
1146 expect(uri.inline().textContent).toEqual("Hello, World!");
1147
1148 uri = attachementClass.create("data:text/plain;title= new ; subTitle = old ;base64,SGVsbG8sIFdvcmxkIQ%3D%3D");
1149 expect(uri.contentType).toEqual("text/plain");
1150 expect(uri.payload).toEqual("Hello, World!");
1151 expect(uri.param["title"]).toEqual("new");
1152 expect(uri.param["subTitle"]).toEqual("old");
1153 expect(uri.base64).toBeTruthy();
1154 expect(uri.isLink).toBeFalsy();
1155 expect(uri.inline().nodeType).toEqual(3);
1156 expect(uri.inline().textContent).toEqual("Hello, World!");
1157 });
hebasta999d6c12018-04-23 12:44:59 +02001158 });
Nils Diewald7c8ced22015-04-15 19:21:00 +00001159 // table = view.toTable();
1160 // table.sortBy('');
1161 // table.element();
1162 // tree = view.toTree();
1163 // tree.element();
Nils Diewalda297f062015-04-02 00:23:46 +00001164});